Пример #1
0
def derive_path_cardano(root: bip32.HDNode, path: Bip32Path) -> bip32.HDNode:
    node = root.clone()
    for i in path:
        node.derive_cardano(i)
    return node
Пример #2
0
def get_address(
    script_type: InputScriptType,
    coin: CoinInfo,
    node: bip32.HDNode,
    multisig: MultisigRedeemScriptType | None = None,
) -> str:
    if multisig:
        # Ensure that our public key is included in the multisig.
        multisig_pubkey_index(multisig, node.public_key())

    if script_type in (InputScriptType.SPENDADDRESS,
                       InputScriptType.SPENDMULTISIG):
        if multisig:  # p2sh multisig
            if coin.address_type_p2sh is None:
                raise wire.ProcessError("Multisig not enabled on this coin")

            pubkeys = multisig_get_pubkeys(multisig)
            address = address_multisig_p2sh(pubkeys, multisig.m, coin)
            if coin.cashaddr_prefix is not None:
                address = address_to_cashaddr(address, coin)
            return address
        if script_type == InputScriptType.SPENDMULTISIG:
            raise wire.ProcessError("Multisig details required")

        # p2pkh
        address = node.address(coin.address_type)
        if coin.cashaddr_prefix is not None:
            address = address_to_cashaddr(address, coin)
        return address

    elif script_type == InputScriptType.SPENDWITNESS:  # native p2wpkh or native p2wsh
        if not coin.segwit or not coin.bech32_prefix:
            raise wire.ProcessError("Segwit not enabled on this coin")
        # native p2wsh multisig
        if multisig is not None:
            pubkeys = multisig_get_pubkeys(multisig)
            return address_multisig_p2wsh(pubkeys, multisig.m,
                                          coin.bech32_prefix)

        # native p2wpkh
        return address_p2wpkh(node.public_key(), coin)

    elif script_type == InputScriptType.SPENDTAPROOT:  # taproot
        if not coin.taproot or not coin.bech32_prefix:
            raise wire.ProcessError("Taproot not enabled on this coin")

        if multisig is not None:
            raise wire.ProcessError("Multisig not supported for taproot")

        return address_p2tr(node.public_key(), coin)

    elif (script_type == InputScriptType.SPENDP2SHWITNESS
          ):  # p2wpkh or p2wsh nested in p2sh
        if not coin.segwit or coin.address_type_p2sh is None:
            raise wire.ProcessError("Segwit not enabled on this coin")
        # p2wsh multisig nested in p2sh
        if multisig is not None:
            pubkeys = multisig_get_pubkeys(multisig)
            return address_multisig_p2wsh_in_p2sh(pubkeys, multisig.m, coin)

        # p2wpkh nested in p2sh
        return address_p2wpkh_in_p2sh(node.public_key(), coin)

    else:
        raise wire.ProcessError("Invalid script type")
Пример #3
0
 def __init__(self, root: bip32.HDNode) -> None:
     self.byron_root = derive_path_cardano(root, paths.BYRON_ROOT)
     self.shelley_root = derive_path_cardano(root, paths.SHELLEY_ROOT)
     self.multisig_root = derive_path_cardano(root, paths.MULTISIG_ROOT)
     self.minting_root = derive_path_cardano(root, paths.MINTING_ROOT)
     root.__del__()
Пример #4
0
def ecdsa_sign(node: bip32.HDNode, digest: bytes) -> bytes:
    sig = secp256k1.sign(node.private_key(), digest)
    sigder = der.encode_seq((sig[1:33], sig[33:65]))
    return sigder
Пример #5
0
 def __init__(self, root: bip32.HDNode) -> None:
     self.byron_root = derive_path_cardano(root, seed_namespaces.BYRON)
     self.shelley_root = derive_path_cardano(root, seed_namespaces.SHELLEY)
     root.__del__()
Пример #6
0
 def __init__(self, root: bip32.HDNode) -> None:
     self.byron_root = derive_path_cardano(root, paths.BYRON_ROOT)
     self.shelley_root = derive_path_cardano(root, paths.SHELLEY_ROOT)
     root.__del__()
Пример #7
0
def node_derive(root: bip32.HDNode, address_n: list):
    node = root.clone()
    node.derive_path(address_n)
    return node
Пример #8
0
 def _derive_path(root: bip32.HDNode, path: Bip32Path) -> bip32.HDNode:
     """Clone and derive path from the root."""
     node = root.clone()
     node.derive_path(path)
     return node
Пример #9
0
def _get_public_key(node: bip32.HDNode) -> Tuple[str, bytes]:
    seckey = node.private_key()
    public_key = secp256k1.publickey(seckey, True)
    wif = public_key_to_wif(public_key)
    return wif, public_key
Пример #10
0
def _get_address_root(node: bip32.HDNode, address_attributes: dict) -> bytes:
    extpubkey = remove_ed25519_prefix(node.public_key()) + node.chain_code()
    return _address_hash([0, [0, extpubkey], address_attributes])
Пример #11
0
def bip340_sign(node: bip32.HDNode, digest: bytes) -> bytes:
    internal_private_key = node.private_key()
    output_private_key = bip340.tweak_secret_key(internal_private_key)
    return bip340.sign(output_private_key, digest)
Пример #12
0
def _encrypt(node: bip32.HDNode, public_key: bytes, payload: bytes) -> bytes:
    salt = random.bytes(NEM_SALT_SIZE)
    iv = random.bytes(AES_BLOCK_SIZE)
    encrypted = node.nem_encrypt(public_key, iv, salt, payload)
    return iv + salt + encrypted