@kya-os/mcp-i 0.1.0-alpha.3.9 → 1.2.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 (328) hide show
  1. package/README.md +350 -213
  2. package/dist/149.js +1 -0
  3. package/dist/189.js +1 -0
  4. package/dist/261.js +1 -0
  5. package/dist/28.js +1 -0
  6. package/dist/295.js +1 -0
  7. package/dist/460.js +1 -0
  8. package/dist/570.js +1 -0
  9. package/dist/634.js +1 -0
  10. package/dist/647.js +1 -0
  11. package/dist/67.js +1 -0
  12. package/dist/739.js +1 -0
  13. package/dist/742.js +1 -0
  14. package/dist/904.js +1 -0
  15. package/dist/938.js +1 -0
  16. package/dist/auth/api-key.d.ts +16 -0
  17. package/dist/auth/api-key.js +82 -0
  18. package/dist/auth/jwt.d.ts +43 -0
  19. package/dist/auth/jwt.js +51 -0
  20. package/dist/auth/oauth/factory.d.ts +12 -0
  21. package/dist/auth/oauth/factory.js +36 -0
  22. package/dist/auth/oauth/index.d.ts +5 -0
  23. package/dist/auth/oauth/index.js +27 -0
  24. package/dist/auth/oauth/providers/proxy-provider.d.ts +13 -0
  25. package/dist/auth/oauth/providers/proxy-provider.js +159 -0
  26. package/dist/auth/oauth/router.d.ts +4 -0
  27. package/dist/auth/oauth/router.js +294 -0
  28. package/dist/auth/oauth/storage/memory-storage.d.ts +12 -0
  29. package/dist/auth/oauth/storage/memory-storage.js +40 -0
  30. package/dist/auth/oauth/types.d.ts +112 -0
  31. package/dist/cache/__tests__/cloudflare-kv-nonce-cache.test.d.ts +4 -0
  32. package/dist/cache/__tests__/cloudflare-kv-nonce-cache.test.js +176 -0
  33. package/dist/cache/__tests__/concurrency.test.d.ts +5 -0
  34. package/dist/cache/__tests__/concurrency.test.js +300 -0
  35. package/dist/cache/__tests__/dynamodb-nonce-cache.test.d.ts +4 -0
  36. package/dist/cache/__tests__/dynamodb-nonce-cache.test.js +176 -0
  37. package/dist/cache/__tests__/memory-nonce-cache.test.d.ts +4 -0
  38. package/dist/cache/__tests__/memory-nonce-cache.test.js +132 -0
  39. package/dist/cache/__tests__/nonce-cache-factory-simple.test.d.ts +4 -0
  40. package/dist/cache/__tests__/nonce-cache-factory-simple.test.js +133 -0
  41. package/dist/cache/__tests__/nonce-cache-factory.test.d.ts +4 -0
  42. package/dist/cache/__tests__/nonce-cache-factory.test.js +252 -0
  43. package/dist/cache/__tests__/redis-nonce-cache.test.d.ts +4 -0
  44. package/dist/cache/__tests__/redis-nonce-cache.test.js +95 -0
  45. package/dist/cache/cloudflare-kv-nonce-cache.d.ts +14 -0
  46. package/dist/cache/cloudflare-kv-nonce-cache.js +93 -0
  47. package/dist/cache/dynamodb-nonce-cache.d.ts +15 -0
  48. package/dist/cache/dynamodb-nonce-cache.js +92 -0
  49. package/dist/cache/index.d.ts +16 -0
  50. package/dist/cache/index.js +32 -0
  51. package/dist/cache/memory-nonce-cache.d.ts +44 -0
  52. package/dist/cache/memory-nonce-cache.js +105 -0
  53. package/dist/cache/nonce-cache-factory.d.ts +20 -0
  54. package/dist/cache/nonce-cache-factory.js +208 -0
  55. package/dist/cache/redis-nonce-cache.d.ts +14 -0
  56. package/dist/cache/redis-nonce-cache.js +53 -0
  57. package/dist/compiler/compiler-context.d.ts +23 -0
  58. package/dist/compiler/compiler-context.js +24 -0
  59. package/dist/compiler/config/constants.d.ts +41 -0
  60. package/dist/compiler/config/constants.js +45 -0
  61. package/dist/compiler/config/index.d.ts +252 -0
  62. package/dist/compiler/config/index.js +15 -0
  63. package/dist/compiler/config/injection.d.ts +26 -0
  64. package/dist/compiler/config/injection.js +58 -0
  65. package/dist/compiler/config/schemas/experimental/index.d.ts +91 -0
  66. package/dist/compiler/config/schemas/experimental/index.js +16 -0
  67. package/dist/compiler/config/schemas/experimental/oauth.d.ts +74 -0
  68. package/dist/compiler/config/schemas/experimental/oauth.js +25 -0
  69. package/dist/compiler/config/schemas/index.d.ts +6 -0
  70. package/dist/compiler/config/schemas/index.js +17 -0
  71. package/dist/compiler/config/schemas/paths.d.ts +9 -0
  72. package/dist/compiler/config/schemas/paths.js +12 -0
  73. package/dist/compiler/config/schemas/transport/http.d.ts +82 -0
  74. package/dist/compiler/config/schemas/transport/http.js +33 -0
  75. package/dist/compiler/config/schemas/transport/stdio.d.ts +9 -0
  76. package/dist/compiler/config/schemas/transport/stdio.js +15 -0
  77. package/dist/compiler/config/schemas/webpack.d.ts +3 -0
  78. package/dist/compiler/config/schemas/webpack.js +15 -0
  79. package/dist/compiler/config/types.d.ts +1 -0
  80. package/dist/compiler/config/types.js +2 -0
  81. package/dist/compiler/config/utils.d.ts +20 -0
  82. package/dist/compiler/config/utils.js +36 -0
  83. package/dist/compiler/generate-env-code.d.ts +1 -0
  84. package/dist/compiler/generate-env-code.js +8 -0
  85. package/dist/compiler/generate-import-code.d.ts +1 -0
  86. package/dist/compiler/generate-import-code.js +24 -0
  87. package/dist/compiler/get-webpack-config/get-entries.d.ts +3 -0
  88. package/dist/compiler/get-webpack-config/get-entries.js +29 -0
  89. package/dist/compiler/get-webpack-config/get-externals.d.ts +7 -0
  90. package/dist/compiler/get-webpack-config/get-externals.js +88 -0
  91. package/dist/compiler/get-webpack-config/get-injected-variables.d.ts +8 -0
  92. package/dist/compiler/get-webpack-config/get-injected-variables.js +25 -0
  93. package/dist/compiler/get-webpack-config/index.d.ts +4 -0
  94. package/dist/compiler/get-webpack-config/index.js +101 -0
  95. package/dist/compiler/get-webpack-config/plugins.d.ts +8 -0
  96. package/dist/compiler/get-webpack-config/plugins.js +132 -0
  97. package/dist/compiler/get-webpack-config/resolve-tsconfig-paths.d.ts +9 -0
  98. package/dist/compiler/get-webpack-config/resolve-tsconfig-paths.js +40 -0
  99. package/dist/compiler/index.d.ts +6 -0
  100. package/dist/compiler/index.js +194 -0
  101. package/dist/compiler/on-first-build.d.ts +3 -0
  102. package/dist/compiler/on-first-build.js +58 -0
  103. package/dist/compiler/parse-xmcp-config.d.ts +9 -0
  104. package/dist/compiler/parse-xmcp-config.js +155 -0
  105. package/dist/compiler/start-http-server.d.ts +1 -0
  106. package/dist/compiler/start-http-server.js +34 -0
  107. package/dist/index.d.ts +12 -0
  108. package/dist/index.js +38 -0
  109. package/dist/index.js.LICENSE.txt +49 -0
  110. package/dist/runtime/__tests__/audit.test.d.ts +4 -0
  111. package/dist/runtime/__tests__/audit.test.js +328 -0
  112. package/dist/runtime/__tests__/identity.test.d.ts +4 -0
  113. package/dist/runtime/__tests__/identity.test.js +164 -0
  114. package/dist/runtime/__tests__/mcpi-runtime.test.d.ts +4 -0
  115. package/dist/runtime/__tests__/mcpi-runtime.test.js +372 -0
  116. package/dist/runtime/__tests__/proof.test.d.ts +4 -0
  117. package/dist/runtime/__tests__/proof.test.js +302 -0
  118. package/dist/runtime/__tests__/session.test.d.ts +4 -0
  119. package/dist/runtime/__tests__/session.test.js +254 -0
  120. package/dist/runtime/__tests__/well-known.test.d.ts +4 -0
  121. package/dist/runtime/__tests__/well-known.test.js +312 -0
  122. package/dist/runtime/adapter-express.js +2 -0
  123. package/dist/runtime/adapter-express.js.LICENSE.txt +252 -0
  124. package/dist/runtime/adapter-nextjs.js +2 -0
  125. package/dist/runtime/adapter-nextjs.js.LICENSE.txt +53 -0
  126. package/dist/runtime/adapters/express/index.d.ts +2 -0
  127. package/dist/runtime/adapters/express/index.js +48 -0
  128. package/dist/runtime/adapters/nextjs/index.d.ts +8 -0
  129. package/dist/runtime/adapters/nextjs/index.js +18 -0
  130. package/dist/runtime/audit.d.ts +93 -0
  131. package/dist/runtime/audit.js +212 -0
  132. package/dist/runtime/debug.d.ts +118 -0
  133. package/dist/runtime/debug.js +612 -0
  134. package/dist/runtime/delegation-hooks.d.ts +85 -0
  135. package/dist/runtime/delegation-hooks.js +116 -0
  136. package/dist/runtime/demo.d.ts +71 -0
  137. package/dist/runtime/demo.js +135 -0
  138. package/dist/runtime/headers.d.ts +1 -0
  139. package/dist/runtime/headers.js +9 -0
  140. package/dist/runtime/http.js +2 -0
  141. package/dist/runtime/http.js.LICENSE.txt +252 -0
  142. package/dist/runtime/identity.d.ts +105 -0
  143. package/dist/runtime/identity.js +232 -0
  144. package/dist/runtime/index.d.ts +16 -0
  145. package/dist/runtime/index.js +56 -0
  146. package/dist/runtime/mcpi-runtime.d.ts +164 -0
  147. package/dist/runtime/mcpi-runtime.js +352 -0
  148. package/dist/runtime/proof.d.ts +87 -0
  149. package/dist/runtime/proof.js +223 -0
  150. package/dist/runtime/session.d.ts +88 -0
  151. package/dist/runtime/session.js +216 -0
  152. package/dist/runtime/stdio.js +2 -0
  153. package/dist/runtime/stdio.js.LICENSE.txt +1 -0
  154. package/dist/runtime/templates/home.d.ts +2 -0
  155. package/dist/runtime/templates/home.js +50 -0
  156. package/dist/runtime/transports/http/base-streamable-http.d.ts +25 -0
  157. package/dist/runtime/transports/http/base-streamable-http.js +16 -0
  158. package/dist/runtime/transports/http/http-context.d.ts +9 -0
  159. package/dist/runtime/transports/http/http-context.js +8 -0
  160. package/dist/runtime/transports/http/index.js +55 -0
  161. package/dist/runtime/transports/http/setup-cors.d.ts +4 -0
  162. package/dist/runtime/transports/http/setup-cors.js +24 -0
  163. package/dist/runtime/transports/http/stateless-streamable-http.d.ts +39 -0
  164. package/dist/runtime/transports/http/stateless-streamable-http.js +331 -0
  165. package/dist/runtime/transports/stdio/index.d.ts +1 -0
  166. package/dist/runtime/transports/stdio/index.js +51 -0
  167. package/dist/runtime/utils/server.d.ts +42 -0
  168. package/dist/runtime/utils/server.js +39 -0
  169. package/dist/runtime/utils/tools.d.ts +8 -0
  170. package/dist/runtime/utils/tools.js +115 -0
  171. package/dist/runtime/verifier-middleware.d.ts +76 -0
  172. package/dist/runtime/verifier-middleware.js +322 -0
  173. package/dist/runtime/well-known.d.ts +151 -0
  174. package/dist/runtime/well-known.js +258 -0
  175. package/dist/storage/config.d.ts +28 -0
  176. package/dist/storage/config.js +79 -0
  177. package/dist/storage/delegation.d.ts +59 -0
  178. package/dist/storage/delegation.js +130 -0
  179. package/dist/storage/merkle-verifier.d.ts +84 -0
  180. package/dist/storage/merkle-verifier.js +261 -0
  181. package/dist/test/__tests__/nonce-cache-integration.test.d.ts +1 -0
  182. package/dist/test/__tests__/nonce-cache-integration.test.js +116 -0
  183. package/dist/test/__tests__/nonce-cache.test.d.ts +1 -0
  184. package/dist/test/__tests__/nonce-cache.test.js +122 -0
  185. package/dist/test/__tests__/runtime-integration.test.d.ts +4 -0
  186. package/dist/test/__tests__/runtime-integration.test.js +192 -0
  187. package/dist/test/__tests__/test-infrastructure.test.d.ts +4 -0
  188. package/dist/test/__tests__/test-infrastructure.test.js +178 -0
  189. package/dist/test/deterministic-keys.d.ts +31 -0
  190. package/dist/test/deterministic-keys.js +108 -0
  191. package/dist/test/examples/test-usage-example.d.ts +140 -0
  192. package/dist/test/examples/test-usage-example.js +175 -0
  193. package/dist/test/index.d.ts +11 -0
  194. package/dist/test/index.js +27 -0
  195. package/dist/test/local-verification.d.ts +28 -0
  196. package/dist/test/local-verification.js +342 -0
  197. package/dist/test/mock-identity-provider.d.ts +96 -0
  198. package/dist/test/mock-identity-provider.js +243 -0
  199. package/dist/test/runtime-integration.d.ts +63 -0
  200. package/dist/test/runtime-integration.js +140 -0
  201. package/dist/test/test-environment.d.ts +26 -0
  202. package/dist/test/test-environment.js +50 -0
  203. package/dist/types/declarations.d.ts +1 -0
  204. package/dist/types/declarations.js +6 -0
  205. package/dist/types/middleware.d.ts +2 -0
  206. package/dist/types/middleware.js +2 -0
  207. package/dist/types/tool.d.ts +80 -0
  208. package/dist/types/tool.js +2 -0
  209. package/dist/utils/cli-icons.d.ts +3 -0
  210. package/dist/utils/cli-icons.js +7 -0
  211. package/dist/utils/constants.d.ts +6 -0
  212. package/dist/utils/constants.js +13 -0
  213. package/dist/utils/context.d.ts +33 -0
  214. package/dist/utils/context.js +58 -0
  215. package/dist/utils/file-watcher.d.ts +19 -0
  216. package/dist/utils/file-watcher.js +49 -0
  217. package/dist/utils/fs-utils.d.ts +2 -0
  218. package/dist/utils/fs-utils.js +22 -0
  219. package/dist/utils/path-validation.d.ts +3 -0
  220. package/dist/utils/path-validation.js +56 -0
  221. package/dist/utils/spawn-process.d.ts +9 -0
  222. package/dist/utils/spawn-process.js +50 -0
  223. package/dist/utils/subscribable.d.ts +12 -0
  224. package/dist/utils/subscribable.js +44 -0
  225. package/package.json +91 -77
  226. package/dist/cjs/auto.js +0 -16
  227. package/dist/cjs/cli-mode.d.ts +0 -16
  228. package/dist/cjs/cli-mode.js +0 -32
  229. package/dist/cjs/crypto.d.ts +0 -16
  230. package/dist/cjs/crypto.js +0 -212
  231. package/dist/cjs/dev-helper.d.ts +0 -3
  232. package/dist/cjs/dev-helper.js +0 -46
  233. package/dist/cjs/encrypted-storage.d.ts +0 -11
  234. package/dist/cjs/encrypted-storage.js +0 -73
  235. package/dist/cjs/index.d.ts +0 -56
  236. package/dist/cjs/index.js +0 -727
  237. package/dist/cjs/logger.d.ts +0 -32
  238. package/dist/cjs/logger.js +0 -85
  239. package/dist/cjs/nextjs.d.ts +0 -10
  240. package/dist/cjs/nextjs.js +0 -83
  241. package/dist/cjs/platform-info.d.ts +0 -36
  242. package/dist/cjs/platform-info.js +0 -274
  243. package/dist/cjs/polling.d.ts +0 -13
  244. package/dist/cjs/polling.js +0 -52
  245. package/dist/cjs/registry/index.d.ts +0 -12
  246. package/dist/cjs/registry/index.js +0 -56
  247. package/dist/cjs/registry/knowthat.d.ts +0 -17
  248. package/dist/cjs/registry/knowthat.js +0 -173
  249. package/dist/cjs/rotation.d.ts +0 -35
  250. package/dist/cjs/rotation.js +0 -102
  251. package/dist/cjs/storage.d.ts +0 -41
  252. package/dist/cjs/storage.js +0 -163
  253. package/dist/cjs/transport.d.ts +0 -35
  254. package/dist/cjs/transport.js +0 -300
  255. package/dist/cjs/types.d.ts +0 -206
  256. package/dist/cjs/vercel-adapter.d.ts +0 -8
  257. package/dist/cjs/vercel-adapter.js +0 -67
  258. package/dist/esm/auto.d.ts +0 -13
  259. package/dist/esm/auto.d.ts.map +0 -1
  260. package/dist/esm/auto.js +0 -30
  261. package/dist/esm/auto.js.map +0 -1
  262. package/dist/esm/cli-mode.d.ts +0 -52
  263. package/dist/esm/cli-mode.d.ts.map +0 -1
  264. package/dist/esm/cli-mode.js +0 -59
  265. package/dist/esm/cli-mode.js.map +0 -1
  266. package/dist/esm/crypto.d.ts +0 -51
  267. package/dist/esm/crypto.d.ts.map +0 -1
  268. package/dist/esm/crypto.js +0 -230
  269. package/dist/esm/crypto.js.map +0 -1
  270. package/dist/esm/dev-helper.d.ts +0 -15
  271. package/dist/esm/dev-helper.d.ts.map +0 -1
  272. package/dist/esm/dev-helper.js +0 -63
  273. package/dist/esm/dev-helper.js.map +0 -1
  274. package/dist/esm/encrypted-storage.d.ts +0 -19
  275. package/dist/esm/encrypted-storage.d.ts.map +0 -1
  276. package/dist/esm/encrypted-storage.js +0 -48
  277. package/dist/esm/encrypted-storage.js.map +0 -1
  278. package/dist/esm/index.d.ts +0 -129
  279. package/dist/esm/index.d.ts.map +0 -1
  280. package/dist/esm/index.js +0 -853
  281. package/dist/esm/index.js.map +0 -1
  282. package/dist/esm/logger.d.ts +0 -46
  283. package/dist/esm/logger.d.ts.map +0 -1
  284. package/dist/esm/logger.js +0 -100
  285. package/dist/esm/logger.js.map +0 -1
  286. package/dist/esm/nextjs.d.ts +0 -22
  287. package/dist/esm/nextjs.d.ts.map +0 -1
  288. package/dist/esm/nextjs.js +0 -83
  289. package/dist/esm/nextjs.js.map +0 -1
  290. package/dist/esm/package.json +0 -1
  291. package/dist/esm/platform-info.d.ts +0 -74
  292. package/dist/esm/platform-info.d.ts.map +0 -1
  293. package/dist/esm/platform-info.js +0 -293
  294. package/dist/esm/platform-info.js.map +0 -1
  295. package/dist/esm/polling.d.ts +0 -29
  296. package/dist/esm/polling.d.ts.map +0 -1
  297. package/dist/esm/polling.js +0 -76
  298. package/dist/esm/polling.js.map +0 -1
  299. package/dist/esm/registry/index.d.ts +0 -43
  300. package/dist/esm/registry/index.d.ts.map +0 -1
  301. package/dist/esm/registry/index.js +0 -89
  302. package/dist/esm/registry/index.js.map +0 -1
  303. package/dist/esm/registry/knowthat.d.ts +0 -44
  304. package/dist/esm/registry/knowthat.d.ts.map +0 -1
  305. package/dist/esm/registry/knowthat.js +0 -220
  306. package/dist/esm/registry/knowthat.js.map +0 -1
  307. package/dist/esm/rotation.d.ts +0 -57
  308. package/dist/esm/rotation.d.ts.map +0 -1
  309. package/dist/esm/rotation.js +0 -133
  310. package/dist/esm/rotation.js.map +0 -1
  311. package/dist/esm/storage.d.ts +0 -65
  312. package/dist/esm/storage.d.ts.map +0 -1
  313. package/dist/esm/storage.js +0 -160
  314. package/dist/esm/storage.js.map +0 -1
  315. package/dist/esm/transport.d.ts +0 -52
  316. package/dist/esm/transport.d.ts.map +0 -1
  317. package/dist/esm/transport.js +0 -340
  318. package/dist/esm/transport.js.map +0 -1
  319. package/dist/esm/types.d.ts +0 -293
  320. package/dist/esm/types.d.ts.map +0 -1
  321. package/dist/esm/types.js +0 -5
  322. package/dist/esm/types.js.map +0 -1
  323. package/dist/esm/vercel-adapter.d.ts +0 -26
  324. package/dist/esm/vercel-adapter.d.ts.map +0 -1
  325. package/dist/esm/vercel-adapter.js +0 -80
  326. package/dist/esm/vercel-adapter.js.map +0 -1
  327. /package/dist/{cjs → auth/oauth}/types.js +0 -0
  328. /package/dist/{cjs/auto.d.ts → runtime/transports/http/index.d.ts} +0 -0
@@ -0,0 +1,164 @@
1
+ "use strict";
2
+ /**
3
+ * Tests for Identity Management System
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const vitest_1 = require("vitest");
7
+ const fs_1 = require("fs");
8
+ const promises_1 = require("fs/promises");
9
+ const path_1 = require("path");
10
+ const identity_js_1 = require("../identity.js");
11
+ // Mock environment variables
12
+ const originalEnv = process.env;
13
+ (0, vitest_1.describe)("IdentityManager", () => {
14
+ let tempDir;
15
+ let identityManager;
16
+ (0, vitest_1.beforeEach)(async () => {
17
+ // Create temp directory for tests
18
+ tempDir = (0, path_1.join)(process.cwd(), ".test-mcpi");
19
+ await (0, promises_1.mkdir)(tempDir, { recursive: true });
20
+ // Reset environment
21
+ process.env = { ...originalEnv };
22
+ delete process.env.AGENT_PRIVATE_KEY;
23
+ delete process.env.AGENT_KEY_ID;
24
+ delete process.env.AGENT_DID;
25
+ delete process.env.KYA_VOUCHED_API_KEY;
26
+ });
27
+ (0, vitest_1.afterEach)(async () => {
28
+ // Cleanup
29
+ try {
30
+ if ((0, fs_1.existsSync)(tempDir)) {
31
+ await (0, promises_1.rmdir)(tempDir, { recursive: true });
32
+ }
33
+ }
34
+ catch (error) {
35
+ // Ignore cleanup errors
36
+ }
37
+ // Restore environment
38
+ process.env = originalEnv;
39
+ });
40
+ (0, vitest_1.describe)("Development Environment", () => {
41
+ (0, vitest_1.beforeEach)(() => {
42
+ identityManager = new identity_js_1.IdentityManager({
43
+ environment: "development",
44
+ devIdentityPath: (0, path_1.join)(tempDir, "identity.json"),
45
+ });
46
+ });
47
+ (0, vitest_1.it)("should generate new identity when none exists", async () => {
48
+ const identity = await identityManager.ensureIdentity();
49
+ (0, vitest_1.expect)(identity).toBeDefined();
50
+ (0, vitest_1.expect)(identity.did).toMatch(/^did:web:localhost:3000:agents:key-[a-f0-9]{8}$/);
51
+ (0, vitest_1.expect)(identity.keyId).toMatch(/^key-[a-f0-9]{8}$/);
52
+ (0, vitest_1.expect)(identity.privateKey).toBeTruthy();
53
+ (0, vitest_1.expect)(identity.publicKey).toBeTruthy();
54
+ (0, vitest_1.expect)(identity.createdAt).toBeTruthy();
55
+ // Verify keys are base64 encoded
56
+ (0, vitest_1.expect)(() => Buffer.from(identity.privateKey, "base64")).not.toThrow();
57
+ (0, vitest_1.expect)(() => Buffer.from(identity.publicKey, "base64")).not.toThrow();
58
+ });
59
+ (0, vitest_1.it)("should load existing identity from file", async () => {
60
+ // Generate first identity
61
+ const identity1 = await identityManager.ensureIdentity();
62
+ // Create new manager instance
63
+ const identityManager2 = new identity_js_1.IdentityManager({
64
+ environment: "development",
65
+ devIdentityPath: (0, path_1.join)(tempDir, "identity.json"),
66
+ });
67
+ // Should load the same identity
68
+ const identity2 = await identityManager2.ensureIdentity();
69
+ (0, vitest_1.expect)(identity2.did).toBe(identity1.did);
70
+ (0, vitest_1.expect)(identity2.keyId).toBe(identity1.keyId);
71
+ (0, vitest_1.expect)(identity2.privateKey).toBe(identity1.privateKey);
72
+ (0, vitest_1.expect)(identity2.publicKey).toBe(identity1.publicKey);
73
+ });
74
+ (0, vitest_1.it)("should cache identity after first load", async () => {
75
+ const identity1 = await identityManager.ensureIdentity();
76
+ const identity2 = await identityManager.ensureIdentity();
77
+ (0, vitest_1.expect)(identity1).toBe(identity2); // Same object reference
78
+ });
79
+ (0, vitest_1.it)("should regenerate identity if file is corrupted", async () => {
80
+ const identityPath = (0, path_1.join)(tempDir, "identity.json");
81
+ // Write corrupted file
82
+ await import("fs/promises").then((fs) => fs.writeFile(identityPath, "invalid json", "utf-8"));
83
+ // Should generate new identity
84
+ const identity = await identityManager.ensureIdentity();
85
+ (0, vitest_1.expect)(identity).toBeDefined();
86
+ (0, vitest_1.expect)(identity.did).toMatch(/^did:web:localhost:3000:agents:key-[a-f0-9]{8}$/);
87
+ });
88
+ (0, vitest_1.it)("should validate identity correctly", async () => {
89
+ const identity = await identityManager.ensureIdentity();
90
+ const isValid = await identityManager.validateIdentity(identity);
91
+ (0, vitest_1.expect)(isValid).toBe(true);
92
+ });
93
+ (0, vitest_1.it)("should reject invalid identity", async () => {
94
+ const invalidIdentity = {
95
+ did: "invalid-did",
96
+ keyId: "key-1",
97
+ privateKey: "invalid-key",
98
+ publicKey: "invalid-key",
99
+ createdAt: new Date().toISOString(),
100
+ };
101
+ const isValid = await identityManager.validateIdentity(invalidIdentity);
102
+ (0, vitest_1.expect)(isValid).toBe(false);
103
+ });
104
+ });
105
+ (0, vitest_1.describe)("Production Environment", () => {
106
+ (0, vitest_1.beforeEach)(() => {
107
+ identityManager = new identity_js_1.IdentityManager({
108
+ environment: "production",
109
+ });
110
+ });
111
+ (0, vitest_1.it)("should load identity from environment variables", async () => {
112
+ // Set up environment variables
113
+ process.env.AGENT_PRIVATE_KEY = Buffer.from("test-private-key-32-bytes-long!!").toString("base64");
114
+ process.env.AGENT_KEY_ID = "key-prod-123";
115
+ process.env.AGENT_DID = "did:web:example.com:agents:my-agent";
116
+ process.env.KYA_VOUCHED_API_KEY = "test-api-key";
117
+ const identity = await identityManager.ensureIdentity();
118
+ (0, vitest_1.expect)(identity.did).toBe("did:web:example.com:agents:my-agent");
119
+ (0, vitest_1.expect)(identity.keyId).toBe("key-prod-123");
120
+ (0, vitest_1.expect)(identity.privateKey).toBe(process.env.AGENT_PRIVATE_KEY);
121
+ (0, vitest_1.expect)(identity.publicKey).toBeTruthy();
122
+ });
123
+ (0, vitest_1.it)("should fail fast when environment variables are missing", async () => {
124
+ // Only set some variables
125
+ process.env.AGENT_DID = "did:web:example.com:agents:my-agent";
126
+ process.env.AGENT_KEY_ID = "key-prod-123";
127
+ await (0, vitest_1.expect)(identityManager.ensureIdentity()).rejects.toThrow(vitest_1.expect.objectContaining({
128
+ message: vitest_1.expect.stringContaining("Missing required environment variables"),
129
+ code: identity_js_1.IDENTITY_ERRORS.ENOIDENTITY,
130
+ }));
131
+ });
132
+ (0, vitest_1.it)("should list all missing environment variables", async () => {
133
+ const error = await identityManager.ensureIdentity().catch((e) => e);
134
+ (0, vitest_1.expect)(error.message).toContain("AGENT_PRIVATE_KEY, AGENT_KEY_ID, AGENT_DID, KYA_VOUCHED_API_KEY");
135
+ });
136
+ });
137
+ (0, vitest_1.describe)("Configuration", () => {
138
+ (0, vitest_1.it)("should use single public DID by default", () => {
139
+ const manager = new identity_js_1.IdentityManager();
140
+ const config = manager.getConfig();
141
+ (0, vitest_1.expect)(config.privacyMode).toBe(false);
142
+ });
143
+ (0, vitest_1.it)("should allow privacy mode configuration", () => {
144
+ const manager = new identity_js_1.IdentityManager({
145
+ environment: "development",
146
+ privacyMode: true,
147
+ });
148
+ const config = manager.getConfig();
149
+ (0, vitest_1.expect)(config.privacyMode).toBe(true);
150
+ });
151
+ (0, vitest_1.it)("should clear cache when requested", async () => {
152
+ const manager = new identity_js_1.IdentityManager({
153
+ environment: "development",
154
+ devIdentityPath: (0, path_1.join)(tempDir, "identity.json"),
155
+ });
156
+ const identity1 = await manager.ensureIdentity();
157
+ manager.clearCache();
158
+ const identity2 = await manager.ensureIdentity();
159
+ // Should be different object references but same content
160
+ (0, vitest_1.expect)(identity1).not.toBe(identity2);
161
+ (0, vitest_1.expect)(identity1.did).toBe(identity2.did);
162
+ });
163
+ });
164
+ });
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Tests for XMCP-I Runtime Integration
3
+ */
4
+ export {};
@@ -0,0 +1,372 @@
1
+ "use strict";
2
+ /**
3
+ * Tests for XMCP-I Runtime Integration
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const vitest_1 = require("vitest");
7
+ const mcpi_runtime_js_1 = require("../mcpi-runtime.js");
8
+ const fs_1 = require("fs");
9
+ const promises_1 = require("fs/promises");
10
+ (0, vitest_1.describe)("MCPIRuntime", () => {
11
+ let runtime;
12
+ let mockLogFunction;
13
+ (0, vitest_1.beforeEach)(async () => {
14
+ mockLogFunction = vitest_1.vi.fn();
15
+ // Mock console.log to avoid noise in tests
16
+ vitest_1.vi.spyOn(console, "log").mockImplementation(() => { });
17
+ vitest_1.vi.spyOn(console, "error").mockImplementation(() => { });
18
+ });
19
+ (0, vitest_1.afterEach)(async () => {
20
+ if (runtime) {
21
+ await runtime.cleanup();
22
+ }
23
+ // Cleanup test directory
24
+ try {
25
+ if ((0, fs_1.existsSync)(".test-mcpi")) {
26
+ await (0, promises_1.rmdir)(".test-mcpi", { recursive: true });
27
+ }
28
+ }
29
+ catch {
30
+ // Ignore cleanup errors
31
+ }
32
+ vitest_1.vi.restoreAllMocks();
33
+ });
34
+ (0, vitest_1.describe)("Runtime Initialization", () => {
35
+ (0, vitest_1.it)("should initialize successfully with default config", async () => {
36
+ runtime = new mcpi_runtime_js_1.MCPIRuntime({
37
+ identity: {
38
+ environment: "development",
39
+ devIdentityPath: ".test-mcpi/identity.json",
40
+ },
41
+ audit: {
42
+ logFunction: mockLogFunction,
43
+ },
44
+ });
45
+ await runtime.initialize();
46
+ const stats = runtime.getStats();
47
+ (0, vitest_1.expect)(stats.identity.did).toBeTruthy();
48
+ (0, vitest_1.expect)(stats.identity.keyId).toBeTruthy();
49
+ (0, vitest_1.expect)(stats.runtime.initialized).toBe(true);
50
+ });
51
+ (0, vitest_1.it)("should initialize with well-known endpoints", async () => {
52
+ runtime = new mcpi_runtime_js_1.MCPIRuntime({
53
+ identity: {
54
+ environment: "development",
55
+ devIdentityPath: ".test-mcpi/identity.json",
56
+ },
57
+ wellKnown: {
58
+ environment: "development",
59
+ baseUrl: "http://localhost:3000",
60
+ },
61
+ });
62
+ await runtime.initialize();
63
+ const stats = runtime.getStats();
64
+ (0, vitest_1.expect)(stats.runtime.wellKnownEnabled).toBe(true);
65
+ const handler = runtime.getWellKnownHandler();
66
+ (0, vitest_1.expect)(handler).toBeDefined();
67
+ (0, vitest_1.expect)(handler.handleDIDDocument).toBeTypeOf("function");
68
+ (0, vitest_1.expect)(handler.handleAgentDocument).toBeTypeOf("function");
69
+ });
70
+ (0, vitest_1.it)("should fail initialization without well-known config when accessing handler", async () => {
71
+ runtime = new mcpi_runtime_js_1.MCPIRuntime({
72
+ identity: {
73
+ environment: "development",
74
+ devIdentityPath: ".test-mcpi/identity.json",
75
+ },
76
+ });
77
+ await runtime.initialize();
78
+ (0, vitest_1.expect)(() => runtime.getWellKnownHandler()).toThrow("Well-known endpoints not configured");
79
+ });
80
+ });
81
+ (0, vitest_1.describe)("Handshake Validation", () => {
82
+ (0, vitest_1.beforeEach)(async () => {
83
+ runtime = new mcpi_runtime_js_1.MCPIRuntime({
84
+ identity: {
85
+ environment: "development",
86
+ devIdentityPath: ".test-mcpi/identity.json",
87
+ },
88
+ audit: {
89
+ logFunction: mockLogFunction,
90
+ },
91
+ });
92
+ await runtime.initialize();
93
+ });
94
+ (0, vitest_1.it)("should validate correct handshake", async () => {
95
+ const request = {
96
+ nonce: "test-nonce-123",
97
+ audience: "example.com",
98
+ timestamp: Math.floor(Date.now() / 1000),
99
+ };
100
+ const session = await runtime.validateHandshake(request);
101
+ (0, vitest_1.expect)(session).toBeTruthy();
102
+ (0, vitest_1.expect)(session.audience).toBe("example.com");
103
+ (0, vitest_1.expect)(session.nonce).toBe("test-nonce-123");
104
+ (0, vitest_1.expect)(session.sessionId).toMatch(/^sess_/);
105
+ });
106
+ (0, vitest_1.it)("should reject invalid handshake", async () => {
107
+ const request = {
108
+ nonce: "test-nonce-old",
109
+ audience: "example.com",
110
+ timestamp: Math.floor(Date.now() / 1000) - 200, // Too old
111
+ };
112
+ const session = await runtime.validateHandshake(request);
113
+ (0, vitest_1.expect)(session).toBeNull();
114
+ });
115
+ });
116
+ (0, vitest_1.describe)("Tool Call Processing", () => {
117
+ let mockSession;
118
+ (0, vitest_1.beforeEach)(async () => {
119
+ runtime = new mcpi_runtime_js_1.MCPIRuntime({
120
+ identity: {
121
+ environment: "development",
122
+ devIdentityPath: ".test-mcpi/identity.json",
123
+ },
124
+ audit: {
125
+ logFunction: mockLogFunction,
126
+ },
127
+ });
128
+ await runtime.initialize();
129
+ // Create a valid session
130
+ const handshakeRequest = {
131
+ nonce: "test-nonce-123",
132
+ audience: "example.com",
133
+ timestamp: Math.floor(Date.now() / 1000),
134
+ };
135
+ mockSession = await runtime.validateHandshake(handshakeRequest);
136
+ });
137
+ (0, vitest_1.it)("should process tool call with proof generation", async () => {
138
+ const toolRequest = {
139
+ method: "test-tool",
140
+ params: { input: "hello" },
141
+ };
142
+ const mockToolHandler = vitest_1.vi.fn().mockResolvedValue({ output: "world" });
143
+ const response = await runtime.processToolCall(toolRequest, mockSession, mockToolHandler);
144
+ (0, vitest_1.expect)(mockToolHandler).toHaveBeenCalledWith(toolRequest);
145
+ (0, vitest_1.expect)(response.data).toEqual({ output: "world" });
146
+ (0, vitest_1.expect)(response.meta?.proof).toBeDefined();
147
+ (0, vitest_1.expect)(response.meta?.proof?.meta.did).toBeTruthy();
148
+ (0, vitest_1.expect)(response.meta?.proof?.jws).toBeTruthy();
149
+ });
150
+ (0, vitest_1.it)("should include scope and delegation in proof", async () => {
151
+ const toolRequest = {
152
+ method: "test-tool",
153
+ params: { input: "hello" },
154
+ };
155
+ const mockToolHandler = vitest_1.vi.fn().mockResolvedValue({ output: "world" });
156
+ const response = await runtime.processToolCall(toolRequest, mockSession, mockToolHandler, {
157
+ scopeId: "orders.create",
158
+ delegationRef: "delegation-123",
159
+ });
160
+ (0, vitest_1.expect)(response.meta?.proof?.meta.scopeId).toBe("orders.create");
161
+ (0, vitest_1.expect)(response.meta?.proof?.meta.delegationRef).toBe("delegation-123");
162
+ });
163
+ (0, vitest_1.it)("should log audit record on tool call", async () => {
164
+ const toolRequest = {
165
+ method: "test-tool",
166
+ params: { input: "hello" },
167
+ };
168
+ const mockToolHandler = vitest_1.vi.fn().mockResolvedValue({ output: "world" });
169
+ await runtime.processToolCall(toolRequest, mockSession, mockToolHandler);
170
+ (0, vitest_1.expect)(mockLogFunction).toHaveBeenCalled();
171
+ const auditLine = mockLogFunction.mock.calls[0][0];
172
+ (0, vitest_1.expect)(auditLine).toContain("audit.v1");
173
+ (0, vitest_1.expect)(auditLine).toContain("verified=yes");
174
+ });
175
+ (0, vitest_1.it)("should handle tool call errors", async () => {
176
+ const toolRequest = {
177
+ method: "failing-tool",
178
+ params: { input: "hello" },
179
+ };
180
+ const mockToolHandler = vitest_1.vi
181
+ .fn()
182
+ .mockRejectedValue(new Error("Tool failed"));
183
+ await (0, vitest_1.expect)(runtime.processToolCall(toolRequest, mockSession, mockToolHandler)).rejects.toThrow("Tool failed");
184
+ // Should still log audit record with verified=no
185
+ (0, vitest_1.expect)(mockLogFunction).toHaveBeenCalled();
186
+ const auditLine = mockLogFunction.mock.calls[0][0];
187
+ (0, vitest_1.expect)(auditLine).toContain("verified=no");
188
+ });
189
+ (0, vitest_1.it)("should fail if runtime not initialized", async () => {
190
+ const uninitializedRuntime = new mcpi_runtime_js_1.MCPIRuntime();
191
+ const toolRequest = {
192
+ method: "test-tool",
193
+ params: { input: "hello" },
194
+ };
195
+ const mockToolHandler = vitest_1.vi.fn().mockResolvedValue({ output: "world" });
196
+ await (0, vitest_1.expect)(uninitializedRuntime.processToolCall(toolRequest, mockSession, mockToolHandler)).rejects.toThrow("Runtime not initialized");
197
+ });
198
+ });
199
+ (0, vitest_1.describe)("Runtime Statistics", () => {
200
+ (0, vitest_1.beforeEach)(async () => {
201
+ runtime = new mcpi_runtime_js_1.MCPIRuntime({
202
+ identity: {
203
+ environment: "development",
204
+ devIdentityPath: ".test-mcpi/identity.json",
205
+ },
206
+ wellKnown: {
207
+ environment: "development",
208
+ baseUrl: "http://localhost:3000",
209
+ },
210
+ });
211
+ await runtime.initialize();
212
+ });
213
+ (0, vitest_1.it)("should provide comprehensive statistics", () => {
214
+ const stats = runtime.getStats();
215
+ (0, vitest_1.expect)(stats.identity.did).toBeTruthy();
216
+ (0, vitest_1.expect)(stats.identity.keyId).toBeTruthy();
217
+ (0, vitest_1.expect)(stats.identity.environment).toBe("development");
218
+ (0, vitest_1.expect)(stats.session.activeSessions).toBe(0);
219
+ (0, vitest_1.expect)(stats.audit.enabled).toBe(true);
220
+ (0, vitest_1.expect)(stats.runtime.initialized).toBe(true);
221
+ (0, vitest_1.expect)(stats.runtime.wellKnownEnabled).toBe(true);
222
+ });
223
+ });
224
+ (0, vitest_1.describe)("Runtime Environment Checks", () => {
225
+ (0, vitest_1.it)("should pass environment checks in Node.js ≥18.18", async () => {
226
+ // This test runs in Node.js, so it should pass
227
+ runtime = new mcpi_runtime_js_1.MCPIRuntime({
228
+ identity: {
229
+ environment: "development",
230
+ devIdentityPath: ".test-mcpi/identity.json",
231
+ },
232
+ });
233
+ await (0, vitest_1.expect)(runtime.initialize()).resolves.not.toThrow();
234
+ });
235
+ (0, vitest_1.it)("should detect Node.js environment", async () => {
236
+ runtime = new mcpi_runtime_js_1.MCPIRuntime({
237
+ identity: {
238
+ environment: "development",
239
+ devIdentityPath: ".test-mcpi/identity.json",
240
+ },
241
+ });
242
+ await runtime.initialize();
243
+ const stats = runtime.getStats();
244
+ (0, vitest_1.expect)(stats.runtime.initialized).toBe(true);
245
+ });
246
+ });
247
+ });
248
+ (0, vitest_1.describe)("Runtime Factory", () => {
249
+ let runtime;
250
+ (0, vitest_1.afterEach)(async () => {
251
+ if (runtime) {
252
+ await runtime.cleanup();
253
+ }
254
+ // Cleanup test directory
255
+ try {
256
+ if ((0, fs_1.existsSync)(".test-mcpi")) {
257
+ await (0, promises_1.rmdir)(".test-mcpi", { recursive: true });
258
+ }
259
+ }
260
+ catch {
261
+ // Ignore cleanup errors
262
+ }
263
+ });
264
+ (0, vitest_1.beforeEach)(() => {
265
+ // Mock console.log to avoid noise in tests
266
+ vitest_1.vi.spyOn(console, "log").mockImplementation(() => { });
267
+ vitest_1.vi.spyOn(console, "error").mockImplementation(() => { });
268
+ });
269
+ (0, vitest_1.afterEach)(() => {
270
+ vitest_1.vi.restoreAllMocks();
271
+ });
272
+ (0, vitest_1.describe)("forDevelopment", () => {
273
+ (0, vitest_1.it)("should create development runtime", async () => {
274
+ runtime = await mcpi_runtime_js_1.RuntimeFactory.forDevelopment({
275
+ identity: {
276
+ devIdentityPath: ".test-mcpi/identity.json",
277
+ },
278
+ });
279
+ const stats = runtime.getStats();
280
+ (0, vitest_1.expect)(stats.identity.environment).toBe("development");
281
+ (0, vitest_1.expect)(stats.runtime.initialized).toBe(true);
282
+ });
283
+ (0, vitest_1.it)("should enable verify link in development", async () => {
284
+ runtime = await mcpi_runtime_js_1.RuntimeFactory.forDevelopment({
285
+ identity: {
286
+ devIdentityPath: ".test-mcpi/identity.json",
287
+ },
288
+ });
289
+ // Should not throw and should be initialized
290
+ (0, vitest_1.expect)(runtime.getStats().runtime.initialized).toBe(true);
291
+ });
292
+ });
293
+ (0, vitest_1.describe)("forProduction", () => {
294
+ (0, vitest_1.it)("should create production runtime with env vars", async () => {
295
+ // Mock production environment variables
296
+ const originalEnv = process.env;
297
+ process.env.AGENT_PRIVATE_KEY = Buffer.from("test-private-key-32-bytes-long!!").toString("base64");
298
+ process.env.AGENT_KEY_ID = "key-prod-123";
299
+ process.env.AGENT_DID = "did:web:example.com:agents:prod-agent";
300
+ process.env.KYA_VOUCHED_API_KEY = "test-api-key";
301
+ try {
302
+ runtime = await mcpi_runtime_js_1.RuntimeFactory.forProduction();
303
+ const stats = runtime.getStats();
304
+ (0, vitest_1.expect)(stats.identity.environment).toBe("production");
305
+ (0, vitest_1.expect)(stats.identity.did).toBe("did:web:example.com:agents:prod-agent");
306
+ (0, vitest_1.expect)(stats.runtime.initialized).toBe(true);
307
+ }
308
+ finally {
309
+ // Restore environment
310
+ process.env = originalEnv;
311
+ }
312
+ });
313
+ });
314
+ (0, vitest_1.describe)("forTesting", () => {
315
+ (0, vitest_1.it)("should create testing runtime", async () => {
316
+ runtime = await mcpi_runtime_js_1.RuntimeFactory.forTesting();
317
+ const stats = runtime.getStats();
318
+ (0, vitest_1.expect)(stats.identity.environment).toBe("development");
319
+ (0, vitest_1.expect)(stats.audit.enabled).toBe(false); // Disabled in tests
320
+ (0, vitest_1.expect)(stats.runtime.initialized).toBe(true);
321
+ });
322
+ (0, vitest_1.it)("should use test identity path", async () => {
323
+ runtime = await mcpi_runtime_js_1.RuntimeFactory.forTesting();
324
+ // Should be initialized without errors
325
+ (0, vitest_1.expect)(runtime.getStats().runtime.initialized).toBe(true);
326
+ });
327
+ });
328
+ });
329
+ (0, vitest_1.describe)("createMCPIRuntime", () => {
330
+ let runtime;
331
+ (0, vitest_1.afterEach)(async () => {
332
+ if (runtime) {
333
+ await runtime.cleanup();
334
+ }
335
+ // Cleanup test directory
336
+ try {
337
+ if ((0, fs_1.existsSync)(".test-mcpi")) {
338
+ await (0, promises_1.rmdir)(".test-mcpi", { recursive: true });
339
+ }
340
+ }
341
+ catch {
342
+ // Ignore cleanup errors
343
+ }
344
+ });
345
+ (0, vitest_1.beforeEach)(() => {
346
+ // Mock console.log to avoid noise in tests
347
+ vitest_1.vi.spyOn(console, "log").mockImplementation(() => { });
348
+ });
349
+ (0, vitest_1.afterEach)(() => {
350
+ vitest_1.vi.restoreAllMocks();
351
+ });
352
+ (0, vitest_1.it)("should create and initialize runtime", async () => {
353
+ runtime = await (0, mcpi_runtime_js_1.createMCPIRuntime)({
354
+ identity: {
355
+ environment: "development",
356
+ devIdentityPath: ".test-mcpi/identity.json",
357
+ },
358
+ });
359
+ (0, vitest_1.expect)(runtime.getStats().runtime.initialized).toBe(true);
360
+ });
361
+ (0, vitest_1.it)("should create runtime with minimal config", async () => {
362
+ runtime = await (0, mcpi_runtime_js_1.createMCPIRuntime)({
363
+ identity: {
364
+ environment: "development",
365
+ devIdentityPath: ".test-mcpi/identity.json",
366
+ },
367
+ });
368
+ const stats = runtime.getStats();
369
+ (0, vitest_1.expect)(stats.runtime.initialized).toBe(true);
370
+ (0, vitest_1.expect)(stats.identity.did).toBeTruthy();
371
+ });
372
+ });
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Tests for Detached Proof Generation
3
+ */
4
+ export {};