Spectre.GAM.Kernel.Authority (Spectre v0.4.0)

Copy Markdown View Source

Pure resolution of the authority that may cover a candidate.

Authority is resolved exclusively from the candidate, the authenticated SubmissionContext, the current authority view and trusted time. Evidence is deliberately absent from this API: facts may satisfy a mandate's conditions, but they cannot create or select the mandate itself.

Every ledger record is decoded before it reaches this module. The resolver therefore consumes typed Candidates and Mandates plus the closed Spectre.GAM.Kernel.Authority.Facts container; accepting alternate storage shapes here would make authority semantics depend on map-key guesses.

Summary

Types

The authority-relevant subset shared by a live or replayed submission context.

Functions

Validates one durable Mandate and returns the exact authority used by Decision.

Verifies that a child Mandate is a subtractive restriction of its parent.

Rechecks mutable authority facts before an admitted Act may start execution.

Explains whether one mandate is eligible without consulting Evidence.

Returns whether a Mandate branch is blocked by an unresolved Meter debt.

Verifies that every label owner explicitly granted within a Mandate lineage.

Resolves the one current mandate which covers candidate.

Returns whether a Mandate or one of its authority ancestors has been superseded.

Verifies that a successor is a strict, non-quantitative restriction.

Types

context()

@type context() :: %{
  :domain_ref => String.t(),
  :scope_ref => String.t(),
  :authenticated_principal_ref => String.t(),
  :authentication_ref => String.t(),
  :ingress_ref => String.t(),
  :host_generation => non_neg_integer(),
  optional(atom()) => term()
}

The authority-relevant subset shared by a live or replayed submission context.

effective()

resolution()

@type resolution() :: {:ok, effective()} | :none | {:ambiguous, [effective()]}

Functions

authorize(candidate, context, mandate, view, time)

Validates one durable Mandate and returns the exact authority used by Decision.

Usually that is the Mandate itself. A retained_controller revocation is the one narrow exception recorded by the Mandate: while it is current, a named controller may revoke that exact Mandate through the ledger kernel. The returned map narrows every field to that single consequence; it is not a new durable Mandate and cannot authorize any other Candidate.

delegation_within?(parent, child, time)

@spec delegation_within?(
  Spectre.GAM.Mandate.t() | map() | keyword(),
  Spectre.GAM.Mandate.t() | map() | keyword(),
  integer()
) :: :ok | {:error, term()}

Verifies that a child Mandate is a subtractive restriction of its parent.

Quantitative transfer still has to be applied through Kernel.Meter.delegate/3; this function checks declared ceilings, not mutable balances. It also requires the parent's conditions to be preserved or strengthened and the recorded revocation policy to remain identical. Equality is intentionally used for opaque purpose parameters and revocation policies because the core has no safe domain-independent way to infer a broader restriction relation. It never creates the child or changes either Mandate.

dispatchable?(act, mandate, view, time)

@spec dispatchable?(
  Spectre.GAM.Act.t(),
  Spectre.GAM.Mandate.t(),
  Spectre.GAM.Kernel.Authority.Facts.t(),
  integer()
) :: :ok | {:error, term()}

Rechecks mutable authority facts before an admitted Act may start execution.

eligible?(candidate, context, mandate, view, time)

Explains whether one mandate is eligible without consulting Evidence.

This function is useful to auditors and to tests which need a stable reason for exclusion. It does not check whether mandate Evidence conditions are met or whether a Meter currently has sufficient available quantity.

meter_debt_status(mandate, view)

@spec meter_debt_status(
  Spectre.GAM.Mandate.t(),
  Spectre.GAM.Kernel.Authority.Facts.t()
) ::
  :ok | {:error, term()}

Returns whether a Mandate branch is blocked by an unresolved Meter debt.

owners_authorize_mandate?(mandate, owner_refs, view)

@spec owners_authorize_mandate?(
  Spectre.GAM.Mandate.t(),
  [String.t()],
  Spectre.GAM.Kernel.Authority.Facts.t()
) :: :ok | {:error, term()}

Verifies that every label owner explicitly granted within a Mandate lineage.

resolve(candidate, context, view, time)

Resolves the one current mandate which covers candidate.

:none includes an unauthenticated or self-contradicting submission context. Multiple independently eligible mandates are returned explicitly instead of being selected by order, evidence, or caller preference.

restriction_status(mandate, view)

@spec restriction_status(
  Spectre.GAM.Mandate.t(),
  Spectre.GAM.Kernel.Authority.Facts.t()
) ::
  :ok | {:error, term()}

Returns whether a Mandate or one of its authority ancestors has been superseded.

restriction_within?(predecessor, successor, time)

@spec restriction_within?(
  Spectre.GAM.Mandate.t() | map() | keyword(),
  Spectre.GAM.Mandate.t() | map() | keyword(),
  integer()
) :: :ok | {:error, term()}

Verifies that a successor is a strict, non-quantitative restriction.

Restriction keeps the same authority lineage and Meter allocation while narrowing at least one decidable boundary. Moving or shrinking quantities is deliberately left to delegation/devolution, so replacing a Mandate cannot silently mint, destroy or strand an in-flight allocation.