parent
d150a6d29c
commit
2f58d419dc
|
@ -32,6 +32,7 @@ except ImportError:
|
||||||
|
|
||||||
class BTChipWallet(BIP32_HD_Wallet):
|
class BTChipWallet(BIP32_HD_Wallet):
|
||||||
wallet_type = 'btchip'
|
wallet_type = 'btchip'
|
||||||
|
device = 'Ledger'
|
||||||
root_derivation = "m/44'/0'"
|
root_derivation = "m/44'/0'"
|
||||||
restore_wallet_class = BIP44_Wallet
|
restore_wallet_class = BIP44_Wallet
|
||||||
|
|
||||||
|
@ -55,10 +56,6 @@ class BTChipWallet(BIP32_HD_Wallet):
|
||||||
self.device_checked = False
|
self.device_checked = False
|
||||||
raise Exception(message)
|
raise Exception(message)
|
||||||
|
|
||||||
def get_action(self):
|
|
||||||
if not self.accounts:
|
|
||||||
return 'create_accounts'
|
|
||||||
|
|
||||||
def can_sign_xpubkey(self, x_pubkey):
|
def can_sign_xpubkey(self, x_pubkey):
|
||||||
xpub, sequence = BIP32_Account.parse_xpubkey(x_pubkey)
|
xpub, sequence = BIP32_Account.parse_xpubkey(x_pubkey)
|
||||||
return xpub in self.master_public_keys.values()
|
return xpub in self.master_public_keys.values()
|
||||||
|
@ -418,6 +415,8 @@ class LedgerPlugin(BasePlugin):
|
||||||
|
|
||||||
def __init__(self, parent, config, name):
|
def __init__(self, parent, config, name):
|
||||||
BasePlugin.__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
|
self.handler = None
|
||||||
|
|
||||||
def constructor(self, s):
|
def constructor(self, s):
|
||||||
|
@ -433,22 +432,29 @@ class LedgerPlugin(BasePlugin):
|
||||||
return False
|
return False
|
||||||
return True
|
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
|
@hook
|
||||||
def close_wallet(self, wallet):
|
def close_wallet(self, wallet):
|
||||||
self.client = None
|
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
|
|
||||||
|
|
|
@ -12,7 +12,6 @@ class Plugin(LedgerPlugin):
|
||||||
def load_wallet(self, wallet, window):
|
def load_wallet(self, wallet, window):
|
||||||
if type(wallet) != BTChipWallet:
|
if type(wallet) != BTChipWallet:
|
||||||
return
|
return
|
||||||
wallet.plugin = self
|
|
||||||
if self.handler is None:
|
if self.handler is None:
|
||||||
self.handler = BTChipQTHandler(window)
|
self.handler = BTChipQTHandler(window)
|
||||||
if self.btchip_is_connected(wallet):
|
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."))
|
window.show_error(_("Ledger device not detected.\nContinuing in watching-only mode."))
|
||||||
wallet.force_watching_only = True
|
wallet.force_watching_only = True
|
||||||
|
|
||||||
|
def on_create_wallet(self, wallet, wizard):
|
||||||
|
self.handler = BTChipQTHandler(wizard)
|
||||||
|
wallet.create_main_account(None)
|
||||||
|
|
||||||
class BTChipQTHandler:
|
class BTChipQTHandler:
|
||||||
|
|
||||||
|
|
|
@ -335,3 +335,25 @@ class TrezorCompatiblePlugin(BasePlugin):
|
||||||
tx = self.prev_tx[tx_hash]
|
tx = self.prev_tx[tx_hash]
|
||||||
tx.deserialize()
|
tx.deserialize()
|
||||||
return self.electrum_tx_to_txtype(tx)
|
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
|
||||||
|
|
|
@ -125,10 +125,6 @@ class QtPlugin(TrezorPlugin):
|
||||||
client.handler = self.create_handler(wizard)
|
client.handler = self.create_handler(wizard)
|
||||||
wallet.create_main_account(None)
|
wallet.create_main_account(None)
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def is_valid_seed(seed):
|
|
||||||
return True
|
|
||||||
|
|
||||||
@hook
|
@hook
|
||||||
def receive_menu(self, menu, addrs, wallet):
|
def receive_menu(self, menu, addrs, wallet):
|
||||||
if type(wallet) != self.wallet_class:
|
if type(wallet) != self.wallet_class:
|
||||||
|
|
Loading…
Reference in New Issue