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

Shared signature-field helpers for typed-transaction structs that carry the
`signature_y_parity` / `signature_r` / `signature_s` triple
(EIP-2930 `V_2930`, EIP-1559 `V2`, EIP-4844 `V3`, EIP-7702 `V4`).

`pack/3` is the shared primitive behind both struct recovery (`get/1`) and
EIP-7702 authorization 6-tuples, which do not carry those map keys.

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.

# `add`

```elixir
@spec add(map(), boolean(), &lt;&lt;_::256&gt;&gt;, &lt;&lt;_::256&gt;&gt;) :: 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`

```elixir
@spec add_packed(map(), &lt;&lt;_::512, _::_*8&gt;&gt;) :: map()
```

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

# `get`

```elixir
@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.

# `pack`

```elixir
@spec pack(boolean() | nil, binary() | nil, binary() | nil) ::
  {:ok, binary()} | {:error, :missing}
```

Packs `y_parity`, `r`, and `s` into the `r <> s <> y_parity` binary used by
typed-transaction recovery. `r` and `s` must be exactly 32 bytes.

Returns `{:error, :missing}` when any field is nil. Callers map that atom to
a domain string (`"transaction missing signature"`, `"authorization missing
signature"`). A short `r` or `s` raises `ArgumentError` rather than emitting
a malformed packed signature.

# `y_parity_from_v`

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

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

---

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