@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.
Files changed (66) hide show
  1. package/dist/adapters/interpreter/adapter.d.ts +2 -2
  2. package/dist/adapters/interpreter/adapter.js +11 -3
  3. package/dist/errors.d.ts +6 -1
  4. package/dist/install/authority-overlap.js +12 -0
  5. package/dist/install/build-add-context-rule.d.ts +1 -1
  6. package/dist/install/read-account-rules.d.ts +79 -0
  7. package/dist/install/read-account-rules.js +241 -0
  8. package/dist/predicate/decode.js +22 -1
  9. package/dist/predicate/encode.js +52 -5
  10. package/dist/predicate/from-json.js +14 -1
  11. package/dist/review-card/builder.js +40 -0
  12. package/dist/review-card/cross-check.js +34 -0
  13. package/dist/review-card/render-leaf.d.ts +1 -1
  14. package/dist/review-card/render-leaf.js +7 -0
  15. package/dist/run/index.js +51 -8
  16. package/dist/run/schemas.d.ts +45 -14
  17. package/dist/run/schemas.js +43 -6
  18. package/dist/simulate/deny-cases.js +11 -0
  19. package/dist/simulate/evaluate.js +86 -5
  20. package/dist/synth/declare.d.ts +13 -0
  21. package/dist/synth/declare.js +34 -5
  22. package/dist/synth/synthesize-from-recording.js +1 -1
  23. package/dist/types.d.ts +21 -1
  24. package/dist/types.js +1 -1
  25. package/dist-cjs/adapters/interpreter/adapter.d.ts +2 -2
  26. package/dist-cjs/adapters/interpreter/adapter.js +11 -3
  27. package/dist-cjs/errors.d.ts +6 -1
  28. package/dist-cjs/install/authority-overlap.js +12 -0
  29. package/dist-cjs/install/build-add-context-rule.d.ts +1 -1
  30. package/dist-cjs/install/read-account-rules.d.ts +79 -0
  31. package/dist-cjs/install/read-account-rules.js +252 -0
  32. package/dist-cjs/predicate/decode.js +22 -1
  33. package/dist-cjs/predicate/encode.js +52 -5
  34. package/dist-cjs/predicate/from-json.js +14 -1
  35. package/dist-cjs/review-card/builder.js +40 -0
  36. package/dist-cjs/review-card/cross-check.js +34 -0
  37. package/dist-cjs/review-card/render-leaf.d.ts +1 -1
  38. package/dist-cjs/review-card/render-leaf.js +7 -0
  39. package/dist-cjs/run/index.js +51 -8
  40. package/dist-cjs/run/schemas.d.ts +45 -14
  41. package/dist-cjs/run/schemas.js +43 -6
  42. package/dist-cjs/simulate/deny-cases.js +11 -0
  43. package/dist-cjs/simulate/evaluate.js +86 -5
  44. package/dist-cjs/synth/declare.d.ts +13 -0
  45. package/dist-cjs/synth/declare.js +34 -5
  46. package/dist-cjs/synth/synthesize-from-recording.js +1 -1
  47. package/dist-cjs/types.d.ts +21 -1
  48. package/dist-cjs/types.js +1 -1
  49. package/package.json +1 -1
  50. package/src/adapters/interpreter/adapter.ts +13 -5
  51. package/src/errors.ts +5 -0
  52. package/src/install/authority-overlap.ts +11 -0
  53. package/src/install/read-account-rules.ts +313 -0
  54. package/src/predicate/decode.ts +22 -1
  55. package/src/predicate/encode.ts +55 -5
  56. package/src/predicate/from-json.ts +14 -1
  57. package/src/review-card/builder.ts +45 -2
  58. package/src/review-card/cross-check.ts +35 -1
  59. package/src/review-card/render-leaf.ts +8 -1
  60. package/src/run/index.ts +54 -8
  61. package/src/run/schemas.ts +43 -6
  62. package/src/simulate/deny-cases.ts +12 -1
  63. package/src/simulate/evaluate.ts +101 -9
  64. package/src/synth/declare.ts +54 -5
  65. package/src/synth/synthesize-from-recording.ts +1 -1
  66. 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 = 3 as const
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 }