@kya-os/contracts 1.3.4 → 1.4.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/dist/agentshield-api/endpoints.d.ts +50 -0
- package/dist/agentshield-api/endpoints.js +46 -0
- package/dist/agentshield-api/index.d.ts +13 -0
- package/dist/agentshield-api/index.js +38 -0
- package/dist/agentshield-api/schemas.d.ts +9914 -0
- package/dist/agentshield-api/schemas.js +165 -0
- package/dist/agentshield-api/types.d.ts +168 -0
- package/dist/agentshield-api/types.js +27 -0
- package/dist/cli.d.ts +388 -0
- package/dist/cli.js +121 -0
- package/dist/config/base.d.ts +96 -0
- package/dist/config/base.js +11 -0
- package/dist/config/delegation.d.ts +194 -0
- package/dist/config/delegation.js +10 -0
- package/dist/config/identity.d.ts +117 -0
- package/dist/config/identity.js +11 -0
- package/dist/config/index.d.ts +33 -0
- package/dist/config/index.js +11 -0
- package/dist/config/proofing.d.ts +120 -0
- package/dist/config/proofing.js +10 -0
- package/dist/config/tool-protection.d.ts +139 -0
- package/dist/config/tool-protection.js +10 -0
- package/dist/dashboard-config/index.d.ts +10 -0
- package/dist/dashboard-config/index.js +31 -0
- package/dist/dashboard-config/schemas.d.ts +5847 -0
- package/dist/dashboard-config/schemas.js +251 -0
- package/dist/dashboard-config/types.d.ts +331 -0
- package/dist/dashboard-config/types.js +11 -0
- package/dist/delegation/constraints.d.ts +991 -0
- package/dist/delegation/constraints.js +209 -0
- package/dist/delegation/index.d.ts +7 -0
- package/dist/delegation/index.js +23 -0
- package/dist/delegation/schemas.d.ts +8381 -0
- package/dist/delegation/schemas.js +475 -0
- package/dist/did/index.d.ts +8 -0
- package/dist/did/index.js +24 -0
- package/dist/did/resolve-contract.d.ts +219 -0
- package/dist/did/resolve-contract.js +31 -0
- package/dist/did/schemas.d.ts +112 -0
- package/dist/did/schemas.js +172 -0
- package/dist/did/types.d.ts +163 -0
- package/dist/did/types.js +70 -0
- package/dist/env/constants.d.ts +57 -0
- package/dist/env/constants.js +59 -0
- package/dist/env/index.d.ts +4 -0
- package/dist/env/index.js +20 -0
- package/dist/handshake.d.ts +158 -0
- package/dist/handshake.js +57 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +56 -0
- package/dist/proof/index.d.ts +8 -0
- package/dist/proof/index.js +24 -0
- package/dist/proof/proof-record.d.ts +837 -0
- package/dist/proof/proof-record.js +133 -0
- package/dist/proof/signing-spec.d.ts +146 -0
- package/dist/proof/signing-spec.js +122 -0
- package/dist/proof.d.ts +415 -0
- package/dist/proof.js +83 -0
- package/dist/registry.d.ts +342 -0
- package/dist/registry.js +118 -0
- package/dist/runtime/errors.d.ts +347 -0
- package/dist/runtime/errors.js +119 -0
- package/dist/runtime/headers.d.ts +83 -0
- package/dist/runtime/headers.js +81 -0
- package/dist/runtime/index.d.ts +5 -0
- package/dist/runtime/index.js +21 -0
- package/dist/test.d.ts +251 -0
- package/dist/test.js +119 -0
- package/dist/tlkrc/index.d.ts +4 -0
- package/dist/tlkrc/index.js +20 -0
- package/dist/tlkrc/rotation.d.ts +245 -0
- package/dist/tlkrc/rotation.js +126 -0
- package/dist/tool-protection/index.d.ts +227 -0
- package/dist/tool-protection/index.js +113 -0
- package/dist/utils/validation.d.ts +30 -0
- package/dist/utils/validation.js +69 -0
- package/dist/vc/index.d.ts +7 -0
- package/dist/vc/index.js +23 -0
- package/dist/vc/schemas.d.ts +2483 -0
- package/dist/vc/schemas.js +224 -0
- package/dist/vc/statuslist.d.ts +493 -0
- package/dist/vc/statuslist.js +132 -0
- package/dist/verifier.d.ts +205 -0
- package/dist/verifier.js +83 -0
- package/dist/well-known/index.d.ts +308 -0
- package/dist/well-known/index.js +134 -0
- package/package.json +6 -1
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* TLKRC (Transparent Log Key Rotation Contract)
|
|
4
|
+
*
|
|
5
|
+
* Types for key rotation events in a transparent, auditable manner
|
|
6
|
+
*
|
|
7
|
+
* Related Spec: MCP-I Core
|
|
8
|
+
* Python Reference: Core-Documentation.md
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.MAX_GRACE_PERIOD_SEC = exports.DEFAULT_GRACE_PERIOD_SEC = exports.RotationChainSchema = exports.RotationEventSchema = void 0;
|
|
12
|
+
exports.validateRotationEvent = validateRotationEvent;
|
|
13
|
+
exports.isRotationChainValid = isRotationChainValid;
|
|
14
|
+
exports.getActiveKeyAt = getActiveKeyAt;
|
|
15
|
+
const zod_1 = require("zod");
|
|
16
|
+
/**
|
|
17
|
+
* Rotation Event Schema
|
|
18
|
+
*
|
|
19
|
+
* Represents a key rotation event in a transparent log.
|
|
20
|
+
* Events form a hash-linked chain for auditability.
|
|
21
|
+
*
|
|
22
|
+
* **Dual-Key Grace Window:**
|
|
23
|
+
* During rotation, both `prevKeyId` and `nextKeyId` are valid
|
|
24
|
+
* from `effectiveAt` until `effectiveAt + grace period`.
|
|
25
|
+
*/
|
|
26
|
+
exports.RotationEventSchema = zod_1.z.object({
|
|
27
|
+
/** DID of the issuer performing the rotation */
|
|
28
|
+
issuerDid: zod_1.z.string().min(1),
|
|
29
|
+
/** Previous key ID being rotated out */
|
|
30
|
+
prevKeyId: zod_1.z.string().min(1),
|
|
31
|
+
/** New key ID being rotated in */
|
|
32
|
+
nextKeyId: zod_1.z.string().min(1),
|
|
33
|
+
/** Timestamp when new key becomes effective (Unix seconds) */
|
|
34
|
+
effectiveAt: zod_1.z.number().int().positive(),
|
|
35
|
+
/** Timestamp when event was issued (Unix seconds) */
|
|
36
|
+
issuedAt: zod_1.z.number().int().positive(),
|
|
37
|
+
/** Sequence number (monotonically increasing) */
|
|
38
|
+
seq: zod_1.z.number().int().nonnegative(),
|
|
39
|
+
/** Hash of previous rotation event (null for first rotation) */
|
|
40
|
+
prevEventHash: zod_1.z.string().optional(),
|
|
41
|
+
/** Signature over the event (using prevKeyId) */
|
|
42
|
+
signature: zod_1.z.string().min(1),
|
|
43
|
+
/** Optional metadata */
|
|
44
|
+
metadata: zod_1.z.record(zod_1.z.any()).optional(),
|
|
45
|
+
}).refine((event) => event.effectiveAt >= event.issuedAt, {
|
|
46
|
+
message: 'effectiveAt must be >= issuedAt',
|
|
47
|
+
});
|
|
48
|
+
/**
|
|
49
|
+
* Rotation Chain
|
|
50
|
+
*
|
|
51
|
+
* Represents a chain of rotation events
|
|
52
|
+
*/
|
|
53
|
+
exports.RotationChainSchema = zod_1.z.object({
|
|
54
|
+
/** Issuer DID */
|
|
55
|
+
issuerDid: zod_1.z.string().min(1),
|
|
56
|
+
/** All rotation events in order */
|
|
57
|
+
events: zod_1.z.array(exports.RotationEventSchema).min(1),
|
|
58
|
+
/** Current active key ID */
|
|
59
|
+
currentKeyId: zod_1.z.string().min(1),
|
|
60
|
+
/** Whether chain is valid */
|
|
61
|
+
valid: zod_1.z.boolean(),
|
|
62
|
+
/** Optional validation errors */
|
|
63
|
+
errors: zod_1.z.array(zod_1.z.string()).optional(),
|
|
64
|
+
});
|
|
65
|
+
/**
|
|
66
|
+
* Validation Helpers
|
|
67
|
+
*/
|
|
68
|
+
/**
|
|
69
|
+
* Validate a rotation event
|
|
70
|
+
*
|
|
71
|
+
* @param event - The event to validate
|
|
72
|
+
* @returns Validation result
|
|
73
|
+
*/
|
|
74
|
+
function validateRotationEvent(event) {
|
|
75
|
+
return exports.RotationEventSchema.safeParse(event);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Validate rotation chain integrity
|
|
79
|
+
*
|
|
80
|
+
* @param chain - The chain to validate
|
|
81
|
+
* @returns true if chain is valid
|
|
82
|
+
*/
|
|
83
|
+
function isRotationChainValid(chain) {
|
|
84
|
+
if (chain.events.length === 0) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
// Check sequence numbers are monotonic
|
|
88
|
+
for (let i = 1; i < chain.events.length; i++) {
|
|
89
|
+
if (chain.events[i].seq <= chain.events[i - 1].seq) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return chain.valid;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Get active key at a specific timestamp
|
|
97
|
+
*
|
|
98
|
+
* @param chain - The rotation chain
|
|
99
|
+
* @param timestamp - Timestamp in seconds
|
|
100
|
+
* @returns Active key ID at that time, or null if none
|
|
101
|
+
*/
|
|
102
|
+
function getActiveKeyAt(chain, timestamp) {
|
|
103
|
+
if (chain.events.length === 0) {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
// Find the most recent event that's effective at the timestamp
|
|
107
|
+
for (let i = chain.events.length - 1; i >= 0; i--) {
|
|
108
|
+
const event = chain.events[i];
|
|
109
|
+
if (event.effectiveAt <= timestamp) {
|
|
110
|
+
return event.nextKeyId;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// If no event is effective yet, use the initial key
|
|
114
|
+
return chain.events[0].prevKeyId;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Constants
|
|
118
|
+
*/
|
|
119
|
+
/**
|
|
120
|
+
* Default grace period for dual-key validity (24 hours)
|
|
121
|
+
*/
|
|
122
|
+
exports.DEFAULT_GRACE_PERIOD_SEC = 24 * 60 * 60;
|
|
123
|
+
/**
|
|
124
|
+
* Maximum reasonable grace period (30 days)
|
|
125
|
+
*/
|
|
126
|
+
exports.MAX_GRACE_PERIOD_SEC = 30 * 24 * 60 * 60;
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP-I Tool Protection Specification
|
|
3
|
+
*
|
|
4
|
+
* This module defines the core tool protection types as specified in the
|
|
5
|
+
* MCP-I protocol. These are pure specification types that define how tools
|
|
6
|
+
* can be protected with delegation requirements and scopes.
|
|
7
|
+
*
|
|
8
|
+
* @module @kya-os/contracts/tool-protection
|
|
9
|
+
*/
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
/**
|
|
12
|
+
* Tool Protection Definition
|
|
13
|
+
*
|
|
14
|
+
* Defines the protection requirements for a tool as per MCP-I spec.
|
|
15
|
+
* This is the canonical definition that all implementations must follow.
|
|
16
|
+
*/
|
|
17
|
+
export interface ToolProtection {
|
|
18
|
+
/**
|
|
19
|
+
* Whether this tool requires explicit delegation from the user
|
|
20
|
+
*/
|
|
21
|
+
requiresDelegation: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* The scopes required to execute this tool
|
|
24
|
+
* Format: "resource:action" (e.g., "files:read", "payment:send")
|
|
25
|
+
*/
|
|
26
|
+
requiredScopes: string[];
|
|
27
|
+
/**
|
|
28
|
+
* Risk level classification for the tool
|
|
29
|
+
* Used to determine appropriate authorization flows
|
|
30
|
+
*/
|
|
31
|
+
riskLevel?: 'low' | 'medium' | 'high' | 'critical';
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Tool Protection Map
|
|
35
|
+
*
|
|
36
|
+
* A mapping of tool names to their protection configurations.
|
|
37
|
+
* This is how tool protections are typically stored and transmitted.
|
|
38
|
+
*/
|
|
39
|
+
export type ToolProtectionMap = Record<string, ToolProtection>;
|
|
40
|
+
/**
|
|
41
|
+
* Tool Protection Response
|
|
42
|
+
*
|
|
43
|
+
* The response format when querying for tool protections.
|
|
44
|
+
* Used by tool protection services and APIs.
|
|
45
|
+
*/
|
|
46
|
+
export interface ToolProtectionResponse {
|
|
47
|
+
/**
|
|
48
|
+
* The tool protections keyed by tool name
|
|
49
|
+
*/
|
|
50
|
+
toolProtections: ToolProtectionMap;
|
|
51
|
+
/**
|
|
52
|
+
* Optional metadata about the response
|
|
53
|
+
*/
|
|
54
|
+
metadata?: {
|
|
55
|
+
/**
|
|
56
|
+
* When this configuration was last updated
|
|
57
|
+
*/
|
|
58
|
+
lastUpdated?: string;
|
|
59
|
+
/**
|
|
60
|
+
* Version of the configuration
|
|
61
|
+
*/
|
|
62
|
+
version?: string;
|
|
63
|
+
/**
|
|
64
|
+
* Source of the configuration
|
|
65
|
+
*/
|
|
66
|
+
source?: string;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Delegation Required Error Data
|
|
71
|
+
*
|
|
72
|
+
* The standardized error data returned when a tool requires delegation
|
|
73
|
+
* but none was provided. This is part of the MCP-I error protocol.
|
|
74
|
+
*/
|
|
75
|
+
export interface DelegationRequiredErrorData {
|
|
76
|
+
/**
|
|
77
|
+
* The name of the tool that requires delegation
|
|
78
|
+
*/
|
|
79
|
+
toolName: string;
|
|
80
|
+
/**
|
|
81
|
+
* The scopes required for this tool
|
|
82
|
+
*/
|
|
83
|
+
requiredScopes: string[];
|
|
84
|
+
/**
|
|
85
|
+
* URL where the user can provide consent/delegation
|
|
86
|
+
*/
|
|
87
|
+
consentUrl?: string;
|
|
88
|
+
/**
|
|
89
|
+
* Alternative field for consent URL (for compatibility)
|
|
90
|
+
*/
|
|
91
|
+
authorizationUrl?: string;
|
|
92
|
+
/**
|
|
93
|
+
* Additional context about why delegation is required
|
|
94
|
+
*/
|
|
95
|
+
reason?: string;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Zod Schemas for Validation
|
|
99
|
+
*/
|
|
100
|
+
export declare const ToolProtectionSchema: z.ZodObject<{
|
|
101
|
+
requiresDelegation: z.ZodBoolean;
|
|
102
|
+
requiredScopes: z.ZodArray<z.ZodString, "many">;
|
|
103
|
+
riskLevel: z.ZodOptional<z.ZodEnum<["low", "medium", "high", "critical"]>>;
|
|
104
|
+
}, "strip", z.ZodTypeAny, {
|
|
105
|
+
requiresDelegation: boolean;
|
|
106
|
+
requiredScopes: string[];
|
|
107
|
+
riskLevel?: "low" | "medium" | "high" | "critical" | undefined;
|
|
108
|
+
}, {
|
|
109
|
+
requiresDelegation: boolean;
|
|
110
|
+
requiredScopes: string[];
|
|
111
|
+
riskLevel?: "low" | "medium" | "high" | "critical" | undefined;
|
|
112
|
+
}>;
|
|
113
|
+
export declare const ToolProtectionMapSchema: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
114
|
+
requiresDelegation: z.ZodBoolean;
|
|
115
|
+
requiredScopes: z.ZodArray<z.ZodString, "many">;
|
|
116
|
+
riskLevel: z.ZodOptional<z.ZodEnum<["low", "medium", "high", "critical"]>>;
|
|
117
|
+
}, "strip", z.ZodTypeAny, {
|
|
118
|
+
requiresDelegation: boolean;
|
|
119
|
+
requiredScopes: string[];
|
|
120
|
+
riskLevel?: "low" | "medium" | "high" | "critical" | undefined;
|
|
121
|
+
}, {
|
|
122
|
+
requiresDelegation: boolean;
|
|
123
|
+
requiredScopes: string[];
|
|
124
|
+
riskLevel?: "low" | "medium" | "high" | "critical" | undefined;
|
|
125
|
+
}>>;
|
|
126
|
+
export declare const ToolProtectionResponseSchema: z.ZodObject<{
|
|
127
|
+
toolProtections: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
128
|
+
requiresDelegation: z.ZodBoolean;
|
|
129
|
+
requiredScopes: z.ZodArray<z.ZodString, "many">;
|
|
130
|
+
riskLevel: z.ZodOptional<z.ZodEnum<["low", "medium", "high", "critical"]>>;
|
|
131
|
+
}, "strip", z.ZodTypeAny, {
|
|
132
|
+
requiresDelegation: boolean;
|
|
133
|
+
requiredScopes: string[];
|
|
134
|
+
riskLevel?: "low" | "medium" | "high" | "critical" | undefined;
|
|
135
|
+
}, {
|
|
136
|
+
requiresDelegation: boolean;
|
|
137
|
+
requiredScopes: string[];
|
|
138
|
+
riskLevel?: "low" | "medium" | "high" | "critical" | undefined;
|
|
139
|
+
}>>;
|
|
140
|
+
metadata: z.ZodOptional<z.ZodObject<{
|
|
141
|
+
lastUpdated: z.ZodOptional<z.ZodString>;
|
|
142
|
+
version: z.ZodOptional<z.ZodString>;
|
|
143
|
+
source: z.ZodOptional<z.ZodString>;
|
|
144
|
+
}, "strip", z.ZodTypeAny, {
|
|
145
|
+
version?: string | undefined;
|
|
146
|
+
lastUpdated?: string | undefined;
|
|
147
|
+
source?: string | undefined;
|
|
148
|
+
}, {
|
|
149
|
+
version?: string | undefined;
|
|
150
|
+
lastUpdated?: string | undefined;
|
|
151
|
+
source?: string | undefined;
|
|
152
|
+
}>>;
|
|
153
|
+
}, "strip", z.ZodTypeAny, {
|
|
154
|
+
toolProtections: Record<string, {
|
|
155
|
+
requiresDelegation: boolean;
|
|
156
|
+
requiredScopes: string[];
|
|
157
|
+
riskLevel?: "low" | "medium" | "high" | "critical" | undefined;
|
|
158
|
+
}>;
|
|
159
|
+
metadata?: {
|
|
160
|
+
version?: string | undefined;
|
|
161
|
+
lastUpdated?: string | undefined;
|
|
162
|
+
source?: string | undefined;
|
|
163
|
+
} | undefined;
|
|
164
|
+
}, {
|
|
165
|
+
toolProtections: Record<string, {
|
|
166
|
+
requiresDelegation: boolean;
|
|
167
|
+
requiredScopes: string[];
|
|
168
|
+
riskLevel?: "low" | "medium" | "high" | "critical" | undefined;
|
|
169
|
+
}>;
|
|
170
|
+
metadata?: {
|
|
171
|
+
version?: string | undefined;
|
|
172
|
+
lastUpdated?: string | undefined;
|
|
173
|
+
source?: string | undefined;
|
|
174
|
+
} | undefined;
|
|
175
|
+
}>;
|
|
176
|
+
export declare const DelegationRequiredErrorDataSchema: z.ZodObject<{
|
|
177
|
+
toolName: z.ZodString;
|
|
178
|
+
requiredScopes: z.ZodArray<z.ZodString, "many">;
|
|
179
|
+
consentUrl: z.ZodOptional<z.ZodString>;
|
|
180
|
+
authorizationUrl: z.ZodOptional<z.ZodString>;
|
|
181
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
182
|
+
}, "strip", z.ZodTypeAny, {
|
|
183
|
+
requiredScopes: string[];
|
|
184
|
+
toolName: string;
|
|
185
|
+
reason?: string | undefined;
|
|
186
|
+
consentUrl?: string | undefined;
|
|
187
|
+
authorizationUrl?: string | undefined;
|
|
188
|
+
}, {
|
|
189
|
+
requiredScopes: string[];
|
|
190
|
+
toolName: string;
|
|
191
|
+
reason?: string | undefined;
|
|
192
|
+
consentUrl?: string | undefined;
|
|
193
|
+
authorizationUrl?: string | undefined;
|
|
194
|
+
}>;
|
|
195
|
+
/**
|
|
196
|
+
* Type Guards
|
|
197
|
+
*/
|
|
198
|
+
export declare function isToolProtection(obj: any): obj is ToolProtection;
|
|
199
|
+
export declare function isToolProtectionMap(obj: any): obj is ToolProtectionMap;
|
|
200
|
+
export declare function isToolProtectionResponse(obj: any): obj is ToolProtectionResponse;
|
|
201
|
+
export declare function isDelegationRequiredErrorData(obj: any): obj is DelegationRequiredErrorData;
|
|
202
|
+
/**
|
|
203
|
+
* Validation Functions
|
|
204
|
+
*/
|
|
205
|
+
export declare function validateToolProtection(obj: any): ToolProtection;
|
|
206
|
+
export declare function validateToolProtectionMap(obj: any): ToolProtectionMap;
|
|
207
|
+
export declare function validateToolProtectionResponse(obj: any): ToolProtectionResponse;
|
|
208
|
+
export declare function validateDelegationRequiredErrorData(obj: any): DelegationRequiredErrorData;
|
|
209
|
+
/**
|
|
210
|
+
* Utility Functions
|
|
211
|
+
*/
|
|
212
|
+
/**
|
|
213
|
+
* Check if a tool requires delegation
|
|
214
|
+
*/
|
|
215
|
+
export declare function toolRequiresDelegation(toolName: string, protections: ToolProtectionMap): boolean;
|
|
216
|
+
/**
|
|
217
|
+
* Get required scopes for a tool
|
|
218
|
+
*/
|
|
219
|
+
export declare function getToolRequiredScopes(toolName: string, protections: ToolProtectionMap): string[];
|
|
220
|
+
/**
|
|
221
|
+
* Get risk level for a tool
|
|
222
|
+
*/
|
|
223
|
+
export declare function getToolRiskLevel(toolName: string, protections: ToolProtectionMap): ToolProtection['riskLevel'] | undefined;
|
|
224
|
+
/**
|
|
225
|
+
* Create a delegation required error
|
|
226
|
+
*/
|
|
227
|
+
export declare function createDelegationRequiredError(toolName: string, requiredScopes: string[], consentUrl?: string): DelegationRequiredErrorData;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* MCP-I Tool Protection Specification
|
|
4
|
+
*
|
|
5
|
+
* This module defines the core tool protection types as specified in the
|
|
6
|
+
* MCP-I protocol. These are pure specification types that define how tools
|
|
7
|
+
* can be protected with delegation requirements and scopes.
|
|
8
|
+
*
|
|
9
|
+
* @module @kya-os/contracts/tool-protection
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.DelegationRequiredErrorDataSchema = exports.ToolProtectionResponseSchema = exports.ToolProtectionMapSchema = exports.ToolProtectionSchema = void 0;
|
|
13
|
+
exports.isToolProtection = isToolProtection;
|
|
14
|
+
exports.isToolProtectionMap = isToolProtectionMap;
|
|
15
|
+
exports.isToolProtectionResponse = isToolProtectionResponse;
|
|
16
|
+
exports.isDelegationRequiredErrorData = isDelegationRequiredErrorData;
|
|
17
|
+
exports.validateToolProtection = validateToolProtection;
|
|
18
|
+
exports.validateToolProtectionMap = validateToolProtectionMap;
|
|
19
|
+
exports.validateToolProtectionResponse = validateToolProtectionResponse;
|
|
20
|
+
exports.validateDelegationRequiredErrorData = validateDelegationRequiredErrorData;
|
|
21
|
+
exports.toolRequiresDelegation = toolRequiresDelegation;
|
|
22
|
+
exports.getToolRequiredScopes = getToolRequiredScopes;
|
|
23
|
+
exports.getToolRiskLevel = getToolRiskLevel;
|
|
24
|
+
exports.createDelegationRequiredError = createDelegationRequiredError;
|
|
25
|
+
const zod_1 = require("zod");
|
|
26
|
+
/**
|
|
27
|
+
* Zod Schemas for Validation
|
|
28
|
+
*/
|
|
29
|
+
exports.ToolProtectionSchema = zod_1.z.object({
|
|
30
|
+
requiresDelegation: zod_1.z.boolean(),
|
|
31
|
+
requiredScopes: zod_1.z.array(zod_1.z.string()),
|
|
32
|
+
riskLevel: zod_1.z.enum(['low', 'medium', 'high', 'critical']).optional()
|
|
33
|
+
});
|
|
34
|
+
exports.ToolProtectionMapSchema = zod_1.z.record(zod_1.z.string(), exports.ToolProtectionSchema);
|
|
35
|
+
exports.ToolProtectionResponseSchema = zod_1.z.object({
|
|
36
|
+
toolProtections: exports.ToolProtectionMapSchema,
|
|
37
|
+
metadata: zod_1.z.object({
|
|
38
|
+
lastUpdated: zod_1.z.string().optional(),
|
|
39
|
+
version: zod_1.z.string().optional(),
|
|
40
|
+
source: zod_1.z.string().optional()
|
|
41
|
+
}).optional()
|
|
42
|
+
});
|
|
43
|
+
exports.DelegationRequiredErrorDataSchema = zod_1.z.object({
|
|
44
|
+
toolName: zod_1.z.string(),
|
|
45
|
+
requiredScopes: zod_1.z.array(zod_1.z.string()),
|
|
46
|
+
consentUrl: zod_1.z.string().optional(),
|
|
47
|
+
authorizationUrl: zod_1.z.string().optional(),
|
|
48
|
+
reason: zod_1.z.string().optional()
|
|
49
|
+
});
|
|
50
|
+
/**
|
|
51
|
+
* Type Guards
|
|
52
|
+
*/
|
|
53
|
+
function isToolProtection(obj) {
|
|
54
|
+
return exports.ToolProtectionSchema.safeParse(obj).success;
|
|
55
|
+
}
|
|
56
|
+
function isToolProtectionMap(obj) {
|
|
57
|
+
return exports.ToolProtectionMapSchema.safeParse(obj).success;
|
|
58
|
+
}
|
|
59
|
+
function isToolProtectionResponse(obj) {
|
|
60
|
+
return exports.ToolProtectionResponseSchema.safeParse(obj).success;
|
|
61
|
+
}
|
|
62
|
+
function isDelegationRequiredErrorData(obj) {
|
|
63
|
+
return exports.DelegationRequiredErrorDataSchema.safeParse(obj).success;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Validation Functions
|
|
67
|
+
*/
|
|
68
|
+
function validateToolProtection(obj) {
|
|
69
|
+
return exports.ToolProtectionSchema.parse(obj);
|
|
70
|
+
}
|
|
71
|
+
function validateToolProtectionMap(obj) {
|
|
72
|
+
return exports.ToolProtectionMapSchema.parse(obj);
|
|
73
|
+
}
|
|
74
|
+
function validateToolProtectionResponse(obj) {
|
|
75
|
+
return exports.ToolProtectionResponseSchema.parse(obj);
|
|
76
|
+
}
|
|
77
|
+
function validateDelegationRequiredErrorData(obj) {
|
|
78
|
+
return exports.DelegationRequiredErrorDataSchema.parse(obj);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Utility Functions
|
|
82
|
+
*/
|
|
83
|
+
/**
|
|
84
|
+
* Check if a tool requires delegation
|
|
85
|
+
*/
|
|
86
|
+
function toolRequiresDelegation(toolName, protections) {
|
|
87
|
+
const protection = protections[toolName];
|
|
88
|
+
return protection?.requiresDelegation ?? false;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Get required scopes for a tool
|
|
92
|
+
*/
|
|
93
|
+
function getToolRequiredScopes(toolName, protections) {
|
|
94
|
+
const protection = protections[toolName];
|
|
95
|
+
return protection?.requiredScopes ?? [];
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Get risk level for a tool
|
|
99
|
+
*/
|
|
100
|
+
function getToolRiskLevel(toolName, protections) {
|
|
101
|
+
return protections[toolName]?.riskLevel;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Create a delegation required error
|
|
105
|
+
*/
|
|
106
|
+
function createDelegationRequiredError(toolName, requiredScopes, consentUrl) {
|
|
107
|
+
return {
|
|
108
|
+
toolName,
|
|
109
|
+
requiredScopes,
|
|
110
|
+
consentUrl,
|
|
111
|
+
authorizationUrl: consentUrl // Include both for compatibility
|
|
112
|
+
};
|
|
113
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared validation utilities for mcpi packages
|
|
3
|
+
* Consolidates common validation patterns to follow DRY principles
|
|
4
|
+
*/
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
/**
|
|
7
|
+
* Generic validation result type
|
|
8
|
+
*/
|
|
9
|
+
export interface ValidationResult<T = any> {
|
|
10
|
+
valid: boolean;
|
|
11
|
+
data?: T;
|
|
12
|
+
errors: string[];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Generic validation function with helpful error messages
|
|
16
|
+
*/
|
|
17
|
+
export declare function validateInput<T>(schema: z.ZodSchema<T>, data: unknown, context?: string): ValidationResult<T>;
|
|
18
|
+
/**
|
|
19
|
+
* Validate object has required properties
|
|
20
|
+
*/
|
|
21
|
+
export declare function hasRequiredProperties(obj: any, properties: string[], context?: string): ValidationResult;
|
|
22
|
+
/**
|
|
23
|
+
* Validate string format patterns
|
|
24
|
+
*/
|
|
25
|
+
export declare const StringValidators: {
|
|
26
|
+
did: (value: string) => boolean;
|
|
27
|
+
kid: (value: string) => boolean;
|
|
28
|
+
url: (value: string) => boolean;
|
|
29
|
+
projectName: (value: string) => boolean;
|
|
30
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Shared validation utilities for mcpi packages
|
|
4
|
+
* Consolidates common validation patterns to follow DRY principles
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.StringValidators = void 0;
|
|
8
|
+
exports.validateInput = validateInput;
|
|
9
|
+
exports.hasRequiredProperties = hasRequiredProperties;
|
|
10
|
+
/**
|
|
11
|
+
* Generic validation function with helpful error messages
|
|
12
|
+
*/
|
|
13
|
+
function validateInput(schema, data, context) {
|
|
14
|
+
const result = schema.safeParse(data);
|
|
15
|
+
if (result.success) {
|
|
16
|
+
return {
|
|
17
|
+
valid: true,
|
|
18
|
+
data: result.data,
|
|
19
|
+
errors: [],
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
const errors = result.error.errors.map((err) => {
|
|
23
|
+
const path = err.path.length > 0 ? ` at ${err.path.join(".")}` : "";
|
|
24
|
+
const contextStr = context ? ` (${context})` : "";
|
|
25
|
+
return `${err.message}${path}${contextStr}`;
|
|
26
|
+
});
|
|
27
|
+
return {
|
|
28
|
+
valid: false,
|
|
29
|
+
errors,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Validate object has required properties
|
|
34
|
+
*/
|
|
35
|
+
function hasRequiredProperties(obj, properties, context) {
|
|
36
|
+
if (typeof obj !== "object" || obj === null) {
|
|
37
|
+
return {
|
|
38
|
+
valid: false,
|
|
39
|
+
errors: [`Expected object${context ? ` for ${context}` : ""}`],
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
const missing = properties.filter((prop) => !(prop in obj));
|
|
43
|
+
if (missing.length > 0) {
|
|
44
|
+
return {
|
|
45
|
+
valid: false,
|
|
46
|
+
errors: [
|
|
47
|
+
`Missing required properties: ${missing.join(", ")}${context ? ` in ${context}` : ""}`,
|
|
48
|
+
],
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
return { valid: true, errors: [] };
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Validate string format patterns
|
|
55
|
+
*/
|
|
56
|
+
exports.StringValidators = {
|
|
57
|
+
did: (value) => /^did:[a-z0-9]+:[a-zA-Z0-9._-]+$/.test(value),
|
|
58
|
+
kid: (value) => /^[a-zA-Z0-9._-]+$/.test(value),
|
|
59
|
+
url: (value) => {
|
|
60
|
+
try {
|
|
61
|
+
new URL(value);
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
projectName: (value) => /^[a-z0-9-]+$/.test(value) && value.length >= 1 && value.length <= 214,
|
|
69
|
+
};
|
package/dist/vc/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Verifiable Credentials Module Exports
|
|
4
|
+
*
|
|
5
|
+
* W3C Verifiable Credentials types, schemas, and utilities
|
|
6
|
+
*/
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
__exportStar(require("./schemas.js"), exports);
|
|
23
|
+
__exportStar(require("./statuslist.js"), exports);
|