sigild 0.0.12 → 0.0.14
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 +63 -3
- package/THREAT_MODEL.md +4 -0
- package/dist/src/audit/index.d.ts +2 -1
- package/dist/src/audit/index.d.ts.map +1 -1
- package/dist/src/audit/index.js +1 -0
- package/dist/src/audit/index.js.map +1 -1
- package/dist/src/audit/log.d.ts +52 -3
- package/dist/src/audit/log.d.ts.map +1 -1
- package/dist/src/audit/log.js +226 -40
- package/dist/src/audit/log.js.map +1 -1
- package/dist/src/bin/sigil-mcp.js +79 -9
- package/dist/src/bin/sigil-mcp.js.map +1 -1
- package/dist/src/cli/main.d.ts.map +1 -1
- package/dist/src/cli/main.js +35 -1
- package/dist/src/cli/main.js.map +1 -1
- package/dist/src/cli/paths.d.ts +4 -0
- package/dist/src/cli/paths.d.ts.map +1 -1
- package/dist/src/cli/paths.js +2 -0
- package/dist/src/cli/paths.js.map +1 -1
- package/dist/src/cli/portal.d.ts.map +1 -1
- package/dist/src/cli/portal.js +11 -1
- package/dist/src/cli/portal.js.map +1 -1
- package/dist/src/confirm/config.d.ts +19 -0
- package/dist/src/confirm/config.d.ts.map +1 -1
- package/dist/src/confirm/config.js +48 -0
- package/dist/src/confirm/config.js.map +1 -1
- package/dist/src/confirm/index.d.ts +1 -1
- package/dist/src/confirm/index.d.ts.map +1 -1
- package/dist/src/confirm/index.js.map +1 -1
- package/dist/src/daemon/handles.d.ts +6 -0
- package/dist/src/daemon/handles.d.ts.map +1 -1
- package/dist/src/daemon/handles.js +11 -0
- package/dist/src/daemon/handles.js.map +1 -1
- package/dist/src/daemon/index.d.ts +1 -1
- package/dist/src/daemon/index.d.ts.map +1 -1
- package/dist/src/daemon/index.js.map +1 -1
- package/dist/src/daemon/methods.d.ts +29 -1
- package/dist/src/daemon/methods.d.ts.map +1 -1
- package/dist/src/daemon/methods.js +293 -27
- package/dist/src/daemon/methods.js.map +1 -1
- package/dist/src/eth/abi.d.ts +82 -0
- package/dist/src/eth/abi.d.ts.map +1 -0
- package/dist/src/eth/abi.js +328 -0
- package/dist/src/eth/abi.js.map +1 -0
- package/dist/src/eth/index.d.ts +1 -0
- package/dist/src/eth/index.d.ts.map +1 -1
- package/dist/src/eth/index.js +1 -0
- package/dist/src/eth/index.js.map +1 -1
- package/dist/src/fs/index.d.ts +2 -0
- package/dist/src/fs/index.d.ts.map +1 -0
- package/dist/src/fs/index.js +2 -0
- package/dist/src/fs/index.js.map +1 -0
- package/dist/src/fs/lock.d.ts +84 -0
- package/dist/src/fs/lock.d.ts.map +1 -0
- package/dist/src/fs/lock.js +329 -0
- package/dist/src/fs/lock.js.map +1 -0
- package/dist/src/mcp/parent-watchdog.d.ts +31 -0
- package/dist/src/mcp/parent-watchdog.d.ts.map +1 -0
- package/dist/src/mcp/parent-watchdog.js +35 -0
- package/dist/src/mcp/parent-watchdog.js.map +1 -0
- package/dist/src/mcp/server.d.ts +7 -0
- package/dist/src/mcp/server.d.ts.map +1 -1
- package/dist/src/mcp/server.js +13 -2
- package/dist/src/mcp/server.js.map +1 -1
- package/dist/src/mcp/tools.d.ts.map +1 -1
- package/dist/src/mcp/tools.js +21 -1
- package/dist/src/mcp/tools.js.map +1 -1
- package/dist/src/policy/evaluate.d.ts.map +1 -1
- package/dist/src/policy/evaluate.js +69 -4
- package/dist/src/policy/evaluate.js.map +1 -1
- package/dist/src/policy/index.d.ts +2 -0
- package/dist/src/policy/index.d.ts.map +1 -1
- package/dist/src/policy/index.js +2 -0
- package/dist/src/policy/index.js.map +1 -1
- package/dist/src/policy/ledger.d.ts +84 -0
- package/dist/src/policy/ledger.d.ts.map +1 -0
- package/dist/src/policy/ledger.js +276 -0
- package/dist/src/policy/ledger.js.map +1 -0
- package/dist/src/policy/loader.d.ts.map +1 -1
- package/dist/src/policy/loader.js +54 -0
- package/dist/src/policy/loader.js.map +1 -1
- package/dist/src/policy/template.d.ts +2 -2
- package/dist/src/policy/template.d.ts.map +1 -1
- package/dist/src/policy/template.js +52 -0
- package/dist/src/policy/template.js.map +1 -1
- package/dist/src/policy/types.d.ts +42 -0
- package/dist/src/policy/types.d.ts.map +1 -1
- package/dist/src/policy/types.js.map +1 -1
- package/dist/src/policy/window.d.ts +22 -0
- package/dist/src/policy/window.d.ts.map +1 -0
- package/dist/src/policy/window.js +66 -0
- package/dist/src/policy/window.js.map +1 -0
- package/dist/src/preview/abi-dir.d.ts +50 -0
- package/dist/src/preview/abi-dir.d.ts.map +1 -0
- package/dist/src/preview/abi-dir.js +175 -0
- package/dist/src/preview/abi-dir.js.map +1 -0
- package/dist/src/preview/decode.d.ts +26 -0
- package/dist/src/preview/decode.d.ts.map +1 -0
- package/dist/src/preview/decode.js +110 -0
- package/dist/src/preview/decode.js.map +1 -0
- package/dist/src/preview/format.d.ts +45 -0
- package/dist/src/preview/format.d.ts.map +1 -0
- package/dist/src/preview/format.js +222 -0
- package/dist/src/preview/format.js.map +1 -0
- package/dist/src/preview/index.d.ts +60 -0
- package/dist/src/preview/index.d.ts.map +1 -0
- package/dist/src/preview/index.js +163 -0
- package/dist/src/preview/index.js.map +1 -0
- package/dist/src/preview/known.d.ts +74 -0
- package/dist/src/preview/known.d.ts.map +1 -0
- package/dist/src/preview/known.js +425 -0
- package/dist/src/preview/known.js.map +1 -0
- package/dist/src/preview/simulate.d.ts +156 -0
- package/dist/src/preview/simulate.d.ts.map +1 -0
- package/dist/src/preview/simulate.js +768 -0
- package/dist/src/preview/simulate.js.map +1 -0
- package/dist/src/preview/simulators.d.ts +39 -0
- package/dist/src/preview/simulators.d.ts.map +1 -0
- package/dist/src/preview/simulators.js +71 -0
- package/dist/src/preview/simulators.js.map +1 -0
- package/dist/src/preview/trust.d.ts +49 -0
- package/dist/src/preview/trust.d.ts.map +1 -0
- package/dist/src/preview/trust.js +279 -0
- package/dist/src/preview/trust.js.map +1 -0
- package/dist/src/preview/types.d.ts +69 -0
- package/dist/src/preview/types.d.ts.map +1 -0
- package/dist/src/preview/types.js +11 -0
- package/dist/src/preview/types.js.map +1 -0
- package/dist/src/preview/units.d.ts +75 -0
- package/dist/src/preview/units.d.ts.map +1 -0
- package/dist/src/preview/units.js +228 -0
- package/dist/src/preview/units.js.map +1 -0
- package/package.json +5 -5
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { AbiDecodeError, decodeAbiTypes } from '../eth/abi.js';
|
|
2
|
+
import { KNOWN_FUNCTIONS } from './known.js';
|
|
3
|
+
import { NO_META } from './types.js';
|
|
4
|
+
import { renderValue } from './units.js';
|
|
5
|
+
/** Cap on a generic (user-ABI) call line, so one huge argument can't flood the push. */
|
|
6
|
+
const MAX_TEXT = 400;
|
|
7
|
+
export function decodeCalldata(data, registry, meta = NO_META, ctx = {}) {
|
|
8
|
+
if (ctx.to === null) {
|
|
9
|
+
return {
|
|
10
|
+
selector: null,
|
|
11
|
+
text: `contract creation, ${data.length}-byte initcode`,
|
|
12
|
+
warnings: [],
|
|
13
|
+
source: 'deploy',
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
if (data.length === 0) {
|
|
17
|
+
return { selector: null, text: 'plain ETH transfer', warnings: [], source: 'empty' };
|
|
18
|
+
}
|
|
19
|
+
if (data.length < 4) {
|
|
20
|
+
return {
|
|
21
|
+
selector: null,
|
|
22
|
+
text: `malformed calldata (${data.length} bytes, too short for a selector)`,
|
|
23
|
+
warnings: [`calldata is ${data.length} bytes — too short to hold a function selector`],
|
|
24
|
+
source: 'unknown',
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
const selector = '0x' + Buffer.from(data.subarray(0, 4)).toString('hex');
|
|
28
|
+
const builtin = KNOWN_FUNCTIONS.get(selector);
|
|
29
|
+
const user = registry.lookup(selector);
|
|
30
|
+
const def = builtin ?? user;
|
|
31
|
+
if (!def) {
|
|
32
|
+
return {
|
|
33
|
+
selector,
|
|
34
|
+
text: `unknown function ${selector} (${data.length} bytes calldata)`,
|
|
35
|
+
warnings: [`unknown selector ${selector} — calldata not decoded`],
|
|
36
|
+
source: 'unknown',
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
const source = builtin ? 'builtin' : 'abi';
|
|
40
|
+
const base = { selector, signature: def.signature, name: def.name, source };
|
|
41
|
+
let values;
|
|
42
|
+
try {
|
|
43
|
+
values = decodeAbiTypes(def.inputs.map((i) => i.abiType), data.subarray(4));
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
if (!(err instanceof AbiDecodeError))
|
|
47
|
+
throw err;
|
|
48
|
+
return {
|
|
49
|
+
...base,
|
|
50
|
+
text: `${def.name}(…) — calldata does not match ${def.signature}`,
|
|
51
|
+
warnings: [`calldata does not decode as ${def.signature}: ${err.message}`],
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
// A user ABI naming the same selector supplies the argument names; the
|
|
55
|
+
// built-in still writes the sentence.
|
|
56
|
+
const names = builtin && user && user.inputs.length === builtin.inputs.length
|
|
57
|
+
? user.inputs.map((i) => i.name)
|
|
58
|
+
: def.inputs.map((i) => i.name);
|
|
59
|
+
const args = def.inputs.map((inp, i) => ({
|
|
60
|
+
name: names[i],
|
|
61
|
+
type: inp.type,
|
|
62
|
+
value: renderValue(inp.type, values[i]),
|
|
63
|
+
}));
|
|
64
|
+
if (builtin) {
|
|
65
|
+
const depth = ctx.depth ?? 0;
|
|
66
|
+
const dctx = {
|
|
67
|
+
to: ctx.to?.toLowerCase() ?? null,
|
|
68
|
+
value: ctx.value ?? 0n,
|
|
69
|
+
meta,
|
|
70
|
+
...(ctx.from !== undefined ? { from: ctx.from.toLowerCase() } : {}),
|
|
71
|
+
...(depth === 0
|
|
72
|
+
? {
|
|
73
|
+
decodeInner: (d) => decodeCalldata(d, registry, meta, { ...ctx, depth: 1 }),
|
|
74
|
+
}
|
|
75
|
+
: {}),
|
|
76
|
+
};
|
|
77
|
+
let desc;
|
|
78
|
+
try {
|
|
79
|
+
desc = builtin.describe(values, dctx);
|
|
80
|
+
}
|
|
81
|
+
catch (err) {
|
|
82
|
+
// A describe bug must not block signing; say so and fall back to the
|
|
83
|
+
// generic rendering.
|
|
84
|
+
desc = {
|
|
85
|
+
text: genericText(def.name, args, values, def.inputs),
|
|
86
|
+
warnings: [`could not describe ${def.signature}: ${err.message}`],
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
...base,
|
|
91
|
+
args,
|
|
92
|
+
text: desc.text,
|
|
93
|
+
...(desc.short !== undefined ? { short: desc.short } : {}),
|
|
94
|
+
warnings: desc.warnings,
|
|
95
|
+
...(desc.tokens && desc.tokens.length > 0 ? { tokens: dedupe(desc.tokens) } : {}),
|
|
96
|
+
...(desc.swapOut ? { swapOut: desc.swapOut } : {}),
|
|
97
|
+
...(desc.innerSwaps ? { innerSwaps: desc.innerSwaps } : {}),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
return { ...base, args, text: genericText(def.name, args, values, def.inputs), warnings: [] };
|
|
101
|
+
}
|
|
102
|
+
function genericText(name, args, values, inputs) {
|
|
103
|
+
const parts = args.map((a, i) => `${a.name}=${renderValue(inputs[i].type, values[i], true)}`);
|
|
104
|
+
const text = `${name}(${parts.join(', ')})`;
|
|
105
|
+
return text.length > MAX_TEXT ? text.slice(0, MAX_TEXT - 1) + '…' : text;
|
|
106
|
+
}
|
|
107
|
+
function dedupe(xs) {
|
|
108
|
+
return [...new Set(xs.map((x) => x.toLowerCase()))];
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=decode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decode.js","sourceRoot":"","sources":["../../../src/preview/decode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/D,OAAO,EAAsC,eAAe,EAAE,MAAM,YAAY,CAAC;AACjF,OAAO,EAAqC,OAAO,EAAwB,MAAM,YAAY,CAAC;AAC9F,OAAO,EAAE,WAAW,EAAE,M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C,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC,CAAE,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;IAC/F,MAAM,IAAI,GAAG,GAAG,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;IAC5C,OAAO,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;AAC3E,CAAC;AAED,SAAS,MAAM,CAAC,EAAY;IAC1B,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC;AACtD,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Simulation } from './simulate.js';
|
|
2
|
+
import type { DecodedCall, TokenMetaLookup } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Rendering for the transaction preview. Pure: given the same decode and
|
|
5
|
+
* simulation it produces byte-identical text, so tests can pin it and the
|
|
6
|
+
* audit log records exactly what the human and the agent were shown.
|
|
7
|
+
*
|
|
8
|
+
* Two shapes:
|
|
9
|
+
* - `renderText`: multi-line, for the agent and the audit log.
|
|
10
|
+
* - `renderHeadline`: one line, ` | `-separated, ≤ ~220 chars, for the
|
|
11
|
+
* phone push where the first glance has to carry the decision.
|
|
12
|
+
*/
|
|
13
|
+
export type PreviewSimulation = Simulation | {
|
|
14
|
+
status: 'skipped';
|
|
15
|
+
reason: string;
|
|
16
|
+
};
|
|
17
|
+
export interface RenderInput {
|
|
18
|
+
decoded: DecodedCall;
|
|
19
|
+
simulation: PreviewSimulation;
|
|
20
|
+
warnings: readonly string[];
|
|
21
|
+
/** Lowercase portal address. */
|
|
22
|
+
from: string;
|
|
23
|
+
/** Lowercase destination, null for a deploy. */
|
|
24
|
+
to: string | null;
|
|
25
|
+
value: bigint;
|
|
26
|
+
chainId: bigint;
|
|
27
|
+
meta: TokenMetaLookup;
|
|
28
|
+
/** Extra trailing lines (e.g. `abi: skipped foo.json: invalid JSON`). */
|
|
29
|
+
footer?: readonly string[];
|
|
30
|
+
}
|
|
31
|
+
export declare const HEADLINE_MAX = 220;
|
|
32
|
+
export declare function renderText(r: RenderInput): string;
|
|
33
|
+
/**
|
|
34
|
+
* The phone headline. What leaves the portal is the decision, so the
|
|
35
|
+
* simulation part lists every debit — native and token outflows, NFTs out,
|
|
36
|
+
* approvals granted — BEFORE any credit, and debits are never cut to fit:
|
|
37
|
+
* a run of attacker-emitted "+1 USDC" credits must not push a real drain
|
|
38
|
+
* off the screen. Only the call description (clipped), the credits
|
|
39
|
+
* (`+N more in`) and the warnings (down to `⚠ N warnings`) give way to
|
|
40
|
+
* HEADLINE_MAX; a headline is longer than that only when the debits are.
|
|
41
|
+
*/
|
|
42
|
+
export declare function renderHeadline(r: RenderInput): string;
|
|
43
|
+
/** One-line simulation status, also what the audit entry records. */
|
|
44
|
+
export declare function simulationSummary(sim: PreviewSimulation): string;
|
|
45
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../../src/preview/format.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA4B,UAAU,EAAE,MAAM,eAAe,CAAC;AAC1E,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAW/D;;;;;;;;;GASG;AAEH,MAAM,MAAM,iBAAiB,GAAG,UAAU,GAAG;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnF,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,WAAW,CAAC;IACrB,UAAU,EAAE,iBAAiB,CAAC;IAC9B,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,gDAAgD;IAChD,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,eAAe,CAAC;IACtB,yEAAyE;IACzE,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC5B;AAED,eAAO,MAAM,YAAY,MAAM,CAAC;AAEhC,wBAAgB,UAAU,CAAC,CAAC,EAAE,WAAW,GAAG,MAAM,CAkCjD;AAOD;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,WAAW,GAAG,MAAM,CAqDrD;AAMD,qEAAqE;AACrE,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,iBAAiB,GAAG,MAAM,CAehE"}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { clean, formatEth, groupThousands, headAmount, isUnlimited, shortAddr, tokenLabel, } from './units.js';
|
|
2
|
+
export const HEADLINE_MAX = 220;
|
|
3
|
+
export function renderText(r) {
|
|
4
|
+
const lines = [];
|
|
5
|
+
lines.push(`call: ${callLine(r)}`);
|
|
6
|
+
lines.push(`value: ${formatEth(r.value)} chain: ${r.chainId}`);
|
|
7
|
+
lines.push(`simulation: ${simulationSummary(r.simulation)}`);
|
|
8
|
+
const sim = r.simulation;
|
|
9
|
+
if (sim.status === 'ok' || sim.status === 'reverted') {
|
|
10
|
+
for (const note of sim.notes)
|
|
11
|
+
lines.push(` note: ${note}`);
|
|
12
|
+
if (sim.status === 'ok') {
|
|
13
|
+
if (sim.approvals && sim.approvals.length > 0) {
|
|
14
|
+
lines.push(` approvals: ${sim.approvals.map((a) => approvalText(a, r.meta)).join('; ')}`);
|
|
15
|
+
}
|
|
16
|
+
if (sim.changes) {
|
|
17
|
+
const deltas = deltaTexts(sim, r.meta);
|
|
18
|
+
lines.push(` balance changes for ${shortAddr(r.from)}: ${deltas.length ? deltas.join(', ') : 'none'}`);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
lines.push(` balance changes: unknown (no event logs from this node)`);
|
|
22
|
+
}
|
|
23
|
+
if (sim.transfers && sim.transfers.length > 0) {
|
|
24
|
+
const more = sim.transfersOmitted > 0 ? `, ${sim.transfersOmitted} more not shown` : '';
|
|
25
|
+
lines.push(` transfers (${sim.transfers.length}${more}):`);
|
|
26
|
+
for (const t of sim.transfers)
|
|
27
|
+
lines.push(` ${transferText(t, r.meta)}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (r.warnings.length > 0) {
|
|
32
|
+
lines.push('warnings:');
|
|
33
|
+
for (const w of r.warnings)
|
|
34
|
+
lines.push(` - ${w}`);
|
|
35
|
+
}
|
|
36
|
+
for (const f of r.footer ?? [])
|
|
37
|
+
lines.push(f);
|
|
38
|
+
// The one place lines are joined: nothing inside a line may start a new one.
|
|
39
|
+
return lines.map(clean).join('\n');
|
|
40
|
+
}
|
|
41
|
+
/** Debits beyond this many are summarized (loudly) rather than listed. */
|
|
42
|
+
const MAX_HEADLINE_DEBITS = 40;
|
|
43
|
+
/** The call description's share of the headline; the rest is for effects. */
|
|
44
|
+
const HEADLINE_CALL_MAX = 90;
|
|
45
|
+
/**
|
|
46
|
+
* The phone headline. What leaves the portal is the decision, so the
|
|
47
|
+
* simulation part lists every debit — native and token outflows, NFTs out,
|
|
48
|
+
* approvals granted — BEFORE any credit, and debits are never cut to fit:
|
|
49
|
+
* a run of attacker-emitted "+1 USDC" credits must not push a real drain
|
|
50
|
+
* off the screen. Only the call description (clipped), the credits
|
|
51
|
+
* (`+N more in`) and the warnings (down to `⚠ N warnings`) give way to
|
|
52
|
+
* HEADLINE_MAX; a headline is longer than that only when the debits are.
|
|
53
|
+
*/
|
|
54
|
+
export function renderHeadline(r) {
|
|
55
|
+
const call = clip(headlineCall(r), HEADLINE_CALL_MAX);
|
|
56
|
+
const sim = r.simulation;
|
|
57
|
+
let simPart;
|
|
58
|
+
let credits = [];
|
|
59
|
+
switch (sim.status) {
|
|
60
|
+
case 'ok': {
|
|
61
|
+
const f = flows(sim, r.meta);
|
|
62
|
+
const debits = f.debits.length > MAX_HEADLINE_DEBITS
|
|
63
|
+
? [
|
|
64
|
+
...f.debits.slice(0, MAX_HEADLINE_DEBITS),
|
|
65
|
+
`!! ${f.debits.length - MAX_HEADLINE_DEBITS} MORE DEBITS — read the preview`,
|
|
66
|
+
]
|
|
67
|
+
: f.debits;
|
|
68
|
+
simPart = ['sim ok', ...debits].join(' ');
|
|
69
|
+
credits = f.credits;
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
case 'reverted':
|
|
73
|
+
simPart = `sim REVERTED: ${clip(sim.revertReason ?? 'unknown reason', 80)}`;
|
|
74
|
+
break;
|
|
75
|
+
case 'unavailable':
|
|
76
|
+
simPart = 'sim unavailable';
|
|
77
|
+
break;
|
|
78
|
+
case 'skipped':
|
|
79
|
+
simPart = 'no sim';
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
let line = `${call} | ${simPart}`;
|
|
83
|
+
const n = r.warnings.length;
|
|
84
|
+
const minWarn = n > 0 ? ` | ⚠ ${n} warning${n === 1 ? '' : 's'}` : '';
|
|
85
|
+
// Credits: as many as fit while leaving room for at least the warning count.
|
|
86
|
+
for (let i = 0; i < credits.length; i++) {
|
|
87
|
+
const rest = credits.length - i - 1;
|
|
88
|
+
const tail = rest > 0 ? ` +${rest} more in` : '';
|
|
89
|
+
if (line.length + 1 + credits[i].length + tail.length + minWarn.length > HEADLINE_MAX) {
|
|
90
|
+
line += ` +${credits.length - i} more in`;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
line += ` ${credits[i]}`;
|
|
94
|
+
}
|
|
95
|
+
if (n > 0) {
|
|
96
|
+
const more = n > 1 ? ` (+${n - 1} more)` : '';
|
|
97
|
+
const full = ` | ⚠ ${r.warnings[0]}${more}`;
|
|
98
|
+
const room = HEADLINE_MAX - line.length;
|
|
99
|
+
if (full.length <= room)
|
|
100
|
+
line += full;
|
|
101
|
+
else if (room > minWarn.length + 12)
|
|
102
|
+
line += clip(` | ⚠ ${r.warnings[0]}`, room - more.length) + more;
|
|
103
|
+
else
|
|
104
|
+
line += minWarn;
|
|
105
|
+
}
|
|
106
|
+
return clean(line);
|
|
107
|
+
}
|
|
108
|
+
function clip(s, max) {
|
|
109
|
+
return s.length > max ? s.slice(0, max - 1) + '…' : s;
|
|
110
|
+
}
|
|
111
|
+
/** One-line simulation status, also what the audit entry records. */
|
|
112
|
+
export function simulationSummary(sim) {
|
|
113
|
+
switch (sim.status) {
|
|
114
|
+
case 'ok':
|
|
115
|
+
case 'reverted': {
|
|
116
|
+
const gas = sim.gasUsed !== null ? `, ${groupThousands(sim.gasUsed)} gas` : '';
|
|
117
|
+
const via = sim.method === 'eth_call' ? ' (eth_call)' : '';
|
|
118
|
+
return sim.status === 'ok'
|
|
119
|
+
? `ok${gas}${via}`
|
|
120
|
+
: `REVERTED — ${sim.revertReason ?? 'unknown reason'}${via}`;
|
|
121
|
+
}
|
|
122
|
+
case 'unavailable':
|
|
123
|
+
return `unavailable — ${sim.reason}`;
|
|
124
|
+
case 'skipped':
|
|
125
|
+
return `skipped — ${sim.reason}`;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function callLine(r) {
|
|
129
|
+
const d = r.decoded;
|
|
130
|
+
if (d.source === 'deploy')
|
|
131
|
+
return d.text;
|
|
132
|
+
if (r.to === null)
|
|
133
|
+
return d.text;
|
|
134
|
+
if (d.source === 'empty')
|
|
135
|
+
return `plain ETH transfer to ${shortAddr(r.to)}`;
|
|
136
|
+
const sym = r.meta(r.to)?.symbol;
|
|
137
|
+
return `${d.text} on ${shortAddr(r.to)}${sym ? ` (${sym})` : ''}`;
|
|
138
|
+
}
|
|
139
|
+
function headlineCall(r) {
|
|
140
|
+
const d = r.decoded;
|
|
141
|
+
if (d.source === 'empty' && r.to !== null) {
|
|
142
|
+
return `send ${formatEth(r.value)} → ${shortAddr(r.to)}`;
|
|
143
|
+
}
|
|
144
|
+
let s = d.short ?? (r.to !== null && d.source !== 'deploy' ? `${d.text} → ${shortAddr(r.to)}` : d.text);
|
|
145
|
+
const eth = formatEth(r.value);
|
|
146
|
+
if (r.value > 0n && !s.includes(eth))
|
|
147
|
+
s += `, value ${eth}`;
|
|
148
|
+
return s;
|
|
149
|
+
}
|
|
150
|
+
function signed(delta, render) {
|
|
151
|
+
return `${delta < 0n ? '-' : '+'}${render(delta < 0n ? -delta : delta)}`;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Split the portal's balance changes into debits (incl. approvals it
|
|
155
|
+
* grants) and credits, debits first in a stable order.
|
|
156
|
+
*/
|
|
157
|
+
function flows(sim, meta, withApprovals = true) {
|
|
158
|
+
const debits = [];
|
|
159
|
+
const credits = [];
|
|
160
|
+
const c = sim.changes;
|
|
161
|
+
if (c) {
|
|
162
|
+
if (c.native < 0n)
|
|
163
|
+
debits.push(signed(c.native, formatEth));
|
|
164
|
+
if (c.native > 0n)
|
|
165
|
+
credits.push(signed(c.native, formatEth));
|
|
166
|
+
for (const e of c.erc20) {
|
|
167
|
+
(e.delta < 0n ? debits : credits).push(signed(e.delta, (v) => headAmount(v, e.token, meta)));
|
|
168
|
+
}
|
|
169
|
+
for (const nft of c.nftOut)
|
|
170
|
+
debits.push(`-NFT ${shortAddr(nft.token)} #${nft.tokenId}`);
|
|
171
|
+
for (const nft of c.nftIn)
|
|
172
|
+
credits.push(`+NFT ${shortAddr(nft.token)} #${nft.tokenId}`);
|
|
173
|
+
for (const e of c.erc1155) {
|
|
174
|
+
(e.delta < 0n ? debits : credits).push(signed(e.delta, (v) => `${v} × id ${e.tokenId} of ${shortAddr(e.token)}`));
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
for (const a of withApprovals ? (sim.approvals ?? []) : []) {
|
|
178
|
+
const revoke = (a.standard === 'erc20' && (a.amount ?? 0n) === 0n) ||
|
|
179
|
+
(a.standard === 'operator' && !a.approved);
|
|
180
|
+
if (!revoke)
|
|
181
|
+
debits.push(`grants ${approvalText(a, meta)}`);
|
|
182
|
+
}
|
|
183
|
+
return { debits, credits };
|
|
184
|
+
}
|
|
185
|
+
/** Balance changes for the long-form text: debits first, then credits. */
|
|
186
|
+
function deltaTexts(sim, meta) {
|
|
187
|
+
const f = flows(sim, meta, false);
|
|
188
|
+
return [...f.debits, ...f.credits];
|
|
189
|
+
}
|
|
190
|
+
function approvalText(a, meta) {
|
|
191
|
+
switch (a.standard) {
|
|
192
|
+
case 'erc20': {
|
|
193
|
+
const amt = a.amount ?? 0n;
|
|
194
|
+
const label = tokenLabel(a.token, meta);
|
|
195
|
+
if (amt === 0n)
|
|
196
|
+
return `${label} → ${shortAddr(a.spender)} revoked`;
|
|
197
|
+
if (isUnlimited(amt))
|
|
198
|
+
return `${label} → ${shortAddr(a.spender)} UNLIMITED`;
|
|
199
|
+
return `${label} → ${shortAddr(a.spender)} ${headAmount(amt, a.token, meta)}`;
|
|
200
|
+
}
|
|
201
|
+
case 'erc721':
|
|
202
|
+
return `NFT ${shortAddr(a.token)} #${a.tokenId} → ${shortAddr(a.spender)}`;
|
|
203
|
+
case 'operator':
|
|
204
|
+
return a.approved
|
|
205
|
+
? `ALL of ${shortAddr(a.token)} → ${shortAddr(a.spender)}`
|
|
206
|
+
: `ALL of ${shortAddr(a.token)} → ${shortAddr(a.spender)} revoked`;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
function transferText(t, meta) {
|
|
210
|
+
const route = `${shortAddr(t.from)} → ${shortAddr(t.to)}`;
|
|
211
|
+
switch (t.standard) {
|
|
212
|
+
case 'native':
|
|
213
|
+
return `${formatEth(t.amount)} ${route}`;
|
|
214
|
+
case 'erc20':
|
|
215
|
+
return `${headAmount(t.amount, t.token, meta)} ${route}`;
|
|
216
|
+
case 'erc721':
|
|
217
|
+
return `NFT ${shortAddr(t.token)} #${t.tokenId} ${route}`;
|
|
218
|
+
case 'erc1155':
|
|
219
|
+
return `${t.amount} × id ${t.tokenId} of ${shortAddr(t.token)} ${route}`;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
//# sourceMappingURL=format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../../src/preview/format.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,EACL,SAAS,EACT,cAAc,EACd,UAAU,EACV,WAAW,EACX,SAAS,EACT,UAAU,GACX,MAAM,YAAY,CAAC;AA8BpB,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,CAAC;AAEhC,MAAM,UAAU,UAAU,CAAC,CAAc;IACvC,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,CAAC,IAAI,CAAC,SAAS,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IACnC,KAAK,CAAC,IAAI,CAAC,UAAU,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;IACjE,KAAK,CAAC,IAAI,CAAC,eAAe,iBAAiB,CAAC,CAAC,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;IAC7D,MAAM,GAAG,GAAG,CAAC,CAAC,UAAU,CAAC;IACzB,IAAI,GAAG,CAAC,MAAM,KAAK,IAAI,IAAI,GAAG,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;QACrD,KAAK,MAAM,IAAI,IAAI,GAAG,CAAC,KAAK;YAAE,KAAK,CAAC,IAAI,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC;QAC5D,IAAI,GAAG,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC;YACxB,IAAI,GAAG,CAAC,SAAS,IAAI,GAAG,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AM,SAAS,CAAC,CAAC,OAAO,OAAO,SAAS,CAAC,CAAC,CAAC,KAAM,CAAC,IAAI,KAAK,EAAE,CAAC;IAC9E,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { SignableTx } from '../eth/index.js';
|
|
2
|
+
import type { JsonRpcUpstream } from '../rpc/upstream.js';
|
|
3
|
+
import { AbiRegistry } from './abi-dir.js';
|
|
4
|
+
import { type PreviewSimulation } from './format.js';
|
|
5
|
+
import { type DecodedCall } from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* "Show me what I'm signing": decode an EVM transaction to English and, when
|
|
8
|
+
* an RPC node is configured for its chain, dry-run it. The result feeds
|
|
9
|
+
* three readers — the human (confirm push headline), the agent (returned
|
|
10
|
+
* text) and the audit log — and two opt-in policy gates (deny on revert,
|
|
11
|
+
* require simulation) that the sign path applies.
|
|
12
|
+
*/
|
|
13
|
+
export interface TxPreview {
|
|
14
|
+
decoded: DecodedCall;
|
|
15
|
+
simulation: PreviewSimulation;
|
|
16
|
+
warnings: string[];
|
|
17
|
+
/** Multi-line, for the agent and the audit log. */
|
|
18
|
+
text: string;
|
|
19
|
+
/** One line, for the confirm push. */
|
|
20
|
+
headline: string;
|
|
21
|
+
}
|
|
22
|
+
export interface BuildTxPreviewInput {
|
|
23
|
+
tx: SignableTx;
|
|
24
|
+
/** The signing portal's address. */
|
|
25
|
+
from: string;
|
|
26
|
+
registry: AbiRegistry;
|
|
27
|
+
/** RPC node for this tx's chain; undefined = no simulation (skipped). */
|
|
28
|
+
simulator?: JsonRpcUpstream;
|
|
29
|
+
/** Why there is no simulator, when the caller knows better than the default. */
|
|
30
|
+
skippedReason?: string;
|
|
31
|
+
timeoutMs?: number;
|
|
32
|
+
}
|
|
33
|
+
export declare function buildTxPreview(input: BuildTxPreviewInput): Promise<TxPreview>;
|
|
34
|
+
/** The simulation ran without the signed fee fields (see simulate.ts). */
|
|
35
|
+
export declare const UNFAITHFUL_WARNING = "simulated without fee fields (node refused: insufficient funds) \u2014 the contract saw tx.gasprice = 0";
|
|
36
|
+
/**
|
|
37
|
+
* Stand-in when building the preview itself failed (a bug, not a node
|
|
38
|
+
* problem — those are already 'unavailable'). Presentation fails open but
|
|
39
|
+
* loud: the sign path proceeds with this warning unless the policy demands
|
|
40
|
+
* a simulation, in which case the 'unavailable' status denies (fail closed).
|
|
41
|
+
*/
|
|
42
|
+
export declare function previewFailure(message: string): TxPreview;
|
|
43
|
+
/** The compact form written into the audit entry. */
|
|
44
|
+
export declare function auditPreview(p: TxPreview): {
|
|
45
|
+
text: string;
|
|
46
|
+
decoded: string;
|
|
47
|
+
simulation: string;
|
|
48
|
+
warnings: string[];
|
|
49
|
+
};
|
|
50
|
+
/** Deep-convert bigints to decimal strings so the value can be JSON-serialized. */
|
|
51
|
+
export declare function jsonSafe(v: unknown): unknown;
|
|
52
|
+
export { AbiRegistry, type AbiFunction, type AbiInput } from './abi-dir.js';
|
|
53
|
+
export { SimulatorResolver, type SimulatorResolverOpts } from './simulators.js';
|
|
54
|
+
export { decodeCalldata, type DecodeCtx } from './decode.js';
|
|
55
|
+
export { simulateTransaction, analyzeLogs, decodeRevert, fetchTokenMeta, parseSymbol, parseDecimals, DEFAULT_SIM_TIMEOUT_MS, type Simulation, type SimTransfer, type SimApproval, type BalanceChanges, type RawLog, type SimulateOpts, } from './simulate.js';
|
|
56
|
+
export { renderText, renderHeadline, simulationSummary, HEADLINE_MAX, type PreviewSimulation, } from './format.js';
|
|
57
|
+
export { KNOWN_FUNCTIONS, EVENT_TOPICS, decodeV3Path, type KnownFunction } from './known.js';
|
|
58
|
+
export type { DecodedCall, DecodedArg, TokenMeta, TokenMetaLookup } from './types.js';
|
|
59
|
+
export { formatUnits, shortAddr, sanitizeSymbol } from './units.js';
|
|
60
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/preview/index.ts"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mFAAmF;AACnF,wBAAgB,QAAQ,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAS5C;AAED,OAAO,EAAE,WAAW,EAAE,KAAK,WAAW,EAAE,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,KAAK,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EACL,mBAAmB,EACnB,WAAW,EACX,YAAY,EACZ,cAAc,EACd,WAAW,EACX,aAAa,EACb,sBAAsB,EACtB,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,MAAM,EACX,KAAK,YAAY,GAClB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,UAAU,EACV,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,KAAK,iBAAiB,GACvB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,YAAY,EAAE,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAC7F,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACtF,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { decodeCalldata } from './decode.js';
|
|
2
|
+
import { renderHeadline, renderText, simulationSummary } from './format.js';
|
|
3
|
+
import { operatorWarning } from './known.js';
|
|
4
|
+
import { simulateTransaction } from './simulate.js';
|
|
5
|
+
import { NO_META } from './types.js';
|
|
6
|
+
import { assessTokens, checkBehaviour, rawCallText } from './trust.js';
|
|
7
|
+
import { clean, isUnlimited, shortAddr } from './units.js';
|
|
8
|
+
export async function buildTxPreview(input) {
|
|
9
|
+
const { tx, registry } = input;
|
|
10
|
+
const from = input.from.toLowerCase();
|
|
11
|
+
const to = tx.to === null ? null : tx.to.toLowerCase();
|
|
12
|
+
const value = BigInt(tx.value);
|
|
13
|
+
const chainId = BigInt(tx.chainId);
|
|
14
|
+
const data = typeof tx.data === 'string' ? Buffer.from(tx.data.slice(2), 'hex') : Buffer.from(tx.data);
|
|
15
|
+
const ctx = { to, value, from };
|
|
16
|
+
// First pass with no metadata: learns which tokens the call names, so the
|
|
17
|
+
// simulator can fetch their symbol/decimals alongside the ones it touches.
|
|
18
|
+
const pre = decodeCalldata(data, registry, NO_META, ctx);
|
|
19
|
+
let simulation;
|
|
20
|
+
if (input.simulator === undefined) {
|
|
21
|
+
simulation = {
|
|
22
|
+
status: 'skipped',
|
|
23
|
+
reason: input.skippedReason ?? `no simulation RPC configured for chain ${chainId}`,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
simulation = await simulateTransaction(tx, from, input.simulator, {
|
|
28
|
+
...(input.timeoutMs !== undefined ? { timeoutMs: input.timeoutMs } : {}),
|
|
29
|
+
extraTokens: pre.tokens ?? [],
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
// Contract-reported symbols are vetted before anything renders them.
|
|
33
|
+
const trust = assessTokens(simulation.status === 'ok' || simulation.status === 'reverted' ? simulation.tokenMeta : {}, chainId);
|
|
34
|
+
const metaTable = trust.meta;
|
|
35
|
+
const meta = (addr) => Object.prototype.hasOwnProperty.call(metaTable, addr) ? metaTable[addr] : undefined;
|
|
36
|
+
let decoded = Object.keys(metaTable).length > 0 ? decodeCalldata(data, registry, meta, ctx) : pre;
|
|
37
|
+
// A friendly verb is only kept when the contract behaved like it.
|
|
38
|
+
const verdict = checkBehaviour(decoded, simulation, { from, to, chainId }, meta);
|
|
39
|
+
const trustWarnings = [];
|
|
40
|
+
if (verdict && !verdict.matches && verdict.rewrite !== false) {
|
|
41
|
+
const raw = rawCallText(decoded);
|
|
42
|
+
const { short: _dropped, ...rest } = decoded;
|
|
43
|
+
decoded = { ...rest, text: raw, short: `${raw} on ${shortAddr(to ?? '')}` };
|
|
44
|
+
}
|
|
45
|
+
if (verdict && !verdict.matches) {
|
|
46
|
+
if (verdict.warning)
|
|
47
|
+
trustWarnings.push(verdict.warning);
|
|
48
|
+
trustWarnings.push(...(verdict.more ?? []));
|
|
49
|
+
}
|
|
50
|
+
if (simulation.status === 'ok' && simulation.changes) {
|
|
51
|
+
const c = simulation.changes;
|
|
52
|
+
const debit = c.native < 0n ||
|
|
53
|
+
c.erc20.some((e) => e.delta < 0n) ||
|
|
54
|
+
c.nftOut.length > 0 ||
|
|
55
|
+
c.erc1155.some((e) => e.delta < 0n);
|
|
56
|
+
const shadyInflow = c.erc20.some((e) => e.delta > 0n && (trust.unverified.has(e.token) || !metaTable[e.token]?.symbol));
|
|
57
|
+
if (debit && shadyInflow)
|
|
58
|
+
trustWarnings.push('inflows from unverified tokens — check the debit');
|
|
59
|
+
}
|
|
60
|
+
// Most actionable first: behaviour mismatch and unverified inflows, then
|
|
61
|
+
// the per-token impersonation details.
|
|
62
|
+
trustWarnings.push(...trust.warnings);
|
|
63
|
+
const warnings = collectWarnings(decoded, simulation, { from, to, value }, trustWarnings);
|
|
64
|
+
const render = {
|
|
65
|
+
decoded,
|
|
66
|
+
simulation,
|
|
67
|
+
warnings,
|
|
68
|
+
from,
|
|
69
|
+
to,
|
|
70
|
+
value,
|
|
71
|
+
chainId,
|
|
72
|
+
meta,
|
|
73
|
+
footer: registry.loadWarnings,
|
|
74
|
+
};
|
|
75
|
+
return {
|
|
76
|
+
decoded,
|
|
77
|
+
simulation,
|
|
78
|
+
warnings,
|
|
79
|
+
text: renderText(render),
|
|
80
|
+
headline: renderHeadline(render),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/** The simulation ran without the signed fee fields (see simulate.ts). */
|
|
84
|
+
export const UNFAITHFUL_WARNING = 'simulated without fee fields (node refused: insufficient funds) — the contract saw tx.gasprice = 0';
|
|
85
|
+
function collectWarnings(decoded, sim, tx, trustWarnings) {
|
|
86
|
+
// Impersonation / behaviour warnings first: they explain everything else.
|
|
87
|
+
const out = [...trustWarnings, ...decoded.warnings];
|
|
88
|
+
if ((sim.status === 'ok' || sim.status === 'reverted') && !sim.faithful) {
|
|
89
|
+
out.push(UNFAITHFUL_WARNING);
|
|
90
|
+
}
|
|
91
|
+
if (sim.status === 'reverted')
|
|
92
|
+
out.push(`simulation reverted: ${sim.revertReason ?? 'unknown'}`);
|
|
93
|
+
if (sim.status === 'unavailable')
|
|
94
|
+
out.push(`simulation unavailable: ${sim.reason}`);
|
|
95
|
+
if (decoded.source === 'unknown' && tx.value > 0n) {
|
|
96
|
+
out.push('calldata to unknown function with ETH value');
|
|
97
|
+
}
|
|
98
|
+
if (tx.to !== null && tx.to === tx.from)
|
|
99
|
+
out.push("destination is the portal's own address");
|
|
100
|
+
if (sim.status === 'ok') {
|
|
101
|
+
for (const a of sim.approvals ?? []) {
|
|
102
|
+
if (a.standard === 'erc20' && a.amount !== undefined && isUnlimited(a.amount)) {
|
|
103
|
+
out.push('UNLIMITED approval');
|
|
104
|
+
}
|
|
105
|
+
if (a.standard === 'operator' && a.approved)
|
|
106
|
+
out.push(operatorWarning(a.spender, a.token));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return [...new Set(out.map(clean))];
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Stand-in when building the preview itself failed (a bug, not a node
|
|
113
|
+
* problem — those are already 'unavailable'). Presentation fails open but
|
|
114
|
+
* loud: the sign path proceeds with this warning unless the policy demands
|
|
115
|
+
* a simulation, in which case the 'unavailable' status denies (fail closed).
|
|
116
|
+
*/
|
|
117
|
+
export function previewFailure(message) {
|
|
118
|
+
const reason = `preview failed: ${message}`;
|
|
119
|
+
const decoded = {
|
|
120
|
+
selector: null,
|
|
121
|
+
text: reason,
|
|
122
|
+
warnings: [reason],
|
|
123
|
+
source: 'unknown',
|
|
124
|
+
};
|
|
125
|
+
return {
|
|
126
|
+
decoded,
|
|
127
|
+
simulation: { status: 'unavailable', reason },
|
|
128
|
+
warnings: [reason],
|
|
129
|
+
text: `call: ${reason}\nwarnings:\n - ${reason}`,
|
|
130
|
+
headline: `⚠ ${reason}`.slice(0, 220),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
/** The compact form written into the audit entry. */
|
|
134
|
+
export function auditPreview(p) {
|
|
135
|
+
return {
|
|
136
|
+
text: p.text,
|
|
137
|
+
decoded: clean(p.decoded.text),
|
|
138
|
+
simulation: clean(simulationSummary(p.simulation)),
|
|
139
|
+
warnings: p.warnings,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/** Deep-convert bigints to decimal strings so the value can be JSON-serialized. */
|
|
143
|
+
export function jsonSafe(v) {
|
|
144
|
+
if (typeof v === 'bigint')
|
|
145
|
+
return v.toString();
|
|
146
|
+
if (Array.isArray(v))
|
|
147
|
+
return v.map(jsonSafe);
|
|
148
|
+
if (typeof v === 'object' && v !== null) {
|
|
149
|
+
const out = {};
|
|
150
|
+
for (const [k, x] of Object.entries(v))
|
|
151
|
+
out[k] = jsonSafe(x);
|
|
152
|
+
return out;
|
|
153
|
+
}
|
|
154
|
+
return v;
|
|
155
|
+
}
|
|
156
|
+
export { AbiRegistry } from './abi-dir.js';
|
|
157
|
+
export { SimulatorResolver } from './simulators.js';
|
|
158
|
+
export { decodeCalldata } from './decode.js';
|
|
159
|
+
export { simulateTransaction, analyzeLogs, decodeRevert, fetchTokenMeta, parseSymbol, parseDecimals, DEFAULT_SIM_TIMEOUT_MS, } from './simulate.js';
|
|
160
|
+
export { renderText, renderHeadline, simulationSummary, HEADLINE_MAX, } from './format.js';
|
|
161
|
+
export { KNOWN_FUNCTIONS, EVENT_TOPICS, decodeV3Path } from './known.js';
|
|
162
|
+
export { formatUnits, shortAddr, sanitizeSymbol } from './units.js';
|
|
163
|
+
//# sourceMappingURL=index.js.map
|