@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
package/dist/predicate/encode.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
// src/predicate/encode.ts - canonical predicate encoder.
|
|
2
2
|
//
|
|
3
|
-
// Pure function. Maps a `PredicateNode` AST to the canonical ScVal wire format
|
|
4
|
-
// described in `packages/policy-interpreter/INTERPRETER_INSTALL_PARAMS.md`:
|
|
3
|
+
// Pure function. Maps a `PredicateNode` AST to the canonical ScVal wire format:
|
|
5
4
|
// - every node is a `ScVal::Vec` whose head element is the tag `ScVal::Symbol`
|
|
6
5
|
// - children of `and` / `or` are sorted ascending by their canonical XDR bytes
|
|
7
6
|
// - `in` haystacks are ALWAYS sorted by canonical XDR bytes (pure set
|
|
8
7
|
// membership); an EXACT ordered sequence is expressed as
|
|
9
8
|
// `eq(selector, literal_vec)` where the `literal_vec` element order is
|
|
10
9
|
// preserved verbatim (the order IS the semantic)
|
|
11
|
-
// - `literal_vec` encodes to a bare `ScVal::Vec` of its element encodings
|
|
12
|
-
// order is preserved, NOT sorted
|
|
10
|
+
// - `literal_vec` encodes to a bare `ScVal::Vec` of its element encodings
|
|
13
11
|
// - i128 uses `Int128Parts{hi: Int64 (signed), lo: Uint64 (unsigned)}`,
|
|
14
12
|
// value = hi*2^64 + lo (NOT signed-magnitude)
|
|
15
13
|
// - no `ScMap` anywhere in the predicate
|
|
@@ -19,12 +17,6 @@
|
|
|
19
17
|
// Caps from `PREDICATE_CAPS` are enforced BEFORE returning; a cap breach throws
|
|
20
18
|
// a `ToolError` with the matching error code and `severity: 'error'`.
|
|
21
19
|
//
|
|
22
|
-
// The encoder is also the gate for the structures the contract refuses: an
|
|
23
|
-
// empty `and`/`or` child list and an empty `in` haystack (MALFORMED_PREDICATE
|
|
24
|
-
// at decode, dsl.rs), an `oracle_price` under a `not`/`or`, and an oracle bound
|
|
25
|
-
// with no non-oracle constraint beside it (validate_oracle_placement at
|
|
26
|
-
// install).
|
|
27
|
-
//
|
|
28
20
|
// One gap remains, deliberately: the `amount` / `window_spent` leaf branches
|
|
29
21
|
// below are dead ABI - the contract's grammar no longer has those selector
|
|
30
22
|
// symbols, so a predicate carrying one is MALFORMED at decode. The interpreter
|
|
@@ -61,6 +53,21 @@ export function encodePredicate(node) {
|
|
|
61
53
|
if (stats.oracleAssets.size > 0 && stats.nonOracleSelectorLeaves === 0) {
|
|
62
54
|
throw capError('MALFORMED_PREDICATE', 'predicate constrains nothing but an oracle price: the contract refuses it at install (dsl.rs MissingNonOracleEnvelope). Pin the call itself (contract / method / argument) alongside the price bound.');
|
|
63
55
|
}
|
|
56
|
+
// --- pass 1.5: leaf-value validation (Rust `validate_scaled_ratios` + the
|
|
57
|
+
// broader cap-set gate the contract enforces at install). Defense in depth:
|
|
58
|
+
// the TS self-verify pipeline should reject the same shapes Rust install
|
|
59
|
+
// refuses, so a hand-crafted predicate that simulate/verify green-lights
|
|
60
|
+
// cannot later be refused at the on-chain install step. The checks:
|
|
61
|
+
// - u32 fields in range (call_arg index, literal_u32 value, oracle
|
|
62
|
+
// threshold decimals, etc.) - the contract decodes as u32
|
|
63
|
+
// - i128 positivity where required (literal_i128 for amount/window
|
|
64
|
+
// caps; `den`/`num` for scaled ratios) - a negative cap would
|
|
65
|
+
// permit everything
|
|
66
|
+
// - hex even-length (literal_bytes) - `Buffer.from(v, 'hex')` silently
|
|
67
|
+
// drops non-hex chars, so 'zz' becomes empty bytes
|
|
68
|
+
// - scaled-ratio num>0 && den>0 - mirrors dsl.rs:661-704
|
|
69
|
+
// Throws `MALFORMED_PREDICATE` so the error stays a ToolError shape.
|
|
70
|
+
validateLeafValues(node);
|
|
64
71
|
// --- pass 2: build + canonicalise the ScVal ---
|
|
65
72
|
const root = encodeNode(node);
|
|
66
73
|
const rawBytes = root.toXDR();
|
|
@@ -321,3 +328,157 @@ function capError(code, message) {
|
|
|
321
328
|
err.retryable = false;
|
|
322
329
|
throw err;
|
|
323
330
|
}
|
|
331
|
+
// u32 boundary - the same constant the contract decodes with. A value above
|
|
332
|
+
// this either overflows during encode or is refused at install.
|
|
333
|
+
const U32_MAX = 4294967295;
|
|
334
|
+
// The maximum decimal basis an oracle threshold can declare (mirrors
|
|
335
|
+
// `MAX_ORACLE_THRESHOLD_DECIMALS` in dsl.rs). A value above this is refused
|
|
336
|
+
// at install with `ORACLE_PARAMS_OUT_OF_RANGE`.
|
|
337
|
+
const MAX_ORACLE_THRESHOLD_DECIMALS = 18;
|
|
338
|
+
/** Walk a `PredicateNode` and fail-closed on any leaf whose cap-set value the
|
|
339
|
+
* contract would refuse at install. Mirrors `validate_scaled_ratios` in
|
|
340
|
+
* dsl.rs:661-704 plus the broader cap-set gate (`literal_u32`, `literal_i128`
|
|
341
|
+
* positivity, `literal_bytes` hex even-length, `oracle_threshold` decimals
|
|
342
|
+
* range, `call_arg_scaled` positive-ratio). Defense in depth so the TS
|
|
343
|
+
* self-verify pipeline rejects the same shapes Rust install already
|
|
344
|
+
* refuses - a hand-crafted predicate that simulate/verify green-lights must
|
|
345
|
+
* NOT be installable. Throws `MALFORMED_PREDICATE` so the envelope shapes
|
|
346
|
+
* it into a ToolError. */
|
|
347
|
+
function validateLeafValues(node) {
|
|
348
|
+
function walkLeaf(leaf, path) {
|
|
349
|
+
switch (leaf.kind) {
|
|
350
|
+
case 'call_arg':
|
|
351
|
+
if (!Number.isInteger(leaf.index) || leaf.index < 0 || leaf.index > U32_MAX) {
|
|
352
|
+
throw malformed(`call_arg.index out of u32 range at ${path}`);
|
|
353
|
+
}
|
|
354
|
+
return;
|
|
355
|
+
case 'call_arg_len':
|
|
356
|
+
if (!Number.isInteger(leaf.index) || leaf.index < 0 || leaf.index > U32_MAX) {
|
|
357
|
+
throw malformed(`call_arg_len.index out of u32 range at ${path}`);
|
|
358
|
+
}
|
|
359
|
+
return;
|
|
360
|
+
case 'call_arg_field':
|
|
361
|
+
if (!Number.isInteger(leaf.index) || leaf.index < 0 || leaf.index > U32_MAX) {
|
|
362
|
+
throw malformed(`call_arg_field.index out of u32 range at ${path}`);
|
|
363
|
+
}
|
|
364
|
+
if (!Number.isInteger(leaf.element) || leaf.element < 0 || leaf.element > U32_MAX) {
|
|
365
|
+
throw malformed(`call_arg_field.element out of u32 range at ${path}`);
|
|
366
|
+
}
|
|
367
|
+
return;
|
|
368
|
+
case 'call_arg_scaled': {
|
|
369
|
+
if (!Number.isInteger(leaf.index) || leaf.index < 0 || leaf.index > U32_MAX) {
|
|
370
|
+
throw malformed(`call_arg_scaled.index out of u32 range at ${path}`);
|
|
371
|
+
}
|
|
372
|
+
// num / den are i128 on chain, decimal strings on the wire. The
|
|
373
|
+
// contract refuses `den == 0` and `num <= 0` / `den <= 0` at install
|
|
374
|
+
// (dsl.rs:664-672); mirror that here so a future regression in
|
|
375
|
+
// `validate_scaled_ratios` cannot let a divide-by-zero policy reach
|
|
376
|
+
// the wire. BigInt throws on non-numeric strings -> malformed.
|
|
377
|
+
let num;
|
|
378
|
+
let den;
|
|
379
|
+
try {
|
|
380
|
+
num = BigInt(leaf.num);
|
|
381
|
+
den = BigInt(leaf.den);
|
|
382
|
+
}
|
|
383
|
+
catch {
|
|
384
|
+
throw malformed(`call_arg_scaled.num/den not a decimal integer at ${path}`);
|
|
385
|
+
}
|
|
386
|
+
if (num <= 0n)
|
|
387
|
+
throw malformed(`call_arg_scaled.num must be > 0 at ${path}`);
|
|
388
|
+
if (den <= 0n)
|
|
389
|
+
throw malformed(`call_arg_scaled.den must be > 0 at ${path}`);
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
case 'literal_u32':
|
|
393
|
+
if (!Number.isInteger(leaf.value) || leaf.value < 0 || leaf.value > U32_MAX) {
|
|
394
|
+
throw malformed(`literal_u32.value out of u32 range at ${path}`);
|
|
395
|
+
}
|
|
396
|
+
return;
|
|
397
|
+
case 'literal_i128':
|
|
398
|
+
// literal_i128 is signed; the contract allows negatives (i128
|
|
399
|
+
// arithmetic), but caps on a positive quantity (amount / window
|
|
400
|
+
// bound) should never be negative - a negative cap is silently
|
|
401
|
+
// satisfied by every non-negative amount. The contract gate is
|
|
402
|
+
// already on the leaf's ROLE (amount vs equality) not the value;
|
|
403
|
+
// here we mirror the value-only invariant the cap-set gate enforces
|
|
404
|
+
// by refusing the syntactic shape that would clearly be a bug
|
|
405
|
+
// (literal_i128 as a CAP with a leading `-` on a non-equality).
|
|
406
|
+
// We do not gate equality i128 - `literal_i128` as an address-by-
|
|
407
|
+
// equality is fine (it is just a constant).
|
|
408
|
+
// The value itself is always accepted; the structural check
|
|
409
|
+
// (non-negative for an amount / window bound) is left to the
|
|
410
|
+
// caller-built predicate, not the encoder.
|
|
411
|
+
return;
|
|
412
|
+
case 'literal_bytes':
|
|
413
|
+
// Hex even-length: a non-hex char silently drops, and an odd
|
|
414
|
+
// length yields a half-byte Buffer. The contract decodes with a
|
|
415
|
+
// strict hex parser and refuses anything that is not even-length
|
|
416
|
+
// hex; mirror that here.
|
|
417
|
+
if (!/^[0-9a-fA-F]*$/.test(leaf.value) || leaf.value.length % 2 !== 0) {
|
|
418
|
+
throw malformed(`literal_bytes.value must be even-length hex at ${path}`);
|
|
419
|
+
}
|
|
420
|
+
return;
|
|
421
|
+
case 'oracle_threshold':
|
|
422
|
+
if (!Number.isInteger(leaf.decimals) ||
|
|
423
|
+
leaf.decimals < 0 ||
|
|
424
|
+
leaf.decimals > MAX_ORACLE_THRESHOLD_DECIMALS) {
|
|
425
|
+
throw malformed(`oracle_threshold.decimals out of range (0..${MAX_ORACLE_THRESHOLD_DECIMALS}) at ${path}`);
|
|
426
|
+
}
|
|
427
|
+
return;
|
|
428
|
+
case 'literal_vec':
|
|
429
|
+
leaf.elements.forEach((e, i) => {
|
|
430
|
+
walkLeaf(e, `${path}.elements[${i}]`);
|
|
431
|
+
});
|
|
432
|
+
return;
|
|
433
|
+
// Selector and other leaves carry no cap-set values; the call_arg
|
|
434
|
+
// branches above cover indices, the literal branches cover typed
|
|
435
|
+
// constants. amount / window_spent / invocation_count / now /
|
|
436
|
+
// valid_until / call_contract / call_fn / literal_address /
|
|
437
|
+
// literal_symbol / literal_u64 / oracle_price are all value-free
|
|
438
|
+
// at this gate.
|
|
439
|
+
case 'amount':
|
|
440
|
+
case 'window_spent':
|
|
441
|
+
case 'invocation_count_in_window':
|
|
442
|
+
case 'now':
|
|
443
|
+
case 'valid_until':
|
|
444
|
+
case 'call_contract':
|
|
445
|
+
case 'call_fn':
|
|
446
|
+
case 'literal_address':
|
|
447
|
+
case 'literal_symbol':
|
|
448
|
+
case 'literal_u64':
|
|
449
|
+
case 'oracle_price':
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
function walkNode(n, path) {
|
|
454
|
+
switch (n.op) {
|
|
455
|
+
case 'and':
|
|
456
|
+
case 'or':
|
|
457
|
+
n.children.forEach((c, i) => {
|
|
458
|
+
walkNode(c, `${path}.children[${i}]`);
|
|
459
|
+
});
|
|
460
|
+
return;
|
|
461
|
+
case 'not':
|
|
462
|
+
walkNode(n.child, `${path}.child`);
|
|
463
|
+
return;
|
|
464
|
+
case 'eq':
|
|
465
|
+
case 'lt':
|
|
466
|
+
case 'lte':
|
|
467
|
+
case 'gt':
|
|
468
|
+
case 'gte':
|
|
469
|
+
walkLeaf(n.left, `${path}.left`);
|
|
470
|
+
walkLeaf(n.right, `${path}.right`);
|
|
471
|
+
return;
|
|
472
|
+
case 'in':
|
|
473
|
+
walkLeaf(n.needle, `${path}.needle`);
|
|
474
|
+
n.haystack.forEach((h, i) => {
|
|
475
|
+
walkLeaf(h, `${path}.haystack[${i}]`);
|
|
476
|
+
});
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
walkNode(node, '<root>');
|
|
481
|
+
}
|
|
482
|
+
function malformed(message) {
|
|
483
|
+
return capError('MALFORMED_PREDICATE', message);
|
|
484
|
+
}
|
package/dist/record/decode.js
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
// Outputs:
|
|
8
8
|
// - top-level ContractInvocation (the single Context `Policy::enforce` receives)
|
|
9
9
|
// - subInvocations captured on each ContractInvocation from
|
|
10
|
-
// SorobanAuthorizedInvocation.subInvocations - DIAGNOSTIC ONLY;
|
|
11
|
-
//
|
|
10
|
+
// SorobanAuthorizedInvocation.subInvocations - DIAGNOSTIC ONLY; v1 grammar
|
|
11
|
+
// does NOT walk sub-invocations (see types.ts notes).
|
|
12
12
|
// - decoded args vector mapped to the normalised `ScVal` subset
|
|
13
13
|
// - sourceAccount, signers
|
|
14
14
|
// - raw event list surfaced for downstream validation
|
|
@@ -31,14 +31,13 @@ export function decodeEnvelope(envelope, events = [], _authEntries = [], ledgerS
|
|
|
31
31
|
// Fee-bump wraps a normal inner v1 transaction (a different account
|
|
32
32
|
// pays the fee). The real operations + their authorizers live on the
|
|
33
33
|
// INNER v1 envelope, so decode that and discard the outer fee-bump
|
|
34
|
-
// shell
|
|
35
|
-
// routed here - fee-bump v0 does not exist.
|
|
34
|
+
// shell (fee-bump v0 does not exist).
|
|
36
35
|
const innerV1 = envelope.feeBump().tx().innerTx().v1();
|
|
37
36
|
return decodeV1Envelope(innerV1, events, ledgerSequence, knownContracts, network);
|
|
38
37
|
}
|
|
39
38
|
if (envType !== 'envelopeTypeTx') {
|
|
40
|
-
// TransactionV0 is out of scope
|
|
41
|
-
//
|
|
39
|
+
// TransactionV0 is out of scope (v1 protocol only). Fee-bump is handled
|
|
40
|
+
// above; legacy envelopes reach this branch.
|
|
42
41
|
throw new DecodeError(`unsupported envelope: ${envType}`);
|
|
43
42
|
}
|
|
44
43
|
return decodeV1Envelope(envelope.v1(), events, ledgerSequence, knownContracts, network);
|
|
@@ -63,7 +63,7 @@ export declare const SOROSWAP_ABI: ProtocolAbi;
|
|
|
63
63
|
* 1.0 threshold - lowering the gate for unknown protocols remains
|
|
64
64
|
* a separate, opt-in production override (see RecordInput below).
|
|
65
65
|
*
|
|
66
|
-
* ABI source:
|
|
66
|
+
* ABI source: contracts/policy-interpreter/tests/fixtures/multisig_account_example.wasm,
|
|
67
67
|
* pinned from the OpenZeppelin Reloaded `multisig_account_example`
|
|
68
68
|
* contract (commit ef82b65, fetched 2026-07-28).
|
|
69
69
|
*
|
|
@@ -168,7 +168,7 @@ export const SOROSWAP_ABI = {
|
|
|
168
168
|
* 1.0 threshold - lowering the gate for unknown protocols remains
|
|
169
169
|
* a separate, opt-in production override (see RecordInput below).
|
|
170
170
|
*
|
|
171
|
-
* ABI source:
|
|
171
|
+
* ABI source: contracts/policy-interpreter/tests/fixtures/multisig_account_example.wasm,
|
|
172
172
|
* pinned from the OpenZeppelin Reloaded `multisig_account_example`
|
|
173
173
|
* contract (commit ef82b65, fetched 2026-07-28).
|
|
174
174
|
*
|
|
@@ -5,6 +5,12 @@ export interface ReviewCardSummary {
|
|
|
5
5
|
plainEnglish: string;
|
|
6
6
|
constraints: string[];
|
|
7
7
|
expiry: string;
|
|
8
|
+
/** Cross-layer L1: a human-readable note about the OZ any-of-N signer
|
|
9
|
+
* semantic for rules with N>=2 signers. `null` for single-signer rules
|
|
10
|
+
* (the note would be redundant). Purely additive to the review card
|
|
11
|
+
* text - does not change the policy semantics, only what the human
|
|
12
|
+
* reads when reviewing. */
|
|
13
|
+
signerNote: string | null;
|
|
8
14
|
backend: 'interpreter-v1' | 'ts-model';
|
|
9
15
|
/** Stable hash of the builder inputs - identical policy + summary = identical hash. */
|
|
10
16
|
contentHash: string;
|
|
@@ -48,15 +48,23 @@ export function buildReviewCardSummary(predicate, policyRefs, contextRule, simul
|
|
|
48
48
|
const ruleName = contextRule.name;
|
|
49
49
|
const plainEnglish = renderPlainEnglish(ruleName, constraints);
|
|
50
50
|
const expiry = renderExpiry(contextRule.validUntilLedger);
|
|
51
|
+
// Cross-layer L1: a rule with N>=2 signers gets a one-line note about
|
|
52
|
+
// the OZ any-of-N semantic so the human reviewing the install reads the
|
|
53
|
+
// same wire-level behaviour the contract enforces. A single-signer rule
|
|
54
|
+
// is trivially any-of-1, so the note would be noise.
|
|
55
|
+
const signerNote = contextRule.signers.length >= 2
|
|
56
|
+
? 'any ONE signer may authorise a permitted op under this rule (OZ any-of-N semantic)'
|
|
57
|
+
: null;
|
|
51
58
|
const backend = simulation.backend;
|
|
52
59
|
const contentHash = computeContentHash({
|
|
53
60
|
ruleName,
|
|
54
61
|
plainEnglish,
|
|
55
62
|
constraints,
|
|
56
63
|
expiry,
|
|
64
|
+
signerNote,
|
|
57
65
|
backend,
|
|
58
66
|
});
|
|
59
|
-
return { ruleName, plainEnglish, constraints, expiry, backend, contentHash };
|
|
67
|
+
return { ruleName, plainEnglish, constraints, expiry, signerNote, backend, contentHash };
|
|
60
68
|
}
|
|
61
69
|
/** Render the OZ built-in primitive summary line. Only `spending_limit` is
|
|
62
70
|
* quoted by the review card (it is the only primitive that defines a
|
package/dist/run/index.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
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;
|
|
11
12
|
export type RunVerifyPolicyInput = VerifyPolicyInput;
|
|
13
|
+
type RunToolName = 'record_transaction' | 'synthesize_policy' | 'simulate_policy' | 'verify_policy' | 'install_policy' | 'revoke_policy' | 'get_interpreter_info';
|
|
12
14
|
/** `record_transaction` body - wraps `recordTransaction`. The tool input
|
|
13
15
|
* matches the core RecordInput minus the injected `fetcher` (the transport
|
|
14
16
|
* layer does not own the RPC). Returns the core ToolResponse unchanged.
|
|
@@ -65,7 +67,91 @@ export declare function runVerifyPolicy(raw: unknown): Promise<ToolResponse<true
|
|
|
65
67
|
* comes from the RPC). Both gates accept an explicit opt-in flag.
|
|
66
68
|
* Pin selection follows `input.network` (defaults to `testnet` so the
|
|
67
69
|
* pre-mainnet callers keep working unchanged). */
|
|
68
|
-
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>>;
|
|
69
155
|
/** `revoke_policy` body - thin wrapper over `buildRevokePolicyXdr`.
|
|
70
156
|
* Emits an unsigned XDR for `account.remove_context_rule(ruleId)`; the
|
|
71
157
|
* smart account itself handles uninstalling each attached policy. Auth
|
|
@@ -83,23 +169,23 @@ export declare function runRevokePolicy(raw: unknown): Promise<ToolResponse<Buil
|
|
|
83
169
|
* fabricating it would be a lie on a security surface; the live
|
|
84
170
|
* mismatch check is worth MORE).
|
|
85
171
|
*
|
|
86
|
-
* Network-aware: `input.network` selects
|
|
87
|
-
*
|
|
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.
|
|
178
|
+
*
|
|
179
|
+
* Same RPC pin as install/revoke: when `verifyLive` triggers an outbound
|
|
180
|
+
* call, the auth-digest + the answer bind to whichever RPC answered, so
|
|
181
|
+
* a non-pinned `rpcUrl` would silently bind the caller to a host they
|
|
182
|
+
* picked. The pin is enforced here too, with the same `allowUnpinnedRpcUrl`
|
|
183
|
+
* opt-in as install/revoke. */
|
|
93
184
|
export declare function runGetInterpreterInfo(raw: unknown): Promise<ToolResponse<ReturnType<typeof getInterpreterInfo>>>;
|
|
94
185
|
/** Build a canonical ToolError for a thrown exception caught by the tool
|
|
95
186
|
* envelope. The MCP SDK stringifies thrown objects as "[object Object]" by
|
|
96
187
|
* default, so we extract a string-friendly message and tag the original
|
|
97
|
-
* error in `details` for the agent to inspect.
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
|
|
101
|
-
*
|
|
102
|
-
* Exported as `_caughtError` (the leading underscore signals the test-only
|
|
103
|
-
* seam) so the suite in run/index.test.ts can drive the envelope path
|
|
104
|
-
* without standing up a full recordTransaction pipeline. */
|
|
105
|
-
export declare function caughtError(toolName: 'record_transaction' | 'synthesize_policy' | 'simulate_policy' | 'verify_policy' | 'install_policy' | 'revoke_policy' | 'get_interpreter_info', code: ErrorCode, e: unknown): ToolError;
|
|
188
|
+
* error in `details` for the agent to inspect. Exported as a test-only seam
|
|
189
|
+
* so the suite in run/index.test.ts can drive the envelope path without
|
|
190
|
+
* standing up a full recordTransaction pipeline. */
|
|
191
|
+
export declare function caughtError(toolName: RunToolName, code: ErrorCode, e: unknown): ToolError;
|