Represents a V4 or EIP-7702 set-code transaction.
EIP-7702 transactions use transaction type 0x04 and extend the EIP-1559
field set with an authorization list. Each authorization entry is a
{chain_id, address, nonce, y_parity, r, s} tuple signed over
0x05 || rlp([chain_id, address, nonce]).
Examples
iex> use Cartouche.Hex
iex> authorization = {
...> 1,
...> ~h[0x0000000000000000000000000000000000000002],
...> 7,
...> false,
...> <<1::256>>,
...> <<2::256>>
...> }
iex> transaction =
...> Cartouche.Transaction.V4.new(
...> 1,
...> {1, :gwei},
...> {100, :gwei},
...> 100_000,
...> ~h[0x0000000000000000000000000000000000000001],
...> {2, :wei},
...> <<1, 2, 3>>,
...> [],
...> [authorization],
...> :mainnet
...> )
...> |> Cartouche.Transaction.V4.add_signature(<<3::256, 4::256, 0>>)
iex> {:ok, decoded} = transaction |> Cartouche.Transaction.V4.encode() |> Cartouche.Transaction.V4.decode()
iex> decoded == transaction
true
Summary
Functions
Adds an authorization signature from a packed binary (r <> s <> v).
Adds an outer transaction signature from a packed binary (r <> s <> v).
Returns the EIP-7702 authorization signing hash.
Returns the EIP-7702 authorization signing payload.
Decode an RLP-encoded EIP-7702 transaction.
Build an RLP-encoded EIP-7702 transaction.
Returns a packed authorization signature (r <> s <> y_parity).
Recovers a packed outer transaction signature (r <> s <> y_parity).
Returns the transaction hash for signed or unsigned encoded bytes.
Constructs an unsigned EIP-7702 transaction.
Recovers the EOA that signed an authorization tuple.
Recovers the signer from a signed EIP-7702 transaction.
Signs the outer EIP-7702 transaction.
Signs an EIP-7702 authorization tuple.
Returns the outer transaction signing payload.
Types
@type authorization() :: {non_neg_integer(), <<_::160>>, non_neg_integer(), boolean(), <<_::256>>, <<_::256>>}
@type authorization_input() :: authorization() | {non_neg_integer(), <<_::160>>, non_neg_integer(), nil, nil, nil}
@type t() :: %Cartouche.Transaction.V4{ access_list: [{<<_::160>>, [<<_::256>>]}], amount: non_neg_integer(), authorization_list: [authorization()], chain_id: non_neg_integer(), data: binary(), destination: <<_::160>>, gas_limit: non_neg_integer(), max_fee_per_gas: non_neg_integer() | nil, max_priority_fee_per_gas: non_neg_integer() | nil, nonce: non_neg_integer(), signature_r: <<_::256>> | nil, signature_s: <<_::256>> | nil, signature_y_parity: boolean() | nil }
@type tx_input() :: t() | %Cartouche.Transaction.V4{ access_list: list() | nil, amount: non_neg_integer() | nil, authorization_list: list() | nil, chain_id: non_neg_integer() | nil, data: binary() | nil, destination: <<_::160>> | nil, gas_limit: non_neg_integer() | nil, max_fee_per_gas: non_neg_integer() | nil, max_priority_fee_per_gas: non_neg_integer() | nil, nonce: non_neg_integer() | nil, signature_r: nil, signature_s: nil, signature_y_parity: nil }
@type unsigned_authorization() :: {non_neg_integer(), <<_::160>>, non_neg_integer()}
Functions
@spec add_authorization_signature(authorization_input(), <<_::520, _::_*8>>) :: authorization()
Adds an authorization signature from a packed binary (r <> s <> v).
Adds an outer transaction signature from a packed binary (r <> s <> v).
@spec authorization_hash(unsigned_authorization() | authorization()) :: <<_::256>>
Returns the EIP-7702 authorization signing hash.
@spec authorization_signing_payload(unsigned_authorization() | authorization()) :: binary()
Returns the EIP-7702 authorization signing payload.
Decode an RLP-encoded EIP-7702 transaction.
Build an RLP-encoded EIP-7702 transaction.
@spec get_authorization_signature(authorization()) :: {:ok, binary()} | {:error, String.t()}
Returns a packed authorization signature (r <> s <> y_parity).
Recovers a packed outer transaction signature (r <> s <> y_parity).
Returns the transaction hash for signed or unsigned encoded bytes.
@spec new( non_neg_integer(), non_neg_integer() | {non_neg_integer(), :wei | :gwei} | nil, non_neg_integer() | {non_neg_integer(), :wei | :gwei} | nil, non_neg_integer(), <<_::160>>, non_neg_integer() | {non_neg_integer(), :wei | :gwei}, binary(), list(), [authorization()], atom() | integer() | nil ) :: t()
Constructs an unsigned EIP-7702 transaction.
@spec recover_authority(authorization()) :: {:ok, <<_::160>>} | {:error, String.t()}
Recovers the EOA that signed an authorization tuple.
Recovers the signer from a signed EIP-7702 transaction.
@spec sign(t(), GenServer.name()) :: {:ok, t()} | {:error, String.t()}
Signs the outer EIP-7702 transaction.
@spec sign_authorization(unsigned_authorization(), GenServer.name()) :: {:ok, authorization()} | {:error, String.t()}
Signs an EIP-7702 authorization tuple.
Returns the outer transaction signing payload.