Specification
Status: stable · Version: 2.4 · Supersedes: LOCK v1.0 (adaptor signatures), v1.1 (Proof-of-Access)
This page summarises the OC Lock specification. The normative text is
SPEC.md (opens in a new tab)
in oc-lock-protocol. Where this page, SPEC.md and the
reference SDK (opens in a new tab) disagree, SPEC.md
wins.
§0 NotationLink to this section
- Bytes are lowercase hex unless marked
base64url. ||denotes byte concatenation.KDF()is HKDF-SHA256 per RFC 5869.AEAD()is AES-256-GCM per NIST SP 800-38D (12-byte IV, 16-byte tag).ECDH(k, P)is X25519 per RFC 7748 (output 32 bytes).BIP322(addr, msg)is a BIP-322 signature, encoded as base64.- Canonical JSON is UTF-8, lexicographically-sorted keys, no insignificant whitespace, LF-terminated. See §5.
§1 ActorsLink to this section
- Sender — the party creating a vault.
- Recipient — the party able to unseal the vault.
- Device — a browser or app instance holding a device keypair bound to a Bitcoin identity.
- Directory — a Nostr relay (or set of relays) storing device records.
- Relay (optional) — a server holding payment-gated content keys, releasing them upon observing qualifying Bitcoin payments.
Sender and recipient may be the same person (self-vault).
§2 IdentitiesLink to this section
An OC identity is the pair (btc_address, attestation_id) where:
btc_addressis a mainnet Bitcoin address (P2WPKH, P2SH-P2WPKH, P2TR, or P2PKH)attestation_idis the SHA-256 of a canonical orangecheck message signed by that address
A recipient MUST have an OC identity known to the sender. OC Lock does not publish recipient pubkeys; it publishes device keys addressable by the recipient's Bitcoin address.
§3 Device keysLink to this section
A device key is a long-lived X25519 keypair generated by a recipient in a particular client and bound to their Bitcoin identity by a BIP-322 signature.
§3.1 GenerationLink to this section
(device_sk, device_pk) := x25519_keygen()
device_sk MUST be stored in a confidential local store (IndexedDB with
extractable=false via WebCrypto if available, else plaintext). device_sk
MUST NOT leave the device.
§3.2 Binding statementLink to this section
oc-lock:device-bind:v3
address: <btc_address>
device_pk: <hex(device_pk)>
nostr_pk: <hex(nostr_pk), x-only, lowercase>
device_id: <random 16-byte hex>
created_at: <iso8601 utc>
Each line terminated with LF (\n).
binding_sig = BIP322(btc_address, binding_statement).
Publishers MUST emit v3. A verifier MUST reject a v3 record whose event.pubkey
differs from the signed nostr_pk. Readers still accept v2 records, which lack
the nostr_pk line, for sealing to device_pk; from 2027-01-21 a v2 record
names no inbox key (§3.4).
§3.3 PublicationLink to this section
Published as a Nostr addressable event (kind 30078):
kind: 30078
tags: [
["d", "oc-lock:device:<btc_address>"],
["addr", "<btc_address>"],
["device_id", "<device_id>"],
["device_pk", "<hex(device_pk)>"],
["alg", "x25519"],
["binding_sig", "<base64(binding_sig)>"]
]
content: <exact bytes of binding_statement>
pubkey: <ephemeral nostr pubkey, see §3.4>
created_at: <unix seconds>
A record is evidence only for the address its signed statement names. A reader
MUST reject a bind whose d tag is neither oc-lock:device:<addr> nor the §3.6
per-device form for that signed address, or whose addr, device_id or
device_pk tag differs from its signed statement. A reader resolving address
A MUST discard every record whose signed address is not A. A revocation is
read from its signed statement alone (§3.5).
A client SHOULD keep publishing a device record, a bind or a revocation until at least two of the relays readers ask, each asked alone, serve back a copy that verifies, or every one of them does when readers ask fewer than two, and SHOULD NOT report the device as set up, or as revoked, until then.
§3.4 Nostr authorshipLink to this section
The Nostr pubkey isn't tied to the Bitcoin identity — authenticity is the
BIP-322 binding_sig. A fresh ephemeral Nostr keypair SHOULD be derived
deterministically from the device secret:
nostr_sk := HKDF(ikm=device_sk, salt="oc-lock/v2/nostr-key", info="nostr-sk", L=32)
Which key is a device's inbox. A v3 record authorizes its signed nostr_pk.
From 2027-01-21T00:00:00Z by the verifier's clock, a v2 record authorizes no
Nostr key. Before then, a v2 record authorizes its event.pubkey only while no
v3 record of the same device exists and exactly one key carries it. A v2 bind
stays live for sealing to device_pk, so a device whose binds are all v2 still
receives envelopes, by link rather than at a Nostr inbox.
Re-binding a v2 device. A client holding a live v2 device's secret SHOULD
publish a v3 statement for the same address, device_id and device_pk, under
the key derived from the device secret. The re-bind MUST carry the v2
statement's created_at, so a revocation of the device retires it too. A client
SHOULD offer the re-bind for its own v2 devices and say when v2 stops naming an
inbox.
§3.5 Rotation and revocationLink to this section
A device stops receiving new envelopes only through a revocation: a
kind-30078 event with device_pk = "revoked", whose content is this statement
and whose binding_sig is the address's BIP-322 signature over it.
oc-lock:device-revoke:v2
address: <btc_address>
device_id: <device_id>
revoked_at: <iso8601 utc>
Every line ends in LF, the last one too. File it under oc-lock:device:<addr>,
which every reader queries. A device revoking itself should carry it under its
own Nostr key, so that every relay that accepts it stops serving that device's
bind; it may use a fresh key. Carry a revocation of another device with a fresh
key. Never carry one with a key that carries another live bind of the address:
relays replace a record by (pubkey, kind, d), so it would take that bind's
place. Readers accept it under any key. The authority is the address's
signature, so a lost device can be revoked with the wallet alone. A reader takes
the revocation's address and device_id from its signed statement, and does not
reject one whose binding_sig verifies because its addr, device_id or
device_pk tag is missing or says something else, or because of its d tag.
Which binds are live. Collect the device records for the address from every
relay you queried and drop each one whose binding_sig does not verify. Before
merging what the relays returned, verify each event under NIP-01 and drop one
that fails; that checks the Nostr wrapper, never which key carries the record. A
bind of (address, device_id) is live unless a remaining revocation of that
pair has a signed revoked_at at or after the bind's signed created_at. That
holds whichever Nostr key carried each record and whichever relay served it, so
a revocation one relay holds retires the bind another relay still serves.
event.created_at orders nothing. A revocation that verifies but signs no
readable revoked_at retires every bind of its device, whatever that bind's
created_at. A revocation whose signature does not verify retires nothing. A
bind whose signed created_at is later than the reader's clock plus a skew
allowance (10 minutes recommended) is not live yet; list it anyway, so it can be
revoked.
A revocation's absence needs the read floor. Page each relay's answer for
the address with until until a page comes back shorter than the limit you
asked for; a relay whose read stopped at a full page, or that stopped answering,
was cut off. The absence of a revocation counts only when the read floor of the
relays queried answered in full: the number queried, less the write quorum of 2,
plus one, and never fewer than one (four of five). While any relay queried was
cut off it does not count at all: the result is unchecked, never "no
revocation". A sender without the floor, or with any relay cut off, MUST NOT
seal, and reports E_RELAY_UNREACHABLE.
Conforming senders MUST seal only to live binds, and report E_REVOKED when
none is left.
Dating a revocation. Sign revoked_at no earlier than your clock and no
earlier than the latest signed created_at among that device's binds you hold,
so the revocation retires a bind dated ahead too. Read the device's records
again before you report it revoked.
- Rotate — bind a new device under a new
device_id, then revoke the old one. The new record does not replace the old: each device publishes under its own Nostr key, so the two sit at different NIP-33 coordinates.
§3.6 Multi-deviceLink to this section
Each device publishes its record under its own Nostr key at
oc-lock:device:<addr>, so the records stay apart by pubkey. New records
should use that form. The per-device form oc-lock:device:<addr>:<device_id>
stays valid, but a #d query for the address does not return it. Senders
encrypt once per live device (§3.5).
§4 Envelope formatLink to this section
A sealed vault is a canonical JSON object. File extension .lock, MIME
application/vnd.oc-lock+json.
§4.1 SchemaLink to this section
{
"v": 2,
"kind": "identity" | "payment",
"id": "<32-byte hex>",
"alg": { "kem": "x25519", "aead": "aes-256-gcm", "kdf": "hkdf-sha256" },
"from": {
"address": "<btc address>",
"attestation_id": "<sha256 of sender's OC message, optional>"
},
"recipients": [
{
"address": "<btc address>",
"device_id": "<recipient device id>",
"device_pk": "<hex X25519 pubkey>",
"eph_pk": "<hex X25519 ephemeral pubkey>",
"wrapped_key": "<base64url(AEAD(content_key, kek, nonce_kek))>",
"nonce_kek": "<12-byte hex>"
}
],
"ciphertext": "<base64url(AEAD(payload, content_key, nonce_ct))>",
"nonce_ct": "<12-byte hex>",
"hint": "<optional plaintext hint, <= 200 bytes>",
"created_at": "<iso8601 utc>",
"expires_at": "<iso8601 utc | null>",
"payment": null | { "amount_sats": <int>, "address": "<btc addr>", "confirmations": <int>, "relay": "<url>" },
"sig": { "alg": "bip322", "pubkey": "<sender btc address>", "value": "<base64 sig>" }
}
§4.2 Encryption (identity mode)Link to this section
- Generate random
content_key(32 bytes). - Generate random
nonce_ct(12 bytes). ciphertext = AEAD(content_key, nonce_ct, payload, aad=envelope_id_draft)whereenvelope_id_draftis SHA-256 of the canonical envelope withid,ciphertext,sig.valueand eachrecipients[*].wrapped_keyset to""(§5). The draft carries the recipient entries step 4 builds, so step 4 runs first.- For each recipient device:
(eph_sk, eph_pk) := x25519_keygen()shared = X25519(eph_sk, device_pk)kek = HKDF(shared, salt=nonce_ct, info="oc-lock/v2/kek:" || device_id, L=32)nonce_kekrandom 12 byteswrapped_key = AEAD(kek, nonce_kek, content_key, aad=device_id)- zeroize
eph_sk
id= SHA-256 of the canonical envelope withidandsig.valueset to""(§5).sig.value = BIP322(sender_addr, id).- Zeroize
content_key.
§4.3 Decryption (identity mode)Link to this section
- Recompute
id. Reject on mismatch. - Reject unless
sig.pubkeyequalsfrom.address. Verifysig.valueagainstidusing BIP-322 andsig.pubkey; reject on failure. (Clients MAY skip verification for self-seals.) A client that skips it, or opens an envelope whosesig.valueis empty, MUST NOT showfrom.addressas the authenticated sender, and MUST NOT takefrom.addressequal to its own address as proof that it sent the envelope. - Find recipient entry matching local
device_id. If none —E_NOT_ADDRESSED. shared = X25519(device_sk, eph_pk).kek = HKDF(shared, salt=nonce_ct, info="oc-lock/v2/kek:" || device_id, L=32).content_key = AEAD.decrypt(kek, nonce_kek, wrapped_key, aad=device_id).payload = AEAD.decrypt(content_key, nonce_ct, ciphertext, aad=envelope_id_draft).- Zeroize
shared,kek,content_key.
§4.4 Payment modeLink to this section
Replaces step 4 in §4.2 with a single "recipient" that is the named relay. The unseal flow requires the recipient to authenticate to the relay (via orangecheck sign-in) and submit a confirmed payment tx; the relay then unwraps the content key and re-wraps for the recipient's device.
The relay is a trust anchor. Clients MUST display the relay URL prominently before accepting payment-mode vaults.
§4.5 Chat and seal modes (OC Chat)Link to this section
OC Chat is a mode of OC Lock. It adds two kind values, "chat" and
"chat-seal". For those kinds recipients[] is delivery routing, not content:
the AAD and the signed id are computed with recipients=[], so a relay or a
seal beacon can re-wrap the envelope and the id, sig and GCM tag stay valid.
A "chat-seal" envelope carries a seal object; its beacon releases the key
only after the chain reaches unlock_block + confirmations. That is
beacon-enforced policy, not Bitcoin consensus. The rules are in SPEC.md §4.5
and §4.6 and the OC Chat spec.
§5 CanonicalizationLink to this section
- UTF-8 JSON with keys sorted lexicographically at every level.
- No insignificant whitespace.
- Arrays preserve order. Within
recipients[], entries MUST be sorted bydevice_idascending. - Numbers: integers within IEEE 754 double range without fractional zeros or exponents.
- Strings:
\uXXXXonly for control chars and"/\. - Final byte is LF.
Reference: RFC 8785 JCS, with the additional recipients[] rule.
Both hashes take these bytes, the final LF included. id sets id and
sig.value to "". envelope_id_draft sets id, ciphertext, sig.value
and each recipients[*].wrapped_key to "", with sig.alg "bip322" and
sig.pubkey the sender's from.address. Test vectors v01–v04 pin both.
§6 ErrorsLink to this section
| Code | Meaning |
|---|---|
E_ | No device key found for this browser. |
E_ | Envelope does not include the recipient's device_. |
E_ | Sender BIP-322 signature did not verify. |
E_ | AEAD authentication failed (tampered or wrong key). |
E_ | expires_ is in the past. |
E_ | No device record for the address is live (§3.5). |
E_ | Relay could not verify required payment. |
E_ | Too few relays answered in full, or one was cut off (§3.5). |
OC Chat adds E_BLOCK_UNMET, E_BEACON_UNAVAILABLE, E_NO_POSTAGE,
E_BAD_POSTAGE and E_THREAD_GAP (OC Chat errors).
§7 Security modelLink to this section
Proves:
- Authenticity (sender's BIP-322 signature over envelope id)
- Confidentiality (only holders of a listed
device_skcan derive the content key) - Identity binding (recipient's
device_pkbound tobtc_addressby BIP-322)
Does NOT prove:
- Order / freshness —
created_atis informational only. - Delivery — transport is your problem.
- Metadata privacy —
from.address,recipients[*].address,hint,payment.addressare plaintext.
Trust assumptions:
- Identity mode: trustless. Nostr relays can censor but cannot forge.
- Payment mode: explicit trust in the named relay.
§8 VersioningLink to this section
v is an integer. Clients MUST reject envelopes whose v they don't support.
Minor additions handled via unknown-field tolerance.
§9 Compliance checklistLink to this section
A client is OC Lock v2 compliant iff:
- Generates device keys as X25519, stores
device_sknon-extractable when WebCrypto permits. - Produces binding statements byte-for-byte per §3.2.
- Publishes kind-30078 records per §3.3 with BIP-322 binding signature.
- Canonicalizes envelopes per §5 — identical
idacross implementations. - Accepts and produces all required envelope fields per §4.1.
- Verifies sender BIP-322 signatures before accepting envelope contents, with
sig.pubkeyequal tofrom.address(§4.3). - Uses a device record only for the address its binding statement signs, under
that address's
dtag (§3.3). - Treats a Nostr key as a device's inbox only as §3.4 allows: from 2027-01-21
only a v3 record's signed
nostr_pk, and still seals to a live v2 bind'sdevice_pk; re-binds a v2 device with the v2 statement'screated_at(§3.4). - Seals only to live binds: applies every revocation whose BIP-322 signature
verifies, from any relay and any Nostr key, whatever its tags, by signed
timestamps, retiring every bind of the device for one that signs no readable
revoked_at, and treats a bind dated ahead of its clock as not live yet (§3.5). - Dates a revocation it signs no earlier than its clock and the latest
created_atamong that device's binds (§3.5). - Files a revocation it publishes under
oc-lock:device:<addr>: a self-revocation under the device's own key, a revocation of another device under a fresh key, never under a key that carries another live bind of the address (§3.5). - Enforces
expires_atwhen present. - Emits error codes per §6.
§10 External identifiersLink to this section
- Nostr kind:
30078(addressable).d-tag namespaceoc-lock:device:*claimed by this spec. - OC Chat's Nostr kinds and the
d-tag namespaceoc-lock-chat-*are claimed by OC Chat as a mode of this verb (kind registry). - File extension:
.lock - MIME:
application/vnd.oc-lock+json(self-allocated)