From c298860e117f72fb960cff84faeabdb2439029ba Mon Sep 17 00:00:00 2001 From: Neil Booth Date: Sat, 26 Dec 2015 12:02:19 +0900 Subject: [PATCH] A fix and cleanups for hardware wallets --- lib/wallet.py | 3 ++- plugins/keepkey/keepkey.py | 16 +++------------- plugins/ledger/ledger.py | 10 ---------- plugins/trezor/trezor.py | 15 +++------------ 4 files changed, 8 insertions(+), 36 deletions(-) diff --git a/lib/wallet.py b/lib/wallet.py index e585cbd0..9bd4de99 100644 --- a/lib/wallet.py +++ b/lib/wallet.py @@ -1681,7 +1681,8 @@ class BIP32_HD_Wallet(BIP32_Wallet): def create_main_account(self, password): # First check the password is valid (this raises if it isn't). - self.check_password(password) + if self.can_change_password(): + self.check_password(password) assert self.next_account_number() == 0 self.create_next_account(password, _('Main account')) self.create_next_account(password) diff --git a/plugins/keepkey/keepkey.py b/plugins/keepkey/keepkey.py index 90f6556c..e76dc6c2 100644 --- a/plugins/keepkey/keepkey.py +++ b/plugins/keepkey/keepkey.py @@ -84,9 +84,6 @@ class KeepKeyWallet(BIP32_HD_Wallet): account_id, (change, address_index) = self.get_address_index(address) return "44'/0'/%s'/%d/%d" % (account_id, change, address_index) - def create_main_account(self, password): - self.create_account('Main account', None) #name, empty password - def mnemonic_to_seed(self, mnemonic, passphrase): # keepkey uses bip39 import pbkdf2, hashlib, hmac @@ -96,15 +93,9 @@ class KeepKeyWallet(BIP32_HD_Wallet): return pbkdf2.PBKDF2(mnemonic, 'mnemonic' + passphrase, iterations = PBKDF2_ROUNDS, macmodule = hmac, digestmodule = hashlib.sha512).read(64) def derive_xkeys(self, root, derivation, password): - x = self.master_private_keys.get(root) - if x: - root_xprv = pw_decode(x, password) - xprv, xpub = bip32_private_derivation(root_xprv, root, derivation) - return xpub, xprv - else: - derivation = derivation.replace(self.root_name,"44'/0'/") - xpub = self.get_public_key(derivation) - return xpub, None + derivation = derivation.replace(self.root_name,"44'/0'/") + xpub = self.get_public_key(derivation) + return xpub, None def get_public_key(self, bip32_path): address_n = self.plugin.get_client().expand_path(bip32_path) @@ -480,4 +471,3 @@ if KEEPKEY: raise return resp - diff --git a/plugins/ledger/ledger.py b/plugins/ledger/ledger.py index 26bb3e50..a93799fd 100644 --- a/plugins/ledger/ledger.py +++ b/plugins/ledger/ledger.py @@ -65,11 +65,6 @@ class BTChipWallet(BIP32_HD_Wallet): def can_create_accounts(self): return False - def synchronize(self): - # synchronize existing accounts - BIP32_Wallet.synchronize(self) - # no further accounts for the moment - def can_change_password(self): return False @@ -152,9 +147,6 @@ class BTChipWallet(BIP32_HD_Wallet): account_id, (change, address_index) = self.get_address_index(address) return "44'/0'/%s'/%d/%d" % (account_id, change, address_index) - def create_main_account(self, password): - self.create_account('Main account', None) #name, empty password - def derive_xkeys(self, root, derivation, password): derivation = derivation.replace(self.root_name,"44'/0'/") xpub = self.get_public_key(derivation) @@ -494,5 +486,3 @@ class LedgerPlugin(BasePlugin): self.wallet.sign_transaction(tx, None) except Exception as e: tx.error = str(e) - - diff --git a/plugins/trezor/trezor.py b/plugins/trezor/trezor.py index 57367edc..4ae22b7b 100644 --- a/plugins/trezor/trezor.py +++ b/plugins/trezor/trezor.py @@ -83,9 +83,6 @@ class TrezorWallet(BIP32_HD_Wallet): account_id, (change, address_index) = self.get_address_index(address) return "44'/0'/%s'/%d/%d" % (account_id, change, address_index) - def create_main_account(self, password): - self.create_account('Main account', None) #name, empty password - def mnemonic_to_seed(self, mnemonic, passphrase): # trezor uses bip39 import pbkdf2, hashlib, hmac @@ -95,15 +92,9 @@ class TrezorWallet(BIP32_HD_Wallet): return pbkdf2.PBKDF2(mnemonic, 'mnemonic' + passphrase, iterations = PBKDF2_ROUNDS, macmodule = hmac, digestmodule = hashlib.sha512).read(64) def derive_xkeys(self, root, derivation, password): - x = self.master_private_keys.get(root) - if x: - root_xprv = pw_decode(x, password) - xprv, xpub = bip32_private_derivation(root_xprv, root, derivation) - return xpub, xprv - else: - derivation = derivation.replace(self.root_name,"44'/0'/") - xpub = self.get_public_key(derivation) - return xpub, None + derivation = derivation.replace(self.root_name,"44'/0'/") + xpub = self.get_public_key(derivation) + return xpub, None def get_public_key(self, bip32_path): address_n = self.plugin.get_client().expand_path(bip32_path)