@callcium/sdk 0.8.0 → 0.10.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 +74 -48
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +411 -330
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/bytes.ts +9 -9
- package/src/constants.ts +37 -175
- package/src/constraint.ts +24 -31
- package/src/descriptor-coder.ts +18 -20
- package/src/descriptor.ts +12 -11
- package/src/errors.ts +0 -3
- package/src/index.ts +8 -17
- package/src/operators.ts +114 -9
- package/src/path.ts +71 -0
- package/src/policy-builder.ts +17 -16
- package/src/policy-coder.ts +22 -41
- package/src/policy-enforcer.ts +90 -35
- package/src/policy-validator.ts +58 -25
- package/src/type-desc.ts +10 -10
- package/src/types.ts +79 -5
- package/src/validation-issue.ts +18 -4
package/src/types.ts
CHANGED
|
@@ -52,8 +52,8 @@ export type SelectorMismatchViolation = {
|
|
|
52
52
|
};
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
|
-
* A
|
|
56
|
-
|
|
55
|
+
* A rule referenced a context property not supplied in the execution context — a context-scoped
|
|
56
|
+
* subject, or an `EQ_CTX` operand on either scope.
|
|
57
57
|
*/
|
|
58
58
|
export type MissingContextViolation = {
|
|
59
59
|
code: "MISSING_CONTEXT";
|
|
@@ -63,7 +63,9 @@ export type MissingContextViolation = {
|
|
|
63
63
|
path: Hex;
|
|
64
64
|
/** Declared type of the missing context property. */
|
|
65
65
|
typeCode: number;
|
|
66
|
+
/** Operator code with the `Op.NOT` bit intact; absent for a context-scoped subject. */
|
|
66
67
|
opCode?: number;
|
|
68
|
+
/** Operator payload; absent for a context-scoped subject. */
|
|
67
69
|
operandData?: Hex;
|
|
68
70
|
};
|
|
69
71
|
|
|
@@ -92,6 +94,11 @@ export type ValueMismatchViolation = {
|
|
|
92
94
|
/** Type code of the failing value's leaf. */
|
|
93
95
|
typeCode: number;
|
|
94
96
|
resolvedValue?: Hex;
|
|
97
|
+
/**
|
|
98
|
+
* Resolved runtime value of a reference operand as a 32-byte word; present when the
|
|
99
|
+
* operator's operand names a reference resolved at enforcement, not a literal.
|
|
100
|
+
*/
|
|
101
|
+
resolvedOperand?: Hex;
|
|
95
102
|
elementIndex?: number;
|
|
96
103
|
};
|
|
97
104
|
|
|
@@ -123,7 +130,7 @@ export type CalldataNavigationViolation =
|
|
|
123
130
|
| CalldataNavigationVariant<"CALLDATA_OUT_OF_BOUNDS">
|
|
124
131
|
| CalldataNavigationVariant<"ARRAY_INDEX_OUT_OF_BOUNDS">;
|
|
125
132
|
|
|
126
|
-
/** A quantified array exceeded `
|
|
133
|
+
/** A quantified array exceeded `PolicyFormat.MAX_QUANTIFIED_ARRAY_LENGTH`. */
|
|
127
134
|
export type QuantifierLimitExceededViolation = {
|
|
128
135
|
code: "QUANTIFIER_LIMIT_EXCEEDED";
|
|
129
136
|
group: number;
|
|
@@ -135,7 +142,7 @@ export type QuantifierLimitExceededViolation = {
|
|
|
135
142
|
};
|
|
136
143
|
|
|
137
144
|
/**
|
|
138
|
-
* A resolved word is not the canonical encoding of its declared type
|
|
145
|
+
* A resolved word is not the canonical encoding of its declared type.
|
|
139
146
|
*
|
|
140
147
|
* `resolvedValue` is the raw 32-byte word as it appeared in calldata, before any masking.
|
|
141
148
|
*/
|
|
@@ -267,13 +274,80 @@ export type IssueSeverity = "info" | "warning" | "error";
|
|
|
267
274
|
/** Category of a validation issue. */
|
|
268
275
|
export type IssueCategory = "typeMismatch" | "contradiction" | "redundancy" | "vacuity" | "compatibility";
|
|
269
276
|
|
|
277
|
+
/**
|
|
278
|
+
* Machine-readable code for a policy validation issue.
|
|
279
|
+
*
|
|
280
|
+
* Each code names one finding of the semantic validator and matches the constant of the same
|
|
281
|
+
* name in the Solidity `IssueCode` library.
|
|
282
|
+
*/
|
|
283
|
+
export type IssueCode =
|
|
284
|
+
// Type mismatch.
|
|
285
|
+
| "VALUE_OP_ON_DYNAMIC"
|
|
286
|
+
| "VALUE_OP_ON_COMPOSITE"
|
|
287
|
+
| "NUMERIC_OP_ON_NON_NUMERIC"
|
|
288
|
+
| "BITMASK_ON_INVALID"
|
|
289
|
+
| "IN_ON_BOOL"
|
|
290
|
+
| "LENGTH_ON_STATIC"
|
|
291
|
+
| "CONTEXT_TYPE_MISMATCH"
|
|
292
|
+
| "UNKNOWN_OPERATOR"
|
|
293
|
+
| "NON_CANONICAL_OPERAND"
|
|
294
|
+
| "UNNAVIGABLE_PATH"
|
|
295
|
+
| "NESTED_QUANTIFIER"
|
|
296
|
+
| "HINT_MISMATCH"
|
|
297
|
+
// Contradiction.
|
|
298
|
+
| "EQ_NEQ_CONTRADICTION"
|
|
299
|
+
| "CONFLICTING_EQUALITY"
|
|
300
|
+
| "OUT_OF_PHYSICAL_BOUNDS"
|
|
301
|
+
| "IMPOSSIBLE_GT"
|
|
302
|
+
| "IMPOSSIBLE_LT"
|
|
303
|
+
| "BOUNDS_EXCLUDE_EQUALITY"
|
|
304
|
+
| "IMPOSSIBLE_RANGE"
|
|
305
|
+
| "SET_EXCLUDES_EQUALITY"
|
|
306
|
+
| "EMPTY_SET_INTERSECTION"
|
|
307
|
+
| "SET_FULLY_EXCLUDED"
|
|
308
|
+
| "LENGTH_EQ_NEQ_CONTRADICTION"
|
|
309
|
+
| "CONFLICTING_LENGTH"
|
|
310
|
+
| "BOUNDS_EXCLUDE_LENGTH"
|
|
311
|
+
| "IMPOSSIBLE_LENGTH_RANGE"
|
|
312
|
+
| "OUT_OF_PHYSICAL_LENGTH_BOUNDS"
|
|
313
|
+
| "IMPOSSIBLE_LENGTH_GT"
|
|
314
|
+
| "IMPOSSIBLE_LENGTH_LT"
|
|
315
|
+
| "BITMASK_CONTRADICTION"
|
|
316
|
+
| "BITMASK_ANY_IMPOSSIBLE"
|
|
317
|
+
| "UNSORTED_IN_SET"
|
|
318
|
+
| "EMPTY_GROUP"
|
|
319
|
+
// Redundancy.
|
|
320
|
+
| "DOMINATED_BOUND"
|
|
321
|
+
| "REDUNDANT_BOUND"
|
|
322
|
+
| "SET_REDUCTION"
|
|
323
|
+
| "SET_REDUNDANCY"
|
|
324
|
+
| "SET_PARTIALLY_EXCLUDED"
|
|
325
|
+
| "DOMINATED_LENGTH_BOUND"
|
|
326
|
+
| "REDUNDANT_LENGTH_BOUND"
|
|
327
|
+
| "REDUNDANT_BITMASK"
|
|
328
|
+
| "DUPLICATE_CONSTRAINT"
|
|
329
|
+
| "FUSIBLE_RANGE"
|
|
330
|
+
| "FUSIBLE_LENGTH_RANGE"
|
|
331
|
+
// Vacuity.
|
|
332
|
+
| "VACUOUS_GTE"
|
|
333
|
+
| "VACUOUS_LTE"
|
|
334
|
+
| "VACUOUS_LENGTH_GTE"
|
|
335
|
+
| "VACUOUS_LENGTH_LTE"
|
|
336
|
+
| "VACUOUS_NEGATED_RANGE"
|
|
337
|
+
| "VACUOUS_NEGATED_LENGTH_RANGE"
|
|
338
|
+
// Compatibility.
|
|
339
|
+
| "PATH_DEPTH_EXCEEDED"
|
|
340
|
+
| "QUANTIFIER_OVER_STATIC_LIMIT"
|
|
341
|
+
| "UNKNOWN_CONTEXT_PROPERTY"
|
|
342
|
+
| "NEGATION_UNDER_ANY";
|
|
343
|
+
|
|
270
344
|
/** A single validation issue found during policy analysis. */
|
|
271
345
|
export type Issue = {
|
|
272
346
|
severity: IssueSeverity;
|
|
273
347
|
category: IssueCategory;
|
|
274
348
|
groupIndex: number;
|
|
275
349
|
constraintIndex: number;
|
|
276
|
-
code:
|
|
350
|
+
code: IssueCode;
|
|
277
351
|
value1: Hex;
|
|
278
352
|
value2: Hex;
|
|
279
353
|
message: string;
|
package/src/validation-issue.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Hex, Issue } from "./types";
|
|
1
|
+
import type { Hex, Issue, IssueCode } from "./types";
|
|
2
2
|
|
|
3
3
|
///////////////////////////////////////////////////////////////////////////
|
|
4
4
|
// Constants
|
|
@@ -12,7 +12,7 @@ const ZERO: Hex = `0x${"0".repeat(64)}`;
|
|
|
12
12
|
|
|
13
13
|
/** Create an issue from operator compatibility results. */
|
|
14
14
|
export function fromOpRule(
|
|
15
|
-
code:
|
|
15
|
+
code: IssueCode,
|
|
16
16
|
message: string,
|
|
17
17
|
groupIndex: number,
|
|
18
18
|
constraintIndex: number,
|
|
@@ -72,6 +72,20 @@ export function hintMismatch(groupIndex: number, constraintIndex: number): Issue
|
|
|
72
72
|
};
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
/** Issue for a context reference whose property cannot match the target type. */
|
|
76
|
+
export function contextTypeMismatch(groupIndex: number, constraintIndex: number, contextId: Hex, typeCode: Hex): Issue {
|
|
77
|
+
return {
|
|
78
|
+
severity: "error",
|
|
79
|
+
category: "typeMismatch",
|
|
80
|
+
groupIndex,
|
|
81
|
+
constraintIndex,
|
|
82
|
+
code: "CONTEXT_TYPE_MISMATCH",
|
|
83
|
+
value1: contextId,
|
|
84
|
+
value2: typeCode,
|
|
85
|
+
message: "Context property type does not match the target type",
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
75
89
|
/** Issue for an operand that is not canonically encoded for the declared type. */
|
|
76
90
|
export function nonCanonicalOperand(groupIndex: number, constraintIndex: number, operand: Hex, canonical: Hex): Issue {
|
|
77
91
|
return {
|
|
@@ -290,7 +304,7 @@ export function unsortedInSet(groupIndex: number, constraintIndex: number): Issu
|
|
|
290
304
|
code: "UNSORTED_IN_SET",
|
|
291
305
|
value1: ZERO,
|
|
292
306
|
value2: ZERO,
|
|
293
|
-
message: "isIn/notIn set is not strictly sorted and deduplicated
|
|
307
|
+
message: "isIn/notIn set is not strictly sorted and deduplicated",
|
|
294
308
|
};
|
|
295
309
|
}
|
|
296
310
|
|
|
@@ -304,7 +318,7 @@ export function emptyGroup(groupIndex: number): Issue {
|
|
|
304
318
|
code: "EMPTY_GROUP",
|
|
305
319
|
value1: ZERO,
|
|
306
320
|
value2: ZERO,
|
|
307
|
-
message: "Group contains zero constraints
|
|
321
|
+
message: "Group contains zero constraints",
|
|
308
322
|
};
|
|
309
323
|
}
|
|
310
324
|
|