@crediolabs/policy-synth 0.2.0 → 0.3.1
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/README.md +4 -4
- package/dist/adapters/interpreter/adapter.d.ts +19 -25
- package/dist/adapters/interpreter/adapter.js +54 -487
- package/dist/errors.d.ts +1 -1
- package/dist/index.d.ts +1 -4
- package/dist/index.js +1 -4
- package/dist/install/build-add-context-rule.d.ts +3 -19
- package/dist/install/build-add-context-rule.js +3 -98
- package/dist/install/build-install-policy.d.ts +4 -53
- package/dist/install/build-install-policy.js +44 -123
- package/dist/install/index.d.ts +0 -2
- package/dist/install/index.js +0 -7
- package/dist/predicate/decode.d.ts +1 -1
- package/dist/predicate/decode.js +2 -70
- package/dist/predicate/encode.js +45 -229
- package/dist/predicate/from-json.js +1 -42
- package/dist/record/decode.js +3 -8
- package/dist/record/freshness.d.ts +17 -11
- package/dist/record/freshness.js +28 -18
- package/dist/review-card/builder.d.ts +4 -3
- package/dist/review-card/builder.js +18 -162
- package/dist/review-card/cross-check.js +2 -105
- package/dist/review-card/render-leaf.d.ts +4 -0
- package/dist/review-card/render-leaf.js +47 -0
- package/dist/run/index.d.ts +36 -139
- package/dist/run/index.js +125 -437
- package/dist/run/schemas.d.ts +168 -1929
- package/dist/run/schemas.js +40 -269
- package/dist/{synth → simulate}/deny-cases.d.ts +4 -8
- package/dist/simulate/deny-cases.js +282 -0
- package/dist/simulate/evaluate.d.ts +18 -0
- package/dist/simulate/evaluate.js +271 -0
- package/dist/simulate/index.d.ts +4 -0
- package/dist/simulate/index.js +8 -0
- package/dist/synth/compose-from-recording.d.ts +24 -51
- package/dist/synth/compose-from-recording.js +120 -282
- package/dist/synth/index.d.ts +0 -5
- package/dist/synth/index.js +0 -5
- package/dist/synth/synthesize-from-recording.d.ts +1 -29
- package/dist/synth/synthesize-from-recording.js +41 -356
- package/dist/types.d.ts +8 -60
- package/dist/types.js +5 -2
- package/dist-cjs/adapters/interpreter/adapter.d.ts +19 -25
- package/dist-cjs/adapters/interpreter/adapter.js +56 -489
- package/dist-cjs/errors.d.ts +1 -1
- package/dist-cjs/index.d.ts +1 -4
- package/dist-cjs/index.js +1 -4
- package/dist-cjs/install/build-add-context-rule.d.ts +3 -19
- package/dist-cjs/install/build-add-context-rule.js +1 -97
- package/dist-cjs/install/build-install-policy.d.ts +4 -53
- package/dist-cjs/install/build-install-policy.js +44 -122
- package/dist-cjs/install/index.d.ts +0 -2
- package/dist-cjs/install/index.js +2 -23
- package/dist-cjs/predicate/decode.d.ts +1 -1
- package/dist-cjs/predicate/decode.js +2 -70
- package/dist-cjs/predicate/encode.js +45 -229
- package/dist-cjs/predicate/from-json.js +1 -42
- package/dist-cjs/record/decode.js +3 -8
- package/dist-cjs/record/freshness.d.ts +17 -11
- package/dist-cjs/record/freshness.js +28 -18
- package/dist-cjs/review-card/builder.d.ts +4 -3
- package/dist-cjs/review-card/builder.js +23 -167
- package/dist-cjs/review-card/cross-check.js +7 -110
- package/dist-cjs/review-card/render-leaf.d.ts +4 -0
- package/dist-cjs/review-card/render-leaf.js +52 -0
- package/dist-cjs/run/index.d.ts +36 -139
- package/dist-cjs/run/index.js +125 -444
- package/dist-cjs/run/schemas.d.ts +168 -1929
- package/dist-cjs/run/schemas.js +41 -270
- package/dist-cjs/{synth → simulate}/deny-cases.d.ts +4 -8
- package/dist-cjs/simulate/deny-cases.js +286 -0
- package/dist-cjs/simulate/evaluate.d.ts +18 -0
- package/dist-cjs/simulate/evaluate.js +274 -0
- package/dist-cjs/simulate/index.d.ts +4 -0
- package/dist-cjs/simulate/index.js +13 -0
- package/dist-cjs/synth/compose-from-recording.d.ts +24 -51
- package/dist-cjs/synth/compose-from-recording.js +120 -282
- package/dist-cjs/synth/index.d.ts +0 -5
- package/dist-cjs/synth/index.js +1 -11
- package/dist-cjs/synth/synthesize-from-recording.d.ts +1 -29
- package/dist-cjs/synth/synthesize-from-recording.js +39 -354
- package/dist-cjs/types.d.ts +8 -60
- package/dist-cjs/types.js +6 -3
- package/package.json +5 -5
- package/src/adapters/interpreter/adapter.ts +76 -572
- package/src/errors.ts +0 -19
- package/src/index.ts +1 -4
- package/src/install/build-add-context-rule.ts +5 -139
- package/src/install/build-install-policy.ts +93 -214
- package/src/install/index.ts +0 -34
- package/src/predicate/decode.ts +2 -70
- package/src/predicate/encode.ts +49 -261
- package/src/predicate/from-json.ts +1 -43
- package/src/record/decode.ts +3 -8
- package/src/record/freshness.ts +29 -18
- package/src/review-card/builder.ts +19 -168
- package/src/review-card/cross-check.ts +3 -105
- package/src/review-card/render-leaf.ts +48 -0
- package/src/run/index.ts +144 -572
- package/src/run/schemas.ts +42 -291
- package/src/simulate/deny-cases.ts +334 -0
- package/src/simulate/evaluate.ts +284 -0
- package/src/simulate/index.ts +11 -0
- package/src/synth/compose-from-recording.ts +148 -347
- package/src/synth/index.ts +0 -13
- package/src/synth/synthesize-from-recording.ts +43 -456
- package/src/types.ts +13 -49
- package/dist/adapters/interpreter/index.d.ts +0 -1
- package/dist/adapters/interpreter/index.js +0 -2
- package/dist/adapters/oz/adapter.d.ts +0 -20
- package/dist/adapters/oz/adapter.js +0 -295
- package/dist/adapters/oz/index.d.ts +0 -1
- package/dist/adapters/oz/index.js +0 -2
- package/dist/codegen/compile-gate.d.ts +0 -33
- package/dist/codegen/compile-gate.js +0 -124
- package/dist/codegen/index.d.ts +0 -2
- package/dist/codegen/index.js +0 -8
- package/dist/codegen/template.d.ts +0 -18
- package/dist/codegen/template.js +0 -148
- package/dist/install/authority-overlap.d.ts +0 -134
- package/dist/install/authority-overlap.js +0 -0
- package/dist/install/build-install-predicate.d.ts +0 -96
- package/dist/install/build-install-predicate.js +0 -444
- package/dist/install/build-merge-policy.d.ts +0 -70
- package/dist/install/build-merge-policy.js +0 -130
- package/dist/install/plan-merge-policy.d.ts +0 -49
- package/dist/install/plan-merge-policy.js +0 -86
- package/dist/install/read-account-rules.d.ts +0 -100
- package/dist/install/read-account-rules.js +0 -283
- package/dist/ir/index.d.ts +0 -1
- package/dist/ir/index.js +0 -2
- package/dist/ir/types.d.ts +0 -140
- package/dist/ir/types.js +0 -11
- package/dist/mandate/index.d.ts +0 -2
- package/dist/mandate/index.js +0 -2
- package/dist/mandate/to-ir.d.ts +0 -3
- package/dist/mandate/to-ir.js +0 -60
- package/dist/mandate/types.d.ts +0 -20
- package/dist/mandate/types.js +0 -8
- package/dist/seams/index.d.ts +0 -1
- package/dist/seams/index.js +0 -2
- package/dist/seams/types.d.ts +0 -66
- package/dist/seams/types.js +0 -11
- package/dist/synth/deny-cases.js +0 -562
- package/dist/synth/evaluate.d.ts +0 -39
- package/dist/synth/evaluate.js +0 -551
- package/dist/synth/harness.d.ts +0 -28
- package/dist/synth/harness.js +0 -47
- package/dist/synth/minimize.d.ts +0 -4
- package/dist/synth/minimize.js +0 -38
- package/dist/synth/permit-context.d.ts +0 -15
- package/dist/synth/permit-context.js +0 -116
- package/dist/synth/predicate-literals.d.ts +0 -5
- package/dist/synth/predicate-literals.js +0 -25
- package/dist/synth/synthesize-from-mandate.d.ts +0 -20
- package/dist/synth/synthesize-from-mandate.js +0 -59
- package/dist/verify/envelope.d.ts +0 -15
- package/dist/verify/envelope.js +0 -22
- package/dist/verify/index.d.ts +0 -3
- package/dist/verify/index.js +0 -3
- package/dist/verify/simulate.d.ts +0 -31
- package/dist/verify/simulate.js +0 -258
- package/dist/verify/verify.d.ts +0 -21
- package/dist/verify/verify.js +0 -189
- package/dist-cjs/adapters/interpreter/index.d.ts +0 -1
- package/dist-cjs/adapters/interpreter/index.js +0 -8
- package/dist-cjs/adapters/oz/adapter.d.ts +0 -20
- package/dist-cjs/adapters/oz/adapter.js +0 -300
- package/dist-cjs/adapters/oz/index.d.ts +0 -1
- package/dist-cjs/adapters/oz/index.js +0 -8
- package/dist-cjs/codegen/compile-gate.d.ts +0 -33
- package/dist-cjs/codegen/compile-gate.js +0 -128
- package/dist-cjs/codegen/index.d.ts +0 -2
- package/dist-cjs/codegen/index.js +0 -14
- package/dist-cjs/codegen/template.d.ts +0 -18
- package/dist-cjs/codegen/template.js +0 -151
- package/dist-cjs/install/authority-overlap.d.ts +0 -134
- package/dist-cjs/install/authority-overlap.js +0 -0
- package/dist-cjs/install/build-install-predicate.d.ts +0 -96
- package/dist-cjs/install/build-install-predicate.js +0 -479
- package/dist-cjs/install/build-merge-policy.d.ts +0 -70
- package/dist-cjs/install/build-merge-policy.js +0 -134
- package/dist-cjs/install/plan-merge-policy.d.ts +0 -49
- package/dist-cjs/install/plan-merge-policy.js +0 -90
- package/dist-cjs/install/read-account-rules.d.ts +0 -100
- package/dist-cjs/install/read-account-rules.js +0 -296
- package/dist-cjs/ir/index.d.ts +0 -1
- package/dist-cjs/ir/index.js +0 -3
- package/dist-cjs/ir/types.d.ts +0 -140
- package/dist-cjs/ir/types.js +0 -12
- package/dist-cjs/mandate/index.d.ts +0 -2
- package/dist-cjs/mandate/index.js +0 -6
- package/dist-cjs/mandate/to-ir.d.ts +0 -3
- package/dist-cjs/mandate/to-ir.js +0 -63
- package/dist-cjs/mandate/types.d.ts +0 -20
- package/dist-cjs/mandate/types.js +0 -9
- package/dist-cjs/seams/index.d.ts +0 -1
- package/dist-cjs/seams/index.js +0 -3
- package/dist-cjs/seams/types.d.ts +0 -66
- package/dist-cjs/seams/types.js +0 -12
- package/dist-cjs/synth/deny-cases.js +0 -568
- package/dist-cjs/synth/evaluate.d.ts +0 -39
- package/dist-cjs/synth/evaluate.js +0 -554
- package/dist-cjs/synth/harness.d.ts +0 -28
- package/dist-cjs/synth/harness.js +0 -50
- package/dist-cjs/synth/minimize.d.ts +0 -4
- package/dist-cjs/synth/minimize.js +0 -41
- package/dist-cjs/synth/permit-context.d.ts +0 -15
- package/dist-cjs/synth/permit-context.js +0 -119
- package/dist-cjs/synth/predicate-literals.d.ts +0 -5
- package/dist-cjs/synth/predicate-literals.js +0 -28
- package/dist-cjs/synth/synthesize-from-mandate.d.ts +0 -20
- package/dist-cjs/synth/synthesize-from-mandate.js +0 -62
- package/dist-cjs/verify/envelope.d.ts +0 -15
- package/dist-cjs/verify/envelope.js +0 -23
- package/dist-cjs/verify/index.d.ts +0 -3
- package/dist-cjs/verify/index.js +0 -8
- package/dist-cjs/verify/simulate.d.ts +0 -31
- package/dist-cjs/verify/simulate.js +0 -261
- package/dist-cjs/verify/verify.d.ts +0 -21
- package/dist-cjs/verify/verify.js +0 -192
- package/src/adapters/interpreter/index.ts +0 -8
- package/src/adapters/oz/adapter.ts +0 -376
- package/src/adapters/oz/index.ts +0 -9
- package/src/codegen/compile-gate.ts +0 -167
- package/src/codegen/index.ts +0 -17
- package/src/codegen/template.ts +0 -165
- package/src/install/authority-overlap.ts +0 -0
- package/src/install/build-merge-policy.ts +0 -219
- package/src/install/plan-merge-policy.ts +0 -133
- package/src/install/read-account-rules.ts +0 -376
- package/src/ir/index.ts +0 -13
- package/src/ir/types.ts +0 -132
- package/src/mandate/index.ts +0 -4
- package/src/mandate/to-ir.ts +0 -71
- package/src/mandate/types.ts +0 -21
- package/src/seams/index.ts +0 -11
- package/src/seams/types.ts +0 -81
- package/src/synth/deny-cases.ts +0 -663
- package/src/synth/evaluate.ts +0 -613
- package/src/synth/harness.ts +0 -68
- package/src/synth/minimize.ts +0 -48
- package/src/synth/permit-context.ts +0 -136
- package/src/synth/predicate-literals.ts +0 -27
- package/src/synth/synthesize-from-mandate.ts +0 -82
- package/src/verify/envelope.ts +0 -28
- package/src/verify/index.ts +0 -5
- package/src/verify/simulate.ts +0 -311
- package/src/verify/verify.ts +0 -243
package/dist-cjs/ir/index.js
DELETED
package/dist-cjs/ir/types.d.ts
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
/** Comparison operator. Mirrors NEAR-V2 `CompOp`. */
|
|
2
|
-
export type IRCompOp = 'eq' | 'lt' | 'lte' | 'gt' | 'gte';
|
|
3
|
-
/** Boolean combinator. Mirrors NEAR-V2 `LogicOp`. */
|
|
4
|
-
export type IRLogic = 'and' | 'or';
|
|
5
|
-
/** Vector match mode for a repeated arg. Mirrors NEAR-V2 `VecMode`. */
|
|
6
|
-
export type IRVecMode = 'all' | 'any';
|
|
7
|
-
/** Scalar value type. Mirrors NEAR-V2 `ScValType`, superset for OZ. */
|
|
8
|
-
export type IRScalarType = 'address' | 'i128' | 'u128' | 'u32' | 'u64' | 'i64' | 'symbol' | 'bytes' | 'bool';
|
|
9
|
-
/** WHERE in the authorized call a value is read. NEAR-V2 selectors first, OZ
|
|
10
|
-
* extensions after (an adapter that cannot express an extension flags it). */
|
|
11
|
-
export type IRSelector = {
|
|
12
|
-
kind: 'arg';
|
|
13
|
-
argIndex: number;
|
|
14
|
-
fieldIndex?: number;
|
|
15
|
-
vecMode?: IRVecMode;
|
|
16
|
-
scalarType: IRScalarType;
|
|
17
|
-
} | {
|
|
18
|
-
kind: 'arg_len';
|
|
19
|
-
argIndex: number;
|
|
20
|
-
} | {
|
|
21
|
-
kind: 'arg_field';
|
|
22
|
-
argIndex: number;
|
|
23
|
-
element: number;
|
|
24
|
-
field: string;
|
|
25
|
-
scalarType: IRScalarType;
|
|
26
|
-
} | {
|
|
27
|
-
kind: 'calldata';
|
|
28
|
-
offset: number;
|
|
29
|
-
length: number;
|
|
30
|
-
} | {
|
|
31
|
-
kind: 'value';
|
|
32
|
-
} | {
|
|
33
|
-
kind: 'amount';
|
|
34
|
-
token: string;
|
|
35
|
-
} | {
|
|
36
|
-
kind: 'window_spent';
|
|
37
|
-
token: string;
|
|
38
|
-
windowSeconds: number;
|
|
39
|
-
} | {
|
|
40
|
-
kind: 'invocation_count';
|
|
41
|
-
windowSeconds: number;
|
|
42
|
-
} | {
|
|
43
|
-
kind: 'now';
|
|
44
|
-
} | {
|
|
45
|
-
kind: 'valid_until';
|
|
46
|
-
} | {
|
|
47
|
-
kind: 'oracle_price';
|
|
48
|
-
asset: string;
|
|
49
|
-
};
|
|
50
|
-
/** A single comparison leaf. `value` is a decimal/hex string (i128-safe;
|
|
51
|
-
* never a JS number). */
|
|
52
|
-
export interface IRCompare {
|
|
53
|
-
selector: IRSelector;
|
|
54
|
-
operator: IRCompOp;
|
|
55
|
-
value: string;
|
|
56
|
-
/** Decimal basis of `value`, for selectors whose comparand is not on a basis
|
|
57
|
-
* the contract can infer. Set for `oracle_price`, where prices normalise to
|
|
58
|
-
* 9 dp and an undeclared basis fails OPEN. */
|
|
59
|
-
valueDecimals?: number;
|
|
60
|
-
}
|
|
61
|
-
/** Condition tree. NEAR-V2 guard/constraint are flat And/Or; the IR allows
|
|
62
|
-
* nesting + `not` + `in` + `eq_seq` so the same IR can later lower to the OZ
|
|
63
|
-
* predicate DSL. Week-1 adapters only lower the flat supported subset and flag
|
|
64
|
-
* the rest. */
|
|
65
|
-
export type IRCondition = {
|
|
66
|
-
op: 'and' | 'or';
|
|
67
|
-
children: IRCondition[];
|
|
68
|
-
} | {
|
|
69
|
-
op: 'not';
|
|
70
|
-
child: IRCondition;
|
|
71
|
-
} | {
|
|
72
|
-
op: 'compare';
|
|
73
|
-
compare: IRCompare;
|
|
74
|
-
} | {
|
|
75
|
-
op: 'in';
|
|
76
|
-
selector: IRSelector;
|
|
77
|
-
values: string[];
|
|
78
|
-
}
|
|
79
|
-
/** Exact ordered sequence equality. The IR-level selector value MUST EQUAL
|
|
80
|
-
* `values` as an ORDERED sequence (e.g. a swap hop `path`). `in` is pure
|
|
81
|
-
* set membership and cannot express order; `eq_seq` is the construct that
|
|
82
|
-
* does. Adapters that cannot express an exact ordered vector (OZ built-ins)
|
|
83
|
-
* flag this as `uncovered` rather than silently dropping it. */
|
|
84
|
-
| {
|
|
85
|
-
op: 'eq_seq';
|
|
86
|
-
selector: IRSelector;
|
|
87
|
-
values: string[];
|
|
88
|
-
}
|
|
89
|
-
/** A swap's output floor, expressed against its own input: the output arg
|
|
90
|
-
* must be at least `inArgIndex * num / den`.
|
|
91
|
-
*
|
|
92
|
-
* It is its own construct because `compare` bounds a selector against a
|
|
93
|
-
* CONSTANT, and a slippage floor has no constant to bound against - the
|
|
94
|
-
* acceptable output depends on the input of the same call. Encoding the
|
|
95
|
-
* recorded output as a constant would pin a policy to one trade size.
|
|
96
|
-
*
|
|
97
|
-
* `num/den` is the caller's minimum acceptable output per unit of input.
|
|
98
|
-
* It is never derived from the recording: the recorded rate is a price at
|
|
99
|
-
* one moment, and freezing it as policy would deny normal trades later.
|
|
100
|
-
* Adapters that cannot express it (the OZ built-ins) flag it `uncovered`. */
|
|
101
|
-
| {
|
|
102
|
-
op: 'slippage_floor';
|
|
103
|
-
outArgIndex: number;
|
|
104
|
-
inArgIndex: number;
|
|
105
|
-
num: string;
|
|
106
|
-
den: string;
|
|
107
|
-
};
|
|
108
|
-
export interface IRPolicyRule {
|
|
109
|
-
/** NEAR-V2 roles whitelist (empty = any; owner exempt). */
|
|
110
|
-
roles: string[];
|
|
111
|
-
/** NEAR-V2 scope filter; each field optional (absent = wildcard). */
|
|
112
|
-
scope: {
|
|
113
|
-
chainId?: number;
|
|
114
|
-
contract?: string;
|
|
115
|
-
method?: string;
|
|
116
|
-
};
|
|
117
|
-
/** NEAR-V2 guard (applicability; skip the rule when it fails). */
|
|
118
|
-
guard?: IRCondition;
|
|
119
|
-
/** NEAR-V2 constraint (AND; reject the transaction when any fails). */
|
|
120
|
-
constraints: IRCondition[];
|
|
121
|
-
/** M-of-N approval (OZ threshold primitives). */
|
|
122
|
-
approval?: {
|
|
123
|
-
kind: 'threshold';
|
|
124
|
-
threshold: number;
|
|
125
|
-
weights?: Record<string, number>;
|
|
126
|
-
};
|
|
127
|
-
/** OZ context-rule expiry. */
|
|
128
|
-
expiry?: {
|
|
129
|
-
validUntilLedger?: number;
|
|
130
|
-
validUntilUnixSeconds?: number;
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
export interface PolicyIR {
|
|
134
|
-
/** NEAR-V2 PolicyChain. */
|
|
135
|
-
chain: 'stellar' | 'evm';
|
|
136
|
-
/** NEAR-V2 DefaultBehavior. OZ context rules are deny-by-default, so
|
|
137
|
-
* `deny_all` is the OZ default fallback when no rule matches. */
|
|
138
|
-
defaultBehavior: 'allow_all' | 'deny_all';
|
|
139
|
-
rules: IRPolicyRule[];
|
|
140
|
-
}
|
package/dist-cjs/ir/types.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// src/ir/types.ts - the PolicyIR ("Policy Tree").
|
|
3
|
-
//
|
|
4
|
-
// `PolicyIR` is the custody-agnostic "Policy Tree" hub (the diagram's Policy
|
|
5
|
-
// Tree) that every CustodyAdapter compiles FROM. It generalizes the NEAR-V2
|
|
6
|
-
// policy schema (roles / scope filter / guard / constraint / comparison leaves /
|
|
7
|
-
// default behaviour) into one chain-neutral shape and extends it with the
|
|
8
|
-
// OZ-only selectors (spend window, oracle price, invocation count, time) so a
|
|
9
|
-
// single IR can serve every backend. NEAR-V2 has no stateful spend window,
|
|
10
|
-
// oracle, time/expiry, or invocation-count; those are marked as OZ extensions
|
|
11
|
-
// below and are only lowered by adapters that declare support for them.
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// src/mandate/index.ts - re-export the Mandate source.
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.mandateToPolicyIR = void 0;
|
|
5
|
-
var to_ir_ts_1 = require("./to-ir.js");
|
|
6
|
-
Object.defineProperty(exports, "mandateToPolicyIR", { enumerable: true, get: function () { return to_ir_ts_1.mandateToPolicyIR; } });
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// src/mandate/to-ir.ts - deterministic lowering of a MandateSpec to a PolicyIR.
|
|
3
|
-
//
|
|
4
|
-
// `mandateToPolicyIR` is pure and total: the same spec always lowers to a
|
|
5
|
-
// byte-identical PolicyIR. No decoding, no inference, no clock. Each mandate
|
|
6
|
-
// field maps to exactly one IR construct:
|
|
7
|
-
// contract/method -> rule.scope
|
|
8
|
-
// spendingLimit -> a `window_spent(token,window) <= limit` compare
|
|
9
|
-
// approvalThreshold-> rule.approval.threshold
|
|
10
|
-
// recipients -> an `in` condition on the recipient arg (flagged as not
|
|
11
|
-
// covered by the OZ adapter; that is expected)
|
|
12
|
-
// expiry -> rule.expiry
|
|
13
|
-
// The top-level default is `deny_all` (OZ context rules are deny-by-default).
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.mandateToPolicyIR = mandateToPolicyIR;
|
|
16
|
-
/** Arg index the recipient allowlist constrains. Pinned to the SEP-41
|
|
17
|
-
* `transfer(from, to, amount)` convention where `to` is arg 1. This condition
|
|
18
|
-
* is flagged as not covered by the OZ adapter (no built-in primitive expresses
|
|
19
|
-
* an arg allowlist), so the index only needs to be deterministic in week-1. */
|
|
20
|
-
const RECIPIENT_ARG_INDEX = 1;
|
|
21
|
-
function mandateToPolicyIR(spec) {
|
|
22
|
-
const scope = { contract: spec.contract };
|
|
23
|
-
if (spec.method !== undefined)
|
|
24
|
-
scope.method = spec.method;
|
|
25
|
-
const constraints = [];
|
|
26
|
-
if (spec.spendingLimit) {
|
|
27
|
-
constraints.push({
|
|
28
|
-
op: 'compare',
|
|
29
|
-
compare: {
|
|
30
|
-
selector: {
|
|
31
|
-
kind: 'window_spent',
|
|
32
|
-
token: spec.spendingLimit.token,
|
|
33
|
-
windowSeconds: spec.spendingLimit.windowSeconds,
|
|
34
|
-
},
|
|
35
|
-
operator: 'lte',
|
|
36
|
-
value: spec.spendingLimit.limit,
|
|
37
|
-
},
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
if (spec.recipients && spec.recipients.length > 0) {
|
|
41
|
-
const selector = {
|
|
42
|
-
kind: 'arg',
|
|
43
|
-
argIndex: RECIPIENT_ARG_INDEX,
|
|
44
|
-
scalarType: 'address',
|
|
45
|
-
};
|
|
46
|
-
constraints.push({ op: 'in', selector, values: [...spec.recipients] });
|
|
47
|
-
}
|
|
48
|
-
const rule = { roles: [], scope, constraints };
|
|
49
|
-
if (spec.approvalThreshold !== undefined) {
|
|
50
|
-
rule.approval = { kind: 'threshold', threshold: spec.approvalThreshold };
|
|
51
|
-
}
|
|
52
|
-
if (spec.expiry) {
|
|
53
|
-
const expiry = {};
|
|
54
|
-
if (spec.expiry.validUntilLedger !== undefined) {
|
|
55
|
-
expiry.validUntilLedger = spec.expiry.validUntilLedger;
|
|
56
|
-
}
|
|
57
|
-
if (spec.expiry.validUntilUnixSeconds !== undefined) {
|
|
58
|
-
expiry.validUntilUnixSeconds = spec.expiry.validUntilUnixSeconds;
|
|
59
|
-
}
|
|
60
|
-
rule.expiry = expiry;
|
|
61
|
-
}
|
|
62
|
-
return { chain: spec.chain, defaultBehavior: 'deny_all', rules: [rule] };
|
|
63
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export interface MandateSpec {
|
|
2
|
-
chain: 'stellar';
|
|
3
|
-
contract: string;
|
|
4
|
-
method?: string;
|
|
5
|
-
/** -> OZ `spending_limit` primitive. `limit` is an i128 decimal string. */
|
|
6
|
-
spendingLimit?: {
|
|
7
|
-
token: string;
|
|
8
|
-
limit: string;
|
|
9
|
-
windowSeconds: number;
|
|
10
|
-
};
|
|
11
|
-
/** -> OZ `simple_threshold` / `weighted_threshold` primitive. */
|
|
12
|
-
approvalThreshold?: number;
|
|
13
|
-
/** Recipient allowlist -> an `in` arg condition (not covered by an OZ built-in). */
|
|
14
|
-
recipients?: string[];
|
|
15
|
-
/** -> OZ context-rule expiry. */
|
|
16
|
-
expiry?: {
|
|
17
|
-
validUntilLedger?: number;
|
|
18
|
-
validUntilUnixSeconds?: number;
|
|
19
|
-
};
|
|
20
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// src/mandate/types.ts - the deterministic Mandate source.
|
|
3
|
-
//
|
|
4
|
-
// A MandateSpec is a declarative policy statement: "this account may call this
|
|
5
|
-
// contract, spending at most L per window, requiring M approvals, to these
|
|
6
|
-
// recipients, until this expiry". It carries NO transaction to decode, NO
|
|
7
|
-
// parseConfidence, and NO inference - it lowers deterministically to a
|
|
8
|
-
// PolicyIR. It is the clean end-to-end demo path, co-equal with the recorder.
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type { ChainDecoder, CompileResult, CustodyAdapter, CustodyCapabilities, CustodyMode, PolicySource, SimulationResult, } from './types.ts';
|
package/dist-cjs/seams/index.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import type { ToolResponse } from '../errors.ts';
|
|
2
|
-
import type { PolicyIR } from '../ir/types.ts';
|
|
3
|
-
import type { Network, ProposedPolicy, RecordedTransaction, ScVal } from '../types.ts';
|
|
4
|
-
/** INPUT: something that produces a normalized RecordedTransaction. */
|
|
5
|
-
export interface PolicySource {
|
|
6
|
-
readonly name: string;
|
|
7
|
-
capture(input: {
|
|
8
|
-
hash?: string;
|
|
9
|
-
xdr?: string;
|
|
10
|
-
network: Network;
|
|
11
|
-
}): Promise<ToolResponse<RecordedTransaction>>;
|
|
12
|
-
}
|
|
13
|
-
/** DECODE: chain-specific call data -> the normalized facts the synth reasons
|
|
14
|
-
* over. */
|
|
15
|
-
export interface ChainDecoder {
|
|
16
|
-
readonly chain: 'stellar' | 'evm';
|
|
17
|
-
decodeInvocation(tx: RecordedTransaction): {
|
|
18
|
-
contract: string;
|
|
19
|
-
method: string;
|
|
20
|
-
args: ScVal[];
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
/** OZ = enforce; `log_only` is reserved for shadow mode (out of scope). */
|
|
24
|
-
export type CustodyMode = 'enforce' | 'log_only';
|
|
25
|
-
/** What a backend can express. A construct needing a false flag is flagged
|
|
26
|
-
* `uncovered` by the adapter, never silently dropped. */
|
|
27
|
-
export interface CustodyCapabilities {
|
|
28
|
-
supportsOraclePrice: boolean;
|
|
29
|
-
supportsSpendWindow: boolean;
|
|
30
|
-
supportsInvocationCount: boolean;
|
|
31
|
-
supportsTimeExpiry: boolean;
|
|
32
|
-
supportsThreshold: boolean;
|
|
33
|
-
supportsGeneralPredicate: boolean;
|
|
34
|
-
}
|
|
35
|
-
/** The result of compiling a PolicyIR for one backend. */
|
|
36
|
-
export interface CompileResult {
|
|
37
|
-
/** false => some IR construct this backend cannot express (see `uncovered`). */
|
|
38
|
-
covered: boolean;
|
|
39
|
-
/** Human-readable list of unsupported constructs. */
|
|
40
|
-
uncovered: string[];
|
|
41
|
-
/** The backend-native installable policy, assembled when a rule lowered. */
|
|
42
|
-
proposed?: ProposedPolicy;
|
|
43
|
-
}
|
|
44
|
-
/** Result of a simulate() dry-run. `ts-model` is the off-chain TS evaluator.
|
|
45
|
-
* Real permit/deny semantics wiring is a later phase; week-1 returns a
|
|
46
|
-
* clearly-marked stub (empty `evaluations`, `permitted: null`). */
|
|
47
|
-
export interface SimulationResult {
|
|
48
|
-
backend: 'ts-model';
|
|
49
|
-
/** Whether the permit tx would be allowed; null until real semantics land. */
|
|
50
|
-
permitted: boolean | null;
|
|
51
|
-
/** Per-construct evaluation trace; empty placeholder in this slice. */
|
|
52
|
-
evaluations: unknown[];
|
|
53
|
-
/** Diagnostics; marks the stub explicitly. */
|
|
54
|
-
notes: string[];
|
|
55
|
-
}
|
|
56
|
-
/** OUTPUT: compile a PolicyIR to a backend-specific installable policy. */
|
|
57
|
-
export interface CustodyAdapter {
|
|
58
|
-
readonly name: string;
|
|
59
|
-
readonly mode: CustodyMode;
|
|
60
|
-
capabilities(): CustodyCapabilities;
|
|
61
|
-
compile(ir: PolicyIR): CompileResult;
|
|
62
|
-
/** Phase-03 wiring; a clearly-marked stub in week-1. */
|
|
63
|
-
simulate(ir: PolicyIR, permitTx: RecordedTransaction): SimulationResult;
|
|
64
|
-
/** Canonical JSON of the IR (portability / audit). */
|
|
65
|
-
export(ir: PolicyIR): string;
|
|
66
|
-
}
|
package/dist-cjs/seams/types.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// src/seams/types.ts - the three custody seams (contracts, not implementations).
|
|
3
|
-
//
|
|
4
|
-
// The synthesizer is decoupled from its edges by three seams:
|
|
5
|
-
// - PolicySource (INPUT): produces a normalized RecordedTransaction. The
|
|
6
|
-
// recorder is the reference source; a MandateSpec
|
|
7
|
-
// lowering is a second, deterministic source.
|
|
8
|
-
// - ChainDecoder (DECODE): chain-specific call data -> normalized facts.
|
|
9
|
-
// - CustodyAdapter (OUTPUT): compile a PolicyIR to a backend-native policy +
|
|
10
|
-
// verify/export it (OZ is the first adapter).
|
|
11
|
-
// These are INTERFACES only. Implementations live in their own modules.
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|