URI: 
       ttrezor: do not rely on deprecated ckd_public (#4416) - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 208606beda445c243620727c68ad19b85e47ada2
   DIR parent c6fce4b7ccb6bcd697889aed4ef90157b9f46a2a
  HTML Author: matejcik <matejcik@gmail.com>
       Date:   Fri,  8 Jun 2018 17:07:49 +0200
       
       ttrezor: do not rely on deprecated ckd_public (#4416)
       
       
       Diffstat:
         M plugins/trezor/trezor.py            |      26 ++++++++++++++++----------
       
       1 file changed, 16 insertions(+), 10 deletions(-)
       ---
   DIR diff --git a/plugins/trezor/trezor.py b/plugins/trezor/trezor.py
       t@@ -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 _
       t@@ -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'
       t@@ -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',)
        
       t@@ -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_
       t@@ -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)))
       t@@ -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,
       t@@ -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),