# `ExGAM.Portable`
[🔗](https://github.com/elchemista/ex_gam/blob/0.1.0/lib/ex_gam/portable.ex#L1)

Portable value boundary for the governed-act record layer.

Durable records are reduced to plain maps and values before they enter the
ledger.  This module rejects runtime-local capabilities (`PID`, port,
reference and function values), improper lists, structs, non-byte-aligned
bitstrings and non-finite floats.  Accepted values are encoded through the
versioned `ExGAM.Canonical.Value` codec, so map iteration order never
affects a digest.

Content references have the form `"prefix:sha256"`.  They are identifiers
for immutable content, not proof that the content is authoritative.

# `path`

```elixir
@type path() :: [term()]
```

# `reason`

```elixir
@type reason() :: term()
```

# `canonical`

```elixir
@spec canonical(term()) :: {:ok, binary()} | {:error, reason()}
```

Alias for `canonical_value/1`, useful at generic record boundaries.

# `canonical_fields`

```elixir
@spec canonical_fields(map(), [atom()]) :: map()
```

Projects known atom fields into the strict string-keyed record representation.

# `canonical_map`

```elixir
@spec canonical_map(map()) :: {:ok, map()} | {:error, reason()}
```

Validates and returns a plain canonical map.

# `canonical_value`

```elixir
@spec canonical_value(term()) :: {:ok, binary()} | {:error, reason()}
```

Returns the deterministic, versioned canonical bytes for a portable value.

# `canonical_value!`

```elixir
@spec canonical_value!(term()) :: binary()
```

Returns canonical bytes or raises when `value` is not portable.

# `content_ref`

```elixir
@spec content_ref(String.t() | atom(), term()) ::
  {:ok, String.t()} | {:error, reason()}
```

Builds a stable `prefix:digest` reference for portable content.

# `content_ref!`

```elixir
@spec content_ref!(String.t() | atom(), term()) :: String.t()
```

Builds a stable content reference or raises.

# `digest`

```elixir
@spec digest(term()) :: {:ok, String.t()} | {:error, reason()}
```

Returns the lowercase SHA-256 digest of a portable value.

# `digest!`

```elixir
@spec digest!(term()) :: String.t()
```

Returns a digest or raises when `value` is not portable.

# `is_non_empty_binary`
*macro* 

Guard for opaque non-empty binary identifiers, without claiming content validity.

# `is_non_negative_integer`
*macro* 

Guard shared by revisions, generations and elapsed millisecond windows.

# `is_plain_map`
*macro* 

Guard for a canonical object container, excluding runtime structs.

# `is_positive_integer`
*macro* 

Guard for strictly positive revisions and quantities.

# `keyword?`

```elixir
@spec keyword?(term()) :: boolean()
```

Checks host keyword options without raising on non-list input.

# `normalize_attrs`

```elixir
@spec normalize_attrs(term(), [atom()], atom()) :: {:ok, map()} | {:error, reason()}
```

Normalizes map or keyword attributes and rejects unknown/duplicate keys.

# `normalize_refs`

```elixir
@spec normalize_refs(term(), atom()) :: {:ok, [String.t()]} | {:error, reason()}
```

Validates, de-duplicates and sorts a reference list.

# `ref`

```elixir
@spec ref(String.t() | atom(), term()) :: {:ok, String.t()} | {:error, reason()}
```

Short alias for `content_ref/2`.

# `resolve_content_ref`

```elixir
@spec resolve_content_ref(String.t() | atom(), nil | String.t(), term()) ::
  {:ok, String.t()} | {:error, reason()}
```

Computes a content reference and rejects a supplied reference that does not match it.

# `restore_canonical`

```elixir
@spec restore_canonical(
  term(),
  (term() -&gt; {:ok, term()} | {:error, reason()}),
  (term() -&gt; map()),
  atom()
) :: {:ok, term()} | {:error, reason()}
```

Restores a record only from the exact plain representation emitted by it.

Record constructors may accept atom-keyed maps, keyword lists and omitted
defaults for ergonomic in-memory construction. Durable decoding must be
stricter: accepting those alternate shapes would give one semantic record
more than one canonical byte representation and digest.

# `stringify_atom_keys`

```elixir
@spec stringify_atom_keys(term()) :: {:ok, term()} | {:error, reason()}
```

Recursively converts atom map keys to strings without changing atom values.

This is intended for portable, host-authored semantic maps whose ergonomic
atom and transport string spellings mean the same thing. It rejects a map
containing both spellings instead of silently choosing one. Other portable
key types are preserved.

# `validate`

```elixir
@spec validate(term()) :: :ok | {:error, reason()}
```

Validates a plain record value within the canonical codec's default resource limits.

# `validate_content_ref`

```elixir
@spec validate_content_ref(term(), String.t() | atom(), atom()) ::
  :ok | {:error, reason()}
```

Checks a `prefix:<lowercase sha256>` content-addressed reference.

# `validate_non_empty_binary`

```elixir
@spec validate_non_empty_binary(term(), atom()) :: :ok | {:error, reason()}
```

Checks a required non-empty binary field.

# `validate_optional_ref`

```elixir
@spec validate_optional_ref(term(), atom()) :: :ok | {:error, reason()}
```

Checks an optional opaque record reference.

# `validate_ref`

```elixir
@spec validate_ref(term(), atom()) :: :ok | {:error, reason()}
```

Checks an opaque record reference. References are non-empty binaries.

# `validate_refs`

```elixir
@spec validate_refs(term(), atom()) :: :ok | {:error, reason()}
```

Checks a list of opaque record references.

---

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