@kya-os/checkpoint-shared 1.4.0 → 1.5.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.
- package/CHANGELOG.md +41 -0
- package/dist/beacon-types/index.d.mts +448 -432
- package/dist/beacon-types/index.d.mts.map +1 -0
- package/dist/beacon-types/index.d.ts +448 -432
- package/dist/beacon-types/index.d.ts.map +1 -0
- package/dist/beacon-types/index.js +286 -182
- package/dist/beacon-types/index.mjs +284 -180
- package/dist/beacon-types/index.mjs.map +1 -0
- package/dist/browser-posture-cookie-Dmq9Brf_.d.mts +5 -0
- package/dist/browser-posture-cookie-Dmq9Brf_.d.mts.map +1 -0
- package/dist/browser-posture-cookie-Dmq9Brf_.d.ts +5 -0
- package/dist/browser-posture-cookie-Dmq9Brf_.d.ts.map +1 -0
- package/dist/browser-posture-cookie.d.mts +2 -0
- package/dist/browser-posture-cookie.d.ts +2 -0
- package/dist/browser-posture-cookie.js +1 -0
- package/dist/browser-posture-cookie.mjs +2 -0
- package/dist/browser-posture-cookie.mjs.map +1 -0
- package/dist/browser-posture-report.d.mts +48 -44
- package/dist/browser-posture-report.d.mts.map +1 -0
- package/dist/browser-posture-report.d.ts +48 -44
- package/dist/browser-posture-report.d.ts.map +1 -0
- package/dist/browser-posture-report.js +1 -1
- package/dist/browser-posture-report.mjs +2 -1
- package/dist/browser-posture-report.mjs.map +1 -0
- package/dist/browser-posture.d.mts +82 -75
- package/dist/browser-posture.d.mts.map +1 -0
- package/dist/browser-posture.d.ts +82 -75
- package/dist/browser-posture.d.ts.map +1 -0
- package/dist/browser-posture.js +167 -18993
- package/dist/browser-posture.mjs +166 -18990
- package/dist/browser-posture.mjs.map +1 -0
- package/dist/browser.d.mts +323 -316
- package/dist/browser.d.mts.map +1 -0
- package/dist/browser.d.ts +323 -316
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +1 -1
- package/dist/browser.mjs +2 -1
- package/dist/browser.mjs.map +1 -0
- package/dist/canonical-signer/index.d.mts +38 -33
- package/dist/canonical-signer/index.d.mts.map +1 -0
- package/dist/canonical-signer/index.d.ts +38 -33
- package/dist/canonical-signer/index.d.ts.map +1 -0
- package/dist/canonical-signer/index.js +411 -181
- package/dist/canonical-signer/index.mjs +383 -175
- package/dist/canonical-signer/index.mjs.map +1 -0
- package/dist/clearance.d.mts +30 -0
- package/dist/clearance.d.mts.map +1 -0
- package/dist/clearance.d.ts +30 -0
- package/dist/clearance.d.ts.map +1 -0
- package/dist/clearance.js +120 -0
- package/dist/clearance.mjs +112 -0
- package/dist/clearance.mjs.map +1 -0
- package/dist/client-ip-1y2iXAYW.js +237 -0
- package/dist/client-ip-HOfe6ucV.mjs +215 -0
- package/dist/client-ip-HOfe6ucV.mjs.map +1 -0
- package/dist/deploy/index.d.mts +339 -339
- package/dist/deploy/index.d.mts.map +1 -0
- package/dist/deploy/index.d.ts +339 -339
- package/dist/deploy/index.d.ts.map +1 -0
- package/dist/deploy/index.js +505 -413
- package/dist/deploy/index.mjs +504 -410
- package/dist/deploy/index.mjs.map +1 -0
- package/dist/errors/index.d.mts +101 -101
- package/dist/errors/index.d.mts.map +1 -0
- package/dist/errors/index.d.ts +101 -101
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +341 -314
- package/dist/errors/index.mjs +340 -311
- package/dist/errors/index.mjs.map +1 -0
- package/dist/external-jr_S4iSS.d.mts +4187 -0
- package/dist/external-jr_S4iSS.d.mts.map +1 -0
- package/dist/external-jr_S4iSS.d.ts +4187 -0
- package/dist/external-jr_S4iSS.d.ts.map +1 -0
- package/dist/gateway/index.d.mts +138 -132
- package/dist/gateway/index.d.mts.map +1 -0
- package/dist/gateway/index.d.ts +138 -132
- package/dist/gateway/index.d.ts.map +1 -0
- package/dist/gateway/index.js +117 -81
- package/dist/gateway/index.mjs +116 -78
- package/dist/gateway/index.mjs.map +1 -0
- package/dist/gateway-client-ip.d.mts +59 -0
- package/dist/gateway-client-ip.d.mts.map +1 -0
- package/dist/gateway-client-ip.d.ts +59 -0
- package/dist/gateway-client-ip.d.ts.map +1 -0
- package/dist/gateway-client-ip.js +149 -0
- package/dist/gateway-client-ip.mjs +139 -0
- package/dist/gateway-client-ip.mjs.map +1 -0
- package/dist/index.d.mts +14901 -14246
- package/dist/index.d.mts.map +1 -0
- package/dist/index.d.ts +14901 -14246
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15180 -31025
- package/dist/index.mjs +15065 -30942
- package/dist/index.mjs.map +1 -0
- package/dist/mcpi/agentshield-api/index.d.mts +45 -44
- package/dist/mcpi/agentshield-api/index.d.mts.map +1 -0
- package/dist/mcpi/agentshield-api/index.d.ts +45 -44
- package/dist/mcpi/agentshield-api/index.d.ts.map +1 -0
- package/dist/mcpi/agentshield-api/index.js +0 -2
- package/dist/mcpi/agentshield-api/index.mjs +1 -1
- package/dist/mcpi/approval-grant/index.d.mts +63 -61
- package/dist/mcpi/approval-grant/index.d.mts.map +1 -0
- package/dist/mcpi/approval-grant/index.d.ts +63 -61
- package/dist/mcpi/approval-grant/index.d.ts.map +1 -0
- package/dist/mcpi/approval-grant/index.js +220 -140
- package/dist/mcpi/approval-grant/index.mjs +219 -137
- package/dist/mcpi/approval-grant/index.mjs.map +1 -0
- package/dist/mcpi/dashboard-config/index.d.mts +2323 -2318
- package/dist/mcpi/dashboard-config/index.d.mts.map +1 -0
- package/dist/mcpi/dashboard-config/index.d.ts +2323 -2318
- package/dist/mcpi/dashboard-config/index.d.ts.map +1 -0
- package/dist/mcpi/dashboard-config/index.js +605 -458
- package/dist/mcpi/dashboard-config/index.mjs +604 -455
- package/dist/mcpi/dashboard-config/index.mjs.map +1 -0
- package/dist/mcpi/multibase-ed25519.d.mts +10 -8
- package/dist/mcpi/multibase-ed25519.d.mts.map +1 -0
- package/dist/mcpi/multibase-ed25519.d.ts +10 -8
- package/dist/mcpi/multibase-ed25519.d.ts.map +1 -0
- package/dist/mcpi/multibase-ed25519.js +182 -106
- package/dist/mcpi/multibase-ed25519.mjs +181 -103
- package/dist/mcpi/multibase-ed25519.mjs.map +1 -0
- package/dist/patterns-CkRVOdtV.js +243 -0
- package/dist/patterns-DzkGy_qk.mjs +173 -0
- package/dist/patterns-DzkGy_qk.mjs.map +1 -0
- package/dist/project-verification-key-C3L5rd8a.js +41 -0
- package/dist/project-verification-key-CgSVX9_m.mjs +37 -0
- package/dist/project-verification-key-CgSVX9_m.mjs.map +1 -0
- package/dist/rolldown-runtime-iY2fYEqi.mjs +19 -0
- package/dist/schemas-BmjNLAE7.js +5677 -0
- package/dist/schemas-DxY-dk9y.mjs +5511 -0
- package/dist/schemas-DxY-dk9y.mjs.map +1 -0
- package/dist/signals/index.d.mts +125 -115
- package/dist/signals/index.d.mts.map +1 -0
- package/dist/signals/index.d.ts +125 -115
- package/dist/signals/index.d.ts.map +1 -0
- package/dist/signals/index.js +1693 -1536
- package/dist/signals/index.mjs +1692 -1533
- package/dist/signals/index.mjs.map +1 -0
- package/dist/test-fixtures/index.d.mts +124 -119
- package/dist/test-fixtures/index.d.mts.map +1 -0
- package/dist/test-fixtures/index.d.ts +124 -119
- package/dist/test-fixtures/index.d.ts.map +1 -0
- package/dist/test-fixtures/index.js +460 -228
- package/dist/test-fixtures/index.mjs +459 -225
- package/dist/test-fixtures/index.mjs.map +1 -0
- package/dist/tool-protection/index.d.mts +343 -343
- package/dist/tool-protection/index.d.mts.map +1 -0
- package/dist/tool-protection/index.d.ts +343 -343
- package/dist/tool-protection/index.d.ts.map +1 -0
- package/dist/tool-protection/index.js +366 -285
- package/dist/tool-protection/index.mjs +365 -282
- package/dist/tool-protection/index.mjs.map +1 -0
- package/fixtures/bot-signal-resolution.json +142 -0
- package/fixtures/browser-posture-claims.json +421 -0
- package/fixtures/browser-posture-headers.json +46 -0
- package/fixtures/detection/reason-codes.json +10 -1
- package/fixtures/kya-http/challenge.delegation.fetcher-200.json +9 -3
- package/fixtures/kya-http/challenge.delegation.full.json +9 -3
- package/fixtures/kya-http/challenge.delegation.minimal.json +9 -3
- package/fixtures/kya-http/error-codes.json +7 -2
- package/package.json +20 -6
|
@@ -1,342 +1,423 @@
|
|
|
1
|
-
'
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let zod = require("zod");
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
4
|
+
//#region src/tool-protection/index.ts
|
|
5
|
+
/**
|
|
6
|
+
* KYA-OS Tool Protection Specification
|
|
7
|
+
*
|
|
8
|
+
* Core types for tool protection with delegation requirements.
|
|
9
|
+
*
|
|
10
|
+
* Consent Flow: type='none' → 2 screens, others → 3 screens (Auth→Consent→Success).
|
|
11
|
+
* DelegationCredential (VC) is created when user confirms on Consent Screen.
|
|
12
|
+
*
|
|
13
|
+
* Ported into checkpoint-shared from `@kya-os/contracts/tool-protection` as part
|
|
14
|
+
* of the E6 / C-series decommission (#2914 / #2917): checkpoint owns its product
|
|
15
|
+
* types now that the DIF `@kya-os/mcp` core is protocol-only. The single external
|
|
16
|
+
* dependency (`envVarNameSchema` from the contracts `vault` module) is inlined
|
|
17
|
+
* below so this module pulls nothing from `@kya-os/contracts`.
|
|
18
|
+
*
|
|
19
|
+
* @module @kya-os/checkpoint-shared/tool-protection
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* Validates an env var name used by the `apikey` authorization requirement.
|
|
23
|
+
* Inlined from the former `@kya-os/contracts/vault` `envVarNameSchema`.
|
|
24
|
+
*/
|
|
25
|
+
const envVarNameSchema = zod.z.string().regex(/^[A-Z][A-Z0-9_]*$/, "Must be a valid env var name (e.g., X_API_KEY)").max(255);
|
|
26
|
+
/** Canonical authorization type values for type safety */
|
|
27
|
+
const AUTHORIZATION_TYPES = {
|
|
28
|
+
/** @deprecated Use OAUTH2 instead. Will be removed in v2.0.0. */
|
|
29
|
+
OAUTH: "oauth",
|
|
30
|
+
/** OAuth 2.0 provider authentication (canonical) */
|
|
31
|
+
OAUTH2: "oauth2",
|
|
32
|
+
PASSWORD: "password",
|
|
33
|
+
MDL: "mdl",
|
|
34
|
+
IDV: "idv",
|
|
35
|
+
VERIFIABLE_CREDENTIAL: "verifiable_credential",
|
|
36
|
+
/** WebAuthn/Passkey authentication */
|
|
37
|
+
WEBAUTHN: "webauthn",
|
|
38
|
+
/** Sign-In with Ethereum (EIP-4361) */
|
|
39
|
+
SIWE: "siwe",
|
|
40
|
+
/** API Key from per-user vault */
|
|
41
|
+
APIKEY: "apikey",
|
|
42
|
+
NONE: "none"
|
|
24
43
|
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
44
|
+
const AuthRequiredErrorDataSchema = zod.z.object({
|
|
45
|
+
error: zod.z.literal("auth_required"),
|
|
46
|
+
type: zod.z.enum([
|
|
47
|
+
"apikey",
|
|
48
|
+
"oauth",
|
|
49
|
+
"credential"
|
|
50
|
+
]),
|
|
51
|
+
envVarNames: zod.z.array(zod.z.string()).optional(),
|
|
52
|
+
configUrl: zod.z.string(),
|
|
53
|
+
message: zod.z.string()
|
|
31
54
|
});
|
|
55
|
+
/**
|
|
56
|
+
* Error class thrown when required auth is missing and no fallback exists.
|
|
57
|
+
*
|
|
58
|
+
* Caught by the tool-call handler in agent.ts and serialized as a
|
|
59
|
+
* machine-readable MCP tool result so clients can present actionable UI.
|
|
60
|
+
*/
|
|
32
61
|
var AuthRequiredError = class extends Error {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
62
|
+
type;
|
|
63
|
+
envVarNames;
|
|
64
|
+
configUrl;
|
|
65
|
+
constructor(opts) {
|
|
66
|
+
const message = opts.message ?? (opts.type === "apikey" && opts.envVarNames?.length ? `API key required: configure ${opts.envVarNames.join(", ")} in your project settings.` : "Authentication required to use this tool.");
|
|
67
|
+
super(message);
|
|
68
|
+
this.name = "AuthRequiredError";
|
|
69
|
+
this.type = opts.type;
|
|
70
|
+
this.envVarNames = opts.envVarNames;
|
|
71
|
+
this.configUrl = opts.configUrl;
|
|
72
|
+
}
|
|
73
|
+
/** Serialize to the wire format MCP clients expect */
|
|
74
|
+
toJSON() {
|
|
75
|
+
return {
|
|
76
|
+
error: "auth_required",
|
|
77
|
+
type: this.type,
|
|
78
|
+
...this.envVarNames && { envVarNames: this.envVarNames },
|
|
79
|
+
configUrl: this.configUrl,
|
|
80
|
+
message: this.message
|
|
81
|
+
};
|
|
82
|
+
}
|
|
54
83
|
};
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
84
|
+
/**
|
|
85
|
+
* Zod Schemas for Validation
|
|
86
|
+
*/
|
|
87
|
+
const AuthorizationRequirementSchema = zod.z.discriminatedUnion("type", [
|
|
88
|
+
zod.z.object({
|
|
89
|
+
type: zod.z.literal("oauth"),
|
|
90
|
+
provider: zod.z.string(),
|
|
91
|
+
requiredScopes: zod.z.array(zod.z.string()).optional()
|
|
92
|
+
}),
|
|
93
|
+
zod.z.object({
|
|
94
|
+
type: zod.z.literal("oauth2"),
|
|
95
|
+
provider: zod.z.string(),
|
|
96
|
+
requiredScopes: zod.z.array(zod.z.string()).optional()
|
|
97
|
+
}),
|
|
98
|
+
zod.z.object({
|
|
99
|
+
type: zod.z.literal("password"),
|
|
100
|
+
provider: zod.z.string()
|
|
101
|
+
}),
|
|
102
|
+
zod.z.object({
|
|
103
|
+
type: zod.z.literal("mdl"),
|
|
104
|
+
issuer: zod.z.string(),
|
|
105
|
+
credentialType: zod.z.string().optional()
|
|
106
|
+
}),
|
|
107
|
+
zod.z.object({
|
|
108
|
+
type: zod.z.literal("idv"),
|
|
109
|
+
provider: zod.z.string(),
|
|
110
|
+
verificationLevel: zod.z.enum([
|
|
111
|
+
"basic",
|
|
112
|
+
"enhanced",
|
|
113
|
+
"loa3"
|
|
114
|
+
]).optional()
|
|
115
|
+
}),
|
|
116
|
+
zod.z.object({
|
|
117
|
+
type: zod.z.literal("verifiable_credential"),
|
|
118
|
+
credentialType: zod.z.string(),
|
|
119
|
+
issuer: zod.z.string().optional()
|
|
120
|
+
}),
|
|
121
|
+
zod.z.object({
|
|
122
|
+
type: zod.z.literal("credential"),
|
|
123
|
+
credentialType: zod.z.string(),
|
|
124
|
+
issuer: zod.z.string().optional()
|
|
125
|
+
}),
|
|
126
|
+
zod.z.object({
|
|
127
|
+
type: zod.z.literal("webauthn"),
|
|
128
|
+
rpId: zod.z.string().optional(),
|
|
129
|
+
userVerification: zod.z.enum([
|
|
130
|
+
"required",
|
|
131
|
+
"preferred",
|
|
132
|
+
"discouraged"
|
|
133
|
+
]).optional()
|
|
134
|
+
}),
|
|
135
|
+
zod.z.object({
|
|
136
|
+
type: zod.z.literal("siwe"),
|
|
137
|
+
chainId: zod.z.number().optional(),
|
|
138
|
+
domain: zod.z.string().optional()
|
|
139
|
+
}),
|
|
140
|
+
zod.z.object({
|
|
141
|
+
type: zod.z.literal("apikey"),
|
|
142
|
+
envVarNames: zod.z.array(envVarNameSchema).min(1),
|
|
143
|
+
headerMapping: zod.z.record(zod.z.string(), zod.z.string())
|
|
144
|
+
}),
|
|
145
|
+
zod.z.object({ type: zod.z.literal("none") })
|
|
116
146
|
]);
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
147
|
+
const ToolProtectionSchema = zod.z.object({
|
|
148
|
+
requiresDelegation: zod.z.boolean(),
|
|
149
|
+
requiredScopes: zod.z.array(zod.z.string()),
|
|
150
|
+
riskLevel: zod.z.enum([
|
|
151
|
+
"low",
|
|
152
|
+
"medium",
|
|
153
|
+
"high",
|
|
154
|
+
"critical"
|
|
155
|
+
]).optional(),
|
|
156
|
+
oauthProvider: zod.z.string().optional(),
|
|
157
|
+
authorization: AuthorizationRequirementSchema.optional()
|
|
124
158
|
});
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
159
|
+
const ToolProtectionMapSchema = zod.z.record(zod.z.string(), ToolProtectionSchema);
|
|
160
|
+
const ToolProtectionResponseSchema = zod.z.object({
|
|
161
|
+
toolProtections: ToolProtectionMapSchema,
|
|
162
|
+
metadata: zod.z.object({
|
|
163
|
+
lastUpdated: zod.z.string().optional(),
|
|
164
|
+
version: zod.z.string().optional(),
|
|
165
|
+
source: zod.z.string().optional()
|
|
166
|
+
}).optional()
|
|
133
167
|
});
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
168
|
+
const DelegationRequiredErrorDataSchema = zod.z.object({
|
|
169
|
+
toolName: zod.z.string(),
|
|
170
|
+
requiredScopes: zod.z.array(zod.z.string()),
|
|
171
|
+
consentUrl: zod.z.string().optional(),
|
|
172
|
+
authorizationUrl: zod.z.string().optional(),
|
|
173
|
+
reason: zod.z.string().optional()
|
|
140
174
|
});
|
|
175
|
+
/**
|
|
176
|
+
* Type Guards
|
|
177
|
+
*/
|
|
141
178
|
function isToolProtection(obj) {
|
|
142
|
-
|
|
179
|
+
return ToolProtectionSchema.safeParse(obj).success;
|
|
143
180
|
}
|
|
144
181
|
function isToolProtectionMap(obj) {
|
|
145
|
-
|
|
182
|
+
return ToolProtectionMapSchema.safeParse(obj).success;
|
|
146
183
|
}
|
|
147
184
|
function isToolProtectionResponse(obj) {
|
|
148
|
-
|
|
185
|
+
return ToolProtectionResponseSchema.safeParse(obj).success;
|
|
149
186
|
}
|
|
150
187
|
function isDelegationRequiredErrorData(obj) {
|
|
151
|
-
|
|
188
|
+
return DelegationRequiredErrorDataSchema.safeParse(obj).success;
|
|
152
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* Type guard to check if an object is a valid AuthorizationRequirement
|
|
192
|
+
*/
|
|
153
193
|
function isAuthorizationRequirement(obj) {
|
|
154
|
-
|
|
194
|
+
return AuthorizationRequirementSchema.safeParse(obj).success;
|
|
155
195
|
}
|
|
196
|
+
/**
|
|
197
|
+
* Type guard to check if a ToolProtection has OAuth authorization
|
|
198
|
+
* Checks for both 'oauth' (deprecated) and 'oauth2' (canonical)
|
|
199
|
+
*/
|
|
156
200
|
function hasOAuthAuthorization(protection) {
|
|
157
|
-
|
|
201
|
+
return protection.authorization?.type === "oauth" || protection.authorization?.type === "oauth2";
|
|
158
202
|
}
|
|
203
|
+
/**
|
|
204
|
+
* Type guard to check if a ToolProtection has password authorization
|
|
205
|
+
*/
|
|
159
206
|
function hasPasswordAuthorization(protection) {
|
|
160
|
-
|
|
207
|
+
return protection.authorization?.type === "password";
|
|
161
208
|
}
|
|
209
|
+
/**
|
|
210
|
+
* Type guard to check if a ToolProtection requires a Verifiable Credential
|
|
211
|
+
*
|
|
212
|
+
* Note: Also returns true for deprecated 'credential' type (normalized to verifiable_credential)
|
|
213
|
+
*/
|
|
162
214
|
function hasVerifiableCredentialAuthorization(protection) {
|
|
163
|
-
|
|
215
|
+
return protection.authorization?.type === "verifiable_credential" || protection.authorization?.type === "credential";
|
|
164
216
|
}
|
|
217
|
+
/**
|
|
218
|
+
* Type guard to check if a ToolProtection has API Key (vault) authorization
|
|
219
|
+
*/
|
|
165
220
|
function hasApiKeyAuthorization(protection) {
|
|
166
|
-
|
|
221
|
+
return protection.authorization?.type === "apikey";
|
|
167
222
|
}
|
|
223
|
+
/**
|
|
224
|
+
* Validation Functions
|
|
225
|
+
*/
|
|
168
226
|
function validateToolProtection(obj) {
|
|
169
|
-
|
|
227
|
+
return ToolProtectionSchema.parse(obj);
|
|
170
228
|
}
|
|
171
229
|
function validateToolProtectionMap(obj) {
|
|
172
|
-
|
|
230
|
+
return ToolProtectionMapSchema.parse(obj);
|
|
173
231
|
}
|
|
174
232
|
function validateToolProtectionResponse(obj) {
|
|
175
|
-
|
|
233
|
+
return ToolProtectionResponseSchema.parse(obj);
|
|
176
234
|
}
|
|
177
235
|
function validateDelegationRequiredErrorData(obj) {
|
|
178
|
-
|
|
236
|
+
return DelegationRequiredErrorDataSchema.parse(obj);
|
|
179
237
|
}
|
|
238
|
+
/**
|
|
239
|
+
* Utility Functions
|
|
240
|
+
*/
|
|
241
|
+
/**
|
|
242
|
+
* Check if a tool requires delegation
|
|
243
|
+
*/
|
|
180
244
|
function toolRequiresDelegation(toolName, protections) {
|
|
181
|
-
|
|
182
|
-
return protection?.requiresDelegation ?? false;
|
|
245
|
+
return protections[toolName]?.requiresDelegation ?? false;
|
|
183
246
|
}
|
|
247
|
+
/**
|
|
248
|
+
* Get required scopes for a tool
|
|
249
|
+
*/
|
|
184
250
|
function getToolRequiredScopes(toolName, protections) {
|
|
185
|
-
|
|
186
|
-
return protection?.requiredScopes ?? [];
|
|
251
|
+
return protections[toolName]?.requiredScopes ?? [];
|
|
187
252
|
}
|
|
253
|
+
/**
|
|
254
|
+
* Get risk level for a tool
|
|
255
|
+
*/
|
|
188
256
|
function getToolRiskLevel(toolName, protections) {
|
|
189
|
-
|
|
257
|
+
return protections[toolName]?.riskLevel;
|
|
190
258
|
}
|
|
259
|
+
/**
|
|
260
|
+
* Create a delegation required error
|
|
261
|
+
*/
|
|
191
262
|
function createDelegationRequiredError(toolName, requiredScopes, consentUrl) {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
};
|
|
263
|
+
return {
|
|
264
|
+
toolName,
|
|
265
|
+
requiredScopes,
|
|
266
|
+
consentUrl,
|
|
267
|
+
authorizationUrl: consentUrl
|
|
268
|
+
};
|
|
199
269
|
}
|
|
270
|
+
/**
|
|
271
|
+
* Normalize tool protection configuration
|
|
272
|
+
* Migrates legacy oauthProvider field to authorization object
|
|
273
|
+
*
|
|
274
|
+
* - Migrates `oauthProvider` → `authorization: { type: 'oauth', provider: ... }`
|
|
275
|
+
* - Ensures `authorization` field is present when `requiresDelegation=true`
|
|
276
|
+
* - Returns fully normalized ToolProtection object
|
|
277
|
+
*
|
|
278
|
+
* @param raw - Raw tool protection data (may have legacy fields or be partial)
|
|
279
|
+
* @returns Normalized ToolProtection object
|
|
280
|
+
*
|
|
281
|
+
* // TODO: Remove normalizeToolProtection() when all tools migrated
|
|
282
|
+
*/
|
|
200
283
|
function normalizeToolProtection(raw) {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
}
|
|
221
|
-
return normalized;
|
|
284
|
+
const normalized = {
|
|
285
|
+
requiresDelegation: raw.requiresDelegation ?? false,
|
|
286
|
+
requiredScopes: raw.requiredScopes ?? [],
|
|
287
|
+
...raw.riskLevel && { riskLevel: raw.riskLevel },
|
|
288
|
+
...raw.oauthProvider && { oauthProvider: raw.oauthProvider }
|
|
289
|
+
};
|
|
290
|
+
if (raw.authorization) {
|
|
291
|
+
normalized.authorization = raw.authorization;
|
|
292
|
+
return normalized;
|
|
293
|
+
}
|
|
294
|
+
if (raw.oauthProvider) {
|
|
295
|
+
normalized.authorization = {
|
|
296
|
+
type: "oauth",
|
|
297
|
+
provider: raw.oauthProvider
|
|
298
|
+
};
|
|
299
|
+
return normalized;
|
|
300
|
+
}
|
|
301
|
+
if (normalized.requiresDelegation && !normalized.authorization && !normalized.oauthProvider) return normalized;
|
|
302
|
+
return normalized;
|
|
222
303
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
304
|
+
/** Consent provider types - stored in delegation metadata to track auth method used */
|
|
305
|
+
const CONSENT_PROVIDER_TYPES = {
|
|
306
|
+
/** Consent-only mode - no authentication, just clickwrap agreement */
|
|
307
|
+
NONE: "none",
|
|
308
|
+
/** OAuth2 provider authentication */
|
|
309
|
+
OAUTH2: "oauth2",
|
|
310
|
+
/** Password-based authentication (email/password, username/password) */
|
|
311
|
+
PASSWORD: "password",
|
|
312
|
+
/** @deprecated Use PASSWORD instead. Alias for backward compatibility */
|
|
313
|
+
CREDENTIAL: "credential",
|
|
314
|
+
/** Email magic link authentication */
|
|
315
|
+
MAGIC_LINK: "magic_link",
|
|
316
|
+
/** One-time password (SMS/email code) */
|
|
317
|
+
OTP: "otp"
|
|
236
318
|
};
|
|
319
|
+
/**
|
|
320
|
+
* Determine consent provider type based on available identity information
|
|
321
|
+
*
|
|
322
|
+
* This is the single source of truth for consent provider type determination.
|
|
323
|
+
*
|
|
324
|
+
* @param hasOAuthIdentity - Whether OAuth identity is available
|
|
325
|
+
* @param isPasswordFlow - Whether this is a password/credential flow
|
|
326
|
+
* @param isMagicLinkFlow - Whether this is a magic link flow
|
|
327
|
+
* @param isOtpFlow - Whether this is an OTP flow
|
|
328
|
+
* @returns The consent provider type
|
|
329
|
+
*/
|
|
237
330
|
function determineConsentProviderType(hasOAuthIdentity, isPasswordFlow = false, isMagicLinkFlow = false, isOtpFlow = false) {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
}
|
|
244
|
-
if (isOtpFlow) {
|
|
245
|
-
return CONSENT_PROVIDER_TYPES.OTP;
|
|
246
|
-
}
|
|
247
|
-
if (hasOAuthIdentity) {
|
|
248
|
-
return CONSENT_PROVIDER_TYPES.OAUTH2;
|
|
249
|
-
}
|
|
250
|
-
return CONSENT_PROVIDER_TYPES.NONE;
|
|
331
|
+
if (isPasswordFlow) return CONSENT_PROVIDER_TYPES.PASSWORD;
|
|
332
|
+
if (isMagicLinkFlow) return CONSENT_PROVIDER_TYPES.MAGIC_LINK;
|
|
333
|
+
if (isOtpFlow) return CONSENT_PROVIDER_TYPES.OTP;
|
|
334
|
+
if (hasOAuthIdentity) return CONSENT_PROVIDER_TYPES.OAUTH2;
|
|
335
|
+
return CONSENT_PROVIDER_TYPES.NONE;
|
|
251
336
|
}
|
|
337
|
+
/**
|
|
338
|
+
* Get a human-readable label for an authorization requirement type
|
|
339
|
+
*/
|
|
252
340
|
function getAuthorizationTypeLabel(auth) {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
case "webauthn":
|
|
268
|
-
return "Passkey / WebAuthn";
|
|
269
|
-
case "siwe":
|
|
270
|
-
return "Sign-In with Ethereum";
|
|
271
|
-
case "apikey":
|
|
272
|
-
return "API Key (Vault)";
|
|
273
|
-
case "none":
|
|
274
|
-
return "Consent Only";
|
|
275
|
-
default: {
|
|
276
|
-
return "Unknown";
|
|
277
|
-
}
|
|
278
|
-
}
|
|
341
|
+
switch (auth.type) {
|
|
342
|
+
case "oauth":
|
|
343
|
+
case "oauth2": return auth.provider ? auth.provider.charAt(0).toUpperCase() + auth.provider.slice(1) : "OAuth Provider";
|
|
344
|
+
case "password": return "Password Authentication";
|
|
345
|
+
case "mdl": return "Mobile Driver's License";
|
|
346
|
+
case "idv": return "Identity Verification";
|
|
347
|
+
case "verifiable_credential": return auth.credentialType || "Verifiable Credential";
|
|
348
|
+
case "credential": return auth.credentialType || "Verifiable Credential";
|
|
349
|
+
case "webauthn": return "Passkey / WebAuthn";
|
|
350
|
+
case "siwe": return "Sign-In with Ethereum";
|
|
351
|
+
case "apikey": return "API Key (Vault)";
|
|
352
|
+
case "none": return "Consent Only";
|
|
353
|
+
default: return "Unknown";
|
|
354
|
+
}
|
|
279
355
|
}
|
|
356
|
+
/**
|
|
357
|
+
* Get a unique key for an authorization requirement (for React keys, caching, etc.)
|
|
358
|
+
*/
|
|
280
359
|
function getAuthorizationTypeKey(auth) {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
return `vc:${auth.issuer || "any"}:${auth.credentialType || "unknown"}`;
|
|
296
|
-
case "webauthn":
|
|
297
|
-
return `webauthn:${auth.rpId || "default"}`;
|
|
298
|
-
case "siwe":
|
|
299
|
-
return `siwe:${auth.chainId || 1}:${auth.domain || "any"}`;
|
|
300
|
-
case "apikey":
|
|
301
|
-
return `apikey:${[...auth.envVarNames].sort().join(",")}`;
|
|
302
|
-
case "none":
|
|
303
|
-
return "none";
|
|
304
|
-
default: {
|
|
305
|
-
return "unknown";
|
|
306
|
-
}
|
|
307
|
-
}
|
|
360
|
+
switch (auth.type) {
|
|
361
|
+
case "oauth": return auth.provider ? `oauth:${auth.provider}` : "oauth";
|
|
362
|
+
case "oauth2": return auth.provider ? `oauth2:${auth.provider}` : "oauth2";
|
|
363
|
+
case "password": return auth.provider ? `password:${auth.provider}` : "password";
|
|
364
|
+
case "mdl": return `mdl:${auth.issuer || "unknown"}:${auth.credentialType || ""}`;
|
|
365
|
+
case "idv": return `idv:${auth.provider || "unknown"}:${auth.verificationLevel || ""}`;
|
|
366
|
+
case "verifiable_credential": return `vc:${auth.issuer || "any"}:${auth.credentialType || "unknown"}`;
|
|
367
|
+
case "credential": return `vc:${auth.issuer || "any"}:${auth.credentialType || "unknown"}`;
|
|
368
|
+
case "webauthn": return `webauthn:${auth.rpId || "default"}`;
|
|
369
|
+
case "siwe": return `siwe:${auth.chainId || 1}:${auth.domain || "any"}`;
|
|
370
|
+
case "apikey": return `apikey:${[...auth.envVarNames].sort().join(",")}`;
|
|
371
|
+
case "none": return "none";
|
|
372
|
+
default: return "unknown";
|
|
373
|
+
}
|
|
308
374
|
}
|
|
375
|
+
/**
|
|
376
|
+
* Normalize authorization requirement type
|
|
377
|
+
*
|
|
378
|
+
* Normalizes deprecated types to their canonical equivalents:
|
|
379
|
+
* - 'oauth' → 'oauth2'
|
|
380
|
+
* - 'credential' → 'verifiable_credential'
|
|
381
|
+
*
|
|
382
|
+
* This function should be called at runtime boundaries when processing
|
|
383
|
+
* authorization requirements.
|
|
384
|
+
*
|
|
385
|
+
* @param auth - Authorization requirement (may contain deprecated types)
|
|
386
|
+
* @param options - Normalization options
|
|
387
|
+
* @returns Normalized authorization requirement
|
|
388
|
+
*
|
|
389
|
+
* @example
|
|
390
|
+
* ```typescript
|
|
391
|
+
* const normalized = normalizeAuthorizationType(
|
|
392
|
+
* { type: 'oauth', provider: 'github' },
|
|
393
|
+
* { warn: true }
|
|
394
|
+
* );
|
|
395
|
+
* // Returns: { type: 'oauth2', provider: 'github' }
|
|
396
|
+
* // Logs: DEPRECATION warning
|
|
397
|
+
* ```
|
|
398
|
+
*/
|
|
309
399
|
function normalizeAuthorizationType(auth, options = {}) {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
);
|
|
329
|
-
}
|
|
330
|
-
const normalized = {
|
|
331
|
-
type: "verifiable_credential",
|
|
332
|
-
credentialType: auth.credentialType,
|
|
333
|
-
...auth.issuer !== void 0 && { issuer: auth.issuer }
|
|
334
|
-
};
|
|
335
|
-
return normalized;
|
|
336
|
-
}
|
|
337
|
-
return auth;
|
|
400
|
+
const { warn = true, logger = console.warn } = options;
|
|
401
|
+
if (auth.type === "oauth") {
|
|
402
|
+
if (warn) logger("DEPRECATION: Authorization type 'oauth' is deprecated and will be removed in v2.0.0. Please update to 'oauth2'. See https://github.com/modelcontextprotocol-identity/xmcp-i/blob/main/docs/migrations/oauth-to-oauth2.md");
|
|
403
|
+
return {
|
|
404
|
+
type: "oauth2",
|
|
405
|
+
provider: auth.provider,
|
|
406
|
+
...auth.requiredScopes !== void 0 && { requiredScopes: auth.requiredScopes }
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
if (auth.type === "credential") {
|
|
410
|
+
if (warn) logger("DEPRECATION: Authorization type 'credential' is deprecated and will be removed in v2.0.0. Please update to 'verifiable_credential'. See https://github.com/modelcontextprotocol-identity/xmcp-i/blob/main/docs/migrations/credential-to-verifiable_credential.md");
|
|
411
|
+
return {
|
|
412
|
+
type: "verifiable_credential",
|
|
413
|
+
credentialType: auth.credentialType,
|
|
414
|
+
...auth.issuer !== void 0 && { issuer: auth.issuer }
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
return auth;
|
|
338
418
|
}
|
|
339
419
|
|
|
420
|
+
//#endregion
|
|
340
421
|
exports.AUTHORIZATION_TYPES = AUTHORIZATION_TYPES;
|
|
341
422
|
exports.AuthRequiredError = AuthRequiredError;
|
|
342
423
|
exports.AuthRequiredErrorDataSchema = AuthRequiredErrorDataSchema;
|
|
@@ -367,4 +448,4 @@ exports.toolRequiresDelegation = toolRequiresDelegation;
|
|
|
367
448
|
exports.validateDelegationRequiredErrorData = validateDelegationRequiredErrorData;
|
|
368
449
|
exports.validateToolProtection = validateToolProtection;
|
|
369
450
|
exports.validateToolProtectionMap = validateToolProtectionMap;
|
|
370
|
-
exports.validateToolProtectionResponse = validateToolProtectionResponse;
|
|
451
|
+
exports.validateToolProtectionResponse = validateToolProtectionResponse;
|