@metalabel/dfos-protocol 0.7.0 → 0.8.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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @metalabel/dfos-protocol
2
2
 
3
- Cryptographic identity and content proof — Ed25519 signed chains, content-addressed CIDs, W3C DIDs. The protocol knows about keys and document hashes. It doesn't know about posts, profiles, or any application concept.
3
+ Ed25519 signed chain primitives for cryptographic identity and verifiable content. Self-certifying DIDs, content-addressed CIDs, offline verification. The protocol operates on keys and document hashes application semantics are a separate concern, free to evolve without protocol changes.
4
4
 
5
5
  ## Install
6
6
 
@@ -13,8 +13,8 @@ npm install @metalabel/dfos-protocol
13
13
  ```ts
14
14
  // Chain verification
15
15
  import { verifyContentChain, verifyIdentityChain } from '@metalabel/dfos-protocol/chain';
16
- // Credentials (auth tokens + VC-JWT)
17
- import { createAuthToken, verifyCredential } from '@metalabel/dfos-protocol/credentials';
16
+ // Credentials (auth tokens + DFOS credentials)
17
+ import { createAuthToken, createDFOSCredential } from '@metalabel/dfos-protocol/credentials';
18
18
  // Crypto primitives
19
19
  import { createJws, dagCborCanonicalEncode, verifyJws } from '@metalabel/dfos-protocol/crypto';
20
20
  // Merkle trees
@@ -26,7 +26,7 @@ import { buildMerkleTree, verifyMerkleProof } from '@metalabel/dfos-protocol/mer
26
26
  | Export | Description |
27
27
  | -------------------------------------- | ----------------------------------------------------------------------- |
28
28
  | `@metalabel/dfos-protocol/chain` | Identity and content chain signing, verification, beacons, countersigns |
29
- | `@metalabel/dfos-protocol/credentials` | Auth tokens (DID-signed JWT) and VC-JWT credentials for authorization |
29
+ | `@metalabel/dfos-protocol/credentials` | Auth tokens (DID-signed JWT) and DFOS credentials for authorization |
30
30
  | `@metalabel/dfos-protocol/crypto` | Ed25519, JWS, JWT, dag-cbor, base64url, ID generation |
31
31
  | `@metalabel/dfos-protocol/merkle` | SHA-256 binary merkle tree, inclusion proofs |
32
32
 
@@ -47,24 +47,11 @@ The `examples/` directory contains deterministic reference fixtures that can be
47
47
  - `identity-delete.json` — genesis + delete (terminal)
48
48
  - `content-lifecycle.json` — create + update (with both documents)
49
49
  - `content-delete.json` — create + delete
50
- - `content-delegated.json` — creator genesis + delegated update with DFOSContentWrite VC-JWT
51
- - `credential-write.json` — DFOSContentWrite VC-JWT (broad + content-narrowed)
52
- - `credential-read.json` — DFOSContentRead VC-JWT
50
+ - `content-delegated.json` — creator genesis + delegated update with DFOS write credential
51
+ - `credential-write.json` — DFOS write credential (broad + content-narrowed)
52
+ - `credential-read.json` — DFOS read credential
53
53
  - `merkle-tree.json` — 5 content IDs → sorted tree → root, with inclusion proof
54
- - `beacon.json` — signed merkle root announcement with witness countersignature
55
-
56
- ## Cross-Language Verification
57
-
58
- The `verify/` directory contains independent verification suites that re-derive CIDs and verify signatures from the reference fixtures — proving protocol correctness across implementations:
59
-
60
- | Language | Path | Status |
61
- | -------- | ---------------- | ------- |
62
- | Go | `verify/go/` | Passing |
63
- | Python | `verify/python/` | Passing |
64
- | Rust | `verify/rust/` | Passing |
65
- | Swift | `verify/swift/` | Passing |
66
-
67
- Each suite uses only its language's native Ed25519, dag-cbor, and multihash implementations — no shared code with the TypeScript reference.
54
+ - `beacon.json` — signed manifest pointer announcement with witness countersignature
68
55
 
69
56
  ## License
70
57
 
@@ -1,140 +1,6 @@
1
- import { z } from 'zod';
2
-
3
- /** Function that signs a byte array and returns a signature */
4
- type Signer = (message: Uint8Array) => Promise<Uint8Array>;
5
- declare const MultikeyPublicKey: z.ZodObject<{
6
- id: z.ZodString;
7
- type: z.ZodLiteral<"Multikey">;
8
- publicKeyMultibase: z.ZodString;
9
- }, z.core.$strict>;
10
- type MultikeyPublicKey = z.infer<typeof MultikeyPublicKey>;
11
- declare const IdentityOperation: z.ZodDiscriminatedUnion<[z.ZodObject<{
12
- version: z.ZodLiteral<1>;
13
- type: z.ZodLiteral<"create">;
14
- authKeys: z.ZodArray<z.ZodObject<{
15
- id: z.ZodString;
16
- type: z.ZodLiteral<"Multikey">;
17
- publicKeyMultibase: z.ZodString;
18
- }, z.core.$strict>>;
19
- assertKeys: z.ZodArray<z.ZodObject<{
20
- id: z.ZodString;
21
- type: z.ZodLiteral<"Multikey">;
22
- publicKeyMultibase: z.ZodString;
23
- }, z.core.$strict>>;
24
- controllerKeys: z.ZodArray<z.ZodObject<{
25
- id: z.ZodString;
26
- type: z.ZodLiteral<"Multikey">;
27
- publicKeyMultibase: z.ZodString;
28
- }, z.core.$strict>>;
29
- createdAt: z.ZodISODateTime;
30
- }, z.core.$strict>, z.ZodObject<{
31
- version: z.ZodLiteral<1>;
32
- type: z.ZodLiteral<"update">;
33
- previousOperationCID: z.ZodString;
34
- authKeys: z.ZodArray<z.ZodObject<{
35
- id: z.ZodString;
36
- type: z.ZodLiteral<"Multikey">;
37
- publicKeyMultibase: z.ZodString;
38
- }, z.core.$strict>>;
39
- assertKeys: z.ZodArray<z.ZodObject<{
40
- id: z.ZodString;
41
- type: z.ZodLiteral<"Multikey">;
42
- publicKeyMultibase: z.ZodString;
43
- }, z.core.$strict>>;
44
- controllerKeys: z.ZodArray<z.ZodObject<{
45
- id: z.ZodString;
46
- type: z.ZodLiteral<"Multikey">;
47
- publicKeyMultibase: z.ZodString;
48
- }, z.core.$strict>>;
49
- createdAt: z.ZodISODateTime;
50
- }, z.core.$strict>, z.ZodObject<{
51
- version: z.ZodLiteral<1>;
52
- type: z.ZodLiteral<"delete">;
53
- previousOperationCID: z.ZodString;
54
- createdAt: z.ZodISODateTime;
55
- }, z.core.$strict>], "type">;
56
- type IdentityOperation = z.infer<typeof IdentityOperation>;
57
- declare const VerifiedIdentity: z.ZodObject<{
58
- did: z.ZodString;
59
- isDeleted: z.ZodBoolean;
60
- authKeys: z.ZodArray<z.ZodObject<{
61
- id: z.ZodString;
62
- type: z.ZodLiteral<"Multikey">;
63
- publicKeyMultibase: z.ZodString;
64
- }, z.core.$strict>>;
65
- assertKeys: z.ZodArray<z.ZodObject<{
66
- id: z.ZodString;
67
- type: z.ZodLiteral<"Multikey">;
68
- publicKeyMultibase: z.ZodString;
69
- }, z.core.$strict>>;
70
- controllerKeys: z.ZodArray<z.ZodObject<{
71
- id: z.ZodString;
72
- type: z.ZodLiteral<"Multikey">;
73
- publicKeyMultibase: z.ZodString;
74
- }, z.core.$strict>>;
75
- }, z.core.$strict>;
76
- type VerifiedIdentity = z.infer<typeof VerifiedIdentity>;
77
- declare const ContentOperation: z.ZodDiscriminatedUnion<[z.ZodObject<{
78
- version: z.ZodLiteral<1>;
79
- type: z.ZodLiteral<"create">;
80
- did: z.ZodString;
81
- documentCID: z.ZodString;
82
- baseDocumentCID: z.ZodNullable<z.ZodString>;
83
- createdAt: z.ZodISODateTime;
84
- note: z.ZodNullable<z.ZodString>;
85
- }, z.core.$strict>, z.ZodObject<{
86
- version: z.ZodLiteral<1>;
87
- type: z.ZodLiteral<"update">;
88
- did: z.ZodString;
89
- previousOperationCID: z.ZodString;
90
- documentCID: z.ZodNullable<z.ZodString>;
91
- baseDocumentCID: z.ZodNullable<z.ZodString>;
92
- createdAt: z.ZodISODateTime;
93
- note: z.ZodNullable<z.ZodString>;
94
- /** VC-JWT authorizing this operation when signer is not the chain creator */
95
- authorization: z.ZodOptional<z.ZodString>;
96
- }, z.core.$strict>, z.ZodObject<{
97
- version: z.ZodLiteral<1>;
98
- type: z.ZodLiteral<"delete">;
99
- did: z.ZodString;
100
- previousOperationCID: z.ZodString;
101
- createdAt: z.ZodISODateTime;
102
- note: z.ZodNullable<z.ZodString>;
103
- /** VC-JWT authorizing this operation when signer is not the chain creator */
104
- authorization: z.ZodOptional<z.ZodString>;
105
- }, z.core.$strict>], "type">;
106
- type ContentOperation = z.infer<typeof ContentOperation>;
107
- /** Beacon: floating signed merkle root announcement */
108
- declare const BeaconPayload: z.ZodObject<{
109
- version: z.ZodLiteral<1>;
110
- type: z.ZodLiteral<"beacon">;
111
- did: z.ZodString;
112
- merkleRoot: z.ZodString;
113
- createdAt: z.ZodISODateTime;
114
- }, z.core.$strict>;
115
- type BeaconPayload = z.infer<typeof BeaconPayload>;
116
- /** Max CBOR-encoded payload size for artifacts (bytes) — protocol constant */
117
- declare const MAX_ARTIFACT_PAYLOAD_SIZE = 16384;
118
- /** Artifact: standalone signed inline document, immutable, CID-addressable */
119
- declare const ArtifactPayload: z.ZodObject<{
120
- version: z.ZodLiteral<1>;
121
- type: z.ZodLiteral<"artifact">;
122
- did: z.ZodString;
123
- content: z.ZodObject<{
124
- $schema: z.ZodString;
125
- }, z.core.$catchall<z.ZodUnknown>>;
126
- createdAt: z.ZodISODateTime;
127
- }, z.core.$strict>;
128
- type ArtifactPayload = z.infer<typeof ArtifactPayload>;
129
- /** Countersign: standalone witness attestation referencing a target operation by CID */
130
- declare const CountersignPayload: z.ZodObject<{
131
- version: z.ZodLiteral<1>;
132
- type: z.ZodLiteral<"countersign">;
133
- did: z.ZodString;
134
- targetCID: z.ZodString;
135
- createdAt: z.ZodISODateTime;
136
- }, z.core.$strict>;
137
- type CountersignPayload = z.infer<typeof CountersignPayload>;
1
+ import { I as IdentityOperation, S as Signer, V as VerifiedIdentity, C as ContentOperation, B as BeaconPayload, a as CountersignPayload, A as ArtifactPayload } from '../schemas-BEl38wrI.js';
2
+ export { M as MAX_ARTIFACT_PAYLOAD_SIZE, b as MultikeyPublicKey, R as RevocationPayload } from '../schemas-BEl38wrI.js';
3
+ import 'zod';
138
4
 
139
5
  /** Ed25519 public key multicodec value */
140
6
  declare const ED25519_PUB_MULTICODEC = 237;
@@ -260,7 +126,8 @@ declare const signContentOperation: (input: {
260
126
  * - Genesis (create) operation: the signer is the chain creator, always authorized
261
127
  * - Subsequent operations signed by the creator DID: authorized (no credential needed)
262
128
  * - Subsequent operations signed by a different DID: must include an `authorization`
263
- * field containing a valid DFOSContentWrite VC-JWT issued by the creator DID
129
+ * field containing a valid DFOS credential with a delegation chain rooting at
130
+ * the creator DID
264
131
  */
265
132
  declare const verifyContentChain: (input: {
266
133
  log: string[];
@@ -268,13 +135,15 @@ declare const verifyContentChain: (input: {
268
135
  resolveKey: (kid: string) => Promise<Uint8Array>;
269
136
  /**
270
137
  * Enforce creator-sovereignty authorization. When true, non-creator signers
271
- * must include a DFOSContentWrite VC-JWT in the operation's `authorization`
272
- * field. When false (default), any signer with a valid signature is accepted.
273
- *
274
- * Web relays should set this to true. Applications migrating to VC-based
275
- * authorization can enable this once all chains include authorization fields.
138
+ * must include a DFOS credential in the operation's `authorization` field
139
+ * with a delegation chain rooting at the creator DID.
276
140
  */
277
141
  enforceAuthorization?: boolean;
142
+ /**
143
+ * Resolve a DID to a VerifiedIdentity. Required when `enforceAuthorization`
144
+ * is true, as credential verification needs identity resolution.
145
+ */
146
+ resolveIdentity?: (did: string) => Promise<VerifiedIdentity | undefined>;
278
147
  }) => Promise<VerifiedContentChain>;
279
148
  /**
280
149
  * Verify a single new content operation against already-verified chain state
@@ -294,12 +163,21 @@ declare const verifyContentExtensionFromTrustedState: (input: {
294
163
  resolveKey: (kid: string) => Promise<Uint8Array>;
295
164
  /** Enforce creator-sovereignty authorization (see verifyContentChain) */
296
165
  enforceAuthorization?: boolean;
166
+ /** Resolve a DID to a VerifiedIdentity. Required when enforceAuthorization is true. */
167
+ resolveIdentity?: (did: string) => Promise<VerifiedIdentity | undefined>;
297
168
  }) => Promise<{
298
169
  state: VerifiedContentChain;
299
170
  operationCID: string;
300
171
  createdAt: string;
301
172
  }>;
302
173
 
174
+ interface VerifiedBeacon {
175
+ did: string;
176
+ manifestContentId: string;
177
+ createdAt: string;
178
+ signerKeyId: string;
179
+ beaconCID: string;
180
+ }
303
181
  /**
304
182
  * Sign a beacon announcement as a JWS
305
183
  */
@@ -311,10 +189,6 @@ declare const signBeacon: (input: {
311
189
  jwsToken: string;
312
190
  beaconCID: string;
313
191
  }>;
314
- interface VerifiedBeacon {
315
- payload: BeaconPayload;
316
- beaconCID: string;
317
- }
318
192
  /**
319
193
  * Verify a beacon JWS — signature, CID, payload schema, clock skew
320
194
  */
@@ -381,4 +255,36 @@ declare const verifyArtifact: (input: {
381
255
  resolveKey: (kid: string) => Promise<Uint8Array>;
382
256
  }) => Promise<VerifiedArtifact>;
383
257
 
384
- export { ArtifactPayload, BeaconPayload, ContentOperation, CountersignPayload, ED25519_PRIV_MULTICODEC, ED25519_PUB_MULTICODEC, IdentityOperation, MAX_ARTIFACT_PAYLOAD_SIZE, MultikeyPublicKey, type Signer, type VerifiedArtifact, type VerifiedBeacon, type VerifiedContentChain, type VerifiedCountersignature, VerifiedIdentity, decodeMultikey, deriveChainIdentifier, deriveContentId, encodeEd25519Multikey, signArtifact, signBeacon, signContentOperation, signCountersignature, signIdentityOperation, verifyArtifact, verifyBeacon, verifyContentChain, verifyContentExtensionFromTrustedState, verifyCountersignature, verifyIdentityChain, verifyIdentityExtensionFromTrustedState };
258
+ interface VerifiedRevocation {
259
+ /** The issuer DID that revoked the credential */
260
+ did: string;
261
+ /** CID of the revoked credential */
262
+ credentialCID: string;
263
+ /** Timestamp of the revocation */
264
+ createdAt: string;
265
+ /** kid from the JWS header */
266
+ signerKeyId: string;
267
+ /** CID of the revocation artifact itself */
268
+ revocationCID: string;
269
+ }
270
+ /**
271
+ * Sign a revocation artifact as a JWS
272
+ */
273
+ declare const signRevocation: (input: {
274
+ issuerDID: string;
275
+ credentialCID: string;
276
+ signer: Signer;
277
+ keyId: string;
278
+ }) => Promise<{
279
+ jwsToken: string;
280
+ revocationCID: string;
281
+ }>;
282
+ /**
283
+ * Verify a revocation JWS — signature, CID, payload schema, signer match
284
+ */
285
+ declare const verifyRevocation: (input: {
286
+ jwsToken: string;
287
+ resolveKey: (kid: string) => Promise<Uint8Array>;
288
+ }) => Promise<VerifiedRevocation>;
289
+
290
+ export { ArtifactPayload, BeaconPayload, ContentOperation, CountersignPayload, ED25519_PRIV_MULTICODEC, ED25519_PUB_MULTICODEC, IdentityOperation, Signer, type VerifiedArtifact, type VerifiedBeacon, type VerifiedContentChain, type VerifiedCountersignature, VerifiedIdentity, type VerifiedRevocation, decodeMultikey, deriveChainIdentifier, deriveContentId, encodeEd25519Multikey, signArtifact, signBeacon, signContentOperation, signCountersignature, signIdentityOperation, signRevocation, verifyArtifact, verifyBeacon, verifyContentChain, verifyContentExtensionFromTrustedState, verifyCountersignature, verifyIdentityChain, verifyIdentityExtensionFromTrustedState, verifyRevocation };
@@ -3,30 +3,34 @@ import {
3
3
  BeaconPayload,
4
4
  ContentOperation,
5
5
  CountersignPayload,
6
- ED25519_PRIV_MULTICODEC,
7
- ED25519_PUB_MULTICODEC,
8
6
  IdentityOperation,
9
7
  MAX_ARTIFACT_PAYLOAD_SIZE,
10
8
  MultikeyPublicKey,
9
+ RevocationPayload,
11
10
  VerifiedIdentity,
12
- decodeMultikey,
13
11
  deriveChainIdentifier,
14
12
  deriveContentId,
15
- encodeEd25519Multikey,
16
13
  signArtifact,
17
14
  signBeacon,
18
15
  signContentOperation,
19
16
  signCountersignature,
20
17
  signIdentityOperation,
18
+ signRevocation,
21
19
  verifyArtifact,
22
20
  verifyBeacon,
23
21
  verifyContentChain,
24
22
  verifyContentExtensionFromTrustedState,
25
23
  verifyCountersignature,
26
24
  verifyIdentityChain,
27
- verifyIdentityExtensionFromTrustedState
28
- } from "../chunk-QKHP7UVL.js";
29
- import "../chunk-CZSEEZLL.js";
25
+ verifyIdentityExtensionFromTrustedState,
26
+ verifyRevocation
27
+ } from "../chunk-LQ56P4SU.js";
28
+ import {
29
+ ED25519_PRIV_MULTICODEC,
30
+ ED25519_PUB_MULTICODEC,
31
+ decodeMultikey,
32
+ encodeEd25519Multikey
33
+ } from "../chunk-MEV6QVLC.js";
30
34
  import "../chunk-ZXXP5W5N.js";
31
35
  export {
32
36
  ArtifactPayload,
@@ -38,6 +42,7 @@ export {
38
42
  IdentityOperation,
39
43
  MAX_ARTIFACT_PAYLOAD_SIZE,
40
44
  MultikeyPublicKey,
45
+ RevocationPayload,
41
46
  VerifiedIdentity,
42
47
  decodeMultikey,
43
48
  deriveChainIdentifier,
@@ -48,11 +53,13 @@ export {
48
53
  signContentOperation,
49
54
  signCountersignature,
50
55
  signIdentityOperation,
56
+ signRevocation,
51
57
  verifyArtifact,
52
58
  verifyBeacon,
53
59
  verifyContentChain,
54
60
  verifyContentExtensionFromTrustedState,
55
61
  verifyCountersignature,
56
62
  verifyIdentityChain,
57
- verifyIdentityExtensionFromTrustedState
63
+ verifyIdentityExtensionFromTrustedState,
64
+ verifyRevocation
58
65
  };