Commit Graph

88 Commits

Author SHA1 Message Date
SomberNight
c68deb25ff daemon: get_wallet: handle OSError for weiiird paths
I think _wallet_key_from_path should not raise.
This is probably the sane way to deal with this.
Though all this is assuming that os.path.realpath can be treated as consistent/stateless.

closes https://github.com/spesmilo/electrum/issues/10182
2025-09-03 14:14:22 +00:00
SomberNight
92bdc4d4ca daemon: load_wallet: add force_check_password arg, and use it in qml
- fix: qml gui errors when trying to open a wallets with only keystore-encryption
  - fixes https://github.com/spesmilo/electrum/issues/10171
- qml gui to prompt for password on wallet open even if wallet is not storage-encrypted
2025-08-23 16:54:48 +00:00
SomberNight
3e4601c61d base64.b64decode: always set validate=True
Notably verifymessage and decrypt(message) were silently ignoring trailing garbage
or inserted non-base64 characters present in signatures/ciphertext.
(both the CLI commands and in the GUI)
I think it is much cleaner and preferable to treat such signatures/ciphertext as invalid.

In fact I find it surprising that base64.b64decode(validate=False) is the default.
Perhaps we should create a helper function for it that set validate=True and use that.
2025-06-03 18:58:05 +00:00
f321x
58b0fdf199 followup 9e225d1: rm save_last_wallet call 2025-06-02 15:07:22 +02:00
ThomasV
9e225d1269 Replace config GUI_LAST_WALLET with CURRENT_WALLET
- CURRENT_WALLET is set when a single wallet is loaded in memory, and it
   remains set after Electrum stops running.
 - If several wallets are loaded at the same time, CURRENT_WALLET is unset,
   and RPCs must specify the wallet explicitly (using --wallet for the CLI)
 - The fallback to 'default_wallet' essentially only applies when
   creating a new wallet file
2025-06-02 14:05:53 +02:00
f321x
38f51a3b13 qml: add terms of use to setup wizard 2025-05-13 14:28:13 +02:00
Sander van Grieken
eb29b7c95c qml: simplify QEConfig and QEDaemon use.
force QEDaemon singleton, and refer to QEDaemon.instance where possible
In cases where we would run into circular dependencies, pass the instance

also refer to singleton QEConfig instead of passing instance in qeapp.py
2025-04-09 13:44:26 +02:00
Sander van Grieken
010b153ab2 qml: fix regression caused by ee42e09387
in qml, we need the password in-memory as the auth wrapper (@auth_protect) does not
pass the password to the wrapped fn.
2025-01-17 12:16:46 +01:00
ThomasV
7113cec4c7 minor fix, follow-up ee42e09387 2024-12-20 15:33:47 +01:00
ThomasV
ee42e09387 anchor channels: unlock wallet on startup if the wallet has channels 2024-12-20 10:10:07 +01:00
ThomasV
2f3d89f415 prepare for separation of ecc module:
- move encrypt/sign functions elsewhere
- remove local dependencies in ecc.py, ecc_fast.py (except logging)
2024-06-17 13:05:57 +02:00
SomberNight
bd9d0ccc33 ecc: refactor/clean-up sign/verify APIs 2024-04-11 15:25:45 +00:00
accumulator
acc7b44a3e Merge pull request #8873 from accumulator/issue_8355
qml: tighten self._loading guard to encompass whole loadWallet fn
2024-02-06 13:55:26 +01:00
Sander van Grieken
482ec89b5d minor, code style, imports 2024-02-05 21:25:13 +01:00
Sander van Grieken
c755a58661 qedaemon: remove redundant, small code style fixes 2024-02-05 18:07:12 +01:00
Sander van Grieken
5aa782a19e qml: extend self._loading guard to encompass _on_backend_wallet_loaded slot as well 2024-02-05 17:59:44 +01:00
Sander van Grieken
b361d02467 qml: tighten self._loading guard to encompass whole loadWallet fn, not just task thread.
Also make sure QEWallet is never instantiated within the task thread.
2024-02-05 17:41:56 +01:00
Sander van Grieken
98264f64ad qml: introduce PasswordStrengthIndicator control, and add to PasswordDialog and WCWalletPassword 2023-11-10 09:30:31 +01:00
Sander van Grieken
6270eae5c9 qml: port PyQt5 to PyQt6 2023-11-07 10:16:18 +01:00
Sander van Grieken
7ca9b735d5 daemon: refactor load_wallet to not just return None, but raise specific exceptions.
The following exceptions should be expected:
FileNotFoundError: given wallet path does not exist
StorageReadWriteError: given file is not readable/writable or containing folder is not writable
InvalidPassword: wallet requires a password but no password or an invalid password was given
WalletFileException: any internal wallet data issue. specific subclasses can be caught separately:
-  WalletRequiresSplit: wallet needs splitting (split_data passed in Exception)
-  WalletRequiresUpgrade: wallet needs upgrade, and no upgrade=True was passed to load_wallet
-  WalletUnfinished: wallet file contains an action and needs additional information to finalize. (WalletDB passed in exception)

Removed qml/qewalletdb.py

This patch also fixes load_wallet calls in electrum/scripts and adds a qml workaround for dialogs opening and closing so
fast that the dialog opened==true property change is missed (which we need to manage the dialog/page stack)
2023-10-10 17:42:07 +02:00
ThomasV
98cecb305e jsondb: raise an exception if a daemon thread attempts to write 2023-09-28 18:33:56 +02:00
Sander van Grieken
e5e1e46b7b qml: add message sign/verify 2023-09-26 11:28:55 +02:00
ThomasV
4cc3c704b2 QML: Check passwords with WalletDB instances that have no storage,
to avoid unwanted side effects.

In qedaemon, call load_wallet with upgrade=True when loading a
wallet. Apparently, this was not done before; db upgrades were
performed as a side-effect of password verification...
2023-09-23 15:15:48 +02:00
Sander van Grieken
190c19d48c whitespace, imports, code style 2023-09-22 16:38:37 +02:00
Sander van Grieken
dec4a8e2c7 qml: wizard fixes 2023-09-20 14:34:31 +02:00
SomberNight
0d29733419 qml/qedaemon.py: don't use daemon._wallets field directly
it's more robust to use the public methods
2023-06-30 10:11:16 +00:00
SomberNight
24980feab7 config: introduce ConfigVars
A new config API is introduced, and ~all of the codebase is adapted to it.
The old API is kept but mainly only for dynamic usage where its extra flexibility is needed.

Using examples, the old config API looked this:
```
>>> config.get("request_expiry", 86400)
604800
>>> config.set_key("request_expiry", 86400)
>>>
```

The new config API instead:
```
>>> config.WALLET_PAYREQ_EXPIRY_SECONDS
604800
>>> config.WALLET_PAYREQ_EXPIRY_SECONDS = 86400
>>>
```

The old API operated on arbitrary string keys, the new one uses
a static ~enum-like list of variables.

With the new API:
- there is a single centralised list of config variables, as opposed to
  these being scattered all over
- no more duplication of default values (in the getters)
- there is now some (minimal for now) type-validation/conversion for
  the config values

closes https://github.com/spesmilo/electrum/pull/5640
closes https://github.com/spesmilo/electrum/pull/5649

Note: there is yet a third API added here, for certain niche/abstract use-cases,
where we need a reference to the config variable itself.
It should only be used when needed:
```
>>> var = config.cv.WALLET_PAYREQ_EXPIRY_SECONDS
>>> var
<ConfigVarWithConfig key='request_expiry'>
>>> var.get()
604800
>>> var.set(3600)
>>> var.get_default_value()
86400
>>> var.is_set()
True
>>> var.is_modifiable()
True
```
2023-05-25 17:39:48 +00:00
Sander van Grieken
89225a9f41 qml: show result dialog after password change 2023-05-12 10:53:02 +02:00
SomberNight
68fb996d20 wallet_db version 52: break non-homogeneous multisig wallets
- case 1: in version 4.4.1, 4.4.2, the qml GUI wizard allowed creating multisig wallets with an old_mpk as cosigner.
- case 2: in version 4.4.0, 4.4.1, 4.4.2, the qml GUI wizard allowed creating multisig wallets with mixed xpub/Ypub/Zpub.

The corresponding missing input validation was a bug in the wizard, it was unintended behaviour. Validation was added in d2cf21fc2b. Note however that there might be users who created such wallet files.

Re case 1 wallet files: there is no version of Electrum that allows spending from such a wallet. Coins received at addresses are not burned, however it is technically challenging to spend them. (unless the multisig can spend without needing the old_mpk cosigner in the quorum).

Re case 2 wallet files: it is possible to create a corresponding spending wallet for such a multisig, however it is a bit tricky. The script type for the addresses in such a heterogeneous xpub wallet is based on the xpub_type of the first keystore. So e.g. given a wallet file [Yprv1, Zpub2] it will have sh(wsh()) scripts, and the cosigner should create a wallet file [Ypub1, Zprv2] (same order).

Technically case 2 wallet files could be "fixed" automatically by converting the xpub types as part of a wallet_db upgrade. However if the wallet files also contain seeds, those cannot be converted ("standard" vs "segwit" electrum seed).
Case 1 wallet files are not possible to "fix" automatically as the cosigner using the old_mpk is not bip32 based.

It is unclear if there are *any* users out there affected by this. I suspect for case 1 it is very likely there are none (not many people have pre-2.0 electrum seeds which were never supported as part of a multisig who would also now try to create a multisig using them); for case 2 however there might be.

This commit breaks both case 1 and case 2 wallets: these wallet files can no longer be opened in new Electrum, an error message is shown and the crash reporter opens. If any potential users opt to send crash reports, at least we will know they exist and can help them recover.
2023-05-11 14:26:11 +00:00
SomberNight
87909485c5 qml: wizard to check if wallet name is already used
was erroring at the very last moment previously
2023-04-27 08:47:02 +00:00
Sander van Grieken
264540e12b qml: consistency camelcase public slots qedaemon, qeinvoice, qewizard 2023-04-25 13:40:16 +02:00
ThomasV
a03f4769ca auth_protect: pass authMessage in the auth_protect decorator,
instead of relying on side-effects

This is probably safer, and also more self-contained.
2023-04-17 18:17:29 +02:00
ThomasV
73dd6827e0 add auth_message to delete_wallet
This changes the flow slightly: pin confirmation is asked after
we have checked that the wallet does not have open channels,
which is better
2023-04-17 17:58:19 +02:00
Sander van Grieken
21d1a6239f qml: always pass wallet password to init_lightning.
emit also dataChanged so UI updates node pubkey
2023-04-14 12:21:38 +02:00
Sander van Grieken
5d4e6b1cd7 qml: fix setting empty password when switching to already open wallet with password 2023-04-14 10:53:53 +02:00
SomberNight
fcff4b7274 qml: begone, you C-style for loops
how am I going to continue in the middle of the loop body if the i+=1 is at the end? :P
2023-04-05 14:13:40 +00:00
SomberNight
1530668960 qt/qml: delay starting network until after first-start-network-setup
The qt, qml, and kivy GUIs have a first-start network-setup screen
that allows the user customising the network settings before creating a wallet.
Previously the daemon used to create the network and start it, before this screen,
before the GUI even starts. If the user changed network settings, those would
be set on the already running network, potentially including restarting the network.

Now it becomes the responsibility of the GUI to start the network, allowing this
first-start customisation to take place before starting the network at all.
The qt and the qml GUIs are adapted to make use of this. Kivy, and the other
prototype GUIs are not adapted and just start the network right away, as before.
2023-03-30 00:59:02 +00:00
Sander van Grieken
39ac484ec7 qml: password change requires password, not PIN. fixes #8257 2023-03-18 00:52:42 +01:00
ThomasV
849d987d0d qml: fix #8247 2023-03-16 20:23:29 +01:00
Sander van Grieken
0f596cf2e9 qml: report unified password change failure, impose minimum password length of 5, disallow empty passwords 2023-03-03 12:56:02 +01:00
Sander van Grieken
c7cb2fb9e6 qml: explicitly use None when empty string is used as password
backend requires None, Qt5 passes empty string
2023-02-28 14:51:19 +01:00
Sander van Grieken
d59e687cdb qml: follow-up fe540200a9 2023-02-28 14:11:52 +01:00
Sander van Grieken
fe540200a9 qml: report wallet open problems when walletdb cannot open a wallet (WalletFileException) 2023-02-28 14:04:20 +01:00
Sander van Grieken
278486602b qml: add loader overlay, avoid interacting with the to-be-unloaded wallet 2023-02-23 18:20:29 +01:00
Sander van Grieken
a56c9687c8 qml: initial async wallet load 2023-02-23 14:39:55 +01:00
Sander van Grieken
e9ad9986d7 qml: qedaemon doesn't need wallet path and name properties, pass them via the signal 2023-02-10 14:27:39 +01:00
Sander van Grieken
0bc8460005 qml: don't initialize instance variables on class scope for non-singletons
(this somehow escaped attention before, as most objects usually don't have multiple instances,
unless multiple wallets are open at the same time.)
Also, move all signal declarations, class constants and variables to the top of class definitions.
2023-01-12 13:09:21 +01:00
Sander van Grieken
20eacc37e1 qml: allow delete wallet if has channels not in REDEEMED state but is channelbackup 2023-01-06 13:42:59 +01:00
Sander van Grieken
79d12330ac qml: let WalletListModel update the wallet state when a wallet is loaded 2022-11-11 12:28:00 +01:00
Sander van Grieken
12086ba0de qml: unify to single WalletListModel, WalletDB trigger actions on every path set,
camelcase more QML exposed functions/slots.
2022-11-11 12:00:07 +01:00