@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-cjs/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;
|