@ninsei-labs/sdk 0.55.2 → 0.55.3

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/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 0.55.3 — 2026-10-31
2
+
3
+ - Relay ask carries both view scalars: 64 bytes of plaintext and an 80-byte ciphertext, the same shape as bid.
4
+ A maker can rebuild the joint view key after a taker refunds an ask.
5
+ - The default `arbitrum-sepolia` factory is pinned by code hash (`0x4d51…615c`), measured from the deployed
6
+ `contracts-testnet-2026.10.26` build. A quote through an unknown factory is refused before signing.
7
+ - `verifyArrival` reports why each Monero node failed (`timeout`, `network`, `http` with status, `bad-answer`)
8
+ and keeps a completed walk pending when another node was unreachable.
9
+
1
10
  ## 0.55.2 — 2026-10-30
2
11
 
3
12
  - `quotes.firmRelay` now carries the signed `orderQuote.xmrAmount` on the order terms it returns, and
@@ -797,7 +797,11 @@ export function allowedProvidersFor(chainOrId) {
797
797
  // record, and its code is compared against this list. Empty for a network = no policy (the factory must still be
798
798
  // named by the record and match the signed quote). Filled at deploy: the factory has no immutables, so one build
799
799
  // gives the same hash to anyone who deployed it - a provider's own factory lands in the same list.
800
- export const KNOWN_FACTORY_CODES = {};
800
+ export const KNOWN_FACTORY_CODES = {
801
+ // contracts-testnet-2026.10.26, factory deployed at 0x69b5a6878b542960af4d239ecc60ad1c9e3e6932.
802
+ // The factory has no immutables; this hash is reproducible from that release's source.
803
+ "arbitrum-sepolia": ["0x4d51e943b7786be7d3f9e2c44ad0b54f82932dba12ac6fa34be5088500d6615c"],
804
+ };
801
805
 
802
806
  export function knownFactoryCodesFor(chainOrId) {
803
807
  const id = typeof chainOrId === "string" ? chainOrId : chainOrId && chainOrId.id;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ninsei-labs/sdk",
3
- "version": "0.55.2",
3
+ "version": "0.55.3",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org/"
package/src/actions.mjs CHANGED
@@ -14,6 +14,7 @@ import * as engine from "./engine.mjs";
14
14
  // sdk/src/swap-flow.mjs. The actions therefore call the module directly instead of reaching it through the
15
15
  // mirror - there is exactly one implementation, and it lives here.
16
16
  import * as flow from "./swap-flow.mjs";
17
+ import { assertWalletChain } from "./chainGuard.mjs";
17
18
 
18
19
  const missingFields = (object, fields) =>
19
20
  fields.filter((k) => object[k] === undefined || object[k] === null || object[k] === "");
@@ -64,6 +65,7 @@ export function createActions({ call = null } = {}) {
64
65
  requestOrFail(request, []);
65
66
  walletOrFail(wallet);
66
67
  const { escrow, expect, onStep } = request;
68
+ await assertWalletChain(wallet, expect.chainId, "mark-ready");
67
69
  return await withCodes("mark-ready", () => flow.markReadyOrder({ escrow, expect, onStep, deps: deps(wallet) }));
68
70
  },
69
71
  /** Claiming: it reveals your own half, so expectations are mandatory. */
@@ -74,6 +76,7 @@ export function createActions({ call = null } = {}) {
74
76
  const sender = typeof wallet.address === "function" ? await wallet.address() : null;
75
77
  const verdict = claimSenderVerdict({ sender, claimer: request.claimer || (expect && expect.claimer) });
76
78
  if (!verdict.ok) throw new SdkError(verdict.code, { field: verdict.field, why: verdict.why, surface: "actions.claim" });
79
+ await assertWalletChain(wallet, expect.chainId, "claim");
77
80
  return await withCodes("claim", () => flow.claimOrder({ escrow, halfClaimer, expect, onStep, deps: deps(wallet) }));
78
81
  },
79
82
  /** Refunding: it also reveals a half. The core passes the expectations ALWAYS, though the engine does not require them. */
@@ -81,6 +84,7 @@ export function createActions({ call = null } = {}) {
81
84
  requestOrFail(request, ["halfLocker"]);
82
85
  walletOrFail(wallet);
83
86
  const { escrow, halfLocker, expect, onStep } = request;
87
+ await assertWalletChain(wallet, expect.chainId, "refund");
84
88
  return await withCodes("refund", () => flow.refundOrder({ escrow, halfLocker, expect, onStep, deps: deps(wallet) }));
85
89
  },
86
90
  };
@@ -0,0 +1,27 @@
1
+ // THE NETWORK A TRANSACTION IS ABOUT TO BE SIGNED ON.
2
+ //
3
+ // The wallet signs on whatever chain it currently serves, while the order, the escrow and the quote were assembled
4
+ // for `expect.chainId`. A wallet left on another network would sign a transaction the contract cannot accept - or,
5
+ // worse, one for a same-address contract on another chain. Read the wallet's chain immediately before the send and
6
+ // refuse a mismatch by name.
7
+ import { SdkError } from "./errors.mjs";
8
+
9
+ export async function assertWalletChain(wallet, chainId, step = "send") {
10
+ const want = Number(chainId);
11
+ if (!Number.isSafeInteger(want) || want <= 0) {
12
+ throw new SdkError("bad-input", { field: "chainId", step });
13
+ }
14
+ // A wallet adapter that cannot answer its chain cannot prove which network it signs on. The production adapters
15
+ // do answer; a caller bringing a bare send/receipt adapter is refused rather than sent blind.
16
+ if (!wallet || typeof wallet.chainId !== "function") {
17
+ throw new SdkError("bad-input", { field: "wallet.chainId", step });
18
+ }
19
+ let got = null;
20
+ try { got = Number(await wallet.chainId()); }
21
+ catch { throw new SdkError("wrong-chain", { vm: "evm", step, want, got: null, why: "unreadable" }); }
22
+ if (!Number.isSafeInteger(got) || got <= 0) {
23
+ throw new SdkError("wrong-chain", { vm: "evm", step, want, got: null, why: "unreadable" });
24
+ }
25
+ if (got !== want) throw new SdkError("wrong-chain", { vm: "evm", step, want, got });
26
+ return want;
27
+ }
package/src/lock.mjs CHANGED
@@ -13,6 +13,7 @@ import * as engine from "./engine.mjs";
13
13
  // THE DEAL FLOW IS A PACKAGE MODULE NOW (#32, wave 3): the registry address is read through it, exactly as
14
14
  // the actions read the order flow.
15
15
  import * as flow from "./swap-flow.mjs";
16
+ import { assertWalletChain } from "./chainGuard.mjs";
16
17
 
17
18
  // THE ORDER'S WORD-ADDRESSES ARE BROUGHT TO 0x HERE, AT THE BOUNDARY, NOT AT EVERY CALLER.
18
19
  //
@@ -88,6 +89,7 @@ export async function send(request, wallet, deps = {}) {
88
89
  const canonical = canonicalTerms(request);
89
90
  terms({ ...canonical, amount: canonical.amountWei });
90
91
  const evm = engine.evm;
92
+ await assertWalletChain(wallet, canonical.chainId, "fund-order");
91
93
  // WHAT READS THE CHAIN IS ALSO A SEAM (as in actions.mjs): by default it is the engine's read, but the caller
92
94
  // can substitute its own. Without this capability the lock step could not be checked beyond predicting the
93
95
  // address - and then "the address from the receipt" would remain an argument on trust, not a verified property.
package/src/order.mjs CHANGED
@@ -272,9 +272,9 @@ export function orderStep({ order, side = null, counterparty = null, standIn = f
272
272
  // computation here. The other's half may not arrive (the order brings it) - then the counterparty's
273
273
  // commitment is taken ready-made or stays null, not invented.
274
274
  commitHalfLocker: norm(builder().halfCommitment(own.side.half)),
275
- commitHalfClaimer: other.half !== undefined && other.half !== null
276
- ? norm(builder().halfCommitment(other.half))
277
- : (other.commitHalfClaimer || null),
275
+ // THE COMMITMENT IS THE ONE THE PROOF WAS VERIFIED AGAINST. A `half` in the counterparty object is not a
276
+ // second source: taking it here would fund a commitment nobody proved and leave the proven half unopened.
277
+ commitHalfClaimer: other.commitHalfClaimer || null,
278
278
  network: network || null,
279
279
  },
280
280
  };
package/src/quotes.mjs CHANGED
@@ -839,6 +839,23 @@ export function createQuotes({ config, http, now = () => Date.now(), evmCall = n
839
839
  const registry = String(features.registry || "").toLowerCase();
840
840
  if (!/^0x[0-9a-f]{40}$/.test(maker) || maker === ZERO_ADDRESS) fail("bad-input", { field: "features.provider" });
841
841
  if (!/^0x[0-9a-f]{40}$/.test(registry) || registry === ZERO_ADDRESS) fail("bad-input", { field: "features.registry" });
842
+ // THE FEATURES' HPKE KEY AND FRAME KEY BELONG TO THE REGISTERED MAKER. Check the registry mapping BEFORE
843
+ // sealing any view material to the HPKE key: a dishonest relay could otherwise hand us its own key, read both
844
+ // view halves and swap in its own node half. The answer's registry check later is not a substitute for this
845
+ // one - by then the view material has already been sealed.
846
+ if (!/^0x[0-9a-f]{40}$/.test(String(features.quoteKey || "").toLowerCase()) || String(features.quoteKey).toLowerCase() === ZERO_ADDRESS) {
847
+ fail("bad-input", { field: "features.quoteKey" });
848
+ }
849
+ if (typeof evmCall !== "function") fail("quote-registry-unchecked", { step: "features", why: "no-chain-read", registry });
850
+ let featureProvider = null;
851
+ try { featureProvider = addressFromWord(await evmCall({ to: registry, data: providerOfData(features.quoteKey) })); }
852
+ catch { fail("quote-registry-unchecked", { step: "features", why: "read-failed", registry }); }
853
+ if (featureProvider === null || featureProvider === ZERO_ADDRESS) {
854
+ fail("quote-key-unknown", { step: "registry", registry, quoteKey: features.quoteKey });
855
+ }
856
+ if (!sameText(featureProvider, features.provider)) {
857
+ fail("quote-provider-mismatch", { step: "registry", got: featureProvider, want: features.provider });
858
+ }
842
859
  if (denylist && typeof order.locker === "string" && denylist.has(order.locker.toLowerCase())) {
843
860
  fail("address-denied", { step: "order-quote" });
844
861
  }
@@ -921,7 +938,7 @@ export function createQuotes({ config, http, now = () => Date.now(), evmCall = n
921
938
  edViewPointClient: own.side.viewPub,
922
939
  edViewPointNode: derived.makerViewPoint,
923
940
  nodeViewScalar: derived.makerViewHalf,
924
- clientViewScalar: side === "bid" ? derived.viewHalf : null,
941
+ clientViewScalar: derived.viewHalf,
925
942
  side,
926
943
  });
927
944
  const quote = result.quote;
@@ -82,7 +82,8 @@ function normaliseProof(proof) {
82
82
  * `features` is the signed public object the relay forwarded; `terms` is the client's request terms (its
83
83
  * `featuresHash` may be omitted and is filled from the verified features). `clientHalf` is
84
84
  * `{commitHalf, edPoint, proof}`; `nodeViewScalar` and `clientViewScalar` are the two view halves the client
85
- * chose. On ask only the node scalar is sent; on bid both.
85
+ * chose. Both are sent on both sides: after a taker refund on an ask the maker needs the taker's view scalar to
86
+ * rebuild the joint view key.
86
87
  */
87
88
  export async function buildFirmRequest({
88
89
  features, terms, clientHalf, edViewPointClient, edViewPointNode,
@@ -130,12 +131,9 @@ export async function buildFirmRequest({
130
131
  if (pointOf(nodeViewScalar, "nodeViewScalar").toLowerCase() !== nodeViewPoint.toLowerCase()) {
131
132
  throw new SdkError("bad-input", { field: "edViewPointNode" });
132
133
  }
133
- let clientScalar = null;
134
- if (requestSide === "bid") {
135
- clientScalar = scalarBytes(clientViewScalar, "clientViewScalar");
136
- if (pointOf(clientViewScalar, "clientViewScalar").toLowerCase() !== clientViewPoint.toLowerCase()) {
137
- throw new SdkError("bad-input", { field: "edViewPointClient" });
138
- }
134
+ const clientScalar = scalarBytes(clientViewScalar, "clientViewScalar");
135
+ if (pointOf(clientViewScalar, "clientViewScalar").toLowerCase() !== clientViewPoint.toLowerCase()) {
136
+ throw new SdkError("bad-input", { field: "edViewPointClient" });
139
137
  }
140
138
  const requestTerms = {
141
139
  market: String(terms.market),
@@ -167,9 +165,9 @@ export async function buildFirmRequest({
167
165
  edViewPointClient: clientViewPoint,
168
166
  edViewPointNode: nodeViewPoint,
169
167
  });
170
- const plaintext = new Uint8Array(requestSide === "ask" ? 32 : 64);
168
+ const plaintext = new Uint8Array(64);
171
169
  plaintext.set(nodeScalar, 0);
172
- if (requestSide === "bid") plaintext.set(clientScalar, 32);
170
+ plaintext.set(clientScalar, 32);
173
171
  const viewEnvelope = await sealViewEnvelope({ hpkeKey: verdict.hpkeKey, info, plaintext });
174
172
  const payload = JSON.stringify({
175
173
  terms: requestTerms,
package/src/swaps.mjs CHANGED
@@ -126,6 +126,7 @@ export function markBodyOf(swap, escrow, order = null) {
126
126
  }
127
127
  return null;
128
128
  };
129
+
129
130
  return {
130
131
  id: swap.id || null,
131
132
  network: swap.network || swap.chain || null,
@@ -592,6 +593,36 @@ export function createSwaps({ preflight, http, createRecord, mode = null, xmrNet
592
593
  return answer.body;
593
594
  }
594
595
 
596
+ // A SELL SENDS XMR ONLY INTO AN ESCROW THE CHAIN ALREADY HOLDS. The relay answer proves the maker signed the
597
+ // terms; it does not prove that the maker funded them. Read the escrow itself (code, status, slots and
598
+ // deadlines), compare the slots with the halves this offer verified, and refuse before `send-xmr`.
599
+ async function sellEscrowGate(escrow, expect) {
600
+ if (!escrow || !expect) throw new SdkError("bad-input", { field: "escrow" });
601
+ let status = null;
602
+ try { status = await flow.orderStatus(escrow, { call: reader }); }
603
+ catch (e) { throw new SdkError("quote-refused", { step: "send-xmr", why: "escrow-unreadable" }); }
604
+ if (!status || status.isFunded !== true || status.isClaimed === true || status.isRefunded === true) {
605
+ throw new SdkError("quote-refused", { step: "send-xmr", why: "escrow-not-open" });
606
+ }
607
+ let deadlines = null;
608
+ try { deadlines = await flow.orderDeadlines(escrow, { call: reader }); }
609
+ catch (e) { throw new SdkError("quote-refused", { step: "send-xmr", why: "deadline-unreadable" }); }
610
+ if (Number(deadlines.readyBy) !== Number(expect.readyBy) || Number(deadlines.t1) !== Number(expect.t1)) {
611
+ throw new SdkError("quote-refused", { step: "send-xmr", why: "terms-mismatch" });
612
+ }
613
+ // Leave time for the XMR to be sent and confirmed before the maker's ready mark closes. The lead is a
614
+ // node setting (`limits.sellReadyLeadSec`), not a second protocol constant.
615
+ const leadSec = Number(limitOf("sellReadyLeadSec", 600));
616
+ if (Math.floor(Date.now() / 1000) + leadSec >= Number(deadlines.readyBy)) {
617
+ throw new SdkError("quote-refused", { step: "send-xmr", why: "deadline-too-close" });
618
+ }
619
+ try { await flow.assertOrderSlots(escrow, expect, "send-xmr", { call: reader }); }
620
+ catch (e) {
621
+ if (e && e.code === "contract-reverted") throw e;
622
+ throw new SdkError("quote-refused", { step: "send-xmr", why: "slots-unreadable" });
623
+ }
624
+ }
625
+
595
626
  return {
596
627
  // list/get DO NOT ASK THE NETWORK: the state lies in storage, and after a page reload the interface raises the swaps
597
628
  // from it, not from memory.
@@ -1398,6 +1429,7 @@ export function createSwaps({ preflight, http, createRecord, mode = null, xmrNet
1398
1429
  || !same(existing.escrow && existing.escrow.moneroAddress, offer.jointAddress)) {
1399
1430
  throw new SdkError("quote-refused", { step: "sell-record", why: "offer-changed" });
1400
1431
  }
1432
+ await sellEscrowGate((existing.escrow && existing.escrow.address) || offer.escrow, existing.expect || null);
1401
1433
  return { id: existing.id, side: "sell", escrow: (existing.escrow && existing.escrow.address) || offer.escrow,
1402
1434
  address: (existing.escrow && existing.escrow.moneroAddress) || offer.jointAddress,
1403
1435
  xmrAmount: (existing.escrow && existing.escrow.xmrAmount) || quote.xmrAmount,
@@ -1479,6 +1511,7 @@ export function createSwaps({ preflight, http, createRecord, mode = null, xmrNet
1479
1511
  commitHalfLocker: (offer.nodeHalf && offer.nodeHalf.commitHalf) || null,
1480
1512
  orderContext: offer.context || null, xmrAmount: quote.xmrAmount || null,
1481
1513
  };
1514
+ await sellEscrowGate(offer.escrow, swap.expect);
1482
1515
  try { engine.swap.saveSwap(swap); } catch { throw new SdkError("storage-unavailable", { step: "save-swap" }); }
1483
1516
  return { id: swap.id, side: "sell", escrow: offer.escrow, address: offer.jointAddress,
1484
1517
  xmrAmount: quote.xmrAmount, claimTip: quote.claimTip || null, orderQuote: offer.orderQuote || null,
package/src/version.mjs CHANGED
@@ -6,4 +6,4 @@
6
6
  // tools/sync-version.mjs. Do not edit it by hand - set the version in package.json and run `npm run sync:version`.
7
7
  // The `version` check in tools/check.mjs refuses a mismatch, and refuses a runtime read of package.json here.
8
8
 
9
- export const SDK_VERSION = "0.55.2";
9
+ export const SDK_VERSION = "0.55.3";
@@ -34,6 +34,22 @@ const intOf = (v) => { const n = Number(v); return Number.isFinite(n) ? Math.tru
34
34
  const txidOf = (v) => (isStr(v) ? v.trim().replace(/^0x/, "").toLowerCase() : null);
35
35
  const hostOf = (url) => { try { return new URL(url).host; } catch { throw new SdkError("bad-input", { field: "nodes.url", unknown: url }); } };
36
36
 
37
+ // ONE FAILED REQUEST, IN THE SHAPE THE CALLER CAN SHOW. A node that did not answer is not evidence about the
38
+ // transaction; it is a visible reason: a timeout, a transport failure, an HTTP status or a bad answer. The list
39
+ // travels beside `checked`, so a pending or arrived verdict never hides a node that failed.
40
+ const failureOf = (error, node) => {
41
+ const params = (error && error.params) || {};
42
+ let code = "network";
43
+ const why = params.why === undefined || params.why === null ? "" : String(params.why);
44
+ if (params.status !== undefined && params.status !== null) code = "http";
45
+ else if (why === "bad-json" || why === "no-height" || why === "no-block") code = "bad-answer";
46
+ else if (/timeout|abort/i.test(why) || /timeout|abort/i.test(String((error && error.name) || ""))) code = "timeout";
47
+ const out = { url: node.url, operator: node.operator, code };
48
+ if (params.status !== undefined && params.status !== null) out.status = params.status;
49
+ if (why) out.why = why;
50
+ return out;
51
+ };
52
+
37
53
  // A NODE LIST IS A LIST OF {url, operator}. The operator is what makes two nodes two witnesses: two nodes of one
38
54
  // operator are one opinion. A plain string is accepted and its operator is the host - a user who adds their own
39
55
  // node is the operator of it.
@@ -167,11 +183,12 @@ export async function verifyArrival(request) {
167
183
 
168
184
  // 1. THE TIP, and with it the first proof that ANY node answers. All nodes down is a named refusal, not silence.
169
185
  const live = [];
186
+ const failed = [];
170
187
  for (const node of nodes) {
171
188
  try { const info = await getInfo(node, fetchImpl, timeoutMs); live.push({ node, info }); }
172
- catch { /* a failed node does not count and blocks nothing */ }
189
+ catch (error) { failed.push(failureOf(error, node)); /* a failed node does not count and blocks nothing */ }
173
190
  }
174
- if (!live.length) throw new SdkError("xmr-no-nodes", { tried: nodes.map((n) => n.url) });
191
+ if (!live.length) throw new SdkError("xmr-no-nodes", { tried: nodes.map((n) => n.url), nodes: failed });
175
192
  const tip = Math.max(...live.map((l) => l.info.height));
176
193
  // THE REPORTED HEIGHT IS THE NEXT BLOCK, NOT A REACHABLE ONE. monerod's get_info returns height = "the block that
177
194
  // will be mined next", so get_block(height) refuses with "greater than current top block". The backend already
@@ -182,15 +199,22 @@ export async function verifyArrival(request) {
182
199
 
183
200
  // 2. LOCATE: from the birth height, by whole blocks. The first reachable node does the walk.
184
201
  let located = null;
185
- let walkError = null;
202
+ let completedWalk = false;
186
203
  for (const { node } of live) {
187
- try { located = await locate(node, { txid: txidHint, address: request.address, viewSecret: request.viewSecret, spendPub: request.spendPub, fromHeight: request.fromHeight, toHeight: top, nowSec, fetchImpl, timeoutMs }); }
188
- catch (error) { walkError = error; located = null; }
204
+ try {
205
+ located = await locate(node, { txid: txidHint, address: request.address, viewSecret: request.viewSecret, spendPub: request.spendPub, fromHeight: request.fromHeight, toHeight: top, nowSec, fetchImpl, timeoutMs });
206
+ completedWalk = true;
207
+ } catch (error) {
208
+ failed.push(failureOf(error, node));
209
+ located = null;
210
+ }
189
211
  if (located) break;
190
212
  }
191
213
  if (!located) {
192
- if (walkError && walkError.code === "xmr-no-nodes") throw walkError;
193
- return { seen: false, state: "pending", txid: txidHint, tip, checked: live.map((l) => ({ url: l.node.url, operator: l.node.operator, height: l.info.height })) };
214
+ // ONE NODE FINISHED THE WALK AND FOUND NOTHING: that is a complete answer, even when another node failed.
215
+ // Only when NO node finished the walk is every node unreachable.
216
+ if (!completedWalk) throw new SdkError("xmr-no-nodes", { tried: nodes.map((n) => n.url), nodes: failed });
217
+ return { seen: false, state: "pending", txid: txidHint, tip, checked: live.map((l) => ({ url: l.node.url, operator: l.node.operator, height: l.info.height })), failed };
194
218
  }
195
219
 
196
220
  // 3. VERIFY ON EVERY NODE: the SAME block hash, the SAME transaction inside it, the confirmations and the money.
@@ -199,18 +223,18 @@ export async function verifyArrival(request) {
199
223
  const record = { url: node.url, operator: node.operator };
200
224
  let info;
201
225
  try { info = await getInfo(node, fetchImpl, timeoutMs); }
202
- catch { record.state = "down"; seen.push(record); continue; }
226
+ catch (error) { record.state = "down"; record.failure = failureOf(error, node); failed.push(record.failure); seen.push(record); continue; }
203
227
  // A LAGGING NODE IS NOT A WITNESS and is not a disagreement: it simply cannot see the block yet.
204
228
  if (!info.synced || info.height < located.height) { record.state = "stale"; record.height = info.height; seen.push(record); continue; }
205
229
  let block;
206
230
  try { block = await getBlock(node, located.height, fetchImpl, timeoutMs); }
207
- catch { record.state = "down"; seen.push(record); continue; }
231
+ catch (error) { record.state = "down"; record.failure = failureOf(error, node); failed.push(record.failure); seen.push(record); continue; }
208
232
  record.blockHash = block.hash;
209
233
  // A SYNCED NODE WITHOUT THIS TRANSACTION IN THAT BLOCK IS A DISAGREEMENT (it may hold a different block hash).
210
234
  if (!block.hash || !block.txHashes.includes(located.txid)) { record.state = "no-tx"; seen.push(record); continue; }
211
235
  let body = null;
212
236
  try { body = (await getBlockTxs(node, block.txHashes, fetchImpl, timeoutMs)).find((t) => t.tx_hash === located.txid) || null; }
213
- catch { record.state = "down"; seen.push(record); continue; }
237
+ catch (error) { record.state = "down"; record.failure = failureOf(error, node); failed.push(record.failure); seen.push(record); continue; }
214
238
  if (!body) { record.state = "no-tx"; seen.push(record); continue; }
215
239
  // THE LOCK IS JUDGED AT THE WITNESS'S TIP, NOT AT THE BLOCK THAT MINED THE TRANSFER. `located.height` stays for
216
240
  // confirmations; a height lock that has matured is no longer `xmr-locked`.
@@ -258,11 +282,12 @@ export async function verifyArrival(request) {
258
282
  txid: located.txid, height: located.height,
259
283
  nodes: disagreeing.map((r) => ({ url: r.url, operator: r.operator, blockHash: r.blockHash || null, why: r.state, outputs: r.outputs || null })),
260
284
  agreed: seen.filter((r) => r.state === "ok").map((r) => ({ url: r.url, operator: r.operator, blockHash: r.blockHash })),
285
+ failed,
261
286
  });
262
287
  }
263
288
 
264
289
  const okay = seen.filter((r) => r.state === "ok");
265
- if (!okay.length) return { seen: false, state: "pending", txid: located.txid, height: located.height, checked: seen };
290
+ if (!okay.length) return { seen: false, state: "pending", txid: located.txid, height: located.height, checked: seen, failed };
266
291
 
267
292
  // THE OBSERVATIONS MUST BE IDENTICAL. Grouping by the whole observation (not just the block hash) means a
268
293
  // node that reports a different amount, output key or unlock state does not count as agreeing with anyone.
@@ -304,15 +329,15 @@ export async function verifyArrival(request) {
304
329
 
305
330
  if (best.operators.size < 2) {
306
331
  return { seen: false, state: "one-node", txid: located.txid, height: located.height, blockHash: best.observation.blockHash,
307
- amountAtomic: amountAtomic.toString(), confirmations, operators: [...best.operators], agreedBy, checked: seen };
332
+ amountAtomic: amountAtomic.toString(), confirmations, operators: [...best.operators], agreedBy, checked: seen, failed };
308
333
  }
309
334
  if (confirmations < minConfirmations) {
310
335
  return { seen: false, state: "pending", why: "confirmations", txid: located.txid, height: located.height, blockHash: best.observation.blockHash,
311
- amountAtomic: amountAtomic.toString(), confirmations, needConfirmations: minConfirmations, agreedBy, checked: seen };
336
+ amountAtomic: amountAtomic.toString(), confirmations, needConfirmations: minConfirmations, agreedBy, checked: seen, failed };
312
337
  }
313
338
  return { seen: true, state: "arrived", txid: located.txid, height: located.height, blockHash: best.observation.blockHash,
314
339
  amountAtomic: amountAtomic.toString(), confirmations, needConfirmations: minConfirmations,
315
- operators: [...best.operators], agreedBy, checked: seen };
340
+ operators: [...best.operators], agreedBy, checked: seen, failed };
316
341
  }
317
342
 
318
343
  /**