@kya-os/contracts 1.7.3 → 1.7.6
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/dist/handshake.d.ts +22 -22
- package/dist/tool-protection/index.d.ts +39 -54
- package/dist/tool-protection/index.js +58 -58
- package/package.json +2 -2
package/dist/handshake.d.ts
CHANGED
|
@@ -23,16 +23,16 @@ export declare const MCPClientInfoSchema: z.ZodObject<{
|
|
|
23
23
|
persistentId: z.ZodOptional<z.ZodString>;
|
|
24
24
|
}, "strip", z.ZodTypeAny, {
|
|
25
25
|
name: string;
|
|
26
|
-
title?: string | undefined;
|
|
27
26
|
version?: string | undefined;
|
|
28
27
|
platform?: string | undefined;
|
|
28
|
+
title?: string | undefined;
|
|
29
29
|
vendor?: string | undefined;
|
|
30
30
|
persistentId?: string | undefined;
|
|
31
31
|
}, {
|
|
32
32
|
name: string;
|
|
33
|
-
title?: string | undefined;
|
|
34
33
|
version?: string | undefined;
|
|
35
34
|
platform?: string | undefined;
|
|
35
|
+
title?: string | undefined;
|
|
36
36
|
vendor?: string | undefined;
|
|
37
37
|
persistentId?: string | undefined;
|
|
38
38
|
}>;
|
|
@@ -50,9 +50,9 @@ export declare const MCPClientSessionInfoSchema: z.ZodObject<{
|
|
|
50
50
|
}, "strip", z.ZodTypeAny, {
|
|
51
51
|
name: string;
|
|
52
52
|
clientId: string;
|
|
53
|
-
title?: string | undefined;
|
|
54
53
|
version?: string | undefined;
|
|
55
54
|
platform?: string | undefined;
|
|
55
|
+
title?: string | undefined;
|
|
56
56
|
vendor?: string | undefined;
|
|
57
57
|
persistentId?: string | undefined;
|
|
58
58
|
protocolVersion?: string | undefined;
|
|
@@ -60,9 +60,9 @@ export declare const MCPClientSessionInfoSchema: z.ZodObject<{
|
|
|
60
60
|
}, {
|
|
61
61
|
name: string;
|
|
62
62
|
clientId: string;
|
|
63
|
-
title?: string | undefined;
|
|
64
63
|
version?: string | undefined;
|
|
65
64
|
platform?: string | undefined;
|
|
65
|
+
title?: string | undefined;
|
|
66
66
|
vendor?: string | undefined;
|
|
67
67
|
persistentId?: string | undefined;
|
|
68
68
|
protocolVersion?: string | undefined;
|
|
@@ -84,17 +84,17 @@ export declare const HandshakeRequestSchema: z.ZodObject<{
|
|
|
84
84
|
clientId: z.ZodOptional<z.ZodString>;
|
|
85
85
|
}, "strip", z.ZodTypeAny, {
|
|
86
86
|
name: string;
|
|
87
|
-
title?: string | undefined;
|
|
88
87
|
version?: string | undefined;
|
|
89
88
|
platform?: string | undefined;
|
|
89
|
+
title?: string | undefined;
|
|
90
90
|
vendor?: string | undefined;
|
|
91
91
|
persistentId?: string | undefined;
|
|
92
92
|
clientId?: string | undefined;
|
|
93
93
|
}, {
|
|
94
94
|
name: string;
|
|
95
|
-
title?: string | undefined;
|
|
96
95
|
version?: string | undefined;
|
|
97
96
|
platform?: string | undefined;
|
|
97
|
+
title?: string | undefined;
|
|
98
98
|
vendor?: string | undefined;
|
|
99
99
|
persistentId?: string | undefined;
|
|
100
100
|
clientId?: string | undefined;
|
|
@@ -102,15 +102,15 @@ export declare const HandshakeRequestSchema: z.ZodObject<{
|
|
|
102
102
|
clientProtocolVersion: z.ZodOptional<z.ZodString>;
|
|
103
103
|
clientCapabilities: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
104
104
|
}, "strip", z.ZodTypeAny, {
|
|
105
|
+
timestamp: number;
|
|
105
106
|
nonce: string;
|
|
106
107
|
audience: string;
|
|
107
|
-
timestamp: number;
|
|
108
108
|
agentDid?: string | undefined;
|
|
109
109
|
clientInfo?: {
|
|
110
110
|
name: string;
|
|
111
|
-
title?: string | undefined;
|
|
112
111
|
version?: string | undefined;
|
|
113
112
|
platform?: string | undefined;
|
|
113
|
+
title?: string | undefined;
|
|
114
114
|
vendor?: string | undefined;
|
|
115
115
|
persistentId?: string | undefined;
|
|
116
116
|
clientId?: string | undefined;
|
|
@@ -118,15 +118,15 @@ export declare const HandshakeRequestSchema: z.ZodObject<{
|
|
|
118
118
|
clientProtocolVersion?: string | undefined;
|
|
119
119
|
clientCapabilities?: Record<string, unknown> | undefined;
|
|
120
120
|
}, {
|
|
121
|
+
timestamp: number;
|
|
121
122
|
nonce: string;
|
|
122
123
|
audience: string;
|
|
123
|
-
timestamp: number;
|
|
124
124
|
agentDid?: string | undefined;
|
|
125
125
|
clientInfo?: {
|
|
126
126
|
name: string;
|
|
127
|
-
title?: string | undefined;
|
|
128
127
|
version?: string | undefined;
|
|
129
128
|
platform?: string | undefined;
|
|
129
|
+
title?: string | undefined;
|
|
130
130
|
vendor?: string | undefined;
|
|
131
131
|
persistentId?: string | undefined;
|
|
132
132
|
clientId?: string | undefined;
|
|
@@ -160,9 +160,9 @@ export declare const SessionContextSchema: z.ZodObject<{
|
|
|
160
160
|
}, "strip", z.ZodTypeAny, {
|
|
161
161
|
name: string;
|
|
162
162
|
clientId: string;
|
|
163
|
-
title?: string | undefined;
|
|
164
163
|
version?: string | undefined;
|
|
165
164
|
platform?: string | undefined;
|
|
165
|
+
title?: string | undefined;
|
|
166
166
|
vendor?: string | undefined;
|
|
167
167
|
persistentId?: string | undefined;
|
|
168
168
|
protocolVersion?: string | undefined;
|
|
@@ -170,9 +170,9 @@ export declare const SessionContextSchema: z.ZodObject<{
|
|
|
170
170
|
}, {
|
|
171
171
|
name: string;
|
|
172
172
|
clientId: string;
|
|
173
|
-
title?: string | undefined;
|
|
174
173
|
version?: string | undefined;
|
|
175
174
|
platform?: string | undefined;
|
|
175
|
+
title?: string | undefined;
|
|
176
176
|
vendor?: string | undefined;
|
|
177
177
|
persistentId?: string | undefined;
|
|
178
178
|
protocolVersion?: string | undefined;
|
|
@@ -204,27 +204,27 @@ export declare const SessionContextSchema: z.ZodObject<{
|
|
|
204
204
|
name?: string | undefined;
|
|
205
205
|
}>>;
|
|
206
206
|
}, "strip", z.ZodTypeAny, {
|
|
207
|
+
ttlMinutes: number;
|
|
208
|
+
timestamp: number;
|
|
207
209
|
nonce: string;
|
|
208
210
|
audience: string;
|
|
209
|
-
timestamp: number;
|
|
210
211
|
sessionId: string;
|
|
211
212
|
createdAt: number;
|
|
212
213
|
lastActivity: number;
|
|
213
|
-
ttlMinutes: number;
|
|
214
214
|
identityState: "anonymous" | "authenticated";
|
|
215
215
|
agentDid?: string | undefined;
|
|
216
|
+
serverDid?: string | undefined;
|
|
216
217
|
clientInfo?: {
|
|
217
218
|
name: string;
|
|
218
219
|
clientId: string;
|
|
219
|
-
title?: string | undefined;
|
|
220
220
|
version?: string | undefined;
|
|
221
221
|
platform?: string | undefined;
|
|
222
|
+
title?: string | undefined;
|
|
222
223
|
vendor?: string | undefined;
|
|
223
224
|
persistentId?: string | undefined;
|
|
224
225
|
protocolVersion?: string | undefined;
|
|
225
226
|
capabilities?: Record<string, unknown> | undefined;
|
|
226
227
|
} | undefined;
|
|
227
|
-
serverDid?: string | undefined;
|
|
228
228
|
clientDid?: string | undefined;
|
|
229
229
|
userDid?: string | undefined;
|
|
230
230
|
oauthIdentity?: {
|
|
@@ -234,26 +234,26 @@ export declare const SessionContextSchema: z.ZodObject<{
|
|
|
234
234
|
name?: string | undefined;
|
|
235
235
|
} | undefined;
|
|
236
236
|
}, {
|
|
237
|
+
timestamp: number;
|
|
237
238
|
nonce: string;
|
|
238
239
|
audience: string;
|
|
239
|
-
timestamp: number;
|
|
240
240
|
sessionId: string;
|
|
241
241
|
createdAt: number;
|
|
242
242
|
lastActivity: number;
|
|
243
243
|
agentDid?: string | undefined;
|
|
244
|
+
serverDid?: string | undefined;
|
|
245
|
+
ttlMinutes?: number | undefined;
|
|
244
246
|
clientInfo?: {
|
|
245
247
|
name: string;
|
|
246
248
|
clientId: string;
|
|
247
|
-
title?: string | undefined;
|
|
248
249
|
version?: string | undefined;
|
|
249
250
|
platform?: string | undefined;
|
|
251
|
+
title?: string | undefined;
|
|
250
252
|
vendor?: string | undefined;
|
|
251
253
|
persistentId?: string | undefined;
|
|
252
254
|
protocolVersion?: string | undefined;
|
|
253
255
|
capabilities?: Record<string, unknown> | undefined;
|
|
254
256
|
} | undefined;
|
|
255
|
-
ttlMinutes?: number | undefined;
|
|
256
|
-
serverDid?: string | undefined;
|
|
257
257
|
clientDid?: string | undefined;
|
|
258
258
|
userDid?: string | undefined;
|
|
259
259
|
identityState?: "anonymous" | "authenticated" | undefined;
|
|
@@ -346,7 +346,7 @@ export declare const NonceCacheConfigSchema: z.ZodObject<{
|
|
|
346
346
|
keyPrefix?: string | undefined;
|
|
347
347
|
}>>;
|
|
348
348
|
}, "strip", z.ZodTypeAny, {
|
|
349
|
-
type?: "
|
|
349
|
+
type?: "cloudflare-kv" | "memory" | "redis" | "dynamodb" | undefined;
|
|
350
350
|
redis?: {
|
|
351
351
|
url: string;
|
|
352
352
|
keyPrefix: string;
|
|
@@ -362,7 +362,7 @@ export declare const NonceCacheConfigSchema: z.ZodObject<{
|
|
|
362
362
|
namespace: string;
|
|
363
363
|
} | undefined;
|
|
364
364
|
}, {
|
|
365
|
-
type?: "
|
|
365
|
+
type?: "cloudflare-kv" | "memory" | "redis" | "dynamodb" | undefined;
|
|
366
366
|
redis?: {
|
|
367
367
|
url: string;
|
|
368
368
|
keyPrefix?: string | undefined;
|
|
@@ -1,28 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* MCP-I Tool Protection Specification
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Core types for tool protection with delegation requirements.
|
|
5
|
+
*
|
|
6
|
+
* Consent Flow: type='none' → 2 screens, others → 3 screens (Auth→Consent→Success).
|
|
7
|
+
* DelegationCredential (VC) is created when user confirms on Consent Screen.
|
|
7
8
|
*
|
|
8
9
|
* @module @kya-os/contracts/tool-protection
|
|
9
10
|
*/
|
|
10
11
|
import { z } from 'zod';
|
|
11
12
|
/**
|
|
12
|
-
* Authorization Requirement
|
|
13
|
-
*
|
|
14
|
-
* Defines the type of authorization required for a tool.
|
|
15
|
-
* Extensible design to support OAuth, password auth, MDL, IDV, verifiable credentials, etc.
|
|
16
|
-
*
|
|
17
|
-
* ## Type Naming Clarification
|
|
13
|
+
* Authorization Requirement - what auth is needed BEFORE consent screen.
|
|
18
14
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* - `verifiable_credential` - W3C Verifiable Credential requirement (preferred)
|
|
22
|
-
* - `credential` - **DEPRECATED** alias for `verifiable_credential` (for backward compatibility)
|
|
23
|
-
* - `mdl` - Mobile Driver's License (ISO 18013-5)
|
|
24
|
-
* - `idv` - Identity Verification provider (Stripe, Onfido, etc.)
|
|
25
|
-
* - `none` - Consent-only (clickwrap agreement, no authentication)
|
|
15
|
+
* Types: none (2 screens), oauth/password/mdl/idv (3 screens), verifiable_credential (future).
|
|
16
|
+
* The VC output is always a DelegationCredential created on consent confirmation.
|
|
26
17
|
*/
|
|
27
18
|
export type AuthorizationRequirement = {
|
|
28
19
|
type: 'oauth';
|
|
@@ -40,12 +31,14 @@ export type AuthorizationRequirement = {
|
|
|
40
31
|
provider: string;
|
|
41
32
|
verificationLevel?: 'basic' | 'enhanced' | 'loa3';
|
|
42
33
|
} | {
|
|
34
|
+
/** Require user to present an existing VC */
|
|
43
35
|
type: 'verifiable_credential';
|
|
44
36
|
credentialType: string;
|
|
45
37
|
issuer?: string;
|
|
46
38
|
} | {
|
|
47
39
|
/**
|
|
48
|
-
* @deprecated Use
|
|
40
|
+
* @deprecated Use 'verifiable_credential' instead. Will be removed in v2.0.0.
|
|
41
|
+
* This is an alias for 'verifiable_credential' for backward compatibility.
|
|
49
42
|
*/
|
|
50
43
|
type: 'credential';
|
|
51
44
|
credentialType: string;
|
|
@@ -53,24 +46,13 @@ export type AuthorizationRequirement = {
|
|
|
53
46
|
} | {
|
|
54
47
|
type: 'none';
|
|
55
48
|
};
|
|
56
|
-
/**
|
|
57
|
-
* Canonical authorization type values
|
|
58
|
-
* Use these constants instead of string literals for type safety
|
|
59
|
-
*/
|
|
49
|
+
/** Canonical authorization type values for type safety */
|
|
60
50
|
export declare const AUTHORIZATION_TYPES: {
|
|
61
|
-
/** OAuth 2.0 provider authentication */
|
|
62
51
|
readonly OAUTH: "oauth";
|
|
63
|
-
/** Username/password or API key authentication */
|
|
64
52
|
readonly PASSWORD: "password";
|
|
65
|
-
/** Mobile Driver's License (ISO 18013-5) */
|
|
66
53
|
readonly MDL: "mdl";
|
|
67
|
-
/** Identity Verification provider */
|
|
68
54
|
readonly IDV: "idv";
|
|
69
|
-
/** W3C Verifiable Credential requirement (preferred) */
|
|
70
55
|
readonly VERIFIABLE_CREDENTIAL: "verifiable_credential";
|
|
71
|
-
/** @deprecated Use VERIFIABLE_CREDENTIAL instead */
|
|
72
|
-
readonly CREDENTIAL: "credential";
|
|
73
|
-
/** Consent-only (clickwrap agreement) */
|
|
74
56
|
readonly NONE: "none";
|
|
75
57
|
};
|
|
76
58
|
export type AuthorizationType = (typeof AUTHORIZATION_TYPES)[keyof typeof AUTHORIZATION_TYPES];
|
|
@@ -852,7 +834,8 @@ export declare function hasPasswordAuthorization(protection: ToolProtection): pr
|
|
|
852
834
|
};
|
|
853
835
|
/**
|
|
854
836
|
* Type guard to check if a ToolProtection requires a Verifiable Credential
|
|
855
|
-
*
|
|
837
|
+
*
|
|
838
|
+
* Note: Also returns true for deprecated 'credential' type (normalized to verifiable_credential)
|
|
856
839
|
*/
|
|
857
840
|
export declare function hasVerifiableCredentialAuthorization(protection: ToolProtection): protection is ToolProtection & {
|
|
858
841
|
authorization: {
|
|
@@ -899,20 +882,7 @@ export declare function createDelegationRequiredError(toolName: string, required
|
|
|
899
882
|
* // TODO: Remove normalizeToolProtection() when all tools migrated (target: Phase 3)
|
|
900
883
|
*/
|
|
901
884
|
export declare function normalizeToolProtection(raw: ToolProtection | PartialToolProtection): ToolProtection;
|
|
902
|
-
/**
|
|
903
|
-
* Consent Provider Types
|
|
904
|
-
*
|
|
905
|
-
* These constants define the authentication method used during consent:
|
|
906
|
-
* - NONE: Consent-only mode (clickwrap) - user agrees without authentication
|
|
907
|
-
* - OAUTH2: OAuth provider authentication (GitHub, Google, etc.)
|
|
908
|
-
* - PASSWORD: Password-based authentication (email/password, username/password)
|
|
909
|
-
* - CREDENTIAL: Alias for PASSWORD (legacy compatibility)
|
|
910
|
-
* - MAGIC_LINK: Email magic link authentication
|
|
911
|
-
* - OTP: One-time password authentication
|
|
912
|
-
*
|
|
913
|
-
* NOTE: This is distinct from AUTHORIZATION_TYPES which define what a TOOL requires.
|
|
914
|
-
* CONSENT_PROVIDER_TYPES define what authentication method the USER used.
|
|
915
|
-
*/
|
|
885
|
+
/** Consent provider types - stored in delegation metadata to track auth method used */
|
|
916
886
|
export declare const CONSENT_PROVIDER_TYPES: {
|
|
917
887
|
/** Consent-only mode - no authentication, just clickwrap agreement */
|
|
918
888
|
readonly NONE: "none";
|
|
@@ -940,16 +910,6 @@ export type ConsentProviderType = (typeof CONSENT_PROVIDER_TYPES)[keyof typeof C
|
|
|
940
910
|
* @returns The consent provider type
|
|
941
911
|
*/
|
|
942
912
|
export declare function determineConsentProviderType(hasOAuthIdentity: boolean, isPasswordFlow?: boolean, isMagicLinkFlow?: boolean, isOtpFlow?: boolean): ConsentProviderType;
|
|
943
|
-
/**
|
|
944
|
-
* Normalize authorization requirement to use canonical type names
|
|
945
|
-
*
|
|
946
|
-
* Migrates legacy 'credential' type to 'verifiable_credential'
|
|
947
|
-
* This ensures consistent type usage across the codebase.
|
|
948
|
-
*
|
|
949
|
-
* @param auth - The authorization requirement (may have legacy type)
|
|
950
|
-
* @returns Normalized authorization requirement with canonical type
|
|
951
|
-
*/
|
|
952
|
-
export declare function normalizeAuthorizationType(auth: AuthorizationRequirement): AuthorizationRequirement;
|
|
953
913
|
/**
|
|
954
914
|
* Get a human-readable label for an authorization requirement type
|
|
955
915
|
*/
|
|
@@ -958,3 +918,28 @@ export declare function getAuthorizationTypeLabel(auth: AuthorizationRequirement
|
|
|
958
918
|
* Get a unique key for an authorization requirement (for React keys, caching, etc.)
|
|
959
919
|
*/
|
|
960
920
|
export declare function getAuthorizationTypeKey(auth: AuthorizationRequirement): string;
|
|
921
|
+
/**
|
|
922
|
+
* Normalize authorization requirement type
|
|
923
|
+
*
|
|
924
|
+
* Normalizes deprecated 'credential' type to 'verifiable_credential' and emits
|
|
925
|
+
* deprecation warnings. This function should be called at runtime boundaries
|
|
926
|
+
* when processing authorization requirements.
|
|
927
|
+
*
|
|
928
|
+
* @param auth - Authorization requirement (may contain deprecated 'credential' type)
|
|
929
|
+
* @param options - Normalization options
|
|
930
|
+
* @returns Normalized authorization requirement
|
|
931
|
+
*
|
|
932
|
+
* @example
|
|
933
|
+
* ```typescript
|
|
934
|
+
* const normalized = normalizeAuthorizationType(
|
|
935
|
+
* { type: 'credential', credentialType: 'delegation' },
|
|
936
|
+
* { warn: true }
|
|
937
|
+
* );
|
|
938
|
+
* // Returns: { type: 'verifiable_credential', credentialType: 'delegation' }
|
|
939
|
+
* // Logs: DEPRECATION warning
|
|
940
|
+
* ```
|
|
941
|
+
*/
|
|
942
|
+
export declare function normalizeAuthorizationType(auth: AuthorizationRequirement, options?: {
|
|
943
|
+
warn?: boolean;
|
|
944
|
+
logger?: (message: string) => void;
|
|
945
|
+
}): AuthorizationRequirement;
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* MCP-I Tool Protection Specification
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* Core types for tool protection with delegation requirements.
|
|
6
|
+
*
|
|
7
|
+
* Consent Flow: type='none' → 2 screens, others → 3 screens (Auth→Consent→Success).
|
|
8
|
+
* DelegationCredential (VC) is created when user confirms on Consent Screen.
|
|
8
9
|
*
|
|
9
10
|
* @module @kya-os/contracts/tool-protection
|
|
10
11
|
*/
|
|
@@ -28,28 +29,17 @@ exports.getToolRiskLevel = getToolRiskLevel;
|
|
|
28
29
|
exports.createDelegationRequiredError = createDelegationRequiredError;
|
|
29
30
|
exports.normalizeToolProtection = normalizeToolProtection;
|
|
30
31
|
exports.determineConsentProviderType = determineConsentProviderType;
|
|
31
|
-
exports.normalizeAuthorizationType = normalizeAuthorizationType;
|
|
32
32
|
exports.getAuthorizationTypeLabel = getAuthorizationTypeLabel;
|
|
33
33
|
exports.getAuthorizationTypeKey = getAuthorizationTypeKey;
|
|
34
|
+
exports.normalizeAuthorizationType = normalizeAuthorizationType;
|
|
34
35
|
const zod_1 = require("zod");
|
|
35
|
-
/**
|
|
36
|
-
* Canonical authorization type values
|
|
37
|
-
* Use these constants instead of string literals for type safety
|
|
38
|
-
*/
|
|
36
|
+
/** Canonical authorization type values for type safety */
|
|
39
37
|
exports.AUTHORIZATION_TYPES = {
|
|
40
|
-
/** OAuth 2.0 provider authentication */
|
|
41
38
|
OAUTH: 'oauth',
|
|
42
|
-
/** Username/password or API key authentication */
|
|
43
39
|
PASSWORD: 'password',
|
|
44
|
-
/** Mobile Driver's License (ISO 18013-5) */
|
|
45
40
|
MDL: 'mdl',
|
|
46
|
-
/** Identity Verification provider */
|
|
47
41
|
IDV: 'idv',
|
|
48
|
-
/** W3C Verifiable Credential requirement (preferred) */
|
|
49
42
|
VERIFIABLE_CREDENTIAL: 'verifiable_credential',
|
|
50
|
-
/** @deprecated Use VERIFIABLE_CREDENTIAL instead */
|
|
51
|
-
CREDENTIAL: 'credential',
|
|
52
|
-
/** Consent-only (clickwrap agreement) */
|
|
53
43
|
NONE: 'none',
|
|
54
44
|
};
|
|
55
45
|
/**
|
|
@@ -80,7 +70,8 @@ exports.AuthorizationRequirementSchema = zod_1.z.discriminatedUnion('type', [
|
|
|
80
70
|
credentialType: zod_1.z.string(),
|
|
81
71
|
issuer: zod_1.z.string().optional(),
|
|
82
72
|
}),
|
|
83
|
-
//
|
|
73
|
+
// Deprecated: 'credential' is an alias for 'verifiable_credential'
|
|
74
|
+
// Will be removed in v2.0.0. Use 'verifiable_credential' instead.
|
|
84
75
|
zod_1.z.object({
|
|
85
76
|
type: zod_1.z.literal('credential'),
|
|
86
77
|
credentialType: zod_1.z.string(),
|
|
@@ -148,11 +139,12 @@ function hasPasswordAuthorization(protection) {
|
|
|
148
139
|
}
|
|
149
140
|
/**
|
|
150
141
|
* Type guard to check if a ToolProtection requires a Verifiable Credential
|
|
151
|
-
*
|
|
142
|
+
*
|
|
143
|
+
* Note: Also returns true for deprecated 'credential' type (normalized to verifiable_credential)
|
|
152
144
|
*/
|
|
153
145
|
function hasVerifiableCredentialAuthorization(protection) {
|
|
154
|
-
|
|
155
|
-
|
|
146
|
+
return (protection.authorization?.type === 'verifiable_credential' ||
|
|
147
|
+
protection.authorization?.type === 'credential');
|
|
156
148
|
}
|
|
157
149
|
/**
|
|
158
150
|
* Validation Functions
|
|
@@ -249,22 +241,9 @@ function normalizeToolProtection(raw) {
|
|
|
249
241
|
return normalized;
|
|
250
242
|
}
|
|
251
243
|
// =============================================================================
|
|
252
|
-
// CONSENT PROVIDER TYPES
|
|
244
|
+
// CONSENT PROVIDER TYPES - Records what auth method was USED (not required)
|
|
253
245
|
// =============================================================================
|
|
254
|
-
/**
|
|
255
|
-
* Consent Provider Types
|
|
256
|
-
*
|
|
257
|
-
* These constants define the authentication method used during consent:
|
|
258
|
-
* - NONE: Consent-only mode (clickwrap) - user agrees without authentication
|
|
259
|
-
* - OAUTH2: OAuth provider authentication (GitHub, Google, etc.)
|
|
260
|
-
* - PASSWORD: Password-based authentication (email/password, username/password)
|
|
261
|
-
* - CREDENTIAL: Alias for PASSWORD (legacy compatibility)
|
|
262
|
-
* - MAGIC_LINK: Email magic link authentication
|
|
263
|
-
* - OTP: One-time password authentication
|
|
264
|
-
*
|
|
265
|
-
* NOTE: This is distinct from AUTHORIZATION_TYPES which define what a TOOL requires.
|
|
266
|
-
* CONSENT_PROVIDER_TYPES define what authentication method the USER used.
|
|
267
|
-
*/
|
|
246
|
+
/** Consent provider types - stored in delegation metadata to track auth method used */
|
|
268
247
|
exports.CONSENT_PROVIDER_TYPES = {
|
|
269
248
|
/** Consent-only mode - no authentication, just clickwrap agreement */
|
|
270
249
|
NONE: 'none',
|
|
@@ -305,29 +284,6 @@ function determineConsentProviderType(hasOAuthIdentity, isPasswordFlow = false,
|
|
|
305
284
|
}
|
|
306
285
|
return exports.CONSENT_PROVIDER_TYPES.NONE;
|
|
307
286
|
}
|
|
308
|
-
// =============================================================================
|
|
309
|
-
// AUTHORIZATION TYPE NORMALIZATION
|
|
310
|
-
// =============================================================================
|
|
311
|
-
/**
|
|
312
|
-
* Normalize authorization requirement to use canonical type names
|
|
313
|
-
*
|
|
314
|
-
* Migrates legacy 'credential' type to 'verifiable_credential'
|
|
315
|
-
* This ensures consistent type usage across the codebase.
|
|
316
|
-
*
|
|
317
|
-
* @param auth - The authorization requirement (may have legacy type)
|
|
318
|
-
* @returns Normalized authorization requirement with canonical type
|
|
319
|
-
*/
|
|
320
|
-
function normalizeAuthorizationType(auth) {
|
|
321
|
-
// Migrate legacy 'credential' to 'verifiable_credential'
|
|
322
|
-
if (auth.type === 'credential') {
|
|
323
|
-
return {
|
|
324
|
-
type: 'verifiable_credential',
|
|
325
|
-
credentialType: auth.credentialType,
|
|
326
|
-
issuer: auth.issuer,
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
return auth;
|
|
330
|
-
}
|
|
331
287
|
/**
|
|
332
288
|
* Get a human-readable label for an authorization requirement type
|
|
333
289
|
*/
|
|
@@ -344,7 +300,9 @@ function getAuthorizationTypeLabel(auth) {
|
|
|
344
300
|
case 'idv':
|
|
345
301
|
return 'Identity Verification';
|
|
346
302
|
case 'verifiable_credential':
|
|
303
|
+
return auth.credentialType || 'Verifiable Credential';
|
|
347
304
|
case 'credential':
|
|
305
|
+
// Deprecated: treat as verifiable_credential
|
|
348
306
|
return auth.credentialType || 'Verifiable Credential';
|
|
349
307
|
case 'none':
|
|
350
308
|
return 'Consent Only';
|
|
@@ -368,7 +326,9 @@ function getAuthorizationTypeKey(auth) {
|
|
|
368
326
|
case 'idv':
|
|
369
327
|
return `idv:${auth.provider}:${auth.verificationLevel || ''}`;
|
|
370
328
|
case 'verifiable_credential':
|
|
329
|
+
return `vc:${auth.issuer || 'any'}:${auth.credentialType}`;
|
|
371
330
|
case 'credential':
|
|
331
|
+
// Deprecated: treat as verifiable_credential
|
|
372
332
|
return `vc:${auth.issuer || 'any'}:${auth.credentialType}`;
|
|
373
333
|
case 'none':
|
|
374
334
|
return 'none';
|
|
@@ -378,3 +338,43 @@ function getAuthorizationTypeKey(auth) {
|
|
|
378
338
|
return 'unknown';
|
|
379
339
|
}
|
|
380
340
|
}
|
|
341
|
+
/**
|
|
342
|
+
* Normalize authorization requirement type
|
|
343
|
+
*
|
|
344
|
+
* Normalizes deprecated 'credential' type to 'verifiable_credential' and emits
|
|
345
|
+
* deprecation warnings. This function should be called at runtime boundaries
|
|
346
|
+
* when processing authorization requirements.
|
|
347
|
+
*
|
|
348
|
+
* @param auth - Authorization requirement (may contain deprecated 'credential' type)
|
|
349
|
+
* @param options - Normalization options
|
|
350
|
+
* @returns Normalized authorization requirement
|
|
351
|
+
*
|
|
352
|
+
* @example
|
|
353
|
+
* ```typescript
|
|
354
|
+
* const normalized = normalizeAuthorizationType(
|
|
355
|
+
* { type: 'credential', credentialType: 'delegation' },
|
|
356
|
+
* { warn: true }
|
|
357
|
+
* );
|
|
358
|
+
* // Returns: { type: 'verifiable_credential', credentialType: 'delegation' }
|
|
359
|
+
* // Logs: DEPRECATION warning
|
|
360
|
+
* ```
|
|
361
|
+
*/
|
|
362
|
+
function normalizeAuthorizationType(auth, options = {}) {
|
|
363
|
+
const { warn = true, logger = console.warn } = options;
|
|
364
|
+
if (auth.type === 'credential') {
|
|
365
|
+
if (warn) {
|
|
366
|
+
logger(`DEPRECATION: Authorization type 'credential' is deprecated and will be removed in v2.0.0. ` +
|
|
367
|
+
`Please update to 'verifiable_credential'. ` +
|
|
368
|
+
`See https://github.com/modelcontextprotocol-identity/xmcp-i/blob/main/docs/migrations/credential-to-verifiable_credential.md`);
|
|
369
|
+
}
|
|
370
|
+
// Normalize to verifiable_credential
|
|
371
|
+
const normalized = {
|
|
372
|
+
type: 'verifiable_credential',
|
|
373
|
+
credentialType: auth.credentialType,
|
|
374
|
+
...(auth.issuer !== undefined && { issuer: auth.issuer }),
|
|
375
|
+
};
|
|
376
|
+
return normalized;
|
|
377
|
+
}
|
|
378
|
+
// No normalization needed
|
|
379
|
+
return auth;
|
|
380
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kya-os/contracts",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.6",
|
|
4
4
|
"description": "Shared contracts, types, and schemas for MCP-I framework",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -95,7 +95,7 @@
|
|
|
95
95
|
},
|
|
96
96
|
"sideEffects": false,
|
|
97
97
|
"dependencies": {
|
|
98
|
-
"@kya-os/consent": "^0.1.
|
|
98
|
+
"@kya-os/consent": "^0.1.5",
|
|
99
99
|
"zod": "^3.25.76"
|
|
100
100
|
},
|
|
101
101
|
"devDependencies": {
|