@kya-os/mcp-i-core 1.0.0 → 1.1.1-canary.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.
Files changed (98) hide show
  1. package/README.md +33 -0
  2. package/dist/__tests__/utils/mock-providers.d.ts +102 -0
  3. package/dist/__tests__/utils/mock-providers.d.ts.map +1 -0
  4. package/dist/__tests__/utils/mock-providers.js +270 -0
  5. package/dist/__tests__/utils/mock-providers.js.map +1 -0
  6. package/dist/cache/tool-protection-cache.d.ts +73 -0
  7. package/dist/cache/tool-protection-cache.d.ts.map +1 -0
  8. package/dist/cache/tool-protection-cache.js +83 -0
  9. package/dist/cache/tool-protection-cache.js.map +1 -0
  10. package/dist/compliance/index.d.ts +8 -0
  11. package/dist/compliance/index.d.ts.map +1 -0
  12. package/dist/compliance/index.js +24 -0
  13. package/dist/compliance/index.js.map +1 -0
  14. package/dist/compliance/schema-registry.d.ts +50 -0
  15. package/dist/compliance/schema-registry.d.ts.map +1 -0
  16. package/dist/compliance/schema-registry.js +438 -0
  17. package/dist/compliance/schema-registry.js.map +1 -0
  18. package/dist/compliance/schema-verifier-v2.d.ts +110 -0
  19. package/dist/compliance/schema-verifier-v2.d.ts.map +1 -0
  20. package/dist/compliance/schema-verifier-v2.js +510 -0
  21. package/dist/compliance/schema-verifier-v2.js.map +1 -0
  22. package/dist/compliance/schema-verifier.d.ts +110 -0
  23. package/dist/compliance/schema-verifier.d.ts.map +1 -0
  24. package/dist/compliance/schema-verifier.js +518 -0
  25. package/dist/compliance/schema-verifier.js.map +1 -0
  26. package/dist/delegation/bitstring.d.ts +139 -0
  27. package/dist/delegation/bitstring.d.ts.map +1 -0
  28. package/dist/delegation/bitstring.js +213 -0
  29. package/dist/delegation/bitstring.js.map +1 -0
  30. package/dist/delegation/cascading-revocation.d.ts +162 -0
  31. package/dist/delegation/cascading-revocation.d.ts.map +1 -0
  32. package/dist/delegation/cascading-revocation.js +263 -0
  33. package/dist/delegation/cascading-revocation.js.map +1 -0
  34. package/dist/delegation/delegation-graph.d.ts +178 -0
  35. package/dist/delegation/delegation-graph.d.ts.map +1 -0
  36. package/dist/delegation/delegation-graph.js +209 -0
  37. package/dist/delegation/delegation-graph.js.map +1 -0
  38. package/dist/delegation/index.d.ts +14 -0
  39. package/dist/delegation/index.d.ts.map +1 -0
  40. package/dist/delegation/index.js +30 -0
  41. package/dist/delegation/index.js.map +1 -0
  42. package/dist/delegation/statuslist-manager.d.ts +148 -0
  43. package/dist/delegation/statuslist-manager.d.ts.map +1 -0
  44. package/dist/delegation/statuslist-manager.js +221 -0
  45. package/dist/delegation/statuslist-manager.js.map +1 -0
  46. package/dist/delegation/storage/index.d.ts +9 -0
  47. package/dist/delegation/storage/index.d.ts.map +1 -0
  48. package/dist/delegation/storage/index.js +25 -0
  49. package/dist/delegation/storage/index.js.map +1 -0
  50. package/dist/delegation/storage/memory-graph-storage.d.ts +70 -0
  51. package/dist/delegation/storage/memory-graph-storage.d.ts.map +1 -0
  52. package/dist/delegation/storage/memory-graph-storage.js +149 -0
  53. package/dist/delegation/storage/memory-graph-storage.js.map +1 -0
  54. package/dist/delegation/storage/memory-statuslist-storage.d.ts +49 -0
  55. package/dist/delegation/storage/memory-statuslist-storage.d.ts.map +1 -0
  56. package/dist/delegation/storage/memory-statuslist-storage.js +67 -0
  57. package/dist/delegation/storage/memory-statuslist-storage.js.map +1 -0
  58. package/dist/delegation/utils.d.ts +19 -0
  59. package/dist/delegation/utils.d.ts.map +1 -0
  60. package/dist/delegation/utils.js +48 -0
  61. package/dist/delegation/utils.js.map +1 -0
  62. package/dist/delegation/vc-issuer.d.ts +135 -0
  63. package/dist/delegation/vc-issuer.d.ts.map +1 -0
  64. package/dist/delegation/vc-issuer.js +140 -0
  65. package/dist/delegation/vc-issuer.js.map +1 -0
  66. package/dist/delegation/vc-verifier.d.ts +213 -0
  67. package/dist/delegation/vc-verifier.d.ts.map +1 -0
  68. package/dist/delegation/vc-verifier.js +354 -0
  69. package/dist/delegation/vc-verifier.js.map +1 -0
  70. package/dist/index.d.ts +16 -0
  71. package/dist/index.d.ts.map +1 -1
  72. package/dist/index.js +64 -1
  73. package/dist/index.js.map +1 -1
  74. package/dist/providers/base.d.ts +1 -1
  75. package/dist/providers/base.d.ts.map +1 -1
  76. package/dist/providers/memory.js +2 -2
  77. package/dist/providers/memory.js.map +1 -1
  78. package/dist/runtime/base.d.ts +23 -0
  79. package/dist/runtime/base.d.ts.map +1 -1
  80. package/dist/runtime/base.js +135 -12
  81. package/dist/runtime/base.js.map +1 -1
  82. package/dist/services/tool-protection.service.d.ts +55 -0
  83. package/dist/services/tool-protection.service.d.ts.map +1 -0
  84. package/dist/services/tool-protection.service.js +158 -0
  85. package/dist/services/tool-protection.service.js.map +1 -0
  86. package/dist/types/tool-protection.d.ts +103 -0
  87. package/dist/types/tool-protection.d.ts.map +1 -0
  88. package/dist/types/tool-protection.js +41 -0
  89. package/dist/types/tool-protection.js.map +1 -0
  90. package/dist/utils/cors.d.ts +44 -0
  91. package/dist/utils/cors.d.ts.map +1 -0
  92. package/dist/utils/cors.js +71 -0
  93. package/dist/utils/cors.js.map +1 -0
  94. package/dist/utils/index.d.ts +5 -0
  95. package/dist/utils/index.d.ts.map +1 -0
  96. package/dist/utils/index.js +21 -0
  97. package/dist/utils/index.js.map +1 -0
  98. package/package.json +11 -6
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ /**
3
+ * Delegation Utilities
4
+ *
5
+ * Shared utility functions for delegation credential operations.
6
+ * Following DRY (Don't Repeat Yourself) principle.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.canonicalizeJSON = canonicalizeJSON;
10
+ /**
11
+ * JSON canonicalization (RFC 8785)
12
+ *
13
+ * Creates a deterministic representation of JSON for signing.
14
+ * Per W3C VC spec, canonicalization ensures identical VCs produce identical signatures.
15
+ *
16
+ * DRY: Single implementation shared across vc-issuer and statuslist-manager.
17
+ *
18
+ * @param obj - The object to canonicalize
19
+ * @returns Canonical JSON string
20
+ */
21
+ function canonicalizeJSON(obj) {
22
+ if (obj === null)
23
+ return 'null';
24
+ if (typeof obj === 'boolean')
25
+ return obj.toString();
26
+ if (typeof obj === 'number') {
27
+ if (!isFinite(obj)) {
28
+ throw new Error('Cannot canonicalize non-finite number');
29
+ }
30
+ return JSON.stringify(obj);
31
+ }
32
+ if (typeof obj === 'string')
33
+ return JSON.stringify(obj);
34
+ if (Array.isArray(obj)) {
35
+ const elements = obj.map((item) => canonicalizeJSON(item));
36
+ return '[' + elements.join(',') + ']';
37
+ }
38
+ if (typeof obj === 'object') {
39
+ const keys = Object.keys(obj).sort();
40
+ const pairs = keys.map((key) => {
41
+ const value = canonicalizeJSON(obj[key]);
42
+ return JSON.stringify(key) + ':' + value;
43
+ });
44
+ return '{' + pairs.join(',') + '}';
45
+ }
46
+ throw new Error(`Cannot canonicalize type: ${typeof obj}`);
47
+ }
48
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/delegation/utils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAaH,4CAuBC;AAlCD;;;;;;;;;;GAUG;AACH,SAAgB,gBAAgB,CAAC,GAAQ;IACvC,IAAI,GAAG,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC;IAChC,IAAI,OAAO,GAAG,KAAK,SAAS;QAAE,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;IACpD,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC5B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;QAC3D,CAAC;QACD,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IACD,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IACxD,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACvB,MAAM,QAAQ,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC;QAC3D,OAAO,GAAG,GAAG,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;IACxC,CAAC;IACD,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC5B,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;QACrC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;YAC7B,MAAM,KAAK,GAAG,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;YACzC,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,KAAK,CAAC;QAC3C,CAAC,CAAC,CAAC;QACH,OAAO,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;IACrC,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,6BAA6B,OAAO,GAAG,EAAE,CAAC,CAAC;AAC7D,CAAC"}
@@ -0,0 +1,135 @@
1
+ /**
2
+ * Delegation Credential Issuer (Platform-Agnostic)
3
+ *
4
+ * Issues W3C Verifiable Credentials for delegations with Ed25519 signatures.
5
+ * Follows the Python POC design (Delegation-Service.md:136-163) where
6
+ * delegations are issued AS W3C VCs.
7
+ *
8
+ * Related Spec: MCP-I §4.1, §4.2, W3C VC Data Model 1.1
9
+ * Python Reference: Delegation-Service.md
10
+ */
11
+ import type { DelegationCredential, DelegationRecord, CredentialStatus, Proof } from '@kya-os/contracts';
12
+ /**
13
+ * Options for issuing a delegation credential
14
+ */
15
+ export interface IssueDelegationOptions {
16
+ /** VC ID (optional, will be generated if not provided) */
17
+ id?: string;
18
+ /** Issuance date (optional, defaults to now) */
19
+ issuanceDate?: string;
20
+ /** Expiration date (optional, derived from constraints if not provided) */
21
+ expirationDate?: string;
22
+ /** Credential status for StatusList2021 (optional) */
23
+ credentialStatus?: CredentialStatus;
24
+ /** Additional context URIs (optional) */
25
+ additionalContexts?: string[];
26
+ }
27
+ /**
28
+ * Signing function interface
29
+ *
30
+ * Platform-specific implementations provide this function to sign VCs.
31
+ * For example:
32
+ * - Node.js: Uses jose library with importPKCS8
33
+ * - Cloudflare: Uses Web Crypto API
34
+ */
35
+ export interface VCSigningFunction {
36
+ /**
37
+ * Sign a canonicalized VC
38
+ *
39
+ * @param canonicalVC - The canonical JSON string to sign
40
+ * @param issuerDid - The DID of the issuer
41
+ * @param kid - The key ID
42
+ * @returns Ed25519Signature2020 proof
43
+ */
44
+ (canonicalVC: string, issuerDid: string, kid: string): Promise<Proof>;
45
+ }
46
+ /**
47
+ * Identity provider interface
48
+ *
49
+ * Platform-specific implementations provide identity details.
50
+ */
51
+ export interface IdentityProvider {
52
+ /** Get the DID of this identity */
53
+ getDid(): string;
54
+ /** Get the key ID of this identity */
55
+ getKeyId(): string;
56
+ /** Get the private key (base64 encoded) */
57
+ getPrivateKey(): string;
58
+ }
59
+ /**
60
+ * Delegation Credential Issuer (Platform-Agnostic)
61
+ *
62
+ * Issues W3C Verifiable Credentials for delegations.
63
+ * Per Python POC (Delegation-Service.md:136-146):
64
+ * - Every delegation MUST be issued as a VC
65
+ * - VC is signed with Ed25519 (Ed25519Signature2020)
66
+ * - StatusList2021 support for efficient revocation
67
+ */
68
+ export declare class DelegationCredentialIssuer {
69
+ private identity;
70
+ private signingFunction;
71
+ constructor(identity: IdentityProvider, signingFunction: VCSigningFunction);
72
+ /**
73
+ * Issue a delegation credential
74
+ *
75
+ * Creates a W3C Verifiable Credential from a delegation record.
76
+ * Signs it with Ed25519 and returns the complete DelegationCredential.
77
+ *
78
+ * @param delegation - The delegation record to issue as a VC
79
+ * @param options - Issuance options
80
+ * @returns Signed DelegationCredential
81
+ */
82
+ issueDelegationCredential(delegation: DelegationRecord, options?: IssueDelegationOptions): Promise<DelegationCredential>;
83
+ /**
84
+ * Create a delegation record and issue it as a VC in one step
85
+ *
86
+ * Convenience method for creating a new delegation from scratch.
87
+ *
88
+ * @param params - Delegation parameters
89
+ * @param options - Issuance options
90
+ * @returns Signed DelegationCredential
91
+ */
92
+ createAndIssueDelegation(params: {
93
+ id: string;
94
+ issuerDid: string;
95
+ subjectDid: string;
96
+ controller?: string;
97
+ parentId?: string;
98
+ constraints: DelegationRecord['constraints'];
99
+ status?: DelegationRecord['status'];
100
+ metadata?: Record<string, any>;
101
+ }, options?: IssueDelegationOptions): Promise<DelegationCredential>;
102
+ /**
103
+ * Canonicalize VC for signing
104
+ *
105
+ * Uses JCS (JSON Canonicalization Scheme, RFC 8785) to create
106
+ * a deterministic representation of the VC.
107
+ *
108
+ * @param vc - The unsigned VC
109
+ * @returns Canonical JSON string
110
+ */
111
+ private canonicalizeVC;
112
+ /**
113
+ * Get issuer DID
114
+ *
115
+ * @returns The DID of this issuer
116
+ */
117
+ getIssuerDid(): string;
118
+ /**
119
+ * Get issuer key ID
120
+ *
121
+ * @returns The key ID of this issuer
122
+ */
123
+ getIssuerKeyId(): string;
124
+ }
125
+ /**
126
+ * Create a delegation credential issuer
127
+ *
128
+ * Convenience factory function.
129
+ *
130
+ * @param identity - Identity provider
131
+ * @param signingFunction - Platform-specific signing function
132
+ * @returns DelegationCredentialIssuer instance
133
+ */
134
+ export declare function createDelegationIssuer(identity: IdentityProvider, signingFunction: VCSigningFunction): DelegationCredentialIssuer;
135
+ //# sourceMappingURL=vc-issuer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vc-issuer.d.ts","sourceRoot":"","sources":["../../src/delegation/vc-issuer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EACV,oBAAoB,EACpB,gBAAgB,EAChB,gBAAgB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B,CAAC,aAAa,CAAC,CAAC;QAC7C,MAAM,CAAC,EAAE,gBAAgB,CAAC,QAAQ,CAAC,CAAC;QACpC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KAChC,EACD,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,oBAAoB,CAAC;IAsBhC;;;;;;;;OAQG;IACH,OAAO,CAAC,cAAc;IAKtB;;;;OAIG;IACH,YAAY,IAAI,MAAM;IAItB;;;;OAIG;IACH,cAAc,IAAI,MAAM;CAGzB;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,gBAAgB,EAC1B,eAAe,EAAE,iBAAiB,GACjC,0BAA0B,CAE5B"}
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ /**
3
+ * Delegation Credential Issuer (Platform-Agnostic)
4
+ *
5
+ * Issues W3C Verifiable Credentials for delegations with Ed25519 signatures.
6
+ * Follows the Python POC design (Delegation-Service.md:136-163) where
7
+ * delegations are issued AS W3C VCs.
8
+ *
9
+ * Related Spec: MCP-I §4.1, §4.2, W3C VC Data Model 1.1
10
+ * Python Reference: Delegation-Service.md
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.DelegationCredentialIssuer = void 0;
14
+ exports.createDelegationIssuer = createDelegationIssuer;
15
+ const contracts_1 = require("@kya-os/contracts");
16
+ const utils_1 = require("./utils");
17
+ /**
18
+ * Delegation Credential Issuer (Platform-Agnostic)
19
+ *
20
+ * Issues W3C Verifiable Credentials for delegations.
21
+ * Per Python POC (Delegation-Service.md:136-146):
22
+ * - Every delegation MUST be issued as a VC
23
+ * - VC is signed with Ed25519 (Ed25519Signature2020)
24
+ * - StatusList2021 support for efficient revocation
25
+ */
26
+ class DelegationCredentialIssuer {
27
+ identity;
28
+ signingFunction;
29
+ constructor(identity, signingFunction) {
30
+ this.identity = identity;
31
+ this.signingFunction = signingFunction;
32
+ }
33
+ /**
34
+ * Issue a delegation credential
35
+ *
36
+ * Creates a W3C Verifiable Credential from a delegation record.
37
+ * Signs it with Ed25519 and returns the complete DelegationCredential.
38
+ *
39
+ * @param delegation - The delegation record to issue as a VC
40
+ * @param options - Issuance options
41
+ * @returns Signed DelegationCredential
42
+ */
43
+ async issueDelegationCredential(delegation, options = {}) {
44
+ // Step 1: Create unsigned VC
45
+ let unsignedVC = (0, contracts_1.wrapDelegationAsVC)(delegation, {
46
+ id: options.id,
47
+ issuanceDate: options.issuanceDate,
48
+ expirationDate: options.expirationDate,
49
+ credentialStatus: options.credentialStatus,
50
+ });
51
+ // Add additional contexts if provided
52
+ if (options.additionalContexts && options.additionalContexts.length > 0) {
53
+ const existingContexts = unsignedVC['@context'];
54
+ unsignedVC = {
55
+ ...unsignedVC,
56
+ '@context': [...existingContexts, ...options.additionalContexts],
57
+ };
58
+ }
59
+ // Step 2: Canonicalize VC (for signing)
60
+ const canonicalVC = this.canonicalizeVC(unsignedVC);
61
+ // Step 3: Sign with Ed25519 using platform-specific signing function
62
+ const proof = await this.signingFunction(canonicalVC, this.identity.getDid(), this.identity.getKeyId());
63
+ // Step 4: Return signed VC
64
+ return {
65
+ ...unsignedVC,
66
+ proof,
67
+ };
68
+ }
69
+ /**
70
+ * Create a delegation record and issue it as a VC in one step
71
+ *
72
+ * Convenience method for creating a new delegation from scratch.
73
+ *
74
+ * @param params - Delegation parameters
75
+ * @param options - Issuance options
76
+ * @returns Signed DelegationCredential
77
+ */
78
+ async createAndIssueDelegation(params, options = {}) {
79
+ const now = Date.now();
80
+ // Create delegation record
81
+ const delegation = {
82
+ id: params.id,
83
+ issuerDid: params.issuerDid,
84
+ subjectDid: params.subjectDid,
85
+ controller: params.controller,
86
+ vcId: options.id || `urn:uuid:${params.id}`,
87
+ parentId: params.parentId,
88
+ constraints: params.constraints,
89
+ signature: '', // Will be filled by VC proof
90
+ status: params.status || 'active',
91
+ createdAt: now,
92
+ metadata: params.metadata,
93
+ };
94
+ // Issue as VC
95
+ return this.issueDelegationCredential(delegation, options);
96
+ }
97
+ /**
98
+ * Canonicalize VC for signing
99
+ *
100
+ * Uses JCS (JSON Canonicalization Scheme, RFC 8785) to create
101
+ * a deterministic representation of the VC.
102
+ *
103
+ * @param vc - The unsigned VC
104
+ * @returns Canonical JSON string
105
+ */
106
+ canonicalizeVC(vc) {
107
+ // DRY: Use shared canonicalization utility
108
+ return (0, utils_1.canonicalizeJSON)(vc);
109
+ }
110
+ /**
111
+ * Get issuer DID
112
+ *
113
+ * @returns The DID of this issuer
114
+ */
115
+ getIssuerDid() {
116
+ return this.identity.getDid();
117
+ }
118
+ /**
119
+ * Get issuer key ID
120
+ *
121
+ * @returns The key ID of this issuer
122
+ */
123
+ getIssuerKeyId() {
124
+ return this.identity.getKeyId();
125
+ }
126
+ }
127
+ exports.DelegationCredentialIssuer = DelegationCredentialIssuer;
128
+ /**
129
+ * Create a delegation credential issuer
130
+ *
131
+ * Convenience factory function.
132
+ *
133
+ * @param identity - Identity provider
134
+ * @param signingFunction - Platform-specific signing function
135
+ * @returns DelegationCredentialIssuer instance
136
+ */
137
+ function createDelegationIssuer(identity, signingFunction) {
138
+ return new DelegationCredentialIssuer(identity, signingFunction);
139
+ }
140
+ //# sourceMappingURL=vc-issuer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vc-issuer.js","sourceRoot":"","sources":["../../src/delegation/vc-issuer.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAyNH,wDAKC;AAtND,iDAAuD;AACvD,mCAA2C;AA0D3C;;;;;;;;GAQG;AACH,MAAa,0BAA0B;IAE3B;IACA;IAFV,YACU,QAA0B,EAC1B,eAAkC;QADlC,aAAQ,GAAR,QAAQ,CAAkB;QAC1B,oBAAe,GAAf,eAAe,CAAmB;IACzC,CAAC;IAEJ;;;;;;;;;OASG;IACH,KAAK,CAAC,yBAAyB,CAC7B,UAA4B,EAC5B,UAAkC,EAAE;QAEpC,6BAA6B;QAC7B,IAAI,UAAU,GAAG,I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3C,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,WAAW,EAAE,MAAM,CAAC,WAAW;YAC/B,SAAS,EAAE,EAAE,EAAE,6BAA6B;YAC5C,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,QAAQ;YACjC,SAAS,EAAE,GAAG;YACd,QAAQ,EAAE,MAAM,CAAC,QAAQ;SAC1B,CAAC;QAEF,cAAc;QACd,OAAO,IAAI,CAAC,yBAAyB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAC7D,CAAC;IAED;;;;;;;;OAQG;IACK,cAAc,CAAC,EAAuC;QAC5D,2CAA2C;QAC3C,OAAO,IAAA,wBAAgB,EAAC,EAAE,CAAC,CAAC;IAC9B,CAAC;IAED;;;;OAIG;IACH,YAAY;QACV,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;IAChC,CAAC;IAED;;;;OAIG;IACH,cAAc;QACZ,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;IAClC,CAAC;CACF;AAlID,gEAkIC;AAED;;;;;;;;GAQG;AACH,SAAgB,sBAAsB,CACpC,QAA0B,EAC1B,eAAkC;IAElC,OAAO,IAAI,0BAA0B,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;AACnE,CAAC"}
@@ -0,0 +1,213 @@
1
+ /**
2
+ * Delegation Credential Verifier (Platform-Agnostic)
3
+ *
4
+ * Progressive enhancement verification for W3C Delegation Credentials.
5
+ * Follows the Edge-Delegation-Verification.md pattern:
6
+ *
7
+ * Stage 1: Fast basic checks (no network, early rejection)
8
+ * Stage 2: Parallel advanced checks (signature, status)
9
+ * Stage 3: Combined results
10
+ *
11
+ * Related Spec: MCP-I §4.3, W3C VC Data Model 1.1
12
+ * Python Reference: Edge-Delegation-Verification.md
13
+ */
14
+ import type { DelegationCredential, CredentialStatus } from '@kya-os/contracts';
15
+ /**
16
+ * Verification result for delegation credentials
17
+ */
18
+ export interface DelegationVCVerificationResult {
19
+ /** Whether the delegation credential is valid */
20
+ valid: boolean;
21
+ /** Reason for invalid result (if valid=false) */
22
+ reason?: string;
23
+ /** Stage at which verification completed */
24
+ stage: 'basic' | 'signature' | 'status' | 'complete';
25
+ /** Whether result came from cache */
26
+ cached?: boolean;
27
+ /** Performance metrics */
28
+ metrics?: {
29
+ basicCheckMs?: number;
30
+ signatureCheckMs?: number;
31
+ statusCheckMs?: number;
32
+ totalMs: number;
33
+ };
34
+ /** Details about what was checked */
35
+ checks?: {
36
+ basicValid?: boolean;
37
+ signatureValid?: boolean;
38
+ statusValid?: boolean;
39
+ };
40
+ }
41
+ /**
42
+ * Options for verification
43
+ */
44
+ export interface VerifyDelegationVCOptions {
45
+ /** Skip cache and force fresh verification */
46
+ skipCache?: boolean;
47
+ /** Skip signature verification (faster, less secure) */
48
+ skipSignature?: boolean;
49
+ /** Skip status checking (faster, may miss revocations) */
50
+ skipStatus?: boolean;
51
+ /** DID resolver for fetching public keys */
52
+ didResolver?: DIDResolver;
53
+ /** Status list resolver for checking revocation */
54
+ statusListResolver?: StatusListResolver;
55
+ }
56
+ /**
57
+ * DID Resolver interface
58
+ */
59
+ export interface DIDResolver {
60
+ /**
61
+ * Resolve a DID to get the DID Document
62
+ * @param did - The DID to resolve
63
+ * @returns DID Document with verification methods
64
+ */
65
+ resolve(did: string): Promise<DIDDocument | null>;
66
+ }
67
+ /**
68
+ * DID Document (simplified)
69
+ */
70
+ export interface DIDDocument {
71
+ id: string;
72
+ verificationMethod?: VerificationMethod[];
73
+ authentication?: (string | VerificationMethod)[];
74
+ assertionMethod?: (string | VerificationMethod)[];
75
+ }
76
+ /**
77
+ * Verification Method
78
+ */
79
+ export interface VerificationMethod {
80
+ id: string;
81
+ type: string;
82
+ controller: string;
83
+ publicKeyJwk?: any;
84
+ publicKeyBase58?: string;
85
+ publicKeyMultibase?: string;
86
+ }
87
+ /**
88
+ * Status List Resolver interface
89
+ */
90
+ export interface StatusListResolver {
91
+ /**
92
+ * Check if a credential is revoked via StatusList2021
93
+ * @param status - The credential status entry
94
+ * @returns true if revoked, false otherwise
95
+ */
96
+ checkStatus(status: CredentialStatus): Promise<boolean>;
97
+ }
98
+ /**
99
+ * Signature verification function interface
100
+ *
101
+ * Platform-specific implementations provide this function.
102
+ */
103
+ export interface SignatureVerificationFunction {
104
+ /**
105
+ * Verify an Ed25519 signature on a VC
106
+ *
107
+ * @param vc - The VC to verify
108
+ * @param publicKeyJwk - The public key in JWK format
109
+ * @returns Verification result
110
+ */
111
+ (vc: DelegationCredential, publicKeyJwk: any): Promise<{
112
+ valid: boolean;
113
+ reason?: string;
114
+ }>;
115
+ }
116
+ /**
117
+ * Delegation Credential Verifier (Platform-Agnostic)
118
+ *
119
+ * Implements progressive enhancement pattern from Edge-Delegation-Verification.md:
120
+ * 1. Fast basic checks (no network) - early rejection
121
+ * 2. Parallel advanced checks (signature + status)
122
+ * 3. Combined results
123
+ */
124
+ export declare class DelegationCredentialVerifier {
125
+ private didResolver?;
126
+ private statusListResolver?;
127
+ private signatureVerifier?;
128
+ private cache;
129
+ private cacheTtl;
130
+ constructor(options?: {
131
+ didResolver?: DIDResolver;
132
+ statusListResolver?: StatusListResolver;
133
+ signatureVerifier?: SignatureVerificationFunction;
134
+ cacheTtl?: number;
135
+ });
136
+ /**
137
+ * Verify a delegation credential with progressive enhancement
138
+ *
139
+ * Per Edge-Delegation-Verification.md:41-102
140
+ *
141
+ * @param vc - The delegation credential to verify
142
+ * @param options - Verification options
143
+ * @returns Verification result
144
+ */
145
+ verifyDelegationCredential(vc: DelegationCredential, options?: VerifyDelegationVCOptions): Promise<DelegationVCVerificationResult>;
146
+ /**
147
+ * Stage 1: Validate basic properties (no network calls)
148
+ *
149
+ * Fast path for early rejection of invalid delegations.
150
+ * Per Edge-Delegation-Verification.md:155-186
151
+ *
152
+ * @param vc - The delegation credential
153
+ * @returns Validation result
154
+ */
155
+ private validateBasicProperties;
156
+ /**
157
+ * Stage 2a: Verify signature
158
+ *
159
+ * Per Edge-Delegation-Verification.md:191-234
160
+ *
161
+ * @param vc - The delegation credential
162
+ * @param didResolver - Optional DID resolver
163
+ * @returns Verification result
164
+ */
165
+ private verifySignature;
166
+ /**
167
+ * Stage 2b: Check credential status via StatusList2021
168
+ *
169
+ * @param status - The credential status entry
170
+ * @param statusListResolver - Optional status list resolver
171
+ * @returns Status check result
172
+ */
173
+ private checkCredentialStatus;
174
+ /**
175
+ * Find verification method in DID document
176
+ *
177
+ * @param didDoc - The DID document
178
+ * @param verificationMethodId - The verification method ID
179
+ * @returns Verification method or undefined
180
+ */
181
+ private findVerificationMethod;
182
+ /**
183
+ * Get from cache
184
+ */
185
+ private getFromCache;
186
+ /**
187
+ * Set in cache
188
+ */
189
+ private setInCache;
190
+ /**
191
+ * Clear cache
192
+ */
193
+ clearCache(): void;
194
+ /**
195
+ * Clear cache entry for specific VC
196
+ */
197
+ clearCacheEntry(id: string): void;
198
+ }
199
+ /**
200
+ * Create a delegation credential verifier
201
+ *
202
+ * Convenience factory function.
203
+ *
204
+ * @param options - Verifier options
205
+ * @returns DelegationCredentialVerifier instance
206
+ */
207
+ export declare function createDelegationVerifier(options?: {
208
+ didResolver?: DIDResolver;
209
+ statusListResolver?: StatusListResolver;
210
+ signatureVerifier?: SignatureVerificationFunction;
211
+ cacheTtl?: number;
212
+ }): DelegationCredentialVerifier;
213
+ //# sourceMappingURL=vc-verifier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vc-verifier.d.ts","sourceRoot":"","sources":["../../src/delegation/vc-verifier.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EACV,oBAAoB,EACpB,gBAAgB,EACjB,MAAM,mBAAmB,CAAC;AAO3B;;GAEG;AACH,MAAM,WAAW,8BAA8B;IAC7C,iDAAiD;IACjD,KAAK,EAAE,OAAO,CAAC;IAEf,iDAAiD;IACjD,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,4CAA4C;IAC5C,KAAK,EAAE,OAAO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