update trezor plugin

This commit is contained in:
ThomasV 2014-08-20 21:01:30 +02:00
parent a203dab415
commit 58e1dd2a24
3 changed files with 21 additions and 40 deletions

View File

@ -424,6 +424,8 @@ class InstallWizard(QDialog):
try: try:
wallet.create_main_account(password) wallet.create_main_account(password)
except BaseException as e: except BaseException as e:
import traceback
traceback.print_exc(file=sys.stdout)
QMessageBox.information(None, _('Error'), str(e), _('OK')) QMessageBox.information(None, _('Error'), str(e), _('OK'))
return return
self.waiting_dialog(wallet.synchronize) self.waiting_dialog(wallet.synchronize)

View File

@ -1273,18 +1273,11 @@ class BIP32_Wallet(Deterministic_Wallet):
self.master_private_keys[name] = pw_encode(xpriv, password) self.master_private_keys[name] = pw_encode(xpriv, password)
self.storage.put('master_private_keys', self.master_private_keys, True) self.storage.put('master_private_keys', self.master_private_keys, True)
def add_master_keys(self, root, derivation, password): def derive_xkeys(self, root, derivation, password):
x = self.master_private_keys.get(root) x = self.master_private_keys[root]
if x: root_xprv = pw_decode(x, password)
master_xpriv = pw_decode(x, password ) xprv, xpub = bip32_private_derivation(root_xprv, root, derivation)
xpriv, xpub = bip32_private_derivation(master_xpriv, root, derivation) return xpub, xprv
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 can_sign(self, tx): def can_sign(self, tx):
if self.is_watching_only(): if self.is_watching_only():
@ -1359,7 +1352,11 @@ class BIP32_HD_Wallet(BIP32_Wallet):
def make_account(self, account_id, password): def make_account(self, account_id, password):
"""Creates and saves the master keys, but does not save the account""" """Creates and saves the master keys, but does not save the account"""
derivation = self.root_name + "%d'"%int(account_id) 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}) account = BIP32_Account({'xpub':xpub})
return account return account

View File

@ -71,7 +71,7 @@ class Plugin(BasePlugin):
def installwizard_restore(self, wizard, storage): def installwizard_restore(self, wizard, storage):
wallet = TrezorWallet(storage) wallet = TrezorWallet(storage)
try: try:
wallet.create_accounts(None) wallet.create_main_account(None)
except BaseException as e: except BaseException as e:
QMessageBox.information(None, _('Error'), str(e), _('OK')) QMessageBox.information(None, _('Error'), str(e), _('OK'))
return return
@ -85,24 +85,13 @@ class Plugin(BasePlugin):
class TrezorWallet(NewWallet): class TrezorWallet(NewWallet):
wallet_type = 'trezor'
def __init__(self, storage): def __init__(self, storage):
NewWallet.__init__(self, storage)
self.transport = None self.transport = None
self.client = None self.client = None
self.mpk = 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 self.device_checked = False
def get_action(self): def get_action(self):
@ -121,9 +110,6 @@ class TrezorWallet(NewWallet):
def is_watching_only(self): def is_watching_only(self):
return False return False
def default_account(self):
return "44'/0'/0'"
def get_client(self): def get_client(self):
if not TREZOR: if not TREZOR:
raise Exception('please install github.com/trezor/python-trezor') raise Exception('please install github.com/trezor/python-trezor')
@ -144,21 +130,17 @@ class TrezorWallet(NewWallet):
self.proper_device = False self.proper_device = False
return self.client return self.client
def account_id(self, i):
return "44'/0'/%d'"%i
def address_id(self, address): def address_id(self, address):
account_id, (change, address_index) = self.get_address_index(address) account_id, (change, address_index) = self.get_address_index(address)
return "%s/%d/%d" % (account_id, change, address_index) return "%s/%d/%d" % (account_id, change, address_index)
def create_accounts(self, password): def create_main_account(self, password):
self.create_account('Main account', '') #name, empty password self.create_account('Main account', None) #name, empty password
def make_account(self, account_id, password): def derive_xkeys(self, root, derivation, password):
xpub = self.get_public_key(account_id) derivation = derivation.replace(self.root_name,"44'/0'/")
self.add_master_public_key(account_id, xpub) xpub = self.get_public_key(derivation)
account = BIP32_Account({'xpub':xpub}) return xpub, None
return account
def get_public_key(self, bip32_path): def get_public_key(self, bip32_path):
address_n = self.get_client().expand_path(bip32_path) address_n = self.get_client().expand_path(bip32_path)