@kya-os/contracts 1.0.0-alpha → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/dist/cli.d.ts +98 -0
  2. package/dist/cli.js +73 -60
  3. package/dist/delegation/constraints.d.ts +982 -0
  4. package/dist/delegation/constraints.js +205 -0
  5. package/dist/delegation/index.d.ts +8 -0
  6. package/dist/delegation/index.js +24 -0
  7. package/dist/delegation/schemas.d.ts +3787 -0
  8. package/dist/delegation/schemas.js +230 -0
  9. package/dist/did/index.d.ts +8 -0
  10. package/dist/did/index.js +24 -0
  11. package/dist/did/resolve-contract.d.ts +220 -0
  12. package/dist/did/resolve-contract.js +32 -0
  13. package/dist/did/types.d.ts +164 -0
  14. package/dist/did/types.js +71 -0
  15. package/dist/env/constants.d.ts +58 -0
  16. package/dist/env/constants.js +60 -0
  17. package/dist/env/index.d.ts +5 -0
  18. package/dist/env/index.js +21 -0
  19. package/dist/handshake.js +35 -32
  20. package/dist/index.d.ts +10 -1
  21. package/dist/index.js +42 -9
  22. package/dist/proof/index.d.ts +9 -0
  23. package/dist/proof/index.js +25 -0
  24. package/dist/proof/proof-record.d.ts +838 -0
  25. package/dist/proof/proof-record.js +134 -0
  26. package/dist/proof/signing-spec.d.ts +147 -0
  27. package/dist/proof/signing-spec.js +123 -0
  28. package/dist/proof.js +35 -32
  29. package/dist/registry.d.ts +46 -46
  30. package/dist/registry.js +79 -76
  31. package/dist/runtime/errors.d.ts +348 -0
  32. package/dist/runtime/errors.js +120 -0
  33. package/dist/runtime/headers.d.ts +84 -0
  34. package/dist/runtime/headers.js +82 -0
  35. package/dist/runtime/index.d.ts +6 -0
  36. package/dist/runtime/index.js +22 -0
  37. package/dist/test.js +50 -45
  38. package/dist/tlkrc/index.d.ts +5 -0
  39. package/dist/tlkrc/index.js +21 -0
  40. package/dist/tlkrc/rotation.d.ts +246 -0
  41. package/dist/tlkrc/rotation.js +127 -0
  42. package/dist/utils/validation.d.ts +31 -0
  43. package/dist/utils/validation.js +70 -0
  44. package/dist/vc/index.d.ts +8 -0
  45. package/dist/vc/index.js +24 -0
  46. package/dist/vc/schemas.d.ts +2484 -0
  47. package/dist/vc/schemas.js +225 -0
  48. package/dist/vc/statuslist.d.ts +494 -0
  49. package/dist/vc/statuslist.js +133 -0
  50. package/dist/verifier.d.ts +56 -0
  51. package/dist/verifier.js +34 -29
  52. package/package.json +67 -15
  53. package/schemas/cli/register-output/v1.0.0.json +2 -2
  54. package/schemas/proof/v1.0.0.json +1 -1
  55. package/schemas/registry/receipt-v1.0.0.json +2 -2
  56. package/schemas/verifier/verify-page/v1.0.0.json +2 -2
  57. package/schemas/well-known/agent/v1.0.0.json +1 -1
  58. package/dist/cli.d.ts.map +0 -1
  59. package/dist/cli.js.map +0 -1
  60. package/dist/handshake.d.ts.map +0 -1
  61. package/dist/handshake.js.map +0 -1
  62. package/dist/index.d.ts.map +0 -1
  63. package/dist/index.js.map +0 -1
  64. package/dist/proof.d.ts.map +0 -1
  65. package/dist/proof.js.map +0 -1
  66. package/dist/registry.d.ts.map +0 -1
  67. package/dist/registry.js.map +0 -1
  68. package/dist/test.d.ts.map +0 -1
  69. package/dist/test.js.map +0 -1
  70. package/dist/verifier.d.ts.map +0 -1
  71. package/dist/verifier.js.map +0 -1
@@ -0,0 +1,205 @@
1
+ "use strict";
2
+ /**
3
+ * CRISP Delegation Constraints
4
+ *
5
+ * Types and schemas for CRISP (Constrained Resource Intent Specification Protocol)
6
+ * constraints on delegations. CRISP enables fine-grained authorization control.
7
+ *
8
+ * Related Spec: MCP-I §4.2
9
+ * Python Reference: Delegation-Documentation.md
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.MAX_WINDOW_DURATION_SEC = exports.MAX_BUDGET_CAP = exports.SUPPORTED_MATCHERS = exports.SUPPORTED_CURRENCIES = exports.DelegationConstraintsSchema = exports.CrispScopeSchema = exports.ScopeMatcherSchema = exports.CrispBudgetSchema = exports.BudgetWindowSchema = exports.WindowKindSchema = exports.CurrencySchema = void 0;
13
+ exports.validateDelegationConstraints = validateDelegationConstraints;
14
+ exports.hasValidTimeRange = hasValidTimeRange;
15
+ exports.areChildConstraintsValid = areChildConstraintsValid;
16
+ exports.doesResourceMatchScope = doesResourceMatchScope;
17
+ const zod_1 = require("zod");
18
+ /**
19
+ * Currency types for CRISP budgets
20
+ */
21
+ exports.CurrencySchema = zod_1.z.enum(['USD', 'ops', 'points']);
22
+ /**
23
+ * Window kind for budget enforcement
24
+ */
25
+ exports.WindowKindSchema = zod_1.z.enum(['rolling', 'fixed']);
26
+ /**
27
+ * Budget Window Schema
28
+ *
29
+ * Defines the time window for budget enforcement
30
+ */
31
+ exports.BudgetWindowSchema = zod_1.z.object({
32
+ /** Type of window (rolling or fixed) */
33
+ kind: exports.WindowKindSchema,
34
+ /** Duration in seconds */
35
+ durationSec: zod_1.z.number().int().positive(),
36
+ });
37
+ /**
38
+ * CRISP Budget Schema
39
+ *
40
+ * Defines spending/usage limits for a delegation
41
+ */
42
+ exports.CrispBudgetSchema = zod_1.z.object({
43
+ /** Unit of the budget */
44
+ unit: exports.CurrencySchema,
45
+ /** Cap/limit for the budget */
46
+ cap: zod_1.z.number().nonnegative(),
47
+ /** Optional time window for the budget */
48
+ window: exports.BudgetWindowSchema.optional(),
49
+ });
50
+ /**
51
+ * Scope matcher types
52
+ */
53
+ exports.ScopeMatcherSchema = zod_1.z.enum(['exact', 'prefix', 'regex']);
54
+ /**
55
+ * CRISP Scope Schema
56
+ *
57
+ * Defines what resources/actions are allowed in a delegation
58
+ */
59
+ exports.CrispScopeSchema = zod_1.z.object({
60
+ /** Resource identifier (e.g., "api:users", "data:emails") */
61
+ resource: zod_1.z.string().min(1),
62
+ /** How to match the resource */
63
+ matcher: exports.ScopeMatcherSchema,
64
+ /** Optional additional constraints on this scope */
65
+ constraints: zod_1.z.record(zod_1.z.any()).optional(),
66
+ });
67
+ /**
68
+ * Delegation Constraints Schema (CRISP)
69
+ *
70
+ * Complete constraint specification for a delegation
71
+ */
72
+ exports.DelegationConstraintsSchema = zod_1.z.object({
73
+ /** Not valid before (Unix timestamp in seconds) */
74
+ notBefore: zod_1.z.number().int().optional(),
75
+ /** Not valid after (Unix timestamp in seconds) */
76
+ notAfter: zod_1.z.number().int().optional(),
77
+ /** CRISP-specific constraints */
78
+ crisp: zod_1.z.object({
79
+ /** Optional budget constraint */
80
+ budget: exports.CrispBudgetSchema.optional(),
81
+ /** Required: at least one scope */
82
+ scopes: zod_1.z.array(exports.CrispScopeSchema).min(1),
83
+ /** Optional additional CRISP fields */
84
+ }).passthrough(),
85
+ }).passthrough(); // Allow extensibility
86
+ /**
87
+ * Validation Helpers
88
+ */
89
+ /**
90
+ * Validate delegation constraints
91
+ *
92
+ * @param constraints - The constraints to validate
93
+ * @returns Validation result
94
+ */
95
+ function validateDelegationConstraints(constraints) {
96
+ return exports.DelegationConstraintsSchema.safeParse(constraints);
97
+ }
98
+ /**
99
+ * Check if constraints have a valid time range
100
+ *
101
+ * @param constraints - The constraints to check
102
+ * @returns true if time range is valid or no time range specified
103
+ */
104
+ function hasValidTimeRange(constraints) {
105
+ if (constraints.notBefore === undefined && constraints.notAfter === undefined) {
106
+ return true;
107
+ }
108
+ if (constraints.notBefore !== undefined && constraints.notAfter !== undefined) {
109
+ return constraints.notBefore < constraints.notAfter;
110
+ }
111
+ return true;
112
+ }
113
+ /**
114
+ * Check if child constraints are within parent constraints
115
+ *
116
+ * This performs basic structural checks. Full chain validation
117
+ * requires runtime implementation.
118
+ *
119
+ * @param parent - Parent delegation constraints
120
+ * @param child - Child delegation constraints
121
+ * @returns true if child is within parent bounds
122
+ */
123
+ function areChildConstraintsValid(parent, child) {
124
+ // Time bounds: child must be within parent
125
+ if (parent.notBefore !== undefined && child.notBefore !== undefined) {
126
+ if (child.notBefore < parent.notBefore) {
127
+ return false;
128
+ }
129
+ }
130
+ if (parent.notAfter !== undefined && child.notAfter !== undefined) {
131
+ if (child.notAfter > parent.notAfter) {
132
+ return false;
133
+ }
134
+ }
135
+ // Budget: child must be ≤ parent (if same unit)
136
+ if (parent.crisp.budget &&
137
+ child.crisp.budget &&
138
+ parent.crisp.budget.unit === child.crisp.budget.unit) {
139
+ if (child.crisp.budget.cap > parent.crisp.budget.cap) {
140
+ return false;
141
+ }
142
+ }
143
+ // Scopes: child scopes must be subset of parent scopes
144
+ // This is a simplified check - full validation is complex
145
+ const parentResources = new Set(parent.crisp.scopes.map((s) => s.resource));
146
+ const allChildResourcesInParent = child.crisp.scopes.every((childScope) => {
147
+ // Check if child resource matches any parent resource
148
+ return parent.crisp.scopes.some((parentScope) => {
149
+ if (parentScope.matcher === 'exact') {
150
+ return parentScope.resource === childScope.resource;
151
+ }
152
+ if (parentScope.matcher === 'prefix') {
153
+ return childScope.resource.startsWith(parentScope.resource);
154
+ }
155
+ // regex matching would require runtime regex evaluation
156
+ return true; // Can't validate regex at type level
157
+ });
158
+ });
159
+ return allChildResourcesInParent;
160
+ }
161
+ /**
162
+ * Check if a resource matches a scope
163
+ *
164
+ * @param resource - The resource to check
165
+ * @param scope - The scope to match against
166
+ * @returns true if resource matches scope
167
+ */
168
+ function doesResourceMatchScope(resource, scope) {
169
+ switch (scope.matcher) {
170
+ case 'exact':
171
+ return resource === scope.resource;
172
+ case 'prefix':
173
+ return resource.startsWith(scope.resource);
174
+ case 'regex':
175
+ try {
176
+ const regex = new RegExp(scope.resource);
177
+ return regex.test(resource);
178
+ }
179
+ catch {
180
+ return false;
181
+ }
182
+ default:
183
+ return false;
184
+ }
185
+ }
186
+ /**
187
+ * Constants
188
+ */
189
+ /**
190
+ * Supported currency types
191
+ */
192
+ exports.SUPPORTED_CURRENCIES = ['USD', 'ops', 'points'];
193
+ /**
194
+ * Supported scope matchers
195
+ */
196
+ exports.SUPPORTED_MATCHERS = ['exact', 'prefix', 'regex'];
197
+ /**
198
+ * Maximum reasonable budget cap (for validation)
199
+ */
200
+ exports.MAX_BUDGET_CAP = Number.MAX_SAFE_INTEGER;
201
+ /**
202
+ * Maximum reasonable window duration (10 years in seconds)
203
+ */
204
+ exports.MAX_WINDOW_DURATION_SEC = 10 * 365 * 24 * 60 * 60;
205
+ //# sourceMappingURL=constraints.js.map
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Delegation Module Exports
3
+ *
4
+ * Types and schemas for delegation records and CRISP constraints
5
+ */
6
+ export * from './schemas.js';
7
+ export * from './constraints.js';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ /**
3
+ * Delegation Module Exports
4
+ *
5
+ * Types and schemas for delegation records and CRISP constraints
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("./constraints.js"), exports);
24
+ //# sourceMappingURL=index.js.map