cashscript_py.helpers.cashtoken module
Utility functions for CashTokens operations (token-aware outputs and address detection).
- is_token_address(address: str) bool[source]
Detect whether a CashAddr is token-aware by inspecting its version byte.
- Parameters:
address – CashAddr string with prefix.
- Returns:
True if the address indicates a token-aware version; False otherwise.
- serialize_token_prefix(token: TokenDetails | None) bytes[source]
Serialize a CashTokens token prefix.
- Layout (when present):
0xef (PREFIX_TOKEN)
token category (32 bytes), encoded in OP_HASH256 byte order (reversed txid)
- token bitfield (1 byte):
- high nibble (structure):
0x40 -> HAS_COMMITMENT_LENGTH (commitment length + commitment follow) 0x20 -> HAS_NFT (low nibble encodes capability: 0x00 none, 0x01 mutable, 0x02 minting) 0x10 -> HAS_AMOUNT (fungible amount follows as varint) 0x80 -> RESERVED (must be 0)
- low nibble (nft_capability):
0x00 none (immutable), 0x01 mutable, 0x02 minting
[NFT commitment length (varint) + commitment (bytes)] if 0x40
[fungible amount (varint)] if 0x10
- Returns:
the token prefix bytes, or empty bytes if token is None.
- Return type:
bytes