Cartouche.Transaction.Signature (Cartouche v0.5.0)

Copy Markdown View Source

Shared signature-field helpers for typed-transaction structs that carry the signature_y_parity / signature_r / signature_s triple (EIP-1559 V2, EIP-4844 V3, and any future post-EIP-2718 type).

These functions operate on the struct as a plain map, so they work uniformly across the typed-transaction modules without coupling them to one another.

Summary

Functions

Attaches explicit signature fields (y_parity, r, s) to a transaction struct. r and s must be exactly 32 bytes and v a boolean y-parity.

Attaches a packed r <> s <> v signature to a transaction struct.

Recovers the packed r <> s <> y_parity signature from a signed transaction, or {:error, "transaction missing signature"} when any signature field is nil.

Derives EIP-155-style y-parity from a packed recovery v byte sequence.

Functions

add(transaction, v, r, s)

@spec add(map(), boolean(), <<_::256>>, <<_::256>>) :: map()

Attaches explicit signature fields (y_parity, r, s) to a transaction struct. r and s must be exactly 32 bytes and v a boolean y-parity.

add_packed(transaction, arg)

@spec add_packed(map(), <<_::512, _::_*8>>) :: map()

Attaches a packed r <> s <> v signature to a transaction struct.

get(map)

@spec get(map()) :: {:ok, binary()} | {:error, String.t()}

Recovers the packed r <> s <> y_parity signature from a signed transaction, or {:error, "transaction missing signature"} when any signature field is nil.

y_parity_from_v(v_bin)

@spec y_parity_from_v(binary()) :: boolean()

Derives EIP-155-style y-parity from a packed recovery v byte sequence.