cashscript_py.helpers.address module

Utility functions for address computations, conversions, and transformations.

public_key_to_cash_address(public_key: bytes, network: Network, address_type: LockingBytecodeType = LockingBytecodeType.P2PKH, token_aware: bool = False) str[source]

Convert a public key to a CashAddress.

Parameters:
  • public_key – Raw public key (compressed or uncompressed).

  • network – Target network.

  • address_type – Address type (default P2PKH).

  • token_aware – If True, uses token-aware address version.

Returns:

CashAddress string.

public_key_to_p2pkh_locking_bytecode(public_key: bytes) bytes[source]

Build a standard P2PKH locking bytecode from a public key.

Parameters:

public_key – Raw public key (compressed or uncompressed).

Returns:

P2PKH locking bytecode.

public_key_to_pkh(public_key: bytes) bytes[source]

Return the HASH160 of a public key (pkh).

script_to_address(script: list[bytes | int], network: Network, address_type: LockingBytecodeType, token_aware: bool = False) str[source]

Convert a script to a CashAddress for the given network/type.

Parameters:
  • script – Script list to encode.

  • network – Target network.

  • address_type – Locking bytecode type (P2SH20/P2SH32/P2PKH/P2PK).

  • token_aware – If True, encode token-aware address version.

Returns:

CashAddress string.

script_to_locking_bytecode(script: list[bytes | int], address_type: LockingBytecodeType) bytes[source]

Hash a script into its P2SH20/P2SH32 (or P2PKH/P2PK) locking bytecode.

Parameters:
  • script – Script list to hash.

  • address_type – Desired locking type.

Returns:

Locking bytecode.

Raises:

ValueError – If the address_type is unsupported.