From 643fbecc15bca5664af39aec818a0ffad6ca20da Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Wed, 14 Feb 2024 12:42:15 +0100 Subject: [PATCH] wizard: fix co-signing hardware wallets data incorrectly referenced --- electrum/plugins/bitbox02/qt.py | 3 ++- electrum/plugins/coldcard/qt.py | 5 ++-- electrum/plugins/digitalbitbox/qt.py | 3 ++- electrum/plugins/keepkey/qt.py | 38 +++++++++++++++------------ electrum/plugins/safe_t/qt.py | 38 +++++++++++++++------------ electrum/plugins/trezor/qt.py | 39 ++++++++++++++++------------ 6 files changed, 70 insertions(+), 56 deletions(-) diff --git a/electrum/plugins/bitbox02/qt.py b/electrum/plugins/bitbox02/qt.py index fe9fb1c32..bfde53251 100644 --- a/electrum/plugins/bitbox02/qt.py +++ b/electrum/plugins/bitbox02/qt.py @@ -122,7 +122,8 @@ class WCBitbox02ScriptAndDerivation(WCScriptAndDerivation): def on_ready(self): super().on_ready() - _name, _info = self.wizard_data['hardware_device'] + current_cosigner = self.wizard.current_cosigner(self.wizard_data) + _name, _info = current_cosigner['hardware_device'] plugin = self.wizard.plugins.get_plugin(_info.plugin_name) device_id = _info.device.id_ diff --git a/electrum/plugins/coldcard/qt.py b/electrum/plugins/coldcard/qt.py index acfdf3d6b..bbdaee213 100644 --- a/electrum/plugins/coldcard/qt.py +++ b/electrum/plugins/coldcard/qt.py @@ -1,11 +1,10 @@ from functools import partial from typing import TYPE_CHECKING -from PyQt5.QtCore import Qt, pyqtSignal +from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QPushButton, QLabel, QVBoxLayout, QWidget, QGridLayout -from electrum.gui.qt.util import (WindowModalDialog, CloseButton, Buttons, getOpenFileName, - getSaveFileName) +from electrum.gui.qt.util import WindowModalDialog, CloseButton, getOpenFileName, getSaveFileName from electrum.gui.qt.main_window import ElectrumWindow from electrum.i18n import _ diff --git a/electrum/plugins/digitalbitbox/qt.py b/electrum/plugins/digitalbitbox/qt.py index 96f94d501..d72389b23 100644 --- a/electrum/plugins/digitalbitbox/qt.py +++ b/electrum/plugins/digitalbitbox/qt.py @@ -83,7 +83,8 @@ class WCDigitalBitboxScriptAndDerivation(WCScriptAndDerivation): def on_ready(self): super().on_ready() - _name, _info = self.wizard_data['hardware_device'] + current_cosigner = self.wizard.current_cosigner(self.wizard_data) + _name, _info = current_cosigner['hardware_device'] plugin = self.wizard.plugins.get_plugin(_info.plugin_name) device_id = _info.device.id_ diff --git a/electrum/plugins/keepkey/qt.py b/electrum/plugins/keepkey/qt.py index 785e9b2f9..9c53499d5 100644 --- a/electrum/plugins/keepkey/qt.py +++ b/electrum/plugins/keepkey/qt.py @@ -19,8 +19,7 @@ from ..hw_wallet.qt import QtHandlerBase, QtPluginBase from ..hw_wallet.plugin import only_hook_if_libraries_available from .keepkey import KeepKeyPlugin, TIM_NEW, TIM_RECOVER, TIM_MNEMONIC, TIM_PRIVKEY -from electrum.gui.qt.wizard.wallet import WCScriptAndDerivation, WCHWUnlock, WCHWXPub -from electrum.gui.qt.wizard.wizard import WizardComponent +from electrum.gui.qt.wizard.wallet import WCScriptAndDerivation, WCHWUnlock, WCHWXPub, WalletWizardComponent if TYPE_CHECKING: from electrum.gui.qt.wizard.wallet import QENewWalletWizard @@ -602,12 +601,13 @@ class SettingsDialog(WindowModalDialog): invoke_client(None) -class WCKeepkeyInitMethod(WizardComponent): +class WCKeepkeyInitMethod(WalletWizardComponent): def __init__(self, parent, wizard): - WizardComponent.__init__(self, parent, wizard, title=_('KeepKey Setup')) + WalletWizardComponent.__init__(self, parent, wizard, title=_('KeepKey Setup')) def on_ready(self): - _name, _info = self.wizard_data['hardware_device'] + current_cosigner = self.wizard.current_cosigner(self.wizard_data) + _name, _info = current_cosigner['hardware_device'] msg = _("Choose how you want to initialize your {}.\n\n" "The first two methods are secure as no secret information " "is entered into your computer.\n\n" @@ -630,35 +630,38 @@ class WCKeepkeyInitMethod(WizardComponent): self._valid = True def apply(self): - self.wizard_data['keepkey_init'] = self.choice_w.selected_item[0] + current_cosigner = self.wizard.current_cosigner(self.wizard_data) + current_cosigner['keepkey_init'] = self.choice_w.selected_key -class WCKeepkeyInitParams(WizardComponent): +class WCKeepkeyInitParams(WalletWizardComponent): def __init__(self, parent, wizard): - WizardComponent.__init__(self, parent, wizard, title=_('KeepKey Setup')) + WalletWizardComponent.__init__(self, parent, wizard, title=_('KeepKey Setup')) self.plugins = wizard.plugins self._busy = True def on_ready(self): - _name, _info = self.wizard_data['hardware_device'] - self.settings_layout = KeepkeyInitLayout(self.wizard_data['keepkey_init'], _info.device.id_) + current_cosigner = self.wizard.current_cosigner(self.wizard_data) + _name, _info = current_cosigner['hardware_device'] + self.settings_layout = KeepkeyInitLayout(current_cosigner['keepkey_init'], _info.device.id_) self.settings_layout.validChanged.connect(self.on_settings_valid_changed) self.layout().addLayout(self.settings_layout) self.layout().addStretch(1) - self.valid = self.wizard_data['keepkey_init'] != TIM_PRIVKEY # TODO: only privkey is validated + self.valid = current_cosigner['keepkey_init'] != TIM_PRIVKEY # TODO: only privkey is validated self.busy = False def on_settings_valid_changed(self, is_valid: bool): self.valid = is_valid def apply(self): - self.wizard_data['keepkey_settings'] = self.settings_layout.get_settings() + current_cosigner = self.wizard.current_cosigner(self.wizard_data) + current_cosigner['keepkey_settings'] = self.settings_layout.get_settings() -class WCKeepkeyInit(WizardComponent, Logger): +class WCKeepkeyInit(WalletWizardComponent, Logger): def __init__(self, parent, wizard): - WizardComponent.__init__(self, parent, wizard, title=_('KeepKey Setup')) + WalletWizardComponent.__init__(self, parent, wizard, title=_('KeepKey Setup')) Logger.__init__(self) self.plugins = wizard.plugins self.plugin = self.plugins.get_plugin('keepkey') @@ -668,9 +671,10 @@ class WCKeepkeyInit(WizardComponent, Logger): self._busy = True def on_ready(self): - settings = self.wizard_data['keepkey_settings'] - method = self.wizard_data['keepkey_init'] - _name, _info = self.wizard_data['hardware_device'] + current_cosigner = self.wizard.current_cosigner(self.wizard_data) + settings = current_cosigner['keepkey_settings'] + method = current_cosigner['keepkey_init'] + _name, _info = current_cosigner['hardware_device'] device_id = _info.device.id_ client = self.plugins.device_manager.client_by_id(device_id, scan_now=False) client.handler = self.plugin.create_handler(self.wizard) diff --git a/electrum/plugins/safe_t/qt.py b/electrum/plugins/safe_t/qt.py index 9f03f4521..77463d5d4 100644 --- a/electrum/plugins/safe_t/qt.py +++ b/electrum/plugins/safe_t/qt.py @@ -19,8 +19,7 @@ from ..hw_wallet.qt import QtHandlerBase, QtPluginBase from ..hw_wallet.plugin import only_hook_if_libraries_available from .safe_t import SafeTPlugin, TIM_NEW, TIM_RECOVER, TIM_MNEMONIC, TIM_PRIVKEY -from electrum.gui.qt.wizard.wallet import WCScriptAndDerivation, WCHWUnlock, WCHWXPub -from electrum.gui.qt.wizard.wizard import WizardComponent +from electrum.gui.qt.wizard.wallet import WCScriptAndDerivation, WCHWUnlock, WCHWXPub, WalletWizardComponent if TYPE_CHECKING: from electrum.gui.qt.wizard.wallet import QENewWalletWizard @@ -534,12 +533,13 @@ class SettingsDialog(WindowModalDialog): invoke_client(None) -class WCSafeTInitMethod(WizardComponent): +class WCSafeTInitMethod(WalletWizardComponent): def __init__(self, parent, wizard): - WizardComponent.__init__(self, parent, wizard, title=_('Safe-T Setup')) + WalletWizardComponent.__init__(self, parent, wizard, title=_('Safe-T Setup')) def on_ready(self): - _name, _info = self.wizard_data['hardware_device'] + current_cosigner = self.wizard.current_cosigner(self.wizard_data) + _name, _info = current_cosigner['hardware_device'] msg = _("Choose how you want to initialize your {}.\n\n" "The first two methods are secure as no secret information " "is entered into your computer.\n\n" @@ -562,35 +562,38 @@ class WCSafeTInitMethod(WizardComponent): self._valid = True def apply(self): - self.wizard_data['safe_t_init'] = self.choice_w.selected_key + current_cosigner = self.wizard.current_cosigner(self.wizard_data) + current_cosigner['safe_t_init'] = self.choice_w.selected_key -class WCSafeTInitParams(WizardComponent): +class WCSafeTInitParams(WalletWizardComponent): def __init__(self, parent, wizard): - WizardComponent.__init__(self, parent, wizard, title=_('Safe-T Setup')) + WalletWizardComponent.__init__(self, parent, wizard, title=_('Safe-T Setup')) self.plugins = wizard.plugins self._busy = True def on_ready(self): - _name, _info = self.wizard_data['hardware_device'] - self.settings_layout = SafeTInitLayout(self.wizard_data['safe_t_init'], _info.device.id_) + current_cosigner = self.wizard.current_cosigner(self.wizard_data) + _name, _info = current_cosigner['hardware_device'] + self.settings_layout = SafeTInitLayout(current_cosigner['safe_t_init'], _info.device.id_) self.settings_layout.validChanged.connect(self.on_settings_valid_changed) self.layout().addLayout(self.settings_layout) self.layout().addStretch(1) - self.valid = self.wizard_data['safe_t_init'] != TIM_PRIVKEY + self.valid = current_cosigner['safe_t_init'] != TIM_PRIVKEY self.busy = False def on_settings_valid_changed(self, is_valid: bool): self.valid = is_valid def apply(self): - self.wizard_data['safe_t_settings'] = self.settings_layout.get_settings() + current_cosigner = self.wizard.current_cosigner(self.wizard_data) + current_cosigner['safe_t_settings'] = self.settings_layout.get_settings() -class WCSafeTInit(WizardComponent, Logger): +class WCSafeTInit(WalletWizardComponent, Logger): def __init__(self, parent, wizard): - WizardComponent.__init__(self, parent, wizard, title=_('Safe-T Setup')) + WalletWizardComponent.__init__(self, parent, wizard, title=_('Safe-T Setup')) Logger.__init__(self) self.plugins = wizard.plugins self.plugin = self.plugins.get_plugin('safe_t') @@ -600,9 +603,10 @@ class WCSafeTInit(WizardComponent, Logger): self._busy = True def on_ready(self): - settings = self.wizard_data['safe_t_settings'] - method = self.wizard_data['safe_t_init'] - _name, _info = self.wizard_data['hardware_device'] + current_cosigner = self.wizard.current_cosigner(self.wizard_data) + settings = current_cosigner['safe_t_settings'] + method = current_cosigner['safe_t_init'] + _name, _info = current_cosigner['hardware_device'] device_id = _info.device.id_ client = self.plugins.device_manager.client_by_id(device_id, scan_now=False) client.handler = self.plugin.create_handler(self.wizard) diff --git a/electrum/plugins/trezor/qt.py b/electrum/plugins/trezor/qt.py index 7c0ff5735..5914ebb79 100644 --- a/electrum/plugins/trezor/qt.py +++ b/electrum/plugins/trezor/qt.py @@ -18,8 +18,7 @@ from electrum.plugins.hw_wallet.plugin import only_hook_if_libraries_available, from electrum.gui.qt.util import (WindowModalDialog, WWLabel, Buttons, CancelButton, OkButton, CloseButton, PasswordLineEdit, getOpenFileName, ChoiceWidget) -from electrum.gui.qt.wizard.wallet import WCScriptAndDerivation, WCHWUnlock, WCHWXPub -from electrum.gui.qt.wizard.wizard import WizardComponent +from electrum.gui.qt.wizard.wallet import WCScriptAndDerivation, WCHWUnlock, WCHWXPub, WalletWizardComponent from .trezor import (TrezorPlugin, TIM_NEW, TIM_RECOVER, TrezorInitSettings, PASSPHRASE_ON_DEVICE, Capability, BackupType, RecoveryDeviceType) @@ -807,7 +806,8 @@ class WCTrezorXPub(WCHWXPub): WCHWXPub.__init__(self, parent, wizard) def get_xpub_from_client(self, client, derivation, xtype): - _name, _info = self.wizard_data['hardware_device'] + current_cosigner = self.wizard.current_cosigner(self.wizard_data) + _name, _info = current_cosigner['hardware_device'] if xtype not in self.plugin.SUPPORTED_XTYPES: raise ScriptTypeNotSupported(_('This type of script is not supported with {}').format(_info.model_name)) if not client.is_uptodate(): @@ -818,15 +818,16 @@ class WCTrezorXPub(WCHWXPub): return client.get_xpub(derivation, xtype, True) -class WCTrezorInitMethod(WizardComponent, Logger): +class WCTrezorInitMethod(WalletWizardComponent, Logger): def __init__(self, parent, wizard): - WizardComponent.__init__(self, parent, wizard, title=_('Trezor Setup')) + WalletWizardComponent.__init__(self, parent, wizard, title=_('Trezor Setup')) Logger.__init__(self) self.plugins = wizard.plugins self.plugin = None def on_ready(self): - _name, _info = self.wizard_data['hardware_device'] + current_cosigner = self.wizard.current_cosigner(self.wizard_data) + _name, _info = current_cosigner['hardware_device'] self.plugin = self.plugins.get_plugin(_info.plugin_name) device_id = _info.device.id_ client = self.plugins.device_manager.client_by_id(device_id, scan_now=False) @@ -858,18 +859,20 @@ class WCTrezorInitMethod(WizardComponent, Logger): def apply(self): if not self.valid: return - self.wizard_data['trezor_init'] = self.choice_w.selected_key + current_cosigner = self.wizard.current_cosigner(self.wizard_data) + current_cosigner['trezor_init'] = self.choice_w.selected_key -class WCTrezorInitParams(WizardComponent): +class WCTrezorInitParams(WalletWizardComponent): def __init__(self, parent, wizard): - WizardComponent.__init__(self, parent, wizard, title=_('Trezor Setup')) + WalletWizardComponent.__init__(self, parent, wizard, title=_('Trezor Setup')) self.plugins = wizard.plugins self._busy = True def on_ready(self): - _name, _info = self.wizard_data['hardware_device'] - self.settings_layout = InitSettingsLayout(self.plugins.device_manager, self.wizard_data['trezor_init'], _info.device.id_) + current_cosigner = self.wizard.current_cosigner(self.wizard_data) + _name, _info = current_cosigner['hardware_device'] + self.settings_layout = InitSettingsLayout(self.plugins.device_manager, current_cosigner['trezor_init'], _info.device.id_) self.layout().addLayout(self.settings_layout) self.layout().addStretch(1) @@ -877,12 +880,13 @@ class WCTrezorInitParams(WizardComponent): self.busy = False def apply(self): - self.wizard_data['trezor_settings'] = self.settings_layout.get_settings() + current_cosigner = self.wizard.current_cosigner(self.wizard_data) + current_cosigner['trezor_settings'] = self.settings_layout.get_settings() -class WCTrezorInit(WizardComponent, Logger): +class WCTrezorInit(WalletWizardComponent, Logger): def __init__(self, parent, wizard): - WizardComponent.__init__(self, parent, wizard, title=_('Trezor Setup')) + WalletWizardComponent.__init__(self, parent, wizard, title=_('Trezor Setup')) Logger.__init__(self) self.plugins = wizard.plugins self.plugin = self.plugins.get_plugin('trezor') @@ -892,9 +896,10 @@ class WCTrezorInit(WizardComponent, Logger): self._busy = True def on_ready(self): - settings = self.wizard_data['trezor_settings'] - method = self.wizard_data['trezor_init'] - _name, _info = self.wizard_data['hardware_device'] + current_cosigner = self.wizard.current_cosigner(self.wizard_data) + settings = current_cosigner['trezor_settings'] + method = current_cosigner['trezor_init'] + _name, _info = current_cosigner['hardware_device'] device_id = _info.device.id_ client = self.plugins.device_manager.client_by_id(device_id, scan_now=False) client.handler = self.plugin.create_handler(self.wizard)