Spectre.GAM.Ledger (Spectre v0.4.0)

Copy Markdown View Source

Facade and independent verifier for an ordered Domain ledger.

A logical append is a non-empty atomic batch. Callers supply both an expected_revision CAS fence and a stable batch_id. Retrying the identical logical batch is idempotent; reusing its identity for different contents is rejected.

The verifier consumes the exported entry chain directly. It does not consult runtime projections, cached authority, or a store-specific index.

Summary

Functions

Returns the stable digest identifying a logical batch request.

Exports a verified Domain ledger as portable plain data.

Exports a runtime snapshot without including store projections.

Returns a verified snapshot of a Domain ledger.

Reads and verifies only the entries after an already verified prefix.

Looks up the durable identity and revision range of a prior batch.

Independently verifies an exported ledger and returns its reconstructed view.

Loads and independently verifies the export produced by a store.

Types

batch_id()

@type batch_id() :: String.t()

batch_info()

@type batch_info() :: %{
  batch_id: batch_id(),
  identity_digest: Spectre.GAM.Ledger.Entry.digest(),
  expected_revision: non_neg_integer(),
  first_revision: pos_integer(),
  last_revision: pos_integer(),
  entry_count: pos_integer(),
  head_digest: Spectre.GAM.Ledger.Entry.digest()
}

cursor()

@type cursor() :: %{
  revision: non_neg_integer(),
  head_digest: Spectre.GAM.Ledger.Entry.digest()
}

domain_ref()

@type domain_ref() :: String.t()

snapshot()

@type snapshot() :: %{
  :domain_ref => domain_ref(),
  :revision => non_neg_integer(),
  :head_digest => Spectre.GAM.Ledger.Entry.digest(),
  :entries => [Spectre.GAM.Ledger.Entry.t()],
  optional(:recovery) => map() | nil
}

Functions

batch_identity(domain_ref, batch_id, payloads, expected_revision)

@spec batch_identity(domain_ref(), batch_id(), [map()], non_neg_integer()) ::
  {:ok, Spectre.GAM.Ledger.Entry.digest()} | {:error, term()}

Returns the stable digest identifying a logical batch request.

export(store, domain_ref, opts \\ [])

@spec export(Spectre.GAM.Ledger.Store.config(), domain_ref(), keyword()) ::
  :not_found | {:ok, map()} | {:error, term()}

Exports a verified Domain ledger as portable plain data.

export_snapshot(snapshot)

@spec export_snapshot(snapshot()) :: {:ok, map()} | {:error, term()}

Exports a runtime snapshot without including store projections.

load(store, domain_ref, opts \\ [])

@spec load(Spectre.GAM.Ledger.Store.config(), domain_ref(), keyword()) ::
  :not_found | {:ok, snapshot()} | {:error, term()}

Returns a verified snapshot of a Domain ledger.

load_from(store, domain_ref, cursor, opts \\ [])

@spec load_from(Spectre.GAM.Ledger.Store.config(), domain_ref(), cursor(), keyword()) ::
  :not_found | {:ok, snapshot()} | {:error, term()}

Reads and verifies only the entries after an already verified prefix.

The cursor must identify a complete batch boundary held by the caller. This is not an independent audit or a way to trust an arbitrary persisted cache: only the suffix is checked against that predecessor. Revisions, digests, Domain binding, complete batches and the captured head are still verified.

lookup_batch(store, domain_ref, batch_id, opts \\ [])

@spec lookup_batch(
  Spectre.GAM.Ledger.Store.config(),
  domain_ref(),
  batch_id(),
  keyword()
) ::
  :not_found | {:ok, batch_info()} | {:error, term()}

Looks up the durable identity and revision range of a prior batch.

verify(data)

@spec verify(map()) :: {:ok, snapshot()} | {:error, term()}

Independently verifies an exported ledger and returns its reconstructed view.

Verification covers canonical entry digests, revision continuity, the previous-digest chain, Domain binding, batch contiguity, and export summary.

verify_store(store, domain_ref, opts \\ [])

@spec verify_store(Spectre.GAM.Ledger.Store.config(), domain_ref(), keyword()) ::
  :not_found | {:ok, snapshot()} | {:error, term()}

Loads and independently verifies the export produced by a store.