# Byte-format and conformance reference

`codec.ts` provides the stable `sitla-wire/1` restricted canonical JSON codec, root derivation, fixed DID-document reconstruction, Gregorian time checks, static record semantics and replacement-chain checks. That frozen descriptor remains version 1; the current descriptor/history use the separate version-2 profile. The reference code and `tests/` are **Apache-2.0**; see [the license](LICENSE) and the separate [specification patent grant](../PATENTS.md). Specifications, schemas and public vectors remain CC0-1.0. Existing application code is not relicensed.

The parser checks a 65,536-byte input limit and 32 container levels before JSON parsing; canonicalization also limits traversal to 10,000 nodes and the same byte/depth budget. Duplicate fields and alternate spellings are rejected by exact canonical-wire comparison. `parseTime` validates real calendar dates and UTC encoding. These concrete reference limits are not a universal deployment resource policy. A caller must enforce advertised budgets, deadlines, request rates and isolation; no wall-clock interruption, process sandbox, network policy, live status lookup, trust-anchor selection, clock assurance or replay store is implemented here.

`validateSemantics` requires prior JSON Schema validation. It is a static helper, not a complete authenticated service or cryptographic policy engine. `conformance.ts` validates fixed schemas/vectors with Ajv and Node crypto. Its fixture verification-key map is trusted test input, never an operator-discovery or issuer-trust mechanism. Runtime clients must validate authorization scopes, key histories, current epochs/status, signature suites, content/amount/terms digests and user permissions independently before an effect.

The files use erasable TypeScript. Node.js 26 can import `codec.ts` directly without compilation or separate declaration files. From this repository, `node --input-type=module -e 'import { canonical } from "./reference/codec.ts"; console.log(canonical({ version: 1 }))'` works without the application repository. Install the locked development dependencies with `npm ci --ignore-scripts` before running `npm test`. The independent Python test uses `dilithium-py`, `jsonschema` and `cryptography` and imports no TypeScript code. Dependency versions are pinned in `tests/requirements.txt`. No private signing key is distributed.

`webauthn.ts` verifies the named ES256 approval profile using independently enrolled RP credentials and the original clientDataJSON bytes. It does not perform browser enrollment, attest hardware, provide an approval UI, maintain a replay/counter/epoch database or execute payments. Those remain authenticated RP duties. The JSON DID adapter explicitly rejects JSON-LD representation requests.

`policy_digest` and operator policy references hash exact resource bytes, including whitespace/newlines; fixture policy bytes are published under `artifacts/wire-v1/policies/`. Wire records use `sitla-wire/1`, stable native contexts such as `SITLA/root/1`, and stable approval/service domains. Prose revision 0.17 is documentary metadata, not a signature invalidation switch. Legacy v0.1/v0.2 fixtures retain their original contexts and byte identities.

Run `npm run test:mutation` for targeted guard-removal checks, independently of `npm test`. The mutation runner imports each temporary mutant before testing so syntax/import failures cannot masquerade as detected security omissions. It checks the core guards and the named payment, circulation and history supplements; see the current total in the repository README. This is not exhaustive or a production-verifier claim.

CI installs Python verification dependencies from `tests/requirements.lock` with `--require-hashes --only-binary=:all:`. The lock includes official PyPI wheel hashes for every pinned dependency; `tests/requirements.txt` is the readable version list. Regenerate and review hashes when changing dependency versions.

`account-id.ts` keeps the legacy combined subject checker and adds recommended `sitla-account/1` account bindings and historical `sitla-account-handle/1` subject checkers (not a current issuance capability). Base identity contains no handle/display-name fields. These helpers check unsigned shapes/identifier relationships only, not issuer proof, current assignment status, QR routing, reservation storage or account authorization.

`lifecycle.ts` validates the separate `sitla-account-lifecycle/1` request/receipt contract and an accepted-key Ed25519 receipt signature. Trusted context comes from the host, not request JSON. It does not authenticate users, approve deletion, maintain a token/mandate store, interrupt jobs, settle payments, purge storage or prove erasure. Its signed fixtures are synthetic operator assertions only.

Verification scope: Node and the independently written Python code verify wire/1 and the supplemental synced-passkey records. Python additionally checks unsigned account subjects/transitions and synthetic signed lifecycle receipts with adversarial cases. These are repository-maintained implementations, not third-party Rust/Go reproduction, a complete signed account-VC verifier, a live uniqueness registry, a browser/hardware certification or actual revocation/deletion. `webauthn_origin_missing` distinguishes absent client origin from `webauthn_origin` (unaccepted origin) and `webauthn_cross_origin` (cross/top-origin context).

`payments.ts` supplies the optional online/Stripe payment-subject, operator-JWS, historical Ed25519 approval and evidence-page checks. See [the exact public artifact scope](../pages/protocol-payment-wire.md). It reuses restricted canonical bytes but does not modify frozen wire/1. Its `sitla-online-account` grant semantics belong to this adapter; public fixtures do not verify live provider execution, current epochs/status, passkey payment attachment envelopes or complete history. Original Ed25519 holder evidence and native ML-DSA grants are separate from the classical server-issued VC. `tests/verify_payments.py` independently checks the CC0 fixture set in existing CI. Regenerate synthetic payment data manually with Node 26 `node tests/generate-payments.ts`; never publish signing keys.

`counterparty-history.ts` publishes the request and signed-payload types for the optional transaction-scoped summary. It supplies no public reputation registry, provider API client or independent dispute-state verifier. Application tests, rather than the public wire/1/payment fixture counts, cover live MCP access and retained provider-history aggregation.

## Selective disclosure circulation

`sd-jwt.ts` verifies the restricted `SITLA-sd-jwt/1` issuer-signature/disclosure profile with native Node Ed25519. It has no network access and does not accept an issuer as trustworthy, resolve root authority, verify fresh holder possession or fetch status. `artifacts/circulation-v1/vectors.json` contains nonpersonal public fixtures, not issuer private keys. Node and `tests/verify_sd_jwt.py` independently reproduce two positive and four negative fixtures. This limited fixture coverage is distinct from legacy wire/payment conformance and from live MCP integration tests.

## DID history specification boundary

The [current DID-history contract](../pages/protocol-did-history.md) requires public license metadata and a `history` container. `codec.ts` reconstructs only its immutable root projection; it is not a current full-document verifier. Existing key-replacement vectors verify component rules, not complete document history, dual-root transitions, latest-state discovery or atomic retained-head/conflict behavior. The current standalone history verifier and signed Node/Python corpus verify that contract separately; neither component fixtures nor that corpus certify a complete wallet or a global latest-state oracle.

`did-history.ts` is the standalone current Node verifier and retained-state reducer. It loads the four `did-history-v2` schemas, verifies native ML-DSA contexts, optional next-root commitment, complete scoped chains, terminal revocation and dual-root links. It keeps acceptance/freshness separate, and its reducer rejects rollback/genuine forks while refusing a signature-only mismatch without a sticky conflict. The host must serialize/atomically commit returned state; this library does not supply a database, remote lookup, issuer trust or latest-head oracle. Python `verify_did_history.py` independently reproduces the signed cases. Native profile signing must be deterministic; a single public signature alone cannot prove how signing randomness was chosen.
