Spectre.GAM.Consequence.Contract (Spectre v0.4.0)

Copy Markdown View Source

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.

Summary

Functions

Returns the semantic boundary kinds explicitly bound by the schema.

Extracts the boundaries explicitly carried by a valid consequence.

Returns the plain, string-keyed ledger representation.

Returns the reference derived from the immutable contract content.

Restores a consequence contract and verifies its content reference.

Builds and validates a content-addressed consequence contract.

Validates the consequence and its exact declared boundary bindings.

Types

t()

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

Functions

binding_kinds(contract)

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

Returns the semantic boundary kinds explicitly bound by the schema.

bindings(contract, consequence)

@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(contract)

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

Returns the plain, string-keyed ledger representation.

content_ref(contract)

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

Returns the reference derived from the immutable contract content.

from_canonical(value)

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

Restores a consequence contract and verifies its content reference.

new(contract)

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

Builds and validates a content-addressed consequence contract.

validate(contract, consequence, boundary)

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

Validates the consequence and its exact declared boundary bindings.