@kya-os/contracts 1.3.2 → 1.3.3

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.
Files changed (82) hide show
  1. package/README.md +1 -1
  2. package/dist/agentshield-api/endpoints.d.ts +21 -0
  3. package/dist/agentshield-api/endpoints.js +20 -0
  4. package/dist/agentshield-api/index.d.ts +5 -0
  5. package/dist/agentshield-api/index.js +27 -0
  6. package/dist/agentshield-api/schemas.d.ts +9846 -0
  7. package/dist/agentshield-api/schemas.js +92 -0
  8. package/dist/agentshield-api/types.d.ts +92 -0
  9. package/dist/agentshield-api/types.js +12 -0
  10. package/dist/cli.d.ts +3 -6
  11. package/dist/cli.js +3 -10
  12. package/dist/config/base.d.ts +19 -0
  13. package/dist/config/base.js +2 -0
  14. package/dist/config/delegation.d.ts +46 -0
  15. package/dist/config/delegation.js +2 -0
  16. package/dist/config/identity.d.ts +22 -0
  17. package/dist/config/identity.js +2 -0
  18. package/dist/config/index.d.ts +17 -0
  19. package/dist/config/index.js +2 -0
  20. package/dist/config/proofing.d.ts +26 -0
  21. package/dist/config/proofing.js +2 -0
  22. package/dist/config/tool-protection.d.ts +36 -0
  23. package/dist/config/tool-protection.js +2 -0
  24. package/dist/delegation/constraints.d.ts +0 -266
  25. package/dist/delegation/constraints.js +3 -110
  26. package/dist/delegation/index.d.ts +0 -6
  27. package/dist/delegation/index.js +0 -6
  28. package/dist/delegation/schemas.d.ts +174 -514
  29. package/dist/delegation/schemas.js +3 -247
  30. package/dist/did/index.d.ts +0 -6
  31. package/dist/did/index.js +0 -6
  32. package/dist/did/resolve-contract.d.ts +0 -167
  33. package/dist/did/resolve-contract.js +0 -20
  34. package/dist/did/schemas.d.ts +0 -80
  35. package/dist/did/schemas.js +4 -97
  36. package/dist/did/types.d.ts +0 -126
  37. package/dist/did/types.js +0 -34
  38. package/dist/env/constants.d.ts +0 -45
  39. package/dist/env/constants.js +0 -45
  40. package/dist/env/index.d.ts +0 -4
  41. package/dist/env/index.js +0 -4
  42. package/dist/handshake.d.ts +0 -21
  43. package/dist/handshake.js +3 -11
  44. package/dist/index.d.ts +0 -15
  45. package/dist/index.js +0 -25
  46. package/dist/proof/index.d.ts +0 -7
  47. package/dist/proof/index.js +0 -7
  48. package/dist/proof/proof-record.d.ts +62 -172
  49. package/dist/proof/proof-record.js +0 -74
  50. package/dist/proof/signing-spec.d.ts +12 -86
  51. package/dist/proof/signing-spec.js +0 -71
  52. package/dist/proof.d.ts +16 -38
  53. package/dist/proof.js +3 -26
  54. package/dist/registry.d.ts +10 -27
  55. package/dist/registry.js +9 -30
  56. package/dist/runtime/errors.d.ts +0 -169
  57. package/dist/runtime/errors.js +0 -69
  58. package/dist/runtime/headers.d.ts +0 -50
  59. package/dist/runtime/headers.js +0 -30
  60. package/dist/runtime/index.d.ts +0 -4
  61. package/dist/runtime/index.js +0 -4
  62. package/dist/test.d.ts +0 -37
  63. package/dist/test.js +0 -37
  64. package/dist/tlkrc/index.d.ts +0 -4
  65. package/dist/tlkrc/index.js +0 -4
  66. package/dist/tlkrc/rotation.d.ts +12 -90
  67. package/dist/tlkrc/rotation.js +0 -72
  68. package/dist/tool-protection/index.d.ts +129 -0
  69. package/dist/tool-protection/index.js +80 -0
  70. package/dist/utils/validation.d.ts +0 -17
  71. package/dist/utils/validation.js +0 -14
  72. package/dist/vc/index.d.ts +0 -6
  73. package/dist/vc/index.js +0 -6
  74. package/dist/vc/schemas.d.ts +0 -596
  75. package/dist/vc/schemas.js +2 -111
  76. package/dist/vc/statuslist.d.ts +0 -202
  77. package/dist/vc/statuslist.js +1 -73
  78. package/dist/verifier.d.ts +9 -13
  79. package/dist/verifier.js +0 -8
  80. package/dist/well-known/index.d.ts +248 -0
  81. package/dist/well-known/index.js +104 -0
  82. package/package.json +27 -5
@@ -1,19 +1,4 @@
1
1
  "use strict";
2
- /**
3
- * Delegation Record Schemas
4
- *
5
- * Types and schemas for delegation records that link VCs with CRISP constraints.
6
- * Delegations represent the transfer of authority from one DID to another.
7
- *
8
- * **IMPORTANT**: Per Python POC design (Delegation-Service.md:136-146),
9
- * delegations SHOULD be issued as W3C Verifiable Credentials, not just reference them.
10
- * This file provides both:
11
- * - DelegationRecord: Legacy/internal format (contains delegation data)
12
- * - DelegationCredential: W3C VC format (delegation as credentialSubject)
13
- *
14
- * Related Spec: MCP-I §4.1, §4.2, W3C VC Data Model 1.1
15
- * Python Reference: Delegation-Documentation.md, Delegation-Service.md
16
- */
17
2
  Object.defineProperty(exports, "__esModule", { value: true });
18
3
  exports.DelegationCredentialSchema = exports.DelegationCredentialSubjectSchema = exports.DELEGATION_CREDENTIAL_CONTEXT = exports.DELEGATION_STATUSES = exports.DEFAULT_DELEGATION_STATUS = exports.MAX_DELEGATION_CHAIN_DEPTH = exports.DelegationVerificationResultSchema = exports.DelegationCreationRequestSchema = exports.DelegationChainSchema = exports.DelegationChainEntrySchema = exports.DelegationRecordSchema = exports.DelegationStatusSchema = void 0;
19
4
  exports.validateDelegationRecord = validateDelegationRecord;
@@ -29,163 +14,63 @@ exports.isDelegationCredentialNotYetValid = isDelegationCredentialNotYetValid;
29
14
  const zod_1 = require("zod");
30
15
  const constraints_js_1 = require("./constraints.js");
31
16
  const schemas_js_1 = require("../vc/schemas.js");
32
- /**
33
- * Delegation Status
34
- *
35
- * Lifecycle status of a delegation
36
- */
37
17
  exports.DelegationStatusSchema = zod_1.z.enum(['active', 'revoked', 'expired']);
38
- /**
39
- * Delegation Record Schema
40
- *
41
- * Complete delegation record linking issuer (delegator) to subject (delegatee)
42
- * with backing VC and CRISP constraints.
43
- *
44
- * **Key Invariants:**
45
- * - Delegation MUST reference a live VC via `vcId`
46
- * - Revocation of VC invalidates all linked delegations
47
- * - Chain: no cycles allowed
48
- * - Child `notAfter` ≤ parent `notAfter`
49
- * - Child scopes ⊆ parent scopes
50
- * - Child budgets ≤ parent budgets (same unit)
51
- */
52
18
  exports.DelegationRecordSchema = zod_1.z.object({
53
- /** Unique identifier for the delegation */
54
19
  id: zod_1.z.string().min(1),
55
- /** DID of the delegator (issuer, e.g., merchant/user) */
56
20
  issuerDid: zod_1.z.string().min(1),
57
- /** DID of the delegatee (subject, e.g., agent) */
58
21
  subjectDid: zod_1.z.string().min(1),
59
- /** Optional controller (user account ID or DID) */
60
22
  controller: zod_1.z.string().optional(),
61
- /** ID of the backing Verifiable Credential */
62
23
  vcId: zod_1.z.string().min(1),
63
- /** Optional parent delegation ID for chain tracking */
64
24
  parentId: zod_1.z.string().optional(),
65
- /** CRISP constraints on this delegation */
66
25
  constraints: constraints_js_1.DelegationConstraintsSchema,
67
- /** Detached JWS signature over canonical delegation document */
68
26
  signature: zod_1.z.string().min(1),
69
- /** Current status of the delegation */
70
27
  status: exports.DelegationStatusSchema,
71
- /** Timestamp when created (milliseconds since epoch) */
72
28
  createdAt: zod_1.z.number().int().positive().optional(),
73
- /** Timestamp when revoked (if status is revoked) */
74
29
  revokedAt: zod_1.z.number().int().positive().optional(),
75
- /** Optional reason for revocation */
76
30
  revokedReason: zod_1.z.string().optional(),
77
- /** Optional metadata */
78
31
  metadata: zod_1.z.record(zod_1.z.any()).optional(),
79
- }).passthrough(); // Allow extensibility
80
- /**
81
- * Delegation Chain Entry
82
- *
83
- * Represents a single link in a delegation chain
84
- */
32
+ }).passthrough();
85
33
  exports.DelegationChainEntrySchema = zod_1.z.object({
86
- /** Delegation ID */
87
34
  delegationId: zod_1.z.string().min(1),
88
- /** Issuer DID */
89
35
  issuerDid: zod_1.z.string().min(1),
90
- /** Subject DID */
91
36
  subjectDid: zod_1.z.string().min(1),
92
- /** VC ID */
93
37
  vcId: zod_1.z.string().min(1),
94
- /** Depth in chain (0 = root) */
95
38
  depth: zod_1.z.number().int().nonnegative(),
96
- /** Constraints */
97
39
  constraints: constraints_js_1.DelegationConstraintsSchema,
98
- /** Status */
99
40
  status: exports.DelegationStatusSchema,
100
41
  });
101
- /**
102
- * Delegation Chain
103
- *
104
- * Represents a complete delegation chain from root to leaf
105
- */
106
42
  exports.DelegationChainSchema = zod_1.z.object({
107
- /** Root issuer DID */
108
43
  rootIssuer: zod_1.z.string().min(1),
109
- /** Leaf subject DID */
110
44
  leafSubject: zod_1.z.string().min(1),
111
- /** All delegations in the chain, ordered root to leaf */
112
45
  chain: zod_1.z.array(exports.DelegationChainEntrySchema).min(1),
113
- /** Total chain depth */
114
46
  depth: zod_1.z.number().int().nonnegative(),
115
- /** Whether the entire chain is valid */
116
47
  valid: zod_1.z.boolean(),
117
- /** Optional validation errors */
118
48
  errors: zod_1.z.array(zod_1.z.string()).optional(),
119
49
  });
120
- /**
121
- * Delegation Creation Request
122
- *
123
- * Input for creating a new delegation
124
- */
125
50
  exports.DelegationCreationRequestSchema = zod_1.z.object({
126
- /** Delegator DID */
127
51
  issuerDid: zod_1.z.string().min(1),
128
- /** Delegatee DID */
129
52
  subjectDid: zod_1.z.string().min(1),
130
- /** Optional controller */
131
53
  controller: zod_1.z.string().optional(),
132
- /** Constraints */
133
54
  constraints: constraints_js_1.DelegationConstraintsSchema,
134
- /** Optional parent delegation ID */
135
55
  parentId: zod_1.z.string().optional(),
136
- /** Optional VC ID (if not provided, will be created) */
137
56
  vcId: zod_1.z.string().optional(),
138
57
  });
139
- /**
140
- * Delegation Verification Result
141
- *
142
- * Result of delegation verification
143
- */
144
58
  exports.DelegationVerificationResultSchema = zod_1.z.object({
145
- /** Whether delegation is valid */
146
59
  valid: zod_1.z.boolean(),
147
- /** Delegation ID */
148
60
  delegationId: zod_1.z.string().min(1),
149
- /** Status */
150
61
  status: exports.DelegationStatusSchema,
151
- /** Optional reason for invalid status */
152
62
  reason: zod_1.z.string().optional(),
153
- /** Whether backing VC is valid */
154
63
  credentialValid: zod_1.z.boolean().optional(),
155
- /** Whether chain is valid (if part of chain) */
156
64
  chainValid: zod_1.z.boolean().optional(),
157
- /** Timestamp of verification */
158
65
  verifiedAt: zod_1.z.number().int().positive(),
159
- /** Optional verification details */
160
66
  details: zod_1.z.record(zod_1.z.any()).optional(),
161
67
  });
162
- /**
163
- * Validation Helpers
164
- */
165
- /**
166
- * Validate a delegation record
167
- *
168
- * @param record - The delegation record to validate
169
- * @returns Validation result
170
- */
171
68
  function validateDelegationRecord(record) {
172
69
  return exports.DelegationRecordSchema.safeParse(record);
173
70
  }
174
- /**
175
- * Validate a delegation chain
176
- *
177
- * @param chain - The delegation chain to validate
178
- * @returns Validation result
179
- */
180
71
  function validateDelegationChain(chain) {
181
72
  return exports.DelegationChainSchema.safeParse(chain);
182
73
  }
183
- /**
184
- * Check if a delegation is expired based on constraints
185
- *
186
- * @param delegation - The delegation to check
187
- * @returns true if expired
188
- */
189
74
  function isDelegationExpired(delegation) {
190
75
  if (!delegation.constraints.notAfter) {
191
76
  return false;
@@ -193,12 +78,6 @@ function isDelegationExpired(delegation) {
193
78
  const nowSec = Math.floor(Date.now() / 1000);
194
79
  return nowSec > delegation.constraints.notAfter;
195
80
  }
196
- /**
197
- * Check if a delegation is not yet valid based on constraints
198
- *
199
- * @param delegation - The delegation to check
200
- * @returns true if not yet valid
201
- */
202
81
  function isDelegationNotYetValid(delegation) {
203
82
  if (!delegation.constraints.notBefore) {
204
83
  return false;
@@ -206,12 +85,6 @@ function isDelegationNotYetValid(delegation) {
206
85
  const nowSec = Math.floor(Date.now() / 1000);
207
86
  return nowSec < delegation.constraints.notBefore;
208
87
  }
209
- /**
210
- * Check if a delegation is currently valid (active and within time bounds)
211
- *
212
- * @param delegation - The delegation to check
213
- * @returns true if currently valid
214
- */
215
88
  function isDelegationCurrentlyValid(delegation) {
216
89
  if (delegation.status !== 'active') {
217
90
  return false;
@@ -224,145 +97,55 @@ function isDelegationCurrentlyValid(delegation) {
224
97
  }
225
98
  return true;
226
99
  }
227
- /**
228
- * Constants
229
- */
230
- /**
231
- * Maximum reasonable delegation chain depth
232
- */
233
100
  exports.MAX_DELEGATION_CHAIN_DEPTH = 10;
234
- /**
235
- * Default delegation status for new delegations
236
- */
237
101
  exports.DEFAULT_DELEGATION_STATUS = 'active';
238
- /**
239
- * Supported delegation statuses
240
- */
241
102
  exports.DELEGATION_STATUSES = ['active', 'revoked', 'expired'];
242
- // ============================================================================
243
- // W3C VC-BASED DELEGATION CREDENTIALS (Phase 3 Implementation)
244
- // ============================================================================
245
- /**
246
- * Delegation Credential Context
247
- *
248
- * Additional JSON-LD context for delegation credentials
249
- */
250
103
  exports.DELEGATION_CREDENTIAL_CONTEXT = 'https://schemas.kya-os.ai/xmcp-i/credentials/delegation.v1.0.0.json';
251
- /**
252
- * Delegation Credential Subject Schema
253
- *
254
- * The credentialSubject of a DelegationCredential contains:
255
- * - id: The delegatee DID (subject of the delegation)
256
- * - delegation: The complete delegation record
257
- *
258
- * Per Python POC (Delegation-Service.md:136-146), delegations are issued AS
259
- * W3C VCs, with the delegation data embedded in the credentialSubject.
260
- */
261
104
  exports.DelegationCredentialSubjectSchema = zod_1.z.object({
262
- /** Subject DID (delegatee) */
263
105
  id: zod_1.z.string().min(1),
264
- /** The delegation information */
265
106
  delegation: zod_1.z.object({
266
- /** Unique identifier for the delegation */
267
107
  id: zod_1.z.string().min(1),
268
- /** DID of the delegator (issuer, e.g., merchant/user) */
269
108
  issuerDid: zod_1.z.string().min(1),
270
- /** DID of the delegatee (subject, e.g., agent) */
271
109
  subjectDid: zod_1.z.string().min(1),
272
- /** Optional controller (user account ID or DID) */
273
110
  controller: zod_1.z.string().optional(),
274
- /** Optional parent delegation ID for chain tracking */
275
111
  parentId: zod_1.z.string().optional(),
276
- /** CRISP constraints on this delegation */
277
112
  constraints: constraints_js_1.DelegationConstraintsSchema,
278
- /** Current status of the delegation */
279
113
  status: exports.DelegationStatusSchema.default('active'),
280
- /** Timestamp when created (milliseconds since epoch) */
281
114
  createdAt: zod_1.z.number().int().positive().optional(),
282
- /** Optional metadata */
283
115
  metadata: zod_1.z.record(zod_1.z.any()).optional(),
284
116
  }),
285
117
  });
286
- /**
287
- * Delegation Credential Schema
288
- *
289
- * W3C Verifiable Credential for delegations.
290
- * This is the PRIMARY format for delegation issuance and verification.
291
- *
292
- * Structure:
293
- * - @context: [...W3C VC contexts, delegation context]
294
- * - type: ['VerifiableCredential', 'DelegationCredential']
295
- * - issuer: Delegator DID
296
- * - issuanceDate: When delegation was created
297
- * - expirationDate: Maps to delegation.constraints.notAfter
298
- * - credentialSubject: Contains delegatee DID + delegation data
299
- * - credentialStatus: StatusList2021Entry for revocation checking
300
- * - proof: Ed25519Signature2020
301
- *
302
- * Per Python POC design (Delegation-Service.md:136-163):
303
- * - Every delegation MUST be issued as a VC
304
- * - Verification checks BOTH the VC signature AND delegation constraints
305
- * - Revocation updates the StatusList2021
306
- *
307
- * Related Spec: MCP-I §4.1, §4.2, W3C VC Data Model 1.1
308
- */
309
118
  exports.DelegationCredentialSchema = schemas_js_1.VerifiableCredentialSchema.extend({
310
- /** @context MUST include delegation context */
311
119
  '@context': zod_1.z
312
120
  .array(zod_1.z.union([zod_1.z.string().url(), zod_1.z.record(zod_1.z.any())]))
313
121
  .refine((contexts) => {
314
- // Check for W3C VC context (first)
315
122
  const firstContext = contexts[0];
316
123
  if (typeof firstContext !== 'string' ||
317
124
  firstContext !== 'https://www.w3.org/2018/credentials/v1') {
318
125
  return false;
319
126
  }
320
- // Optionally include delegation context (recommended)
321
127
  return true;
322
128
  }, {
323
129
  message: 'First @context must be W3C VC context',
324
130
  }),
325
- /** type MUST include both VerifiableCredential and DelegationCredential */
326
131
  type: zod_1.z
327
132
  .array(zod_1.z.string())
328
133
  .refine((types) => types.includes('VerifiableCredential') &&
329
134
  types.includes('DelegationCredential'), {
330
135
  message: 'type must include both "VerifiableCredential" and "DelegationCredential"',
331
136
  }),
332
- /** issuer is the delegator DID */
333
137
  issuer: schemas_js_1.IssuerSchema,
334
- /** issuanceDate maps to delegation creation time */
335
138
  issuanceDate: zod_1.z.string().datetime(),
336
- /** expirationDate maps to delegation.constraints.notAfter */
337
139
  expirationDate: zod_1.z.string().datetime().optional(),
338
- /** credentialSubject contains delegatee DID + delegation data */
339
140
  credentialSubject: exports.DelegationCredentialSubjectSchema,
340
- /** credentialStatus for StatusList2021 revocation checking */
341
141
  credentialStatus: schemas_js_1.CredentialStatusSchema.optional(),
342
- /** proof is Ed25519Signature2020 */
343
142
  proof: schemas_js_1.ProofSchema.optional(),
344
143
  });
345
- /**
346
- * Validate a delegation credential
347
- *
348
- * @param credential - The delegation credential to validate
349
- * @returns Validation result
350
- */
351
144
  function validateDelegationCredential(credential) {
352
145
  return exports.DelegationCredentialSchema.safeParse(credential);
353
146
  }
354
- /**
355
- * Extract DelegationRecord from DelegationCredential
356
- *
357
- * Utility to extract the legacy DelegationRecord format from a W3C VC.
358
- * Useful for backward compatibility and internal processing.
359
- *
360
- * @param vc - The delegation credential
361
- * @returns DelegationRecord
362
- */
363
147
  function extractDelegationFromVC(vc) {
364
148
  const delegation = vc.credentialSubject.delegation;
365
- // Extract signature from proof (may be in different formats)
366
149
  let signature = '';
367
150
  if (vc.proof) {
368
151
  const proof = vc.proof;
@@ -373,33 +156,22 @@ function extractDelegationFromVC(vc) {
373
156
  issuerDid: delegation.issuerDid,
374
157
  subjectDid: delegation.subjectDid,
375
158
  controller: delegation.controller,
376
- vcId: vc.id || `vc:${delegation.id}`, // VC id becomes vcId
159
+ vcId: vc.id || `vc:${delegation.id}`,
377
160
  parentId: delegation.parentId,
378
161
  constraints: delegation.constraints,
379
162
  signature,
380
163
  status: delegation.status,
381
164
  createdAt: delegation.createdAt,
382
- revokedAt: undefined, // Revocation status comes from credentialStatus
165
+ revokedAt: undefined,
383
166
  revokedReason: undefined,
384
167
  metadata: delegation.metadata,
385
168
  };
386
169
  }
387
- /**
388
- * Create DelegationCredential from DelegationRecord (unsigned)
389
- *
390
- * Wraps a DelegationRecord in a W3C VC structure (without proof).
391
- * The caller must sign this to create a valid DelegationCredential.
392
- *
393
- * @param delegation - The delegation record
394
- * @param options - Optional VC options (id, issuanceDate, etc.)
395
- * @returns Unsigned DelegationCredential
396
- */
397
170
  function wrapDelegationAsVC(delegation, options) {
398
171
  const now = new Date().toISOString();
399
172
  const expirationDate = delegation.constraints.notAfter
400
173
  ? new Date(delegation.constraints.notAfter * 1000).toISOString()
401
174
  : options?.expirationDate;
402
- // Compute issuanceDate
403
175
  let issuanceDate = options?.issuanceDate || now;
404
176
  if (!options?.issuanceDate && delegation.createdAt) {
405
177
  issuanceDate = new Date(delegation.createdAt).toISOString();
@@ -431,14 +203,7 @@ function wrapDelegationAsVC(delegation, options) {
431
203
  credentialStatus: options?.credentialStatus,
432
204
  };
433
205
  }
434
- /**
435
- * Check if a delegation credential is expired
436
- *
437
- * @param vc - The delegation credential
438
- * @returns true if expired
439
- */
440
206
  function isDelegationCredentialExpired(vc) {
441
- // Check VC expiration
442
207
  if (vc.expirationDate) {
443
208
  const expirationDate = new Date(vc.expirationDate);
444
209
  const now = new Date();
@@ -446,7 +211,6 @@ function isDelegationCredentialExpired(vc) {
446
211
  return true;
447
212
  }
448
213
  }
449
- // Check delegation constraints notAfter
450
214
  const delegation = vc.credentialSubject.delegation;
451
215
  if (delegation.constraints.notAfter) {
452
216
  const nowSec = Math.floor(Date.now() / 1000);
@@ -456,15 +220,8 @@ function isDelegationCredentialExpired(vc) {
456
220
  }
457
221
  return false;
458
222
  }
459
- /**
460
- * Check if a delegation credential is not yet valid
461
- *
462
- * @param vc - The delegation credential
463
- * @returns true if not yet valid
464
- */
465
223
  function isDelegationCredentialNotYetValid(vc) {
466
224
  const delegation = vc.credentialSubject.delegation;
467
- // Check delegation constraints notBefore
468
225
  if (delegation.constraints.notBefore) {
469
226
  const nowSec = Math.floor(Date.now() / 1000);
470
227
  if (nowSec < delegation.constraints.notBefore) {
@@ -473,4 +230,3 @@ function isDelegationCredentialNotYetValid(vc) {
473
230
  }
474
231
  return false;
475
232
  }
476
- //# sourceMappingURL=schemas.js.map
@@ -1,9 +1,3 @@
1
- /**
2
- * DID Module Exports
3
- *
4
- * Types and contracts for W3C Decentralized Identifiers (DIDs)
5
- */
6
1
  export * from './types.js';
7
2
  export * from './resolve-contract.js';
8
3
  export * from './schemas.js';
9
- //# sourceMappingURL=index.d.ts.map
package/dist/did/index.js CHANGED
@@ -1,9 +1,4 @@
1
1
  "use strict";
2
- /**
3
- * DID Module Exports
4
- *
5
- * Types and contracts for W3C Decentralized Identifiers (DIDs)
6
- */
7
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
3
  if (k2 === undefined) k2 = k;
9
4
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -22,4 +17,3 @@ Object.defineProperty(exports, "__esModule", { value: true });
22
17
  __exportStar(require("./types.js"), exports);
23
18
  __exportStar(require("./resolve-contract.js"), exports);
24
19
  __exportStar(require("./schemas.js"), exports);
25
- //# sourceMappingURL=index.js.map
@@ -1,220 +1,53 @@
1
- /**
2
- * DID Resolver Contract
3
- *
4
- * Interface contracts for DID resolution across different implementations.
5
- * This file contains ONLY interfaces and types - no functional code.
6
- *
7
- * Related Spec: MCP-I §2.3
8
- * Python Reference: DID-Service.md
9
- */
10
1
  import type { DidDocument } from './types.js';
11
- /**
12
- * Options for DID resolution
13
- */
14
2
  export interface ResolveOptions {
15
- /**
16
- * Maximum time in milliseconds to wait for resolution
17
- * Default: 500ms (as per env/constants.ts)
18
- */
19
3
  timeoutMs?: number;
20
- /**
21
- * Whether to accept cached resolution results
22
- * If false, forces a fresh resolution
23
- * Default: true
24
- */
25
4
  acceptCache?: boolean;
26
- /**
27
- * Desired cache TTL for this resolution in seconds
28
- * Implementation may ignore if not applicable
29
- */
30
5
  cacheTtlSec?: number;
31
- /**
32
- * Additional metadata to pass to the resolver
33
- * Used for method-specific resolution options
34
- */
35
6
  metadata?: Record<string, any>;
36
7
  }
37
- /**
38
- * Result of DID resolution
39
- *
40
- * Contains the resolved DID Document and metadata about the resolution.
41
- */
42
8
  export interface ResolveResult {
43
- /**
44
- * The resolved DID Document
45
- */
46
9
  doc: DidDocument;
47
- /**
48
- * Timestamp (milliseconds since epoch) when the document was fetched
49
- */
50
10
  fetchedAt: number;
51
- /**
52
- * Cache TTL in seconds (if applicable)
53
- * Indicates how long this result may be cached
54
- */
55
11
  cacheTtlSec?: number;
56
- /**
57
- * Metadata about the resolution process
58
- * May include method-specific information
59
- */
60
12
  metadata?: {
61
- /** Source of the resolution (e.g., "cache", "network", "local") */
62
13
  source?: string;
63
- /** Method used for resolution */
64
14
  method?: string;
65
- /** Whether the document was retrieved from cache */
66
15
  fromCache?: boolean;
67
- /** Additional method-specific metadata */
68
16
  [key: string]: any;
69
17
  };
70
18
  }
71
- /**
72
- * Resolution Error Details
73
- *
74
- * Structure for errors during DID resolution.
75
- */
76
19
  export interface ResolutionError {
77
- /** Error code (e.g., "notFound", "invalidDid", "methodNotSupported") */
78
20
  code: string;
79
- /** Human-readable error message */
80
21
  message: string;
81
- /** Original error if available */
82
22
  cause?: Error;
83
- /** Additional error details */
84
23
  details?: Record<string, any>;
85
24
  }
86
- /**
87
- * DID Resolver Interface
88
- *
89
- * Defines the contract for resolving DIDs to DID Documents.
90
- * Implementations must handle different DID methods and provide caching.
91
- *
92
- * **Implementation Notes:**
93
- * - Resolvers SHOULD support caching to improve performance
94
- * - Resolvers MUST respect timeoutMs to prevent hanging
95
- * - Resolvers MUST validate DID format before attempting resolution
96
- * - Resolvers MAY support multiple DID methods via a registry pattern
97
- *
98
- * **Edge Compatibility:**
99
- * Implementations intended for edge environments should:
100
- * - Minimize dependencies
101
- * - Support offline resolution where possible (e.g., did:key)
102
- * - Use efficient caching strategies
103
- * - Handle network failures gracefully
104
- */
105
25
  export interface DidResolver {
106
- /**
107
- * Resolve a DID to its DID Document
108
- *
109
- * @param did - The DID to resolve (e.g., "did:key:z6Mk...")
110
- * @param opts - Resolution options
111
- * @returns Promise resolving to the DID Document and metadata
112
- * @throws {ResolutionError} If resolution fails
113
- */
114
26
  resolve(did: string, opts?: ResolveOptions): Promise<ResolveResult>;
115
27
  }
116
- /**
117
- * DID Method Resolver Interface
118
- *
119
- * Interface for method-specific resolvers.
120
- * A universal resolver delegates to method resolvers based on the DID method.
121
- */
122
28
  export interface DidMethodResolver {
123
- /**
124
- * The DID method this resolver handles (e.g., "key", "web")
125
- */
126
29
  readonly method: string;
127
- /**
128
- * Resolve a DID using this method
129
- *
130
- * @param did - The DID to resolve
131
- * @param opts - Resolution options
132
- * @returns Promise resolving to the DID Document and metadata
133
- * @throws {ResolutionError} If resolution fails
134
- */
135
30
  resolve(did: string, opts?: ResolveOptions): Promise<ResolveResult>;
136
- /**
137
- * Check if this resolver supports the given DID
138
- *
139
- * @param did - The DID to check
140
- * @returns true if this resolver can handle the DID
141
- */
142
31
  supports(did: string): boolean;
143
32
  }
144
- /**
145
- * DID Resolution Cache Interface
146
- *
147
- * Interface for caching resolved DID Documents.
148
- */
149
33
  export interface DidResolutionCache {
150
- /**
151
- * Get a cached resolution result
152
- *
153
- * @param did - The DID to look up
154
- * @returns Promise resolving to cached result or null if not found/expired
155
- */
156
34
  get(did: string): Promise<ResolveResult | null>;
157
- /**
158
- * Store a resolution result in cache
159
- *
160
- * @param did - The DID being cached
161
- * @param result - The resolution result
162
- * @param ttlSec - TTL in seconds
163
- * @returns Promise resolving when stored
164
- */
165
35
  set(did: string, result: ResolveResult, ttlSec: number): Promise<void>;
166
- /**
167
- * Invalidate cached result for a DID
168
- *
169
- * @param did - The DID to invalidate
170
- * @returns Promise resolving when invalidated
171
- */
172
36
  invalidate(did: string): Promise<void>;
173
- /**
174
- * Clear all cached results
175
- *
176
- * @returns Promise resolving when cleared
177
- */
178
37
  clear(): Promise<void>;
179
38
  }
180
- /**
181
- * Universal DID Resolver Configuration
182
- *
183
- * Configuration for a universal resolver that delegates to method-specific resolvers.
184
- */
185
39
  export interface UniversalResolverConfig {
186
- /**
187
- * Method-specific resolvers
188
- * Key is the method name (e.g., "key", "web")
189
- */
190
40
  methodResolvers?: Map<string, DidMethodResolver> | Record<string, DidMethodResolver>;
191
- /**
192
- * Optional cache implementation
193
- */
194
41
  cache?: DidResolutionCache;
195
- /**
196
- * Default resolution options
197
- */
198
42
  defaultOptions?: ResolveOptions;
199
43
  }
200
- /**
201
- * Common resolution error codes
202
- */
203
44
  export declare const RESOLUTION_ERROR_CODES: {
204
- /** DID not found */
205
45
  readonly NOT_FOUND: "notFound";
206
- /** Invalid DID format */
207
46
  readonly INVALID_DID: "invalidDid";
208
- /** DID method not supported */
209
47
  readonly METHOD_NOT_SUPPORTED: "methodNotSupported";
210
- /** Resolution timeout */
211
48
  readonly TIMEOUT: "timeout";
212
- /** Network error during resolution */
213
49
  readonly NETWORK_ERROR: "networkError";
214
- /** Invalid DID Document structure */
215
50
  readonly INVALID_DOCUMENT: "invalidDocument";
216
- /** Internal resolver error */
217
51
  readonly INTERNAL_ERROR: "internalError";
218
52
  };
219
53
  export type ResolutionErrorCode = (typeof RESOLUTION_ERROR_CODES)[keyof typeof RESOLUTION_ERROR_CODES];
220
- //# sourceMappingURL=resolve-contract.d.ts.map