Envelope format
OC Lock envelopes are JSON. They canonicalize via
RFC 8785 (opens in a new tab) (JSON Canonicalization
Scheme) with one spec-specific rule: the recipients[] array is sorted by
device_id lexicographically. The normative text is
§4 of the spec.
ShapeLink to this section
{
"v": 2,
"kind": "identity",
"id": "<32-byte envelope id, hex>",
"alg": { "kem": "x25519", "aead": "aes-256-gcm", "kdf": "hkdf-sha256" },
"from": {
"address": "bc1qalice..."
},
"recipients": [
{
"address": "bc1qbob...",
"device_id": "<recipient device id>",
"device_pk": "<X25519 public key, hex>",
"eph_pk": "<ephemeral X25519 public key, hex>",
"wrapped_key": "<AES-GCM(kek, nonce_kek, content_key), base64url>",
"nonce_kek": "<12-byte nonce, hex>"
}
],
"ciphertext": "<AES-GCM(content_key, nonce_ct, payload) + tag, base64url>",
"nonce_ct": "<12-byte nonce, hex>",
"hint": "<optional plaintext hint, <= 200 bytes>",
"created_at": "2026-04-24T06:47:29.977Z",
"expires_at": null,
"payment": null,
"sig": {
"alg": "bip322",
"pubkey": "bc1qalice...",
"value": "<BIP-322 signature over id, base64>"
}
}
CanonicalizationLink to this section
Two hashes come from the canonical bytes:
- The AAD. Set
id,ciphertext,sig.valueand everyrecipients[*].wrapped_keyto"", sortrecipients[]bydevice_id, apply RFC 8785, append LF, and SHA-256 the bytes. The payload is encrypted under this 32-byte digest as AES-GCM associated data. - The
id. With the ciphertext in place, setidandsig.valueto"", canonicalize the same way, and SHA-256 the bytes. Hex-encode the digest: that is the envelopeid.
The sender BIP-322-signs the id string with from.address and puts the result
in sig.value.
Field semanticsLink to this section
| Field | Why |
|---|---|
v | 2. Any change to the shape or canonicalization rule requires a new version. |
kind | identity (sealed to device keys) or payment (sealed to a named relay, released on payment). |
id | Content-addressed identifier: SHA-256 of the canonical envelope with id and sig. empty, hex. |
alg | The fixed suite: X25519, AES-256-GCM, HKDF-SHA256. |
from. | The sender's Bitcoin address. Optional attestation_ names an OC attestation. |
recipients[] | One entry per recipient device, each with its own ephemeral key and wrapped content key. Sorted by device_. |
ciphertext | AES-256-GCM over the payload with the content key, nonce_, and the AAD above. |
nonce_ | 12-byte nonce for the payload. Also the HKDF salt for every key-encryption key. |
hint | Optional plaintext, up to 200 bytes. Visible to anyone holding the envelope. |
created_ | ISO 8601 UTC time of sealing. |
expires_ | ISO 8601 UTC, or null. |
payment | null in identity mode; the amount, address, confirmations and relay in payment mode. |
sig | BIP-322 signature over id by the sender's address. Empty when the sender did not sign. |
Validation checklistLink to this section
A recipient validating an envelope MUST:
- Check
v === 2and a knownkind. Reject anything else. - Reject an envelope whose
expires_athas passed. - Recompute the
id(canonicalize withidandsig.valueempty, SHA-256) and reject a mismatch. - Check
sig.pubkey === from.addressand verifysig.valueas a BIP-322 signature overidby that address. (A client MAY skip this for its own self-seals.) - Find the recipient entry whose
device_idmatches the local device. - Derive
kek = HKDF(X25519(device_sk, eph_pk), salt = nonce_ct, info = "oc-lock/v2/kek:" || device_id). - Decrypt
wrapped_keywithkek,nonce_kekand AADdevice_idto recover the content key. - Decrypt
ciphertextwith the content key,nonce_ct, and the AAD above.
Skipping any step breaks the security model.
AAD and subject linesLink to this section
The AAD commits the payload to every plaintext field except the ones it replaces
with "": v, kind, alg, from, each recipient's identity and ephemeral
key, nonce_ct, hint, created_at, expires_at and payment. A sender that
wants a subject line visible before decryption puts it in hint. If anyone
changes the hint, or any other committed field, decryption fails with a GCM
auth-tag mismatch, and the id no longer matches the signature.
Canonical-bytes test vectorsLink to this section
oc-lock-protocol/test-vectors/ (opens in a new tab)
ships envelope fixtures (v01-minimal to v04-with-hint) and device-binding
fixtures. The reference impl in @orangecheck/lock-core passes those vectors on
every CI push. See conformance vectors.
See alsoLink to this section
- How it works — the four-step flow that produces this envelope
- Device keys — the X25519 keys the
recipients[].device_pkpoints at - Canonical message format — the line-format cousin used by other orangecheck protocols