Exemplo n.º 1
0
 def f(x_pubkey):
     if is_extended_pubkey(x_pubkey):
         xpub, s = BIP32_Account.parse_xpubkey(x_pubkey)
     else:
         xpub = xpub_from_pubkey(x_pubkey.decode('hex'))
         s = []
     node = ckd_public.deserialize(xpub)
     return types.HDNodePathType(node=node, address_n=s)
Exemplo n.º 2
0
 def f(x_pubkey):
     if x_pubkey.is_bip32_key():
         xpub, path = x_pubkey.bip32_extended_key_and_path()
     else:
         xpub = BIP32PublicKey(x_pubkey.to_public_key(),
                               NULL_DERIVATION, Net.COIN)
         xpub = xpub.to_extended_key_string()
         path = []
     node = keepkeylib.ckd_public.deserialize(xpub)
     return types.HDNodePathType(node=node, address_n=path)
Exemplo n.º 3
0
    def tx_outputs(self, keystore: KeepKey_KeyStore, derivation: str,
                   tx: Transaction):
        has_change = False
        account_derivation = tuple(bip32_decompose_chain_string(derivation))
        keystore_fingerprint = keystore.get_fingerprint()

        outputs = []
        assert tx.output_info is not None
        for tx_output, output_metadatas in zip(tx.outputs, tx.output_info):
            info = output_metadatas.get(keystore_fingerprint)
            if info is not None and not has_change:
                has_change = True  # no more than one change address
                key_derivation, xpubs, m = info
                if len(xpubs) == 1:
                    script_type = types.PAYTOADDRESS
                    txoutputtype = types.TxOutputType(
                        amount=tx_output.value,
                        script_type=script_type,
                        address_n=account_derivation + key_derivation,
                    )
                else:
                    script_type = types.PAYTOMULTISIG
                    nodes = [
                        keepkeylib.ckd_public.deserialize(xpub)
                        for xpub in xpubs
                    ]
                    pubkeys = [
                        types.HDNodePathType(node=node,
                                             address_n=key_derivation)
                        for node in nodes
                    ]
                    multisig = types.MultisigRedeemScriptType(
                        pubkeys=pubkeys, signatures=[b''] * len(pubkeys), m=m)
                    txoutputtype = types.TxOutputType(
                        multisig=multisig,
                        amount=tx_output.value,
                        address_n=account_derivation + key_derivation,
                        script_type=script_type)
            else:
                txoutputtype = types.TxOutputType()
                txoutputtype.amount = tx_output.value
                address = classify_tx_output(tx_output)
                if isinstance(address, Address):
                    txoutputtype.script_type = types.PAYTOADDRESS
                    txoutputtype.address = address.to_string()

            outputs.append(txoutputtype)

        return outputs