cashscript_py.signature_template module
SignatureTemplate utilities for Schnorr/ECDSA signatures.
Supports BCH SIGHASH flags (including SIGHASH_UTXOS), deterministic Schnorr, and a P2PKH unlocker helper.
- class SignatureTemplate(signer: bytes | str, hashtype: HashType = <HashType.SIGHASH_ALL|SIGHASH_UTXOS: 33>, signature_algorithm: SignatureAlgorithm = <SignatureAlgorithm.SCHNORR: 1>, deterministic_schnorr: bool = False)[source]
Bases:
objectEncapsulates private-key signing for Bitcoin Cash transactions/messages.
Provides methods to sign 32-byte hashes with Schnorr or ECDSA, generate signatures including the hashtype byte for CHECKSIG, and assemble a P2PKH unlocker for standard inputs.
- generate_signature(payload: bytes, bch_fork_id: bool = True) bytes[source]
Sign a 32-byte hash and append the hashtype byte for CHECKSIG.
- Parameters:
payload – 32-byte sighash.
bch_fork_id – If True, include SIGHASH_FORKID in the hashtype.
- Returns:
raw sig + 1-byte hashtype.
- Return type:
Signature bytes suitable for CHECKSIG
- get_hash_type(bch_fork_id: bool = True) HashType[source]
Return the configured SIGHASH flags (optionally OR-ed with ForkID).
- get_signature_algorithm() SignatureAlgorithm[source]
Return the signature algorithm (Schnorr or ECDSA).
- sign_message_hash(payload: bytes) bytes[source]
Sign a 32-byte message hash (no hashtype byte).
- Parameters:
payload – A 32-byte message digest.
- Returns:
64-byte Schnorr signature, or
DER-encoded ECDSA signature (variable length).
- Return type:
Raw signature bytes