1
0

hardware wallets: pass xtype to get_xpub

This commit is contained in:
ThomasV
2017-10-31 11:45:25 +01:00
parent 1ecfcea8dc
commit f36024e216
8 changed files with 26 additions and 34 deletions

View File

@@ -84,7 +84,8 @@ class DigitalBitbox_Client():
return self.hid_send_encrypt(b'{"xpub": "%s"}' % bip32_path.encode('utf8'))
def get_xpub(self, bip32_path):
def get_xpub(self, bip32_path, xtype):
assert xpub == 'standard'
reply = self._get_xpub(bip32_path)
if reply:
return reply['xpub']
@@ -646,7 +647,7 @@ class DigitalBitboxPlugin(HW_PluginBase):
client = devmgr.client_by_id(device_id)
client.handler = self.create_handler(wizard)
client.setupRunning = True
client.get_xpub("m/44'/0'")
client.get_xpub("m/44'/0'", 'standard')
def is_mobile_paired(self):
@@ -667,12 +668,12 @@ class DigitalBitboxPlugin(HW_PluginBase):
self.handler.show_error(str(e))
def get_xpub(self, device_id, derivation, wizard):
def get_xpub(self, device_id, derivation, xtype, wizard):
devmgr = self.device_manager()
client = devmgr.client_by_id(device_id)
client.handler = self.create_handler(wizard)
client.check_device_dialog()
xpub = client.get_xpub(derivation)
xpub = client.get_xpub(derivation, xtype)
return xpub

View File

@@ -51,7 +51,7 @@ class Ledger_Client():
def i4b(self, x):
return pack('>I', x)
def get_xpub(self, bip32_path):
def get_xpub(self, bip32_path, xtype):
self.checkDevice()
# bip32_path is of the form 44'/0'/1'
# S-L-O-W - we don't handle the fingerprint directly, so compute
@@ -60,14 +60,11 @@ class Ledger_Client():
#self.get_client() # prompt for the PIN before displaying the dialog if necessary
#self.handler.show_message("Computing master public key")
try:
if (os.getenv("LEDGER_NATIVE_SEGWIT") is not None) and self.supports_native_segwit():
xtype = 'p2wpkh'
elif bip32_path.startswith("m/49'/"):
if not self.supports_segwit():
raise Exception("Firmware version too old for Segwit support. Please update at https://www.ledgerwallet.com")
xtype = 'p2wpkh-p2sh'
else:
xtype = 'standard'
if xtype in ['p2wpkh', 'p2wsh'] and not nelf.supports_native_segwit():
raise Exception("Firmware version too old for Segwit support. Please update at https://www.ledgerwallet.com")
if xtype in ['p2wpkh-p2sh', 'p2wsh-p2sh'] and not self.supports_segwit():
raise Exception("Firmware version too old for Segwit support. Please update at https://www.ledgerwallet.com")
splitPath = bip32_path.split('/')
if splitPath[0] == 'm':
splitPath = splitPath[1:]
@@ -493,18 +490,15 @@ class LedgerPlugin(HW_PluginBase):
devmgr = self.device_manager()
device_id = device_info.device.id_
client = devmgr.client_by_id(device_id)
#client.handler = wizard
client.handler = self.create_handler(wizard)
#client.get_xpub('m')
client.get_xpub("m/44'/0'") # TODO replace by direct derivation once Nano S > 1.1
client.get_xpub("m/44'/0'", 'standard') # TODO replace by direct derivation once Nano S > 1.1
def get_xpub(self, device_id, derivation, wizard):
def get_xpub(self, device_id, derivation, xtype, wizard):
devmgr = self.device_manager()
client = devmgr.client_by_id(device_id)
#client.handler = wizard
client.handler = self.create_handler(wizard)
client.checkDevice()
xpub = client.get_xpub(derivation)
xpub = client.get_xpub(derivation, xtype)
return xpub
def get_client(self, keystore, force_pair=True):

View File

@@ -147,16 +147,12 @@ class TrezorClientBase(GuiMixin, PrintError):
def i4b(self, x):
return pack('>I', x)
def get_xpub(self, bip32_path):
def get_xpub(self, bip32_path, xtype):
address_n = self.expand_path(bip32_path)
creating = False #self.next_account_number() == 0
creating = False
node = self.get_public_node(address_n, creating).node
xtype = 'p2wpkh-p2sh' if bip32_path.startswith("m/49'/") else 'standard'
return serialize_xpub(xtype, node.chain_code, node.public_key, node.depth, self.i4b(node.fingerprint), self.i4b(node.child_num))
#def address_from_derivation(self, derivation):
# return self.get_address('Bitcoin', self.expand_path(derivation))
def toggle_passphrase(self):
if self.features.passphrase_protection:
self.msg = _("Confirm on your %s device to disable passphrases")

View File

@@ -220,14 +220,14 @@ class TrezorCompatiblePlugin(HW_PluginBase):
client.handler = self.create_handler(wizard)
if not device_info.initialized:
self.initialize_device(device_id, wizard, client.handler)
client.get_xpub('m')
client.get_xpub('m', 'standard')
client.used()
def get_xpub(self, device_id, derivation, wizard):
def get_xpub(self, device_id, derivation, xtype, wizard):
devmgr = self.device_manager()
client = devmgr.client_by_id(device_id)
client.handler = wizard
xpub = client.get_xpub(derivation)
xpub = client.get_xpub(derivation, xtype)
client.used()
return xpub