Builder for STAS 3.0 (stas3-freeze-multisig) locking scripts.
Summary
Functions
Build flags byte from boolean options.
Build a STAS3 locking script.
Compute the requestedScriptHash for a STAS3 locking script.
Decode a swap action data binary into structured fields.
Encode swap action data fields into a binary for embedding in a locking script.
Extract the locking script tail (everything after owner + action_data fields).
Push data with appropriate length prefix.
Functions
@spec build_stas3_flags(boolean() | BSV.Tokens.ScriptFlags.t()) :: binary()
Build flags byte from boolean options.
Accepts either a single boolean (legacy: freezable only) or a
ScriptFlags struct for full flag support.
@spec build_stas3_locking_script( <<_::160>>, <<_::160>>, BSV.Tokens.ActionData.t() | nil, boolean(), boolean() | BSV.Tokens.ScriptFlags.t(), [binary()], [binary()] ) :: {:ok, BSV.Script.t()} | {:error, term()}
Build a STAS3 locking script.
Parameters
owner_pkh- 20-byte owner public key hashredemption_pkh- 20-byte redemption public key hashaction_data- optional action data ({:swap, hash}or{:custom, bytes})frozen- whether the token is frozenfreezable- whether the token supports freeze operationsservice_fields- list of additional service field binariesoptional_data- list of additional optional data binaries
@spec compute_stas3_requested_script_hash(binary()) :: <<_::256>>
Compute the requestedScriptHash for a STAS3 locking script.
Extracts the "tail" of a locking script (everything after the owner and action_data fields), then returns SHA256(tail). This hash is used in swap action data to identify the counterparty's expected locking script structure.
Parameters
locking_script- Full STAS3 locking script binary
Returns
A 32-byte SHA256 hash of the locking script tail.
@spec decode_swap_action_data(binary()) :: {:ok, BSV.Tokens.ActionData.swap_fields()} | {:error, term()}
Decode a swap action data binary into structured fields.
Parses one or more 61-byte swap legs from the binary. Each leg starts with kind byte 0x01 followed by 32-byte hash, 20-byte PKH, and two uint32 LE values.
Parameters
data- Binary starting with kind byte 0x01
Returns
{:ok, swap_fields} or {:error, reason}
@spec encode_swap_action_data(BSV.Tokens.ActionData.swap_fields()) :: binary()
Encode swap action data fields into a binary for embedding in a locking script.
Each swap leg is 61 bytes: 1 (kind 0x01) + 32 (hash) + 20 (pkh) + 4 (numerator LE) + 4 (denominator LE).
Parameters
fields- Map with:requested_script_hash(32 bytes),:requested_pkh(20 bytes),:rate_numerator(uint32),:rate_denominator(uint32)
Returns
A 61-byte binary encoding the swap action data.
Extract the locking script tail (everything after owner + action_data fields).
The STAS3 locking script layout is:
- Owner field: OP_DATA_20 (0x14) + 20-byte PKH
- Action data field: push_data or OP_FALSE(0x00) or OP_2(0x52)
- Tail: everything from base template to end of script
Parameters
script- Full STAS3 locking script binary
Returns
Binary containing everything after the action_data field.
Push data with appropriate length prefix.