@ninsei-labs/sdk 0.55.4 → 0.57.2
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 +60 -0
- package/LICENSE-POLICY.md +9 -2
- package/README.md +51 -24
- package/THIRD_PARTY_NOTICES.md +174 -0
- package/assets/vendors/MANIFEST.json +18 -0
- package/assets/vendors/sdk/sdk-browser.js +2059 -2
- package/engine/atomic/dleq2.js +187 -22
- package/engine/atomic/order.js +21 -3
- package/engine/core/config.js +17 -24
- package/engine/core/deployments.generated.js +103 -0
- package/engine/core/store.js +25 -4
- package/engine/core/swap.js +54 -52
- package/engine/evm/asyncRoute.js +1 -1
- package/engine/evm/claimGas.js +2 -1
- package/engine/evm/escrow.js +13 -8
- package/engine/evm/factory.js +24 -26
- package/engine/evm/funding.js +8 -3
- package/engine/evm/index.js +2 -4
- package/engine/evm/session.js +3 -3
- package/engine/monero/scan.js +101 -22
- package/engine/recovery/restore.js +8 -8
- package/engine/sdk/bridge.js +3 -6
- package/index.d.ts +57 -27
- package/package.json +25 -8
- package/src/actions.mjs +52 -9
- package/src/adapters/evm-wallet.mjs +24 -5
- package/src/adapters/index.d.ts +66 -0
- package/src/adapters/index.mjs +0 -6
- package/src/codes.mjs +14 -0
- package/src/config.mjs +1 -0
- package/src/engine.mjs +6 -6
- package/src/feeEstimate.mjs +11 -4
- package/src/http.mjs +4 -1
- package/src/index.mjs +4 -3
- package/src/legs/kyber.mjs +23 -0
- package/src/lock.mjs +2 -1
- package/src/order.mjs +108 -20
- package/src/primitives.mjs +4 -5
- package/src/probes.mjs +9 -3
- package/src/provider/envFile.mjs +11 -1
- package/src/public/networks.d.ts +45 -0
- package/src/public/networks.mjs +10 -1
- package/src/public/order.d.ts +4 -0
- package/src/public/recovery.d.ts +40 -54
- package/src/public/recovery.mjs +2 -8
- package/src/public/xmr.d.ts +14 -3
- package/src/public/xmr.mjs +1 -1
- package/src/quoteEip712Spec.mjs +9 -1
- package/src/quotes.mjs +118 -49
- package/src/record.mjs +3 -3
- package/src/recovery-key.mjs +161 -237
- package/src/relayFeatures.mjs +25 -13
- package/src/relayFirmClient.mjs +69 -6
- package/src/relayQuote.mjs +87 -10
- package/src/relayRequest.mjs +12 -3
- package/src/relayView.mjs +3 -3
- package/src/swap-flow.mjs +153 -67
- package/src/swaps.mjs +346 -174
- package/src/sweep-restore.mjs +14 -6
- package/src/sweep.mjs +34 -11
- package/src/version.mjs +1 -1
- package/src/xmr-arrival.mjs +55 -24
- package/assets/vendors/atomic/atomic-browser.js +0 -24
- package/engine/atomic/order-client.js +0 -56
- package/engine/atomic/order-worker.js +0 -156
- package/engine/evm/asyncExec.js +0 -577
- package/engine/evm/asyncLegs.js +0 -308
- package/src/adapters/node-test-evm-wallet.mjs +0 -357
package/src/sweep-restore.mjs
CHANGED
|
@@ -65,7 +65,7 @@ const heightOf = async (driver, name) => {
|
|
|
65
65
|
// AN INCOMPLETE SCAN IS A NAMED OUTCOME, NOT A ZERO BALANCE. The wallet library's sync is best-effort: a node
|
|
66
66
|
// that refuses block downloads leaves a wallet at height 0, and a caller that only reads `unlocked` shows "no
|
|
67
67
|
// XMR". The heights and the sync error decide the verdict here, so the page does not have to guess.
|
|
68
|
-
const scanCompleteness = async (driver, { syncError = null, rescanError = null } = {}) => {
|
|
68
|
+
const scanCompleteness = async (driver, { syncError = null, rescanError = null, spentChecked = true } = {}) => {
|
|
69
69
|
const walletHeight = await heightOf(driver, "getHeight");
|
|
70
70
|
const nodeHeight = await heightOf(driver, "getDaemonHeight");
|
|
71
71
|
let reason = null;
|
|
@@ -76,6 +76,9 @@ const scanCompleteness = async (driver, { syncError = null, rescanError = null }
|
|
|
76
76
|
else if (syncError) reason = "sync-failed";
|
|
77
77
|
else if (walletHeight === null || nodeHeight === null) reason = "no-heights";
|
|
78
78
|
else if (walletHeight < nodeHeight) reason = "behind-node";
|
|
79
|
+
// A BALANCE FROM A WINDOW IS NOT A COMPLETE SCAN WHEN SPENT STATUS WAS NEVER READ. An output spent just after
|
|
80
|
+
// `t1` would still look withdrawable; naming the gap is safer than reporting a complete pass over it.
|
|
81
|
+
else if (!spentChecked) reason = "spent-status-unavailable";
|
|
79
82
|
return { scanComplete: reason === null, ...(reason === null ? {} : { scanIncompleteReason: reason }), walletHeight, nodeHeight };
|
|
80
83
|
};
|
|
81
84
|
|
|
@@ -244,9 +247,13 @@ export async function restoreWallet(request = {}) {
|
|
|
244
247
|
why: e && e.params && e.params.why ? e.params.why : null,
|
|
245
248
|
};
|
|
246
249
|
}
|
|
247
|
-
// THE KEY IMAGES OF THE WALLET, CHECKED AT THE NODE
|
|
248
|
-
//
|
|
249
|
-
|
|
250
|
+
// THE KEY IMAGES OF THE WALLET, CHECKED AT THE NODE - ONLY WHEN THE CALLER EXPLICITLY TRUSTS THAT NODE.
|
|
251
|
+
// Key images are linkable: a third-party daemon can tie them to the visitor's connection and recognise later
|
|
252
|
+
// spends. The window path must not leak them by default. A trusted-node caller opts in with
|
|
253
|
+
// `window.trustedNode: true`; otherwise the pass reports spent status as unavailable and the full-scan path
|
|
254
|
+
// (which uses the wallet's own spent check) remains available.
|
|
255
|
+
if (windowReport.used && requestWindow.nodeUrl && requestWindow.trustedNode === true
|
|
256
|
+
&& typeof driver.getKeyImages === "function") {
|
|
250
257
|
try {
|
|
251
258
|
const exported = await driver.getKeyImages();
|
|
252
259
|
const images = Array.isArray(exported) ? exported
|
|
@@ -270,12 +277,13 @@ export async function restoreWallet(request = {}) {
|
|
|
270
277
|
} catch { windowReport.spent = null; windowReport.spentWhy = "check-failed"; }
|
|
271
278
|
} else if (windowReport.used && requestWindow.nodeUrl) {
|
|
272
279
|
windowReport.spent = null;
|
|
273
|
-
windowReport.spentWhy = "no-key-images";
|
|
280
|
+
windowReport.spentWhy = requestWindow.trustedNode === true ? "no-key-images" : "untrusted-node";
|
|
274
281
|
}
|
|
275
282
|
// A WINDOW WITH COINS IS THE ANSWER. A window with none falls through to the full scan unless the caller
|
|
276
283
|
// explicitly turned the fallback off.
|
|
277
284
|
if (windowReport.used && (windowTotal > 0n || windowUnlocked > 0n || requestWindow.fallback === false)) {
|
|
278
|
-
const completeness = await scanCompleteness(driver, { syncError: windowSyncError
|
|
285
|
+
const completeness = await scanCompleteness(driver, { syncError: windowSyncError,
|
|
286
|
+
spentChecked: windowReport.spent !== null && windowReport.spent !== undefined });
|
|
279
287
|
return {
|
|
280
288
|
total: windowTotal.toString(), unlocked: windowUnlocked.toString(), scanHeight,
|
|
281
289
|
...completeness, passes: 1, lockedPass: false, window: windowReport,
|
package/src/sweep.mjs
CHANGED
|
@@ -11,7 +11,7 @@ import { restoreWallet } from "./sweep-restore.mjs";
|
|
|
11
11
|
import { moneroWalletAdapter } from "./adapters/monero-wallet.mjs";
|
|
12
12
|
import { checkDestination } from "./destination.mjs";
|
|
13
13
|
import { revealedHalfWord } from "./sweep-half.mjs";
|
|
14
|
-
import {
|
|
14
|
+
import { takerHalvesV2 } from "./recovery-key.mjs";
|
|
15
15
|
import { jointAddress } from "./order.mjs";
|
|
16
16
|
import { formatXmr } from "../engine/core/xmrAmount.js";
|
|
17
17
|
|
|
@@ -29,6 +29,28 @@ const xmrAmountOf = (value) => {
|
|
|
29
29
|
// The same boundary as when the file was issued: a passphrase shorter than twelve characters will not open the file.
|
|
30
30
|
const MIN_PASSPHRASE = 12;
|
|
31
31
|
const STEPS = ["unlock", "sync", "sweep", "relay"];
|
|
32
|
+
|
|
33
|
+
// A NODE MUST NOT BE ABLE TO SET THE WITHDRAWAL FEE. The node's estimate reaches the SDK through the wallet,
|
|
34
|
+
// and an untrusted node can answer with most of the balance. The absolute ceiling is deliberately far above a
|
|
35
|
+
// normal priority fee (0.01 XMR) while still rejecting a percentage-sized charge. A caller that needs another
|
|
36
|
+
// ceiling can pass `maxFeeAtomic` explicitly.
|
|
37
|
+
export const MAX_SWEEP_FEE_ATOMIC = 10_000_000_000n; // 0.01 XMR
|
|
38
|
+
|
|
39
|
+
export function sweepFeeVerdict({ feeAtomic = null, amountAtomic = null, maxFeeAtomic = MAX_SWEEP_FEE_ATOMIC } = {}) {
|
|
40
|
+
if (feeAtomic === null || feeAtomic === undefined) {
|
|
41
|
+
// A FEE THAT WAS NOT REPORTED IS NOT A FREE WITHDRAWAL. The ceiling cannot be applied to an unknown number;
|
|
42
|
+
// the page must show the refusal instead of a withdrawal whose cost is invisible.
|
|
43
|
+
return { ok: false, code: "sweep-fee-unknown", checked: false, fee: null, limit: String(maxFeeAtomic) };
|
|
44
|
+
}
|
|
45
|
+
let fee;
|
|
46
|
+
let amount;
|
|
47
|
+
let limit;
|
|
48
|
+
try { fee = BigInt(feeAtomic); amount = amountAtomic === null || amountAtomic === undefined ? null : BigInt(amountAtomic); limit = BigInt(maxFeeAtomic); }
|
|
49
|
+
catch { return { ok: false, code: "sweep-fee-too-high", why: "unreadable", fee: String(feeAtomic), limit: String(maxFeeAtomic) }; }
|
|
50
|
+
if (fee < 0n || limit < 0n) return { ok: false, code: "sweep-fee-too-high", why: "negative", fee: fee.toString(), limit: limit.toString() };
|
|
51
|
+
if (fee > limit) return { ok: false, code: "sweep-fee-too-high", why: "ceiling", fee: fee.toString(), limit: limit.toString(), amount: amount === null ? null : amount.toString() };
|
|
52
|
+
return { ok: true, checked: true, fee: fee.toString(), limit: limit.toString(), amount: amount === null ? null : amount.toString() };
|
|
53
|
+
}
|
|
32
54
|
// `revealedHalf()` on the escrow. Public data: the function returns the half the settlement published.
|
|
33
55
|
const REVEALED_HALF_SELECTOR = "0x3f267bb6";
|
|
34
56
|
|
|
@@ -60,17 +82,12 @@ const payloadFromOrder = async (request) => {
|
|
|
60
82
|
// TWO DERIVATIONS, BOTH LIVE. A v1 order has an index; a v2 order has the public salt from OrderCreated and
|
|
61
83
|
// the factory in its binding. The page may hand either shape back; reading `index` from a v2 order would invent
|
|
62
84
|
// a number and rebuild the wrong address.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
halves = takerHalvesV2({ mnemonic: request.mnemonic, chainId, factory: order.factory, salt: order.salt });
|
|
69
|
-
} else {
|
|
70
|
-
const index = Number(order.index);
|
|
71
|
-
if (!Number.isSafeInteger(index) || index < 0) throw new SdkError("bad-input", { field: "order.index" });
|
|
72
|
-
halves = takerHalves({ mnemonic: request.mnemonic, chainId, index });
|
|
85
|
+
// ONE DERIVATION. An order without the factory and salt of its OrderCreated event is not an order this key can
|
|
86
|
+
// rebuild; there is no index branch left to guess from.
|
|
87
|
+
if (typeof order.factory !== "string" || !/^0x[0-9a-fA-F]{40}$/.test(order.factory)) {
|
|
88
|
+
throw new SdkError("bad-input", { field: "order.factory" });
|
|
73
89
|
}
|
|
90
|
+
const halves = takerHalvesV2({ mnemonic: request.mnemonic, chainId, factory: order.factory, salt: order.salt });
|
|
74
91
|
const buy = side === "buy";
|
|
75
92
|
if (bare(buy ? order.edPointLocker : order.edPointClaimer) !== bare(halves.spendPoint)) {
|
|
76
93
|
throw new SdkError("bad-input", { field: "order", why: "spend-point" });
|
|
@@ -366,6 +383,12 @@ export function createSweep({ http, config, call = null }) {
|
|
|
366
383
|
// support, and the interface would show a free transfer.
|
|
367
384
|
const fee = await feeOf(wallet, signed);
|
|
368
385
|
const feeValue = fee === null ? null : BigInt(fee);
|
|
386
|
+
const feeVerdict = sweepFeeVerdict({
|
|
387
|
+
feeAtomic: fee,
|
|
388
|
+
amountAtomic: unlocked,
|
|
389
|
+
...(request.maxFeeAtomic === undefined || request.maxFeeAtomic === null ? {} : { maxFeeAtomic: request.maxFeeAtomic }),
|
|
390
|
+
});
|
|
391
|
+
if (!feeVerdict.ok) throw new SdkError(feeVerdict.code, { fee: feeVerdict.fee, limit: feeVerdict.limit, amount: feeVerdict.amount, why: feeVerdict.why });
|
|
369
392
|
const token = "sweep-" + (++sessionSeq);
|
|
370
393
|
sessions.set(token, { wallet, plan, signed });
|
|
371
394
|
return {
|
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.
|
|
9
|
+
export const SDK_VERSION = "0.57.2";
|
package/src/xmr-arrival.mjs
CHANGED
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
// hashes), never for a single transaction: otherwise a node links the user's IP to the trade. Requests carry
|
|
24
24
|
// `Content-Type: text/plain` (verified on every node in the default list - it avoids the CORS preflight).
|
|
25
25
|
//
|
|
26
|
-
// WHAT THE MAKER GIVES IS ONLY A HINT. The maker's node may name the payout txid; the backend may relay
|
|
27
|
-
//
|
|
28
|
-
// swap's birth height (a few dozen blocks).
|
|
26
|
+
// WHAT THE MAKER GIVES IS ONLY A REPORTED HINT. The maker's node may name the payout txid; the backend may relay
|
|
27
|
+
// it, but it does not narrow the walk and cannot hide another transfer. Every matching transfer is judged; the
|
|
28
|
+
// client scans blocks from the swap's birth height (a few dozen blocks).
|
|
29
29
|
import { SdkError } from "./errors.mjs";
|
|
30
30
|
import * as engine from "./engine.mjs";
|
|
31
31
|
|
|
@@ -47,7 +47,7 @@ const failureOf = (error, node) => {
|
|
|
47
47
|
const name = String(params.name || (error && error.name) || "");
|
|
48
48
|
if (params.status !== undefined && params.status !== null) code = "http";
|
|
49
49
|
else if (/^(TimeoutError|AbortError)$/.test(name) || /timeout|abort/i.test(why) || /timeout|abort/i.test(name)) code = "timeout";
|
|
50
|
-
else if (why === "bad-json" || why === "no-height" || why === "no-block") code = "bad-answer";
|
|
50
|
+
else if (why === "bad-json" || why === "no-height" || why === "no-block" || why === "busy" || why === "partial-transactions") code = "bad-answer";
|
|
51
51
|
const out = { url: node.url, operator: node.operator, code };
|
|
52
52
|
if (params.status !== undefined && params.status !== null) out.status = params.status;
|
|
53
53
|
if (why) out.why = why;
|
|
@@ -106,6 +106,10 @@ async function getInfo(node, fetchImpl, timeoutMs) {
|
|
|
106
106
|
const j = await call(node, "/json_rpc", { jsonrpc: "2.0", id: "info", method: "get_info" }, fetchImpl, timeoutMs);
|
|
107
107
|
const r = j && j.result;
|
|
108
108
|
if (!r || !Number.isFinite(Number(r.height))) throw new SdkError("xmr-no-nodes", { node: node.url, why: "no-height" });
|
|
109
|
+
// A BUSY NODE HAS NOT FINISHED ITS OWN VIEW. Its height is not evidence that the walk was complete.
|
|
110
|
+
if (r.busy === true || r.busy_syncing === true || (typeof r.status === "string" && r.status && r.status !== "OK")) {
|
|
111
|
+
throw new SdkError("xmr-no-nodes", { node: node.url, why: "busy" });
|
|
112
|
+
}
|
|
109
113
|
return { height: Number(r.height), synced: r.synchronized !== false, nettype: r.nettype || null };
|
|
110
114
|
}
|
|
111
115
|
|
|
@@ -127,15 +131,27 @@ async function getBlock(node, height, fetchImpl, timeoutMs) {
|
|
|
127
131
|
async function getBlockTxs(node, hashes, fetchImpl, timeoutMs) {
|
|
128
132
|
if (!hashes.length) return [];
|
|
129
133
|
const j = await call(node, "/get_transactions", { txs_hashes: hashes, decode_as_json: true }, fetchImpl, timeoutMs);
|
|
130
|
-
const wrappers = j.txs
|
|
131
|
-
|
|
132
|
-
|
|
134
|
+
const wrappers = Array.isArray(j.txs) ? j.txs : [];
|
|
135
|
+
const bodies = Array.isArray(j.txs_as_json) ? j.txs_as_json : [];
|
|
136
|
+
// A PARTIAL ANSWER IS NOT AN EMPTY BLOCK. If the node returns fewer transactions than the block named, the walk
|
|
137
|
+
// cannot conclude "no payment": that answer is unknown and must stop the refund path.
|
|
138
|
+
if (bodies.length !== hashes.length || (wrappers.length && wrappers.length !== hashes.length)) {
|
|
139
|
+
throw new SdkError("xmr-no-nodes", { node: node.url, why: "partial-transactions", want: hashes.length, got: bodies.length });
|
|
140
|
+
}
|
|
141
|
+
const out = bodies.map((s, i) => {
|
|
142
|
+
let body;
|
|
143
|
+
try { body = typeof s === "string" ? JSON.parse(s) : s; }
|
|
144
|
+
catch { throw new SdkError("xmr-no-nodes", { node: node.url, why: "bad-json" }); }
|
|
133
145
|
const w = wrappers[i] || {};
|
|
134
146
|
body.tx_hash = String(w.tx_hash || body.tx_hash || "").replace(/^0x/, "").toLowerCase();
|
|
135
147
|
body.block_height = w.block_height ?? null;
|
|
136
148
|
body.confirmations = w.confirmations ?? null;
|
|
137
149
|
return body;
|
|
138
|
-
});
|
|
150
|
+
}).filter((body) => hashes.includes(String(body.tx_hash || "").toLowerCase()));
|
|
151
|
+
if (out.length !== hashes.length) {
|
|
152
|
+
throw new SdkError("xmr-no-nodes", { node: node.url, why: "partial-transactions", want: hashes.length, got: out.length });
|
|
153
|
+
}
|
|
154
|
+
return out;
|
|
139
155
|
}
|
|
140
156
|
|
|
141
157
|
// The amount of our own outputs in a matched transaction (a swap can be paid in several outputs). An output whose
|
|
@@ -143,29 +159,43 @@ async function getBlockTxs(node, hashes, fetchImpl, timeoutMs) {
|
|
|
143
159
|
const sumOutputs = (hit) => hit.outputs.reduce((n, o) => n + (o.amountVerified ? (o.amountAtomic || 0n) : 0n), 0n);
|
|
144
160
|
|
|
145
161
|
/**
|
|
146
|
-
* FIND THE
|
|
147
|
-
*
|
|
148
|
-
*
|
|
162
|
+
* FIND THE BEST MATCHING TRANSFER. Blocks are walked from the swap's birth height upwards and the whole block is
|
|
163
|
+
* asked for each height, so a public node never learns which transaction is ours. Every matching transfer is
|
|
164
|
+
* judged: a full unlocked payout wins over dust or a locked one. The reported hint is not an input here.
|
|
149
165
|
*/
|
|
150
|
-
async function locate(node, {
|
|
166
|
+
async function locate(node, { expectedAtomic, address, viewSecret, spendPub, fromHeight, toHeight, nowSec, fetchImpl, timeoutMs }) {
|
|
151
167
|
const from = Math.max(0, intOf(fromHeight) ?? 0);
|
|
152
168
|
const to = intOf(toHeight);
|
|
153
169
|
if (!Number.isFinite(to) || to < from) throw new SdkError("bad-input", { field: "fromHeight", got: fromHeight });
|
|
170
|
+
let best = null;
|
|
154
171
|
for (let h = from; h <= to; h++) {
|
|
155
172
|
const { txHashes } = await getBlock(node, h, fetchImpl, timeoutMs);
|
|
156
173
|
if (!txHashes.length) continue;
|
|
157
|
-
|
|
174
|
+
// EVERY BLOCK IS WALKED. The reported hint cannot hide a full payout in another block.
|
|
158
175
|
const txs = await getBlockTxs(node, txHashes, fetchImpl, timeoutMs);
|
|
159
176
|
for (const tx of txs) {
|
|
160
|
-
|
|
161
|
-
|
|
177
|
+
const hit = engine.xmrScan.matchTransaction(tx, [{ address, viewSecret, spendPub }], {
|
|
178
|
+
height: h, tipHeight: Math.max(0, to), nowSec,
|
|
179
|
+
});
|
|
162
180
|
// LOCATE FINDS AN OUTPUT, NOT AN AMOUNT. The amount can be forged or unbacked; the verification step below
|
|
163
181
|
// refuses it. Requiring a positive verified sum here made two nodes that agreed on a forged amount look like
|
|
164
182
|
// "no transaction at all".
|
|
165
|
-
if (hit.length)
|
|
183
|
+
if (!hit.length) continue;
|
|
184
|
+
const amountAtomic = sumOutputs(hit[0]);
|
|
185
|
+
const amountVerified = hit[0].outputs.every((o) => o.amountVerified === true);
|
|
186
|
+
const locked = hit[0].unlock && hit[0].unlock.locked === true;
|
|
187
|
+
// JUDGE EVERY MATCHING TRANSFER. A dust transfer before the full payout is a real candidate but a worse
|
|
188
|
+
// one; a full unlocked payout wins over a full locked one. The verification step still compares the chosen
|
|
189
|
+
// transaction across operators.
|
|
190
|
+
const score = (amountAtomic >= expectedAtomic ? 4 : 0) + (amountVerified ? 2 : 0) + (locked ? 0 : 1);
|
|
191
|
+
const candidate = { txid: tx.tx_hash, height: h };
|
|
192
|
+
if (score === 7) return candidate;
|
|
193
|
+
if (!best || score > best.score || (score === best.score && amountAtomic > best.amountAtomic)) {
|
|
194
|
+
best = { ...candidate, score, amountAtomic };
|
|
195
|
+
}
|
|
166
196
|
}
|
|
167
197
|
}
|
|
168
|
-
return
|
|
198
|
+
return best;
|
|
169
199
|
}
|
|
170
200
|
|
|
171
201
|
/**
|
|
@@ -212,11 +242,11 @@ export async function verifyArrival(request) {
|
|
|
212
242
|
|
|
213
243
|
// 2. LOCATE: from the birth height, by whole blocks. The first reachable node does the walk.
|
|
214
244
|
let located = null;
|
|
215
|
-
|
|
245
|
+
const completedOperators = new Set();
|
|
216
246
|
for (const { node } of live) {
|
|
217
247
|
try {
|
|
218
|
-
located = await locate(node, {
|
|
219
|
-
|
|
248
|
+
located = await locate(node, { expectedAtomic, address: request.address, viewSecret: request.viewSecret, spendPub: request.spendPub, fromHeight: request.fromHeight, toHeight: top, nowSec, fetchImpl, timeoutMs });
|
|
249
|
+
if (!located) completedOperators.add(node.operator);
|
|
220
250
|
} catch (error) {
|
|
221
251
|
failed.push(failureOf(error, node));
|
|
222
252
|
located = null;
|
|
@@ -224,10 +254,11 @@ export async function verifyArrival(request) {
|
|
|
224
254
|
if (located) break;
|
|
225
255
|
}
|
|
226
256
|
if (!located) {
|
|
227
|
-
//
|
|
228
|
-
//
|
|
229
|
-
|
|
230
|
-
|
|
257
|
+
// ABSENCE IS A CLAIM ABOUT MONEY, SO IT NEEDS TWO OPERATORS. One node can withhold a transaction and make
|
|
258
|
+
// this walk look empty; a refund signed on that answer would take the depositor's ETH from a maker who paid.
|
|
259
|
+
// Only when no node finished the walk is every node unreachable.
|
|
260
|
+
if (!completedOperators.size) throw new SdkError("xmr-no-nodes", { tried: nodes.map((n) => n.url), nodes: failed });
|
|
261
|
+
return { seen: false, state: "pending", absent: completedOperators.size >= 2, txid: txidHint, tip, completedOperators: [...completedOperators], checked: live.map((l) => ({ url: l.node.url, operator: l.node.operator, height: l.info.height })), failed };
|
|
231
262
|
}
|
|
232
263
|
|
|
233
264
|
// 3. VERIFY ON EVERY NODE: the SAME block hash, the SAME transaction inside it, the confirmations and the money.
|