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

One immutable record in a Domain ledger.

Entries are numbered from one and form a SHA-256 chain. The digest covers
the Domain, revision, batch coordinates, trusted recording time, previous
digest, and payload. The
payload must be a plain portable map; executable values and structs are
rejected by `Spectre.GAM.Canonical.Value`.

`Entry` structs are an in-memory convenience only. The durable form returned
by `to_data/1` is a plain map with string keys.

# `digest`

```elixir
@type digest() :: &lt;&lt;_::512&gt;&gt;
```

# `t`

```elixir
@type t() :: %Spectre.GAM.Ledger.Entry{
  batch_id: String.t(),
  batch_index: non_neg_integer(),
  batch_size: pos_integer(),
  digest: digest(),
  domain_ref: String.t(),
  payload: map(),
  prev_digest: digest(),
  recorded_at: non_neg_integer(),
  revision: pos_integer(),
  schema_version: pos_integer()
}
```

# `batch_identity`

```elixir
@spec batch_identity(String.t(), String.t(), [map()], non_neg_integer()) ::
  {:ok, digest()} | {:error, term()}
```

Computes the stable identity of a logical batch request.

# `build`

```elixir
@spec build(
  String.t(),
  pos_integer(),
  String.t(),
  non_neg_integer(),
  pos_integer(),
  non_neg_integer(),
  digest(),
  map()
) :: {:ok, t()} | {:error, term()}
```

Builds a new Entry and computes its canonical digest.

# `build_batch`

```elixir
@spec build_batch(
  String.t(),
  String.t(),
  [map()],
  non_neg_integer(),
  non_neg_integer(),
  digest()
) :: {:ok, [t()]} | {:error, term()}
```

Builds a complete linked batch after validating its portable payloads.

# `decode`

```elixir
@spec decode(binary()) :: {:ok, t()} | {:error, term()}
```

Decodes and verifies canonical Entry bytes.

# `encode`

```elixir
@spec encode(t()) :: {:ok, binary()} | {:error, term()}
```

Encodes an Entry with the canonical value codec.

# `from_data`

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

Restores and verifies an Entry from its plain-map durable form.

# `genesis_digest`

```elixir
@spec genesis_digest() :: digest()
```

Returns the fixed predecessor digest used by revision one.

# `max_batch_entries`

```elixir
@spec max_batch_entries() :: pos_integer()
```

Returns the maximum number of entries accepted in one atomic batch.

# `new`

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

Builds and validates an Entry from its complete durable fields.

# `schema_version`

```elixir
@spec schema_version() :: pos_integer()
```

Returns the durable Entry schema version.

# `to_data`

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

Returns the plain-map durable representation of an Entry.

# `verify`

```elixir
@spec verify(t()) :: :ok | {:error, term()}
```

Verifies that an Entry digest exactly matches its durable contents.

# `verify_chain`

```elixir
@spec verify_chain(
  [t() | map()],
  keyword()
) :: {:ok, map()} | {:error, term()}
```

Verifies a contiguous chain without consulting a projection or store.

---

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