brainchain-verify 0.5.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +144 -7
- package/dist/cli.js +201 -24
- package/dist/verify.d.ts +151 -3
- package/dist/verify.js +979 -29
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,10 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
Check any BrainChain decision against the chain. The tool reads the decision from the `DecisionLog`, fetches the record Jev's answer was published in, recomputes its hashes and confidence, and applies the task's thresholds the way the contracts do. It needs a public RPC and nothing else: no keys, no account.
|
|
4
4
|
|
|
5
|
+
It also checks the reputation BrainChain writes for its workers. Each entry in the ERC-8004 registry on Robinhood Chain is followed through its signed receipt to the decision, the payment and the task on the board.
|
|
6
|
+
|
|
5
7
|
```sh
|
|
6
8
|
npx brainchain-verify mainnet 1
|
|
7
9
|
npx brainchain-verify mainnet --task 11 --set v3-1
|
|
8
10
|
npx brainchain-verify testnet 100 --json
|
|
11
|
+
npx brainchain-verify mainnet --receipt receipt.json
|
|
12
|
+
npx brainchain-verify mainnet --entry 20424:7
|
|
13
|
+
npx brainchain-verify mainnet --agent 20424
|
|
9
14
|
```
|
|
10
15
|
|
|
11
16
|
Requires Node.js 22 or later.
|
|
@@ -13,8 +18,11 @@ Requires Node.js 22 or later.
|
|
|
13
18
|
## Usage
|
|
14
19
|
|
|
15
20
|
```text
|
|
16
|
-
brainchain-verify <mainnet|testnet|chainId> <decisionId> [--set <TaskBoard>] [--rpc <url>] [--json]
|
|
17
|
-
brainchain-verify <mainnet|testnet|chainId> --task <taskId> [--set <TaskBoard>] [--rpc <url>] [--json]
|
|
21
|
+
brainchain-verify <mainnet|testnet|chainId> <decisionId> [--set <TaskBoard>] [--rpc <url>] [--offline] [--json]
|
|
22
|
+
brainchain-verify <mainnet|testnet|chainId> --task <taskId> [--set <TaskBoard>] [--rpc <url>] [--offline] [--json]
|
|
23
|
+
brainchain-verify <mainnet|testnet|chainId> [<decisionId>] --receipt <file|url> [--set <TaskBoard>] [--rpc <url>] [--json]
|
|
24
|
+
brainchain-verify mainnet --entry <agentId>:[<writer>:]<feedbackIndex> [--rpc <url>] [--registry-rpc <url>] [--json]
|
|
25
|
+
brainchain-verify mainnet --agent <agentId> [--rpc <url>] [--registry-rpc <url>] [--json]
|
|
18
26
|
```
|
|
19
27
|
|
|
20
28
|
| Argument | Meaning |
|
|
@@ -24,6 +32,11 @@ brainchain-verify <mainnet|testnet|chainId> --task <taskId> [--set <TaskBoard>]
|
|
|
24
32
|
| `--task <id>` | Check every decision about one task, oldest first. |
|
|
25
33
|
| `--set <TaskBoard>` | A retired contract set from 3.0.0 on, by its TaskBoard address, by the key a decision page uses (`?set=v3-1`, or an older one the site still opens, such as `v4` for `v3-4`) or by release (`3.1.0`). Without it, the active set. Each set numbers its tasks and decisions from 1. The `v2` set is not supported: its board named tasks by id alone, which the subject check does not read. |
|
|
26
34
|
| `--rpc <url>` | Another RPC for the same chain. Records and briefs on private addresses are read only when this RPC is on one too. |
|
|
35
|
+
| `--receipt <file\|url>` | Check the receipt for a paid job, from a JSON file or an http(s) URL. Without a decision id, the tool checks the decision the receipt names, in the contract set its DecisionLog belongs to. See [receipts](#receipts). |
|
|
36
|
+
| `--entry <agentId>:[<writer>:]<index>` | Check one reputation entry BrainChain wrote. See [reputation entries](#reputation-entries). |
|
|
37
|
+
| `--agent <agentId>` | Check every reputation entry BrainChain wrote for one agent, oldest first. |
|
|
38
|
+
| `--registry-rpc <url>` | Another RPC for Robinhood Chain, where the ERC-8004 registries are. |
|
|
39
|
+
| `--offline` | Fetch no receipt from the brain host. A receipt given with `--receipt` is still checked. |
|
|
27
40
|
| `--json` | One JSON object on stdout. |
|
|
28
41
|
| `--version` | Print the version. |
|
|
29
42
|
|
|
@@ -68,27 +81,89 @@ The verdict is `match`, `withheld`, `UNVERIFIED` or `MISMATCH`. `withheld` means
|
|
|
68
81
|
| `input-hash` | `keccak256` of the record's `request`, serialized canonically (keys sorted, no whitespace), equals `inputHash`. |
|
|
69
82
|
| `kind` | The record's kind is the one on chain. |
|
|
70
83
|
| `subject` | A task decision names `TaskBoard.subjectOf(task)` for this chain and board. A change names its exact call. A grade of outside work is matched by the rules below. |
|
|
71
|
-
| `options` | The probabilities cover exactly the options in the question. |
|
|
84
|
+
| `options` | The probabilities cover exactly the options in the question. A panel that decided without Jev records none of Jev's, and `panel` checks that it names Jev as missing. |
|
|
72
85
|
| `answer` | The record's answer encodes to the one on chain: the hired model's id or worker address, or 1 for accept, pay, adopt and allow and 0 for their opposites. |
|
|
73
86
|
| `confidence` | The record's confidence times 10,000, rounded, equals `confidenceBps`. |
|
|
74
87
|
| `top-option` | For a hire, ruling or change, the answer is Jev's most likely option. |
|
|
75
|
-
| `confidence-recomputed` | The confidence follows from the probabilities. A hire uses `(p - 1/n) / (1 - 1/n)`, within 0.02 because the probabilities are rounded to two decimals. A grade sums the probabilities on the paid levels. A change uses the chosen option's probability, and so does a ruling recorded before rulings were graded twice. A grade or ruling with a `second` or `checks` field follows the two-grader rule: the probability of paying is the lower of Jev's and the second grader's, zero when the brief's checks failed, and the answer and confidence follow it. |
|
|
88
|
+
| `confidence-recomputed` | The confidence follows from the probabilities. A hire uses `(p - 1/n) / (1 - 1/n)`, within 0.02 because the probabilities are rounded to two decimals. A grade sums the probabilities on the paid levels. A change uses the chosen option's probability, and so does a ruling recorded before rulings were graded twice. A grade or ruling with a `second` or `checks` field follows the two-grader rule: the probability of paying is the lower of Jev's and the second grader's, zero when the brief's checks failed, and the answer and confidence follow it. A record with a `panel` field follows the panel's rule instead, as [decided by a panel](#decided-by-a-panel) describes. |
|
|
76
89
|
| `second-grader` | On a decision graded twice: the second grader's probability of paying recomputes from its probabilities, and the receipt id it carries is shown. |
|
|
90
|
+
| `judge` | On a decision by a panel, one line for each judge after the second grader: its probability of paying recomputes from its probabilities, which cover the question's options, and the receipt id it carries is shown. |
|
|
91
|
+
| `panel` | On a decision by a panel: the candidate rules recompute from the judges' probabilities of paying, the record's rule is one of them, and a panel short of a member says which and pays only from 90%. |
|
|
77
92
|
| `brief` | The question quotes the task's brief, fetched from its `Posted` event and checked against `briefHash`. Bytes that miss the hash are a `FAIL`; a host that cannot be read is a `skip`. |
|
|
93
|
+
| `checks` | A brief can carry checks: a fenced block marked `python checks` or `javascript checks`. The record of a grade or ruling on that brief holds BrainChain's run of them after the delivered code, and the line names the run's language and outcome. A run that failed, timed out, found no code in that language or was too long to run makes the answer reject, or refund on a ruling, at 10,000 bps. A run that passed is in the question the graders read, in BrainChain's own wording. A task record with checks in its brief and no run is a `FAIL`. |
|
|
78
94
|
| `levels` | A grade or ruling used the brief's own quality levels and pass level. On a grade of outside work, the pass level is a whole number naming one of the question's levels above the lowest. |
|
|
79
95
|
| `threshold` | The task's threshold, applied as `TaskBoard.hire`, `grade`, `rule` and `ruleAppeal` do, gives the outcome the board emitted. A poster can raise the grade and ruling thresholds while the task is open, so they can be higher than when it was posted; they cannot change after the hire. A ruling on appeal (set 3.5.0 and later) is checked against the board's `AppealRuled` event. A change is queued only on a yes. |
|
|
80
96
|
| `change-subject`, `change-call` | A queued change is the call the decision names and the call Jev was shown. |
|
|
97
|
+
| `evidence` | The record's evidence hash recomputes from the chain's `inputHash` and the record's judges, payments and versions, and equals the hash its `Recorded` event carries in `payloadURI`. |
|
|
98
|
+
| `versions` | The key the record names sent the decision's `Recorded` transaction, and the image and app it names are the ones the DecisionLog attested that key for. |
|
|
99
|
+
| `receipt` | The receipt's EIP-712 signature recovers to the key that sent the decision's `Recorded` transaction. |
|
|
100
|
+
| `receipt-decision` | The receipt names this decision, its DecisionLog, its chain and the record's evidence hash. |
|
|
101
|
+
| `receipt-outcome` | The receipt's outcome is the board's for a task, or the grade bar's for a paid grade. |
|
|
102
|
+
| `receipt-payment` | The receipt's payment is one the record names, and the payment transaction moved its amount from the payer to the desk. |
|
|
81
103
|
|
|
82
104
|
Some checks skip by design:
|
|
83
105
|
|
|
84
106
|
- A decision the board never applied, because a later decision or a closed window settled the task, skips `threshold`.
|
|
85
107
|
- A grade recorded before the chain gated on the paid levels skips `confidence-recomputed`: its confidence is Jev's score confidence, which the probabilities alone do not give.
|
|
108
|
+
- A grade or ruling recorded before BrainChain ran a brief's checks skips `checks` when its brief carries some. Such a record has no `jevPaid`, which every later grade and ruling states unless its panel decided without Jev.
|
|
109
|
+
- A grade of outside work skips `checks` when its brief ends in a checks block and its record holds no run. The section on grades of outside work says why.
|
|
110
|
+
|
|
111
|
+
### Decided by a panel
|
|
112
|
+
|
|
113
|
+
A grade or ruling can be put to a panel: Jev, the second grader and a third judge, each asked the same question from the same state. Its record then has a `panel` field beside `second`. A record from Jev and the second grader under the lower-of rule has no `panel` field and is checked as before.
|
|
114
|
+
|
|
115
|
+
On a record with a panel, the tool checks that:
|
|
116
|
+
|
|
117
|
+
- each judge's probability of paying recomputes from its own probabilities, measured as Jev's is, and matches its `paid`. Jev's matches `jevPaid`.
|
|
118
|
+
- each candidate in `rules` recomputes over the judges that answered. `lower-of` is the lowest probability. `majority` is the lowest within the surest majority, which is the median with three judges. `median` is the middle probability, or the mean of the middle two.
|
|
119
|
+
- `rules` holds exactly `lower-of`, `majority` and `median`, and `rule` names one of them.
|
|
120
|
+
- the answer and confidence follow from that rule's value: accept or pay from 0.5, at the probability of the answer, and reject or refund at 100% when the brief's checks failed.
|
|
121
|
+
- each judge's receipt id is shown, as for the second grader.
|
|
122
|
+
|
|
123
|
+
A panel of three can decide without a member that stopped answering. `panel.degraded` then names the missing member and gives the bar, which must be 0.9: the panel pays only from 90%, and below it the answer is reject or refund. At least two judges must have answered. When the second grader is missing, the record has no `second`. When Jev is missing, the record holds none of Jev's probabilities and no `jevPaid`, and `model` names the version BrainChain asked for, which `degraded.missing` must name too.
|
|
124
|
+
|
|
125
|
+
### Evidence and versions
|
|
126
|
+
|
|
127
|
+
A record made since BrainChain kept evidence has three more fields. `versions` names the version of the questions Jev was asked, the key that recorded the decision, and the enclave image and app the DecisionLog attested that key for. `payments` lists what an agent paid for the job through BrainChain. `evidence` is one hash over what the decision rests on. A record made before has none of the three and is checked as it always was.
|
|
128
|
+
|
|
129
|
+
`evidence` is the `keccak256` of `{ input, judges, payments, versions }` in canonical form. `input` is the decision's `inputHash` on chain, in lowercase. `judges` is Jev's `{ model, probabilities }`, then `second` and each entry of `panel.judges` as `{ model, probabilities, requestHash, receipt }`. `payments` is the record's, or `[]`. None of these parts is withheld with the work, so the hash is rebuilt on a copy served without it too.
|
|
130
|
+
|
|
131
|
+
The chain holds the hash too. A decision's `payloadURI` in its `Recorded` event ends in `#evidence=` and the hash, written in the same transaction as the decision. The rebuilt hash and the record's `evidence` must both equal it, and a `payloadURI` with any other fragment fails. The tool fetches the record without the fragment, as every HTTP client does, so the location names the same file. A decision recorded before the hash went on chain has no fragment, and its rebuilt hash is held to the record's own field.
|
|
132
|
+
|
|
133
|
+
`versions.brain` must be the account that sent the decision's `Recorded` transaction. Only the log's brain can record, so that is the key that recorded it. Its image and app must be the ones in the latest `BrainAttested` event for that key at or before the decision's block. A key the owner named with `setBrain` has no such event, and its records name no image or app. `versions.prompt` is shown. It is the version of the questions on [How Jev is asked](https://docs.usebrainchain.com/how-jev-is-asked), which nothing on chain records.
|
|
134
|
+
|
|
135
|
+
### Receipts
|
|
136
|
+
|
|
137
|
+
Every job an agent pays BrainChain for gets a receipt, signed by the key that records decisions. A paid grade gets one once Jev decides it. A paid task gets one once the board pays or refunds it, for the grade or ruling it settled on. The receipt is EIP-712 under the domain `BrainChain receipt`, version 1, on the DecisionLog, in the envelope of the x402 offer-and-receipt extension (version 0.6): `{ format, payload, signature }`.
|
|
138
|
+
|
|
139
|
+
For each paid grade or ruling, the tool asks the host that serves the record for its receipt at `/receipts/<DecisionLog in lowercase>/<decision id>.json`. A host that has none yet is a `skip`. `--offline` turns this off, and `--receipt` checks a receipt you kept instead.
|
|
140
|
+
|
|
141
|
+
On a receipt, the tool checks that:
|
|
142
|
+
|
|
143
|
+
- the signature recovers to the account that sent the decision's `Recorded` transaction, and `payload.brain` names it. The key comes from the transaction, so a receipt still checks after a release names a new key in `brain()`.
|
|
144
|
+
- `chainId`, `decisionLog`, `decision` and `evidence` are this chain, this DecisionLog, this decision and the record's evidence hash.
|
|
145
|
+
- for a task, the board paid it for `accepted` and refunded it for `rejected`, and the last grade or ruling it applied is this decision. For a paid grade, `accepted` means accept at or above the board's grade bar when the decision was recorded.
|
|
146
|
+
- `network`, `asset`, `amount`, `payer` and `transaction` are those of a payment in the record, and on that network the transaction moved `amount` of `asset` from `payer` to the desk. The desk is the `payTo` for that network in the brain host's `/network.json`, which the tool believes only when `brain()` on the active DecisionLog signed it. A desk's former addresses count on EVM networks.
|
|
147
|
+
|
|
148
|
+
The tool reads payments on Base, Robinhood Chain and Solana, and on their testnets, from their public RPCs. When `/network.json` or the payment's network cannot be read, `receipt-payment` skips and says why.
|
|
149
|
+
|
|
150
|
+
### Keeping a receipt
|
|
151
|
+
|
|
152
|
+
The reply to `POST /x402/grades` carries the receipt in its `receipt` field once the grade is decided. `GET /x402/tasks/<order>` carries it once the task is paid or refunded. Save the reply, or the receipt alone, as JSON:
|
|
153
|
+
|
|
154
|
+
```sh
|
|
155
|
+
npx brainchain-verify mainnet --receipt reply.json
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
The receipt names its decision and its DecisionLog, so the command needs no id, and a receipt on a retired set opens that set. With an id, the receipt is held to that decision. The host serves the same receipt at `https://brain.usebrainchain.com/receipts/<DecisionLog>/<decision id>.json`, at the same address after the contracts change, so a URL works as well as a file.
|
|
159
|
+
|
|
160
|
+
The reply that delivers a paid grade also carries the extension's own receipt in its `PAYMENT-RESPONSE` header, under `extensions["offer-receipt"].info.receipt`, signed by the same key. `--receipt` reads it too. It names no decision, evidence, outcome or amount, so give the decision's id: the tool checks its signer and its network, payer and transaction, and skips `receipt-decision`.
|
|
86
161
|
|
|
87
162
|
### Records served without the work
|
|
88
163
|
|
|
89
164
|
Work stays private until it is accepted, so a grade or ruling on work that was not accepted is served with the work taken out and the header `x-brainchain-withheld: result`. That copy cannot match `payloadHash` or `inputHash`, so `record-hash` and `input-hash` skip and the verdict is `withheld`, never `match`. Exit status stays 0.
|
|
90
165
|
|
|
91
|
-
The header alone proves nothing, so the tool honours it only under the `withheld` check above. The record's answer and confidence are still held to the chain, and for a task so are its brief, levels and threshold.
|
|
166
|
+
The header alone proves nothing, so the tool honours it only under the `withheld` check above. The record's answer and confidence are still held to the chain, and for a task so are its brief, levels and threshold. On a decision whose `payloadURI` carries its evidence hash, every judge's answer, Jev's included, the payments and the versions are held to that hash on chain, so a copy whose judges, payments or versions changed fails `evidence`. The question is the host's word. On an older decision, nothing ties the rest of the copy to the chain: the question, the split of the probabilities behind the confidence, the second grader and any other judge are all the host's word. The chain's rules are the records service's own: a task's work is public once it is paid or graded accepted (a house task's once graded), a paid grade's once accepted, and the delivery in an ACP evaluation never.
|
|
92
167
|
|
|
93
168
|
### Grades of outside work
|
|
94
169
|
|
|
@@ -99,6 +174,66 @@ A grade of work delivered outside BrainChain has no task on the board. The recor
|
|
|
99
174
|
|
|
100
175
|
Its answer and confidence are checked, and the confidence is recomputed from the record's own levels and pass level. Nothing on chain says what those levels should be, so `levels` skips and `threshold` skips: `payloadHash` commits them, but no brief does. The caller who paid for the grade received its verdict directly.
|
|
101
176
|
|
|
177
|
+
A paid grade runs the checks sent with its request. BrainChain appends them to the brief as its last block, and `checks` holds their run to the same rule as a task's. A caller can also write such a block into the brief's own text, where nothing runs it, and the record reads the same either way. So a brief that ends in a checks block with no run is a `skip`. An ACP evaluation runs no checks.
|
|
178
|
+
|
|
179
|
+
## Reputation entries
|
|
180
|
+
|
|
181
|
+
Each task that settles for a registered worker becomes one entry in the ERC-8004 reputation registry on Robinhood Chain (`0x8004BAa17C55a88189AE136b182e5fdA19dE9b63`). The value is 100 when the board paid the bounty and 0 when it refunded it, under the tags `brainchain` and `task`, and the endpoint is the task's page. An entry for a task an agent paid BrainChain for points at the task's signed [receipt](#receipts): `feedbackURI` is where the receipt is served, and `feedbackHash` is the `keccak256` of the receipt as served there. Every other entry names the task page again and carries a zero hash. That covers house tasks, tasks posted straight on the board, ACP orders and entries written before receipts.
|
|
182
|
+
|
|
183
|
+
```sh
|
|
184
|
+
npx brainchain-verify mainnet --entry 20424:7
|
|
185
|
+
npx brainchain-verify mainnet --entry 20424:0xafB0C4Ef895D4895040cdC6435B96D3EE8350c6E:12
|
|
186
|
+
npx brainchain-verify mainnet --agent 20424 --json
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
The registry names an entry by its agent id, the address that wrote it and its index, which counts from 1 for each agent and writer. `--entry` takes the three in that order, separated by colons. BrainChain writes from `0x97D558417c3D61f1074422AD843e1Db1E565b952`, and wrote from `0xafB0C4Ef895D4895040cdC6435B96D3EE8350c6E` before 10 November 2026. Leave the writer out for an entry from the first. Anyone can write under the same tags, so the tool reads entries from these two addresses only.
|
|
190
|
+
|
|
191
|
+
On an entry, the tool checks, in order:
|
|
192
|
+
|
|
193
|
+
| Check | What passes |
|
|
194
|
+
| --- | --- |
|
|
195
|
+
| `entry` | The entry's `NewFeedback` event and the registry's `readFeedback` agree. The tags are `brainchain` and `task`, and the value is 100 or 0 with no decimals. |
|
|
196
|
+
| `endpoint` | The endpoint is a task page naming the task and its board, and the board is in one of the contract sets the tool carries. Entries written before 5 November name the task alone. Task ids restart with each board, so `endpoint` skips on them and the task's checks do not run. |
|
|
197
|
+
| `feedback-hash` | The `keccak256` of the bytes served at `feedbackURI` equals `feedbackHash`. A zero hash is a `skip` that reads `no receipt`. |
|
|
198
|
+
| `entry-receipt` | The receipt is one BrainChain signs. It names a decision its DecisionLog holds, in one of the contract sets the tool carries, and `feedbackURI` is that decision's receipt address. |
|
|
199
|
+
| the decision's checks | The decision the receipt names, checked as any decision is, with this receipt. That covers its record, its evidence hash, and the receipt's signature, outcome and payment. The lines keep their names. |
|
|
200
|
+
| `entry-task` | The decision's subject is `subjectOf(task)` on the board the endpoint names. |
|
|
201
|
+
| `entry-value` | The board paid the task for 100 and refunded it for 0. With a receipt, its outcome is `accepted` for 100 and `rejected` for 0. |
|
|
202
|
+
| `entry-worker` | The board's `WorkerHired` event for the task names the agent. A house worker is hired by the `keccak256` of its model name, so agent 20424 is `keccak256("claude")`. The tool carries the five house agents, 20424 to 20428, as [Worker models](https://docs.usebrainchain.com/workers#erc-8004-identity) lists them. An outside worker is hired by its address, left-padded to 32 bytes. That address must have owned the agent, or been its registered wallet, on the identity registry (`0x8004A169FB4a3325136EB29fA0ceB6D2e539a432`) when the board hired it. |
|
|
203
|
+
|
|
204
|
+
The public RPC for Robinhood Chain keeps no past state, so the tool replays the agent's transfers and wallet changes on the identity registry up to the hire's block time. A transfer clears the wallet, as the registry does.
|
|
205
|
+
|
|
206
|
+
```text
|
|
207
|
+
$ npx brainchain-verify mainnet --entry 20424:7
|
|
208
|
+
Entry 20424:7 in the ERC-8004 reputation registry on Robinhood Chain (0x8004BAa17C55a88189AE136b182e5fdA19dE9b63)
|
|
209
|
+
|
|
210
|
+
ok entry: value 100 for agent 20424 under brainchain and task, written by 0x97D5…b952 in block 114772689, as the registry holds it
|
|
211
|
+
ok endpoint: task 49 on board 0x44b8…A211, contract set v3-5
|
|
212
|
+
skip no receipt: the entry's feedbackHash is zero. Only a task an agent paid BrainChain for has a signed receipt; house tasks, tasks posted straight on the board, ACP orders and older entries have none
|
|
213
|
+
ok value: 100, as the board paid task 49
|
|
214
|
+
ok worker: the board hired claude for task 49 as keccak256("claude"), and agent 20424 is the house worker claude
|
|
215
|
+
|
|
216
|
+
Verdict: no receipt. No signed receipt backs this entry, and the checks the chain allows without one passed.
|
|
217
|
+
Not checked: that Jev produced the answer. See https://docs.usebrainchain.com/trust-model
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
An entry's verdict is `match`, `no receipt`, `withheld`, `MISMATCH` or `UNVERIFIED`. `no receipt` means the hash is zero and every check that could run passed. `withheld` is a decision record served without the work, as for any decision.
|
|
221
|
+
|
|
222
|
+
`--agent` gives one line per entry: its verdict, its name and what it is about. Below an entry go the lines of any check that failed or could not run. The last line counts the entries, those with a receipt, those whose receipt and decision checked out, and those that failed. `--entry` with a name from the list shows every check.
|
|
223
|
+
|
|
224
|
+
```text
|
|
225
|
+
$ npx brainchain-verify mainnet --agent 20425
|
|
226
|
+
Agent 20425 in the ERC-8004 reputation registry on Robinhood Chain (0x8004BAa17C55a88189AE136b182e5fdA19dE9b63): 8 entries BrainChain wrote
|
|
227
|
+
|
|
228
|
+
no receipt 20425:0xafB0C4Ef895D4895040cdC6435B96D3EE8350c6E:1 value 100, task 1
|
|
229
|
+
no receipt 20425:0xafB0C4Ef895D4895040cdC6435B96D3EE8350c6E:4 value 100, task 22 in set v3-5
|
|
230
|
+
no receipt 20425:2 value 100, task 41 in set v3-5
|
|
231
|
+
|
|
232
|
+
8 entries, 0 with a receipt, 0 verified, 0 failed.
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
Trimmed to three entries.
|
|
236
|
+
|
|
102
237
|
## What it cannot check
|
|
103
238
|
|
|
104
239
|
That Jev produced the answer. BrainChain records Jev's answers, and the contracts bound what a recorded answer can do. A decision that passes every check has the question, answer and probabilities the chain acted on. The [trust model](https://docs.usebrainchain.com/trust-model) explains what the chain relies on and what bounds it.
|
|
@@ -108,12 +243,12 @@ That Jev produced the answer. BrainChain records Jev's answers, and the contract
|
|
|
108
243
|
| Code | Meaning |
|
|
109
244
|
| --- | --- |
|
|
110
245
|
| 0 | Every check that could run passed. Skips do not fail a decision. A `withheld` verdict also exits 0, so read the verdict if you need to tell it from a full match. |
|
|
111
|
-
| 1 | A check failed, a record could not be fetched, or the decision could not be read: an unknown id, a task with no decisions, an RPC error. |
|
|
246
|
+
| 1 | A check failed, a record or receipt could not be fetched, or the decision or entry could not be read: an unknown id, a task with no decisions, an entry the registry does not hold, an RPC error, a `--receipt` that cannot be read. |
|
|
112
247
|
| 2 | Bad arguments, or an RPC that serves another chain. |
|
|
113
248
|
|
|
114
249
|
## JSON
|
|
115
250
|
|
|
116
|
-
`--json` prints one object. `decisions` holds one entry, or one per decision with `--task`. `verdict` is `match`, `withheld`, `mismatch` or `unverified` (a record could not be fetched). With `withheld`, `withheldNotChecked` says what was left out, and the decision carries `withheld: true`. A grade of outside work carries `outside: true`. Each check keeps its `name` across releases, and its `status` is `ok`, `fail`, `skip` or `error`. When the tool cannot run, it prints `{ "error": "..." }` and exits 1, or 2 for bad arguments or an RPC that serves another chain. Trimmed to one check:
|
|
251
|
+
`--json` prints one object. `decisions` holds one entry, or one per decision with `--task`. `verdict` is `match`, `withheld`, `mismatch` or `unverified` (a record could not be fetched). With `withheld`, `withheldNotChecked` says what was left out, and the decision carries `withheld: true`. A grade of outside work carries `outside: true`. A grade or ruling that holds a run of its brief's checks carries `run`, with the run's `language` and `outcome`. A grade or ruling decided by a panel carries `panel`: its `rule`, `judges` with each judge that answered by `model` and `paid`, Jev first, and `degraded`. A degraded panel also carries `missing` and `bar`. These are the record's own values, and the `judge` and `panel` checks say whether they recompute. A decision whose record matched the evidence hash on chain carries it as `evidence`. A decision whose receipt was checked carries `receipt`: where it was read as `from`, and the `job` and `outcome` it states. Each check keeps its `name` across releases, and its `status` is `ok`, `fail`, `skip` or `error`. When the tool cannot run, it prints `{ "error": "..." }` and exits 1, or 2 for bad arguments or an RPC that serves another chain. Trimmed to one check:
|
|
117
252
|
|
|
118
253
|
```json
|
|
119
254
|
{
|
|
@@ -151,6 +286,8 @@ That Jev produced the answer. BrainChain records Jev's answers, and the contract
|
|
|
151
286
|
}
|
|
152
287
|
```
|
|
153
288
|
|
|
289
|
+
With `--entry` or `--agent`, the object holds `registry`, `verdict`, `summary` and `entries` instead of `set` and `decisions`, and `agentId` with `--agent`. `verdict` is `match`, `no-receipt`, `withheld`, `mismatch` or `unverified`. It is `no-receipt` only when every check passed and no entry had a receipt. `summary` counts `entries`, `withReceipt`, `verified`, `failed` and `unverified`. Each entry carries its name as `entry`, the fields of its `NewFeedback` event, the `task`, `board` and `set` its endpoint names, the `decision` its receipt names with its `id`, `set` and `kind`, its own `verdict` and its `checks`.
|
|
290
|
+
|
|
154
291
|
## Building
|
|
155
292
|
|
|
156
293
|
```sh
|
package/dist/cli.js
CHANGED
|
@@ -3,27 +3,41 @@ import { createRequire } from "node:module";
|
|
|
3
3
|
import { createPublicClient, http, isAddress } from "viem";
|
|
4
4
|
import { decisionLogAbi, taskBoardAbi } from "./abi.js";
|
|
5
5
|
import { NETWORKS } from "./deployments.js";
|
|
6
|
-
import { clean, decisionsOf, errorMessage, outcomeOf, verifyDecision, withheldNotChecked } from "./verify.js";
|
|
6
|
+
import { clean, decisionsOf, entriesOf, entryName, entryOutcome, errorMessage, outcomeOf, readReceipt, receiptDecision, REPUTATION, verifyDecision, verifyEntry, withheldNotChecked, } from "./verify.js";
|
|
7
7
|
const USAGE = `Usage:
|
|
8
|
-
brainchain-verify <mainnet|testnet|chainId> <decisionId> [--set <TaskBoard>] [--rpc <url>] [--json]
|
|
9
|
-
brainchain-verify <mainnet|testnet|chainId> --task <taskId> [--set <TaskBoard>] [--rpc <url>] [--json]
|
|
8
|
+
brainchain-verify <mainnet|testnet|chainId> <decisionId> [--set <TaskBoard>] [--rpc <url>] [--offline] [--json]
|
|
9
|
+
brainchain-verify <mainnet|testnet|chainId> --task <taskId> [--set <TaskBoard>] [--rpc <url>] [--offline] [--json]
|
|
10
|
+
brainchain-verify <mainnet|testnet|chainId> [<decisionId>] --receipt <file|url> [--set <TaskBoard>] [--rpc <url>] [--json]
|
|
11
|
+
brainchain-verify mainnet --entry <agentId>:[<writer>:]<feedbackIndex> [--rpc <url>] [--registry-rpc <url>] [--json]
|
|
12
|
+
brainchain-verify mainnet --agent <agentId> [--rpc <url>] [--registry-rpc <url>] [--json]
|
|
10
13
|
|
|
11
14
|
Checks a BrainChain decision against the chain: reads it from the DecisionLog,
|
|
12
15
|
fetches the published record, recomputes its hashes and confidence, and applies
|
|
13
16
|
the task's thresholds as the contracts do. Needs no keys.
|
|
14
17
|
|
|
15
18
|
--task <id> check every decision about one task
|
|
19
|
+
--receipt <r> check the receipt for a paid job, from a file or a URL, against
|
|
20
|
+
the decision it names, or the one given
|
|
21
|
+
--entry <e> check one ERC-8004 reputation entry BrainChain wrote: the entry,
|
|
22
|
+
its receipt, the decision and payment the receipt names, and the
|
|
23
|
+
task, value and worker on the board. The writer is needed only
|
|
24
|
+
for an entry from an address BrainChain no longer writes from
|
|
25
|
+
--agent <id> check every entry BrainChain wrote for one agent
|
|
26
|
+
--offline fetch no receipt from the brain host
|
|
16
27
|
--set <board> a retired contract set from 3.0.0 on, by TaskBoard address, by
|
|
17
28
|
its key on the site (v3-1) or by release (3.1.0); without it, the
|
|
18
29
|
active set
|
|
19
30
|
--rpc <url> another RPC for the same chain; records and briefs on private
|
|
20
31
|
addresses are read only when this is on one too
|
|
32
|
+
--registry-rpc <url>
|
|
33
|
+
another RPC for Robinhood Chain, where the registries are
|
|
21
34
|
--json one JSON object on stdout
|
|
22
35
|
--version print the version
|
|
23
36
|
|
|
24
37
|
Exit status: 0 when every check that could run matches, 1 on a mismatch or when
|
|
25
38
|
a decision or its record cannot be read, 2 on bad arguments.`;
|
|
26
39
|
const TRUST_MODEL = "https://docs.usebrainchain.com/trust-model";
|
|
40
|
+
const NOT_CHECKED = "That Jev produced the answer. BrainChain records Jev's answers, and the contracts bound what a recorded answer can do.";
|
|
27
41
|
// Sets before 3.0.0 named tasks by id alone, which the subject check does not model, so the package carries none.
|
|
28
42
|
const BEFORE_3 = /^(v2(-|$)|2\.|0x83b31d99fa31a9e5257955a737ef34c40f1c57bf$)/i;
|
|
29
43
|
function usage(message) {
|
|
@@ -51,27 +65,49 @@ const flag = (name) => {
|
|
|
51
65
|
args.splice(at, 2);
|
|
52
66
|
return value;
|
|
53
67
|
};
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
68
|
+
const toggle = (name) => {
|
|
69
|
+
const at = args.indexOf(name);
|
|
70
|
+
if (at >= 0)
|
|
71
|
+
args.splice(at, 1);
|
|
72
|
+
return at >= 0;
|
|
73
|
+
};
|
|
74
|
+
const json = toggle("--json");
|
|
75
|
+
const offline = toggle("--offline");
|
|
57
76
|
const taskArg = flag("--task");
|
|
58
77
|
const setArg = flag("--set");
|
|
59
78
|
const rpcArg = flag("--rpc");
|
|
79
|
+
const receiptArg = flag("--receipt");
|
|
80
|
+
const entryArg = flag("--entry");
|
|
81
|
+
const agentArg = flag("--agent");
|
|
82
|
+
const registryRpcArg = flag("--registry-rpc");
|
|
60
83
|
// -1 is a bad id, not an option; the id check below says so.
|
|
61
84
|
const unknown = args.find((arg) => arg.startsWith("-") && !/^-\d/.test(arg));
|
|
62
85
|
if (unknown)
|
|
63
86
|
usage(`Unknown option ${unknown}`);
|
|
64
|
-
|
|
87
|
+
const web = (url) => URL.canParse(url) && ["http:", "https:"].includes(new URL(url).protocol);
|
|
88
|
+
if (rpcArg !== undefined && !web(rpcArg))
|
|
65
89
|
usage("--rpc needs an http or https URL");
|
|
90
|
+
if (registryRpcArg !== undefined && !web(registryRpcArg))
|
|
91
|
+
usage("--registry-rpc needs an http or https URL");
|
|
66
92
|
const [networkArg, idArg, ...extra] = args;
|
|
67
93
|
if (networkArg === undefined)
|
|
68
94
|
usage("Name a network: mainnet, testnet or a chain id");
|
|
69
95
|
if (extra.length > 0 || (taskArg !== undefined && idArg !== undefined))
|
|
70
96
|
usage("Too many arguments");
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if (
|
|
97
|
+
if (taskArg !== undefined && receiptArg !== undefined)
|
|
98
|
+
usage("A receipt is for one decision: name it, not a task");
|
|
99
|
+
const reputation = entryArg !== undefined || agentArg !== undefined;
|
|
100
|
+
if (reputation && (idArg !== undefined || taskArg !== undefined || receiptArg !== undefined || setArg !== undefined || offline)) {
|
|
101
|
+
usage("An entry names its own task, decision and receipt, so --entry and --agent take only --rpc, --registry-rpc and --json");
|
|
102
|
+
}
|
|
103
|
+
if (!reputation && registryRpcArg !== undefined)
|
|
104
|
+
usage("--registry-rpc is for --entry and --agent");
|
|
105
|
+
if (entryArg !== undefined && agentArg !== undefined)
|
|
106
|
+
usage("Name one entry with --entry, or an agent with --agent");
|
|
107
|
+
if (!reputation && taskArg === undefined && idArg === undefined && receiptArg === undefined)
|
|
108
|
+
usage("Name a decision id, a task with --task, or an entry with --entry");
|
|
109
|
+
const given = taskArg ?? idArg;
|
|
110
|
+
if (given !== undefined && !/^[1-9]\d*$/.test(given))
|
|
75
111
|
usage(`${taskArg === undefined ? "A decision" : "A task"} id is a whole number from 1`);
|
|
76
112
|
const foundNetwork = Object.hasOwn(NETWORKS, networkArg)
|
|
77
113
|
? NETWORKS[networkArg]
|
|
@@ -79,8 +115,21 @@ const foundNetwork = Object.hasOwn(NETWORKS, networkArg)
|
|
|
79
115
|
if (!foundNetwork)
|
|
80
116
|
usage(`Unknown network "${networkArg}": use mainnet, testnet, 274663 or 274630`);
|
|
81
117
|
const network = foundNetwork;
|
|
118
|
+
const client = createPublicClient({ transport: http(rpcArg ?? network.rpc) });
|
|
119
|
+
const TAGS = { ok: "ok", fail: "FAIL", skip: "skip", error: "ERROR" };
|
|
120
|
+
const tally = (checks, status) => checks.filter((c) => c.status === status).length;
|
|
121
|
+
const ENTRY_TAGS = { match: "match", "no-receipt": "no receipt", withheld: "withheld", mismatch: "MISMATCH", unverified: "UNVERIFIED" };
|
|
122
|
+
if (reputation)
|
|
123
|
+
await checkEntries();
|
|
124
|
+
const receipt = receiptArg === undefined ? undefined : await readReceipt(client, receiptArg).catch((error) => fail(errorMessage(error)));
|
|
125
|
+
const named = receipt && receiptDecision(receipt.value);
|
|
126
|
+
const target = given ?? named?.decision;
|
|
127
|
+
if (target === undefined || !/^[1-9]\d*$/.test(target))
|
|
128
|
+
usage("The receipt names no decision; give the decision's id");
|
|
129
|
+
// A receipt names its log, so it opens a retired set on its own.
|
|
130
|
+
const receiptSet = named && network.sets.find((s) => s.log.toLowerCase() === named.decisionLog.toLowerCase());
|
|
82
131
|
const foundSet = setArg === undefined
|
|
83
|
-
? network.sets[0]
|
|
132
|
+
? (receiptSet ?? network.sets[0])
|
|
84
133
|
: network.sets.find((s) => (isAddress(setArg) ? s.board.toLowerCase() === setArg.toLowerCase() : s.key === setArg || s.release === setArg || s.aliases?.includes(setArg)));
|
|
85
134
|
if (!foundSet) {
|
|
86
135
|
if (setArg !== undefined && BEFORE_3.test(setArg))
|
|
@@ -89,12 +138,7 @@ if (!foundSet) {
|
|
|
89
138
|
usage(`No contract set ${setArg} on ${network.name}. Sets: ${sets.join(", ")}`);
|
|
90
139
|
}
|
|
91
140
|
const set = foundSet;
|
|
92
|
-
const ctx = {
|
|
93
|
-
client: createPublicClient({ transport: http(rpcArg ?? network.rpc) }),
|
|
94
|
-
network,
|
|
95
|
-
set,
|
|
96
|
-
briefs: new Map(),
|
|
97
|
-
};
|
|
141
|
+
const ctx = { client, network, set, briefs: new Map(), offline };
|
|
98
142
|
function fail(message, status = 1) {
|
|
99
143
|
if (json)
|
|
100
144
|
console.log(JSON.stringify({ error: clean(message) }, null, 2));
|
|
@@ -102,8 +146,6 @@ function fail(message, status = 1) {
|
|
|
102
146
|
console.error(clean(message));
|
|
103
147
|
process.exit(status);
|
|
104
148
|
}
|
|
105
|
-
const TAGS = { ok: "ok", fail: "FAIL", skip: "skip", error: "ERROR" };
|
|
106
|
-
const tally = (checks, status) => checks.filter((c) => c.status === status).length;
|
|
107
149
|
function verdict(reports) {
|
|
108
150
|
const all = reports.flatMap((r) => r.checks);
|
|
109
151
|
const failed = tally(all, "fail");
|
|
@@ -136,6 +178,10 @@ function report(reports, header, task) {
|
|
|
136
178
|
task: r.task,
|
|
137
179
|
...(r.outside ? { outside: true } : {}),
|
|
138
180
|
...(r.withheld ? { withheld: true } : {}),
|
|
181
|
+
...(r.run ? { run: r.run } : {}),
|
|
182
|
+
...(r.panel ? { panel: r.panel } : {}),
|
|
183
|
+
...(r.evidence ? { evidence: r.evidence } : {}),
|
|
184
|
+
...(r.receipt ? { receipt: r.receipt } : {}),
|
|
139
185
|
block: r.block,
|
|
140
186
|
recordedAt: r.recordedAt,
|
|
141
187
|
confidenceBps: r.confidenceBps,
|
|
@@ -154,7 +200,7 @@ function report(reports, header, task) {
|
|
|
154
200
|
skipped,
|
|
155
201
|
decisions,
|
|
156
202
|
...(overall === "withheld" ? { withheldNotChecked: withheldNotChecked(reports) } : {}),
|
|
157
|
-
notChecked:
|
|
203
|
+
notChecked: NOT_CHECKED,
|
|
158
204
|
trustModel: TRUST_MODEL,
|
|
159
205
|
};
|
|
160
206
|
console.log(JSON.stringify(out, null, 2));
|
|
@@ -170,10 +216,141 @@ function report(reports, header, task) {
|
|
|
170
216
|
console.log(`Not checked: that Jev produced the answer. See ${TRUST_MODEL}`);
|
|
171
217
|
process.exit(failed + errors > 0 ? 1 : 0);
|
|
172
218
|
}
|
|
173
|
-
|
|
174
|
-
const chainId = await
|
|
219
|
+
async function sameChain(registry) {
|
|
220
|
+
const chainId = await client.getChainId();
|
|
175
221
|
if (chainId !== network.chainId)
|
|
176
222
|
usage(`The RPC serves chain ${chainId}, not ${network.name} (${network.chainId})`);
|
|
223
|
+
const registryChain = await registry?.client.getChainId();
|
|
224
|
+
if (registry && registryChain !== registry.chainId)
|
|
225
|
+
usage(`The registry RPC serves chain ${registryChain}, not Robinhood Chain (${registry.chainId})`);
|
|
226
|
+
}
|
|
227
|
+
function entryVerdict(r) {
|
|
228
|
+
const failed = tally(r.checks, "fail");
|
|
229
|
+
switch (entryOutcome([r])) {
|
|
230
|
+
case "mismatch":
|
|
231
|
+
return `Verdict: MISMATCH. ${failed} check${failed === 1 ? "" : "s"} failed; see the FAIL lines.`;
|
|
232
|
+
case "unverified":
|
|
233
|
+
return "Verdict: UNVERIFIED. The receipt or the record behind it could not be fetched, so the checks that need it did not run; see the ERROR lines.";
|
|
234
|
+
case "withheld":
|
|
235
|
+
return `Verdict: withheld, not a full match. ${withheldNotChecked([r.decision])}`;
|
|
236
|
+
case "no-receipt":
|
|
237
|
+
return "Verdict: no receipt. No signed receipt backs this entry, and the checks the chain allows without one passed.";
|
|
238
|
+
case "match":
|
|
239
|
+
if (tally(r.checks, "skip") > 0)
|
|
240
|
+
return "Verdict: match. Every check that could run passed; the skip lines say what could not be checked.";
|
|
241
|
+
return "Verdict: match. The entry, its receipt, the decision and payment the receipt names, and the task on the board agree with the chain.";
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
/** What an entry is about, on its line in an agent's list. */
|
|
245
|
+
function about(r) {
|
|
246
|
+
const task = r.task === undefined ? `endpoint ${r.endpoint}` : `task ${r.task}${r.set ? ` in set ${r.set}` : r.board ? ` on board ${r.board}` : ""}`;
|
|
247
|
+
return `value ${r.value}, ${task}${r.decision ? `, decision ${r.decision.id}` : ""}`;
|
|
248
|
+
}
|
|
249
|
+
function reportEntries(reports, header, agentId) {
|
|
250
|
+
const outcomes = reports.map((r) => entryOutcome([r]));
|
|
251
|
+
const receipted = reports.filter((r) => BigInt(r.feedbackHash) !== 0n);
|
|
252
|
+
const summary = {
|
|
253
|
+
entries: reports.length,
|
|
254
|
+
withReceipt: receipted.length,
|
|
255
|
+
verified: receipted.filter((r) => ["match", "withheld"].includes(entryOutcome([r]))).length,
|
|
256
|
+
failed: outcomes.filter((o) => o === "mismatch").length,
|
|
257
|
+
unverified: outcomes.filter((o) => o === "unverified").length,
|
|
258
|
+
};
|
|
259
|
+
const all = reports.flatMap((r) => r.checks);
|
|
260
|
+
const status = tally(all, "fail") + tally(all, "error") > 0 ? 1 : 0;
|
|
261
|
+
if (json) {
|
|
262
|
+
const entries = reports.map(({ checks, decision, ...r }, i) => ({
|
|
263
|
+
...r,
|
|
264
|
+
...(decision ? { decision: { id: decision.id, set: decision.set, kind: decision.kind, ...(decision.task === undefined ? {} : { task: decision.task }) } } : {}),
|
|
265
|
+
verdict: outcomes[i],
|
|
266
|
+
checks,
|
|
267
|
+
}));
|
|
268
|
+
const out = {
|
|
269
|
+
network: network.name,
|
|
270
|
+
chainId: network.chainId,
|
|
271
|
+
registry: { chainId: REPUTATION.chainId, address: REPUTATION.address, writers: REPUTATION.writers },
|
|
272
|
+
...(agentId === undefined ? {} : { agentId }),
|
|
273
|
+
verdict: entryOutcome(reports),
|
|
274
|
+
summary,
|
|
275
|
+
entries,
|
|
276
|
+
notChecked: NOT_CHECKED,
|
|
277
|
+
trustModel: TRUST_MODEL,
|
|
278
|
+
};
|
|
279
|
+
console.log(JSON.stringify(out, null, 2));
|
|
280
|
+
process.exit(status);
|
|
281
|
+
}
|
|
282
|
+
console.log(`${header}\n`);
|
|
283
|
+
const [one] = reports;
|
|
284
|
+
if (agentId === undefined && one) {
|
|
285
|
+
for (const c of one.checks)
|
|
286
|
+
console.log(` ${TAGS[c.status].padEnd(5)} ${c.message}`);
|
|
287
|
+
console.log(`\n${entryVerdict(one)}`);
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
for (const [i, r] of reports.entries()) {
|
|
291
|
+
console.log(` ${ENTRY_TAGS[outcomes[i]].padEnd(10)} ${r.entry} ${about(r)}`);
|
|
292
|
+
for (const c of r.checks)
|
|
293
|
+
if (c.status === "fail" || c.status === "error")
|
|
294
|
+
console.log(` ${TAGS[c.status].padEnd(5)} ${c.message}`);
|
|
295
|
+
}
|
|
296
|
+
const { entries, withReceipt, verified, failed, unverified } = summary;
|
|
297
|
+
console.log(`\n${entries} entr${entries === 1 ? "y" : "ies"}, ${withReceipt} with a receipt, ${verified} verified, ${failed} failed${unverified > 0 ? `, ${unverified} could not be checked` : ""}.`);
|
|
298
|
+
}
|
|
299
|
+
console.log(`Not checked: that Jev produced the answer. See ${TRUST_MODEL}`);
|
|
300
|
+
process.exit(status);
|
|
301
|
+
}
|
|
302
|
+
/** --entry and --agent: BrainChain's entries in the ERC-8004 reputation registry, each checked through its receipt to the chain. */
|
|
303
|
+
async function checkEntries() {
|
|
304
|
+
if (network.chainId !== REPUTATION.network)
|
|
305
|
+
usage("BrainChain writes reputation entries for mainnet tasks only, so --entry and --agent read mainnet");
|
|
306
|
+
const registry = { ...REPUTATION, client: createPublicClient({ transport: http(registryRpcArg ?? REPUTATION.rpc) }) };
|
|
307
|
+
const [current, ...earlier] = registry.writers;
|
|
308
|
+
const where = `in the ERC-8004 reputation registry on Robinhood Chain (${registry.address})`;
|
|
309
|
+
const ctx = { client, network, set: network.sets[0], briefs: new Map() };
|
|
310
|
+
if (entryArg !== undefined) {
|
|
311
|
+
const parts = /^(0|[1-9]\d{0,77}):(?:(0x[0-9a-fA-F]{40}):)?([1-9]\d{0,19})$/.exec(entryArg);
|
|
312
|
+
if (!parts)
|
|
313
|
+
usage("An entry is <agentId>:<feedbackIndex>, or <agentId>:<writer>:<feedbackIndex> for one BrainChain wrote from an earlier address");
|
|
314
|
+
const named = parts[2];
|
|
315
|
+
const writer = named === undefined ? current : registry.writers.find((w) => w.toLowerCase() === named.toLowerCase());
|
|
316
|
+
if (!writer)
|
|
317
|
+
usage(`BrainChain writes its entries from ${registry.writers.join(" and ")}, not ${named}`);
|
|
318
|
+
const agentId = BigInt(parts[1]);
|
|
319
|
+
const index = BigInt(parts[3]);
|
|
320
|
+
try {
|
|
321
|
+
await sameChain(registry);
|
|
322
|
+
const found = await entriesOf(registry, agentId, [writer]);
|
|
323
|
+
const entry = found.find((f) => f.feedbackIndex === index);
|
|
324
|
+
if (!entry) {
|
|
325
|
+
const held = found.length === 0 ? `has written no entry for agent ${agentId}` : `wrote entries 1 to ${found.at(-1).feedbackIndex} for agent ${agentId}`;
|
|
326
|
+
const hint = named === undefined && earlier.length > 0 ? `. It wrote earlier ones from ${earlier.join(" and ")}: name one as ${agentId}:<writer>:<feedbackIndex>` : "";
|
|
327
|
+
fail(`BrainChain ${held} from ${writer}${hint}`);
|
|
328
|
+
}
|
|
329
|
+
reportEntries([await verifyEntry(ctx, registry, entry)], `Entry ${entryName(registry, entry)} ${where}`);
|
|
330
|
+
}
|
|
331
|
+
catch (error) {
|
|
332
|
+
fail(errorMessage(error));
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
if (!/^(0|[1-9]\d{0,77})$/.test(agentArg))
|
|
336
|
+
usage("An agent id is a whole number");
|
|
337
|
+
const agentId = BigInt(agentArg);
|
|
338
|
+
try {
|
|
339
|
+
await sameChain(registry);
|
|
340
|
+
const found = await entriesOf(registry, agentId);
|
|
341
|
+
if (found.length === 0)
|
|
342
|
+
fail(`BrainChain has written no entry for agent ${agentId} ${where}`);
|
|
343
|
+
const reports = [];
|
|
344
|
+
for (const f of found)
|
|
345
|
+
reports.push(await verifyEntry(ctx, registry, f));
|
|
346
|
+
reportEntries(reports, `Agent ${agentId} ${where}: ${found.length} entr${found.length === 1 ? "y" : "ies"} BrainChain wrote`, agentId.toString());
|
|
347
|
+
}
|
|
348
|
+
catch (error) {
|
|
349
|
+
fail(errorMessage(error));
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
try {
|
|
353
|
+
await sameChain();
|
|
177
354
|
const where = `on ${network.name}, contract set ${set.key}`;
|
|
178
355
|
if (taskArg !== undefined) {
|
|
179
356
|
const task = BigInt(taskArg);
|
|
@@ -195,7 +372,7 @@ try {
|
|
|
195
372
|
const hint = others.length > 0 ? ` Each set numbers its own decisions; try --set ${others.join(" or ")}.` : "";
|
|
196
373
|
fail(`DecisionLog ${set.log} (set ${set.key}) holds decisions 1 to ${decisions}.${hint}`);
|
|
197
374
|
}
|
|
198
|
-
report([await verifyDecision(ctx, id)], `Decision ${id} ${where} (DecisionLog ${set.log})`);
|
|
375
|
+
report([await verifyDecision(ctx, id, receipt)], `Decision ${id} ${where} (DecisionLog ${set.log})`);
|
|
199
376
|
}
|
|
200
377
|
catch (error) {
|
|
201
378
|
fail(errorMessage(error));
|