@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.
- package/README.md +350 -213
- package/dist/149.js +1 -0
- package/dist/189.js +1 -0
- package/dist/261.js +1 -0
- package/dist/28.js +1 -0
- package/dist/295.js +1 -0
- package/dist/460.js +1 -0
- package/dist/570.js +1 -0
- package/dist/634.js +1 -0
- package/dist/647.js +1 -0
- package/dist/67.js +1 -0
- package/dist/739.js +1 -0
- package/dist/742.js +1 -0
- package/dist/904.js +1 -0
- package/dist/938.js +1 -0
- package/dist/auth/api-key.d.ts +16 -0
- package/dist/auth/api-key.js +82 -0
- package/dist/auth/jwt.d.ts +43 -0
- package/dist/auth/jwt.js +51 -0
- package/dist/auth/oauth/factory.d.ts +12 -0
- package/dist/auth/oauth/factory.js +36 -0
- package/dist/auth/oauth/index.d.ts +5 -0
- package/dist/auth/oauth/index.js +27 -0
- package/dist/auth/oauth/providers/proxy-provider.d.ts +13 -0
- package/dist/auth/oauth/providers/proxy-provider.js +159 -0
- package/dist/auth/oauth/router.d.ts +4 -0
- package/dist/auth/oauth/router.js +294 -0
- package/dist/auth/oauth/storage/memory-storage.d.ts +12 -0
- package/dist/auth/oauth/storage/memory-storage.js +40 -0
- package/dist/auth/oauth/types.d.ts +112 -0
- package/dist/cache/__tests__/cloudflare-kv-nonce-cache.test.d.ts +4 -0
- package/dist/cache/__tests__/cloudflare-kv-nonce-cache.test.js +176 -0
- package/dist/cache/__tests__/concurrency.test.d.ts +5 -0
- package/dist/cache/__tests__/concurrency.test.js +300 -0
- package/dist/cache/__tests__/dynamodb-nonce-cache.test.d.ts +4 -0
- package/dist/cache/__tests__/dynamodb-nonce-cache.test.js +176 -0
- package/dist/cache/__tests__/memory-nonce-cache.test.d.ts +4 -0
- package/dist/cache/__tests__/memory-nonce-cache.test.js +132 -0
- package/dist/cache/__tests__/nonce-cache-factory-simple.test.d.ts +4 -0
- package/dist/cache/__tests__/nonce-cache-factory-simple.test.js +133 -0
- package/dist/cache/__tests__/nonce-cache-factory.test.d.ts +4 -0
- package/dist/cache/__tests__/nonce-cache-factory.test.js +252 -0
- package/dist/cache/__tests__/redis-nonce-cache.test.d.ts +4 -0
- package/dist/cache/__tests__/redis-nonce-cache.test.js +95 -0
- package/dist/cache/cloudflare-kv-nonce-cache.d.ts +14 -0
- package/dist/cache/cloudflare-kv-nonce-cache.js +93 -0
- package/dist/cache/dynamodb-nonce-cache.d.ts +15 -0
- package/dist/cache/dynamodb-nonce-cache.js +92 -0
- package/dist/cache/index.d.ts +16 -0
- package/dist/cache/index.js +32 -0
- package/dist/cache/memory-nonce-cache.d.ts +44 -0
- package/dist/cache/memory-nonce-cache.js +105 -0
- package/dist/cache/nonce-cache-factory.d.ts +20 -0
- package/dist/cache/nonce-cache-factory.js +208 -0
- package/dist/cache/redis-nonce-cache.d.ts +14 -0
- package/dist/cache/redis-nonce-cache.js +53 -0
- package/dist/compiler/compiler-context.d.ts +23 -0
- package/dist/compiler/compiler-context.js +24 -0
- package/dist/compiler/config/constants.d.ts +41 -0
- package/dist/compiler/config/constants.js +45 -0
- package/dist/compiler/config/index.d.ts +252 -0
- package/dist/compiler/config/index.js +15 -0
- package/dist/compiler/config/injection.d.ts +26 -0
- package/dist/compiler/config/injection.js +58 -0
- package/dist/compiler/config/schemas/experimental/index.d.ts +91 -0
- package/dist/compiler/config/schemas/experimental/index.js +16 -0
- package/dist/compiler/config/schemas/experimental/oauth.d.ts +74 -0
- package/dist/compiler/config/schemas/experimental/oauth.js +25 -0
- package/dist/compiler/config/schemas/index.d.ts +6 -0
- package/dist/compiler/config/schemas/index.js +17 -0
- package/dist/compiler/config/schemas/paths.d.ts +9 -0
- package/dist/compiler/config/schemas/paths.js +12 -0
- package/dist/compiler/config/schemas/transport/http.d.ts +82 -0
- package/dist/compiler/config/schemas/transport/http.js +33 -0
- package/dist/compiler/config/schemas/transport/stdio.d.ts +9 -0
- package/dist/compiler/config/schemas/transport/stdio.js +15 -0
- package/dist/compiler/config/schemas/webpack.d.ts +3 -0
- package/dist/compiler/config/schemas/webpack.js +15 -0
- package/dist/compiler/config/types.d.ts +1 -0
- package/dist/compiler/config/types.js +2 -0
- package/dist/compiler/config/utils.d.ts +20 -0
- package/dist/compiler/config/utils.js +36 -0
- package/dist/compiler/generate-env-code.d.ts +1 -0
- package/dist/compiler/generate-env-code.js +8 -0
- package/dist/compiler/generate-import-code.d.ts +1 -0
- package/dist/compiler/generate-import-code.js +24 -0
- package/dist/compiler/get-webpack-config/get-entries.d.ts +3 -0
- package/dist/compiler/get-webpack-config/get-entries.js +29 -0
- package/dist/compiler/get-webpack-config/get-externals.d.ts +7 -0
- package/dist/compiler/get-webpack-config/get-externals.js +88 -0
- package/dist/compiler/get-webpack-config/get-injected-variables.d.ts +8 -0
- package/dist/compiler/get-webpack-config/get-injected-variables.js +25 -0
- package/dist/compiler/get-webpack-config/index.d.ts +4 -0
- package/dist/compiler/get-webpack-config/index.js +101 -0
- package/dist/compiler/get-webpack-config/plugins.d.ts +8 -0
- package/dist/compiler/get-webpack-config/plugins.js +132 -0
- package/dist/compiler/get-webpack-config/resolve-tsconfig-paths.d.ts +9 -0
- package/dist/compiler/get-webpack-config/resolve-tsconfig-paths.js +40 -0
- package/dist/compiler/index.d.ts +6 -0
- package/dist/compiler/index.js +194 -0
- package/dist/compiler/on-first-build.d.ts +3 -0
- package/dist/compiler/on-first-build.js +58 -0
- package/dist/compiler/parse-xmcp-config.d.ts +9 -0
- package/dist/compiler/parse-xmcp-config.js +155 -0
- package/dist/compiler/start-http-server.d.ts +1 -0
- package/dist/compiler/start-http-server.js +34 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +38 -0
- package/dist/index.js.LICENSE.txt +49 -0
- package/dist/runtime/__tests__/audit.test.d.ts +4 -0
- package/dist/runtime/__tests__/audit.test.js +328 -0
- package/dist/runtime/__tests__/identity.test.d.ts +4 -0
- package/dist/runtime/__tests__/identity.test.js +164 -0
- package/dist/runtime/__tests__/mcpi-runtime.test.d.ts +4 -0
- package/dist/runtime/__tests__/mcpi-runtime.test.js +372 -0
- package/dist/runtime/__tests__/proof.test.d.ts +4 -0
- package/dist/runtime/__tests__/proof.test.js +302 -0
- package/dist/runtime/__tests__/session.test.d.ts +4 -0
- package/dist/runtime/__tests__/session.test.js +254 -0
- package/dist/runtime/__tests__/well-known.test.d.ts +4 -0
- package/dist/runtime/__tests__/well-known.test.js +312 -0
- package/dist/runtime/adapter-express.js +2 -0
- package/dist/runtime/adapter-express.js.LICENSE.txt +252 -0
- package/dist/runtime/adapter-nextjs.js +2 -0
- package/dist/runtime/adapter-nextjs.js.LICENSE.txt +53 -0
- package/dist/runtime/adapters/express/index.d.ts +2 -0
- package/dist/runtime/adapters/express/index.js +48 -0
- package/dist/runtime/adapters/nextjs/index.d.ts +8 -0
- package/dist/runtime/adapters/nextjs/index.js +18 -0
- package/dist/runtime/audit.d.ts +93 -0
- package/dist/runtime/audit.js +212 -0
- package/dist/runtime/debug.d.ts +118 -0
- package/dist/runtime/debug.js +612 -0
- package/dist/runtime/delegation-hooks.d.ts +85 -0
- package/dist/runtime/delegation-hooks.js +116 -0
- package/dist/runtime/demo.d.ts +71 -0
- package/dist/runtime/demo.js +135 -0
- package/dist/runtime/headers.d.ts +1 -0
- package/dist/runtime/headers.js +9 -0
- package/dist/runtime/http.js +2 -0
- package/dist/runtime/http.js.LICENSE.txt +252 -0
- package/dist/runtime/identity.d.ts +105 -0
- package/dist/runtime/identity.js +232 -0
- package/dist/runtime/index.d.ts +16 -0
- package/dist/runtime/index.js +56 -0
- package/dist/runtime/mcpi-runtime.d.ts +164 -0
- package/dist/runtime/mcpi-runtime.js +352 -0
- package/dist/runtime/proof.d.ts +87 -0
- package/dist/runtime/proof.js +223 -0
- package/dist/runtime/session.d.ts +88 -0
- package/dist/runtime/session.js +216 -0
- package/dist/runtime/stdio.js +2 -0
- package/dist/runtime/stdio.js.LICENSE.txt +1 -0
- package/dist/runtime/templates/home.d.ts +2 -0
- package/dist/runtime/templates/home.js +50 -0
- package/dist/runtime/transports/http/base-streamable-http.d.ts +25 -0
- package/dist/runtime/transports/http/base-streamable-http.js +16 -0
- package/dist/runtime/transports/http/http-context.d.ts +9 -0
- package/dist/runtime/transports/http/http-context.js +8 -0
- package/dist/runtime/transports/http/index.js +55 -0
- package/dist/runtime/transports/http/setup-cors.d.ts +4 -0
- package/dist/runtime/transports/http/setup-cors.js +24 -0
- package/dist/runtime/transports/http/stateless-streamable-http.d.ts +39 -0
- package/dist/runtime/transports/http/stateless-streamable-http.js +331 -0
- package/dist/runtime/transports/stdio/index.d.ts +1 -0
- package/dist/runtime/transports/stdio/index.js +51 -0
- package/dist/runtime/utils/server.d.ts +42 -0
- package/dist/runtime/utils/server.js +39 -0
- package/dist/runtime/utils/tools.d.ts +8 -0
- package/dist/runtime/utils/tools.js +115 -0
- package/dist/runtime/verifier-middleware.d.ts +76 -0
- package/dist/runtime/verifier-middleware.js +322 -0
- package/dist/runtime/well-known.d.ts +151 -0
- package/dist/runtime/well-known.js +258 -0
- package/dist/storage/config.d.ts +28 -0
- package/dist/storage/config.js +79 -0
- package/dist/storage/delegation.d.ts +59 -0
- package/dist/storage/delegation.js +130 -0
- package/dist/storage/merkle-verifier.d.ts +84 -0
- package/dist/storage/merkle-verifier.js +261 -0
- package/dist/test/__tests__/nonce-cache-integration.test.d.ts +1 -0
- package/dist/test/__tests__/nonce-cache-integration.test.js +116 -0
- package/dist/test/__tests__/nonce-cache.test.d.ts +1 -0
- package/dist/test/__tests__/nonce-cache.test.js +122 -0
- package/dist/test/__tests__/runtime-integration.test.d.ts +4 -0
- package/dist/test/__tests__/runtime-integration.test.js +192 -0
- package/dist/test/__tests__/test-infrastructure.test.d.ts +4 -0
- package/dist/test/__tests__/test-infrastructure.test.js +178 -0
- package/dist/test/deterministic-keys.d.ts +31 -0
- package/dist/test/deterministic-keys.js +108 -0
- package/dist/test/examples/test-usage-example.d.ts +140 -0
- package/dist/test/examples/test-usage-example.js +175 -0
- package/dist/test/index.d.ts +11 -0
- package/dist/test/index.js +27 -0
- package/dist/test/local-verification.d.ts +28 -0
- package/dist/test/local-verification.js +342 -0
- package/dist/test/mock-identity-provider.d.ts +96 -0
- package/dist/test/mock-identity-provider.js +243 -0
- package/dist/test/runtime-integration.d.ts +63 -0
- package/dist/test/runtime-integration.js +140 -0
- package/dist/test/test-environment.d.ts +26 -0
- package/dist/test/test-environment.js +50 -0
- package/dist/types/declarations.d.ts +1 -0
- package/dist/types/declarations.js +6 -0
- package/dist/types/middleware.d.ts +2 -0
- package/dist/types/middleware.js +2 -0
- package/dist/types/tool.d.ts +80 -0
- package/dist/types/tool.js +2 -0
- package/dist/utils/cli-icons.d.ts +3 -0
- package/dist/utils/cli-icons.js +7 -0
- package/dist/utils/constants.d.ts +6 -0
- package/dist/utils/constants.js +13 -0
- package/dist/utils/context.d.ts +33 -0
- package/dist/utils/context.js +58 -0
- package/dist/utils/file-watcher.d.ts +19 -0
- package/dist/utils/file-watcher.js +49 -0
- package/dist/utils/fs-utils.d.ts +2 -0
- package/dist/utils/fs-utils.js +22 -0
- package/dist/utils/path-validation.d.ts +3 -0
- package/dist/utils/path-validation.js +56 -0
- package/dist/utils/spawn-process.d.ts +9 -0
- package/dist/utils/spawn-process.js +50 -0
- package/dist/utils/subscribable.d.ts +12 -0
- package/dist/utils/subscribable.js +44 -0
- package/package.json +91 -77
- package/dist/cjs/auto.js +0 -16
- package/dist/cjs/cli-mode.d.ts +0 -16
- package/dist/cjs/cli-mode.js +0 -32
- package/dist/cjs/crypto.d.ts +0 -16
- package/dist/cjs/crypto.js +0 -212
- package/dist/cjs/dev-helper.d.ts +0 -3
- package/dist/cjs/dev-helper.js +0 -46
- package/dist/cjs/encrypted-storage.d.ts +0 -11
- package/dist/cjs/encrypted-storage.js +0 -73
- package/dist/cjs/index.d.ts +0 -56
- package/dist/cjs/index.js +0 -727
- package/dist/cjs/logger.d.ts +0 -32
- package/dist/cjs/logger.js +0 -85
- package/dist/cjs/nextjs.d.ts +0 -10
- package/dist/cjs/nextjs.js +0 -83
- package/dist/cjs/platform-info.d.ts +0 -36
- package/dist/cjs/platform-info.js +0 -274
- package/dist/cjs/polling.d.ts +0 -13
- package/dist/cjs/polling.js +0 -52
- package/dist/cjs/registry/index.d.ts +0 -12
- package/dist/cjs/registry/index.js +0 -56
- package/dist/cjs/registry/knowthat.d.ts +0 -17
- package/dist/cjs/registry/knowthat.js +0 -173
- package/dist/cjs/rotation.d.ts +0 -35
- package/dist/cjs/rotation.js +0 -102
- package/dist/cjs/storage.d.ts +0 -41
- package/dist/cjs/storage.js +0 -163
- package/dist/cjs/transport.d.ts +0 -35
- package/dist/cjs/transport.js +0 -300
- package/dist/cjs/types.d.ts +0 -206
- package/dist/cjs/vercel-adapter.d.ts +0 -8
- package/dist/cjs/vercel-adapter.js +0 -67
- package/dist/esm/auto.d.ts +0 -13
- package/dist/esm/auto.d.ts.map +0 -1
- package/dist/esm/auto.js +0 -30
- package/dist/esm/auto.js.map +0 -1
- package/dist/esm/cli-mode.d.ts +0 -52
- package/dist/esm/cli-mode.d.ts.map +0 -1
- package/dist/esm/cli-mode.js +0 -59
- package/dist/esm/cli-mode.js.map +0 -1
- package/dist/esm/crypto.d.ts +0 -51
- package/dist/esm/crypto.d.ts.map +0 -1
- package/dist/esm/crypto.js +0 -230
- package/dist/esm/crypto.js.map +0 -1
- package/dist/esm/dev-helper.d.ts +0 -15
- package/dist/esm/dev-helper.d.ts.map +0 -1
- package/dist/esm/dev-helper.js +0 -63
- package/dist/esm/dev-helper.js.map +0 -1
- package/dist/esm/encrypted-storage.d.ts +0 -19
- package/dist/esm/encrypted-storage.d.ts.map +0 -1
- package/dist/esm/encrypted-storage.js +0 -48
- package/dist/esm/encrypted-storage.js.map +0 -1
- package/dist/esm/index.d.ts +0 -129
- package/dist/esm/index.d.ts.map +0 -1
- package/dist/esm/index.js +0 -853
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/logger.d.ts +0 -46
- package/dist/esm/logger.d.ts.map +0 -1
- package/dist/esm/logger.js +0 -100
- package/dist/esm/logger.js.map +0 -1
- package/dist/esm/nextjs.d.ts +0 -22
- package/dist/esm/nextjs.d.ts.map +0 -1
- package/dist/esm/nextjs.js +0 -83
- package/dist/esm/nextjs.js.map +0 -1
- package/dist/esm/package.json +0 -1
- package/dist/esm/platform-info.d.ts +0 -74
- package/dist/esm/platform-info.d.ts.map +0 -1
- package/dist/esm/platform-info.js +0 -293
- package/dist/esm/platform-info.js.map +0 -1
- package/dist/esm/polling.d.ts +0 -29
- package/dist/esm/polling.d.ts.map +0 -1
- package/dist/esm/polling.js +0 -76
- package/dist/esm/polling.js.map +0 -1
- package/dist/esm/registry/index.d.ts +0 -43
- package/dist/esm/registry/index.d.ts.map +0 -1
- package/dist/esm/registry/index.js +0 -89
- package/dist/esm/registry/index.js.map +0 -1
- package/dist/esm/registry/knowthat.d.ts +0 -44
- package/dist/esm/registry/knowthat.d.ts.map +0 -1
- package/dist/esm/registry/knowthat.js +0 -220
- package/dist/esm/registry/knowthat.js.map +0 -1
- package/dist/esm/rotation.d.ts +0 -57
- package/dist/esm/rotation.d.ts.map +0 -1
- package/dist/esm/rotation.js +0 -133
- package/dist/esm/rotation.js.map +0 -1
- package/dist/esm/storage.d.ts +0 -65
- package/dist/esm/storage.d.ts.map +0 -1
- package/dist/esm/storage.js +0 -160
- package/dist/esm/storage.js.map +0 -1
- package/dist/esm/transport.d.ts +0 -52
- package/dist/esm/transport.d.ts.map +0 -1
- package/dist/esm/transport.js +0 -340
- package/dist/esm/transport.js.map +0 -1
- package/dist/esm/types.d.ts +0 -293
- package/dist/esm/types.d.ts.map +0 -1
- package/dist/esm/types.js +0 -5
- package/dist/esm/types.js.map +0 -1
- package/dist/esm/vercel-adapter.d.ts +0 -26
- package/dist/esm/vercel-adapter.d.ts.map +0 -1
- package/dist/esm/vercel-adapter.js +0 -80
- package/dist/esm/vercel-adapter.js.map +0 -1
- /package/dist/{cjs → auth/oauth}/types.js +0 -0
- /package/dist/{cjs/auto.d.ts → runtime/transports/http/index.d.ts} +0 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const memory_nonce_cache_js_1 = require("../../cache/memory-nonce-cache.js");
|
|
5
|
+
const nonce_cache_factory_js_1 = require("../../cache/nonce-cache-factory.js");
|
|
6
|
+
(0, vitest_1.describe)("NonceCache", () => {
|
|
7
|
+
(0, vitest_1.describe)("MemoryNonceCache", () => {
|
|
8
|
+
let cache;
|
|
9
|
+
(0, vitest_1.beforeEach)(() => {
|
|
10
|
+
cache = new memory_nonce_cache_js_1.MemoryNonceCache();
|
|
11
|
+
});
|
|
12
|
+
(0, vitest_1.it)("should not find non-existent nonce", async () => {
|
|
13
|
+
const exists = await cache.has("non-existent-nonce");
|
|
14
|
+
(0, vitest_1.expect)(exists).toBe(false);
|
|
15
|
+
});
|
|
16
|
+
(0, vitest_1.it)("should add and find nonce", async () => {
|
|
17
|
+
const nonce = "test-nonce-123";
|
|
18
|
+
await cache.add(nonce, 60); // 60 seconds TTL
|
|
19
|
+
const exists = await cache.has(nonce);
|
|
20
|
+
(0, vitest_1.expect)(exists).toBe(true);
|
|
21
|
+
});
|
|
22
|
+
(0, vitest_1.it)("should prevent replay attacks by rejecting duplicate nonces", async () => {
|
|
23
|
+
const nonce = "duplicate-nonce";
|
|
24
|
+
await cache.add(nonce, 60);
|
|
25
|
+
await (0, vitest_1.expect)(cache.add(nonce, 60)).rejects.toThrow("Nonce duplicate-nonce already exists - potential replay attack");
|
|
26
|
+
});
|
|
27
|
+
(0, vitest_1.it)("should expire nonces after TTL", async () => {
|
|
28
|
+
const nonce = "expiring-nonce";
|
|
29
|
+
await cache.add(nonce, 0.1); // 0.1 seconds TTL
|
|
30
|
+
// Should exist immediately
|
|
31
|
+
(0, vitest_1.expect)(await cache.has(nonce)).toBe(true);
|
|
32
|
+
// Wait for expiry
|
|
33
|
+
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
34
|
+
// Should be expired
|
|
35
|
+
(0, vitest_1.expect)(await cache.has(nonce)).toBe(false);
|
|
36
|
+
});
|
|
37
|
+
(0, vitest_1.it)("should clean up expired entries", async () => {
|
|
38
|
+
const nonce1 = "nonce-1";
|
|
39
|
+
const nonce2 = "nonce-2";
|
|
40
|
+
await cache.add(nonce1, 0.1); // Short TTL
|
|
41
|
+
await cache.add(nonce2, 60); // Long TTL
|
|
42
|
+
// Wait for first nonce to expire
|
|
43
|
+
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
44
|
+
await cache.cleanup();
|
|
45
|
+
(0, vitest_1.expect)(await cache.has(nonce1)).toBe(false);
|
|
46
|
+
(0, vitest_1.expect)(await cache.has(nonce2)).toBe(true);
|
|
47
|
+
});
|
|
48
|
+
(0, vitest_1.it)("should handle atomic add-if-absent semantics", async () => {
|
|
49
|
+
const nonce = "atomic-test";
|
|
50
|
+
// First add should succeed
|
|
51
|
+
await (0, vitest_1.expect)(cache.add(nonce, 60)).resolves.not.toThrow();
|
|
52
|
+
// Second add should fail
|
|
53
|
+
await (0, vitest_1.expect)(cache.add(nonce, 60)).rejects.toThrow("potential replay attack");
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
(0, vitest_1.describe)("Cache Type Detection", () => {
|
|
57
|
+
(0, vitest_1.beforeEach)(() => {
|
|
58
|
+
// Clear environment variables
|
|
59
|
+
delete process.env.mcpi_NONCE_CACHE_TYPE;
|
|
60
|
+
delete process.env.REDIS_URL;
|
|
61
|
+
delete process.env.mcpi_REDIS_URL;
|
|
62
|
+
delete process.env.AWS_REGION;
|
|
63
|
+
delete process.env.mcpi_DYNAMODB_TABLE;
|
|
64
|
+
});
|
|
65
|
+
(0, vitest_1.it)("should detect memory cache by default", () => {
|
|
66
|
+
const type = (0, nonce_cache_factory_js_1.detectCacheType)();
|
|
67
|
+
(0, vitest_1.expect)(type).toBe("memory");
|
|
68
|
+
});
|
|
69
|
+
(0, vitest_1.it)("should detect redis when REDIS_URL is set", () => {
|
|
70
|
+
process.env.REDIS_URL = "redis://localhost:6379";
|
|
71
|
+
const type = (0, nonce_cache_factory_js_1.detectCacheType)();
|
|
72
|
+
(0, vitest_1.expect)(type).toBe("redis");
|
|
73
|
+
});
|
|
74
|
+
(0, vitest_1.it)("should detect dynamodb when AWS_REGION is set", () => {
|
|
75
|
+
process.env.AWS_REGION = "us-east-1";
|
|
76
|
+
const type = (0, nonce_cache_factory_js_1.detectCacheType)();
|
|
77
|
+
(0, vitest_1.expect)(type).toBe("dynamodb");
|
|
78
|
+
});
|
|
79
|
+
(0, vitest_1.it)("should respect explicit cache type configuration", () => {
|
|
80
|
+
process.env.REDIS_URL = "redis://localhost:6379"; // This would normally trigger redis
|
|
81
|
+
process.env.mcpi_NONCE_CACHE_TYPE = "memory";
|
|
82
|
+
const type = (0, nonce_cache_factory_js_1.detectCacheType)();
|
|
83
|
+
(0, vitest_1.expect)(type).toBe("memory");
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
(0, vitest_1.describe)("Cache Factory", () => {
|
|
87
|
+
(0, vitest_1.it)("should create memory cache by default", async () => {
|
|
88
|
+
const cache = await (0, nonce_cache_factory_js_1.createNonceCache)();
|
|
89
|
+
(0, vitest_1.expect)(cache).toBeInstanceOf(memory_nonce_cache_js_1.MemoryNonceCache);
|
|
90
|
+
});
|
|
91
|
+
(0, vitest_1.it)("should create memory cache when redis connection fails", async () => {
|
|
92
|
+
// Mock console.warn to avoid noise in tests
|
|
93
|
+
const warnSpy = vitest_1.vi.spyOn(console, "warn").mockImplementation(() => { });
|
|
94
|
+
const cache = await (0, nonce_cache_factory_js_1.createNonceCache)({
|
|
95
|
+
type: "redis",
|
|
96
|
+
redis: { url: "redis://invalid-host:6379", keyPrefix: "test:" },
|
|
97
|
+
});
|
|
98
|
+
(0, vitest_1.expect)(cache).toBeInstanceOf(memory_nonce_cache_js_1.MemoryNonceCache);
|
|
99
|
+
// Check that we got a warning about Redis failure (the exact message may vary)
|
|
100
|
+
(0, vitest_1.expect)(warnSpy).toHaveBeenCalledWith(vitest_1.expect.stringContaining("Failed to"), vitest_1.expect.anything());
|
|
101
|
+
warnSpy.mockRestore();
|
|
102
|
+
});
|
|
103
|
+
(0, vitest_1.it)("should handle missing configuration gracefully", async () => {
|
|
104
|
+
const warnSpy = vitest_1.vi.spyOn(console, "warn").mockImplementation(() => { });
|
|
105
|
+
const cache = await (0, nonce_cache_factory_js_1.createNonceCache)({
|
|
106
|
+
type: "dynamodb",
|
|
107
|
+
// Missing tableName
|
|
108
|
+
});
|
|
109
|
+
(0, vitest_1.expect)(cache).toBeInstanceOf(memory_nonce_cache_js_1.MemoryNonceCache);
|
|
110
|
+
(0, vitest_1.expect)(warnSpy).toHaveBeenCalledWith(vitest_1.expect.stringContaining("DynamoDB table name not found"));
|
|
111
|
+
warnSpy.mockRestore();
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
(0, vitest_1.describe)("Multi-instance Warning", () => {
|
|
115
|
+
(0, vitest_1.it)("should warn about multi-instance limitations for memory cache", () => {
|
|
116
|
+
const warnSpy = vitest_1.vi.spyOn(console, "warn").mockImplementation(() => { });
|
|
117
|
+
new memory_nonce_cache_js_1.MemoryNonceCache();
|
|
118
|
+
(0, vitest_1.expect)(warnSpy).toHaveBeenCalledWith(vitest_1.expect.stringContaining("not suitable for multi-instance deployments"));
|
|
119
|
+
warnSpy.mockRestore();
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
});
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Runtime integration tests
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const vitest_1 = require("vitest");
|
|
7
|
+
const test_environment_js_1 = require("../test-environment.js");
|
|
8
|
+
const mock_identity_provider_js_1 = require("../mock-identity-provider.js");
|
|
9
|
+
const runtime_integration_js_1 = require("../runtime-integration.js");
|
|
10
|
+
const test_1 = require("@kya-os/contracts/test");
|
|
11
|
+
(0, vitest_1.describe)("Runtime Integration", () => {
|
|
12
|
+
(0, vitest_1.beforeEach)(() => {
|
|
13
|
+
(0, test_environment_js_1.configureTestEnvironment)({ seed: "runtime-test" });
|
|
14
|
+
(0, mock_identity_provider_js_1.resetMockIdentityProvider)();
|
|
15
|
+
});
|
|
16
|
+
(0, vitest_1.describe)("Test Runtime Configuration", () => {
|
|
17
|
+
(0, vitest_1.it)("should provide test runtime config in test mode", () => {
|
|
18
|
+
const config = (0, runtime_integration_js_1.getTestRuntimeConfig)();
|
|
19
|
+
(0, vitest_1.expect)(config).toBeDefined();
|
|
20
|
+
(0, vitest_1.expect)(config?.skipKTACalls).toBe(true);
|
|
21
|
+
(0, vitest_1.expect)(config?.useMockIdentities).toBe(true);
|
|
22
|
+
(0, vitest_1.expect)(config?.deterministicKeys).toBe(true);
|
|
23
|
+
(0, vitest_1.expect)(config?.mockKTAResponses).toBe(true);
|
|
24
|
+
});
|
|
25
|
+
(0, vitest_1.it)("should return null config outside test mode", () => {
|
|
26
|
+
// Temporarily disable test mode
|
|
27
|
+
const originalEnv = process.env.XMCP_ENV;
|
|
28
|
+
process.env.XMCP_ENV = "production";
|
|
29
|
+
const config = (0, runtime_integration_js_1.getTestRuntimeConfig)();
|
|
30
|
+
(0, vitest_1.expect)(config).toBeNull();
|
|
31
|
+
// Restore test mode
|
|
32
|
+
process.env.XMCP_ENV = originalEnv;
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
(0, vitest_1.describe)("KTA Call Interception", () => {
|
|
36
|
+
(0, vitest_1.it)("should intercept register calls", async () => {
|
|
37
|
+
const result = await (0, runtime_integration_js_1.interceptKTACall)("register", async () => {
|
|
38
|
+
throw new Error("Should not call original");
|
|
39
|
+
});
|
|
40
|
+
(0, vitest_1.expect)(result).toMatchObject({
|
|
41
|
+
success: true,
|
|
42
|
+
agentURL: vitest_1.expect.stringContaining("test-kta.example.com"),
|
|
43
|
+
conformanceCapabilities: ["handshake", "signing", "verification"],
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
(0, vitest_1.it)("should intercept delegation checks", async () => {
|
|
47
|
+
const result = await (0, runtime_integration_js_1.interceptKTACall)("checkDelegation", async () => {
|
|
48
|
+
throw new Error("Should not call original");
|
|
49
|
+
});
|
|
50
|
+
(0, vitest_1.expect)(result).toMatchObject({
|
|
51
|
+
status: "active",
|
|
52
|
+
valid: true,
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
(0, vitest_1.it)("should intercept claim calls", async () => {
|
|
56
|
+
const result = await (0, runtime_integration_js_1.interceptKTACall)("claim", async () => {
|
|
57
|
+
throw new Error("Should not call original");
|
|
58
|
+
});
|
|
59
|
+
(0, vitest_1.expect)(result).toMatchObject({
|
|
60
|
+
success: true,
|
|
61
|
+
claimed: true,
|
|
62
|
+
agentURL: vitest_1.expect.stringContaining("test-kta.example.com"),
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
(0, vitest_1.it)("should use custom mock response when provided", async () => {
|
|
66
|
+
const customResponse = { custom: "response" };
|
|
67
|
+
const result = await (0, runtime_integration_js_1.interceptKTACall)("register", async () => {
|
|
68
|
+
throw new Error("Should not call original");
|
|
69
|
+
}, async () => customResponse);
|
|
70
|
+
(0, vitest_1.expect)(result).toEqual(customResponse);
|
|
71
|
+
});
|
|
72
|
+
(0, vitest_1.it)("should call original function when not in test mode", async () => {
|
|
73
|
+
// Temporarily disable test mode
|
|
74
|
+
const originalEnv = process.env.XMCP_ENV;
|
|
75
|
+
process.env.XMCP_ENV = "production";
|
|
76
|
+
let originalCalled = false;
|
|
77
|
+
await (0, runtime_integration_js_1.interceptKTACall)("register", async () => {
|
|
78
|
+
originalCalled = true;
|
|
79
|
+
return { called: true };
|
|
80
|
+
});
|
|
81
|
+
(0, vitest_1.expect)(originalCalled).toBe(true);
|
|
82
|
+
// Restore test mode
|
|
83
|
+
process.env.XMCP_ENV = originalEnv;
|
|
84
|
+
});
|
|
85
|
+
(0, vitest_1.it)("should throw error for unknown operations", async () => {
|
|
86
|
+
await (0, vitest_1.expect)((0, runtime_integration_js_1.interceptKTACall)("unknownOperation", async () => ({ success: true }))).rejects.toThrow(test_1.TEST_ERROR_CODES.INVALID_TEST_CONFIGURATION);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
(0, vitest_1.describe)("Test Identity for Runtime", () => {
|
|
90
|
+
(0, vitest_1.it)("should get test identity for runtime", () => {
|
|
91
|
+
const identity = (0, runtime_integration_js_1.getTestIdentityForRuntime)("agent1");
|
|
92
|
+
(0, vitest_1.expect)(identity).toBeDefined();
|
|
93
|
+
(0, vitest_1.expect)(identity.did).toBeDefined();
|
|
94
|
+
(0, vitest_1.expect)(identity.keyId).toBeDefined();
|
|
95
|
+
(0, vitest_1.expect)(identity.privateKey).toBeDefined();
|
|
96
|
+
(0, vitest_1.expect)(identity.publicKey).toBeDefined();
|
|
97
|
+
});
|
|
98
|
+
(0, vitest_1.it)("should throw error for non-existent identity", () => {
|
|
99
|
+
(0, vitest_1.expect)(() => {
|
|
100
|
+
(0, runtime_integration_js_1.getTestIdentityForRuntime)("nonexistent");
|
|
101
|
+
}).toThrow(test_1.TEST_ERROR_CODES.INVALID_TEST_CONFIGURATION);
|
|
102
|
+
});
|
|
103
|
+
(0, vitest_1.it)("should throw error outside test mode", () => {
|
|
104
|
+
// Temporarily disable test mode
|
|
105
|
+
const originalEnv = process.env.XMCP_ENV;
|
|
106
|
+
process.env.XMCP_ENV = "production";
|
|
107
|
+
(0, vitest_1.expect)(() => {
|
|
108
|
+
(0, runtime_integration_js_1.getTestIdentityForRuntime)("agent1");
|
|
109
|
+
}).toThrow(test_1.TEST_ERROR_CODES.INVALID_TEST_CONFIGURATION);
|
|
110
|
+
// Restore test mode
|
|
111
|
+
process.env.XMCP_ENV = originalEnv;
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
(0, vitest_1.describe)("Test Session Context", () => {
|
|
115
|
+
(0, vitest_1.it)("should create test session context with defaults", () => {
|
|
116
|
+
const context = (0, runtime_integration_js_1.createTestSessionContext)();
|
|
117
|
+
(0, vitest_1.expect)(context).toMatchObject({
|
|
118
|
+
sessionId: "sess_test_default",
|
|
119
|
+
audience: "test.example.com",
|
|
120
|
+
nonce: "test_nonce_123",
|
|
121
|
+
timestamp: vitest_1.expect.any(Number),
|
|
122
|
+
createdAt: vitest_1.expect.any(Number),
|
|
123
|
+
lastActivity: vitest_1.expect.any(Number),
|
|
124
|
+
ttlMinutes: 30,
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
(0, vitest_1.it)("should create test session context with custom options", () => {
|
|
128
|
+
const options = {
|
|
129
|
+
sessionId: "custom_session",
|
|
130
|
+
audience: "custom.example.com",
|
|
131
|
+
nonce: "custom_nonce",
|
|
132
|
+
timestamp: 1234567890,
|
|
133
|
+
};
|
|
134
|
+
const context = (0, runtime_integration_js_1.createTestSessionContext)(options);
|
|
135
|
+
(0, vitest_1.expect)(context).toMatchObject({
|
|
136
|
+
sessionId: "custom_session",
|
|
137
|
+
audience: "custom.example.com",
|
|
138
|
+
nonce: "custom_nonce",
|
|
139
|
+
timestamp: 1234567890,
|
|
140
|
+
ttlMinutes: 30,
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
(0, vitest_1.it)("should throw error outside test mode", () => {
|
|
144
|
+
// Temporarily disable test mode
|
|
145
|
+
const originalEnv = process.env.XMCP_ENV;
|
|
146
|
+
process.env.XMCP_ENV = "production";
|
|
147
|
+
(0, vitest_1.expect)(() => {
|
|
148
|
+
(0, runtime_integration_js_1.createTestSessionContext)();
|
|
149
|
+
}).toThrow(test_1.TEST_ERROR_CODES.INVALID_TEST_CONFIGURATION);
|
|
150
|
+
// Restore test mode
|
|
151
|
+
process.env.XMCP_ENV = originalEnv;
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
(0, vitest_1.describe)("Test Environment Validation", () => {
|
|
155
|
+
(0, vitest_1.it)("should validate test environment successfully", () => {
|
|
156
|
+
const validation = (0, runtime_integration_js_1.validateTestEnvironment)();
|
|
157
|
+
(0, vitest_1.expect)(validation.valid).toBe(true);
|
|
158
|
+
(0, vitest_1.expect)(validation.errors).toHaveLength(0);
|
|
159
|
+
});
|
|
160
|
+
(0, vitest_1.it)("should detect invalid test environment", () => {
|
|
161
|
+
// Temporarily disable test mode
|
|
162
|
+
const originalEnv = process.env.XMCP_ENV;
|
|
163
|
+
process.env.XMCP_ENV = "production";
|
|
164
|
+
const validation = (0, runtime_integration_js_1.validateTestEnvironment)();
|
|
165
|
+
(0, vitest_1.expect)(validation.valid).toBe(false);
|
|
166
|
+
(0, vitest_1.expect)(validation.errors).toContain("XMCP_ENV is not set to 'test'");
|
|
167
|
+
// Restore test mode
|
|
168
|
+
process.env.XMCP_ENV = originalEnv;
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
(0, vitest_1.describe)("Test Mode Guard", () => {
|
|
172
|
+
(0, vitest_1.it)("should allow function execution in test mode", () => {
|
|
173
|
+
const testFunction = (0, runtime_integration_js_1.testModeOnly)(() => "test result");
|
|
174
|
+
(0, vitest_1.expect)(testFunction()).toBe("test result");
|
|
175
|
+
});
|
|
176
|
+
(0, vitest_1.it)("should prevent function execution outside test mode", () => {
|
|
177
|
+
// Temporarily disable test mode
|
|
178
|
+
const originalEnv = process.env.XMCP_ENV;
|
|
179
|
+
process.env.XMCP_ENV = "production";
|
|
180
|
+
const testFunction = (0, runtime_integration_js_1.testModeOnly)(() => "test result");
|
|
181
|
+
(0, vitest_1.expect)(() => {
|
|
182
|
+
testFunction();
|
|
183
|
+
}).toThrow(test_1.TEST_ERROR_CODES.INVALID_TEST_CONFIGURATION);
|
|
184
|
+
// Restore test mode
|
|
185
|
+
process.env.XMCP_ENV = originalEnv;
|
|
186
|
+
});
|
|
187
|
+
(0, vitest_1.it)("should preserve function arguments and return types", () => {
|
|
188
|
+
const testFunction = (0, runtime_integration_js_1.testModeOnly)((a, b) => `${a}-${b}`);
|
|
189
|
+
(0, vitest_1.expect)(testFunction(42, "test")).toBe("42-test");
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
});
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Test infrastructure validation tests
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const vitest_1 = require("vitest");
|
|
7
|
+
const test_environment_js_1 = require("../test-environment.js");
|
|
8
|
+
const deterministic_keys_js_1 = require("../deterministic-keys.js");
|
|
9
|
+
const mock_identity_provider_js_1 = require("../mock-identity-provider.js");
|
|
10
|
+
const local_verification_js_1 = require("../local-verification.js");
|
|
11
|
+
const test_1 = require("@kya-os/contracts/test");
|
|
12
|
+
(0, vitest_1.describe)("Test Infrastructure", () => {
|
|
13
|
+
(0, vitest_1.beforeEach)(() => {
|
|
14
|
+
// Configure test environment
|
|
15
|
+
(0, test_environment_js_1.configureTestEnvironment)({ seed: "test-seed" });
|
|
16
|
+
(0, mock_identity_provider_js_1.resetMockIdentityProvider)();
|
|
17
|
+
});
|
|
18
|
+
(0, vitest_1.describe)("Test Environment", () => {
|
|
19
|
+
(0, vitest_1.it)("should detect test mode", () => {
|
|
20
|
+
(0, vitest_1.expect)((0, test_environment_js_1.isTestMode)()).toBe(true);
|
|
21
|
+
});
|
|
22
|
+
(0, vitest_1.it)("should skip KTA calls in test mode", () => {
|
|
23
|
+
(0, vitest_1.expect)((0, test_environment_js_1.shouldSkipKTACalls)()).toBe(true);
|
|
24
|
+
});
|
|
25
|
+
(0, vitest_1.it)("should configure test environment", () => {
|
|
26
|
+
(0, test_environment_js_1.configureTestEnvironment)({
|
|
27
|
+
seed: "custom-seed",
|
|
28
|
+
skipKTACalls: true,
|
|
29
|
+
});
|
|
30
|
+
(0, vitest_1.expect)(process.env.XMCP_TEST_SEED).toBe("custom-seed");
|
|
31
|
+
(0, vitest_1.expect)(process.env.XMCP_SKIP_KTA_CALLS).toBe("true");
|
|
32
|
+
(0, vitest_1.expect)(process.env.XMCP_ENV).toBe("test");
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
(0, vitest_1.describe)("Deterministic Keys", () => {
|
|
36
|
+
(0, vitest_1.it)("should generate deterministic key pairs", () => {
|
|
37
|
+
const keys1 = (0, deterministic_keys_js_1.generateDeterministicKeyPair)("test-seed-1");
|
|
38
|
+
const keys2 = (0, deterministic_keys_js_1.generateDeterministicKeyPair)("test-seed-1");
|
|
39
|
+
const keys3 = (0, deterministic_keys_js_1.generateDeterministicKeyPair)("test-seed-2");
|
|
40
|
+
// Same seed should produce same keys
|
|
41
|
+
(0, vitest_1.expect)(keys1.privateKey).toBe(keys2.privateKey);
|
|
42
|
+
(0, vitest_1.expect)(keys1.publicKey).toBe(keys2.publicKey);
|
|
43
|
+
// Different seed should produce different keys
|
|
44
|
+
(0, vitest_1.expect)(keys1.privateKey).not.toBe(keys3.privateKey);
|
|
45
|
+
(0, vitest_1.expect)(keys1.publicKey).not.toBe(keys3.publicKey);
|
|
46
|
+
});
|
|
47
|
+
(0, vitest_1.it)("should generate test identities", () => {
|
|
48
|
+
const identity = (0, deterministic_keys_js_1.generateTestIdentity)("test-identity", {
|
|
49
|
+
did: test_1.TEST_DIDS.AGENT_1,
|
|
50
|
+
keyId: test_1.TEST_KEY_IDS.KEY_TEST_1,
|
|
51
|
+
});
|
|
52
|
+
(0, vitest_1.expect)(identity.did).toBe(test_1.TEST_DIDS.AGENT_1);
|
|
53
|
+
(0, vitest_1.expect)(identity.keyId).toBe(test_1.TEST_KEY_IDS.KEY_TEST_1);
|
|
54
|
+
(0, vitest_1.expect)(identity.privateKey).toBeDefined();
|
|
55
|
+
(0, vitest_1.expect)(identity.publicKey).toBeDefined();
|
|
56
|
+
(0, vitest_1.expect)(identity.createdAt).toBeDefined();
|
|
57
|
+
(0, vitest_1.expect)(identity.lastRotated).toBeDefined();
|
|
58
|
+
});
|
|
59
|
+
(0, vitest_1.it)("should provide predefined test identities", () => {
|
|
60
|
+
const identities = (0, deterministic_keys_js_1.getPredefinedTestIdentities)();
|
|
61
|
+
(0, vitest_1.expect)(identities.agent1).toBeDefined();
|
|
62
|
+
(0, vitest_1.expect)(identities.agent2).toBeDefined();
|
|
63
|
+
(0, vitest_1.expect)(identities.verifier1).toBeDefined();
|
|
64
|
+
(0, vitest_1.expect)(identities.agent1.did).toBe(test_1.TEST_DIDS.AGENT_1);
|
|
65
|
+
(0, vitest_1.expect)(identities.agent2.did).toBe(test_1.TEST_DIDS.AGENT_2);
|
|
66
|
+
(0, vitest_1.expect)(identities.verifier1.did).toBe(test_1.TEST_DIDS.VERIFIER_1);
|
|
67
|
+
});
|
|
68
|
+
(0, vitest_1.it)("should generate deterministic nonces", () => {
|
|
69
|
+
const nonce1 = (0, deterministic_keys_js_1.generateTestNonce)("seed1");
|
|
70
|
+
const nonce2 = (0, deterministic_keys_js_1.generateTestNonce)("seed1");
|
|
71
|
+
const nonce3 = (0, deterministic_keys_js_1.generateTestNonce)("seed2");
|
|
72
|
+
(0, vitest_1.expect)(nonce1).toBe(nonce2);
|
|
73
|
+
(0, vitest_1.expect)(nonce1).not.toBe(nonce3);
|
|
74
|
+
});
|
|
75
|
+
(0, vitest_1.it)("should generate deterministic session IDs", () => {
|
|
76
|
+
const sessionId1 = (0, deterministic_keys_js_1.generateTestSessionId)("seed1");
|
|
77
|
+
const sessionId2 = (0, deterministic_keys_js_1.generateTestSessionId)("seed1");
|
|
78
|
+
const sessionId3 = (0, deterministic_keys_js_1.generateTestSessionId)("seed2");
|
|
79
|
+
(0, vitest_1.expect)(sessionId1).toBe(sessionId2);
|
|
80
|
+
(0, vitest_1.expect)(sessionId1).not.toBe(sessionId3);
|
|
81
|
+
(0, vitest_1.expect)(sessionId1).toMatch(/^sess_test_/);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
(0, vitest_1.describe)("Mock Identity Provider", () => {
|
|
85
|
+
(0, vitest_1.it)("should create mock identity provider", () => {
|
|
86
|
+
const provider = new mock_identity_provider_js_1.MockIdentityProvider();
|
|
87
|
+
const identities = provider.getAllIdentities();
|
|
88
|
+
(0, vitest_1.expect)(Object.keys(identities)).toContain("agent1");
|
|
89
|
+
(0, vitest_1.expect)(Object.keys(identities)).toContain("agent2");
|
|
90
|
+
(0, vitest_1.expect)(Object.keys(identities)).toContain("verifier1");
|
|
91
|
+
});
|
|
92
|
+
(0, vitest_1.it)("should manage identities", () => {
|
|
93
|
+
const provider = new mock_identity_provider_js_1.MockIdentityProvider();
|
|
94
|
+
const testIdentity = (0, deterministic_keys_js_1.generateTestIdentity)("custom-test");
|
|
95
|
+
provider.setIdentity("custom", testIdentity);
|
|
96
|
+
const retrieved = provider.getIdentity("custom");
|
|
97
|
+
(0, vitest_1.expect)(retrieved).toEqual(testIdentity);
|
|
98
|
+
});
|
|
99
|
+
(0, vitest_1.it)("should manage delegation status", () => {
|
|
100
|
+
const provider = new mock_identity_provider_js_1.MockIdentityProvider();
|
|
101
|
+
provider.setDelegation("did:test:agent-1:key-test-1", "active");
|
|
102
|
+
(0, vitest_1.expect)(provider.getDelegationStatus("did:test:agent-1", "key-test-1")).toBe("active");
|
|
103
|
+
provider.setDelegation("did:test:agent-1:key-test-1", "revoked");
|
|
104
|
+
(0, vitest_1.expect)(provider.getDelegationStatus("did:test:agent-1", "key-test-1")).toBe("revoked");
|
|
105
|
+
});
|
|
106
|
+
(0, vitest_1.it)("should simulate KTA failures", () => {
|
|
107
|
+
const provider = new mock_identity_provider_js_1.MockIdentityProvider();
|
|
108
|
+
provider.simulateKTAFailure("network");
|
|
109
|
+
(0, vitest_1.expect)(provider.shouldSimulateKTAFailure("network")).toBe(true);
|
|
110
|
+
(0, vitest_1.expect)(provider.shouldSimulateKTAFailure("auth")).toBe(false);
|
|
111
|
+
provider.clearKTAFailure("network");
|
|
112
|
+
(0, vitest_1.expect)(provider.shouldSimulateKTAFailure("network")).toBe(false);
|
|
113
|
+
});
|
|
114
|
+
(0, vitest_1.it)("should mock registration calls", async () => {
|
|
115
|
+
const provider = new mock_identity_provider_js_1.MockIdentityProvider();
|
|
116
|
+
// Success case
|
|
117
|
+
const result = await provider.mockRegister("did:test:agent-1", "key-test-1");
|
|
118
|
+
(0, vitest_1.expect)(result.success).toBe(true);
|
|
119
|
+
(0, vitest_1.expect)(result.agentURL).toContain("agent-1");
|
|
120
|
+
// Failure case
|
|
121
|
+
provider.simulateKTAFailure("auth");
|
|
122
|
+
const failResult = await provider.mockRegister("did:test:agent-1", "key-test-1");
|
|
123
|
+
(0, vitest_1.expect)(failResult.success).toBe(false);
|
|
124
|
+
(0, vitest_1.expect)(failResult.error).toBeDefined();
|
|
125
|
+
});
|
|
126
|
+
(0, vitest_1.it)("should use global provider", () => {
|
|
127
|
+
const provider1 = (0, mock_identity_provider_js_1.getMockIdentityProvider)();
|
|
128
|
+
const provider2 = (0, mock_identity_provider_js_1.getMockIdentityProvider)();
|
|
129
|
+
(0, vitest_1.expect)(provider1).toBe(provider2);
|
|
130
|
+
provider1.setIdentity("test", (0, deterministic_keys_js_1.generateTestIdentity)("test"));
|
|
131
|
+
(0, vitest_1.expect)(provider2.getIdentity("test")).toBeDefined();
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
(0, vitest_1.describe)("Local Verification", () => {
|
|
135
|
+
(0, vitest_1.it)("should verify mock proofs locally", async () => {
|
|
136
|
+
const mockProof = (0, local_verification_js_1.createMockProof)({
|
|
137
|
+
did: test_1.TEST_DIDS.AGENT_1,
|
|
138
|
+
keyId: test_1.TEST_KEY_IDS.KEY_TEST_1,
|
|
139
|
+
});
|
|
140
|
+
const result = await (0, local_verification_js_1.verifyProofLocally)(mockProof);
|
|
141
|
+
(0, vitest_1.expect)(result.valid).toBe(true);
|
|
142
|
+
(0, vitest_1.expect)(result.did).toBe(test_1.TEST_DIDS.AGENT_1);
|
|
143
|
+
(0, vitest_1.expect)(result.keyId).toBe(test_1.TEST_KEY_IDS.KEY_TEST_1);
|
|
144
|
+
(0, vitest_1.expect)(result.signature.valid).toBe(true);
|
|
145
|
+
(0, vitest_1.expect)(result.proof.valid).toBe(true);
|
|
146
|
+
(0, vitest_1.expect)(result.session.valid).toBe(true);
|
|
147
|
+
});
|
|
148
|
+
(0, vitest_1.it)("should detect invalid proofs", async () => {
|
|
149
|
+
const invalidProof = {
|
|
150
|
+
jws: "invalid-signature",
|
|
151
|
+
meta: {
|
|
152
|
+
did: "invalid-did",
|
|
153
|
+
kid: "invalid-key",
|
|
154
|
+
ts: Date.now() / 1000,
|
|
155
|
+
nonce: "test-nonce",
|
|
156
|
+
audience: "test.example.com",
|
|
157
|
+
sessionId: "sess_test",
|
|
158
|
+
requestHash: "sha256:invalid",
|
|
159
|
+
responseHash: "sha256:invalid",
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
const result = await (0, local_verification_js_1.verifyProofLocally)(invalidProof);
|
|
163
|
+
(0, vitest_1.expect)(result.valid).toBe(false);
|
|
164
|
+
(0, vitest_1.expect)(result.errors.length).toBeGreaterThan(0);
|
|
165
|
+
});
|
|
166
|
+
(0, vitest_1.it)("should verify DID documents locally", async () => {
|
|
167
|
+
const result = await (0, local_verification_js_1.verifyDIDDocumentLocally)(test_1.TEST_DIDS.AGENT_1);
|
|
168
|
+
(0, vitest_1.expect)(result.valid).toBe(true);
|
|
169
|
+
(0, vitest_1.expect)(result.document).toBeDefined();
|
|
170
|
+
(0, vitest_1.expect)(result.document.id).toBe(test_1.TEST_DIDS.AGENT_1);
|
|
171
|
+
});
|
|
172
|
+
(0, vitest_1.it)("should handle missing DID documents", async () => {
|
|
173
|
+
const result = await (0, local_verification_js_1.verifyDIDDocumentLocally)("did:test:nonexistent");
|
|
174
|
+
(0, vitest_1.expect)(result.valid).toBe(false);
|
|
175
|
+
(0, vitest_1.expect)(result.error).toContain("No identity found");
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deterministic key generation for testing
|
|
3
|
+
*/
|
|
4
|
+
import { type MockIdentity } from "@kya-os/contracts/test";
|
|
5
|
+
/**
|
|
6
|
+
* Generate deterministic Ed25519 key pair from seed
|
|
7
|
+
*/
|
|
8
|
+
export declare function generateDeterministicKeyPair(seed: string): {
|
|
9
|
+
privateKey: string;
|
|
10
|
+
publicKey: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Generate test identity with deterministic keys
|
|
14
|
+
*/
|
|
15
|
+
export declare function generateTestIdentity(testName: string, options?: {
|
|
16
|
+
did?: string;
|
|
17
|
+
keyId?: string;
|
|
18
|
+
seed?: string;
|
|
19
|
+
}): MockIdentity;
|
|
20
|
+
/**
|
|
21
|
+
* Get predefined test identities
|
|
22
|
+
*/
|
|
23
|
+
export declare function getPredefinedTestIdentities(): Record<string, MockIdentity>;
|
|
24
|
+
/**
|
|
25
|
+
* Generate nonce for testing (deterministic if seed provided)
|
|
26
|
+
*/
|
|
27
|
+
export declare function generateTestNonce(seed?: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* Generate session ID for testing (deterministic if seed provided)
|
|
30
|
+
*/
|
|
31
|
+
export declare function generateTestSessionId(seed?: string): string;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Deterministic key generation for testing
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.generateDeterministicKeyPair = generateDeterministicKeyPair;
|
|
7
|
+
exports.generateTestIdentity = generateTestIdentity;
|
|
8
|
+
exports.getPredefinedTestIdentities = getPredefinedTestIdentities;
|
|
9
|
+
exports.generateTestNonce = generateTestNonce;
|
|
10
|
+
exports.generateTestSessionId = generateTestSessionId;
|
|
11
|
+
const crypto_1 = require("crypto");
|
|
12
|
+
const test_1 = require("@kya-os/contracts/test");
|
|
13
|
+
const test_environment_1 = require("./test-environment");
|
|
14
|
+
/**
|
|
15
|
+
* Generate deterministic Ed25519 key pair from seed
|
|
16
|
+
*/
|
|
17
|
+
function generateDeterministicKeyPair(seed) {
|
|
18
|
+
(0, test_environment_1.ensureTestMode)();
|
|
19
|
+
try {
|
|
20
|
+
// Create deterministic seed by hashing the input
|
|
21
|
+
const hash = (0, crypto_1.createHash)("sha256").update(seed).digest();
|
|
22
|
+
// For testing, we'll use the hash as a mock private key
|
|
23
|
+
// In a real implementation, this would use proper Ed25519 key derivation
|
|
24
|
+
const privateKey = hash.toString("base64");
|
|
25
|
+
// Generate a mock public key by hashing the private key
|
|
26
|
+
const publicKey = (0, crypto_1.createHash)("sha256")
|
|
27
|
+
.update(privateKey)
|
|
28
|
+
.digest()
|
|
29
|
+
.toString("base64");
|
|
30
|
+
return {
|
|
31
|
+
privateKey,
|
|
32
|
+
publicKey,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
throw new Error(`${test_1.TEST_ERROR_CODES.DETERMINISTIC_KEY_GENERATION_FAILED}: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Generate test identity with deterministic keys
|
|
41
|
+
*/
|
|
42
|
+
function generateTestIdentity(testName, options = {}) {
|
|
43
|
+
(0, test_environment_1.ensureTestMode)();
|
|
44
|
+
const seed = options.seed || (0, test_environment_1.getCurrentTestSeed)(testName);
|
|
45
|
+
const did = options.did || test_1.TEST_DIDS.AGENT_1;
|
|
46
|
+
const keyId = options.keyId || test_1.TEST_KEY_IDS.KEY_TEST_1;
|
|
47
|
+
const { privateKey, publicKey } = generateDeterministicKeyPair(`${seed}-${testName}-${did}-${keyId}`);
|
|
48
|
+
const now = new Date().toISOString();
|
|
49
|
+
return {
|
|
50
|
+
did,
|
|
51
|
+
keyId,
|
|
52
|
+
privateKey,
|
|
53
|
+
publicKey,
|
|
54
|
+
createdAt: now,
|
|
55
|
+
lastRotated: now,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Get predefined test identities
|
|
60
|
+
*/
|
|
61
|
+
function getPredefinedTestIdentities() {
|
|
62
|
+
(0, test_environment_1.ensureTestMode)();
|
|
63
|
+
return {
|
|
64
|
+
agent1: generateTestIdentity("agent1", {
|
|
65
|
+
did: test_1.TEST_DIDS.AGENT_1,
|
|
66
|
+
keyId: test_1.TEST_KEY_IDS.KEY_TEST_1,
|
|
67
|
+
}),
|
|
68
|
+
agent2: generateTestIdentity("agent2", {
|
|
69
|
+
did: test_1.TEST_DIDS.AGENT_2,
|
|
70
|
+
keyId: test_1.TEST_KEY_IDS.KEY_TEST_2,
|
|
71
|
+
}),
|
|
72
|
+
verifier1: generateTestIdentity("verifier1", {
|
|
73
|
+
did: test_1.TEST_DIDS.VERIFIER_1,
|
|
74
|
+
keyId: test_1.TEST_KEY_IDS.KEY_VERIFIER_1,
|
|
75
|
+
}),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Generate nonce for testing (deterministic if seed provided)
|
|
80
|
+
*/
|
|
81
|
+
function generateTestNonce(seed) {
|
|
82
|
+
(0, test_environment_1.ensureTestMode)();
|
|
83
|
+
if (seed) {
|
|
84
|
+
// Deterministic nonce for reproducible tests
|
|
85
|
+
return (0, crypto_1.createHash)("sha256")
|
|
86
|
+
.update(`nonce-${seed}-${(0, test_environment_1.getCurrentTestSeed)()}`)
|
|
87
|
+
.digest()
|
|
88
|
+
.subarray(0, 16)
|
|
89
|
+
.toString("base64url");
|
|
90
|
+
}
|
|
91
|
+
// Random nonce for general testing
|
|
92
|
+
return (0, crypto_1.randomBytes)(16).toString("base64url");
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Generate session ID for testing (deterministic if seed provided)
|
|
96
|
+
*/
|
|
97
|
+
function generateTestSessionId(seed) {
|
|
98
|
+
(0, test_environment_1.ensureTestMode)();
|
|
99
|
+
if (seed) {
|
|
100
|
+
// Deterministic session ID for reproducible tests
|
|
101
|
+
return `sess_test_${(0, crypto_1.createHash)("sha256")
|
|
102
|
+
.update(`session-${seed}-${(0, test_environment_1.getCurrentTestSeed)()}`)
|
|
103
|
+
.digest("hex")
|
|
104
|
+
.substring(0, 16)}`;
|
|
105
|
+
}
|
|
106
|
+
// Random session ID for general testing
|
|
107
|
+
return `sess_test_${(0, crypto_1.randomBytes)(8).toString("hex")}`;
|
|
108
|
+
}
|