BSV.Tokens.Proof (bsv_sdk v1.5.1)

Copy Markdown View Source

Prev-TX split utility for Back-to-Genesis (BTG) proof system.

Provides split_tx_around_output/2, which splits a raw serialized transaction into three byte segments around a specified output index. The spender pushes these three segments in the unlocking script so that the BTG locking script can reconstruct the previous transaction, verify its hash against the outpoint txid, and inspect the output's locking script for legitimacy.

Summary

Functions

Encode a non-negative integer as a Bitcoin varint byte sequence.

Read a Bitcoin varint from data at the given offset.

Split a raw serialized transaction into three byte segments around the output at index vout.

Functions

encode_varint(value)

@spec encode_varint(non_neg_integer()) :: binary()

Encode a non-negative integer as a Bitcoin varint byte sequence.

read_varint(data, offset)

@spec read_varint(binary(), non_neg_integer()) ::
  {:ok, {non_neg_integer(), non_neg_integer()}} | {:error, String.t()}

Read a Bitcoin varint from data at the given offset.

Returns {:ok, {value, new_offset}} on success.

split_tx_around_output(raw_tx, vout)

@spec split_tx_around_output(binary(), non_neg_integer()) ::
  {:ok, {binary(), binary(), binary()}} | {:error, String.t()}

Split a raw serialized transaction into three byte segments around the output at index vout.

Returns {:ok, {prefix, output_bytes, suffix}} where: hash256(prefix <> output_bytes <> suffix) == txid

The output_bytes segment contains the serialized output at vout in wire format: satoshis(8 LE) + varint(script_len) + script_bytes.