# `Spectre.GAM.Consequence.Contract`
[🔗](https://github.com/elchemista/spectre/blob/0.4.0/lib/spectre/gam/consequence/contract.ex#L1)

Portable, closed schema for one governed consequence class.

A contract is deliberately small. Maps name every allowed key, `$list`
describes a homogeneous list, `$optional` and `$nullable` are explicit, and
`$const` fixes a literal value. Scalar leaves use one of the documented type
names; `portable` accepts any canonical portable value so application tools
can carry their own nested arguments. The four binding leaves (`subject_ref`,
`subject_refs`, `target_ref`
and `target_refs`) derive the exact Candidate endpoints. `destination_ref(s)`
additionally bind the disclosure destination, while `meter_requests` binds
the exact quantitative request. A proposer therefore cannot validate
authority against different endpoints or cost than the consequence carries.

The schema is data stored in the Surface. It contains no callback or module
reference and is therefore independently replayable.

# `t`

```elixir
@type t() :: %Spectre.GAM.Consequence.Contract{
  ref: String.t(),
  schema_version: 1,
  shape: term()
}
```

# `binding_kinds`

```elixir
@spec binding_kinds(t()) :: MapSet.t(atom())
```

Returns the semantic boundary kinds explicitly bound by the schema.

# `bindings`

```elixir
@spec bindings(t(), term()) :: {:ok, map()} | {:error, term()}
```

Extracts the boundaries explicitly carried by a valid consequence.

Authoring can reuse the same schema walk as admission instead of guessing
targets or Meter quantities. This is not authorization and supplies neither
an executor nor consent. Runtime validation still compares every boundary.

# `canonical`

```elixir
@spec canonical(t()) :: map()
```

Returns the plain, string-keyed ledger representation.

# `content_ref`

```elixir
@spec content_ref(t()) :: String.t()
```

Returns the reference derived from the immutable contract content.

# `from_canonical`

```elixir
@spec from_canonical(map()) :: {:ok, t()} | {:error, term()}
```

Restores a consequence contract and verifies its content reference.

# `new`

```elixir
@spec new(map() | keyword() | t()) :: {:ok, t()} | {:error, term()}
```

Builds and validates a content-addressed consequence contract.

# `validate`

```elixir
@spec validate(t(), term(), map()) :: :ok | {:error, term()}
```

Validates the consequence and its exact declared boundary bindings.

---

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