# Synthetic receipt-signing-key lifecycle

Source: https://usecns.dev/hippocampus-topic-synthetic-receipt-signing-key-lifecycle/

[Start here](https://usecns.dev/manual-hippocampus/)
[CLI commands](https://usecns.dev/commands-hippocampus/)
[Configuration & integration](https://usecns.dev/hippocampus-topics/)

This library-only surface changes **local trust policy**, not archive/ingress/receipt-v1 bytes, TLS enrollment, capabilities, collector configuration or CLI commands. Eight fixed publicly forgeable TEST Ed25519 keys occupy lifetime slots 0–7. Slot zero preserves the legacy RFC8032 vector; `synthetic_receipt_key(slot) -> Result<[u8; 32], WireError>` and `synthetic_receipt_key_id(slot) -> Result<String, WireError>` return fixed public bytes and their lowercase SHA-256 identifier. Unsupported slots fail. No key is imported, advertised by a receipt or learned over HTTP.

`ReceiptKey { slot, start_sequence, end_sequence, status }` uses a start-inclusive/end-exclusive lifecycle sequence interval, not wall-clock time. `ReceiptKeyStatus` is `Active`, `Retired` or irreversible `Compromised`. `ReceiptPolicy { controller, receiver, archive, generation, keys }` fixes trusted receiver scope, with 1–8 unique slots, no overlapping nonempty intervals and at most one active signer (zero is allowed). Starts are positive; starts/ends are bounded by signed-64-bit maximum. Active has no end, retired requires an end; an empty `[start,start)` bootstrap epoch is valid. History cannot be pruned, reused, reopened, remapped or extended after ending.

Pure policy methods do no I/O and authorize nothing by themselves; fallible methods return `WireError`:

| Method | Contract |
| --- | --- |
| `ReceiptPolicy::legacy(controller, receiver, archive, generation)` | Construct slot 0 active from sequence 1; call `validate()` before trusting caller-supplied values. |
| `validate()` | Check bounded scope/keys/status/interval invariants. |
| `validate_transition(&prior)` | Also preserve scope, existing slots/starts/ended intervals and irreversible retirement/compromise. |
| `rotate(slot, fence)` | Return new policy retiring current active at fence and starting an unused slot there; validate transition. |
| `compromise(slot, fence, replacement: Option<u8>)` | Mark key compromised, closing an active epoch at fence; optional unused replacement becomes active at fence. Compromising a retired key preserves its original interval. Omitting replacement may leave zero signers. |

`verify_receipt_with_policy(envelope, &verified_ingress, &policy) -> Result<PolicyVerifiedReceipt, WireError>` checks unchanged bounded receipt schema/signature, exact ingress scope/bytes, policy generation and signer sequence interval. It tries the at-most-eight independently provisioned fixed public keys, requiring one matching signer; no embedded key ID is needed or accepted. `PolicyVerifiedReceipt { receipt: VerifiedReceipt, signer_slot, signer_key_id, verification }` reports `ReceiptVerification::{Trusted, Compromised}`. A retired in-range signature remains trusted historical evidence; a compromised in-range signature yields `Compromised`, **not an error or authorization to acknowledge pending work**. Out-of-range/unknown signatures fail. Explicit single-key `verify_receipt` remains available but cannot enforce these lifecycle decisions.

Receiver controls return `ReceiptPolicySnapshot { revision, policy }`:

| Receiver method | Durable contract / errors |
| --- | --- |
| `receipt_policy()` | Read current scope-bound snapshot; no discovery or policy mutation. |
| `rotate_receipt_key(expected_revision, expected_fence, slot)` | CAS revision plus **exact next lifecycle sequence** fence. Commit policy revision + lifecycle sequence together; retired history/receipt bytes stay exact. |
| `compromise_receipt_key(expected_revision, expected_fence, slot, replacement)` | Same atomic fence/CAS; irreversible compromise with optional replacement. Audits all saved receipts, including erased payload rows, before either control commits. |
| `open_with_receipt_floor(root, &identity, minimum_lifecycle_sequence, minimum_receipt_revision)` | Enforce independently retained lifecycle and receipt-policy floors before normal audit/recovery. `open` supplies receipt floor zero and makes no receipt-policy rollback claim. |

Revision starts at 1. Current identical state is a no-op **after** revision checking; stale CAS is denied, wrong next fence is `LifecycleMismatch`, invalid slot/transition is denied, corrupt saved receipts fail integrity, bounds can fail quota. Read/reconcile state after uncertain controls before retry. A fence consumes one lifecycle sequence: bootstrap rotation at fence 1 means first new acceptance is sequence 2. Supply the fence from independently trusted lifecycle state, not merely receipt time or policy revision. Serialized policy bytes are bounded to 16 KiB; eight lifetime slots are never evicted. Controls work at payload saturation.

No active signer denies **new acceptance before staging/recovery touches payload storage**, but authorized historical replay/lookup, suppression, TLS credential controls and advisory capabilities remain available. Historical receipts are never re-signed or rewritten; compromise does not recall earlier acceptance. Receiver structural audits can retain compromised history without treating it as acknowledgment trust.

Sender `receipt_policy()` returns its own durable snapshot. `set_receipt_policy(expected_revision, independently_authorized_policy)` validates immutable destination scope, irreversible transition and every saved receipt before atomic revision update (16 KiB saved-policy ceiling). Stale revision is `Conflict`, invalid policy/scope/transition is `InvalidSetup`, receipt inconsistency is integrity failure. Current identical policy is a no-op after CAS checking. Receiver and sender policy revisions are independent counters; never copy revision numbers as if they were one authority. `open_with_receipt_floor(root, &setup, min_receipt_revision)` refuses a lower saved policy; ordinary `open` supplies zero. Legacy sender schema 1 upgrades atomically to schema 2 with slot-zero policy revision 1 while preserving jobs/receipts; partial/malformed/current missing policy refuses, not rebootstrap.

HTTPS `client.with_receipt_policy(policy) -> Result<Self, TransportError>` installs an independently authorized scope-bound snapshot; invalid/mismatched policy is `InvalidConfig`. `new` alone is explicitly legacy-slot-zero-only. Both `send` and `lookup` require `Trusted`; compromised evidence fails `InvalidEvidence`. A stale HTTPS snapshot can still validate an old signature, but cannot override the sender's current durable policy. Capabilities/GET/PUT never enroll or synchronize receipt trust. Loss of independent policy floors alongside catalogs is undetectable coherent rollback, not supported restore.

Practical synthetic cutover: independently prepare `legacy_policy.rotate(1, fence)?`; explicitly authorize/install that value with `sender.set_receipt_policy(sender_revision, policy.clone())?` and construct HTTPS client with `.with_receipt_policy(policy.clone())?`; separately authorize `receiver.rotate_receipt_key(receiver_revision, fence, 1)?`. Do not derive trust automatically from receiver responses. Pause attempts while coordinating this caller-owned cutover: stale peers may refuse without changing pending bytes. Preserve returned independent floors. A retired key's prior lost receipt can still reconcile; compromising that signer instead blocks pending acknowledgment, while previously accepted jobs stay terminal and expose the changed verdict.

Runnable public-interface examples and refusal tests (isolated synthetic fixtures only):

```
cargo test --locked --test wire independently_frozen_public_key_corpus_and_exact_sequence_boundaries
cargo test --locked --features synthetic-receiver --test receiver receipt_rotation_exact_fence_cas_retired_replay_and_new_signatures
cargo test --locked --features synthetic-sender --test sender independently_prepared_rotation_accepts_new_key_and_replays_old_exact_receipt
cargo test --locked --features synthetic-https --test transport receipt_no_signer_refuses_before_staging_without_disabling_independent_controls
```

`receipt-key-lifecycle.json` freezes eight OpenSSL-derived keys/signatures and eight exact sequence-boundary cases independently of the Rust signer. The existing legacy vector/example remains unchanged. Full fault-feature tests additionally cover atomic policy/schema commits, stale callbacks and independent floors. An early credential refusal can surface as client `Connection` if TLS closes before the empty 403 arrives; tests separately assert server denial and no unauthorized acceptance. Neither error implies unsent bytes or permission to reclaim evidence.