@ninsei-labs/sdk 0.59.0 → 0.61.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/README.md +40 -8
- package/assets/vendors/MANIFEST.json +1 -1
- package/assets/vendors/sdk/sdk-browser.js +4 -4
- package/engine/atomic/dleq2.js +0 -4
- package/engine/atomic/halfenc.js +0 -4
- package/engine/atomic/halves.js +0 -4
- package/engine/atomic/order.js +0 -4
- package/engine/atomic/orderContext.js +0 -4
- package/engine/atomic/orderHalfCommit.js +0 -4
- package/engine/core/chainSource.js +0 -4
- package/engine/core/clock.js +0 -4
- package/engine/core/config.js +0 -4
- package/engine/core/deployments.generated.js +1 -17
- package/engine/core/finality.js +0 -4
- package/engine/core/format.js +0 -4
- package/engine/core/preSignGuards.js +0 -4
- package/engine/core/rfqSource.js +0 -3
- package/engine/core/sellWindow.js +0 -4
- package/engine/core/store.js +0 -4
- package/engine/core/swap.js +0 -4
- package/engine/evm/amounts.js +0 -4
- package/engine/evm/asyncRoute.js +0 -4
- package/engine/evm/auth.js +0 -4
- package/engine/evm/claimGas.js +2 -6
- package/engine/evm/dex.js +0 -4
- package/engine/evm/escrow.js +0 -4
- package/engine/evm/factory.js +0 -4
- package/engine/evm/fees.js +0 -4
- package/engine/evm/funding.js +2 -5
- package/engine/evm/gasReserve.js +0 -4
- package/engine/evm/index.js +5 -9
- package/engine/evm/injected.js +0 -4
- package/engine/evm/permit.js +0 -4
- package/engine/evm/prices.js +0 -4
- package/engine/evm/session.js +0 -4
- package/engine/mock/chain.js +0 -4
- package/engine/monero/address.js +0 -3
- package/engine/monero/halvesSweep.js +0 -4
- package/engine/monero/node.js +0 -4
- package/engine/monero/swapKeys.js +0 -4
- package/engine/monero/unlock.js +2 -6
- package/engine/monero/wallet.js +0 -3
- package/engine/recovery/recoveryFile.js +0 -4
- package/engine/recovery/restore.js +0 -4
- package/engine/sdk/bridge.js +3 -7
- package/engine/ui/dom.js +0 -4
- package/engine/ui/walletModal.js +0 -4
- package/index.d.ts +89 -36
- package/package.json +3 -2
- package/src/engine.mjs +17 -26
- package/src/index.mjs +1 -1
- package/src/predictEscrow.mjs +25 -0
- package/src/public/recovery.d.ts +1 -1
- package/src/quotes.mjs +2 -5
- package/src/relayClaim.mjs +17 -3
- package/src/relayFirmClient.mjs +18 -0
- package/src/swap-flow.mjs +7 -10
- package/src/swaps.mjs +349 -76
- package/src/sweep.mjs +9 -2
- package/src/version.mjs +1 -1
- package/src/xmr-arrival.mjs +61 -41
package/src/sweep.mjs
CHANGED
|
@@ -175,7 +175,7 @@ const feeOf = async (wallet, signed) => {
|
|
|
175
175
|
return /^\d+$/.test(text) ? text : null;
|
|
176
176
|
};
|
|
177
177
|
|
|
178
|
-
export function createSweep({ call = null }) {
|
|
178
|
+
export function createSweep({ call = null, fetchImpl = null } = {}) {
|
|
179
179
|
// THE NAME IS NEEDED BY THE OBJECT ITSELF: `run` calls `api.plan(...)` - the step order is held by the plan and
|
|
180
180
|
// the withdrawal living in one object, not in two copies. During a manual merge of branches the object was left
|
|
181
181
|
// unnamed, and the withdrawal failed with "api is not defined": not a refusal, but a breakdown. `node --check`
|
|
@@ -336,7 +336,14 @@ export function createSweep({ call = null }) {
|
|
|
336
336
|
// spendable - re-check the spent status once. The wallet is the same withdrawal adapter `sign` takes; the page
|
|
337
337
|
// no longer decides when a second pass is needed.
|
|
338
338
|
async restore(request) {
|
|
339
|
-
|
|
339
|
+
const merged = { ...(request || {}) };
|
|
340
|
+
if (merged.fetchImpl !== undefined && merged.fetchImpl !== null && typeof merged.fetchImpl !== "function") {
|
|
341
|
+
throw new SdkError("bad-input", { field: "fetchImpl" });
|
|
342
|
+
}
|
|
343
|
+
// THE INSTANCE TRANSPORT REACHES THE WINDOW AND KEY-IMAGE READS TOO. A per-call `fetchImpl` still wins;
|
|
344
|
+
// without this fallback a Tor/proxy caller's restore would silently use the page's global fetch.
|
|
345
|
+
if (typeof merged.fetchImpl !== "function" && typeof fetchImpl === "function") merged.fetchImpl = fetchImpl;
|
|
346
|
+
return await restoreWallet(merged);
|
|
340
347
|
},
|
|
341
348
|
|
|
342
349
|
// THE WITHDRAWAL ITSELF. The wallet arrives as an adapter (the WASM and the worker live with whoever builds the
|
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.61.0";
|
package/src/xmr-arrival.mjs
CHANGED
|
@@ -14,10 +14,9 @@
|
|
|
14
14
|
// and the screen says the nodes do not agree. When only one operator has confirmed, the core names that state
|
|
15
15
|
// (`one-node`) instead of waiting silently.
|
|
16
16
|
//
|
|
17
|
-
// WHERE THE RULE LIVES. "Locked by unlock_time is not an arrival" is ONE rule (issue #84). It
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
// same way (www/js/monero/scan.js) - a second copy would be a second truth about money.
|
|
17
|
+
// WHERE THE RULE LIVES. "Locked by unlock_time is not an arrival" is ONE rule (issue #84). It lives in the
|
|
18
|
+
// SDK's engine (engine/monero/unlock.js) and is read through the engine seam. The block parser lives beside it
|
|
19
|
+
// (engine/monero/scan.js) - a second copy would be a second truth about money.
|
|
21
20
|
//
|
|
22
21
|
// PRIVACY. Public nodes are asked for the WHOLE BLOCK (get_block plus /get_transactions over all of the block's
|
|
23
22
|
// hashes), never for a single transaction: otherwise a node links the user's IP to the trade. Requests carry
|
|
@@ -402,7 +401,7 @@ export async function verifyArrival(request) {
|
|
|
402
401
|
const amountAtomic = best.nodes[0].amountAtomic;
|
|
403
402
|
const agreedBy = best.nodes.map((r) => ({ url: r.url, operator: r.operator, blockHash: r.blockHash, confirmations: r.confirmations }));
|
|
404
403
|
|
|
405
|
-
// LOCKED IS NOT AN ARRIVAL, and the rule for that is the shared one (issue #84),
|
|
404
|
+
// LOCKED IS NOT AN ARRIVAL, and the rule for that is the shared one (issue #84), in the SDK engine.
|
|
406
405
|
const locked = best.nodes.find((r) => r.unlock && r.unlock.locked);
|
|
407
406
|
if (locked) {
|
|
408
407
|
const until = locked.unlock;
|
|
@@ -490,6 +489,7 @@ async function locateInSlices(node, { expectedAtomic, address, viewSecret, spend
|
|
|
490
489
|
const last = witnessSliceIndex(Math.min(toHeight, target));
|
|
491
490
|
let best = null;
|
|
492
491
|
let completed = false;
|
|
492
|
+
let servedTop = null;
|
|
493
493
|
let failure = null;
|
|
494
494
|
for (let index = first; index <= last; index++) {
|
|
495
495
|
let slice;
|
|
@@ -506,6 +506,9 @@ async function locateInSlices(node, { expectedAtomic, address, viewSecret, spend
|
|
|
506
506
|
failure = error;
|
|
507
507
|
break;
|
|
508
508
|
}
|
|
509
|
+
// THE HIGHEST BLOCK THE WITNESS ACTUALLY SERVED. A newer tip can arrive inside the last slice; the caller
|
|
510
|
+
// uses this to raise the common target, so a walk that stopped at 115 cannot complete a target of 116.
|
|
511
|
+
servedTop = servedTop === null ? slice.to : Math.max(servedTop, slice.to);
|
|
509
512
|
for (const block of slice.blocks) {
|
|
510
513
|
// THE SLICE IS A FIXED WINDOW; THE SWAP STARTS AT `fromHeight`. Blocks before the birth height may contain
|
|
511
514
|
// an earlier transfer to the same address, and counting them would make the slice walk disagree with the
|
|
@@ -526,17 +529,13 @@ async function locateInSlices(node, { expectedAtomic, address, viewSecret, spend
|
|
|
526
529
|
if (!best || score > best.score || (score === best.score && amountAtomic > best.amountAtomic)) best = candidate;
|
|
527
530
|
}
|
|
528
531
|
}
|
|
529
|
-
// THE WHOLE SLICE WAS READ. A perfect candidate
|
|
530
|
-
// the
|
|
531
|
-
//
|
|
532
|
-
//
|
|
533
|
-
if (best && best.score === 7) {
|
|
534
|
-
completed = slice.to >= target;
|
|
535
|
-
break;
|
|
536
|
-
}
|
|
532
|
+
// THE WHOLE SLICE WAS READ. A perfect candidate does not end the walk: a later slice can contain a newer tip,
|
|
533
|
+
// and the witness must still prove it reached the common target. Completion is judged by the LAST BLOCK the
|
|
534
|
+
// witness actually served, not by the slice index: a witness can stop inside the same 20-block window as the
|
|
535
|
+
// target and still be behind it.
|
|
537
536
|
if (index === last) completed = slice.to >= target;
|
|
538
537
|
}
|
|
539
|
-
return { located: best, completed, failure };
|
|
538
|
+
return { located: best, completed, servedTop, failure };
|
|
540
539
|
}
|
|
541
540
|
|
|
542
541
|
/**
|
|
@@ -612,9 +611,7 @@ export async function verifyArrivalShadow(request) {
|
|
|
612
611
|
highestTop = highestTop === null ? top : Math.max(highestTop, top);
|
|
613
612
|
readable.push({ node, top, entry });
|
|
614
613
|
}
|
|
615
|
-
|
|
616
|
-
let completed = false;
|
|
617
|
-
const completedWitnessOperators = new Set();
|
|
614
|
+
const walkResults = [];
|
|
618
615
|
for (const { node, top, entry } of readable) {
|
|
619
616
|
const targetTop = highestTop === null ? top : Math.max(top, highestTop);
|
|
620
617
|
try {
|
|
@@ -623,39 +620,55 @@ export async function verifyArrivalShadow(request) {
|
|
|
623
620
|
targetTop,
|
|
624
621
|
nowSec, network, fetchImpl, timeoutMs,
|
|
625
622
|
});
|
|
626
|
-
|
|
627
|
-
if (found.completed) completedWitnessOperators.add(node.operator || node.url);
|
|
628
|
-
if (found.failure) {
|
|
629
|
-
failed.push(failureOf(found.failure, node));
|
|
630
|
-
entry.state = "error";
|
|
631
|
-
} else if (!found.completed) entry.state = found.located ? "partial" : "behind";
|
|
632
|
-
if (found.located) {
|
|
633
|
-
observations.push({
|
|
634
|
-
operator: node.operator || node.url, url: node.url, seen: true, completed: found.completed,
|
|
635
|
-
txid: found.located.txid, height: found.located.height, blockHash: found.located.blockHash,
|
|
636
|
-
amountAtomic: found.located.amountAtomic.toString(), locked: found.located.locked === true,
|
|
637
|
-
});
|
|
638
|
-
if (!located || found.located.score > located.score) {
|
|
639
|
-
located = found.located;
|
|
640
|
-
located.operator = node.operator;
|
|
641
|
-
located.url = node.url;
|
|
642
|
-
}
|
|
643
|
-
} else if (found.completed) {
|
|
644
|
-
observations.push({ operator: node.operator || node.url, url: node.url, seen: false, completed: true,
|
|
645
|
-
txid: null, height: null, blockHash: null, amountAtomic: null, locked: null });
|
|
646
|
-
}
|
|
623
|
+
walkResults.push({ node, top, entry, found });
|
|
647
624
|
} catch (error) {
|
|
648
625
|
entry.state = "error";
|
|
649
626
|
failed.push(failureOf(error, node));
|
|
650
627
|
}
|
|
651
628
|
}
|
|
652
629
|
|
|
630
|
+
// THE TARGET CAN MOVE DURING THE WALK. A witness may serve a tip newer than every `get_info` top, and the
|
|
631
|
+
// parser accepts it; the earlier target would let the other witnesses complete against a block they never read.
|
|
632
|
+
// Raise the target to the highest served tip and judge completion again, after every walk.
|
|
633
|
+
for (const { found } of walkResults) {
|
|
634
|
+
if (found.servedTop === null || found.servedTop === undefined) continue;
|
|
635
|
+
highestTop = highestTop === null ? found.servedTop : Math.max(highestTop, found.servedTop);
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
let located = null;
|
|
639
|
+
let completed = false;
|
|
640
|
+
const completedWitnessOperators = new Set();
|
|
641
|
+
for (const { node, entry, found } of walkResults) {
|
|
642
|
+
const finalCompleted = Boolean(found.completed && found.servedTop !== null
|
|
643
|
+
&& highestTop !== null && found.servedTop >= highestTop);
|
|
644
|
+
if (found.failure) {
|
|
645
|
+
failed.push(failureOf(found.failure, node));
|
|
646
|
+
entry.state = "error";
|
|
647
|
+
} else {
|
|
648
|
+
entry.state = finalCompleted ? "ok" : (found.located ? "partial" : "behind");
|
|
649
|
+
}
|
|
650
|
+
completed = completed || finalCompleted;
|
|
651
|
+
if (finalCompleted) completedWitnessOperators.add(node.operator || node.url);
|
|
652
|
+
if (found.located) {
|
|
653
|
+
observations.push({
|
|
654
|
+
operator: node.operator || node.url, url: node.url, seen: true, completed: finalCompleted,
|
|
655
|
+
txid: found.located.txid, height: found.located.height, blockHash: found.located.blockHash,
|
|
656
|
+
amountAtomic: found.located.amountAtomic.toString(), locked: found.located.locked === true,
|
|
657
|
+
});
|
|
658
|
+
if (!located || found.located.score > located.score) {
|
|
659
|
+
located = found.located;
|
|
660
|
+
located.operator = node.operator;
|
|
661
|
+
located.url = node.url;
|
|
662
|
+
}
|
|
663
|
+
} else if (finalCompleted) {
|
|
664
|
+
observations.push({ operator: node.operator || node.url, url: node.url, seen: false, completed: true,
|
|
665
|
+
txid: null, height: null, blockHash: null, amountAtomic: null, locked: null });
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
|
|
653
669
|
if (!located) failed.push(...staleWitnesses);
|
|
654
670
|
const completedOperators = [...completedWitnessOperators];
|
|
655
671
|
const independentOperators = completedOperators.filter((operator) => String(operator).toLowerCase() !== "ninsei");
|
|
656
|
-
const required = 2;
|
|
657
|
-
const witnessQuorum = { required, completed: completedOperators, independent: independentOperators,
|
|
658
|
-
ok: (network === "mainnet" ? independentOperators.length : completedOperators.length) >= required };
|
|
659
672
|
|
|
660
673
|
// ONE OPINION PER OPERATOR, THEN COMPARE THE OPINIONS. A second instance of the same operator may repeat the
|
|
661
674
|
// first, but it may not silently contradict it; a different operator that reports another block, amount or
|
|
@@ -697,6 +710,12 @@ export async function verifyArrivalShadow(request) {
|
|
|
697
710
|
const field = observationField(representatives[0], representatives[i]);
|
|
698
711
|
if (field) witnessDisagreements.push({ operators: [representatives[0].operator, representatives[i].operator], field });
|
|
699
712
|
}
|
|
713
|
+
// A QUORUM OF WALKERS IS NOT A QUORUM OF ANSWERS. Compute this after the witness-to-witness comparison: two
|
|
714
|
+
// completed operators that disagree have not agreed on anything, even though each reached the target.
|
|
715
|
+
const required = 2;
|
|
716
|
+
const witnessQuorum = { required, completed: completedOperators, independent: independentOperators,
|
|
717
|
+
ok: (network === "mainnet" ? independentOperators.length : completedOperators.length) >= required
|
|
718
|
+
&& witnessDisagreements.length === 0 };
|
|
700
719
|
const witnessEvidence = { observations: representatives, disagreements: witnessDisagreements };
|
|
701
720
|
|
|
702
721
|
const witness = located
|
|
@@ -734,6 +753,7 @@ export async function verifyArrivalShadow(request) {
|
|
|
734
753
|
witnessDisagreements.push({ operators: [observation.operator], field: "amountAtomic", against: "exact" });
|
|
735
754
|
}
|
|
736
755
|
}
|
|
756
|
+
if (checked.some((entry) => entry.state !== "ok")) add("witness:not-completed");
|
|
737
757
|
if (witnessDisagreements.length) add("witness:disagreement");
|
|
738
758
|
agrees = problems.length === 0;
|
|
739
759
|
} else if (located) {
|