BSV.Tokens.Script.StasBtgBuilder (bsv_sdk v1.5.1)

Copy Markdown View Source

Builder for STAS-BTG (Back-to-Genesis) locking scripts.

The STAS-BTG template extends the standard STAS v2 template with a dual-path spending mechanism:

Path A — BTG Proof (OP_IF branch)

The unlocking script pushes <sig> <pubkey> <prefix> <output> <suffix> OP_TRUE. The BTG preamble verifies the prev-TX proof.

Path B — Checkpoint Attestation (OP_ELSE branch)

The unlocking script pushes <sig_owner> <pubkey_owner> <sig_issuer> <pubkey_issuer> OP_FALSE. The checkpoint gate verifies the issuer's co-signature.

Summary

Functions

Build the checkpoint attestation gate bytes.

Build a STAS-BTG locking script with dual-path spending.

Find the byte offset of the redemption PKH within the BTG preamble.

Push a number onto a script using minimal encoding.

Functions

build_checkpoint_gate(arg)

@spec build_checkpoint_gate(<<_::160>>) :: binary()

Build the checkpoint attestation gate bytes.

Gate performs: OP_DUP OP_HASH160 push_20(redemption_pkh) OP_EQUALVERIFY OP_CHECKSIGVERIFY Total: 25 bytes.

build_stas_btg_locking_script(arg1, arg2, splittable)

@spec build_stas_btg_locking_script(<<_::160>>, <<_::160>>, boolean()) ::
  {:ok, BSV.Script.t()} | {:error, term()}

Build a STAS-BTG locking script with dual-path spending.

Parameters

  • owner_pkh - 20-byte public key hash of the owner
  • redemption_pkh - 20-byte public key hash for redemption / token ID
  • splittable - whether the token can be split

Returns

{:ok, Script.t()} containing the STAS-BTG locking script.

find_preamble_redemption_offset(script)

@spec find_preamble_redemption_offset(binary()) :: non_neg_integer() | nil

Find the byte offset of the redemption PKH within the BTG preamble.

Scans for the pattern: 0x14 (push 20 bytes) + 20 bytes + 0x88 (OP_EQUALVERIFY) within the first 350 bytes of the script.

push_number(value)

@spec push_number(integer()) :: binary()

Push a number onto a script using minimal encoding.