@taifoon/jev 0.2.16 → 0.2.18

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 CHANGED
@@ -14,7 +14,8 @@ npx @taifoon/jev run --demo
14
14
 
15
15
  ![npx @taifoon/jev run --demo: a BitAgent job on Base, graded by Jev, checked against the chain](https://raw.githubusercontent.com/taifoon-io/jev/main/docs/demo.gif)
16
16
 
17
- Then grade your own with your TypeSafe key from [console.typesafe.ai](https://console.typesafe.ai). Installing it also
17
+ Then grade your own: with no key, on your free grades on the Taifoon coordination layer (3 a day per caller), or with
18
+ your TypeSafe key from [console.typesafe.ai](https://console.typesafe.ai). Installing it also
18
19
  installs Taifoon's other packages (@taifoon/jev-wilson, @taifoon/n8n-nodes-typesafe). No key inside, and it signs nothing. Recording a grade on chain is optional.
19
20
 
20
21
  ## Quick start
@@ -55,7 +56,7 @@ claims the evidence cannot support. Grade one with your key:
55
56
  ```
56
57
  TYPESAFE_KEY=… npx @taifoon/jev run --job-file examples/jobs/invoice-extraction.json
57
58
  npx @taifoon/jev run --demo # offline, no key: replays the Base job below and checks it against the chain
58
- npx @taifoon/jev run # a live Base job from the coordination layer's queue (needs TYPESAFE_KEY)
59
+ npx @taifoon/jev run # a live Base job from the coordination layer's queue (your TYPESAFE_KEY, else the free grades)
59
60
  ```
60
61
 
61
62
  ## A Base job, graded
@@ -121,8 +122,9 @@ Safe by default: your own TypeSafe key only, nothing recorded, nothing signed or
121
122
  | `--seller-record <k>/<n>` | read from the layer | Price the premium here from the seller's record (k delivered of n graded) with [`@taifoon/jev-wilson`](https://www.npmjs.com/package/@taifoon/jev-wilson): the layer's numbers, no request |
122
123
  | `--yes` / `--json` | ask per step / text | Run every step without asking / print the whole trace as JSON |
123
124
 
124
- Environment: `TYPESAFE_KEY` (your key; without it a job that needs Jev stops and says where to get one, while a job the
125
- code checks reject is still graded). Exit codes: `0` done, `1` a step failed, `2` a flag was refused.
125
+ Environment: `TYPESAFE_KEY` (your key; without it a job that needs Jev is graded on your free grades on the layer, and
126
+ past them it stops and says how to pay one grade; a job the code checks reject is graded either way; `--no-layer`, `--demo` and `--job-file` ask
127
+ no one). `TAIFOON_RELAYER_KEY` pays layer grades past the free ones from that key's balance. Exit codes: `0` done, `1` a step failed, `2` a flag was refused.
126
128
 
127
129
  ## What you must know
128
130
 
@@ -132,8 +134,12 @@ code checks reject is still graded). Exit codes: `0` done, `1` a step failed, `2
132
134
  - **Code composes the verdict** under THRESHOLDS_v1: complete, reject or needs_review. needs_review ends nothing and
133
135
  leaves room for an appeal. Above 50 USDC a complete is held for review.
134
136
  - **Nothing is signed.** `record()` and `evaluatorCall()` return unsigned calls. Whoever holds the seat signs.
135
- - **Your key.** Jev is called with your own TypeSafe key from [console.typesafe.ai](https://console.typesafe.ai),
136
- directly at TypeSafe. The key is not stored and never appears in a receipt.
137
+ - **Your key, or the free grades.** With your own TypeSafe key from [console.typesafe.ai](https://console.typesafe.ai),
138
+ Jev is called directly at TypeSafe; the key is not stored and never appears in a receipt. Without one, `grade()`
139
+ claims one of your free grades on the coordination layer (`POST https://coord.taifoon.dev/v1/judge/compose`, 3 a day
140
+ per caller): the layer asks Jev the same four questions and this package composes the verdict from the answers, so the
141
+ receipt is the same shape (`via.connection: "trial"`, with the grades left). Past them the layer answers 402 with the
142
+ price of one grade (x402), or pass `layerKey` (a Taifoon key) to pay from its balance. `layer: false` turns this off.
137
143
  - **What the result is.** *Graded against a published rubric by a pinned decision model, with an appeal.* It is not
138
144
  "independently verified". An on-chain record is an attestation by whoever sent it, not a proof the answer is right.
139
145
 
@@ -146,7 +152,7 @@ code checks reject is still graded). Exit codes: `0` done, `1` a step failed, `2
146
152
  | `facts({ delivered, checks, priceUsdc? })` | Runs the checks your protocol supplies |
147
153
  | `record(receipt, { network, send? })` | Returns the unsigned `JevAnswerLog.record` and `JevDecisionLog.record` calls |
148
154
  | `evaluatorCall(protocol, jobId, verdict, digest)` | Returns the one unsigned call that ends the job; `null` for needs_review |
149
- | `verify(receiptOrDigest)` | Recomputes every digest and finds the records on chain |
155
+ | `verify(receiptOrDigest, { network? })` | Recomputes every digest and finds the records on chain (the devnet unless you name a chain; see Chains) |
150
156
 
151
157
  `verifyDecision(record, { answers? })` does the same for a decision as the coordination layer serves it at
152
158
  `/v1/judge/decisions/{id}`: the input fingerprint, the decision digest, the answers digest and the verdict RUBRIC_v1
@@ -173,8 +179,42 @@ npx @taifoon/jev verify <decision id> --network base # recompute the served re
173
179
  npx @taifoon/jev workflows export ./jev-workflows
174
180
  ```
175
181
 
182
+ ## Chains
183
+
184
+ `verify` reads the Jev logs on every chain they are deployed to: the Taifoon devnet (36927), Base (8453), Arbitrum One
185
+ (42161), Arc (5042) and Monad (143). Robinhood Chain (4663), Taifoon mainnet (3692781) and Ethereum (1) are known
186
+ chains with no Jev log yet; `verify` says so instead of reading them.
187
+
188
+ | Flag | What it does |
189
+ |---|---|
190
+ | `--chain <id or name>` | Read one chain: `devnet`, `base`, `arbitrum`, `arc`, `monad`, `robinhood`, `taifoon`, or a chain id |
191
+ | `--network devnet\|base\|any` | The earlier flag; still works. `any` is the same as naming no chain |
192
+ | `--rpc <url[,url]>` | Read through these endpoints instead of the rotation below |
193
+
194
+ With no chain named, a decision id is read on the chain its record names (its anchor); a bare digest is looked up on
195
+ the devnet first, then Base, then the other chains, and the first chain that holds it answers. Nothing reads a mainnet
196
+ unless the record or you name one: the tests and examples use the devnet.
197
+
198
+ Every chain read goes through the warmbed rotation (`https://warmbed.taifoon.dev`), which lists the endpoints it
199
+ measured to serve log windows for that chain. A rate limit, a server error or a timeout moves the read to the next
200
+ endpoint, two passes over the list; a revert does not. When warmbed does not answer, the package uses the static list
201
+ it ships (`src/rpc-fallback.ts`, generated from the RPC registry).
202
+
203
+ `onChain.status` in the output tells the outcomes apart:
204
+
205
+ | `status` | Meaning |
206
+ |---|---|
207
+ | `recorded` | The answer row is on chain (and the decision row, when there is one: `checks.decisionOnChain`) |
208
+ | `not_recorded` | The chain answered and holds no row for this digest |
209
+ | `rpc_unavailable` | No endpoint answered; the row may exist. Try again later, or pass `--rpc` |
210
+ | `not_deployed` | No Jev log on that chain |
211
+ | `skipped` | `verify(x, { chain: false })`: digests recomputed, no chain read |
212
+
213
+ In code: `verify(digest, { network: 'arbitrum' })` (a name or a chain id), `{ rpc: 'https://…' }`, and `JevChainError`
214
+ (`code`: `rpc_unavailable`, `not_deployed`, `reverted`, `bad_input`) from the lower-level calls.
215
+
176
216
  ## Licence
177
217
 
178
218
  Independent project. Jev and TypeSafe are products of TypeSafe AI, Inc., which does not endorse this package.
179
219
 
180
- Built by Taifoon. MIT. Its runtime dependencies are Taifoon's own packages, @taifoon/jev-wilson (the pricing) and @taifoon/n8n-nodes-typesafe; nothing third-party. It contains no key. It calls Jev only with your own TypeSafe key.
220
+ Built by Taifoon. MIT. Its runtime dependencies are Taifoon's own packages, @taifoon/jev-wilson (the pricing) and @taifoon/n8n-nodes-typesafe; nothing third-party. It contains no key. It calls Jev with your own TypeSafe key, or without one through your free grades on the Taifoon coordination layer.
package/bin/jev.mjs CHANGED
@@ -3,7 +3,10 @@
3
3
  // jev workflows list [--version X] the bundled n8n workflows (and which nodes and credentials each needs)
4
4
  // jev workflows export <dir> [--version X] write them, their schemas, manifest and README into <dir>
5
5
  // jev run [--job 8453:81100] [--evidence pack.json] [--network …] [--yes] [--json] one job through the pipeline, step by step
6
- // jev verify <answers-digest | decision id> [--network devnet|base|any] (a decision id: recompute its record offline, then) find the digest's JevAnswered / Decided rows (default any: devnet, then Base 8453)
6
+ // jev verify <answers-digest | decision id> [--chain <id|name>] [--rpc url[,url]] (a decision id: recompute its record offline, then) find the digest's
7
+ // JevAnswered / Decided rows: on --chain, else the chain the decision record names, else every chain with Jev logs (devnet,
8
+ // Base, then the rest). Chain reads go through warmbed's rotation, then the registry's static list; --rpc overrides both.
9
+ // --network devnet|base|any still works (any = no chain named).
7
10
  import { cpSync, existsSync, readdirSync, readFileSync } from 'node:fs';
8
11
  import { dirname, join, resolve } from 'node:path';
9
12
  import { fileURLToPath } from 'node:url';
@@ -16,6 +19,9 @@ const flag = (n) => { const i = args.indexOf(n); return i >= 0 ? args.splice(i,
16
19
  const BUNDLES = readdirSync(join(ROOT, 'workflows')).filter((d) => /^\d+\.\d+\.\d+$/.test(d)).sort((x, y) => x.localeCompare(y, undefined, { numeric: true }));
17
20
  const version = flag('--version') ?? BUNDLES.at(-1) ?? PKG.version;
18
21
  const network = flag('--network') ?? 'any';
22
+ // --rpc <url[,url…]>: read through these endpoints instead of warmbed's rotation (the named or anchored chain; else Base)
23
+ const rpcFlag = flag('--rpc');
24
+ const chainFlag = flag('--chain');
19
25
  const bundle = join(ROOT, 'workflows', version);
20
26
  const die = (m) => { console.error(m); process.exit(1); };
21
27
  const [cmd, sub, target] = args;
@@ -34,9 +40,12 @@ if (cmd === 'workflows') {
34
40
  } else if (cmd === 'run') {
35
41
  await import('./run.mjs').then((m) => m.run(process.argv.slice(3)));
36
42
  } else if (cmd === 'verify' && sub) {
37
- const { verify, verifyDecision, LAYER } = await import('../dist/index.js');
38
- if (!['devnet', 'base', 'any'].includes(network)) die('--network is devnet, base or any');
39
- let digest = sub; let offline = null;
43
+ const { verify, verifyDecision, LAYER, chainIdOf, JEV_CHAINS } = await import('../dist/index.js');
44
+ // which chain(s) to read: --chain <id|name> (or --network devnet|base|<chain>) names one; otherwise the chain the decision
45
+ // record names (its anchor); otherwise every chain with Jev logs in turn (devnet, Base, then the rest) until one holds it
46
+ let named = null;
47
+ try { named = chainFlag ? chainIdOf(chainFlag) : network !== 'any' ? chainIdOf(network) : null; } catch (e) { die(e.message); }
48
+ let digest = sub; let offline = null; let anchor = null;
40
49
  // a decision id (or its /v1/judge/decisions URL): read the served record and its answers, recompute both here, then
41
50
  // find the answers digest on chain like any other
42
51
  const m = /(decision-\d+-[0-9a-f]{10})/.exec(sub);
@@ -48,11 +57,20 @@ if (cmd === 'workflows') {
48
57
  offline = verifyDecision(rec, ans?.record ? { answers: ans.record } : {});
49
58
  if (!ad) { console.log(JSON.stringify({ offline }, null, 1)); process.exit(offline.ok ? 0 : 2); }
50
59
  digest = ad;
60
+ const a = rec?.decision?.anchor;
61
+ if (a && a.status === 'ok' && Number.isInteger(Number(a.chain))) anchor = { chain: Number(a.chain), block: Number(a.block) || undefined };
62
+ }
63
+ const chains = named ? [named] : anchor ? [anchor.chain] : JEV_CHAINS;
64
+ // --rpc reads one chain: the named or anchored one, else Base (the endpoints a reader passes are almost always Base's)
65
+ const rpcFor = (c) => (rpcFlag && (chains.length === 1 || c === 8453) ? { rpc: rpcFlag } : {});
66
+ let v = null;
67
+ for (const c of chains) {
68
+ const r = await verify(digest, { network: c, ...rpcFor(c), ...(anchor && anchor.chain === c && anchor.block ? { decisionBlock: anchor.block } : {}) });
69
+ if (!v || r.checks.answersOnChain || (c === 8453 && !v.ok)) v = r;
70
+ if (r.checks.answersOnChain) break;
51
71
  }
52
- let v = await verify(digest, { network: network === 'base' ? 'base' : 'devnet' });
53
- if (network === 'any' && !v.checks.answersOnChain) { const b = await verify(sub, { network: 'base' }); if (b.checks.answersOnChain || !v.ok) v = b; }
54
72
  console.log(JSON.stringify(offline ? { offline, ...v, ok: v.ok && offline.ok } : v, null, 1));
55
73
  process.exit(v.ok && (!offline || offline.ok) ? 0 : 2);
56
74
  } else {
57
- console.log(`jev ${PKG.version}\n jev workflows list [--version X]\n jev workflows export <dir> [--version X]\n jev run [--job <chain>:<id>] [--evidence pack.json] [--network none|devnet|base|both] [--yes] [--json]\n jev verify <answers-digest | decision id> [--network devnet|base|any]`);
75
+ console.log(`jev ${PKG.version}\n jev workflows list [--version X]\n jev workflows export <dir> [--version X]\n jev run [--job <chain>:<id>] [--evidence pack.json] [--network none|devnet|base|both] [--yes] [--json]\n jev verify <answers-digest | decision id> [--chain <id|name>] [--rpc url[,url]]`);
58
76
  }
package/bin/run.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  // jev run — one job through the pipeline, one step at a time.
2
- // jev run the first ready job on the coordination layer's queue (needs TYPESAFE_KEY)
2
+ // jev run the first ready job on the coordination layer's queue (your TYPESAFE_KEY, else the free grades)
3
3
  // jev run --job 8453:81100 a job you name (chain:id; ids like bitagent:8453:7287 work too)
4
4
  // jev run --evidence pack.json your own pack, no layer at all: { subject, state, delivered?, checks?, priceUsdc? }
5
5
  // jev run --job-file job.json one agent job: { id, task, criteria[], delivered, source?, checks[] } (see examples/jobs/)
@@ -71,7 +71,7 @@ export async function run(argv) {
71
71
 
72
72
  const t = createTerm({ quiet: json });
73
73
  const rl = yes ? null : createInterface({ input: process.stdin, output: process.stdout });
74
- t.info(`jev run · ${noLayer ? 'offline' : `layer ${layer ?? 'https://coord.taifoon.dev'}`} · grade on ${demo ? `Jev's recorded answers for ${rec.job.ref} (${rec.job.task})` : ansFile ? 'supplied answers' : process.env.TYPESAFE_KEY ? 'your TypeSafe key' : 'no key: set TYPESAFE_KEY, or try --demo'} · record → ${network === 'none' ? 'none (opt in with --record devnet|base|both)' : network}${process.env.TAIFOON_RELAYER_KEY ? ' + the layer' : ''}`);
74
+ t.info(`jev run · ${noLayer ? 'offline' : `layer ${layer ?? 'https://coord.taifoon.dev'}`} · grade on ${demo ? `Jev's recorded answers for ${rec.job.ref} (${rec.job.task})` : ansFile ? 'supplied answers' : process.env.TYPESAFE_KEY ? 'your TypeSafe key' : noLayer ? 'no key: set TYPESAFE_KEY, or try --demo' : 'your free grades on the layer (no TypeSafe key)'} · record → ${network === 'none' ? 'none (opt in with --record devnet|base|both)' : network}${process.env.TAIFOON_RELAYER_KEY ? ' + the layer' : ''}`);
75
75
 
76
76
  const trace = await pipeline({
77
77
  layer, job, network, protocol, priceUsdc: price ? Number(price) : undefined, sellerRecord: recM ? { k: Number(recM[1]), n: Number(recM[2]) } : undefined,
@@ -60,3 +60,14 @@ export declare const REGISTRY_ADDRESSES: {
60
60
  readonly block: 48395723;
61
61
  };
62
62
  };
63
+ /** The Jev logs on every chain the registry deploys them to (JevAnswerLog + JevDecisionLog, from their deploy block). */
64
+ export declare const JEV_LOGS: Readonly<Record<number, {
65
+ answerLog: {
66
+ address: string;
67
+ fromBlock: number;
68
+ };
69
+ decisionLog: {
70
+ address: string;
71
+ fromBlock: number;
72
+ };
73
+ }>>;
package/dist/addresses.js CHANGED
@@ -22,3 +22,11 @@ export const REGISTRY_ADDRESSES = {
22
22
  /** standards-erc8183 · BitAgent ERC-8183 escrow (live) */
23
23
  bitagentErc8183: { chainId: 8453, address: '0x5009ABB3A309115a4a682C66BAf3BC9E0329BaB7', block: 48395723 },
24
24
  };
25
+ /** The Jev logs on every chain the registry deploys them to (JevAnswerLog + JevDecisionLog, from their deploy block). */
26
+ export const JEV_LOGS = {
27
+ 143: { answerLog: { address: '0x29fEEc116e0CAbbaf38e9EBF2BBf65d82D672104', fromBlock: 110216088 }, decisionLog: { address: '0x1aC6266b9926cB3E206D5dc0c9d1B7c873aa150a', fromBlock: 110216093 } },
28
+ 5042: { answerLog: { address: '0x45214361A8cADb8aEe6302cd5653E119E5a89839', fromBlock: 24071071 }, decisionLog: { address: '0x863db7dAc69CC614a98822082cbe884F1f3b55cA', fromBlock: 24071074 } },
29
+ 8453: { answerLog: { address: '0x8e9B9cE86a2d55c10318607b0c815B7B8C66254d', fromBlock: 51863008 }, decisionLog: { address: '0x209490d6A0FFC5368A42b0c2208BDCda853f6a92', fromBlock: 51856200 } },
30
+ 36927: { answerLog: { address: '0xD8c1d8188Fc8EE388792f6EB3B3dbd4f341Ba8e3', fromBlock: 1106754 }, decisionLog: { address: '0x1D622511862DD7DEffB8fEeBc225E0FAdA1e9A05', fromBlock: 981099 } },
31
+ 42161: { answerLog: { address: '0x29fEEc116e0CAbbaf38e9EBF2BBf65d82D672104', fromBlock: 511340178 }, decisionLog: { address: '0x1aC6266b9926cB3E206D5dc0c9d1B7c873aa150a', fromBlock: 511340188 } },
32
+ };
package/dist/ask.d.ts CHANGED
@@ -6,9 +6,16 @@ export type Asked = {
6
6
  answers: Record<string, Answer>;
7
7
  model: string | null;
8
8
  latency_ms: number | null;
9
- connection: 'key';
10
- trial: null;
9
+ connection: 'key' | 'trial';
10
+ trial: {
11
+ calls: number;
12
+ left: number;
13
+ } | null;
11
14
  };
15
+ /** the coordination layer, where a caller without a TypeSafe key claims its free grades */
16
+ export declare const LAYER_URL = "https://coord.taifoon.dev";
17
+ /** the questions the layer's free grade answers (RUBRIC_v1 asks exactly these); another rubric needs the caller's own key */
18
+ export declare const LAYER_QUESTIONS: readonly string[];
12
19
  export declare class JevError extends Error {
13
20
  readonly status: number;
14
21
  readonly next?: string | undefined;
@@ -22,3 +29,12 @@ export declare function askJev(a: {
22
29
  model?: string;
23
30
  fetch?: typeof fetch;
24
31
  }): Promise<Asked>;
32
+ /** A free grade on the coordination layer (or one paid from a Taifoon key's balance, with `apiKey`): the layer asks Jev the
33
+ * four RUBRIC questions on `text` and returns the answers; this package composes the verdict from them as with a key. */
34
+ export declare function askLayer(a: {
35
+ text: string;
36
+ questions: readonly Question[];
37
+ layer?: string;
38
+ apiKey?: string | null;
39
+ fetch?: typeof fetch;
40
+ }): Promise<Asked>;
package/dist/ask.js CHANGED
@@ -1,6 +1,10 @@
1
1
  export const TYPESAFE_URL = 'https://api.typesafe.ai';
2
2
  /** The model every key-path call asks for. Pinned, not `jev-latest`: a record says which model answered, and an alias can move. */
3
3
  export const JEV_MODEL = 'jev-1.13.0';
4
+ /** the coordination layer, where a caller without a TypeSafe key claims its free grades */
5
+ export const LAYER_URL = 'https://coord.taifoon.dev';
6
+ /** the questions the layer's free grade answers (RUBRIC_v1 asks exactly these); another rubric needs the caller's own key */
7
+ export const LAYER_QUESTIONS = Object.freeze(['spec_met', 'unsupported_claim', 'ending', 'cheat_shaped']);
4
8
  export class JevError extends Error {
5
9
  status;
6
10
  next;
@@ -33,3 +37,29 @@ export async function askJev(a) {
33
37
  }
34
38
  return { answers, model: j.model ?? null, latency_ms: Date.now() - started, connection: 'key', trial: null };
35
39
  }
40
+ /** A free grade on the coordination layer (or one paid from a Taifoon key's balance, with `apiKey`): the layer asks Jev the
41
+ * four RUBRIC questions on `text` and returns the answers; this package composes the verdict from them as with a key. */
42
+ export async function askLayer(a) {
43
+ const f = a.fetch ?? fetch;
44
+ const started = Date.now();
45
+ const other = a.questions.map((q) => q.id).filter((id) => !LAYER_QUESTIONS.includes(id));
46
+ if (other.length)
47
+ throw new JevError(`the layer's free grade answers ${LAYER_QUESTIONS.join(', ')}; this rubric also asks ${other.join(', ')}: pass { key } (your TypeSafe key)`, 400, 'grade({ key: process.env.TYPESAFE_KEY })');
48
+ const base = (a.layer ?? LAYER_URL).replace(/\/$/, '');
49
+ if (!/^https:\/\//.test(base) && !/^http:\/\/(localhost|127\.0\.0\.1)(:\d+)?$/.test(base))
50
+ throw new JevError('the layer is only called over https', 400);
51
+ const r = await f(`${base}/v1/judge/compose`, { method: 'POST', headers: { 'content-type': 'application/json', 'x-taifoon-client': '@taifoon/jev', ...(a.apiKey ? { 'x-api-key': a.apiKey } : {}) }, body: JSON.stringify({ state: a.text }), signal: AbortSignal.timeout(65_000) });
52
+ const j = (await r.json().catch(() => ({})));
53
+ if (r.status === 402)
54
+ throw new JevError('no free grade left for this caller today: pass { key } (your TypeSafe key), a Taifoon key (layerKey), or pay one grade with x402 at POST ' + `${base}/v1/judge/compose`, 402, `${base}/v1/judge/compose`);
55
+ if (!r.ok)
56
+ throw new JevError(`the layer answered ${r.status}${j.error ? `: ${String(j.error).slice(0, 200)}` : ''}`, r.status);
57
+ const answers = {};
58
+ for (const q of a.questions) {
59
+ const x = j.receipt?.answers?.[q.id];
60
+ if (x)
61
+ answers[q.id] = norm(q.id, x);
62
+ }
63
+ const g = j.quota?.grades;
64
+ return { answers, model: j.model ?? null, latency_ms: Date.now() - started, connection: 'trial', trial: g && typeof g.free === 'number' && typeof g.left === 'number' ? { calls: g.free, left: g.left } : null };
65
+ }
@@ -0,0 +1,18 @@
1
+ export declare const DEVNET = 36927;
2
+ export declare const CHAIN_NAMES: Readonly<Record<number, string>>;
3
+ export declare const chainName: (id: number) => string;
4
+ /** A chain id from an id ("8453"), a name ("base", "Arbitrum One") or a number. Throws JevChainError bad_input. */
5
+ export declare function chainIdOf(x: string | number): number;
6
+ /** The Jev logs of a chain, or null when none is deployed there. */
7
+ export declare const jevLogsOn: (chainId: number) => {
8
+ answerLog: {
9
+ address: string;
10
+ fromBlock: number;
11
+ };
12
+ decisionLog: {
13
+ address: string;
14
+ fromBlock: number;
15
+ };
16
+ } | null;
17
+ /** Every chain that carries Jev logs, the devnet first, then Base, then the rest by id. */
18
+ export declare const JEV_CHAINS: readonly number[];
package/dist/chains.js ADDED
@@ -0,0 +1,31 @@
1
+ // The chains verify() knows: every chain the coordination layer reads, by id or name, and the Jev logs on each
2
+ // (vendored from the address registry: src/addresses.ts JEV_LOGS). A chain without Jev logs is known but has nothing to verify.
3
+ import { JEV_LOGS } from './addresses.js';
4
+ import { JevChainError } from './errors.js';
5
+ export const DEVNET = 36927;
6
+ export const CHAIN_NAMES = {
7
+ 36927: 'Taifoon devnet', 8453: 'Base', 42161: 'Arbitrum One', 5042: 'Arc', 4663: 'Robinhood Chain', 143: 'Monad',
8
+ 3692781: 'Taifoon mainnet', 1: 'Ethereum',
9
+ };
10
+ const ALIASES = {
11
+ devnet: 36927, 'taifoon-devnet': 36927, base: 8453, arbitrum: 42161, 'arbitrum-one': 42161, arb: 42161, arc: 5042,
12
+ robinhood: 4663, 'robinhood-chain': 4663, monad: 143, taifoon: 3692781, 'taifoon-mainnet': 3692781, ethereum: 1, eth: 1,
13
+ };
14
+ export const chainName = (id) => `${CHAIN_NAMES[id] ?? 'chain'} (${id})`;
15
+ /** A chain id from an id ("8453"), a name ("base", "Arbitrum One") or a number. Throws JevChainError bad_input. */
16
+ export function chainIdOf(x) {
17
+ if (typeof x === 'number' && Number.isInteger(x) && x > 0)
18
+ return x;
19
+ const s = String(x).trim().toLowerCase().replace(/\s+/g, '-');
20
+ if (/^\d+$/.test(s))
21
+ return Number(s);
22
+ const id = ALIASES[s];
23
+ if (!id)
24
+ throw new JevChainError('bad_input', `unknown chain "${x}"; use an id or one of: ${Object.keys(ALIASES).join(', ')}`);
25
+ return id;
26
+ }
27
+ /** The Jev logs of a chain, or null when none is deployed there. */
28
+ export const jevLogsOn = (chainId) => JEV_LOGS[chainId] ?? null;
29
+ /** Every chain that carries Jev logs, the devnet first, then Base, then the rest by id. */
30
+ export const JEV_CHAINS = Object.keys(JEV_LOGS).map(Number)
31
+ .sort((a, b) => (a === DEVNET ? -1 : b === DEVNET ? 1 : a === 8453 ? -1 : b === 8453 ? 1 : a - b));
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Why a chain read did not give an answer. `rpc_unavailable`: every endpoint failed (rate limit, 5xx, timeout); the record
3
+ * may well exist, try again or pass --rpc. `not_deployed`: no Jev log on that chain. `reverted`: the call reverted.
4
+ * `bad_input`: an argument verify() cannot use. "Not recorded" is not an error: verify() reports it in onChain.status.
5
+ */
6
+ export type JevChainErrorCode = 'rpc_unavailable' | 'not_deployed' | 'reverted' | 'bad_input';
7
+ export declare class JevChainError extends Error {
8
+ readonly code: JevChainErrorCode;
9
+ readonly chainId?: number;
10
+ constructor(code: JevChainErrorCode, message: string, chainId?: number);
11
+ }
package/dist/errors.js ADDED
@@ -0,0 +1,5 @@
1
+ export class JevChainError extends Error {
2
+ code;
3
+ chainId;
4
+ constructor(code, message, chainId) { super(message); this.name = 'JevChainError'; this.code = code; this.chainId = chainId; }
5
+ }
package/dist/grade.d.ts CHANGED
@@ -20,6 +20,11 @@ export type GradeInput = {
20
20
  caller?: string;
21
21
  /** base URL for `key` (default https://api.typesafe.ai) */
22
22
  endpoint?: string;
23
+ /** with no `key` and no `answers`: the coordination layer whose free grades are claimed (default https://coord.taifoon.dev);
24
+ * false never calls it (then a key or answers are required) */
25
+ layer?: string | false;
26
+ /** a Taifoon key (tfr_…): a grade past the free ones is paid from its balance on the layer */
27
+ layerKey?: string | null;
23
28
  fetch?: typeof fetch;
24
29
  /** ms since epoch for the answer record; default now */
25
30
  at?: number;
package/dist/grade.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // grade(): evidence → deterministic facts → Jev's atomic questions → composed verdict → receipt.
2
- import { askJev, JevError } from './ask.js';
2
+ import { askJev, askLayer, JevError } from './ask.js';
3
3
  import { answersOf, buildReceipt, DEFAULT_FACTS, inputFor, packOf, rubricOf } from './receipt.js';
4
4
  export async function grade(g) {
5
5
  const rubric = rubricOf(g.rubric);
@@ -17,9 +17,12 @@ export async function grade(g) {
17
17
  connection = 'supplied';
18
18
  }
19
19
  else {
20
- if (!g.key)
20
+ if (!g.key && g.layer === false)
21
21
  throw new JevError('pass { key } (your TypeSafe key, from console.typesafe.ai) or { answers } you already have', 400);
22
- asked = await askJev({ text: jevState, questions: rubric.asked, key: g.key, endpoint: g.endpoint, fetch: g.fetch });
22
+ // _FREE_GRADES_v1_: no key of your own → the caller's free grades on the coordination layer (then x402 or a Taifoon key)
23
+ asked = g.key
24
+ ? await askJev({ text: jevState, questions: rubric.asked, key: g.key, endpoint: g.endpoint, fetch: g.fetch })
25
+ : await askLayer({ text: jevState, questions: rubric.asked, layer: g.layer || undefined, apiKey: g.layerKey, fetch: g.fetch });
23
26
  const missing = rubric.asked.filter((q) => !asked.answers[q.id]).map((q) => q.id);
24
27
  if (missing.length)
25
28
  throw new JevError(`Jev returned no valid answer for: ${missing.join(', ')}`, 502);
package/dist/index.d.ts CHANGED
@@ -20,6 +20,9 @@ export { prepareJob, runCheck } from './job.js';
20
20
  export { record } from './record.js';
21
21
  export { evaluatorCall } from './evaluator/index.js';
22
22
  export { verify } from './verify.js';
23
+ export { JevChainError, type JevChainErrorCode } from './errors.js';
24
+ export { CHAIN_NAMES, JEV_CHAINS, chainIdOf, chainName, jevLogsOn } from './chains.js';
25
+ export { rpcRotation, WARMBED } from './rpc.js';
23
26
  export { verifyDecision } from './decision.js';
24
27
  export { pipeline, STEPS, LAYER, factsFromEvidence, protocolFor, parseJob, localQuote } from './pipeline.js';
25
28
  export { RUBRIC_v1 } from './rubric.js';
@@ -28,7 +31,7 @@ export type { GradeInput, Receipt } from './grade.js';
28
31
  export type { FactsInput, Check } from './facts.js';
29
32
  export type { JobSpec, JobCheck, PreparedJob } from './job.js';
30
33
  export type { Recorded, UnsignedCall, Network } from './record.js';
31
- export type { Verification, AnswerEvent, DecisionEvent } from './verify.js';
34
+ export type { Verification, AnswerEvent, DecisionEvent, ChainStatus, VerifyOptions, VerifyNetwork } from './verify.js';
32
35
  export type { DecisionRecord, DecisionCheck } from './decision.js';
33
36
  export type { Protocol, Adapter, AdapterOpts, EvaluatorCall } from './evaluator/index.js';
34
37
  export type { JevError } from './ask.js';
package/dist/index.js CHANGED
@@ -20,6 +20,9 @@ export { prepareJob, runCheck } from './job.js';
20
20
  export { record } from './record.js';
21
21
  export { evaluatorCall } from './evaluator/index.js';
22
22
  export { verify } from './verify.js';
23
+ export { JevChainError } from './errors.js';
24
+ export { CHAIN_NAMES, JEV_CHAINS, chainIdOf, chainName, jevLogsOn } from './chains.js';
25
+ export { rpcRotation, WARMBED } from './rpc.js';
23
26
  export { verifyDecision } from './decision.js';
24
27
  export { pipeline, STEPS, LAYER, factsFromEvidence, protocolFor, parseJob, localQuote } from './pipeline.js';
25
28
  export { RUBRIC_v1 } from './rubric.js';
package/dist/pipeline.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // pipeline(): one job through the coordination layer's steps, each step a function with a typed output.
2
2
  // pick → evidence → facts → grade → record → evaluator → premium → verify
3
3
  // Every step works without the layer too: pass `evidence` (your own pack) and the layer is never read; `grade` then
4
- // runs on your own TypeSafe key (or answers you already have), `record` returns unsigned calls, `premium` is priced from a `sellerRecord` you pass (or skipped). With the layer
4
+ // runs on your own TypeSafe key (or answers you already have, or without either on the caller's free grades on the layer), `record` returns unsigned calls, `premium` is priced from a `sellerRecord` you pass (or skipped). With the layer
5
5
  // (https://coord.taifoon.dev by default) the job comes from /v1/judge/queue, the pack from /v1/judge/evidence, the
6
6
  // seller's terms from /v1/pools/quote, and — only with a relayer key — the answers are recorded on the layer through
7
7
  // /v1/judge/answers/record. Nothing here signs a transaction.
@@ -156,12 +156,17 @@ export async function pipeline(o = {}) {
156
156
  }
157
157
  else if (o.key)
158
158
  g.key = o.key;
159
+ // _FREE_GRADES_v1_: no key → the caller's free grades on this layer (paid from relayerKey's balance past them); offline: none
160
+ else {
161
+ g.layer = layer ?? false;
162
+ g.layerKey = o.relayerKey ?? null;
163
+ }
159
164
  // no key: a job the code checks reject is still graded (Jev is not asked); only asking Jev needs the key
160
165
  try {
161
166
  t.receipt = await grade(g);
162
167
  }
163
168
  catch (e) {
164
- if (!o.key && !o.answers && /TypeSafe key/.test(e.message))
169
+ if (!o.key && !o.answers && !layer && /TypeSafe key/.test(e.message))
165
170
  throw new Error('Jev needs your TypeSafe key: set TYPESAFE_KEY (console.typesafe.ai), or pass answers you already have');
166
171
  throw e;
167
172
  }
@@ -0,0 +1,4 @@
1
+ export declare const RPC_FALLBACK: Readonly<Record<number, {
2
+ logs: readonly string[];
3
+ call: readonly string[];
4
+ }>>;
@@ -0,0 +1,36 @@
1
+ // GENERATED by scripts/vendor-rpc.mjs from packages/rpc/fallback.json (measured 2026-10-08). Do not edit.
2
+ // The fallback only: verify() asks warmbed's rotation first and uses these when warmbed does not answer.
3
+ export const RPC_FALLBACK = {
4
+ 36927: {
5
+ logs: ["https://rpc.taifoon.dev"],
6
+ call: ["https://rpc.taifoon.dev"],
7
+ },
8
+ 8453: {
9
+ logs: ["https://base.rpc.blxrbdn.com", "https://base.public.blockpi.network/v1/rpc/public", "https://base-rpc.publicnode.com", "https://gateway.tenderly.co/public/base", "https://base.gateway.tenderly.co"],
10
+ call: ["https://base.rpc.blxrbdn.com", "https://base.public.blockpi.network/v1/rpc/public", "https://gateway.tenderly.co/public/base", "https://base.gateway.tenderly.co", "https://base-rpc.publicnode.com", "https://developer-access-mainnet.base.org", "https://mainnet.base.org", "https://base.drpc.org", "https://base-mainnet.public.blastapi.io", "https://api.zan.top/base-mainnet", "https://base.meowrpc.com", "https://base-public.nodies.app"],
11
+ },
12
+ 42161: {
13
+ logs: ["https://arb1.arbitrum.io/rpc", "https://gateway.tenderly.co/public/arbitrum", "https://arbitrum.gateway.tenderly.co"],
14
+ call: ["https://arb1.arbitrum.io/rpc", "https://gateway.tenderly.co/public/arbitrum", "https://arbitrum.gateway.tenderly.co", "https://arbitrum.drpc.org", "https://arbitrum-one-rpc.publicnode.com", "https://arbitrum-one.public.blastapi.io"],
15
+ },
16
+ 5042: {
17
+ logs: ["https://rpc.mainnet.arc.io", "https://rpc.quicknode.mainnet.arc.io", "https://rpc.blockdaemon.mainnet.arc.io", "https://arc.gateway.tenderly.co"],
18
+ call: ["https://rpc.mainnet.arc.io", "https://rpc.quicknode.mainnet.arc.io", "https://rpc.blockdaemon.mainnet.arc.io", "https://arc.gateway.tenderly.co", "https://rpc.drpc.mainnet.arc.io", "https://arc.drpc.org", "https://arc-rpc.publicnode.com"],
19
+ },
20
+ 4663: {
21
+ logs: ["https://rpc.mainnet.chain.robinhood.com", "https://rpc.ordofi.network"],
22
+ call: ["https://rpc.mainnet.chain.robinhood.com", "https://rpc.ordofi.network", "https://robinhood.drpc.org", "https://robinhood-rpc.publicnode.com"],
23
+ },
24
+ 143: {
25
+ logs: ["https://rpc1.monad.xyz", "https://infra.originstake.com/monad/evm"],
26
+ call: ["https://rpc1.monad.xyz", "https://infra.originstake.com/monad/evm", "https://rpc.monad.xyz", "https://rpc3.monad.xyz", "https://rpc-mainnet.monadinfra.com", "https://monad.gateway.tenderly.co", "https://rpc.ankr.com/monad_mainnet", "https://rpc4.monad.xyz"],
27
+ },
28
+ 3692781: {
29
+ logs: ["https://mainnet.taifoon.dev"],
30
+ call: ["https://mainnet.taifoon.dev"],
31
+ },
32
+ 1: {
33
+ logs: ["https://gateway.tenderly.co/public/mainnet", "https://rpc.mevblocker.io", "https://mainnet.gateway.tenderly.co", "https://ethereum.publicnode.com", "https://rpc.flashbots.net"],
34
+ call: ["https://gateway.tenderly.co/public/mainnet", "https://mainnet.gateway.tenderly.co", "https://rpc.mevblocker.io", "https://ethereum-rpc.publicnode.com", "https://ethereum.publicnode.com", "https://rpc.flashbots.net", "https://eth.drpc.org"],
35
+ },
36
+ };
package/dist/rpc.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ export declare const WARMBED = "https://warmbed.taifoon.dev";
2
+ export declare const RPC_TIMEOUT_MS = 30000;
3
+ /** Forget the cached rotations (tests; a long-running process never needs it: entries expire after 60 s). */
4
+ export declare function clearRpcCache(): void;
5
+ /** warmbed's rotation of a chain for `need`, then the static fallback (deduplicated). Never throws. */
6
+ export declare function rpcRotation(chainId: number, f?: typeof fetch, need?: 'logs' | 'call'): Promise<string[]>;
7
+ /** The cap an endpoint names when it refuses a range ("eth_getLogs is limited to a 500 range"), or null. */
8
+ export declare function rangeCapOf(message: string): number | null;
9
+ /**
10
+ * One JSON-RPC call over a list of endpoints (or one URL): each endpoint in turn, two passes with a short pause, each
11
+ * attempt bounded by RPC_TIMEOUT_MS. Throws JevChainError reverted / rpc_unavailable, or the range refusal as is.
12
+ */
13
+ export declare function rpcCall<T>(rpc: string | readonly string[], f: typeof fetch, method: string, params: unknown[], o?: {
14
+ chainId?: number;
15
+ passes?: number;
16
+ timeoutMs?: number;
17
+ }): Promise<T>;
package/dist/rpc.js ADDED
@@ -0,0 +1,87 @@
1
+ // The RPCs the package reads through: warmbed's rotation (https://warmbed.taifoon.dev, endpoints it measured to serve
2
+ // eth_getLogs windows), then the static list vendored from the RPC registry (src/rpc-fallback.ts). A rate limit, a 5xx,
3
+ // a timeout or a refusal moves a call to the next endpoint; a revert is thrown at once (JevChainError reverted), and so is a
4
+ // range refusal that names its cap (the caller narrows the window). When every endpoint failed: JevChainError rpc_unavailable.
5
+ import { JevChainError } from './errors.js';
6
+ import { RPC_FALLBACK } from './rpc-fallback.js';
7
+ export const WARMBED = 'https://warmbed.taifoon.dev';
8
+ export const RPC_TIMEOUT_MS = 30_000;
9
+ const WARMBED_TIMEOUT_MS = 2_500;
10
+ const TTL_MS = 60_000;
11
+ const cache = new Map();
12
+ /** Forget the cached rotations (tests; a long-running process never needs it: entries expire after 60 s). */
13
+ export function clearRpcCache() { cache.clear(); }
14
+ /** warmbed's rotation of a chain for `need`, then the static fallback (deduplicated). Never throws. */
15
+ export async function rpcRotation(chainId, f = fetch, need = 'logs') {
16
+ const k = `${chainId}:${need}`;
17
+ const hit = cache.get(k);
18
+ if (hit && Date.now() - hit.at < TTL_MS)
19
+ return hit.urls;
20
+ let warm = [];
21
+ try {
22
+ const r = await f(`${WARMBED}/warmbed/chain/${chainId}/rotation?need=${need}${need === 'logs' ? '&min_span=500' : ''}&n=8`, { signal: AbortSignal.timeout(WARMBED_TIMEOUT_MS) });
23
+ const body = r && r.ok ? (await r.json()) : null;
24
+ if (Array.isArray(body))
25
+ warm = body.map((e) => (e && typeof e === 'object' ? String(e.url ?? '') : '')).filter((u) => /^https:\/\//.test(u));
26
+ }
27
+ catch {
28
+ warm = [];
29
+ }
30
+ const urls = [...new Set([...warm, ...(RPC_FALLBACK[chainId]?.[need] ?? []), ...(RPC_FALLBACK[chainId]?.call ?? [])])];
31
+ if (warm.length)
32
+ cache.set(k, { at: Date.now(), urls });
33
+ return urls;
34
+ }
35
+ const REVERT = /revert|invalid opcode|out of gas/i;
36
+ /** The cap an endpoint names when it refuses a range ("eth_getLogs is limited to a 500 range"), or null. */
37
+ export function rangeCapOf(message) {
38
+ const m = /limited to (?:a )?(\d+)(?: block)? range/i.exec(message) ?? /range (?:is )?(?:limited|capped) (?:to|at) (\d+)/i.exec(message);
39
+ return m ? Number(m[1]) : null;
40
+ }
41
+ /**
42
+ * One JSON-RPC call over a list of endpoints (or one URL): each endpoint in turn, two passes with a short pause, each
43
+ * attempt bounded by RPC_TIMEOUT_MS. Throws JevChainError reverted / rpc_unavailable, or the range refusal as is.
44
+ */
45
+ export async function rpcCall(rpc, f, method, params, o = {}) {
46
+ const urls = typeof rpc === 'string' ? [rpc] : rpc;
47
+ if (!urls.length)
48
+ throw new JevChainError('rpc_unavailable', `${method}: no RPC endpoint`, o.chainId);
49
+ const passes = o.passes ?? 2;
50
+ let last = '';
51
+ for (let p = 0; p < passes; p++) {
52
+ for (const u of urls) {
53
+ try {
54
+ const r = await f(u, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ jsonrpc: '2.0', id: 1, method, params }), signal: AbortSignal.timeout(o.timeoutMs ?? RPC_TIMEOUT_MS) });
55
+ if (typeof r.status === 'number' && r.status >= 400) {
56
+ last = `${hostOf(u)}: http ${r.status}`;
57
+ continue;
58
+ }
59
+ const j = (await r.json());
60
+ if (j.error) {
61
+ const msg = String(j.error.message ?? j.error.code);
62
+ if (j.error.code === 3 || REVERT.test(msg))
63
+ throw new JevChainError('reverted', `${method}: ${msg}`, o.chainId);
64
+ if (rangeCapOf(msg))
65
+ throw Object.assign(new Error(`${method}: ${msg}`), { final: true });
66
+ last = `${hostOf(u)}: ${msg.slice(0, 160)}`;
67
+ continue;
68
+ }
69
+ return j.result;
70
+ }
71
+ catch (e) {
72
+ if (e instanceof JevChainError || e.final)
73
+ throw e;
74
+ last = `${hostOf(u)}: ${e instanceof Error ? e.message : String(e)}`;
75
+ }
76
+ }
77
+ if (p + 1 < passes)
78
+ await new Promise((r) => setTimeout(r, 400 * (p + 1)));
79
+ }
80
+ throw new JevChainError('rpc_unavailable', `${method}: every RPC endpoint failed (last: ${last})`, o.chainId);
81
+ }
82
+ function hostOf(u) { try {
83
+ return new URL(u).host;
84
+ }
85
+ catch {
86
+ return u;
87
+ } }
package/dist/verify.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { rangeCapOf } from './rpc.js';
1
2
  import { type Hex } from './hash.js';
2
3
  import type { Receipt } from './receipt.js';
3
4
  import { type Rubric, type RubricInput } from './rubric.js';
@@ -25,36 +26,48 @@ export type DecisionEvent = {
25
26
  export type Verification = {
26
27
  ok: boolean;
27
28
  checks: Record<string, boolean>;
29
+ /** status: recorded (the answer row is on chain) · not_recorded (the chain answered, no row) · rpc_unavailable (no endpoint
30
+ * answered: the row may exist) · not_deployed (no Jev log on that chain) · skipped (chain: false) */
28
31
  onChain: {
29
32
  chainId: number;
30
33
  answers: AnswerEvent[];
31
34
  decisions: DecisionEvent[];
35
+ status?: ChainStatus;
32
36
  };
33
37
  problems: string[];
34
38
  };
39
+ export type ChainStatus = 'recorded' | 'not_recorded' | 'rpc_unavailable' | 'not_deployed' | 'skipped';
35
40
  export type Log = {
36
41
  transactionHash: string;
37
42
  blockNumber: string;
38
43
  topics: string[];
39
44
  data: Hex;
40
45
  };
41
- /** The block cap an endpoint names when it refuses a range ("eth_getLogs is limited to a 500 range"), or null. */
42
- export declare function rangeCapOf(message: string): number | null;
46
+ type Rpc = string | readonly string[];
47
+ export { rangeCapOf };
43
48
  /**
44
49
  * eth_getLogs over [from, to], nearest to `center` first, in windows of at most `step` blocks (public Base endpoints
45
50
  * refuse wide ranges: mainnet.base.org caps a call at 500 blocks). A refusal that names a smaller cap shrinks the
46
51
  * window and retries. Stops at the first window where `hit` matches, so a record next to its answer costs one call.
47
52
  */
48
- export declare function logsAround(rpc: string, f: typeof fetch, address: string, topics: Array<string | null>, center: number, from: number, to: number, hit: (l: Log) => boolean, step?: number): Promise<Log[]>;
49
- /**
50
- * `network`: 'devnet' (default, chain 36927) or 'base' (8453). On Base the answer row is found through
51
- * JevAnswerLog.recordedAt (trusted records only) and the decision row in a window around it, because public Base
52
- * endpoints refuse wide log ranges.
53
- */
54
- export declare function verify(x: Receipt | string, opts?: {
55
- rpc?: string;
53
+ export declare function logsAround(rpc: Rpc, f: typeof fetch, address: string, topics: Array<string | null>, center: number, from: number, to: number, hit: (l: Log) => boolean, step?: number, chainId?: number): Promise<Log[]>;
54
+ /** Which chain verify() reads: 'devnet' (default, 36927), 'base', a chain id or a chain name ("arbitrum", "arc", "monad" …). */
55
+ export type VerifyNetwork = 'devnet' | 'base' | number | string;
56
+ export type VerifyOptions = {
57
+ /** one URL, a comma list or a list: read through these instead of warmbed's rotation */
58
+ rpc?: string | readonly string[];
56
59
  fetch?: typeof fetch;
57
60
  rubric?: Rubric | RubricInput;
61
+ /** false: recompute the digests only, read no chain */
58
62
  chain?: boolean;
59
- network?: 'devnet' | 'base';
60
- }): Promise<Verification>;
63
+ network?: VerifyNetwork;
64
+ /** a block near the decision row (a decision record's anchor.block): its window is read first */
65
+ decisionBlock?: number;
66
+ };
67
+ /**
68
+ * Recompute a receipt (or take a bare answers digest), then find its rows on one chain. Every chain but the devnet is
69
+ * read through JevAnswerLog.recordedAt (trusted records only) and the decision row in windows around it, because public
70
+ * endpoints refuse wide log ranges; the devnet is read in one range. The chain is read through warmbed's rotation, then
71
+ * the registry's static list; `rpc` overrides both.
72
+ */
73
+ export declare function verify(x: Receipt | string, opts?: VerifyOptions): Promise<Verification>;
package/dist/verify.js CHANGED
@@ -1,7 +1,9 @@
1
1
  // verify(): recompute every digest a receipt carries, re-compose its verdict from its own answers, then find the chain
2
2
  // events that hold those digests. Given a bare answers digest, it finds the JevAnswered log for it.
3
3
  import { decode } from './abi.js';
4
- import { CONTRACTS } from './contracts.js';
4
+ import { chainIdOf, chainName, DEVNET, jevLogsOn } from './chains.js';
5
+ import { JevChainError } from './errors.js';
6
+ import { rangeCapOf, rpcCall, rpcRotation } from './rpc.js';
5
7
  import { keccakHex, sha256Hex } from './hash.js';
6
8
  import { answersDigestOf, confidenceBpsOf, decisionAnswersOf, decisionDigest, subjectIdOf } from './records.js';
7
9
  import { defineRubric, receiptBody, receiptHashOf, RUBRIC_v1 } from './rubric.js';
@@ -10,34 +12,23 @@ const TOPIC_DECIDED = keccakHex('Decided(bytes32,bytes32,address,uint256,bytes32
10
12
  const ANSWERED_DATA = ['address', 'bytes32', 'bytes32', 'string', 'string', 'uint256', 'bool'];
11
13
  const DECIDED_DATA = ['uint256', 'bytes32', 'uint16', 'string', 'string'];
12
14
  const hexN = (n) => '0x' + n.toString(16);
13
- async function rpcCall(rpc, f, method, params) {
14
- const r = await f(rpc, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ jsonrpc: '2.0', id: 1, method, params }), signal: AbortSignal.timeout(30_000) });
15
- const j = (await r.json());
16
- if (j.error)
17
- throw new Error(`${method}: ${j.error.message}`);
18
- return j.result;
19
- }
20
- async function logs(rpc, f, address, topics, fromBlock, toBlock) {
21
- return (await rpcCall(rpc, f, 'eth_getLogs', [{ address, topics, fromBlock: hexN(fromBlock), toBlock: toBlock == null ? 'latest' : hexN(toBlock) }])) ?? [];
15
+ async function logs(rpc, f, address, topics, fromBlock, toBlock, chainId) {
16
+ return (await rpcCall(rpc, f, 'eth_getLogs', [{ address, topics, fromBlock: hexN(fromBlock), toBlock: toBlock == null ? 'latest' : hexN(toBlock) }], { chainId })) ?? [];
22
17
  }
23
18
  const SEL_RECORDED_AT = keccakHex('recordedAt(bytes32)').slice(0, 10);
24
19
  /** JevAnswerLog.recordedAt(digest): the block of the first trusted record, 0 when none. */
25
- async function recordedAt(rpc, f, address, digest) {
26
- const out = await rpcCall(rpc, f, 'eth_call', [{ to: address, data: SEL_RECORDED_AT + digest.slice(2) }, 'latest']);
20
+ async function recordedAt(rpc, f, address, digest, chainId) {
21
+ const out = await rpcCall(rpc, f, 'eth_call', [{ to: address, data: SEL_RECORDED_AT + digest.slice(2) }, 'latest'], { chainId });
27
22
  return out && out !== '0x' ? Number(BigInt(out)) : 0;
28
23
  }
29
- /** The block cap an endpoint names when it refuses a range ("eth_getLogs is limited to a 500 range"), or null. */
30
- export function rangeCapOf(message) {
31
- const m = /limited to (?:a )?(\d+)(?: block)? range/i.exec(message) ?? /range (?:is )?(?:limited|capped) (?:to|at) (\d+)/i.exec(message);
32
- return m ? Number(m[1]) : null;
33
- }
24
+ export { rangeCapOf };
34
25
  /**
35
26
  * eth_getLogs over [from, to], nearest to `center` first, in windows of at most `step` blocks (public Base endpoints
36
27
  * refuse wide ranges: mainnet.base.org caps a call at 500 blocks). A refusal that names a smaller cap shrinks the
37
28
  * window and retries. Stops at the first window where `hit` matches, so a record next to its answer costs one call.
38
29
  */
39
- export async function logsAround(rpc, f, address, topics, center, from, to, hit, step = 500) {
40
- const head = Number(BigInt(await rpcCall(rpc, f, 'eth_blockNumber', [])));
30
+ export async function logsAround(rpc, f, address, topics, center, from, to, hit, step = 500, chainId) {
31
+ const head = Number(BigInt(await rpcCall(rpc, f, 'eth_blockNumber', [], { chainId })));
41
32
  to = Math.min(to, head); // endpoints refuse a range past the head
42
33
  center = Math.min(Math.max(center, from), to);
43
34
  const out = [];
@@ -46,7 +37,7 @@ export async function logsAround(rpc, f, address, topics, center, from, to, hit,
46
37
  try {
47
38
  const got = [];
48
39
  for (let x = a; x <= b; x += step)
49
- got.push(...(await logs(rpc, f, address, topics, x, Math.min(b, x + step - 1))));
40
+ got.push(...(await logs(rpc, f, address, topics, x, Math.min(b, x + step - 1), chainId)));
50
41
  return got;
51
42
  }
52
43
  catch (e) {
@@ -79,20 +70,18 @@ export async function logsAround(rpc, f, address, topics, center, from, to, hit,
79
70
  const answerEvent = (l) => { const [recorder, inputDigest, decisionDigest, model, uri, , trusted] = decode(ANSWERED_DATA, l.data); return { tx: l.transactionHash, block: parseInt(l.blockNumber, 16), recorder: String(recorder), trusted: Boolean(trusted), subject: l.topics[2], inputDigest: inputDigest, decisionDigest: decisionDigest, model: String(model), uri: String(uri) }; };
80
71
  const decisionEvent = (l) => { const [index, digest, bps, model, uri] = decode(DECIDED_DATA, l.data); return { tx: l.transactionHash, block: parseInt(l.blockNumber, 16), recorder: `0x${String(l.topics[3]).slice(26)}`, index: Number(index), digest: digest, confidenceBps: Number(bps), model: String(model), uri: String(uri) }; };
81
72
  /**
82
- * `network`: 'devnet' (default, chain 36927) or 'base' (8453). On Base the answer row is found through
83
- * JevAnswerLog.recordedAt (trusted records only) and the decision row in a window around it, because public Base
84
- * endpoints refuse wide log ranges.
73
+ * Recompute a receipt (or take a bare answers digest), then find its rows on one chain. Every chain but the devnet is
74
+ * read through JevAnswerLog.recordedAt (trusted records only) and the decision row in windows around it, because public
75
+ * endpoints refuse wide log ranges; the devnet is read in one range. The chain is read through warmbed's rotation, then
76
+ * the registry's static list; `rpc` overrides both.
85
77
  */
86
78
  export async function verify(x, opts = {}) {
87
- const network = opts.network ?? 'devnet';
79
+ const chainId = chainIdOf(opts.network ?? 'devnet');
88
80
  const f = opts.fetch ?? fetch;
89
- const rpc = opts.rpc ?? CONTRACTS[network].rpc;
90
- const dev = network === 'base'
91
- ? { chainId: CONTRACTS.base.chainId, answerLog: CONTRACTS.base.answerLog, decisionLog: CONTRACTS.base.decisionLog }
92
- : { chainId: CONTRACTS.devnet.chainId, answerLog: CONTRACTS.devnet.answerLog, decisionLog: CONTRACTS.devnet.decisionLog };
81
+ const dev = { chainId, ...(jevLogsOn(chainId) ?? { answerLog: null, decisionLog: null }) };
93
82
  const checks = {};
94
83
  const problems = [];
95
- const onChain = { chainId: dev.chainId, answers: [], decisions: [] };
84
+ const onChain = { chainId: dev.chainId, answers: [], decisions: [], status: 'skipped' };
96
85
  let answersDigest;
97
86
  let subjectId = null;
98
87
  let decision = null;
@@ -125,32 +114,46 @@ export async function verify(x, opts = {}) {
125
114
  decision = x.decision?.digest ?? null;
126
115
  }
127
116
  if (opts.chain !== false && answersDigest) {
128
- try {
129
- if (!dev.answerLog || !dev.decisionLog)
130
- throw new Error(`this package version carries no ${network} address for the logs`);
131
- if (network === 'base') {
132
- const at = await recordedAt(rpc, f, dev.answerLog.address, answersDigest);
133
- if (at > 0)
134
- onChain.answers = (await logs(rpc, f, dev.answerLog.address, [TOPIC_ANSWERED, null, null, answersDigest], at, at)).map(answerEvent);
135
- }
136
- else
137
- onChain.answers = (await logs(rpc, f, dev.answerLog.address, [TOPIC_ANSWERED, null, null, answersDigest], dev.answerLog.fromBlock)).map(answerEvent);
138
- // a bare digest: the answer row names its subject and decision, so the decision row can be found too
139
- const first = onChain.answers[0];
140
- if (!subjectId && first && !/^0x0{64}$/.test(first.decisionDigest)) {
141
- subjectId = first.subject;
142
- decision = first.decisionDigest;
117
+ const where = chainName(chainId);
118
+ if (!dev.answerLog || !dev.decisionLog) {
119
+ onChain.status = 'not_deployed';
120
+ problems.push(`no Jev log is deployed on ${where}`);
121
+ }
122
+ else {
123
+ try {
124
+ // an explicit rpc (one URL, a comma list or a list) wins; otherwise warmbed's rotation, then the static fallback
125
+ const given = typeof opts.rpc === 'string' ? opts.rpc.split(',').map((u) => u.trim()).filter(Boolean) : opts.rpc;
126
+ const rpc = given?.length ? given : await rpcRotation(chainId, f);
127
+ if (chainId !== DEVNET) {
128
+ const at = await recordedAt(rpc, f, dev.answerLog.address, answersDigest, chainId);
129
+ if (at > 0)
130
+ onChain.answers = (await logs(rpc, f, dev.answerLog.address, [TOPIC_ANSWERED, null, null, answersDigest], at, at, chainId)).map(answerEvent);
131
+ }
132
+ else
133
+ onChain.answers = (await logs(rpc, f, dev.answerLog.address, [TOPIC_ANSWERED, null, null, answersDigest], dev.answerLog.fromBlock, undefined, chainId)).map(answerEvent);
134
+ // a bare digest: the answer row names its subject and decision, so the decision row can be found too
135
+ const first = onChain.answers[0];
136
+ if (!subjectId && first && !/^0x0{64}$/.test(first.decisionDigest)) {
137
+ subjectId = first.subject;
138
+ decision = first.decisionDigest;
139
+ }
140
+ if (subjectId && decision) {
141
+ const center = opts.decisionBlock ?? first?.block;
142
+ const found = chainId !== DEVNET && center
143
+ ? await logsAround(rpc, f, dev.decisionLog.address, [TOPIC_DECIDED, subjectId], center, Math.max(dev.decisionLog.fromBlock, center - 4000), center + 4000, (l) => decisionEvent(l).digest.toLowerCase() === decision.toLowerCase(), 500, chainId)
144
+ : await logs(rpc, f, dev.decisionLog.address, [TOPIC_DECIDED, subjectId], dev.decisionLog.fromBlock, undefined, chainId);
145
+ onChain.decisions = found.map(decisionEvent).filter((d) => d.digest.toLowerCase() === decision.toLowerCase());
146
+ }
147
+ onChain.status = onChain.answers.length ? 'recorded' : 'not_recorded';
148
+ if (!onChain.answers.length)
149
+ problems.push(`not recorded on ${where}`);
143
150
  }
144
- if (subjectId && decision) {
145
- const found = network === 'base' && first
146
- ? await logsAround(rpc, f, dev.decisionLog.address, [TOPIC_DECIDED, subjectId], first.block, Math.max(dev.decisionLog.fromBlock, first.block - 4000), first.block + 4000, (l) => decisionEvent(l).digest.toLowerCase() === decision.toLowerCase())
147
- : await logs(rpc, f, dev.decisionLog.address, [TOPIC_DECIDED, subjectId], dev.decisionLog.fromBlock);
148
- onChain.decisions = found.map(decisionEvent).filter((d) => d.digest.toLowerCase() === decision.toLowerCase());
151
+ catch (e) {
152
+ const unavailable = !(e instanceof JevChainError) || e.code === 'rpc_unavailable';
153
+ onChain.status = unavailable ? 'rpc_unavailable' : onChain.answers.length ? 'recorded' : 'not_recorded';
154
+ problems.push(`${unavailable ? `RPC unavailable on ${where}` : `chain read failed on ${where}`}: ${e instanceof Error ? e.message : String(e)}`);
149
155
  }
150
156
  }
151
- catch (e) {
152
- problems.push(`chain read failed: ${e instanceof Error ? e.message : String(e)}`);
153
- }
154
157
  checks.answersOnChain = onChain.answers.length > 0;
155
158
  if (decision)
156
159
  checks.decisionOnChain = onChain.decisions.length > 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taifoon/jev",
3
- "version": "0.2.16",
3
+ "version": "0.2.18",
4
4
  "description": "Grade AI agent jobs with TypeSafe's Jev and record the verdict on chain: code checks the facts, Jev answers a published rubric, and you get a receipt, the on-chain record and the evaluator call for ERC-8183 and Virtuals ACP. No runtime dependencies, no key inside.",
5
5
  "keywords": [
6
6
  "jev",