@crediolabs/policy-synth 0.1.17 → 0.2.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 +44 -246
- package/dist/adapters/interpreter/adapter.d.ts +6 -7
- package/dist/adapters/interpreter/adapter.js +28 -48
- package/dist/adapters/oz/adapter.js +12 -13
- package/dist/codegen/compile-gate.js +5 -0
- package/dist/codegen/template.js +17 -0
- package/dist/install/authority-overlap.d.ts +134 -0
- package/dist/install/authority-overlap.js +0 -0
- package/dist/install/build-add-context-rule.d.ts +8 -0
- package/dist/install/build-add-context-rule.js +17 -46
- package/dist/install/build-install-policy.d.ts +12 -5
- package/dist/install/build-install-policy.js +32 -23
- package/dist/install/build-merge-policy.d.ts +70 -0
- package/dist/install/build-merge-policy.js +130 -0
- package/dist/install/get-interpreter-info.js +2 -2
- package/dist/install/index.d.ts +3 -1
- package/dist/install/index.js +8 -1
- package/dist/install/oz-auth.js +5 -3
- package/dist/install/plan-merge-policy.d.ts +49 -0
- package/dist/install/plan-merge-policy.js +86 -0
- package/dist/install/read-account-rules.d.ts +100 -0
- package/dist/install/read-account-rules.js +283 -0
- package/dist/predicate/decode.js +1 -1
- package/dist/predicate/encode.js +171 -10
- package/dist/record/decode.js +5 -6
- package/dist/registry/protocols.d.ts +1 -1
- package/dist/registry/protocols.js +1 -1
- package/dist/review-card/builder.d.ts +6 -0
- package/dist/review-card/builder.js +9 -1
- package/dist/run/index.d.ts +104 -18
- package/dist/run/index.js +359 -75
- package/dist/run/schemas.d.ts +479 -18
- package/dist/run/schemas.js +132 -24
- package/dist/synth/compose-from-recording.d.ts +10 -15
- package/dist/synth/compose-from-recording.js +79 -124
- package/dist/synth/deny-cases.d.ts +5 -0
- package/dist/synth/deny-cases.js +52 -13
- package/dist/synth/evaluate.js +69 -119
- package/dist/synth/harness.d.ts +13 -1
- package/dist/synth/harness.js +22 -1
- package/dist/synth/index.d.ts +1 -1
- package/dist/synth/synthesize-from-recording.d.ts +31 -21
- package/dist/synth/synthesize-from-recording.js +129 -155
- package/dist-cjs/adapters/interpreter/adapter.d.ts +6 -7
- package/dist-cjs/adapters/interpreter/adapter.js +28 -48
- package/dist-cjs/adapters/oz/adapter.js +12 -13
- package/dist-cjs/codegen/compile-gate.js +5 -0
- package/dist-cjs/codegen/template.js +17 -0
- package/dist-cjs/install/authority-overlap.d.ts +134 -0
- package/dist-cjs/install/authority-overlap.js +0 -0
- package/dist-cjs/install/build-add-context-rule.d.ts +8 -0
- package/dist-cjs/install/build-add-context-rule.js +17 -45
- package/dist-cjs/install/build-install-policy.d.ts +12 -5
- package/dist-cjs/install/build-install-policy.js +32 -23
- package/dist-cjs/install/build-merge-policy.d.ts +70 -0
- package/dist-cjs/install/build-merge-policy.js +134 -0
- package/dist-cjs/install/get-interpreter-info.js +2 -2
- package/dist-cjs/install/index.d.ts +3 -1
- package/dist-cjs/install/index.js +24 -3
- package/dist-cjs/install/oz-auth.js +5 -3
- package/dist-cjs/install/plan-merge-policy.d.ts +49 -0
- package/dist-cjs/install/plan-merge-policy.js +90 -0
- package/dist-cjs/install/read-account-rules.d.ts +100 -0
- package/dist-cjs/install/read-account-rules.js +296 -0
- package/dist-cjs/predicate/decode.js +1 -1
- package/dist-cjs/predicate/encode.js +171 -10
- package/dist-cjs/record/decode.js +5 -6
- package/dist-cjs/registry/protocols.d.ts +1 -1
- package/dist-cjs/registry/protocols.js +1 -1
- package/dist-cjs/review-card/builder.d.ts +6 -0
- package/dist-cjs/review-card/builder.js +9 -1
- package/dist-cjs/run/index.d.ts +104 -18
- package/dist-cjs/run/index.js +360 -74
- package/dist-cjs/run/schemas.d.ts +479 -18
- package/dist-cjs/run/schemas.js +133 -25
- package/dist-cjs/synth/compose-from-recording.d.ts +10 -15
- package/dist-cjs/synth/compose-from-recording.js +79 -124
- package/dist-cjs/synth/deny-cases.d.ts +5 -0
- package/dist-cjs/synth/deny-cases.js +52 -13
- package/dist-cjs/synth/evaluate.js +69 -119
- package/dist-cjs/synth/harness.d.ts +13 -1
- package/dist-cjs/synth/harness.js +22 -1
- package/dist-cjs/synth/index.d.ts +1 -1
- package/dist-cjs/synth/synthesize-from-recording.d.ts +31 -21
- package/dist-cjs/synth/synthesize-from-recording.js +129 -153
- package/package.json +1 -1
- package/src/adapters/interpreter/adapter.ts +28 -48
- package/src/adapters/oz/adapter.ts +12 -13
- package/src/codegen/compile-gate.ts +5 -0
- package/src/codegen/template.ts +17 -0
- package/src/install/authority-overlap.ts +0 -0
- package/src/install/build-add-context-rule.ts +29 -56
- package/src/install/build-install-policy.ts +41 -23
- package/src/install/build-merge-policy.ts +219 -0
- package/src/install/get-interpreter-info.ts +2 -2
- package/src/install/index.ts +36 -2
- package/src/install/oz-auth.ts +5 -3
- package/src/install/plan-merge-policy.ts +133 -0
- package/src/install/read-account-rules.ts +376 -0
- package/src/predicate/decode.ts +1 -1
- package/src/predicate/encode.ts +176 -10
- package/src/record/decode.ts +5 -6
- package/src/registry/protocols.ts +1 -1
- package/src/review-card/builder.ts +17 -1
- package/src/run/index.ts +500 -102
- package/src/run/schemas.ts +145 -24
- package/src/synth/compose-from-recording.ts +87 -132
- package/src/synth/deny-cases.ts +59 -13
- package/src/synth/evaluate.ts +70 -118
- package/src/synth/harness.ts +29 -1
- package/src/synth/index.ts +1 -0
- package/src/synth/synthesize-from-recording.ts +209 -192
- package/src/contracts/policy-template/OZ_POLICY_TRAIT.md +0 -196
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
# OZ_POLICY_TRAIT.md — OpenZeppelin Stellar Accounts Pinned Trait Definitions
|
|
2
|
-
|
|
3
|
-
> **Pinned at:** `OpenZeppelin/stellar-contracts@v0.8.0-rc.3`
|
|
4
|
-
> **Commit SHA:** `4114bb8e2d7f090bdd9f45731e0607071d5ecea2`
|
|
5
|
-
> **Permalink:** https://github.com/OpenZeppelin/stellar-contracts/blob/4114bb8e2d7f090bdd9f45731e0607071d5ecea2/packages/accounts/src/policies/mod.rs
|
|
6
|
-
> **Policy trait file:** https://github.com/OpenZeppelin/stellar-contracts/blob/4114bb8e2d7f090bdd9f45731e0607071d5ecea2/packages/accounts/src/policies/mod.rs
|
|
7
|
-
> **Storage file (Signer, ContextRule, add_context_rule):** https://github.com/OpenZeppelin/stellar-contracts/blob/4114bb8e2d7f090bdd9f45731e0607071d5ecea2/packages/accounts/src/smart_account/storage.rs
|
|
8
|
-
> **Verified:** 2026-07-24 by W3 agent
|
|
9
|
-
|
|
10
|
-
---
|
|
11
|
-
|
|
12
|
-
## Policy Trait
|
|
13
|
-
|
|
14
|
-
Source: `packages/accounts/src/policies/mod.rs` (permalinked above)
|
|
15
|
-
|
|
16
|
-
```rust
|
|
17
|
-
pub trait Policy {
|
|
18
|
-
type AccountParams: FromVal<Env, Val>;
|
|
19
|
-
|
|
20
|
-
fn enforce(
|
|
21
|
-
e: &Env,
|
|
22
|
-
context: Context,
|
|
23
|
-
authenticated_signers: Vec<Signer>,
|
|
24
|
-
context_rule: ContextRule,
|
|
25
|
-
smart_account: Address,
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
fn install(
|
|
29
|
-
e: &Env,
|
|
30
|
-
install_params: Self::AccountParams,
|
|
31
|
-
context_rule: ContextRule,
|
|
32
|
-
smart_account: Address,
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
fn uninstall(e: &Env, context_rule: ContextRule, smart_account: Address);
|
|
36
|
-
}
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
### Key observations
|
|
40
|
-
|
|
41
|
-
- `Policy::enforce` receives a **single `Context`** — the authorization context being enforced. It does **NOT** carry a `sub_invocations` field. Sub-invocations live under `InvokerContractAuthEntry::Contract(SubContractInvocation)` and are used for `authorize_as_current_contract`, not passed to `Policy::enforce`.
|
|
42
|
-
- The `Context` type is defined in `soroban_sdk::auth::Context` (external, not in this repo).
|
|
43
|
-
- `install` takes `Self::AccountParams` — the interpreter's `PolicyInstallParams` struct satisfies this via `FromVal` / `IntoVal`.
|
|
44
|
-
- `uninstall` requires the `ContextRule` to be passed by the caller; the interpreter stores it to compute the `rule_id`.
|
|
45
|
-
|
|
46
|
-
---
|
|
47
|
-
|
|
48
|
-
## Signer Enum
|
|
49
|
-
|
|
50
|
-
Source: `packages/accounts/src/smart_account/storage.rs` lines 148–155 (permalinked above)
|
|
51
|
-
|
|
52
|
-
```rust
|
|
53
|
-
pub enum Signer {
|
|
54
|
-
Delegated(Address),
|
|
55
|
-
External(Address, Bytes),
|
|
56
|
-
}
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
**Two variants only.** No `Key` variant. No `SmartAccount` variant. The verifier address + key bytes for an external signer are carried in the `External` variant itself. There is **no master/non-master discriminator** on the type.
|
|
60
|
-
|
|
61
|
-
---
|
|
62
|
-
|
|
63
|
-
## ContextRuleType Enum
|
|
64
|
-
|
|
65
|
-
Source: `packages/accounts/src/smart_account/storage.rs` lines 170–177
|
|
66
|
-
|
|
67
|
-
```rust
|
|
68
|
-
pub enum ContextRuleType {
|
|
69
|
-
Default,
|
|
70
|
-
CallContract(Address),
|
|
71
|
-
CreateContract(BytesN<32>),
|
|
72
|
-
}
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
---
|
|
76
|
-
|
|
77
|
-
## ContextRule Struct
|
|
78
|
-
|
|
79
|
-
Source: `packages/accounts/src/smart_account/storage.rs` lines 179–199
|
|
80
|
-
|
|
81
|
-
```rust
|
|
82
|
-
pub struct ContextRule {
|
|
83
|
-
pub id: u32,
|
|
84
|
-
pub context_type: ContextRuleType,
|
|
85
|
-
pub name: String,
|
|
86
|
-
pub signers: Vec<Signer>,
|
|
87
|
-
pub signer_ids: Vec<u32>,
|
|
88
|
-
pub policies: Vec<Address>,
|
|
89
|
-
pub policy_ids: Vec<u32>,
|
|
90
|
-
pub valid_until: Option<u32>,
|
|
91
|
-
}
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
---
|
|
95
|
-
|
|
96
|
-
## add_context_rule Signature
|
|
97
|
-
|
|
98
|
-
Source: `packages/accounts/src/smart_account/storage.rs` lines 620–645
|
|
99
|
-
|
|
100
|
-
```rust
|
|
101
|
-
pub fn add_context_rule(
|
|
102
|
-
e: &Env,
|
|
103
|
-
context_type: &ContextRuleType,
|
|
104
|
-
name: &String,
|
|
105
|
-
valid_until: Option<u32>,
|
|
106
|
-
signers: &Vec<Signer>,
|
|
107
|
-
policies: &Map<Address, Val>,
|
|
108
|
-
) -> ContextRule
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
### Auth requirements
|
|
112
|
-
|
|
113
|
-
- `add_context_rule` is called by the **smart account itself** (the contract owning the context rules).
|
|
114
|
-
- Auth is enforced by Soroban's `require_auth` on the calling context — the smart account's master signer (or a delegated signer with sufficient weight) must authorize the call.
|
|
115
|
-
- The interpreter's `install` function is called **within the same transaction** as `add_context_rule` and receives the same `smart_account` address.
|
|
116
|
-
- The interpreter **cannot** read the smart account's master set; it receives only the already-authorized `ContextRule` and `smart_account` address.
|
|
117
|
-
|
|
118
|
-
> **CORRECTED 2026-07-27 - do not read the line above as a safety guarantee.**
|
|
119
|
-
> An earlier version of this file said the interpreter "does NOT need to" read the
|
|
120
|
-
> master set because the master authorizes `add_context_rule` directly. The master
|
|
121
|
-
> *can* authorize it. It is **not** true that only the master can.
|
|
122
|
-
>
|
|
123
|
-
> Verified at this pinned commit: `storage.rs` states `add_policy` /
|
|
124
|
-
> `add_context_rule` modify storage "without requiring authorization. Ensure proper
|
|
125
|
-
> access control is implemented at the contract level"; `mod.rs:439` and `mod.rs:246`
|
|
126
|
-
> implement that as `e.current_contract_address().require_auth()`, a self-auth
|
|
127
|
-
> resolved through the account's own context rules; and `mod.rs:80` states that
|
|
128
|
-
> "a `Default` rule matches any context".
|
|
129
|
-
>
|
|
130
|
-
> Therefore any signer on a `Default` rule can attach or replace a policy - including
|
|
131
|
-
> a delegated agent, on its own rule. See `plans/security-finding-install-authorization.md`.
|
|
132
|
-
|
|
133
|
-
### Safe mechanism for master-only install
|
|
134
|
-
|
|
135
|
-
Two-step install is the install **path**. It is NOT relied on as the authorization
|
|
136
|
-
**guarantee**, because the auth it inherits is whatever the account's own rules permit:
|
|
137
|
-
|
|
138
|
-
1. Owner calls `add_context_rule` with the interpreter address + initial rule.
|
|
139
|
-
2. Interpreter's `install` is called within the same auth context.
|
|
140
|
-
3. Re-install is structurally possible via `install_nonce` (stored nonce + 1 check).
|
|
141
|
-
|
|
142
|
-
The guarantee comes from the interpreter pinning its own authorized installer set at
|
|
143
|
-
first install for `(smart_account, rule_id)`, and denying later installs and
|
|
144
|
-
uninstalls from outside that set with `MASTER_AUTH_REQUIRED`. Rotation goes through
|
|
145
|
-
`rotate_master_signer_set(new_set)`, gated by the old set.
|
|
146
|
-
|
|
147
|
-
`install_nonce` alone does not close this: it blocks replay of an *old* document, but
|
|
148
|
-
a *fresh* looser document with `nonce + 1` would otherwise be accepted.
|
|
149
|
-
|
|
150
|
-
---
|
|
151
|
-
|
|
152
|
-
## Framework Limits (OZ Hard Limits)
|
|
153
|
-
|
|
154
|
-
Source: `packages/accounts/src/smart_account/storage.rs` (permalinked above)
|
|
155
|
-
|
|
156
|
-
| Limit | Value |
|
|
157
|
-
|---|---|
|
|
158
|
-
| `maxPoliciesPerRule` | **5** |
|
|
159
|
-
| `maxSignersPerRule` | **15** |
|
|
160
|
-
| Per-account rule cap | **None** (OZ imposes no cap) |
|
|
161
|
-
|
|
162
|
-
These are enforced by OZ internally; the interpreter enforces the same caps at install time.
|
|
163
|
-
|
|
164
|
-
---
|
|
165
|
-
|
|
166
|
-
## add_policy (Second Attach Path)
|
|
167
|
-
|
|
168
|
-
`add_context_rule` installs the rule + signers. A **second separate call** (`add_policy`) attaches a policy contract to an existing rule:
|
|
169
|
-
|
|
170
|
-
```rust
|
|
171
|
-
pub fn add_policy(
|
|
172
|
-
e: &Env,
|
|
173
|
-
context_rule_id: u32,
|
|
174
|
-
policy: Address,
|
|
175
|
-
install_param: Val,
|
|
176
|
-
) -> u32
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
Parameters:
|
|
180
|
-
- `context_rule_id: u32` — the rule to attach to
|
|
181
|
-
- `policy: Address` — the policy contract address
|
|
182
|
-
- `install_param: Val` — arbitrary `Val` passed to `Policy::install`; for the interpreter this is `PolicyInstallParams` as ScVal
|
|
183
|
-
- Returns `u32` — the new policy id within the rule
|
|
184
|
-
|
|
185
|
-
**Auth:** same pattern — `require_auth` on the smart account. The `policy` address must point to a deployed `Policy` contract.
|
|
186
|
-
|
|
187
|
-
---
|
|
188
|
-
|
|
189
|
-
## Related Files
|
|
190
|
-
|
|
191
|
-
| File | Purpose |
|
|
192
|
-
|---|---|
|
|
193
|
-
| `packages/accounts/src/smart_account/mod.rs` | Smart account contract entry points |
|
|
194
|
-
| `packages/accounts/src/smart_account/storage.rs` | Signer, ContextRule, add_context_rule, add_policy |
|
|
195
|
-
| `packages/accounts/src/policies/mod.rs` | Policy trait definition |
|
|
196
|
-
| `packages/accounts/src/policies/oz_primitive.rs` | Built-in OZ policies (spending_limit, threshold) |
|