<!-- Apache-2.0 -->
# receipt/v1 — Action Receipt Specification

Status: NORMATIVE v1 (implemented by `core/receipt.py`; test vectors in `tests/`)

## 1. Overview

A **receipt** is a signed, canonical statement by its signing key about an
action. Receipts are the atom of evidence: they are what gets logged, proven,
exported, and verified. A valid receipt proves the integrity and attributed
signature of the recorded bytes under the supplied trust material. It does not
independently prove that the action occurred, that capture was complete, or
that the recorded payload was truthful.

## 2. Encoding

- Body: JSON, canonicalized per **RFC 8785 (JCS)**. All hashing and signing
  operate on canonical bytes. Two semantically equal bodies MUST produce
  identical bytes.
- Envelope: **DSSE** (`payloadType` + base64 payload + signatures), with
  PAE = `"DSSEv1" SP len(type) SP type SP len(body) SP body`.
- `payloadType` MUST be `application/vnd.evd.receipt.v1+json`.
- Signature algorithm: **Ed25519**. `keyid` = base64url(SHA-256(raw public
  key))[:16] — deterministic from key material; verifiers MUST reject a JWK
  whose `kid` does not match its key.
- The algorithm MAY be named explicitly by the optional body member `alg`
  (see §3). Its **absence means `EdDSA`**, so every receipt written before
  this member existed keeps its exact bytes and its exact verdict.
- **Signature members (normative).** A signature object carries exactly
  `keyid`, `sig`, and OPTIONALLY `alg`; every value MUST be a string. A
  verifier MUST reject a signature object carrying any other member, and MUST
  NOT ignore one. This is stated because ignoring an unrecognised member is
  precisely how a named algorithm becomes meaningless: a claim nobody reads is
  not a claim.
- **Signature-object `alg` (normative, optional).** Names the algorithm of that
  one signature. The only value implemented is `"EdDSA"`. **Absence means
  `"EdDSA"`**, so every receipt issued before this member existed keeps its
  verdict unchanged, and this is a pure addition. A verifier encountering any
  other value MUST return NOT_VERIFIED. It MUST NOT verify the signatures it
  understands and report success — there is no "verified except for the parts
  we did not understand". The identifier is the JOSE/COSE name `EdDSA`,
  matching the `alg` this repository already writes into a JWK and already
  enforces in its key log — **not** the prose name `Ed25519` used above for the
  curve — and exactly one spelling is accepted in this member, so that a
  verifier cannot accept a second one by accident. Unlike the body `alg` (§3),
  this member sits outside the DSSE PAE and is covered neither by the
  signature nor by `receipt_hash`; because its only accepted value is
  equivalent to its absence, it can turn a signature into a refusal but can
  never make one verify. The two members are independent but share one
  accepted spelling, `"EdDSA"`, in the body and on a signature object; a
  receipt carrying both MUST satisfy both.
  *Out of scope: implementing any further algorithm. This ships the ability to
  NAME the algorithm and to REFUSE an unknown one; a classical + PQ hybrid is a
  later format change, and it does not change what an unknown name means here.*

**Size cap (normative).** The RFC 8785 canonical body MUST NOT exceed
**8192 bytes**. Producing an oversize receipt is a producer-side error:
producers MUST refuse to sign it (receipts are metadata; anything bigger is
payload smuggling). Verifiers do NOT enforce the cap — existing logs may
legally contain historic receipts, and the verifier judges signatures and
proofs, not the producer's budget.

## 3. Body fields (all REQUIRED)

| Field | Type | Meaning |
|---|---|---|
| `schema` | string | `"evd/receipt/v1"` |
| `tenant_id` | string | issuing tenant |
| `agent_id` | string | acting principal, registered per tenant |
| `seq` | int | per-`(tenant, agent)` monotonic counter in `1..2^53-1` (the exact RFC 8785/JCS integer domain), starting at 1. A gap is evidence of a missing receipt — the system is honest about its own holes |
| `action_type` | string | namespaced, e.g. `llm.chat`, `tool.call`, `payment.execute` |
| `commitments` | object | field → hex commitment (see §4) |
| `context` | object | non-secret metadata (model ref, endpoint, status). MUST NOT contain payloads |
| `parents` | array | receipt hashes of causal parents (the receipt DAG; session → step → tool call) |
| `ts_client` | string | RFC 3339 UTC, client clock |
| `ts_server` | string | RFC 3339 UTC, log clock |
| `idempotency_key` | string | client-chosen; the log deduplicates on `(tenant_id, idempotency_key)`, first write wins |

Signed timestamps use exactly canonical extended UTC:
`YYYY-MM-DDTHH:MM:SS[.1..6 fractional digits]Z`. Basic dates, ISO week dates,
space separators, offsets, impossible calendar dates, leap seconds, and more
than six fractional digits are invalid. This fixed form makes chronological
comparison identical across verifier implementations.

The member set is closed. The eleven fields above are required; the additive
`session_id` (non-empty string) and `session_inferred` (boolean) fields may
appear only as a pair, and the additive `alg` field may appear alone.

**`alg` — explicit algorithm identifier (normative).** `alg` names the
signature algorithm of the receipt. It is OPTIONAL, and its absence means
exactly `"EdDSA"` — the JOSE/COSE name used on a signature object (§2), and
the only value either verifier recognises today. If present it MUST be the
string `"EdDSA"`; a receipt whose `alg` is any other value — including the
curve name `"ed25519"` in any case — or is not a string, is
**NOT_VERIFIED**. This is a fail-closed rule, not a warning: a verifier MUST
NOT ignore an algorithm it does not understand, and MUST NOT report a
receipt as verified except for the parts it could not interpret. Because
`alg` lives in the signed body it is covered by the DSSE signature and by
`receipt_hash`, so it cannot be added, removed, or edited in transit. v1
ships the *ability to name* the algorithm and to refuse an unknown one;
introducing a second recognised value is a future format change.

Identity strings are non-empty and `action_type` is a
lowercase namespaced string. `commitments` maps non-empty names to lowercase
SHA-256 hex, `context` is an object, and `parents` contains at most 32 distinct
lowercase receipt hashes. Every receipt's `tenant_id` MUST equal the final
tenant component of the signed checkpoint/log origin that covers it.

**`receipt_hash`** = SHA-256(canonical body), lowercase hex. This value is
the Merkle leaf (see log-v1) and the value `parents` references.

## 4. Commitments

`commitment = SHA-256( domain ‖ 0x00 ‖ nonce ‖ 0x00 ‖ payload )`, hex.

- `domain` MUST begin with `evd/v1/` (domain separation: a prompt commitment
  can never be replayed as an output commitment).
- `nonce` MUST be ≥ 16 random bytes (32 recommended), held by the client
  (edge shape) or a nonce vault. Prevents dictionary attacks on
  low-entropy payloads.
- Payloads never enter receipts, the log, or bundles. **Selective
  disclosure** = revealing `(payload, nonce)` to a chosen party, who
  recomputes the commitment.
- Streaming: producers MAY compute the commitment incrementally
  (`domain ‖ 0x00 ‖ nonce ‖ 0x00` then chunks); the result MUST equal the
  one-shot computation.

## 5. Signatures & cumulative independently rooted dual attestation

An envelope carries 1..n signatures over the same PAE bytes:

- **E0/E1 and carried anchor/timestamp material**: the log's issuing key (per
  tenant). This signature alone never earns E2; only a covering checkpoint
  successfully re-read by the Evidence Report's explicit live mode **and** a
  timestamp chain ending at a relying-party-supplied root can do so.
- **dual-attestation wire shape**: additionally, an edge-recorder key held at
  the *customer's* edge. Verifiers checking that shape MUST require both
  `keyid`s. An E3 award requires every E2 condition and additionally requires
  the relying party to supply the recorder key out of band. Keys carried in
  the same bundle do not
  independently establish counterparty identity or control merely because
  both signatures verify.
  Neither party alone can then forge or repudiate a receipt.

**Which kid is which, and the flow (normative):**

1. **Registration** — the recorder key is generated at the customer edge
   (file-based in v1; KMS is a post-gate increment) and enters the tenant
   log as a SPONSORED `evd.key.created` entry (log-v1 §5): the entry is
   signed by the tenant ISSUER key and carries `context.role="recorder"`.
   Registration requires the tenant's admin API credential; that credential
   never runs in the recorder. Until registered, the hosted side rejects the
   recorder's uploads (HTTP 403) — they wait in the edge spool.
2. **Capture** — the recorder signs each receipt with the RECORDER key
   (primary signature) and spools locally. Payload bytes, nonces, and vault
   content NEVER leave the edge on the evidence plane; envelopes carry
   commitments only (the sentinel test enforces this).
3. **Ingest** — `POST /evd/ingest`. This is a narrow managed-recorder
   admission boundary, never a generic receipt append API. The hosted side
   applies the ordered law below and only then COUNTER-SIGNS with the tenant
   issuer key and appends. The appended envelope carries the edge and issuer
   signatures.
4. **Verification rule (amended for relying-party-rooted evidence levels)** —
   the in-log rule above is the
   NECESSARY half: `verify_envelope(env, log_keys, require_kids={issuer_kid,
   recorder_kid})` with both kids drawn from the LOG's key history (log-v1
   §5) and valid at the receipt's `ts_server`. It is never sufficient for an
   E3 AWARD, because E3 is cumulative on E2 and the log is the subject's own
   artifact — the subject's
   log vouching for the subject's recorder is the defect the 2026-08-03
   audit withdrew. An E3 award requires every E2 condition and additionally
   requires the co-signature bytes to verify under a recorder key the RELYING
   PARTY supplied out of band (`trust["recorder_keys"]`, keyed by kid), the
   co-signing kid to be an active NON-ISSUER key registered with the
   `recorder` role in the replayed log, and an issuer signature beside it. A
   verified recorder attestation without E2 remains an inspectable fact and
   never awards E3. This recorder-attestation fact proves possession of the
   exact relying-party-named recorder key; it does not by itself prove legal,
   organisational, or operational independence between the signers. E3 is a
   post-action evidence level, separate from the Counterparty Assurance
   handshake; neither the fact nor the level supplies a Counterparty Assurance
   authority or
   replay verdict.

**Legacy privileged-co-signature rule.** Offline verifiers MUST reject a
multi-signed receipt when `agent_id` begins `_`, or when `action_type` begins
`evd.key.`, `authority.`, `source.`, `action.`, `lineage.`, `node.`,
`evd.finding.`, `evd.gap.`, `evd.coverage.`, or `registration.`. These
namespaces drive key, authority, or other privileged replay and their
legitimate builders are issuer-only; an edge+issuer shape proves exposure to
the superseded generic managed-ingest path. This forensic rule deliberately
does not invalidate historical multi-signed `x.*`/custom evidence. Such leaves
remain evidence, while the managed upgrade audit may flag them as outside the
current positive admission profile. `interaction.message` remains an admitted
bilateral action.

**Ordering** — the recorder assigns per-agent monotonic `seq` at the edge;
the durable journal/spool preserves accepted capture order and `sync()` stops at
the first failure, so hosted leaf order matches that accepted sequence.
Concurrent sync calls serialize, and a receipt appended while a sync is awaiting
ingest MUST remain after that sync removes its successfully delivered prefix.
Bounded-storage/reserve refusal is an explicit cannot-retain gap, not a
losslessness claim.
`ts_server` is the recorder-observed capture time (the server side of the
customer's local relay), not managed-ingest arrival time; this preserves the
truth of receipts that remain offline in the spool before upload.

### 5.1 Managed ingest admission law

The following checks occur in this order. A rejection is a 4xx response and
MUST NOT add an issuer signature, append a leaf, or alter key, authority,
registration, lineage, Node, finding, or coverage state.

1. **Authenticate and stream-bound.** Resolve `x-api-key` to exactly one tenant
   and require its exact `recorder` role before opening a tenant store. The
   admin credential returned by signup is rejected here, and the recorder
   credential is rejected by every admin/console/portal/OTel route. Stream the
   HTTP request through a **16,384 byte** hard limit before JSON parsing; both
   declared and chunked overflows return 413.
2. **Parse the exact upload profile, before cryptography.** The request is
   exactly `{ "envelope": ... }`; the DSSE envelope has exactly `payload`,
   `payloadType`, and `signatures`; `payloadType` is the receipt/v1 media type;
   base64 is canonical; duplicate JSON keys are forbidden; and the decoded
   payload is at most **8192 bytes**. The payload MUST already be the RFC 8785
   canonical bytes of one `evd/receipt/v1` body with the required §3 fields
   and their declared types (plus only the additive `session_id` /
   `session_inferred` pair). `seq` is in `1..2^53-1`. An upload carries **1..7
   distinct 64-byte Ed25519 recorder signatures**. The verifier-wide cap is
   **nine**: the managed issuer appends its current signature and, only during
   the signed bounded issuer-rotation overlap, its immediately preceding
   issuer signature. No edge upload may consume either issuer slot.
3. **Bind tenant and constrain the edge role.** The signed `tenant_id` MUST
   equal the tenant authenticated by the API key. `agent_id` MUST NOT begin
   `_`. The managed edge action profile is a positive allow-list:
   `llm.chat`, `tool.call`, `data.read`, `payment.execute`,
   `interaction.message`, `policy.decision`, `guardrail.blocked`,
   `human.approve`, `human.override`, `human.reject`,
   `human.escalation_timeout`, `agent.deployed`, `agent.config_changed`,
   `agent.tool_granted`, and `agent.revoked`. Every other
   namespace is denied until explicitly admitted; in particular `evd.key.*`,
   `authority.*`, `action.*`, `source.*`, `registration.*`, `lineage.*`,
   `node.*`, and `passport.*` are internal producer paths and can never arrive
   through an edge upload. Plaintext `context` keys MUST be a subset of the
   selected action's `context-v1` dial plus the four universal lineage /
   correlation keys; an undeclared key is rejected as payload smuggling.
   Values are also schema-checked: universal IDs and ordinary declared fields
   are strings; `requested_tool_names` / `arg_keys` are arrays of strings;
   declared booleans are JSON booleans; counters/durations are nonnegative
   int64 values (never booleans); `status` is a string or nonnegative int64.
   The frozen bands and `result_kind` use the exact `context-v1` enums. Nested
   objects and arrays on scalar fields are payload smuggling and are rejected.
4. **Resolve idempotency under the tenant store lock.** Reusing an
   `idempotency_key` for different payload bytes is 409. An exact retry is
   acknowledged with the already-stored leaf index and payload hash only when
   its edge signature list exactly matches the stored envelope before the
   final issuer signature. It consumes no quota and is still acknowledged
   after prospective recorder-key revocation: no new claim is being admitted.
   A matching unfinalized quota reservation is reconciled best-effort; control
   DB failure MUST NOT withhold the 200 for an already-durable tenant leaf.
5. **Authenticate every signature for a new leaf.** Every uploaded signature
   MUST be valid over the PAE bytes under a distinct, currently active key in
   this authenticated tenant's key log whose signed key-creation event carries
   `role="recorder"`. Unlabelled historical keys and issuer keys are not
   recorders. One valid signature never masks an unknown, malformed, revoked,
   unlabelled, issuer-role, or invalid extra signature.
6. **Reserve and append once.** Before quota, reject an already-recorded
   `(agent_id, seq)` with 409. Only a genuinely new, fully admitted leaf takes
   one tenant receipt quota unit. The control plane atomically creates a
   durable `(tenant_id, idempotency_key, receipt_hash)` reservation and debit;
   an exact retry reuses it, a different hash is 409, and exhaustion is 429.
   If quota remains, and only then, the hosted issuer counter-signs and appends
   while the tenant store lock is held, then finalizes the reservation. A
   signer/append failure or process loss can leave one conservative reservation
   but can never double-debit its retry.

These failures are fail-closed for evidence admission but remain fail-open for
the business action: the recorder returns the upstream response, keeps the
signed receipt in its durable ordered spool, and retries without fabricating a
successful evidence write.

**Managed migration.** A fresh signup returns `api_key` (admin) and
`recorder_api_key` (ingest only). Existing recorder deployments MUST move the
runtime `EVD_API_KEY` to the secret returned once by admin-authenticated
`POST /evd/api-keys/recorder`; issuance atomically revokes that tenant's prior
recorder API credentials. They MUST also register a NEW edge signing key
through the admin-authenticated `/evd/keys/register` route. Historical
unlabelled keys are intentionally not inferred to be recorders.

`GET /evd/ingest/keys` accepts only that exact recorder credential and returns
the authenticated tenant id, active public keys whose immutable key-log event
explicitly grants `role="recorder"`, and known permanently ineligible kids.
Recorder sync MUST validate the exact response schema, tenant binding, JWK kid
derivation, and every spooled DSSE signature before using this view. This lets
K1-signed spool entries drain after a local move to registered K2 while K1 is
still active. Unknown kids remain spooled pending registration; a known
unroled/revoked kid may be durably quarantined. Managed ingest MUST repeat all
§5.1 tenant, role, profile, and cryptographic checks; discovery is a safe local
replay decision, never admission authority.

## 6. Verification (normative for verifiers)

1. `payloadType` is exactly the receipt type; envelope has ≥1 signature.
2. Every signature verifies over PAE(payloadType, payload) with a key whose
   `kid` matches its material. Unknown `kid` ⇒ FAIL (no unsigned-key
   tolerance).
3. The complete closed body profile in §3 is valid, including tenant binding
   to the signed checkpoint/log origin.
4. `receipt_hash` is recomputed from payload bytes — never trusted from
   context.
5. Inclusion in the log is checked per log-v1 §4 using the recomputed hash.

**Ed25519 strictness (decided, not accidental)** — both shipped verifiers
deliberately use *non-strict* Ed25519 verification: the Python verifier via
`cryptography` (OpenSSL's RFC 8032 check) and the Rust verifier via
`ed25519-dalek`'s `verify` (not `verify_strict`). This guarantees the two
implementations accept exactly the same signature set, so a bundle can never
verify under one verifier and fail under the other. The extra canonicity
rejections of strict mode buy nothing here: `receipt_hash` commits to the
payload bytes alone (rule 4) and signatures are attached, never hashed, so
signature malleability cannot alter what a receipt proves.
