What changed, and why it matters
This commit fixes a bug in Electrum's wallet setup wizard. Previously, if a user tried to import an individual private key for an unusual script type (like p2wsh), the wizard would crash with an internal error instead of showing a friendly message saying it's not supported. The fix catches that internal error and converts it into a user-facing message. It is a robustness improvement, not a fix for a security vulnerability that allows theft or remote attacks.
No urgent action required. Treat as a normal bug fix / UX hardening patch. Users importing individual private keys should ensure they use supported script types.
Security signals we found
Unhandled exception converted to user-facing error
Improves input validation and error handling in wallet import path
No memory corruption, privilege escalation, or cryptographic weakness evident
Evidence from the diff
In electrum/wizard.py, the NewWalletWizard.import_privkey_or_address flow now wraps bitcoin.pubkey_to_address() in a try/except for descriptor.NotLegacySinglesigScriptType. When raised, it converts the exception to a UserFacingException with a localized message explaining that importing individual private keys of the given txin_type is unsupported. This prevents an unhandled exception during wallet creation for script types that cannot produce a legacy singlesig descriptor.
Changed components
electrum/wizard.pyNewWalletWizard.import_privkey_or_addressInspect captured patch +7 / −2
diff --git a/electrum/wizard.py b/electrum/wizard.py
index d441b02..6b2e7b6 100644
--- a/electrum/wizard.py
+++ b/electrum/wizard.py
@@ -16,7 +16,7 @@ from electrum.storage import WalletStorage, StorageEncryptionVersion, StorageRea
from electrum.util import UserFacingException
from electrum.wallet_db import WalletDB
from electrum.bip32 import normalize_bip32_derivation, xpub_type
-from electrum import keystore, mnemonic, bitcoin
+from electrum import descriptor, keystore, mnemonic, bitcoin
from electrum.mnemonic import is_any_2fa_seed_type, can_seed_have_passphrase
from electrum.util import multisig_type
@@ -702,7 +702,12 @@ class NewWalletWizard(KeystoreWizard):
for pk in keys:
assert bitcoin.is_private_key(pk)
txin_type, pubkey = k.import_privkey(pk, None)
- addr = bitcoin.pubkey_to_address(txin_type, pubkey)
+ try:
+ addr = bitcoin.pubkey_to_address(txin_type, pubkey)
+ except descriptor.NotLegacySinglesigScriptType as e:
+ raise UserFacingException(
+ _("Importing individual private keys of type '{}' is not supported.").format(txin_type),
+ ) from e
addresses[addr] = {'type': txin_type, 'pubkey': pubkey}
elif 'address_list' in data:
for addr in data['address_list'].split():
Why this scored 21/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.