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: object

Encapsulates 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_public_key() bytes[source]

Return the compressed public key (33 bytes).

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

unlock_p2pkh() Unlocker[source]

Create a standard P2PKH Unlocker using this template.

Returns:

An Unlocker that can sign and unlock P2PKH inputs for this key.

verify_signature(signature: bytes, payload: bytes) bool[source]

Verify a raw signature against a 32-byte message hash.

Parameters:
  • signature – Raw signature (64-byte Schnorr or DER ECDSA).

  • payload – 32-byte message digest.

Returns:

True if the signature is valid for this template’s public key.