BSV.Tokens.Template.Stas (bsv_sdk v1.5.0)

Copy Markdown View Source

STAS unlocking script templates (P2PKH and P2MPKH).

Supports both legacy (P2PKH-only, no spend type) and v3 (with spend type) signing modes.

For P2PKH: produces <sig> <pubkey>. For P2MPKH: produces <sig1> … <sigM> <serialized_multisig_script>.

The on-chain STAS script auto-detects the format based on the size of the public key data: 33 bytes → P2PKH; otherwise → P2MPKH.

Summary

Functions

Estimated unlocking script length in bytes.

Sign a STAS input, producing a P2PKH or P2MPKH unlocking script.

Create a STAS unlocker struct from a PrivateKey (P2PKH, backward compatible).

Create a STAS unlocker from a SigningKey (dispatches P2PKH vs P2MPKH).

Create a STAS P2MPKH unlocker struct from threshold keys and a multisig script.

Types

t()

@type t() :: %BSV.Tokens.Template.Stas{
  sighash_flag: non_neg_integer(),
  signing_key: BSV.Tokens.SigningKey.t(),
  spend_type: BSV.Tokens.SpendType.t() | nil
}

Functions

estimate_length(stas, _, _)

Estimated unlocking script length in bytes.

sign(stas, tx, input_index)

Sign a STAS input, producing a P2PKH or P2MPKH unlocking script.

unlock(key, opts \\ [])

@spec unlock(
  BSV.PrivateKey.t(),
  keyword()
) :: t()

Create a STAS unlocker struct from a PrivateKey (P2PKH, backward compatible).

Options

  • :spend_typeSpendType.t() for v3 scripts (default: nil for legacy)
  • :sighash_flag — sighash flag byte (default: 0x41)

unlock_from_signing_key(signing_key, opts \\ [])

@spec unlock_from_signing_key(
  BSV.Tokens.SigningKey.t(),
  keyword()
) :: t()

Create a STAS unlocker from a SigningKey (dispatches P2PKH vs P2MPKH).

unlock_mpkh(private_keys, multisig, opts \\ [])

Create a STAS P2MPKH unlocker struct from threshold keys and a multisig script.

Options

  • :spend_typeSpendType.t() for v3 scripts (default: nil)
  • :sighash_flag — sighash flag byte (default: 0x41)