# `BSV.Tokens.Stas3.Validate`
[🔗](https://github.com/Bittoku/bsv_sdk_elixir/blob/main/lib/bsv/tokens/stas3/validate.ex#L1)

STAS 3.0 v0.1 §9 build-time enforcement helpers.

These predicates run BEFORE signing, on the resolved input + destination
set assembled by a factory. They catch spec violations at construction
time so that we never produce a transaction whose engine would reject
it on broadcast.

## Coverage

  * `freeze/2` — §9.2 Freeze / Unfreeze:
      - exactly one STAS output,
      - non-`var2` fields byte-identical to the input,
      - FREEZABLE flag bit set in the input's flags.

  * `confiscation/1` — §9.3 Confiscation:
      - CONFISCATABLE flag bit set in the input's flags.

  * `swap_cancel/2` — §9.4 Swap cancellation:
      - input must carry a swap descriptor (action 0x01),
      - exactly one STAS output,
      - output's owner equals the input's `var2.receiveAddr`.

Each function returns `:ok` on success or `{:error, atom_or_tuple}` on
failure. Error atoms are the ones documented in the brief:

  * `:freeze_output_count`, `:freeze_field_drift`, `:freeze_flag_not_set`
  * `:confiscate_flag_not_set`
  * `:swap_cancel_missing_descriptor`, `:swap_cancel_output_count`,
    `:swap_cancel_owner_mismatch`

Per spec §9.6, these checks are applied independently — the calling
factory chooses which to invoke based on its own intent. The §9.6
precedence rule (Confiscation > Freeze > Swap > Regular) is informative
for engines that must classify a spend post-hoc; in this SDK the
factory is authoritative.

# `destination`

```elixir
@type destination() :: %{:owner_pkh =&gt; &lt;&lt;_::160&gt;&gt;, optional(any()) =&gt; any()}
```

A STAS3 destination as understood by the STAS3 factory layer.

# `token_input`

```elixir
@type token_input() :: %{:locking_script =&gt; BSV.Script.t(), optional(any()) =&gt; any()}
```

A token input as understood by the STAS3 factory layer.

# `confiscation`

```elixir
@spec confiscation(token_input()) :: :ok | {:error, atom()}
```

Validate a confiscation build per spec §9.3.

Requires only that the input's `flags` field has the CONFISCATABLE bit
set. Output count and `var2` content are unconstrained per spec.

# `freeze`

```elixir
@spec freeze(token_input(), [destination()]) :: :ok | {:error, atom()}
```

Validate a freeze (or unfreeze) build per spec §9.2.

Requires:

  * exactly one destination (single STAS output),
  * destination's `owner_pkh` and `redemption_pkh` byte-identical to
    the input — `var2` is the only field permitted to drift,
  * input's `flags` field has the FREEZABLE bit set.

# `swap_cancel`

```elixir
@spec swap_cancel(token_input(), [destination()]) :: :ok | {:error, atom()}
```

Validate a swap-cancellation build per spec §9.4.

Requires:

  * input's `var2` parses as a swap descriptor (action `0x01`),
  * exactly one destination,
  * destination's `owner_pkh` equals the input's `var2.receiveAddr`.

Authorisation against `receiveAddr` is enforced by the engine at
spend time and is not re-checked here.

---

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