trezor: do not rely on deprecated ckd_public (#4416)
This commit is contained in:
@@ -3,7 +3,7 @@ import traceback
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from electrum.util import bfh, bh2u, versiontuple, UserCancelled
|
from electrum.util import bfh, bh2u, versiontuple, UserCancelled
|
||||||
from electrum.bitcoin import (b58_address_to_hash160, xpub_from_pubkey,
|
from electrum.bitcoin import (b58_address_to_hash160, xpub_from_pubkey, deserialize_xpub,
|
||||||
TYPE_ADDRESS, TYPE_SCRIPT, is_address)
|
TYPE_ADDRESS, TYPE_SCRIPT, is_address)
|
||||||
from electrum import constants
|
from electrum import constants
|
||||||
from electrum.i18n import _
|
from electrum.i18n import _
|
||||||
@@ -80,7 +80,7 @@ class TrezorPlugin(HW_PluginBase):
|
|||||||
#
|
#
|
||||||
# class-static variables: client_class, firmware_URL, handler_class,
|
# class-static variables: client_class, firmware_URL, handler_class,
|
||||||
# libraries_available, libraries_URL, minimum_firmware,
|
# libraries_available, libraries_URL, minimum_firmware,
|
||||||
# wallet_class, ckd_public, types
|
# wallet_class, types
|
||||||
|
|
||||||
firmware_URL = 'https://wallet.trezor.io'
|
firmware_URL = 'https://wallet.trezor.io'
|
||||||
libraries_URL = 'https://github.com/trezor/python-trezor'
|
libraries_URL = 'https://github.com/trezor/python-trezor'
|
||||||
@@ -117,10 +117,8 @@ class TrezorPlugin(HW_PluginBase):
|
|||||||
|
|
||||||
from . import client
|
from . import client
|
||||||
from . import transport
|
from . import transport
|
||||||
import trezorlib.ckd_public
|
|
||||||
import trezorlib.messages
|
import trezorlib.messages
|
||||||
self.client_class = client.TrezorClient
|
self.client_class = client.TrezorClient
|
||||||
self.ckd_public = trezorlib.ckd_public
|
|
||||||
self.types = trezorlib.messages
|
self.types = trezorlib.messages
|
||||||
self.DEVICE_IDS = ('TREZOR',)
|
self.DEVICE_IDS = ('TREZOR',)
|
||||||
|
|
||||||
@@ -268,6 +266,17 @@ class TrezorPlugin(HW_PluginBase):
|
|||||||
client.load_device_by_xprv(item, pin, passphrase_protection,
|
client.load_device_by_xprv(item, pin, passphrase_protection,
|
||||||
label, language)
|
label, language)
|
||||||
|
|
||||||
|
def _make_node_path(self, xpub, address_n):
|
||||||
|
_, depth, fingerprint, child_num, chain_code, key = deserialize_xpub(xpub)
|
||||||
|
node = self.types.HDNodeType(
|
||||||
|
depth=depth,
|
||||||
|
fingerprint=int.from_bytes(fingerprint, 'big'),
|
||||||
|
child_num=int.from_bytes(child_num, 'big'),
|
||||||
|
chain_code=chain_code,
|
||||||
|
public_key=key,
|
||||||
|
)
|
||||||
|
return self.types.HDNodePathType(node=node, address_n=address_n)
|
||||||
|
|
||||||
def setup_device(self, device_info, wizard, purpose):
|
def setup_device(self, device_info, wizard, purpose):
|
||||||
devmgr = self.device_manager()
|
devmgr = self.device_manager()
|
||||||
device_id = device_info.device.id_
|
device_id = device_info.device.id_
|
||||||
@@ -333,8 +342,7 @@ class TrezorPlugin(HW_PluginBase):
|
|||||||
client.get_address(self.get_coin_name(), address_n, True, script_type=script_type)
|
client.get_address(self.get_coin_name(), address_n, True, script_type=script_type)
|
||||||
else:
|
else:
|
||||||
def f(xpub):
|
def f(xpub):
|
||||||
node = self.ckd_public.deserialize(xpub)
|
return self._make_node_path(xpub, [change, index])
|
||||||
return self.types.HDNodePathType(node=node, address_n=[change, index])
|
|
||||||
pubkeys = wallet.get_public_keys(address)
|
pubkeys = wallet.get_public_keys(address)
|
||||||
# sort xpubs using the order of pubkeys
|
# sort xpubs using the order of pubkeys
|
||||||
sorted_pubkeys, sorted_xpubs = zip(*sorted(zip(pubkeys, xpubs)))
|
sorted_pubkeys, sorted_xpubs = zip(*sorted(zip(pubkeys, xpubs)))
|
||||||
@@ -371,8 +379,7 @@ class TrezorPlugin(HW_PluginBase):
|
|||||||
else:
|
else:
|
||||||
xpub = xpub_from_pubkey(0, bfh(x_pubkey))
|
xpub = xpub_from_pubkey(0, bfh(x_pubkey))
|
||||||
s = []
|
s = []
|
||||||
node = self.ckd_public.deserialize(xpub)
|
return self._make_node_path(xpub, s)
|
||||||
return self.types.HDNodePathType(node=node, address_n=s)
|
|
||||||
pubkeys = list(map(f, x_pubkeys))
|
pubkeys = list(map(f, x_pubkeys))
|
||||||
multisig = self.types.MultisigRedeemScriptType(
|
multisig = self.types.MultisigRedeemScriptType(
|
||||||
pubkeys=pubkeys,
|
pubkeys=pubkeys,
|
||||||
@@ -436,8 +443,7 @@ class TrezorPlugin(HW_PluginBase):
|
|||||||
else:
|
else:
|
||||||
script_type = self.types.OutputScriptType.PAYTOMULTISIG
|
script_type = self.types.OutputScriptType.PAYTOMULTISIG
|
||||||
address_n = self.client_class.expand_path("/%d/%d" % index)
|
address_n = self.client_class.expand_path("/%d/%d" % index)
|
||||||
nodes = map(self.ckd_public.deserialize, xpubs)
|
pubkeys = [self._make_node_path(xpub, address_n) for xpub in xpubs]
|
||||||
pubkeys = [self.types.HDNodePathType(node=node, address_n=address_n) for node in nodes]
|
|
||||||
multisig = self.types.MultisigRedeemScriptType(
|
multisig = self.types.MultisigRedeemScriptType(
|
||||||
pubkeys=pubkeys,
|
pubkeys=pubkeys,
|
||||||
signatures=[b''] * len(pubkeys),
|
signatures=[b''] * len(pubkeys),
|
||||||
|
|||||||
Reference in New Issue
Block a user