@kya-os/mcp-i-core 1.3.7-canary.0 → 1.3.7-canary.clientinfo.20251126041014

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 (236) hide show
  1. package/.turbo/turbo-build.log +4 -0
  2. package/.turbo/turbo-test$colon$coverage.log +4239 -0
  3. package/.turbo/turbo-test.log +2973 -0
  4. package/COMPLIANCE_IMPROVEMENT_REPORT.md +483 -0
  5. package/Composer 3.md +615 -0
  6. package/GPT-5.md +1169 -0
  7. package/OPUS-plan.md +352 -0
  8. package/PHASE_3_AND_4.1_SUMMARY.md +585 -0
  9. package/PHASE_3_SUMMARY.md +317 -0
  10. package/PHASE_4.1.3_SUMMARY.md +428 -0
  11. package/PHASE_4.1_COMPLETE.md +525 -0
  12. package/PHASE_4_USER_DID_IDENTITY_LINKING_PLAN.md +1240 -0
  13. package/SCHEMA_COMPLIANCE_REPORT.md +275 -0
  14. package/TEST_PLAN.md +571 -0
  15. package/coverage/coverage-final.json +57 -0
  16. package/dist/__tests__/utils/mock-providers.d.ts +1 -2
  17. package/dist/__tests__/utils/mock-providers.d.ts.map +1 -1
  18. package/dist/__tests__/utils/mock-providers.js.map +1 -1
  19. package/dist/cache/oauth-config-cache.d.ts +69 -0
  20. package/dist/cache/oauth-config-cache.d.ts.map +1 -0
  21. package/dist/cache/oauth-config-cache.js +76 -0
  22. package/dist/cache/oauth-config-cache.js.map +1 -0
  23. package/dist/identity/idp-token-resolver.d.ts +53 -0
  24. package/dist/identity/idp-token-resolver.d.ts.map +1 -0
  25. package/dist/identity/idp-token-resolver.js +108 -0
  26. package/dist/identity/idp-token-resolver.js.map +1 -0
  27. package/dist/identity/idp-token-storage.interface.d.ts +42 -0
  28. package/dist/identity/idp-token-storage.interface.d.ts.map +1 -0
  29. package/dist/identity/idp-token-storage.interface.js +12 -0
  30. package/dist/identity/idp-token-storage.interface.js.map +1 -0
  31. package/dist/identity/user-did-manager.d.ts +39 -1
  32. package/dist/identity/user-did-manager.d.ts.map +1 -1
  33. package/dist/identity/user-did-manager.js +69 -3
  34. package/dist/identity/user-did-manager.js.map +1 -1
  35. package/dist/index.d.ts +24 -0
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +43 -1
  38. package/dist/index.js.map +1 -1
  39. package/dist/runtime/audit-logger.d.ts +37 -0
  40. package/dist/runtime/audit-logger.d.ts.map +1 -0
  41. package/dist/runtime/audit-logger.js +9 -0
  42. package/dist/runtime/audit-logger.js.map +1 -0
  43. package/dist/runtime/base.d.ts +19 -2
  44. package/dist/runtime/base.d.ts.map +1 -1
  45. package/dist/runtime/base.js +227 -11
  46. package/dist/runtime/base.js.map +1 -1
  47. package/dist/services/access-control.service.d.ts.map +1 -1
  48. package/dist/services/access-control.service.js +199 -15
  49. package/dist/services/access-control.service.js.map +1 -1
  50. package/dist/services/authorization/authorization-registry.d.ts +29 -0
  51. package/dist/services/authorization/authorization-registry.d.ts.map +1 -0
  52. package/dist/services/authorization/authorization-registry.js +57 -0
  53. package/dist/services/authorization/authorization-registry.js.map +1 -0
  54. package/dist/services/authorization/types.d.ts +53 -0
  55. package/dist/services/authorization/types.d.ts.map +1 -0
  56. package/dist/services/authorization/types.js +10 -0
  57. package/dist/services/authorization/types.js.map +1 -0
  58. package/dist/services/batch-delegation.service.d.ts +53 -0
  59. package/dist/services/batch-delegation.service.d.ts.map +1 -0
  60. package/dist/services/batch-delegation.service.js +95 -0
  61. package/dist/services/batch-delegation.service.js.map +1 -0
  62. package/dist/services/index.d.ts +2 -0
  63. package/dist/services/index.d.ts.map +1 -1
  64. package/dist/services/index.js +4 -1
  65. package/dist/services/index.js.map +1 -1
  66. package/dist/services/oauth-config.service.d.ts +53 -0
  67. package/dist/services/oauth-config.service.d.ts.map +1 -0
  68. package/dist/services/oauth-config.service.js +141 -0
  69. package/dist/services/oauth-config.service.js.map +1 -0
  70. package/dist/services/oauth-provider-registry.d.ts +88 -0
  71. package/dist/services/oauth-provider-registry.d.ts.map +1 -0
  72. package/dist/services/oauth-provider-registry.js +128 -0
  73. package/dist/services/oauth-provider-registry.js.map +1 -0
  74. package/dist/services/oauth-service.d.ts +77 -0
  75. package/dist/services/oauth-service.d.ts.map +1 -0
  76. package/dist/services/oauth-service.js +373 -0
  77. package/dist/services/oauth-service.js.map +1 -0
  78. package/dist/services/oauth-token-retrieval.service.d.ts +49 -0
  79. package/dist/services/oauth-token-retrieval.service.d.ts.map +1 -0
  80. package/dist/services/oauth-token-retrieval.service.js +150 -0
  81. package/dist/services/oauth-token-retrieval.service.js.map +1 -0
  82. package/dist/services/provider-resolver.d.ts +48 -0
  83. package/dist/services/provider-resolver.d.ts.map +1 -0
  84. package/dist/services/provider-resolver.js +121 -0
  85. package/dist/services/provider-resolver.js.map +1 -0
  86. package/dist/services/provider-validator.d.ts +55 -0
  87. package/dist/services/provider-validator.d.ts.map +1 -0
  88. package/dist/services/provider-validator.js +135 -0
  89. package/dist/services/provider-validator.js.map +1 -0
  90. package/dist/services/session-registration.service.d.ts +80 -0
  91. package/dist/services/session-registration.service.d.ts.map +1 -0
  92. package/dist/services/session-registration.service.js +228 -0
  93. package/dist/services/session-registration.service.js.map +1 -0
  94. package/dist/services/tool-context-builder.d.ts +57 -0
  95. package/dist/services/tool-context-builder.d.ts.map +1 -0
  96. package/dist/services/tool-context-builder.js +125 -0
  97. package/dist/services/tool-context-builder.js.map +1 -0
  98. package/dist/services/tool-protection.service.d.ts +27 -0
  99. package/dist/services/tool-protection.service.d.ts.map +1 -1
  100. package/dist/services/tool-protection.service.js +194 -4
  101. package/dist/services/tool-protection.service.js.map +1 -1
  102. package/dist/types/oauth-required-error.d.ts +40 -0
  103. package/dist/types/oauth-required-error.d.ts.map +1 -0
  104. package/dist/types/oauth-required-error.js +40 -0
  105. package/dist/types/oauth-required-error.js.map +1 -0
  106. package/dist/utils/did-helpers.d.ts +33 -0
  107. package/dist/utils/did-helpers.d.ts.map +1 -1
  108. package/dist/utils/did-helpers.js +40 -0
  109. package/dist/utils/did-helpers.js.map +1 -1
  110. package/dist/utils/index.d.ts +1 -0
  111. package/dist/utils/index.d.ts.map +1 -1
  112. package/dist/utils/index.js +1 -0
  113. package/dist/utils/index.js.map +1 -1
  114. package/docs/API_REFERENCE.md +1362 -0
  115. package/docs/COMPLIANCE_MATRIX.md +691 -0
  116. package/docs/STATUSLIST2021_GUIDE.md +696 -0
  117. package/docs/W3C_VC_DELEGATION_GUIDE.md +710 -0
  118. package/package.json +23 -54
  119. package/scripts/audit-compliance.ts +724 -0
  120. package/src/__tests__/cache/tool-protection-cache.test.ts +640 -0
  121. package/src/__tests__/config/provider-runtime-config.test.ts +309 -0
  122. package/src/__tests__/delegation-e2e.test.ts +690 -0
  123. package/src/__tests__/identity/user-did-manager.test.ts +213 -0
  124. package/src/__tests__/index.test.ts +56 -0
  125. package/src/__tests__/integration/full-flow.test.ts +776 -0
  126. package/src/__tests__/integration.test.ts +281 -0
  127. package/src/__tests__/providers/base.test.ts +173 -0
  128. package/src/__tests__/providers/memory.test.ts +319 -0
  129. package/src/__tests__/regression/phase2-regression.test.ts +429 -0
  130. package/src/__tests__/runtime/audit-logger.test.ts +154 -0
  131. package/src/__tests__/runtime/base-extensions.test.ts +593 -0
  132. package/src/__tests__/runtime/base.test.ts +869 -0
  133. package/src/__tests__/runtime/delegation-flow.test.ts +164 -0
  134. package/src/__tests__/runtime/proof-client-did.test.ts +375 -0
  135. package/src/__tests__/runtime/route-interception.test.ts +686 -0
  136. package/src/__tests__/runtime/tool-protection-enforcement.test.ts +908 -0
  137. package/src/__tests__/services/agentshield-integration.test.ts +784 -0
  138. package/src/__tests__/services/cache-busting.test.ts +125 -0
  139. package/src/__tests__/services/oauth-service-pkce.test.ts +556 -0
  140. package/src/__tests__/services/provider-resolver-edge-cases.test.ts +591 -0
  141. package/src/__tests__/services/tool-protection-oauth-provider.test.ts +480 -0
  142. package/src/__tests__/services/tool-protection.service.test.ts +1366 -0
  143. package/src/__tests__/utils/mock-providers.ts +340 -0
  144. package/src/cache/oauth-config-cache.d.ts +69 -0
  145. package/src/cache/oauth-config-cache.d.ts.map +1 -0
  146. package/src/cache/oauth-config-cache.js.map +1 -0
  147. package/src/cache/oauth-config-cache.ts +123 -0
  148. package/src/cache/tool-protection-cache.ts +171 -0
  149. package/src/compliance/EXAMPLE.md +412 -0
  150. package/src/compliance/__tests__/schema-verifier.test.ts +797 -0
  151. package/src/compliance/index.ts +8 -0
  152. package/src/compliance/schema-registry.ts +460 -0
  153. package/src/compliance/schema-verifier.ts +708 -0
  154. package/src/config/__tests__/remote-config.spec.ts +268 -0
  155. package/src/config/remote-config.ts +174 -0
  156. package/src/config.ts +309 -0
  157. package/src/delegation/__tests__/audience-validator.test.ts +112 -0
  158. package/src/delegation/__tests__/bitstring.test.ts +346 -0
  159. package/src/delegation/__tests__/cascading-revocation.test.ts +628 -0
  160. package/src/delegation/__tests__/delegation-graph.test.ts +584 -0
  161. package/src/delegation/__tests__/utils.test.ts +152 -0
  162. package/src/delegation/__tests__/vc-issuer.test.ts +442 -0
  163. package/src/delegation/__tests__/vc-verifier.test.ts +922 -0
  164. package/src/delegation/audience-validator.ts +52 -0
  165. package/src/delegation/bitstring.ts +278 -0
  166. package/src/delegation/cascading-revocation.ts +370 -0
  167. package/src/delegation/delegation-graph.ts +299 -0
  168. package/src/delegation/index.ts +14 -0
  169. package/src/delegation/statuslist-manager.ts +353 -0
  170. package/src/delegation/storage/__tests__/memory-graph-storage.test.ts +366 -0
  171. package/src/delegation/storage/__tests__/memory-statuslist-storage.test.ts +228 -0
  172. package/src/delegation/storage/index.ts +9 -0
  173. package/src/delegation/storage/memory-graph-storage.ts +178 -0
  174. package/src/delegation/storage/memory-statuslist-storage.ts +77 -0
  175. package/src/delegation/utils.ts +42 -0
  176. package/src/delegation/vc-issuer.ts +232 -0
  177. package/src/delegation/vc-verifier.ts +568 -0
  178. package/src/identity/idp-token-resolver.ts +147 -0
  179. package/src/identity/idp-token-storage.interface.ts +59 -0
  180. package/src/identity/user-did-manager.ts +370 -0
  181. package/src/index.ts +271 -0
  182. package/src/providers/base.d.ts +91 -0
  183. package/src/providers/base.d.ts.map +1 -0
  184. package/src/providers/base.js.map +1 -0
  185. package/src/providers/base.ts +96 -0
  186. package/src/providers/memory.ts +142 -0
  187. package/src/runtime/audit-logger.ts +39 -0
  188. package/src/runtime/base.ts +1329 -0
  189. package/src/services/__tests__/access-control.integration.test.ts +443 -0
  190. package/src/services/__tests__/access-control.proof-response-validation.test.ts +578 -0
  191. package/src/services/__tests__/access-control.service.test.ts +970 -0
  192. package/src/services/__tests__/batch-delegation.service.test.ts +351 -0
  193. package/src/services/__tests__/crypto.service.test.ts +531 -0
  194. package/src/services/__tests__/oauth-provider-registry.test.ts +142 -0
  195. package/src/services/__tests__/proof-verifier.integration.test.ts +485 -0
  196. package/src/services/__tests__/proof-verifier.test.ts +489 -0
  197. package/src/services/__tests__/provider-resolution.integration.test.ts +202 -0
  198. package/src/services/__tests__/provider-resolver.test.ts +213 -0
  199. package/src/services/__tests__/storage.service.test.ts +358 -0
  200. package/src/services/access-control.service.ts +990 -0
  201. package/src/services/authorization/authorization-registry.ts +66 -0
  202. package/src/services/authorization/types.ts +71 -0
  203. package/src/services/batch-delegation.service.ts +137 -0
  204. package/src/services/crypto.service.ts +302 -0
  205. package/src/services/errors.ts +76 -0
  206. package/src/services/index.ts +18 -0
  207. package/src/services/oauth-config.service.d.ts +53 -0
  208. package/src/services/oauth-config.service.d.ts.map +1 -0
  209. package/src/services/oauth-config.service.js.map +1 -0
  210. package/src/services/oauth-config.service.ts +192 -0
  211. package/src/services/oauth-provider-registry.d.ts +57 -0
  212. package/src/services/oauth-provider-registry.d.ts.map +1 -0
  213. package/src/services/oauth-provider-registry.js.map +1 -0
  214. package/src/services/oauth-provider-registry.ts +141 -0
  215. package/src/services/oauth-service.ts +544 -0
  216. package/src/services/oauth-token-retrieval.service.ts +245 -0
  217. package/src/services/proof-verifier.ts +478 -0
  218. package/src/services/provider-resolver.d.ts +48 -0
  219. package/src/services/provider-resolver.d.ts.map +1 -0
  220. package/src/services/provider-resolver.js.map +1 -0
  221. package/src/services/provider-resolver.ts +146 -0
  222. package/src/services/provider-validator.ts +170 -0
  223. package/src/services/session-registration.service.ts +317 -0
  224. package/src/services/storage.service.ts +566 -0
  225. package/src/services/tool-context-builder.ts +172 -0
  226. package/src/services/tool-protection.service.ts +982 -0
  227. package/src/types/oauth-required-error.ts +63 -0
  228. package/src/types/tool-protection.ts +155 -0
  229. package/src/utils/__tests__/did-helpers.test.ts +101 -0
  230. package/src/utils/base64.ts +148 -0
  231. package/src/utils/cors.ts +83 -0
  232. package/src/utils/did-helpers.ts +150 -0
  233. package/src/utils/index.ts +8 -0
  234. package/src/utils/storage-keys.ts +278 -0
  235. package/tsconfig.json +21 -0
  236. package/vitest.config.ts +56 -0
@@ -0,0 +1,1362 @@
1
+ # API Reference
2
+
3
+ Complete API reference for `@kya-os/mcp-i-core` package.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Installation](#installation)
8
+ - [Core Classes](#core-classes)
9
+ - [DelegationIssuer](#delegationissuer)
10
+ - [DelegationVerifier](#delegationverifier)
11
+ - [DelegationGraph](#delegationgraph)
12
+ - [StatusList2021](#statuslist2021)
13
+ - [StatusList2021Manager](#statuslist2021manager)
14
+ - [StatusList2021Storage](#statuslist2021storage)
15
+ - [Schema Verification](#schema-verification)
16
+ - [SchemaVerifier](#schemaverifier)
17
+ - [SchemaRegistry](#schemaregistry)
18
+ - [Types](#types)
19
+ - [Utilities](#utilities)
20
+
21
+ ## Installation
22
+
23
+ ```bash
24
+ npm install @kya-os/mcp-i-core
25
+ # or
26
+ pnpm add @kya-os/mcp-i-core
27
+ # or
28
+ yarn add @kya-os/mcp-i-core
29
+ ```
30
+
31
+ ## Core Classes
32
+
33
+ ### DelegationIssuer
34
+
35
+ Issues W3C Verifiable Credentials for delegation.
36
+
37
+ #### Constructor
38
+
39
+ ```typescript
40
+ new DelegationIssuer(options: DelegationIssuerOptions)
41
+ ```
42
+
43
+ **Parameters:**
44
+
45
+ | Name | Type | Description |
46
+ |------|------|-------------|
47
+ | `options.issuerDid` | `string` | DID of the issuing agent |
48
+ | `options.privateKeyJwk` | `JsonWebKey` | Private key in JWK format |
49
+ | `options.statusListManager?` | `StatusList2021Manager` | Optional status list manager for revocation |
50
+
51
+ **Example:**
52
+
53
+ ```typescript
54
+ import { DelegationIssuer } from '@kya-os/mcp-i-core';
55
+
56
+ const issuer = new DelegationIssuer({
57
+ issuerDid: 'did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK',
58
+ privateKeyJwk: {
59
+ kty: 'OKP',
60
+ crv: 'Ed25519',
61
+ d: 'base64-encoded-private-key',
62
+ x: 'base64-encoded-public-key',
63
+ },
64
+ });
65
+ ```
66
+
67
+ #### Methods
68
+
69
+ ##### `issue()`
70
+
71
+ Issue a delegation credential.
72
+
73
+ ```typescript
74
+ async issue(options: DelegationIssuanceOptions): Promise<DelegationCredential>
75
+ ```
76
+
77
+ **Parameters:**
78
+
79
+ | Name | Type | Description |
80
+ |------|------|-------------|
81
+ | `options.subjectDid` | `string` | DID of the delegate (recipient) |
82
+ | `options.constraints` | `DelegationConstraints` | CRISP constraints for the delegation |
83
+ | `options.audience?` | `string` | Target audience URL |
84
+ | `options.expirationDate?` | `string` | ISO 8601 expiration date |
85
+ | `options.credentialStatus?` | `CredentialStatus` | StatusList2021 entry |
86
+ | `options.parentDelegation?` | `string` | Parent delegation ID for chains |
87
+
88
+ **Returns:** `Promise<DelegationCredential>` - The issued delegation credential
89
+
90
+ **Example:**
91
+
92
+ ```typescript
93
+ const delegation = await issuer.issue({
94
+ subjectDid: 'did:key:z6MkrWXJPkxPCuQF7RqeKZFdZqBXz3oCG7PUty5dXLKGzELj',
95
+ constraints: {
96
+ budget: {
97
+ maxCost: 100,
98
+ currency: 'USD',
99
+ },
100
+ scope: {
101
+ allowedTools: ['read_file', 'write_file'],
102
+ allowedResources: ['/documents/*'],
103
+ },
104
+ time: {
105
+ notBefore: new Date().toISOString(),
106
+ notAfter: new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString(),
107
+ },
108
+ },
109
+ audience: 'https://api.example.com',
110
+ });
111
+
112
+ console.log('Delegation ID:', delegation.id);
113
+ ```
114
+
115
+ ##### `issueWithStatus()`
116
+
117
+ Issue a delegation with automatic status list integration.
118
+
119
+ ```typescript
120
+ async issueWithStatus(options: DelegationIssuanceOptions): Promise<DelegationCredential>
121
+ ```
122
+
123
+ **Parameters:** Same as `issue()` but `credentialStatus` is automatically generated.
124
+
125
+ **Returns:** `Promise<DelegationCredential>` - The issued delegation credential with status
126
+
127
+ **Example:**
128
+
129
+ ```typescript
130
+ const delegation = await issuer.issueWithStatus({
131
+ subjectDid: 'did:key:z6MkrWXJPkxPCuQF7RqeKZFdZqBXz3oCG7PUty5dXLKGzELj',
132
+ constraints: {
133
+ scope: {
134
+ allowedTools: ['read_file'],
135
+ },
136
+ },
137
+ });
138
+
139
+ // Automatically includes credentialStatus field
140
+ console.log('Status index:', delegation.credentialStatus?.statusListIndex);
141
+ ```
142
+
143
+ ---
144
+
145
+ ### DelegationVerifier
146
+
147
+ Verifies delegation credentials.
148
+
149
+ #### Constructor
150
+
151
+ ```typescript
152
+ new DelegationVerifier(options?: DelegationVerifierOptions)
153
+ ```
154
+
155
+ **Parameters:**
156
+
157
+ | Name | Type | Description |
158
+ |------|------|-------------|
159
+ | `options.didResolver?` | `DIDResolver` | Custom DID resolver |
160
+ | `options.statusListFetcher?` | `StatusListFetcher` | Custom status list fetcher |
161
+ | `options.checkStatus?` | `boolean` | Enable status checking (default: true) |
162
+ | `options.checkExpiration?` | `boolean` | Enable expiration checking (default: true) |
163
+
164
+ **Example:**
165
+
166
+ ```typescript
167
+ import { DelegationVerifier } from '@kya-os/mcp-i-core';
168
+
169
+ const verifier = new DelegationVerifier({
170
+ checkStatus: true,
171
+ checkExpiration: true,
172
+ });
173
+ ```
174
+
175
+ #### Methods
176
+
177
+ ##### `verify()`
178
+
179
+ Verify a delegation credential.
180
+
181
+ ```typescript
182
+ async verify(options: DelegationVerificationOptions): Promise<DelegationVerificationResult>
183
+ ```
184
+
185
+ **Parameters:**
186
+
187
+ | Name | Type | Description |
188
+ |------|------|-------------|
189
+ | `options.credential` | `DelegationCredential` | The delegation to verify |
190
+ | `options.expectedAudience?` | `string` | Expected audience (must match) |
191
+ | `options.expectedSubject?` | `string` | Expected subject DID (must match) |
192
+ | `options.checkChain?` | `boolean` | Verify entire delegation chain |
193
+ | `options.now?` | `Date` | Current time for expiration checks |
194
+
195
+ **Returns:** `Promise<DelegationVerificationResult>` - Verification result
196
+
197
+ **Example:**
198
+
199
+ ```typescript
200
+ const result = await verifier.verify({
201
+ credential: delegation,
202
+ expectedAudience: 'https://api.example.com',
203
+ checkChain: true,
204
+ });
205
+
206
+ if (result.verified) {
207
+ console.log('✅ Delegation is valid');
208
+ console.log('Subject:', result.subject);
209
+ console.log('Issuer:', result.issuer);
210
+ console.log('Constraints:', result.constraints);
211
+ } else {
212
+ console.error('❌ Verification failed:', result.error);
213
+ if (result.statusRevoked) {
214
+ console.error(' Reason: Credential revoked');
215
+ }
216
+ if (result.expired) {
217
+ console.error(' Reason: Credential expired');
218
+ }
219
+ }
220
+ ```
221
+
222
+ ##### `verifyChain()`
223
+
224
+ Verify a complete delegation chain.
225
+
226
+ ```typescript
227
+ async verifyChain(delegation: DelegationCredential): Promise<ChainVerificationResult>
228
+ ```
229
+
230
+ **Parameters:**
231
+
232
+ | Name | Type | Description |
233
+ |------|------|-------------|
234
+ | `delegation` | `DelegationCredential` | The delegation at the end of the chain |
235
+
236
+ **Returns:** `Promise<ChainVerificationResult>` - Chain verification result
237
+
238
+ **Example:**
239
+
240
+ ```typescript
241
+ // Verify multi-level delegation chain
242
+ const result = await verifier.verifyChain(leafDelegation);
243
+
244
+ if (result.valid) {
245
+ console.log('✅ Chain is valid');
246
+ console.log('Chain length:', result.chain.length);
247
+ console.log('Root issuer:', result.rootIssuer);
248
+
249
+ // Print chain
250
+ for (const [i, delegation] of result.chain.entries()) {
251
+ console.log(` Level ${i}: ${delegation.issuer} → ${delegation.credentialSubject.id}`);
252
+ }
253
+ } else {
254
+ console.error('❌ Chain verification failed');
255
+ console.error(' Invalid at level:', result.invalidAtLevel);
256
+ console.error(' Reason:', result.error);
257
+ }
258
+ ```
259
+
260
+ ---
261
+
262
+ ### DelegationGraph
263
+
264
+ Manages delegation relationships and cascading revocation.
265
+
266
+ #### Constructor
267
+
268
+ ```typescript
269
+ new DelegationGraph(options?: DelegationGraphOptions)
270
+ ```
271
+
272
+ **Parameters:**
273
+
274
+ | Name | Type | Description |
275
+ |------|------|-------------|
276
+ | `options.storage?` | `GraphStorage` | Custom graph storage backend |
277
+
278
+ **Example:**
279
+
280
+ ```typescript
281
+ import { DelegationGraph } from '@kya-os/mcp-i-core';
282
+
283
+ const graph = new DelegationGraph();
284
+ ```
285
+
286
+ #### Methods
287
+
288
+ ##### `addDelegation()`
289
+
290
+ Add a delegation to the graph.
291
+
292
+ ```typescript
293
+ async addDelegation(delegation: DelegationCredential): Promise<void>
294
+ ```
295
+
296
+ **Parameters:**
297
+
298
+ | Name | Type | Description |
299
+ |------|------|-------------|
300
+ | `delegation` | `DelegationCredential` | The delegation to add |
301
+
302
+ **Example:**
303
+
304
+ ```typescript
305
+ // Build delegation graph
306
+ await graph.addDelegation(parentDelegation);
307
+ await graph.addDelegation(childDelegation1);
308
+ await graph.addDelegation(childDelegation2);
309
+
310
+ console.log('Graph size:', await graph.size());
311
+ ```
312
+
313
+ ##### `getChildren()`
314
+
315
+ Get all direct children of a delegation.
316
+
317
+ ```typescript
318
+ async getChildren(delegationId: string): Promise<DelegationCredential[]>
319
+ ```
320
+
321
+ **Parameters:**
322
+
323
+ | Name | Type | Description |
324
+ |------|------|-------------|
325
+ | `delegationId` | `string` | ID of the parent delegation |
326
+
327
+ **Returns:** `Promise<DelegationCredential[]>` - Array of child delegations
328
+
329
+ **Example:**
330
+
331
+ ```typescript
332
+ const children = await graph.getChildren(parentDelegation.id);
333
+ console.log(`Found ${children.length} children`);
334
+
335
+ for (const child of children) {
336
+ console.log(` - ${child.id} (issued to ${child.credentialSubject.id})`);
337
+ }
338
+ ```
339
+
340
+ ##### `getDescendants()`
341
+
342
+ Get all descendants (recursive) of a delegation.
343
+
344
+ ```typescript
345
+ async getDescendants(delegationId: string): Promise<DelegationCredential[]>
346
+ ```
347
+
348
+ **Parameters:**
349
+
350
+ | Name | Type | Description |
351
+ |------|------|-------------|
352
+ | `delegationId` | `string` | ID of the ancestor delegation |
353
+
354
+ **Returns:** `Promise<DelegationCredential[]>` - Array of all descendants
355
+
356
+ **Example:**
357
+
358
+ ```typescript
359
+ // Get entire subtree
360
+ const descendants = await graph.getDescendants(rootDelegation.id);
361
+ console.log(`Total descendants: ${descendants.length}`);
362
+ ```
363
+
364
+ ##### `revokeDelegation()`
365
+
366
+ Revoke a delegation and optionally all descendants.
367
+
368
+ ```typescript
369
+ async revokeDelegation(
370
+ delegationId: string,
371
+ statusListManager: StatusList2021Manager,
372
+ options?: RevocationOptions
373
+ ): Promise<RevocationResult>
374
+ ```
375
+
376
+ **Parameters:**
377
+
378
+ | Name | Type | Description |
379
+ |------|------|-------------|
380
+ | `delegationId` | `string` | ID of delegation to revoke |
381
+ | `statusListManager` | `StatusList2021Manager` | Status list manager |
382
+ | `options.cascade?` | `boolean` | Revoke all descendants (default: true) |
383
+
384
+ **Returns:** `Promise<RevocationResult>` - Revocation result with list of revoked IDs
385
+
386
+ **Example:**
387
+
388
+ ```typescript
389
+ // Revoke parent and all children
390
+ const result = await graph.revokeDelegation(
391
+ parentDelegation.id,
392
+ statusListManager,
393
+ { cascade: true }
394
+ );
395
+
396
+ console.log('Revoked delegations:', result.revokedIds.length);
397
+ for (const id of result.revokedIds) {
398
+ console.log(` - ${id}`);
399
+ }
400
+ ```
401
+
402
+ ##### `getPath()`
403
+
404
+ Get the path from root to a delegation.
405
+
406
+ ```typescript
407
+ async getPath(delegationId: string): Promise<DelegationCredential[]>
408
+ ```
409
+
410
+ **Parameters:**
411
+
412
+ | Name | Type | Description |
413
+ |------|------|-------------|
414
+ | `delegationId` | `string` | ID of target delegation |
415
+
416
+ **Returns:** `Promise<DelegationCredential[]>` - Array of delegations from root to target
417
+
418
+ **Example:**
419
+
420
+ ```typescript
421
+ const path = await graph.getPath(leafDelegation.id);
422
+
423
+ console.log('Delegation chain:');
424
+ for (const [i, delegation] of path.entries()) {
425
+ console.log(` ${i + 1}. ${delegation.issuer} → ${delegation.credentialSubject.id}`);
426
+ }
427
+ ```
428
+
429
+ ---
430
+
431
+ ## StatusList2021
432
+
433
+ ### StatusList2021Manager
434
+
435
+ Manages StatusList2021 credentials for revocation.
436
+
437
+ #### Constructor
438
+
439
+ ```typescript
440
+ new StatusList2021Manager(options: StatusList2021ManagerOptions)
441
+ ```
442
+
443
+ **Parameters:**
444
+
445
+ | Name | Type | Description |
446
+ |------|------|-------------|
447
+ | `options.issuerDid` | `string` | DID of the status list issuer |
448
+ | `options.statusListUrl` | `string` | Public URL where status list will be hosted |
449
+ | `options.storage` | `StatusList2021Storage` | Storage backend for bitstrings |
450
+ | `options.privateKeyJwk?` | `JsonWebKey` | Private key for signing status lists |
451
+
452
+ **Example:**
453
+
454
+ ```typescript
455
+ import { StatusList2021Manager, InMemoryStatusListStorage } from '@kya-os/mcp-i-core';
456
+
457
+ const manager = new StatusList2021Manager({
458
+ issuerDid: 'did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK',
459
+ statusListUrl: 'https://issuer.example.com/status/1',
460
+ storage: new InMemoryStatusListStorage(),
461
+ privateKeyJwk: issuerPrivateKey,
462
+ });
463
+ ```
464
+
465
+ #### Methods
466
+
467
+ ##### `createStatusList()`
468
+
469
+ Create a new status list credential.
470
+
471
+ ```typescript
472
+ async createStatusList(options: CreateStatusListOptions): Promise<StatusListCredential>
473
+ ```
474
+
475
+ **Parameters:**
476
+
477
+ | Name | Type | Description |
478
+ |------|------|-------------|
479
+ | `options.id` | `string` | Status list credential ID (URL) |
480
+ | `options.purpose` | `'revocation' \| 'suspension'` | Purpose of the status list |
481
+ | `options.length?` | `number` | Initial bitstring length (default: 131072) |
482
+
483
+ **Returns:** `Promise<StatusListCredential>` - The status list credential
484
+
485
+ **Example:**
486
+
487
+ ```typescript
488
+ const statusListVC = await manager.createStatusList({
489
+ id: 'https://issuer.example.com/status/1',
490
+ purpose: 'revocation',
491
+ });
492
+
493
+ console.log('Status list created:', statusListVC.id);
494
+ ```
495
+
496
+ ##### `allocateIndex()`
497
+
498
+ Allocate the next available index in the status list.
499
+
500
+ ```typescript
501
+ async allocateIndex(): Promise<number>
502
+ ```
503
+
504
+ **Returns:** `Promise<number>` - The allocated index
505
+
506
+ **Example:**
507
+
508
+ ```typescript
509
+ const index = await manager.allocateIndex();
510
+ console.log('Allocated index:', index);
511
+
512
+ // Use in credential
513
+ const credentialStatus = {
514
+ id: `${statusListUrl}#${index}`,
515
+ type: 'StatusList2021Entry',
516
+ statusPurpose: 'revocation',
517
+ statusListIndex: index.toString(),
518
+ statusListCredential: statusListUrl,
519
+ };
520
+ ```
521
+
522
+ ##### `revokeCredential()`
523
+
524
+ Revoke a credential by setting its status list bit to 1.
525
+
526
+ ```typescript
527
+ async revokeCredential(index: number): Promise<void>
528
+ ```
529
+
530
+ **Parameters:**
531
+
532
+ | Name | Type | Description |
533
+ |------|------|-------------|
534
+ | `index` | `number` | Status list index to revoke |
535
+
536
+ **Example:**
537
+
538
+ ```typescript
539
+ await manager.revokeCredential(42);
540
+ console.log('Credential at index 42 revoked');
541
+ ```
542
+
543
+ ##### `unrevokeCredential()`
544
+
545
+ Unrevoke a credential by setting its status list bit to 0.
546
+
547
+ ```typescript
548
+ async unrevokeCredential(index: number): Promise<void>
549
+ ```
550
+
551
+ **Parameters:**
552
+
553
+ | Name | Type | Description |
554
+ |------|------|-------------|
555
+ | `index` | `number` | Status list index to unrevoke |
556
+
557
+ **Example:**
558
+
559
+ ```typescript
560
+ await manager.unrevokeCredential(42);
561
+ console.log('Credential at index 42 restored');
562
+ ```
563
+
564
+ ##### `batchRevoke()`
565
+
566
+ Revoke multiple credentials atomically.
567
+
568
+ ```typescript
569
+ async batchRevoke(indexes: number[]): Promise<void>
570
+ ```
571
+
572
+ **Parameters:**
573
+
574
+ | Name | Type | Description |
575
+ |------|------|-------------|
576
+ | `indexes` | `number[]` | Array of indexes to revoke |
577
+
578
+ **Example:**
579
+
580
+ ```typescript
581
+ await manager.batchRevoke([42, 100, 250, 1337]);
582
+ console.log('4 credentials revoked');
583
+ ```
584
+
585
+ ##### `checkStatus()`
586
+
587
+ Check if a credential is revoked.
588
+
589
+ ```typescript
590
+ async checkStatus(index: number): Promise<boolean>
591
+ ```
592
+
593
+ **Parameters:**
594
+
595
+ | Name | Type | Description |
596
+ |------|------|-------------|
597
+ | `index` | `number` | Status list index to check |
598
+
599
+ **Returns:** `Promise<boolean>` - `true` if revoked, `false` if valid
600
+
601
+ **Example:**
602
+
603
+ ```typescript
604
+ const isRevoked = await manager.checkStatus(42);
605
+ if (isRevoked) {
606
+ console.log('Credential is revoked');
607
+ } else {
608
+ console.log('Credential is valid');
609
+ }
610
+ ```
611
+
612
+ ##### `getStatusList()`
613
+
614
+ Get the current status list credential.
615
+
616
+ ```typescript
617
+ async getStatusList(url: string): Promise<StatusListCredential>
618
+ ```
619
+
620
+ **Parameters:**
621
+
622
+ | Name | Type | Description |
623
+ |------|------|-------------|
624
+ | `url` | `string` | Status list URL |
625
+
626
+ **Returns:** `Promise<StatusListCredential>` - The status list credential
627
+
628
+ **Example:**
629
+
630
+ ```typescript
631
+ const statusListVC = await manager.getStatusList(
632
+ 'https://issuer.example.com/status/1'
633
+ );
634
+
635
+ console.log('Encoded bitstring:', statusListVC.credentialSubject.encodedList);
636
+ ```
637
+
638
+ ##### `getMetrics()`
639
+
640
+ Get status list metrics.
641
+
642
+ ```typescript
643
+ async getMetrics(): Promise<StatusListMetrics>
644
+ ```
645
+
646
+ **Returns:** `Promise<StatusListMetrics>` - Status list metrics
647
+
648
+ **Example:**
649
+
650
+ ```typescript
651
+ const metrics = await manager.getMetrics();
652
+
653
+ console.log('Metrics:', {
654
+ allocatedIndexes: metrics.allocatedIndexes,
655
+ revokedCount: metrics.revokedCount,
656
+ revocationRate: (metrics.revokedCount / metrics.allocatedIndexes * 100).toFixed(2) + '%',
657
+ compressedSize: (metrics.compressedSize / 1024).toFixed(2) + 'KB',
658
+ compressionRatio: (metrics.uncompressedSize / metrics.compressedSize).toFixed(2) + 'x',
659
+ });
660
+ ```
661
+
662
+ ---
663
+
664
+ ### StatusList2021Storage
665
+
666
+ Storage interface for status list bitstrings.
667
+
668
+ #### Interface
669
+
670
+ ```typescript
671
+ interface StatusList2021Storage {
672
+ getBitstring(statusListId: string): Promise<Uint8Array | null>;
673
+ setBitstring(statusListId: string, bitstring: Uint8Array): Promise<void>;
674
+ deleteBitstring(statusListId: string): Promise<void>;
675
+ }
676
+ ```
677
+
678
+ #### Implementations
679
+
680
+ ##### InMemoryStatusListStorage
681
+
682
+ In-memory storage (for development/testing).
683
+
684
+ ```typescript
685
+ import { InMemoryStatusListStorage } from '@kya-os/mcp-i-core';
686
+
687
+ const storage = new InMemoryStatusListStorage();
688
+ ```
689
+
690
+ ##### RedisStatusListStorage
691
+
692
+ Redis-backed storage (for production).
693
+
694
+ ```typescript
695
+ import { RedisStatusListStorage } from '@kya-os/mcp-i-core';
696
+ import Redis from 'ioredis';
697
+
698
+ const redis = new Redis(process.env.REDIS_URL);
699
+ const storage = new RedisStatusListStorage({
700
+ client: redis,
701
+ keyPrefix: 'statuslist:',
702
+ ttl: 86400, // 24 hours
703
+ });
704
+ ```
705
+
706
+ ##### DynamoDBStatusListStorage
707
+
708
+ AWS DynamoDB storage (for production).
709
+
710
+ ```typescript
711
+ import { DynamoDBStatusListStorage } from '@kya-os/mcp-i-core';
712
+ import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
713
+
714
+ const dynamodb = new DynamoDBClient({ region: 'us-east-1' });
715
+ const storage = new DynamoDBStatusListStorage({
716
+ client: dynamodb,
717
+ tableName: 'StatusLists',
718
+ ttl: 86400,
719
+ });
720
+ ```
721
+
722
+ ---
723
+
724
+ ## Schema Verification
725
+
726
+ ### SchemaVerifier
727
+
728
+ Verifies implementations against JSON Schema draft-07 schemas.
729
+
730
+ #### Constructor
731
+
732
+ ```typescript
733
+ new SchemaVerifier(options?: SchemaVerifierOptions)
734
+ ```
735
+
736
+ **Parameters:**
737
+
738
+ | Name | Type | Description |
739
+ |------|------|-------------|
740
+ | `options.schemaRegistry?` | `SchemaRegistry` | Custom schema registry |
741
+ | `options.strictMode?` | `boolean` | Enable strict validation (default: true) |
742
+
743
+ **Example:**
744
+
745
+ ```typescript
746
+ import { SchemaVerifier } from '@kya-os/mcp-i-core';
747
+
748
+ const verifier = new SchemaVerifier({
749
+ strictMode: true,
750
+ });
751
+ ```
752
+
753
+ #### Methods
754
+
755
+ ##### `registerSchema()`
756
+
757
+ Register a schema for validation.
758
+
759
+ ```typescript
760
+ async registerSchema(name: string, schemaUrl: string): Promise<void>
761
+ ```
762
+
763
+ **Parameters:**
764
+
765
+ | Name | Type | Description |
766
+ |------|------|-------------|
767
+ | `name` | `string` | Schema identifier |
768
+ | `schemaUrl` | `string` | URL to JSON Schema |
769
+
770
+ **Example:**
771
+
772
+ ```typescript
773
+ await verifier.registerSchema(
774
+ 'delegation-credential',
775
+ 'https://schemas.kya-os.ai/delegation-credential.schema.json'
776
+ );
777
+ ```
778
+
779
+ ##### `verifySchema()`
780
+
781
+ Verify an implementation against a registered schema.
782
+
783
+ ```typescript
784
+ async verifySchema(schemaName: string, implementation: any): Promise<SchemaComplianceReport>
785
+ ```
786
+
787
+ **Parameters:**
788
+
789
+ | Name | Type | Description |
790
+ |------|------|-------------|
791
+ | `schemaName` | `string` | Registered schema name |
792
+ | `implementation` | `any` | Implementation to verify |
793
+
794
+ **Returns:** `Promise<SchemaComplianceReport>` - Compliance report
795
+
796
+ **Example:**
797
+
798
+ ```typescript
799
+ const report = await verifier.verifySchema('delegation-credential', myDelegation);
800
+
801
+ if (report.compliant) {
802
+ console.log('✅ 100% compliant');
803
+ } else {
804
+ console.log(`❌ ${report.compliancePercentage}% compliant`);
805
+
806
+ // Show issues
807
+ console.log('Missing fields:', report.missingFields);
808
+
809
+ for (const [field, result] of Object.entries(report.fieldCompliance)) {
810
+ if (result.typeMatch === 'mismatch') {
811
+ console.log(`Field '${field}':`);
812
+ console.log(` Expected: ${result.expectedType}`);
813
+ console.log(` Actual: ${result.actualType}`);
814
+ }
815
+ }
816
+ }
817
+ ```
818
+
819
+ ##### `verifyAll()`
820
+
821
+ Verify implementation against multiple schemas.
822
+
823
+ ```typescript
824
+ async verifyAll(
825
+ schemas: string[],
826
+ implementation: any
827
+ ): Promise<FullComplianceReport>
828
+ ```
829
+
830
+ **Parameters:**
831
+
832
+ | Name | Type | Description |
833
+ |------|------|-------------|
834
+ | `schemas` | `string[]` | Array of schema names |
835
+ | `implementation` | `any` | Implementation to verify |
836
+
837
+ **Returns:** `Promise<FullComplianceReport>` - Compliance report for all schemas
838
+
839
+ **Example:**
840
+
841
+ ```typescript
842
+ const report = await verifier.verifyAll(
843
+ ['delegation-credential', 'delegation-constraints'],
844
+ myDelegation
845
+ );
846
+
847
+ console.log(`Overall compliance: ${report.overallCompliance}%`);
848
+
849
+ for (const [schema, result] of Object.entries(report.schemaResults)) {
850
+ console.log(`${schema}: ${result.compliancePercentage}%`);
851
+ }
852
+ ```
853
+
854
+ ---
855
+
856
+ ### SchemaRegistry
857
+
858
+ Registry for managing schemas.
859
+
860
+ #### Constructor
861
+
862
+ ```typescript
863
+ new SchemaRegistry(options?: SchemaRegistryOptions)
864
+ ```
865
+
866
+ **Example:**
867
+
868
+ ```typescript
869
+ import { SchemaRegistry } from '@kya-os/mcp-i-core';
870
+
871
+ const registry = new SchemaRegistry();
872
+ ```
873
+
874
+ #### Methods
875
+
876
+ ##### `register()`
877
+
878
+ Register a schema.
879
+
880
+ ```typescript
881
+ async register(name: string, schema: any): Promise<void>
882
+ ```
883
+
884
+ ##### `get()`
885
+
886
+ Get a registered schema.
887
+
888
+ ```typescript
889
+ async get(name: string): Promise<any>
890
+ ```
891
+
892
+ ##### `has()`
893
+
894
+ Check if schema is registered.
895
+
896
+ ```typescript
897
+ async has(name: string): Promise<boolean>
898
+ ```
899
+
900
+ ##### `list()`
901
+
902
+ List all registered schemas.
903
+
904
+ ```typescript
905
+ async list(): Promise<string[]>
906
+ ```
907
+
908
+ ---
909
+
910
+ ## Types
911
+
912
+ ### DelegationCredential
913
+
914
+ W3C Verifiable Credential for delegation.
915
+
916
+ ```typescript
917
+ interface DelegationCredential {
918
+ '@context': string[];
919
+ id: string;
920
+ type: string[];
921
+ issuer: string;
922
+ issuanceDate: string;
923
+ expirationDate?: string;
924
+ credentialSubject: {
925
+ id: string;
926
+ constraints: DelegationConstraints;
927
+ };
928
+ credentialStatus?: CredentialStatus;
929
+ proof: Ed25519Proof;
930
+ }
931
+ ```
932
+
933
+ ### DelegationConstraints
934
+
935
+ CRISP constraints for delegation.
936
+
937
+ ```typescript
938
+ interface DelegationConstraints {
939
+ // Cost constraints
940
+ budget?: {
941
+ maxCost: number;
942
+ currency: string;
943
+ };
944
+
945
+ // Resource constraints
946
+ resources?: {
947
+ maxRequests?: number;
948
+ maxTokens?: number;
949
+ maxStorage?: number;
950
+ };
951
+
952
+ // Identity constraints
953
+ identity?: {
954
+ requiredDid?: string;
955
+ allowedIssuers?: string[];
956
+ };
957
+
958
+ // Scope constraints
959
+ scope?: {
960
+ allowedTools?: string[];
961
+ allowedResources?: string[];
962
+ deniedTools?: string[];
963
+ deniedResources?: string[];
964
+ };
965
+
966
+ // Purpose constraints
967
+ purpose?: {
968
+ description: string;
969
+ category?: string;
970
+ };
971
+
972
+ // Time constraints
973
+ time?: {
974
+ notBefore?: string;
975
+ notAfter?: string;
976
+ maxDuration?: number;
977
+ };
978
+ }
979
+ ```
980
+
981
+ ### DelegationVerificationResult
982
+
983
+ Result of delegation verification.
984
+
985
+ ```typescript
986
+ interface DelegationVerificationResult {
987
+ verified: boolean;
988
+ error?: string;
989
+ subject?: string;
990
+ issuer?: string;
991
+ constraints?: DelegationConstraints;
992
+ statusRevoked?: boolean;
993
+ expired?: boolean;
994
+ signatureValid?: boolean;
995
+ }
996
+ ```
997
+
998
+ ### CredentialStatus
999
+
1000
+ StatusList2021 credential status.
1001
+
1002
+ ```typescript
1003
+ interface CredentialStatus {
1004
+ id: string;
1005
+ type: 'StatusList2021Entry';
1006
+ statusPurpose: 'revocation' | 'suspension';
1007
+ statusListIndex: string;
1008
+ statusListCredential: string;
1009
+ }
1010
+ ```
1011
+
1012
+ ### StatusListCredential
1013
+
1014
+ StatusList2021 credential.
1015
+
1016
+ ```typescript
1017
+ interface StatusListCredential {
1018
+ '@context': string[];
1019
+ id: string;
1020
+ type: string[];
1021
+ issuer: string;
1022
+ issuanceDate: string;
1023
+ credentialSubject: {
1024
+ id: string;
1025
+ type: 'StatusList2021';
1026
+ statusPurpose: 'revocation' | 'suspension';
1027
+ encodedList: string;
1028
+ };
1029
+ proof: Ed25519Proof;
1030
+ }
1031
+ ```
1032
+
1033
+ ### SchemaComplianceReport
1034
+
1035
+ Schema compliance verification report.
1036
+
1037
+ ```typescript
1038
+ interface SchemaComplianceReport {
1039
+ schemaName: string;
1040
+ schemaUrl: string;
1041
+ compliant: boolean;
1042
+ compliancePercentage: number;
1043
+ totalFields: number;
1044
+ compliantFields: number;
1045
+ fieldCompliance: Record<string, FieldComplianceResult>;
1046
+ missingFields: string[];
1047
+ extraFields: string[];
1048
+ typeMismatches: Record<string, { expected: string; actual: string }>;
1049
+ }
1050
+ ```
1051
+
1052
+ ### FieldComplianceResult
1053
+
1054
+ Field-level compliance result.
1055
+
1056
+ ```typescript
1057
+ interface FieldComplianceResult {
1058
+ present: boolean;
1059
+ expectedType: string;
1060
+ actualType: string | null;
1061
+ typeMatch: 'match' | 'mismatch' | 'absent';
1062
+ valueMatch: 'match' | 'mismatch' | 'absent';
1063
+ }
1064
+ ```
1065
+
1066
+ ---
1067
+
1068
+ ## Utilities
1069
+
1070
+ ### `createSchemaVerifier()`
1071
+
1072
+ Factory function to create a SchemaVerifier with default settings.
1073
+
1074
+ ```typescript
1075
+ function createSchemaVerifier(options?: SchemaVerifierOptions): SchemaVerifier
1076
+ ```
1077
+
1078
+ **Example:**
1079
+
1080
+ ```typescript
1081
+ import { createSchemaVerifier } from '@kya-os/mcp-i-core';
1082
+
1083
+ const verifier = createSchemaVerifier();
1084
+ await verifier.registerSchema('my-schema', 'https://example.com/schema.json');
1085
+ ```
1086
+
1087
+ ### `verifyDelegation()`
1088
+
1089
+ Helper function to verify a delegation credential.
1090
+
1091
+ ```typescript
1092
+ async function verifyDelegation(
1093
+ options: DelegationVerificationOptions
1094
+ ): Promise<DelegationVerificationResult>
1095
+ ```
1096
+
1097
+ **Example:**
1098
+
1099
+ ```typescript
1100
+ import { verifyDelegation } from '@kya-os/mcp-i-core';
1101
+
1102
+ const result = await verifyDelegation({
1103
+ credential: delegation,
1104
+ expectedAudience: 'https://api.example.com',
1105
+ checkStatus: true,
1106
+ });
1107
+
1108
+ if (result.verified) {
1109
+ console.log('✅ Valid delegation');
1110
+ }
1111
+ ```
1112
+
1113
+ ### `parseDID()`
1114
+
1115
+ Parse a DID string into components.
1116
+
1117
+ ```typescript
1118
+ function parseDID(did: string): ParsedDID
1119
+ ```
1120
+
1121
+ **Example:**
1122
+
1123
+ ```typescript
1124
+ import { parseDID } from '@kya-os/mcp-i-core';
1125
+
1126
+ const parsed = parseDID('did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK');
1127
+
1128
+ console.log({
1129
+ method: parsed.method, // 'key'
1130
+ id: parsed.id, // 'z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK'
1131
+ full: parsed.full, // full DID string
1132
+ });
1133
+ ```
1134
+
1135
+ ### `canonicalHash()`
1136
+
1137
+ Create a canonical hash of data.
1138
+
1139
+ ```typescript
1140
+ async function canonicalHash(
1141
+ data: any,
1142
+ algorithm: 'sha256' | 'sha512'
1143
+ ): Promise<string>
1144
+ ```
1145
+
1146
+ **Example:**
1147
+
1148
+ ```typescript
1149
+ import { canonicalHash } from '@kya-os/mcp-i-core';
1150
+
1151
+ const hash = await canonicalHash({ foo: 'bar' }, 'sha256');
1152
+ console.log(hash); // "sha256:abc123..."
1153
+ ```
1154
+
1155
+ ---
1156
+
1157
+ ## Error Handling
1158
+
1159
+ All async methods may throw errors. Always use try-catch:
1160
+
1161
+ ```typescript
1162
+ import { DelegationIssuer, DelegationError } from '@kya-os/mcp-i-core';
1163
+
1164
+ try {
1165
+ const delegation = await issuer.issue({
1166
+ subjectDid: 'did:key:z6Mkr...',
1167
+ constraints: { /* ... */ },
1168
+ });
1169
+ } catch (error) {
1170
+ if (error instanceof DelegationError) {
1171
+ console.error('Delegation error:', error.message);
1172
+ console.error('Code:', error.code);
1173
+ } else {
1174
+ console.error('Unexpected error:', error);
1175
+ }
1176
+ }
1177
+ ```
1178
+
1179
+ ### Common Error Codes
1180
+
1181
+ | Code | Description |
1182
+ |------|-------------|
1183
+ | `INVALID_DID` | DID format is invalid |
1184
+ | `INVALID_CONSTRAINTS` | Constraints do not meet schema requirements |
1185
+ | `SIGNATURE_FAILED` | Cryptographic signature verification failed |
1186
+ | `STATUS_REVOKED` | Credential has been revoked |
1187
+ | `EXPIRED` | Credential has expired |
1188
+ | `CHAIN_INVALID` | Delegation chain verification failed |
1189
+ | `SCHEMA_INVALID` | Schema validation failed |
1190
+ | `STATUS_LIST_UNAVAILABLE` | Cannot fetch status list |
1191
+
1192
+ ---
1193
+
1194
+ ## Complete Examples
1195
+
1196
+ ### Example 1: Full Delegation Lifecycle
1197
+
1198
+ ```typescript
1199
+ import {
1200
+ DelegationIssuer,
1201
+ DelegationVerifier,
1202
+ StatusList2021Manager,
1203
+ InMemoryStatusListStorage,
1204
+ } from '@kya-os/mcp-i-core';
1205
+
1206
+ async function delegationLifecycle() {
1207
+ // 1. Setup
1208
+ const issuerDid = 'did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK';
1209
+ const delegateDid = 'did:key:z6MkrWXJPkxPCuQF7RqeKZFdZqBXz3oCG7PUty5dXLKGzELj';
1210
+
1211
+ // 2. Create status list manager
1212
+ const statusListManager = new StatusList2021Manager({
1213
+ issuerDid,
1214
+ statusListUrl: 'https://issuer.example.com/status/1',
1215
+ storage: new InMemoryStatusListStorage(),
1216
+ });
1217
+
1218
+ await statusListManager.createStatusList({
1219
+ id: 'https://issuer.example.com/status/1',
1220
+ purpose: 'revocation',
1221
+ });
1222
+
1223
+ // 3. Create issuer
1224
+ const issuer = new DelegationIssuer({
1225
+ issuerDid,
1226
+ privateKeyJwk: issuerPrivateKey,
1227
+ statusListManager,
1228
+ });
1229
+
1230
+ // 4. Issue delegation
1231
+ const delegation = await issuer.issueWithStatus({
1232
+ subjectDid: delegateDid,
1233
+ constraints: {
1234
+ scope: {
1235
+ allowedTools: ['read_file'],
1236
+ allowedResources: ['/documents/*'],
1237
+ },
1238
+ time: {
1239
+ notAfter: new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString(),
1240
+ },
1241
+ },
1242
+ });
1243
+
1244
+ console.log('✅ Delegation issued:', delegation.id);
1245
+
1246
+ // 5. Verify delegation
1247
+ const verifier = new DelegationVerifier();
1248
+ const result1 = await verifier.verify({
1249
+ credential: delegation,
1250
+ checkStatus: true,
1251
+ statusListFetcher: async (url) => {
1252
+ return await statusListManager.getStatusList(url);
1253
+ },
1254
+ });
1255
+
1256
+ console.log('✅ Verification 1:', result1.verified);
1257
+
1258
+ // 6. Revoke delegation
1259
+ const statusIndex = parseInt(delegation.credentialStatus!.statusListIndex);
1260
+ await statusListManager.revokeCredential(statusIndex);
1261
+
1262
+ console.log('🔒 Delegation revoked');
1263
+
1264
+ // 7. Verify again (should fail)
1265
+ const result2 = await verifier.verify({
1266
+ credential: delegation,
1267
+ checkStatus: true,
1268
+ statusListFetcher: async (url) => {
1269
+ return await statusListManager.getStatusList(url);
1270
+ },
1271
+ });
1272
+
1273
+ console.log('❌ Verification 2:', result2.verified); // false
1274
+ console.log(' Status revoked:', result2.statusRevoked); // true
1275
+ }
1276
+ ```
1277
+
1278
+ ### Example 2: Delegation Chains
1279
+
1280
+ ```typescript
1281
+ import {
1282
+ DelegationIssuer,
1283
+ DelegationGraph,
1284
+ StatusList2021Manager,
1285
+ } from '@kya-os/mcp-i-core';
1286
+
1287
+ async function delegationChains() {
1288
+ const issuer = new DelegationIssuer({ /* ... */ });
1289
+ const graph = new DelegationGraph();
1290
+ const statusListManager = new StatusList2021Manager({ /* ... */ });
1291
+
1292
+ // Issue root delegation
1293
+ const root = await issuer.issue({
1294
+ subjectDid: 'did:key:alice',
1295
+ constraints: {
1296
+ scope: { allowedTools: ['*'] },
1297
+ },
1298
+ });
1299
+
1300
+ // Issue child delegation
1301
+ const child = await issuer.issue({
1302
+ subjectDid: 'did:key:bob',
1303
+ constraints: {
1304
+ scope: { allowedTools: ['read_file'] },
1305
+ },
1306
+ parentDelegation: root.id,
1307
+ });
1308
+
1309
+ // Issue grandchild delegation
1310
+ const grandchild = await issuer.issue({
1311
+ subjectDid: 'did:key:charlie',
1312
+ constraints: {
1313
+ scope: { allowedTools: ['read_file'] },
1314
+ },
1315
+ parentDelegation: child.id,
1316
+ });
1317
+
1318
+ // Build graph
1319
+ await graph.addDelegation(root);
1320
+ await graph.addDelegation(child);
1321
+ await graph.addDelegation(grandchild);
1322
+
1323
+ // Get chain
1324
+ const chain = await graph.getPath(grandchild.id);
1325
+ console.log('Chain length:', chain.length); // 3
1326
+
1327
+ // Revoke root (cascades to all children)
1328
+ await graph.revokeDelegation(root.id, statusListManager, { cascade: true });
1329
+ console.log('All delegations revoked');
1330
+ }
1331
+ ```
1332
+
1333
+ ---
1334
+
1335
+ ## TypeScript Configuration
1336
+
1337
+ For best TypeScript experience, use these settings:
1338
+
1339
+ ```json
1340
+ {
1341
+ "compilerOptions": {
1342
+ "target": "ES2020",
1343
+ "module": "commonjs",
1344
+ "lib": ["ES2020"],
1345
+ "strict": true,
1346
+ "esModuleInterop": true,
1347
+ "skipLibCheck": true,
1348
+ "forceConsistentCasingInFileNames": true,
1349
+ "resolveJsonModule": true
1350
+ }
1351
+ }
1352
+ ```
1353
+
1354
+ ---
1355
+
1356
+ ## Further Reading
1357
+
1358
+ - [W3C VC Delegation Guide](./W3C_VC_DELEGATION_GUIDE.md)
1359
+ - [StatusList2021 Guide](./STATUSLIST2021_GUIDE.md)
1360
+ - [Compliance Matrix](./COMPLIANCE_MATRIX.md)
1361
+ - [W3C Verifiable Credentials](https://www.w3.org/TR/vc-data-model/)
1362
+ - [W3C StatusList2021](https://www.w3.org/TR/vc-status-list-2021/)