electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 58e1dd2a247df4151a17d84c34e5c1900612375a
parent a203dab4152b00b48ca1bf744b671a0c4a1e055a
Author: ThomasV <thomasv@gitorious>
Date:   Wed, 20 Aug 2014 21:01:30 +0200

update trezor plugin

Diffstat:
Mgui/qt/installwizard.py | 2++
Mlib/wallet.py | 23++++++++++-------------
Mplugins/trezor.py | 36+++++++++---------------------------
3 files changed, 21 insertions(+), 40 deletions(-)

diff --git a/gui/qt/installwizard.py b/gui/qt/installwizard.py @@ -424,6 +424,8 @@ class InstallWizard(QDialog): try: wallet.create_main_account(password) except BaseException as e: + import traceback + traceback.print_exc(file=sys.stdout) QMessageBox.information(None, _('Error'), str(e), _('OK')) return self.waiting_dialog(wallet.synchronize) diff --git a/lib/wallet.py b/lib/wallet.py @@ -1273,18 +1273,11 @@ class BIP32_Wallet(Deterministic_Wallet): self.master_private_keys[name] = pw_encode(xpriv, password) self.storage.put('master_private_keys', self.master_private_keys, True) - def add_master_keys(self, root, derivation, password): - x = self.master_private_keys.get(root) - if x: - master_xpriv = pw_decode(x, password ) - xpriv, xpub = bip32_private_derivation(master_xpriv, root, derivation) - self.add_master_public_key(derivation, xpub) - self.add_master_private_key(derivation, xpriv, password) - else: - master_xpub = self.master_public_keys[root] - xpub = bip32_public_derivation(master_xpub, root, derivation) - self.add_master_public_key(derivation, xpub) - return xpub + def derive_xkeys(self, root, derivation, password): + x = self.master_private_keys[root] + root_xprv = pw_decode(x, password) + xprv, xpub = bip32_private_derivation(root_xprv, root, derivation) + return xpub, xprv def can_sign(self, tx): if self.is_watching_only(): @@ -1359,7 +1352,11 @@ class BIP32_HD_Wallet(BIP32_Wallet): def make_account(self, account_id, password): """Creates and saves the master keys, but does not save the account""" derivation = self.root_name + "%d'"%int(account_id) - xpub = self.add_master_keys(self.root_name, derivation, password) + xpub, xprv = self.derive_xkeys(self.root_name, derivation, password) + self.add_master_public_key(derivation, xpub) + if xprv: + self.add_master_private_key(derivation, xprv, password) + account = BIP32_Account({'xpub':xpub}) return account diff --git a/plugins/trezor.py b/plugins/trezor.py @@ -71,7 +71,7 @@ class Plugin(BasePlugin): def installwizard_restore(self, wizard, storage): wallet = TrezorWallet(storage) try: - wallet.create_accounts(None) + wallet.create_main_account(None) except BaseException as e: QMessageBox.information(None, _('Error'), str(e), _('OK')) return @@ -85,24 +85,13 @@ class Plugin(BasePlugin): class TrezorWallet(NewWallet): + wallet_type = 'trezor' def __init__(self, storage): + NewWallet.__init__(self, storage) self.transport = None self.client = None self.mpk = None - - NewWallet.__init__(self, storage) - - self.seed = 'trezor' - - self.storage.put('gap_limit', 20, False) #obey BIP44 gap limit of 20 - - self.use_encryption = False - - self.storage.put('seed', self.seed, False) - self.storage.put('seed_version', self.seed_version, False) - self.storage.put('use_encryption', self.use_encryption, False) - self.device_checked = False def get_action(self): @@ -121,9 +110,6 @@ class TrezorWallet(NewWallet): def is_watching_only(self): return False - def default_account(self): - return "44'/0'/0'" - def get_client(self): if not TREZOR: raise Exception('please install github.com/trezor/python-trezor') @@ -144,21 +130,17 @@ class TrezorWallet(NewWallet): self.proper_device = False return self.client - def account_id(self, i): - return "44'/0'/%d'"%i - def address_id(self, address): account_id, (change, address_index) = self.get_address_index(address) return "%s/%d/%d" % (account_id, change, address_index) - def create_accounts(self, password): - self.create_account('Main account', '') #name, empty password + def create_main_account(self, password): + self.create_account('Main account', None) #name, empty password - def make_account(self, account_id, password): - xpub = self.get_public_key(account_id) - self.add_master_public_key(account_id, xpub) - account = BIP32_Account({'xpub':xpub}) - return account + def derive_xkeys(self, root, derivation, password): + 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.get_client().expand_path(bip32_path)