@kya-os/mcp-i-core 1.3.13 → 1.3.15

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 (255) hide show
  1. package/dist/config/remote-config.js +9 -12
  2. package/dist/runtime/base.d.ts +2 -1
  3. package/dist/runtime/base.js +34 -6
  4. package/dist/services/access-control.service.js +5 -0
  5. package/dist/services/tool-protection.service.js +17 -8
  6. package/package.json +2 -2
  7. package/.turbo/turbo-build.log +0 -4
  8. package/.turbo/turbo-test$colon$coverage.log +0 -4586
  9. package/.turbo/turbo-test.log +0 -4631
  10. package/COMPLIANCE_IMPROVEMENT_REPORT.md +0 -483
  11. package/Composer 3.md +0 -615
  12. package/GPT-5.md +0 -1169
  13. package/OPUS-plan.md +0 -352
  14. package/PHASE_3_AND_4.1_SUMMARY.md +0 -585
  15. package/PHASE_3_SUMMARY.md +0 -317
  16. package/PHASE_4.1.3_SUMMARY.md +0 -428
  17. package/PHASE_4.1_COMPLETE.md +0 -525
  18. package/PHASE_4_USER_DID_IDENTITY_LINKING_PLAN.md +0 -1240
  19. package/SCHEMA_COMPLIANCE_REPORT.md +0 -275
  20. package/TEST_PLAN.md +0 -571
  21. package/coverage/coverage-final.json +0 -60
  22. package/dist/cache/oauth-config-cache.d.ts.map +0 -1
  23. package/dist/cache/oauth-config-cache.js.map +0 -1
  24. package/dist/cache/tool-protection-cache.d.ts.map +0 -1
  25. package/dist/cache/tool-protection-cache.js.map +0 -1
  26. package/dist/compliance/index.d.ts.map +0 -1
  27. package/dist/compliance/index.js.map +0 -1
  28. package/dist/compliance/schema-registry.d.ts.map +0 -1
  29. package/dist/compliance/schema-registry.js.map +0 -1
  30. package/dist/compliance/schema-verifier.d.ts.map +0 -1
  31. package/dist/compliance/schema-verifier.js.map +0 -1
  32. package/dist/config/remote-config.d.ts.map +0 -1
  33. package/dist/config/remote-config.js.map +0 -1
  34. package/dist/config.d.ts.map +0 -1
  35. package/dist/config.js.map +0 -1
  36. package/dist/delegation/audience-validator.d.ts.map +0 -1
  37. package/dist/delegation/audience-validator.js.map +0 -1
  38. package/dist/delegation/bitstring.d.ts.map +0 -1
  39. package/dist/delegation/bitstring.js.map +0 -1
  40. package/dist/delegation/cascading-revocation.d.ts.map +0 -1
  41. package/dist/delegation/cascading-revocation.js.map +0 -1
  42. package/dist/delegation/delegation-graph.d.ts.map +0 -1
  43. package/dist/delegation/delegation-graph.js.map +0 -1
  44. package/dist/delegation/did-key-resolver.d.ts.map +0 -1
  45. package/dist/delegation/did-key-resolver.js.map +0 -1
  46. package/dist/delegation/index.d.ts.map +0 -1
  47. package/dist/delegation/index.js.map +0 -1
  48. package/dist/delegation/statuslist-manager.d.ts.map +0 -1
  49. package/dist/delegation/statuslist-manager.js.map +0 -1
  50. package/dist/delegation/storage/index.d.ts.map +0 -1
  51. package/dist/delegation/storage/index.js.map +0 -1
  52. package/dist/delegation/storage/memory-graph-storage.d.ts.map +0 -1
  53. package/dist/delegation/storage/memory-graph-storage.js.map +0 -1
  54. package/dist/delegation/storage/memory-statuslist-storage.d.ts.map +0 -1
  55. package/dist/delegation/storage/memory-statuslist-storage.js.map +0 -1
  56. package/dist/delegation/utils.d.ts.map +0 -1
  57. package/dist/delegation/utils.js.map +0 -1
  58. package/dist/delegation/vc-issuer.d.ts.map +0 -1
  59. package/dist/delegation/vc-issuer.js.map +0 -1
  60. package/dist/delegation/vc-verifier.d.ts.map +0 -1
  61. package/dist/delegation/vc-verifier.js.map +0 -1
  62. package/dist/identity/idp-token-resolver.d.ts.map +0 -1
  63. package/dist/identity/idp-token-resolver.js.map +0 -1
  64. package/dist/identity/idp-token-storage.interface.d.ts.map +0 -1
  65. package/dist/identity/idp-token-storage.interface.js.map +0 -1
  66. package/dist/identity/user-did-manager.d.ts.map +0 -1
  67. package/dist/identity/user-did-manager.js.map +0 -1
  68. package/dist/index.d.ts.map +0 -1
  69. package/dist/index.js.map +0 -1
  70. package/dist/providers/base.d.ts.map +0 -1
  71. package/dist/providers/base.js.map +0 -1
  72. package/dist/providers/memory.d.ts.map +0 -1
  73. package/dist/providers/memory.js.map +0 -1
  74. package/dist/runtime/audit-logger.d.ts.map +0 -1
  75. package/dist/runtime/audit-logger.js.map +0 -1
  76. package/dist/runtime/base.d.ts.map +0 -1
  77. package/dist/runtime/base.js.map +0 -1
  78. package/dist/services/access-control.service.d.ts.map +0 -1
  79. package/dist/services/access-control.service.js.map +0 -1
  80. package/dist/services/authorization/authorization-registry.d.ts.map +0 -1
  81. package/dist/services/authorization/authorization-registry.js.map +0 -1
  82. package/dist/services/authorization/types.d.ts.map +0 -1
  83. package/dist/services/authorization/types.js.map +0 -1
  84. package/dist/services/batch-delegation.service.d.ts.map +0 -1
  85. package/dist/services/batch-delegation.service.js.map +0 -1
  86. package/dist/services/crypto.service.d.ts.map +0 -1
  87. package/dist/services/crypto.service.js.map +0 -1
  88. package/dist/services/errors.d.ts.map +0 -1
  89. package/dist/services/errors.js.map +0 -1
  90. package/dist/services/index.d.ts.map +0 -1
  91. package/dist/services/index.js.map +0 -1
  92. package/dist/services/oauth-config.service.d.ts.map +0 -1
  93. package/dist/services/oauth-config.service.js.map +0 -1
  94. package/dist/services/oauth-provider-registry.d.ts.map +0 -1
  95. package/dist/services/oauth-provider-registry.js.map +0 -1
  96. package/dist/services/oauth-service.d.ts.map +0 -1
  97. package/dist/services/oauth-service.js.map +0 -1
  98. package/dist/services/oauth-token-retrieval.service.d.ts.map +0 -1
  99. package/dist/services/oauth-token-retrieval.service.js.map +0 -1
  100. package/dist/services/proof-verifier.d.ts.map +0 -1
  101. package/dist/services/proof-verifier.js.map +0 -1
  102. package/dist/services/provider-resolver.d.ts.map +0 -1
  103. package/dist/services/provider-resolver.js.map +0 -1
  104. package/dist/services/provider-validator.d.ts.map +0 -1
  105. package/dist/services/provider-validator.js.map +0 -1
  106. package/dist/services/session-registration.service.d.ts.map +0 -1
  107. package/dist/services/session-registration.service.js.map +0 -1
  108. package/dist/services/storage.service.d.ts.map +0 -1
  109. package/dist/services/storage.service.js.map +0 -1
  110. package/dist/services/tool-context-builder.d.ts.map +0 -1
  111. package/dist/services/tool-context-builder.js.map +0 -1
  112. package/dist/services/tool-protection.service.d.ts.map +0 -1
  113. package/dist/services/tool-protection.service.js.map +0 -1
  114. package/dist/types/oauth-required-error.d.ts.map +0 -1
  115. package/dist/types/oauth-required-error.js.map +0 -1
  116. package/dist/types/tool-protection.d.ts.map +0 -1
  117. package/dist/types/tool-protection.js.map +0 -1
  118. package/dist/utils/base58.d.ts.map +0 -1
  119. package/dist/utils/base58.js.map +0 -1
  120. package/dist/utils/base64.d.ts.map +0 -1
  121. package/dist/utils/base64.js.map +0 -1
  122. package/dist/utils/cors.d.ts.map +0 -1
  123. package/dist/utils/cors.js.map +0 -1
  124. package/dist/utils/did-helpers.d.ts.map +0 -1
  125. package/dist/utils/did-helpers.js.map +0 -1
  126. package/dist/utils/index.d.ts.map +0 -1
  127. package/dist/utils/index.js.map +0 -1
  128. package/dist/utils/storage-keys.d.ts.map +0 -1
  129. package/dist/utils/storage-keys.js.map +0 -1
  130. package/docs/API_REFERENCE.md +0 -1362
  131. package/docs/COMPLIANCE_MATRIX.md +0 -691
  132. package/docs/STATUSLIST2021_GUIDE.md +0 -696
  133. package/docs/W3C_VC_DELEGATION_GUIDE.md +0 -710
  134. package/src/__tests__/cache/tool-protection-cache.test.ts +0 -640
  135. package/src/__tests__/config/provider-runtime-config.test.ts +0 -309
  136. package/src/__tests__/delegation-e2e.test.ts +0 -690
  137. package/src/__tests__/identity/user-did-manager.test.ts +0 -232
  138. package/src/__tests__/index.test.ts +0 -56
  139. package/src/__tests__/integration/full-flow.test.ts +0 -789
  140. package/src/__tests__/integration.test.ts +0 -281
  141. package/src/__tests__/providers/base.test.ts +0 -173
  142. package/src/__tests__/providers/memory.test.ts +0 -319
  143. package/src/__tests__/regression/phase2-regression.test.ts +0 -429
  144. package/src/__tests__/runtime/audit-logger.test.ts +0 -154
  145. package/src/__tests__/runtime/base-extensions.test.ts +0 -595
  146. package/src/__tests__/runtime/base.test.ts +0 -869
  147. package/src/__tests__/runtime/delegation-flow.test.ts +0 -164
  148. package/src/__tests__/runtime/proof-client-did.test.ts +0 -376
  149. package/src/__tests__/runtime/route-interception.test.ts +0 -686
  150. package/src/__tests__/runtime/tool-protection-enforcement.test.ts +0 -908
  151. package/src/__tests__/services/agentshield-integration.test.ts +0 -791
  152. package/src/__tests__/services/cache-busting.test.ts +0 -125
  153. package/src/__tests__/services/oauth-service-pkce.test.ts +0 -556
  154. package/src/__tests__/services/provider-resolver-edge-cases.test.ts +0 -591
  155. package/src/__tests__/services/tool-protection-merged-config.test.ts +0 -485
  156. package/src/__tests__/services/tool-protection-oauth-provider.test.ts +0 -480
  157. package/src/__tests__/services/tool-protection.service.test.ts +0 -1373
  158. package/src/__tests__/utils/mock-providers.ts +0 -340
  159. package/src/cache/oauth-config-cache.d.ts +0 -69
  160. package/src/cache/oauth-config-cache.d.ts.map +0 -1
  161. package/src/cache/oauth-config-cache.js.map +0 -1
  162. package/src/cache/oauth-config-cache.ts +0 -123
  163. package/src/cache/tool-protection-cache.ts +0 -171
  164. package/src/compliance/EXAMPLE.md +0 -412
  165. package/src/compliance/__tests__/schema-verifier.test.ts +0 -797
  166. package/src/compliance/index.ts +0 -8
  167. package/src/compliance/schema-registry.ts +0 -460
  168. package/src/compliance/schema-verifier.ts +0 -708
  169. package/src/config/__tests__/merged-config.spec.ts +0 -445
  170. package/src/config/__tests__/remote-config.spec.ts +0 -268
  171. package/src/config/remote-config.ts +0 -264
  172. package/src/config.ts +0 -312
  173. package/src/delegation/__tests__/audience-validator.test.ts +0 -112
  174. package/src/delegation/__tests__/bitstring.test.ts +0 -346
  175. package/src/delegation/__tests__/cascading-revocation.test.ts +0 -628
  176. package/src/delegation/__tests__/delegation-graph.test.ts +0 -584
  177. package/src/delegation/__tests__/did-key-resolver.test.ts +0 -265
  178. package/src/delegation/__tests__/utils.test.ts +0 -152
  179. package/src/delegation/__tests__/vc-issuer.test.ts +0 -442
  180. package/src/delegation/__tests__/vc-verifier.test.ts +0 -922
  181. package/src/delegation/audience-validator.ts +0 -52
  182. package/src/delegation/bitstring.ts +0 -278
  183. package/src/delegation/cascading-revocation.ts +0 -370
  184. package/src/delegation/delegation-graph.ts +0 -299
  185. package/src/delegation/did-key-resolver.ts +0 -179
  186. package/src/delegation/index.ts +0 -14
  187. package/src/delegation/statuslist-manager.ts +0 -353
  188. package/src/delegation/storage/__tests__/memory-graph-storage.test.ts +0 -366
  189. package/src/delegation/storage/__tests__/memory-statuslist-storage.test.ts +0 -228
  190. package/src/delegation/storage/index.ts +0 -9
  191. package/src/delegation/storage/memory-graph-storage.ts +0 -178
  192. package/src/delegation/storage/memory-statuslist-storage.ts +0 -77
  193. package/src/delegation/utils.ts +0 -221
  194. package/src/delegation/vc-issuer.ts +0 -232
  195. package/src/delegation/vc-verifier.ts +0 -568
  196. package/src/identity/idp-token-resolver.ts +0 -181
  197. package/src/identity/idp-token-storage.interface.ts +0 -94
  198. package/src/identity/user-did-manager.ts +0 -526
  199. package/src/index.ts +0 -310
  200. package/src/providers/base.d.ts +0 -91
  201. package/src/providers/base.d.ts.map +0 -1
  202. package/src/providers/base.js.map +0 -1
  203. package/src/providers/base.ts +0 -96
  204. package/src/providers/memory.ts +0 -142
  205. package/src/runtime/audit-logger.ts +0 -39
  206. package/src/runtime/base.ts +0 -1392
  207. package/src/services/__tests__/access-control.integration.test.ts +0 -443
  208. package/src/services/__tests__/access-control.proof-response-validation.test.ts +0 -578
  209. package/src/services/__tests__/access-control.service.test.ts +0 -970
  210. package/src/services/__tests__/batch-delegation.service.test.ts +0 -351
  211. package/src/services/__tests__/crypto.service.test.ts +0 -531
  212. package/src/services/__tests__/oauth-provider-registry.test.ts +0 -142
  213. package/src/services/__tests__/proof-verifier.integration.test.ts +0 -485
  214. package/src/services/__tests__/proof-verifier.test.ts +0 -489
  215. package/src/services/__tests__/provider-resolution.integration.test.ts +0 -202
  216. package/src/services/__tests__/provider-resolver.test.ts +0 -213
  217. package/src/services/__tests__/storage.service.test.ts +0 -358
  218. package/src/services/access-control.service.ts +0 -990
  219. package/src/services/authorization/authorization-registry.ts +0 -66
  220. package/src/services/authorization/types.ts +0 -71
  221. package/src/services/batch-delegation.service.ts +0 -137
  222. package/src/services/crypto.service.ts +0 -302
  223. package/src/services/errors.ts +0 -76
  224. package/src/services/index.ts +0 -18
  225. package/src/services/oauth-config.service.d.ts +0 -53
  226. package/src/services/oauth-config.service.d.ts.map +0 -1
  227. package/src/services/oauth-config.service.js.map +0 -1
  228. package/src/services/oauth-config.service.ts +0 -192
  229. package/src/services/oauth-provider-registry.d.ts +0 -57
  230. package/src/services/oauth-provider-registry.d.ts.map +0 -1
  231. package/src/services/oauth-provider-registry.js.map +0 -1
  232. package/src/services/oauth-provider-registry.ts +0 -141
  233. package/src/services/oauth-service.ts +0 -544
  234. package/src/services/oauth-token-retrieval.service.ts +0 -245
  235. package/src/services/proof-verifier.ts +0 -478
  236. package/src/services/provider-resolver.d.ts +0 -48
  237. package/src/services/provider-resolver.d.ts.map +0 -1
  238. package/src/services/provider-resolver.js.map +0 -1
  239. package/src/services/provider-resolver.ts +0 -146
  240. package/src/services/provider-validator.ts +0 -170
  241. package/src/services/session-registration.service.ts +0 -251
  242. package/src/services/storage.service.ts +0 -566
  243. package/src/services/tool-context-builder.ts +0 -237
  244. package/src/services/tool-protection.service.ts +0 -1070
  245. package/src/types/oauth-required-error.ts +0 -63
  246. package/src/types/tool-protection.ts +0 -155
  247. package/src/utils/__tests__/did-helpers.test.ts +0 -156
  248. package/src/utils/base58.ts +0 -109
  249. package/src/utils/base64.ts +0 -148
  250. package/src/utils/cors.ts +0 -83
  251. package/src/utils/did-helpers.ts +0 -210
  252. package/src/utils/index.ts +0 -8
  253. package/src/utils/storage-keys.ts +0 -278
  254. package/tsconfig.json +0 -21
  255. package/vitest.config.ts +0 -56
@@ -1,264 +0,0 @@
1
- /**
2
- * Remote Configuration Fetching
3
- *
4
- * Service for fetching configuration from remote APIs (AgentShield dashboard)
5
- * with caching support for performance optimization.
6
- *
7
- * @module @kya-os/mcp-i-core/config/remote-config
8
- */
9
-
10
- import type { MCPIConfig } from '@kya-os/contracts/config';
11
- import type { MergedMCPIServerConfig } from '@kya-os/contracts/dashboard-config';
12
- import type { ToolProtection, ToolProtectionMap } from '@kya-os/contracts/tool-protection';
13
- import { AGENTSHIELD_ENDPOINTS } from '@kya-os/contracts/agentshield-api';
14
-
15
- /**
16
- * Options for fetching remote configuration
17
- */
18
- export interface RemoteConfigOptions {
19
- /**
20
- * API base URL
21
- * @example 'https://kya.vouched.id'
22
- */
23
- apiUrl: string;
24
-
25
- /**
26
- * API key for authentication
27
- */
28
- apiKey: string;
29
-
30
- /**
31
- * Project ID (optional, preferred over agentDid)
32
- * Used for project-scoped configuration
33
- */
34
- projectId?: string;
35
-
36
- /**
37
- * Agent DID (optional, used when projectId not available)
38
- * Used for agent-scoped configuration
39
- */
40
- agentDid?: string;
41
-
42
- /**
43
- * Cache TTL in milliseconds
44
- * @default 300000 (5 minutes)
45
- */
46
- cacheTtl?: number;
47
-
48
- /**
49
- * Fetch provider function
50
- * Platform-agnostic fetch implementation
51
- */
52
- fetchProvider: (url: string, options: RequestInit) => Promise<Response>;
53
- }
54
-
55
- /**
56
- * Cache interface for remote configuration
57
- * Abstracts platform-specific caching (KV, Redis, Memory, etc.)
58
- */
59
- export interface RemoteConfigCache {
60
- /**
61
- * Get a cached value
62
- */
63
- get(key: string): Promise<string | null>;
64
-
65
- /**
66
- * Set a cached value with TTL
67
- */
68
- set(key: string, value: string, ttl: number): Promise<void>;
69
- }
70
-
71
- /**
72
- * Fetch configuration from remote API (AgentShield dashboard)
73
- *
74
- * Attempts to fetch configuration from the AgentShield API with caching support.
75
- * Falls back gracefully if remote fetch fails.
76
- *
77
- * @param options - Remote config options
78
- * @param cache - Optional cache implementation
79
- * @returns Configuration object or null if fetch fails
80
- */
81
- export async function fetchRemoteConfig(
82
- options: RemoteConfigOptions,
83
- cache?: RemoteConfigCache
84
- ): Promise<MCPIConfig | null> {
85
- const { apiUrl, apiKey, projectId, agentDid, cacheTtl = 300000, fetchProvider } = options;
86
-
87
- // Generate cache key
88
- const cacheKey = projectId
89
- ? `config:project:${projectId}`
90
- : agentDid
91
- ? `config:agent:${agentDid}`
92
- : null;
93
-
94
- // Try cache first
95
- if (cache && cacheKey) {
96
- try {
97
- const cached = await cache.get(cacheKey);
98
- if (cached) {
99
- try {
100
- const parsed = JSON.parse(cached) as { config: MCPIConfig; expiresAt: number };
101
- if (parsed.expiresAt > Date.now()) {
102
- return parsed.config;
103
- }
104
- } catch {
105
- // Invalid cache entry, continue to fetch
106
- }
107
- }
108
- } catch (error) {
109
- // Cache read failed, continue to fetch
110
- console.warn('[RemoteConfig] Cache read failed:', error);
111
- }
112
- }
113
-
114
- // Fetch from API
115
- try {
116
- // Build API URL
117
- let url: string;
118
- if (projectId) {
119
- // Use project-scoped endpoint (preferred)
120
- url = `${apiUrl}${AGENTSHIELD_ENDPOINTS.CONFIG(projectId)}`;
121
- } else if (agentDid) {
122
- // Use agent-scoped endpoint
123
- url = `${apiUrl}/api/v1/bouncer/config?agent_did=${encodeURIComponent(agentDid)}`;
124
- } else {
125
- console.warn('[RemoteConfig] Neither projectId nor agentDid provided');
126
- return null;
127
- }
128
-
129
- const response = await fetchProvider(url, {
130
- headers: {
131
- 'Authorization': `Bearer ${apiKey}`,
132
- 'Content-Type': 'application/json'
133
- }
134
- });
135
-
136
- if (!response.ok) {
137
- console.warn(`[RemoteConfig] API returned ${response.status}: ${response.statusText}`);
138
- return null;
139
- }
140
-
141
- const data = await response.json();
142
-
143
- // Extract config from API response
144
- // API response format: { success: boolean, data: { config: MCPIConfig } }
145
- const responseData = data as { config?: MCPIConfig; data?: { config?: MCPIConfig }; success?: boolean };
146
- const config = responseData.config || responseData.data?.config || (responseData.success ? responseData.data as MCPIConfig | null : null) as MCPIConfig | null;
147
-
148
- if (!config) {
149
- console.warn('[RemoteConfig] No config found in API response');
150
- return null;
151
- }
152
-
153
- // Cache the result
154
- if (cache && cacheKey) {
155
- try {
156
- await cache.set(
157
- cacheKey,
158
- JSON.stringify({
159
- config,
160
- expiresAt: Date.now() + cacheTtl
161
- }),
162
- cacheTtl
163
- );
164
- } catch (error) {
165
- // Cache write failed, but we got the config so continue
166
- console.warn('[RemoteConfig] Cache write failed:', error);
167
- }
168
- }
169
-
170
- return config as MCPIConfig;
171
- } catch (error) {
172
- console.warn('[RemoteConfig] Failed to fetch config:', error);
173
- return null;
174
- }
175
- }
176
-
177
- /**
178
- * Get tool protection for a specific tool from a merged config
179
- *
180
- * This helper function extracts tool protection from a merged config response.
181
- * It handles both the new format (toolProtection.tools) and returns null
182
- * for unprotected or unknown tools.
183
- *
184
- * @param config - Merged config object (must have toolProtection.tools)
185
- * @param toolName - Name of the tool to look up
186
- * @returns Tool protection or null if tool not protected or not found
187
- *
188
- * @since 1.6.0
189
- */
190
- export function getToolProtection(
191
- config: { toolProtection?: { tools?: ToolProtectionMap } },
192
- toolName: string
193
- ): ToolProtection | null {
194
- const tools = config?.toolProtection?.tools;
195
-
196
- if (!tools) {
197
- return null;
198
- }
199
-
200
- // Check for specific tool protection first
201
- let protection = tools[toolName];
202
-
203
- // Fall back to wildcard protection if specific tool not found
204
- if (!protection && tools['*']) {
205
- protection = tools['*'];
206
- }
207
-
208
- // Return null for unprotected tools (requiresDelegation: false) or unknown tools
209
- if (!protection || !protection.requiresDelegation) {
210
- return null;
211
- }
212
-
213
- return protection;
214
- }
215
-
216
- /**
217
- * Extract tool protections map from merged config
218
- *
219
- * This helper function extracts the tool protections map from a merged config.
220
- * Returns an empty object if no tools are found.
221
- *
222
- * @param config - Config object that may contain toolProtection.tools
223
- * @returns Tool protection map or empty object
224
- *
225
- * @since 1.6.0
226
- */
227
- export function extractToolProtections(
228
- config: { toolProtection?: { tools?: ToolProtectionMap } } | null | undefined
229
- ): ToolProtectionMap {
230
- if (!config?.toolProtection?.tools) {
231
- return {};
232
- }
233
- return config.toolProtection.tools;
234
- }
235
-
236
- /**
237
- * Check if config has embedded tool protections
238
- *
239
- * Utility to check if a config response is in the new merged format
240
- * with embedded tool protections.
241
- *
242
- * @param config - Config object to check
243
- * @returns True if config has embedded tools, false otherwise
244
- *
245
- * @since 1.6.0
246
- */
247
- export function hasMergedToolProtections(
248
- config: unknown
249
- ): config is { toolProtection: { tools: ToolProtectionMap } } {
250
- if (!config || typeof config !== 'object') {
251
- return false;
252
- }
253
-
254
- const c = config as { toolProtection?: { tools?: unknown } };
255
- return (
256
- c.toolProtection !== undefined &&
257
- typeof c.toolProtection === 'object' &&
258
- c.toolProtection !== null &&
259
- 'tools' in c.toolProtection &&
260
- typeof c.toolProtection.tools === 'object' &&
261
- c.toolProtection.tools !== null // typeof null === 'object' in JS
262
- );
263
- }
264
-
package/src/config.ts DELETED
@@ -1,312 +0,0 @@
1
- /**
2
- * Provider-based Runtime Configuration
3
- *
4
- * Core configuration for MCP-I runtime using the provider pattern.
5
- * This is the foundation for all platform-specific implementations.
6
- *
7
- * @module @kya-os/mcp-i-core/config
8
- */
9
-
10
- import type {
11
- MCPIBaseConfig,
12
- RuntimeIdentityConfig,
13
- ProofingConfig,
14
- DelegationConfig,
15
- ToolProtectionSourceConfig
16
- } from '@kya-os/contracts/config';
17
-
18
- import type {
19
- CryptoProvider,
20
- ClockProvider,
21
- FetchProvider,
22
- StorageProvider,
23
- NonceCacheProvider,
24
- IdentityProvider
25
- } from './providers/base';
26
-
27
- import type { ToolProtectionService } from './services/tool-protection.service';
28
-
29
- /**
30
- * Provider-based runtime configuration
31
- *
32
- * This configuration is used internally by MCPIRuntimeBase and provides
33
- * the foundation for all platform-specific implementations. It uses the
34
- * provider pattern for platform abstraction, allowing different implementations
35
- * for Node.js, Cloudflare Workers, and other environments.
36
- */
37
- export interface ProviderRuntimeConfig extends MCPIBaseConfig {
38
- /**
39
- * Cryptographic operations provider
40
- * Handles signing, verification, and key generation
41
- */
42
- cryptoProvider: CryptoProvider;
43
-
44
- /**
45
- * Time operations provider
46
- * Provides current time and timestamp generation
47
- */
48
- clockProvider: ClockProvider;
49
-
50
- /**
51
- * HTTP fetch operations provider
52
- * Handles external API calls
53
- */
54
- fetchProvider: FetchProvider;
55
-
56
- /**
57
- * Storage operations provider
58
- * Handles persistent data storage
59
- */
60
- storageProvider: StorageProvider;
61
-
62
- /**
63
- * Nonce cache provider
64
- * Handles replay prevention
65
- */
66
- nonceCacheProvider: NonceCacheProvider;
67
-
68
- /**
69
- * Identity management provider
70
- * Handles agent identity and DID operations
71
- */
72
- identityProvider: IdentityProvider;
73
-
74
- /**
75
- * Session configuration
76
- * Controls session handling and timeouts
77
- */
78
- session?: {
79
- /**
80
- * Allowed timestamp skew in seconds
81
- * @default 120
82
- */
83
- timestampSkewSeconds?: number;
84
-
85
- /**
86
- * Session TTL in minutes
87
- * @default 30
88
- */
89
- ttlMinutes?: number;
90
- };
91
-
92
- /**
93
- * Identity configuration (optional)
94
- * When provided, enables identity features
95
- */
96
- identity?: RuntimeIdentityConfig;
97
-
98
- /**
99
- * Proofing configuration (optional)
100
- * When provided, enables proof generation
101
- */
102
- proofing?: ProofingConfig;
103
-
104
- /**
105
- * Delegation configuration (optional)
106
- * When provided, enables delegation verification
107
- */
108
- delegation?: DelegationConfig;
109
-
110
- /**
111
- * Tool protection service (optional)
112
- * When provided, enables runtime tool protection
113
- * Note: This is different from tool registry which is compile-time
114
- */
115
- toolProtectionService?: ToolProtectionService;
116
-
117
- /**
118
- * Tool protection source configuration (optional)
119
- * Alternative to toolProtectionService for configuration-based setup
120
- */
121
- toolProtection?: ToolProtectionSourceConfig;
122
- }
123
-
124
- /**
125
- * Builder for provider runtime configuration
126
- * Helps create valid configurations with proper defaults
127
- */
128
- export class ProviderRuntimeConfigBuilder {
129
- private config: Partial<ProviderRuntimeConfig> = {
130
- environment: 'development'
131
- };
132
-
133
- /**
134
- * Set the providers (required)
135
- */
136
- withProviders(providers: {
137
- cryptoProvider: CryptoProvider;
138
- clockProvider: ClockProvider;
139
- fetchProvider: FetchProvider;
140
- storageProvider: StorageProvider;
141
- nonceCacheProvider: NonceCacheProvider;
142
- identityProvider: IdentityProvider;
143
- }): this {
144
- Object.assign(this.config, providers);
145
- return this;
146
- }
147
-
148
- /**
149
- * Set the environment
150
- */
151
- withEnvironment(env: 'development' | 'production'): this {
152
- this.config.environment = env;
153
- return this;
154
- }
155
-
156
- /**
157
- * Configure session handling
158
- */
159
- withSession(session: {
160
- timestampSkewSeconds?: number;
161
- ttlMinutes?: number;
162
- }): this {
163
- this.config.session = session;
164
- return this;
165
- }
166
-
167
- /**
168
- * Enable identity features
169
- */
170
- withIdentity(identity: RuntimeIdentityConfig): this {
171
- this.config.identity = identity;
172
- return this;
173
- }
174
-
175
- /**
176
- * Enable proofing features
177
- */
178
- withProofing(proofing: ProofingConfig): this {
179
- this.config.proofing = proofing;
180
- return this;
181
- }
182
-
183
- /**
184
- * Enable delegation features
185
- */
186
- withDelegation(delegation: DelegationConfig): this {
187
- this.config.delegation = delegation;
188
- return this;
189
- }
190
-
191
- /**
192
- * Set tool protection service
193
- */
194
- withToolProtectionService(service: ToolProtectionService): this {
195
- this.config.toolProtectionService = service;
196
- return this;
197
- }
198
-
199
- /**
200
- * Set tool protection configuration
201
- */
202
- withToolProtection(config: ToolProtectionSourceConfig): this {
203
- this.config.toolProtection = config;
204
- return this;
205
- }
206
-
207
- /**
208
- * Enable audit features
209
- */
210
- withAudit(audit: {
211
- enabled: boolean;
212
- includeProofHashes?: boolean;
213
- }): this {
214
- this.config.audit = audit;
215
- return this;
216
- }
217
-
218
- /**
219
- * Enable well-known endpoints
220
- */
221
- withWellKnown(wellKnown: {
222
- enabled: boolean;
223
- serviceName?: string;
224
- }): this {
225
- this.config.wellKnown = wellKnown;
226
- return this;
227
- }
228
-
229
- /**
230
- * Build the configuration
231
- * Validates that all required providers are set
232
- */
233
- build(): ProviderRuntimeConfig {
234
- const required = [
235
- 'cryptoProvider',
236
- 'clockProvider',
237
- 'fetchProvider',
238
- 'storageProvider',
239
- 'nonceCacheProvider',
240
- 'identityProvider'
241
- ];
242
-
243
- for (const field of required) {
244
- if (!(field in this.config)) {
245
- throw new Error(`Missing required provider: ${field}`);
246
- }
247
- }
248
-
249
- // Apply defaults
250
- return {
251
- environment: 'development',
252
- session: {
253
- timestampSkewSeconds: 120,
254
- ttlMinutes: 30
255
- },
256
- ...this.config
257
- } as ProviderRuntimeConfig;
258
- }
259
- }
260
-
261
- /**
262
- * Re-export base types for convenience
263
- */
264
- export type {
265
- MCPIBaseConfig,
266
- RuntimeIdentityConfig as BaseIdentityConfig,
267
- ProofingConfig,
268
- DelegationConfig,
269
- ToolProtectionSourceConfig
270
- } from '@kya-os/contracts/config';
271
-
272
- /**
273
- * Re-export remote config utilities
274
- */
275
- export {
276
- fetchRemoteConfig,
277
- getToolProtection,
278
- extractToolProtections,
279
- hasMergedToolProtections,
280
- type RemoteConfigOptions,
281
- type RemoteConfigCache
282
- } from './config/remote-config';
283
-
284
- /**
285
- * Create a provider runtime configuration
286
- * Convenience function for creating configurations
287
- */
288
- export function createProviderRuntimeConfig(
289
- providers: {
290
- cryptoProvider: CryptoProvider;
291
- clockProvider: ClockProvider;
292
- fetchProvider: FetchProvider;
293
- storageProvider: StorageProvider;
294
- nonceCacheProvider: NonceCacheProvider;
295
- identityProvider: IdentityProvider;
296
- },
297
- options?: Partial<Omit<ProviderRuntimeConfig, keyof typeof providers>>
298
- ): ProviderRuntimeConfig {
299
- return new ProviderRuntimeConfigBuilder()
300
- .withProviders(providers)
301
- .withEnvironment(options?.environment || 'development')
302
- .withSession(options?.session || {})
303
- .withIdentity(options?.identity || { enabled: false, environment: 'development' })
304
- .withProofing(options?.proofing || { enabled: false })
305
- .withDelegation(options?.delegation || {
306
- enabled: false,
307
- verifier: { type: 'memory' }
308
- })
309
- .withAudit(options?.audit || { enabled: false })
310
- .withWellKnown(options?.wellKnown || { enabled: true })
311
- .build();
312
- }
@@ -1,112 +0,0 @@
1
- /**
2
- * Tests for Delegation Audience Validation
3
- *
4
- * @package @kya-os/mcp-i-core/delegation/__tests__
5
- */
6
-
7
- import { describe, it, expect } from "vitest";
8
- import { verifyDelegationAudience } from "../audience-validator";
9
- import type { DelegationRecord } from "@kya-os/contracts/delegation";
10
-
11
- describe("verifyDelegationAudience", () => {
12
- const serverDid = "did:web:server.example.com";
13
-
14
- it("should return true when delegation has no audience", () => {
15
- const delegation: DelegationRecord = {
16
- id: "del_001",
17
- issuerDid: "did:web:user.com",
18
- subjectDid: "did:key:zagent123",
19
- controller: "user_alice",
20
- vcId: "vc_001",
21
- constraints: {
22
- scopes: ["tool:execute"],
23
- // No audience field
24
- },
25
- createdAt: Date.now(),
26
- expiresAt: Date.now() + 3600000,
27
- };
28
-
29
- expect(verifyDelegationAudience(delegation, serverDid)).toBe(true);
30
- });
31
-
32
- it("should return true when delegation audience matches server DID", () => {
33
- const delegation: DelegationRecord = {
34
- id: "del_002",
35
- issuerDid: "did:web:user.com",
36
- subjectDid: "did:key:zagent123",
37
- controller: "user_bob",
38
- vcId: "vc_002",
39
- constraints: {
40
- scopes: ["tool:execute"],
41
- audience: serverDid, // Matches server DID
42
- },
43
- createdAt: Date.now(),
44
- expiresAt: Date.now() + 3600000,
45
- };
46
-
47
- expect(verifyDelegationAudience(delegation, serverDid)).toBe(true);
48
- });
49
-
50
- it("should return false when delegation audience does not match server DID", () => {
51
- const delegation: DelegationRecord = {
52
- id: "del_003",
53
- issuerDid: "did:web:user.com",
54
- subjectDid: "did:key:zagent123",
55
- controller: "user_charlie",
56
- vcId: "vc_003",
57
- constraints: {
58
- scopes: ["tool:execute"],
59
- audience: "did:web:other-server.com", // Different server
60
- },
61
- createdAt: Date.now(),
62
- expiresAt: Date.now() + 3600000,
63
- };
64
-
65
- expect(verifyDelegationAudience(delegation, serverDid)).toBe(false);
66
- });
67
-
68
- it("should return true when server DID is in audience array", () => {
69
- const delegation: DelegationRecord = {
70
- id: "del_004",
71
- issuerDid: "did:web:user.com",
72
- subjectDid: "did:key:zagent123",
73
- controller: "user_dave",
74
- vcId: "vc_004",
75
- constraints: {
76
- scopes: ["tool:execute"],
77
- audience: [
78
- "did:web:server1.com",
79
- serverDid, // Server DID is in array
80
- "did:web:server3.com",
81
- ],
82
- },
83
- createdAt: Date.now(),
84
- expiresAt: Date.now() + 3600000,
85
- };
86
-
87
- expect(verifyDelegationAudience(delegation, serverDid)).toBe(true);
88
- });
89
-
90
- it("should return false when server DID is not in audience array", () => {
91
- const delegation: DelegationRecord = {
92
- id: "del_005",
93
- issuerDid: "did:web:user.com",
94
- subjectDid: "did:key:zagent123",
95
- controller: "user_eve",
96
- vcId: "vc_005",
97
- constraints: {
98
- scopes: ["tool:execute"],
99
- audience: [
100
- "did:web:server1.com",
101
- "did:web:server2.com",
102
- // serverDid not in array
103
- ],
104
- },
105
- createdAt: Date.now(),
106
- expiresAt: Date.now() + 3600000,
107
- };
108
-
109
- expect(verifyDelegationAudience(delegation, serverDid)).toBe(false);
110
- });
111
- });
112
-