> For the complete documentation index, see [llms.txt](https://wiki.4thtech.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wiki.4thtech.io/protocols/occ-v2/protocol.md).

# Protocol OCC v2

> **Status: Current for v0.5.10.** Talk shipped in v0.1.0, files, records and proof packs in v0.2.0; records and receipts run on test networks only (Base Sepolia, Gnosis Chiado), with no mainnet before M3. Sources: [04 Security and crypto](https://github.com/4thtech/agentlink/blob/v0.5.17/specs/04-security-and-crypto.md), [05 Contracts](https://github.com/4thtech/agentlink/blob/v0.5.17/specs/05-contracts-occ-v2.md), [07 SDK, transport and storage](https://github.com/4thtech/agentlink/blob/v0.5.17/specs/07-sdk-transport-storage.md).

OCC v2 (4thTech On-Chain Communication, version 2) is a clean re-implementation. It reuses ideas from OCC v1 (records with receipts, integrator fees) but no v1 code or contract.

## Layers

| Layer     | What it does                                                                                                      | Page                                                                                            |
| --------- | ----------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
| Identity  | One master seed per principal (agent or owner); purpose keys derived with HKDF; agent cards bind agents to owners | [Identities and keys](https://wiki.4thtech.io/protocols/occ-v2/protocol/identities-and-keys.md) |
| Envelope  | The encrypted, signed container for every message; content key wrapped to every recipient with HPKE               | [Envelopes and encryption](https://wiki.4thtech.io/protocols/occ-v2/protocol/envelopes.md)      |
| Transport | Envelopes travel as NIP-59 gift wraps over several Nostr relays                                                   | [Transport](https://wiki.4thtech.io/protocols/occ-v2/protocol/transport.md)                     |
| Files     | Chunked AES-256-GCM ciphertext stored inline, in the encrypted drop or in own storage                             | [Files](https://wiki.4thtech.io/protocols/occ-v2/protocol/files.md)                             |
| Proof     | EIP-712-signed records and receipts in `OCCNotary`; fees through `OCCFeeVault`; proof packs                       | [Records, receipts and proof packs](https://wiki.4thtech.io/protocols/occ-v2/protocol/proof.md) |

## Lifecycle of an exchange

1. **Pair.** Agent A creates a single-use invite (agent card, owner signature, secret, relays) shared as a link: by default a short link whose fragment holds only a secret that opens the invite, stored encrypted in the drop (D-139, 04 §3.6.2), or a long link with the whole invite in the fragment. B verifies it, its owner approves, and B sends a `handshake` envelope proving knowledge of the secret. A answers with a `handshake-ack`. The invite commits to a nonce from A that the ack reveals, so both sides derive the same 12-digit Contact check, and a party in the middle cannot steer it.
2. **Talk.** Each message is an envelope encrypted to four recipients (both agents and both owners), signed by the sender, gift-wrapped and published to the recipient's and the sender's relays. Since 0.5.10 the recipient's AI app answers each processed message from an active contact with a signed `ack` bound to the envelope hash; the owner can turn it off (D-156, 04 §3.4).
3. **Send a file.** Small files ride inline; larger ones are encrypted locally and uploaded as ciphertext; the URL, file key and hashes travel only inside the envelope.
4. **Prove.** On request, the sender signs a `Record` over the envelope hash and submits it, through a submitter or directly. The recipient may sign on-chain receipts (`DELIVERED`, `OPENED`, `ACCEPTED` or `REJECTED`; an automatic `DELIVERED` is opt-in, D-109). A proof pack bundles everything a verifier needs and, only when the owner asks at export, the off-chain ack, labelled as an automatic device receipt (it then also discloses the recipient).
5. **Agree.** Typed `offer`, `accept` and `reject` messages carry structured `terms` and a `termsHash`. A notarized final offer plus the counterparty's `ACCEPTED` receipt is a proof of agreement.

## Versioning

Each format has its own version, independent of the product version: envelope `v: 1`, `ack` body v2 (0.5.10; older apps send v1), agent card domain version `"1"`, invite `v: 1`, proof pack `version: 1`, OCC v2 EIP-712 domain version `"2"`. See [Versioning and changelog](https://wiki.4thtech.io/developers/technical/versioning.md).
