# Wire input and receipt contract

Source: https://usecns.dev/hippocampus-topic-wire-input-and-receipt-contract/

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

`Binding` requires `controller`, `origin`, `receiver`, `archive`, `episode`, `bundle`, `enrollment_revision`. Supply it from trusted configuration, never infer authority from incoming metadata. Controller is 1–128 UTF-8 bytes without controls; receiver/archive are 1–64 ASCII alphanumeric/underscore/hyphen bytes; origin is 32 lowercase hex, episode/bundle 64 lowercase hex, revision positive `u64`. IDs are case-sensitive, not normalized paths or credentials.

`validate_ingress(metadata, body, &expected) -> Result<TransportVerified, WireError>` accepts strict JSON with exactly `kind: "hippocampus.ingress"`, `version: 1`, `archive_schema: 1`, `normalizer: 1`, `binding`, `body_sha256`, `body_length`. Required/unknown/duplicate fields, trailing JSON, wrong versions, mismatched binding/length/hash fail. Metadata is at most `MAX_METADATA_BYTES` (4096); unchanged borrowed body at most `MAX_BODY_BYTES` (64 MiB). The returned `body()`, `binding()`, `body_sha256()` mean transport checks only, not archive semantics, authorization or durable acceptance.

`verify_receipt(envelope, &verified_ingress, &pinned_key) -> Result<VerifiedReceipt, WireError>` verifies Ed25519 over exact decoded payload bytes; pin the 32-byte key independently. Envelope has only standard padded-base64 `payload_b64` and `signature_b64`. Limits: `MAX_RECEIPT_BYTES` 16 KiB and decoded `MAX_RECEIPT_PAYLOAD_BYTES` 8192. Required signed fields: `kind: "hippocampus.primary-acceptance"`, `version/archive_schema/normalizer: 1`, `binding`, `body_sha256`, `body_length`, `receipt_id`, `lifecycle_generation`, `lifecycle_sequence`, `committed_unix_ms`, `durability_profile`. Receipt/generation IDs are 32 lowercase hex; profile follows receiver-name grammar. Sequence/time are `u64` (wire allows zero). No canonicalization: changing JSON whitespace/key order changes signed bytes.

`VerifiedReceipt` exposes `payload()`, `binding()`, `receipt_id()`, `lifecycle_generation()`, `lifecycle_sequence()`, `committed_unix_ms()`, `durability_profile()`. It attests historical acceptance only: no freshness, current retention, erasure, legal authority or independently proven storage. `WireError` is content-free: `SizeLimit`, `InvalidMessage`, `UnsupportedVersion`, `BindingMismatch`, `BodyMismatch`, `InvalidSignature`, `ReceiptMismatch`. The single-key verifier checks no lifecycle policy; use the policy-aware API below for retired/compromised epochs. There is no embedded-key trust, general signing or operational key-custody API.

Practical exact-byte example (`tests/fixtures/wire-v1`, exercised by `tests/wire.rs`):

```
use hippocampus::wire::{validate_ingress, verify_receipt, Binding};
let expected: serde_json::Value = serde_json::from_slice(
    include_bytes!("tests/fixtures/wire-v1/expected.json"))?;
let trusted_binding: Binding = serde_json::from_value(expected["binding"].clone())?;
let hex = expected["public_key_hex"].as_str().ok_or("missing fixture key")?;
let key_bytes = (0..32).map(|i| u8::from_str_radix(&hex[2*i..2*i+2], 16))
    .collect::<Result<Vec<_>, _>>()?;
let pinned_key: [u8; 32] = key_bytes.try_into().map_err(|_| "invalid fixture key")?;
let body = include_bytes!("tests/fixtures/wire-v1/bundle.json");
let metadata = include_bytes!("tests/fixtures/wire-v1/ingress.json");
let ingress = validate_ingress(metadata, body, &trusted_binding)?;
let receipt = verify_receipt(
    include_bytes!("tests/fixtures/wire-v1/receipt-envelope.json"),
    &ingress, &pinned_key)?;
assert_eq!(receipt.binding(), &trusted_binding);
```

The snippet assumes a source at checkout root and a caller returning `Result<(), Box<dyn std::error::Error>>`; the test command above is the self-contained runnable version. Expected output is no error and a matching binding. This example pins the independently frozen **public test** vector, never an incoming envelope's key. Never reserialize `bundle.json` before verifying its frozen metadata/receipt.