Spectre.Authority.Envelope (Spectre v0.3.0)

Copy Markdown View Source

Effective, portable authority granted to one canonical Definition.

Requests and grants are deliberately separate. compose/2 intersects every requested capability with a host-owned ceiling; a request can therefore never create authority by itself. The resulting envelope contains grants only and is safe to seal into a Spectre.Definition.Manifest.

Summary

Functions

Returns whether value is effectively granted in field.

Intersects requested authority with the host-owned authority ceiling.

Intersects authority or raises with its stable validation reason.

Returns the canonical SHA-256 digest of the effective grants.

Returns an envelope with no grants and no limits.

Restores an envelope from decoded canonical data.

Builds and validates an effective authority envelope.

Builds an envelope or raises with its stable validation reason.

Returns the Authority Envelope schema version.

Returns the portable data sealed into a Definition Manifest.

Types

t()

@type t() :: %Spectre.Authority.Envelope{
  actions: [term()],
  consents: [term()],
  effects: [term()],
  event_classes: [term()],
  external_data_refs: [term()],
  limits: %{optional(atom()) => term()},
  model_profiles: [term()],
  model_purposes: [term()],
  open_capabilities: [term()],
  operations: [term()],
  prompt_budget_classes: [term()],
  prompt_phases: [term()],
  schema_version: pos_integer(),
  secret_refs: [term()],
  state_reads: [term()],
  state_writes: [term()]
}

Functions

allows?(envelope, field, value)

@spec allows?(t(), atom(), term()) :: boolean()

Returns whether value is effectively granted in field.

compose(requested, ceiling)

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

Intersects requested authority with the host-owned authority ceiling.

Capability lists use canonical value identity. Numeric limits are reduced to the stricter value; non-numeric limits, such as risk classes, are taken from the ceiling and only appear when both sides declared the limit.

compose!(requested, ceiling)

@spec compose!(t() | map() | keyword(), t() | map() | keyword()) :: t()

Intersects authority or raises with its stable validation reason.

digest(envelope)

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

Returns the canonical SHA-256 digest of the effective grants.

empty()

@spec empty() :: t()

Returns an envelope with no grants and no limits.

from_data(data)

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

Restores an envelope from decoded canonical data.

new(envelope)

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

Builds and validates an effective authority envelope.

new!(attrs)

@spec new!(t() | map() | keyword()) :: t()

Builds an envelope or raises with its stable validation reason.

schema_version()

@spec schema_version() :: pos_integer()

Returns the Authority Envelope schema version.

to_data(envelope)

@spec to_data(t()) :: map()

Returns the portable data sealed into a Definition Manifest.