diff --git a/plugins/ledger/ledger.py b/plugins/ledger/ledger.py index 55a7fd0f..99b7b245 100644 --- a/plugins/ledger/ledger.py +++ b/plugins/ledger/ledger.py @@ -32,6 +32,7 @@ except ImportError: class BTChipWallet(BIP32_HD_Wallet): wallet_type = 'btchip' + device = 'Ledger' root_derivation = "m/44'/0'" restore_wallet_class = BIP44_Wallet @@ -55,10 +56,6 @@ class BTChipWallet(BIP32_HD_Wallet): self.device_checked = False raise Exception(message) - def get_action(self): - if not self.accounts: - return 'create_accounts' - def can_sign_xpubkey(self, x_pubkey): xpub, sequence = BIP32_Account.parse_xpubkey(x_pubkey) return xpub in self.master_public_keys.values() @@ -418,6 +415,8 @@ class LedgerPlugin(BasePlugin): def __init__(self, parent, config, name): BasePlugin.__init__(self, parent, config, name) + self.wallet_class.plugin = self + self.device = self.wallet_class.device self.handler = None def constructor(self, s): @@ -433,22 +432,29 @@ class LedgerPlugin(BasePlugin): return False return True + @staticmethod + def is_valid_seed(seed): + return True + + def on_restore_wallet(self, wallet, wizard): + assert isinstance(wallet, self.wallet_class) + + msg = _("Enter the seed for your %s wallet:" % self.device) + seed = wizard.request_seed(msg, is_valid = self.is_valid_seed) + + # Restored wallets are not hardware wallets + wallet_class = self.wallet_class.restore_wallet_class + wallet.storage.put('wallet_type', wallet_class.wallet_type) + wallet = wallet_class(wallet.storage) + + # Ledger wallets don't use passphrases + passphrase = unicode() + password = wizard.request_password() + wallet.add_seed(seed, password) + wallet.add_cosigner_seed(seed, 'x/', password, passphrase) + wallet.create_main_account(password) + return wallet + @hook def close_wallet(self, wallet): self.client = None - - @hook - def installwizard_load_wallet(self, wallet, window): - self.load_wallet(wallet, window) - - @hook - def installwizard_restore(self, wizard, storage): - if storage.get('wallet_type') != 'btchip': - return - wallet = BTChipWallet(storage) - try: - wallet.create_main_account(None) - except BaseException as e: - QMessageBox.information(None, _('Error'), str(e), _('OK')) - return - return wallet diff --git a/plugins/ledger/qt.py b/plugins/ledger/qt.py index 0b9a3aff..8e1e8f9d 100644 --- a/plugins/ledger/qt.py +++ b/plugins/ledger/qt.py @@ -12,7 +12,6 @@ class Plugin(LedgerPlugin): def load_wallet(self, wallet, window): if type(wallet) != BTChipWallet: return - wallet.plugin = self if self.handler is None: self.handler = BTChipQTHandler(window) if self.btchip_is_connected(wallet): @@ -23,6 +22,9 @@ class Plugin(LedgerPlugin): window.show_error(_("Ledger device not detected.\nContinuing in watching-only mode.")) wallet.force_watching_only = True + def on_create_wallet(self, wallet, wizard): + self.handler = BTChipQTHandler(wizard) + wallet.create_main_account(None) class BTChipQTHandler: diff --git a/plugins/trezor/plugin.py b/plugins/trezor/plugin.py index f7121bfa..8f05fd45 100644 --- a/plugins/trezor/plugin.py +++ b/plugins/trezor/plugin.py @@ -335,3 +335,25 @@ class TrezorCompatiblePlugin(BasePlugin): tx = self.prev_tx[tx_hash] tx.deserialize() return self.electrum_tx_to_txtype(tx) + + @staticmethod + def is_valid_seed(seed): + return True + + def on_restore_wallet(self, wallet, wizard): + assert isinstance(wallet, self.wallet_class) + + msg = _("Enter the seed for your %s wallet:" % self.device) + seed = wizard.request_seed(msg, is_valid = self.is_valid_seed) + + # Restored wallets are not hardware wallets + wallet_class = self.wallet_class.restore_wallet_class + wallet.storage.put('wallet_type', wallet_class.wallet_type) + wallet = wallet_class(wallet.storage) + + passphrase = wizard.request_passphrase(self.device, restore=True) + password = wizard.request_password() + wallet.add_seed(seed, password) + wallet.add_cosigner_seed(seed, 'x/', password, passphrase) + wallet.create_main_account(password) + return wallet diff --git a/plugins/trezor/qt_generic.py b/plugins/trezor/qt_generic.py index 7d6d25c2..72077963 100644 --- a/plugins/trezor/qt_generic.py +++ b/plugins/trezor/qt_generic.py @@ -125,10 +125,6 @@ class QtPlugin(TrezorPlugin): client.handler = self.create_handler(wizard) wallet.create_main_account(None) - @staticmethod - def is_valid_seed(seed): - return True - @hook def receive_menu(self, menu, addrs, wallet): if type(wallet) != self.wallet_class: