@metalabel/dfos-protocol 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/PROTOCOL.md DELETED
@@ -1,1121 +0,0 @@
1
- # DFOS Protocol
2
-
3
- Verifiable identity and content chains — Ed25519 signatures, content-addressed CIDs, W3C DIDs. Cross-language verification in TypeScript, Go, Python, Rust, and Swift.
4
-
5
- This spec is under active review. Discuss it in the [clear.txt](https://clear.dfos.com) space on DFOS.
6
-
7
- [Source](https://github.com/metalabel/dfos/tree/main/packages/dfos-protocol) · [npm](https://www.npmjs.com/package/@metalabel/dfos-protocol) · [Gist](https://gist.github.com/bvalosek/ed4c96fd4b841302de544ffaee871648)
8
-
9
- ---
10
-
11
- ## Philosophy
12
-
13
- DFOS is a dark forest operating system. Content lives in private spaces — visible only to members, governed by the communities that create it. The cryptographic proof layer is public: signed chains of commitments that anyone can independently verify with a public key and any standard EdDSA library.
14
-
15
- Two chain types — identity and content — use the same mechanics: Ed25519 signatures, JWS compact tokens, content-addressed CIDs. The protocol knows about keys and document hashes. It doesn't know about posts, profiles, or any application concept. Document semantics are application layer — free to evolve without protocol changes.
16
-
17
- The protocol is not coupled to the DFOS platform. Any system implementing the same chain primitives produces interoperable, cross-verifiable proofs. An identity created on one system can sign content on another.
18
-
19
- ---
20
-
21
- ## Protocol Overview
22
-
23
- The DFOS protocol has five components:
24
-
25
- | Component | Concern |
26
- | --------------------- | ---------------------------------------------------------------------------- |
27
- | **Crypto core** | Identity chains + content chains — Ed25519 signatures, JWS tokens, CID links |
28
- | **Credentials** | Auth tokens (DID-signed JWT) and VC-JWT credentials for authorization |
29
- | **Beacons** | Signed merkle root announcements — periodic commitment over content sets |
30
- | **Countersignatures** | Witness attestation — third-party signatures over existing chain operations |
31
- | **Merkle trees** | SHA-256 binary trees over content IDs — inclusion proofs for beacon roots |
32
-
33
- The crypto core is the trust boundary — everything below it is cryptographically verified. Documents are flat content objects, content-addressed directly: `documentCID = CID(dagCborCanonicalEncode(contentObject))`. What goes inside the content object is application-defined — see the [DFOS Content Model](https://protocol.dfos.com/content-model) for the standard schema library.
34
-
35
- ### Crypto Core: Two Chain Types
36
-
37
- | | Identity Chain | Content Chain |
38
- | -------------- | -------------------------- | -------------------------------- |
39
- | Commits to | Key sets (embedded) | Documents (by CID reference) |
40
- | Identifier | `did:dfos:<hash>` | `<hash>` (bare) |
41
- | Operations | create, update, delete | create, update, delete |
42
- | JWS typ | `did:dfos:identity-op` | `did:dfos:content-op` |
43
- | Self-sovereign | Yes (signs own operations) | No (signed by external identity) |
44
-
45
- Both chains are signed linked lists of state commitments. Identity chains embed their state (key sets). Content chains reference their state via `documentCID` — a content-addressed pointer to a flat content object.
46
-
47
- ### Addressing
48
-
49
- Three addressing modes, self-describing by format:
50
-
51
- | Thing | Form | Example |
52
- | --------------------- | ------------------------ | --------------------------------- |
53
- | Operation or document | CID (dag-cbor + SHA-256) | `bafyrei...` (base32lower) |
54
- | Content chain | contentId (22-char hash) | `a82z92a3hndk6c97thcrn8` |
55
- | Identity chain | DID | `did:dfos:e3vvtck42d4eacdnzvtrn6` |
56
-
57
- CIDs are specific immutable artifacts — a pointer to an exact operation or document. Content IDs are living content chain entities — the 22-char bare hash derived from the genesis CID. DIDs are living identity chain entities.
58
-
59
- Operations and documents are CIDs — standard IPLD content addresses. Content chains and identity chains use derived identifiers — `customAlpha(SHA-256(genesis CID bytes))`. Same derivation for both. Identity chains prepend `did:dfos:` (W3C DID spec). Content identifiers are bare — just the 22-char hash, no prefix.
60
-
61
- Application code may add prefixes for routing (e.g., `post_xxxx`) — these are strippable semantic sugar, not part of the protocol identifier.
62
-
63
- ---
64
-
65
- ## Protocol Rules
66
-
67
- ### Commitment Scheme
68
-
69
- Both operations and documents are content-addressed via **CID** (`dagCborCanonicalEncode(payload)` → SHA-256 → CIDv1). Operations are additionally signed via **JWS**.
70
-
71
- | Representation | Encoding | Purpose |
72
- | -------------- | -------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- |
73
- | CID | `dagCborCanonicalEncode(payload)` → SHA-256 → CIDv1 | Deterministic content addressing for operations and documents |
74
- | JWS | `base64url(JSON.stringify(header))` + `.` + `base64url(JSON.stringify(payload))` → EdDSA signature covers both | Signature verification for operations |
75
-
76
- CID uses [dag-cbor canonical encoding](https://ipld.io/specs/codecs/dag-cbor/spec/) for determinism — given the same logical payload, the CID MUST be identical regardless of implementation language or platform. JWS uses standard JSON for library interoperability. The dag-cbor hex test vectors in this document allow byte-level verification.
77
-
78
- ### Chain Validity
79
-
80
- A valid chain is a **linear sequence** of operations. Each operation (after genesis) links to its predecessor via `previousOperationCID`. The chain provides structural ordering independent of timestamps.
81
-
82
- **Forks are invalid at the protocol level.** Two operations referencing the same `previousOperationCID` constitute a fork. The protocol does not define fork resolution — this is application-defined (e.g., longest chain, first-seen, advisory locks).
83
-
84
- **Timestamp ordering**: `createdAt` SHOULD be strictly increasing within a chain. Implementations SHOULD reject operations with non-increasing timestamps as a sanity check against replayed or mis-ordered operations. However, the chain link (CID reference) is the authoritative ordering mechanism, not the timestamp. Implementations MAY relax timestamp ordering in constrained environments where clock synchronization is impractical.
85
-
86
- ### Identity Chain Signer Validity
87
-
88
- An identity chain operation is valid only if the signing key was a **controller key in the immediately prior state**. For genesis operations, the signing key MUST be one of the controller keys declared in that same operation — this is the bootstrap: the genesis operation introduces and simultaneously authorizes its own keys.
89
-
90
- This is a self-sovereign invariant: the identity chain defines its own valid signers via `controllerKeys`, and the protocol enforces this. No external authority is consulted.
91
-
92
- ### Content Chain Signer Model
93
-
94
- Content chain verification requires a **valid EdDSA signature** and delegates key resolution to the caller. The `kid` in each operation's JWS header is a DID URL (`did:dfos:<id>#<keyId>`). The verifier calls `resolveKey(kid)` to obtain the raw Ed25519 public key bytes for that key on that identity. How the resolver obtains and validates the identity's key state is application-defined.
95
-
96
- **Creator sovereignty**: The DID that signs the genesis (create) operation is the **chain creator** and permanently owns the chain. The creator can sign subsequent operations directly — no credential needed. Other DIDs require a **DFOSContentWrite** VC-JWT credential in the operation's `authorization` field, issued by the creator DID. See [Credentials](#credentials) for the VC-JWT format.
97
-
98
- **Signer-payload consistency**: The `kid` DID in the JWS header MUST match the `did` field in the content operation payload. This enables discrimination between author operations and countersignatures — if the kid DID differs from the payload `did`, it is a countersignature (witness attestation), not a chain operation.
99
-
100
- **What the protocol enforces:**
101
-
102
- - The EdDSA signature on each operation is valid against the key returned by `resolveKey(kid)`
103
- - Chain integrity (CID links, timestamp ordering, terminal state)
104
- - The `kid` DID matches the payload `did` for chain operations
105
- - Creator-sovereignty authorization (when `enforceAuthorization` is enabled): non-creator signers must present a valid DFOSContentWrite VC-JWT issued by the creator
106
-
107
- **What the protocol does NOT enforce (application concerns):**
108
-
109
- - Which key role (auth, assert, controller) the signing key must have
110
- - Ownership or attribution semantics beyond creator sovereignty
111
-
112
- ### Terminal States and Special Operations
113
-
114
- **`delete` is the only terminal state.** No valid operations may follow a delete. An implementation MUST reject any operation after a delete. Delete prevents future operations but does NOT remove data — the complete chain remains intact for verification. Data removal is an application concern.
115
-
116
- **Controller key requirement:** `update` operations on identity chains MUST include at least one controller key. If decommissioning is intended, `delete` is the correct terminal operation.
117
-
118
- **Content-null:** An `update` on a content chain with `documentCID: null` means the content exists but its document is cleared. The chain continues — a subsequent update can set content again.
119
-
120
- ### `typ` Header
121
-
122
- The JWS `typ` header uses protocol-specific values (not IANA media types):
123
-
124
- | `typ` value | Usage |
125
- | ---------------------- | --------------------------------------------- |
126
- | `did:dfos:identity-op` | Identity chain operations |
127
- | `did:dfos:content-op` | Content chain operations |
128
- | `did:dfos:beacon` | Beacon announcements |
129
- | `JWT` | Auth tokens (DID-signed relay authentication) |
130
- | `vc+jwt` | VC-JWT credentials (W3C VC Data Model v2) |
131
-
132
- Protocol-specific `typ` values are non-standard per JOSE convention, documented intentionally. `JWT` and `vc+jwt` follow IANA conventions. The `typ` header aids routing but is not security-critical. Implementations SHOULD validate it but MUST NOT rely on it for security decisions.
133
-
134
- ### Operation Field Limits
135
-
136
- The protocol defines maximum sizes for all operation fields as abuse-prevention ceilings. Implementations MUST reject operations that exceed these bounds. Implementations MAY impose stricter limits.
137
-
138
- | Field | Max | Rationale |
139
- | -------------------------------------------- | --------- | -------------------------------------- |
140
- | `did` | 256 chars | ~8× typical `did:dfos:` (~31 chars) |
141
- | `key.id` | 64 chars | ~3× typical key ID (`key_` + 22 chars) |
142
- | `key.publicKeyMultibase` | 128 chars | ~2× Ed25519 multikey (~50 chars) |
143
- | `authKeys` / `assertKeys` / `controllerKeys` | 16 items | Generous for key rotation |
144
- | `previousOperationCID` | 256 chars | ~4× typical CIDv1 (~60 chars) |
145
- | `documentCID` | 256 chars | Same as above |
146
- | `note` | 256 chars | Short annotation, not prose |
147
-
148
- These limits are enforced by the Zod schemas in `src/chain/schemas.ts`. Any implementation parsing operations MUST reject values exceeding these bounds.
149
-
150
- The protocol does NOT limit:
151
-
152
- - **Document content size** — the protocol commits to a CID, not the document. Document size limits are application/registry concerns.
153
- - **Chain length** — no maximum operations per chain.
154
- - **Number of chains per identity** — application scaling concern.
155
-
156
- ---
157
-
158
- ## Standards and Dependencies
159
-
160
- | Component | Standard / Library |
161
- | ------------------- | -------------------------------------------------------------------------- |
162
- | Key generation | Ed25519 (RFC 8032) via `@noble/curves/ed25519` |
163
- | Signature algorithm | EdDSA over Ed25519 (pure, no prehash — Ed25519 handles SHA-512 internally) |
164
- | Key encoding | W3C Multikey (multicodec `0xed01` + base58btc multibase) |
165
- | Signed envelopes | JWS Compact Serialization (RFC 7515) with `alg: "EdDSA"` |
166
- | Content addressing | CIDv1 with dag-cbor codec (`0x71`) + SHA-256 multihash (`0x12`) |
167
- | ID encoding | SHA-256 → custom 19-char alphabet, 22 characters |
168
-
169
- ### ID Alphabet
170
-
171
- ```
172
- Alphabet: 2346789acdefhknrtvz (19 characters)
173
- Length: 22 characters
174
- Entropy: ~93.4 bits (19^22)
175
- ```
176
-
177
- Process: `SHA-256(input) → for each of first 22 bytes: alphabet[byte % 19]`. The modulo introduces a ~0.3% bias (256 is not evenly divisible by 19) — not security-relevant for identifiers.
178
-
179
- DIDs: `did:dfos:` + 22-char ID derived from `SHA-256(genesis CID raw bytes)`
180
- Key IDs: `key_` + 22-char ID. Convention: derive from public key hash (`key_` + `customAlpha(SHA-256(publicKey))`), making key IDs deterministic and verifiable. Not a protocol requirement — key IDs can be any string.
181
-
182
- ### Multikey Encoding (W3C Multikey for Ed25519)
183
-
184
- ```
185
- Encode:
186
- 1. Take 32-byte Ed25519 public key
187
- 2. Prepend multicodec varint prefix [0xed, 0x01] (unsigned varint for 0xed = 237 = ed25519-pub)
188
- 3. Base58btc encode the 34-byte result
189
- 4. Prepend 'z' multibase prefix
190
- → "z6Mk..."
191
-
192
- Decode:
193
- 1. Strip 'z' multibase prefix
194
- 2. Base58btc decode → 34 bytes
195
- 3. First 2 bytes must be [0xed, 0x01] (ed25519-pub multicodec varint)
196
- 4. Remaining 32 bytes = raw Ed25519 public key
197
- ```
198
-
199
- **Worked example:**
200
-
201
- ```
202
- Public key (hex): ba421e272fad4f941c221e47f87d9253bdc04f7d4ad2625ae667ab9f0688ce32
203
- Prefix + key (hex): ed01 ba421e272fad4f941c221e47f87d9253bdc04f7d4ad2625ae667ab9f0688ce32
204
- Base58btc + 'z': z6MkrzLMNwoJSV4P3YccWcbtk8vd9LtgMKnLeaDLUqLuASjb
205
- ```
206
-
207
- Note: `[0xed, 0x01]` is the unsigned varint encoding of 237 (`0xed`). Since `0xed > 0x7f`, it requires two bytes in varint format: `0xed` (low 7 bits + continuation bit) then `0x01` (high bits). This is NOT big-endian `[0x00, 0xed]`.
208
-
209
- ### CID Construction (dag-cbor + SHA-256)
210
-
211
- ```
212
- 1. JSON payload → dag-cbor canonical encoding → CBOR bytes
213
- 2. SHA-256(CBOR bytes) → 32-byte hash
214
- 3. Construct CIDv1:
215
- - Version: 1 (varint: 0x01)
216
- - Codec: dag-cbor (varint: 0x71)
217
- - Multihash: SHA-256 (function: 0x12, length: 0x20, digest: 32 bytes)
218
- 4. CID binary = [0x01, 0x71, 0x12, 0x20, ...32 hash bytes]
219
- 5. Base32lower multibase encode → "bafyrei..."
220
- ```
221
-
222
- dag-cbor canonical ordering: map keys sorted by encoded byte length first, then lexicographic. Strings to CBOR text strings. Null to CBOR null. Arrays to CBOR arrays. Objects to CBOR maps with sorted keys.
223
-
224
- #### Number Encoding (Critical for CID Determinism)
225
-
226
- JSON has a single number type (IEEE 754 double). CBOR has distinct integer and floating-point types with different byte encodings. This difference is the most common source of CID divergence across implementations.
227
-
228
- **Rule: JSON numbers that are mathematically integers (no fractional part) MUST be encoded as CBOR integers (major type 0/1), never as CBOR floats.** This is consistent with the [IPLD data model](https://ipld.io/docs/data-model/) integer/float distinction and required by the [dag-cbor codec spec](https://ipld.io/specs/codecs/dag-cbor/spec/).
229
-
230
- Why this matters: CBOR integer `1` encodes as a single byte `0x01`. CBOR float `1.0` encodes as three bytes `0xf9 0x3c 0x00` (half-precision). Same logical value, different bytes, different SHA-256, different CID. An implementation that encodes `version: 1` as a float will produce a valid CBOR document but a wrong CID — silent, undetectable without cross-implementation testing.
231
-
232
- **Common trap**: Languages that decode JSON into untyped maps (Go's `map[string]any`, Python's `dict`, etc.) typically represent all JSON numbers as floating-point. When this decoded value is then CBOR-encoded, it becomes a CBOR float instead of an integer. Implementations MUST normalize number types after JSON deserialization and before CBOR encoding.
233
-
234
- **Integer bounds**: dag-cbor integers are limited to the range `[-(2^64), 2^64 - 1]`. All integer fields in the current protocol (`version: 1`) are small positive values. Future protocol extensions SHOULD NOT introduce integer fields that exceed JSON's safe integer range (`2^53 - 1`), as JSON serialization would lose precision.
235
-
236
- **Verification test vector** — encodes `{"version": 1, "type": "test"}`:
237
-
238
- ```
239
- Integer encoding (CORRECT):
240
- CBOR: a2647479706564746573746776657273696f6e01
241
- CID: bafyreihp6omsp6icc6ee63ox2ovsaxm6s7ikd2a7k5eh2qz2qd5soh5bsa
242
-
243
- Float encoding (WRONG — different bytes, different CID):
244
- CBOR: a2647479706564746573746776657273696f6ef93c00
245
- CID: bafyreiawbms4476m5jlrmqtyvtwe5ta3eo2bh7mdprtomfgfype7j57o4q
246
- ```
247
-
248
- If your implementation produces the float CID, your number encoding is incorrect. The byte at offset 19 in the CBOR output is the discriminator: `0x01` = correct (CBOR integer), `0xf9` = wrong (CBOR float16 header).
249
-
250
- **Worked example (genesis identity operation):**
251
-
252
- ```
253
- CBOR bytes (441 bytes, hex):
254
- a66474797065666372656174656776657273696f6e0168617574684b65797381a3626964781a6b
255
- 65795f72396576333466766332337a393939766561616674386474797065684d756c74696b6579
256
- 727075626c69634b65794d756c74696261736578307a364d6b727a4c4d4e776f4a535634503359
257
- 6363576362746b387664394c74674d4b6e4c6561444c55714c7541536a62696372656174656441
258
- 747818323032362d30332d30375430303a30303a30302e3030305a6a6173736572744b65797381
259
- a3626964781a6b65795f72396576333466766332337a393939766561616674386474797065684d
260
- 756c74696b6579727075626c69634b65794d756c74696261736578307a364d6b727a4c4d4e776f
261
- 4a5356345033596363576362746b387664394c74674d4b6e4c6561444c55714c7541536a626e63
262
- 6f6e74726f6c6c65724b65797381a3626964781a6b65795f72396576333466766332337a393939
263
- 766561616674386474797065684d756c74696b6579727075626c69634b65794d756c7469626173
264
- 6578307a364d6b727a4c4d4e776f4a5356345033596363576362746b387664394c74674d4b6e4c
265
- 6561444c55714c7541536a62
266
-
267
- CID bytes (hex): 01711220206a5e6140a5114f1e49f3ca4b339fb2cb8e70bbb34968b23156fd0e3237b486
268
- CID string: bafyreibanjpgcqffcfhr4sptzjfthh5szohhbo5tjfulemkw7uhden5uqy
269
- ```
270
-
271
- ### DID Derivation (worked example)
272
-
273
- ```
274
- Input: CID bytes (hex) = 01711220206a5e6140a5114f1e49f3ca4b339fb2cb8e70bbb34968b23156fd0e3237b486
275
- Step 1: SHA-256(CID bytes) = 4360cfbcbbb3f1614c8e02dbfe8d55935e1195cd2129820ab8aef94bde12ea8a
276
- Step 2: Take first 22 bytes: 43 60 cf bc bb b3 f1 61 4c 8e 02 db fe 8d 55 93 5e 11 95 cd 21 29
277
- Step 3: For each byte, alphabet[byte % 19]:
278
- 43=67 → 67%19=10 → 'e'
279
- 60=96 → 96%19=1 → '3'
280
- cf=207 → 207%19=17 → 'v'
281
- bc=188 → 188%19=17 → 'v'
282
- ...
283
- Result: e3vvtck42d4eacdnzvtrn6
284
- DID: did:dfos:e3vvtck42d4eacdnzvtrn6
285
- ```
286
-
287
- ---
288
-
289
- ## Operation Schemas
290
-
291
- ### Identity Operations
292
-
293
- ```typescript
294
- // Genesis — starts the identity chain
295
- { version: 1, type: "create",
296
- authKeys: MultikeyPublicKey[],
297
- assertKeys: MultikeyPublicKey[],
298
- controllerKeys: MultikeyPublicKey[], // must have at least one
299
- createdAt: string } // ISO 8601, ms precision, UTC
300
-
301
- // Key rotation / modification
302
- { version: 1, type: "update",
303
- previousOperationCID: string, // CID of previous operation
304
- authKeys: MultikeyPublicKey[],
305
- assertKeys: MultikeyPublicKey[],
306
- controllerKeys: MultikeyPublicKey[], // must have at least one
307
- createdAt: string }
308
-
309
- // Permanent destruction
310
- { version: 1, type: "delete",
311
- previousOperationCID: string,
312
- createdAt: string }
313
- ```
314
-
315
- ### Content Operations
316
-
317
- ```typescript
318
- // Genesis — starts the content chain, commits initial document
319
- { version: 1, type: "create",
320
- did: string, // author DID, committed to by CID
321
- documentCID: string, // CID of flat content object
322
- baseDocumentCID: string | null, // edit lineage — CID of prior document version
323
- createdAt: string,
324
- note: string | null }
325
-
326
- // Content change (null documentCID = clear content)
327
- { version: 1, type: "update",
328
- did: string, // author DID
329
- previousOperationCID: string,
330
- documentCID: string | null,
331
- baseDocumentCID: string | null,
332
- createdAt: string,
333
- note: string | null,
334
- authorization?: string } // VC-JWT for delegated operations
335
-
336
- // Permanent destruction
337
- { version: 1, type: "delete",
338
- did: string, // author DID
339
- previousOperationCID: string,
340
- createdAt: string,
341
- note: string | null,
342
- authorization?: string } // VC-JWT for delegated operations
343
- ```
344
-
345
- ### MultikeyPublicKey
346
-
347
- ```typescript
348
- { id: string, // e.g. "key_r9ev34fvc23z999veaaft8"
349
- type: "Multikey", // literal discriminator
350
- publicKeyMultibase: string } // e.g. "z6MkrzLMNwoJSV4P3YccWcbtk8vd9LtgMKnLeaDLUqLuASjb"
351
- ```
352
-
353
- ---
354
-
355
- ## JWS Envelope Format
356
-
357
- ### Signing
358
-
359
- ```
360
- signingInput = base64url(JSON.stringify(header)) + "." + base64url(JSON.stringify(payload))
361
- signature = ed25519.sign(UTF8_bytes(signingInput), privateKey)
362
- token = signingInput + "." + base64url(signature)
363
- ```
364
-
365
- ### kid Rules
366
-
367
- | Context | kid format | Example |
368
- | ------------------------- | ----------- | ---------------------------- |
369
- | Identity create (genesis) | Bare key ID | `key_r9ev34fvc23z999veaaft8` |
370
- | Identity update/delete | DID URL | See below |
371
- | All content ops | DID URL | See below |
372
-
373
- DID URL examples:
374
-
375
- ```
376
- did:dfos:e3vvtck42d4eacdnzvtrn6#key_r9ev34fvc23z999veaaft8
377
- did:dfos:e3vvtck42d4eacdnzvtrn6#key_ez9a874tckr3dv933d3ckd
378
- ```
379
-
380
- ### `cid` Header
381
-
382
- Every operation JWS (identity-op and content-op) includes a `cid` field in the protected header. This is the CIDv1 string of the operation payload, derived from `dagCborCanonicalEncode(payload) → SHA-256 → CIDv1 → base32lower`. The `cid` is computed before signing and embedded in the protected header, so it is covered by the EdDSA signature.
383
-
384
- **Signing order:**
385
-
386
- 1. Construct the operation payload
387
- 2. Derive the operation CID: `dagCborCanonicalEncode(payload) → CIDv1`
388
- 3. Build the protected header including `cid`
389
- 4. Sign: `ed25519.sign(UTF8(base64url(header) + "." + base64url(payload)), privateKey)`
390
-
391
- **Verification rule:** After verifying the JWS signature and deriving the operation CID from the parsed payload, implementations MUST reject operations where:
392
-
393
- - `header.cid` is missing
394
- - `header.cid` does not match the derived CID
395
-
396
- A CID mismatch between header and derived value immediately surfaces dag-cbor encoding disagreements across implementations.
397
-
398
- Note: JWT auth tokens and VC-JWT credentials do NOT include a `cid` header — this field is specific to operation JWS tokens and beacons.
399
-
400
- ### CID Derivation
401
-
402
- ```
403
- operation CID = dagCborCanonicalEncode(operation_payload) → SHA-256 → CIDv1 → base32lower string
404
- ```
405
-
406
- The CID is derived from the JWS payload (the unsigned operation JSON), NOT from the JWS token itself.
407
-
408
- ### DID Derivation
409
-
410
- ```
411
- DID = "did:dfos:" + idEncode(SHA-256(genesis_CID_raw_bytes))
412
- ```
413
-
414
- Where `idEncode` is the 19-char alphabet encoding described above.
415
-
416
- ---
417
-
418
- ## Credentials
419
-
420
- Two credential types handle authentication and authorization. Both are DID-signed JWTs using Ed25519 (`alg: "EdDSA"`).
421
-
422
- ### Auth Tokens (Relay Authentication)
423
-
424
- A DID-signed JWT proving the caller controls a DID. Short-lived, scoped to a specific relay via the `aud` (audience) claim. Used for relay AuthN — establishing identity before making requests.
425
-
426
- **JWT Header:**
427
-
428
- ```json
429
- {
430
- "alg": "EdDSA",
431
- "typ": "JWT",
432
- "kid": "did:dfos:e3vvtck42d4eacdnzvtrn6#key_r9ev34fvc23z999veaaft8"
433
- }
434
- ```
435
-
436
- **JWT Payload:**
437
-
438
- ```json
439
- {
440
- "iss": "did:dfos:e3vvtck42d4eacdnzvtrn6",
441
- "sub": "did:dfos:e3vvtck42d4eacdnzvtrn6",
442
- "aud": "relay.example.com",
443
- "exp": 1772845200,
444
- "iat": 1772841600
445
- }
446
- ```
447
-
448
- | Field | Type | Description |
449
- | ----- | ------ | ---------------------------------------------------------- |
450
- | `iss` | string | DID proving identity (the signer) |
451
- | `sub` | string | Same as `iss` for auth tokens |
452
- | `aud` | string | Target relay hostname (prevents cross-relay replay) |
453
- | `exp` | number | Expiration — unix seconds (short-lived, typically minutes) |
454
- | `iat` | number | Issued-at — unix seconds |
455
-
456
- **Verification:** Standard JWT verification — EdDSA signature check, temporal validity (`iat` must not be in the future, `exp` must be after current time), audience match. The `kid` MUST be a DID URL (`did:dfos:xxx#key_yyy`) and the `kid` DID MUST match `iss`.
457
-
458
- Auth tokens do NOT include a `cid` header — they are ephemeral session tokens, not content-addressed artifacts.
459
-
460
- ### VC-JWT Credentials (Authorization)
461
-
462
- W3C Verifiable Credential Data Model v2 credentials encoded as JWT (`typ: "vc+jwt"`). Two credential types:
463
-
464
- | Credential Type | Purpose |
465
- | ------------------ | ------------------------------------------------------------ |
466
- | `DFOSContentWrite` | Authorize extending a content chain (embedded in operations) |
467
- | `DFOSContentRead` | Authorize reading content plane data (presented to relay) |
468
-
469
- **VC-JWT Header:**
470
-
471
- ```json
472
- {
473
- "alg": "EdDSA",
474
- "typ": "vc+jwt",
475
- "kid": "did:dfos:e3vvtck42d4eacdnzvtrn6#key_r9ev34fvc23z999veaaft8"
476
- }
477
- ```
478
-
479
- **VC-JWT Payload:**
480
-
481
- ```json
482
- {
483
- "iss": "did:dfos:e3vvtck42d4eacdnzvtrn6",
484
- "sub": "did:dfos:nzkf838efr424433rn2rzk",
485
- "exp": 1798761600,
486
- "iat": 1772841600,
487
- "vc": {
488
- "@context": ["https://www.w3.org/ns/credentials/v2"],
489
- "type": ["VerifiableCredential", "DFOSContentWrite"],
490
- "credentialSubject": {}
491
- }
492
- }
493
- ```
494
-
495
- | Field | Type | Description |
496
- | ---------------------- | -------- | -------------------------------------------------------- |
497
- | `iss` | string | DID granting the credential (content creator/controller) |
498
- | `sub` | string | DID receiving the credential (collaborator/reader) |
499
- | `exp` | number | Expiration — unix seconds |
500
- | `iat` | number | Issued-at — unix seconds |
501
- | `vc.@context` | string[] | Must be `["https://www.w3.org/ns/credentials/v2"]` |
502
- | `vc.type` | string[] | `["VerifiableCredential", "<DFOSCredentialType>"]` |
503
- | `vc.credentialSubject` | object | Optional narrowing — see scope narrowing below |
504
-
505
- **Scope narrowing:** The `credentialSubject` object may contain a `contentId` field. If absent, the credential grants broad access to all content by the issuer. If present, the credential is narrowed to the specific content chain.
506
-
507
- ```json
508
- // Broad — all content by this DID
509
- { "credentialSubject": {} }
510
-
511
- // Narrow — specific content chain only
512
- { "credentialSubject": { "contentId": "a82z92a3hndk6c97thcrn8" } }
513
- ```
514
-
515
- **Verification:** EdDSA signature check, temporal validity (`iat` must not be in the future, `exp` must be after current time — using operation `createdAt` for chain-embedded VCs, wall clock for relay-presented VCs), `kid` DID URL format, `kid` DID matches `iss`, payload structure via Zod schema. Optionally verify `sub` and credential type match expectations.
516
-
517
- ### Content Chain Authorization
518
-
519
- When `enforceAuthorization` is enabled on content chain verification:
520
-
521
- 1. **Genesis operation**: The signer is the chain creator, always authorized
522
- 2. **Creator signs subsequent ops**: Authorized directly — no credential needed
523
- 3. **Different DID signs**: Must include an `authorization` field containing a valid `DFOSContentWrite` VC-JWT where:
524
- - `iss` matches the chain creator DID
525
- - `sub` matches the signing DID
526
- - The credential is temporally valid (`iat <= op.createdAt < exp`, not wall clock)
527
- - If `contentId` is present in `credentialSubject`, it must match this chain's contentId
528
- - The credential type is `DFOSContentWrite`
529
-
530
- The `authorization` field is available on `update` and `delete` content operations. It is absent for creator-signed operations.
531
-
532
- ---
533
-
534
- ## Beacons
535
-
536
- A beacon is a signed announcement of a merkle root — a periodic commitment over a set of content IDs. Beacons are floating signed artifacts, not chained. They provide a compact, verifiable snapshot of an identity's content set at a point in time.
537
-
538
- ### Beacon Payload
539
-
540
- ```json
541
- {
542
- "version": 1,
543
- "type": "beacon",
544
- "did": "did:dfos:e3vvtck42d4eacdnzvtrn6",
545
- "merkleRoot": "7e80d4780f454e0fca0b090d8c646f572b49354f54154531606105aad2fda28e",
546
- "createdAt": "2026-03-07T00:05:00.000Z"
547
- }
548
- ```
549
-
550
- | Field | Type | Description |
551
- | ------------ | ------ | ------------------------------------------------------- |
552
- | `version` | 1 | Protocol version |
553
- | `type` | string | Literal `"beacon"` |
554
- | `did` | string | DID of the identity publishing the beacon |
555
- | `merkleRoot` | string | Hex-encoded SHA-256 root (64 chars, `/^[0-9a-f]{64}$/`) |
556
- | `createdAt` | string | ISO 8601 timestamp |
557
-
558
- ### Beacon JWS Header
559
-
560
- ```json
561
- {
562
- "alg": "EdDSA",
563
- "typ": "did:dfos:beacon",
564
- "kid": "did:dfos:e3vvtck42d4eacdnzvtrn6#key_r9ev34fvc23z999veaaft8",
565
- "cid": "bafyreihholuui7s7ns74iem6ahfxsb472hwogbqd32yrrp5fztc3kxa5qu"
566
- }
567
- ```
568
-
569
- ### Worked Example: Beacon
570
-
571
- Using the reference identity (`did:dfos:e3vvtck42d4eacdnzvtrn6`) and key 1 from the identity chain examples. The beacon commits to a merkle root over 5 content IDs (see Merkle Tree worked example below).
572
-
573
- **Beacon CID** (dag-cbor canonical encode → CIDv1):
574
-
575
- ```
576
- bafyreihholuui7s7ns74iem6ahfxsb472hwogbqd32yrrp5fztc3kxa5qu
577
- ```
578
-
579
- **Controller JWS** (key 1 signs):
580
-
581
- ```
582
- kid: did:dfos:e3vvtck42d4eacdnzvtrn6#key_r9ev34fvc23z999veaaft8
583
- typ: did:dfos:beacon
584
- cid: bafyreihholuui7s7ns74iem6ahfxsb472hwogbqd32yrrp5fztc3kxa5qu
585
- ```
586
-
587
- **Witness countersignature** (key 2 signs the same payload — same CID, different kid):
588
-
589
- ```
590
- kid: did:dfos:e3vvtck42d4eacdnzvtrn6#key_ez9a874tckr3dv933d3ckd
591
- typ: did:dfos:beacon
592
- cid: bafyreihholuui7s7ns74iem6ahfxsb472hwogbqd32yrrp5fztc3kxa5qu
593
- ```
594
-
595
- Both JWS tokens commit to identical bytes (same CID). The controller/witness distinction is determined at verification time by comparing the `kid` DID to the payload `did`.
596
-
597
- Full JWS tokens are in [`examples/beacon.json`](https://github.com/metalabel/dfos/blob/main/packages/dfos-protocol/examples/beacon.json).
598
-
599
- ### Beacon Semantics
600
-
601
- Beacons are not chained — there is no `previousOperationCID`. For a given DID, the latest beacon with a strictly-greater `createdAt` timestamp wins. Beacons replace, not accumulate.
602
-
603
- **Clock skew tolerance**: Implementations MUST reject beacons with a `createdAt` more than 5 minutes in the future relative to the verifier's clock. This prevents pre-dating attacks while accommodating reasonable clock drift.
604
-
605
- **merkleRoot**: A hex-encoded SHA-256 hash (64 characters). This is a commitment, not a CID — it uses raw SHA-256, not dag-cbor encoding. See the Merkle Tree section below for construction. An empty content set produces a `null` merkle root (no beacon needed).
606
-
607
- ---
608
-
609
- ## Merkle Trees
610
-
611
- Beacons commit to a set of content IDs via a pure SHA-256 binary Merkle tree. The tree has no dag-cbor dependency — it uses only SHA-256 over raw bytes.
612
-
613
- ### Construction
614
-
615
- 1. **Collect** all content IDs (22-char bare hashes) in the set
616
- 2. **Sort** content IDs lexicographically (UTF-8 byte order)
617
- 3. **Hash leaves**: for each content ID, `SHA-256(UTF-8(contentId))` → 32-byte leaf hash
618
- 4. **Build tree**: recursively pair adjacent hashes. For each pair, `SHA-256(left || right)` → 32 bytes. If a level has an odd number of nodes, the last node is promoted to the next level unpaired.
619
- 5. **Root**: the final 32-byte hash, hex-encoded to a 64-character string
620
-
621
- An empty set of content IDs produces a `null` root. A single content ID produces a root equal to `hex(SHA-256(UTF-8(contentId)))`.
622
-
623
- ### Worked Example: Merkle Tree
624
-
625
- 5 content IDs: `["alpha", "bravo", "charlie", "delta", "echo"]`
626
-
627
- Already sorted lexicographically. Hash each leaf:
628
-
629
- ```
630
- alpha → SHA-256("alpha") → 8ed3f6ad685b959ead7022518e1af76cd816f8e8ec7ccdda1ed4018e8f2223f8
631
- bravo → SHA-256("bravo") → 4f4a9410ffcdf895c4adb880659e9b5c0dd1f23a30790684340b3eaacb045398
632
- charlie → SHA-256("charlie") → 36ef585cd42d49706cd2827a77d86c91bfdaf87a3f22b8f0e0308bd2c16cf85f
633
- delta → SHA-256("delta") → 18ac3e7343f016890c510e93f935261169d9e3f565436429830faf0934f4f8e4
634
- echo → SHA-256("echo") → 092c79e8f80e559e404bcf660c48f3522b67aba9ff1484b0367e1a4ddef7431d
635
- ```
636
-
637
- Build tree bottom-up, pairing left-to-right. Odd nodes promote unpaired:
638
-
639
- ```
640
- Level 0 (leaves): [alpha] [bravo] [charlie] [delta] [echo]
641
- Level 1: [alpha‖bravo] [charlie‖delta] [echo] ← promoted
642
- Level 2: [L1-left‖L1-mid] [echo] ← promoted
643
- Level 3 (root): [L2-left‖echo]
644
- ```
645
-
646
- Interior hashes:
647
-
648
- ```
649
- SHA-256(alpha‖bravo) → 90d39555bb3c223e12f5a375c3011d2462fe2e1e36b8416a0b623d5831a9b4f3
650
- SHA-256(charlie‖delta) → 6b55e77bef32937d9ccce2bd4b18127b0483f0be8e5b63c30bcc2b0d09f7dd44
651
- SHA-256(alpha‖bravo ‖ charlie‖delta) → 23c83cb862e3b6a86eb2dfa0ea8ba0edcf1c3f3b8f14abc5eb9d72eab2edc2f7
652
- ```
653
-
654
- **Root** (level 3):
655
-
656
- ```
657
- SHA-256(23c83c...edc2f7 ‖ 092c79...f7431d) → 7e80d4780f454e0fca0b090d8c646f572b49354f54154531606105aad2fda28e
658
- ```
659
-
660
- ### Inclusion Proofs
661
-
662
- A Merkle inclusion proof demonstrates that a specific content ID is part of the committed set without revealing the full set. The proof consists of sibling hashes along the path from leaf to root, plus a direction (left/right) for each step.
663
-
664
- ### Worked Example: Inclusion Proof for "charlie"
665
-
666
- Starting from the leaf hash of "charlie" (`36ef58...`), walk to the root using sibling hashes:
667
-
668
- ```
669
- Step 1: charlie (index 2) paired with delta (index 3)
670
- sibling: 4f4a9410...045398 (delta leaf) position: right
671
- → SHA-256(charlie ‖ delta) → 6b55e77b...f7dd44
672
-
673
- Step 2: charlie‖delta paired with alpha‖bravo
674
- sibling: 90d39555...a9b4f3 (alpha‖bravo) position: left
675
- → SHA-256(alpha‖bravo ‖ charlie‖delta) → 23c83cb8...edc2f7
676
-
677
- Step 3: L2-left paired with echo (promoted)
678
- sibling: 092c79e8...f7431d (echo leaf) position: right
679
- → SHA-256(L2-left ‖ echo) → 7e80d478...fda28e ✓ matches root
680
- ```
681
-
682
- Proof path (from [`examples/merkle-tree.json`](https://github.com/metalabel/dfos/blob/main/packages/dfos-protocol/examples/merkle-tree.json)):
683
-
684
- ```json
685
- [
686
- {
687
- "hash": "4f4a9410ffcdf895c4adb880659e9b5c0dd1f23a30790684340b3eaacb045398",
688
- "position": "right"
689
- },
690
- {
691
- "hash": "90d39555bb3c223e12f5a375c3011d2462fe2e1e36b8416a0b623d5831a9b4f3",
692
- "position": "left"
693
- },
694
- {
695
- "hash": "092c79e8f80e559e404bcf660c48f3522b67aba9ff1484b0367e1a4ddef7431d",
696
- "position": "right"
697
- }
698
- ]
699
- ```
700
-
701
- ---
702
-
703
- ## Countersignatures
704
-
705
- A countersignature is a witness attestation — a third-party identity signing the same CID-committed bytes as an existing chain operation. Countersignatures use the same JWS format and `typ` (`did:dfos:content-op`) as the original operation.
706
-
707
- ### Discrimination Rule
708
-
709
- The protocol distinguishes author operations from countersignatures by comparing the `kid` DID in the JWS header to the `did` field in the operation payload:
710
-
711
- - **`kid` DID === payload `did`** → author operation (chain operation)
712
- - **`kid` DID !== payload `did`** → witness countersignature
713
-
714
- ### Semantics
715
-
716
- A countersignature proves that a witness identity has seen and attested to a specific operation. The witness signs the exact same payload (same CID), but with their own key. The countersignature's JWS header will contain the witness's `kid` (their DID URL), while the payload's `did` field remains the original author's DID.
717
-
718
- Countersignatures are not part of the chain — they do not have `previousOperationCID` links and do not affect chain state. They are auxiliary attestations stored alongside chain operations.
719
-
720
- ---
721
-
722
- ## Verification
723
-
724
- ### Identity Chain
725
-
726
- 1. Decode each JWS, parse payload as IdentityOperation
727
- 2. First op MUST be `type: "create"` — this is the genesis bootstrap:
728
- - The controller keys declared in the genesis payload are trusted because the identity does not exist before this operation. There is no prior state to verify against.
729
- - The signing key (resolved from `kid`) MUST be one of the controller keys declared in this same operation. The genesis simultaneously introduces and authorizes its own keys.
730
- - Derive the operation CID via dag-cbor canonical encoding. Verify `header.cid` matches the derived CID. Derive the DID from the CID.
731
- 3. For each subsequent op: verify `previousOperationCID` matches previous op's derived CID. Verify `createdAt` is strictly increasing (SHOULD — see Protocol Rules).
732
- 4. Verify the chain is not in a terminal state (deleted) before applying any operation.
733
- 5. Resolve `kid` — genesis uses bare key ID, non-genesis uses DID URL (extract DID, verify it matches the derived DID; extract key ID).
734
- 6. Find controller key matching key ID **in the current state** (i.e., the state after all preceding operations). Decode multikey → raw Ed25519 public key.
735
- 7. Verify EdDSA JWS signature over the signing input bytes.
736
- 8. Apply state change: `create` initializes key state, `update` replaces key state (must have at least one controller key), `delete` marks terminal.
737
-
738
- ### Content Chain
739
-
740
- 1. Decode each JWS, parse payload as ContentOperation
741
- 2. First op must be `type: "create"` — the signer is the chain creator
742
- 3. For each subsequent op: verify `previousOperationCID` matches, verify `createdAt` increasing
743
- 4. Derive the operation CID via dag-cbor canonical encoding. Verify `header.cid` matches the derived CID.
744
- 5. Verify the `kid` DID matches the payload `did` field (mismatches indicate a countersignature, not a chain operation)
745
- 6. Resolve `kid` via external key resolver (caller provides)
746
- 7. Verify EdDSA JWS signature
747
- 8. If `enforceAuthorization` is enabled and the signer DID differs from the chain creator: verify the `authorization` field contains a valid `DFOSContentWrite` VC-JWT issued by the creator DID, with `sub` matching the signer, not expired at `op.createdAt`, and `contentId` (if present) matching this chain
748
- 9. Apply state change (set document, clear, or delete)
749
-
750
- ---
751
-
752
- ## Deterministic Reference Artifacts
753
-
754
- All artifacts below are deterministic and reproducible from fixed seeds. An independent implementer can verify every value using standard Ed25519 + dag-cbor libraries. Private keys are derived from `SHA-256(UTF8("dfos-protocol-reference-key-N"))`.
755
-
756
- ### Key 1 (Genesis Controller)
757
-
758
- ```
759
- Seed: SHA-256("dfos-protocol-reference-key-1")
760
- Private key: 132d4bebdb6e62359afb930fe15d756a92ad96e6b0d47619988f5a1a55272aac
761
- Public key: ba421e272fad4f941c221e47f87d9253bdc04f7d4ad2625ae667ab9f0688ce32
762
- Multikey: z6MkrzLMNwoJSV4P3YccWcbtk8vd9LtgMKnLeaDLUqLuASjb
763
- Key ID: key_r9ev34fvc23z999veaaft8
764
- ```
765
-
766
- ### Key 2 (Rotated Controller)
767
-
768
- ```
769
- Seed: SHA-256("dfos-protocol-reference-key-2")
770
- Private key: 384f5626906db84f6a773ec46475ff2d4458e92dd4dd13fe03dbb7510f4ca2a8
771
- Public key: 0f350f994f94d675f04a325bd316ebedd740ca206eaaf609bdb641b5faa0f78c
772
- Multikey: z6MkfUd65JrAhfdgFuMCccU9ThQvjB2fJAMUHkuuajF992gK
773
- Key ID: key_ez9a874tckr3dv933d3ckd
774
- ```
775
-
776
- ### Identity Chain: Create (Genesis)
777
-
778
- Operation:
779
-
780
- ```json
781
- {
782
- "version": 1,
783
- "type": "create",
784
- "authKeys": [
785
- {
786
- "id": "key_r9ev34fvc23z999veaaft8",
787
- "type": "Multikey",
788
- "publicKeyMultibase": "z6MkrzLMNwoJSV4P3YccWcbtk8vd9LtgMKnLeaDLUqLuASjb"
789
- }
790
- ],
791
- "assertKeys": [
792
- {
793
- "id": "key_r9ev34fvc23z999veaaft8",
794
- "type": "Multikey",
795
- "publicKeyMultibase": "z6MkrzLMNwoJSV4P3YccWcbtk8vd9LtgMKnLeaDLUqLuASjb"
796
- }
797
- ],
798
- "controllerKeys": [
799
- {
800
- "id": "key_r9ev34fvc23z999veaaft8",
801
- "type": "Multikey",
802
- "publicKeyMultibase": "z6MkrzLMNwoJSV4P3YccWcbtk8vd9LtgMKnLeaDLUqLuASjb"
803
- }
804
- ],
805
- "createdAt": "2026-03-07T00:00:00.000Z"
806
- }
807
- ```
808
-
809
- JWS Header:
810
-
811
- ```json
812
- {
813
- "alg": "EdDSA",
814
- "typ": "did:dfos:identity-op",
815
- "kid": "key_r9ev34fvc23z999veaaft8",
816
- "cid": "bafyreibanjpgcqffcfhr4sptzjfthh5szohhbo5tjfulemkw7uhden5uqy"
817
- }
818
- ```
819
-
820
- JWS Signature (hex):
821
-
822
- ```
823
- 103af20cad6ebed8b1fb5edc1ee9fdb7a31a705231dab326305d502f37c3e531654ac3af31cb9ef7ba428069f709778b545b55c60a42a21d241925e2a0a2b303
824
- ```
825
-
826
- JWS Token:
827
-
828
- ```
829
- eyJhbGciOiJFZERTQSIsInR5cCI6ImRpZDpkZm9zOmlkZW50aXR5LW9wIiwia2lkIjoia2V5X3I5ZXYzNGZ2YzIzejk5OXZlYWFmdDgiLCJjaWQiOiJiYWZ5cmVpYmFuanBnY3FmZmNmaHI0c3B0empmdGhoNXN6b2hoYm81dGpmdWxlbWt3N3VoZGVuNXVxeSJ9.eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiY3JlYXRlIiwiYXV0aEtleXMiOlt7ImlkIjoia2V5X3I5ZXYzNGZ2YzIzejk5OXZlYWFmdDgiLCJ0eXBlIjoiTXVsdGlrZXkiLCJwdWJsaWNLZXlNdWx0aWJhc2UiOiJ6Nk1rcnpMTU53b0pTVjRQM1ljY1djYnRrOHZkOUx0Z01LbkxlYURMVXFMdUFTamIifV0sImFzc2VydEtleXMiOlt7ImlkIjoia2V5X3I5ZXYzNGZ2YzIzejk5OXZlYWFmdDgiLCJ0eXBlIjoiTXVsdGlrZXkiLCJwdWJsaWNLZXlNdWx0aWJhc2UiOiJ6Nk1rcnpMTU53b0pTVjRQM1ljY1djYnRrOHZkOUx0Z01LbkxlYURMVXFMdUFTamIifV0sImNvbnRyb2xsZXJLZXlzIjpbeyJpZCI6ImtleV9yOWV2MzRmdmMyM3o5OTF2ZWFhZnQ4IiwidHlwZSI6Ik11bHRpa2V5IiwicHVibGljS2V5TXVsdGliYXNlIjoiejZNa3J6TE1Od29KU1Y0UDNZY2NXY2J0azh2ZDlMdGdNS25MZWFETFVxTHVBU2piIn1dLCJjcmVhdGVkQXQiOiIyMDI2LTAzLTA3VDAwOjAwOjAwLjAwMFoifQ.EDryDK1uvtix-17cHun9t6MacFIx2rMmMF1QLzfD5TFlSsOvMcue97pCgGn3CXeLVFtVxgpCoh0kGSXioKKzAw
830
- ```
831
-
832
- Operation CID:
833
-
834
- ```
835
- bafyreibanjpgcqffcfhr4sptzjfthh5szohhbo5tjfulemkw7uhden5uqy
836
- ```
837
-
838
- **Derived DID: `did:dfos:e3vvtck42d4eacdnzvtrn6`**
839
-
840
- ### Identity Chain: Update (Key Rotation)
841
-
842
- JWS Header:
843
-
844
- ```json
845
- {
846
- "alg": "EdDSA",
847
- "typ": "did:dfos:identity-op",
848
- "kid": "did:dfos:e3vvtck42d4eacdnzvtrn6#key_r9ev34fvc23z999veaaft8",
849
- "cid": "bafyreicym4cyiednld73smbx32szaei7xdulqn4g3ste5e2w2ulajr3oqm"
850
- }
851
- ```
852
-
853
- Operation:
854
-
855
- ```json
856
- {
857
- "version": 1,
858
- "type": "update",
859
- "previousOperationCID": "bafyreibanjpgcqffcfhr4sptzjfthh5szohhbo5tjfulemkw7uhden5uqy",
860
- "authKeys": [
861
- {
862
- "id": "key_ez9a874tckr3dv933d3ckd",
863
- "type": "Multikey",
864
- "publicKeyMultibase": "z6MkfUd65JrAhfdgFuMCccU9ThQvjB2fJAMUHkuuajF992gK"
865
- }
866
- ],
867
- "assertKeys": [
868
- {
869
- "id": "key_ez9a874tckr3dv933d3ckd",
870
- "type": "Multikey",
871
- "publicKeyMultibase": "z6MkfUd65JrAhfdgFuMCccU9ThQvjB2fJAMUHkuuajF992gK"
872
- }
873
- ],
874
- "controllerKeys": [
875
- {
876
- "id": "key_ez9a874tckr3dv933d3ckd",
877
- "type": "Multikey",
878
- "publicKeyMultibase": "z6MkfUd65JrAhfdgFuMCccU9ThQvjB2fJAMUHkuuajF992gK"
879
- }
880
- ],
881
- "createdAt": "2026-03-07T00:01:00.000Z"
882
- }
883
- ```
884
-
885
- JWS Signature (hex):
886
-
887
- ```
888
- 31272ea0196038ade3e505fdb45730d68bb4a382e0273886244b19e69bea881af549a800c80bf987ec1a8d086d83c20fedd2e533453895e5b6891adaf78e5c0e
889
- ```
890
-
891
- JWS Token:
892
-
893
- ```
894
- eyJhbGciOiJFZERTQSIsInR5cCI6ImRpZDpkZm9zOmlkZW50aXR5LW9wIiwia2lkIjoiZGlkOmRmb3M6ZTN2dnRjazQyZDRlYWNkbnp2dHJuNiNrZXlfcjlldjM0ZnZjMjN6OTk5dmVhYWZ0OCIsImNpZCI6ImJhZnlyZWljeW00Y3lpZWRubGQ3M3NtYngzMnN6YWVpN3hkdWxxbjRnM3N0ZTVlMncydWxhanIzb3FtIn0.eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoidXBkYXRlIiwicHJldmlvdXNPcGVyYXRpb25DSUQiOiJiYWZ5cmVpYmFuanBnY3FmZmNmaHI0c3B0empmdGhoNXN6b2hoYm81dGpmdWxlbWt3N3VoZGVuNXVxeSIsImF1dGhLZXlzIjpbeyJpZCI6ImtleV9lejlhODc0dGNrcjNkdjkzM2QzY2tkIiwidHlwZSI6Ik11bHRpa2V5IiwicHVibGljS2V5TXVsdGliYXNlIjoiejZNa2ZVZDY1SnJBaGZkZ0Z1TUNjY1U5VGhRdmpCMmZKQU1VSGt1dWFqRjk5MmdLIn1dLCJhc3NlcnRLZXlzIjpbeyJpZCI6ImtleV9lejlhODc0dGNrcjNkdjkzM2QzY2tkIiwidHlwZSI6Ik11bHRpa2V5IiwicHVibGljS2V5TXVsdGliYXNlIjoiejZNa2ZVZDY1SnJBaGZkZ0Z1TUNjY1U5VGhRdmpCMmZKQU1VSGt1dWFqRjk5MmdLIn1dLCJjb250cm9sbGVyS2V5cyI6W3siaWQiOiJrZXlfZXo5YTg3NHRja3IzZHY5MzNkM2NrZCIsInR5cGUiOiJNdWx0aWtleSIsInB1YmxpY0tleU11bHRpYmFzZSI6Ino2TWtmVWQ2NUpyQWhmZGdGdU1DY2NVOVRoUXZqQjJmSkFNVUhrdXVhakY5OTJnSyJ9XSwiY3JlYXRlZEF0IjoiMjAyNi0wMy0wN1QwMDowMTowMC4wMDBaIn0.MScuoBlgOK3j5QX9tFcw1ou0o4LgJziGJEsZ5pvqiBr1SagAyAv5h-wajQhtg8IP7dLlM0U4leW2iRra945cDg
895
- ```
896
-
897
- Operation CID:
898
-
899
- ```
900
- bafyreicym4cyiednld73smbx32szaei7xdulqn4g3ste5e2w2ulajr3oqm
901
- ```
902
-
903
- Post-rotation: DID unchanged (`did:dfos:e3vvtck42d4eacdnzvtrn6`), controller rotated to `key_ez9a874tckr3dv933d3ckd`.
904
-
905
- ### Content Chain: Document + Create
906
-
907
- Document (flat content object):
908
-
909
- ```json
910
- {
911
- "$schema": "https://schemas.dfos.com/post/v1",
912
- "format": "short-post",
913
- "title": "Hello World",
914
- "body": "First post on the protocol.",
915
- "createdByDID": "did:dfos:e3vvtck42d4eacdnzvtrn6"
916
- }
917
- ```
918
-
919
- Document CID:
920
-
921
- ```
922
- bafyreihzwuoupfg3dxip6xmgzmxsywyii2jeoxxzbgx3zxm2in7knoi3g4
923
- ```
924
-
925
- Content Create JWS Header:
926
-
927
- ```json
928
- {
929
- "alg": "EdDSA",
930
- "typ": "did:dfos:content-op",
931
- "kid": "did:dfos:e3vvtck42d4eacdnzvtrn6#key_ez9a874tckr3dv933d3ckd",
932
- "cid": "bafyreiaedhjq64aajpwociahl5w37j6uoxr5mojoq5dnah6fpvxr5d4lxu"
933
- }
934
- ```
935
-
936
- Content Create Payload:
937
-
938
- ```json
939
- {
940
- "version": 1,
941
- "type": "create",
942
- "did": "did:dfos:e3vvtck42d4eacdnzvtrn6",
943
- "documentCID": "bafyreihzwuoupfg3dxip6xmgzmxsywyii2jeoxxzbgx3zxm2in7knoi3g4",
944
- "baseDocumentCID": null,
945
- "createdAt": "2026-03-07T00:02:00.000Z",
946
- "note": null
947
- }
948
- ```
949
-
950
- Content Create JWS Signature (hex):
951
-
952
- ```
953
- 46feaf973e4c7ebc2a0d4ad25481ace197de05b91051205c5e1c7067a85fb9d4abe4cc61625d3c853a8b0ce0345b534c8cdd07b34216f635d3c0bc0fd5d30306
954
- ```
955
-
956
- Content Create JWS Token:
957
-
958
- ```
959
- eyJhbGciOiJFZERTQSIsInR5cCI6ImRpZDpkZm9zOmNvbnRlbnQtb3AiLCJraWQiOiJkaWQ6ZGZvczplM3Z2dGNrNDJkNGVhY2RuenZ0cm42I2tleV9lejlhODc0dGNrcjNkdjkzM2QzY2tkIiwiY2lkIjoiYmFmeXJlaWFlZGhqcTY0YWFqcHdvY2lhaGw1dzM3ajZ1b3hyNW1vam9xNWRuYWg2ZnB2eHI1ZDRseHUifQ.eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiY3JlYXRlIiwiZGlkIjoiZGlkOmRmb3M6ZTN2dnRjazQyZDRlYWNkbnp2dHJuNiIsImRvY3VtZW50Q0lEIjoiYmFmeXJlaWh6d3VvdXBmZzNkeGlwNnhtZ3pteHN5d3lpaTJqZW94eHpiZ3gzenhtMmluN2tub2kzZzQiLCJiYXNlRG9jdW1lbnRDSUQiOm51bGwsImNyZWF0ZWRBdCI6IjIwMjYtMDMtMDdUMDA6MDI6MDAuMDAwWiIsIm5vdGUiOm51bGx9.Rv6vlz5MfrwqDUrSVIGs4ZfeBbkQUSBcXhxwZ6hfudSr5MxhYl08hTqLDOA0W1NMjN0Hs0IW9jXTwLwP1dMDBg
960
- ```
961
-
962
- Content Operation CID:
963
-
964
- ```
965
- bafyreiaedhjq64aajpwociahl5w37j6uoxr5mojoq5dnah6fpvxr5d4lxu
966
- ```
967
-
968
- ### Content Chain: Update
969
-
970
- Content Update Payload:
971
-
972
- ```json
973
- {
974
- "version": 1,
975
- "type": "update",
976
- "did": "did:dfos:e3vvtck42d4eacdnzvtrn6",
977
- "previousOperationCID": "bafyreiaedhjq64aajpwociahl5w37j6uoxr5mojoq5dnah6fpvxr5d4lxu",
978
- "documentCID": "bafyreidh7e36cvwy3uw5ypitcqk7uoktbkkkj7e6hxhky4o75rxn7kxilu",
979
- "baseDocumentCID": "bafyreihzwuoupfg3dxip6xmgzmxsywyii2jeoxxzbgx3zxm2in7knoi3g4",
980
- "createdAt": "2026-03-07T00:03:00.000Z",
981
- "note": "edited title and body"
982
- }
983
- ```
984
-
985
- Updated document (flat content object):
986
-
987
- ```json
988
- {
989
- "$schema": "https://schemas.dfos.com/post/v1",
990
- "format": "short-post",
991
- "title": "Hello World (edited)",
992
- "body": "Updated content.",
993
- "createdByDID": "did:dfos:e3vvtck42d4eacdnzvtrn6"
994
- }
995
- ```
996
-
997
- Document CID (edited):
998
-
999
- ```
1000
- bafyreidh7e36cvwy3uw5ypitcqk7uoktbkkkj7e6hxhky4o75rxn7kxilu
1001
- ```
1002
-
1003
- Content Update CID:
1004
-
1005
- ```
1006
- bafyreih6e5cbjitpozhzhgmfktmiohmxyn3ucwhqd3mjixizvwmlhv7hm4
1007
- ```
1008
-
1009
- ### Content Chain Verified State
1010
-
1011
- ```
1012
- Content ID: a82z92a3hndk6c97thcrn8
1013
- Genesis CID: bafyreiaedhjq64aajpwociahl5w37j6uoxr5mojoq5dnah6fpvxr5d4lxu
1014
- Head CID: bafyreih6e5cbjitpozhzhgmfktmiohmxyn3ucwhqd3mjixizvwmlhv7hm4
1015
- ```
1016
-
1017
- ---
1018
-
1019
- ## Verification Checklist (For Independent Implementers)
1020
-
1021
- Given the artifacts above, verify:
1022
-
1023
- 1. **Multikey decode**: strip `z`, base58btc decode, strip `[0xed, 0x01]` prefix → raw public key:
1024
-
1025
- ```
1026
- z6MkrzLMNwoJSV4P3YccWcbtk8vd9LtgMKnLeaDLUqLuASjb
1027
- → ba421e272fad4f941c221e47f87d9253bdc04f7d4ad2625ae667ab9f0688ce32
1028
- ```
1029
-
1030
- 2. **Genesis JWS verify**: split token on `.`, take first two segments as signing input (UTF-8 bytes), base64url-decode third segment as 64-byte signature, `ed25519.verify(signature, signingInputBytes, publicKey)` → true. The header contains `cid` alongside `alg`, `typ`, and `kid`.
1031
-
1032
- 3. **Genesis CID**: base64url-decode JWS payload → parse JSON → dag-cbor canonical encode → SHA-256 → CIDv1 → should be:
1033
-
1034
- ```
1035
- bafyreibanjpgcqffcfhr4sptzjfthh5szohhbo5tjfulemkw7uhden5uqy
1036
- ```
1037
-
1038
- 4. **CID header**: Verify each operation JWS header contains `cid` matching the derived operation CID
1039
-
1040
- 5. **DID derivation**: take raw CID bytes of genesis CID → SHA-256 → first 22 bytes → `byte % 19` → alphabet lookup → should be `e3vvtck42d4eacdnzvtrn6` → DID = `did:dfos:e3vvtck42d4eacdnzvtrn6`
1041
-
1042
- 6. **Rotation JWS**: signed by OLD controller key (key 1). Verify with key 1's public key. kid:
1043
-
1044
- ```
1045
- did:dfos:e3vvtck42d4eacdnzvtrn6#key_r9ev34fvc23z999veaaft8
1046
- ```
1047
-
1048
- 7. **Content create JWS**: signed by NEW controller key (key 2, post-rotation). Verify with key 2's public key. kid:
1049
-
1050
- ```
1051
- did:dfos:e3vvtck42d4eacdnzvtrn6#key_ez9a874tckr3dv933d3ckd
1052
- ```
1053
-
1054
- 8. **Document CID**: dag-cbor canonical encode the flat content object → SHA-256 → CIDv1 → should be:
1055
-
1056
- ```
1057
- bafyreihzwuoupfg3dxip6xmgzmxsywyii2jeoxxzbgx3zxm2in7knoi3g4
1058
- ```
1059
-
1060
- 9. **Content operation `did` field**: verify the `did` field in each content operation matches the `kid` DID in the JWS header
1061
-
1062
- 10. **Content chain integrity**: update's `previousOperationCID` matches create's operation CID
1063
-
1064
- 11. **Chain completeness**: all operation CIDs, DID derivation, key rotation, and content chain linkage verified end-to-end.
1065
-
1066
- 12. **VC-JWT credential verify**: using the issuer's public key, verify a `DFOSContentWrite` or `DFOSContentRead` credential: check EdDSA signature, `typ: "vc+jwt"`, expiration, `kid` DID URL format, `kid` DID matches `iss`, `vc` claim structure matches W3C VC Data Model v2, credential type matches expected DFOS type. Test vectors in [`examples/credential-write.json`](https://github.com/metalabel/dfos/blob/main/packages/dfos-protocol/examples/credential-write.json) and [`examples/credential-read.json`](https://github.com/metalabel/dfos/blob/main/packages/dfos-protocol/examples/credential-read.json).
1067
-
1068
- 13. **Delegated content chain verify**: using [`examples/content-delegated.json`](https://github.com/metalabel/dfos/blob/main/packages/dfos-protocol/examples/content-delegated.json), verify a content chain where the genesis is signed by the creator and a subsequent update is signed by a delegate with an embedded `DFOSContentWrite` VC-JWT in the `authorization` field. The VC must be issued by the creator DID, with `sub` matching the delegate DID.
1069
-
1070
- 14. **Number encoding determinism**: dag-cbor encode `{"version": 1, "type": "test"}` and verify:
1071
- - CBOR hex is `a2647479706564746573746776657273696f6e01` (20 bytes)
1072
- - CID is `bafyreihp6omsp6icc6ee63ox2ovsaxm6s7ikd2a7k5eh2qz2qd5soh5bsa`
1073
- - Byte at offset 19 is `0x01` (CBOR integer 1), NOT `0xf9` (CBOR float header)
1074
- - If your implementation decodes this payload from JSON (e.g., from a JWS token) and then re-encodes to dag-cbor, the CID MUST still match. This catches the JSON `float64` → CBOR float trap.
1075
-
1076
- ---
1077
-
1078
- ## Source and Verification
1079
-
1080
- All source lives in [`packages/dfos-protocol/`](https://github.com/metalabel/dfos/tree/main/packages/dfos-protocol) — self-contained, zero monorepo dependencies. 293 checks across 5 languages.
1081
-
1082
- - [`crypto/ed25519`](https://github.com/metalabel/dfos/blob/main/packages/dfos-protocol/src/crypto/ed25519.ts) — `createNewEd25519Keypair`, `importEd25519Keypair`, `signPayloadEd25519`, `isValidEd25519Signature`
1083
- - [`crypto/jws`](https://github.com/metalabel/dfos/blob/main/packages/dfos-protocol/src/crypto/jws.ts) — `createJws`, `verifyJws`, `decodeJwsUnsafe`
1084
- - [`crypto/jwt`](https://github.com/metalabel/dfos/blob/main/packages/dfos-protocol/src/crypto/jwt.ts) — `createJwt`, `verifyJwt`
1085
- - [`crypto/base64url`](https://github.com/metalabel/dfos/blob/main/packages/dfos-protocol/src/crypto/base64url.ts) — `base64urlEncode`, `base64urlDecode`
1086
- - [`crypto/multiformats`](https://github.com/metalabel/dfos/blob/main/packages/dfos-protocol/src/crypto/multiformats.ts) — `dagCborCanonicalEncode`, `dagCborCanonicalEqual`
1087
- - [`crypto/id`](https://github.com/metalabel/dfos/blob/main/packages/dfos-protocol/src/crypto/id.ts) — `generateId`, `generateIdNoPrefix`, `isValidId`
1088
- - [`chain/multikey`](https://github.com/metalabel/dfos/blob/main/packages/dfos-protocol/src/chain/multikey.ts) — `encodeEd25519Multikey`, `decodeMultikey`
1089
- - [`chain/schemas`](https://github.com/metalabel/dfos/blob/main/packages/dfos-protocol/src/chain/schemas.ts) — `IdentityOperation`, `ContentOperation`, `MultikeyPublicKey`, `VerifiedIdentity`
1090
- - [`chain/identity-chain`](https://github.com/metalabel/dfos/blob/main/packages/dfos-protocol/src/chain/identity-chain.ts) — `signIdentityOperation`, `verifyIdentityChain`
1091
- - [`chain/content-chain`](https://github.com/metalabel/dfos/blob/main/packages/dfos-protocol/src/chain/content-chain.ts) — `signContentOperation`, `verifyContentChain`
1092
- - [`chain/derivation`](https://github.com/metalabel/dfos/blob/main/packages/dfos-protocol/src/chain/derivation.ts) — `deriveChainIdentifier`, `deriveContentId`
1093
- - [`chain/beacon`](https://github.com/metalabel/dfos/blob/main/packages/dfos-protocol/src/chain/beacon.ts) — `signBeacon`, `verifyBeacon`
1094
- - [`chain/countersign`](https://github.com/metalabel/dfos/blob/main/packages/dfos-protocol/src/chain/countersign.ts) — `signCountersignature`, `verifyCountersignature`
1095
- - [`credentials/auth-token`](https://github.com/metalabel/dfos/blob/main/packages/dfos-protocol/src/credentials/auth-token.ts) — `createAuthToken`, `verifyAuthToken`
1096
- - [`credentials/credential`](https://github.com/metalabel/dfos/blob/main/packages/dfos-protocol/src/credentials/credential.ts) — `createCredential`, `verifyCredential`, `decodeCredentialUnsafe`
1097
- - [`credentials/schemas`](https://github.com/metalabel/dfos/blob/main/packages/dfos-protocol/src/credentials/schemas.ts) — `AuthTokenClaims`, `CredentialClaims`, `VCClaim`, `DFOSCredentialType`
1098
- - [`merkle/tree`](https://github.com/metalabel/dfos/blob/main/packages/dfos-protocol/src/merkle/tree.ts) — `buildMerkleTree`, `hashLeaf`
1099
- - [`merkle/proof`](https://github.com/metalabel/dfos/blob/main/packages/dfos-protocol/src/merkle/proof.ts) — `generateMerkleProof`, `verifyMerkleProof`
1100
-
1101
- ### Related Specifications
1102
-
1103
- - [DID Method: `did:dfos`](https://protocol.dfos.com/did-method) — W3C DID method specification for identity chains
1104
- - [Content Model](https://protocol.dfos.com/content-model) — Standard content schemas (post, profile) for document content objects
1105
-
1106
- ### Cross-Language Verification
1107
-
1108
- | Language | Tests | Source |
1109
- | ---------- | ----- | ---------------------------------------------------------------------------------------------------- |
1110
- | TypeScript | 190 | [`tests/`](https://github.com/metalabel/dfos/tree/main/packages/dfos-protocol/tests) |
1111
- | Python | 59 | [`verify/python/`](https://github.com/metalabel/dfos/tree/main/packages/dfos-protocol/verify/python) |
1112
- | Go | 15 | [`verify/go/`](https://github.com/metalabel/dfos/tree/main/packages/dfos-protocol/verify/go) |
1113
- | Rust | 15 | [`verify/rust/`](https://github.com/metalabel/dfos/tree/main/packages/dfos-protocol/verify/rust) |
1114
- | Swift | 14 | [`verify/swift/`](https://github.com/metalabel/dfos/tree/main/packages/dfos-protocol/verify/swift) |
1115
-
1116
- ---
1117
-
1118
- ## Special Thanks
1119
-
1120
- - **Vinny Bellavia** — [stcisgood.com](https://stcisgood.com)
1121
- - **Allison Clift-Jennings** — [Jura Labs](https://juralabs.com)