@kya-os/mcp-i-core 1.8.0 → 1.8.1

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 (111) hide show
  1. package/dist/conformance/capability-verifier-adapter.d.ts +66 -0
  2. package/dist/conformance/capability-verifier-adapter.js +61 -0
  3. package/dist/conformance/index.d.ts +3 -1
  4. package/dist/conformance/index.js +7 -1
  5. package/dist/conformance/validate-level2.d.ts +13 -3
  6. package/dist/conformance/validate-level2.js +15 -5
  7. package/dist/conformance/vc-jwt-verifier.d.ts +55 -0
  8. package/dist/conformance/vc-jwt-verifier.js +147 -0
  9. package/dist/delegation/did-web-resolver.d.ts +60 -0
  10. package/dist/delegation/did-web-resolver.js +129 -0
  11. package/dist/index.d.ts +2 -1
  12. package/dist/index.js +9 -1
  13. package/package.json +3 -3
  14. package/dist/auth/handshake.d.ts +0 -119
  15. package/dist/auth/handshake.js +0 -250
  16. package/dist/auth/index.d.ts +0 -6
  17. package/dist/auth/index.js +0 -11
  18. package/dist/auth/types.d.ts +0 -46
  19. package/dist/auth/types.js +0 -10
  20. package/dist/cache/oauth-config-cache.d.ts +0 -69
  21. package/dist/cache/oauth-config-cache.js +0 -76
  22. package/dist/cache/tool-protection-cache.d.ts +0 -89
  23. package/dist/cache/tool-protection-cache.js +0 -118
  24. package/dist/compliance/index.d.ts +0 -8
  25. package/dist/compliance/index.js +0 -24
  26. package/dist/compliance/schema-registry.d.ts +0 -50
  27. package/dist/compliance/schema-registry.js +0 -438
  28. package/dist/compliance/schema-verifier.d.ts +0 -110
  29. package/dist/compliance/schema-verifier.js +0 -518
  30. package/dist/config/remote-config.d.ts +0 -173
  31. package/dist/config/remote-config.js +0 -253
  32. package/dist/config.d.ts +0 -182
  33. package/dist/config.js +0 -148
  34. package/dist/identity/idp-token-resolver.d.ts +0 -69
  35. package/dist/identity/idp-token-resolver.js +0 -136
  36. package/dist/identity/idp-token-storage.interface.d.ts +0 -80
  37. package/dist/identity/idp-token-storage.interface.js +0 -14
  38. package/dist/identity/user-did-manager.d.ts +0 -228
  39. package/dist/identity/user-did-manager.js +0 -356
  40. package/dist/logging/index.d.ts +0 -5
  41. package/dist/logging/index.js +0 -10
  42. package/dist/logging/logger.d.ts +0 -33
  43. package/dist/logging/logger.js +0 -104
  44. package/dist/proof/generator.d.ts +0 -109
  45. package/dist/proof/generator.js +0 -236
  46. package/dist/proof/index.d.ts +0 -5
  47. package/dist/proof/index.js +0 -11
  48. package/dist/providers/base.d.ts +0 -95
  49. package/dist/providers/base.js +0 -47
  50. package/dist/providers/memory.d.ts +0 -42
  51. package/dist/providers/memory.js +0 -121
  52. package/dist/runtime/audit-logger.d.ts +0 -37
  53. package/dist/runtime/audit-logger.js +0 -9
  54. package/dist/runtime/base.d.ts +0 -375
  55. package/dist/runtime/base.js +0 -1491
  56. package/dist/runtime/ext-apps-constants.d.ts +0 -14
  57. package/dist/runtime/ext-apps-constants.js +0 -17
  58. package/dist/services/access-control.service.d.ts +0 -138
  59. package/dist/services/access-control.service.js +0 -721
  60. package/dist/services/authorization/authorization-registry.d.ts +0 -29
  61. package/dist/services/authorization/authorization-registry.js +0 -58
  62. package/dist/services/authorization/types.d.ts +0 -53
  63. package/dist/services/authorization/types.js +0 -10
  64. package/dist/services/batch-delegation.service.d.ts +0 -53
  65. package/dist/services/batch-delegation.service.js +0 -95
  66. package/dist/services/crypto.service.d.ts +0 -69
  67. package/dist/services/crypto.service.js +0 -225
  68. package/dist/services/delegation-error-formatter.d.ts +0 -124
  69. package/dist/services/delegation-error-formatter.js +0 -214
  70. package/dist/services/errors.d.ts +0 -49
  71. package/dist/services/errors.js +0 -66
  72. package/dist/services/index.d.ts +0 -9
  73. package/dist/services/index.js +0 -15
  74. package/dist/services/oauth-config.service.d.ts +0 -53
  75. package/dist/services/oauth-config.service.js +0 -141
  76. package/dist/services/oauth-provider-registry.d.ts +0 -88
  77. package/dist/services/oauth-provider-registry.js +0 -128
  78. package/dist/services/oauth-service.d.ts +0 -122
  79. package/dist/services/oauth-service.js +0 -442
  80. package/dist/services/oauth-token-retrieval.service.d.ts +0 -49
  81. package/dist/services/oauth-token-retrieval.service.js +0 -150
  82. package/dist/services/policy.service.d.ts +0 -130
  83. package/dist/services/policy.service.js +0 -399
  84. package/dist/services/proof-verifier.d.ts +0 -98
  85. package/dist/services/proof-verifier.js +0 -319
  86. package/dist/services/provider-resolver.d.ts +0 -89
  87. package/dist/services/provider-resolver.js +0 -196
  88. package/dist/services/provider-validator.d.ts +0 -55
  89. package/dist/services/provider-validator.js +0 -135
  90. package/dist/services/session-registration.service.d.ts +0 -80
  91. package/dist/services/session-registration.service.js +0 -174
  92. package/dist/services/storage.service.d.ts +0 -116
  93. package/dist/services/storage.service.js +0 -411
  94. package/dist/services/tool-context-builder.d.ts +0 -74
  95. package/dist/services/tool-context-builder.js +0 -215
  96. package/dist/services/tool-protection.service.d.ts +0 -193
  97. package/dist/services/tool-protection.service.js +0 -736
  98. package/dist/session/index.d.ts +0 -5
  99. package/dist/session/index.js +0 -11
  100. package/dist/session/manager.d.ts +0 -113
  101. package/dist/session/manager.js +0 -273
  102. package/dist/types/oauth-required-error.d.ts +0 -46
  103. package/dist/types/oauth-required-error.js +0 -42
  104. package/dist/types/tool-protection.d.ts +0 -144
  105. package/dist/types/tool-protection.js +0 -48
  106. package/dist/utils/cors.d.ts +0 -44
  107. package/dist/utils/cors.js +0 -71
  108. package/dist/utils/index.d.ts +0 -8
  109. package/dist/utils/index.js +0 -24
  110. package/dist/utils/storage-keys.d.ts +0 -120
  111. package/dist/utils/storage-keys.js +0 -217
package/dist/index.js CHANGED
@@ -24,7 +24,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
24
24
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
25
25
  };
26
26
  Object.defineProperty(exports, "__esModule", { value: true });
27
- exports.DEFAULT_TRUSTED_ISSUERS = exports.validateLevel2 = exports.parseVCJWT = exports.completeVCJWT = exports.createUnsignedVCJWT = exports.canonicalizeJSON = exports.resolveDidKeySync = exports.publicKeyToJwk = exports.extractPublicKeyFromDidKey = exports.isEd25519DidKey = exports.createDidKeyResolver = exports.buildChainString = exports.buildDelegationProofJWT = exports.MemoryDelegationGraphStorage = exports.MemoryStatusListStorage = exports.createCascadingRevocationManager = exports.CascadingRevocationManager = exports.createDelegationGraph = exports.DelegationGraphManager = exports.isIndexSet = exports.BitstringManager = exports.createStatusListManager = exports.StatusList2021Manager = exports.createDelegationVerifier = exports.DelegationCredentialVerifier = exports.createDelegationIssuer = exports.DelegationCredentialIssuer = void 0;
27
+ exports.createCapabilityVerifier = exports.createCombinedDidResolver = exports.createVcJwtSignatureVerifier = exports.DEFAULT_TRUSTED_ISSUERS = exports.validateLevel2 = exports.verifyCapabilities = exports.parseVCJWT = exports.completeVCJWT = exports.createUnsignedVCJWT = exports.canonicalizeJSON = exports.didWebToUrl = exports.createDidWebResolver = exports.resolveDidKeySync = exports.publicKeyToJwk = exports.extractPublicKeyFromDidKey = exports.isEd25519DidKey = exports.createDidKeyResolver = exports.buildChainString = exports.buildDelegationProofJWT = exports.MemoryDelegationGraphStorage = exports.MemoryStatusListStorage = exports.createCascadingRevocationManager = exports.CascadingRevocationManager = exports.createDelegationGraph = exports.DelegationGraphManager = exports.isIndexSet = exports.BitstringManager = exports.createStatusListManager = exports.StatusList2021Manager = exports.createDelegationVerifier = exports.DelegationCredentialVerifier = exports.createDelegationIssuer = exports.DelegationCredentialIssuer = void 0;
28
28
  __exportStar(require("@kya-os/mcp-i-runtime"), exports);
29
29
  // Delegation (W3C VC-based)
30
30
  var vc_issuer_1 = require("./delegation/vc-issuer");
@@ -63,6 +63,10 @@ Object.defineProperty(exports, "isEd25519DidKey", { enumerable: true, get: funct
63
63
  Object.defineProperty(exports, "extractPublicKeyFromDidKey", { enumerable: true, get: function () { return did_key_resolver_1.extractPublicKeyFromDidKey; } });
64
64
  Object.defineProperty(exports, "publicKeyToJwk", { enumerable: true, get: function () { return did_key_resolver_1.publicKeyToJwk; } });
65
65
  Object.defineProperty(exports, "resolveDidKeySync", { enumerable: true, get: function () { return did_key_resolver_1.resolveDidKeySync; } });
66
+ // DID:web Resolver (Phase 3 VC Verification)
67
+ var did_web_resolver_1 = require("./delegation/did-web-resolver");
68
+ Object.defineProperty(exports, "createDidWebResolver", { enumerable: true, get: function () { return did_web_resolver_1.createDidWebResolver; } });
69
+ Object.defineProperty(exports, "didWebToUrl", { enumerable: true, get: function () { return did_web_resolver_1.didWebToUrl; } });
66
70
  // Delegation VC JWT utilities
67
71
  var utils_1 = require("./delegation/utils");
68
72
  Object.defineProperty(exports, "canonicalizeJSON", { enumerable: true, get: function () { return utils_1.canonicalizeJSON; } });
@@ -72,6 +76,10 @@ Object.defineProperty(exports, "parseVCJWT", { enumerable: true, get: function (
72
76
  // Level 2 capability attestation validator (spec follow-up to
73
77
  // modelcontextprotocol-identity#46)
74
78
  var index_js_1 = require("./conformance/index.js");
79
+ Object.defineProperty(exports, "verifyCapabilities", { enumerable: true, get: function () { return index_js_1.verifyCapabilities; } });
75
80
  Object.defineProperty(exports, "validateLevel2", { enumerable: true, get: function () { return index_js_1.validateLevel2; } });
76
81
  Object.defineProperty(exports, "DEFAULT_TRUSTED_ISSUERS", { enumerable: true, get: function () { return index_js_1.DEFAULT_TRUSTED_ISSUERS; } });
82
+ Object.defineProperty(exports, "createVcJwtSignatureVerifier", { enumerable: true, get: function () { return index_js_1.createVcJwtSignatureVerifier; } });
83
+ Object.defineProperty(exports, "createCombinedDidResolver", { enumerable: true, get: function () { return index_js_1.createCombinedDidResolver; } });
84
+ Object.defineProperty(exports, "createCapabilityVerifier", { enumerable: true, get: function () { return index_js_1.createCapabilityVerifier; } });
77
85
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kya-os/mcp-i-core",
3
- "version": "1.8.0",
3
+ "version": "1.8.1",
4
4
  "description": "Compatibility shim — re-exports @kya-os/mcp-i-runtime (product layer) plus the pinned W3C-VC delegation modules. Prefer @kya-os/mcp-i-runtime directly.",
5
5
  "license": "MIT",
6
6
  "author": "Dylan Hobbs",
@@ -31,8 +31,8 @@
31
31
  "prepublishOnly": "npm run build && node ../create-mcpi-app/scripts/validate-no-workspace.js"
32
32
  },
33
33
  "dependencies": {
34
- "@kya-os/contracts": "^1.8.0",
35
- "@kya-os/mcp": "^1.6.1",
34
+ "@kya-os/contracts": "^1.9.0",
35
+ "@kya-os/mcp": "^1.10.1",
36
36
  "@kya-os/mcp-i-runtime": "^1.0.0",
37
37
  "jose": "^5.6.3",
38
38
  "json-canonicalize": "^2.0.0",
@@ -1,119 +0,0 @@
1
- /**
2
- * Authorization Handshake — Platform-agnostic Protocol Reference
3
- *
4
- * Orchestrates the authorization flow for MCP-I bouncer:
5
- * 1. Check agent reputation (optional)
6
- * 2. Verify delegation exists
7
- * 3. Return needs_authorization error if missing
8
- *
9
- * This module uses only the global fetch API — no Node-specific imports.
10
- * It is safe to run on Node.js, Cloudflare Workers, and any fetch-capable runtime.
11
- *
12
- * Flow:
13
- * - If delegation exists + valid → allow (fast path)
14
- * - If delegation missing → return needs_authorization with hints
15
- * - If reputation too low (optional) → require authorization
16
- */
17
- import { NeedsAuthorizationError } from "@kya-os/contracts/runtime";
18
- import { DelegationRecord } from "@kya-os/contracts/delegation";
19
- import { DelegationVerifier, VerifyDelegationResult } from "./types";
20
- export type { DelegationVerifier, VerifyDelegationResult };
21
- /**
22
- * Agent reputation data from KTA
23
- */
24
- export interface AgentReputation {
25
- agentDid: string;
26
- score: number;
27
- totalInteractions: number;
28
- successRate: number;
29
- riskLevel: "low" | "medium" | "high" | "unknown";
30
- updatedAt: number;
31
- }
32
- /**
33
- * Configuration for auth handshake
34
- */
35
- export interface AuthHandshakeConfig {
36
- delegationVerifier: DelegationVerifier;
37
- resumeTokenStore: ResumeTokenStore;
38
- kta?: {
39
- apiUrl: string;
40
- apiKey?: string;
41
- apiFormat?: "kta" | "argus";
42
- };
43
- bouncer: {
44
- authorizationUrl: string;
45
- resumeTokenTtl?: number;
46
- requireAuthForUnknown?: boolean;
47
- minReputationScore?: number;
48
- };
49
- debug?: boolean;
50
- }
51
- /**
52
- * Result of auth handshake verification
53
- */
54
- export interface VerifyOrHintsResult {
55
- authorized: boolean;
56
- delegation?: DelegationRecord;
57
- credential?: {
58
- agent_did: string;
59
- user_did: string;
60
- scopes: string[];
61
- authorization: {
62
- type: "oauth" | "oauth2" | "password" | "credential" | "webauthn" | "siwe" | "none";
63
- provider?: string;
64
- credentialType?: string;
65
- rpId?: string;
66
- userVerification?: "required" | "preferred" | "discouraged";
67
- chainId?: number;
68
- domain?: string;
69
- };
70
- [key: string]: unknown;
71
- };
72
- authError?: NeedsAuthorizationError;
73
- reputation?: AgentReputation;
74
- reason?: string;
75
- }
76
- /**
77
- * Resume token store interface
78
- */
79
- export interface ResumeTokenStore {
80
- create(agentDid: string, scopes: string[], metadata?: Record<string, unknown>): Promise<string>;
81
- get(token: string): Promise<{
82
- agentDid: string;
83
- scopes: string[];
84
- createdAt: number;
85
- expiresAt: number;
86
- metadata?: Record<string, unknown>;
87
- } | null>;
88
- fulfill(token: string): Promise<void>;
89
- }
90
- /**
91
- * Simple in-memory resume token store (for testing/development).
92
- * Not suitable for multi-instance deployments.
93
- */
94
- export declare class MemoryResumeTokenStore implements ResumeTokenStore {
95
- private tokens;
96
- private ttl;
97
- constructor(ttlMs?: number);
98
- create(agentDid: string, scopes: string[], metadata?: Record<string, unknown>): Promise<string>;
99
- get(token: string): Promise<{
100
- agentDid: string;
101
- scopes: string[];
102
- createdAt: number;
103
- expiresAt: number;
104
- metadata?: Record<string, unknown>;
105
- } | null>;
106
- fulfill(token: string): Promise<void>;
107
- clear(): void;
108
- }
109
- /**
110
- * Main auth handshake function.
111
- *
112
- * Verifies agent authorization or returns authorization hints.
113
- */
114
- export declare function verifyOrHints(agentDid: string, scopes: string[], config: AuthHandshakeConfig, _resumeToken?: string): Promise<VerifyOrHintsResult>;
115
- /**
116
- * Helper: Check if scopes are sensitive and require authorization.
117
- */
118
- export declare function hasSensitiveScopes(scopes: string[]): boolean;
119
- //# sourceMappingURL=handshake.d.ts.map
@@ -1,250 +0,0 @@
1
- "use strict";
2
- /**
3
- * Authorization Handshake — Platform-agnostic Protocol Reference
4
- *
5
- * Orchestrates the authorization flow for MCP-I bouncer:
6
- * 1. Check agent reputation (optional)
7
- * 2. Verify delegation exists
8
- * 3. Return needs_authorization error if missing
9
- *
10
- * This module uses only the global fetch API — no Node-specific imports.
11
- * It is safe to run on Node.js, Cloudflare Workers, and any fetch-capable runtime.
12
- *
13
- * Flow:
14
- * - If delegation exists + valid → allow (fast path)
15
- * - If delegation missing → return needs_authorization with hints
16
- * - If reputation too low (optional) → require authorization
17
- */
18
- Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.MemoryResumeTokenStore = void 0;
20
- exports.verifyOrHints = verifyOrHints;
21
- exports.hasSensitiveScopes = hasSensitiveScopes;
22
- const runtime_1 = require("@kya-os/contracts/runtime");
23
- const logging_1 = require("../logging");
24
- /**
25
- * Simple in-memory resume token store (for testing/development).
26
- * Not suitable for multi-instance deployments.
27
- */
28
- class MemoryResumeTokenStore {
29
- tokens = new Map();
30
- ttl;
31
- constructor(ttlMs = 600_000) {
32
- this.ttl = ttlMs;
33
- }
34
- async create(agentDid, scopes, metadata) {
35
- const token = `rt_${Date.now()}_${Math.random().toString(36).substring(2, 18)}`;
36
- const now = Date.now();
37
- this.tokens.set(token, {
38
- agentDid,
39
- scopes,
40
- createdAt: now,
41
- expiresAt: now + this.ttl,
42
- metadata,
43
- fulfilled: false,
44
- });
45
- return token;
46
- }
47
- async get(token) {
48
- const data = this.tokens.get(token);
49
- if (!data)
50
- return null;
51
- if (Date.now() > data.expiresAt) {
52
- this.tokens.delete(token);
53
- return null;
54
- }
55
- if (data.fulfilled)
56
- return null;
57
- return {
58
- agentDid: data.agentDid,
59
- scopes: data.scopes,
60
- createdAt: data.createdAt,
61
- expiresAt: data.expiresAt,
62
- metadata: data.metadata,
63
- };
64
- }
65
- async fulfill(token) {
66
- const data = this.tokens.get(token);
67
- if (data) {
68
- data.fulfilled = true;
69
- }
70
- }
71
- clear() {
72
- this.tokens.clear();
73
- }
74
- }
75
- exports.MemoryResumeTokenStore = MemoryResumeTokenStore;
76
- /**
77
- * Main auth handshake function.
78
- *
79
- * Verifies agent authorization or returns authorization hints.
80
- */
81
- async function verifyOrHints(agentDid, scopes, config, _resumeToken) {
82
- const startTime = Date.now();
83
- if (config.debug) {
84
- logging_1.logger.debug(`[AuthHandshake] Verifying ${agentDid} for scopes: ${scopes.join(", ")}`);
85
- }
86
- let reputation;
87
- if (config.kta && config.bouncer.minReputationScore !== undefined) {
88
- try {
89
- reputation = await fetchAgentReputation(agentDid, config.kta);
90
- if (config.debug) {
91
- logging_1.logger.debug(`[AuthHandshake] Reputation score: ${reputation.score}`);
92
- }
93
- if (reputation.score < config.bouncer.minReputationScore) {
94
- if (config.debug) {
95
- logging_1.logger.debug(`[AuthHandshake] Reputation ${reputation.score} < ${config.bouncer.minReputationScore}, requiring authorization`);
96
- }
97
- const authError = await buildNeedsAuthorizationError(agentDid, scopes, config, "Agent reputation score below threshold");
98
- return {
99
- authorized: false,
100
- authError,
101
- reputation,
102
- reason: "Low reputation score",
103
- };
104
- }
105
- }
106
- catch (error) {
107
- logging_1.logger.warn("[AuthHandshake] Failed to check reputation:", error);
108
- }
109
- }
110
- let delegationResult;
111
- try {
112
- delegationResult = await config.delegationVerifier.verify(agentDid, scopes);
113
- }
114
- catch (error) {
115
- logging_1.logger.error("[AuthHandshake] Delegation verification failed:", error);
116
- const errorMessage = `Delegation verification error: ${error instanceof Error ? error.message : "Unknown error"}`;
117
- const authError = await buildNeedsAuthorizationError(agentDid, scopes, config, errorMessage);
118
- return {
119
- authorized: false,
120
- authError,
121
- reason: errorMessage,
122
- };
123
- }
124
- if (delegationResult.valid && delegationResult.delegation) {
125
- if (config.debug) {
126
- logging_1.logger.debug(`[AuthHandshake] Delegation valid, authorized (${Date.now() - startTime}ms)`);
127
- }
128
- return {
129
- authorized: true,
130
- delegation: delegationResult.delegation,
131
- credential: delegationResult.credential,
132
- reputation,
133
- reason: "Valid delegation found",
134
- };
135
- }
136
- if (config.debug) {
137
- logging_1.logger.debug(`[AuthHandshake] No delegation found, returning needs_authorization (${Date.now() - startTime}ms)`);
138
- }
139
- const authError = await buildNeedsAuthorizationError(agentDid, scopes, config, delegationResult.reason ?? "No valid delegation found");
140
- return {
141
- authorized: false,
142
- authError,
143
- reputation,
144
- reason: delegationResult.reason ?? "No delegation",
145
- };
146
- }
147
- /**
148
- * Fetch agent reputation from KTA.
149
- */
150
- async function fetchAgentReputation(agentDid, ktaConfig) {
151
- const apiUrl = ktaConfig.apiUrl.replace(/\/$/, "");
152
- const headers = {
153
- "Content-Type": "application/json",
154
- };
155
- if (ktaConfig.apiKey) {
156
- headers["X-API-Key"] = ktaConfig.apiKey;
157
- }
158
- const isArgusFormat = ktaConfig.apiFormat === "argus";
159
- let response;
160
- if (isArgusFormat) {
161
- response = await fetch(`${apiUrl}/v1/reputation/${encodeURIComponent(agentDid)}`, {
162
- method: "POST",
163
- headers,
164
- body: JSON.stringify({ include_details: false }),
165
- });
166
- }
167
- else {
168
- response = await fetch(`${apiUrl}/api/v1/reputation/${encodeURIComponent(agentDid)}`, {
169
- method: "GET",
170
- headers,
171
- });
172
- }
173
- if (!response.ok) {
174
- if (response.status === 404) {
175
- return {
176
- agentDid,
177
- score: 50,
178
- totalInteractions: 0,
179
- successRate: 0,
180
- riskLevel: "unknown",
181
- updatedAt: Date.now(),
182
- };
183
- }
184
- throw new Error(`KTA API error: ${response.status} ${response.statusText}`);
185
- }
186
- const data = (await response.json());
187
- const score = data.score ?? 50;
188
- const levelRaw = (data.level ??
189
- data.riskLevel ??
190
- "unknown").toLowerCase();
191
- const riskLevel = levelRaw === "low" || levelRaw === "medium" || levelRaw === "high"
192
- ? levelRaw
193
- : "unknown";
194
- return {
195
- agentDid: data.agent_did ??
196
- data.agentDid ??
197
- agentDid,
198
- score,
199
- totalInteractions: data.totalInteractions ?? 0,
200
- successRate: data.successRate ?? 0,
201
- riskLevel,
202
- updatedAt: data.calculatedAt
203
- ? new Date(data.calculatedAt).getTime()
204
- : (data.updatedAt ?? Date.now()),
205
- };
206
- }
207
- /**
208
- * Build needs_authorization error with hints.
209
- */
210
- async function buildNeedsAuthorizationError(agentDid, scopes, config, message) {
211
- const resumeToken = await config.resumeTokenStore.create(agentDid, scopes, {
212
- requestedAt: Date.now(),
213
- });
214
- const expiresAt = Date.now() + (config.bouncer.resumeTokenTtl ?? 600_000);
215
- const authUrl = new URL(config.bouncer.authorizationUrl);
216
- authUrl.searchParams.set("agent_did", agentDid);
217
- authUrl.searchParams.set("scopes", scopes.join(","));
218
- authUrl.searchParams.set("resume_token", resumeToken);
219
- const authCode = resumeToken.substring(0, 8).toUpperCase();
220
- const display = {
221
- title: "Authorization Required",
222
- hint: ["link", "qr"],
223
- authorizationCode: authCode,
224
- qrUrl: `https://chart.googleapis.com/chart?cht=qr&chs=300x300&chl=${encodeURIComponent(authUrl.toString())}`,
225
- };
226
- return (0, runtime_1.createNeedsAuthorizationError)({
227
- message,
228
- authorizationUrl: authUrl.toString(),
229
- resumeToken,
230
- expiresAt,
231
- scopes,
232
- display,
233
- });
234
- }
235
- /**
236
- * Helper: Check if scopes are sensitive and require authorization.
237
- */
238
- function hasSensitiveScopes(scopes) {
239
- const sensitivePatterns = [
240
- "write",
241
- "delete",
242
- "admin",
243
- "payment",
244
- "transfer",
245
- "execute",
246
- "modify",
247
- ];
248
- return scopes.some((scope) => sensitivePatterns.some((pattern) => scope.toLowerCase().includes(pattern)));
249
- }
250
- //# sourceMappingURL=handshake.js.map
@@ -1,6 +0,0 @@
1
- /**
2
- * Auth module — platform-agnostic authorization handshake reference implementation.
3
- */
4
- export { verifyOrHints, hasSensitiveScopes, MemoryResumeTokenStore, type AuthHandshakeConfig, type VerifyOrHintsResult, type AgentReputation, type ResumeTokenStore, } from "./handshake";
5
- export type { DelegationVerifier, VerifyDelegationResult } from "./types";
6
- //# sourceMappingURL=index.d.ts.map
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MemoryResumeTokenStore = exports.hasSensitiveScopes = exports.verifyOrHints = void 0;
4
- /**
5
- * Auth module — platform-agnostic authorization handshake reference implementation.
6
- */
7
- var handshake_1 = require("./handshake");
8
- Object.defineProperty(exports, "verifyOrHints", { enumerable: true, get: function () { return handshake_1.verifyOrHints; } });
9
- Object.defineProperty(exports, "hasSensitiveScopes", { enumerable: true, get: function () { return handshake_1.hasSensitiveScopes; } });
10
- Object.defineProperty(exports, "MemoryResumeTokenStore", { enumerable: true, get: function () { return handshake_1.MemoryResumeTokenStore; } });
11
- //# sourceMappingURL=index.js.map
@@ -1,46 +0,0 @@
1
- /**
2
- * Authorization types for mcp-i-core auth module.
3
- *
4
- * These are the minimal interfaces required by the auth handshake.
5
- * Platform adapters (packages/mcp-i, packages/mcp-i-cloudflare) may extend
6
- * these types with additional fields.
7
- */
8
- import { DelegationRecord } from "@kya-os/contracts/delegation";
9
- /**
10
- * Result of a delegation verification check.
11
- * Structurally compatible with the full VerifyDelegationResult in packages/mcp-i.
12
- */
13
- export interface VerifyDelegationResult {
14
- /** Whether a valid delegation was found */
15
- valid: boolean;
16
- /** The delegation record (if found) */
17
- delegation?: DelegationRecord;
18
- /** Credential from AgentShield API (includes authorization method) */
19
- credential?: {
20
- agent_did: string;
21
- user_did: string;
22
- scopes: string[];
23
- authorization: {
24
- type: "oauth" | "oauth2" | "password" | "credential" | "webauthn" | "siwe" | "none";
25
- provider?: string;
26
- credentialType?: string;
27
- rpId?: string;
28
- userVerification?: "required" | "preferred" | "discouraged";
29
- chainId?: number;
30
- domain?: string;
31
- };
32
- [key: string]: unknown;
33
- };
34
- /** Reason for invalid result */
35
- reason?: string;
36
- /** Whether result came from cache */
37
- cached?: boolean;
38
- }
39
- /**
40
- * Minimal delegation verifier interface required by verifyOrHints().
41
- * Concrete implementations live in packages/mcp-i (AgentShieldAPIDelegationVerifier, etc.).
42
- */
43
- export interface DelegationVerifier {
44
- verify(agentDid: string, scopes: string[]): Promise<VerifyDelegationResult>;
45
- }
46
- //# sourceMappingURL=types.d.ts.map
@@ -1,10 +0,0 @@
1
- "use strict";
2
- /**
3
- * Authorization types for mcp-i-core auth module.
4
- *
5
- * These are the minimal interfaces required by the auth handshake.
6
- * Platform adapters (packages/mcp-i, packages/mcp-i-cloudflare) may extend
7
- * these types with additional fields.
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- //# sourceMappingURL=types.js.map
@@ -1,69 +0,0 @@
1
- /**
2
- * Platform-agnostic cache interface for OAuth provider configurations
3
- *
4
- * This interface allows different runtime adapters to provide their own
5
- * caching implementations (e.g., in-memory for Node.js, KV for Cloudflare)
6
- *
7
- * @package @kya-os/mcp-i-core
8
- */
9
- import type { OAuthConfig } from "@kya-os/contracts/config";
10
- /**
11
- * Cache interface for storing and retrieving OAuth provider configurations
12
- */
13
- export interface OAuthConfigCache {
14
- /**
15
- * Retrieve a cached OAuth configuration
16
- * @param key Cache key (typically projectId)
17
- * @returns Cached config or null if not found/expired
18
- */
19
- get(key: string): Promise<OAuthConfig | null>;
20
- /**
21
- * Store an OAuth configuration in cache
22
- * @param key Cache key (typically projectId)
23
- * @param value OAuth configuration to cache
24
- * @param ttl Time-to-live in milliseconds
25
- */
26
- set(key: string, value: OAuthConfig, ttl: number): Promise<void>;
27
- /**
28
- * Clear all cached entries
29
- */
30
- clear(): Promise<void>;
31
- /**
32
- * Remove a specific cache entry
33
- * @param key Cache key to remove
34
- */
35
- delete(key: string): Promise<void>;
36
- }
37
- /**
38
- * In-memory cache implementation
39
- *
40
- * Suitable for:
41
- * - Node.js runtimes
42
- * - Development/testing
43
- * - Single-instance deployments
44
- *
45
- * NOT suitable for:
46
- * - Multi-instance deployments (cache not shared)
47
- * - Serverless environments (state not persisted)
48
- */
49
- export declare class InMemoryOAuthConfigCache implements OAuthConfigCache {
50
- private cache;
51
- get(key: string): Promise<OAuthConfig | null>;
52
- set(key: string, value: OAuthConfig, ttl: number): Promise<void>;
53
- clear(): Promise<void>;
54
- delete(key: string): Promise<void>;
55
- }
56
- /**
57
- * No-op cache implementation (disables caching)
58
- *
59
- * Use when:
60
- * - You want to disable caching entirely
61
- * - Testing scenarios that require fresh data
62
- */
63
- export declare class NoOpOAuthConfigCache implements OAuthConfigCache {
64
- get(_key: string): Promise<OAuthConfig | null>;
65
- set(_key: string, _value: OAuthConfig, _ttl: number): Promise<void>;
66
- clear(): Promise<void>;
67
- delete(_key: string): Promise<void>;
68
- }
69
- //# sourceMappingURL=oauth-config-cache.d.ts.map
@@ -1,76 +0,0 @@
1
- "use strict";
2
- /**
3
- * Platform-agnostic cache interface for OAuth provider configurations
4
- *
5
- * This interface allows different runtime adapters to provide their own
6
- * caching implementations (e.g., in-memory for Node.js, KV for Cloudflare)
7
- *
8
- * @package @kya-os/mcp-i-core
9
- */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.NoOpOAuthConfigCache = exports.InMemoryOAuthConfigCache = void 0;
12
- /**
13
- * In-memory cache implementation
14
- *
15
- * Suitable for:
16
- * - Node.js runtimes
17
- * - Development/testing
18
- * - Single-instance deployments
19
- *
20
- * NOT suitable for:
21
- * - Multi-instance deployments (cache not shared)
22
- * - Serverless environments (state not persisted)
23
- */
24
- class InMemoryOAuthConfigCache {
25
- cache = new Map();
26
- async get(key) {
27
- const entry = this.cache.get(key);
28
- if (!entry) {
29
- return null;
30
- }
31
- // Check if expired
32
- if (Date.now() > entry.expiresAt) {
33
- this.cache.delete(key);
34
- return null;
35
- }
36
- return entry.value;
37
- }
38
- async set(key, value, ttl) {
39
- // If TTL is <= 0, don't store (entry would be immediately expired)
40
- if (ttl <= 0) {
41
- return;
42
- }
43
- const expiresAt = Date.now() + ttl;
44
- this.cache.set(key, { value, expiresAt });
45
- }
46
- async clear() {
47
- this.cache.clear();
48
- }
49
- async delete(key) {
50
- this.cache.delete(key);
51
- }
52
- }
53
- exports.InMemoryOAuthConfigCache = InMemoryOAuthConfigCache;
54
- /**
55
- * No-op cache implementation (disables caching)
56
- *
57
- * Use when:
58
- * - You want to disable caching entirely
59
- * - Testing scenarios that require fresh data
60
- */
61
- class NoOpOAuthConfigCache {
62
- async get(_key) {
63
- return null;
64
- }
65
- async set(_key, _value, _ttl) {
66
- // No-op
67
- }
68
- async clear() {
69
- // No-op
70
- }
71
- async delete(_key) {
72
- // No-op
73
- }
74
- }
75
- exports.NoOpOAuthConfigCache = NoOpOAuthConfigCache;
76
- //# sourceMappingURL=oauth-config-cache.js.map