@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,342 @@
1
+ "use strict";
2
+ /**
3
+ * Local verification utilities for offline testing
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.verifyProofLocally = verifyProofLocally;
7
+ exports.verifyDIDDocumentLocally = verifyDIDDocumentLocally;
8
+ exports.createMockProof = createMockProof;
9
+ const crypto_1 = require("crypto");
10
+ const test_1 = require("@kya-os/contracts/test");
11
+ const test_environment_1 = require("./test-environment");
12
+ const mock_identity_provider_1 = require("./mock-identity-provider");
13
+ /**
14
+ * Canonicalize data using JCS (JSON Canonicalization Scheme)
15
+ * For testing, we'll use a simplified version
16
+ */
17
+ function canonicalizeJSON(data) {
18
+ // Simplified JCS implementation for testing
19
+ // In production, this would use a proper JCS library
20
+ return JSON.stringify(data, Object.keys(data).sort());
21
+ }
22
+ /**
23
+ * Generate SHA-256 hash with prefix
24
+ */
25
+ function generateHash(data) {
26
+ return `sha256:${(0, crypto_1.createHash)("sha256").update(data).digest("hex")}`;
27
+ }
28
+ /**
29
+ * Verify Ed25519 signature locally (mock implementation for testing)
30
+ */
31
+ function verifySignature(data, signature, publicKey) {
32
+ (0, test_environment_1.ensureTestMode)();
33
+ try {
34
+ // Mock signature verification for testing
35
+ // In production, this would use proper Ed25519 verification
36
+ const expectedSignature = (0, crypto_1.createHash)("sha256")
37
+ .update(data + publicKey)
38
+ .digest("base64");
39
+ const valid = signature === expectedSignature;
40
+ return {
41
+ valid,
42
+ error: valid ? undefined : "Signature verification failed",
43
+ };
44
+ }
45
+ catch (error) {
46
+ return {
47
+ valid: false,
48
+ error: error instanceof Error
49
+ ? error.message
50
+ : "Unknown signature verification error",
51
+ };
52
+ }
53
+ }
54
+ /**
55
+ * Verify proof structure and content
56
+ */
57
+ function verifyProofStructure(proof) {
58
+ (0, test_environment_1.ensureTestMode)();
59
+ const errors = [];
60
+ // Check required fields
61
+ const requiredFields = ["jws", "meta"];
62
+ const requiredMetaFields = [
63
+ "did",
64
+ "kid",
65
+ "ts",
66
+ "nonce",
67
+ "audience",
68
+ "sessionId",
69
+ "requestHash",
70
+ "responseHash",
71
+ ];
72
+ let structure = true;
73
+ if (!proof || typeof proof !== "object") {
74
+ structure = false;
75
+ errors.push("Proof must be an object");
76
+ }
77
+ else {
78
+ for (const field of requiredFields) {
79
+ if (!(field in proof)) {
80
+ structure = false;
81
+ errors.push(`Missing required field: ${field}`);
82
+ }
83
+ }
84
+ if (proof.meta && typeof proof.meta === "object") {
85
+ for (const field of requiredMetaFields) {
86
+ if (!(field in proof.meta)) {
87
+ structure = false;
88
+ errors.push(`Missing required meta field: ${field}`);
89
+ }
90
+ }
91
+ }
92
+ else {
93
+ structure = false;
94
+ errors.push("Proof meta must be an object");
95
+ }
96
+ }
97
+ // Check timestamp validity (within reasonable bounds)
98
+ let timestamps = true;
99
+ if (proof?.meta?.ts) {
100
+ const now = Date.now() / 1000;
101
+ const proofTime = proof.meta.ts;
102
+ const skew = Math.abs(now - proofTime);
103
+ if (skew > 300) {
104
+ // 5 minutes for testing
105
+ timestamps = false;
106
+ errors.push(`Timestamp too far from current time: ${skew}s`);
107
+ }
108
+ }
109
+ else {
110
+ timestamps = false;
111
+ errors.push("Missing or invalid timestamp");
112
+ }
113
+ // Check hash format
114
+ let hashes = true;
115
+ if (proof?.meta?.requestHash &&
116
+ !proof.meta.requestHash.startsWith("sha256:")) {
117
+ hashes = false;
118
+ errors.push("Request hash must start with 'sha256:'");
119
+ }
120
+ if (proof?.meta?.responseHash &&
121
+ !proof.meta.responseHash.startsWith("sha256:")) {
122
+ hashes = false;
123
+ errors.push("Response hash must start with 'sha256:'");
124
+ }
125
+ const valid = structure && timestamps && hashes;
126
+ return {
127
+ valid,
128
+ structure,
129
+ timestamps,
130
+ hashes,
131
+ error: errors.length > 0 ? errors.join("; ") : undefined,
132
+ };
133
+ }
134
+ /**
135
+ * Verify session validity
136
+ */
137
+ function verifySession(sessionId, timestamp) {
138
+ (0, test_environment_1.ensureTestMode)();
139
+ if (!sessionId || typeof sessionId !== "string") {
140
+ return {
141
+ valid: false,
142
+ expired: false,
143
+ error: "Invalid session ID",
144
+ };
145
+ }
146
+ // For testing, assume sessions are valid for 30 minutes
147
+ const now = Date.now() / 1000;
148
+ const sessionAge = now - timestamp;
149
+ const expired = sessionAge > 1800; // 30 minutes
150
+ return {
151
+ valid: !expired,
152
+ expired,
153
+ error: expired ? "Session expired" : undefined,
154
+ };
155
+ }
156
+ /**
157
+ * Perform local verification of a proof without KTA calls
158
+ */
159
+ async function verifyProofLocally(proof, request, response) {
160
+ (0, test_environment_1.ensureTestMode)();
161
+ try {
162
+ const errors = [];
163
+ const warnings = [];
164
+ // Verify proof structure
165
+ const proofCheck = verifyProofStructure(proof);
166
+ if (!proofCheck.valid && proofCheck.error) {
167
+ errors.push(proofCheck.error);
168
+ }
169
+ let signatureValid = false;
170
+ let did;
171
+ let keyId;
172
+ if (proofCheck.structure && proof?.meta) {
173
+ did = proof.meta.did;
174
+ keyId = proof.meta.kid;
175
+ // Get mock identity for verification
176
+ const mockProvider = (0, mock_identity_provider_1.getMockIdentityProvider)();
177
+ const identity = mockProvider.getIdentity("agent1") ||
178
+ mockProvider.getIdentity("agent2") ||
179
+ mockProvider.getIdentity("verifier1");
180
+ if (identity && identity.did === did && identity.keyId === keyId) {
181
+ // Verify signature using mock implementation
182
+ const canonicalMeta = canonicalizeJSON(proof.meta);
183
+ const signatureCheck = verifySignature(canonicalMeta, proof.jws, identity.publicKey);
184
+ signatureValid = signatureCheck.valid;
185
+ if (!signatureValid && signatureCheck.error) {
186
+ errors.push(signatureCheck.error);
187
+ }
188
+ }
189
+ else {
190
+ errors.push(`No matching identity found for DID: ${did}, KeyID: ${keyId}`);
191
+ }
192
+ }
193
+ // Verify session
194
+ const sessionCheck = verifySession(proof?.meta?.sessionId, proof?.meta?.ts);
195
+ if (!sessionCheck.valid && sessionCheck.error) {
196
+ errors.push(sessionCheck.error);
197
+ }
198
+ if (sessionCheck.expired) {
199
+ warnings.push("Session is expired");
200
+ }
201
+ // Verify hashes if request/response provided
202
+ if (request && proof?.meta?.requestHash) {
203
+ const expectedRequestHash = generateHash(canonicalizeJSON(request));
204
+ if (expectedRequestHash !== proof.meta.requestHash) {
205
+ errors.push("Request hash mismatch");
206
+ }
207
+ }
208
+ if (response && proof?.meta?.responseHash) {
209
+ const expectedResponseHash = generateHash(canonicalizeJSON(response));
210
+ if (expectedResponseHash !== proof.meta.responseHash) {
211
+ errors.push("Response hash mismatch");
212
+ }
213
+ }
214
+ const result = {
215
+ valid: errors.length === 0,
216
+ did,
217
+ keyId,
218
+ signature: {
219
+ valid: signatureValid,
220
+ algorithm: "EdDSA",
221
+ error: signatureValid ? undefined : "Signature verification failed",
222
+ },
223
+ proof: proofCheck,
224
+ session: sessionCheck,
225
+ errors,
226
+ warnings,
227
+ };
228
+ return test_1.LocalVerificationResultSchema.parse(result);
229
+ }
230
+ catch (error) {
231
+ const errorMessage = error instanceof Error ? error.message : "Unknown verification error";
232
+ return test_1.LocalVerificationResultSchema.parse({
233
+ valid: false,
234
+ signature: {
235
+ valid: false,
236
+ algorithm: "EdDSA",
237
+ error: "Verification failed",
238
+ },
239
+ proof: {
240
+ valid: false,
241
+ structure: false,
242
+ timestamps: false,
243
+ hashes: false,
244
+ error: errorMessage,
245
+ },
246
+ session: {
247
+ valid: false,
248
+ expired: false,
249
+ error: "Session verification failed",
250
+ },
251
+ errors: [errorMessage],
252
+ warnings: [],
253
+ });
254
+ }
255
+ }
256
+ /**
257
+ * Verify DID document locally (mock implementation)
258
+ */
259
+ async function verifyDIDDocumentLocally(did) {
260
+ (0, test_environment_1.ensureTestMode)();
261
+ try {
262
+ const mockProvider = (0, mock_identity_provider_1.getMockIdentityProvider)();
263
+ const identities = mockProvider.getAllIdentities();
264
+ // Find identity with matching DID
265
+ const identity = Object.values(identities).find((id) => id.did === did);
266
+ if (!identity) {
267
+ return {
268
+ valid: false,
269
+ error: `No identity found for DID: ${did}`,
270
+ };
271
+ }
272
+ // Generate mock DID document
273
+ const document = {
274
+ "@context": ["https://www.w3.org/ns/did/v1"],
275
+ id: did,
276
+ verificationMethod: [
277
+ {
278
+ id: `${did}#${identity.keyId}`,
279
+ type: "Ed25519VerificationKey2020",
280
+ controller: did,
281
+ publicKeyMultibase: `z${identity.publicKey}`,
282
+ },
283
+ ],
284
+ authentication: [`${did}#${identity.keyId}`],
285
+ assertionMethod: [`${did}#${identity.keyId}`],
286
+ };
287
+ return {
288
+ valid: true,
289
+ document,
290
+ };
291
+ }
292
+ catch (error) {
293
+ return {
294
+ valid: false,
295
+ error: error instanceof Error
296
+ ? error.message
297
+ : "Unknown DID verification error",
298
+ };
299
+ }
300
+ }
301
+ /**
302
+ * Create a mock proof for testing
303
+ */
304
+ function createMockProof(options) {
305
+ (0, test_environment_1.ensureTestMode)();
306
+ const mockProvider = (0, mock_identity_provider_1.getMockIdentityProvider)();
307
+ const identity = mockProvider.getIdentity("agent1");
308
+ if (!identity) {
309
+ throw new Error(`${test_1.TEST_ERROR_CODES.LOCAL_VERIFICATION_FAILED}: No test identity available`);
310
+ }
311
+ const now = Math.floor(Date.now() / 1000);
312
+ const did = options.did || identity.did;
313
+ const keyId = options.keyId || identity.keyId;
314
+ const sessionId = options.sessionId || "sess_test_mock";
315
+ const nonce = options.nonce || "mock_nonce";
316
+ const audience = options.audience || "test.example.com";
317
+ const requestHash = options.request
318
+ ? generateHash(canonicalizeJSON(options.request))
319
+ : "sha256:mock_request_hash";
320
+ const responseHash = options.response
321
+ ? generateHash(canonicalizeJSON(options.response))
322
+ : "sha256:mock_response_hash";
323
+ const meta = {
324
+ did,
325
+ kid: keyId,
326
+ ts: now,
327
+ nonce,
328
+ audience,
329
+ sessionId,
330
+ requestHash,
331
+ responseHash,
332
+ };
333
+ // Generate mock JWS signature
334
+ const canonicalMeta = canonicalizeJSON(meta);
335
+ const jws = (0, crypto_1.createHash)("sha256")
336
+ .update(canonicalMeta + identity.publicKey)
337
+ .digest("base64");
338
+ return {
339
+ jws,
340
+ meta,
341
+ };
342
+ }
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Mock Identity Provider for testing
3
+ */
4
+ import { type MockIdentity, type MockDelegationStatus, type MockKTAFailureType, type MockIdentityProviderConfig } from "@kya-os/contracts/test";
5
+ /**
6
+ * Mock Identity Provider for testing XMCP-I applications
7
+ */
8
+ export declare class MockIdentityProvider {
9
+ private identities;
10
+ private delegations;
11
+ private ktaFailures;
12
+ private deterministicSeed?;
13
+ constructor(config?: Partial<MockIdentityProviderConfig>);
14
+ /**
15
+ * Configure the mock provider
16
+ */
17
+ configure(config: Partial<MockIdentityProviderConfig>): void;
18
+ /**
19
+ * Load predefined test identities
20
+ */
21
+ private loadPredefinedIdentities;
22
+ /**
23
+ * Set identity for a given key
24
+ */
25
+ setIdentity(key: string, identity: MockIdentity): void;
26
+ /**
27
+ * Get identity by key
28
+ */
29
+ getIdentity(key: string): MockIdentity | undefined;
30
+ /**
31
+ * Generate and set a new test identity
32
+ */
33
+ generateIdentity(key: string, testName: string, options?: {
34
+ did?: string;
35
+ keyId?: string;
36
+ }): MockIdentity;
37
+ /**
38
+ * Set delegation status for a DID:KeyID combination
39
+ */
40
+ setDelegation(didKeyId: string, status: MockDelegationStatus): void;
41
+ /**
42
+ * Get delegation status
43
+ */
44
+ getDelegationStatus(did: string, keyId: string): MockDelegationStatus;
45
+ /**
46
+ * Simulate KTA failure scenarios
47
+ */
48
+ simulateKTAFailure(errorType: MockKTAFailureType): void;
49
+ /**
50
+ * Clear KTA failure simulation
51
+ */
52
+ clearKTAFailure(errorType: MockKTAFailureType): void;
53
+ /**
54
+ * Check if a KTA failure should be simulated
55
+ */
56
+ shouldSimulateKTAFailure(errorType: MockKTAFailureType): boolean;
57
+ /**
58
+ * Get all active KTA failures
59
+ */
60
+ getActiveKTAFailures(): MockKTAFailureType[];
61
+ /**
62
+ * Mock KTA registration call
63
+ */
64
+ mockRegister(did: string, _keyId: string): Promise<{
65
+ success: boolean;
66
+ agentURL?: string;
67
+ error?: string;
68
+ }>;
69
+ /**
70
+ * Mock KTA delegation check
71
+ */
72
+ mockCheckDelegation(did: string, keyId: string): Promise<{
73
+ status: MockDelegationStatus;
74
+ error?: string;
75
+ }>;
76
+ /**
77
+ * Reset the mock provider to initial state
78
+ */
79
+ reset(): void;
80
+ /**
81
+ * Get all configured identities
82
+ */
83
+ getAllIdentities(): Record<string, MockIdentity>;
84
+ /**
85
+ * Get all delegation statuses
86
+ */
87
+ getAllDelegations(): Record<string, MockDelegationStatus>;
88
+ }
89
+ /**
90
+ * Get or create the global mock identity provider
91
+ */
92
+ export declare function getMockIdentityProvider(): MockIdentityProvider;
93
+ /**
94
+ * Reset the global mock identity provider
95
+ */
96
+ export declare function resetMockIdentityProvider(): void;
@@ -0,0 +1,243 @@
1
+ "use strict";
2
+ /**
3
+ * Mock Identity Provider for testing
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.MockIdentityProvider = void 0;
7
+ exports.getMockIdentityProvider = getMockIdentityProvider;
8
+ exports.resetMockIdentityProvider = resetMockIdentityProvider;
9
+ const test_1 = require("@kya-os/contracts/test");
10
+ const test_environment_1 = require("./test-environment");
11
+ const deterministic_keys_1 = require("./deterministic-keys");
12
+ /**
13
+ * Mock Identity Provider for testing XMCP-I applications
14
+ */
15
+ class MockIdentityProvider {
16
+ identities = new Map();
17
+ delegations = new Map();
18
+ ktaFailures = new Set();
19
+ deterministicSeed;
20
+ constructor(config) {
21
+ (0, test_environment_1.ensureTestMode)();
22
+ if (config) {
23
+ this.configure(config);
24
+ }
25
+ else {
26
+ // Load predefined test identities by default
27
+ this.loadPredefinedIdentities();
28
+ }
29
+ }
30
+ /**
31
+ * Configure the mock provider
32
+ */
33
+ configure(config) {
34
+ (0, test_environment_1.ensureTestMode)();
35
+ // Validate configuration
36
+ const validatedConfig = test_1.MockIdentityProviderConfigSchema.partial().parse(config);
37
+ if (validatedConfig.identities) {
38
+ this.identities.clear();
39
+ Object.entries(validatedConfig.identities).forEach(([key, identity]) => {
40
+ this.identities.set(key, identity);
41
+ });
42
+ }
43
+ if (validatedConfig.delegations) {
44
+ this.delegations.clear();
45
+ Object.entries(validatedConfig.delegations).forEach(([key, status]) => {
46
+ this.delegations.set(key, status);
47
+ });
48
+ }
49
+ if (validatedConfig.ktaFailures) {
50
+ this.ktaFailures.clear();
51
+ validatedConfig.ktaFailures.forEach((failure) => {
52
+ this.ktaFailures.add(failure);
53
+ });
54
+ }
55
+ if (validatedConfig.deterministicSeed) {
56
+ this.deterministicSeed = validatedConfig.deterministicSeed;
57
+ }
58
+ }
59
+ /**
60
+ * Load predefined test identities
61
+ */
62
+ loadPredefinedIdentities() {
63
+ const predefined = (0, deterministic_keys_1.getPredefinedTestIdentities)();
64
+ Object.entries(predefined).forEach(([key, identity]) => {
65
+ this.identities.set(key, identity);
66
+ // Set all predefined identities as active by default
67
+ this.delegations.set(`${identity.did}:${identity.keyId}`, "active");
68
+ });
69
+ }
70
+ /**
71
+ * Set identity for a given key
72
+ */
73
+ setIdentity(key, identity) {
74
+ (0, test_environment_1.ensureTestMode)();
75
+ this.identities.set(key, identity);
76
+ }
77
+ /**
78
+ * Get identity by key
79
+ */
80
+ getIdentity(key) {
81
+ (0, test_environment_1.ensureTestMode)();
82
+ return this.identities.get(key);
83
+ }
84
+ /**
85
+ * Generate and set a new test identity
86
+ */
87
+ generateIdentity(key, testName, options) {
88
+ (0, test_environment_1.ensureTestMode)();
89
+ const identity = (0, deterministic_keys_1.generateTestIdentity)(testName, {
90
+ ...options,
91
+ seed: this.deterministicSeed,
92
+ });
93
+ this.setIdentity(key, identity);
94
+ this.setDelegation(`${identity.did}:${identity.keyId}`, "active");
95
+ return identity;
96
+ }
97
+ /**
98
+ * Set delegation status for a DID:KeyID combination
99
+ */
100
+ setDelegation(didKeyId, status) {
101
+ (0, test_environment_1.ensureTestMode)();
102
+ this.delegations.set(didKeyId, status);
103
+ }
104
+ /**
105
+ * Get delegation status
106
+ */
107
+ getDelegationStatus(did, keyId) {
108
+ (0, test_environment_1.ensureTestMode)();
109
+ return this.delegations.get(`${did}:${keyId}`) || "revoked";
110
+ }
111
+ /**
112
+ * Simulate KTA failure scenarios
113
+ */
114
+ simulateKTAFailure(errorType) {
115
+ (0, test_environment_1.ensureTestMode)();
116
+ this.ktaFailures.add(errorType);
117
+ }
118
+ /**
119
+ * Clear KTA failure simulation
120
+ */
121
+ clearKTAFailure(errorType) {
122
+ (0, test_environment_1.ensureTestMode)();
123
+ this.ktaFailures.delete(errorType);
124
+ }
125
+ /**
126
+ * Check if a KTA failure should be simulated
127
+ */
128
+ shouldSimulateKTAFailure(errorType) {
129
+ (0, test_environment_1.ensureTestMode)();
130
+ return this.ktaFailures.has(errorType);
131
+ }
132
+ /**
133
+ * Get all active KTA failures
134
+ */
135
+ getActiveKTAFailures() {
136
+ (0, test_environment_1.ensureTestMode)();
137
+ return Array.from(this.ktaFailures);
138
+ }
139
+ /**
140
+ * Mock KTA registration call
141
+ */
142
+ async mockRegister(did, _keyId) {
143
+ (0, test_environment_1.ensureTestMode)();
144
+ // Simulate network failure
145
+ if (this.shouldSimulateKTAFailure("network")) {
146
+ throw new Error(`${test_1.TEST_ERROR_CODES.MOCK_KTA_FAILURE}: Network error`);
147
+ }
148
+ // Simulate auth failure
149
+ if (this.shouldSimulateKTAFailure("auth")) {
150
+ return {
151
+ success: false,
152
+ error: "Authentication failed",
153
+ };
154
+ }
155
+ // Simulate invalid response
156
+ if (this.shouldSimulateKTAFailure("invalid")) {
157
+ return {
158
+ success: false,
159
+ error: "Invalid response from KTA",
160
+ };
161
+ }
162
+ // Simulate timeout
163
+ if (this.shouldSimulateKTAFailure("timeout")) {
164
+ await new Promise((resolve) => setTimeout(resolve, 5000));
165
+ throw new Error(`${test_1.TEST_ERROR_CODES.MOCK_KTA_FAILURE}: Request timeout`);
166
+ }
167
+ // Success case
168
+ return {
169
+ success: true,
170
+ agentURL: `https://test-kta.example.com/agents/${did.replace("did:test:", "")}`,
171
+ };
172
+ }
173
+ /**
174
+ * Mock KTA delegation check
175
+ */
176
+ async mockCheckDelegation(did, keyId) {
177
+ (0, test_environment_1.ensureTestMode)();
178
+ // Simulate failures if configured
179
+ if (this.shouldSimulateKTAFailure("network")) {
180
+ throw new Error(`${test_1.TEST_ERROR_CODES.MOCK_KTA_FAILURE}: Network error during delegation check`);
181
+ }
182
+ if (this.shouldSimulateKTAFailure("auth")) {
183
+ return {
184
+ status: "revoked",
185
+ error: "Authentication failed",
186
+ };
187
+ }
188
+ const status = this.getDelegationStatus(did, keyId);
189
+ return { status };
190
+ }
191
+ /**
192
+ * Reset the mock provider to initial state
193
+ */
194
+ reset() {
195
+ (0, test_environment_1.ensureTestMode)();
196
+ this.identities.clear();
197
+ this.delegations.clear();
198
+ this.ktaFailures.clear();
199
+ this.deterministicSeed = undefined;
200
+ this.loadPredefinedIdentities();
201
+ }
202
+ /**
203
+ * Get all configured identities
204
+ */
205
+ getAllIdentities() {
206
+ (0, test_environment_1.ensureTestMode)();
207
+ return Object.fromEntries(this.identities.entries());
208
+ }
209
+ /**
210
+ * Get all delegation statuses
211
+ */
212
+ getAllDelegations() {
213
+ (0, test_environment_1.ensureTestMode)();
214
+ return Object.fromEntries(this.delegations.entries());
215
+ }
216
+ }
217
+ exports.MockIdentityProvider = MockIdentityProvider;
218
+ /**
219
+ * Global mock identity provider instance for testing
220
+ */
221
+ let globalMockProvider;
222
+ /**
223
+ * Get or create the global mock identity provider
224
+ */
225
+ function getMockIdentityProvider() {
226
+ (0, test_environment_1.ensureTestMode)();
227
+ if (!globalMockProvider) {
228
+ globalMockProvider = new MockIdentityProvider();
229
+ }
230
+ return globalMockProvider;
231
+ }
232
+ /**
233
+ * Reset the global mock identity provider
234
+ */
235
+ function resetMockIdentityProvider() {
236
+ (0, test_environment_1.ensureTestMode)();
237
+ if (globalMockProvider) {
238
+ globalMockProvider.reset();
239
+ }
240
+ else {
241
+ globalMockProvider = new MockIdentityProvider();
242
+ }
243
+ }