proof402-verify 0.0.0-stage → 0.1.1

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/dist/index.js ADDED
@@ -0,0 +1,342 @@
1
+ // ../inspector/src/verify.ts
2
+ var CHAIN_ID = 84532;
3
+ var RPCS = ["https://sepolia.base.org", "https://base-sepolia-rpc.publicnode.com"];
4
+ var DEPLOYMENTS_URL = "https://raw.githubusercontent.com/proof402/proof402/main/deployments/basesepolia.json";
5
+ var CIRCLE_USDC = "0x036cbd53842c5426634e7929541ec2318f3dcf7e";
6
+ var STATES = ["None", "Open", "Captured", "Reclaimed", "Voided"];
7
+ var POLICY = {
8
+ name: "policy",
9
+ type: "tuple",
10
+ components: [
11
+ { name: "version", type: "uint16" },
12
+ { name: "chainId", type: "uint64" },
13
+ { name: "buyer", type: "address" },
14
+ { name: "seller", type: "address" },
15
+ { name: "verifier", type: "address" },
16
+ { name: "target", type: "address" },
17
+ { name: "invariantId", type: "bytes32" },
18
+ { name: "maxAmount", type: "uint256" },
19
+ { name: "deadline", type: "uint64" },
20
+ { name: "salt", type: "uint256" }
21
+ ]
22
+ };
23
+ var ESCROW_ABI = [
24
+ {
25
+ type: "function",
26
+ name: "tasks",
27
+ stateMutability: "view",
28
+ inputs: [{ name: "", type: "uint256" }],
29
+ outputs: [POLICY, { name: "policyHash", type: "bytes32" }, { name: "state", type: "uint8" }, { name: "attemptCount", type: "uint16" }]
30
+ },
31
+ { type: "function", name: "token", stateMutability: "view", inputs: [], outputs: [{ name: "", type: "address" }] },
32
+ {
33
+ type: "event",
34
+ name: "TaskCreated",
35
+ inputs: [{ name: "taskId", type: "uint256", indexed: true }, { ...POLICY, indexed: false }, { name: "policyHash", type: "bytes32", indexed: false }]
36
+ },
37
+ {
38
+ type: "event",
39
+ name: "EvidenceSubmitted",
40
+ inputs: [
41
+ { name: "taskId", type: "uint256", indexed: true },
42
+ { name: "evidenceHash", type: "bytes32", indexed: true },
43
+ { name: "attempt", type: "uint256", indexed: false },
44
+ { name: "passed", type: "bool", indexed: false }
45
+ ]
46
+ },
47
+ {
48
+ type: "event",
49
+ name: "TaskCaptured",
50
+ inputs: [
51
+ { name: "taskId", type: "uint256", indexed: true },
52
+ { name: "seller", type: "address", indexed: true },
53
+ { name: "payout", type: "uint256", indexed: false },
54
+ { name: "fee", type: "uint256", indexed: false }
55
+ ]
56
+ },
57
+ {
58
+ type: "event",
59
+ name: "TaskReclaimed",
60
+ inputs: [{ name: "taskId", type: "uint256", indexed: true }, { name: "buyer", type: "address", indexed: true }, { name: "amount", type: "uint256", indexed: false }]
61
+ },
62
+ {
63
+ type: "event",
64
+ name: "TaskVoided",
65
+ inputs: [{ name: "taskId", type: "uint256", indexed: true }, { name: "buyer", type: "address", indexed: true }, { name: "amount", type: "uint256", indexed: false }]
66
+ },
67
+ {
68
+ type: "event",
69
+ name: "Transfer",
70
+ inputs: [{ name: "from", type: "address", indexed: true }, { name: "to", type: "address", indexed: true }, { name: "value", type: "uint256", indexed: false }]
71
+ }
72
+ ];
73
+ var VERIFY_CHECKS = [
74
+ { id: "anchor", label: "Escrow and verifier match the ones published in the public repo" },
75
+ { id: "token", label: "Settlement token is Circle's testnet USDC" },
76
+ { id: "terms", label: "Terms stored on chain match the terms shown" },
77
+ { id: "hash", label: "Terms hash recomputed in your browser matches" },
78
+ { id: "state", label: "State and number of proofs match" },
79
+ { id: "opened", label: "Opening transaction created this task" },
80
+ { id: "proofs", label: "Every proof shown is in its transaction, with the same verdict" },
81
+ { id: "settled", label: "Settlement moved the money as shown" }
82
+ ];
83
+ var lc = (s) => (s ?? "").toLowerCase();
84
+ var shortAddr = (a) => `${a.slice(0, 6)}…${a.slice(-4)}`;
85
+ async function verifyTask(task, attempts, update, opts = {}) {
86
+ const viem = await import("viem");
87
+ const { baseSepolia } = await import("viem/chains");
88
+ let calls = 0;
89
+ const transport = viem.fallback(((opts.rpcUrls?.length) ? opts.rpcUrls : RPCS).map((url) => viem.http(url, { timeout: 12000, retryCount: 1, onFetchRequest: () => void calls++ })));
90
+ const client = viem.createPublicClient({ chain: baseSepolia, transport });
91
+ const escrow = viem.getAddress(task.escrow);
92
+ const run = async (id, fn) => {
93
+ update(id, "running");
94
+ try {
95
+ const r = await fn();
96
+ if (typeof r === "string")
97
+ update(id, "ok", r);
98
+ else
99
+ update(id, "skip", r.skip);
100
+ } catch (e) {
101
+ update(id, "fail", e instanceof Error ? e.message.split(`
102
+ `)[0].slice(0, 220) : String(e));
103
+ }
104
+ };
105
+ const must = (cond, msg) => {
106
+ if (!cond)
107
+ throw new Error(msg);
108
+ };
109
+ if (task.chain_id !== CHAIN_ID) {
110
+ for (const c of VERIFY_CHECKS)
111
+ update(c.id, "skip", "This check reads Base Sepolia; this task is on another chain.");
112
+ return 0;
113
+ }
114
+ await run("anchor", async () => {
115
+ let res;
116
+ try {
117
+ res = await fetch(opts.deploymentsUrl ?? DEPLOYMENTS_URL, { cache: "no-store", credentials: "omit" });
118
+ } catch {
119
+ return { skip: "Couldn't reach GitHub." };
120
+ }
121
+ if (!res.ok)
122
+ return { skip: `The public repo isn't reachable (HTTP ${res.status}).` };
123
+ const d = await res.json();
124
+ const current = lc(d.escrow) === lc(escrow);
125
+ const prev = (d.previousEscrows ?? []).find((p) => lc(p.address) === lc(escrow));
126
+ must(current || !!prev, `This page reads ${shortAddr(escrow)}, the repo publishes ${shortAddr(d.escrow ?? "none")}.`);
127
+ const verifier = !current && prev?.verifier || d.verifier?.address;
128
+ must(!!verifier && lc(task.verifier) === lc(verifier), `This task is judged by ${shortAddr(task.verifier)}, not Proof402's verifier ${shortAddr(verifier ?? "none")}: its proofs were never checked by Proof402.`);
129
+ return current ? `Escrow ${shortAddr(escrow)} and verifier ${shortAddr(verifier)}, as in deployments/basesepolia.json` : `Escrow ${shortAddr(escrow)}, listed in deployments/basesepolia.json as the escrow before ${shortAddr(d.escrow ?? "")}, and verifier ${shortAddr(verifier)}`;
130
+ });
131
+ await run("token", async () => {
132
+ const token = await client.readContract({ address: escrow, abi: ESCROW_ABI, functionName: "token" });
133
+ must(lc(token) === CIRCLE_USDC, `The escrow settles in ${shortAddr(token)}, not Circle USDC.`);
134
+ return `${shortAddr(token)} (USDC)`;
135
+ });
136
+ let stored;
137
+ try {
138
+ stored = await client.readContract({ address: escrow, abi: ESCROW_ABI, functionName: "tasks", args: [BigInt(task.task_id)] });
139
+ } catch (e) {
140
+ const why = `Couldn't read the task from the chain: ${e instanceof Error ? e.message.split(`
141
+ `)[0].slice(0, 160) : e}`;
142
+ for (const c of VERIFY_CHECKS.slice(2))
143
+ update(c.id, "fail", why);
144
+ return calls;
145
+ }
146
+ const [policy, policyHash, stateIx, attemptCount] = stored;
147
+ await run("terms", async () => {
148
+ const diffs = [];
149
+ const cmp = (name, chain, shown) => {
150
+ if (lc(String(chain)) !== lc(String(shown)))
151
+ diffs.push(`${name}: chain ${String(chain)}, shown ${String(shown)}`);
152
+ };
153
+ cmp("chain", policy.chainId, task.chain_id);
154
+ cmp("buyer", policy.buyer, task.buyer);
155
+ cmp("seller", policy.seller, task.seller);
156
+ cmp("verifier", policy.verifier, task.verifier);
157
+ cmp("target", policy.target, task.target);
158
+ cmp("rule", policy.invariantId, task.invariant_id);
159
+ cmp("amount", policy.maxAmount, task.max_amount);
160
+ cmp("deadline", policy.deadline, task.deadline);
161
+ must(diffs.length === 0, diffs.join("; "));
162
+ return "Buyer, seller, verifier, target, rule, amount and deadline all agree";
163
+ });
164
+ await run("hash", async () => {
165
+ const local = viem.keccak256(viem.encodeAbiParameters([POLICY], [policy]));
166
+ must(local === policyHash, `Recomputed ${local.slice(0, 12)}…, chain stores ${policyHash.slice(0, 12)}…`);
167
+ must(lc(local) === lc(task.policy_hash), `Chain and your browser agree on ${local.slice(0, 12)}…, but this page shows ${task.policy_hash.slice(0, 12)}…`);
168
+ return `${local.slice(0, 18)}…`;
169
+ });
170
+ await run("state", async () => {
171
+ const state = STATES[stateIx] ?? `unknown(${stateIx})`;
172
+ must(state === task.state, `Chain says ${state}, page says ${task.state}.`);
173
+ must(attemptCount === task.attempts && attemptCount === attempts.length, `Chain counts ${attemptCount} proofs; page shows ${attempts.length}.`);
174
+ return `${state}, ${attemptCount} proof${attemptCount === 1 ? "" : "s"}`;
175
+ });
176
+ const eventsIn = async (hash) => {
177
+ const rc = await client.getTransactionReceipt({ hash });
178
+ must(rc.status === "success", "The transaction reverted.");
179
+ const events = rc.logs.flatMap((l) => {
180
+ try {
181
+ return [{ address: lc(l.address), ...viem.decodeEventLog({ abi: ESCROW_ABI, data: l.data, topics: l.topics }) }];
182
+ } catch {
183
+ return [];
184
+ }
185
+ });
186
+ return { rc, events };
187
+ };
188
+ const id = BigInt(task.task_id);
189
+ await run("opened", async () => {
190
+ const { rc, events } = await eventsIn(task.created_tx);
191
+ must(Number(rc.blockNumber) === task.created_block, `Mined in block ${rc.blockNumber}, page says ${task.created_block}.`);
192
+ const ev = events.find((e) => e.address === lc(escrow) && e.eventName === "TaskCreated" && e.args.taskId === id);
193
+ must(!!ev, "No TaskCreated event for this task in that transaction.");
194
+ must(lc(ev.args.policyHash) === lc(policyHash), "The event's terms hash differs from storage.");
195
+ return `Block ${rc.blockNumber.toLocaleString("en-US")}`;
196
+ });
197
+ await run("proofs", async () => {
198
+ if (attempts.length === 0)
199
+ return { skip: "No proofs submitted yet." };
200
+ for (const a of attempts) {
201
+ const { events } = await eventsIn(a.tx_hash);
202
+ const ev = events.find((e) => {
203
+ if (e.address !== lc(escrow) || e.eventName !== "EvidenceSubmitted")
204
+ return false;
205
+ const g = e.args;
206
+ return g.taskId === id && Number(g.attempt) === a.attempt;
207
+ });
208
+ must(!!ev, `Proof ${a.attempt}: no matching event in its transaction.`);
209
+ const g = ev.args;
210
+ must(lc(g.evidenceHash) === lc(a.evidence_hash), `Proof ${a.attempt}: evidence hash differs.`);
211
+ must(g.passed === a.passed, `Proof ${a.attempt}: chain says ${g.passed ? "verified" : "refused"}, page says ${a.passed ? "verified" : "refused"}.`);
212
+ }
213
+ const ok = attempts.filter((a) => a.passed).length;
214
+ return `${attempts.length} of ${attempts.length} match (${ok} verified, ${attempts.length - ok} refused)`;
215
+ });
216
+ await run("settled", async () => {
217
+ if (task.state === "Open")
218
+ return { skip: "Not settled yet: the money is still held." };
219
+ must(!!task.terminal_tx, "The page shows no settlement transaction.");
220
+ const { events } = await eventsIn(task.terminal_tx);
221
+ const token = lc(CIRCLE_USDC);
222
+ const transfer = (to, value) => events.some((e) => {
223
+ if (e.address !== token || e.eventName !== "Transfer")
224
+ return false;
225
+ const g = e.args;
226
+ return lc(g.from) === lc(escrow) && lc(g.to) === lc(to) && g.value === value;
227
+ });
228
+ if (task.state === "Captured") {
229
+ const ev = events.find((e) => e.address === lc(escrow) && e.eventName === "TaskCaptured" && e.args.taskId === id);
230
+ must(!!ev, "No TaskCaptured event in the settlement transaction.");
231
+ const g = ev.args;
232
+ must(lc(g.seller) === lc(policy.seller), "Paid to someone other than the seller in the terms.");
233
+ must(String(g.payout) === task.payout && String(g.fee) === task.fee, `Chain: payout ${g.payout}, fee ${g.fee}; page: ${task.payout}, ${task.fee}.`);
234
+ must(transfer(policy.seller, g.payout), "The token contract shows no matching transfer to the seller.");
235
+ return `${viem.formatUnits(g.payout, 6)} USDC transferred to ${shortAddr(policy.seller)}`;
236
+ }
237
+ const name = task.state === "Reclaimed" ? "TaskReclaimed" : "TaskVoided";
238
+ const ev = events.find((e) => e.address === lc(escrow) && e.eventName === name && e.args.taskId === id);
239
+ must(!!ev, `No ${name} event in the settlement transaction.`);
240
+ const g = ev.args;
241
+ must(lc(g.buyer) === lc(policy.buyer) && String(g.amount) === task.refunded, "Refund amount or recipient differs.");
242
+ must(transfer(policy.buyer, g.amount), "The token contract shows no matching refund transfer.");
243
+ return `${viem.formatUnits(g.amount, 6)} USDC returned to ${shortAddr(policy.buyer)}`;
244
+ });
245
+ return calls;
246
+ }
247
+ // ../inspector/src/signature.ts
248
+ var SIGN_DOMAIN = "proof402-answer/v1";
249
+ function parseSignature(header) {
250
+ const out = {};
251
+ for (const part of header.split(",")) {
252
+ const i = part.indexOf("=");
253
+ if (i > 0)
254
+ out[part.slice(0, i).trim()] = part.slice(i + 1).trim();
255
+ }
256
+ return out;
257
+ }
258
+ function signedMessage(uri, body) {
259
+ const head = new TextEncoder().encode(`${SIGN_DOMAIN}
260
+ ${uri}
261
+ `);
262
+ const m = new Uint8Array(head.length + body.length);
263
+ m.set(head);
264
+ m.set(body, head.length);
265
+ return m;
266
+ }
267
+ var b64 = (s) => Uint8Array.from(atob(s), (c) => c.charCodeAt(0));
268
+ async function verifyAnswer(uri, body, header, keys) {
269
+ const p = parseSignature(header);
270
+ const key = keys.keys.find((k) => k.keyid === p.keyid);
271
+ if (!key)
272
+ return { keyid: p.keyid ?? "", signer: "", secp256k1: false, mldsa65: false, error: "signed by a key that is not published" };
273
+ const msg = signedMessage(uri, body);
274
+ const [{ keccak256, recoverMessageAddress }, { ml_dsa65 }] = await Promise.all([import("viem"), import("@noble/post-quantum/ml-dsa.js")]);
275
+ let ec = false;
276
+ try {
277
+ const who = await recoverMessageAddress({ message: { raw: keccak256(msg) }, signature: p.secp256k1 });
278
+ ec = who.toLowerCase() === key.secp256k1.toLowerCase();
279
+ } catch {
280
+ ec = false;
281
+ }
282
+ let ml = false;
283
+ try {
284
+ ml = ml_dsa65.verify(b64(p.mldsa65 ?? ""), msg, b64(key.mldsa65), { context: new TextEncoder().encode(SIGN_DOMAIN) });
285
+ } catch {
286
+ ml = false;
287
+ }
288
+ return { keyid: key.keyid, signer: key.secp256k1, secp256k1: ec, mldsa65: ml };
289
+ }
290
+ // src/api.ts
291
+ var DEFAULT_API = "https://proof402.isworking.dev";
292
+ var TIMEOUT_MS = 15000;
293
+ async function get(url) {
294
+ const res = await fetch(url, { headers: { accept: "application/json" }, signal: AbortSignal.timeout(TIMEOUT_MS) });
295
+ if (!res.ok) {
296
+ const hint = res.status === 404 ? " (no such task?)" : "";
297
+ throw new Error(`GET ${url} → HTTP ${res.status}${hint}`);
298
+ }
299
+ return res;
300
+ }
301
+ async function fetchSigned(url, keys) {
302
+ const res = await get(url);
303
+ const bytes = new Uint8Array(await res.arrayBuffer());
304
+ const header = res.headers.get("proof402-signature");
305
+ const u = new URL(url);
306
+ const signature = header ? await verifyAnswer(u.pathname + u.search, bytes, header, keys) : { keyid: "", signer: "", secp256k1: false, mldsa65: false, error: "the answer carries no signature" };
307
+ let body;
308
+ try {
309
+ body = JSON.parse(new TextDecoder().decode(bytes));
310
+ } catch {
311
+ throw new Error(`GET ${url} did not return JSON`);
312
+ }
313
+ return { url, body, signature };
314
+ }
315
+ async function fetchTask(taskId, chainId = 84532, api = DEFAULT_API) {
316
+ const base = api.replace(/\/+$/, "");
317
+ const keys = await (await get(`${base}/.well-known/proof402-keys.json`)).json();
318
+ if (!Array.isArray(keys?.keys) || keys.keys.length === 0)
319
+ throw new Error(`${base} publishes no signing keys`);
320
+ const [task, attempts] = await Promise.all([
321
+ fetchSigned(`${base}/v1/tasks/${chainId}/${taskId}`, keys),
322
+ fetchSigned(`${base}/v1/tasks/${chainId}/${taskId}/attempts`, keys)
323
+ ]);
324
+ if (task.body.task_id !== taskId || task.body.chain_id !== chainId)
325
+ throw new Error(`asked for task ${taskId} on chain ${chainId}, the API answered task ${task.body.task_id} on chain ${task.body.chain_id}`);
326
+ if (!Array.isArray(attempts.body.attempts) || attempts.body.attempts.some((a) => a.task_id !== taskId || a.chain_id !== chainId))
327
+ throw new Error(`the API's proof list for task ${taskId} contains another task's proofs`);
328
+ return { task, attempts };
329
+ }
330
+ export {
331
+ DEFAULT_API,
332
+ DEPLOYMENTS_URL,
333
+ RPCS,
334
+ SIGN_DOMAIN,
335
+ VERIFY_CHECKS,
336
+ fetchSigned,
337
+ fetchTask,
338
+ parseSignature,
339
+ signedMessage,
340
+ verifyAnswer,
341
+ verifyTask
342
+ };
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Proof402-Signature verification (see indexer/sign.go):
3
+ *
4
+ * message = "proof402-answer/v1\n" + request URI + "\n" + body
5
+ * secp256k1 = EIP-191 personal signature over keccak256(message), from the published address
6
+ * mldsa65 = ML-DSA-65 over message, context "proof402-answer/v1"
7
+ *
8
+ * Both must verify. Libraries load on demand.
9
+ */
10
+ export declare const SIGN_DOMAIN = "proof402-answer/v1";
11
+ export type KeysDoc = {
12
+ keys: {
13
+ keyid: string;
14
+ secp256k1: string;
15
+ mldsa65: string;
16
+ }[];
17
+ };
18
+ export type SigResult = {
19
+ keyid: string;
20
+ signer: string;
21
+ secp256k1: boolean;
22
+ mldsa65: boolean;
23
+ error?: string;
24
+ };
25
+ export declare function parseSignature(header: string): Record<string, string>;
26
+ export declare function signedMessage(uri: string, body: Uint8Array): Uint8Array;
27
+ export declare function verifyAnswer(uri: string, body: Uint8Array, header: string, keys: KeysDoc): Promise<SigResult>;
28
+ /** Fetches one API answer and checks its signature against the published keys. */
29
+ export declare function checkSignedAnswer(path: string): Promise<SigResult>;
@@ -0,0 +1,170 @@
1
+ /** Mirrors the Go indexer's derived view (types are the API contract). */
2
+ export interface Task {
3
+ chain_id: number;
4
+ escrow: string;
5
+ task_id: number;
6
+ policy_hash: string;
7
+ buyer: string;
8
+ seller: string;
9
+ verifier: string;
10
+ target: string;
11
+ invariant_id: string;
12
+ max_amount: string;
13
+ deadline: number;
14
+ version: number;
15
+ created_tx: string;
16
+ created_block: number;
17
+ state: "Open" | "Captured" | "Reclaimed" | "Voided";
18
+ terminal_tx: string | null;
19
+ terminal_block: number | null;
20
+ payout: string | null;
21
+ fee: string | null;
22
+ refunded: string | null;
23
+ attempts: number;
24
+ }
25
+ export interface Attempt {
26
+ chain_id: number;
27
+ tx_hash: string;
28
+ log_index: number;
29
+ escrow: string;
30
+ task_id: number;
31
+ attempt: number;
32
+ evidence_hash: string;
33
+ passed: boolean;
34
+ block_number: number;
35
+ sandbox: string | null;
36
+ pre_balance: string | null;
37
+ post_balance: string | null;
38
+ }
39
+ export interface ReceiptV1 {
40
+ schema: string;
41
+ commitment: {
42
+ chain_id: number;
43
+ escrow: string;
44
+ task_id: number;
45
+ policy_hash: string;
46
+ terms: {
47
+ version: number;
48
+ buyer: string;
49
+ seller: string;
50
+ verifier: string;
51
+ target: string;
52
+ invariant_id: string;
53
+ asset: string;
54
+ max_amount: string;
55
+ max_amount_human: string;
56
+ decimals: number;
57
+ deadline: number;
58
+ deadline_human: string;
59
+ };
60
+ };
61
+ evidence: {
62
+ verifier_version: string;
63
+ attempts: Array<{
64
+ attempt: number;
65
+ evidence_hash: string;
66
+ passed: boolean;
67
+ tx_hash: string;
68
+ log_index: number;
69
+ block_number: number;
70
+ sandbox?: string;
71
+ pre_balance?: string;
72
+ post_balance?: string;
73
+ }>;
74
+ };
75
+ outcome: {
76
+ state: "OPEN_AFTER_INVALID" | "CAPTURED" | "RECLAIMED" | "VOIDED";
77
+ settlement_tx: string | null;
78
+ settlement_block: number | null;
79
+ payout?: string;
80
+ payout_human?: string;
81
+ fee?: string;
82
+ fee_human?: string;
83
+ refunded?: string;
84
+ refunded_human?: string;
85
+ };
86
+ metadata: {
87
+ explorer: string;
88
+ generated_at: string;
89
+ commitment_sha256: string;
90
+ };
91
+ }
92
+ export interface Health {
93
+ ok: boolean;
94
+ chain_id: number;
95
+ escrow: string;
96
+ latest_block: number;
97
+ cursor_block: number;
98
+ blocks_behind: number;
99
+ stale: boolean;
100
+ /** This deployment's verifier. The escrow accepts any verifier a buyer names. */
101
+ verifier?: string;
102
+ verifier_version: string;
103
+ }
104
+ export interface Stats {
105
+ tasks_total: number;
106
+ by_state: Record<string, number>;
107
+ attempts_total: number;
108
+ captures_payout_sum: string;
109
+ fees_sum: string;
110
+ unique_sellers: number;
111
+ }
112
+ /** The Rust simulator's isolated output envelope (SIMULATED — never live data). */
113
+ export interface SimTotals {
114
+ tasks: number;
115
+ passed: number;
116
+ paid_usdc: number;
117
+ refunded_usdc: number;
118
+ paid_for_failed_usdc: number;
119
+ }
120
+ /** Simulator output (schema proof402.sim/2). SIMULATED — never mixed with live data. */
121
+ export interface SimRun {
122
+ schema: "proof402.sim/2";
123
+ label: "SIMULATED";
124
+ seed: number;
125
+ tasks: number;
126
+ price_usdc: number;
127
+ policy: {
128
+ name: string;
129
+ gamma: number;
130
+ c: number;
131
+ learns_from: string;
132
+ };
133
+ sellers: {
134
+ id: string;
135
+ role: string;
136
+ segments: {
137
+ from: number;
138
+ to: number;
139
+ pass_rate: number;
140
+ }[];
141
+ }[];
142
+ events: {
143
+ task: number;
144
+ text: string;
145
+ }[];
146
+ proof402: SimTotals;
147
+ x402_same_routing: SimTotals;
148
+ x402_uniform_routing: SimTotals;
149
+ adaptation: {
150
+ moved_off_c_after: number | null;
151
+ adopted_d_after: number | null;
152
+ };
153
+ windows: {
154
+ end: number;
155
+ share: [number, number, number, number];
156
+ passed: number;
157
+ uniform_passed: number;
158
+ }[];
159
+ wasted: {
160
+ task: number;
161
+ same_routing: number;
162
+ uniform_routing: number;
163
+ }[];
164
+ runs: {
165
+ task: number;
166
+ seller: string;
167
+ passed: boolean;
168
+ reason: string;
169
+ }[];
170
+ }
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Verify a task without trusting this site.
3
+ *
4
+ * Everything below runs in the visitor's browser and talks only to Base Sepolia's
5
+ * public RPC endpoints (and, for one anchor, the public GitHub repo). The Proof402
6
+ * server is not asked anything: each check compares what this page shows (which came
7
+ * from our indexer) with what the chain itself says.
8
+ *
9
+ * Checks, in order:
10
+ * 1. The escrow and the task's verifier are the ones published in the repo's
11
+ * deployments file. The escrow accepts any verifier its buyer names, so without
12
+ * this a task judged by a contract that passes everything would pass every check.
13
+ * 2. Its settlement token is Circle's testnet USDC.
14
+ * 3. The task's stored terms equal the terms shown.
15
+ * 4. The terms hash, recomputed here as keccak256(abi.encode(policy)), equals the
16
+ * hash stored on chain and the one shown.
17
+ * 5. The state and the number of proofs match.
18
+ * 6. The opening transaction emitted TaskCreated for this task in the block shown.
19
+ * 7. Every proof shown is an EvidenceSubmitted event in its transaction, with the
20
+ * same attempt number, evidence hash and verdict.
21
+ * 8. The settlement transaction emitted the outcome shown, and the token contract
22
+ * really moved that amount to the seller (paid) or the buyer (refunded).
23
+ */
24
+ import type { Attempt, Task } from "./types";
25
+ export type CheckStatus = "pending" | "running" | "ok" | "fail" | "skip";
26
+ export interface Check {
27
+ id: string;
28
+ label: string;
29
+ status: CheckStatus;
30
+ detail?: string;
31
+ }
32
+ export declare const RPCS: string[];
33
+ export declare const DEPLOYMENTS_URL = "https://raw.githubusercontent.com/proof402/proof402/main/deployments/basesepolia.json";
34
+ export declare const POLICY: {
35
+ readonly name: "policy";
36
+ readonly type: "tuple";
37
+ readonly components: readonly [{
38
+ readonly name: "version";
39
+ readonly type: "uint16";
40
+ }, {
41
+ readonly name: "chainId";
42
+ readonly type: "uint64";
43
+ }, {
44
+ readonly name: "buyer";
45
+ readonly type: "address";
46
+ }, {
47
+ readonly name: "seller";
48
+ readonly type: "address";
49
+ }, {
50
+ readonly name: "verifier";
51
+ readonly type: "address";
52
+ }, {
53
+ readonly name: "target";
54
+ readonly type: "address";
55
+ }, {
56
+ readonly name: "invariantId";
57
+ readonly type: "bytes32";
58
+ }, {
59
+ readonly name: "maxAmount";
60
+ readonly type: "uint256";
61
+ }, {
62
+ readonly name: "deadline";
63
+ readonly type: "uint64";
64
+ }, {
65
+ readonly name: "salt";
66
+ readonly type: "uint256";
67
+ }];
68
+ };
69
+ export declare const VERIFY_CHECKS: Pick<Check, "id" | "label">[];
70
+ export interface VerifyOptions {
71
+ /** Base Sepolia JSON-RPC endpoints, tried in order (default: two public ones). */
72
+ rpcUrls?: string[];
73
+ /** Where the escrow and verifier addresses are published (default: the repo's deployments file). */
74
+ deploymentsUrl?: string;
75
+ }
76
+ /** Runs every check, reporting progress through `update`. Returns the number of RPC calls. */
77
+ export declare function verifyTask(task: Task, attempts: Attempt[], update: (id: string, status: CheckStatus, detail?: string) => void, opts?: VerifyOptions): Promise<number>;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Reads a task and its proofs from a Proof402 API and checks each answer's
3
+ * Proof402-Signature (secp256k1 and ML-DSA-65) against the keys the API publishes.
4
+ *
5
+ * A valid signature proves what the API said, so a wrong answer can be shown to be
6
+ * the API's; it does not make the answer true. The chain checks do that.
7
+ */
8
+ import { type KeysDoc, type SigResult } from "../../inspector/src/signature";
9
+ import type { Attempt, Task } from "../../inspector/src/types";
10
+ export declare const DEFAULT_API = "https://proof402.isworking.dev";
11
+ export interface SignedAnswer<T> {
12
+ url: string;
13
+ body: T;
14
+ signature: SigResult;
15
+ }
16
+ export interface FetchedTask {
17
+ task: SignedAnswer<Task>;
18
+ attempts: SignedAnswer<{
19
+ attempts: Attempt[];
20
+ count: number;
21
+ }>;
22
+ }
23
+ /** Fetches one JSON answer and checks its signature against `keys`. */
24
+ export declare function fetchSigned<T>(url: string, keys: KeysDoc): Promise<SignedAnswer<T>>;
25
+ /** Fetches a task and its proofs from `api`, with both answers' signatures checked. */
26
+ export declare function fetchTask(taskId: number, chainId?: number, api?: string): Promise<FetchedTask>;
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,13 @@
1
+ interface Args {
2
+ taskId: number;
3
+ api: string;
4
+ rpc: string[];
5
+ anchor?: string;
6
+ json: boolean;
7
+ }
8
+ export declare function parseArgs(argv: string[]): Args | {
9
+ exit: number;
10
+ out: string;
11
+ };
12
+ export declare function main(argv: string[]): Promise<number>;
13
+ export {};
@@ -0,0 +1,13 @@
1
+ /**
2
+ * proof402-verify: check a Proof402 task against Base Sepolia without trusting Proof402.
3
+ *
4
+ * The chain checks are the site's own "Check against the chain" code (inspector/src/verify.ts),
5
+ * bundled here unchanged, so the command line and the browser cannot drift apart.
6
+ */
7
+ export { verifyTask, VERIFY_CHECKS, RPCS, DEPLOYMENTS_URL } from "../../inspector/src/verify";
8
+ export type { Check, CheckStatus, VerifyOptions } from "../../inspector/src/verify";
9
+ export { verifyAnswer, parseSignature, signedMessage, SIGN_DOMAIN } from "../../inspector/src/signature";
10
+ export type { KeysDoc, SigResult } from "../../inspector/src/signature";
11
+ export type { Task, Attempt } from "../../inspector/src/types";
12
+ export { fetchSigned, fetchTask, DEFAULT_API } from "./api";
13
+ export type { SignedAnswer, FetchedTask } from "./api";