@kya-os/mcp-i-runtime 1.0.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/.turbo/turbo-build.log +4 -0
- package/dist/auth/handshake.d.ts +136 -0
- package/dist/auth/handshake.d.ts.map +1 -0
- package/dist/auth/handshake.js +276 -0
- package/dist/auth/handshake.js.map +1 -0
- package/dist/auth/index.d.ts +6 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +12 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/types.d.ts +52 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +10 -0
- package/dist/auth/types.js.map +1 -0
- package/dist/cache/oauth-config-cache.d.ts +69 -0
- package/dist/cache/oauth-config-cache.d.ts.map +1 -0
- package/dist/cache/oauth-config-cache.js +76 -0
- package/dist/cache/oauth-config-cache.js.map +1 -0
- package/dist/cache/tool-protection-cache.d.ts +102 -0
- package/dist/cache/tool-protection-cache.d.ts.map +1 -0
- package/dist/cache/tool-protection-cache.js +131 -0
- package/dist/cache/tool-protection-cache.js.map +1 -0
- package/dist/compliance/index.d.ts +8 -0
- package/dist/compliance/index.d.ts.map +1 -0
- package/dist/compliance/index.js +24 -0
- package/dist/compliance/index.js.map +1 -0
- package/dist/compliance/schema-registry.d.ts +50 -0
- package/dist/compliance/schema-registry.d.ts.map +1 -0
- package/dist/compliance/schema-registry.js +438 -0
- package/dist/compliance/schema-registry.js.map +1 -0
- package/dist/compliance/schema-verifier.d.ts +110 -0
- package/dist/compliance/schema-verifier.d.ts.map +1 -0
- package/dist/compliance/schema-verifier.js +518 -0
- package/dist/compliance/schema-verifier.js.map +1 -0
- package/dist/config/remote-config.d.ts +188 -0
- package/dist/config/remote-config.d.ts.map +1 -0
- package/dist/config/remote-config.js +268 -0
- package/dist/config/remote-config.js.map +1 -0
- package/dist/config.d.ts +182 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +148 -0
- package/dist/config.js.map +1 -0
- package/dist/identity/idp-token-resolver.d.ts +69 -0
- package/dist/identity/idp-token-resolver.d.ts.map +1 -0
- package/dist/identity/idp-token-resolver.js +136 -0
- package/dist/identity/idp-token-resolver.js.map +1 -0
- package/dist/identity/idp-token-storage.interface.d.ts +80 -0
- package/dist/identity/idp-token-storage.interface.d.ts.map +1 -0
- package/dist/identity/idp-token-storage.interface.js +14 -0
- package/dist/identity/idp-token-storage.interface.js.map +1 -0
- package/dist/identity/user-did-manager.d.ts +228 -0
- package/dist/identity/user-did-manager.d.ts.map +1 -0
- package/dist/identity/user-did-manager.js +356 -0
- package/dist/identity/user-did-manager.js.map +1 -0
- package/dist/index.d.ts +69 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +193 -0
- package/dist/index.js.map +1 -0
- package/dist/logging/index.d.ts +5 -0
- package/dist/logging/index.d.ts.map +1 -0
- package/dist/logging/index.js +10 -0
- package/dist/logging/index.js.map +1 -0
- package/dist/logging/logger.d.ts +33 -0
- package/dist/logging/logger.d.ts.map +1 -0
- package/dist/logging/logger.js +104 -0
- package/dist/logging/logger.js.map +1 -0
- package/dist/proof/generator.d.ts +109 -0
- package/dist/proof/generator.d.ts.map +1 -0
- package/dist/proof/generator.js +236 -0
- package/dist/proof/generator.js.map +1 -0
- package/dist/proof/index.d.ts +5 -0
- package/dist/proof/index.d.ts.map +1 -0
- package/dist/proof/index.js +11 -0
- package/dist/proof/index.js.map +1 -0
- package/dist/providers/base.d.ts +95 -0
- package/dist/providers/base.d.ts.map +1 -0
- package/dist/providers/base.js +47 -0
- package/dist/providers/base.js.map +1 -0
- package/dist/providers/memory.d.ts +42 -0
- package/dist/providers/memory.d.ts.map +1 -0
- package/dist/providers/memory.js +121 -0
- package/dist/providers/memory.js.map +1 -0
- package/dist/runtime/audit-logger.d.ts +37 -0
- package/dist/runtime/audit-logger.d.ts.map +1 -0
- package/dist/runtime/audit-logger.js +9 -0
- package/dist/runtime/audit-logger.js.map +1 -0
- package/dist/runtime/base.d.ts +392 -0
- package/dist/runtime/base.d.ts.map +1 -0
- package/dist/runtime/base.js +1527 -0
- package/dist/runtime/base.js.map +1 -0
- package/dist/runtime/dif-core.d.ts +33 -0
- package/dist/runtime/dif-core.d.ts.map +1 -0
- package/dist/runtime/dif-core.js +14 -0
- package/dist/runtime/dif-core.js.map +1 -0
- package/dist/runtime/ext-apps-constants.d.ts +20 -0
- package/dist/runtime/ext-apps-constants.d.ts.map +1 -0
- package/dist/runtime/ext-apps-constants.js +23 -0
- package/dist/runtime/ext-apps-constants.js.map +1 -0
- package/dist/services/access-control.service.d.ts +138 -0
- package/dist/services/access-control.service.d.ts.map +1 -0
- package/dist/services/access-control.service.js +721 -0
- package/dist/services/access-control.service.js.map +1 -0
- package/dist/services/authorization/authorization-registry.d.ts +29 -0
- package/dist/services/authorization/authorization-registry.d.ts.map +1 -0
- package/dist/services/authorization/authorization-registry.js +58 -0
- package/dist/services/authorization/authorization-registry.js.map +1 -0
- package/dist/services/authorization/types.d.ts +53 -0
- package/dist/services/authorization/types.d.ts.map +1 -0
- package/dist/services/authorization/types.js +10 -0
- package/dist/services/authorization/types.js.map +1 -0
- package/dist/services/batch-delegation.service.d.ts +53 -0
- package/dist/services/batch-delegation.service.d.ts.map +1 -0
- package/dist/services/batch-delegation.service.js +95 -0
- package/dist/services/batch-delegation.service.js.map +1 -0
- package/dist/services/crypto.service.d.ts +69 -0
- package/dist/services/crypto.service.d.ts.map +1 -0
- package/dist/services/crypto.service.js +225 -0
- package/dist/services/crypto.service.js.map +1 -0
- package/dist/services/delegation-error-formatter.d.ts +124 -0
- package/dist/services/delegation-error-formatter.d.ts.map +1 -0
- package/dist/services/delegation-error-formatter.js +214 -0
- package/dist/services/delegation-error-formatter.js.map +1 -0
- package/dist/services/errors.d.ts +49 -0
- package/dist/services/errors.d.ts.map +1 -0
- package/dist/services/errors.js +66 -0
- package/dist/services/errors.js.map +1 -0
- package/dist/services/index.d.ts +9 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +15 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/oauth-config.service.d.ts +53 -0
- package/dist/services/oauth-config.service.d.ts.map +1 -0
- package/dist/services/oauth-config.service.js +141 -0
- package/dist/services/oauth-config.service.js.map +1 -0
- package/dist/services/oauth-provider-registry.d.ts +88 -0
- package/dist/services/oauth-provider-registry.d.ts.map +1 -0
- package/dist/services/oauth-provider-registry.js +128 -0
- package/dist/services/oauth-provider-registry.js.map +1 -0
- package/dist/services/oauth-service.d.ts +122 -0
- package/dist/services/oauth-service.d.ts.map +1 -0
- package/dist/services/oauth-service.js +442 -0
- package/dist/services/oauth-service.js.map +1 -0
- package/dist/services/oauth-token-retrieval.service.d.ts +49 -0
- package/dist/services/oauth-token-retrieval.service.d.ts.map +1 -0
- package/dist/services/oauth-token-retrieval.service.js +150 -0
- package/dist/services/oauth-token-retrieval.service.js.map +1 -0
- package/dist/services/policy.service.d.ts +130 -0
- package/dist/services/policy.service.d.ts.map +1 -0
- package/dist/services/policy.service.js +399 -0
- package/dist/services/policy.service.js.map +1 -0
- package/dist/services/proof-verifier.d.ts +103 -0
- package/dist/services/proof-verifier.d.ts.map +1 -0
- package/dist/services/proof-verifier.js +190 -0
- package/dist/services/proof-verifier.js.map +1 -0
- package/dist/services/provider-resolver.d.ts +89 -0
- package/dist/services/provider-resolver.d.ts.map +1 -0
- package/dist/services/provider-resolver.js +196 -0
- package/dist/services/provider-resolver.js.map +1 -0
- package/dist/services/provider-validator.d.ts +55 -0
- package/dist/services/provider-validator.d.ts.map +1 -0
- package/dist/services/provider-validator.js +135 -0
- package/dist/services/provider-validator.js.map +1 -0
- package/dist/services/session-registration.service.d.ts +80 -0
- package/dist/services/session-registration.service.d.ts.map +1 -0
- package/dist/services/session-registration.service.js +174 -0
- package/dist/services/session-registration.service.js.map +1 -0
- package/dist/services/storage.service.d.ts +116 -0
- package/dist/services/storage.service.d.ts.map +1 -0
- package/dist/services/storage.service.js +411 -0
- package/dist/services/storage.service.js.map +1 -0
- package/dist/services/tool-context-builder.d.ts +74 -0
- package/dist/services/tool-context-builder.d.ts.map +1 -0
- package/dist/services/tool-context-builder.js +215 -0
- package/dist/services/tool-context-builder.js.map +1 -0
- package/dist/services/tool-protection.service.d.ts +209 -0
- package/dist/services/tool-protection.service.d.ts.map +1 -0
- package/dist/services/tool-protection.service.js +752 -0
- package/dist/services/tool-protection.service.js.map +1 -0
- package/dist/session/index.d.ts +5 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +11 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/manager.d.ts +118 -0
- package/dist/session/manager.d.ts.map +1 -0
- package/dist/session/manager.js +285 -0
- package/dist/session/manager.js.map +1 -0
- package/dist/types/oauth-required-error.d.ts +46 -0
- package/dist/types/oauth-required-error.d.ts.map +1 -0
- package/dist/types/oauth-required-error.js +42 -0
- package/dist/types/oauth-required-error.js.map +1 -0
- package/dist/types/tool-protection.d.ts +144 -0
- package/dist/types/tool-protection.d.ts.map +1 -0
- package/dist/types/tool-protection.js +48 -0
- package/dist/types/tool-protection.js.map +1 -0
- package/dist/utils/base58.d.ts +31 -0
- package/dist/utils/base58.d.ts.map +1 -0
- package/dist/utils/base58.js +103 -0
- package/dist/utils/base58.js.map +1 -0
- package/dist/utils/base64.d.ts +32 -0
- package/dist/utils/base64.d.ts.map +1 -0
- package/dist/utils/base64.js +172 -0
- package/dist/utils/base64.js.map +1 -0
- package/dist/utils/cors.d.ts +52 -0
- package/dist/utils/cors.d.ts.map +1 -0
- package/dist/utils/cors.js +79 -0
- package/dist/utils/cors.js.map +1 -0
- package/dist/utils/did-helpers.d.ts +168 -0
- package/dist/utils/did-helpers.d.ts.map +1 -0
- package/dist/utils/did-helpers.js +222 -0
- package/dist/utils/did-helpers.js.map +1 -0
- package/dist/utils/index.d.ts +8 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +24 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/storage-keys.d.ts +120 -0
- package/dist/utils/storage-keys.d.ts.map +1 -0
- package/dist/utils/storage-keys.js +217 -0
- package/dist/utils/storage-keys.js.map +1 -0
- package/dist/wire-format.d.ts +62 -0
- package/dist/wire-format.d.ts.map +1 -0
- package/dist/wire-format.js +89 -0
- package/dist/wire-format.js.map +1 -0
- package/package.json +83 -0
- package/src/__tests__/cache/tool-protection-cache.test.ts +640 -0
- package/src/__tests__/config/provider-runtime-config.test.ts +309 -0
- package/src/__tests__/config.test.ts +307 -0
- package/src/__tests__/identity/user-did-manager.test.ts +232 -0
- package/src/__tests__/index.test.ts +56 -0
- package/src/__tests__/integration/full-flow.test.ts +779 -0
- package/src/__tests__/integration.test.ts +281 -0
- package/src/__tests__/providers/base.test.ts +173 -0
- package/src/__tests__/providers/memory.test.ts +319 -0
- package/src/__tests__/regression/phase2-regression.test.ts +406 -0
- package/src/__tests__/runtime/audit-logger.test.ts +154 -0
- package/src/__tests__/runtime/base-extensions.test.ts +595 -0
- package/src/__tests__/runtime/base.test.ts +1328 -0
- package/src/__tests__/runtime/delegation-flow.test.ts +159 -0
- package/src/__tests__/runtime/process-tool-call-security.test.ts +1024 -0
- package/src/__tests__/runtime/proof-client-did.test.ts +376 -0
- package/src/__tests__/runtime/provider-selection.test.ts +292 -0
- package/src/__tests__/runtime/route-interception.test.ts +670 -0
- package/src/__tests__/runtime/tool-protection-enforcement.test.ts +989 -0
- package/src/__tests__/services/access-control-retry.test.ts +595 -0
- package/src/__tests__/services/agentshield-integration.test.ts +709 -0
- package/src/__tests__/services/cache-busting.test.ts +125 -0
- package/src/__tests__/services/oauth-service-errors.test.ts +704 -0
- package/src/__tests__/services/oauth-service-pkce.test.ts +556 -0
- package/src/__tests__/services/oauth-service-secret-resolution.test.ts +349 -0
- package/src/__tests__/services/provider-resolver-edge-cases.test.ts +591 -0
- package/src/__tests__/services/tool-protection-failsafe.test.ts +683 -0
- package/src/__tests__/services/tool-protection-merged-config.test.ts +664 -0
- package/src/__tests__/services/tool-protection-oauth-provider.test.ts +300 -0
- package/src/__tests__/services/tool-protection.service.test.ts +1201 -0
- package/src/__tests__/utils/mock-providers.ts +340 -0
- package/src/__tests__/wire-format.test.ts +123 -0
- package/src/auth/__tests__/resume-token.test.ts +42 -0
- package/src/auth/handshake.ts +476 -0
- package/src/auth/index.ts +15 -0
- package/src/auth/types.ts +68 -0
- package/src/cache/__tests__/oauth-config-cache.test.ts +215 -0
- package/src/cache/oauth-config-cache.d.ts +69 -0
- package/src/cache/oauth-config-cache.d.ts.map +1 -0
- package/src/cache/oauth-config-cache.js.map +1 -0
- package/src/cache/oauth-config-cache.ts +123 -0
- package/src/cache/tool-protection-cache.ts +184 -0
- package/src/compliance/EXAMPLE.md +412 -0
- package/src/compliance/__tests__/schema-verifier.test.ts +791 -0
- package/src/compliance/index.ts +8 -0
- package/src/compliance/schema-registry.ts +460 -0
- package/src/compliance/schema-verifier.ts +708 -0
- package/src/config/__tests__/merged-config.spec.ts +445 -0
- package/src/config/__tests__/remote-config-edge-cases.test.ts +424 -0
- package/src/config/__tests__/remote-config-helpers.test.ts +280 -0
- package/src/config/__tests__/remote-config.spec.ts +265 -0
- package/src/config/remote-config.ts +368 -0
- package/src/config.ts +312 -0
- package/src/identity/__tests__/idp-token-resolver.test.ts +340 -0
- package/src/identity/__tests__/user-did-manager.test.ts +487 -0
- package/src/identity/idp-token-resolver.ts +181 -0
- package/src/identity/idp-token-storage.interface.ts +102 -0
- package/src/identity/user-did-manager.ts +592 -0
- package/src/index.ts +331 -0
- package/src/logging/__tests__/logger.test.ts +366 -0
- package/src/logging/index.ts +10 -0
- package/src/logging/logger.ts +112 -0
- package/src/proof/__tests__/crypto-parity.test.ts +202 -0
- package/src/proof/__tests__/proof-generator.test.ts +484 -0
- package/src/proof/generator.ts +347 -0
- package/src/proof/index.ts +12 -0
- package/src/providers/base.d.ts +91 -0
- package/src/providers/base.d.ts.map +1 -0
- package/src/providers/base.js.map +1 -0
- package/src/providers/base.ts +100 -0
- package/src/providers/memory.ts +142 -0
- package/src/runtime/__tests__/dif-esm-bridge.test.ts +33 -0
- package/src/runtime/__tests__/ext-apps-consent.test.ts +334 -0
- package/src/runtime/audit-logger.ts +39 -0
- package/src/runtime/base.ts +2100 -0
- package/src/runtime/dif-core.ts +39 -0
- package/src/runtime/ext-apps-constants.ts +20 -0
- package/src/services/__tests__/access-control.integration.test.ts +441 -0
- package/src/services/__tests__/access-control.proof-response-validation.test.ts +578 -0
- package/src/services/__tests__/access-control.service.test.ts +1132 -0
- package/src/services/__tests__/batch-delegation.service.test.ts +351 -0
- package/src/services/__tests__/crypto.service.test.ts +531 -0
- package/src/services/__tests__/delegation-error-formatter.test.ts +643 -0
- package/src/services/__tests__/oauth-config.service.test.ts +359 -0
- package/src/services/__tests__/oauth-provider-registry.test.ts +142 -0
- package/src/services/__tests__/oauth-token-retrieval.service.test.ts +365 -0
- package/src/services/__tests__/proof-verifier.integration.test.ts +494 -0
- package/src/services/__tests__/proof-verifier.test.ts +489 -0
- package/src/services/__tests__/provider-resolution.integration.test.ts +202 -0
- package/src/services/__tests__/provider-resolver.test.ts +213 -0
- package/src/services/__tests__/provider-validator.test.ts +370 -0
- package/src/services/__tests__/session-registration.service.test.ts +312 -0
- package/src/services/__tests__/storage.service.test.ts +358 -0
- package/src/services/__tests__/tool-context-builder.test.ts +438 -0
- package/src/services/access-control.service.ts +1048 -0
- package/src/services/authorization/authorization-registry.ts +67 -0
- package/src/services/authorization/types.ts +71 -0
- package/src/services/batch-delegation.service.ts +136 -0
- package/src/services/crypto.service.ts +296 -0
- package/src/services/delegation-error-formatter.ts +299 -0
- package/src/services/errors.ts +76 -0
- package/src/services/index.ts +34 -0
- package/src/services/oauth-config.service.d.ts +53 -0
- package/src/services/oauth-config.service.d.ts.map +1 -0
- package/src/services/oauth-config.service.js.map +1 -0
- package/src/services/oauth-config.service.ts +192 -0
- package/src/services/oauth-provider-registry.d.ts +57 -0
- package/src/services/oauth-provider-registry.d.ts.map +1 -0
- package/src/services/oauth-provider-registry.js.map +1 -0
- package/src/services/oauth-provider-registry.ts +141 -0
- package/src/services/oauth-service.ts +652 -0
- package/src/services/oauth-token-retrieval.service.ts +245 -0
- package/src/services/policy.service.ts +527 -0
- package/src/services/proof-verifier.ts +295 -0
- package/src/services/provider-resolver.d.ts +48 -0
- package/src/services/provider-resolver.d.ts.map +1 -0
- package/src/services/provider-resolver.js.map +1 -0
- package/src/services/provider-resolver.ts +236 -0
- package/src/services/provider-validator.ts +170 -0
- package/src/services/session-registration.service.ts +259 -0
- package/src/services/storage.service.ts +566 -0
- package/src/services/tool-context-builder.ts +285 -0
- package/src/services/tool-protection.service.ts +971 -0
- package/src/session/__tests__/session-manager.test.ts +327 -0
- package/src/session/index.ts +10 -0
- package/src/session/manager.ts +380 -0
- package/src/types/__tests__/oauth-required-error.test.ts +79 -0
- package/src/types/__tests__/tool-protection.test.ts +121 -0
- package/src/types/oauth-required-error.ts +71 -0
- package/src/types/tool-protection.ts +179 -0
- package/src/utils/__tests__/base58.test.ts +281 -0
- package/src/utils/__tests__/base64.test.ts +239 -0
- package/src/utils/__tests__/cors.test.ts +184 -0
- package/src/utils/__tests__/did-helpers.test.ts +156 -0
- package/src/utils/__tests__/storage-keys.test.ts +372 -0
- package/src/utils/base58.ts +109 -0
- package/src/utils/base64.ts +185 -0
- package/src/utils/cors.ts +93 -0
- package/src/utils/did-helpers.ts +229 -0
- package/src/utils/index.ts +8 -0
- package/src/utils/storage-keys.ts +285 -0
- package/src/wire-format.ts +114 -0
- package/tsconfig.json +21 -0
- package/vitest.config.mts +57 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dynamic-import seam for the DIF `@kya-os/mcp` core (C2 / issue #2916).
|
|
3
|
+
*
|
|
4
|
+
* `@kya-os/mcp` ("KYA-OS for MCP") is ESM-only (`"type": "module"`); this
|
|
5
|
+
* package (`@kya-os/mcp-i-core`) is CommonJS (`module: Node16`). A static
|
|
6
|
+
* `import ... from "@kya-os/mcp"` in source compiles to a `require()` of an
|
|
7
|
+
* ESM-only module, which TypeScript rejects under Node16 resolution (TS1479).
|
|
8
|
+
*
|
|
9
|
+
* `@kya-os/mcp-i-core` is the root of the dependency graph (mcp-i, mcp-i-cloudflare,
|
|
10
|
+
* etc. depend on it), so the seam lives here — every CJS consumer that needs to
|
|
11
|
+
* reach DIF can import `loadDifCore` from this package. The node-side product
|
|
12
|
+
* layer reaches DIF lazily through this async seam: a dynamic `import()` is
|
|
13
|
+
* preserved as a native dynamic import in CJS output, so Node loads the ESM
|
|
14
|
+
* module at runtime. The promise is cached so the import resolves once per process.
|
|
15
|
+
*
|
|
16
|
+
* Re-homes that compose DIF primitives call `loadDifCore()` and destructure
|
|
17
|
+
* what they need (e.g. `const { ProofVerifier } = await loadDifCore()`).
|
|
18
|
+
*
|
|
19
|
+
* `typeof import(...)` below is a *type-only* reference — it is erased at
|
|
20
|
+
* compile time and produces no `require`, so it does not trip TS1479. Under
|
|
21
|
+
* Node16 a type query of an ESM-only module from CJS additionally needs an
|
|
22
|
+
* explicit `resolution-mode: "import"` attribute (TS1542) so the compiler
|
|
23
|
+
* resolves it in ESM mode.
|
|
24
|
+
*/
|
|
25
|
+
export type DifCore = typeof import("@kya-os/mcp", {
|
|
26
|
+
with: { "resolution-mode": "import" }
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
let cached: Promise<DifCore> | undefined;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Resolve the DIF `@kya-os/mcp` core module via a cached dynamic import.
|
|
33
|
+
*
|
|
34
|
+
* @returns the `@kya-os/mcp` module namespace (proof/session/delegation
|
|
35
|
+
* primitives, middleware factories, etc.).
|
|
36
|
+
*/
|
|
37
|
+
export function loadDifCore(): Promise<DifCore> {
|
|
38
|
+
return (cached ??= import("@kya-os/mcp"));
|
|
39
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Apps Extension Constants
|
|
3
|
+
*
|
|
4
|
+
* Shared constants for the MCP Apps consent UI integration.
|
|
5
|
+
* Kept separate from the runtime class so consumers can import
|
|
6
|
+
* without pulling in the full MCPIRuntimeBase dependency.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* URI for the shared consent UI resource.
|
|
11
|
+
* All consent-requiring tools reference this single resource;
|
|
12
|
+
* tool-specific data is passed via structuredContent.
|
|
13
|
+
*
|
|
14
|
+
* C4 (#2918): de-branded from the legacy `ui://mcpi-consent/authorize`. The
|
|
15
|
+
* client only reads this URI within a single request/response exchange (it is
|
|
16
|
+
* returned in the tool result's `_meta.ui` and read back immediately), so no
|
|
17
|
+
* dual-accept window is required — the server emits and serves the new value
|
|
18
|
+
* atomically.
|
|
19
|
+
*/
|
|
20
|
+
export const CONSENT_UI_RESOURCE_URI = "ui://kya-os-consent/authorize";
|
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integration Tests for AccessControlApiService and ProofVerifier
|
|
3
|
+
*
|
|
4
|
+
* End-to-end integration tests covering:
|
|
5
|
+
* - Delegation verification flow with AccessControlApiService
|
|
6
|
+
* - Proof submission flow with AccessControlApiService
|
|
7
|
+
* - Proof verification with ProofVerifier
|
|
8
|
+
* - Runtime integration with service injection
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { describe, it, expect, beforeEach, vi } from "vitest";
|
|
12
|
+
import { AccessControlApiService } from "../access-control.service.js";
|
|
13
|
+
import { ProofVerifier } from "../proof-verifier.js";
|
|
14
|
+
import { MCPIRuntimeBase } from "../../runtime/base.js";
|
|
15
|
+
import {
|
|
16
|
+
createMockProviders,
|
|
17
|
+
MockFetchProvider,
|
|
18
|
+
} from "../../__tests__/utils/mock-providers.js";
|
|
19
|
+
import type { ProviderRuntimeConfig } from "../../config.js";
|
|
20
|
+
import type { DetachedProof } from "@kya-os/contracts/proof";
|
|
21
|
+
import type { VerifyDelegationRequest, ProofSubmissionRequest } from "@kya-os/contracts/agentshield-api";
|
|
22
|
+
import { AgentShieldAPIError } from "@kya-os/contracts/agentshield-api";
|
|
23
|
+
|
|
24
|
+
describe("AccessControlApiService Integration", () => {
|
|
25
|
+
let accessControlService: AccessControlApiService;
|
|
26
|
+
let proofVerifier: ProofVerifier;
|
|
27
|
+
let runtime: MCPIRuntimeBase;
|
|
28
|
+
let mockFetchProvider: MockFetchProvider;
|
|
29
|
+
let mockProviders: ReturnType<typeof createMockProviders>;
|
|
30
|
+
|
|
31
|
+
beforeEach(() => {
|
|
32
|
+
mockProviders = createMockProviders();
|
|
33
|
+
mockFetchProvider = mockProviders.fetchProvider as MockFetchProvider;
|
|
34
|
+
|
|
35
|
+
// Reset fetch mock before each test
|
|
36
|
+
vi.clearAllMocks();
|
|
37
|
+
mockFetchProvider.fetch.mockClear();
|
|
38
|
+
|
|
39
|
+
accessControlService = new AccessControlApiService({
|
|
40
|
+
baseUrl: "https://api.example.com",
|
|
41
|
+
apiKey: "test-api-key",
|
|
42
|
+
fetchProvider: mockFetchProvider,
|
|
43
|
+
logger: vi.fn(),
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
proofVerifier = new ProofVerifier({
|
|
47
|
+
cryptoProvider: mockProviders.cryptoProvider,
|
|
48
|
+
clockProvider: mockProviders.clockProvider,
|
|
49
|
+
nonceCacheProvider: mockProviders.nonceCacheProvider,
|
|
50
|
+
fetchProvider: mockFetchProvider,
|
|
51
|
+
timestampSkewSeconds: 120,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const config: ProviderRuntimeConfig = {
|
|
55
|
+
...mockProviders,
|
|
56
|
+
environment: "development",
|
|
57
|
+
session: {
|
|
58
|
+
timestampSkewSeconds: 120,
|
|
59
|
+
ttlMinutes: 30,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
runtime = new MCPIRuntimeBase(config);
|
|
64
|
+
(runtime as any).proofVerifier = proofVerifier;
|
|
65
|
+
(runtime as any).accessControlService = accessControlService;
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
describe("Delegation Verification Flow", () => {
|
|
69
|
+
it("should verify delegation end-to-end", async () => {
|
|
70
|
+
const request: VerifyDelegationRequest = {
|
|
71
|
+
agent_did: "did:key:z123",
|
|
72
|
+
scopes: ["scope1", "scope2"],
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const mockResponse = {
|
|
76
|
+
success: true,
|
|
77
|
+
data: {
|
|
78
|
+
valid: true,
|
|
79
|
+
delegation_id: "123e4567-e89b-12d3-a456-426614174000", // Valid UUID format
|
|
80
|
+
credential: {
|
|
81
|
+
agent_did: "did:key:z123",
|
|
82
|
+
user_did: "did:key:zUser123", // REQUIRED: User DID
|
|
83
|
+
scopes: ["scope1", "scope2"],
|
|
84
|
+
issued_at: Math.floor(Date.now() / 1000), // Unix timestamp (positive integer)
|
|
85
|
+
created_at: Math.floor(Date.now() / 1000), // Unix timestamp (positive integer)
|
|
86
|
+
authorization: { type: "oauth", provider: "github" }, // REQUIRED: Authorization method
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
metadata: {
|
|
90
|
+
requestId: "test-request-id",
|
|
91
|
+
timestamp: new Date().toISOString(),
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
mockFetchProvider.fetch.mockResolvedValue(
|
|
96
|
+
new Response(JSON.stringify(mockResponse), {
|
|
97
|
+
status: 200,
|
|
98
|
+
headers: { "Content-Type": "application/json" },
|
|
99
|
+
})
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
const result = await accessControlService.verifyDelegation(request);
|
|
103
|
+
|
|
104
|
+
expect(result.data.valid).toBe(true);
|
|
105
|
+
expect(result.data.delegation_id).toBe(
|
|
106
|
+
"123e4567-e89b-12d3-a456-426614174000"
|
|
107
|
+
);
|
|
108
|
+
expect(result.data.credential?.scopes).toEqual(["scope1", "scope2"]);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("should handle delegation verification failure", async () => {
|
|
112
|
+
const request: VerifyDelegationRequest = {
|
|
113
|
+
agent_did: "did:key:z123",
|
|
114
|
+
scopes: ["scope1"],
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const mockResponse = {
|
|
118
|
+
success: true,
|
|
119
|
+
data: {
|
|
120
|
+
valid: false,
|
|
121
|
+
reason: "No delegation found for agent",
|
|
122
|
+
},
|
|
123
|
+
metadata: {
|
|
124
|
+
requestId: "test-request-id",
|
|
125
|
+
timestamp: new Date().toISOString(),
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
mockFetchProvider.fetch.mockResolvedValue(
|
|
130
|
+
new Response(JSON.stringify(mockResponse), {
|
|
131
|
+
status: 200,
|
|
132
|
+
headers: { "Content-Type": "application/json" },
|
|
133
|
+
})
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
const result = await accessControlService.verifyDelegation(request);
|
|
137
|
+
|
|
138
|
+
expect(result.data.valid).toBe(false);
|
|
139
|
+
expect(result.data.reason).toBe("No delegation found for agent");
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
describe("Proof Submission Flow", () => {
|
|
144
|
+
it("should submit proof end-to-end", async () => {
|
|
145
|
+
const proof: DetachedProof = {
|
|
146
|
+
jws: "header.payload.signature",
|
|
147
|
+
meta: {
|
|
148
|
+
did: "did:key:z123",
|
|
149
|
+
kid: "did:key:z123#key-1",
|
|
150
|
+
ts: Math.floor(Date.now() / 1000), // Unix timestamp in seconds
|
|
151
|
+
nonce: "nonce-123",
|
|
152
|
+
audience: "mcp-client",
|
|
153
|
+
sessionId: "session-123",
|
|
154
|
+
requestHash: "sha256:" + "a".repeat(64),
|
|
155
|
+
responseHash: "sha256:" + "b".repeat(64),
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
const request = {
|
|
160
|
+
session_id: "550e8400-e29b-41d4-a716-446655440000", // Valid UUID
|
|
161
|
+
delegation_id: "123e4567-e89b-12d3-a456-426614174000", // Valid UUID format
|
|
162
|
+
proofs: [proof],
|
|
163
|
+
context: {
|
|
164
|
+
toolCalls: [
|
|
165
|
+
{
|
|
166
|
+
tool: "testTool",
|
|
167
|
+
args: { param: "value" },
|
|
168
|
+
scopeId: "testTool:execute",
|
|
169
|
+
},
|
|
170
|
+
],
|
|
171
|
+
},
|
|
172
|
+
} as ProofSubmissionRequest;
|
|
173
|
+
|
|
174
|
+
const mockResponse = {
|
|
175
|
+
success: true,
|
|
176
|
+
accepted: 1,
|
|
177
|
+
rejected: 0,
|
|
178
|
+
outcomes: {
|
|
179
|
+
success: 1,
|
|
180
|
+
failed: 0,
|
|
181
|
+
blocked: 0,
|
|
182
|
+
error: 0,
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
mockFetchProvider.fetch.mockResolvedValue(
|
|
187
|
+
new Response(JSON.stringify(mockResponse), {
|
|
188
|
+
status: 200,
|
|
189
|
+
headers: { "Content-Type": "application/json" },
|
|
190
|
+
})
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
const result = await accessControlService.submitProofs(request);
|
|
194
|
+
|
|
195
|
+
// Type assertion needed due to TypeScript type resolution issues with outdated node_modules types
|
|
196
|
+
// The actual runtime type has accepted/rejected/outcomes, but node_modules has old types
|
|
197
|
+
const typedResult = result as unknown as {
|
|
198
|
+
success: boolean;
|
|
199
|
+
accepted: number;
|
|
200
|
+
rejected: number;
|
|
201
|
+
outcomes: Record<string, number>;
|
|
202
|
+
errors?: Array<{
|
|
203
|
+
proof_index: number;
|
|
204
|
+
error: { code: string; message: string };
|
|
205
|
+
}>;
|
|
206
|
+
};
|
|
207
|
+
expect(typedResult.accepted).toBe(1);
|
|
208
|
+
expect(typedResult.rejected).toBe(0);
|
|
209
|
+
expect(typedResult.outcomes.success).toBe(1);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it("should handle proof submission with errors", async () => {
|
|
213
|
+
const proof: DetachedProof = {
|
|
214
|
+
jws: "invalid.jws.signature",
|
|
215
|
+
meta: {
|
|
216
|
+
did: "did:key:z123",
|
|
217
|
+
kid: "did:key:z123#key-1",
|
|
218
|
+
ts: Math.floor(Date.now() / 1000), // Unix timestamp in seconds
|
|
219
|
+
nonce: "nonce-123",
|
|
220
|
+
audience: "mcp-client",
|
|
221
|
+
sessionId: "session-123",
|
|
222
|
+
requestHash: "sha256:" + "a".repeat(64),
|
|
223
|
+
responseHash: "sha256:" + "b".repeat(64),
|
|
224
|
+
},
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
const request: ProofSubmissionRequest = {
|
|
228
|
+
session_id: "550e8400-e29b-41d4-a716-446655440000", // Valid UUID
|
|
229
|
+
delegation_id: null, // Explicitly set to null for optional field
|
|
230
|
+
proofs: [proof],
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
const mockResponse = {
|
|
234
|
+
success: true,
|
|
235
|
+
accepted: 0,
|
|
236
|
+
rejected: 1,
|
|
237
|
+
outcomes: {
|
|
238
|
+
success: 0,
|
|
239
|
+
failed: 1,
|
|
240
|
+
blocked: 0,
|
|
241
|
+
error: 0,
|
|
242
|
+
},
|
|
243
|
+
errors: [
|
|
244
|
+
{
|
|
245
|
+
proof_index: 0,
|
|
246
|
+
error: {
|
|
247
|
+
code: "invalid_signature",
|
|
248
|
+
message: "Invalid JWS signature",
|
|
249
|
+
},
|
|
250
|
+
},
|
|
251
|
+
],
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
mockFetchProvider.fetch.mockResolvedValue(
|
|
255
|
+
new Response(JSON.stringify(mockResponse), {
|
|
256
|
+
status: 200,
|
|
257
|
+
headers: { "Content-Type": "application/json" },
|
|
258
|
+
})
|
|
259
|
+
);
|
|
260
|
+
|
|
261
|
+
const result = await accessControlService.submitProofs(request);
|
|
262
|
+
|
|
263
|
+
// Type assertion needed due to TypeScript type resolution issues with outdated node_modules types
|
|
264
|
+
// The actual runtime type has accepted/rejected/outcomes, but node_modules has old types
|
|
265
|
+
const typedResult = result as unknown as {
|
|
266
|
+
success: boolean;
|
|
267
|
+
accepted: number;
|
|
268
|
+
rejected: number;
|
|
269
|
+
outcomes: Record<string, number>;
|
|
270
|
+
errors?: Array<{
|
|
271
|
+
proof_index: number;
|
|
272
|
+
error: { code: string; message: string };
|
|
273
|
+
}>;
|
|
274
|
+
};
|
|
275
|
+
expect(typedResult.accepted).toBe(0);
|
|
276
|
+
expect(typedResult.rejected).toBe(1);
|
|
277
|
+
expect(typedResult.errors).toBeDefined();
|
|
278
|
+
expect(typedResult.errors?.length).toBe(1);
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
describe("Proof Verification Flow", () => {
|
|
283
|
+
it("should verify proof using ProofVerifier", async () => {
|
|
284
|
+
// Set up DID document for resolution
|
|
285
|
+
const didDoc = {
|
|
286
|
+
id: "did:key:z123",
|
|
287
|
+
verificationMethod: [
|
|
288
|
+
{
|
|
289
|
+
id: "did:key:z123#key-1",
|
|
290
|
+
type: "JsonWebKey2020",
|
|
291
|
+
publicKeyJwk: {
|
|
292
|
+
kty: "OKP",
|
|
293
|
+
crv: "Ed25519",
|
|
294
|
+
x: "VCpo2LMLhn6iWku8MKvSLg2ZAoC-nlOyPVQaO3FxVeQ",
|
|
295
|
+
},
|
|
296
|
+
},
|
|
297
|
+
],
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
mockFetchProvider.setDIDDocument("did:key:z123", didDoc);
|
|
301
|
+
|
|
302
|
+
const proof: DetachedProof = {
|
|
303
|
+
jws: "header.payload.signature",
|
|
304
|
+
meta: {
|
|
305
|
+
did: "did:key:z123",
|
|
306
|
+
kid: "did:key:z123#key-1",
|
|
307
|
+
ts: Math.floor(Date.now() / 1000), // Unix timestamp in seconds
|
|
308
|
+
nonce: "nonce-123",
|
|
309
|
+
audience: "mcp-client",
|
|
310
|
+
sessionId: "session-123",
|
|
311
|
+
requestHash: "sha256:" + "a".repeat(64),
|
|
312
|
+
responseHash: "sha256:" + "b".repeat(64),
|
|
313
|
+
},
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
// Note: This test would require actual cryptographic verification
|
|
317
|
+
// For now, we test the flow structure
|
|
318
|
+
const publicKeyJwk = didDoc.verificationMethod[0].publicKeyJwk as {
|
|
319
|
+
kty: "OKP";
|
|
320
|
+
crv: "Ed25519";
|
|
321
|
+
x: string;
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
// Mock nonce cache to return false (nonce not seen)
|
|
325
|
+
vi.spyOn(mockProviders.nonceCacheProvider, "has").mockResolvedValue(
|
|
326
|
+
false
|
|
327
|
+
);
|
|
328
|
+
|
|
329
|
+
const result = await proofVerifier.verifyProof(proof, publicKeyJwk);
|
|
330
|
+
|
|
331
|
+
// Result will depend on actual signature verification
|
|
332
|
+
expect(result).toBeDefined();
|
|
333
|
+
expect("valid" in result).toBe(true);
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
describe("Runtime Integration", () => {
|
|
338
|
+
it("should use AccessControlApiService from runtime", async () => {
|
|
339
|
+
const request: VerifyDelegationRequest = {
|
|
340
|
+
agent_did: "did:key:z123",
|
|
341
|
+
scopes: ["scope1"],
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
const mockResponse = {
|
|
345
|
+
success: true,
|
|
346
|
+
data: { valid: true },
|
|
347
|
+
metadata: {
|
|
348
|
+
requestId: "test-request-id",
|
|
349
|
+
timestamp: new Date().toISOString(),
|
|
350
|
+
},
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
mockFetchProvider.fetch.mockResolvedValue(
|
|
354
|
+
new Response(JSON.stringify(mockResponse), {
|
|
355
|
+
status: 200,
|
|
356
|
+
headers: { "Content-Type": "application/json" },
|
|
357
|
+
})
|
|
358
|
+
);
|
|
359
|
+
|
|
360
|
+
const runtimeService = (runtime as any)
|
|
361
|
+
.accessControlService as AccessControlApiService;
|
|
362
|
+
|
|
363
|
+
expect(runtimeService).toBeDefined();
|
|
364
|
+
const result = await runtimeService.verifyDelegation(request);
|
|
365
|
+
expect(result.data.valid).toBe(true);
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
it("should use ProofVerifier from runtime", async () => {
|
|
369
|
+
const runtimeVerifier = (runtime as any).proofVerifier as ProofVerifier;
|
|
370
|
+
expect(runtimeVerifier).toBeDefined();
|
|
371
|
+
|
|
372
|
+
// Verify it's the same instance
|
|
373
|
+
expect(runtimeVerifier).toBe(proofVerifier);
|
|
374
|
+
});
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
describe("Error Handling and Retry", () => {
|
|
378
|
+
it("should retry on transient errors", async () => {
|
|
379
|
+
const request: VerifyDelegationRequest = {
|
|
380
|
+
agent_did: "did:key:z123",
|
|
381
|
+
scopes: ["scope1"],
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
const mockResponse = {
|
|
385
|
+
success: true,
|
|
386
|
+
data: { valid: true },
|
|
387
|
+
metadata: {
|
|
388
|
+
requestId: "test-request-id",
|
|
389
|
+
timestamp: new Date().toISOString(),
|
|
390
|
+
},
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
// First call fails with 500, second succeeds
|
|
394
|
+
mockFetchProvider.fetch
|
|
395
|
+
.mockResolvedValueOnce(
|
|
396
|
+
new Response("Internal Server Error", { status: 500 })
|
|
397
|
+
)
|
|
398
|
+
.mockResolvedValueOnce(
|
|
399
|
+
new Response(JSON.stringify(mockResponse), {
|
|
400
|
+
status: 200,
|
|
401
|
+
headers: { "Content-Type": "application/json" },
|
|
402
|
+
})
|
|
403
|
+
);
|
|
404
|
+
|
|
405
|
+
const result = await accessControlService.verifyDelegation(request);
|
|
406
|
+
|
|
407
|
+
expect(result.data.valid).toBe(true);
|
|
408
|
+
expect(mockFetchProvider.fetch).toHaveBeenCalledTimes(2);
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
it("should not retry on client errors", async () => {
|
|
412
|
+
const request: VerifyDelegationRequest = {
|
|
413
|
+
agent_did: "did:key:z123",
|
|
414
|
+
scopes: ["scope1"],
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
mockFetchProvider.fetch.mockResolvedValue(
|
|
418
|
+
new Response(
|
|
419
|
+
JSON.stringify({
|
|
420
|
+
success: false,
|
|
421
|
+
error: {
|
|
422
|
+
code: "validation_error",
|
|
423
|
+
message: "Invalid request",
|
|
424
|
+
},
|
|
425
|
+
}),
|
|
426
|
+
{
|
|
427
|
+
status: 400,
|
|
428
|
+
headers: { "Content-Type": "application/json" },
|
|
429
|
+
}
|
|
430
|
+
)
|
|
431
|
+
);
|
|
432
|
+
|
|
433
|
+
await expect(
|
|
434
|
+
accessControlService.verifyDelegation(request)
|
|
435
|
+
).rejects.toThrow(AgentShieldAPIError);
|
|
436
|
+
|
|
437
|
+
// Should not retry
|
|
438
|
+
expect(mockFetchProvider.fetch).toHaveBeenCalledTimes(1);
|
|
439
|
+
});
|
|
440
|
+
});
|
|
441
|
+
});
|