@crediolabs/policy-synth 0.1.18 → 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 +3 -2
- 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 +1 -1
- package/dist/install/build-merge-policy.d.ts +70 -0
- package/dist/install/build-merge-policy.js +130 -0
- package/dist/install/index.d.ts +2 -0
- package/dist/install/index.js +7 -0
- 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/run/index.d.ts +93 -8
- package/dist/run/index.js +282 -11
- package/dist/run/schemas.d.ts +290 -11
- package/dist/run/schemas.js +77 -11
- 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 +1 -0
- 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/index.d.ts +2 -0
- package/dist-cjs/install/index.js +23 -2
- 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/run/index.d.ts +93 -8
- package/dist-cjs/run/index.js +283 -10
- package/dist-cjs/run/schemas.d.ts +290 -11
- package/dist-cjs/run/schemas.js +78 -12
- package/package.json +1 -1
- package/src/install/authority-overlap.ts +0 -0
- package/src/install/build-add-context-rule.ts +12 -1
- package/src/install/build-merge-policy.ts +219 -0
- package/src/install/index.ts +34 -0
- package/src/install/plan-merge-policy.ts +133 -0
- package/src/install/read-account-rules.ts +376 -0
- package/src/run/index.ts +386 -14
- package/src/run/schemas.ts +84 -11
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
//! Reading an OpenZeppelin smart account's context rules back off chain.
|
|
2
|
+
//!
|
|
3
|
+
//! `authority-overlap.ts` needs to know what a signer can already do before a
|
|
4
|
+
//! new policy is installed. That means every rule on the account: its context
|
|
5
|
+
//! type, its signers, its attached policies, and - for rules our interpreter
|
|
6
|
+
//! polices - the predicate itself.
|
|
7
|
+
//!
|
|
8
|
+
//! The predicate is NOT reachable through a contract call. The interpreter
|
|
9
|
+
//! exposes no getter for `StoredDoc` (`lib.rs` publishes only `grammar_version`,
|
|
10
|
+
//! `install`, `enforce`, the pause pair, `uninstall` and
|
|
11
|
+
//! `rotate_master_signer_set`), so it is read as a ledger entry instead. That
|
|
12
|
+
//! keeps this a pure client-side capability: adding a getter would change a
|
|
13
|
+
//! deployed contract's ABI and force a redeploy plus re-audit to obtain data
|
|
14
|
+
//! the ledger already exposes.
|
|
15
|
+
//!
|
|
16
|
+
//! The decoders here are pure so they can be tested without a network; the
|
|
17
|
+
//! caller supplies raw `ScVal`s.
|
|
18
|
+
import { Account, Address, BASE_FEE, Contract, Keypair, rpc, TransactionBuilder, xdr, } from '@stellar/stellar-sdk';
|
|
19
|
+
import { decodePredicate } from "../predicate/decode.js";
|
|
20
|
+
/** `storage.rs:295` - the third element of the persistent doc key tuple. */
|
|
21
|
+
export const K_DOC = 1;
|
|
22
|
+
/** Persistent-storage key for a rule's stored document:
|
|
23
|
+
* `(account, rule_id, K_DOC)`, per `storage.rs:4`. */
|
|
24
|
+
export function docKeyScVal(smartAccount, ruleId) {
|
|
25
|
+
return xdr.ScVal.scvVec([
|
|
26
|
+
new Address(smartAccount).toScVal(),
|
|
27
|
+
xdr.ScVal.scvU32(ruleId),
|
|
28
|
+
xdr.ScVal.scvU32(K_DOC),
|
|
29
|
+
]);
|
|
30
|
+
}
|
|
31
|
+
/** Ledger key for the interpreter's persistent entry holding that document. */
|
|
32
|
+
export function docLedgerKey(interpreter, smartAccount, ruleId) {
|
|
33
|
+
return xdr.LedgerKey.contractData(new xdr.LedgerKeyContractData({
|
|
34
|
+
contract: new Address(interpreter).toScAddress(),
|
|
35
|
+
key: docKeyScVal(smartAccount, ruleId),
|
|
36
|
+
durability: xdr.ContractDataDurability.persistent(),
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
// ---- ScVal helpers -----
|
|
40
|
+
/** Field of a `#[contracttype]` struct, which the host encodes as a map keyed
|
|
41
|
+
* by field-name symbol. Returns undefined when the field is absent so a
|
|
42
|
+
* caller can distinguish "not there" from "there and empty". */
|
|
43
|
+
function mapField(v, name) {
|
|
44
|
+
if (v.switch() !== xdr.ScValType.scvMap())
|
|
45
|
+
return undefined;
|
|
46
|
+
for (const entry of v.map() ?? []) {
|
|
47
|
+
const key = entry.key();
|
|
48
|
+
if (key.switch() === xdr.ScValType.scvSymbol() && key.sym().toString() === name) {
|
|
49
|
+
return entry.val();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
function u32Of(v) {
|
|
55
|
+
return v?.switch() === xdr.ScValType.scvU32() ? v.u32() : undefined;
|
|
56
|
+
}
|
|
57
|
+
function addressOf(v) {
|
|
58
|
+
if (!v || v.switch() !== xdr.ScValType.scvAddress())
|
|
59
|
+
return undefined;
|
|
60
|
+
return Address.fromScAddress(v.address()).toString();
|
|
61
|
+
}
|
|
62
|
+
/** An enum variant of a `#[contracttype]` enum: `ScVal::Vec([Symbol, ...args])`. */
|
|
63
|
+
function enumVariant(v) {
|
|
64
|
+
if (!v || v.switch() !== xdr.ScValType.scvVec())
|
|
65
|
+
return undefined;
|
|
66
|
+
const items = v.vec() ?? [];
|
|
67
|
+
const head = items[0];
|
|
68
|
+
if (!head || head.switch() !== xdr.ScValType.scvSymbol())
|
|
69
|
+
return undefined;
|
|
70
|
+
return { tag: head.sym().toString(), args: items.slice(1) };
|
|
71
|
+
}
|
|
72
|
+
// ---- decoders -----
|
|
73
|
+
/** OZ `ContextRuleType`. An unrecognised tag is reported as `default`, which
|
|
74
|
+
* is the widest reading and therefore the safe one: it makes the rule look
|
|
75
|
+
* like it could serve any call, so overlap is over-reported, never missed. */
|
|
76
|
+
export function decodeContextType(v) {
|
|
77
|
+
const variant = enumVariant(v);
|
|
78
|
+
if (!variant)
|
|
79
|
+
return { kind: 'default' };
|
|
80
|
+
if (variant.tag === 'CallContract') {
|
|
81
|
+
const addr = addressOf(variant.args[0]);
|
|
82
|
+
return addr ? { kind: 'call_contract', address: addr } : { kind: 'default' };
|
|
83
|
+
}
|
|
84
|
+
if (variant.tag === 'CreateContract') {
|
|
85
|
+
const arg = variant.args[0];
|
|
86
|
+
const hash = arg?.switch() === xdr.ScValType.scvBytes() ? arg.bytes().toString('hex') : '';
|
|
87
|
+
return { kind: 'create_contract', wasmHash: hash };
|
|
88
|
+
}
|
|
89
|
+
return { kind: 'default' };
|
|
90
|
+
}
|
|
91
|
+
/** OZ `Signer::Delegated(Address) | Signer::External(Address, Bytes)`. */
|
|
92
|
+
export function decodeSigner(v) {
|
|
93
|
+
const variant = enumVariant(v);
|
|
94
|
+
if (!variant)
|
|
95
|
+
return undefined;
|
|
96
|
+
if (variant.tag === 'Delegated') {
|
|
97
|
+
const addr = addressOf(variant.args[0]);
|
|
98
|
+
return addr ? { kind: 'delegated', address: addr } : undefined;
|
|
99
|
+
}
|
|
100
|
+
if (variant.tag === 'External') {
|
|
101
|
+
const verifier = addressOf(variant.args[0]);
|
|
102
|
+
const keyArg = variant.args[1];
|
|
103
|
+
const keyBytes = keyArg?.switch() === xdr.ScValType.scvBytes() ? keyArg.bytes().toString('hex') : '';
|
|
104
|
+
return verifier ? { kind: 'external', verifier, keyBytes } : undefined;
|
|
105
|
+
}
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
/** A full OZ `ContextRule` as returned by `get_context_rule(id)`.
|
|
109
|
+
* `predicate` is filled in separately from the ledger entry. */
|
|
110
|
+
export function decodeContextRule(v) {
|
|
111
|
+
const id = u32Of(mapField(v, 'id'));
|
|
112
|
+
if (id === undefined)
|
|
113
|
+
return undefined;
|
|
114
|
+
const signersVal = mapField(v, 'signers');
|
|
115
|
+
const signers = [];
|
|
116
|
+
if (signersVal?.switch() === xdr.ScValType.scvVec()) {
|
|
117
|
+
for (const s of signersVal.vec() ?? []) {
|
|
118
|
+
const decoded = decodeSigner(s);
|
|
119
|
+
if (decoded)
|
|
120
|
+
signers.push(decoded);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const policiesVal = mapField(v, 'policies');
|
|
124
|
+
const policyAddresses = [];
|
|
125
|
+
if (policiesVal?.switch() === xdr.ScValType.scvVec()) {
|
|
126
|
+
for (const p of policiesVal.vec() ?? []) {
|
|
127
|
+
const addr = addressOf(p);
|
|
128
|
+
if (addr)
|
|
129
|
+
policyAddresses.push(addr);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// `policy_ids` is index-aligned with `policies` in OZ's ContextRule. Only
|
|
133
|
+
// the ids can be passed to `remove_policy`, so a detach is impossible
|
|
134
|
+
// without them; they are read here rather than looked up again later.
|
|
135
|
+
const policyIdsVal = mapField(v, 'policy_ids');
|
|
136
|
+
const policyIds = [];
|
|
137
|
+
if (policyIdsVal?.switch() === xdr.ScValType.scvVec()) {
|
|
138
|
+
for (const pid of policyIdsVal.vec() ?? []) {
|
|
139
|
+
const n = u32Of(pid);
|
|
140
|
+
if (n !== undefined)
|
|
141
|
+
policyIds.push(n);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return {
|
|
145
|
+
id,
|
|
146
|
+
contextType: decodeContextType(mapField(v, 'context_type')),
|
|
147
|
+
signers,
|
|
148
|
+
policyAddresses,
|
|
149
|
+
...(policyIds.length > 0 ? { policyIds } : {}),
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/** `storage.rs:296` - the third element of the persistent nonce key tuple. */
|
|
153
|
+
export const K_NONCE = 2;
|
|
154
|
+
/** Ledger key for a rule's stored install nonce. Read directly for the same
|
|
155
|
+
* reason as the document: the interpreter publishes no getter. */
|
|
156
|
+
export function nonceLedgerKey(interpreter, smartAccount, ruleId) {
|
|
157
|
+
return xdr.LedgerKey.contractData(new xdr.LedgerKeyContractData({
|
|
158
|
+
contract: new Address(interpreter).toScAddress(),
|
|
159
|
+
key: xdr.ScVal.scvVec([
|
|
160
|
+
new Address(smartAccount).toScVal(),
|
|
161
|
+
xdr.ScVal.scvU32(ruleId),
|
|
162
|
+
xdr.ScVal.scvU32(K_NONCE),
|
|
163
|
+
]),
|
|
164
|
+
durability: xdr.ContractDataDurability.persistent(),
|
|
165
|
+
}));
|
|
166
|
+
}
|
|
167
|
+
export function decodeStoredOracleBounds(v) {
|
|
168
|
+
const read = (name) => u32Of(mapField(v, name));
|
|
169
|
+
const staleness = read('oracle_max_staleness_seconds');
|
|
170
|
+
const deviation = read('oracle_max_deviation_bps');
|
|
171
|
+
const xfeed = read('oracle_max_xfeed_dev_bps');
|
|
172
|
+
return {
|
|
173
|
+
...(staleness !== undefined ? { maxStalenessSeconds: staleness } : {}),
|
|
174
|
+
...(deviation !== undefined ? { maxDeviationBps: deviation } : {}),
|
|
175
|
+
...(xfeed !== undefined ? { maxCrossFeedDeviationBps: xfeed } : {}),
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
/** Raw predicate bytes out of a `StoredDoc` ledger entry value. */
|
|
179
|
+
export function decodeStoredPredicateBytes(v) {
|
|
180
|
+
const field = mapField(v, 'predicate_bytes');
|
|
181
|
+
if (!field || field.switch() !== xdr.ScValType.scvBytes())
|
|
182
|
+
return undefined;
|
|
183
|
+
return field.bytes();
|
|
184
|
+
}
|
|
185
|
+
/** How far the id scan will probe before giving up. OZ imposes no per-account
|
|
186
|
+
* rule cap, so there is no exact bound to derive; this one is far above any
|
|
187
|
+
* realistic account and keeps a malformed `Count` from spinning forever. */
|
|
188
|
+
export const MAX_RULE_ID_SCAN = 512;
|
|
189
|
+
/**
|
|
190
|
+
* Every context rule on the account, with predicates filled in for the rules
|
|
191
|
+
* our interpreter polices.
|
|
192
|
+
*
|
|
193
|
+
* Rule ids are NOT contiguous. OZ assigns them from a monotonic `NextId` and
|
|
194
|
+
* decrements `Count` on removal without ever reusing an id
|
|
195
|
+
* (`smart_account/storage.rs`: `add_context_rule` bumps `NextId`,
|
|
196
|
+
* `remove_context_rule` only lowers `Count`), so after any removal
|
|
197
|
+
* `Count < NextId` and the live ids have gaps. Iterating `0..Count-1` would
|
|
198
|
+
* silently skip live rules at higher ids, and a skipped rule is a missed
|
|
199
|
+
* overlap - the one error that reports safety which does not exist. Instead
|
|
200
|
+
* the scan walks ids upward until it has accounted for `Count` live rules.
|
|
201
|
+
*
|
|
202
|
+
* A rule whose predicate cannot be read is deliberately left without one. That
|
|
203
|
+
* demotes it to the `foreign` class, so the scan reports it as opaque instead
|
|
204
|
+
* of assuming it is narrow.
|
|
205
|
+
*/
|
|
206
|
+
export async function collectObservedRules(args) {
|
|
207
|
+
const count = await args.reader.getContextRuleCount(args.smartAccount);
|
|
208
|
+
const limit = args.maxRuleIdScan ?? MAX_RULE_ID_SCAN;
|
|
209
|
+
const rules = [];
|
|
210
|
+
const unreadablePredicateRuleIds = [];
|
|
211
|
+
let id = 0;
|
|
212
|
+
while (rules.length < count && id < limit) {
|
|
213
|
+
const raw = await args.reader.getContextRule(args.smartAccount, id);
|
|
214
|
+
id++;
|
|
215
|
+
if (!raw)
|
|
216
|
+
continue;
|
|
217
|
+
const rule = decodeContextRule(raw);
|
|
218
|
+
if (!rule)
|
|
219
|
+
continue;
|
|
220
|
+
if (rule.policyAddresses.includes(args.interpreterAddress)) {
|
|
221
|
+
const doc = await args.reader.getStoredDoc(args.interpreterAddress, args.smartAccount, rule.id);
|
|
222
|
+
const bytes = doc ? decodeStoredPredicateBytes(doc) : undefined;
|
|
223
|
+
if (bytes) {
|
|
224
|
+
try {
|
|
225
|
+
rule.predicate = decodePredicate(bytes);
|
|
226
|
+
// Carried so a merge can re-install the SAME bounds. They are
|
|
227
|
+
// tighten-only overrides, so losing them widens the policy quietly.
|
|
228
|
+
if (doc)
|
|
229
|
+
rule.oracleBounds = decodeStoredOracleBounds(doc);
|
|
230
|
+
}
|
|
231
|
+
catch {
|
|
232
|
+
unreadablePredicateRuleIds.push(rule.id);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
unreadablePredicateRuleIds.push(rule.id);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
rules.push(rule);
|
|
240
|
+
}
|
|
241
|
+
return { rules, unreadablePredicateRuleIds, incomplete: rules.length < count };
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* An `AccountRuleReader` over a live RPC server.
|
|
245
|
+
*
|
|
246
|
+
* The two OZ getters are read-only simulations, built the same way as
|
|
247
|
+
* `getContractVersion` in `build-install-policy.ts`: the source account is
|
|
248
|
+
* constructed locally because a simulation never checks its sequence number,
|
|
249
|
+
* and asking the network for a random key would 404.
|
|
250
|
+
*
|
|
251
|
+
* The stored document is fetched as a ledger entry rather than a contract
|
|
252
|
+
* call, because the interpreter publishes no getter for it.
|
|
253
|
+
*/
|
|
254
|
+
export function accountRuleReaderFromServer(server, networkPassphrase) {
|
|
255
|
+
async function simulateCall(contract, method, ...args) {
|
|
256
|
+
const account = new Account(Keypair.random().publicKey(), '0');
|
|
257
|
+
const tx = new TransactionBuilder(account, { fee: BASE_FEE, networkPassphrase })
|
|
258
|
+
.addOperation(new Contract(contract).call(method, ...args))
|
|
259
|
+
.setTimeout(30)
|
|
260
|
+
.build();
|
|
261
|
+
const sim = await server.simulateTransaction(tx);
|
|
262
|
+
if (rpc.Api.isSimulationError(sim))
|
|
263
|
+
return undefined;
|
|
264
|
+
return sim.result?.retval;
|
|
265
|
+
}
|
|
266
|
+
return {
|
|
267
|
+
async getContextRuleCount(smartAccount) {
|
|
268
|
+
const val = await simulateCall(smartAccount, 'get_context_rules_count');
|
|
269
|
+
return u32Of(val) ?? 0;
|
|
270
|
+
},
|
|
271
|
+
async getContextRule(smartAccount, ruleId) {
|
|
272
|
+
return simulateCall(smartAccount, 'get_context_rule', xdr.ScVal.scvU32(ruleId));
|
|
273
|
+
},
|
|
274
|
+
async getStoredDoc(interpreter, smartAccount, ruleId) {
|
|
275
|
+
const key = docLedgerKey(interpreter, smartAccount, ruleId);
|
|
276
|
+
const res = await server.getLedgerEntries(key);
|
|
277
|
+
const entry = res.entries?.[0]?.val;
|
|
278
|
+
if (!entry || entry.switch() !== xdr.LedgerEntryType.contractData())
|
|
279
|
+
return undefined;
|
|
280
|
+
return entry.contractData().val();
|
|
281
|
+
},
|
|
282
|
+
};
|
|
283
|
+
}
|
package/dist/run/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { type ErrorCode, type PredicateNode, type ProposedPolicy, type RecordedTransaction, type ToolError, type ToolResponse } from '../index.ts';
|
|
2
|
+
import { type AuthorityOverlap } from '../install/authority-overlap.ts';
|
|
2
3
|
import { type BuildInstallPolicyResult, type BuildRevokePolicyResult } from '../install/build-install-policy.ts';
|
|
3
4
|
import { getInterpreterInfo } from '../install/get-interpreter-info.ts';
|
|
4
5
|
import type { SimulationResult } from '../verify/envelope.ts';
|
|
5
6
|
import { type RecordTransactionInput, type SimulatePolicyInput, type SynthesizePolicyInput, type VerifyPolicyInput } from './schemas.ts';
|
|
6
7
|
export type { GetInterpreterInfoInput, InstallPolicyInput, RecordTransactionInput, RevokePolicyInput, SimulatePolicyInput, SynthesizePolicyInput, VerifyPolicyInput, } from './schemas.ts';
|
|
7
|
-
export { ComposeUserResponsesSchema, GetInterpreterInfoInputSchema, InstallPolicyInputSchema, InterpreterOptionsSchema, MAINNET_RPC_URL, MandateSpecSchema, NetworkSchema, OraclePriceFixtureSchema, OzAdapterConfigSchema, PINNED_INTERPRETER_ADDRESS_BY_NETWORK, PINNED_INTERPRETER_GRAMMAR_VERSION, PINNED_INTERPRETER_MAINNET_ADDRESS, PINNED_INTERPRETER_TESTNET_ADDRESS,
|
|
8
|
+
export { ComposeUserResponsesSchema, GetInterpreterInfoInputSchema, InstallPolicyInputSchema, InterpreterOptionsSchema, MAINNET_RPC_URL, MandateSpecSchema, NetworkSchema, OraclePriceFixtureSchema, OzAdapterConfigSchema, PINNED_INTERPRETER_ADDRESS_BY_NETWORK, PINNED_INTERPRETER_GRAMMAR_VERSION, PINNED_INTERPRETER_MAINNET_ADDRESS, PINNED_INTERPRETER_TESTNET_ADDRESS, PINNED_INTERPRETER_WASM_SHA256_BY_NETWORK, PredicateLeafSchema, PredicateNodeSchema, RecordedTransactionSchema, RecordTransactionInputSchema, RevokePolicyInputSchema, RPC_URL_BY_NETWORK, SimulatePolicyInputSchema, SynthesizePolicyInputSchema, TESTNET_RPC_URL, ToolErrorSchema, VerifyPolicyInputSchema, } from './schemas.ts';
|
|
8
9
|
export type RunRecordTransactionInput = RecordTransactionInput;
|
|
9
10
|
export type RunSynthesizePolicyInput = SynthesizePolicyInput;
|
|
10
11
|
export type RunSimulatePolicyInput = SimulatePolicyInput;
|
|
@@ -66,7 +67,91 @@ export declare function runVerifyPolicy(raw: unknown): Promise<ToolResponse<true
|
|
|
66
67
|
* comes from the RPC). Both gates accept an explicit opt-in flag.
|
|
67
68
|
* Pin selection follows `input.network` (defaults to `testnet` so the
|
|
68
69
|
* pre-mainnet callers keep working unchanged). */
|
|
69
|
-
export declare function runInstallPolicy(raw: unknown): Promise<ToolResponse<
|
|
70
|
+
export declare function runInstallPolicy(raw: unknown): Promise<ToolResponse<InstallPolicyResult>>;
|
|
71
|
+
/** Default-deny on the cross-rule scan.
|
|
72
|
+
*
|
|
73
|
+
* Refuses whenever the scan cannot establish that this policy binds the calls
|
|
74
|
+
* it names. An unpoliced neighbour provably does not constrain them. An
|
|
75
|
+
* opaque one, policed by a contract this tool cannot decode, is not KNOWN to,
|
|
76
|
+
* and "not known to" is not "safe" - the same posture as the interpreter and
|
|
77
|
+
* RPC pins. An incomplete scan is refused for the same reason: the overlap
|
|
78
|
+
* list is then a subset of the account, so an empty list proves nothing.
|
|
79
|
+
*
|
|
80
|
+
* `not-restricting` is reported but does NOT block. Both rules are ours and
|
|
81
|
+
* both constrain the calls, and the conjunction remedy is offered; refusing
|
|
82
|
+
* there would also block the legitimate act of adding a separate capability,
|
|
83
|
+
* which OZ composes correctly as a union.
|
|
84
|
+
*
|
|
85
|
+
* Returns a ToolError or null, matching `enforceInterpreterPin`. */
|
|
86
|
+
export declare function enforceAuthorityScan(scan: AuthorityScanReport | undefined, allowOverlap: boolean | undefined): ToolError | null;
|
|
87
|
+
/** The install response, plus what the cross-rule scan found. The scan is
|
|
88
|
+
* advisory data about the account, not part of the transaction, so it is
|
|
89
|
+
* additive: a caller that ignores it gets exactly the previous shape. */
|
|
90
|
+
export type InstallPolicyResult = BuildInstallPolicyResult & {
|
|
91
|
+
authorityScan?: AuthorityScanReport;
|
|
92
|
+
};
|
|
93
|
+
/** What the cross-rule scan found, carried on the install response so the
|
|
94
|
+
* review surface can show it alongside the transaction being signed.
|
|
95
|
+
*
|
|
96
|
+
* SCOPE, and it is narrow: this answers "can a signer OF THIS RULE reach the
|
|
97
|
+
* same calls through a different rule". A rule sharing no signer with this
|
|
98
|
+
* one cannot be reached by this rule's signers, so it is not a way around
|
|
99
|
+
* this policy; it is a different principal's authority, which no policy
|
|
100
|
+
* installed here was ever going to constrain. Other rules keep their own
|
|
101
|
+
* signers, and an account administrator can add signers or rules afterwards.
|
|
102
|
+
*
|
|
103
|
+
* An empty `overlaps` is therefore NOT a statement that the account is safe,
|
|
104
|
+
* only that this rule's own signers gain no unconstrained path through the
|
|
105
|
+
* rules that exist right now. */
|
|
106
|
+
export interface AuthorityScanReport {
|
|
107
|
+
/** False when the scan did not run. `reason` then says why, and the absence
|
|
108
|
+
* of overlaps proves nothing. */
|
|
109
|
+
ran: boolean;
|
|
110
|
+
/** True when the caller passed `skipAuthorityScan`. Distinguishes a
|
|
111
|
+
* deliberate skip from a scan that tried and failed: both carry
|
|
112
|
+
* `ran: false`, but only the failure refuses the install. Recorded rather
|
|
113
|
+
* than omitted so the response shows that no opinion was formed, instead
|
|
114
|
+
* of looking like a version that never had the check. */
|
|
115
|
+
skipped?: boolean;
|
|
116
|
+
/** True when the account has more rules than the scan accounted for, so the
|
|
117
|
+
* overlap list is a subset. */
|
|
118
|
+
incomplete?: boolean;
|
|
119
|
+
reason?: string;
|
|
120
|
+
overlaps: AuthorityOverlap[];
|
|
121
|
+
}
|
|
122
|
+
/** The merge response: one step's transaction plus what it will cost. */
|
|
123
|
+
export interface MergePolicyResult {
|
|
124
|
+
unsignedXdr: string;
|
|
125
|
+
smartAccount: string;
|
|
126
|
+
sourceAccount: string;
|
|
127
|
+
step: 'detach' | 'reinstall';
|
|
128
|
+
call: {
|
|
129
|
+
contract: string;
|
|
130
|
+
fn: string;
|
|
131
|
+
ruleId: number;
|
|
132
|
+
};
|
|
133
|
+
authNonce: string;
|
|
134
|
+
authValidUntilLedger: number;
|
|
135
|
+
rootInvocationXdr: string;
|
|
136
|
+
/** sha256 of the merged predicate, so the caller can pin what step 2 will
|
|
137
|
+
* install while they are still looking at step 1. */
|
|
138
|
+
mergedPredicateHash: string;
|
|
139
|
+
mergedPredicateBlobBase64: string;
|
|
140
|
+
warnings: string[];
|
|
141
|
+
followUp: string;
|
|
142
|
+
}
|
|
143
|
+
/** `merge_policy` body - the tightening remedy for a cross-rule overlap.
|
|
144
|
+
*
|
|
145
|
+
* Replaces a rule's predicate with the conjunction of it and a new one. This
|
|
146
|
+
* is the action `install_policy` recommends when it reports an overlap
|
|
147
|
+
* between two rules our interpreter polices, and it is deliberately NOT
|
|
148
|
+
* something `install_policy` does on its own: it detaches a live policy, so
|
|
149
|
+
* the operator has to ask for it.
|
|
150
|
+
*
|
|
151
|
+
* Two transactions in order. `add_policy` refuses a policy already on the
|
|
152
|
+
* rule, so the old attachment goes first, and the second transaction cannot
|
|
153
|
+
* be simulated until the first confirms. */
|
|
154
|
+
export declare function runMergePolicy(raw: unknown): Promise<ToolResponse<MergePolicyResult>>;
|
|
70
155
|
/** `revoke_policy` body - thin wrapper over `buildRevokePolicyXdr`.
|
|
71
156
|
* Emits an unsigned XDR for `account.remove_context_rule(ruleId)`; the
|
|
72
157
|
* smart account itself handles uninstalling each attached policy. Auth
|
|
@@ -84,12 +169,12 @@ export declare function runRevokePolicy(raw: unknown): Promise<ToolResponse<Buil
|
|
|
84
169
|
* fabricating it would be a lie on a security surface; the live
|
|
85
170
|
* mismatch check is worth MORE).
|
|
86
171
|
*
|
|
87
|
-
* Network-aware: `input.network` selects
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
172
|
+
* Network-aware: `input.network` selects the interpreter address, the RPC
|
|
173
|
+
* and the wasm hash. The networks run different binaries - testnet carries
|
|
174
|
+
* the selector-leaf minimum and the signer-set cap, mainnet predates both -
|
|
175
|
+
* so the hash is read through
|
|
176
|
+
* `PINNED_INTERPRETER_WASM_SHA256_BY_NETWORK`. UNAUDITED at the time of
|
|
177
|
+
* writing.
|
|
93
178
|
*
|
|
94
179
|
* Same RPC pin as install/revoke: when `verifyLive` triggers an outbound
|
|
95
180
|
* call, the auth-digest + the answer bind to whichever RPC answered, so
|