diff --git a/electrum/plugins/satochip/qt.py b/electrum/plugins/satochip/qt.py index 70932b97eb76..cd9425b3c13b 100644 --- a/electrum/plugins/satochip/qt.py +++ b/electrum/plugins/satochip/qt.py @@ -1,26 +1,27 @@ +from functools import partial +from os import urandom +import textwrap +import threading + from electrum.i18n import _ from electrum.logging import get_logger -from electrum.keystore import bip39_is_checksum_valid +from electrum.util import UserFacingException from electrum.simple_config import SimpleConfig from electrum.gui.qt.util import (EnterButton, Buttons, CloseButton, icon_path, OkButton, CancelButton, WindowModalDialog, WWLabel, PasswordLineEdit) from electrum.gui.qt.qrcodewidget import QRDialog from electrum.gui.qt.wizard.wallet import (WCHaveSeed, WCEnterExt, WCScriptAndDerivation, - WCHWUnlock, WCHWXPub, WalletWizardComponent, QENewWalletWizard) + WCHWUnlock, WCHWXPub, WalletWizardComponent, QENewWalletWizard) from electrum.plugin import hook +from electrum.plugins.hw_wallet.qt import QtHandlerBase, QtPluginBase + from PyQt6.QtGui import QPixmap from PyQt6.QtCore import Qt, pyqtSignal from PyQt6.QtWidgets import (QPushButton, QLabel, QVBoxLayout, QHBoxLayout, - QWidget, QGridLayout, QComboBox, QLineEdit, QTextEdit, QTabWidget) - -from functools import partial -from os import urandom -import textwrap -import threading + QWidget, QGridLayout, QComboBox, QLineEdit, QTabWidget) # satochip from .satochip import SatochipPlugin -from ..hw_wallet.qt import QtHandlerBase, QtPluginBase # pysatochip from pysatochip.CardConnector import UnexpectedSW12Error, CardError, CardNotPresentError, WrongPinError @@ -49,6 +50,7 @@ _("If set, you will need your passphrase along with your BIP39 seed to restore your wallet from a backup. "), ] + class Plugin(SatochipPlugin, QtPluginBase): icon_unpaired = "satochip_unpaired.png" icon_paired = "satochip.png" @@ -104,7 +106,8 @@ def extend_wizard(self, wizard: 'QENewWalletWizard'): }, 'satochip_have_seed': { 'gui': WCHaveSeed, - 'next': lambda d: 'satochip_have_ext' if wizard.wants_ext(d) else 'satochip_import_seed' + 'next': lambda d: 'satochip_have_ext' if wizard.wants_ext(d) else 'satochip_import_seed', + 'params': {'seed_options': ['ext', 'bip39']} }, 'satochip_have_ext': { 'gui': WCEnterExt, @@ -255,10 +258,14 @@ def _change_card_label(): def show_values(self, client): _logger.info("Show value!") - is_ok = client.verify_PIN() - if not is_ok: - msg = f"action cancelled by user" - self.window.show_error(msg) + try: + is_ok = client.verify_PIN() + if not is_ok: + msg = f"action cancelled by user" + self.window.show_error(msg) + return + except UserFacingException as e: + self.window.show_error(str(e)) return sw_rel = 'v' + str(SATOCHIP_PROTOCOL_MAJOR_VERSION) + \ @@ -412,7 +419,7 @@ def reset_seed_dialog(self, msg): parent = self.top_level_window() d = WindowModalDialog(parent, _("Enter PIN")) pw = QLineEdit() - pw.setEchoMode(2) + pw.setEchoMode(QLineEdit.EchoMode.Password) pw.setMinimumWidth(200) vbox = QVBoxLayout() @@ -645,7 +652,6 @@ def change_card_label_dialog(self, client, msg): parent = self.top_level_window() d = WindowModalDialog(parent, _("Enter Label")) pw = QLineEdit() - pw.setEchoMode(0) pw.setMinimumWidth(200) vbox = QVBoxLayout() @@ -929,6 +935,7 @@ def apply(self): # Import seed wizard # ########################## + class WCSeedMessage(WalletWizardComponent): def __init__(self, parent, wizard): WalletWizardComponent.__init__(self, parent, wizard, title=_('Satochip needs a seed')) diff --git a/electrum/plugins/satochip/satochip.py b/electrum/plugins/satochip/satochip.py index 38d4ef5ac578..29775b6200a1 100644 --- a/electrum/plugins/satochip/satochip.py +++ b/electrum/plugins/satochip/satochip.py @@ -20,7 +20,7 @@ from ..hw_wallet import HW_PluginBase, HardwareClientBase # pysatochip -from pysatochip.CardConnector import CardConnector +from pysatochip.CardConnector import CardConnector, UninitializedSeedError from pysatochip.CardConnector import CardNotPresentError, UnexpectedSW12Error, WrongPinError, PinBlockedError, PinRequiredError from pysatochip.Satochip2FA import Satochip2FA, SERVER_LIST @@ -163,7 +163,10 @@ def get_xpub(self, bip32_path, xtype): # bip32_path is of the form 44'/0'/1' _logger.info(f"[SatochipClient] get_xpub(): bip32_path={bip32_path}") (depth, bytepath) = bip32path2bytes(bip32_path) - (childkey, childchaincode) = self.cc.card_bip32_get_extendedkey(bytepath) + try: + (childkey, childchaincode) = self.cc.card_bip32_get_extendedkey(bytepath) + except UninitializedSeedError as e: + raise UserFacingException(str(e)) if depth == 0: # masterkey fingerprint = bytes([0, 0, 0, 0]) child_number = bytes([0, 0, 0, 0])