@ninsei-labs/sdk 0.56.1 → 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 +13 -0
- package/LICENSE-POLICY.md +9 -2
- package/README.md +17 -4
- package/THIRD_PARTY_NOTICES.md +174 -0
- package/assets/vendors/MANIFEST.json +1 -5
- package/assets/vendors/sdk/sdk-browser.js +5 -4
- package/engine/atomic/dleq2.js +116 -15
- 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/swap.js +7 -7
- 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 +11 -6
- 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 +2 -5
- package/index.d.ts +48 -11
- package/package.json +4 -2
- package/src/actions.mjs +8 -5
- package/src/codes.mjs +5 -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 +1 -1
- package/src/legs/kyber.mjs +23 -0
- package/src/lock.mjs +1 -0
- package/src/order.mjs +108 -20
- package/src/primitives.mjs +4 -5
- package/src/probes.mjs +9 -3
- package/src/public/networks.d.ts +45 -0
- package/src/public/networks.mjs +10 -1
- package/src/public/xmr.mjs +1 -1
- package/src/quotes.mjs +97 -23
- package/src/recovery-key.mjs +32 -14
- package/src/relayFeatures.mjs +25 -13
- package/src/relayFirmClient.mjs +33 -7
- package/src/relayQuote.mjs +87 -10
- package/src/relayView.mjs +3 -3
- package/src/swap-flow.mjs +100 -58
- package/src/swaps.mjs +234 -64
- package/src/sweep-restore.mjs +8 -4
- package/src/sweep.mjs +5 -1
- 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/swaps.mjs
CHANGED
|
@@ -13,7 +13,7 @@ import * as engine from "./engine.mjs";
|
|
|
13
13
|
import * as recordModule from "./record.mjs";
|
|
14
14
|
// The order: our own side is built by the engine's builder, the counterparty's side is verified and accepted, and
|
|
15
15
|
// the joint address is assembled from the halves. There are no formulas of our own in the core - see order.mjs.
|
|
16
|
-
import {
|
|
16
|
+
import { buildOwnSideFromHalvesKnown, contextOf, halfHex, norm, normalizeCounterpartyView, orderStepChunked } from "./order.mjs";
|
|
17
17
|
// Locking the funds: sending goes through the already-finished step (`lock.send`), the wallet is an adapter from outside.
|
|
18
18
|
import * as lock from "./lock.mjs";
|
|
19
19
|
import * as flow from "./swap-flow.mjs";
|
|
@@ -21,7 +21,7 @@ import { fundingReceiptVerdict } from "../engine/evm/funding.js";
|
|
|
21
21
|
import { vmOfChain, legFor } from "./legs/index.mjs";
|
|
22
22
|
// THE VIEW HALVES - from the core's primitives: the sum of two halves is the key the wallet sees incoming payments
|
|
23
23
|
// with. There is no arithmetic of the core's own here either (see order.mjs) - we use the same halves builder.
|
|
24
|
-
import {
|
|
24
|
+
import { primitives } from "./primitives.mjs";
|
|
25
25
|
import { probeMoneroNode } from "./probes.mjs";
|
|
26
26
|
// MARKING READY - A FINISHED STEP, NOT A SECOND IMPLEMENTATION OF IT: it requires the order expectations and checks
|
|
27
27
|
// the slots against the chain BEFORE signing (actions.markReady). The watch must call exactly it, otherwise "we saw
|
|
@@ -35,9 +35,9 @@ import {
|
|
|
35
35
|
} from "./recovery-key.mjs";
|
|
36
36
|
// THE XMR ARRIVAL CHECK ON TWO NODES (issue #85) - IN THE CORE, from the same mirrored rule and block parser.
|
|
37
37
|
import * as xmrArrival from "./xmr-arrival.mjs";
|
|
38
|
-
// THE MAKER'S DECLINE (issue #40): the escrow's `Declined` event
|
|
39
|
-
//
|
|
40
|
-
// vocabulary live in one module, so this file names the state instead of re-reading
|
|
38
|
+
// THE MAKER'S DECLINE (issue #40): the escrow's `Declined` event is the decision. The node's `declined` +
|
|
39
|
+
// `compliance` status is an observation on the wire, not a second source this file trusts; the detectors and the
|
|
40
|
+
// neutral vocabulary live in one module, so this file names the state instead of re-reading either.
|
|
41
41
|
import { declineOf, logReaderOf, blockBoundaryOf, DECLINED_TOPIC0, DECLINED_TERMINAL, DECLINED_CODE } from "./decline.mjs";
|
|
42
42
|
|
|
43
43
|
// THE ENGINE'S SETTLEMENT KINDS -> THE CONTRACT'S CODES: THE KEY IS THE KIND THE ENGINE REALLY WRITES.
|
|
@@ -74,7 +74,13 @@ const TERMINAL = {
|
|
|
74
74
|
[DECLINED_TERMINAL]: DECLINED_TERMINAL,
|
|
75
75
|
};
|
|
76
76
|
|
|
77
|
-
const num = (v) => {
|
|
77
|
+
const num = (v) => {
|
|
78
|
+
// NULL/UNDEFINED/EMPTY IS NOT ZERO. `Number(null)` is 0, which made every unknown amount look measured as empty;
|
|
79
|
+
// a missing number is a missing fact and the state/interface must see null.
|
|
80
|
+
if (v === null || v === undefined || v === "") return null;
|
|
81
|
+
const n = Number(v);
|
|
82
|
+
return Number.isFinite(n) ? n : null;
|
|
83
|
+
};
|
|
78
84
|
|
|
79
85
|
// THE SERVICE'S NAMED STATE FOR FUNDS THAT ARE ON THE ADDRESS BUT BARRED BY THE TRANSACTION'S unlock_time
|
|
80
86
|
// (app/store.mjs, app/watcher.mjs; the rule itself is app/indexer.mjs, unlockStateOf). "Has the XMR arrived" is
|
|
@@ -236,11 +242,16 @@ export function toState(swap) {
|
|
|
236
242
|
// WHAT HAS ALREADY MOVED ON THE SWAP - the two signs the removal prompt warns about. Computed HERE from the
|
|
237
243
|
// record: the screen must not reach into it for them.
|
|
238
244
|
funds: {
|
|
239
|
-
|
|
245
|
+
// UNKNOWN IS NULL, NOT ZERO. Zero is a measured empty amount; an absent field is a different fact and the
|
|
246
|
+
// interface must be able to show a dash instead of claiming that nothing arrived. The engine's xmrView
|
|
247
|
+
// materialises a zero when it has no session, so the evidence is checked before its `seen`.
|
|
248
|
+
receivedXmr: (swap.xmrSession !== null && swap.xmrSession !== undefined)
|
|
249
|
+
|| (swap.xmr && (swap.xmr.received !== undefined || swap.xmr.arrived !== undefined))
|
|
250
|
+
? num(d.xmrAmount && d.xmrAmount.seen) : null,
|
|
240
251
|
escrowLocked: !!(swap.escrow && (swap.escrow.fundTx || swap.escrow.secret)),
|
|
241
252
|
},
|
|
242
|
-
pay: { token: swap.payToken || "eth", amount: num(swap.payAmount)
|
|
243
|
-
get: { xmr: num(swap.xmrAmount)
|
|
253
|
+
pay: { token: swap.payToken || "eth", amount: num(swap.payAmount) },
|
|
254
|
+
get: { xmr: num(swap.xmrAmount) },
|
|
244
255
|
step: active.code,
|
|
245
256
|
steps,
|
|
246
257
|
deadlines: {
|
|
@@ -292,6 +303,13 @@ const MIN_PASSPHRASE = 12;
|
|
|
292
303
|
export const recordInputOf = (request, xmrNetwork = null) => {
|
|
293
304
|
const quote = request && request.quote && typeof request.quote === "object" ? request.quote : {};
|
|
294
305
|
const pass = (v) => (v === undefined || v === null || v === "" ? undefined : v);
|
|
306
|
+
const orderAtomic = request && request.order && request.order.xmrAmount !== undefined && request.order.xmrAmount !== null
|
|
307
|
+
? String(request.order.xmrAmount) : null;
|
|
308
|
+
const quoteAtomic = request && request.orderQuote && request.orderQuote.xmrAmount !== undefined && request.orderQuote.xmrAmount !== null
|
|
309
|
+
? String(request.orderQuote.xmrAmount) : null;
|
|
310
|
+
if (orderAtomic !== null && quoteAtomic !== null && orderAtomic !== quoteAtomic) {
|
|
311
|
+
throw new SdkError("bad-input", { field: "xmrAmount", why: "order-vs-quote" });
|
|
312
|
+
}
|
|
295
313
|
return {
|
|
296
314
|
side: request.side || "buy",
|
|
297
315
|
network: quote.chain ? quote.chain : undefined,
|
|
@@ -305,10 +323,7 @@ export const recordInputOf = (request, xmrNetwork = null) => {
|
|
|
305
323
|
// order's `xmrAmount` is the exact atomic value the maker will pay, and the arrival check compares that one.
|
|
306
324
|
// THE SIGNED FIGURE, NEVER A DISPLAY ONE. The firm path puts the quote's signed `xmrAmount` on the order it
|
|
307
325
|
// returns; a bare `quote.size` is a rounded screen number and must not reach the arrival check.
|
|
308
|
-
expectedAtomic:
|
|
309
|
-
? String(request.order.xmrAmount)
|
|
310
|
-
: (request.orderQuote && request.orderQuote.xmrAmount !== undefined && request.orderQuote.xmrAmount !== null
|
|
311
|
-
? String(request.orderQuote.xmrAmount) : undefined),
|
|
326
|
+
expectedAtomic: quoteAtomic !== null ? quoteAtomic : (orderAtomic !== null ? orderAtomic : undefined),
|
|
312
327
|
// THE ORDER-QUOTE ID IS PART OF THE RECORD, NOT A DETAIL OF THE SCREEN (a defect found): our service uses it to
|
|
313
328
|
// tie the created escrow to the provider node's record, and without it the node cannot take the ETH
|
|
314
329
|
// (sdk/src/swap-flow.mjs: quoteId: quote.id -> swap.orderQuoteId; markBodyOf reads exactly this field).
|
|
@@ -366,7 +381,7 @@ export function sellWatchTimeoutMs({ configuredMs = 1_200_000, readyBySec = null
|
|
|
366
381
|
return Math.max(configured, (readyAt - now + SELL_WATCH_MARGIN_SEC) * 1000);
|
|
367
382
|
}
|
|
368
383
|
|
|
369
|
-
export function createSwaps({ preflight, http, createRecord, mode = null, xmrNetwork = null, call = null, store = engine.store,
|
|
384
|
+
export function createSwaps({ preflight, http, createRecord, mode = null, xmrNetwork = null, call = null, now = null, evmBlock = null, store = engine.store,
|
|
370
385
|
// THE PATHS AND LIMITS ARE BROUGHT BY THE CONFIGURATION: the "server" step's paths are named by names (config.route),
|
|
371
386
|
// and the timeout and rate of the watch polling - in config.limits. Without the configuration the step answers with a
|
|
372
387
|
// code rather than following invented paths.
|
|
@@ -389,6 +404,27 @@ export function createSwaps({ preflight, http, createRecord, mode = null, xmrNet
|
|
|
389
404
|
// substitute your own. Otherwise the lock step could not be checked beyond predicting the address - and "the address
|
|
390
405
|
// from the receipt" would remain an argument on trust, not a verified property.
|
|
391
406
|
const reader = typeof call === "function" ? call : engine.evm.readContract;
|
|
407
|
+
// ONE BLOCK FOR THE SELL GATE. A block read is a seam like the contract read: `evmBlock` from the interface
|
|
408
|
+
// wins, then the wallet's own provider. The number pins every escrow read below to the same state; the
|
|
409
|
+
// timestamp is the chain's clock, not the device's.
|
|
410
|
+
const chainSnapshot = async (wallet = null) => {
|
|
411
|
+
let block = null;
|
|
412
|
+
if (typeof evmBlock === "function") {
|
|
413
|
+
block = await evmBlock("latest");
|
|
414
|
+
} else if (wallet && typeof wallet.driver === "function") {
|
|
415
|
+
const provider = wallet.driver();
|
|
416
|
+
if (provider && typeof provider.request === "function") {
|
|
417
|
+
const tag = await provider.request({ method: "eth_blockNumber" });
|
|
418
|
+
if (typeof tag === "string" && /^0x[0-9a-f]+$/i.test(tag)) {
|
|
419
|
+
block = await provider.request({ method: "eth_getBlockByNumber", params: [tag, false] });
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
const number = block && Number(block.number);
|
|
424
|
+
const timestamp = block && Number(block.timestamp);
|
|
425
|
+
if (!Number.isSafeInteger(number) || number < 0 || !Number.isFinite(timestamp) || timestamp <= 0) return null;
|
|
426
|
+
return { blockTag: "0x" + number.toString(16), timestamp };
|
|
427
|
+
};
|
|
392
428
|
// THE SAME RULE FOR THE LOGS: one reader per facade, chosen once.
|
|
393
429
|
const logReader = logReaderOf(chainLogs);
|
|
394
430
|
// MARKING READY GOES THROUGH THE SAME READ SEAM as the lock: checking the slots and signing must go one way,
|
|
@@ -422,11 +458,19 @@ export function createSwaps({ preflight, http, createRecord, mode = null, xmrNet
|
|
|
422
458
|
// A START THAT ENDED WITH A SENT TRANSACTION AND NO RECEIPT IS RESUMED, NOT RESENT. The transaction hash and the
|
|
423
459
|
// predicted escrow are kept on the record; a retry of the same quote reads that receipt instead of building a
|
|
424
460
|
// second side and sending a second deposit.
|
|
425
|
-
const pendingFundingOf = (quoteId) => {
|
|
461
|
+
const pendingFundingOf = (quoteId, salt) => {
|
|
426
462
|
const id = String(quoteId || "");
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
463
|
+
const saltHex = String(salt || "").replace(/^0x/i, "").toLowerCase();
|
|
464
|
+
if (!id && !saltHex) return null;
|
|
465
|
+
return records().find((swap) => {
|
|
466
|
+
if (!(swap.fundingPending === true || (swap.escrow && swap.escrow.fundingPending === true))) return false;
|
|
467
|
+
if (id && String(swap.orderQuoteId || "") === id) return true;
|
|
468
|
+
// THE RELAY ANSWER MAY CARRY NO ORDER ID. The salt is the client's own binding to the same escrow: it is
|
|
469
|
+
// written into the terms and the predicted address is derived from it, so it identifies the pending record
|
|
470
|
+
// without inventing an id or asking the factory again.
|
|
471
|
+
const recordedSalt = String((swap.escrow && swap.escrow.salt) || swap.recoverySalt || "").replace(/^0x/i, "").toLowerCase();
|
|
472
|
+
return Boolean(saltHex && recordedSalt === saltHex);
|
|
473
|
+
}) || null;
|
|
430
474
|
};
|
|
431
475
|
async function resumePendingFunding(record, request) {
|
|
432
476
|
const swap = record.swap || record;
|
|
@@ -437,7 +481,23 @@ export function createSwaps({ preflight, http, createRecord, mode = null, xmrNet
|
|
|
437
481
|
// so its own status() is asked before the start is left pending forever. A failed read is not "not funded".
|
|
438
482
|
let onChain = null;
|
|
439
483
|
if (escrowRecord.address) {
|
|
440
|
-
try { onChain = await flow.orderStatus(escrowRecord.address, { call: reader }); }
|
|
484
|
+
try { onChain = await flow.orderStatus(escrowRecord.address, { call: reader }); }
|
|
485
|
+
catch (error) {
|
|
486
|
+
// AN EMPTY status() ANSWER IS A SUCCESSFUL READ OF AN ADDRESS WITH NO CONTRACT, not an unreadable chain.
|
|
487
|
+
// Anything else leaves `onChain` null and the record pending: a failed read must never authorise a resend.
|
|
488
|
+
if (/short .*status\(\)/.test(String((error && error.message) || error))) onChain = { isFunded: false, absent: true };
|
|
489
|
+
else onChain = null;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
// A PROCESS THAT DIED BETWEEN THE PRE-SEND RECORD AND THE WALLET CALL LEFT "not-sent" BEHIND. The chain was
|
|
493
|
+
// read and the escrow is not funded, so no transaction can be in flight: clear the mark and let the caller
|
|
494
|
+
// build the same salt/address again. If the read failed, the record stays pending - never resend blind.
|
|
495
|
+
if (!txHash && onChain && !onChain.isFunded && escrowRecord.fundingReason === "not-sent") {
|
|
496
|
+
delete swap.fundingPending;
|
|
497
|
+
swap.escrow = { ...escrowRecord, fundingPending: false, fundingReason: "send-not-started" };
|
|
498
|
+
try { engine.swap.saveSwap(swap, store); }
|
|
499
|
+
catch { throw new SdkError("storage-unavailable", { step: "save-pending" }); }
|
|
500
|
+
return null;
|
|
441
501
|
}
|
|
442
502
|
if (!txHash && !(onChain && onChain.isFunded)) {
|
|
443
503
|
return { id: swap.id || null, escrow: escrowRecord.address || null,
|
|
@@ -630,27 +690,37 @@ export function createSwaps({ preflight, http, createRecord, mode = null, xmrNet
|
|
|
630
690
|
// A SELL SENDS XMR ONLY INTO AN ESCROW THE CHAIN ALREADY HOLDS. The relay answer proves the maker signed the
|
|
631
691
|
// terms; it does not prove that the maker funded them. Read the escrow itself (code, status, slots and
|
|
632
692
|
// deadlines), compare the slots with the halves this offer verified, and refuse before `send-xmr`.
|
|
633
|
-
async function sellEscrowGate(escrow, expect) {
|
|
693
|
+
async function sellEscrowGate(escrow, expect, wallet = null) {
|
|
634
694
|
if (!escrow || !expect) throw new SdkError("bad-input", { field: "escrow" });
|
|
695
|
+
let snapshot = null;
|
|
696
|
+
try { snapshot = await chainSnapshot(wallet); }
|
|
697
|
+
catch (e) { throw new SdkError("quote-refused", { step: "send-xmr", why: "block-unreadable" }); }
|
|
698
|
+
// Compatibility with a caller that has neither a wallet nor a block seam: the reads still go to `latest`,
|
|
699
|
+
// and the deadline falls back to the documented `now` seam. A live sell carries one of the two.
|
|
700
|
+
const gate = { call: reader, blockTag: snapshot ? snapshot.blockTag : "latest" };
|
|
701
|
+
const chainNow = snapshot ? snapshot.timestamp : Math.floor((typeof now === "function" ? now() : Date.now()) / 1000);
|
|
635
702
|
let status = null;
|
|
636
|
-
try { status = await flow.orderStatus(escrow,
|
|
703
|
+
try { status = await flow.orderStatus(escrow, gate); }
|
|
637
704
|
catch (e) { throw new SdkError("quote-refused", { step: "send-xmr", why: "escrow-unreadable" }); }
|
|
638
705
|
if (!status || status.isFunded !== true || status.isClaimed === true || status.isRefunded === true) {
|
|
639
706
|
throw new SdkError("quote-refused", { step: "send-xmr", why: "escrow-not-open" });
|
|
640
707
|
}
|
|
641
708
|
let deadlines = null;
|
|
642
|
-
try { deadlines = await flow.orderDeadlines(escrow,
|
|
709
|
+
try { deadlines = await flow.orderDeadlines(escrow, gate); }
|
|
643
710
|
catch (e) { throw new SdkError("quote-refused", { step: "send-xmr", why: "deadline-unreadable" }); }
|
|
644
711
|
if (Number(deadlines.readyBy) !== Number(expect.readyBy) || Number(deadlines.t1) !== Number(expect.t1)) {
|
|
645
712
|
throw new SdkError("quote-refused", { step: "send-xmr", why: "terms-mismatch" });
|
|
646
713
|
}
|
|
647
|
-
// Leave time for the XMR to be sent and confirmed before the maker's ready mark closes. The lead
|
|
648
|
-
//
|
|
649
|
-
const
|
|
650
|
-
|
|
714
|
+
// Leave time for the XMR to be sent and confirmed before the maker's ready mark closes. The lead follows the
|
|
715
|
+
// confirmation setting; an explicit `limits.sellReadyLeadSec` can override it for a stand.
|
|
716
|
+
const confirmations = Math.max(1, Number(limitOf("xmrConfirmations", 10)));
|
|
717
|
+
const blockTimeSec = Math.max(1, Number(limitOf("xmrBlockTimeSec", 120)));
|
|
718
|
+
const configuredLead = Number(limitOf("sellReadyLeadSec", 0));
|
|
719
|
+
const leadSec = Number.isFinite(configuredLead) && configuredLead > 0 ? configuredLead : confirmations * blockTimeSec;
|
|
720
|
+
if (chainNow + leadSec >= Number(deadlines.readyBy)) {
|
|
651
721
|
throw new SdkError("quote-refused", { step: "send-xmr", why: "deadline-too-close" });
|
|
652
722
|
}
|
|
653
|
-
try { await flow.assertOrderSlots(escrow, expect, "send-xmr",
|
|
723
|
+
try { await flow.assertOrderSlots(escrow, expect, "send-xmr", gate); }
|
|
654
724
|
catch (e) {
|
|
655
725
|
if (e && e.code === "contract-reverted") throw e;
|
|
656
726
|
throw new SdkError("quote-refused", { step: "send-xmr", why: "slots-unreadable" });
|
|
@@ -799,9 +869,9 @@ export function createSwaps({ preflight, http, createRecord, mode = null, xmrNet
|
|
|
799
869
|
* uses (xmr-arrival.verifyArrival): two nodes of different operators on one block, and money barred by
|
|
800
870
|
* unlock_time is not an arrival.
|
|
801
871
|
*
|
|
802
|
-
* ONLY A POSITIVE "NOT ARRIVED" REFUNDS (
|
|
803
|
-
*
|
|
804
|
-
*
|
|
872
|
+
* ONLY A POSITIVE "NOT ARRIVED" REFUNDS (`absent: true`, returned only when two operators completed the walk
|
|
873
|
+
* and found no matching transaction). `pending` with a transaction, `one-node`, and every failure to check are NOT
|
|
874
|
+
* "no money": the helper refuses to sign, so a lagging or busy witness can never look like an empty address.
|
|
805
875
|
*
|
|
806
876
|
* IT FIRES ONLY WHEN LESS THAN THE CONFIRMATIONS' TIME IS LEFT before `readyBy`
|
|
807
877
|
* (`minConfirmations * blockTimeSec`, overridable with `leadSec`): refunding earlier would abandon a maker who
|
|
@@ -831,12 +901,12 @@ export function createSwaps({ preflight, http, createRecord, mode = null, xmrNet
|
|
|
831
901
|
const spendPub = request.spendPub || e.moneroSpendPub || null;
|
|
832
902
|
if (!spendPub) throw new SdkError("bad-input", { field: "spendPub" });
|
|
833
903
|
// THE EXPECTED SUM IN ATOMIC UNITS. Given explicitly, or derived from the record's XMR amount (1 XMR = 10^12).
|
|
834
|
-
|
|
904
|
+
// THE AMOUNT MUST BE THE SIGNED ONE. `swap.xmrAmount` is a display figure; deriving the arrival amount from
|
|
905
|
+
// it would let a rounded number decide whether a payment is short. A record without the signed value is
|
|
906
|
+
// refused instead of guessed.
|
|
907
|
+
const expectedAtomic = request.expectedAtomic !== undefined && request.expectedAtomic !== null
|
|
835
908
|
? request.expectedAtomic : (e.expectedAtomic !== undefined && e.expectedAtomic !== null ? e.expectedAtomic : null);
|
|
836
|
-
if (expectedAtomic === null
|
|
837
|
-
expectedAtomic = BigInt(Math.round(Number(swap.xmrAmount) * 1e12)).toString();
|
|
838
|
-
}
|
|
839
|
-
if (expectedAtomic === null) throw new SdkError("bad-input", { field: "expectedAtomic" });
|
|
909
|
+
if (expectedAtomic === null) throw new SdkError("bad-input", { field: "expectedAtomic", why: "unsigned-amount" });
|
|
840
910
|
const readyBy = Number(request.readyBySec !== undefined && request.readyBySec !== null ? request.readyBySec : e.readyBy);
|
|
841
911
|
if (!Number.isFinite(readyBy) || readyBy <= 0) throw new SdkError("bad-input", { field: "readyBySec" });
|
|
842
912
|
const minConfirmations = Number.isFinite(Number(request.minConfirmations)) && Number(request.minConfirmations) > 0
|
|
@@ -845,6 +915,15 @@ export function createSwaps({ preflight, http, createRecord, mode = null, xmrNet
|
|
|
845
915
|
? Number(request.blockTimeSec) : limitOf("xmrBlockTimeSec", 120);
|
|
846
916
|
const leadSec = Number.isFinite(Number(request.leadSec)) && Number(request.leadSec) >= 0
|
|
847
917
|
? Number(request.leadSec) : minConfirmations * blockTimeSec;
|
|
918
|
+
// THE WALK STARTS AT THE SWAP'S BIRTH, NEVER AT GENESIS. A missing height used to become block 0, so a refund
|
|
919
|
+
// check on a real chain would walk every block ever mined. The record carries the measured height; a caller
|
|
920
|
+
// that has neither an explicit height nor a record height is refused rather than given a scan of the whole chain.
|
|
921
|
+
const fromHeight = request.fromHeight !== undefined && request.fromHeight !== null
|
|
922
|
+
? Number(request.fromHeight)
|
|
923
|
+
: Number(swap && (swap.restoreHeight ?? e.moneroRestoreHeight ?? e.restoreHeight));
|
|
924
|
+
if (!Number.isSafeInteger(fromHeight) || fromHeight <= 0) {
|
|
925
|
+
throw new SdkError("bad-input", { field: "fromHeight", why: "missing" });
|
|
926
|
+
}
|
|
848
927
|
const nowSec = Number.isFinite(Number(request.nowSec)) ? Number(request.nowSec) : nowOf();
|
|
849
928
|
const leftSec = Math.floor(readyBy - nowSec);
|
|
850
929
|
// PAST `readyBy` THE EARLY WINDOW IS GONE and the claim window is open: refunding is no longer ours to open.
|
|
@@ -852,16 +931,31 @@ export function createSwaps({ preflight, http, createRecord, mode = null, xmrNet
|
|
|
852
931
|
// TIME STILL LEFT BEYOND THE RESERVE - the maker has room to deliver; a refund now would abandon a live trade.
|
|
853
932
|
if (leftSec > leadSec) return { refunded: false, state: "waiting", leftSec, needSec: leadSec, readyBy, nowSec };
|
|
854
933
|
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
934
|
+
let verdict = null;
|
|
935
|
+
try {
|
|
936
|
+
verdict = await verify({
|
|
937
|
+
nodes: request.nodes, address, viewSecret, spendPub, expectedAtomic, minConfirmations,
|
|
938
|
+
txid: request.txid || null, fromHeight,
|
|
939
|
+
timeoutMs: request.timeoutMs, nowSec,
|
|
940
|
+
});
|
|
941
|
+
} catch (error) {
|
|
942
|
+
// A SHORT PAYMENT OR A LOCKED OUTPUT IS NOT AN EMPTY ADDRESS. It is also not a completed arrival: return
|
|
943
|
+
// the named state and sign nothing. The caller can wait for the remainder or the lock to mature.
|
|
944
|
+
if (error && error.code === "xmr-underpaid") {
|
|
945
|
+
return { refunded: false, state: "arrival-underpaid", leftSec, verdict: null, error: error.params || null };
|
|
946
|
+
}
|
|
947
|
+
if (error && error.code === "xmr-locked") {
|
|
948
|
+
return { refunded: false, state: "arrival-locked", leftSec, verdict: null, error: error.params || null };
|
|
949
|
+
}
|
|
950
|
+
throw error;
|
|
951
|
+
}
|
|
860
952
|
// THE XMR IS THERE - NOTHING IS REFUNDED. This is the decisive condition of the guard: without it the
|
|
861
953
|
// client would take the ETH back from under a maker who has already sent the XMR.
|
|
862
954
|
if (verdict.seen) return { refunded: false, state: "arrived", leftSec, verdict };
|
|
863
|
-
//
|
|
864
|
-
//
|
|
955
|
+
// A TRANSACTION THAT IS THERE BUT NOT YET SETTLED IS NOT AN EMPTY ADDRESS. `pending` with a txid or height,
|
|
956
|
+
// and `one-node`, mean the money was seen; only the explicit absence marker proves there is nothing to wait
|
|
957
|
+
// for. A throw from `verify` above never reaches here and signs nothing either.
|
|
958
|
+
if (!verdict || verdict.absent !== true) return { refunded: false, state: "arrival-pending", leftSec, verdict };
|
|
865
959
|
const res = await refund({ escrow, halfLocker, expect: request.expect, onStep: request.onStep }, request.wallet);
|
|
866
960
|
return { refunded: true, state: "refunded", hash: (res && res.hash) || null, leftSec, verified: verdict };
|
|
867
961
|
},
|
|
@@ -892,8 +986,13 @@ export function createSwaps({ preflight, http, createRecord, mode = null, xmrNet
|
|
|
892
986
|
// RESUME BEFORE ANY NEW SIDE OR SEND. The previous start may have sent the deposit and lost the receipt;
|
|
893
987
|
// reusing its hash is the only way to learn the escrow without a second payment.
|
|
894
988
|
const quoteForResume = (request.orderQuote && request.orderQuote.id) || (request.quote && request.quote.id) || null;
|
|
895
|
-
const
|
|
896
|
-
|
|
989
|
+
const saltForResume = request.recoverySalt || (request.order && request.order.salt) ||
|
|
990
|
+
(request.orderQuote && request.orderQuote.salt) || null;
|
|
991
|
+
const pendingRecord = pendingFundingOf(quoteForResume, saltForResume);
|
|
992
|
+
if (pendingRecord) {
|
|
993
|
+
const resumed = await resumePendingFunding(pendingRecord, request);
|
|
994
|
+
if (resumed) return resumed;
|
|
995
|
+
}
|
|
897
996
|
// A NEW START USES A PER-ORDER SALT. When the caller brings no `recoverySalt`, the order's own salt is the
|
|
898
997
|
// client salt; a missing salt is drawn here and written into the order before its context is built.
|
|
899
998
|
if (request.recoverySalt === undefined || request.recoverySalt === null) {
|
|
@@ -942,9 +1041,8 @@ export function createSwaps({ preflight, http, createRecord, mode = null, xmrNet
|
|
|
942
1041
|
// values: the DLEQ proof would then be bound to nothing.
|
|
943
1042
|
const orderContext = contextOf(request.order);
|
|
944
1043
|
|
|
945
|
-
// THE KEY RECORD
|
|
946
|
-
//
|
|
947
|
-
// No per-swap file is assembled on this path.
|
|
1044
|
+
// THE KEY RECORD AND THE SIDE. A key is made once and kept through the SDK's store; this path uses the
|
|
1045
|
+
// per-order salt, and no per-swap file is assembled here.
|
|
948
1046
|
let recovery = null;
|
|
949
1047
|
{
|
|
950
1048
|
const storage = store.storage();
|
|
@@ -974,7 +1072,7 @@ export function createSwaps({ preflight, http, createRecord, mode = null, xmrNet
|
|
|
974
1072
|
if (salt !== orderSalt) throw new SdkError("bad-input", { field: "recoverySalt", why: "order-salt" });
|
|
975
1073
|
const derived = takerHalvesV2({ mnemonic: key.mnemonic, chainId, factory: request.order.factory, salt });
|
|
976
1074
|
recovery = { storage, key, salt, derivation: "salt-v2", newKey: !saved || saved.backupConfirmed !== true };
|
|
977
|
-
keySide =
|
|
1075
|
+
keySide = buildOwnSideFromHalvesKnown(request.order, { spendHalf: derived.spendHalf, viewHalf: derived.viewHalf }).side;
|
|
978
1076
|
// THE MAKER'S VIEW HALF IS DERIVED FROM THE KEY, NOT CHOSEN BY THE NODE. Without this binding a
|
|
979
1077
|
// signed quote could carry another view half; the funded address would differ from the one the twelve
|
|
980
1078
|
// words rebuild, and `sweep.fromOrder` would refuse after the funds were locked.
|
|
@@ -1017,7 +1115,7 @@ export function createSwaps({ preflight, http, createRecord, mode = null, xmrNet
|
|
|
1017
1115
|
// go red (and rightly so). There is no second build of the side here.
|
|
1018
1116
|
let builtSide = null;
|
|
1019
1117
|
if (!record.swapWallet) {
|
|
1020
|
-
const step =
|
|
1118
|
+
const step = await orderStepChunked({
|
|
1021
1119
|
order: request.order, side: made.side || null, counterparty: request.counterparty || null,
|
|
1022
1120
|
standIn: mode !== "live", network: (record.swap.moneroNetwork || xmrNetwork || null),
|
|
1023
1121
|
});
|
|
@@ -1125,10 +1223,46 @@ export function createSwaps({ preflight, http, createRecord, mode = null, xmrNet
|
|
|
1125
1223
|
throw new SdkError("quote-refused", { step: "quote-binding", why: "counterparty-half" });
|
|
1126
1224
|
}
|
|
1127
1225
|
}
|
|
1226
|
+
// THE SIGNED QUOTE MUST STILL BE VALID WHEN THE MONEY MOVES. The proof and the record work take seconds; a
|
|
1227
|
+
// quote that expired in that window would reach the wallet and revert at the factory. Check the signed field
|
|
1228
|
+
// immediately before the send, with a small margin for the next block.
|
|
1229
|
+
const validUntil = request.orderQuote && request.orderQuote.validUntil !== undefined
|
|
1230
|
+
? request.orderQuote.validUntil
|
|
1231
|
+
: undefined;
|
|
1232
|
+
if (validUntil !== undefined && validUntil !== null) {
|
|
1233
|
+
const until = Number(validUntil);
|
|
1234
|
+
// THE CLOCK IS THE SDK'S OWN SEAM, IN MILLISECONDS, LIKE EVERY OTHER NOW IN THE FACADE.
|
|
1235
|
+
const nowMs = typeof now === "function" ? Number(now()) : Date.now();
|
|
1236
|
+
const nowSec = Math.floor(nowMs / 1000);
|
|
1237
|
+
if (!Number.isSafeInteger(until) || !Number.isSafeInteger(nowSec) || until <= nowSec + 30) {
|
|
1238
|
+
throw new SdkError("quote-expired", { validUntil: Number.isFinite(until) ? until : null, now: Number.isFinite(nowSec) ? nowSec : null, marginSec: 30, step: "lock" });
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1128
1241
|
lockRequest.quote = request.orderQuote || null;
|
|
1242
|
+
// THE PENDING RECORD EXISTS BEFORE THE SEND, NOT AFTER THE RECEIPT WAIT. If the receipt arrives late (or the
|
|
1243
|
+
// process dies while waiting), a retry must find the predicted escrow and read it instead of asking for a
|
|
1244
|
+
// second deposit. `fundOrder` calls this after its state guard and immediately before `eth_sendTransaction`.
|
|
1245
|
+
const notePredicted = async ({ escrow: predicted, salt }) => {
|
|
1246
|
+
if (!predicted || !/^0x[0-9a-fA-F]{40}$/.test(String(predicted))) return;
|
|
1247
|
+
const escrowRecord = record.swap.escrow && typeof record.swap.escrow === "object" ? record.swap.escrow : {};
|
|
1248
|
+
record.swap.fundingPending = true;
|
|
1249
|
+
record.swap.escrow = { ...escrowRecord, address: predicted, salt: salt || escrowRecord.salt || null,
|
|
1250
|
+
fundingPending: true, fundingReason: "not-sent" };
|
|
1251
|
+
try { engine.swap.saveSwap(record.swap, store); }
|
|
1252
|
+
catch { throw new SdkError("storage-unavailable", { step: "save-pending" }); }
|
|
1253
|
+
};
|
|
1129
1254
|
let funded = null;
|
|
1130
|
-
try { funded = await lock.send(lockRequest, wallet, { call: reader }); }
|
|
1255
|
+
try { funded = await lock.send(lockRequest, wallet, { call: reader, onPredicted: notePredicted }); }
|
|
1131
1256
|
catch (error) {
|
|
1257
|
+
// A REJECTION BEFORE BROADCAST MUST NOT LEAVE THE SWAP STUCK IN funding-pending. The pre-send record exists
|
|
1258
|
+
// for a process that dies while the send is in flight; an explicit wallet refusal is the other case, and the
|
|
1259
|
+
// retry has to be allowed to sign again. A transaction that was already mined is caught by the escrow's own
|
|
1260
|
+
// state guard; one still in the mempool is not, and the resend can revert and cost gas - never a second deposit.
|
|
1261
|
+
if (record.swap.escrow && record.swap.escrow.fundingReason === "not-sent") {
|
|
1262
|
+
delete record.swap.fundingPending;
|
|
1263
|
+
record.swap.escrow = { ...record.swap.escrow, fundingPending: false, fundingReason: "send-rejected" };
|
|
1264
|
+
try { engine.swap.saveSwap(record.swap, store); } catch { /* the pending record stays; never resend blind */ }
|
|
1265
|
+
}
|
|
1132
1266
|
if (error && typeof error.code === "string") throw error;
|
|
1133
1267
|
throw new SdkError("server-unavailable", { step: "lock" });
|
|
1134
1268
|
}
|
|
@@ -1250,7 +1384,8 @@ export function createSwaps({ preflight, http, createRecord, mode = null, xmrNet
|
|
|
1250
1384
|
//
|
|
1251
1385
|
// THE DECLINE IS ASKED WITH TWO INDEPENDENT SOURCES AND EITHER ONE ENDS THE WAIT:
|
|
1252
1386
|
// * THE CHAIN - the escrow's own `Declined` event, through the same log reader the rest of the core uses;
|
|
1253
|
-
// * THE WIRE - the status the service answers with
|
|
1387
|
+
// * THE WIRE - the status the service answers with is an observation, not a decision; it never writes the
|
|
1388
|
+
// decline.
|
|
1254
1389
|
// A CHAIN READ THAT FAILS is neither a decline nor a refusal of the swap: the wait goes on and the wire may
|
|
1255
1390
|
// still answer. What the chain read did is carried out with the result (`chain.checked` / `chain.error`), so
|
|
1256
1391
|
// a broken reader is visible instead of silent.
|
|
@@ -1420,7 +1555,7 @@ export function createSwaps({ preflight, http, createRecord, mode = null, xmrNet
|
|
|
1420
1555
|
|| !same(existing.escrow && existing.escrow.moneroAddress, offer.jointAddress)) {
|
|
1421
1556
|
throw new SdkError("quote-refused", { step: "sell-record", why: "offer-changed" });
|
|
1422
1557
|
}
|
|
1423
|
-
await sellEscrowGate((existing.escrow && existing.escrow.address) || offer.escrow, existing.expect || null);
|
|
1558
|
+
await sellEscrowGate((existing.escrow && existing.escrow.address) || offer.escrow, existing.expect || null, request.wallet);
|
|
1424
1559
|
return { id: existing.id, side: "sell", escrow: (existing.escrow && existing.escrow.address) || offer.escrow,
|
|
1425
1560
|
address: (existing.escrow && existing.escrow.moneroAddress) || offer.jointAddress,
|
|
1426
1561
|
xmrAmount: (existing.escrow && existing.escrow.xmrAmount) || quote.xmrAmount,
|
|
@@ -1436,6 +1571,23 @@ export function createSwaps({ preflight, http, createRecord, mode = null, xmrNet
|
|
|
1436
1571
|
if (!saved && !supplied) throw new SdkError("bad-input", { field: "recoveryKey" });
|
|
1437
1572
|
const key = saved || importRecoveryKey(supplied);
|
|
1438
1573
|
if (!saved) saveRecoveryKey(storage, { ...key, backupConfirmed: false });
|
|
1574
|
+
// A SELL CARRIES THE SAME KEY AS A BUY, SO IT NEEDS THE SAME BACKUP GATE. The one-time XMR address is the
|
|
1575
|
+
// moment the seller can lose money; handing it out before the twelve words are saved turns a closed tab into
|
|
1576
|
+
// an unrecoverable sale. The buy path already refuses to fund until this flag is true.
|
|
1577
|
+
if (!saved || saved.backupConfirmed !== true) {
|
|
1578
|
+
if (typeof request.onRecoveryKey !== "function") throw new SdkError("bad-input", { field: "onRecoveryKey" });
|
|
1579
|
+
let file = null;
|
|
1580
|
+
try {
|
|
1581
|
+
file = {
|
|
1582
|
+
name: recoveryKeyFileName(key),
|
|
1583
|
+
contents: await createRecoveryKeyFile({ mnemonic: key.mnemonic, createdAt: key.createdAt, passphrase: request.passphrase }),
|
|
1584
|
+
};
|
|
1585
|
+
} catch { throw new SdkError("recovery-failed", { step: "encrypt-key" }); }
|
|
1586
|
+
const confirmed = await request.onRecoveryKey(file);
|
|
1587
|
+
if (confirmed !== true) throw new SdkError("recovery-declined", { key: key.fingerprint });
|
|
1588
|
+
try { saveRecoveryKey(storage, { ...key, backupConfirmed: true }); }
|
|
1589
|
+
catch { throw new SdkError("storage-unavailable", { step: "save-recovery-key" }); }
|
|
1590
|
+
}
|
|
1439
1591
|
const chainId = Number(order.chainId);
|
|
1440
1592
|
if (!Number.isSafeInteger(chainId) || chainId <= 0) throw new SdkError("bad-input", { field: "order.chainId" });
|
|
1441
1593
|
if (!order.factory || order.salt === undefined || order.salt === null) throw new SdkError("bad-input", { field: "order" });
|
|
@@ -1443,17 +1595,16 @@ export function createSwaps({ preflight, http, createRecord, mode = null, xmrNet
|
|
|
1443
1595
|
try { salt = recoverySaltOf(offer.recovery && offer.recovery.salt ? offer.recovery.salt : order.salt); }
|
|
1444
1596
|
catch { throw new SdkError("bad-input", { field: "offer.recovery" }); }
|
|
1445
1597
|
const derived = takerHalvesV2({ mnemonic: key.mnemonic, chainId, factory: order.factory, salt });
|
|
1446
|
-
const own =
|
|
1598
|
+
const own = buildOwnSideFromHalvesKnown(order, { spendHalf: derived.spendHalf, viewHalf: derived.viewHalf });
|
|
1447
1599
|
// THE OFFER MUST NAME THE HALF THIS KEY ACTUALLY PRODUCES. The relay already checked the proof; the record
|
|
1448
1600
|
// needs the same point and commitment, otherwise a later claim would reveal a half the escrow rejects.
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
if (!ownCommit || low160(ownCommit) !== low160(quote.commitHalfClaimer)) {
|
|
1601
|
+
// THE COMMITMENT COMES FROM THE HALF, NOT FROM A SECOND PROOF. `buildOwnSideFromHalvesKnown` derives it with
|
|
1602
|
+
// the same builder the contract mirrors; the side carries no proof because the firm answer already did.
|
|
1603
|
+
const ownCommit = own.commitHalf;
|
|
1604
|
+
// THE WHOLE COMMITMENT, NOT ITS LOW 160 BITS. `findSwaps` compares all 32 bytes, so a bid whose high 96 bits
|
|
1605
|
+
// differ would be invisible to a words-only search while `startSell` accepted it.
|
|
1606
|
+
const fullHex = (v) => String(v || "").replace(/^0x/, "").toLowerCase();
|
|
1607
|
+
if (!ownCommit || fullHex(ownCommit) !== fullHex(quote.commitHalfClaimer)) {
|
|
1457
1608
|
throw new SdkError("quote-refused", { step: "sell-record", why: "commitment" });
|
|
1458
1609
|
}
|
|
1459
1610
|
if (String(own.spendPoint).toLowerCase() !== String(quote.edPointClaimer || "").toLowerCase()) {
|
|
@@ -1500,7 +1651,7 @@ export function createSwaps({ preflight, http, createRecord, mode = null, xmrNet
|
|
|
1500
1651
|
// from the escrow/deadline/slot gate must remove it again; otherwise the interface lists send-xmr for an
|
|
1501
1652
|
// order the SDK never checked.
|
|
1502
1653
|
try {
|
|
1503
|
-
await sellEscrowGate(offer.escrow, swap.expect);
|
|
1654
|
+
await sellEscrowGate(offer.escrow, swap.expect, request.wallet);
|
|
1504
1655
|
} catch (error) {
|
|
1505
1656
|
try { engine.swap.forgetSwap(swap.id, store); } catch { /* the gate's refusal is the actionable one */ }
|
|
1506
1657
|
throw error;
|
|
@@ -1553,6 +1704,16 @@ export function createSwaps({ preflight, http, createRecord, mode = null, xmrNet
|
|
|
1553
1704
|
timeoutMs = sellWatchTimeoutMs({ configuredMs: timeoutMs, readyBySec: deadlines.readyBy });
|
|
1554
1705
|
} catch { /* no deadline read: keep the configured wait */ }
|
|
1555
1706
|
}
|
|
1707
|
+
// THE CLAIM OPENS AT readyBy WITHOUT A MARK. The deadline comes from the escrow once; the clock is the
|
|
1708
|
+
// facade's own millisecond seam, so a simulation and a caller that controls time agree with the rest of
|
|
1709
|
+
// the SDK. A failed deadline read does not invent a claim window.
|
|
1710
|
+
let deadlines = null;
|
|
1711
|
+
try { deadlines = await flow.orderDeadlines(escrow, { call: reader }); }
|
|
1712
|
+
catch { /* no deadline: the wait keeps its configured timeout and never reports claim-open */ }
|
|
1713
|
+
const nowSec = () => {
|
|
1714
|
+
const at = typeof now === "function" ? Number(now()) : Date.now();
|
|
1715
|
+
return Number.isFinite(at) ? Math.floor(at / 1000) : null;
|
|
1716
|
+
};
|
|
1556
1717
|
const started = Date.now();
|
|
1557
1718
|
let lastStatus = null;
|
|
1558
1719
|
let lastError = null;
|
|
@@ -1562,7 +1723,7 @@ export function createSwaps({ preflight, http, createRecord, mode = null, xmrNet
|
|
|
1562
1723
|
if (lastStatus && (lastStatus.isClaimed || lastStatus.isRefunded)) {
|
|
1563
1724
|
return { escrow, state: lastStatus.isClaimed ? "claimed" : "refunded",
|
|
1564
1725
|
funded: lastStatus.isFunded, claimed: lastStatus.isClaimed, refunded: lastStatus.isRefunded,
|
|
1565
|
-
ready: null, balanceWei: String(lastStatus.balance), waitedMs: Date.now() - started };
|
|
1726
|
+
ready: null, claimOpen: false, balanceWei: String(lastStatus.balance), waitedMs: Date.now() - started };
|
|
1566
1727
|
}
|
|
1567
1728
|
if (lastStatus && lastStatus.isFunded) {
|
|
1568
1729
|
let ready = null;
|
|
@@ -1573,7 +1734,16 @@ export function createSwaps({ preflight, http, createRecord, mode = null, xmrNet
|
|
|
1573
1734
|
} catch (error) { lastError = (error && error.code) || "ready-unread"; }
|
|
1574
1735
|
if (ready === true) {
|
|
1575
1736
|
return { escrow, state: "ready", funded: true, claimed: false, refunded: false,
|
|
1576
|
-
ready: true, balanceWei: String(lastStatus.balance), waitedMs: Date.now() - started };
|
|
1737
|
+
ready: true, claimOpen: false, balanceWei: String(lastStatus.balance), waitedMs: Date.now() - started };
|
|
1738
|
+
}
|
|
1739
|
+
}
|
|
1740
|
+
// AFTER readyBy THE CLAIM IS OPEN EVEN WITHOUT THE NODE'S READY MARK. The order is funded, no terminal
|
|
1741
|
+
// action was seen, and the escrow's own deadline has passed; the seller can claim the ETH now.
|
|
1742
|
+
if (lastStatus && lastStatus.isFunded && deadlines && Number.isSafeInteger(Number(deadlines.readyBy))) {
|
|
1743
|
+
const at = nowSec();
|
|
1744
|
+
if (at !== null && at >= Number(deadlines.readyBy)) {
|
|
1745
|
+
return { escrow, state: "claim-open", funded: true, claimed: false, refunded: false,
|
|
1746
|
+
ready: false, claimOpen: true, balanceWei: String(lastStatus.balance), waitedMs: Date.now() - started };
|
|
1577
1747
|
}
|
|
1578
1748
|
}
|
|
1579
1749
|
if (Date.now() - started >= timeoutMs) {
|
package/src/sweep-restore.mjs
CHANGED
|
@@ -247,9 +247,13 @@ export async function restoreWallet(request = {}) {
|
|
|
247
247
|
why: e && e.params && e.params.why ? e.params.why : null,
|
|
248
248
|
};
|
|
249
249
|
}
|
|
250
|
-
// THE KEY IMAGES OF THE WALLET, CHECKED AT THE NODE
|
|
251
|
-
//
|
|
252
|
-
|
|
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") {
|
|
253
257
|
try {
|
|
254
258
|
const exported = await driver.getKeyImages();
|
|
255
259
|
const images = Array.isArray(exported) ? exported
|
|
@@ -273,7 +277,7 @@ export async function restoreWallet(request = {}) {
|
|
|
273
277
|
} catch { windowReport.spent = null; windowReport.spentWhy = "check-failed"; }
|
|
274
278
|
} else if (windowReport.used && requestWindow.nodeUrl) {
|
|
275
279
|
windowReport.spent = null;
|
|
276
|
-
windowReport.spentWhy = "no-key-images";
|
|
280
|
+
windowReport.spentWhy = requestWindow.trustedNode === true ? "no-key-images" : "untrusted-node";
|
|
277
281
|
}
|
|
278
282
|
// A WINDOW WITH COINS IS THE ANSWER. A window with none falls through to the full scan unless the caller
|
|
279
283
|
// explicitly turned the fallback off.
|
package/src/sweep.mjs
CHANGED
|
@@ -37,7 +37,11 @@ const STEPS = ["unlock", "sync", "sweep", "relay"];
|
|
|
37
37
|
export const MAX_SWEEP_FEE_ATOMIC = 10_000_000_000n; // 0.01 XMR
|
|
38
38
|
|
|
39
39
|
export function sweepFeeVerdict({ feeAtomic = null, amountAtomic = null, maxFeeAtomic = MAX_SWEEP_FEE_ATOMIC } = {}) {
|
|
40
|
-
if (feeAtomic === null || feeAtomic === undefined)
|
|
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
|
+
}
|
|
41
45
|
let fee;
|
|
42
46
|
let amount;
|
|
43
47
|
let limit;
|
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";
|