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

STAS protocol flags field.

The flags field is embedded in the trailing metadata of a STAS locking script,
immediately after the redemption address/MPKH. Each bit enables an optional
administrative capability that is set at issuance and cannot be changed.

## Bit Layout

| Bit | Flag            | Effect                                      |
|-----|-----------------|---------------------------------------------|
| 0   | `freezable`     | Enables freeze/unfreeze by authority         |
| 1   | `confiscatable` | Enables confiscation by authority             |

When a flag is enabled, a corresponding **service field** follows the flags
in the trailing metadata, containing the authority address/MPKH for that
capability. Service fields appear left-to-right in the opposite order of the
flag bits (right-to-left).

## Encoding

The flags field is always present unless no data follows the redemption PKH.
Use `OP_0` (0x00) or `<<0x01, 0x00>>` for default (no flags). Do NOT use
`OP_1`–`OP_16` for the flags field — use pushdata encoding.

# `t`

```elixir
@type t() :: %BSV.Tokens.ScriptFlags{confiscatable: boolean(), freezable: boolean()}
```

# `decode`

```elixir
@spec decode(binary()) :: {:ok, t()} | {:error, :invalid_flags}
```

Decode a flags binary into a `ScriptFlags` struct.

# `encode`

```elixir
@spec encode(t()) :: binary()
```

Encode flags to a binary for embedding in a locking script.

Returns a binary where bit 0 = freezable, bit 1 = confiscatable.

# `service_field_count`

```elixir
@spec service_field_count(t()) :: non_neg_integer()
```

Returns the number of service fields expected for the given flags.

---

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