@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/quotes.mjs
CHANGED
|
@@ -21,8 +21,8 @@ import * as engine from "./engine.mjs";
|
|
|
21
21
|
import { orderQuoteMissingFields, recoverOrderQuoteKey } from "./quoteEip712.mjs";
|
|
22
22
|
import { claimGasGiftWei } from "../engine/evm/claimGas.js";
|
|
23
23
|
import { parseXmr } from "../engine/core/xmrAmount.js";
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
24
|
+
import { takerHalvesV2, recoverySaltOf } from "./recovery-key.mjs";
|
|
25
|
+
import { acceptCounterpartyChunked, buildOwnSideFromHalvesChunked, jointAddress } from "./order.mjs";
|
|
26
26
|
import { requestFirmQuote } from "./relayFirmClient.mjs";
|
|
27
27
|
// THE CHAIN READ NEEDED TO ASK THE REGISTRY WHO OWNS THE KEY. The selector is COMPUTED from the signature, not
|
|
28
28
|
// remembered: a single wrong hex digit would call another function and return a zero address - and a zero
|
|
@@ -52,6 +52,25 @@ const addressFromWord = (raw) => {
|
|
|
52
52
|
return h.length >= 40 ? "0x" + h.slice(-40).toLowerCase() : null;
|
|
53
53
|
};
|
|
54
54
|
|
|
55
|
+
// THE CASHIER IS THE NETWORK'S VAULT, NOT A FIELD THE MAKER MAY CHOOSE. The escrow binds it at birth, but the
|
|
56
|
+
// client must refuse an answer before it funds or sends XMR: a look-alike vault with the canonical runtime and
|
|
57
|
+
// crafted storage would pass the escrow's code check and make every claim revert after the payout.
|
|
58
|
+
const pinnedCashier = (config) => {
|
|
59
|
+
const chain = config && config.settlement && config.settlement.chain;
|
|
60
|
+
const value = chain && chain.escrow && chain.escrow.cashier;
|
|
61
|
+
return typeof value === "string" && /^0x[0-9a-fA-F]{40}$/.test(value) ? value.toLowerCase() : null;
|
|
62
|
+
};
|
|
63
|
+
const requirePinnedCashier = (quote, step, config) => {
|
|
64
|
+
const chain = config && config.settlement && config.settlement.chain;
|
|
65
|
+
const pin = pinnedCashier(config);
|
|
66
|
+
// A caller without a network profile has nothing to compare against. A profile that names a chain but no vault
|
|
67
|
+
// is a broken profile, not a free pass: refuse it before a quote can be funded.
|
|
68
|
+
if (!pin && !chain) return;
|
|
69
|
+
const got = String(quote && quote.cashier || "").toLowerCase();
|
|
70
|
+
if (!pin) fail("quote-cashier-mismatch", { step, why: "no-pinned-cashier", got: got || null });
|
|
71
|
+
if (got !== pin) fail("quote-cashier-mismatch", { step, got: got || null, want: pin });
|
|
72
|
+
};
|
|
73
|
+
|
|
55
74
|
const num = (v) => (v === undefined || v === null || v === "" ? null : (Number.isFinite(Number(v)) ? Number(v) : null));
|
|
56
75
|
const pairAsset = (pair) => String(pair || "").split("/")[0].toUpperCase();
|
|
57
76
|
const pairCurrency = (pair) => String(pair || "").split("/")[1] ? String(pair).split("/")[1].toUpperCase() : "";
|
|
@@ -249,6 +268,29 @@ const compactRefusal = (r) => ({ ...compactOffer(r), code: r.code, why: r.why })
|
|
|
249
268
|
* base fee and the same formula; a quote may carry up to twice that estimate (gas moves between the sizing and
|
|
250
269
|
* the check). Zero is the buy side and is always allowed. An unmeasured base fee is a refusal, not a free pass.
|
|
251
270
|
*/
|
|
271
|
+
/**
|
|
272
|
+
* THE PRIORITY FEE OF A BLOCK, FROM ONE RULE. An explicit priority field wins; a plain RPC block may carry only
|
|
273
|
+
* `gasPrice`, so the priority is the part above the base fee. No block or no readable pair means zero - the
|
|
274
|
+
* caller then uses the base fee alone, which is the old, stricter behaviour.
|
|
275
|
+
*/
|
|
276
|
+
const priorityFeeOfBlock = (block) => {
|
|
277
|
+
if (!block || typeof block !== "object") return 0n;
|
|
278
|
+
const explicit = block.priorityFeePerGas !== undefined && block.priorityFeePerGas !== null
|
|
279
|
+
? block.priorityFeePerGas
|
|
280
|
+
: (block.maxPriorityFeePerGas !== undefined && block.maxPriorityFeePerGas !== null
|
|
281
|
+
? block.maxPriorityFeePerGas : null);
|
|
282
|
+
if (explicit !== null) return explicit;
|
|
283
|
+
const base = block.baseFeePerGas !== undefined ? block.baseFeePerGas : block.baseFeeWei;
|
|
284
|
+
if (block.gasPrice === undefined || block.gasPrice === null || base === undefined || base === null) return 0n;
|
|
285
|
+
try {
|
|
286
|
+
const gas = BigInt(block.gasPrice);
|
|
287
|
+
const baseValue = BigInt(base);
|
|
288
|
+
return gas > baseValue ? gas - baseValue : 0n;
|
|
289
|
+
} catch { return 0n; }
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
export const claimPriorityFeeOfBlock = priorityFeeOfBlock;
|
|
293
|
+
|
|
252
294
|
export function claimTipVerdict({ claimTipWei = 0, baseFeeWei = null, priorityFeeWei = 0, factor = 2 } = {}) {
|
|
253
295
|
let tip = 0n;
|
|
254
296
|
try { tip = BigInt(claimTipWei === undefined || claimTipWei === null || claimTipWei === "" ? 0 : claimTipWei); }
|
|
@@ -424,6 +466,7 @@ export function createQuotes({ config, http, now = () => Date.now(), evmCall = n
|
|
|
424
466
|
const ticket = res.body;
|
|
425
467
|
const quote = (ticket.handoff && ticket.handoff.quote) || ticket.quote || null;
|
|
426
468
|
if (!quote || typeof quote !== "object") fail("quote-field-unbound", { step: "order-sell", field: "quote" });
|
|
469
|
+
requirePinnedCashier(quote, "order-sell", config);
|
|
427
470
|
// THE SALE TICKET IS A SIGNED QUOTE, AND IT GETS THE SAME GATES AS `firm`: every field of the signed set,
|
|
428
471
|
// its expiry, the EIP-712 signature and the named key, the registry's provider mapping, the interface's
|
|
429
472
|
// allow-list, and the factory/implementation policy. The one difference is the binding below: a sale has no
|
|
@@ -439,8 +482,11 @@ export function createQuotes({ config, http, now = () => Date.now(), evmCall = n
|
|
|
439
482
|
// milliseconds (Date.now), so exactly ONE boundary is converted - "now", not the quote value itself: one
|
|
440
483
|
// unit for the value, one conversion at the input.
|
|
441
484
|
const nowSec = Math.floor(now() / 1000);
|
|
442
|
-
|
|
443
|
-
|
|
485
|
+
// THE TTL IS MANDATORY AND MUST BE IN THE FUTURE. Zero, a fraction, an unsafe integer and a missing value are
|
|
486
|
+
// not "never expires": the relay path already requires a safe future integer, and a direct quote must not be
|
|
487
|
+
// weaker than the same quote after it crosses the relay.
|
|
488
|
+
if (!Number.isSafeInteger(validUntil) || validUntil <= nowSec) {
|
|
489
|
+
fail("quote-expired", { step: "signature", validUntil: quote.validUntil });
|
|
444
490
|
}
|
|
445
491
|
// RECOVER, THEN MATCH THE NAMED KEY. A signature that does not recover is one refusal; a valid signature
|
|
446
492
|
// that recovers to a DIFFERENT address is another (the quote names a key that did not sign it).
|
|
@@ -601,14 +647,8 @@ export function createQuotes({ config, http, now = () => Date.now(), evmCall = n
|
|
|
601
647
|
const baseFeeWei = block && (block.baseFeePerGas !== undefined ? block.baseFeePerGas : block.baseFeeWei);
|
|
602
648
|
// THE NODE SIZES THE TIP FROM THE GAS PRICE, PRIORITY INCLUDED. The SDK used to pass only the base fee, so an
|
|
603
649
|
// honest L1 tip (or a base fee that dropped between sizing and checking) was refused.
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
try {
|
|
607
|
-
const gas = BigInt(block.gasPrice); const base = BigInt(baseFeeWei);
|
|
608
|
-
priorityFeeWei = gas > base ? gas - base : 0n;
|
|
609
|
-
} catch { priorityFeeWei = 0n; }
|
|
610
|
-
}
|
|
611
|
-
const verdict = claimTipVerdict({ claimTipWei: shownBig, baseFeeWei, priorityFeeWei: priorityFeeWei === null ? 0n : priorityFeeWei });
|
|
650
|
+
const priorityFeeWei = priorityFeeOfBlock(block);
|
|
651
|
+
const verdict = claimTipVerdict({ claimTipWei: shownBig, baseFeeWei, priorityFeeWei });
|
|
612
652
|
if (!verdict.ok) fail(verdict.code, { step: "claimTip", ...verdict });
|
|
613
653
|
}
|
|
614
654
|
return ticket;
|
|
@@ -651,6 +691,7 @@ export function createQuotes({ config, http, now = () => Date.now(), evmCall = n
|
|
|
651
691
|
}
|
|
652
692
|
const body = res.body;
|
|
653
693
|
const quote = body.quote;
|
|
694
|
+
requirePinnedCashier(quote, "order-quote", config);
|
|
654
695
|
// THE MAKER'S VIEW HALF IS OURS, NOT THE NODE'S CHOICE. When the caller supplies it, the quote must carry the
|
|
655
696
|
// same scalar back; otherwise the maker used another half and the joint view key cannot be rebuilt from the key.
|
|
656
697
|
if (viewHalfClaimer !== null) {
|
|
@@ -673,8 +714,11 @@ export function createQuotes({ config, http, now = () => Date.now(), evmCall = n
|
|
|
673
714
|
// milliseconds (Date.now), so exactly ONE boundary is converted - "now", not the quote value itself: one
|
|
674
715
|
// unit for the value, one conversion at the input.
|
|
675
716
|
const nowSec = Math.floor(now() / 1000);
|
|
676
|
-
|
|
677
|
-
|
|
717
|
+
// THE TTL IS MANDATORY AND MUST BE IN THE FUTURE. Zero, a fraction, an unsafe integer and a missing value are
|
|
718
|
+
// not "never expires": the relay path already requires a safe future integer, and a direct quote must not be
|
|
719
|
+
// weaker than the same quote after it crosses the relay.
|
|
720
|
+
if (!Number.isSafeInteger(validUntil) || validUntil <= nowSec) {
|
|
721
|
+
fail("quote-expired", { step: "signature", validUntil: quote.validUntil });
|
|
678
722
|
}
|
|
679
723
|
// RECOVER, THEN MATCH THE NAMED KEY. A signature that does not recover is one refusal; a valid signature
|
|
680
724
|
// that recovers to a DIFFERENT address is another (the quote names a key that did not sign it).
|
|
@@ -813,7 +857,8 @@ export function createQuotes({ config, http, now = () => Date.now(), evmCall = n
|
|
|
813
857
|
let block = null;
|
|
814
858
|
try { block = await evmBlock("latest"); } catch { fail("quote-tip-unchecked", { step: "claimTip", why: "block-read-failed" }); }
|
|
815
859
|
const baseFeeWei = block && (block.baseFeePerGas !== undefined ? block.baseFeePerGas : block.baseFeeWei);
|
|
816
|
-
const
|
|
860
|
+
const priorityFeeWei = priorityFeeOfBlock(block);
|
|
861
|
+
const verdict = claimTipVerdict({ claimTipWei: quote.claimTip, baseFeeWei, priorityFeeWei });
|
|
817
862
|
if (!verdict.ok) fail(verdict.code, { step: "claimTip", ...verdict });
|
|
818
863
|
}
|
|
819
864
|
return quote;
|
|
@@ -839,6 +884,14 @@ export function createQuotes({ config, http, now = () => Date.now(), evmCall = n
|
|
|
839
884
|
const registry = String(features.registry || "").toLowerCase();
|
|
840
885
|
if (!/^0x[0-9a-f]{40}$/.test(maker) || maker === ZERO_ADDRESS) fail("bad-input", { field: "features.provider" });
|
|
841
886
|
if (!/^0x[0-9a-f]{40}$/.test(registry) || registry === ZERO_ADDRESS) fail("bad-input", { field: "features.registry" });
|
|
887
|
+
// THE REGISTRY IS A PROPERTY OF THE NETWORK, NOT OF THE FEATURES THAT ARRIVED WITH THE QUOTE. A relay that
|
|
888
|
+
// names its own registry can authorise its own maker. The pinned value comes from the network config; a
|
|
889
|
+
// network without a pinned registry keeps the old path until it is deployed.
|
|
890
|
+
const pinnedRegistry = config && config.settlement && config.settlement.chain &&
|
|
891
|
+
config.settlement.chain.escrow && config.settlement.chain.escrow.registry;
|
|
892
|
+
if (pinnedRegistry && !sameText(registry, pinnedRegistry)) {
|
|
893
|
+
fail("bad-input", { field: "features.registry", why: "not-the-network-registry" });
|
|
894
|
+
}
|
|
842
895
|
// THE FEATURES' HPKE KEY AND FRAME KEY BELONG TO THE REGISTERED MAKER. Check the registry mapping BEFORE
|
|
843
896
|
// sealing any view material to the HPKE key: a dishonest relay could otherwise hand us its own key, read both
|
|
844
897
|
// view halves and swap in its own node half. The answer's registry check later is not a substitute for this
|
|
@@ -856,7 +909,10 @@ export function createQuotes({ config, http, now = () => Date.now(), evmCall = n
|
|
|
856
909
|
if (!sameText(featureProvider, features.provider)) {
|
|
857
910
|
fail("quote-provider-mismatch", { step: "registry", got: featureProvider, want: features.provider });
|
|
858
911
|
}
|
|
859
|
-
|
|
912
|
+
// THE CLIENT'S OWN ADDRESS IS WHAT THE DENYLIST COVERS. On an ask that is the locker; on a bid the client
|
|
913
|
+
// is the claimer, and testing the maker's locker there checks the wrong party.
|
|
914
|
+
const deniedAddress = side === "bid" ? order.claimer : order.locker;
|
|
915
|
+
if (denylist && typeof deniedAddress === "string" && denylist.has(deniedAddress.toLowerCase())) {
|
|
860
916
|
fail("address-denied", { step: "order-quote" });
|
|
861
917
|
}
|
|
862
918
|
// THE PROVIDER'S ROLE IS PART OF THE SIDE. A caller that names another claimer/locker is not asking
|
|
@@ -889,29 +945,18 @@ export function createQuotes({ config, http, now = () => Date.now(), evmCall = n
|
|
|
889
945
|
: request.recoveryKey && typeof request.recoveryKey.mnemonic === "string" ? request.recoveryKey.mnemonic : null;
|
|
890
946
|
if (!mnemonic) fail("bad-input", { field: "recoveryKey" });
|
|
891
947
|
const saltRequested = request.recoverySalt !== undefined && request.recoverySalt !== null;
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
if (
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
derivation = { kind: "index-v1", index };
|
|
901
|
-
} else {
|
|
902
|
-
if (!order.factory || !/^0x[0-9a-f]{40}$/i.test(String(order.factory))) fail("bad-input", { field: "order.factory" });
|
|
903
|
-
let salt = null;
|
|
904
|
-
try { salt = recoverySaltOf(saltRequested ? request.recoverySalt : order.salt); }
|
|
905
|
-
catch { fail("bad-input", { field: "recoverySalt" }); }
|
|
906
|
-
if (saltRequested) {
|
|
907
|
-
let orderSalt = null;
|
|
908
|
-
try { orderSalt = recoverySaltOf(order.salt); } catch { fail("bad-input", { field: "recoverySalt", why: "order-salt" }); }
|
|
909
|
-
if (salt !== orderSalt) fail("bad-input", { field: "recoverySalt", why: "order-salt" });
|
|
910
|
-
}
|
|
911
|
-
derived = takerHalvesV2({ mnemonic, chainId, factory: order.factory, salt });
|
|
912
|
-
derivation = { kind: "salt-v2", salt };
|
|
948
|
+
if (!order.factory || !/^0x[0-9a-f]{40}$/i.test(String(order.factory))) fail("bad-input", { field: "order.factory" });
|
|
949
|
+
let salt = null;
|
|
950
|
+
try { salt = recoverySaltOf(saltRequested ? request.recoverySalt : order.salt); }
|
|
951
|
+
catch { fail("bad-input", { field: "recoverySalt" }); }
|
|
952
|
+
if (saltRequested) {
|
|
953
|
+
let orderSalt = null;
|
|
954
|
+
try { orderSalt = recoverySaltOf(order.salt); } catch { fail("bad-input", { field: "recoverySalt", why: "order-salt" }); }
|
|
955
|
+
if (salt !== orderSalt) fail("bad-input", { field: "recoverySalt", why: "order-salt" });
|
|
913
956
|
}
|
|
914
|
-
const
|
|
957
|
+
const derived = takerHalvesV2({ mnemonic, chainId, factory: order.factory, salt });
|
|
958
|
+
const derivation = { kind: "salt-v2", salt };
|
|
959
|
+
const own = await buildOwnSideFromHalvesChunked(order, { spendHalf: derived.spendHalf, viewHalf: derived.viewHalf });
|
|
915
960
|
const xa = secp256k1.Point.fromHex(own.side.proof.XA);
|
|
916
961
|
const clientHalf = {
|
|
917
962
|
commitHalf: bytesToHexQ(keccak256(xa.toBytes(false).slice(1))),
|
|
@@ -942,11 +987,12 @@ export function createQuotes({ config, http, now = () => Date.now(), evmCall = n
|
|
|
942
987
|
side,
|
|
943
988
|
});
|
|
944
989
|
const quote = result.quote;
|
|
990
|
+
requirePinnedCashier(quote, "relay", config);
|
|
945
991
|
// THE NODE HALF IS NOT A DECORATION. The answer's proof must stand in THIS order's context and the proven
|
|
946
992
|
// point must be the one the quote commits to. For ask that is the claimer's commitment; for bid the node
|
|
947
993
|
// half is the locker's and carries its own commitment. This is the same engine check the swap path uses.
|
|
948
994
|
const nodeHalf = result.nodeHalf;
|
|
949
|
-
|
|
995
|
+
await acceptCounterpartyChunked({
|
|
950
996
|
context: own.context,
|
|
951
997
|
side: own.side,
|
|
952
998
|
counterparty: side === "ask"
|
|
@@ -1051,7 +1097,8 @@ export function createQuotes({ config, http, now = () => Date.now(), evmCall = n
|
|
|
1051
1097
|
let block = null;
|
|
1052
1098
|
try { block = await evmBlock("latest"); } catch { fail("quote-tip-unchecked", { step: "claimTip", why: "block-read-failed" }); }
|
|
1053
1099
|
const baseFeeWei = block && (block.baseFeePerGas !== undefined ? block.baseFeePerGas : block.baseFeeWei);
|
|
1054
|
-
const
|
|
1100
|
+
const priorityFeeWei = priorityFeeOfBlock(block);
|
|
1101
|
+
const verdict = claimTipVerdict({ claimTipWei: quote.claimTip, baseFeeWei, priorityFeeWei });
|
|
1055
1102
|
if (!verdict.ok) fail(verdict.code, { step: "claimTip", ...verdict });
|
|
1056
1103
|
}
|
|
1057
1104
|
// THE SIGNED XMR AMOUNT TRAVELS WITH THE ORDER TERMS. `swaps.start` records its order as given, and the
|
|
@@ -1060,19 +1107,41 @@ export function createQuotes({ config, http, now = () => Date.now(), evmCall = n
|
|
|
1060
1107
|
const signedAtomic = result.orderQuote && result.orderQuote.xmrAmount !== undefined && result.orderQuote.xmrAmount !== null
|
|
1061
1108
|
? String(result.orderQuote.xmrAmount) : null;
|
|
1062
1109
|
if (!signedAtomic) fail("quote-field-unbound", { step: "xmrAmount", field: "orderQuote.xmrAmount" });
|
|
1110
|
+
// THE ANSWER IS ALSO A START REQUEST. `swaps.start` reads the paying asset from the quote; the relay answer
|
|
1111
|
+
// carried only the signed order terms, so a caller that followed the guide reached `balance-unchecked`.
|
|
1112
|
+
// The asset is display metadata here; the signed `orderQuote` is unchanged.
|
|
1113
|
+
const marketAsset = request.market && String(request.market).includes(":")
|
|
1114
|
+
? String(request.market).split(":").slice(1).join(":") : null;
|
|
1115
|
+
const asset = String(order.asset || marketAsset || "").trim();
|
|
1116
|
+
const startQuote = { ...quote, viewHalfClaimer: derived.makerViewHalf, xmrAmount: signedAtomic,
|
|
1117
|
+
...(asset ? { asset, token: asset.toLowerCase() } : {}),
|
|
1118
|
+
// A STABLE ID FOR THE PENDING-FUNDING RECORD. The signed nonce is the one value every relay answer carries.
|
|
1119
|
+
...(quote.nonce !== undefined && quote.nonce !== null ? { id: String(quote.nonce) } : {}) };
|
|
1120
|
+
const startCounterparty = {
|
|
1121
|
+
proof: nodeHalf.proof,
|
|
1122
|
+
edPointClaimer: side === "ask" ? quote.edPointClaimer : nodeHalf.edPoint,
|
|
1123
|
+
commitHalfClaimer: side === "ask" ? quote.commitHalfClaimer : nodeHalf.commitHalf,
|
|
1124
|
+
viewHalfClaimer: derived.makerViewHalf,
|
|
1125
|
+
viewPoint: side === "ask" ? result.edViewPointClaimer : result.edViewPointLocker,
|
|
1126
|
+
};
|
|
1127
|
+
// ONE ORDER OBJECT, TWO REFERENCES. `order` and `startRequest.order` must not drift apart.
|
|
1128
|
+
const startOrder = { ...order, xmrAmount: signedAtomic };
|
|
1063
1129
|
return {
|
|
1064
1130
|
...result,
|
|
1065
|
-
quote:
|
|
1066
|
-
order:
|
|
1131
|
+
quote: startQuote,
|
|
1132
|
+
order: startOrder,
|
|
1133
|
+
// THE CALLER ADDS ITS WALLET, `receiveTo` AND THE HEIGHT; everything the relay can know is here.
|
|
1134
|
+
startRequest: {
|
|
1135
|
+
quote: startQuote,
|
|
1136
|
+
order: startOrder,
|
|
1137
|
+
orderQuote: result.orderQuote,
|
|
1138
|
+
counterparty: startCounterparty,
|
|
1139
|
+
recoveryKey: request.recoveryKey,
|
|
1140
|
+
recoverySalt: order.salt,
|
|
1141
|
+
},
|
|
1067
1142
|
// THE SHAPE `swaps.start` TAKES: the proof and the claimer commitment travel with the view half, so a
|
|
1068
1143
|
// caller can pass this object as `counterparty` without rebuilding the relay fields.
|
|
1069
|
-
counterparty:
|
|
1070
|
-
proof: nodeHalf.proof,
|
|
1071
|
-
edPointClaimer: side === "ask" ? quote.edPointClaimer : nodeHalf.edPoint,
|
|
1072
|
-
commitHalfClaimer: side === "ask" ? quote.commitHalfClaimer : nodeHalf.commitHalf,
|
|
1073
|
-
viewHalfClaimer: derived.makerViewHalf,
|
|
1074
|
-
viewPoint: side === "ask" ? result.edViewPointClaimer : result.edViewPointLocker,
|
|
1075
|
-
},
|
|
1144
|
+
counterparty: startCounterparty,
|
|
1076
1145
|
viewHalfClaimer: derived.makerViewHalf,
|
|
1077
1146
|
viewHalfPoint: derived.makerViewPoint,
|
|
1078
1147
|
jointAddress: oneTimeAddress.address,
|
package/src/record.mjs
CHANGED
|
@@ -44,11 +44,11 @@ export function ownSide(order = null, known = null) {
|
|
|
44
44
|
* edPointLocker, edViewPointLocker). The counterparty's half cannot and need not be put in: it will come from
|
|
45
45
|
* the order.
|
|
46
46
|
*/
|
|
47
|
-
export function createRecord(input, { order = null, side: knownSide = null } = {}) {
|
|
47
|
+
export function createRecord(input, { order = null, side: knownSide = null, store = null } = {}) {
|
|
48
48
|
if (!input || typeof input !== "object") throw new SdkError("bad-input", { field: "input" });
|
|
49
49
|
const side = knownSide || ownSide(order);
|
|
50
50
|
let swap = null;
|
|
51
|
-
try { swap = engine.swap.createSwap(input); } catch { throw new SdkError("bad-input", { field: "input" }); }
|
|
51
|
+
try { swap = engine.swap.createSwap(input, store); } catch { throw new SdkError("bad-input", { field: "input" }); }
|
|
52
52
|
const escrow = { ...(swap.escrow || {}),
|
|
53
53
|
// THE HALVES ARE A HEX STRING (a BigInt does not survive JSON), the points are in canonical form: that is how
|
|
54
54
|
// both the slot check against the chain and the address check read them.
|
|
@@ -74,6 +74,6 @@ export function createRecord(input, { order = null, side: knownSide = null } = {
|
|
|
74
74
|
// (www/js/ui/views/confirm.js: swap.orderQuoteId = flow.quoteId).
|
|
75
75
|
const quoteId = input && input.orderQuoteId;
|
|
76
76
|
if (quoteId !== undefined && quoteId !== null && quoteId !== "") record.orderQuoteId = quoteId;
|
|
77
|
-
try { engine.swap.saveSwap(record); } catch { throw new SdkError("storage-unavailable", { step: "save-swap" }); }
|
|
77
|
+
try { engine.swap.saveSwap(record, store); } catch { throw new SdkError("storage-unavailable", { step: "save-swap" }); }
|
|
78
78
|
return { swap: record, side, missing: ["counterparty-half"], nextStep: "order" };
|
|
79
79
|
}
|