@crediolabs/policy-synth 0.4.0 → 0.5.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/adapters/interpreter/adapter.d.ts +2 -2
- package/dist/adapters/interpreter/adapter.js +11 -3
- package/dist/errors.d.ts +6 -1
- package/dist/install/authority-overlap.js +12 -0
- package/dist/install/build-add-context-rule.d.ts +1 -1
- package/dist/install/read-account-rules.d.ts +79 -0
- package/dist/install/read-account-rules.js +241 -0
- package/dist/predicate/decode.js +22 -1
- package/dist/predicate/encode.js +52 -5
- package/dist/predicate/from-json.js +14 -1
- package/dist/review-card/builder.js +40 -0
- package/dist/review-card/cross-check.js +34 -0
- package/dist/review-card/render-leaf.d.ts +1 -1
- package/dist/review-card/render-leaf.js +7 -0
- package/dist/run/index.js +51 -8
- package/dist/run/schemas.d.ts +45 -14
- package/dist/run/schemas.js +43 -6
- package/dist/simulate/deny-cases.js +11 -0
- package/dist/simulate/evaluate.js +86 -5
- package/dist/synth/declare.d.ts +13 -0
- package/dist/synth/declare.js +34 -5
- package/dist/synth/synthesize-from-recording.js +1 -1
- package/dist/types.d.ts +21 -1
- package/dist/types.js +1 -1
- package/dist-cjs/adapters/interpreter/adapter.d.ts +2 -2
- package/dist-cjs/adapters/interpreter/adapter.js +11 -3
- package/dist-cjs/errors.d.ts +6 -1
- package/dist-cjs/install/authority-overlap.js +12 -0
- package/dist-cjs/install/build-add-context-rule.d.ts +1 -1
- package/dist-cjs/install/read-account-rules.d.ts +79 -0
- package/dist-cjs/install/read-account-rules.js +252 -0
- package/dist-cjs/predicate/decode.js +22 -1
- package/dist-cjs/predicate/encode.js +52 -5
- package/dist-cjs/predicate/from-json.js +14 -1
- package/dist-cjs/review-card/builder.js +40 -0
- package/dist-cjs/review-card/cross-check.js +34 -0
- package/dist-cjs/review-card/render-leaf.d.ts +1 -1
- package/dist-cjs/review-card/render-leaf.js +7 -0
- package/dist-cjs/run/index.js +51 -8
- package/dist-cjs/run/schemas.d.ts +45 -14
- package/dist-cjs/run/schemas.js +43 -6
- package/dist-cjs/simulate/deny-cases.js +11 -0
- package/dist-cjs/simulate/evaluate.js +86 -5
- package/dist-cjs/synth/declare.d.ts +13 -0
- package/dist-cjs/synth/declare.js +34 -5
- package/dist-cjs/synth/synthesize-from-recording.js +1 -1
- package/dist-cjs/types.d.ts +21 -1
- package/dist-cjs/types.js +1 -1
- package/package.json +1 -1
- package/src/adapters/interpreter/adapter.ts +13 -5
- package/src/errors.ts +5 -0
- package/src/install/authority-overlap.ts +11 -0
- package/src/install/read-account-rules.ts +313 -0
- package/src/predicate/decode.ts +22 -1
- package/src/predicate/encode.ts +55 -5
- package/src/predicate/from-json.ts +14 -1
- package/src/review-card/builder.ts +45 -2
- package/src/review-card/cross-check.ts +35 -1
- package/src/review-card/render-leaf.ts +8 -1
- package/src/run/index.ts +54 -8
- package/src/run/schemas.ts +43 -6
- package/src/simulate/deny-cases.ts +12 -1
- package/src/simulate/evaluate.ts +101 -9
- package/src/synth/declare.ts +54 -5
- package/src/synth/synthesize-from-recording.ts +1 -1
- package/src/types.ts +16 -1
package/src/types.ts
CHANGED
|
@@ -105,7 +105,7 @@ export type PolicyRef = {
|
|
|
105
105
|
* `contracts/policy-interpreter/src/version.rs`. Every value this package puts on
|
|
106
106
|
* the wire derives from here; `grammar-version-parity.test.ts` pins it to the
|
|
107
107
|
* contract so a skew cannot pass a green test run. */
|
|
108
|
-
export const GRAMMAR_VERSION =
|
|
108
|
+
export const GRAMMAR_VERSION = 4 as const
|
|
109
109
|
|
|
110
110
|
/** A serialised predicate document stored against a (smart_account, rule_id) pair. */
|
|
111
111
|
export interface PolicyDocument {
|
|
@@ -128,8 +128,15 @@ export interface PolicyDocument {
|
|
|
128
128
|
/** The versioned predicate AST (interpreter side). Tagged union. */
|
|
129
129
|
export type PredicateNode =
|
|
130
130
|
| { op: 'and'; children: PredicateNode[] }
|
|
131
|
+
// Permits when ANY child permits. Children are canonically sorted like
|
|
132
|
+
// `and`, so authoring order is NOT preserved; when every branch denies, the
|
|
133
|
+
// contract reports the first branch's reason in wire order.
|
|
134
|
+
| { op: 'or'; children: PredicateNode[] }
|
|
131
135
|
| { op: 'eq'; left: PredicateLeaf; right: PredicateLeaf }
|
|
136
|
+
| { op: 'lt'; left: PredicateLeaf; right: PredicateLeaf }
|
|
132
137
|
| { op: 'lte'; left: PredicateLeaf; right: PredicateLeaf }
|
|
138
|
+
| { op: 'gt'; left: PredicateLeaf; right: PredicateLeaf }
|
|
139
|
+
| { op: 'gte'; left: PredicateLeaf; right: PredicateLeaf }
|
|
133
140
|
| {
|
|
134
141
|
op: 'in'
|
|
135
142
|
needle: PredicateLeaf
|
|
@@ -150,6 +157,14 @@ export type PredicateLeaf =
|
|
|
150
157
|
// recorded ScVal type. A non-vec arg, missing element, missing field, or
|
|
151
158
|
// type mismatch all DENY (fail-closed).
|
|
152
159
|
| { kind: 'call_arg_field'; index: number; element: number; field: string }
|
|
160
|
+
// `args[index] * num / den`, truncating toward zero. The one leaf whose
|
|
161
|
+
// value is COMPUTED from the call rather than read from it, and the only
|
|
162
|
+
// selector allowed on the right of a comparison - which is what lets a swap
|
|
163
|
+
// bound its output against its own input instead of against a constant that
|
|
164
|
+
// would pin the policy to one trade size. `num`/`den` are i128 decimal
|
|
165
|
+
// strings. Install refuses a zero or non-positive ratio (214), because a
|
|
166
|
+
// negative ratio inverts the comparison.
|
|
167
|
+
| { kind: 'call_arg_scaled'; index: number; num: string; den: string }
|
|
153
168
|
// Literal leaves: bare ScVal on the wire (no selector-tuple wrapper). Right-hand side of
|
|
154
169
|
// comparisons, elements of `in` haystacks, and operands to future arithmetic nodes.
|
|
155
170
|
| { kind: 'literal_address'; value: string }
|