@callcium/sdk 0.1.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/index.d.ts +701 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3216 -0
- package/dist/index.js.map +1 -0
- package/package.json +63 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,701 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
/** Hex-encoded byte string, 0x-prefixed. */
|
|
3
|
+
type Hex = `0x${string}`;
|
|
4
|
+
/** Ethereum address, 0x-prefixed. */
|
|
5
|
+
type Address = `0x${string}`;
|
|
6
|
+
/** Byte range in a source blob. */
|
|
7
|
+
type Span = {
|
|
8
|
+
start: number;
|
|
9
|
+
end: number;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Execution context for context-scoped rules.
|
|
13
|
+
* Each property maps to a well-known EVM execution environment value.
|
|
14
|
+
* Only the properties referenced by the policy need to be supplied.
|
|
15
|
+
*/
|
|
16
|
+
type Context = {
|
|
17
|
+
msgSender?: Address;
|
|
18
|
+
msgValue?: bigint;
|
|
19
|
+
blockTimestamp?: bigint;
|
|
20
|
+
blockNumber?: bigint;
|
|
21
|
+
chainId?: bigint;
|
|
22
|
+
txOrigin?: Address;
|
|
23
|
+
};
|
|
24
|
+
/** Result of enforcing a policy: pass with matched group index, or fail with one violation per failed group. */
|
|
25
|
+
type EnforceResult = {
|
|
26
|
+
ok: true;
|
|
27
|
+
matchedGroup: number;
|
|
28
|
+
} | {
|
|
29
|
+
ok: false;
|
|
30
|
+
violations: Violation[];
|
|
31
|
+
};
|
|
32
|
+
/** Machine-readable reason code for an enforcement violation. */
|
|
33
|
+
type ViolationCode = "VALUE_MISMATCH" | "SELECTOR_MISMATCH" | "MISSING_SELECTOR" | "CALLDATA_OUT_OF_BOUNDS" | "ARRAY_INDEX_OUT_OF_BOUNDS" | "MISSING_CONTEXT" | "QUANTIFIER_LIMIT_EXCEEDED" | "QUANTIFIER_EMPTY_ARRAY";
|
|
34
|
+
/** Details of a single rule failure during enforcement. */
|
|
35
|
+
type Violation = {
|
|
36
|
+
/** Group index that failed. Absent for pre-group failures (e.g. selector mismatch). */group?: number; /** Rule index within the group. Absent for pre-rule failures. */
|
|
37
|
+
rule?: number;
|
|
38
|
+
code: ViolationCode;
|
|
39
|
+
message: string; /** Rule path that was being evaluated when the violation occurred. */
|
|
40
|
+
path?: Hex; /** The actual value found in calldata or context, for diagnostic display. */
|
|
41
|
+
resolvedValue?: Hex;
|
|
42
|
+
};
|
|
43
|
+
/** Canonical structured representation of a policy. */
|
|
44
|
+
type PolicyData = {
|
|
45
|
+
isSelectorless: boolean;
|
|
46
|
+
selector: Hex;
|
|
47
|
+
descriptor: Hex;
|
|
48
|
+
groups: Constraint[][];
|
|
49
|
+
span?: Span;
|
|
50
|
+
};
|
|
51
|
+
/** A collection of operators targeting a specific value. */
|
|
52
|
+
type Constraint = {
|
|
53
|
+
scope: number;
|
|
54
|
+
path: Hex;
|
|
55
|
+
operators: Hex[];
|
|
56
|
+
span?: Span;
|
|
57
|
+
};
|
|
58
|
+
/** A decoded value with its byte position in the source blob. */
|
|
59
|
+
type Field<T> = {
|
|
60
|
+
value: T;
|
|
61
|
+
span: Span;
|
|
62
|
+
};
|
|
63
|
+
/** Structural representation of a decoded parameter within the descriptor. */
|
|
64
|
+
type DecodedParam = {
|
|
65
|
+
index: number;
|
|
66
|
+
typeCode: number;
|
|
67
|
+
isDynamic: boolean;
|
|
68
|
+
staticSize: number;
|
|
69
|
+
path: Hex;
|
|
70
|
+
span: Span;
|
|
71
|
+
};
|
|
72
|
+
/** Structural representation of a decoded rule with per-field spans. */
|
|
73
|
+
type DecodedRule = {
|
|
74
|
+
ruleSize: Field<number>;
|
|
75
|
+
scope: Field<number>;
|
|
76
|
+
pathDepth: Field<number>;
|
|
77
|
+
path: Field<Hex>;
|
|
78
|
+
opCode: Field<number>;
|
|
79
|
+
dataLength: Field<number>;
|
|
80
|
+
data: Field<Hex>;
|
|
81
|
+
span: Span;
|
|
82
|
+
};
|
|
83
|
+
/** Structural representation of a decoded group with metadata spans. */
|
|
84
|
+
type DecodedGroup = {
|
|
85
|
+
ruleCount: Field<number>;
|
|
86
|
+
groupSize: Field<number>;
|
|
87
|
+
rules: DecodedRule[];
|
|
88
|
+
span: Span;
|
|
89
|
+
};
|
|
90
|
+
/** Structural representation of a decoded policy with full byte-level spans. */
|
|
91
|
+
type DecodedPolicy = {
|
|
92
|
+
header: Field<number>;
|
|
93
|
+
selector: Field<Hex>;
|
|
94
|
+
descLength: Field<number>;
|
|
95
|
+
descriptor: {
|
|
96
|
+
raw: Hex;
|
|
97
|
+
header: Field<{
|
|
98
|
+
version: number;
|
|
99
|
+
paramCount: number;
|
|
100
|
+
}>;
|
|
101
|
+
params: DecodedParam[];
|
|
102
|
+
span: Span;
|
|
103
|
+
};
|
|
104
|
+
groupCount: Field<number>;
|
|
105
|
+
groups: DecodedGroup[];
|
|
106
|
+
span: Span;
|
|
107
|
+
version: number;
|
|
108
|
+
isSelectorless: boolean;
|
|
109
|
+
};
|
|
110
|
+
/** Severity of a validation issue. */
|
|
111
|
+
type IssueSeverity = "info" | "warning" | "error";
|
|
112
|
+
/** Category of a validation issue. */
|
|
113
|
+
type IssueCategory = "typeMismatch" | "contradiction" | "redundancy" | "vacuity";
|
|
114
|
+
/** A single validation issue found during policy analysis. */
|
|
115
|
+
type Issue = {
|
|
116
|
+
severity: IssueSeverity;
|
|
117
|
+
category: IssueCategory;
|
|
118
|
+
groupIndex: number;
|
|
119
|
+
constraintIndex: number;
|
|
120
|
+
code: string;
|
|
121
|
+
value1: Hex;
|
|
122
|
+
value2: Hex;
|
|
123
|
+
message: string;
|
|
124
|
+
};
|
|
125
|
+
//#endregion
|
|
126
|
+
//#region src/constraint.d.ts
|
|
127
|
+
/** Accepted scalar value types for operator arguments. */
|
|
128
|
+
type ScalarValue = bigint | number | boolean | string;
|
|
129
|
+
/**
|
|
130
|
+
* Mutable builder that accumulates operators targeting a single path.
|
|
131
|
+
* Implements the `Constraint` interface so it can be passed directly to policy builders.
|
|
132
|
+
*/
|
|
133
|
+
declare class ConstraintBuilder implements Constraint {
|
|
134
|
+
readonly scope: number;
|
|
135
|
+
readonly path: Hex;
|
|
136
|
+
readonly operators: Hex[];
|
|
137
|
+
/** @internal */
|
|
138
|
+
constructor(scope: number, path: Hex);
|
|
139
|
+
/** Push a pre-encoded operator hex string and return this for chaining. */
|
|
140
|
+
private push;
|
|
141
|
+
/** Assert the value equals `value`. */
|
|
142
|
+
eq(value: ScalarValue): this;
|
|
143
|
+
/** Assert the value does not equal `value`. */
|
|
144
|
+
neq(value: ScalarValue): this;
|
|
145
|
+
/** Assert the value is greater than `bound`. */
|
|
146
|
+
gt(bound: bigint | number): this;
|
|
147
|
+
/** Assert the value is less than `bound`. */
|
|
148
|
+
lt(bound: bigint | number): this;
|
|
149
|
+
/** Assert the value is greater than or equal to `bound`. */
|
|
150
|
+
gte(bound: bigint | number): this;
|
|
151
|
+
/** Assert the value is less than or equal to `bound`. */
|
|
152
|
+
lte(bound: bigint | number): this;
|
|
153
|
+
/**
|
|
154
|
+
* Assert the value is within [min, max] inclusive.
|
|
155
|
+
* @throws {CallciumError} If min > max.
|
|
156
|
+
*/
|
|
157
|
+
between(min: bigint | number, max: bigint | number): this;
|
|
158
|
+
/**
|
|
159
|
+
* Assert the value is a member of the set.
|
|
160
|
+
* Values are sorted and deduplicated before encoding.
|
|
161
|
+
* @throws {CallciumError} If the set is empty after deduplication.
|
|
162
|
+
*/
|
|
163
|
+
isIn(values: readonly ScalarValue[]): this;
|
|
164
|
+
/**
|
|
165
|
+
* Assert the value is not a member of the set.
|
|
166
|
+
* @throws {CallciumError} If the set is empty after deduplication.
|
|
167
|
+
*/
|
|
168
|
+
notIn(values: readonly ScalarValue[]): this;
|
|
169
|
+
/** Assert all bits in `mask` are set. */
|
|
170
|
+
bitmaskAll(mask: bigint): this;
|
|
171
|
+
/** Assert at least one bit in `mask` is set. */
|
|
172
|
+
bitmaskAny(mask: bigint): this;
|
|
173
|
+
/** Assert no bit in `mask` is set. */
|
|
174
|
+
bitmaskNone(mask: bigint): this;
|
|
175
|
+
/** Assert the runtime length equals `n`. */
|
|
176
|
+
lengthEq(n: bigint | number): this;
|
|
177
|
+
/** Assert the runtime length is greater than `n`. */
|
|
178
|
+
lengthGt(n: bigint | number): this;
|
|
179
|
+
/** Assert the runtime length is less than `n`. */
|
|
180
|
+
lengthLt(n: bigint | number): this;
|
|
181
|
+
/** Assert the runtime length is greater than or equal to `n`. */
|
|
182
|
+
lengthGte(n: bigint | number): this;
|
|
183
|
+
/** Assert the runtime length is less than or equal to `n`. */
|
|
184
|
+
lengthLte(n: bigint | number): this;
|
|
185
|
+
/**
|
|
186
|
+
* Assert the runtime length is within [min, max] inclusive.
|
|
187
|
+
* @throws {CallciumError} If min > max.
|
|
188
|
+
*/
|
|
189
|
+
lengthBetween(min: bigint | number, max: bigint | number): this;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Target a calldata argument by path.
|
|
193
|
+
* Each argument is a big-endian uint16 step; multiple steps navigate into nested types.
|
|
194
|
+
*/
|
|
195
|
+
declare function arg(p0: number): ConstraintBuilder;
|
|
196
|
+
declare function arg(p0: number, p1: number): ConstraintBuilder;
|
|
197
|
+
declare function arg(p0: number, p1: number, p2: number): ConstraintBuilder;
|
|
198
|
+
declare function arg(p0: number, p1: number, p2: number, p3: number): ConstraintBuilder;
|
|
199
|
+
/** Target the `msg.sender` context property. */
|
|
200
|
+
declare function msgSender(): ConstraintBuilder;
|
|
201
|
+
/** Target the `msg.value` context property. */
|
|
202
|
+
declare function msgValue(): ConstraintBuilder;
|
|
203
|
+
/** Target the `block.timestamp` context property. */
|
|
204
|
+
declare function blockTimestamp(): ConstraintBuilder;
|
|
205
|
+
/** Target the `block.number` context property. */
|
|
206
|
+
declare function blockNumber(): ConstraintBuilder;
|
|
207
|
+
/** Target the `block.chainid` context property. */
|
|
208
|
+
declare function chainId(): ConstraintBuilder;
|
|
209
|
+
/** Target the `tx.origin` context property. */
|
|
210
|
+
declare function txOrigin(): ConstraintBuilder;
|
|
211
|
+
//#endregion
|
|
212
|
+
//#region src/policy-builder.d.ts
|
|
213
|
+
/** Fluent builder for constructing Callcium policies. */
|
|
214
|
+
declare class PolicyBuilder {
|
|
215
|
+
private draft;
|
|
216
|
+
private constructor();
|
|
217
|
+
/**
|
|
218
|
+
* Create a builder from a function signature.
|
|
219
|
+
* @param signature - ABI function signature, e.g. `"transfer(address,uint256)"`.
|
|
220
|
+
*/
|
|
221
|
+
static create(signature: string): PolicyBuilder;
|
|
222
|
+
/**
|
|
223
|
+
* Create a selectorless builder from a raw type string.
|
|
224
|
+
* @param typesCsv - Comma-separated ABI type strings, e.g. `"address,uint256"`.
|
|
225
|
+
*/
|
|
226
|
+
static createRaw(typesCsv: string): PolicyBuilder;
|
|
227
|
+
/**
|
|
228
|
+
* Add a constraint to the current group.
|
|
229
|
+
* @param constraint - A `Constraint` object or a `ConstraintBuilder` instance.
|
|
230
|
+
*/
|
|
231
|
+
add(constraint: Constraint | ConstraintBuilder): this;
|
|
232
|
+
/** Start a new constraint group (OR branch). */
|
|
233
|
+
or(): this;
|
|
234
|
+
/**
|
|
235
|
+
* Build the policy into an encoded binary blob.
|
|
236
|
+
* @returns The policy as a 0x-prefixed hex string.
|
|
237
|
+
* @throws {CallciumError} If any group is empty or validation finds errors.
|
|
238
|
+
*/
|
|
239
|
+
build(): Hex;
|
|
240
|
+
/**
|
|
241
|
+
* Validate the policy without encoding.
|
|
242
|
+
* @returns All validation issues found.
|
|
243
|
+
*/
|
|
244
|
+
validate(): Issue[];
|
|
245
|
+
/** Throw if any group is empty. */
|
|
246
|
+
private checkGroups;
|
|
247
|
+
/** Convert the draft to a PolicyData structure. */
|
|
248
|
+
private toPolicyData;
|
|
249
|
+
}
|
|
250
|
+
//#endregion
|
|
251
|
+
//#region src/policy-coder.d.ts
|
|
252
|
+
/**
|
|
253
|
+
* Parse a BE16-encoded hex path into an array of step values.
|
|
254
|
+
* @param path - 0x-prefixed hex string containing BE16-encoded path steps.
|
|
255
|
+
* @returns Array of numeric step values.
|
|
256
|
+
*/
|
|
257
|
+
declare function parsePathSteps(path: Hex): number[];
|
|
258
|
+
/**
|
|
259
|
+
* Encode a PolicyData structure into the canonical binary format.
|
|
260
|
+
* @param data - The policy data to encode.
|
|
261
|
+
* @returns The encoded policy as a 0x-prefixed hex string.
|
|
262
|
+
*/
|
|
263
|
+
declare function encode(data: PolicyData): Hex;
|
|
264
|
+
/**
|
|
265
|
+
* Decode a binary policy blob into a PolicyData structure.
|
|
266
|
+
* @param blob - Binary policy as 0x-prefixed hex string.
|
|
267
|
+
* @returns The decoded policy data with constraints grouped by scope and path.
|
|
268
|
+
* @throws {CallciumError} If the blob is structurally malformed.
|
|
269
|
+
*/
|
|
270
|
+
declare function decode(blob: Hex): PolicyData;
|
|
271
|
+
/**
|
|
272
|
+
* Inspect a binary policy blob, returning the structural representation with full byte-level spans.
|
|
273
|
+
* @param blob - Binary policy as 0x-prefixed hex string.
|
|
274
|
+
* @returns The inspected policy with per-field spans for every structural element.
|
|
275
|
+
* @throws {CallciumError} If the blob is structurally malformed.
|
|
276
|
+
*/
|
|
277
|
+
declare function inspect$1(blob: Hex): DecodedPolicy;
|
|
278
|
+
/** Encode, decode, and inspect policies in the canonical binary format. */
|
|
279
|
+
declare const PolicyCoder: {
|
|
280
|
+
encode: typeof encode;
|
|
281
|
+
decode: typeof decode;
|
|
282
|
+
inspect: typeof inspect$1;
|
|
283
|
+
};
|
|
284
|
+
//#endregion
|
|
285
|
+
//#region src/descriptor.d.ts
|
|
286
|
+
/** Structural type information extracted from a descriptor node. */
|
|
287
|
+
type TypeInfo = {
|
|
288
|
+
typeCode: number;
|
|
289
|
+
isDynamic: boolean;
|
|
290
|
+
staticSize: number;
|
|
291
|
+
};
|
|
292
|
+
/**
|
|
293
|
+
* Return the byte length of the node at `offset`.
|
|
294
|
+
* Elementary nodes occupy exactly one byte; composite nodes encode their
|
|
295
|
+
* length in the lower 12 bits of the 24-bit meta field.
|
|
296
|
+
*/
|
|
297
|
+
declare function nodeLength(desc: Uint8Array, offset: number): number;
|
|
298
|
+
/**
|
|
299
|
+
* Return the byte offset of the `fieldIndex`-th field inside a tuple node.
|
|
300
|
+
* Starts at the first field and skips `fieldIndex` nodes using `nodeLength`.
|
|
301
|
+
*/
|
|
302
|
+
declare function tupleFieldOffset(desc: Uint8Array, tupleOffset: number, fieldIndex: number): number;
|
|
303
|
+
/** Return paramCount from header byte 1. */
|
|
304
|
+
declare function paramCount(desc: Uint8Array): number;
|
|
305
|
+
/** Return byte offset of the N-th top-level param (0-indexed). */
|
|
306
|
+
declare function paramOffset(desc: Uint8Array, index: number): number;
|
|
307
|
+
/**
|
|
308
|
+
* Inspect the type node at a given byte offset.
|
|
309
|
+
* @param desc - Raw descriptor bytes.
|
|
310
|
+
* @param offset - Byte position of the node.
|
|
311
|
+
* @returns typeCode, isDynamic, and staticSize in bytes.
|
|
312
|
+
*/
|
|
313
|
+
declare function inspect(desc: Uint8Array, offset: number): TypeInfo;
|
|
314
|
+
/**
|
|
315
|
+
* Resolve the type at a calldata path (array of step indices).
|
|
316
|
+
*
|
|
317
|
+
* The first step selects a top-level param. Each subsequent step descends
|
|
318
|
+
* into the current node: for tuples it selects a field, for arrays it
|
|
319
|
+
* advances to the element descriptor.
|
|
320
|
+
*
|
|
321
|
+
* @param desc - Raw descriptor bytes.
|
|
322
|
+
* @param steps - Path steps, length >= 1.
|
|
323
|
+
* @returns TypeInfo for the node at the resolved path.
|
|
324
|
+
* @throws {CallciumError} On empty steps, out-of-bounds param, or descent into elementary type.
|
|
325
|
+
*/
|
|
326
|
+
declare function typeAt(desc: Uint8Array, steps: number[]): TypeInfo;
|
|
327
|
+
/**
|
|
328
|
+
* Return tuple field count at a tuple node offset.
|
|
329
|
+
* @param desc - Raw descriptor bytes.
|
|
330
|
+
* @param offset - Byte position of the tuple node.
|
|
331
|
+
*/
|
|
332
|
+
declare function tupleFieldCount(desc: Uint8Array, offset: number): number;
|
|
333
|
+
/**
|
|
334
|
+
* Return static array length at a static array node offset.
|
|
335
|
+
* @param desc - Raw descriptor bytes.
|
|
336
|
+
* @param offset - Byte position of the static array node.
|
|
337
|
+
*/
|
|
338
|
+
declare function staticArrayLength(desc: Uint8Array, offset: number): number;
|
|
339
|
+
/**
|
|
340
|
+
* Return the byte offset of the array element descriptor.
|
|
341
|
+
* @param offset - Byte position of the array node (static or dynamic).
|
|
342
|
+
*/
|
|
343
|
+
declare function arrayElementOffset(offset: number): number;
|
|
344
|
+
/** Inspect and navigate raw descriptor bytes. */
|
|
345
|
+
declare const Descriptor: {
|
|
346
|
+
paramCount: typeof paramCount;
|
|
347
|
+
paramOffset: typeof paramOffset;
|
|
348
|
+
inspect: typeof inspect;
|
|
349
|
+
typeAt: typeof typeAt;
|
|
350
|
+
tupleFieldOffset: typeof tupleFieldOffset;
|
|
351
|
+
tupleFieldCount: typeof tupleFieldCount;
|
|
352
|
+
staticArrayLength: typeof staticArrayLength;
|
|
353
|
+
nodeLength: typeof nodeLength;
|
|
354
|
+
arrayElementOffset: typeof arrayElementOffset;
|
|
355
|
+
};
|
|
356
|
+
//#endregion
|
|
357
|
+
//#region src/policy-validator.d.ts
|
|
358
|
+
/**
|
|
359
|
+
* True if operator `opCode` is allowed on a target with the given type info.
|
|
360
|
+
* Tolerates the NOT flag on `opCode`.
|
|
361
|
+
*/
|
|
362
|
+
declare function isOpAllowed(opCode: number, typeInfo: TypeInfo): boolean;
|
|
363
|
+
/**
|
|
364
|
+
* Validate a policy for type mismatches, contradictions, redundancies, and vacuities.
|
|
365
|
+
* @param data - The canonical policy data to validate.
|
|
366
|
+
* @returns All validation issues found, ordered by group and constraint index.
|
|
367
|
+
*/
|
|
368
|
+
declare function validate(data: PolicyData): Issue[];
|
|
369
|
+
/** Semantic validation for policies. */
|
|
370
|
+
declare const PolicyValidator: {
|
|
371
|
+
validate: typeof validate;
|
|
372
|
+
};
|
|
373
|
+
//#endregion
|
|
374
|
+
//#region src/policy-enforcer.d.ts
|
|
375
|
+
/**
|
|
376
|
+
* Check a policy against ABI-encoded call data without throwing on violations.
|
|
377
|
+
* @param policy - Binary policy blob as 0x-prefixed hex string.
|
|
378
|
+
* @param callData - ABI-encoded call data as 0x-prefixed hex string.
|
|
379
|
+
* @param context - Optional execution context for context-scoped rules.
|
|
380
|
+
* @returns Pass with matched group index, or fail with one violation per failed group.
|
|
381
|
+
* @throws {CallciumError} If the policy blob is structurally malformed.
|
|
382
|
+
*/
|
|
383
|
+
declare function check(policy: Hex, callData: Hex, context?: Context): EnforceResult;
|
|
384
|
+
/**
|
|
385
|
+
* Enforce a policy against ABI-encoded call data, throwing on violation.
|
|
386
|
+
* @param policy - Binary policy blob as 0x-prefixed hex string.
|
|
387
|
+
* @param callData - ABI-encoded call data as 0x-prefixed hex string.
|
|
388
|
+
* @param context - Optional execution context for context-scoped rules.
|
|
389
|
+
* @throws {PolicyViolationError} If the policy rejects the call data.
|
|
390
|
+
* @throws {CallciumError} If the policy blob is structurally malformed.
|
|
391
|
+
*/
|
|
392
|
+
declare function enforce(policy: Hex, callData: Hex, context?: Context): void;
|
|
393
|
+
/** Check and enforce policies against ABI-encoded call data. */
|
|
394
|
+
declare const PolicyEnforcer: {
|
|
395
|
+
check: typeof check;
|
|
396
|
+
enforce: typeof enforce;
|
|
397
|
+
};
|
|
398
|
+
//#endregion
|
|
399
|
+
//#region src/bytes.d.ts
|
|
400
|
+
/** Convert a hex string to a byte array, stripping the 0x prefix if present. */
|
|
401
|
+
declare function hexToBytes(hex: string): Uint8Array;
|
|
402
|
+
/** Convert a byte array to a 0x-prefixed lowercase hex string. */
|
|
403
|
+
declare function bytesToHex(bytes: Uint8Array): Hex;
|
|
404
|
+
/** Validate and brand a hex string as an address. Throws if the runtime length is not exactly 20 bytes. */
|
|
405
|
+
declare function toAddress(hex: string): Address;
|
|
406
|
+
//#endregion
|
|
407
|
+
//#region src/descriptor-coder.d.ts
|
|
408
|
+
/**
|
|
409
|
+
* Encode a comma-separated list of ABI type strings into a binary descriptor.
|
|
410
|
+
*
|
|
411
|
+
* @param typesCsv - Comma-separated ABI type strings, e.g. `"address,uint256,(bool,bytes32)[],string"`.
|
|
412
|
+
* @returns Binary descriptor bytes starting with the version+paramCount header.
|
|
413
|
+
* @throws {CallciumError} With code `INVALID_TYPE_STRING` for malformed input.
|
|
414
|
+
* @throws {CallciumError} With code `UNKNOWN_TYPE` for unrecognised type names.
|
|
415
|
+
*/
|
|
416
|
+
declare function fromTypes(typesCsv: string): Uint8Array;
|
|
417
|
+
/**
|
|
418
|
+
* Reconstruct a comma-separated list of ABI type strings from a binary descriptor.
|
|
419
|
+
*
|
|
420
|
+
* Inverse of `fromTypes`: `toTypes(fromTypes(s))` returns `s` for any valid input.
|
|
421
|
+
*
|
|
422
|
+
* @param desc - Binary descriptor bytes (with version+paramCount header).
|
|
423
|
+
* @returns Comma-separated ABI type strings, e.g. `"address,uint256,(bool,bytes32)[]"`.
|
|
424
|
+
* @throws {CallciumError} If the descriptor is malformed.
|
|
425
|
+
*/
|
|
426
|
+
declare function toTypes(desc: Uint8Array): string;
|
|
427
|
+
/** Encode and decode descriptors. */
|
|
428
|
+
declare const DescriptorCoder: {
|
|
429
|
+
fromTypes: typeof fromTypes;
|
|
430
|
+
toTypes: typeof toTypes;
|
|
431
|
+
};
|
|
432
|
+
//#endregion
|
|
433
|
+
//#region src/constants.d.ts
|
|
434
|
+
/**
|
|
435
|
+
* Extract a `{ KEY: code }` map from a table with `key` and `code` fields.
|
|
436
|
+
* @internal
|
|
437
|
+
*/
|
|
438
|
+
type CodeMap<T extends readonly {
|
|
439
|
+
readonly key: string;
|
|
440
|
+
readonly code: number;
|
|
441
|
+
}[]> = { readonly [E in T[number] as E["key"]]: E["code"] };
|
|
442
|
+
/** Rule scope discriminant: context (EVM environment) vs. calldata (ABI payload). */
|
|
443
|
+
declare const Scope: CodeMap<readonly [{
|
|
444
|
+
readonly key: "CONTEXT";
|
|
445
|
+
readonly code: 0;
|
|
446
|
+
readonly label: "context";
|
|
447
|
+
}, {
|
|
448
|
+
readonly key: "CALLDATA";
|
|
449
|
+
readonly code: 1;
|
|
450
|
+
readonly label: "calldata";
|
|
451
|
+
}]>;
|
|
452
|
+
/** Display metadata for a scope code. */
|
|
453
|
+
type ScopeInfo = {
|
|
454
|
+
label: string;
|
|
455
|
+
};
|
|
456
|
+
/**
|
|
457
|
+
* Map a scope code to its display label.
|
|
458
|
+
* @param code - Scope byte value.
|
|
459
|
+
* @returns Display metadata for the scope.
|
|
460
|
+
* @throws {CallciumError} If the code is not a recognised scope.
|
|
461
|
+
*/
|
|
462
|
+
declare function lookupScope(code: number): ScopeInfo;
|
|
463
|
+
/** Well-known context property IDs for context-scope rules. */
|
|
464
|
+
declare const ContextProperty: CodeMap<readonly [{
|
|
465
|
+
readonly key: "MSG_SENDER";
|
|
466
|
+
readonly code: 0;
|
|
467
|
+
readonly label: "msg.sender";
|
|
468
|
+
readonly typeCode: 64;
|
|
469
|
+
}, {
|
|
470
|
+
readonly key: "MSG_VALUE";
|
|
471
|
+
readonly code: 1;
|
|
472
|
+
readonly label: "msg.value";
|
|
473
|
+
readonly typeCode: 31;
|
|
474
|
+
}, {
|
|
475
|
+
readonly key: "BLOCK_TIMESTAMP";
|
|
476
|
+
readonly code: 2;
|
|
477
|
+
readonly label: "block.timestamp";
|
|
478
|
+
readonly typeCode: 31;
|
|
479
|
+
}, {
|
|
480
|
+
readonly key: "BLOCK_NUMBER";
|
|
481
|
+
readonly code: 3;
|
|
482
|
+
readonly label: "block.number";
|
|
483
|
+
readonly typeCode: 31;
|
|
484
|
+
}, {
|
|
485
|
+
readonly key: "CHAIN_ID";
|
|
486
|
+
readonly code: 4;
|
|
487
|
+
readonly label: "block.chainid";
|
|
488
|
+
readonly typeCode: 31;
|
|
489
|
+
}, {
|
|
490
|
+
readonly key: "TX_ORIGIN";
|
|
491
|
+
readonly code: 5;
|
|
492
|
+
readonly label: "tx.origin";
|
|
493
|
+
readonly typeCode: 64;
|
|
494
|
+
}]>;
|
|
495
|
+
/** Display metadata for a context property code. */
|
|
496
|
+
type ContextPropertyInfo = {
|
|
497
|
+
label: string;
|
|
498
|
+
contextKey: keyof Context;
|
|
499
|
+
typeCode: number;
|
|
500
|
+
};
|
|
501
|
+
/**
|
|
502
|
+
* Map a context property code to its display label and ABI type code.
|
|
503
|
+
* @param code - Context property ID.
|
|
504
|
+
* @returns Display metadata including the Solidity type code for the property value.
|
|
505
|
+
* @throws {CallciumError} If the code is not a recognised context property.
|
|
506
|
+
*/
|
|
507
|
+
declare function lookupContextProperty(code: number): ContextPropertyInfo;
|
|
508
|
+
/** Protocol-imposed safety limits for path depth and quantifier array size. */
|
|
509
|
+
declare const Limits: {
|
|
510
|
+
readonly MAX_PATH_DEPTH: 32;
|
|
511
|
+
readonly MAX_QUANTIFIED_ARRAY_LENGTH: 256;
|
|
512
|
+
};
|
|
513
|
+
/** Operand count category for operator data validation. */
|
|
514
|
+
type Operands = "single" | "range" | "variadic";
|
|
515
|
+
/** @internal */
|
|
516
|
+
declare const OP_TABLE: readonly [{
|
|
517
|
+
readonly key: "EQ";
|
|
518
|
+
readonly code: 1;
|
|
519
|
+
readonly label: "==";
|
|
520
|
+
readonly operands: "single";
|
|
521
|
+
}, {
|
|
522
|
+
readonly key: "GT";
|
|
523
|
+
readonly code: 2;
|
|
524
|
+
readonly label: ">";
|
|
525
|
+
readonly operands: "single";
|
|
526
|
+
}, {
|
|
527
|
+
readonly key: "LT";
|
|
528
|
+
readonly code: 3;
|
|
529
|
+
readonly label: "<";
|
|
530
|
+
readonly operands: "single";
|
|
531
|
+
}, {
|
|
532
|
+
readonly key: "GTE";
|
|
533
|
+
readonly code: 4;
|
|
534
|
+
readonly label: ">=";
|
|
535
|
+
readonly operands: "single";
|
|
536
|
+
}, {
|
|
537
|
+
readonly key: "LTE";
|
|
538
|
+
readonly code: 5;
|
|
539
|
+
readonly label: "<=";
|
|
540
|
+
readonly operands: "single";
|
|
541
|
+
}, {
|
|
542
|
+
readonly key: "BETWEEN";
|
|
543
|
+
readonly code: 6;
|
|
544
|
+
readonly label: "between";
|
|
545
|
+
readonly operands: "range";
|
|
546
|
+
}, {
|
|
547
|
+
readonly key: "IN";
|
|
548
|
+
readonly code: 7;
|
|
549
|
+
readonly label: "in";
|
|
550
|
+
readonly operands: "variadic";
|
|
551
|
+
}, {
|
|
552
|
+
readonly key: "BITMASK_ALL";
|
|
553
|
+
readonly code: 16;
|
|
554
|
+
readonly label: "bitmask all";
|
|
555
|
+
readonly operands: "single";
|
|
556
|
+
}, {
|
|
557
|
+
readonly key: "BITMASK_ANY";
|
|
558
|
+
readonly code: 17;
|
|
559
|
+
readonly label: "bitmask any";
|
|
560
|
+
readonly operands: "single";
|
|
561
|
+
}, {
|
|
562
|
+
readonly key: "BITMASK_NONE";
|
|
563
|
+
readonly code: 18;
|
|
564
|
+
readonly label: "bitmask none";
|
|
565
|
+
readonly operands: "single";
|
|
566
|
+
}, {
|
|
567
|
+
readonly key: "LENGTH_EQ";
|
|
568
|
+
readonly code: 32;
|
|
569
|
+
readonly label: "length ==";
|
|
570
|
+
readonly operands: "single";
|
|
571
|
+
}, {
|
|
572
|
+
readonly key: "LENGTH_GT";
|
|
573
|
+
readonly code: 33;
|
|
574
|
+
readonly label: "length >";
|
|
575
|
+
readonly operands: "single";
|
|
576
|
+
}, {
|
|
577
|
+
readonly key: "LENGTH_LT";
|
|
578
|
+
readonly code: 34;
|
|
579
|
+
readonly label: "length <";
|
|
580
|
+
readonly operands: "single";
|
|
581
|
+
}, {
|
|
582
|
+
readonly key: "LENGTH_GTE";
|
|
583
|
+
readonly code: 35;
|
|
584
|
+
readonly label: "length >=";
|
|
585
|
+
readonly operands: "single";
|
|
586
|
+
}, {
|
|
587
|
+
readonly key: "LENGTH_LTE";
|
|
588
|
+
readonly code: 36;
|
|
589
|
+
readonly label: "length <=";
|
|
590
|
+
readonly operands: "single";
|
|
591
|
+
}, {
|
|
592
|
+
readonly key: "LENGTH_BETWEEN";
|
|
593
|
+
readonly code: 37;
|
|
594
|
+
readonly label: "length between";
|
|
595
|
+
readonly operands: "range";
|
|
596
|
+
}];
|
|
597
|
+
/** Callcium policy operator codes. */
|
|
598
|
+
declare const Op: CodeMap<typeof OP_TABLE> & {
|
|
599
|
+
readonly NOT: 0x80;
|
|
600
|
+
};
|
|
601
|
+
/** Display metadata for an operator code. */
|
|
602
|
+
type OpInfo = {
|
|
603
|
+
label: string;
|
|
604
|
+
operands: Operands;
|
|
605
|
+
};
|
|
606
|
+
/**
|
|
607
|
+
* Map an operator code to its display label. Strips the NOT flag automatically.
|
|
608
|
+
* @param code - Operator byte value (may include the NOT flag).
|
|
609
|
+
* @returns Display metadata for the base operator.
|
|
610
|
+
* @throws {CallciumError} If the base code is not a recognised operator.
|
|
611
|
+
*/
|
|
612
|
+
declare function lookupOp(code: number): OpInfo;
|
|
613
|
+
/** Reserved path step values that trigger quantified evaluation over array elements. */
|
|
614
|
+
declare const Quantifier: CodeMap<readonly [{
|
|
615
|
+
readonly key: "ALL_OR_EMPTY";
|
|
616
|
+
readonly code: 65535;
|
|
617
|
+
readonly label: "all or empty";
|
|
618
|
+
}, {
|
|
619
|
+
readonly key: "ALL";
|
|
620
|
+
readonly code: 65534;
|
|
621
|
+
readonly label: "all";
|
|
622
|
+
}, {
|
|
623
|
+
readonly key: "ANY";
|
|
624
|
+
readonly code: 65533;
|
|
625
|
+
readonly label: "any";
|
|
626
|
+
}]>;
|
|
627
|
+
/** Display metadata for a quantifier step. */
|
|
628
|
+
type QuantifierInfo = {
|
|
629
|
+
label: string;
|
|
630
|
+
};
|
|
631
|
+
/** Check whether a path step is a quantifier (ALL_OR_EMPTY, ALL, or ANY). */
|
|
632
|
+
declare function isQuantifier(step: number): boolean;
|
|
633
|
+
/**
|
|
634
|
+
* Map a quantifier path step to its display label.
|
|
635
|
+
* @param code - Quantifier step value.
|
|
636
|
+
* @returns Display metadata for the quantifier.
|
|
637
|
+
* @throws {CallciumError} If the code is not a recognised quantifier.
|
|
638
|
+
*/
|
|
639
|
+
declare function lookupQuantifier(code: number): QuantifierInfo;
|
|
640
|
+
/** ABI type code ranges and sentinel values for the descriptor format. */
|
|
641
|
+
declare const TypeCode: {
|
|
642
|
+
readonly UINT_MIN: 0;
|
|
643
|
+
readonly UINT_MAX: 31;
|
|
644
|
+
readonly INT_MIN: 32;
|
|
645
|
+
readonly INT_MAX: 63;
|
|
646
|
+
readonly ADDRESS: 64;
|
|
647
|
+
readonly BOOL: 65;
|
|
648
|
+
readonly FUNCTION: 66;
|
|
649
|
+
readonly FIXED_BYTES_MIN: 80;
|
|
650
|
+
readonly FIXED_BYTES_MAX: 111;
|
|
651
|
+
readonly BYTES: 112;
|
|
652
|
+
readonly STRING: 113;
|
|
653
|
+
readonly STATIC_ARRAY: 128;
|
|
654
|
+
readonly DYNAMIC_ARRAY: 129;
|
|
655
|
+
readonly TUPLE: 144;
|
|
656
|
+
};
|
|
657
|
+
/** Structural category for a descriptor type code. */
|
|
658
|
+
type TypeClass = "elementary" | "tuple" | "staticArray" | "dynamicArray";
|
|
659
|
+
/** Structural classification without label — used by the decoder hot path. */
|
|
660
|
+
type TypeClassInfo = {
|
|
661
|
+
typeClass: TypeClass;
|
|
662
|
+
isDynamic: boolean;
|
|
663
|
+
};
|
|
664
|
+
/** Display metadata for a descriptor type code. */
|
|
665
|
+
type TypeCodeInfo = TypeClassInfo & {
|
|
666
|
+
label: string;
|
|
667
|
+
};
|
|
668
|
+
/**
|
|
669
|
+
* Map a raw type code byte to its Solidity label, structural category, and dynamism.
|
|
670
|
+
* @param code - A single-byte descriptor type code.
|
|
671
|
+
* @returns Label, type class, and whether the type is ABI-dynamic.
|
|
672
|
+
* @throws {CallciumError} If the code is not a recognised type code.
|
|
673
|
+
*/
|
|
674
|
+
declare function lookupTypeCode(code: number): TypeCodeInfo;
|
|
675
|
+
//#endregion
|
|
676
|
+
//#region src/errors.d.ts
|
|
677
|
+
/** Machine-readable error code for structural decoding and validation failures. */
|
|
678
|
+
type CallciumErrorCode = "UNSUPPORTED_VERSION" | "MALFORMED_HEADER" | "UNEXPECTED_END" | "NODE_OVERFLOW" | "UNKNOWN_TYPE_CODE" | "INVALID_OPERATOR" | "INVALID_ARRAY_LENGTH" | "INVALID_TUPLE_FIELD_COUNT" | "PARAM_COUNT_MISMATCH" | "EMPTY_POLICY" | "EMPTY_GROUP" | "EMPTY_PATH" | "INVALID_CONTEXT_PATH" | "INVALID_CONTEXT_PROPERTY" | "INVALID_QUANTIFIER" | "INVALID_SCOPE" | "RULE_SIZE_MISMATCH" | "GROUP_SIZE_MISMATCH" | "GROUP_OVERFLOW" | "RULE_OVERFLOW" | "TRAILING_BYTES" | "INTERNAL_ERROR" | "INVALID_SIGNATURE" | "INVALID_TYPE_STRING" | "UNKNOWN_TYPE" | "DESCRIPTOR_TOO_LARGE" | "INVALID_PATH" | "DUPLICATE_PATH" | "INVALID_CONSTRAINT" | "INVALID_OPERATOR_DATA" | "EMPTY_SET" | "SET_TOO_LARGE" | "INVALID_RANGE" | "GROUP_COUNT_OVERFLOW" | "RULE_COUNT_OVERFLOW" | "RULE_SIZE_OVERFLOW" | "DESC_LENGTH_OVERFLOW" | "INVALID_HEX" | "VALIDATION_ERROR";
|
|
679
|
+
/**
|
|
680
|
+
* Thrown when a policy or descriptor blob is structurally malformed.
|
|
681
|
+
* The optional `offset` indicates the byte position in the source blob where the error was detected.
|
|
682
|
+
*/
|
|
683
|
+
declare class CallciumError extends Error {
|
|
684
|
+
readonly code: CallciumErrorCode;
|
|
685
|
+
/** Byte position in the source blob where the error was detected, if applicable. */
|
|
686
|
+
readonly offset?: number;
|
|
687
|
+
constructor(code: CallciumErrorCode, message: string, offset?: number);
|
|
688
|
+
}
|
|
689
|
+
/**
|
|
690
|
+
* Thrown by `PolicyEnforcer.enforce` when calldata fails policy enforcement.
|
|
691
|
+
* Distinct from `CallciumError("VALIDATION_ERROR")`, which signals static
|
|
692
|
+
* issues in the policy itself.
|
|
693
|
+
* Carries the full list of violations (one per failed group).
|
|
694
|
+
*/
|
|
695
|
+
declare class PolicyViolationError extends Error {
|
|
696
|
+
readonly violations: Violation[];
|
|
697
|
+
constructor(violations: Violation[]);
|
|
698
|
+
}
|
|
699
|
+
//#endregion
|
|
700
|
+
export { type Address, CallciumError, type CallciumErrorCode, type Constraint, type ConstraintBuilder, type Context, ContextProperty, type ContextPropertyInfo, type DecodedGroup, type DecodedParam, type DecodedPolicy, type DecodedRule, Descriptor, DescriptorCoder, type EnforceResult, type Field, type Hex, type Issue, type IssueCategory, type IssueSeverity, Limits, Op, type OpInfo, type Operands, PolicyBuilder, PolicyCoder, type PolicyData, PolicyEnforcer, PolicyValidator, PolicyViolationError, Quantifier, type QuantifierInfo, type ScalarValue, Scope, type ScopeInfo, type Span, type TypeClass, type TypeClassInfo, TypeCode, type TypeCodeInfo, type TypeInfo, type Violation, type ViolationCode, arg, blockNumber, blockTimestamp, bytesToHex, chainId, hexToBytes, isOpAllowed, isQuantifier, lookupContextProperty, lookupOp, lookupQuantifier, lookupScope, lookupTypeCode, msgSender, msgValue, parsePathSteps, toAddress, txOrigin };
|
|
701
|
+
//# sourceMappingURL=index.d.ts.map
|