@kya-os/mcp-i-core 1.2.3-canary.6 → 1.3.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 (231) hide show
  1. package/.claude/settings.local.json +9 -0
  2. package/.turbo/turbo-build.log +4 -0
  3. package/.turbo/turbo-test$colon$coverage.log +4514 -0
  4. package/.turbo/turbo-test.log +2973 -0
  5. package/COMPLIANCE_IMPROVEMENT_REPORT.md +483 -0
  6. package/Composer 3.md +615 -0
  7. package/GPT-5.md +1169 -0
  8. package/OPUS-plan.md +352 -0
  9. package/PHASE_3_AND_4.1_SUMMARY.md +585 -0
  10. package/PHASE_3_SUMMARY.md +317 -0
  11. package/PHASE_4.1.3_SUMMARY.md +428 -0
  12. package/PHASE_4.1_COMPLETE.md +525 -0
  13. package/PHASE_4_USER_DID_IDENTITY_LINKING_PLAN.md +1240 -0
  14. package/SCHEMA_COMPLIANCE_REPORT.md +275 -0
  15. package/TEST_PLAN.md +571 -0
  16. package/coverage/coverage-final.json +57 -0
  17. package/dist/__tests__/utils/mock-providers.d.ts +1 -2
  18. package/dist/__tests__/utils/mock-providers.d.ts.map +1 -1
  19. package/dist/__tests__/utils/mock-providers.js.map +1 -1
  20. package/dist/cache/oauth-config-cache.d.ts +69 -0
  21. package/dist/cache/oauth-config-cache.d.ts.map +1 -0
  22. package/dist/cache/oauth-config-cache.js +76 -0
  23. package/dist/cache/oauth-config-cache.js.map +1 -0
  24. package/dist/identity/idp-token-resolver.d.ts +53 -0
  25. package/dist/identity/idp-token-resolver.d.ts.map +1 -0
  26. package/dist/identity/idp-token-resolver.js +108 -0
  27. package/dist/identity/idp-token-resolver.js.map +1 -0
  28. package/dist/identity/idp-token-storage.interface.d.ts +42 -0
  29. package/dist/identity/idp-token-storage.interface.d.ts.map +1 -0
  30. package/dist/identity/idp-token-storage.interface.js +12 -0
  31. package/dist/identity/idp-token-storage.interface.js.map +1 -0
  32. package/dist/identity/user-did-manager.d.ts +39 -1
  33. package/dist/identity/user-did-manager.d.ts.map +1 -1
  34. package/dist/identity/user-did-manager.js +69 -3
  35. package/dist/identity/user-did-manager.js.map +1 -1
  36. package/dist/index.d.ts +22 -0
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +39 -1
  39. package/dist/index.js.map +1 -1
  40. package/dist/runtime/audit-logger.d.ts +37 -0
  41. package/dist/runtime/audit-logger.d.ts.map +1 -0
  42. package/dist/runtime/audit-logger.js +9 -0
  43. package/dist/runtime/audit-logger.js.map +1 -0
  44. package/dist/runtime/base.d.ts +58 -2
  45. package/dist/runtime/base.d.ts.map +1 -1
  46. package/dist/runtime/base.js +266 -11
  47. package/dist/runtime/base.js.map +1 -1
  48. package/dist/services/access-control.service.d.ts.map +1 -1
  49. package/dist/services/access-control.service.js +200 -35
  50. package/dist/services/access-control.service.js.map +1 -1
  51. package/dist/services/authorization/authorization-registry.d.ts +29 -0
  52. package/dist/services/authorization/authorization-registry.d.ts.map +1 -0
  53. package/dist/services/authorization/authorization-registry.js +57 -0
  54. package/dist/services/authorization/authorization-registry.js.map +1 -0
  55. package/dist/services/authorization/types.d.ts +53 -0
  56. package/dist/services/authorization/types.d.ts.map +1 -0
  57. package/dist/services/authorization/types.js +10 -0
  58. package/dist/services/authorization/types.js.map +1 -0
  59. package/dist/services/batch-delegation.service.d.ts +53 -0
  60. package/dist/services/batch-delegation.service.d.ts.map +1 -0
  61. package/dist/services/batch-delegation.service.js +95 -0
  62. package/dist/services/batch-delegation.service.js.map +1 -0
  63. package/dist/services/oauth-config.service.d.ts +53 -0
  64. package/dist/services/oauth-config.service.d.ts.map +1 -0
  65. package/dist/services/oauth-config.service.js +117 -0
  66. package/dist/services/oauth-config.service.js.map +1 -0
  67. package/dist/services/oauth-provider-registry.d.ts +77 -0
  68. package/dist/services/oauth-provider-registry.d.ts.map +1 -0
  69. package/dist/services/oauth-provider-registry.js +112 -0
  70. package/dist/services/oauth-provider-registry.js.map +1 -0
  71. package/dist/services/oauth-service.d.ts +77 -0
  72. package/dist/services/oauth-service.d.ts.map +1 -0
  73. package/dist/services/oauth-service.js +348 -0
  74. package/dist/services/oauth-service.js.map +1 -0
  75. package/dist/services/oauth-token-retrieval.service.d.ts +49 -0
  76. package/dist/services/oauth-token-retrieval.service.d.ts.map +1 -0
  77. package/dist/services/oauth-token-retrieval.service.js +150 -0
  78. package/dist/services/oauth-token-retrieval.service.js.map +1 -0
  79. package/dist/services/provider-resolver.d.ts +48 -0
  80. package/dist/services/provider-resolver.d.ts.map +1 -0
  81. package/dist/services/provider-resolver.js +120 -0
  82. package/dist/services/provider-resolver.js.map +1 -0
  83. package/dist/services/provider-validator.d.ts +55 -0
  84. package/dist/services/provider-validator.d.ts.map +1 -0
  85. package/dist/services/provider-validator.js +135 -0
  86. package/dist/services/provider-validator.js.map +1 -0
  87. package/dist/services/tool-context-builder.d.ts +57 -0
  88. package/dist/services/tool-context-builder.d.ts.map +1 -0
  89. package/dist/services/tool-context-builder.js +125 -0
  90. package/dist/services/tool-context-builder.js.map +1 -0
  91. package/dist/services/tool-protection.service.d.ts +87 -10
  92. package/dist/services/tool-protection.service.d.ts.map +1 -1
  93. package/dist/services/tool-protection.service.js +282 -112
  94. package/dist/services/tool-protection.service.js.map +1 -1
  95. package/dist/types/oauth-required-error.d.ts +40 -0
  96. package/dist/types/oauth-required-error.d.ts.map +1 -0
  97. package/dist/types/oauth-required-error.js +40 -0
  98. package/dist/types/oauth-required-error.js.map +1 -0
  99. package/dist/utils/did-helpers.d.ts +33 -0
  100. package/dist/utils/did-helpers.d.ts.map +1 -1
  101. package/dist/utils/did-helpers.js +40 -0
  102. package/dist/utils/did-helpers.js.map +1 -1
  103. package/dist/utils/index.d.ts +1 -0
  104. package/dist/utils/index.d.ts.map +1 -1
  105. package/dist/utils/index.js +1 -0
  106. package/dist/utils/index.js.map +1 -1
  107. package/docs/API_REFERENCE.md +1362 -0
  108. package/docs/COMPLIANCE_MATRIX.md +691 -0
  109. package/docs/STATUSLIST2021_GUIDE.md +696 -0
  110. package/docs/W3C_VC_DELEGATION_GUIDE.md +710 -0
  111. package/package.json +24 -50
  112. package/scripts/audit-compliance.ts +724 -0
  113. package/src/__tests__/cache/tool-protection-cache.test.ts +640 -0
  114. package/src/__tests__/config/provider-runtime-config.test.ts +309 -0
  115. package/src/__tests__/delegation-e2e.test.ts +690 -0
  116. package/src/__tests__/identity/user-did-manager.test.ts +213 -0
  117. package/src/__tests__/index.test.ts +56 -0
  118. package/src/__tests__/integration/full-flow.test.ts +776 -0
  119. package/src/__tests__/integration.test.ts +281 -0
  120. package/src/__tests__/providers/base.test.ts +173 -0
  121. package/src/__tests__/providers/memory.test.ts +319 -0
  122. package/src/__tests__/regression/phase2-regression.test.ts +427 -0
  123. package/src/__tests__/runtime/audit-logger.test.ts +154 -0
  124. package/src/__tests__/runtime/base-extensions.test.ts +593 -0
  125. package/src/__tests__/runtime/base.test.ts +869 -0
  126. package/src/__tests__/runtime/delegation-flow.test.ts +164 -0
  127. package/src/__tests__/runtime/proof-client-did.test.ts +375 -0
  128. package/src/__tests__/runtime/route-interception.test.ts +686 -0
  129. package/src/__tests__/runtime/tool-protection-enforcement.test.ts +908 -0
  130. package/src/__tests__/services/agentshield-integration.test.ts +784 -0
  131. package/src/__tests__/services/provider-resolver-edge-cases.test.ts +487 -0
  132. package/src/__tests__/services/tool-protection-oauth-provider.test.ts +480 -0
  133. package/src/__tests__/services/tool-protection.service.test.ts +1366 -0
  134. package/src/__tests__/utils/mock-providers.ts +340 -0
  135. package/src/cache/oauth-config-cache.d.ts +69 -0
  136. package/src/cache/oauth-config-cache.d.ts.map +1 -0
  137. package/src/cache/oauth-config-cache.js +71 -0
  138. package/src/cache/oauth-config-cache.js.map +1 -0
  139. package/src/cache/oauth-config-cache.ts +123 -0
  140. package/src/cache/tool-protection-cache.ts +171 -0
  141. package/src/compliance/EXAMPLE.md +412 -0
  142. package/src/compliance/__tests__/schema-verifier.test.ts +797 -0
  143. package/src/compliance/index.ts +8 -0
  144. package/src/compliance/schema-registry.ts +460 -0
  145. package/src/compliance/schema-verifier.ts +708 -0
  146. package/src/config/__tests__/remote-config.spec.ts +268 -0
  147. package/src/config/remote-config.ts +174 -0
  148. package/src/config.ts +309 -0
  149. package/src/delegation/__tests__/audience-validator.test.ts +112 -0
  150. package/src/delegation/__tests__/bitstring.test.ts +346 -0
  151. package/src/delegation/__tests__/cascading-revocation.test.ts +628 -0
  152. package/src/delegation/__tests__/delegation-graph.test.ts +584 -0
  153. package/src/delegation/__tests__/utils.test.ts +152 -0
  154. package/src/delegation/__tests__/vc-issuer.test.ts +442 -0
  155. package/src/delegation/__tests__/vc-verifier.test.ts +922 -0
  156. package/src/delegation/audience-validator.ts +52 -0
  157. package/src/delegation/bitstring.ts +278 -0
  158. package/src/delegation/cascading-revocation.ts +370 -0
  159. package/src/delegation/delegation-graph.ts +299 -0
  160. package/src/delegation/index.ts +14 -0
  161. package/src/delegation/statuslist-manager.ts +353 -0
  162. package/src/delegation/storage/__tests__/memory-graph-storage.test.ts +366 -0
  163. package/src/delegation/storage/__tests__/memory-statuslist-storage.test.ts +228 -0
  164. package/src/delegation/storage/index.ts +9 -0
  165. package/src/delegation/storage/memory-graph-storage.ts +178 -0
  166. package/src/delegation/storage/memory-statuslist-storage.ts +77 -0
  167. package/src/delegation/utils.ts +42 -0
  168. package/src/delegation/vc-issuer.ts +232 -0
  169. package/src/delegation/vc-verifier.ts +568 -0
  170. package/src/identity/idp-token-resolver.ts +147 -0
  171. package/src/identity/idp-token-storage.interface.ts +59 -0
  172. package/src/identity/user-did-manager.ts +370 -0
  173. package/src/index.ts +260 -0
  174. package/src/providers/base.d.ts +91 -0
  175. package/src/providers/base.d.ts.map +1 -0
  176. package/src/providers/base.js +38 -0
  177. package/src/providers/base.js.map +1 -0
  178. package/src/providers/base.ts +96 -0
  179. package/src/providers/memory.ts +142 -0
  180. package/src/runtime/audit-logger.ts +39 -0
  181. package/src/runtime/base.ts +1329 -0
  182. package/src/services/__tests__/access-control.integration.test.ts +443 -0
  183. package/src/services/__tests__/access-control.proof-response-validation.test.ts +578 -0
  184. package/src/services/__tests__/access-control.service.test.ts +970 -0
  185. package/src/services/__tests__/batch-delegation.service.test.ts +351 -0
  186. package/src/services/__tests__/crypto.service.test.ts +531 -0
  187. package/src/services/__tests__/oauth-provider-registry.test.ts +142 -0
  188. package/src/services/__tests__/proof-verifier.integration.test.ts +485 -0
  189. package/src/services/__tests__/proof-verifier.test.ts +489 -0
  190. package/src/services/__tests__/provider-resolution.integration.test.ts +198 -0
  191. package/src/services/__tests__/provider-resolver.test.ts +217 -0
  192. package/src/services/__tests__/storage.service.test.ts +358 -0
  193. package/src/services/access-control.service.ts +990 -0
  194. package/src/services/authorization/authorization-registry.ts +66 -0
  195. package/src/services/authorization/types.ts +71 -0
  196. package/src/services/batch-delegation.service.ts +137 -0
  197. package/src/services/crypto.service.ts +302 -0
  198. package/src/services/errors.ts +76 -0
  199. package/src/services/index.ts +9 -0
  200. package/src/services/oauth-config.service.d.ts +53 -0
  201. package/src/services/oauth-config.service.d.ts.map +1 -0
  202. package/src/services/oauth-config.service.js +113 -0
  203. package/src/services/oauth-config.service.js.map +1 -0
  204. package/src/services/oauth-config.service.ts +166 -0
  205. package/src/services/oauth-provider-registry.d.ts +57 -0
  206. package/src/services/oauth-provider-registry.d.ts.map +1 -0
  207. package/src/services/oauth-provider-registry.js +73 -0
  208. package/src/services/oauth-provider-registry.js.map +1 -0
  209. package/src/services/oauth-provider-registry.ts +123 -0
  210. package/src/services/oauth-service.ts +510 -0
  211. package/src/services/oauth-token-retrieval.service.ts +245 -0
  212. package/src/services/proof-verifier.ts +478 -0
  213. package/src/services/provider-resolver.d.ts +48 -0
  214. package/src/services/provider-resolver.d.ts.map +1 -0
  215. package/src/services/provider-resolver.js +106 -0
  216. package/src/services/provider-resolver.js.map +1 -0
  217. package/src/services/provider-resolver.ts +144 -0
  218. package/src/services/provider-validator.ts +170 -0
  219. package/src/services/storage.service.ts +566 -0
  220. package/src/services/tool-context-builder.ts +172 -0
  221. package/src/services/tool-protection.service.ts +958 -0
  222. package/src/types/oauth-required-error.ts +63 -0
  223. package/src/types/tool-protection.ts +155 -0
  224. package/src/utils/__tests__/did-helpers.test.ts +101 -0
  225. package/src/utils/base64.ts +148 -0
  226. package/src/utils/cors.ts +83 -0
  227. package/src/utils/did-helpers.ts +150 -0
  228. package/src/utils/index.ts +8 -0
  229. package/src/utils/storage-keys.ts +278 -0
  230. package/tsconfig.json +21 -0
  231. package/vitest.config.ts +56 -0
@@ -0,0 +1,278 @@
1
+ /**
2
+ * Storage Key Migration Utilities
3
+ *
4
+ * Provides utilities for migrating from old storage key formats to new composite formats.
5
+ * This supports Phase 3 Task 2 (StorageService) and Phase 4 (User DID identity linking).
6
+ *
7
+ * @package @kya-os/mcp-i-core
8
+ */
9
+
10
+ /**
11
+ * Legacy storage key format (agent-only, causes multi-tenant conflicts)
12
+ * Format: `agent:${agentDid}:delegation`
13
+ */
14
+ export function legacyDelegationKey(agentDid: string): string {
15
+ return `agent:${agentDid}:delegation`;
16
+ }
17
+
18
+ /**
19
+ * New composite storage key format (user+agent scoped, prevents conflicts)
20
+ * Format: `delegation:user:${userDid}:agent:${agentDid}:project:${projectId}`
21
+ *
22
+ * Note: projectId is optional for backward compatibility
23
+ */
24
+ export function compositeDelegationKey(
25
+ userDid: string,
26
+ agentDid: string,
27
+ projectId?: string
28
+ ): string {
29
+ if (projectId) {
30
+ return `delegation:user:${userDid}:agent:${agentDid}:project:${projectId}`;
31
+ }
32
+ return `delegation:user:${userDid}:agent:${agentDid}`;
33
+ }
34
+
35
+ /**
36
+ * Session cache key format
37
+ * Format: `session:${sessionId}`
38
+ */
39
+ export function sessionKey(sessionId: string): string {
40
+ return `session:${sessionId}`;
41
+ }
42
+
43
+ /**
44
+ * User DID storage key format
45
+ * Format: `userDid:oauth:${provider}:${subject}`
46
+ */
47
+ export function userDidKey(provider: string, subject: string): string {
48
+ return `userDid:oauth:${provider}:${subject}`;
49
+ }
50
+
51
+ /**
52
+ * OAuth identity mapping key format
53
+ * Format: `oauth:${provider}:${subject}`
54
+ */
55
+ export function oauthIdentityKey(provider: string, subject: string): string {
56
+ return `oauth:${provider}:${subject}`;
57
+ }
58
+
59
+ /**
60
+ * Verification cache key format
61
+ * Format: `verified:${tokenHash}`
62
+ */
63
+ export function verificationCacheKey(tokenHash: string): string {
64
+ return `verified:${tokenHash}`;
65
+ }
66
+
67
+ /**
68
+ * Nonce tracking key format
69
+ * Format: `nonce:${nonce}`
70
+ */
71
+ export function nonceKey(nonce: string): string {
72
+ return `nonce:${nonce}`;
73
+ }
74
+
75
+ /**
76
+ * Storage key migration result
77
+ */
78
+ export interface MigrationResult {
79
+ /** Number of keys migrated */
80
+ migrated: number;
81
+
82
+ /** Number of keys that failed to migrate */
83
+ failed: number;
84
+
85
+ /** List of migrated key pairs (old -> new) */
86
+ migrations: Array<{ oldKey: string; newKey: string }>;
87
+
88
+ /** List of errors encountered */
89
+ errors: Array<{ key: string; error: string }>;
90
+ }
91
+
92
+ /**
93
+ * Storage provider interface for migration operations
94
+ *
95
+ * Matches the base StorageProvider abstract class contract.
96
+ */
97
+ export interface StorageProvider {
98
+ get(key: string): Promise<string | null>;
99
+ set(key: string, value: string): Promise<void>;
100
+ delete(key: string): Promise<void>;
101
+ exists(key: string): Promise<boolean>;
102
+ list(prefix?: string): Promise<string[]>;
103
+ }
104
+
105
+ /**
106
+ * Migrate delegation keys from legacy format to composite format
107
+ *
108
+ * This function:
109
+ * 1. Finds all legacy keys (`agent:${did}:delegation`)
110
+ * 2. Attempts to extract userDid from session data or OAuth mappings
111
+ * 3. Creates new composite keys (`delegation:user:${userDid}:agent:${agentDid}`)
112
+ * 4. Copies values to new keys
113
+ * 5. Optionally deletes old keys (dry-run mode available)
114
+ *
115
+ * @param storage - Storage provider instance
116
+ * @param options - Migration options
117
+ * @returns Migration result with statistics
118
+ */
119
+ export async function migrateDelegationKeys(
120
+ storage: StorageProvider,
121
+ options: {
122
+ /** If true, only report what would be migrated without making changes */
123
+ dryRun?: boolean;
124
+
125
+ /** If true, delete old keys after successful migration */
126
+ deleteOldKeys?: boolean;
127
+
128
+ /** Optional userDid resolver function (if not provided, attempts to extract from session) */
129
+ resolveUserDid?: (agentDid: string, sessionId?: string) => Promise<string | null>;
130
+ } = {}
131
+ ): Promise<MigrationResult> {
132
+ const result: MigrationResult = {
133
+ migrated: 0,
134
+ failed: 0,
135
+ migrations: [],
136
+ errors: [],
137
+ };
138
+
139
+ try {
140
+ // Find all legacy delegation keys
141
+ const legacyKeys = await storage.list('agent:');
142
+ const delegationKeys = legacyKeys.filter((key) =>
143
+ key.match(/^agent:[^:]+:delegation$/)
144
+ );
145
+
146
+ console.log(`Found ${delegationKeys.length} legacy delegation keys to migrate`);
147
+
148
+ for (const oldKey of delegationKeys) {
149
+ try {
150
+ // Extract agentDid from key: `agent:${agentDid}:delegation`
151
+ const match = oldKey.match(/^agent:([^:]+):delegation$/);
152
+ if (!match) {
153
+ result.errors.push({
154
+ key: oldKey,
155
+ error: 'Invalid legacy key format',
156
+ });
157
+ result.failed++;
158
+ continue;
159
+ }
160
+
161
+ const agentDid = match[1];
162
+
163
+ // Get the value from old key
164
+ const value = await storage.get(oldKey);
165
+ if (!value) {
166
+ // Key exists but has no value - skip
167
+ continue;
168
+ }
169
+
170
+ // Try to resolve userDid
171
+ let userDid: string | null = null;
172
+ let sessionId: string | undefined = undefined;
173
+
174
+ // First, attempt to extract from session data to get both userDid and sessionId
175
+ const sessionKeys = await storage.list('session:');
176
+ for (const sessionKey of sessionKeys) {
177
+ const sessionData = await storage.get(sessionKey);
178
+ if (sessionData) {
179
+ try {
180
+ const parsed = JSON.parse(sessionData);
181
+ if (parsed.userDid && parsed.agentDid === agentDid) {
182
+ userDid = parsed.userDid;
183
+ // Extract sessionId from key: `session:${sessionId}`
184
+ const sessionMatch = sessionKey.match(/^session:(.+)$/);
185
+ if (sessionMatch) {
186
+ sessionId = sessionMatch[1];
187
+ }
188
+ break;
189
+ }
190
+ } catch {
191
+ // Not JSON, skip
192
+ }
193
+ }
194
+ }
195
+
196
+ // If custom resolver provided, use it (with sessionId context if available)
197
+ if (options.resolveUserDid) {
198
+ const resolvedUserDid = await options.resolveUserDid(agentDid, sessionId);
199
+ // Use resolved userDid if available, otherwise fall back to extracted one
200
+ if (resolvedUserDid) {
201
+ userDid = resolvedUserDid;
202
+ }
203
+ }
204
+
205
+ if (!userDid) {
206
+ // Cannot migrate without userDid - skip for now
207
+ result.errors.push({
208
+ key: oldKey,
209
+ error: 'Cannot resolve userDid - skipping migration',
210
+ });
211
+ result.failed++;
212
+ continue;
213
+ }
214
+
215
+ // Create new composite key
216
+ const newKey = compositeDelegationKey(userDid, agentDid);
217
+
218
+ if (options.dryRun) {
219
+ // Just record what would be migrated
220
+ result.migrations.push({ oldKey, newKey });
221
+ result.migrated++;
222
+ } else {
223
+ // Copy value to new key
224
+ await storage.set(newKey, value);
225
+ result.migrations.push({ oldKey, newKey });
226
+ result.migrated++;
227
+
228
+ // Optionally delete old key
229
+ if (options.deleteOldKeys) {
230
+ await storage.delete(oldKey);
231
+ }
232
+ }
233
+ } catch (error) {
234
+ result.errors.push({
235
+ key: oldKey,
236
+ error: error instanceof Error ? error.message : String(error),
237
+ });
238
+ result.failed++;
239
+ }
240
+ }
241
+ } catch (error) {
242
+ result.errors.push({
243
+ key: 'migration',
244
+ error: error instanceof Error ? error.message : String(error),
245
+ });
246
+ }
247
+
248
+ return result;
249
+ }
250
+
251
+ /**
252
+ * Storage key constants for consistent namespace management
253
+ *
254
+ * These match the Phase 4 storage key architecture.
255
+ */
256
+ export const STORAGE_KEYS = {
257
+ /** User DID storage (persistent - 90 days) */
258
+ userDid: userDidKey,
259
+
260
+ /** OAuth identity mapping (persistent - 90 days) */
261
+ oauthIdentity: oauthIdentityKey,
262
+
263
+ /** User+Agent delegation tokens (persistent - 7 days) */
264
+ delegation: compositeDelegationKey,
265
+
266
+ /** Session cache (temporary - 30 minutes) */
267
+ session: sessionKey,
268
+
269
+ /** Legacy delegation format (deprecated - 24 hours) */
270
+ legacyDelegation: legacyDelegationKey,
271
+
272
+ /** Verification cache (temporary - 5 minutes) */
273
+ verificationCache: verificationCacheKey,
274
+
275
+ /** Nonce tracking (temporary - 5 minutes) */
276
+ nonce: nonceKey,
277
+ } as const;
278
+
package/tsconfig.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "Node16",
5
+ "lib": ["ES2022"],
6
+ "outDir": "./dist",
7
+ "rootDir": "./src",
8
+ "strict": true,
9
+ "esModuleInterop": true,
10
+ "skipLibCheck": true,
11
+ "forceConsistentCasingInFileNames": true,
12
+ "declaration": true,
13
+ "declarationMap": true,
14
+ "sourceMap": true,
15
+ "moduleResolution": "node16",
16
+ "resolveJsonModule": true,
17
+ "allowSyntheticDefaultImports": true
18
+ },
19
+ "include": ["src/**/*"],
20
+ "exclude": ["node_modules", "dist", "**/*.test.ts", "**/*.spec.ts"]
21
+ }
@@ -0,0 +1,56 @@
1
+ import { defineConfig } from "vitest/config";
2
+ import path from "path";
3
+
4
+ export default defineConfig({
5
+ resolve: {
6
+ alias: {
7
+ // Map contracts subpath exports to their actual dist paths for vitest resolution
8
+ // These aliases work for both source files and bundled code in node_modules
9
+ "@kya-os/contracts/proof": path.resolve(__dirname, "../contracts/dist/proof/index.js"),
10
+ "@kya-os/contracts/delegation": path.resolve(__dirname, "../contracts/dist/delegation/index.js"),
11
+ "@kya-os/contracts/agentshield-api": path.resolve(__dirname, "../contracts/dist/agentshield-api/index.js"),
12
+ "@kya-os/contracts/config": path.resolve(__dirname, "../contracts/dist/config/index.js"),
13
+ "@kya-os/contracts/tool-protection": path.resolve(__dirname, "../contracts/dist/tool-protection/index.js"),
14
+ "@kya-os/contracts/well-known": path.resolve(__dirname, "../contracts/dist/well-known/index.js"),
15
+ "@kya-os/contracts/runtime": path.resolve(__dirname, "../contracts/dist/runtime/index.js"),
16
+ "@kya-os/contracts/handshake": path.resolve(__dirname, "../contracts/dist/handshake.js"),
17
+ "@kya-os/contracts/test": path.resolve(__dirname, "../contracts/dist/test.js"),
18
+ "@kya-os/contracts": path.resolve(__dirname, "../contracts/dist/index.js"),
19
+ },
20
+ // Ensure aliases are resolved before node_modules
21
+ dedupe: ["@kya-os/contracts"],
22
+ // Force resolution to use workspace contracts
23
+ conditions: ["node", "import", "require"],
24
+ },
25
+ // Force vitest to inline contracts and mcp-i-core packages so aliases work
26
+ // This ensures that bundled code in node_modules can resolve contracts subpath exports
27
+ server: {
28
+ deps: {
29
+ inline: ["@kya-os/contracts", "@kya-os/mcp-i-core"],
30
+ },
31
+ },
32
+ test: {
33
+ globals: true,
34
+ environment: "node",
35
+ coverage: {
36
+ provider: "v8",
37
+ reporter: ["json", "text-summary"],
38
+ include: ["src/**/*.ts"],
39
+ exclude: [
40
+ "src/**/__tests__/**",
41
+ "src/**/*.test.ts",
42
+ "dist/**",
43
+ "node_modules/**",
44
+ ],
45
+ reportsDirectory: "./coverage",
46
+ clean: true,
47
+ // Coverage thresholds removed - will be re-enabled when coverage improves
48
+ // thresholds: {
49
+ // lines: 80,
50
+ // branches: 70,
51
+ // functions: 80,
52
+ // statements: 80,
53
+ // },
54
+ },
55
+ },
56
+ });