Tamale.Digest (tamale v0.1.0)

Copy Markdown

Canonical digests — the portable replacement for BEAM-specific term_to_binary hashing. Spec: docs/spec/canonical-digest.md.

A canonical term is nil, a boolean, an integer, a UTF-8 binary, a list of canonical terms, or a map with binary or atom keys whose values are canonical terms. Anything else — floats, tuples, structs — is rejected: adapting domain values into canonical form is the channel adapter's job (normalization per docs/decisions/0005 — Decimal strings, frame indices, ...), not the kernel's. Rejecting floats at this boundary is what keeps that adapter obligation honest.

The digest is the lowercase hex of sha256(canonical_encoding(term)), so any language can reproduce it — that is what lets Tamale.Patch join the conformance vectors.

Summary

Types

A term the kernel can digest without adapter help.

Functions

Lowercase hex of sha256(canonical_encoding(term)).

The canonical byte encoding of a term (exposed so the spec and the conformance vectors can pin the encoding itself, not just the digest).

Types

canonical()

@type canonical() ::
  nil
  | boolean()
  | integer()
  | binary()
  | [canonical()]
  | %{optional(binary() | atom()) => canonical()}

A term the kernel can digest without adapter help.

Functions

digest(term)

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

Lowercase hex of sha256(canonical_encoding(term)).

encode(term)

@spec encode(term()) :: {:ok, iodata()} | {:error, term()}

The canonical byte encoding of a term (exposed so the spec and the conformance vectors can pin the encoding itself, not just the digest).