# `Spectre.GAM.Ledger`
[🔗](https://github.com/elchemista/spectre/blob/0.4.0/lib/spectre/gam/ledger.ex#L1)

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.

# `batch_id`

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

# `batch_info`

```elixir
@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`

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

# `domain_ref`

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

# `snapshot`

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

# `batch_identity`

```elixir
@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`

```elixir
@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`

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

Exports a runtime snapshot without including store projections.

# `load`

```elixir
@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`

```elixir
@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`

```elixir
@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`

```elixir
@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`

```elixir
@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.

---

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