diff --git a/electrum/gui/qt/wizard/wallet.py b/electrum/gui/qt/wizard/wallet.py index b644ed5ba..931c7d107 100644 --- a/electrum/gui/qt/wizard/wallet.py +++ b/electrum/gui/qt/wizard/wallet.py @@ -1277,15 +1277,30 @@ class WCHWUnlock(WizardComponent, Logger): t.start() def validate(self): + self.valid = False if self.password and not self.error: - self.apply() - self.valid = True - else: - self.valid = False + if not self.check_hw_decrypt(): + self.error = _('This hardware device could not decrypt this wallet. Is it the correct one?') + else: + self.apply() + self.valid = True if self.valid: self.wizard.requestNext.emit() # via signal, so it triggers Next/Finish on GUI thread after on_updated() + def check_hw_decrypt(self): + wallet_file = self.wizard_data['wallet_name'] + + storage = WalletStorage(wallet_file) + if not storage.is_encrypted_with_hw_device(): + return True + + try: + storage.decrypt(self.password) + except InvalidPassword: + return False + return True + def apply(self): if self.valid: self.wizard_data['password'] = self.password diff --git a/electrum/wizard.py b/electrum/wizard.py index 0ea5282eb..300a1641f 100644 --- a/electrum/wizard.py +++ b/electrum/wizard.py @@ -273,7 +273,7 @@ class NewWalletWizard(AbstractWizard): # returns (sub)dict of current cosigner (or root if first) def current_cosigner(self, wizard_data: dict) -> dict: wdata = wizard_data - if wizard_data['wallet_type'] == 'multisig' and 'multisig_current_cosigner' in wizard_data: + if wizard_data.get('wallet_type') == 'multisig' and 'multisig_current_cosigner' in wizard_data: cosigner = wizard_data['multisig_current_cosigner'] wdata = wizard_data['multisig_cosigner_data'][str(cosigner)] return wdata @@ -311,7 +311,9 @@ class NewWalletWizard(AbstractWizard): return wizard_data['keystore_type'] == 'hardware' def wallet_password_view(self, wizard_data: dict) -> str: - return 'wallet_password_hardware' if self.is_hardware(wizard_data) else 'wallet_password' + if self.is_hardware(wizard_data) and wizard_data['wallet_type'] == 'standard': + return 'wallet_password_hardware' + return 'wallet_password' def on_hardware_device(self, wizard_data: dict, new_wallet=True) -> str: _type, _info = wizard_data['hardware_device'] @@ -581,7 +583,7 @@ class NewWalletWizard(AbstractWizard): if k and k.may_have_password(): k.update_password(None, data['password']) enc_version = StorageEncryptionVersion.USER_PASSWORD - if 'keystore_type' in data and data['keystore_type'] == 'hardware': + if data.get('keystore_type') == 'hardware' and data['wallet_type'] == 'standard': enc_version = StorageEncryptionVersion.XPUB_PASSWORD storage.set_password(data['password'], enc_version=enc_version)