@kya-os/contracts 1.3.1-canary.0 → 1.3.1-canary.2

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 (55) hide show
  1. package/dist/cli.d.ts +48 -10
  2. package/dist/cli.js +18 -6
  3. package/dist/delegation/schemas.d.ts +4330 -29
  4. package/dist/delegation/schemas.js +248 -2
  5. package/dist/did/index.d.ts +1 -0
  6. package/dist/did/index.js +1 -0
  7. package/dist/did/schemas.d.ts +113 -0
  8. package/dist/did/schemas.js +173 -0
  9. package/dist/did/types.d.ts +1 -1
  10. package/dist/handshake.d.ts +2 -2
  11. package/dist/index.d.ts +2 -0
  12. package/dist/index.js +3 -0
  13. package/dist/proof.d.ts +238 -0
  14. package/dist/proof.js +32 -1
  15. package/dist/registry.d.ts +15 -15
  16. package/dist/registry.js +3 -2
  17. package/dist/test.d.ts +19 -19
  18. package/dist/test.js +5 -5
  19. package/dist/utils/validation.d.ts +1 -1
  20. package/dist/utils/validation.js +1 -1
  21. package/dist/verifier.d.ts +31 -17
  22. package/dist/verifier.js +18 -2
  23. package/package.json +3 -5
  24. package/dist/cli.d.ts.map +0 -1
  25. package/dist/delegation/constraints.d.ts.map +0 -1
  26. package/dist/delegation/index.d.ts.map +0 -1
  27. package/dist/delegation/schemas.d.ts.map +0 -1
  28. package/dist/did/index.d.ts.map +0 -1
  29. package/dist/did/resolve-contract.d.ts.map +0 -1
  30. package/dist/did/types.d.ts.map +0 -1
  31. package/dist/env/constants.d.ts.map +0 -1
  32. package/dist/env/index.d.ts.map +0 -1
  33. package/dist/handshake.d.ts.map +0 -1
  34. package/dist/index.d.ts.map +0 -1
  35. package/dist/proof/index.d.ts.map +0 -1
  36. package/dist/proof/proof-record.d.ts.map +0 -1
  37. package/dist/proof/signing-spec.d.ts.map +0 -1
  38. package/dist/proof.d.ts.map +0 -1
  39. package/dist/registry.d.ts.map +0 -1
  40. package/dist/runtime/errors.d.ts.map +0 -1
  41. package/dist/runtime/headers.d.ts.map +0 -1
  42. package/dist/runtime/index.d.ts.map +0 -1
  43. package/dist/test.d.ts.map +0 -1
  44. package/dist/tlkrc/index.d.ts.map +0 -1
  45. package/dist/tlkrc/rotation.d.ts.map +0 -1
  46. package/dist/utils/validation.d.ts.map +0 -1
  47. package/dist/vc/index.d.ts.map +0 -1
  48. package/dist/vc/schemas.d.ts.map +0 -1
  49. package/dist/vc/statuslist.d.ts.map +0 -1
  50. package/dist/verifier.d.ts.map +0 -1
  51. package/schemas/cli/register-output/v1.0.0.json +0 -69
  52. package/schemas/proof/v1.0.0.json +0 -80
  53. package/schemas/registry/receipt-v1.0.0.json +0 -60
  54. package/schemas/verifier/verify-page/v1.0.0.json +0 -94
  55. package/schemas/well-known/agent/v1.0.0.json +0 -49
@@ -5,18 +5,30 @@
5
5
  * Types and schemas for delegation records that link VCs with CRISP constraints.
6
6
  * Delegations represent the transfer of authority from one DID to another.
7
7
  *
8
- * Related Spec: MCP-I §4.1, §4.2
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
9
15
  * Python Reference: Delegation-Documentation.md, Delegation-Service.md
10
16
  */
11
17
  Object.defineProperty(exports, "__esModule", { value: true });
12
- 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;
18
+ 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;
13
19
  exports.validateDelegationRecord = validateDelegationRecord;
14
20
  exports.validateDelegationChain = validateDelegationChain;
15
21
  exports.isDelegationExpired = isDelegationExpired;
16
22
  exports.isDelegationNotYetValid = isDelegationNotYetValid;
17
23
  exports.isDelegationCurrentlyValid = isDelegationCurrentlyValid;
24
+ exports.validateDelegationCredential = validateDelegationCredential;
25
+ exports.extractDelegationFromVC = extractDelegationFromVC;
26
+ exports.wrapDelegationAsVC = wrapDelegationAsVC;
27
+ exports.isDelegationCredentialExpired = isDelegationCredentialExpired;
28
+ exports.isDelegationCredentialNotYetValid = isDelegationCredentialNotYetValid;
18
29
  const zod_1 = require("zod");
19
30
  const constraints_js_1 = require("./constraints.js");
31
+ const schemas_js_1 = require("../vc/schemas.js");
20
32
  /**
21
33
  * Delegation Status
22
34
  *
@@ -227,4 +239,238 @@ exports.DEFAULT_DELEGATION_STATUS = 'active';
227
239
  * Supported delegation statuses
228
240
  */
229
241
  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
+ 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
+ exports.DelegationCredentialSubjectSchema = zod_1.z.object({
262
+ /** Subject DID (delegatee) */
263
+ id: zod_1.z.string().min(1),
264
+ /** The delegation information */
265
+ delegation: zod_1.z.object({
266
+ /** Unique identifier for the delegation */
267
+ id: zod_1.z.string().min(1),
268
+ /** DID of the delegator (issuer, e.g., merchant/user) */
269
+ issuerDid: zod_1.z.string().min(1),
270
+ /** DID of the delegatee (subject, e.g., agent) */
271
+ subjectDid: zod_1.z.string().min(1),
272
+ /** Optional controller (user account ID or DID) */
273
+ controller: zod_1.z.string().optional(),
274
+ /** Optional parent delegation ID for chain tracking */
275
+ parentId: zod_1.z.string().optional(),
276
+ /** CRISP constraints on this delegation */
277
+ constraints: constraints_js_1.DelegationConstraintsSchema,
278
+ /** Current status of the delegation */
279
+ status: exports.DelegationStatusSchema.default('active'),
280
+ /** Timestamp when created (milliseconds since epoch) */
281
+ createdAt: zod_1.z.number().int().positive().optional(),
282
+ /** Optional metadata */
283
+ metadata: zod_1.z.record(zod_1.z.any()).optional(),
284
+ }),
285
+ });
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
+ exports.DelegationCredentialSchema = schemas_js_1.VerifiableCredentialSchema.extend({
310
+ /** @context MUST include delegation context */
311
+ '@context': zod_1.z
312
+ .array(zod_1.z.union([zod_1.z.string().url(), zod_1.z.record(zod_1.z.any())]))
313
+ .refine((contexts) => {
314
+ // Check for W3C VC context (first)
315
+ const firstContext = contexts[0];
316
+ if (typeof firstContext !== 'string' ||
317
+ firstContext !== 'https://www.w3.org/2018/credentials/v1') {
318
+ return false;
319
+ }
320
+ // Optionally include delegation context (recommended)
321
+ return true;
322
+ }, {
323
+ message: 'First @context must be W3C VC context',
324
+ }),
325
+ /** type MUST include both VerifiableCredential and DelegationCredential */
326
+ type: zod_1.z
327
+ .array(zod_1.z.string())
328
+ .refine((types) => types.includes('VerifiableCredential') &&
329
+ types.includes('DelegationCredential'), {
330
+ message: 'type must include both "VerifiableCredential" and "DelegationCredential"',
331
+ }),
332
+ /** issuer is the delegator DID */
333
+ issuer: schemas_js_1.IssuerSchema,
334
+ /** issuanceDate maps to delegation creation time */
335
+ issuanceDate: zod_1.z.string().datetime(),
336
+ /** expirationDate maps to delegation.constraints.notAfter */
337
+ expirationDate: zod_1.z.string().datetime().optional(),
338
+ /** credentialSubject contains delegatee DID + delegation data */
339
+ credentialSubject: exports.DelegationCredentialSubjectSchema,
340
+ /** credentialStatus for StatusList2021 revocation checking */
341
+ credentialStatus: schemas_js_1.CredentialStatusSchema.optional(),
342
+ /** proof is Ed25519Signature2020 */
343
+ proof: schemas_js_1.ProofSchema.optional(),
344
+ });
345
+ /**
346
+ * Validate a delegation credential
347
+ *
348
+ * @param credential - The delegation credential to validate
349
+ * @returns Validation result
350
+ */
351
+ function validateDelegationCredential(credential) {
352
+ return exports.DelegationCredentialSchema.safeParse(credential);
353
+ }
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
+ function extractDelegationFromVC(vc) {
364
+ const delegation = vc.credentialSubject.delegation;
365
+ // Extract signature from proof (may be in different formats)
366
+ let signature = '';
367
+ if (vc.proof) {
368
+ const proof = vc.proof;
369
+ signature = proof.proofValue || proof.jws || proof.signatureValue || '';
370
+ }
371
+ return {
372
+ id: delegation.id,
373
+ issuerDid: delegation.issuerDid,
374
+ subjectDid: delegation.subjectDid,
375
+ controller: delegation.controller,
376
+ vcId: vc.id || `vc:${delegation.id}`, // VC id becomes vcId
377
+ parentId: delegation.parentId,
378
+ constraints: delegation.constraints,
379
+ signature,
380
+ status: delegation.status,
381
+ createdAt: delegation.createdAt,
382
+ revokedAt: undefined, // Revocation status comes from credentialStatus
383
+ revokedReason: undefined,
384
+ metadata: delegation.metadata,
385
+ };
386
+ }
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
+ function wrapDelegationAsVC(delegation, options) {
398
+ const now = new Date().toISOString();
399
+ const expirationDate = delegation.constraints.notAfter
400
+ ? new Date(delegation.constraints.notAfter * 1000).toISOString()
401
+ : options?.expirationDate;
402
+ // Compute issuanceDate
403
+ let issuanceDate = options?.issuanceDate || now;
404
+ if (!options?.issuanceDate && delegation.createdAt) {
405
+ issuanceDate = new Date(delegation.createdAt).toISOString();
406
+ }
407
+ return {
408
+ '@context': [
409
+ 'https://www.w3.org/2018/credentials/v1',
410
+ exports.DELEGATION_CREDENTIAL_CONTEXT,
411
+ ],
412
+ id: options?.id || delegation.vcId || `urn:uuid:${delegation.id}`,
413
+ type: ['VerifiableCredential', 'DelegationCredential'],
414
+ issuer: delegation.issuerDid,
415
+ issuanceDate,
416
+ expirationDate,
417
+ credentialSubject: {
418
+ id: delegation.subjectDid,
419
+ delegation: {
420
+ id: delegation.id,
421
+ issuerDid: delegation.issuerDid,
422
+ subjectDid: delegation.subjectDid,
423
+ controller: delegation.controller,
424
+ parentId: delegation.parentId,
425
+ constraints: delegation.constraints,
426
+ status: delegation.status,
427
+ createdAt: delegation.createdAt,
428
+ metadata: delegation.metadata,
429
+ },
430
+ },
431
+ credentialStatus: options?.credentialStatus,
432
+ };
433
+ }
434
+ /**
435
+ * Check if a delegation credential is expired
436
+ *
437
+ * @param vc - The delegation credential
438
+ * @returns true if expired
439
+ */
440
+ function isDelegationCredentialExpired(vc) {
441
+ // Check VC expiration
442
+ if (vc.expirationDate) {
443
+ const expirationDate = new Date(vc.expirationDate);
444
+ const now = new Date();
445
+ if (expirationDate < now) {
446
+ return true;
447
+ }
448
+ }
449
+ // Check delegation constraints notAfter
450
+ const delegation = vc.credentialSubject.delegation;
451
+ if (delegation.constraints.notAfter) {
452
+ const nowSec = Math.floor(Date.now() / 1000);
453
+ if (nowSec > delegation.constraints.notAfter) {
454
+ return true;
455
+ }
456
+ }
457
+ return false;
458
+ }
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
+ function isDelegationCredentialNotYetValid(vc) {
466
+ const delegation = vc.credentialSubject.delegation;
467
+ // Check delegation constraints notBefore
468
+ if (delegation.constraints.notBefore) {
469
+ const nowSec = Math.floor(Date.now() / 1000);
470
+ if (nowSec < delegation.constraints.notBefore) {
471
+ return true;
472
+ }
473
+ }
474
+ return false;
475
+ }
230
476
  //# sourceMappingURL=schemas.js.map
@@ -5,4 +5,5 @@
5
5
  */
6
6
  export * from './types.js';
7
7
  export * from './resolve-contract.js';
8
+ export * from './schemas.js';
8
9
  //# sourceMappingURL=index.d.ts.map
package/dist/did/index.js CHANGED
@@ -21,4 +21,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
22
  __exportStar(require("./types.js"), exports);
23
23
  __exportStar(require("./resolve-contract.js"), exports);
24
+ __exportStar(require("./schemas.js"), exports);
24
25
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,113 @@
1
+ /**
2
+ * DID Document Zod Schemas
3
+ *
4
+ * Runtime validation schemas for DID Documents conforming to W3C DID Core specification.
5
+ * These schemas complement the TypeScript types in types.ts with runtime validation.
6
+ *
7
+ * Related Spec: MCP-I §2.1, §2.3, W3C DID Core 1.0
8
+ */
9
+ import { z } from 'zod';
10
+ import type { DidDocument, VerificationMethod, DidService } from './types.js';
11
+ /**
12
+ * Standard W3C DID Core context
13
+ */
14
+ export declare const DID_CONTEXT: "https://www.w3.org/ns/did/v1";
15
+ /**
16
+ * DID Context Entry Schema
17
+ *
18
+ * A context entry can be:
19
+ * - A URL string (most common)
20
+ * - A context definition object
21
+ */
22
+ export declare const DidContextEntrySchema: z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodAny>]>;
23
+ /**
24
+ * DID @context Schema
25
+ *
26
+ * The @context property in DID Documents can be:
27
+ * - A single string (typically the base DID context)
28
+ * - An array of strings/objects (base context + additional contexts)
29
+ * - A context definition object (for custom contexts)
30
+ *
31
+ * Per W3C DID Core spec, the base DID context should be present,
32
+ * but we allow flexibility for different DID methods and extensions.
33
+ */
34
+ export declare const DidContextSchema: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodAny>]>, "atleastone">, z.ZodRecord<z.ZodString, z.ZodAny>]>;
35
+ /**
36
+ * Verification Method Type Schema
37
+ */
38
+ export declare const VerificationMethodTypeSchema: z.ZodEnum<["Ed25519VerificationKey2020", "JsonWebKey2020", "EcdsaSecp256k1VerificationKey2019"]>;
39
+ /**
40
+ * Public Key JWK Schema (RFC 7517)
41
+ */
42
+ export declare const PublicKeyJwkSchema: z.ZodObject<{
43
+ /** Key Type */
44
+ kty: z.ZodString;
45
+ /** Curve (for elliptic curve keys) */
46
+ crv: z.ZodString;
47
+ /** X coordinate */
48
+ x: z.ZodString;
49
+ /** Y coordinate (optional for some key types) */
50
+ y: z.ZodOptional<z.ZodString>;
51
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
52
+ /** Key Type */
53
+ kty: z.ZodString;
54
+ /** Curve (for elliptic curve keys) */
55
+ crv: z.ZodString;
56
+ /** X coordinate */
57
+ x: z.ZodString;
58
+ /** Y coordinate (optional for some key types) */
59
+ y: z.ZodOptional<z.ZodString>;
60
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
61
+ /** Key Type */
62
+ kty: z.ZodString;
63
+ /** Curve (for elliptic curve keys) */
64
+ crv: z.ZodString;
65
+ /** X coordinate */
66
+ x: z.ZodString;
67
+ /** Y coordinate (optional for some key types) */
68
+ y: z.ZodOptional<z.ZodString>;
69
+ }, z.ZodTypeAny, "passthrough">>;
70
+ /**
71
+ * Verification Method Schema
72
+ */
73
+ export declare const VerificationMethodSchema: z.ZodType<VerificationMethod>;
74
+ /**
75
+ * DID Service Schema
76
+ */
77
+ export declare const DidServiceSchema: z.ZodType<DidService>;
78
+ /**
79
+ * Verification Relationship Entry Schema
80
+ *
81
+ * Can be either a string reference to a verification method
82
+ * or an embedded verification method object.
83
+ */
84
+ export declare const VerificationRelationshipEntrySchema: z.ZodUnion<[z.ZodString, z.ZodType<VerificationMethod, z.ZodTypeDef, VerificationMethod>]>;
85
+ /**
86
+ * DID Document Schema
87
+ *
88
+ * Validates a DID Document structure per W3C DID Core specification.
89
+ */
90
+ export declare const DidDocumentSchema: z.ZodType<DidDocument>;
91
+ /**
92
+ * DID Method Schema
93
+ */
94
+ export declare const DidMethodSchema: z.ZodEnum<["key", "web", "jwk", "ion", "ebsi"]>;
95
+ /**
96
+ * Helper function to validate a DID Document
97
+ *
98
+ * @param doc - The document to validate
99
+ * @returns The validated document or throws ZodError
100
+ */
101
+ export declare function validateDidDocument(doc: unknown): DidDocument;
102
+ /**
103
+ * Helper function to safely validate a DID Document
104
+ *
105
+ * @param doc - The document to validate
106
+ * @returns Result object with success status and data/error
107
+ */
108
+ export declare function safeValidateDidDocument(doc: unknown): {
109
+ success: boolean;
110
+ data?: DidDocument;
111
+ error?: z.ZodError;
112
+ };
113
+ //# sourceMappingURL=schemas.d.ts.map
@@ -0,0 +1,173 @@
1
+ "use strict";
2
+ /**
3
+ * DID Document Zod Schemas
4
+ *
5
+ * Runtime validation schemas for DID Documents conforming to W3C DID Core specification.
6
+ * These schemas complement the TypeScript types in types.ts with runtime validation.
7
+ *
8
+ * Related Spec: MCP-I §2.1, §2.3, W3C DID Core 1.0
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.DidMethodSchema = exports.DidDocumentSchema = exports.VerificationRelationshipEntrySchema = exports.DidServiceSchema = exports.VerificationMethodSchema = exports.PublicKeyJwkSchema = exports.VerificationMethodTypeSchema = exports.DidContextSchema = exports.DidContextEntrySchema = exports.DID_CONTEXT = void 0;
12
+ exports.validateDidDocument = validateDidDocument;
13
+ exports.safeValidateDidDocument = safeValidateDidDocument;
14
+ const zod_1 = require("zod");
15
+ /**
16
+ * Standard W3C DID Core context
17
+ */
18
+ exports.DID_CONTEXT = 'https://www.w3.org/ns/did/v1';
19
+ /**
20
+ * DID Context Entry Schema
21
+ *
22
+ * A context entry can be:
23
+ * - A URL string (most common)
24
+ * - A context definition object
25
+ */
26
+ exports.DidContextEntrySchema = zod_1.z.union([
27
+ zod_1.z.string().url(),
28
+ zod_1.z.record(zod_1.z.any()),
29
+ ]);
30
+ /**
31
+ * DID @context Schema
32
+ *
33
+ * The @context property in DID Documents can be:
34
+ * - A single string (typically the base DID context)
35
+ * - An array of strings/objects (base context + additional contexts)
36
+ * - A context definition object (for custom contexts)
37
+ *
38
+ * Per W3C DID Core spec, the base DID context should be present,
39
+ * but we allow flexibility for different DID methods and extensions.
40
+ */
41
+ exports.DidContextSchema = zod_1.z.union([
42
+ // Single string context (e.g., "https://www.w3.org/ns/did/v1")
43
+ zod_1.z.string().url(),
44
+ // Array of contexts (strings or objects)
45
+ zod_1.z.array(exports.DidContextEntrySchema).nonempty(),
46
+ // Context definition object
47
+ zod_1.z.record(zod_1.z.any()),
48
+ ]);
49
+ /**
50
+ * Verification Method Type Schema
51
+ */
52
+ exports.VerificationMethodTypeSchema = zod_1.z.enum([
53
+ 'Ed25519VerificationKey2020',
54
+ 'JsonWebKey2020',
55
+ 'EcdsaSecp256k1VerificationKey2019',
56
+ ]);
57
+ /**
58
+ * Public Key JWK Schema (RFC 7517)
59
+ */
60
+ exports.PublicKeyJwkSchema = zod_1.z
61
+ .object({
62
+ /** Key Type */
63
+ kty: zod_1.z.string(),
64
+ /** Curve (for elliptic curve keys) */
65
+ crv: zod_1.z.string(),
66
+ /** X coordinate */
67
+ x: zod_1.z.string(),
68
+ /** Y coordinate (optional for some key types) */
69
+ y: zod_1.z.string().optional(),
70
+ })
71
+ .passthrough(); // Allow additional JWK properties
72
+ /**
73
+ * Verification Method Schema
74
+ */
75
+ exports.VerificationMethodSchema = zod_1.z.object({
76
+ /** Verification method identifier */
77
+ id: zod_1.z.string(),
78
+ /** Type of verification method */
79
+ type: exports.VerificationMethodTypeSchema,
80
+ /** Controller DID */
81
+ controller: zod_1.z.string(),
82
+ /** Multibase-encoded public key (for Ed25519VerificationKey2020) */
83
+ publicKeyMultibase: zod_1.z.string().optional(),
84
+ /** JSON Web Key (for JsonWebKey2020) */
85
+ publicKeyJwk: exports.PublicKeyJwkSchema.optional(),
86
+ });
87
+ /**
88
+ * DID Service Schema
89
+ */
90
+ exports.DidServiceSchema = zod_1.z.object({
91
+ /** Service identifier */
92
+ id: zod_1.z.string(),
93
+ /** Service type(s) */
94
+ type: zod_1.z.union([zod_1.z.string(), zod_1.z.array(zod_1.z.string())]),
95
+ /** Service endpoint(s) */
96
+ serviceEndpoint: zod_1.z.union([
97
+ zod_1.z.string(),
98
+ zod_1.z.array(zod_1.z.string()),
99
+ zod_1.z.record(zod_1.z.any()),
100
+ ]),
101
+ });
102
+ /**
103
+ * Verification Relationship Entry Schema
104
+ *
105
+ * Can be either a string reference to a verification method
106
+ * or an embedded verification method object.
107
+ */
108
+ exports.VerificationRelationshipEntrySchema = zod_1.z.union([
109
+ zod_1.z.string(), // Reference to verification method
110
+ exports.VerificationMethodSchema, // Embedded verification method
111
+ ]);
112
+ /**
113
+ * DID Document Schema
114
+ *
115
+ * Validates a DID Document structure per W3C DID Core specification.
116
+ */
117
+ exports.DidDocumentSchema = zod_1.z
118
+ .object({
119
+ /** JSON-LD context */
120
+ '@context': exports.DidContextSchema.optional(),
121
+ /** The DID this document describes */
122
+ id: zod_1.z.string().refine((val) => val.startsWith('did:'), {
123
+ message: 'DID must start with "did:"',
124
+ }),
125
+ /** Alternative identifiers */
126
+ alsoKnownAs: zod_1.z.array(zod_1.z.string()).optional(),
127
+ /** Verification methods */
128
+ verificationMethod: zod_1.z.array(exports.VerificationMethodSchema).optional(),
129
+ /** Authentication verification relationship */
130
+ authentication: zod_1.z.array(exports.VerificationRelationshipEntrySchema).optional(),
131
+ /** Assertion method verification relationship */
132
+ assertionMethod: zod_1.z.array(exports.VerificationRelationshipEntrySchema).optional(),
133
+ /** Key agreement verification relationship */
134
+ keyAgreement: zod_1.z.array(exports.VerificationRelationshipEntrySchema).optional(),
135
+ /** Capability invocation verification relationship */
136
+ capabilityInvocation: zod_1.z
137
+ .array(exports.VerificationRelationshipEntrySchema)
138
+ .optional(),
139
+ /** Capability delegation verification relationship */
140
+ capabilityDelegation: zod_1.z
141
+ .array(exports.VerificationRelationshipEntrySchema)
142
+ .optional(),
143
+ /** Service endpoints */
144
+ service: zod_1.z.array(exports.DidServiceSchema).optional(),
145
+ })
146
+ .passthrough(); // Allow additional properties for extensibility
147
+ /**
148
+ * DID Method Schema
149
+ */
150
+ exports.DidMethodSchema = zod_1.z.enum(['key', 'web', 'jwk', 'ion', 'ebsi']);
151
+ /**
152
+ * Helper function to validate a DID Document
153
+ *
154
+ * @param doc - The document to validate
155
+ * @returns The validated document or throws ZodError
156
+ */
157
+ function validateDidDocument(doc) {
158
+ return exports.DidDocumentSchema.parse(doc);
159
+ }
160
+ /**
161
+ * Helper function to safely validate a DID Document
162
+ *
163
+ * @param doc - The document to validate
164
+ * @returns Result object with success status and data/error
165
+ */
166
+ function safeValidateDidDocument(doc) {
167
+ const result = exports.DidDocumentSchema.safeParse(doc);
168
+ if (result.success) {
169
+ return { success: true, data: result.data };
170
+ }
171
+ return { success: false, error: result.error };
172
+ }
173
+ //# sourceMappingURL=schemas.js.map
@@ -21,7 +21,7 @@ export type VerificationMethodType = 'Ed25519VerificationKey2020' | 'JsonWebKey2
21
21
  *
22
22
  * **kid Derivation Guidelines:**
23
23
  * - For did:key: kid = `${did}#${multibaseKey}`
24
- * - For did:web: kid = `${did}#${keyId}` where keyId is from DID Document
24
+ * - For did:web: kid = `${did}#${kid}` where kid is from DID Document
25
25
  * - The kid MUST be resolvable to a verification method in the DID Document
26
26
  */
27
27
  export interface VerificationMethod {
@@ -28,20 +28,20 @@ export declare const SessionContextSchema: z.ZodObject<{
28
28
  ttlMinutes: z.ZodDefault<z.ZodNumber>;
29
29
  agentDid: z.ZodOptional<z.ZodString>;
30
30
  }, "strip", z.ZodTypeAny, {
31
+ createdAt: number;
31
32
  nonce: string;
32
33
  audience: string;
33
34
  timestamp: number;
34
35
  sessionId: string;
35
- createdAt: number;
36
36
  lastActivity: number;
37
37
  ttlMinutes: number;
38
38
  agentDid?: string | undefined;
39
39
  }, {
40
+ createdAt: number;
40
41
  nonce: string;
41
42
  audience: string;
42
43
  timestamp: number;
43
44
  sessionId: string;
44
- createdAt: number;
45
45
  lastActivity: number;
46
46
  agentDid?: string | undefined;
47
47
  ttlMinutes?: number | undefined;
package/dist/index.d.ts CHANGED
@@ -19,6 +19,8 @@ export * from "./registry.js";
19
19
  export * from "./cli.js";
20
20
  export * from "./test.js";
21
21
  export * from "./utils/validation.js";
22
+ export * from "./vc/index.js";
23
+ export * from "./delegation/index.js";
22
24
  export declare const CONTRACTS_VERSION = "1.2.1";
23
25
  export declare const SUPPORTED_XMCP_I_VERSION = "^1.0.0";
24
26
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -37,6 +37,9 @@ __exportStar(require("./registry.js"), exports);
37
37
  __exportStar(require("./cli.js"), exports);
38
38
  __exportStar(require("./test.js"), exports);
39
39
  __exportStar(require("./utils/validation.js"), exports);
40
+ // W3C VC and Delegation exports (for mcp-i-core compatibility)
41
+ __exportStar(require("./vc/index.js"), exports);
42
+ __exportStar(require("./delegation/index.js"), exports);
40
43
  // Version information
41
44
  exports.CONTRACTS_VERSION = "1.2.1";
42
45
  exports.SUPPORTED_XMCP_I_VERSION = "^1.0.0";