@metalabel/dfos-protocol 0.11.0 → 0.12.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.
@@ -1,5 +1,5 @@
1
- import { I as IdentityOperation, h as Signer, V as VerifiedIdentity, S as ServiceEntry, b as ContentOperation, c as CountersignPayload, a as ArtifactPayload } from '../schemas-Myod8ES9.js';
2
- export { A as ARTIFACT_CID_ANCHOR_RE, C as CONTENT_ID_ANCHOR_RE, M as MAX_ARTIFACT_PAYLOAD_SIZE, d as MAX_SERVICES_ENTRIES, e as MAX_SERVICES_PAYLOAD_SIZE, f as MultikeyPublicKey, R as RevocationPayload, g as ServicesArray } from '../schemas-Myod8ES9.js';
1
+ import { I as IdentityOperation, i as Signer, V as VerifiedIdentity, S as ServiceEntry, b as ContentOperation, c as CountersignPayload, a as ArtifactPayload } from '../schemas-Bb_9P8_s.js';
2
+ export { A as ARTIFACT_CID_ANCHOR_RE, C as CONTENT_ID_ANCHOR_RE, M as MAX_ARTIFACT_PAYLOAD_SIZE, d as MAX_OPERATION_SIZE, e as MAX_SERVICES_ENTRIES, f as MAX_SERVICES_PAYLOAD_SIZE, g as MultikeyPublicKey, R as RevocationPayload, h as ServicesArray } from '../schemas-Bb_9P8_s.js';
3
3
  import 'zod';
4
4
 
5
5
  /** Ed25519 public key multicodec value */
@@ -6,6 +6,7 @@ import {
6
6
  CountersignPayload,
7
7
  IdentityOperation,
8
8
  MAX_ARTIFACT_PAYLOAD_SIZE,
9
+ MAX_OPERATION_SIZE,
9
10
  MAX_SERVICES_ENTRIES,
10
11
  MAX_SERVICES_PAYLOAD_SIZE,
11
12
  MultikeyPublicKey,
@@ -33,14 +34,14 @@ import {
33
34
  verifyIdentityChain,
34
35
  verifyIdentityExtensionFromTrustedState,
35
36
  verifyRevocation
36
- } from "../chunk-SDUOUFTF.js";
37
+ } from "../chunk-J5C4OXL4.js";
37
38
  import {
38
39
  ED25519_PRIV_MULTICODEC,
39
40
  ED25519_PUB_MULTICODEC,
40
41
  decodeMultikey,
41
42
  encodeEd25519Multikey
42
- } from "../chunk-LQFOBE6X.js";
43
- import "../chunk-GQOZJKKO.js";
43
+ } from "../chunk-J3XXF6F5.js";
44
+ import "../chunk-4QQ5HK5M.js";
44
45
  export {
45
46
  ARTIFACT_CID_ANCHOR_RE,
46
47
  ArtifactPayload,
@@ -51,6 +52,7 @@ export {
51
52
  ED25519_PUB_MULTICODEC,
52
53
  IdentityOperation,
53
54
  MAX_ARTIFACT_PAYLOAD_SIZE,
55
+ MAX_OPERATION_SIZE,
54
56
  MAX_SERVICES_ENTRIES,
55
57
  MAX_SERVICES_PAYLOAD_SIZE,
56
58
  MultikeyPublicKey,
@@ -239,7 +239,11 @@ var dagCborCanonicalEncode = async (value) => {
239
239
  });
240
240
  };
241
241
  var MAX_SAFE_CANONICAL_INTEGER = 9007199254740991;
242
- var assertCanonicalNumbers = (value) => {
242
+ var MAX_CANONICAL_DEPTH = 1024;
243
+ var assertCanonicalNumbers = (value, depth = 0) => {
244
+ if (depth > MAX_CANONICAL_DEPTH) {
245
+ throw new Error(`value nesting exceeds max depth ${MAX_CANONICAL_DEPTH}`);
246
+ }
243
247
  if (typeof value === "number") {
244
248
  if (!Number.isFinite(value)) {
245
249
  throw new Error(`non-finite number is not canonicalizable: ${value}`);
@@ -257,11 +261,11 @@ var assertCanonicalNumbers = (value) => {
257
261
  return;
258
262
  }
259
263
  if (Array.isArray(value)) {
260
- for (const entry of value) assertCanonicalNumbers(entry);
264
+ for (const entry of value) assertCanonicalNumbers(entry, depth + 1);
261
265
  return;
262
266
  }
263
267
  if (value !== null && typeof value === "object") {
264
- for (const entry of Object.values(value)) assertCanonicalNumbers(entry);
268
+ for (const entry of Object.values(value)) assertCanonicalNumbers(entry, depth + 1);
265
269
  }
266
270
  };
267
271
  var parseDagCborCID = (cid) => {
@@ -5,27 +5,24 @@ import {
5
5
  decodeJwsUnsafe,
6
6
  verifyJws,
7
7
  verifyJwt
8
- } from "./chunk-GQOZJKKO.js";
8
+ } from "./chunk-4QQ5HK5M.js";
9
9
 
10
10
  // src/credentials/schemas.ts
11
11
  import { z } from "zod";
12
- var MAX_DID = 256;
13
- var MAX_AUD = 512;
14
- var MAX_RESOURCE = 512;
15
- var MAX_ACTION = 64;
16
12
  var MAX_ATT = 32;
17
13
  var MAX_PRF = 1;
18
- var Attenuation = z.strictObject({
19
- resource: z.string().min(1).max(MAX_RESOURCE),
20
- action: z.string().min(1).max(MAX_ACTION)
14
+ var MAX_CREDENTIAL_SIZE = 262144;
15
+ var Attenuation = z.looseObject({
16
+ resource: z.string().min(1),
17
+ action: z.string().min(1)
21
18
  });
22
- var DFOSCredentialPayload = z.strictObject({
19
+ var DFOSCredentialPayload = z.looseObject({
23
20
  version: z.literal(1),
24
21
  type: z.literal("DFOSCredential"),
25
22
  /** Issuer DID */
26
- iss: z.string().min(1).max(MAX_DID),
23
+ iss: z.string().min(1),
27
24
  /** Audience DID or "*" for public credentials */
28
- aud: z.string().min(1).max(MAX_AUD),
25
+ aud: z.string().min(1),
29
26
  /** Attenuations — resource + action pairs */
30
27
  att: z.array(Attenuation).min(1).max(MAX_ATT),
31
28
  /** Parent credential JWS tokens (for delegation chains) */
@@ -35,13 +32,13 @@ var DFOSCredentialPayload = z.strictObject({
35
32
  /** Issued at — unix seconds */
36
33
  iat: z.number().int().positive()
37
34
  });
38
- var AuthTokenClaims = z.strictObject({
35
+ var AuthTokenClaims = z.looseObject({
39
36
  /** Issuer — the DID proving identity */
40
- iss: z.string().max(MAX_DID),
37
+ iss: z.string(),
41
38
  /** Subject — same as iss for auth tokens */
42
- sub: z.string().max(MAX_DID),
39
+ sub: z.string(),
43
40
  /** Audience — target relay hostname (prevents cross-relay replay) */
44
- aud: z.string().max(MAX_AUD),
41
+ aud: z.string(),
45
42
  /** Expiration — unix seconds, short-lived (minutes) */
46
43
  exp: z.number().int().positive(),
47
44
  /** Issued at — unix seconds */
@@ -187,6 +184,11 @@ var createDFOSCredential = async (options) => {
187
184
  return jwsToken;
188
185
  };
189
186
  var verifyDFOSCredential = async (jwsToken, options) => {
187
+ if (jwsToken.length > MAX_CREDENTIAL_SIZE) {
188
+ throw new CredentialVerificationError(
189
+ `credential exceeds max size: ${jwsToken.length} > ${MAX_CREDENTIAL_SIZE}`
190
+ );
191
+ }
190
192
  const decoded = decodeJwsUnsafe(jwsToken);
191
193
  if (!decoded) throw new CredentialVerificationError("failed to decode credential JWS");
192
194
  if (decoded.header.typ !== "did:dfos:credential") {
@@ -372,6 +374,7 @@ export {
372
374
  ED25519_PRIV_MULTICODEC,
373
375
  encodeEd25519Multikey,
374
376
  decodeMultikey,
377
+ MAX_CREDENTIAL_SIZE,
375
378
  Attenuation,
376
379
  DFOSCredentialPayload,
377
380
  AuthTokenClaims,
@@ -1,52 +1,46 @@
1
1
  import {
2
+ MAX_CREDENTIAL_SIZE,
2
3
  decodeDFOSCredentialUnsafe,
3
4
  decodeMultikey,
4
5
  matchesResource,
5
6
  verifyDFOSCredential,
6
7
  verifyDelegationChain
7
- } from "./chunk-LQFOBE6X.js";
8
+ } from "./chunk-J3XXF6F5.js";
8
9
  import {
9
10
  createJws,
10
11
  dagCborCanonicalEncode,
11
12
  decodeJwsUnsafe,
12
13
  generateIdNoPrefix,
13
14
  verifyJws
14
- } from "./chunk-GQOZJKKO.js";
15
+ } from "./chunk-4QQ5HK5M.js";
15
16
 
16
17
  // src/chain/schemas.ts
17
18
  import { z } from "zod";
18
- var MAX_KEY_ID = 64;
19
- var MAX_PUBLIC_KEY_MULTIBASE = 128;
20
- var MAX_CID = 256;
21
- var MAX_NOTE = 256;
22
- var MAX_KEYS_PER_ROLE = 16;
23
- var MAX_DID = 256;
24
- var MAX_SERVICE_ID = 64;
25
- var MAX_SERVICE_TYPE = 64;
26
- var MAX_SERVICE_STRING = 512;
19
+ var MAX_KEYS_PER_ROLE = 256;
27
20
  var MAX_RELATION = 64;
28
- var MAX_SERVICES_ENTRIES = 16;
29
- var MAX_SERVICES_PAYLOAD_SIZE = 8192;
30
- var MultikeyPublicKey = z.strictObject({
31
- id: z.string().max(MAX_KEY_ID),
21
+ var MAX_SERVICES_ENTRIES = 256;
22
+ var MAX_SERVICES_PAYLOAD_SIZE = 32768;
23
+ var MAX_OPERATION_SIZE = 65536;
24
+ var MultikeyPublicKey = z.looseObject({
25
+ id: z.string(),
32
26
  type: z.literal("Multikey"),
33
- publicKeyMultibase: z.string().max(MAX_PUBLIC_KEY_MULTIBASE)
27
+ publicKeyMultibase: z.string()
34
28
  });
35
29
  var CONTENT_ID_ANCHOR_RE = /^[2346789acdefhknrtvz]{31}$/;
36
30
  var ARTIFACT_CID_ANCHOR_RE = /^baf[a-z2-7]{20,}$/;
37
31
  var ServiceEntry = z.object({
38
- id: z.string().min(1).max(MAX_SERVICE_ID),
39
- type: z.string().min(1).max(MAX_SERVICE_TYPE)
32
+ id: z.string().min(1),
33
+ type: z.string().min(1)
40
34
  }).catchall(z.unknown()).superRefine((entry, ctx) => {
41
35
  if (entry.type === "DfosRelay") {
42
36
  const endpoint = entry["endpoint"];
43
- if (typeof endpoint !== "string" || endpoint.length < 1 || endpoint.length > MAX_SERVICE_STRING) {
37
+ if (typeof endpoint !== "string" || endpoint.length < 1) {
44
38
  ctx.addIssue({ code: "custom", message: "DfosRelay requires a non-empty endpoint string" });
45
39
  }
46
40
  } else if (entry.type === "ContentAnchor") {
47
41
  const label = entry["label"];
48
42
  const anchor = entry["anchor"];
49
- if (typeof label !== "string" || label.length < 1 || label.length > MAX_SERVICE_STRING) {
43
+ if (typeof label !== "string" || label.length < 1) {
50
44
  ctx.addIssue({
51
45
  code: "custom",
52
46
  message: "ContentAnchor requires a non-empty label string"
@@ -65,8 +59,8 @@ var ServicesArray = z.array(ServiceEntry).max(MAX_SERVICES_ENTRIES).refine(
65
59
  "service entry ids must be unique"
66
60
  );
67
61
  var Iso8601 = z.iso.datetime({ offset: false, precision: 3 });
68
- var CIDString = z.string().max(MAX_CID);
69
- var IdentityCreate = z.strictObject({
62
+ var CIDString = z.string();
63
+ var IdentityCreate = z.looseObject({
70
64
  version: z.literal(1),
71
65
  type: z.literal("create"),
72
66
  authKeys: z.array(MultikeyPublicKey).max(MAX_KEYS_PER_ROLE),
@@ -77,7 +71,7 @@ var IdentityCreate = z.strictObject({
77
71
  services: ServicesArray.optional(),
78
72
  createdAt: Iso8601
79
73
  });
80
- var IdentityUpdate = z.strictObject({
74
+ var IdentityUpdate = z.looseObject({
81
75
  version: z.literal(1),
82
76
  type: z.literal("update"),
83
77
  previousOperationCID: CIDString,
@@ -88,7 +82,7 @@ var IdentityUpdate = z.strictObject({
88
82
  services: ServicesArray.optional(),
89
83
  createdAt: Iso8601
90
84
  });
91
- var IdentityDelete = z.strictObject({
85
+ var IdentityDelete = z.looseObject({
92
86
  version: z.literal(1),
93
87
  type: z.literal("delete"),
94
88
  previousOperationCID: CIDString,
@@ -100,7 +94,7 @@ var IdentityOperation = z.discriminatedUnion("type", [
100
94
  IdentityDelete
101
95
  ]);
102
96
  var VerifiedIdentity = z.strictObject({
103
- did: z.string().max(MAX_DID),
97
+ did: z.string(),
104
98
  isDeleted: z.boolean(),
105
99
  authKeys: z.array(MultikeyPublicKey).max(MAX_KEYS_PER_ROLE),
106
100
  assertKeys: z.array(MultikeyPublicKey).max(MAX_KEYS_PER_ROLE),
@@ -108,34 +102,34 @@ var VerifiedIdentity = z.strictObject({
108
102
  /** Resolved discovery vocabulary — projection of the winning head's services */
109
103
  services: ServicesArray
110
104
  });
111
- var ContentCreate = z.strictObject({
105
+ var ContentCreate = z.looseObject({
112
106
  version: z.literal(1),
113
107
  type: z.literal("create"),
114
- did: z.string().max(MAX_DID),
108
+ did: z.string(),
115
109
  documentCID: CIDString,
116
110
  baseDocumentCID: CIDString.nullable(),
117
111
  createdAt: Iso8601,
118
- note: z.string().max(MAX_NOTE).nullable()
112
+ note: z.string().nullable()
119
113
  });
120
- var ContentUpdate = z.strictObject({
114
+ var ContentUpdate = z.looseObject({
121
115
  version: z.literal(1),
122
116
  type: z.literal("update"),
123
- did: z.string().max(MAX_DID),
117
+ did: z.string(),
124
118
  previousOperationCID: CIDString,
125
119
  documentCID: CIDString.nullable(),
126
120
  baseDocumentCID: CIDString.nullable(),
127
121
  createdAt: Iso8601,
128
- note: z.string().max(MAX_NOTE).nullable(),
122
+ note: z.string().nullable(),
129
123
  /** DFOS credential authorizing this operation when signer is not the chain creator */
130
124
  authorization: z.string().optional()
131
125
  });
132
- var ContentDelete = z.strictObject({
126
+ var ContentDelete = z.looseObject({
133
127
  version: z.literal(1),
134
128
  type: z.literal("delete"),
135
- did: z.string().max(MAX_DID),
129
+ did: z.string(),
136
130
  previousOperationCID: CIDString,
137
131
  createdAt: Iso8601,
138
- note: z.string().max(MAX_NOTE).nullable(),
132
+ note: z.string().nullable(),
139
133
  /** DFOS credential authorizing this operation when signer is not the chain creator */
140
134
  authorization: z.string().optional()
141
135
  });
@@ -144,28 +138,27 @@ var ContentOperation = z.discriminatedUnion("type", [
144
138
  ContentUpdate,
145
139
  ContentDelete
146
140
  ]);
147
- var MAX_SCHEMA = 256;
148
141
  var MAX_ARTIFACT_PAYLOAD_SIZE = 16384;
149
- var ArtifactContent = z.object({ $schema: z.string().max(MAX_SCHEMA) }).catchall(z.unknown());
150
- var ArtifactPayload = z.strictObject({
142
+ var ArtifactContent = z.object({ $schema: z.string() }).catchall(z.unknown());
143
+ var ArtifactPayload = z.looseObject({
151
144
  version: z.literal(1),
152
145
  type: z.literal("artifact"),
153
- did: z.string().max(MAX_DID),
146
+ did: z.string(),
154
147
  content: ArtifactContent,
155
148
  createdAt: Iso8601
156
149
  });
157
- var CountersignPayload = z.strictObject({
150
+ var CountersignPayload = z.looseObject({
158
151
  version: z.literal(1),
159
152
  type: z.literal("countersign"),
160
- did: z.string().max(MAX_DID),
153
+ did: z.string(),
161
154
  targetCID: CIDString,
162
155
  relation: z.string().min(1).max(MAX_RELATION).optional(),
163
156
  createdAt: Iso8601
164
157
  });
165
- var RevocationPayload = z.strictObject({
158
+ var RevocationPayload = z.looseObject({
166
159
  version: z.literal(1),
167
160
  type: z.literal("revocation"),
168
- did: z.string().max(MAX_DID),
161
+ did: z.string(),
169
162
  credentialCID: CIDString,
170
163
  createdAt: Iso8601
171
164
  });
@@ -288,6 +281,11 @@ var verifyIdentityChain = async (input) => {
288
281
  }
289
282
  }
290
283
  const encoded = await dagCborCanonicalEncode(op);
284
+ if (encoded.bytes.length > MAX_OPERATION_SIZE) {
285
+ throw new Error(
286
+ `log[${idx}]: operation exceeds max size: ${encoded.bytes.length} > ${MAX_OPERATION_SIZE}`
287
+ );
288
+ }
291
289
  const operationCID = encoded.cid.toString();
292
290
  if (!decoded.header.cid) {
293
291
  throw new Error(`log[${idx}]: missing cid in protected header`);
@@ -383,6 +381,9 @@ var verifyIdentityExtensionFromTrustedState = async (input) => {
383
381
  throw new Error("createdAt must be after last op");
384
382
  }
385
383
  const encoded = await dagCborCanonicalEncode(op);
384
+ if (encoded.bytes.length > MAX_OPERATION_SIZE) {
385
+ throw new Error(`operation exceeds max size: ${encoded.bytes.length} > ${MAX_OPERATION_SIZE}`);
386
+ }
386
387
  const operationCID = encoded.cid.toString();
387
388
  if (!decoded.header.cid) throw new Error("missing cid in protected header");
388
389
  if (decoded.header.cid !== operationCID) throw new Error("cid mismatch in protected header");
@@ -434,6 +435,18 @@ var verifyIdentityExtensionFromTrustedState = async (input) => {
434
435
  };
435
436
 
436
437
  // src/chain/content-chain.ts
438
+ var operationSizeForCap = async (op, fullByteLength) => {
439
+ const auth = op.authorization;
440
+ if (typeof auth !== "string") return fullByteLength;
441
+ if (auth.length > MAX_CREDENTIAL_SIZE) {
442
+ throw new Error(
443
+ `authorization credential exceeds max size: ${auth.length} > ${MAX_CREDENTIAL_SIZE}`
444
+ );
445
+ }
446
+ const { authorization: _omit, ...rest } = op;
447
+ const encoded = await dagCborCanonicalEncode(rest);
448
+ return encoded.bytes.length;
449
+ };
437
450
  var signContentOperation = async (input) => {
438
451
  const encoded = await dagCborCanonicalEncode(input.operation);
439
452
  const operationCID = encoded.cid.toString();
@@ -557,6 +570,10 @@ var verifyContentChain = async (input) => {
557
570
  }
558
571
  }
559
572
  const encoded = await dagCborCanonicalEncode(op);
573
+ const opSize = await operationSizeForCap(op, encoded.bytes.length);
574
+ if (opSize > MAX_OPERATION_SIZE) {
575
+ throw new Error(`operation exceeds max size: ${opSize} > ${MAX_OPERATION_SIZE}`);
576
+ }
560
577
  const operationCID = encoded.cid.toString();
561
578
  if (!decoded.header.cid) {
562
579
  throw new Error(`log[${idx}]: missing cid in protected header`);
@@ -658,6 +675,10 @@ var verifyContentExtensionFromTrustedState = async (input) => {
658
675
  }
659
676
  }
660
677
  const encoded = await dagCborCanonicalEncode(op);
678
+ const opSize = await operationSizeForCap(op, encoded.bytes.length);
679
+ if (opSize > MAX_OPERATION_SIZE) {
680
+ throw new Error(`operation exceeds max size: ${opSize} > ${MAX_OPERATION_SIZE}`);
681
+ }
661
682
  const operationCID = encoded.cid.toString();
662
683
  if (!decoded.header.cid) throw new Error("missing cid in protected header");
663
684
  if (decoded.header.cid !== operationCID) throw new Error("cid mismatch in protected header");
@@ -835,6 +856,7 @@ var verifyRevocation = async (input) => {
835
856
  export {
836
857
  MAX_SERVICES_ENTRIES,
837
858
  MAX_SERVICES_PAYLOAD_SIZE,
859
+ MAX_OPERATION_SIZE,
838
860
  MultikeyPublicKey,
839
861
  CONTENT_ID_ANCHOR_RE,
840
862
  ARTIFACT_CID_ANCHOR_RE,
@@ -1,11 +1,22 @@
1
1
  import { z } from 'zod';
2
- import { V as VerifiedIdentity } from '../schemas-Myod8ES9.js';
2
+ import { V as VerifiedIdentity } from '../schemas-Bb_9P8_s.js';
3
3
 
4
+ /**
5
+ * Max byte length of a credential JWS token — the credential's analog of
6
+ * MAX_OPERATION_SIZE. Credentials are EXEMPT from the 64 KiB operation cap (a
7
+ * maximum-depth 16-hop delegation chain embeds each parent token in `prf` and
8
+ * legitimately exceeds it), so they carry their own larger ceiling. Measured
9
+ * over the serialized leaf token, which contains the entire nested chain, so one
10
+ * bound caps the whole delegation. A DoS guard on the nested `prf` structure;
11
+ * generous (a max-depth chain serializes to well under this). VALIDITY-
12
+ * determining: MUST match the Go reference (maxCredentialSize in jwt.go).
13
+ */
14
+ declare const MAX_CREDENTIAL_SIZE = 262144;
4
15
  /** Single attenuation entry — resource + action pair */
5
16
  declare const Attenuation: z.ZodObject<{
6
17
  resource: z.ZodString;
7
18
  action: z.ZodString;
8
- }, z.core.$strict>;
19
+ }, z.core.$loose>;
9
20
  type Attenuation = z.infer<typeof Attenuation>;
10
21
  /** DFOS credential payload — UCAN-style authorization token */
11
22
  declare const DFOSCredentialPayload: z.ZodObject<{
@@ -16,11 +27,11 @@ declare const DFOSCredentialPayload: z.ZodObject<{
16
27
  att: z.ZodArray<z.ZodObject<{
17
28
  resource: z.ZodString;
18
29
  action: z.ZodString;
19
- }, z.core.$strict>>;
30
+ }, z.core.$loose>>;
20
31
  prf: z.ZodDefault<z.ZodArray<z.ZodString>>;
21
32
  exp: z.ZodNumber;
22
33
  iat: z.ZodNumber;
23
- }, z.core.$strict>;
34
+ }, z.core.$loose>;
24
35
  type DFOSCredentialPayload = z.infer<typeof DFOSCredentialPayload>;
25
36
  /** Claims for a DID-signed auth token (relay AuthN) */
26
37
  declare const AuthTokenClaims: z.ZodObject<{
@@ -29,7 +40,7 @@ declare const AuthTokenClaims: z.ZodObject<{
29
40
  aud: z.ZodString;
30
41
  exp: z.ZodNumber;
31
42
  iat: z.ZodNumber;
32
- }, z.core.$strict>;
43
+ }, z.core.$loose>;
33
44
  type AuthTokenClaims = z.infer<typeof AuthTokenClaims>;
34
45
 
35
46
  interface AuthTokenCreateOptions {
@@ -200,4 +211,4 @@ declare class CredentialVerificationError extends Error {
200
211
  constructor(message: string);
201
212
  }
202
213
 
203
- export { Attenuation, AuthTokenClaims, type AuthTokenCreateOptions, AuthTokenVerificationError, type AuthTokenVerifyOptions, CredentialVerificationError, DFOSCredentialPayload, type VerifiedAuthToken, type VerifiedDFOSCredential, type VerifiedDelegationChain, createAuthToken, createDFOSCredential, decodeDFOSCredentialUnsafe, isAttenuated, matchesResource, verifyAuthToken, verifyDFOSCredential, verifyDelegationChain };
214
+ export { Attenuation, AuthTokenClaims, type AuthTokenCreateOptions, AuthTokenVerificationError, type AuthTokenVerifyOptions, CredentialVerificationError, DFOSCredentialPayload, MAX_CREDENTIAL_SIZE, type VerifiedAuthToken, type VerifiedDFOSCredential, type VerifiedDelegationChain, createAuthToken, createDFOSCredential, decodeDFOSCredentialUnsafe, isAttenuated, matchesResource, verifyAuthToken, verifyDFOSCredential, verifyDelegationChain };
@@ -4,6 +4,7 @@ import {
4
4
  AuthTokenVerificationError,
5
5
  CredentialVerificationError,
6
6
  DFOSCredentialPayload,
7
+ MAX_CREDENTIAL_SIZE,
7
8
  createAuthToken,
8
9
  createDFOSCredential,
9
10
  decodeDFOSCredentialUnsafe,
@@ -12,14 +13,15 @@ import {
12
13
  verifyAuthToken,
13
14
  verifyDFOSCredential,
14
15
  verifyDelegationChain
15
- } from "../chunk-LQFOBE6X.js";
16
- import "../chunk-GQOZJKKO.js";
16
+ } from "../chunk-J3XXF6F5.js";
17
+ import "../chunk-4QQ5HK5M.js";
17
18
  export {
18
19
  Attenuation,
19
20
  AuthTokenClaims,
20
21
  AuthTokenVerificationError,
21
22
  CredentialVerificationError,
22
23
  DFOSCredentialPayload,
24
+ MAX_CREDENTIAL_SIZE,
23
25
  createAuthToken,
24
26
  createDFOSCredential,
25
27
  decodeDFOSCredentialUnsafe,
@@ -21,7 +21,7 @@ import {
21
21
  signPayloadEd25519,
22
22
  verifyJws,
23
23
  verifyJwt
24
- } from "../chunk-GQOZJKKO.js";
24
+ } from "../chunk-4QQ5HK5M.js";
25
25
  export {
26
26
  JwsVerificationError,
27
27
  JwtVerificationError,
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
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';
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_OPERATION_SIZE, e as MAX_SERVICES_ENTRIES, f as MAX_SERVICES_PAYLOAD_SIZE, g as MultikeyPublicKey, R as RevocationPayload, S as ServiceEntry, h as ServicesArray, i as Signer, V as VerifiedIdentity } from './schemas-Bb_9P8_s.js';
3
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';
4
- export { Attenuation, AuthTokenClaims, AuthTokenCreateOptions, AuthTokenVerificationError, AuthTokenVerifyOptions, CredentialVerificationError, DFOSCredentialPayload, VerifiedAuthToken, VerifiedDFOSCredential, VerifiedDelegationChain, createAuthToken, createDFOSCredential, decodeDFOSCredentialUnsafe, isAttenuated, matchesResource, verifyAuthToken, verifyDFOSCredential, verifyDelegationChain } from './credentials/index.js';
4
+ export { Attenuation, AuthTokenClaims, AuthTokenCreateOptions, AuthTokenVerificationError, AuthTokenVerifyOptions, CredentialVerificationError, DFOSCredentialPayload, MAX_CREDENTIAL_SIZE, VerifiedAuthToken, VerifiedDFOSCredential, VerifiedDelegationChain, createAuthToken, createDFOSCredential, decodeDFOSCredentialUnsafe, isAttenuated, matchesResource, verifyAuthToken, verifyDFOSCredential, verifyDelegationChain } from './credentials/index.js';
5
5
  import 'multiformats';
6
6
  import 'multiformats/cid';
7
7
  import 'zod';
package/dist/index.js CHANGED
@@ -6,6 +6,7 @@ import {
6
6
  CountersignPayload,
7
7
  IdentityOperation,
8
8
  MAX_ARTIFACT_PAYLOAD_SIZE,
9
+ MAX_OPERATION_SIZE,
9
10
  MAX_SERVICES_ENTRIES,
10
11
  MAX_SERVICES_PAYLOAD_SIZE,
11
12
  MultikeyPublicKey,
@@ -33,7 +34,7 @@ import {
33
34
  verifyIdentityChain,
34
35
  verifyIdentityExtensionFromTrustedState,
35
36
  verifyRevocation
36
- } from "./chunk-SDUOUFTF.js";
37
+ } from "./chunk-J5C4OXL4.js";
37
38
  import {
38
39
  Attenuation,
39
40
  AuthTokenClaims,
@@ -42,6 +43,7 @@ import {
42
43
  DFOSCredentialPayload,
43
44
  ED25519_PRIV_MULTICODEC,
44
45
  ED25519_PUB_MULTICODEC,
46
+ MAX_CREDENTIAL_SIZE,
45
47
  createAuthToken,
46
48
  createDFOSCredential,
47
49
  decodeDFOSCredentialUnsafe,
@@ -52,7 +54,7 @@ import {
52
54
  verifyAuthToken,
53
55
  verifyDFOSCredential,
54
56
  verifyDelegationChain
55
- } from "./chunk-LQFOBE6X.js";
57
+ } from "./chunk-J3XXF6F5.js";
56
58
  import {
57
59
  JwsVerificationError,
58
60
  JwtVerificationError,
@@ -76,7 +78,7 @@ import {
76
78
  signPayloadEd25519,
77
79
  verifyJws,
78
80
  verifyJwt
79
- } from "./chunk-GQOZJKKO.js";
81
+ } from "./chunk-4QQ5HK5M.js";
80
82
  export {
81
83
  ARTIFACT_CID_ANCHOR_RE,
82
84
  ArtifactPayload,
@@ -94,6 +96,8 @@ export {
94
96
  JwsVerificationError,
95
97
  JwtVerificationError,
96
98
  MAX_ARTIFACT_PAYLOAD_SIZE,
99
+ MAX_CREDENTIAL_SIZE,
100
+ MAX_OPERATION_SIZE,
97
101
  MAX_SERVICES_ENTRIES,
98
102
  MAX_SERVICES_PAYLOAD_SIZE,
99
103
  MultikeyPublicKey,
@@ -2,15 +2,36 @@ import { z } from 'zod';
2
2
 
3
3
  /** Function that signs a byte array and returns a signature */
4
4
  type Signer = (message: Uint8Array) => Promise<Uint8Array>;
5
- /** Max number of service entries in an identity's services state */
6
- declare const MAX_SERVICES_ENTRIES = 16;
7
- /** Max CBOR-encoded size of the services array (bytes) protocol constant */
8
- declare const MAX_SERVICES_PAYLOAD_SIZE = 8192;
5
+ /**
6
+ * Max number of service entries in an identity's services state — a generous
7
+ * cardinality ceiling on resolution fan-out. Individual entry fields are NOT
8
+ * separately length-capped (no per-field length zoo): the aggregate byte cap
9
+ * below, plus the operation-size cap, bound entry size. The op-size cap is the
10
+ * real arbiter when services and keys are both large.
11
+ */
12
+ declare const MAX_SERVICES_ENTRIES = 256;
13
+ /**
14
+ * Max CBOR-encoded size of the services array (bytes) — the SINGLE aggregate that
15
+ * bounds the services manifest, replacing the former per-field length caps (the
16
+ * same collapse the op-size cap applied at the operation level). Sized so the
17
+ * 256-entry ceiling is genuinely reachable with realistic entries.
18
+ */
19
+ declare const MAX_SERVICES_PAYLOAD_SIZE = 32768;
20
+ /**
21
+ * Max dag-cbor-encoded size of a single protocol operation payload (bytes) — the
22
+ * one aggregate validity bound on operation size, measured over the exact bytes
23
+ * the CID commits to. Generously set (64 KiB) so it never binds a legitimate
24
+ * proof-layer operation while bounding decode/verify cost (a DoS + determinism
25
+ * invariant). This is a VALIDITY-determining cap: it MUST be identical across
26
+ * implementations. Large binary media does NOT travel in operation payloads —
27
+ * it is referenced, not inlined — so this bound is about proof-layer ops only.
28
+ */
29
+ declare const MAX_OPERATION_SIZE = 65536;
9
30
  declare const MultikeyPublicKey: z.ZodObject<{
10
31
  id: z.ZodString;
11
32
  type: z.ZodLiteral<"Multikey">;
12
33
  publicKeyMultibase: z.ZodString;
13
- }, z.core.$strict>;
34
+ }, z.core.$loose>;
14
35
  type MultikeyPublicKey = z.infer<typeof MultikeyPublicKey>;
15
36
  /**
16
37
  * Anchor target shapes — a ContentAnchor references a STABLE content
@@ -49,23 +70,23 @@ declare const IdentityOperation: z.ZodDiscriminatedUnion<[z.ZodObject<{
49
70
  id: z.ZodString;
50
71
  type: z.ZodLiteral<"Multikey">;
51
72
  publicKeyMultibase: z.ZodString;
52
- }, z.core.$strict>>;
73
+ }, z.core.$loose>>;
53
74
  assertKeys: z.ZodArray<z.ZodObject<{
54
75
  id: z.ZodString;
55
76
  type: z.ZodLiteral<"Multikey">;
56
77
  publicKeyMultibase: z.ZodString;
57
- }, z.core.$strict>>;
78
+ }, z.core.$loose>>;
58
79
  controllerKeys: z.ZodArray<z.ZodObject<{
59
80
  id: z.ZodString;
60
81
  type: z.ZodLiteral<"Multikey">;
61
82
  publicKeyMultibase: z.ZodString;
62
- }, z.core.$strict>>;
83
+ }, z.core.$loose>>;
63
84
  services: z.ZodOptional<z.ZodArray<z.ZodObject<{
64
85
  id: z.ZodString;
65
86
  type: z.ZodString;
66
87
  }, z.core.$catchall<z.ZodUnknown>>>>;
67
88
  createdAt: z.ZodISODateTime;
68
- }, z.core.$strict>, z.ZodObject<{
89
+ }, z.core.$loose>, z.ZodObject<{
69
90
  version: z.ZodLiteral<1>;
70
91
  type: z.ZodLiteral<"update">;
71
92
  previousOperationCID: z.ZodString;
@@ -73,28 +94,28 @@ declare const IdentityOperation: z.ZodDiscriminatedUnion<[z.ZodObject<{
73
94
  id: z.ZodString;
74
95
  type: z.ZodLiteral<"Multikey">;
75
96
  publicKeyMultibase: z.ZodString;
76
- }, z.core.$strict>>;
97
+ }, z.core.$loose>>;
77
98
  assertKeys: z.ZodArray<z.ZodObject<{
78
99
  id: z.ZodString;
79
100
  type: z.ZodLiteral<"Multikey">;
80
101
  publicKeyMultibase: z.ZodString;
81
- }, z.core.$strict>>;
102
+ }, z.core.$loose>>;
82
103
  controllerKeys: z.ZodArray<z.ZodObject<{
83
104
  id: z.ZodString;
84
105
  type: z.ZodLiteral<"Multikey">;
85
106
  publicKeyMultibase: z.ZodString;
86
- }, z.core.$strict>>;
107
+ }, z.core.$loose>>;
87
108
  services: z.ZodOptional<z.ZodArray<z.ZodObject<{
88
109
  id: z.ZodString;
89
110
  type: z.ZodString;
90
111
  }, z.core.$catchall<z.ZodUnknown>>>>;
91
112
  createdAt: z.ZodISODateTime;
92
- }, z.core.$strict>, z.ZodObject<{
113
+ }, z.core.$loose>, z.ZodObject<{
93
114
  version: z.ZodLiteral<1>;
94
115
  type: z.ZodLiteral<"delete">;
95
116
  previousOperationCID: z.ZodString;
96
117
  createdAt: z.ZodISODateTime;
97
- }, z.core.$strict>], "type">;
118
+ }, z.core.$loose>], "type">;
98
119
  type IdentityOperation = z.infer<typeof IdentityOperation>;
99
120
  declare const VerifiedIdentity: z.ZodObject<{
100
121
  did: z.ZodString;
@@ -103,17 +124,17 @@ declare const VerifiedIdentity: z.ZodObject<{
103
124
  id: z.ZodString;
104
125
  type: z.ZodLiteral<"Multikey">;
105
126
  publicKeyMultibase: z.ZodString;
106
- }, z.core.$strict>>;
127
+ }, z.core.$loose>>;
107
128
  assertKeys: z.ZodArray<z.ZodObject<{
108
129
  id: z.ZodString;
109
130
  type: z.ZodLiteral<"Multikey">;
110
131
  publicKeyMultibase: z.ZodString;
111
- }, z.core.$strict>>;
132
+ }, z.core.$loose>>;
112
133
  controllerKeys: z.ZodArray<z.ZodObject<{
113
134
  id: z.ZodString;
114
135
  type: z.ZodLiteral<"Multikey">;
115
136
  publicKeyMultibase: z.ZodString;
116
- }, z.core.$strict>>;
137
+ }, z.core.$loose>>;
117
138
  services: z.ZodArray<z.ZodObject<{
118
139
  id: z.ZodString;
119
140
  type: z.ZodString;
@@ -128,7 +149,7 @@ declare const ContentOperation: z.ZodDiscriminatedUnion<[z.ZodObject<{
128
149
  baseDocumentCID: z.ZodNullable<z.ZodString>;
129
150
  createdAt: z.ZodISODateTime;
130
151
  note: z.ZodNullable<z.ZodString>;
131
- }, z.core.$strict>, z.ZodObject<{
152
+ }, z.core.$loose>, z.ZodObject<{
132
153
  version: z.ZodLiteral<1>;
133
154
  type: z.ZodLiteral<"update">;
134
155
  did: z.ZodString;
@@ -138,7 +159,7 @@ declare const ContentOperation: z.ZodDiscriminatedUnion<[z.ZodObject<{
138
159
  createdAt: z.ZodISODateTime;
139
160
  note: z.ZodNullable<z.ZodString>;
140
161
  authorization: z.ZodOptional<z.ZodString>;
141
- }, z.core.$strict>, z.ZodObject<{
162
+ }, z.core.$loose>, z.ZodObject<{
142
163
  version: z.ZodLiteral<1>;
143
164
  type: z.ZodLiteral<"delete">;
144
165
  did: z.ZodString;
@@ -146,7 +167,7 @@ declare const ContentOperation: z.ZodDiscriminatedUnion<[z.ZodObject<{
146
167
  createdAt: z.ZodISODateTime;
147
168
  note: z.ZodNullable<z.ZodString>;
148
169
  authorization: z.ZodOptional<z.ZodString>;
149
- }, z.core.$strict>], "type">;
170
+ }, z.core.$loose>], "type">;
150
171
  type ContentOperation = z.infer<typeof ContentOperation>;
151
172
  /** Max CBOR-encoded payload size for artifacts (bytes) — protocol constant */
152
173
  declare const MAX_ARTIFACT_PAYLOAD_SIZE = 16384;
@@ -159,7 +180,7 @@ declare const ArtifactPayload: z.ZodObject<{
159
180
  $schema: z.ZodString;
160
181
  }, z.core.$catchall<z.ZodUnknown>>;
161
182
  createdAt: z.ZodISODateTime;
162
- }, z.core.$strict>;
183
+ }, z.core.$loose>;
163
184
  type ArtifactPayload = z.infer<typeof ArtifactPayload>;
164
185
  /**
165
186
  * Countersign: standalone witness attestation referencing a target operation by CID.
@@ -177,7 +198,7 @@ declare const CountersignPayload: z.ZodObject<{
177
198
  targetCID: z.ZodString;
178
199
  relation: z.ZodOptional<z.ZodString>;
179
200
  createdAt: z.ZodISODateTime;
180
- }, z.core.$strict>;
201
+ }, z.core.$loose>;
181
202
  type CountersignPayload = z.infer<typeof CountersignPayload>;
182
203
  /** Revocation: signed credential revocation artifact, gossiped on the proof plane */
183
204
  declare const RevocationPayload: z.ZodObject<{
@@ -186,7 +207,7 @@ declare const RevocationPayload: z.ZodObject<{
186
207
  did: z.ZodString;
187
208
  credentialCID: z.ZodString;
188
209
  createdAt: z.ZodISODateTime;
189
- }, z.core.$strict>;
210
+ }, z.core.$loose>;
190
211
  type RevocationPayload = z.infer<typeof RevocationPayload>;
191
212
 
192
- export { ARTIFACT_CID_ANCHOR_RE as A, CONTENT_ID_ANCHOR_RE as C, IdentityOperation as I, MAX_ARTIFACT_PAYLOAD_SIZE as M, RevocationPayload as R, ServiceEntry as S, VerifiedIdentity as V, ArtifactPayload as a, ContentOperation as b, CountersignPayload as c, MAX_SERVICES_ENTRIES as d, MAX_SERVICES_PAYLOAD_SIZE as e, MultikeyPublicKey as f, ServicesArray as g, type Signer as h };
213
+ export { ARTIFACT_CID_ANCHOR_RE as A, CONTENT_ID_ANCHOR_RE as C, IdentityOperation as I, MAX_ARTIFACT_PAYLOAD_SIZE as M, RevocationPayload as R, ServiceEntry as S, VerifiedIdentity as V, ArtifactPayload as a, ContentOperation as b, CountersignPayload as c, MAX_OPERATION_SIZE as d, MAX_SERVICES_ENTRIES as e, MAX_SERVICES_PAYLOAD_SIZE as f, MultikeyPublicKey as g, ServicesArray as h, type Signer as i };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metalabel/dfos-protocol",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "type": "module",
5
5
  "description": "DFOS Protocol — Ed25519 signed chain primitives, services, credentials, and verification",
6
6
  "license": "MIT",