@kya-os/contracts 1.5.3-canary.16 → 1.5.3-canary.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +17 -0
- package/.turbo/turbo-test$colon$coverage.log +85 -0
- package/.turbo/turbo-test.log +32 -0
- package/coverage/coverage-final.json +38 -0
- package/dist/consent/schemas.d.ts +18 -0
- package/dist/consent/schemas.js +10 -0
- package/dist/dashboard-config/schemas.d.ts +1424 -220
- package/dist/tool-protection/index.d.ts +418 -8
- package/dist/tool-protection/index.js +61 -2
- package/package.json +35 -129
- package/schemas/cli/register-output/v1.0.0.json +69 -0
- package/schemas/identity/v1.0.0.json +46 -0
- package/schemas/proof/v1.0.0.json +80 -0
- package/schemas/registry/receipt-v1.0.0.json +60 -0
- package/schemas/verifier/verify-page/v1.0.0.json +94 -0
- package/schemas/well-known/agent/v1.0.0.json +67 -0
- package/schemas/well-known/did/v1.0.0.json +174 -0
- package/scripts/emit-schemas.js +11 -0
- package/src/agentshield-api/admin-schemas.ts +31 -0
- package/src/agentshield-api/admin-types.ts +47 -0
- package/src/agentshield-api/endpoints.ts +60 -0
- package/src/agentshield-api/index.ts +70 -0
- package/src/agentshield-api/schemas.ts +304 -0
- package/src/agentshield-api/types.ts +317 -0
- package/src/audit/index.ts +128 -0
- package/src/cli.ts +156 -0
- package/src/config/base.ts +107 -0
- package/src/config/builder.ts +97 -0
- package/src/config/delegation.ts +232 -0
- package/src/config/identity.ts +252 -0
- package/src/config/index.ts +78 -0
- package/src/config/proofing.ts +138 -0
- package/src/config/tool-context.ts +41 -0
- package/src/config/tool-protection.ts +174 -0
- package/src/consent/index.ts +32 -0
- package/src/consent/schemas.ts +334 -0
- package/src/consent/types.ts +199 -0
- package/src/dashboard-config/default-config.json +86 -0
- package/src/dashboard-config/default-config.ts +266 -0
- package/src/dashboard-config/index.ts +48 -0
- package/src/dashboard-config/schemas.ts +286 -0
- package/src/dashboard-config/types.ts +404 -0
- package/src/delegation/constraints.ts +267 -0
- package/src/delegation/index.ts +8 -0
- package/src/delegation/schemas.ts +595 -0
- package/src/did/index.ts +9 -0
- package/src/did/resolve-contract.ts +255 -0
- package/src/did/schemas.ts +190 -0
- package/src/did/types.ts +224 -0
- package/src/env/constants.ts +70 -0
- package/src/env/index.ts +5 -0
- package/src/handshake.ts +125 -0
- package/src/index.ts +45 -0
- package/src/proof/index.ts +31 -0
- package/src/proof/proof-record.ts +163 -0
- package/src/proof/signing-spec.ts +146 -0
- package/src/proof.ts +99 -0
- package/src/registry.ts +146 -0
- package/src/runtime/errors.ts +153 -0
- package/src/runtime/headers.ts +136 -0
- package/src/runtime/index.ts +6 -0
- package/src/test.ts +143 -0
- package/src/tlkrc/index.ts +5 -0
- package/src/tlkrc/rotation.ts +153 -0
- package/src/tool-protection/index.ts +343 -0
- package/src/utils/validation.ts +93 -0
- package/src/vc/index.ts +8 -0
- package/src/vc/schemas.ts +277 -0
- package/src/vc/statuslist.ts +279 -0
- package/src/verifier.ts +92 -0
- package/src/well-known/index.ts +237 -0
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CRISP Delegation Constraints
|
|
3
|
+
*
|
|
4
|
+
* Types and schemas for CRISP (Constrained Resource Intent Specification Protocol)
|
|
5
|
+
* constraints on delegations. CRISP enables fine-grained authorization control.
|
|
6
|
+
*
|
|
7
|
+
* Related Spec: MCP-I §4.2
|
|
8
|
+
* Python Reference: Delegation-Documentation.md
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { z } from 'zod';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Currency types for CRISP budgets
|
|
15
|
+
*/
|
|
16
|
+
export const CurrencySchema = z.enum(['USD', 'ops', 'points']);
|
|
17
|
+
export type Currency = z.infer<typeof CurrencySchema>;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Window kind for budget enforcement
|
|
21
|
+
*/
|
|
22
|
+
export const WindowKindSchema = z.enum(['rolling', 'fixed']);
|
|
23
|
+
export type WindowKind = z.infer<typeof WindowKindSchema>;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Budget Window Schema
|
|
27
|
+
*
|
|
28
|
+
* Defines the time window for budget enforcement
|
|
29
|
+
*/
|
|
30
|
+
export const BudgetWindowSchema = z.object({
|
|
31
|
+
/** Type of window (rolling or fixed) */
|
|
32
|
+
kind: WindowKindSchema,
|
|
33
|
+
|
|
34
|
+
/** Duration in seconds */
|
|
35
|
+
durationSec: z.number().int().positive(),
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
export type BudgetWindow = z.infer<typeof BudgetWindowSchema>;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* CRISP Budget Schema
|
|
42
|
+
*
|
|
43
|
+
* Defines spending/usage limits for a delegation
|
|
44
|
+
*/
|
|
45
|
+
export const CrispBudgetSchema = z.object({
|
|
46
|
+
/** Unit of the budget */
|
|
47
|
+
unit: CurrencySchema,
|
|
48
|
+
|
|
49
|
+
/** Cap/limit for the budget */
|
|
50
|
+
cap: z.number().nonnegative(),
|
|
51
|
+
|
|
52
|
+
/** Optional time window for the budget */
|
|
53
|
+
window: BudgetWindowSchema.optional(),
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
export type CrispBudget = z.infer<typeof CrispBudgetSchema>;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Scope matcher types
|
|
60
|
+
*/
|
|
61
|
+
export const ScopeMatcherSchema = z.enum(['exact', 'prefix', 'regex']);
|
|
62
|
+
export type ScopeMatcher = z.infer<typeof ScopeMatcherSchema>;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* CRISP Scope Schema
|
|
66
|
+
*
|
|
67
|
+
* Defines what resources/actions are allowed in a delegation
|
|
68
|
+
*/
|
|
69
|
+
export const CrispScopeSchema = z.object({
|
|
70
|
+
/** Resource identifier (e.g., "api:users", "data:emails") */
|
|
71
|
+
resource: z.string().min(1),
|
|
72
|
+
|
|
73
|
+
/** How to match the resource */
|
|
74
|
+
matcher: ScopeMatcherSchema,
|
|
75
|
+
|
|
76
|
+
/** Optional additional constraints on this scope */
|
|
77
|
+
constraints: z.record(z.any()).optional(),
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
export type CrispScope = z.infer<typeof CrispScopeSchema>;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Delegation Constraints Schema (CRISP)
|
|
84
|
+
*
|
|
85
|
+
* Complete constraint specification for a delegation
|
|
86
|
+
*/
|
|
87
|
+
export const DelegationConstraintsSchema = z.object({
|
|
88
|
+
/** Not valid before (Unix timestamp in seconds) */
|
|
89
|
+
notBefore: z.number().int().optional(),
|
|
90
|
+
|
|
91
|
+
/** Not valid after (Unix timestamp in seconds) */
|
|
92
|
+
notAfter: z.number().int().optional(),
|
|
93
|
+
|
|
94
|
+
/** Simple scopes array (for Phase 1 bouncer - simplified model) */
|
|
95
|
+
scopes: z.array(z.string()).optional(),
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Optional target server DID(s) for this delegation
|
|
99
|
+
* If omitted, delegation is valid on any server accepting the scopes
|
|
100
|
+
* If specified, delegation is only valid on the specified server(s)
|
|
101
|
+
*/
|
|
102
|
+
audience: z.union([
|
|
103
|
+
z.string().startsWith("did:"),
|
|
104
|
+
z.array(z.string().startsWith("did:"))
|
|
105
|
+
]).optional(),
|
|
106
|
+
|
|
107
|
+
/** CRISP-specific constraints (full model) */
|
|
108
|
+
crisp: z.object({
|
|
109
|
+
/** Optional budget constraint */
|
|
110
|
+
budget: CrispBudgetSchema.optional(),
|
|
111
|
+
|
|
112
|
+
/** Required: at least one scope */
|
|
113
|
+
scopes: z.array(CrispScopeSchema).min(1),
|
|
114
|
+
|
|
115
|
+
/** Optional additional CRISP fields */
|
|
116
|
+
}).passthrough().optional(),
|
|
117
|
+
}).passthrough(); // Allow extensibility
|
|
118
|
+
|
|
119
|
+
export type DelegationConstraints = z.infer<typeof DelegationConstraintsSchema>;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Validation Helpers
|
|
123
|
+
*/
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Validate delegation constraints
|
|
127
|
+
*
|
|
128
|
+
* @param constraints - The constraints to validate
|
|
129
|
+
* @returns Validation result
|
|
130
|
+
*/
|
|
131
|
+
export function validateDelegationConstraints(constraints: unknown) {
|
|
132
|
+
return DelegationConstraintsSchema.safeParse(constraints);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Check if constraints have a valid time range
|
|
137
|
+
*
|
|
138
|
+
* @param constraints - The constraints to check
|
|
139
|
+
* @returns true if time range is valid or no time range specified
|
|
140
|
+
*/
|
|
141
|
+
export function hasValidTimeRange(constraints: DelegationConstraints): boolean {
|
|
142
|
+
if (constraints.notBefore === undefined && constraints.notAfter === undefined) {
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (constraints.notBefore !== undefined && constraints.notAfter !== undefined) {
|
|
147
|
+
return constraints.notBefore < constraints.notAfter;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Check if child constraints are within parent constraints
|
|
155
|
+
*
|
|
156
|
+
* This performs basic structural checks. Full chain validation
|
|
157
|
+
* requires runtime implementation.
|
|
158
|
+
*
|
|
159
|
+
* @param parent - Parent delegation constraints
|
|
160
|
+
* @param child - Child delegation constraints
|
|
161
|
+
* @returns true if child is within parent bounds
|
|
162
|
+
*/
|
|
163
|
+
export function areChildConstraintsValid(
|
|
164
|
+
parent: DelegationConstraints,
|
|
165
|
+
child: DelegationConstraints
|
|
166
|
+
): boolean {
|
|
167
|
+
// Time bounds: child must be within parent
|
|
168
|
+
if (parent.notBefore !== undefined && child.notBefore !== undefined) {
|
|
169
|
+
if (child.notBefore < parent.notBefore) {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (parent.notAfter !== undefined && child.notAfter !== undefined) {
|
|
175
|
+
if (child.notAfter > parent.notAfter) {
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Budget: child must be ≤ parent (if same unit)
|
|
181
|
+
if (
|
|
182
|
+
parent.crisp?.budget &&
|
|
183
|
+
child.crisp?.budget &&
|
|
184
|
+
parent.crisp.budget.unit === child.crisp.budget.unit
|
|
185
|
+
) {
|
|
186
|
+
if (child.crisp.budget.cap > parent.crisp.budget.cap) {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Scopes: child scopes must be subset of parent scopes
|
|
192
|
+
// This is a simplified check - full validation is complex
|
|
193
|
+
if (parent.crisp && child.crisp) {
|
|
194
|
+
const parentResources = new Set(
|
|
195
|
+
parent.crisp.scopes.map((s) => s.resource)
|
|
196
|
+
);
|
|
197
|
+
const allChildResourcesInParent = child.crisp.scopes.every((childScope) => {
|
|
198
|
+
// Check if child resource matches any parent resource
|
|
199
|
+
return parent.crisp!.scopes.some((parentScope) => {
|
|
200
|
+
if (parentScope.matcher === 'exact') {
|
|
201
|
+
return parentScope.resource === childScope.resource;
|
|
202
|
+
}
|
|
203
|
+
if (parentScope.matcher === 'prefix') {
|
|
204
|
+
return childScope.resource.startsWith(parentScope.resource);
|
|
205
|
+
}
|
|
206
|
+
// regex matching would require runtime regex evaluation
|
|
207
|
+
return true; // Can't validate regex at type level
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
return allChildResourcesInParent;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return true; // Can't validate if crisp is not present
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Check if a resource matches a scope
|
|
219
|
+
*
|
|
220
|
+
* @param resource - The resource to check
|
|
221
|
+
* @param scope - The scope to match against
|
|
222
|
+
* @returns true if resource matches scope
|
|
223
|
+
*/
|
|
224
|
+
export function doesResourceMatchScope(
|
|
225
|
+
resource: string,
|
|
226
|
+
scope: CrispScope
|
|
227
|
+
): boolean {
|
|
228
|
+
switch (scope.matcher) {
|
|
229
|
+
case 'exact':
|
|
230
|
+
return resource === scope.resource;
|
|
231
|
+
case 'prefix':
|
|
232
|
+
return resource.startsWith(scope.resource);
|
|
233
|
+
case 'regex':
|
|
234
|
+
try {
|
|
235
|
+
const regex = new RegExp(scope.resource);
|
|
236
|
+
return regex.test(resource);
|
|
237
|
+
} catch {
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
default:
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Constants
|
|
247
|
+
*/
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Supported currency types
|
|
251
|
+
*/
|
|
252
|
+
export const SUPPORTED_CURRENCIES: Currency[] = ['USD', 'ops', 'points'];
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Supported scope matchers
|
|
256
|
+
*/
|
|
257
|
+
export const SUPPORTED_MATCHERS: ScopeMatcher[] = ['exact', 'prefix', 'regex'];
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Maximum reasonable budget cap (for validation)
|
|
261
|
+
*/
|
|
262
|
+
export const MAX_BUDGET_CAP = Number.MAX_SAFE_INTEGER;
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Maximum reasonable window duration (10 years in seconds)
|
|
266
|
+
*/
|
|
267
|
+
export const MAX_WINDOW_DURATION_SEC = 10 * 365 * 24 * 60 * 60;
|