|
|
@ -3,7 +3,7 @@ import traceback |
|
|
|
import sys |
|
|
|
|
|
|
|
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) |
|
|
|
from electrum import constants |
|
|
|
from electrum.i18n import _ |
|
|
@ -80,7 +80,7 @@ class TrezorPlugin(HW_PluginBase): |
|
|
|
# |
|
|
|
# class-static variables: client_class, firmware_URL, handler_class, |
|
|
|
# libraries_available, libraries_URL, minimum_firmware, |
|
|
|
# wallet_class, ckd_public, types |
|
|
|
# wallet_class, types |
|
|
|
|
|
|
|
firmware_URL = 'https://wallet.trezor.io' |
|
|
|
libraries_URL = 'https://github.com/trezor/python-trezor' |
|
|
@ -117,10 +117,8 @@ class TrezorPlugin(HW_PluginBase): |
|
|
|
|
|
|
|
from . import client |
|
|
|
from . import transport |
|
|
|
import trezorlib.ckd_public |
|
|
|
import trezorlib.messages |
|
|
|
self.client_class = client.TrezorClient |
|
|
|
self.ckd_public = trezorlib.ckd_public |
|
|
|
self.types = trezorlib.messages |
|
|
|
self.DEVICE_IDS = ('TREZOR',) |
|
|
|
|
|
|
@ -268,6 +266,17 @@ class TrezorPlugin(HW_PluginBase): |
|
|
|
client.load_device_by_xprv(item, pin, passphrase_protection, |
|
|
|
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): |
|
|
|
devmgr = self.device_manager() |
|
|
|
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) |
|
|
|
else: |
|
|
|
def f(xpub): |
|
|
|
node = self.ckd_public.deserialize(xpub) |
|
|
|
return self.types.HDNodePathType(node=node, address_n=[change, index]) |
|
|
|
return self._make_node_path(xpub, [change, index]) |
|
|
|
pubkeys = wallet.get_public_keys(address) |
|
|
|
# sort xpubs using the order of pubkeys |
|
|
|
sorted_pubkeys, sorted_xpubs = zip(*sorted(zip(pubkeys, xpubs))) |
|
|
@ -371,8 +379,7 @@ class TrezorPlugin(HW_PluginBase): |
|
|
|
else: |
|
|
|
xpub = xpub_from_pubkey(0, bfh(x_pubkey)) |
|
|
|
s = [] |
|
|
|
node = self.ckd_public.deserialize(xpub) |
|
|
|
return self.types.HDNodePathType(node=node, address_n=s) |
|
|
|
return self._make_node_path(xpub, s) |
|
|
|
pubkeys = list(map(f, x_pubkeys)) |
|
|
|
multisig = self.types.MultisigRedeemScriptType( |
|
|
|
pubkeys=pubkeys, |
|
|
@ -436,8 +443,7 @@ class TrezorPlugin(HW_PluginBase): |
|
|
|
else: |
|
|
|
script_type = self.types.OutputScriptType.PAYTOMULTISIG |
|
|
|
address_n = self.client_class.expand_path("/%d/%d" % index) |
|
|
|
nodes = map(self.ckd_public.deserialize, xpubs) |
|
|
|
pubkeys = [self.types.HDNodePathType(node=node, address_n=address_n) for node in nodes] |
|
|
|
pubkeys = [self._make_node_path(xpub, address_n) for xpub in xpubs] |
|
|
|
multisig = self.types.MultisigRedeemScriptType( |
|
|
|
pubkeys=pubkeys, |
|
|
|
signatures=[b''] * len(pubkeys), |
|
|
|