@metalabel/dfos-protocol 0.9.0 → 0.11.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 +7 -11
- package/dist/chain/index.d.ts +37 -33
- package/dist/chain/index.js +27 -9
- package/dist/{chunk-ZXXP5W5N.js → chunk-GQOZJKKO.js} +58 -10
- package/dist/{chunk-24VGJGUM.js → chunk-LQFOBE6X.js} +25 -27
- package/dist/{chunk-UEJ364OG.js → chunk-SDUOUFTF.js} +110 -75
- package/dist/credentials/index.d.ts +3 -12
- package/dist/credentials/index.js +2 -2
- package/dist/crypto/index.d.ts +16 -7
- package/dist/crypto/index.js +3 -1
- package/dist/index.d.ts +3 -4
- package/dist/index.js +29 -21
- package/dist/{schemas-BEl38wrI.d.ts → schemas-Myod8ES9.d.ts} +58 -14
- package/examples/content-delegated.json +11 -11
- package/examples/content-delete.json +5 -5
- package/examples/content-lifecycle.json +9 -9
- package/examples/credential-read.json +3 -3
- package/examples/credential-write.json +5 -5
- package/examples/identity-delete.json +4 -4
- package/examples/identity-genesis.json +3 -3
- package/examples/identity-rotation.json +4 -4
- package/examples/identity-services.json +38 -0
- package/package.json +10 -14
- package/dist/chunk-E5CFQG2B.js +0 -99
- package/dist/merkle/index.d.ts +0 -45
- package/dist/merkle/index.js +0 -14
- package/examples/beacon.json +0 -14
- package/examples/merkle-tree.json +0 -28
- package/schemas/manifest.v1.json +0 -29
|
@@ -4,14 +4,14 @@ import {
|
|
|
4
4
|
matchesResource,
|
|
5
5
|
verifyDFOSCredential,
|
|
6
6
|
verifyDelegationChain
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-LQFOBE6X.js";
|
|
8
8
|
import {
|
|
9
9
|
createJws,
|
|
10
10
|
dagCborCanonicalEncode,
|
|
11
11
|
decodeJwsUnsafe,
|
|
12
12
|
generateIdNoPrefix,
|
|
13
13
|
verifyJws
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-GQOZJKKO.js";
|
|
15
15
|
|
|
16
16
|
// src/chain/schemas.ts
|
|
17
17
|
import { z } from "zod";
|
|
@@ -21,11 +21,49 @@ var MAX_CID = 256;
|
|
|
21
21
|
var MAX_NOTE = 256;
|
|
22
22
|
var MAX_KEYS_PER_ROLE = 16;
|
|
23
23
|
var MAX_DID = 256;
|
|
24
|
+
var MAX_SERVICE_ID = 64;
|
|
25
|
+
var MAX_SERVICE_TYPE = 64;
|
|
26
|
+
var MAX_SERVICE_STRING = 512;
|
|
27
|
+
var MAX_RELATION = 64;
|
|
28
|
+
var MAX_SERVICES_ENTRIES = 16;
|
|
29
|
+
var MAX_SERVICES_PAYLOAD_SIZE = 8192;
|
|
24
30
|
var MultikeyPublicKey = z.strictObject({
|
|
25
31
|
id: z.string().max(MAX_KEY_ID),
|
|
26
32
|
type: z.literal("Multikey"),
|
|
27
33
|
publicKeyMultibase: z.string().max(MAX_PUBLIC_KEY_MULTIBASE)
|
|
28
34
|
});
|
|
35
|
+
var CONTENT_ID_ANCHOR_RE = /^[2346789acdefhknrtvz]{31}$/;
|
|
36
|
+
var ARTIFACT_CID_ANCHOR_RE = /^baf[a-z2-7]{20,}$/;
|
|
37
|
+
var ServiceEntry = z.object({
|
|
38
|
+
id: z.string().min(1).max(MAX_SERVICE_ID),
|
|
39
|
+
type: z.string().min(1).max(MAX_SERVICE_TYPE)
|
|
40
|
+
}).catchall(z.unknown()).superRefine((entry, ctx) => {
|
|
41
|
+
if (entry.type === "DfosRelay") {
|
|
42
|
+
const endpoint = entry["endpoint"];
|
|
43
|
+
if (typeof endpoint !== "string" || endpoint.length < 1 || endpoint.length > MAX_SERVICE_STRING) {
|
|
44
|
+
ctx.addIssue({ code: "custom", message: "DfosRelay requires a non-empty endpoint string" });
|
|
45
|
+
}
|
|
46
|
+
} else if (entry.type === "ContentAnchor") {
|
|
47
|
+
const label = entry["label"];
|
|
48
|
+
const anchor = entry["anchor"];
|
|
49
|
+
if (typeof label !== "string" || label.length < 1 || label.length > MAX_SERVICE_STRING) {
|
|
50
|
+
ctx.addIssue({
|
|
51
|
+
code: "custom",
|
|
52
|
+
message: "ContentAnchor requires a non-empty label string"
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
if (typeof anchor !== "string" || !(CONTENT_ID_ANCHOR_RE.test(anchor) || ARTIFACT_CID_ANCHOR_RE.test(anchor))) {
|
|
56
|
+
ctx.addIssue({
|
|
57
|
+
code: "custom",
|
|
58
|
+
message: "ContentAnchor anchor must be a 31-char contentId or a CIDv1 artifact CID"
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
var ServicesArray = z.array(ServiceEntry).max(MAX_SERVICES_ENTRIES).refine(
|
|
64
|
+
(arr) => new Set(arr.map((e) => e.id)).size === arr.length,
|
|
65
|
+
"service entry ids must be unique"
|
|
66
|
+
);
|
|
29
67
|
var Iso8601 = z.iso.datetime({ offset: false, precision: 3 });
|
|
30
68
|
var CIDString = z.string().max(MAX_CID);
|
|
31
69
|
var IdentityCreate = z.strictObject({
|
|
@@ -34,6 +72,9 @@ var IdentityCreate = z.strictObject({
|
|
|
34
72
|
authKeys: z.array(MultikeyPublicKey).max(MAX_KEYS_PER_ROLE),
|
|
35
73
|
assertKeys: z.array(MultikeyPublicKey).max(MAX_KEYS_PER_ROLE),
|
|
36
74
|
controllerKeys: z.array(MultikeyPublicKey).max(MAX_KEYS_PER_ROLE),
|
|
75
|
+
// Full-state discovery vocabulary. Optional so ops without services encode
|
|
76
|
+
// identically (undefined strips under canonical CBOR — CID-neutral).
|
|
77
|
+
services: ServicesArray.optional(),
|
|
37
78
|
createdAt: Iso8601
|
|
38
79
|
});
|
|
39
80
|
var IdentityUpdate = z.strictObject({
|
|
@@ -43,6 +84,8 @@ var IdentityUpdate = z.strictObject({
|
|
|
43
84
|
authKeys: z.array(MultikeyPublicKey).max(MAX_KEYS_PER_ROLE),
|
|
44
85
|
assertKeys: z.array(MultikeyPublicKey).max(MAX_KEYS_PER_ROLE),
|
|
45
86
|
controllerKeys: z.array(MultikeyPublicKey).min(1, "update must have at least one controller key").max(MAX_KEYS_PER_ROLE),
|
|
87
|
+
// Full-state: an update REPLACES the entire services set (omit to clear).
|
|
88
|
+
services: ServicesArray.optional(),
|
|
46
89
|
createdAt: Iso8601
|
|
47
90
|
});
|
|
48
91
|
var IdentityDelete = z.strictObject({
|
|
@@ -61,7 +104,9 @@ var VerifiedIdentity = z.strictObject({
|
|
|
61
104
|
isDeleted: z.boolean(),
|
|
62
105
|
authKeys: z.array(MultikeyPublicKey).max(MAX_KEYS_PER_ROLE),
|
|
63
106
|
assertKeys: z.array(MultikeyPublicKey).max(MAX_KEYS_PER_ROLE),
|
|
64
|
-
controllerKeys: z.array(MultikeyPublicKey).max(MAX_KEYS_PER_ROLE)
|
|
107
|
+
controllerKeys: z.array(MultikeyPublicKey).max(MAX_KEYS_PER_ROLE),
|
|
108
|
+
/** Resolved discovery vocabulary — projection of the winning head's services */
|
|
109
|
+
services: ServicesArray
|
|
65
110
|
});
|
|
66
111
|
var ContentCreate = z.strictObject({
|
|
67
112
|
version: z.literal(1),
|
|
@@ -99,13 +144,6 @@ var ContentOperation = z.discriminatedUnion("type", [
|
|
|
99
144
|
ContentUpdate,
|
|
100
145
|
ContentDelete
|
|
101
146
|
]);
|
|
102
|
-
var BeaconPayload = z.strictObject({
|
|
103
|
-
version: z.literal(1),
|
|
104
|
-
type: z.literal("beacon"),
|
|
105
|
-
did: z.string().max(MAX_DID),
|
|
106
|
-
manifestContentId: z.string().max(MAX_CID),
|
|
107
|
-
createdAt: Iso8601
|
|
108
|
-
});
|
|
109
147
|
var MAX_SCHEMA = 256;
|
|
110
148
|
var MAX_ARTIFACT_PAYLOAD_SIZE = 16384;
|
|
111
149
|
var ArtifactContent = z.object({ $schema: z.string().max(MAX_SCHEMA) }).catchall(z.unknown());
|
|
@@ -121,6 +159,7 @@ var CountersignPayload = z.strictObject({
|
|
|
121
159
|
type: z.literal("countersign"),
|
|
122
160
|
did: z.string().max(MAX_DID),
|
|
123
161
|
targetCID: CIDString,
|
|
162
|
+
relation: z.string().min(1).max(MAX_RELATION).optional(),
|
|
124
163
|
createdAt: Iso8601
|
|
125
164
|
});
|
|
126
165
|
var RevocationPayload = z.strictObject({
|
|
@@ -140,6 +179,27 @@ var deriveContentId = (cidBytes) => {
|
|
|
140
179
|
return generateIdNoPrefix({ seed: cidBytes });
|
|
141
180
|
};
|
|
142
181
|
|
|
182
|
+
// src/chain/services.ts
|
|
183
|
+
var assertServicesWithinCap = async (services) => {
|
|
184
|
+
const encoded = await dagCborCanonicalEncode(services);
|
|
185
|
+
if (encoded.bytes.length > MAX_SERVICES_PAYLOAD_SIZE) {
|
|
186
|
+
throw new Error(
|
|
187
|
+
`services payload exceeds max size: ${encoded.bytes.length} > ${MAX_SERVICES_PAYLOAD_SIZE}`
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
var classifyAnchor = (anchor) => {
|
|
192
|
+
if (CONTENT_ID_ANCHOR_RE.test(anchor)) return "chain";
|
|
193
|
+
if (ARTIFACT_CID_ANCHOR_RE.test(anchor)) return "artifact";
|
|
194
|
+
return "invalid";
|
|
195
|
+
};
|
|
196
|
+
var RECOGNIZED_SERVICE_TYPES = ["DfosRelay", "ContentAnchor"];
|
|
197
|
+
var isRecognizedServiceType = (type) => RECOGNIZED_SERVICE_TYPES.includes(type);
|
|
198
|
+
var relayEndpoints = (services) => services.filter((e) => e.type === "DfosRelay").map((e) => e["endpoint"]).filter((v) => typeof v === "string");
|
|
199
|
+
var anchorsByLabel = (services, label) => services.filter(
|
|
200
|
+
(e) => e.type === "ContentAnchor" && e["label"] === label
|
|
201
|
+
);
|
|
202
|
+
|
|
143
203
|
// src/chain/identity-chain.ts
|
|
144
204
|
var signIdentityOperation = async (input) => {
|
|
145
205
|
const kid = input.identityDID ? `${input.identityDID}#${input.keyId}` : input.keyId;
|
|
@@ -162,6 +222,7 @@ var verifyIdentityChain = async (input) => {
|
|
|
162
222
|
authKeys: [],
|
|
163
223
|
assertKeys: [],
|
|
164
224
|
controllerKeys: [],
|
|
225
|
+
services: [],
|
|
165
226
|
seenKeys: /* @__PURE__ */ new Map()
|
|
166
227
|
};
|
|
167
228
|
for (const [idx, jwsToken] of input.log.entries()) {
|
|
@@ -190,6 +251,7 @@ var verifyIdentityChain = async (input) => {
|
|
|
190
251
|
state.authKeys = op.authKeys;
|
|
191
252
|
state.assertKeys = op.assertKeys;
|
|
192
253
|
state.controllerKeys = op.controllerKeys;
|
|
254
|
+
state.services = op.services ?? [];
|
|
193
255
|
}
|
|
194
256
|
if (op.type === "update" || op.type === "delete") {
|
|
195
257
|
if (op.previousOperationCID !== state.previousOperationCID) {
|
|
@@ -217,6 +279,13 @@ var verifyIdentityChain = async (input) => {
|
|
|
217
279
|
throw new Error(`log[${idx}]: cannot repeat key ids in same usage`);
|
|
218
280
|
}
|
|
219
281
|
});
|
|
282
|
+
if (op.services) {
|
|
283
|
+
try {
|
|
284
|
+
await assertServicesWithinCap(op.services);
|
|
285
|
+
} catch (e) {
|
|
286
|
+
throw new Error(`log[${idx}]: ${e.message}`);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
220
289
|
}
|
|
221
290
|
const encoded = await dagCborCanonicalEncode(op);
|
|
222
291
|
const operationCID = encoded.cid.toString();
|
|
@@ -271,6 +340,7 @@ var verifyIdentityChain = async (input) => {
|
|
|
271
340
|
state.authKeys = op.authKeys;
|
|
272
341
|
state.assertKeys = op.assertKeys;
|
|
273
342
|
state.controllerKeys = op.controllerKeys;
|
|
343
|
+
state.services = op.services ?? [];
|
|
274
344
|
break;
|
|
275
345
|
case "delete":
|
|
276
346
|
state.isDeleted = true;
|
|
@@ -283,7 +353,8 @@ var verifyIdentityChain = async (input) => {
|
|
|
283
353
|
isDeleted: state.isDeleted,
|
|
284
354
|
authKeys: state.authKeys,
|
|
285
355
|
assertKeys: state.assertKeys,
|
|
286
|
-
controllerKeys: state.controllerKeys
|
|
356
|
+
controllerKeys: state.controllerKeys,
|
|
357
|
+
services: state.services
|
|
287
358
|
};
|
|
288
359
|
};
|
|
289
360
|
var verifyIdentityExtensionFromTrustedState = async (input) => {
|
|
@@ -342,19 +413,22 @@ var verifyIdentityExtensionFromTrustedState = async (input) => {
|
|
|
342
413
|
throw new Error("cannot repeat key ids in same usage");
|
|
343
414
|
}
|
|
344
415
|
});
|
|
416
|
+
if (op.services) await assertServicesWithinCap(op.services);
|
|
345
417
|
}
|
|
346
418
|
const newState = op.type === "update" ? {
|
|
347
419
|
did: currentState.did,
|
|
348
420
|
isDeleted: false,
|
|
349
421
|
authKeys: op.authKeys,
|
|
350
422
|
assertKeys: op.assertKeys,
|
|
351
|
-
controllerKeys: op.controllerKeys
|
|
423
|
+
controllerKeys: op.controllerKeys,
|
|
424
|
+
services: op.services ?? []
|
|
352
425
|
} : {
|
|
353
426
|
did: currentState.did,
|
|
354
427
|
isDeleted: true,
|
|
355
428
|
authKeys: currentState.authKeys,
|
|
356
429
|
assertKeys: currentState.assertKeys,
|
|
357
|
-
controllerKeys: currentState.controllerKeys
|
|
430
|
+
controllerKeys: currentState.controllerKeys,
|
|
431
|
+
services: currentState.services
|
|
358
432
|
};
|
|
359
433
|
return { state: newState, operationCID, createdAt: op.createdAt };
|
|
360
434
|
};
|
|
@@ -383,10 +457,14 @@ var verifyOperationAuthorization = async (input) => {
|
|
|
383
457
|
resolveIdentity: input.resolveIdentity,
|
|
384
458
|
now: opCreatedAtUnix
|
|
385
459
|
});
|
|
460
|
+
if (input.isRevoked && await input.isRevoked(credential.iss, credential.credentialCID)) {
|
|
461
|
+
throw new Error("credential is revoked");
|
|
462
|
+
}
|
|
386
463
|
await verifyDelegationChain(credential, {
|
|
387
464
|
resolveIdentity: input.resolveIdentity,
|
|
388
465
|
rootDID: input.creatorDID,
|
|
389
|
-
now: opCreatedAtUnix
|
|
466
|
+
now: opCreatedAtUnix,
|
|
467
|
+
...input.isRevoked ? { isRevoked: input.isRevoked } : {}
|
|
390
468
|
});
|
|
391
469
|
if (credential.aud !== "*" && credential.aud !== input.operationDID) {
|
|
392
470
|
throw new Error(
|
|
@@ -470,7 +548,8 @@ var verifyContentChain = async (input) => {
|
|
|
470
548
|
creatorDID: state.creatorDID,
|
|
471
549
|
contentId: state.contentId,
|
|
472
550
|
createdAt: op.createdAt,
|
|
473
|
-
resolveIdentity: input.resolveIdentity
|
|
551
|
+
resolveIdentity: input.resolveIdentity,
|
|
552
|
+
...input.isRevoked ? { isRevoked: input.isRevoked } : {}
|
|
474
553
|
});
|
|
475
554
|
} catch (err) {
|
|
476
555
|
const message = err instanceof Error ? err.message : "unknown error";
|
|
@@ -570,7 +649,8 @@ var verifyContentExtensionFromTrustedState = async (input) => {
|
|
|
570
649
|
creatorDID: currentState.creatorDID,
|
|
571
650
|
contentId: currentState.contentId,
|
|
572
651
|
createdAt: op.createdAt,
|
|
573
|
-
resolveIdentity: input.resolveIdentity
|
|
652
|
+
resolveIdentity: input.resolveIdentity,
|
|
653
|
+
...input.isRevoked ? { isRevoked: input.isRevoked } : {}
|
|
574
654
|
});
|
|
575
655
|
} catch (err) {
|
|
576
656
|
const message = err instanceof Error ? err.message : "unknown error";
|
|
@@ -593,61 +673,6 @@ var verifyContentExtensionFromTrustedState = async (input) => {
|
|
|
593
673
|
return { state: newState, operationCID, createdAt: op.createdAt };
|
|
594
674
|
};
|
|
595
675
|
|
|
596
|
-
// src/chain/beacon.ts
|
|
597
|
-
var signBeacon = async (input) => {
|
|
598
|
-
const encoded = await dagCborCanonicalEncode(input.payload);
|
|
599
|
-
const beaconCID = encoded.cid.toString();
|
|
600
|
-
const jwsToken = await createJws({
|
|
601
|
-
header: { alg: "EdDSA", typ: "did:dfos:beacon", kid: input.kid, cid: beaconCID },
|
|
602
|
-
payload: input.payload,
|
|
603
|
-
sign: input.signer
|
|
604
|
-
});
|
|
605
|
-
return { jwsToken, beaconCID };
|
|
606
|
-
};
|
|
607
|
-
var MAX_FUTURE_MS = 5 * 60 * 1e3;
|
|
608
|
-
var verifyBeacon = async (input) => {
|
|
609
|
-
const decoded = decodeJwsUnsafe(input.jwsToken);
|
|
610
|
-
if (!decoded) throw new Error("failed to decode beacon JWS");
|
|
611
|
-
const result = BeaconPayload.safeParse(decoded.payload);
|
|
612
|
-
if (!result.success) {
|
|
613
|
-
const messages = result.error.issues.map((e) => e.message).join(", ");
|
|
614
|
-
throw new Error(`invalid beacon payload: ${messages}`);
|
|
615
|
-
}
|
|
616
|
-
const payload = result.data;
|
|
617
|
-
if (decoded.header.typ !== "did:dfos:beacon") {
|
|
618
|
-
throw new Error(`invalid beacon typ: ${decoded.header.typ}`);
|
|
619
|
-
}
|
|
620
|
-
const kid = decoded.header.kid;
|
|
621
|
-
const hashIdx = kid.indexOf("#");
|
|
622
|
-
if (hashIdx < 0) throw new Error("beacon kid must be a DID URL");
|
|
623
|
-
const kidDid = kid.substring(0, hashIdx);
|
|
624
|
-
if (kidDid !== payload.did) {
|
|
625
|
-
throw new Error("beacon kid DID does not match payload did");
|
|
626
|
-
}
|
|
627
|
-
const publicKey = await input.resolveKey(kid);
|
|
628
|
-
try {
|
|
629
|
-
verifyJws({ token: input.jwsToken, publicKey });
|
|
630
|
-
} catch {
|
|
631
|
-
throw new Error("invalid beacon signature");
|
|
632
|
-
}
|
|
633
|
-
const encoded = await dagCborCanonicalEncode(payload);
|
|
634
|
-
const beaconCID = encoded.cid.toString();
|
|
635
|
-
if (!decoded.header.cid) throw new Error("missing cid in beacon header");
|
|
636
|
-
if (decoded.header.cid !== beaconCID) throw new Error("beacon cid mismatch");
|
|
637
|
-
const now = input.now ?? Date.now();
|
|
638
|
-
const beaconTime = new Date(payload.createdAt).getTime();
|
|
639
|
-
if (beaconTime > now + MAX_FUTURE_MS) {
|
|
640
|
-
throw new Error("beacon createdAt is too far in the future");
|
|
641
|
-
}
|
|
642
|
-
return {
|
|
643
|
-
did: payload.did,
|
|
644
|
-
manifestContentId: payload.manifestContentId,
|
|
645
|
-
createdAt: payload.createdAt,
|
|
646
|
-
signerKeyId: kid,
|
|
647
|
-
beaconCID
|
|
648
|
-
};
|
|
649
|
-
};
|
|
650
|
-
|
|
651
676
|
// src/chain/countersign.ts
|
|
652
677
|
var signCountersignature = async (input) => {
|
|
653
678
|
const encoded = await dagCborCanonicalEncode(input.payload);
|
|
@@ -691,7 +716,8 @@ var verifyCountersignature = async (input) => {
|
|
|
691
716
|
return {
|
|
692
717
|
countersignCID,
|
|
693
718
|
witnessDID: payload.did,
|
|
694
|
-
targetCID: payload.targetCID
|
|
719
|
+
targetCID: payload.targetCID,
|
|
720
|
+
...payload.relation !== void 0 ? { relation: payload.relation } : {}
|
|
695
721
|
};
|
|
696
722
|
};
|
|
697
723
|
|
|
@@ -807,25 +833,34 @@ var verifyRevocation = async (input) => {
|
|
|
807
833
|
};
|
|
808
834
|
|
|
809
835
|
export {
|
|
836
|
+
MAX_SERVICES_ENTRIES,
|
|
837
|
+
MAX_SERVICES_PAYLOAD_SIZE,
|
|
810
838
|
MultikeyPublicKey,
|
|
839
|
+
CONTENT_ID_ANCHOR_RE,
|
|
840
|
+
ARTIFACT_CID_ANCHOR_RE,
|
|
841
|
+
ServiceEntry,
|
|
842
|
+
ServicesArray,
|
|
811
843
|
IdentityOperation,
|
|
812
844
|
VerifiedIdentity,
|
|
813
845
|
ContentOperation,
|
|
814
|
-
BeaconPayload,
|
|
815
846
|
MAX_ARTIFACT_PAYLOAD_SIZE,
|
|
816
847
|
ArtifactPayload,
|
|
817
848
|
CountersignPayload,
|
|
818
849
|
RevocationPayload,
|
|
819
850
|
deriveChainIdentifier,
|
|
820
851
|
deriveContentId,
|
|
852
|
+
assertServicesWithinCap,
|
|
853
|
+
classifyAnchor,
|
|
854
|
+
RECOGNIZED_SERVICE_TYPES,
|
|
855
|
+
isRecognizedServiceType,
|
|
856
|
+
relayEndpoints,
|
|
857
|
+
anchorsByLabel,
|
|
821
858
|
signIdentityOperation,
|
|
822
859
|
verifyIdentityChain,
|
|
823
860
|
verifyIdentityExtensionFromTrustedState,
|
|
824
861
|
signContentOperation,
|
|
825
862
|
verifyContentChain,
|
|
826
863
|
verifyContentExtensionFromTrustedState,
|
|
827
|
-
signBeacon,
|
|
828
|
-
verifyBeacon,
|
|
829
864
|
signCountersignature,
|
|
830
865
|
verifyCountersignature,
|
|
831
866
|
signArtifact,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { V as VerifiedIdentity } from '../schemas-
|
|
2
|
+
import { V as VerifiedIdentity } from '../schemas-Myod8ES9.js';
|
|
3
3
|
|
|
4
4
|
/** Single attenuation entry — resource + action pair */
|
|
5
5
|
declare const Attenuation: z.ZodObject<{
|
|
@@ -11,34 +11,23 @@ type Attenuation = z.infer<typeof Attenuation>;
|
|
|
11
11
|
declare const DFOSCredentialPayload: z.ZodObject<{
|
|
12
12
|
version: z.ZodLiteral<1>;
|
|
13
13
|
type: z.ZodLiteral<"DFOSCredential">;
|
|
14
|
-
/** Issuer DID */
|
|
15
14
|
iss: z.ZodString;
|
|
16
|
-
/** Audience DID or "*" for public credentials */
|
|
17
15
|
aud: z.ZodString;
|
|
18
|
-
/** Attenuations — resource + action pairs */
|
|
19
16
|
att: z.ZodArray<z.ZodObject<{
|
|
20
17
|
resource: z.ZodString;
|
|
21
18
|
action: z.ZodString;
|
|
22
19
|
}, z.core.$strict>>;
|
|
23
|
-
/** Parent credential JWS tokens (for delegation chains) */
|
|
24
20
|
prf: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
25
|
-
/** Expiration — unix seconds */
|
|
26
21
|
exp: z.ZodNumber;
|
|
27
|
-
/** Issued at — unix seconds */
|
|
28
22
|
iat: z.ZodNumber;
|
|
29
23
|
}, z.core.$strict>;
|
|
30
24
|
type DFOSCredentialPayload = z.infer<typeof DFOSCredentialPayload>;
|
|
31
25
|
/** Claims for a DID-signed auth token (relay AuthN) */
|
|
32
26
|
declare const AuthTokenClaims: z.ZodObject<{
|
|
33
|
-
/** Issuer — the DID proving identity */
|
|
34
27
|
iss: z.ZodString;
|
|
35
|
-
/** Subject — same as iss for auth tokens */
|
|
36
28
|
sub: z.ZodString;
|
|
37
|
-
/** Audience — target relay hostname (prevents cross-relay replay) */
|
|
38
29
|
aud: z.ZodString;
|
|
39
|
-
/** Expiration — unix seconds, short-lived (minutes) */
|
|
40
30
|
exp: z.ZodNumber;
|
|
41
|
-
/** Issued at — unix seconds */
|
|
42
31
|
iat: z.ZodNumber;
|
|
43
32
|
}, z.core.$strict>;
|
|
44
33
|
type AuthTokenClaims = z.infer<typeof AuthTokenClaims>;
|
|
@@ -74,6 +63,8 @@ interface VerifiedAuthToken {
|
|
|
74
63
|
aud: string;
|
|
75
64
|
/** Token expiration (unix seconds) */
|
|
76
65
|
exp: number;
|
|
66
|
+
/** Token issued-at (unix seconds) */
|
|
67
|
+
iat: number;
|
|
77
68
|
/** kid from the JWT header */
|
|
78
69
|
kid: string;
|
|
79
70
|
}
|
|
@@ -12,8 +12,8 @@ import {
|
|
|
12
12
|
verifyAuthToken,
|
|
13
13
|
verifyDFOSCredential,
|
|
14
14
|
verifyDelegationChain
|
|
15
|
-
} from "../chunk-
|
|
16
|
-
import "../chunk-
|
|
15
|
+
} from "../chunk-LQFOBE6X.js";
|
|
16
|
+
import "../chunk-GQOZJKKO.js";
|
|
17
17
|
export {
|
|
18
18
|
Attenuation,
|
|
19
19
|
AuthTokenClaims,
|
package/dist/crypto/index.d.ts
CHANGED
|
@@ -14,22 +14,22 @@ declare const base64urlDecode: (str: string) => Uint8Array;
|
|
|
14
14
|
* Generate a new random Ed25519 keypair
|
|
15
15
|
*/
|
|
16
16
|
declare const createNewEd25519Keypair: () => {
|
|
17
|
-
privateKey: Uint8Array<ArrayBufferLike>;
|
|
18
|
-
publicKey: Uint8Array<ArrayBufferLike>;
|
|
17
|
+
privateKey: Uint8Array<ArrayBufferLike> & Uint8Array<ArrayBuffer>;
|
|
18
|
+
publicKey: Uint8Array<ArrayBufferLike> & Uint8Array<ArrayBuffer>;
|
|
19
19
|
};
|
|
20
20
|
/**
|
|
21
21
|
* Generate an Ed25519 keypair from a private key
|
|
22
22
|
*/
|
|
23
23
|
declare const importEd25519Keypair: (privateKey: Uint8Array) => {
|
|
24
24
|
privateKey: Uint8Array<ArrayBufferLike>;
|
|
25
|
-
publicKey: Uint8Array<ArrayBufferLike>;
|
|
25
|
+
publicKey: Uint8Array<ArrayBufferLike> & Uint8Array<ArrayBuffer>;
|
|
26
26
|
};
|
|
27
27
|
/**
|
|
28
28
|
* Sign a payload with an Ed25519 private key
|
|
29
29
|
*
|
|
30
30
|
* Ed25519 handles hashing internally (SHA-512) — no external prehash needed
|
|
31
31
|
*/
|
|
32
|
-
declare const signPayloadEd25519: (payload: Uint8Array, privateKey: Uint8Array) => Uint8Array<ArrayBufferLike>;
|
|
32
|
+
declare const signPayloadEd25519: (payload: Uint8Array, privateKey: Uint8Array) => Uint8Array<ArrayBufferLike> & Uint8Array<ArrayBuffer>;
|
|
33
33
|
/**
|
|
34
34
|
* Check that a signature is valid for a given payload and Ed25519 public key
|
|
35
35
|
*/
|
|
@@ -51,7 +51,7 @@ declare const generateIdNoPrefix: (options?: {
|
|
|
51
51
|
/**
|
|
52
52
|
* Generate a prefixed ID
|
|
53
53
|
*
|
|
54
|
-
* Without options: generates random
|
|
54
|
+
* Without options: generates random 31-char ID
|
|
55
55
|
* With { seed }: generates deterministic ID from seed (for external ID mapping)
|
|
56
56
|
*
|
|
57
57
|
* @example
|
|
@@ -66,7 +66,7 @@ declare const generateId: <T extends string>(prefix: T, options?: {
|
|
|
66
66
|
*
|
|
67
67
|
* @param prefix - Expected prefix (e.g., 'msg', 'post')
|
|
68
68
|
* @param id - ID to validate
|
|
69
|
-
* @returns true if ID has correct prefix and length (prefix + _ +
|
|
69
|
+
* @returns true if ID has correct prefix and length (prefix + _ + 31 chars)
|
|
70
70
|
*
|
|
71
71
|
* @example
|
|
72
72
|
* isValidId('msg', 'msg_abc123...') // true
|
|
@@ -125,6 +125,15 @@ declare class JwsVerificationError extends Error {
|
|
|
125
125
|
constructor(message: string);
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
+
/**
|
|
129
|
+
* Apply the DFOS signature verification profile to a decoded protected header.
|
|
130
|
+
*
|
|
131
|
+
* Throws the provided error type with a precise message on any violation. The
|
|
132
|
+
* caller invokes this BEFORE verifying the signature so that an out-of-profile
|
|
133
|
+
* token is rejected regardless of whether its signature would have verified.
|
|
134
|
+
*/
|
|
135
|
+
declare const assertJwsProfile: (header: Record<string, unknown>, makeError: (message: string) => Error) => void;
|
|
136
|
+
|
|
128
137
|
interface JwtHeader {
|
|
129
138
|
alg: 'EdDSA';
|
|
130
139
|
typ: 'JWT';
|
|
@@ -202,4 +211,4 @@ declare const parseDagCborCID: (cid: string) => CID<unknown, number, number, mul
|
|
|
202
211
|
*/
|
|
203
212
|
declare const isCanonicallyEqual: (data1: unknown, data2: unknown) => Promise<boolean>;
|
|
204
213
|
|
|
205
|
-
export { type JwsHeader, JwsVerificationError, type JwtClaims, type JwtCreateOptions, type JwtHeader, JwtVerificationError, type JwtVerifyOptions, type PrefixedID, base64urlDecode, base64urlEncode, createJws, createJwt, createNewEd25519Keypair, dagCborCanonicalEncode, decodeJwsUnsafe, decodeJwtUnsafe, generateId, generateIdNoPrefix, importEd25519Keypair, isCanonicallyEqual, isValidEd25519Signature, isValidId, normalizedId, parseDagCborCID, signPayloadEd25519, verifyJws, verifyJwt };
|
|
214
|
+
export { type JwsHeader, JwsVerificationError, type JwtClaims, type JwtCreateOptions, type JwtHeader, JwtVerificationError, type JwtVerifyOptions, type PrefixedID, assertJwsProfile, base64urlDecode, base64urlEncode, createJws, createJwt, createNewEd25519Keypair, dagCborCanonicalEncode, decodeJwsUnsafe, decodeJwtUnsafe, generateId, generateIdNoPrefix, importEd25519Keypair, isCanonicallyEqual, isValidEd25519Signature, isValidId, normalizedId, parseDagCborCID, signPayloadEd25519, verifyJws, verifyJwt };
|
package/dist/crypto/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
JwsVerificationError,
|
|
3
3
|
JwtVerificationError,
|
|
4
|
+
assertJwsProfile,
|
|
4
5
|
base64urlDecode,
|
|
5
6
|
base64urlEncode,
|
|
6
7
|
createJws,
|
|
@@ -20,10 +21,11 @@ import {
|
|
|
20
21
|
signPayloadEd25519,
|
|
21
22
|
verifyJws,
|
|
22
23
|
verifyJwt
|
|
23
|
-
} from "../chunk-
|
|
24
|
+
} from "../chunk-GQOZJKKO.js";
|
|
24
25
|
export {
|
|
25
26
|
JwsVerificationError,
|
|
26
27
|
JwtVerificationError,
|
|
28
|
+
assertJwsProfile,
|
|
27
29
|
base64urlDecode,
|
|
28
30
|
base64urlEncode,
|
|
29
31
|
createJws,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
export { JwsHeader, JwsVerificationError, JwtClaims, JwtCreateOptions, JwtHeader, JwtVerificationError, JwtVerifyOptions, PrefixedID, base64urlDecode, base64urlEncode, createJws, createJwt, createNewEd25519Keypair, dagCborCanonicalEncode, decodeJwsUnsafe, decodeJwtUnsafe, generateId, generateIdNoPrefix, importEd25519Keypair, isCanonicallyEqual, isValidEd25519Signature, isValidId, normalizedId, parseDagCborCID, signPayloadEd25519, verifyJws, verifyJwt } from './crypto/index.js';
|
|
2
|
-
export { A as
|
|
3
|
-
export { ED25519_PRIV_MULTICODEC, ED25519_PUB_MULTICODEC,
|
|
4
|
-
export { MerkleProof, buildMerkleTree, generateMerkleProof, hashLeaf, hexToBytes, verifyMerkleProof } from './merkle/index.js';
|
|
1
|
+
export { JwsHeader, JwsVerificationError, JwtClaims, JwtCreateOptions, JwtHeader, JwtVerificationError, JwtVerifyOptions, PrefixedID, assertJwsProfile, base64urlDecode, base64urlEncode, createJws, createJwt, createNewEd25519Keypair, dagCborCanonicalEncode, decodeJwsUnsafe, decodeJwtUnsafe, generateId, generateIdNoPrefix, importEd25519Keypair, isCanonicallyEqual, isValidEd25519Signature, isValidId, normalizedId, parseDagCborCID, signPayloadEd25519, verifyJws, verifyJwt } from './crypto/index.js';
|
|
2
|
+
export { A as ARTIFACT_CID_ANCHOR_RE, a as ArtifactPayload, C as CONTENT_ID_ANCHOR_RE, b as ContentOperation, c as CountersignPayload, I as IdentityOperation, M as MAX_ARTIFACT_PAYLOAD_SIZE, d as MAX_SERVICES_ENTRIES, e as MAX_SERVICES_PAYLOAD_SIZE, f as MultikeyPublicKey, R as RevocationPayload, S as ServiceEntry, g as ServicesArray, h as Signer, V as VerifiedIdentity } from './schemas-Myod8ES9.js';
|
|
3
|
+
export { AnchorKind, ED25519_PRIV_MULTICODEC, ED25519_PUB_MULTICODEC, RECOGNIZED_SERVICE_TYPES, VerifiedArtifact, VerifiedContentChain, VerifiedCountersignature, VerifiedRevocation, anchorsByLabel, assertServicesWithinCap, classifyAnchor, decodeMultikey, deriveChainIdentifier, deriveContentId, encodeEd25519Multikey, isRecognizedServiceType, relayEndpoints, signArtifact, signContentOperation, signCountersignature, signIdentityOperation, signRevocation, verifyArtifact, verifyContentChain, verifyContentExtensionFromTrustedState, verifyCountersignature, verifyIdentityChain, verifyIdentityExtensionFromTrustedState, verifyRevocation } from './chain/index.js';
|
|
5
4
|
export { Attenuation, AuthTokenClaims, AuthTokenCreateOptions, AuthTokenVerificationError, AuthTokenVerifyOptions, CredentialVerificationError, DFOSCredentialPayload, VerifiedAuthToken, VerifiedDFOSCredential, VerifiedDelegationChain, createAuthToken, createDFOSCredential, decodeDFOSCredentialUnsafe, isAttenuated, matchesResource, verifyAuthToken, verifyDFOSCredential, verifyDelegationChain } from './credentials/index.js';
|
|
6
5
|
import 'multiformats';
|
|
7
6
|
import 'multiformats/cid';
|
package/dist/index.js
CHANGED
|
@@ -1,37 +1,39 @@
|
|
|
1
1
|
import {
|
|
2
|
+
ARTIFACT_CID_ANCHOR_RE,
|
|
2
3
|
ArtifactPayload,
|
|
3
|
-
|
|
4
|
+
CONTENT_ID_ANCHOR_RE,
|
|
4
5
|
ContentOperation,
|
|
5
6
|
CountersignPayload,
|
|
6
7
|
IdentityOperation,
|
|
7
8
|
MAX_ARTIFACT_PAYLOAD_SIZE,
|
|
9
|
+
MAX_SERVICES_ENTRIES,
|
|
10
|
+
MAX_SERVICES_PAYLOAD_SIZE,
|
|
8
11
|
MultikeyPublicKey,
|
|
12
|
+
RECOGNIZED_SERVICE_TYPES,
|
|
9
13
|
RevocationPayload,
|
|
14
|
+
ServiceEntry,
|
|
15
|
+
ServicesArray,
|
|
10
16
|
VerifiedIdentity,
|
|
17
|
+
anchorsByLabel,
|
|
18
|
+
assertServicesWithinCap,
|
|
19
|
+
classifyAnchor,
|
|
11
20
|
deriveChainIdentifier,
|
|
12
21
|
deriveContentId,
|
|
22
|
+
isRecognizedServiceType,
|
|
23
|
+
relayEndpoints,
|
|
13
24
|
signArtifact,
|
|
14
|
-
signBeacon,
|
|
15
25
|
signContentOperation,
|
|
16
26
|
signCountersignature,
|
|
17
27
|
signIdentityOperation,
|
|
18
28
|
signRevocation,
|
|
19
29
|
verifyArtifact,
|
|
20
|
-
verifyBeacon,
|
|
21
30
|
verifyContentChain,
|
|
22
31
|
verifyContentExtensionFromTrustedState,
|
|
23
32
|
verifyCountersignature,
|
|
24
33
|
verifyIdentityChain,
|
|
25
34
|
verifyIdentityExtensionFromTrustedState,
|
|
26
35
|
verifyRevocation
|
|
27
|
-
} from "./chunk-
|
|
28
|
-
import {
|
|
29
|
-
buildMerkleTree,
|
|
30
|
-
generateMerkleProof,
|
|
31
|
-
hashLeaf,
|
|
32
|
-
hexToBytes,
|
|
33
|
-
verifyMerkleProof
|
|
34
|
-
} from "./chunk-E5CFQG2B.js";
|
|
36
|
+
} from "./chunk-SDUOUFTF.js";
|
|
35
37
|
import {
|
|
36
38
|
Attenuation,
|
|
37
39
|
AuthTokenClaims,
|
|
@@ -50,10 +52,11 @@ import {
|
|
|
50
52
|
verifyAuthToken,
|
|
51
53
|
verifyDFOSCredential,
|
|
52
54
|
verifyDelegationChain
|
|
53
|
-
} from "./chunk-
|
|
55
|
+
} from "./chunk-LQFOBE6X.js";
|
|
54
56
|
import {
|
|
55
57
|
JwsVerificationError,
|
|
56
58
|
JwtVerificationError,
|
|
59
|
+
assertJwsProfile,
|
|
57
60
|
base64urlDecode,
|
|
58
61
|
base64urlEncode,
|
|
59
62
|
createJws,
|
|
@@ -73,13 +76,14 @@ import {
|
|
|
73
76
|
signPayloadEd25519,
|
|
74
77
|
verifyJws,
|
|
75
78
|
verifyJwt
|
|
76
|
-
} from "./chunk-
|
|
79
|
+
} from "./chunk-GQOZJKKO.js";
|
|
77
80
|
export {
|
|
81
|
+
ARTIFACT_CID_ANCHOR_RE,
|
|
78
82
|
ArtifactPayload,
|
|
79
83
|
Attenuation,
|
|
80
84
|
AuthTokenClaims,
|
|
81
85
|
AuthTokenVerificationError,
|
|
82
|
-
|
|
86
|
+
CONTENT_ID_ANCHOR_RE,
|
|
83
87
|
ContentOperation,
|
|
84
88
|
CountersignPayload,
|
|
85
89
|
CredentialVerificationError,
|
|
@@ -90,12 +94,20 @@ export {
|
|
|
90
94
|
JwsVerificationError,
|
|
91
95
|
JwtVerificationError,
|
|
92
96
|
MAX_ARTIFACT_PAYLOAD_SIZE,
|
|
97
|
+
MAX_SERVICES_ENTRIES,
|
|
98
|
+
MAX_SERVICES_PAYLOAD_SIZE,
|
|
93
99
|
MultikeyPublicKey,
|
|
100
|
+
RECOGNIZED_SERVICE_TYPES,
|
|
94
101
|
RevocationPayload,
|
|
102
|
+
ServiceEntry,
|
|
103
|
+
ServicesArray,
|
|
95
104
|
VerifiedIdentity,
|
|
105
|
+
anchorsByLabel,
|
|
106
|
+
assertJwsProfile,
|
|
107
|
+
assertServicesWithinCap,
|
|
96
108
|
base64urlDecode,
|
|
97
109
|
base64urlEncode,
|
|
98
|
-
|
|
110
|
+
classifyAnchor,
|
|
99
111
|
createAuthToken,
|
|
100
112
|
createDFOSCredential,
|
|
101
113
|
createJws,
|
|
@@ -111,19 +123,17 @@ export {
|
|
|
111
123
|
encodeEd25519Multikey,
|
|
112
124
|
generateId,
|
|
113
125
|
generateIdNoPrefix,
|
|
114
|
-
generateMerkleProof,
|
|
115
|
-
hashLeaf,
|
|
116
|
-
hexToBytes,
|
|
117
126
|
importEd25519Keypair,
|
|
118
127
|
isAttenuated,
|
|
119
128
|
isCanonicallyEqual,
|
|
129
|
+
isRecognizedServiceType,
|
|
120
130
|
isValidEd25519Signature,
|
|
121
131
|
isValidId,
|
|
122
132
|
matchesResource,
|
|
123
133
|
normalizedId,
|
|
124
134
|
parseDagCborCID,
|
|
135
|
+
relayEndpoints,
|
|
125
136
|
signArtifact,
|
|
126
|
-
signBeacon,
|
|
127
137
|
signContentOperation,
|
|
128
138
|
signCountersignature,
|
|
129
139
|
signIdentityOperation,
|
|
@@ -131,7 +141,6 @@ export {
|
|
|
131
141
|
signRevocation,
|
|
132
142
|
verifyArtifact,
|
|
133
143
|
verifyAuthToken,
|
|
134
|
-
verifyBeacon,
|
|
135
144
|
verifyContentChain,
|
|
136
145
|
verifyContentExtensionFromTrustedState,
|
|
137
146
|
verifyCountersignature,
|
|
@@ -141,6 +150,5 @@ export {
|
|
|
141
150
|
verifyIdentityExtensionFromTrustedState,
|
|
142
151
|
verifyJws,
|
|
143
152
|
verifyJwt,
|
|
144
|
-
verifyMerkleProof,
|
|
145
153
|
verifyRevocation
|
|
146
154
|
};
|