Ejemplo n.º 1
0
 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
     # 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 = bitcoin.hash_160(publicKey)
         fingerprint = unpack(">I", h[0:4])[0]
     nodeData = self.dongleObject.getWalletPublicKey(bip32_path)
     publicKey = 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])
     xpub = bitcoin.serialize_xpub(xtype, nodeData['chainCode'], publicKey,
                                   depth, self.i4b(fingerprint),
                                   self.i4b(childnum))
     return xpub
Ejemplo n.º 2
0
    def get_xpub(self, bip32_path, xtype):
        assert xtype in SatochipPlugin.SUPPORTED_XTYPES
       
        try:
            # needs PIN
            self.cc.card_verify_PIN()
            
            # bip32_path is of the form 44'/0'/1'
            self.print_error("[get_xpub(): bip32_path = ", bip32_path)#debugSatochip
            (depth, bytepath)= bip32path2bytes(bip32_path)
            (childkey, childchaincode)= self.cc.card_bip32_get_extendedkey(bytepath)

            if depth == 0: #masterkey
                fingerprint= bytes([0,0,0,0])
                child_number= bytes([0,0,0,0])
            else: #get parent info
                (parentkey, parentchaincode)= self.cc.card_bip32_get_extendedkey(bytepath[0:-4])
                fingerprint= hash_160(parentkey.get_public_key_bytes(compressed=True))[0:4]
                child_number= bytepath[-4:]
            #xpub= serialize_xpub('standard', childchaincode, childkey.get_public_key_bytes(compressed=True), depth, fingerprint, child_number)
            xpub= serialize_xpub(xtype, childchaincode, childkey.get_public_key_bytes(compressed=True), depth, fingerprint, child_number)
            self.print_error("SatochipClient: get_xpub(): xpub=", xpub)#debugSatochip
            return xpub
            # return BIP32Node(xtype=xtype,
                                 # eckey=childkey,
                                 # chaincode=childchaincode,
                                 # depth=depth,
                                 # fingerprint=fingerprint,
                                 # child_number=child_number).to_xpub() 
        except Exception as e:
            self.print_error(repr(e))
            return None
Ejemplo n.º 3
0
    def get_xpub(self, bip32_path, xtype):
        assert xtype in SatochipPlugin.SUPPORTED_XTYPES

        try:
            hex_authentikey = self.handler.win.wallet.storage.get(
                'authentikey')
            self.print_error(
                "get_xpub(): self.handler.win.wallet.storage.authentikey:",
                hex_authentikey)  #debugSatochip
            if hex_authentikey is not None:
                self.cc.parser.authentikey_from_storage = ECPubkey(
                    bytes.fromhex(hex_authentikey))
        except Exception as e:  #attributeError?
            self.print_error(
                "get_xpub(): exception when getting authentikey from self.handler.win.wallet.storage:",
                str(e))  #debugSatochip

        try:
            # needs PIN
            self.cc.card_verify_PIN()

            # bip32_path is of the form 44'/0'/1'
            self.print_error("[get_xpub(): bip32_path = ",
                             bip32_path)  #debugSatochip
            (depth, bytepath) = bip32path2bytes(bip32_path)
            (childkey,
             childchaincode) = self.cc.card_bip32_get_extendedkey(bytepath)

            if depth == 0:  #masterkey
                fingerprint = bytes([0, 0, 0, 0])
                child_number = bytes([0, 0, 0, 0])
            else:  #get parent info
                (parentkey,
                 parentchaincode) = self.cc.card_bip32_get_extendedkey(
                     bytepath[0:-4])
                fingerprint = hash_160(
                    parentkey.get_public_key_bytes(compressed=True))[0:4]
                child_number = bytepath[-4:]
            #xpub= serialize_xpub('standard', childchaincode, childkey.get_public_key_bytes(compressed=True), depth, fingerprint, child_number)
            xpub = serialize_xpub(
                xtype, childchaincode,
                childkey.get_public_key_bytes(compressed=True), depth,
                fingerprint, child_number)
            self.print_error("SatochipClient: get_xpub(): xpub=",
                             xpub)  #debugSatochip
            return xpub
            # return BIP32Node(xtype=xtype,
            # eckey=childkey,
            # chaincode=childchaincode,
            # depth=depth,
            # fingerprint=fingerprint,
            # child_number=child_number).to_xpub()
        except Exception as e:
            self.print_error(repr(e))
            return None
Ejemplo n.º 4
0
def tx_from_components(all_components, session_hash):
    """ Returns the tx and a list of indices matching inputs with components"""
    input_indices = []
    assert len(session_hash) == 32
    if Protocol.FUSE_ID is None:
        prefix = []
    else:
        assert len(Protocol.FUSE_ID) == 4
        prefix = [4, *Protocol.FUSE_ID]
    inputs = []
    outputs = [
        (TYPE_SCRIPT,
         ScriptOutput(bytes([OpCodes.OP_RETURN, *prefix, 32]) + session_hash),
         0)
    ]
    for i, compser in enumerate(all_components):
        comp = pb.Component()
        comp.ParseFromString(compser)
        ctype = comp.WhichOneof('component')
        if ctype == 'input':
            inp = comp.input
            if len(inp.prev_txid) != 32:
                raise FusionError("bad component prevout")
            inputs.append(
                dict(address=Address.from_P2PKH_hash(hash_160(inp.pubkey)),
                     prevout_hash=inp.prev_txid[::-1].hex(),
                     prevout_n=inp.prev_index,
                     num_sig=1,
                     signatures=[None],
                     type='p2pkh',
                     x_pubkeys=[inp.pubkey.hex()],
                     pubkeys=[inp.pubkey.hex()],
                     sequence=0xffffffff,
                     value=inp.amount))
            input_indices.append(i)
        elif ctype == 'output':
            out = comp.output
            atype, addr = get_address_from_output_script(out.scriptpubkey)
            if atype != TYPE_ADDRESS:
                raise FusionError("bad component address")
            outputs.append((TYPE_ADDRESS, addr, out.amount))
        elif ctype != 'blank':
            raise FusionError("bad component")
    tx = Transaction.from_io(inputs, outputs, locktime=0, sign_schnorr=True)
    tx.version = 1
    return tx, input_indices
Ejemplo n.º 5
0
    def get_xpub(self, bip32_path, xtype):
        assert xtype in SatochipPlugin.SUPPORTED_XTYPES

        try:
            hex_authentikey = self.handler.win.wallet.storage.get(
                'authentikey')
            print_error(
                "[satochip] SatochipClient: get_xpub(): self.handler.win.wallet.storage.authentikey:"
                + str(hex_authentikey))  #debugSatochip
            if hex_authentikey is not None:
                self.parser.authentikey_from_storage = ECPubkey(
                    bytes.fromhex(hex_authentikey))
        except Exception as e:  #attributeError?
            print_error(
                "[satochip] SatochipClient: get_xpub(): exception when getting authentikey from self.handler.win.wallet.storage:"
                + str(e))  #debugSatochip

        # bip32_path is of the form 44'/0'/1'
        print_error("[satochip] SatochipClient: get_xpub(): bip32_path=" +
                    bip32_path)  #debugSatochip
        (depth, bytepath) = bip32path2bytes(bip32_path)
        (childkey,
         childchaincode) = self.cc.card_bip32_get_extendedkey(bytepath)
        #print_error("[satochip] SatochipClient: get_xpub(): depth="+str(depth))#debugSatochip
        if depth == 0:  #masterkey
            fingerprint = bytes([0, 0, 0, 0])
            child_number = bytes([0, 0, 0, 0])
        else:  #get parent info
            #print_error("[satochip] SatochipClient: get_xpub(): get xpub for parent")#debugSatochip
            (parentkey, parentchaincode) = self.cc.card_bip32_get_extendedkey(
                bytepath[0:-4])
            fingerprint = hash_160(
                parentkey.get_public_key_bytes(compressed=True))[0:4]
            child_number = bytepath[-4:]
        #xpub= serialize_xpub('standard', childchaincode, childkey.get_public_key_bytes(compressed=True), depth, fingerprint, child_number)
        xpub = serialize_xpub(xtype, childchaincode,
                              childkey.get_public_key_bytes(compressed=True),
                              depth, fingerprint, child_number)
        print_error("[satochip] SatochipClient: get_xpub(): xpub=" +
                    str(xpub))  #debugSatochip
        return xpub