@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/codegen/template.js
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
// src/codegen/template.ts - deterministic Rust source generator for the OZ
|
|
2
|
-
// `Policy` escape-hatch skeleton.
|
|
3
|
-
//
|
|
4
|
-
// SUPERSEDED. The architecture this belongs to no longer exists. A deployed
|
|
5
|
-
// policy involves exactly two contracts, the OZ smart account and one
|
|
6
|
-
// immutable interpreter, and the synthesiser emits policy DATA rather than
|
|
7
|
-
// code. Nothing on the synthesis path reaches this module, and no install can
|
|
8
|
-
// produce a contract from it. When a constraint falls outside the grammar the
|
|
9
|
-
// answer is to version the synthesiser and the interpreter together, not to
|
|
10
|
-
// put unaudited Rust on chain per policy.
|
|
11
|
-
//
|
|
12
|
-
// Deleting it is a decision nobody has taken yet, not a dependency question.
|
|
13
|
-
// `compile-gate.ts` takes a Rust string and knows nothing about this module,
|
|
14
|
-
// and its tests compile a hardcoded fixture, so the gate keeps working either
|
|
15
|
-
// way. What deleting this would remove is the only in-repo producer of policy
|
|
16
|
-
// Rust for the gate to check. Do not read its presence as the product
|
|
17
|
-
// generating contracts, and do not wire it into the synthesis path.
|
|
18
|
-
//
|
|
19
|
-
// What follows describes the abandoned design.
|
|
20
|
-
//
|
|
21
|
-
// This is the LAST-RESORT tool for constraints the v1 DSL cannot express. It
|
|
22
|
-
// lives OUT of the audited happy-path surface; the synthesiser never emits it
|
|
23
|
-
// automatically. It mirrors Zodiac Roles' `Custom` operator: a hand-written
|
|
24
|
-
// (here: scaffolded) policy the operator assumes responsibility for.
|
|
25
|
-
//
|
|
26
|
-
// The skeleton carries five storage invariants the user MUST preserve when
|
|
27
|
-
// filling in the predicate logic:
|
|
28
|
-
// 1. `smart_account.require_auth()` is invoked INSIDE `enforce`.
|
|
29
|
-
// 2. Storage is keyed by the composite `(smart_account, rule_id)`.
|
|
30
|
-
// 3. Chain reads use `unwrap_or_default()` so a missing key is a permitted
|
|
31
|
-
// default, not a panic.
|
|
32
|
-
// 4. Storage is `persistent()` (NOT `instance()`) so the policy survives
|
|
33
|
-
// contract instance lifecycle changes.
|
|
34
|
-
// 5. `uninstall` removes the stored state.
|
|
35
|
-
//
|
|
36
|
-
// Determinism: same `(spec, name)` -> byte-identical output. No clock, no RNG,
|
|
37
|
-
// no environment reads.
|
|
38
|
-
/** Format a name for use as a Rust identifier. The input is constrained by
|
|
39
|
-
* the caller (a kebab-case policy name + alphanumeric addresses); this is a
|
|
40
|
-
* belt-and-braces sanitiser that maps anything non-identifier to '_'. */
|
|
41
|
-
function asRustIdent(s) {
|
|
42
|
-
let out = '';
|
|
43
|
-
for (let i = 0; i < s.length; i++) {
|
|
44
|
-
const ch = s.charCodeAt(i);
|
|
45
|
-
const ok = (ch >= 48 && ch <= 57) || // 0-9
|
|
46
|
-
(ch >= 65 && ch <= 90) || // A-Z
|
|
47
|
-
(ch >= 97 && ch <= 122) || // a-z
|
|
48
|
-
ch === 95; // _
|
|
49
|
-
out += ok ? s[i] : '_';
|
|
50
|
-
}
|
|
51
|
-
// Identifiers may not start with a digit.
|
|
52
|
-
if (out.length > 0 && out.charCodeAt(0) >= 48 && out.charCodeAt(0) <= 57) {
|
|
53
|
-
out = `_${out}`;
|
|
54
|
-
}
|
|
55
|
-
return out || 'policy';
|
|
56
|
-
}
|
|
57
|
-
/** Render the `uncovered` list as a `//` comment block (one line per item). */
|
|
58
|
-
function renderUncovered(uncovered) {
|
|
59
|
-
if (uncovered.length === 0) {
|
|
60
|
-
return ' // (no specific uncovered constructs reported)';
|
|
61
|
-
}
|
|
62
|
-
return uncovered.map((line) => ` // - ${line}`).join('\n');
|
|
63
|
-
}
|
|
64
|
-
/** Generate a deterministic OZ `Policy` skeleton for an uncovered constraint.
|
|
65
|
-
*
|
|
66
|
-
* The skeleton is NOT a finished policy; the user fills in the predicate
|
|
67
|
-
* logic in the marked TODO(user) holes and audits the result themselves.
|
|
68
|
-
*
|
|
69
|
-
* Same `(spec, name)` always produces byte-identical output. */
|
|
70
|
-
export function generateRust(spec, name) {
|
|
71
|
-
const _contract = spec.contract;
|
|
72
|
-
const _fnName = spec.fnName ?? 'enforce';
|
|
73
|
-
const structName = asRustIdent(name);
|
|
74
|
-
const _dataKeyName = `${asRustIdent(name)}_data`;
|
|
75
|
-
const uncoveredBlock = renderUncovered(spec.uncovered);
|
|
76
|
-
return `// Auto-generated by the OZ Policy Builder codegen escape hatch.
|
|
77
|
-
// THIS OUTPUT IS THE USER'S TO COMPLETE AND AUDIT.
|
|
78
|
-
// The synthesiser never emits it on the happy path; reach for it only when
|
|
79
|
-
// a constraint cannot be expressed in the v1 DSL grammar (same shape as
|
|
80
|
-
// Zodiac Roles' \`Custom\` operator).
|
|
81
|
-
|
|
82
|
-
#![no_std]
|
|
83
|
-
|
|
84
|
-
use soroban_sdk::{contract, contractimpl, contracttype, Address, Env, Vec};
|
|
85
|
-
|
|
86
|
-
#[contracttype]
|
|
87
|
-
pub enum DataKey {
|
|
88
|
-
/// Composite key \`(smart_account, rule_id)\` so multiple policies on
|
|
89
|
-
/// one smart account coexist without collision.
|
|
90
|
-
State(Address, u32),
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
#[contract]
|
|
94
|
-
pub struct ${structName};
|
|
95
|
-
|
|
96
|
-
#[contractimpl]
|
|
97
|
-
impl ${structName} {
|
|
98
|
-
pub fn install(e: &Env, smart_account: Address, rule_id: u32) {
|
|
99
|
-
// TODO(user): initialise policy state for this (smart_account, rule_id).
|
|
100
|
-
// The skeleton leaves the stored value empty; the predicate body
|
|
101
|
-
// (in \`enforce\`) decides what to read.
|
|
102
|
-
e.storage().persistent().set(
|
|
103
|
-
&DataKey::State(smart_account.clone(), rule_id),
|
|
104
|
-
&(),
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
pub fn enforce(
|
|
109
|
-
e: &Env,
|
|
110
|
-
smart_account: Address,
|
|
111
|
-
rule_id: u32,
|
|
112
|
-
_signers: Vec<Address>,
|
|
113
|
-
) {
|
|
114
|
-
// Invariant 1: authorise the smart account BEFORE any state read or
|
|
115
|
-
// predicate evaluation. Removing this call opens the policy to
|
|
116
|
-
// impersonation by any caller with a valid rule_id.
|
|
117
|
-
smart_account.require_auth();
|
|
118
|
-
|
|
119
|
-
// Invariant 2 + 4: read stored state through the composite key on
|
|
120
|
-
// \`persistent()\` storage. \`unwrap_or_default()\` (invariant 3)
|
|
121
|
-
// makes an empty key a permitted default rather than a panic.
|
|
122
|
-
let _state: () = e
|
|
123
|
-
.storage()
|
|
124
|
-
.persistent()
|
|
125
|
-
.get(&DataKey::State(smart_account.clone(), rule_id))
|
|
126
|
-
.unwrap_or_default();
|
|
127
|
-
|
|
128
|
-
// --- uncovered constraints the v1 DSL refused to express ---
|
|
129
|
-
${uncoveredBlock}
|
|
130
|
-
|
|
131
|
-
// TODO(user): replace the placeholder below with the real predicate
|
|
132
|
-
// body. The recorded flow's \`(contract, fn_name, args)\` is the
|
|
133
|
-
// single authorised call \`Policy::enforce\` receives; match against
|
|
134
|
-
// \`e\` here.
|
|
135
|
-
let _ = (_state, &e);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
pub fn uninstall(e: &Env, smart_account: Address, rule_id: u32) {
|
|
139
|
-
// Invariant 5: \`uninstall\` removes the stored state so a subsequent
|
|
140
|
-
// install starts from a clean slate (and the nonce returns to its
|
|
141
|
-
// post-uninstall value).
|
|
142
|
-
e.storage()
|
|
143
|
-
.persistent()
|
|
144
|
-
.remove(&DataKey::State(smart_account, rule_id));
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
`;
|
|
148
|
-
}
|
|
@@ -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 };
|