# `Cartouche.Transaction.TypedDecode`
[🔗](https://github.com/ZenHive/onchain-stack/blob/cartouche-v0.9.0/packages/cartouche/lib/cartouche/transaction/typed_decode.ex#L1)

Shared EIP-2718 typed-transaction envelope helpers.

Every typed transaction (EIP-2930 `V_2930`, EIP-7702 `V4`, …) decodes the
same way: match the leading type byte, RLP-decode the remaining payload, then
hand the decoded field list to a type-specific `decode_fields` callback. This
module also owns the EIP-2930 access-list encode/decode guards so every
envelope that carries an access list rejects the same malformed entries on
both sides of the wire.

# `access_list`

```elixir
@type access_list() :: [{&lt;&lt;_::160&gt;&gt;, [&lt;&lt;_::256&gt;&gt;]}]
```

EIP-2930 access list: `{address, [storage_key]}` pairs.

# `access_list_entry`

```elixir
@type access_list_entry() :: {&lt;&lt;_::160&gt;&gt;, [&lt;&lt;_::256&gt;&gt;]}
```

# `decode`

```elixir
@spec decode(binary(), byte(), String.t(), (list() -&gt;
                                        {:ok, term()} | {:error, String.t()})) ::
  {:ok, term()} | {:error, String.t()}
```

Dispatches a typed-transaction binary.

Matches the leading `tx_type` byte, RLP-decodes the rest (returning `invalid`
on malformed RLP), and applies `decode_fields` to the decoded field list. Any
other leading byte (or non-binary) yields `{:error, invalid}`.

# `decode_access_list`

```elixir
@spec decode_access_list(term(), String.t()) ::
  {:ok, access_list()} | {:error, String.t()}
```

Decodes an RLP-decoded access list into `{address, [storage_key]}` tuples.

Each entry must be a `[20-byte address, [32-byte storage_key, ...]]` list;
anything else yields `{:error, invalid}`. Shared by every typed transaction
that carries an EIP-2930 access list (`V_2930`, `V3`, …).

# `decode_word`

```elixir
@spec decode_word(binary(), String.t()) :: {:ok, &lt;&lt;_::256&gt;&gt;} | {:error, String.t()}
```

Left-pads a signature/word binary to a full 32-byte word.

Words longer than 32 bytes are rejected with `{:error, invalid}`.

# `decode_y_parity`

```elixir
@spec decode_y_parity(binary(), String.t()) :: {:ok, boolean()} | {:error, String.t()}
```

Decodes an RLP `y_parity` field (`0`/`1`) into a boolean.

Any other value — or a non-binary that `:binary.decode_unsigned/1` rejects —
yields `{:error, invalid}`.

# `encode_access_list`

```elixir
@spec encode_access_list(term()) :: [[&lt;&lt;_::160&gt;&gt; | [&lt;&lt;_::256&gt;&gt;]]]
```

Encodes an access list as EIP-2930 RLP items (`[address, storage_keys]`).

Constructors that document a bare-address shorthand must canonicalize to
`{address, []}` before calling this. Malformed entries raise `ArgumentError`.

# `validate_access_list_entry!`

```elixir
@spec validate_access_list_entry!(term()) :: access_list_entry()
```

Accepts a canonical `{address, storage_keys}` access-list entry.

Used by constructors that lift documented shorthand before encoding.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
