agent-receipt-verify 0.2.2 → 0.2.4

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.
Files changed (35) hide show
  1. package/README.md +38 -3
  2. package/bin/cli.mjs +16 -0
  3. package/package.json +6 -3
  4. package/src/settlement-link-vectors.mjs +241 -0
  5. package/src/verify-delivery.mjs +507 -0
  6. package/src/x402-discovery-census.mjs +24 -1
  7. package/src/x402-offer-receipt.mjs +49 -3
  8. package/tools/bouw-afrekening-vectoren.mjs +273 -0
  9. package/tools/naar-kanon-vorm.mjs +172 -0
  10. package/tools/pack-inhoud.mjs +45 -1
  11. package/vectors/settlement-link/find-candidates-onchain.json +44 -0
  12. package/vectors/settlement-link/no-candidates-not-measured.json +41 -0
  13. package/vectors/settlement-link/opens-live-2.json +48 -0
  14. package/vectors/settlement-link/opens-live-3.json +48 -0
  15. package/vectors/settlement-link/opens-live.json +48 -0
  16. package/vectors/settlement-link/two-identical-payments.json +86 -0
  17. package/vectors/settlement-link/wrong-nonce-live-2.json +46 -0
  18. package/vectors/settlement-link/wrong-nonce-live-3.json +46 -0
  19. package/vectors/settlement-link/wrong-nonce-live.json +46 -0
  20. package/vectors/settlement-link/wrong-salt-live-2.json +46 -0
  21. package/vectors/settlement-link/wrong-salt-live-3.json +46 -0
  22. package/vectors/settlement-link/wrong-salt-live.json +46 -0
  23. package/vectors/settlement-link-kanon/README.md +69 -0
  24. package/vectors/settlement-link-kanon/find-candidates-onchain.json +43 -0
  25. package/vectors/settlement-link-kanon/no-candidates-not-measured.json +42 -0
  26. package/vectors/settlement-link-kanon/opens-live-2.json +47 -0
  27. package/vectors/settlement-link-kanon/opens-live-3.json +47 -0
  28. package/vectors/settlement-link-kanon/opens-live.json +47 -0
  29. package/vectors/settlement-link-kanon/two-identical-payments.json +76 -0
  30. package/vectors/settlement-link-kanon/wrong-nonce-live-2.json +46 -0
  31. package/vectors/settlement-link-kanon/wrong-nonce-live-3.json +46 -0
  32. package/vectors/settlement-link-kanon/wrong-nonce-live.json +46 -0
  33. package/vectors/settlement-link-kanon/wrong-salt-live-2.json +46 -0
  34. package/vectors/settlement-link-kanon/wrong-salt-live-3.json +46 -0
  35. package/vectors/settlement-link-kanon/wrong-salt-live.json +46 -0
@@ -0,0 +1,273 @@
1
+ #!/usr/bin/env node
2
+ // Bouwt testvectoren voor de helft NA het betalen: hoort dit bonnetje bij die ene
3
+ // afrekening?
4
+ //
5
+ // WAAROM DEZE ER ZIJN. De gepubliceerde vectoren van iamonuwa/kanon dekken de
6
+ // AUTORISATIE van een koper voor de afrekening. Niemand heeft vectoren gepubliceerd
7
+ // voor de stap erna. In x402#3396 zei de auteur van die vectoren op 2026-10-17
8
+ // letterlijk: "if you want receipt-to-settlement vectors in Kanon's shape, I'm open to
9
+ // that, with the part that needs a chain read marked as such." Dit bestand maakt
10
+ // precies dat, in zijn vorm, met dat veld.
11
+ //
12
+ // DE SPLITSING DIE HIJ VROEG, en die is inhoudelijk het hele punt. Een bonnetje aan een
13
+ // afrekening binden bestaat uit twee stappen met heel verschillende eisen:
14
+ //
15
+ // 1. VIND de kandidaat-nonces die deze betaler in dit venster verbruikte.
16
+ // Dat vereist een ketenlezing. Niet reproduceerbaar zonder RPC, en de uitkomst
17
+ // hangt af van hoe ver je terugkijkt.
18
+ // 2. OPEN het commitment op precies een van die kandidaten.
19
+ // Dat is pure rekenkunde: sha256 over tag, methode, asset, autorisator,
20
+ // identifier en zout. Offline, deterministisch, en voor altijd reproduceerbaar.
21
+ //
22
+ // Stap 2 is waar de spec iets beweert, en stap 2 heeft GEEN keten nodig zodra je de
23
+ // kandidaten meegeeft. Daarom draagt elke vector hier `requires_chain_read`, en zijn de
24
+ // offline vectoren degene waar een vreemde iets aan heeft.
25
+ //
26
+ // ALLE DATA IS ECHT. De bonnetjes komen uit echte betalingen op Base Sepolia aan
27
+ // https://api.tokenizen.nl/api/paid/verify-ownership. De nonces en transactiehashes
28
+ // zijn door onze eigen linker op de keten gevonden. Koper en verkoper zijn allebei wij,
29
+ // dus dit bewijst dat de keten sluit, niet dat iemand anders hem gebruikt.
30
+ //
31
+ // DEZE GENERATOR WEIGERT TE LIEGEN. Voor elke positieve vector wordt het commitment
32
+ // opnieuw berekend uit de losse velden en vergeleken met wat in het ondertekende
33
+ // bonnetje staat. Klopt dat niet, dan schrijft hij niets en faalt hij luid. Een
34
+ // vectorbestand dat zichzelf niet opent is erger dan geen vectorbestand, want iedereen
35
+ // die het gebruikt bouwt op een fout.
36
+ //
37
+ // Gebruik: node tools/bouw-afrekening-vectoren.mjs [--droog]
38
+
39
+ import fs from 'node:fs'
40
+ import path from 'node:path'
41
+ import { fileURLToPath } from 'node:url'
42
+ import { berekenCommitment } from '../src/x402-offer-receipt.mjs'
43
+
44
+ const WORTEL = fileURLToPath(new URL('..', import.meta.url))
45
+ const UIT = path.join(WORTEL, 'vectors', 'settlement-link')
46
+
47
+ // De drie echte betalingen, met de afrekening die onze linker op de keten vond.
48
+ // De nonce staat hier NIET omdat wij hem kozen, maar omdat hij gevonden is; de
49
+ // controle hieronder bewijst dat hij bij dit bonnetje hoort.
50
+ const ECHT = [
51
+ {
52
+ bestand: 'receipt-live-base-sepolia.json',
53
+ nonce: '0x1120412c78ea1b2e8bf9eacfc3264c71a23ecd9b1fa579eb16030693344d5dfe',
54
+ tx: '0xed87b09bfb20a8c8b69908e163fcea6432d193d389640c0465afcb5561dfeb30',
55
+ kandidaten: 2,
56
+ },
57
+ {
58
+ bestand: 'receipt-live-base-sepolia-2.json',
59
+ nonce: '0x515895dfac6f148a4cfdf5c4f8266b7859dbd6534cdf77104b1be9f484eb5005',
60
+ tx: '0x2898d0ceb97ddf60af98e19c94fc0adddbdf1e64f9032e62454085e37acfe36b',
61
+ kandidaten: 3,
62
+ },
63
+ {
64
+ bestand: 'receipt-live-base-sepolia-3.json',
65
+ nonce: '0x4b133bbec3ce0d8177a9010784faedb459f04384b45316bb526a5f96c90a70de',
66
+ tx: '0x2a9e95d63a5af8210767baa69143b364dad51caffc29a152c77e03bc508d7199',
67
+ kandidaten: 2,
68
+ },
69
+ ]
70
+
71
+ const lees = (b) => JSON.parse(fs.readFileSync(path.join(WORTEL, 'examples', b), 'utf8'))
72
+
73
+ function basis(id, beschrijving, encodes) {
74
+ return {
75
+ id,
76
+ schema_version: '3.0.0',
77
+ protocol: 'x402',
78
+ scheme: 'exact',
79
+ network: 'eip155:84532',
80
+ asset_transfer_method: 'eip3009',
81
+ encodes,
82
+ provenance: [
83
+ 'x402 offer-receipt extension section 5.6.4, as proposed in pull request 3827 at commit 0e492d6 and not on main',
84
+ 'EIP-3009',
85
+ ],
86
+ description: beschrijving,
87
+ }
88
+ }
89
+
90
+ const vectoren = []
91
+ const fouten = []
92
+
93
+ for (const e of ECHT) {
94
+ const bron = lees(e.bestand)
95
+ const p = bron.receipt.payload
96
+ const betaler = p.payer
97
+
98
+ // DE CONTROLE DIE DEZE GENERATOR EERLIJK HOUDT. Herbereken het commitment uit de
99
+ // losse velden. Opent het niet op de nonce die wij hier opschrijven, dan is onze
100
+ // toewijzing fout en mag er niets geschreven worden.
101
+ const herberekend = berekenCommitment({
102
+ method: 'eip3009',
103
+ asset: bron.asset,
104
+ authorizer: betaler,
105
+ identifier: e.nonce,
106
+ salt: bron.authorizationSalt,
107
+ })
108
+ if (String(herberekend).toLowerCase() !== String(p.authorizationCommitment).toLowerCase()) {
109
+ fouten.push(`${e.bestand}: het commitment opent NIET op de opgegeven nonce. ` +
110
+ `berekend ${herberekend}, in het bonnetje ${p.authorizationCommitment}`)
111
+ continue
112
+ }
113
+
114
+ const kort = e.bestand.replace('receipt-live-base-sepolia', 'live').replace('.json', '')
115
+
116
+ // 1. De offline positieve: de kandidaten zijn MEEGEGEVEN, dus geen keten nodig.
117
+ vectoren.push({
118
+ ...basis(
119
+ `x402-evm-settlement-link-opens-${kort}`,
120
+ 'A version 2 receipt whose authorizationCommitment opens on exactly one of the candidate nonces supplied with it. No chain access is needed because the candidates are given; this is the arithmetic half of section 5.6.4.',
121
+ 'Receipt-to-settlement binding verified offline against a supplied candidate set.',
122
+ ),
123
+ requires_chain_read: false,
124
+ input: {
125
+ receipt: bron.receipt,
126
+ authorizationSalt: bron.authorizationSalt,
127
+ asset: bron.asset,
128
+ candidates: [{ authorizer: betaler, nonce: e.nonce }],
129
+ },
130
+ context: {
131
+ note: 'Real payment on Base Sepolia to https://api.tokenizen.nl/api/paid/verify-ownership. Buyer and seller are the same party, which proves the chain closes end to end and nothing about adoption.',
132
+ settlement_transaction: e.tx,
133
+ },
134
+ expected: { linked: true, outcome: 'LINKED', identifier: e.nonce },
135
+ })
136
+
137
+ // 2. De offline negatieve die het meest zegt: het zout van een ANDER bonnetje.
138
+ // Dit is waar de hele constructie op rust, want zonder het zout zouden twee
139
+ // identieke betalingen niet uit elkaar te houden zijn.
140
+ const ander = ECHT.find((x) => x.bestand !== e.bestand)
141
+ const anderBron = lees(ander.bestand)
142
+ vectoren.push({
143
+ ...basis(
144
+ `x402-evm-settlement-link-wrong-salt-${kort}`,
145
+ 'The same receipt and the same candidate, but the salt of a different payment. The commitment must not open. This is the case the whole construction rests on: without the salt, two payments with identical terms could not be told apart.',
146
+ 'A salt that belongs to another payment must not open this commitment.',
147
+ ),
148
+ requires_chain_read: false,
149
+ input: {
150
+ receipt: bron.receipt,
151
+ authorizationSalt: anderBron.authorizationSalt,
152
+ asset: bron.asset,
153
+ candidates: [{ authorizer: betaler, nonce: e.nonce }],
154
+ },
155
+ context: { note: 'Both salts are real and come from two separate payments with identical terms.' },
156
+ expected: { linked: false, outcome: 'NOT_LINKED' },
157
+ })
158
+
159
+ // 3. De offline negatieve met de nonce van een andere betaling.
160
+ vectoren.push({
161
+ ...basis(
162
+ `x402-evm-settlement-link-wrong-nonce-${kort}`,
163
+ 'The correct receipt and salt, but a candidate nonce that belongs to a different settlement by the same payer. The commitment must not open on it.',
164
+ 'A candidate that is not this payment must not satisfy the commitment.',
165
+ ),
166
+ requires_chain_read: false,
167
+ input: {
168
+ receipt: bron.receipt,
169
+ authorizationSalt: bron.authorizationSalt,
170
+ asset: bron.asset,
171
+ candidates: [{ authorizer: betaler, nonce: ander.nonce }],
172
+ },
173
+ context: { note: 'Both nonces were really consumed by this payer; only one belongs to this receipt.' },
174
+ expected: { linked: false, outcome: 'NOT_LINKED' },
175
+ })
176
+ }
177
+
178
+ // 4. De vector die de twee identieke betalingen naast elkaar zet. Dit is het geval dat
179
+ // een lezer overtuigt, want hier zijn de voorwaarden letterlijk gelijk.
180
+ if (ECHT.length >= 2 && fouten.length === 0) {
181
+ const a = lees(ECHT[0].bestand)
182
+ const b = lees(ECHT[1].bestand)
183
+ vectoren.push({
184
+ ...basis(
185
+ 'x402-evm-settlement-link-two-identical-payments',
186
+ 'Two payments with identical terms (same payer, same asset, same amount, same resource) each open on their own settlement and on no other. Given both candidate sets together, each receipt selects exactly one.',
187
+ 'Disambiguation of two otherwise indistinguishable payments.',
188
+ ),
189
+ requires_chain_read: false,
190
+ input: {
191
+ receipts: [
192
+ { receipt: a.receipt, authorizationSalt: a.authorizationSalt, asset: a.asset },
193
+ { receipt: b.receipt, authorizationSalt: b.authorizationSalt, asset: b.asset },
194
+ ],
195
+ candidates: [
196
+ { authorizer: a.receipt.payload.payer, nonce: ECHT[0].nonce },
197
+ { authorizer: b.receipt.payload.payer, nonce: ECHT[1].nonce },
198
+ ],
199
+ },
200
+ context: {
201
+ note: 'Both are real payments on Base Sepolia with the same terms. Without the salt these two could not be told apart by any later reader.',
202
+ settlements: [ECHT[0].tx, ECHT[1].tx],
203
+ },
204
+ expected: {
205
+ linked: true,
206
+ outcome: 'LINKED',
207
+ mapping: [
208
+ { receipt_index: 0, identifier: ECHT[0].nonce },
209
+ { receipt_index: 1, identifier: ECHT[1].nonce },
210
+ ],
211
+ },
212
+ })
213
+ }
214
+
215
+ // 5. De uitkomst die kanon nog niet kent, en die wij juist wel nodig hebben: een
216
+ // controle die NIET KON DRAAIEN is geen afkeuring. Dit vector beschrijft dat geval
217
+ // zonder een keten nodig te hebben: er zijn geen kandidaten verkregen.
218
+ vectoren.push({
219
+ ...basis(
220
+ 'x402-evm-settlement-link-no-candidates-not-measured',
221
+ 'No candidate set could be obtained, for example because no chain access was available or the lookup window produced nothing. The correct answer is NOT_MEASURED and explicitly not NOT_LINKED: a check that could not run is not a receipt that fails. This is the third outcome a two-valued vocabulary cannot express.',
222
+ 'An incomplete check must be distinguishable from a failed one.',
223
+ ),
224
+ requires_chain_read: false,
225
+ input: {
226
+ receipt: lees(ECHT[0].bestand).receipt,
227
+ authorizationSalt: lees(ECHT[0].bestand).authorizationSalt,
228
+ asset: lees(ECHT[0].bestand).asset,
229
+ candidates: null,
230
+ },
231
+ context: { note: 'candidates is null rather than an empty list, and the two mean different things: null is "we did not obtain a list", empty is "we obtained a list and it was empty".' },
232
+ expected: { linked: null, outcome: 'NOT_MEASURED' },
233
+ })
234
+
235
+ // 6. En het geval dat wel een keten nodig heeft, expliciet als zodanig gemarkeerd.
236
+ vectoren.push({
237
+ ...basis(
238
+ 'x402-evm-settlement-link-find-candidates-onchain',
239
+ 'The full section 5.6.4 walk, starting from only the receipt, the salt and the asset: find the nonces this payer consumed in a window, then open the commitment on exactly one. Requires an archive-capable RPC for Base Sepolia. Included so the chain-dependent half is named rather than hidden, but a runner without RPC access should skip it and report that, not fail it.',
240
+ 'The chain-reading half of the walk, marked as such.',
241
+ ),
242
+ requires_chain_read: true,
243
+ input: {
244
+ receipt: lees(ECHT[0].bestand).receipt,
245
+ authorizationSalt: lees(ECHT[0].bestand).authorizationSalt,
246
+ asset: lees(ECHT[0].bestand).asset,
247
+ },
248
+ context: {
249
+ rpc: 'any Base Sepolia endpoint that serves eth_getLogs over the window around the receipt issuedAt',
250
+ expected_candidate_count: ECHT[0].kandidaten,
251
+ note: 'The candidate count is what the window actually produced on 2026-10-18 and will grow as this payer makes more payments; a runner should assert "exactly one opens", not the count.',
252
+ },
253
+ expected: { linked: true, outcome: 'LINKED', identifier: ECHT[0].nonce, settlement_transaction: ECHT[0].tx },
254
+ })
255
+
256
+ if (fouten.length) {
257
+ console.error('GEEN ENKELE VECTOR GESCHREVEN. De controle faalde:')
258
+ for (const f of fouten) console.error(' ' + f)
259
+ process.exitCode = 1
260
+ } else {
261
+ const droog = process.argv.includes('--droog')
262
+ if (!droog) {
263
+ fs.mkdirSync(UIT, { recursive: true })
264
+ for (const v of vectoren) {
265
+ fs.writeFileSync(path.join(UIT, v.id.replace('x402-evm-settlement-link-', '') + '.json'), JSON.stringify(v, null, 2) + '\n')
266
+ }
267
+ }
268
+ const offline = vectoren.filter((v) => !v.requires_chain_read).length
269
+ console.log(`${vectoren.length} vectoren${droog ? ' (droog, niets geschreven)' : ' geschreven naar vectors/settlement-link/'}`)
270
+ console.log(` offline, zonder keten te lezen : ${offline}`)
271
+ console.log(` met ketenlezing, gemarkeerd : ${vectoren.length - offline}`)
272
+ console.log(` elk commitment opnieuw berekend en gelijk bevonden aan het ondertekende bonnetje`)
273
+ }
@@ -0,0 +1,172 @@
1
+ #!/usr/bin/env node
2
+ // Zet onze afrekening-vectoren om naar de vorm van de kanon-vectoren.
3
+ //
4
+ // WAAROM DIT BESTAAT, en het is een verzoek en geen eigen inval. De auteur van de
5
+ // kanon-vectoren schreef op 2026-10-17 in x402#3396: "if you want receipt-to-settlement
6
+ // vectors in Kanon's shape, I'm open to that, with the part that needs a chain read
7
+ // marked as such." Dit is dat, met die markering erin.
8
+ //
9
+ // WAT HIER WEL EN NIET VERTAALD KAN WORDEN, en dat tweede is het interessante deel.
10
+ // Zijn `expected` is `{ valid: boolean, reason_code: string }`. Twee van onze vier
11
+ // uitkomsten passen daar precies in. De andere twee niet, en dat is geen slordigheid
12
+ // van hem maar het gat dat hij in dezelfde reactie zelf benoemde en zei te willen
13
+ // dichten. Daarom laat dit script die twee gevallen ZICHTBAAR open staan in plaats van
14
+ // ze in `valid: false` te duwen:
15
+ //
16
+ // LINKED -> valid true, reason_code LINKED
17
+ // NOT_LINKED -> valid false, reason_code NOT_LINKED
18
+ // AMBIGUOUS -> valid false, reason_code AMBIGUOUS
19
+ // NOT_MEASURED -> GEEN valid. `measurable: false` plus een reason_code.
20
+ //
21
+ // Die laatste regel is het hele punt van de omzetting. Een bonnetje waarvan de
22
+ // kandidatenlijst niet opgehaald kon worden is NIET afgekeurd, en het in `valid: false`
23
+ // schrijven zou een eerlijke verkoper beschuldigen omdat onze RPC haperde. Liever een
24
+ // veld dat zijn validator nog niet kent dan een onwaarheid die hij wel kan lezen.
25
+ //
26
+ // EN DE GRENS VAN DEZE VERTALING, want die hoort erbij. Zijn corpus dekt de autorisatie
27
+ // van de KOPER voor de afrekening: geldigheidsvenster, malleability, domein-replay,
28
+ // nonce-hergebruik, bedrag. Dit corpus dekt de andere kant: opent het gezouten
29
+ // commitment in een ONDERTEKEND bonnetje op precies een afrekening op de keten. Die
30
+ // twee overlappen nergens, dus dit is een aanvulling en geen samenvoeging.
31
+ //
32
+ // Gebruik:
33
+ // node tools/naar-kanon-vorm.mjs schrijft naar vectors/settlement-link-kanon
34
+ // node tools/naar-kanon-vorm.mjs --controleer schrijft niets, meldt alleen afwijkingen
35
+
36
+ import fs from 'node:fs'
37
+ import path from 'node:path'
38
+ import { fileURLToPath } from 'node:url'
39
+
40
+ const WORTEL = fileURLToPath(new URL('..', import.meta.url))
41
+ export const BRONMAP = path.join(WORTEL, 'vectors', 'settlement-link')
42
+ export const DOELMAP = path.join(WORTEL, 'vectors', 'settlement-link-kanon')
43
+
44
+ /** Hun schema-versie, zoals die in elk van hun eigen vectoren staat. */
45
+ export const KANON_SCHEMA_VERSIE = '3.0.0'
46
+
47
+ /**
48
+ * De vertaaltabel van onze uitkomst naar hun expected-blok.
49
+ *
50
+ * `valid` wordt met opzet WEGGELATEN bij NOT_MEASURED, niet op false gezet. Een
51
+ * ontbrekend veld is voor een lezer een vraag; een false is een beschuldiging.
52
+ */
53
+ export function naarExpected(onze) {
54
+ const o = onze?.outcome
55
+ if (o === 'LINKED') {
56
+ return { valid: true, reason_code: 'LINKED' }
57
+ }
58
+ if (o === 'NOT_LINKED') {
59
+ return { valid: false, reason_code: 'NOT_LINKED' }
60
+ }
61
+ if (o === 'AMBIGUOUS') {
62
+ return { valid: false, reason_code: 'AMBIGUOUS' }
63
+ }
64
+ if (o === 'NOT_MEASURED') {
65
+ return {
66
+ measurable: false,
67
+ reason_code: 'NOT_MEASURED',
68
+ note:
69
+ 'Deliberately carries no `valid`. The candidate set could not be obtained, so this says ' +
70
+ 'nothing about the receipt. Writing valid:false here would blame an honest seller for a ' +
71
+ 'failed chain read. This is the third-outcome gap discussed in x402#3396.',
72
+ }
73
+ }
74
+ return null
75
+ }
76
+
77
+ /** Zet een van onze vectoren om. Geeft null terug als de uitkomst niet te vertalen is. */
78
+ export function zetOm(v) {
79
+ const expected = naarExpected(v.expected)
80
+ if (!expected) return null
81
+ const uit = {
82
+ id: v.id,
83
+ schema_version: KANON_SCHEMA_VERSIE,
84
+ protocol: v.protocol ?? 'x402',
85
+ scheme: v.scheme ?? 'exact',
86
+ network: v.network,
87
+ asset_transfer_method: v.asset_transfer_method ?? 'eip3009',
88
+ // Een eigen veld, en het staat er omdat hun corpus deze as niet heeft. Hun vectoren
89
+ // gaan allemaal over de autorisatie VOOR de afrekening; deze gaan over het bonnetje
90
+ // NA de afrekening. Zonder dit veld zou een lezer de twee verzamelingen door elkaar
91
+ // halen zodra ze in een map staan.
92
+ verifies: 'receipt-to-settlement',
93
+ encodes: v.encodes,
94
+ provenance: v.provenance,
95
+ description: v.description,
96
+ // DE MARKERING DIE ERO M GEVRAAGD WERD. Hun schema heeft dit veld niet, dus het is
97
+ // additief: een loper die het niet kent negeert het en draait de vector gewoon, een
98
+ // loper die het wel kent weet dat er een RPC nodig is.
99
+ ...(v.requires_chain_read ? { requires_chain_read: true } : {}),
100
+ input: v.input,
101
+ ...(v.context ? { context: v.context } : {}),
102
+ expected,
103
+ }
104
+ return uit
105
+ }
106
+
107
+ export function laadBron(map = BRONMAP) {
108
+ if (!fs.existsSync(map)) return []
109
+ return fs.readdirSync(map).filter((f) => f.endsWith('.json')).sort()
110
+ .map((f) => ({ bestand: f, inhoud: JSON.parse(fs.readFileSync(path.join(map, f), 'utf8')) }))
111
+ }
112
+
113
+ const ditBestand = fileURLToPath(import.meta.url)
114
+ if (process.argv[1] && path.resolve(process.argv[1]) === path.resolve(ditBestand)) {
115
+ const alleenControleren = process.argv.includes('--controleer')
116
+ const bron = laadBron()
117
+ if (!bron.length) {
118
+ console.error('no vectors found in vectors/settlement-link')
119
+ process.exit(1)
120
+ }
121
+
122
+ if (!alleenControleren) fs.mkdirSync(DOELMAP, { recursive: true })
123
+
124
+ let geschreven = 0
125
+ let ongewijzigd = 0
126
+ let afwijkend = 0
127
+ let nietTeVertalen = 0
128
+ const telling = {}
129
+
130
+ for (const { bestand, inhoud } of bron) {
131
+ const om = zetOm(inhoud)
132
+ if (!om) {
133
+ nietTeVertalen++
134
+ console.log(' SKIP ' + bestand + ' (outcome ' + String(inhoud?.expected?.outcome) + ' has no translation)')
135
+ continue
136
+ }
137
+ const code = om.expected.reason_code
138
+ telling[code] = (telling[code] ?? 0) + 1
139
+ const doel = path.join(DOELMAP, bestand)
140
+ const tekst = JSON.stringify(om, null, 2) + '\n'
141
+ if (alleenControleren) {
142
+ const bestaat = fs.existsSync(doel) ? fs.readFileSync(doel, 'utf8') : null
143
+ if (bestaat === tekst) ongewijzigd++
144
+ else { afwijkend++; console.log(' DIFFERS ' + bestand + (bestaat === null ? ' (missing)' : '')) }
145
+ continue
146
+ }
147
+ fs.writeFileSync(doel, tekst)
148
+ geschreven++
149
+ }
150
+
151
+ console.log('')
152
+ if (alleenControleren) {
153
+ console.log(ongewijzigd + ' up to date, ' + afwijkend + ' differ, ' + nietTeVertalen + ' untranslatable')
154
+ process.exitCode = afwijkend === 0 ? 0 : 1
155
+ } else {
156
+ console.log(geschreven + ' vectors written to vectors/settlement-link-kanon')
157
+ }
158
+ console.log('')
159
+ console.log('reason codes used:')
160
+ for (const [k, v] of Object.entries(telling).sort((a, b) => b[1] - a[1])) {
161
+ console.log(' ' + String(v).padStart(3) + ' ' + k)
162
+ }
163
+ const ketenLees = bron.filter((b) => b.inhoud.requires_chain_read).length
164
+ console.log('')
165
+ console.log(ketenLees + ' of ' + bron.length + ' carry requires_chain_read:true, so a runner knows to expect an RPC.')
166
+ console.log('')
167
+ console.log('One honest note about the translation, and it is the reason this exists:')
168
+ console.log('Kanon expected is valid plus a reason_code. LINKED, NOT_LINKED and AMBIGUOUS map')
169
+ console.log('onto that cleanly. NOT_MEASURED does not, so those files carry measurable:false')
170
+ console.log('and no valid at all, rather than a valid:false that would read as a verdict about')
171
+ console.log('a seller when the truth is that our own chain read did not happen.')
172
+ }
@@ -28,6 +28,7 @@
28
28
  // Exitcode 0 als er een lijst is, 1 als de inhoud niet te meten was.
29
29
 
30
30
  import { execSync } from 'node:child_process'
31
+ import { readFileSync } from 'node:fs'
31
32
  import path from 'node:path'
32
33
  import { fileURLToPath } from 'node:url'
33
34
 
@@ -47,7 +48,13 @@ export function lijstUitPackUitvoer(ruw) {
47
48
  throw new Error('npm pack gaf geen json terug: ' + String(e.message).slice(0, 80))
48
49
  }
49
50
 
50
- const uitEntry = (e) => (e && Array.isArray(e.files) ? e.files.map((f) => f.path) : null)
51
+ // EEN LEGE LIJST IS GEEN LIJST. `Array.isArray([])` is waar en `[]` is in javascript
52
+ // ook waar, dus een entry met `files: []` kwam hier als geldige uitkomst door en gaf
53
+ // een lege bestandslijst terug. Dat is precies wat de koptekst hierboven belooft NIET
54
+ // te doen, en het is ook de storing die deze file se eigen geschiedenis beschrijft:
55
+ // twaalf controles die verdwenen terwijl de suite groen bleef. Een tarball met nul
56
+ // bestanden bestaat niet, dus dit is altijd een meetfout en nooit een uitkomst.
57
+ const uitEntry = (e) => (e && Array.isArray(e.files) && e.files.length ? e.files.map((f) => f.path) : null)
51
58
 
52
59
  // Vorm 1: een array van entries (npm 11.11.0 en ouder).
53
60
  if (Array.isArray(j)) {
@@ -83,6 +90,43 @@ export function pakInhoud({ cwd = WORTEL, draai = null } = {}) {
83
90
  return lijstUitPackUitvoer(uit)
84
91
  }
85
92
 
93
+
94
+ /**
95
+ * Wat de tarball MOET dragen, afgeleid uit de verzendtabel van de cli zelf.
96
+ *
97
+ * WAAROM AFGELEID EN NIET OPGESCHREVEN. De publicatiestap heette "de tarball moet NOTICE,
98
+ * LICENSE en alles waar de cli naar verwijst dragen" en toetste vijf vaste paden, terwijl
99
+ * de verzendtabel negen modules heeft. Zeven subcommando's werden dus nooit gecontroleerd.
100
+ * Zou `files` in package.json ooit `src/` kwijtraken, dan ging er een pakket uit waarvan
101
+ * elk subcommando bij de eerste aanroep crasht, en deze poort zou groen staan. Een lijst
102
+ * die met de hand wordt bijgehouden loopt per definitie achter op de tabel die hij
103
+ * bewaakt; deze leest die tabel.
104
+ *
105
+ * De drie vaste regels eronder staan er wel met de hand, en met opzet: NOTICE en LICENSE
106
+ * zijn een LICENTIEPLICHT (wij verspreiden testvectoren van derden onder Apache-2.0) en
107
+ * volgen uit geen enkele tabel. Het profielbestand staat erbij omdat de ladder het leest
108
+ * zonder dat een importregel dat verraadt.
109
+ */
110
+ export function verwachteBestanden({ cliPad = null } = {}) {
111
+ const pad = cliPad ?? path.join(WORTEL, 'bin', 'cli.mjs')
112
+ const bron = readFileSync(pad, 'utf8')
113
+ const tabel = bron.match(/const onderdelen = \{([^}]*)\}/)
114
+ if (!tabel) {
115
+ throw new Error('de verzendtabel is niet te vinden in ' + pad + ', dus de verwachte inhoud is ONGEMETEN')
116
+ }
117
+ const modules = [...tabel[1].matchAll(/'([^']+\.mjs)'/g)].map((m) => m[1].replace(/^\.\.\//, ''))
118
+ if (!modules.length) {
119
+ throw new Error('de verzendtabel in ' + pad + ' bevat geen enkel modulepad, dus hier is iets stuk')
120
+ }
121
+ return [
122
+ 'NOTICE',
123
+ 'LICENSE',
124
+ 'bin/cli.mjs',
125
+ 'profiles/x402-deployed-ladder-v1.json',
126
+ ...modules,
127
+ ]
128
+ }
129
+
86
130
  const ditBestand = fileURLToPath(import.meta.url)
87
131
  if (process.argv[1] && path.resolve(process.argv[1]) === path.resolve(ditBestand)) {
88
132
  try {
@@ -0,0 +1,44 @@
1
+ {
2
+ "id": "x402-evm-settlement-link-find-candidates-onchain",
3
+ "schema_version": "3.0.0",
4
+ "protocol": "x402",
5
+ "scheme": "exact",
6
+ "network": "eip155:84532",
7
+ "asset_transfer_method": "eip3009",
8
+ "encodes": "The chain-reading half of the walk, marked as such.",
9
+ "provenance": [
10
+ "x402 offer-receipt extension section 5.6.4, as proposed in pull request 3827 at commit 0e492d6 and not on main",
11
+ "EIP-3009"
12
+ ],
13
+ "description": "The full section 5.6.4 walk, starting from only the receipt, the salt and the asset: find the nonces this payer consumed in a window, then open the commitment on exactly one. Requires an archive-capable RPC for Base Sepolia. Included so the chain-dependent half is named rather than hidden, but a runner without RPC access should skip it and report that, not fail it.",
14
+ "requires_chain_read": true,
15
+ "input": {
16
+ "receipt": {
17
+ "format": "eip712",
18
+ "payload": {
19
+ "version": 2,
20
+ "network": "eip155:84532",
21
+ "resourceUrl": "https://api.tokenizen.nl/api/paid/verify-ownership",
22
+ "payer": "0x87f344b6Ec48A936373d774D3De8649DEEB66Ee1",
23
+ "issuedAt": 1792187030,
24
+ "transaction": "",
25
+ "authorizationMethod": "eip3009",
26
+ "authorizationCommitment": "0x5c35a61a09a566a9c284fad18a70ac2ddfff34d01d2a3ce776ce94e8d5b38ff8"
27
+ },
28
+ "signature": "0x78615cb22986af0aad6e08b74ca78773bb58ece21660e84e4b35b3e5c1841b0075238ca9bfdf0f969ad3f2903af8f391fafd1b3fc7ebbf1fb5c949a3948fccde1c"
29
+ },
30
+ "authorizationSalt": "0xea85b2473363fd8fff1ccdd7f8638be8b47c7c05023e3e2e3f81bebb085ba2ad",
31
+ "asset": "0x036CbD53842c5426634e7929541eC2318f3dCF7e"
32
+ },
33
+ "context": {
34
+ "rpc": "any Base Sepolia endpoint that serves eth_getLogs over the window around the receipt issuedAt",
35
+ "expected_candidate_count": 2,
36
+ "note": "The candidate count is what the window actually produced on 2026-10-18 and will grow as this payer makes more payments; a runner should assert \"exactly one opens\", not the count."
37
+ },
38
+ "expected": {
39
+ "linked": true,
40
+ "outcome": "LINKED",
41
+ "identifier": "0x1120412c78ea1b2e8bf9eacfc3264c71a23ecd9b1fa579eb16030693344d5dfe",
42
+ "settlement_transaction": "0xed87b09bfb20a8c8b69908e163fcea6432d193d389640c0465afcb5561dfeb30"
43
+ }
44
+ }
@@ -0,0 +1,41 @@
1
+ {
2
+ "id": "x402-evm-settlement-link-no-candidates-not-measured",
3
+ "schema_version": "3.0.0",
4
+ "protocol": "x402",
5
+ "scheme": "exact",
6
+ "network": "eip155:84532",
7
+ "asset_transfer_method": "eip3009",
8
+ "encodes": "An incomplete check must be distinguishable from a failed one.",
9
+ "provenance": [
10
+ "x402 offer-receipt extension section 5.6.4, as proposed in pull request 3827 at commit 0e492d6 and not on main",
11
+ "EIP-3009"
12
+ ],
13
+ "description": "No candidate set could be obtained, for example because no chain access was available or the lookup window produced nothing. The correct answer is NOT_MEASURED and explicitly not NOT_LINKED: a check that could not run is not a receipt that fails. This is the third outcome a two-valued vocabulary cannot express.",
14
+ "requires_chain_read": false,
15
+ "input": {
16
+ "receipt": {
17
+ "format": "eip712",
18
+ "payload": {
19
+ "version": 2,
20
+ "network": "eip155:84532",
21
+ "resourceUrl": "https://api.tokenizen.nl/api/paid/verify-ownership",
22
+ "payer": "0x87f344b6Ec48A936373d774D3De8649DEEB66Ee1",
23
+ "issuedAt": 1792187030,
24
+ "transaction": "",
25
+ "authorizationMethod": "eip3009",
26
+ "authorizationCommitment": "0x5c35a61a09a566a9c284fad18a70ac2ddfff34d01d2a3ce776ce94e8d5b38ff8"
27
+ },
28
+ "signature": "0x78615cb22986af0aad6e08b74ca78773bb58ece21660e84e4b35b3e5c1841b0075238ca9bfdf0f969ad3f2903af8f391fafd1b3fc7ebbf1fb5c949a3948fccde1c"
29
+ },
30
+ "authorizationSalt": "0xea85b2473363fd8fff1ccdd7f8638be8b47c7c05023e3e2e3f81bebb085ba2ad",
31
+ "asset": "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
32
+ "candidates": null
33
+ },
34
+ "context": {
35
+ "note": "candidates is null rather than an empty list, and the two mean different things: null is \"we did not obtain a list\", empty is \"we obtained a list and it was empty\"."
36
+ },
37
+ "expected": {
38
+ "linked": null,
39
+ "outcome": "NOT_MEASURED"
40
+ }
41
+ }
@@ -0,0 +1,48 @@
1
+ {
2
+ "id": "x402-evm-settlement-link-opens-live-2",
3
+ "schema_version": "3.0.0",
4
+ "protocol": "x402",
5
+ "scheme": "exact",
6
+ "network": "eip155:84532",
7
+ "asset_transfer_method": "eip3009",
8
+ "encodes": "Receipt-to-settlement binding verified offline against a supplied candidate set.",
9
+ "provenance": [
10
+ "x402 offer-receipt extension section 5.6.4, as proposed in pull request 3827 at commit 0e492d6 and not on main",
11
+ "EIP-3009"
12
+ ],
13
+ "description": "A version 2 receipt whose authorizationCommitment opens on exactly one of the candidate nonces supplied with it. No chain access is needed because the candidates are given; this is the arithmetic half of section 5.6.4.",
14
+ "requires_chain_read": false,
15
+ "input": {
16
+ "receipt": {
17
+ "format": "eip712",
18
+ "payload": {
19
+ "version": 2,
20
+ "network": "eip155:84532",
21
+ "resourceUrl": "https://api.tokenizen.nl/api/paid/verify-ownership",
22
+ "payer": "0x87f344b6Ec48A936373d774D3De8649DEEB66Ee1",
23
+ "issuedAt": 1792187518,
24
+ "transaction": "",
25
+ "authorizationMethod": "eip3009",
26
+ "authorizationCommitment": "0xfecee93e1aec7d6858a218bf324f23e2a4eed07925d8d4542b9662c5026e3d22"
27
+ },
28
+ "signature": "0x02f5ba0d2b7928a2dbb1d8845b664a79d38eebcd0a2c4532ed3c6b922051bf8d47c8aafb0520a875a708e3ed480d84a537962ea90d66ce2ee3811f4229aa8b401b"
29
+ },
30
+ "authorizationSalt": "0x63072ea656fe922bf04c9cefc4275314d695fff01e5b57f6628c8df0252cc5dc",
31
+ "asset": "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
32
+ "candidates": [
33
+ {
34
+ "authorizer": "0x87f344b6Ec48A936373d774D3De8649DEEB66Ee1",
35
+ "nonce": "0x515895dfac6f148a4cfdf5c4f8266b7859dbd6534cdf77104b1be9f484eb5005"
36
+ }
37
+ ]
38
+ },
39
+ "context": {
40
+ "note": "Real payment on Base Sepolia to https://api.tokenizen.nl/api/paid/verify-ownership. Buyer and seller are the same party, which proves the chain closes end to end and nothing about adoption.",
41
+ "settlement_transaction": "0x2898d0ceb97ddf60af98e19c94fc0adddbdf1e64f9032e62454085e37acfe36b"
42
+ },
43
+ "expected": {
44
+ "linked": true,
45
+ "outcome": "LINKED",
46
+ "identifier": "0x515895dfac6f148a4cfdf5c4f8266b7859dbd6534cdf77104b1be9f484eb5005"
47
+ }
48
+ }