Skip to content
On this page

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

JSON
{
    "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:

  1. The AAD. Set id, ciphertext, sig.value and every recipients[*].wrapped_key to "", sort recipients[] by device_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.
  2. The id. With the ciphertext in place, set id and sig.value to "", canonicalize the same way, and SHA-256 the bytes. Hex-encode the digest: that is the envelope id.

The sender BIP-322-signs the id string with from.address and puts the result in sig.value.

Field semanticsLink to this section

FieldWhy
v2. Any change to the shape or canonicalization rule requires a new version.
kindidentity (sealed to device keys) or payment (sealed to a named relay, released on payment).
idContent-addressed identifier: SHA-256 of the canonical envelope with id and sig.value empty, hex.
algThe fixed suite: X25519, AES-256-GCM, HKDF-SHA256.
from.addressThe sender's Bitcoin address. Optional attestation_id names an OC attestation.
recipients[]One entry per recipient device, each with its own ephemeral key and wrapped content key. Sorted by device_id.
ciphertextAES-256-GCM over the payload with the content key, nonce_ct, and the AAD above.
nonce_ct12-byte nonce for the payload. Also the HKDF salt for every key-encryption key.
hintOptional plaintext, up to 200 bytes. Visible to anyone holding the envelope.
created_atISO 8601 UTC time of sealing.
expires_atISO 8601 UTC, or null.
paymentnull in identity mode; the amount, address, confirmations and relay in payment mode.
sigBIP-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:

  1. Check v === 2 and a known kind. Reject anything else.
  2. Reject an envelope whose expires_at has passed.
  3. Recompute the id (canonicalize with id and sig.value empty, SHA-256) and reject a mismatch.
  4. Check sig.pubkey === from.address and verify sig.value as a BIP-322 signature over id by that address. (A client MAY skip this for its own self-seals.)
  5. Find the recipient entry whose device_id matches the local device.
  6. Derive kek = HKDF(X25519(device_sk, eph_pk), salt = nonce_ct, info = "oc-lock/v2/kek:" || device_id).
  7. Decrypt wrapped_key with kek, nonce_kek and AAD device_id to recover the content key.
  8. Decrypt ciphertext with 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