Example #1
0
    def get_master_public_key(self, bip32_path):
        self.checkDevice()
        # bip32_path is of the form 44'/0'/1'
        # S-L-O-W - we don't handle the fingerprint directly, so compute
        # it manually from the previous node
        # This only happens once so it's bearable
        #self.get_client() # prompt for the PIN before displaying the dialog if necessary
        #self.handler.show_message("Computing master public key")
        splitPath = bip32_path.split('/')
        if splitPath[0] == 'm':
            splitPath = splitPath[1:]
            bip32_path = bip32_path[2:]
        fingerprint = 0
        if len(splitPath) > 1:
            prevPath = "/".join(splitPath[0:len(splitPath) - 1])
            nodeData = self.dongleObject.getWalletPublicKey(prevPath)
            publicKey = compress_public_key(nodeData['publicKey'])
            h = hashlib.new('ripemd160')
            h.update(hashlib.sha256(publicKey).digest())
            fingerprint = unpack(">I", h.digest()[0:4])[0]
        nodeData = self.dongleObject.getWalletPublicKey(bip32_path)
        publicKey = bytes(compress_public_key(nodeData['publicKey']))
        depth = len(splitPath)
        lastChild = splitPath[len(splitPath) - 1].split('\'')
        childnum = int(lastChild[0]) if len(
            lastChild) == 1 else 0x80000000 | int(lastChild[0])

        derivation = BIP32Derivation(
            chain_code=nodeData['chainCode'],
            depth=depth,
            parent_fingerprint=pack_be_uint32(fingerprint),
            n=childnum)
        return BIP32PublicKey(PublicKey.from_bytes(publicKey), derivation,
                              Net.COIN)
Example #2
0
 def get_master_public_key(self, bip32_path, creating=False):
     address_n = bip32_decompose_chain_string(bip32_path)
     with self.run_flow(creating_wallet=creating):
         node = trezorlib.btc.get_public_node(self.client, address_n).node
     self.used()
     derivation = BIP32Derivation(chain_code=node.chain_code,
                                  depth=node.depth,
                                  parent_fingerprint=pack_be_uint32(
                                      node.fingerprint),
                                  n=node.child_num)
     return BIP32PublicKey(PublicKey.from_bytes(node.public_key),
                           derivation, Net.COIN)
Example #3
0
 def get_master_public_key(self, bip32_path):
     address_n = bip32_decompose_chain_string(bip32_path)
     creating = False
     node = self.get_public_node(address_n, creating).node
     self.used()
     derivation = BIP32Derivation(chain_code=node.chain_code,
                                  depth=node.depth,
                                  parent_fingerprint=pack_be_uint32(
                                      node.fingerprint),
                                  n=node.child_num)
     return BIP32PublicKey(PublicKey.from_bytes(node.public_key),
                           derivation, Net.COIN)
Example #4
0
 def get_master_public_key(self,
                           bip32_path: str,
                           creating: bool = False) -> BIP32PublicKey:
     address_n = bip32_decompose_chain_string(bip32_path)
     # This will be cleared by the wrapper around `get_public_node`.
     self.creating_wallet = creating
     node = self.get_public_node(address_n).node
     self.used()
     derivation = BIP32Derivation(chain_code=node.chain_code,
                                  depth=node.depth,
                                  parent_fingerprint=pack_be_uint32(
                                      node.fingerprint),
                                  n=node.child_num)
     return BIP32PublicKey(PublicKey.from_bytes(node.public_key),
                           derivation, Net.COIN)
Example #5
0
from electrumsv.app_state import app_state
from electrumsv.device import Device
from electrumsv.exceptions import UserCancelled
from electrumsv.i18n import _
from electrumsv.keystore import Hardware_KeyStore
from electrumsv.logs import logs
from electrumsv.networks import Net
from electrumsv.transaction import classify_tx_output
from electrumsv.util import bfh

from ..hw_wallet import HW_PluginBase

# TREZOR initialization methods
TIM_NEW, TIM_RECOVER, TIM_MNEMONIC, TIM_PRIVKEY = range(0, 4)
KEEPKEY_PRODUCT_KEY = 'KeepKey'
NULL_DERIVATION = BIP32Derivation(chain_code=bytes(32), n=0, depth=0, parent_fingerprint=bytes(4))


class KeepKey_KeyStore(Hardware_KeyStore):
    hw_type = 'keepkey'
    device = KEEPKEY_PRODUCT_KEY

    def get_derivation(self):
        return self.derivation

    def get_client(self, force_pair=True):
        return self.plugin.get_client(self, force_pair)

    def decrypt_message(self, sequence, message, password):
        raise RuntimeError(_('Encryption and decryption are not implemented by {}').format(
            self.device))