@crediolabs/policy-synth 0.2.0 → 0.3.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/README.md +4 -4
- package/dist/adapters/interpreter/adapter.d.ts +19 -25
- package/dist/adapters/interpreter/adapter.js +54 -487
- package/dist/adapters/interpreter/index.d.ts +1 -1
- package/dist/adapters/interpreter/index.js +1 -1
- package/dist/adapters/oz/adapter.js +1 -15
- 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/ir/index.d.ts +1 -1
- package/dist/ir/types.d.ts +7 -76
- package/dist/ir/types.js +0 -2
- 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/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/seams/types.d.ts +0 -2
- package/dist/simulate/deny-cases.d.ts +26 -0
- 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/deny-cases.d.ts +5 -7
- package/dist/synth/deny-cases.js +23 -373
- package/dist/synth/evaluate.d.ts +0 -21
- package/dist/synth/evaluate.js +56 -336
- package/dist/synth/index.d.ts +0 -5
- package/dist/synth/index.js +0 -5
- package/dist/synth/permit-context.d.ts +2 -9
- package/dist/synth/permit-context.js +1 -82
- 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/verify/simulate.d.ts +1 -14
- package/dist/verify/simulate.js +2 -88
- package/dist/verify/verify.d.ts +1 -7
- package/dist/verify/verify.js +0 -8
- package/dist-cjs/adapters/interpreter/adapter.d.ts +19 -25
- package/dist-cjs/adapters/interpreter/adapter.js +56 -489
- package/dist-cjs/adapters/interpreter/index.d.ts +1 -1
- package/dist-cjs/adapters/interpreter/index.js +1 -2
- package/dist-cjs/adapters/oz/adapter.js +1 -15
- 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/ir/index.d.ts +1 -1
- package/dist-cjs/ir/types.d.ts +7 -76
- package/dist-cjs/ir/types.js +0 -2
- 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/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/seams/types.d.ts +0 -2
- package/dist-cjs/simulate/deny-cases.d.ts +26 -0
- 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/deny-cases.d.ts +5 -7
- package/dist-cjs/synth/deny-cases.js +23 -374
- package/dist-cjs/synth/evaluate.d.ts +0 -21
- package/dist-cjs/synth/evaluate.js +57 -337
- package/dist-cjs/synth/index.d.ts +0 -5
- package/dist-cjs/synth/index.js +1 -11
- package/dist-cjs/synth/permit-context.d.ts +2 -9
- package/dist-cjs/synth/permit-context.js +1 -82
- 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/dist-cjs/verify/simulate.d.ts +1 -14
- package/dist-cjs/verify/simulate.js +2 -88
- package/dist-cjs/verify/verify.d.ts +1 -7
- package/dist-cjs/verify/verify.js +0 -8
- package/package.json +4 -4
- 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/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/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-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/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/src/types.ts
CHANGED
|
@@ -64,13 +64,11 @@ export const MAX_SCVAL_CLONE_DEPTH = 30 as const
|
|
|
64
64
|
* - MAX_DEPTH = 5: 3 walkthroughs need depth 2; budget = 2x growth + 1 for `not` chain.
|
|
65
65
|
* - MAX_LEAVES = 200: allowlists (recipients, paths) typically < 100; budget = 2x + 1 nested allowlist.
|
|
66
66
|
* - MAX_PREDICATE_BYTES = 32 KB: well under the per-ledger-entry 64 KB persistent-storage limit.
|
|
67
|
-
* - MAX_ORACLE_READS = 6: two-round confirmation per asset consumes 2 reads; cap accommodates a predicate that references up to 3 unique oracle assets (3 * 2 = 6 reads). Stays a fail-closed install-time cap.
|
|
68
67
|
* - MAX_IN_OPERAND_COUNT = 32: allowlist < 32 is a UX-natural bound. */
|
|
69
68
|
export const PREDICATE_CAPS = {
|
|
70
69
|
MAX_DEPTH: 5,
|
|
71
70
|
MAX_LEAVES: 200,
|
|
72
71
|
MAX_PREDICATE_BYTES: 32 * 1024,
|
|
73
|
-
MAX_ORACLE_READS: 6,
|
|
74
72
|
MAX_IN_OPERAND_COUNT: 32,
|
|
75
73
|
} as const
|
|
76
74
|
|
|
@@ -97,15 +95,23 @@ export type SignerDraft =
|
|
|
97
95
|
| { kind: 'external'; verifier: string; keyBytes: string }
|
|
98
96
|
|
|
99
97
|
/** Reference to one policy attached to a context rule. */
|
|
100
|
-
export type PolicyRef =
|
|
101
|
-
|
|
102
|
-
|
|
98
|
+
export type PolicyRef = {
|
|
99
|
+
kind: 'interpreter'
|
|
100
|
+
interpreterAddress: string
|
|
101
|
+
predicateBlobBase64: string
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Grammar version baked into the interpreter wasm, mirroring `SELF_VERSION` in
|
|
105
|
+
* `contracts/policy-interpreter/src/version.rs`. Every value this package puts on
|
|
106
|
+
* the wire derives from here; `grammar-version-parity.test.ts` pins it to the
|
|
107
|
+
* contract so a skew cannot pass a green test run. */
|
|
108
|
+
export const GRAMMAR_VERSION = 3 as const
|
|
103
109
|
|
|
104
110
|
/** A serialised predicate document stored against a (smart_account, rule_id) pair. */
|
|
105
111
|
export interface PolicyDocument {
|
|
106
112
|
/** Grammar version baked into the interpreter wasm. Fail-closed strict match at install
|
|
107
113
|
* AND at evaluate (defence in depth). NOT the per-edit revision. */
|
|
108
|
-
grammarVersion:
|
|
114
|
+
grammarVersion: typeof GRAMMAR_VERSION
|
|
109
115
|
/** Per-rule install nonce. Must equal the interpreter's stored nonce + 1 at install.
|
|
110
116
|
* First install accepts nonce = 1 with stored nonce = 0. Re-install is structurally
|
|
111
117
|
* possible by incrementing the nonce; uninstall removes the nonce with state so a
|
|
@@ -117,24 +123,13 @@ export interface PolicyDocument {
|
|
|
117
123
|
/** Hash of the post-canonicalisation bytes of encodedPredicate. Stored alongside the
|
|
118
124
|
* doc and re-verified at evaluate. */
|
|
119
125
|
predicateHash: string
|
|
120
|
-
/** Per-policy overrides of oracle thresholds; absent = use defaults.
|
|
121
|
-
* Overrides may TIGHTEN only (never widen) - the interpreter rejects any per-policy
|
|
122
|
-
* value looser than the wasm-level defaults at install. */
|
|
123
|
-
oracleParams?: {
|
|
124
|
-
/** Seconds; must be <= MAX_ORACLE_STALENESS_SECONDS (600). */
|
|
125
|
-
maxStalenessSeconds?: number
|
|
126
|
-
/** Basis points; must be <= MAX_ORACLE_DEVIATION_BPS (200). */
|
|
127
|
-
maxDeviationBps?: number
|
|
128
|
-
}
|
|
129
126
|
}
|
|
130
127
|
|
|
131
128
|
/** The versioned predicate AST (interpreter side). Tagged union. */
|
|
132
129
|
export type PredicateNode =
|
|
133
130
|
| { op: 'and'; children: PredicateNode[] }
|
|
134
|
-
| { op: 'or'; children: PredicateNode[] }
|
|
135
|
-
| { op: 'not'; child: PredicateNode }
|
|
136
131
|
| { op: 'eq'; left: PredicateLeaf; right: PredicateLeaf }
|
|
137
|
-
| { op: '
|
|
132
|
+
| { op: 'lte'; left: PredicateLeaf; right: PredicateLeaf }
|
|
138
133
|
| {
|
|
139
134
|
op: 'in'
|
|
140
135
|
needle: PredicateLeaf
|
|
@@ -155,48 +150,18 @@ export type PredicateLeaf =
|
|
|
155
150
|
// recorded ScVal type. A non-vec arg, missing element, missing field, or
|
|
156
151
|
// type mismatch all DENY (fail-closed).
|
|
157
152
|
| { kind: 'call_arg_field'; index: number; element: number; field: string }
|
|
158
|
-
// `call_arg_scaled(index, num, den)` evaluates to `args[index] * num / den`
|
|
159
|
-
// (truncating toward zero). The slippage-floor leaf: a swap policy
|
|
160
|
-
// expresses `call_arg[out] >= call_arg_scaled(in, num, den)` as "the
|
|
161
|
-
// minimum output must be at least this ratio of the input". `num`/`den`
|
|
162
|
-
// are decimal strings on i128 (mirrors `literal_i128`); the contract
|
|
163
|
-
// refuses `den == 0` and `num <= 0` / `den <= 0` at install.
|
|
164
|
-
| { kind: 'call_arg_scaled'; index: number; num: string; den: string }
|
|
165
|
-
// `call_sub_invocation[i]` is NOT in v1 grammar. OZ `Policy::enforce`
|
|
166
|
-
// receives one `Context`, not a sub-invocation tree; sub-invocations live under
|
|
167
|
-
// `InvokerContractAuthEntry::Contract(SubContractInvocation)`, not in the
|
|
168
|
-
// enforce Context. Scope is per-authorized-context; a v1.1 sub-invocation
|
|
169
|
-
// tree leaf is gated on the enforce-Context-shape spike result.
|
|
170
|
-
| { kind: 'amount'; token: string }
|
|
171
|
-
| { kind: 'window_spent'; token: string; windowSeconds: number }
|
|
172
|
-
| { kind: 'now' }
|
|
173
|
-
| { kind: 'valid_until' }
|
|
174
|
-
| { kind: 'invocation_count_in_window'; windowSecs: number }
|
|
175
|
-
| { kind: 'oracle_price'; asset: string } // Stellar Address (SAC address for SEP-41; XLM uses its network SAC)
|
|
176
|
-
// The right-hand side of an oracle comparison. It carries its own decimal
|
|
177
|
-
// basis because the contract cannot recover it: prices normalise to 9 dp, so
|
|
178
|
-
// a raw 14-dp threshold is ~10^5 too large and `price <= threshold` becomes
|
|
179
|
-
// trivially true. `value` is a decimal string on i128, like `literal_i128`.
|
|
180
|
-
| { kind: 'oracle_threshold'; value: string; decimals: number }
|
|
181
153
|
// Literal leaves: bare ScVal on the wire (no selector-tuple wrapper). Right-hand side of
|
|
182
154
|
// comparisons, elements of `in` haystacks, and operands to future arithmetic nodes.
|
|
183
155
|
| { kind: 'literal_address'; value: string }
|
|
184
156
|
| { kind: 'literal_i128'; value: string }
|
|
185
157
|
| { kind: 'literal_symbol'; value: string }
|
|
186
158
|
| { kind: 'literal_u32'; value: number }
|
|
187
|
-
| { kind: 'literal_u64'; value: string }
|
|
188
|
-
| { kind: 'literal_bytes'; value: string } // hex string; wrapped as ScVal::Bytes at encode time
|
|
189
159
|
// Exact ordered vector of literals (e.g. a swap hop path). Encodes to a bare
|
|
190
160
|
// ScVal::Vec with the caller's order preserved verbatim - the order IS the
|
|
191
161
|
// semantic. An exact ordered sequence equality is expressed by `eq(selector,
|
|
192
162
|
// literal_vec([...]))`. `in` is reserved for pure set membership (sorted).
|
|
193
163
|
| { kind: 'literal_vec'; elements: PredicateLeaf[] }
|
|
194
164
|
|
|
195
|
-
export interface OZPrimitiveConfig {
|
|
196
|
-
primitive: 'spending_limit' | 'simple_threshold' | 'weighted_threshold'
|
|
197
|
-
params: Record<string, unknown>
|
|
198
|
-
}
|
|
199
|
-
|
|
200
165
|
export interface ContractInvocation {
|
|
201
166
|
contract: string
|
|
202
167
|
fn: string
|
|
@@ -263,7 +228,6 @@ export type AmbiguityCode =
|
|
|
263
228
|
| 'AMOUNT_BOUND_MISSING'
|
|
264
229
|
| 'RECIPIENT_ALLOWLIST_EMPTY'
|
|
265
230
|
| 'FREQUENCY_BOUND_MISSING'
|
|
266
|
-
| 'ORACLE_ASSET_UNKNOWN'
|
|
267
231
|
| 'MULTIPLE_UNRELATED_TARGETS'
|
|
268
232
|
|
|
269
233
|
/** Structured recording freshness. `overall` is the gate threshold (default 1.0); the
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import type { PredicateNode, SignerDraft } from '../types.ts';
|
|
2
|
-
/** Wildcard component of a `Selector`: the predicate does not pin this half. */
|
|
3
|
-
export declare const ANY = "*";
|
|
4
|
-
/** A (contract, function) pair a predicate may permit. `ANY` in either half
|
|
5
|
-
* means unconstrained, so `{contract: ANY, fn: ANY}` is "any call at all". */
|
|
6
|
-
export interface Selector {
|
|
7
|
-
contract: string;
|
|
8
|
-
fn: string;
|
|
9
|
-
}
|
|
10
|
-
export type ContextType = {
|
|
11
|
-
kind: 'default';
|
|
12
|
-
} | {
|
|
13
|
-
kind: 'call_contract';
|
|
14
|
-
address: string;
|
|
15
|
-
} | {
|
|
16
|
-
kind: 'create_contract';
|
|
17
|
-
wasmHash: string;
|
|
18
|
-
};
|
|
19
|
-
/** How much we can say about a neighbouring rule.
|
|
20
|
-
* - `interpreter`: policed by our interpreter and the predicate was readable,
|
|
21
|
-
* so its authority is known exactly and it can be merged.
|
|
22
|
-
* - `foreign`: policed by some other contract. The address is visible, the
|
|
23
|
-
* semantics are not, so it must be reviewed by hand.
|
|
24
|
-
* - `unpoliced`: no policy at all. Whatever the rule's context type allows,
|
|
25
|
-
* its signers may do without constraint. */
|
|
26
|
-
export type RuleClass = 'interpreter' | 'foreign' | 'unpoliced';
|
|
27
|
-
export interface ObservedRule {
|
|
28
|
-
id: number;
|
|
29
|
-
contextType: ContextType;
|
|
30
|
-
signers: SignerDraft[];
|
|
31
|
-
/** Policy contract addresses attached to the rule, in OZ's order. */
|
|
32
|
-
policyAddresses: string[];
|
|
33
|
-
/** OZ's global registry ids for those policies, index-aligned with
|
|
34
|
-
* `policyAddresses`. `remove_policy` takes the id, not the address, so
|
|
35
|
-
* detaching a policy is impossible without them. */
|
|
36
|
-
policyIds?: number[];
|
|
37
|
-
/** Per-policy oracle bounds from the stored document, when it was
|
|
38
|
-
* readable. A merge must re-install these or it silently widens them. */
|
|
39
|
-
oracleBounds?: {
|
|
40
|
-
maxStalenessSeconds?: number;
|
|
41
|
-
maxDeviationBps?: number;
|
|
42
|
-
maxCrossFeedDeviationBps?: number;
|
|
43
|
-
};
|
|
44
|
-
/** Decoded predicate. Present only when the rule is policed by our
|
|
45
|
-
* interpreter AND the stored document was readable. */
|
|
46
|
-
predicate?: PredicateNode;
|
|
47
|
-
}
|
|
48
|
-
export interface IntendedInstall {
|
|
49
|
-
/** Rule the predicate is being installed onto. A re-install onto the same
|
|
50
|
-
* id is a replacement, not an overlap, so this id is skipped. */
|
|
51
|
-
ruleId: number;
|
|
52
|
-
contextType: ContextType;
|
|
53
|
-
signers: SignerDraft[];
|
|
54
|
-
predicate: PredicateNode;
|
|
55
|
-
}
|
|
56
|
-
export type OverlapSeverity =
|
|
57
|
-
/** A neighbouring rule imposes no constraint at all on the shared calls. */
|
|
58
|
-
'bypass'
|
|
59
|
-
/** A neighbouring policy exists but we cannot read what it permits. */
|
|
60
|
-
| 'unknown'
|
|
61
|
-
/** Both rules are ours. The new rule will not restrict the shared calls,
|
|
62
|
-
* because the signer can name whichever rule is more permissive. */
|
|
63
|
-
| 'not-restricting';
|
|
64
|
-
export interface AuthorityOverlap {
|
|
65
|
-
ruleId: number;
|
|
66
|
-
ruleClass: RuleClass;
|
|
67
|
-
severity: OverlapSeverity;
|
|
68
|
-
/** Signers present in both rules. Overlap is only reachable by a signer who
|
|
69
|
-
* can name both rules, so a rule sharing no signer is not a collision. */
|
|
70
|
-
sharedSigners: SignerDraft[];
|
|
71
|
-
/** The selectors both rules can serve. Non-empty by construction. */
|
|
72
|
-
sharedSelectors: Selector[];
|
|
73
|
-
/** True when the neighbour is ours and can therefore be replaced by the
|
|
74
|
-
* conjunction of the two predicates. */
|
|
75
|
-
mergeable: boolean;
|
|
76
|
-
advice: string;
|
|
77
|
-
}
|
|
78
|
-
/** Canonical key for signer equality. Mirrors OZ's `Signer` enum: a delegated
|
|
79
|
-
* signer is its address, an external signer is the verifier plus the key
|
|
80
|
-
* bytes, since one verifier may hold many keys. */
|
|
81
|
-
export declare function signerKey(s: SignerDraft): string;
|
|
82
|
-
/** Intersection of two selector SETS: every compatible pairing survives. */
|
|
83
|
-
export declare function intersectSelectors(a: Selector[], b: Selector[]): Selector[];
|
|
84
|
-
/**
|
|
85
|
-
* The set of `(contract, fn)` selectors a predicate may permit.
|
|
86
|
-
*
|
|
87
|
-
* This is a deliberate OVER-approximation: every call the predicate actually
|
|
88
|
-
* permits is covered by some returned selector, and unrecognised structure
|
|
89
|
-
* widens to the wildcard rather than narrowing. That direction is what makes
|
|
90
|
-
* the emptiness test below sound. A call carries exactly one `(contract, fn)`,
|
|
91
|
-
* so if two predicates' over-approximations do not intersect, no single call
|
|
92
|
-
* can be routed to either of them and the rules provably cannot collide.
|
|
93
|
-
*
|
|
94
|
-
* `not` is treated as unconstrained. Complementing a selector set would need
|
|
95
|
-
* the universe of addresses and function names, which is not available and
|
|
96
|
-
* would not be sound to guess.
|
|
97
|
-
*/
|
|
98
|
-
export declare function permittedSelectors(node: PredicateNode): Selector[];
|
|
99
|
-
/** Selectors a context type admits, before the predicate narrows them. */
|
|
100
|
-
export declare function selectorsForContextType(ct: ContextType): Selector[];
|
|
101
|
-
/** What a rule can actually authorise: its context type narrowed by its
|
|
102
|
-
* predicate. An unpoliced or unreadable rule contributes no narrowing. */
|
|
103
|
-
export declare function effectiveSelectors(rule: ObservedRule): Selector[];
|
|
104
|
-
/**
|
|
105
|
-
* Every existing rule that a signer of the intended install could name instead.
|
|
106
|
-
*
|
|
107
|
-
* A rule collides when it shares at least one signer AND at least one selector,
|
|
108
|
-
* because both conditions are needed for the signer to have a choice. The rule
|
|
109
|
-
* being installed onto is skipped: re-installing over it replaces its
|
|
110
|
-
* predicate rather than adding a second source of authority.
|
|
111
|
-
*/
|
|
112
|
-
export declare function findAuthorityOverlaps(args: {
|
|
113
|
-
intended: IntendedInstall;
|
|
114
|
-
existing: ObservedRule[];
|
|
115
|
-
}): AuthorityOverlap[];
|
|
116
|
-
export interface MergeResult {
|
|
117
|
-
ok: boolean;
|
|
118
|
-
predicate?: PredicateNode;
|
|
119
|
-
/** Set when `ok` is false. */
|
|
120
|
-
reason?: string;
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Conjunction of an existing predicate with a new one, for the tightening case.
|
|
124
|
-
*
|
|
125
|
-
* `and` children are flattened so repeated merges do not nest, which keeps the
|
|
126
|
-
* encoded form closer to the byte cap.
|
|
127
|
-
*
|
|
128
|
-
* The guard matters more than the merge. `and` is only correct when the caller
|
|
129
|
-
* means to tighten. Applied to two predicates that pin DIFFERENT selectors it
|
|
130
|
-
* produces a predicate permitting nothing, which silently disables the policy
|
|
131
|
-
* instead of restricting it. That case is refused, because the caller wanted
|
|
132
|
-
* two capabilities and two rules already express that correctly.
|
|
133
|
-
*/
|
|
134
|
-
export declare function mergeIntoAnd(existing: PredicateNode, incoming: PredicateNode): MergeResult;
|
|
Binary file
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { Contract } from '@stellar/stellar-sdk';
|
|
2
|
-
import type { InstallRpcClient } from './build-install-policy.ts';
|
|
3
|
-
/** Inputs for the install-predicate build. */
|
|
4
|
-
export interface BuildInstallPredicateArgs {
|
|
5
|
-
/** The smart account contract address (C...). The interpreter hashes
|
|
6
|
-
* this rule's `signers` at install; we fetch it via `get_context_rule`
|
|
7
|
-
* on this address, not reconstruct it. */
|
|
8
|
-
smartAccount: string;
|
|
9
|
-
/** The signer that authorises the install (G... wallet). */
|
|
10
|
-
sourceAccount: string;
|
|
11
|
-
/** The rule id the account assigned in call 1. */
|
|
12
|
-
ruleId: number;
|
|
13
|
-
/** The interpreter contract address (C...). */
|
|
14
|
-
interpreterAddress: string;
|
|
15
|
-
/** Network passphrase - pins the hash the auth digest binds. */
|
|
16
|
-
networkPassphrase: string;
|
|
17
|
-
/** Already-encoded (base64) canonical ScVal of the predicate. */
|
|
18
|
-
encodedPredicate: string;
|
|
19
|
-
/** Hex sha256 of the canonical predicate XDR bytes. */
|
|
20
|
-
predicateHash: string;
|
|
21
|
-
/** Grammar version override; defaults to 1. */
|
|
22
|
-
grammarVersion?: number;
|
|
23
|
-
/** Base fee in stroops; defaults to BASE_FEE (100). */
|
|
24
|
-
baseFee?: number;
|
|
25
|
-
/** RPC client to use for the simulation pass; injected for tests. */
|
|
26
|
-
rpc: InstallRpcClient;
|
|
27
|
-
/** Ledger window (in ledgers) for the auth entry's `validUntil`. */
|
|
28
|
-
authValidUntilLedgers?: number;
|
|
29
|
-
}
|
|
30
|
-
/** Human-readable description of the install-predicate call, decoded FROM
|
|
31
|
-
* the built XDR (not from the input args). The wallet signature binds
|
|
32
|
-
* to bytes; the review card has to bind to the same bytes, so this is
|
|
33
|
-
* the only safe source.
|
|
34
|
-
*
|
|
35
|
-
* `ruleId` is NOT decoded from the XDR - it lives inside
|
|
36
|
-
* `raw_context_rule`, which is passed through verbatim. Decoding it
|
|
37
|
-
* here would re-introduce the client-side reconstruction the file
|
|
38
|
-
* header warns against. The top-level `BuildInstallPredicateResult`
|
|
39
|
-
* echoes the caller-supplied rule id instead. */
|
|
40
|
-
export interface InstallPredicateCallDescribes {
|
|
41
|
-
/** The interpreter that will hold the predicate. */
|
|
42
|
-
targetContract: string;
|
|
43
|
-
/** The fn name on the target (always `install` today). */
|
|
44
|
-
fnName: 'install';
|
|
45
|
-
/** Grammar version the interpreter enforces; read off the wire. */
|
|
46
|
-
grammarVersion: number;
|
|
47
|
-
/** Per-rule install nonce; read off the wire. */
|
|
48
|
-
installNonce: number;
|
|
49
|
-
/** Hex sha256 of the encoded predicate blob; read off the wire. */
|
|
50
|
-
predicateHash: string;
|
|
51
|
-
/** Hex sha256 of the predicate bytes embedded in the params map. The
|
|
52
|
-
* two values MUST match; a difference is a wire tampering signal. */
|
|
53
|
-
predicateSha256OfEmbeddedBytes: string;
|
|
54
|
-
/** The smart account address encoded in args[2], read off the wire. */
|
|
55
|
-
smartAccountOnWire: string;
|
|
56
|
-
}
|
|
57
|
-
/** Output of the install-predicate build. The unsigned XDR is the
|
|
58
|
-
* wallet's input; the wallet signs it (single envelope signature) and
|
|
59
|
-
* submits. The auth tree matches install_policy: account entry
|
|
60
|
-
* carrying OZ's AuthPayload + a source-account delegated signer entry.
|
|
61
|
-
* Both are covered by the envelope signature. */
|
|
62
|
-
export interface BuildInstallPredicateResult {
|
|
63
|
-
/** Unsigned Soroban transaction envelope, base64 XDR. */
|
|
64
|
-
unsignedXdr: string;
|
|
65
|
-
/** Smart account contract address (echo). */
|
|
66
|
-
smartAccount: string;
|
|
67
|
-
/** Source account (echo) - the address that signs the envelope. */
|
|
68
|
-
sourceAccount: string;
|
|
69
|
-
/** The interpreter contract address (echo). */
|
|
70
|
-
interpreterAddress: string;
|
|
71
|
-
/** The rule id the account assigned in call 1 (echo). */
|
|
72
|
-
ruleId: number;
|
|
73
|
-
/** The host-call target + fn name. */
|
|
74
|
-
call: {
|
|
75
|
-
contract: string;
|
|
76
|
-
fn: 'install';
|
|
77
|
-
};
|
|
78
|
-
/** The smart-account auth nonce (snapshot). */
|
|
79
|
-
authNonce: string;
|
|
80
|
-
/** The ledger sequence + window the auth entry expires at. */
|
|
81
|
-
authValidUntilLedger: number;
|
|
82
|
-
/** The captured rootInvocation for the smart-account entry. */
|
|
83
|
-
rootInvocationXdr: string;
|
|
84
|
-
/** Human-readable description of the install call, decoded FROM the
|
|
85
|
-
* built unsigned XDR (not from the input args). The wallet signature
|
|
86
|
-
* binds to bytes; the review card has to bind to the same bytes, so
|
|
87
|
-
* this is the only safe source. */
|
|
88
|
-
describes: InstallPredicateCallDescribes;
|
|
89
|
-
}
|
|
90
|
-
/** Build the unsigned transaction envelope for
|
|
91
|
-
* `interpreter.install(params, raw_context_rule, smart_account)`. The
|
|
92
|
-
* output XDR is signed by the wallet, not by us. */
|
|
93
|
-
export declare function buildInstallPredicateXdr(args: BuildInstallPredicateArgs): Promise<BuildInstallPredicateResult>;
|
|
94
|
-
/** Re-export `Contract` so the run-layer does not need to import the
|
|
95
|
-
* SDK directly. Mirrors the build-install-policy.ts convention. */
|
|
96
|
-
export { Contract };
|