@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/engine/evm/index.js
CHANGED
|
@@ -38,10 +38,8 @@ export * from "./permit.js";
|
|
|
38
38
|
// THE ASYNCHRONOUS ROUTE, EXECUTED - through the same engine seam as the decision that chooses it. The page reaches
|
|
39
39
|
// it through the bridge; the SDK carries the same module in its engine mirror (tools/build-sdk-engine.mjs).
|
|
40
40
|
export * from "./asyncRoute.js";
|
|
41
|
-
|
|
42
|
-
//
|
|
43
|
-
// so the page and the SDK carry one implementation each.
|
|
44
|
-
export * from "./asyncLegs.js";
|
|
41
|
+
// THE EXECUTOR IS THE PACKAGE'S PROVIDER LAYER (src/legs/cow.mjs and its siblings). The generated mirror that
|
|
42
|
+
// used to execute the route here carried a second submit/status path; it was removed with the order worker.
|
|
45
43
|
|
|
46
44
|
// currentProvider - the wallet provider goes OUT to the SDK core (evm-wallet.mjs) so signing uses the same
|
|
47
45
|
// key as the page. Screens do not need it; they read status()/isConnected().
|
package/engine/evm/session.js
CHANGED
|
@@ -109,7 +109,7 @@ async function loadLib() {
|
|
|
109
109
|
if (!lib) {
|
|
110
110
|
// A dynamic import of our own file: CSP script-src 'self' allows it,
|
|
111
111
|
// and the 2 MB bundle loads only when the user actually presses Connect.
|
|
112
|
-
lib = await import("../../assets/vendors/walletconnect/wc-browser.js?v=
|
|
112
|
+
lib = await import("../../assets/vendors/walletconnect/wc-browser.js?v=fb64f27c");
|
|
113
113
|
}
|
|
114
114
|
return lib;
|
|
115
115
|
}
|
|
@@ -654,11 +654,11 @@ export async function switchChain(chainSlugOrId) {
|
|
|
654
654
|
//
|
|
655
655
|
// Needed to learn the escrow address BEFORE it is created (factory.predict) and to read state
|
|
656
656
|
// (escrow.status) while polling. Requires no keys, asks the wallet nothing - only the provider.
|
|
657
|
-
export async function readContract({ to, data } = {}) {
|
|
657
|
+
export async function readContract({ to, data, block = "latest" } = {}) {
|
|
658
658
|
if (!provider) throw new Error("wallet not connected: nothing to read the contract with");
|
|
659
659
|
if (!to) throw new Error("no contract address given");
|
|
660
660
|
if (!data) throw new Error("no call data given");
|
|
661
|
-
const result = await provider.request({ method: "eth_call", params: [{ to, data }, "latest"] });
|
|
661
|
+
const result = await provider.request({ method: "eth_call", params: [{ to, data }, block || "latest"] });
|
|
662
662
|
if (typeof result !== "string" || !result.startsWith("0x")) {
|
|
663
663
|
throw new Error("unexpected answer to a contract call: " + String(result).slice(0, 60));
|
|
664
664
|
}
|
package/engine/monero/scan.js
CHANGED
|
@@ -144,17 +144,72 @@ export function derivedOutputKey(derivation, outputIndex, spendPubHex) {
|
|
|
144
144
|
|
|
145
145
|
// Helper: the tx public key sits in the transaction extra, tag 0x01, 32 bytes. We read extra as is - the same
|
|
146
146
|
// parse the wallet does. extra arrives from the node as a BYTE ARRAY (not hex), so both forms are accepted.
|
|
147
|
-
|
|
147
|
+
//
|
|
148
|
+
// MONERO'S EXTRA IS A TAGGED SEQUENCE, NOT A FIXED LAYOUT. The tags we must know here:
|
|
149
|
+
// 0x00 padding - a run of zero bytes (the tag itself is one of them), no length field;
|
|
150
|
+
// 0x01 public key - 32 bytes;
|
|
151
|
+
// 0x02 nonce - varint length, then that many bytes;
|
|
152
|
+
// 0x03 merge mining - a length-prefixed string holding varint depth + 32-byte hash;
|
|
153
|
+
// 0x04 additional - varint count, then count * 32-byte public keys, ONE PER OUTPUT INDEX.
|
|
154
|
+
// The old parser treated 0x00 as an additional key and skipped it with `1 + b[i+1]`, and it stopped at 0x04.
|
|
155
|
+
// A subaddress payment in a mixed transaction then looked absent: the main key does not derive that output.
|
|
156
|
+
function readExtraVarint(bytes, at) {
|
|
157
|
+
let value = 0n;
|
|
158
|
+
let shift = 0n;
|
|
159
|
+
let i = at;
|
|
160
|
+
for (let count = 0; count < 10 && i < bytes.length; count++) {
|
|
161
|
+
const byte = bytes[i++];
|
|
162
|
+
value |= BigInt(byte & 0x7f) << shift;
|
|
163
|
+
if ((byte & 0x80) === 0) return { value, next: i };
|
|
164
|
+
shift += 7n;
|
|
165
|
+
}
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** The transaction keys in `extra`: the main key(s) and the per-output additional keys (tag 0x04). */
|
|
170
|
+
export function txKeysFromExtra(extra) {
|
|
148
171
|
const b = Array.isArray(extra) ? Uint8Array.from(extra) : hexToBytes(extra);
|
|
172
|
+
const txPublicKeys = [];
|
|
173
|
+
const additionalPublicKeys = [];
|
|
149
174
|
let i = 0;
|
|
150
175
|
while (i < b.length) {
|
|
151
|
-
const tag = b[i];
|
|
152
|
-
if (tag ===
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
176
|
+
const tag = b[i++];
|
|
177
|
+
if (tag === 0x00) {
|
|
178
|
+
// Padding is a run of zeros; the next non-zero byte is the next tag (or the end).
|
|
179
|
+
while (i < b.length && b[i] === 0x00) i++;
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
if (tag === 0x01) {
|
|
183
|
+
if (i + 32 > b.length) break;
|
|
184
|
+
txPublicKeys.push(bytesToHex(b.subarray(i, i + 32)));
|
|
185
|
+
i += 32;
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
if (tag === 0x02 || tag === 0x03) {
|
|
189
|
+
const size = readExtraVarint(b, i);
|
|
190
|
+
if (!size || size.value > BigInt(b.length - size.next)) break;
|
|
191
|
+
i = size.next + Number(size.value);
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
if (tag === 0x04) {
|
|
195
|
+
const count = readExtraVarint(b, i);
|
|
196
|
+
if (!count || count.value > BigInt(Math.floor((b.length - count.next) / 32))) break;
|
|
197
|
+
i = count.next;
|
|
198
|
+
for (let n = 0; n < Number(count.value); n++) {
|
|
199
|
+
additionalPublicKeys.push(bytesToHex(b.subarray(i, i + 32)));
|
|
200
|
+
i += 32;
|
|
201
|
+
}
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
// An unknown tag is not a guess: stop before it and use only what was parsed unambiguously.
|
|
205
|
+
break;
|
|
156
206
|
}
|
|
157
|
-
return
|
|
207
|
+
return { txPublicKeys, additionalPublicKeys };
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** The first tx public key in `extra`, or null. Kept for callers that only need the primary key. */
|
|
211
|
+
export function txPublicKeyFromExtra(extra) {
|
|
212
|
+
return txKeysFromExtra(extra).txPublicKeys[0] || null;
|
|
158
213
|
}
|
|
159
214
|
|
|
160
215
|
// Amount and mask decryption. THE ENCODING IS CHOSEN BY THE RingCT TYPE, not by a boolean:
|
|
@@ -201,20 +256,32 @@ export function decodeMask(ecdhMaskHex, scalarLE, rctType) {
|
|
|
201
256
|
}
|
|
202
257
|
|
|
203
258
|
// MAIN: parse a transaction and return OUR outputs (their indices, keys and amounts).
|
|
204
|
-
// txView - { txPublicKey, vout: [{key, index}], ecdhAmounts: [...], ecdhMasks: [...], outPk: [...], rctVersion }
|
|
205
|
-
|
|
206
|
-
|
|
259
|
+
// txView - { txPublicKey(s), additionalPublicKeys, vout: [{key, index}], ecdhAmounts: [...], ecdhMasks: [...], outPk: [...], rctVersion }
|
|
260
|
+
//
|
|
261
|
+
// ADDITIONAL KEYS ARE PER OUTPUT, NOT PER TRANSACTION. A transaction paying several subaddresses carries tag 0x04:
|
|
262
|
+
// key i belongs to output i. Trying only the main key misses those outputs; trying every additional key against
|
|
263
|
+
// every output would be wrong in the other direction and can match another recipient's output. The main key is
|
|
264
|
+
// tried first, then this output's own additional key, exactly as the wallet does.
|
|
265
|
+
export function findOurOutputs({ txPublicKey = null, txPublicKeys = null, additionalPublicKeys = [], viewSecretHex, spendPubHex, outputs, ecdhAmounts = [], ecdhMasks = [], outPk = [], rctVersion = 2 }) {
|
|
266
|
+
const primaryKeys = Array.isArray(txPublicKeys) ? txPublicKeys.filter(Boolean)
|
|
267
|
+
: (txPublicKey ? [txPublicKey] : []);
|
|
268
|
+
const additional = Array.isArray(additionalPublicKeys) ? additionalPublicKeys : [];
|
|
269
|
+
if (!primaryKeys.length && !additional.length) throw new Error("the transaction has no public key (extra tag 0x01/0x04) - nothing to parse");
|
|
207
270
|
// The key form is tried EXPLICITLY; the winner's name goes up so the log shows what was used. If none matched,
|
|
208
271
|
// the first meaningful form is returned, not nothing.
|
|
209
272
|
const usable = viewSecretCandidates(viewSecretHex).filter(([, v]) => v !== null);
|
|
210
273
|
const first = usable[0] || ["unparsed", null];
|
|
211
274
|
for (const [form, secret] of usable) {
|
|
212
|
-
const
|
|
275
|
+
const primaryDerivations = primaryKeys.map((key) => keyDerivation(key, secret));
|
|
213
276
|
const found = [];
|
|
214
277
|
for (const o of outputs) {
|
|
215
|
-
|
|
216
|
-
const
|
|
217
|
-
if (
|
|
278
|
+
// The main keys first, then only THIS output's additional key.
|
|
279
|
+
const candidates = primaryDerivations.slice();
|
|
280
|
+
if (additional[o.index]) candidates.push(keyDerivation(additional[o.index], secret));
|
|
281
|
+
for (const derivation of candidates) {
|
|
282
|
+
const scalar = hashToScalar(derivation, varint(o.index));
|
|
283
|
+
const derived = derivedOutputKey(derivation, o.index, spendPubHex);
|
|
284
|
+
if (derived.toLowerCase() !== String(o.key).toLowerCase()) continue;
|
|
218
285
|
// The amount decryption uses THIS output's SCALAR, least-significant first.
|
|
219
286
|
const amount = ecdhAmounts[o.index] ? decodeAmount(ecdhAmounts[o.index], scalarToBytesLE(scalar), rctVersion) : null;
|
|
220
287
|
// THE COMMITMENT CHECK: outPk[i] = mask*G + amount*H. A node can flip a bit of the encrypted amount
|
|
@@ -230,13 +297,14 @@ export function findOurOutputs({ txPublicKey, viewSecretHex, spendPubHex, output
|
|
|
230
297
|
amountVerified = amountMaskCommitment(amount, mask).toLowerCase() === String(outPk[o.index]).replace(/^0x/, "").toLowerCase();
|
|
231
298
|
} catch { amountVerified = false; }
|
|
232
299
|
}
|
|
233
|
-
found.push({ index: o.index, key: o.key, amountAtomic: amount, maskAtomic: mask, amountVerified });
|
|
300
|
+
found.push({ index: o.index, key: o.key, amountAtomic: amount, maskAtomic: mask, amountVerified, derivation: bytesToHex(derivation) });
|
|
301
|
+
break; // one derivation per output; a later key cannot make it ours twice
|
|
234
302
|
}
|
|
235
303
|
}
|
|
236
|
-
if (found.length) return { derivation:
|
|
304
|
+
if (found.length) return { derivation: found[0].derivation, outputs: found, viewKeyForm: form };
|
|
237
305
|
}
|
|
238
306
|
return {
|
|
239
|
-
derivation: first[1] === null ? null : bytesToHex(keyDerivation(
|
|
307
|
+
derivation: first[1] === null || !primaryKeys.length ? null : bytesToHex(keyDerivation(primaryKeys[0], first[1])),
|
|
240
308
|
outputs: [],
|
|
241
309
|
viewKeyForm: first[0],
|
|
242
310
|
};
|
|
@@ -260,10 +328,15 @@ const baseUrl = (value) => {
|
|
|
260
328
|
return out;
|
|
261
329
|
};
|
|
262
330
|
|
|
263
|
-
export async function fetchBlock(daemonUrl, height, fetchImpl = globalThis.fetch) {
|
|
331
|
+
export async function fetchBlock(daemonUrl, height, fetchImpl = globalThis.fetch, timeoutMs = 8000) {
|
|
332
|
+
// THE DEADLINE COVERS THE BODY, NOT ONLY THE HEADERS. Without a signal a daemon that sends `{` and stops holds
|
|
333
|
+
// the whole scan forever.
|
|
334
|
+
const signal = typeof AbortSignal !== "undefined" && AbortSignal.timeout
|
|
335
|
+
? AbortSignal.timeout(Math.max(1, Number(timeoutMs) || 8000)) : undefined;
|
|
264
336
|
const res = await fetchImpl(`${baseUrl(daemonUrl)}/json_rpc`, {
|
|
265
337
|
method: "POST", headers: { "Content-Type": "application/json" },
|
|
266
338
|
body: JSON.stringify({ jsonrpc: "2.0", id: "block", method: "get_block", params: { height } }),
|
|
339
|
+
signal,
|
|
267
340
|
});
|
|
268
341
|
const j = await res.json();
|
|
269
342
|
// A BUSY ANSWER IS NOT AN EMPTY BLOCK. The daemon answers BUSY while it is still indexing; a reader that treats
|
|
@@ -281,11 +354,14 @@ export async function fetchBlock(daemonUrl, height, fetchImpl = globalThis.fetch
|
|
|
281
354
|
|
|
282
355
|
// Transactions by hash list. We hit the PATH /get_transactions, not /json_rpc: over JSON-RPC this method
|
|
283
356
|
// silently returns empty, which looks like "no transactions".
|
|
284
|
-
export async function fetchTransactions(daemonUrl, hashes, fetchImpl = globalThis.fetch) {
|
|
357
|
+
export async function fetchTransactions(daemonUrl, hashes, fetchImpl = globalThis.fetch, timeoutMs = 8000) {
|
|
285
358
|
if (!hashes.length) return [];
|
|
359
|
+
const signal = typeof AbortSignal !== "undefined" && AbortSignal.timeout
|
|
360
|
+
? AbortSignal.timeout(Math.max(1, Number(timeoutMs) || 8000)) : undefined;
|
|
286
361
|
const res = await fetchImpl(`${baseUrl(daemonUrl)}/get_transactions`, {
|
|
287
362
|
method: "POST", headers: { "Content-Type": "application/json" },
|
|
288
363
|
body: JSON.stringify({ txs_hashes: hashes, decode_as_json: true }),
|
|
364
|
+
signal,
|
|
289
365
|
});
|
|
290
366
|
const j = await res.json();
|
|
291
367
|
// A BUSY ANSWER IS NOT AN EMPTY BLOCK. The daemon says BUSY while it is still indexing; returning [] would turn
|
|
@@ -327,8 +403,10 @@ export async function fetchTransactions(daemonUrl, hashes, fetchImpl = globalThi
|
|
|
327
403
|
// is taken as a number, LE-hex or BE-hex. The result carries viewKeyForm: the form name that matched.
|
|
328
404
|
export function matchTransaction(tx, watched, { height = null, tipHeight = null, nowSec = null } = {}) {
|
|
329
405
|
const out = [];
|
|
330
|
-
|
|
331
|
-
|
|
406
|
+
// BOTH KEY LISTS ARE PART OF THE TRANSACTION. A subaddress output carries its own key under tag 0x04; using only
|
|
407
|
+
// `txPublicKeyFromExtra` drops exactly those outputs.
|
|
408
|
+
const keys = txKeysFromExtra(tx.extra);
|
|
409
|
+
if (!keys.txPublicKeys.length && !keys.additionalPublicKeys.length) return out;
|
|
332
410
|
// WHETHER THE OUTPUT IS LOCKED IS DECIDED HERE, ONCE PER TRANSACTION: all its outputs carry one unlock_time.
|
|
333
411
|
// A normal transaction (unlock_time = 0) goes as before; the height comes from the block holding the transfer.
|
|
334
412
|
const blockHeight = height === null || height === undefined ? (tx.block_height ?? null) : height;
|
|
@@ -346,7 +424,8 @@ export function matchTransaction(tx, watched, { height = null, tipHeight = null,
|
|
|
346
424
|
const rctVersion = (tx.rct_signatures || {}).type || 2;
|
|
347
425
|
for (const w of watched) {
|
|
348
426
|
const r = findOurOutputs({
|
|
349
|
-
|
|
427
|
+
txPublicKeys: keys.txPublicKeys, additionalPublicKeys: keys.additionalPublicKeys,
|
|
428
|
+
viewSecretHex: w.viewSecret, spendPubHex: w.spendPub,
|
|
350
429
|
outputs, ecdhAmounts, ecdhMasks, outPk, rctVersion: Number(rctVersion) || 1,
|
|
351
430
|
});
|
|
352
431
|
if (r.outputs.length) out.push({ address: w.address, index: w.index ?? null, outputs: r.outputs, derivation: r.derivation, viewKeyForm: r.viewKeyForm, unlockTime: Number(tx.unlock_time) || 0, unlock });
|
|
@@ -20,8 +20,8 @@ import { swapAddressFromHalves, watchViewSeedHex } from "../monero/swapKeys.js";
|
|
|
20
20
|
// carries HALVES, and has NO full spend key: each side has only its half, the second is revealed on chain at ETH
|
|
21
21
|
// claim. So a v3 file builds a VIEWING wallet; spending becomes possible only after the reveal.
|
|
22
22
|
//
|
|
23
|
-
// deps is needed for testability:
|
|
24
|
-
//
|
|
23
|
+
// deps is needed for testability: the SDK passes its own primitives here, and tests pass their own. There is no
|
|
24
|
+
// second browser bundle for this branch.
|
|
25
25
|
export async function restoreWalletFromPayload(payload, deps = {}) {
|
|
26
26
|
const { warnings } = validatePayload(payload);
|
|
27
27
|
const m = payload.moneroWallet;
|
|
@@ -70,14 +70,14 @@ export async function restoreFromHalves(payload, warnings = [], deps = {}) {
|
|
|
70
70
|
const libs = deps.halves && deps.addressFromKeys
|
|
71
71
|
? { halves: deps.halves, addressFromKeys: deps.addressFromKeys, keccak256: deps.keccak256 }
|
|
72
72
|
: await (async () => {
|
|
73
|
-
|
|
73
|
+
// THE SDK'S OWN PRIMITIVES, NOT A SECOND BROWSER BUNDLE. The five names are the same @noble packages
|
|
74
|
+
// the package already ships, and a separate build of them was exactly the duplicated crypto path this
|
|
75
|
+
// recovery branch used to keep alive.
|
|
76
|
+
const { primitives } = await import("../../src/primitives.mjs");
|
|
74
77
|
const { createHalves } = await import("../atomic/halves.js");
|
|
75
78
|
const { addressFromKeys } = await import("../monero/address.js");
|
|
76
|
-
const halves = createHalves(
|
|
77
|
-
|
|
78
|
-
keccak256: vendor.keccak256, randomBytes: vendor.randomBytes,
|
|
79
|
-
});
|
|
80
|
-
return { halves, addressFromKeys, keccak256: vendor.keccak256 };
|
|
79
|
+
const halves = createHalves(primitives);
|
|
80
|
+
return { halves, addressFromKeys, keccak256: primitives.keccak256 };
|
|
81
81
|
})();
|
|
82
82
|
if (!libs.keccak256) throw new Error("no keccak256: the address cannot be checked without it");
|
|
83
83
|
|
package/engine/sdk/bridge.js
CHANGED
|
@@ -68,7 +68,7 @@ import { height as nodeHeightValue } from "../monero/node.js";
|
|
|
68
68
|
|
|
69
69
|
// THE CORE ADDRESS AS A STRING - THE BUILT BUNDLE SHIPPED WITH THE PACKAGE. A relative URL resolves both in the
|
|
70
70
|
// published `engine/` tree and in the page that serves this shim from `www/js/sdk/`; ?v=<hash> keeps the cache fresh.
|
|
71
|
-
const SDK_BUNDLE = new URL("../../assets/vendors/sdk/sdk-browser.js?v=
|
|
71
|
+
const SDK_BUNDLE = new URL("../../assets/vendors/sdk/sdk-browser.js?v=fa7dc71a", import.meta.url).href;
|
|
72
72
|
|
|
73
73
|
// A NAMED SEAM FOR CHECKS - THE SAME TECHNIQUE AS sdkBookUse BELOW. The asynchronous path is driven against a
|
|
74
74
|
// stand-in order book (the demo network has no provider), and the ordinary escrow funding that follows a settled
|
|
@@ -599,8 +599,6 @@ export async function sdkAddressNetwork(address) {
|
|
|
599
599
|
// modules, and the screen gets them through the seam, not by a second road into the engine;
|
|
600
600
|
// * networkFromShape/networkLabel - the Monero address shape and its name: the same format module the core
|
|
601
601
|
// mirrors (there is no second prefix table);
|
|
602
|
-
// * createOrderWorker - the atomic-swap halves worker: the cryptography lives in one place and is called by a
|
|
603
|
-
// worker so the main thread does not freeze;
|
|
604
602
|
// * createSwap/createReverseSwap/activeSwaps - the RECORD of the demo and reverse deal (the record is kept by
|
|
605
603
|
// the engine; the core exposes its STATE via swaps.list/swaps.progress).
|
|
606
604
|
// * createSwapWallet - THE FORM'S DEAL WALLET (state between screens, ui/formState.js): the page wallet with
|
|
@@ -614,11 +612,10 @@ import { orderGasReservePlan } from "../evm/gasReserve.js";
|
|
|
614
612
|
import { quoteDexOut, dexLegVerdict } from "../evm/dex.js";
|
|
615
613
|
import { toWei } from "../evm/funding.js";
|
|
616
614
|
import { cachedFeeTerms, feeWeiFor, ensureFeeTerms } from "../evm/fees.js";
|
|
617
|
-
import { createOrderWorker } from "../atomic/order-client.js";
|
|
618
615
|
import { activeSwaps, createSwap, createReverseSwap } from "../core/swap.js";
|
|
619
616
|
|
|
620
617
|
export { evm, networkFromShape };
|
|
621
618
|
export * as swapCore from "../core/swap.js";
|
|
622
619
|
export * as moneroNode from "../monero/node.js";
|
|
623
|
-
export { networkLabel, probeMode, createSwapWallet, amountInputValue, refreshChainPrices, priceLabel, orderGasReservePlan, quoteDexOut, dexLegVerdict, toWei, cachedFeeTerms, feeWeiFor, ensureFeeTerms,
|
|
620
|
+
export { networkLabel, probeMode, createSwapWallet, amountInputValue, refreshChainPrices, priceLabel, orderGasReservePlan, quoteDexOut, dexLegVerdict, toWei, cachedFeeTerms, feeWeiFor, ensureFeeTerms, activeSwaps, createSwap, createReverseSwap };
|
|
624
621
|
|
package/index.d.ts
CHANGED
|
@@ -49,7 +49,7 @@ export interface NinseiOptions {
|
|
|
49
49
|
* from the node on the CI contour.
|
|
50
50
|
*/
|
|
51
51
|
xmrNetwork: "mainnet" | "stagenet" | "testnet" | "fakechain";
|
|
52
|
-
/** Where to load
|
|
52
|
+
/** Where to load the Monero bundles from. Default "/". */
|
|
53
53
|
assetsBase?: string;
|
|
54
54
|
/** Storage for unfinished swaps and sessions. Default - a localStorage adapter, if present. */
|
|
55
55
|
storage?: StorageAdapter;
|
|
@@ -110,11 +110,14 @@ export interface NinseiOptions {
|
|
|
110
110
|
evmLogs?: EvmLogReader;
|
|
111
111
|
/**
|
|
112
112
|
* READING A SETTLEMENT BLOCK FROM OUTSIDE (`(tag) => block`): the claim-tip check needs the chain's current
|
|
113
|
-
*
|
|
114
|
-
* buy side) never call it.
|
|
113
|
+
* base and priority fees. A missing seam is `quote-tip-unchecked` when a quote carries a non-zero tip; zero tips
|
|
114
|
+
* (the buy side) never call it.
|
|
115
115
|
*/
|
|
116
116
|
evmBlock?: (tag?: string) => Promise<{ readonly baseFeePerGas?: string | number | bigint | null;
|
|
117
|
-
readonly baseFeeWei?: string | number | bigint | null
|
|
117
|
+
readonly baseFeeWei?: string | number | bigint | null;
|
|
118
|
+
readonly priorityFeePerGas?: string | number | bigint | null;
|
|
119
|
+
readonly maxPriorityFeePerGas?: string | number | bigint | null;
|
|
120
|
+
readonly gasPrice?: string | number | bigint | null }>;
|
|
118
121
|
/**
|
|
119
122
|
* THE INTERFACE'S OWN ADMISSION LIST - policy, not proof. The chain (maker registry, providerOf, taken from the
|
|
120
123
|
* quote) proves whose key signed; this says whom THIS interface trades with at all. An array of provider
|
|
@@ -712,6 +715,15 @@ export interface FirmRelayAnswer {
|
|
|
712
715
|
/** The escrow address predicted from the signed quote and the depositor's half. */
|
|
713
716
|
readonly escrow: string;
|
|
714
717
|
readonly recovery: { readonly kind: "salt-v2"; readonly salt: string };
|
|
718
|
+
/** Everything `swaps.start` can take from the relay; the caller adds its wallet, `receiveTo` and height. */
|
|
719
|
+
readonly startRequest: Readonly<{
|
|
720
|
+
quote: Readonly<Record<string, unknown>>;
|
|
721
|
+
order: Readonly<Record<string, unknown>>;
|
|
722
|
+
orderQuote: Readonly<Record<string, unknown>>;
|
|
723
|
+
counterparty: Readonly<Record<string, unknown>>;
|
|
724
|
+
recoveryKey: unknown;
|
|
725
|
+
recoverySalt: string;
|
|
726
|
+
}>;
|
|
715
727
|
readonly relay: string | null;
|
|
716
728
|
readonly offered: number | null;
|
|
717
729
|
readonly forwarded: Readonly<Record<string, unknown>> | null;
|
|
@@ -853,8 +865,9 @@ export interface SwapsApi {
|
|
|
853
865
|
* THE CLIENT'S OWN EARLY REFUND WHEN THE XMR DID NOT ARRIVE (issue #88). While the interface is open, a depositor
|
|
854
866
|
* who sees no XMR on the joint address takes the ETH back BEFORE `readyBy` - after it the maker may claim even
|
|
855
867
|
* without the ready mark, and the early window is gone. The arrival is decided by THE SAME check as the watch
|
|
856
|
-
* (`verifyArrival`). Only a
|
|
857
|
-
* to check (no nodes, a disagreement) throws its own code and
|
|
868
|
+
* (`verifyArrival`). Only a verdict with `absent: true` refunds; a transaction that is seen (`pending` with a txid or
|
|
869
|
+
* height, `one-node`, `arrived`) does not; a failure to check (no nodes, a disagreement) throws its own code and
|
|
870
|
+
* signs nothing. It fires only when less than the
|
|
858
871
|
* confirmations' time is left before `readyBy` (`minConfirmations * blockTimeSec`, overridable with `leadSec`).
|
|
859
872
|
*/
|
|
860
873
|
refundIfXmrMissing(request: AutoRefundRequest, deps?: AutoRefundDeps): Promise<AutoRefundVerdict>;
|
|
@@ -978,6 +991,10 @@ export interface XmrArrivalRequest {
|
|
|
978
991
|
export interface XmrArrivalVerdict {
|
|
979
992
|
readonly seen: boolean;
|
|
980
993
|
readonly state: "arrived" | "pending" | "one-node";
|
|
994
|
+
/** True only when a node completed the walk and found no matching transaction. */
|
|
995
|
+
readonly absent?: boolean;
|
|
996
|
+
/** The operators whose completed walk found no matching transaction. */
|
|
997
|
+
readonly completedOperators?: readonly string[];
|
|
981
998
|
readonly txid: string | null;
|
|
982
999
|
readonly height?: number;
|
|
983
1000
|
readonly blockHash?: string;
|
|
@@ -1043,7 +1060,8 @@ export interface AutoRefundDeps {
|
|
|
1043
1060
|
/** What the client's own refund decided: refunded, waiting, still time, or the XMR is there. */
|
|
1044
1061
|
export interface AutoRefundVerdict {
|
|
1045
1062
|
readonly refunded: boolean;
|
|
1046
|
-
readonly state: "refunded" | "waiting" | "claim-window" | "arrived"
|
|
1063
|
+
readonly state: "refunded" | "waiting" | "claim-window" | "arrival-pending" | "arrived" |
|
|
1064
|
+
"arrival-underpaid" | "arrival-locked";
|
|
1047
1065
|
readonly hash?: string | null;
|
|
1048
1066
|
readonly leftSec: number;
|
|
1049
1067
|
readonly needSec?: number;
|
|
@@ -1090,6 +1108,15 @@ export interface SellStartRequest {
|
|
|
1090
1108
|
readonly offer: FirmRelayAnswer;
|
|
1091
1109
|
/** The twelve-word key; required only when no key is stored yet. */
|
|
1092
1110
|
readonly recoveryKey?: string | { readonly mnemonic: string };
|
|
1111
|
+
/** The recovery file's passphrase. In memory; the interface puts it on disk if it deems fit. */
|
|
1112
|
+
readonly passphrase?: string;
|
|
1113
|
+
/** Asked when the key is new or not yet confirmed. Returning anything but `true` refuses before `send-xmr`. */
|
|
1114
|
+
onRecoveryKey?(file: RecoveryFile): Promise<boolean>;
|
|
1115
|
+
/**
|
|
1116
|
+
* The EVM wallet whose provider supplies the block number and timestamp for the one-block escrow gate.
|
|
1117
|
+
* Optional: without it the gate falls back to `latest` and the facade clock. The same wallet that will claim.
|
|
1118
|
+
*/
|
|
1119
|
+
readonly wallet?: Pick<WalletAdapter, "driver">;
|
|
1093
1120
|
}
|
|
1094
1121
|
|
|
1095
1122
|
export interface SellStart {
|
|
@@ -1122,12 +1149,14 @@ export interface SellWatchRequest {
|
|
|
1122
1149
|
|
|
1123
1150
|
export interface SellWatchResult {
|
|
1124
1151
|
readonly escrow: string;
|
|
1125
|
-
readonly state: "ready" | "claimed" | "refunded";
|
|
1152
|
+
readonly state: "ready" | "claim-open" | "claimed" | "refunded";
|
|
1126
1153
|
readonly funded: boolean;
|
|
1127
1154
|
readonly claimed: boolean;
|
|
1128
1155
|
readonly refunded: boolean;
|
|
1129
1156
|
/** `null` for a terminal claim/refund: the ready mark is not part of that answer. */
|
|
1130
1157
|
readonly ready: boolean | null;
|
|
1158
|
+
/** True when the escrow's readyBy has passed and no ready mark or terminal action was seen. */
|
|
1159
|
+
readonly claimOpen: boolean;
|
|
1131
1160
|
readonly balanceWei: string;
|
|
1132
1161
|
readonly waitedMs: number;
|
|
1133
1162
|
}
|
|
@@ -1274,8 +1303,8 @@ export interface RecoveryFile {
|
|
|
1274
1303
|
export interface SwapState {
|
|
1275
1304
|
readonly id: string;
|
|
1276
1305
|
readonly direction: "buy" | "sell";
|
|
1277
|
-
readonly pay: { readonly token: string; readonly amount: number };
|
|
1278
|
-
readonly get: { readonly xmr: number };
|
|
1306
|
+
readonly pay: { readonly token: string; readonly amount: number | null };
|
|
1307
|
+
readonly get: { readonly xmr: number | null };
|
|
1279
1308
|
/** The current step's code. The texts are the interface's. */
|
|
1280
1309
|
readonly step: StepCode;
|
|
1281
1310
|
/** All steps in the order of passage: what is done, what is running now, what failed. */
|
|
@@ -1332,7 +1361,7 @@ export interface SwapState {
|
|
|
1332
1361
|
/** The swap has a settlement record: the list splits live from settled by THIS flag, not by the phase's text. */
|
|
1333
1362
|
readonly settled: boolean;
|
|
1334
1363
|
/** WHAT HAS ALREADY MOVED: the sum seen at the address and whether the record holds a lock or a secret. */
|
|
1335
|
-
readonly funds: { readonly receivedXmr: number; readonly escrowLocked: boolean };
|
|
1364
|
+
readonly funds: { readonly receivedXmr: number | null; readonly escrowLocked: boolean };
|
|
1336
1365
|
}
|
|
1337
1366
|
|
|
1338
1367
|
export interface StepState {
|
|
@@ -1444,6 +1473,11 @@ export interface SweepRestoreRequest {
|
|
|
1444
1473
|
readonly toHeight: number;
|
|
1445
1474
|
readonly tipHeight: number;
|
|
1446
1475
|
readonly fallback?: boolean;
|
|
1476
|
+
/**
|
|
1477
|
+
* EXPLICIT PERMISSION TO SEND KEY IMAGES TO `nodeUrl` for the spent check. Absent/false: key images never leave
|
|
1478
|
+
* the wallet in the window path, and the result names `spentWhy: "untrusted-node"` with an incomplete scan.
|
|
1479
|
+
*/
|
|
1480
|
+
readonly trustedNode?: boolean;
|
|
1447
1481
|
};
|
|
1448
1482
|
/** The fetch used for `get_block`; absent - the global fetch. */
|
|
1449
1483
|
readonly fetchImpl?: typeof fetch;
|
|
@@ -1885,6 +1919,8 @@ export type ErrorCode =
|
|
|
1885
1919
|
| "quote-factory-mismatch"
|
|
1886
1920
|
/** The factory's runtime code is not a build this interface knows (`extcodehash`). */
|
|
1887
1921
|
| "quote-factory-code-unknown"
|
|
1922
|
+
/** The signed quote names a cashier other than the network's vault. */
|
|
1923
|
+
| "quote-cashier-mismatch"
|
|
1888
1924
|
| "recovery-declined"
|
|
1889
1925
|
| "recovery-failed"
|
|
1890
1926
|
| "storage-unavailable"
|
|
@@ -1913,6 +1949,7 @@ export type ErrorCode =
|
|
|
1913
1949
|
| "insufficient-funds"
|
|
1914
1950
|
/** A wallet/node reported a withdrawal fee above the SDK's ceiling; the transfer is refused. */
|
|
1915
1951
|
| "sweep-fee-too-high"
|
|
1952
|
+
| "sweep-fee-unknown"
|
|
1916
1953
|
/** The maker declines to pay the claim gas; the refusal is shown before the deal (issue #78). */
|
|
1917
1954
|
| "gas-refused-by-maker"
|
|
1918
1955
|
/** The claim gas was ordered but the recipient's balance did not grow. */
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ninsei-labs/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.57.2",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
7
7
|
},
|
|
8
8
|
"packageManager": "pnpm@12.11.2",
|
|
9
9
|
"description": "XMR <-> EVM swap engine: quotes, guards, order steps, recovery (no DOM, no user-facing strings)",
|
|
10
|
-
"license": "MIT",
|
|
10
|
+
"license": "(MIT AND LGPL-3.0-only)",
|
|
11
11
|
"type": "module",
|
|
12
12
|
"main": "src/index.mjs",
|
|
13
13
|
"scripts": {
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"check:mirror": "node tools/check.mjs --only=mirror",
|
|
21
21
|
"check:pack": "node tools/check.mjs --only=pack",
|
|
22
22
|
"check:pack-teeth": "node tools/run-teeth-isolated.mjs tools/check-pack-teeth.mjs",
|
|
23
|
+
"check:guard-teeth": "node tools/run-teeth-isolated.mjs tools/check-guard-teeth.mjs",
|
|
23
24
|
"check:secrets": "node tools/check.mjs --only=secrets",
|
|
24
25
|
"check:vendor-bundles": "node tools/check.mjs --only=vendor-bundles",
|
|
25
26
|
"check:dleq-vectors": "node tools/check-dleq-vectors.mjs",
|
|
@@ -69,6 +70,7 @@
|
|
|
69
70
|
"check:factory-selectors": "node tools/check-factory-selectors.mjs",
|
|
70
71
|
"check:fee-estimate": "node tools/check-fee-estimate.mjs",
|
|
71
72
|
"check:deadline-scale": "node tools/check-deadline-scale.mjs",
|
|
73
|
+
"check:deployment-pins": "node tools/check-deployment-pins.mjs",
|
|
72
74
|
"check:node-probe": "node tools/check-node-probe.mjs",
|
|
73
75
|
"check:recovery-key": "node tools/check.mjs --only=recovery-key",
|
|
74
76
|
"check:recovery-open": "node tools/check-recovery-open.mjs",
|
package/src/actions.mjs
CHANGED
|
@@ -68,8 +68,11 @@ export function createActions({ call = null, blockTime = null } = {}) {
|
|
|
68
68
|
if (!provider || typeof provider.request !== "function") {
|
|
69
69
|
return async () => { throw new SdkError("wallet-not-connected", { surface: "actions.read" }); };
|
|
70
70
|
}
|
|
71
|
-
return async ({ to, data }) => {
|
|
72
|
-
|
|
71
|
+
return async ({ to, data, from }) => {
|
|
72
|
+
// The simulation needs the same sender as the transaction: mark-ready and claim are sender-bound. For a
|
|
73
|
+
// plain read the field is simply absent.
|
|
74
|
+
const tx = from ? { to, data, from } : { to, data };
|
|
75
|
+
const result = await provider.request({ method: "eth_call", params: [tx, "latest"] });
|
|
73
76
|
if (typeof result !== "string" || !result.startsWith("0x")) {
|
|
74
77
|
throw new SdkError("contract-reverted", { surface: "actions.read" });
|
|
75
78
|
}
|
|
@@ -77,8 +80,8 @@ export function createActions({ call = null, blockTime = null } = {}) {
|
|
|
77
80
|
};
|
|
78
81
|
};
|
|
79
82
|
// THE LATEST BLOCK TIMESTAMP IS THE CLOCK THE CONTRACT USES. It comes from the same provider as the contract
|
|
80
|
-
// reads; an absent provider or an unreadable block leaves it null, and the
|
|
81
|
-
//
|
|
83
|
+
// reads; an absent provider or an unreadable block leaves it null, and the half-revealing action refuses with
|
|
84
|
+
// `clock-unreadable` rather than signing without a time verdict.
|
|
82
85
|
const clockFor = (wallet) => typeof blockTime === "function" ? blockTime : async () => {
|
|
83
86
|
try {
|
|
84
87
|
const provider = providerOf(wallet);
|
|
@@ -96,7 +99,7 @@ export function createActions({ call = null, blockTime = null } = {}) {
|
|
|
96
99
|
if (typeof sender !== "string" || !sender.trim()) throw new SdkError("bad-input", { field: "wallet.address", step });
|
|
97
100
|
return sender;
|
|
98
101
|
};
|
|
99
|
-
const deps = (wallet, chainId, from) => ({ call: readerFor(wallet), send: (tx) => wallet.send({ ...tx, chainId, from }), receipt: (h) => wallet.receipt(h), blockTime: clockFor(wallet) });
|
|
102
|
+
const deps = (wallet, chainId, from) => ({ call: readerFor(wallet), from, send: (tx) => wallet.send({ ...tx, chainId, from }), receipt: (h) => wallet.receipt(h), blockTime: clockFor(wallet) });
|
|
100
103
|
return {
|
|
101
104
|
/** Marking "I saw the XMR on the shared address". Without it, claiming is forbidden by the contract. */
|
|
102
105
|
async markReady(request, wallet) {
|
package/src/codes.mjs
CHANGED
|
@@ -83,10 +83,12 @@ export const ERROR_CODES = [
|
|
|
83
83
|
// quote-factory-unknown - the record names no factory (zero);
|
|
84
84
|
// quote-factory-mismatch - the signed quote names a DIFFERENT factory than the record;
|
|
85
85
|
// quote-factory-code-unknown - the factory's code is not a build this interface knows.
|
|
86
|
+
// quote-cashier-mismatch - the signed quote names a cashier other than the network's vault.
|
|
86
87
|
"quote-factory-unchecked",
|
|
87
88
|
"quote-factory-unknown",
|
|
88
89
|
"quote-factory-mismatch",
|
|
89
90
|
"quote-factory-code-unknown",
|
|
91
|
+
"quote-cashier-mismatch",
|
|
90
92
|
"recovery-declined",
|
|
91
93
|
"recovery-failed",
|
|
92
94
|
"storage-unavailable",
|
|
@@ -123,6 +125,7 @@ export const ERROR_CODES = [
|
|
|
123
125
|
// most of the withdrawal. The refusal names the fee and the limit so the interface does not present it as a
|
|
124
126
|
// normal transfer.
|
|
125
127
|
"sweep-fee-too-high",
|
|
128
|
+
"sweep-fee-unknown",
|
|
126
129
|
// CLAIM GAS FOR THE XMR SELLER (issue #78). The seller comes from Monero and has no coin on the EVM side to pay
|
|
127
130
|
// for the claim, so the maker may send it - but only when asked for, and only after the core has CONFIRMED the
|
|
128
131
|
// gas actually arrived. The three codes name the three states the interface must not blur together:
|
|
@@ -173,6 +176,7 @@ export const ERROR_META = Object.freeze({
|
|
|
173
176
|
"quote-factory-unknown": { retryable: false, side: "chain" },
|
|
174
177
|
"quote-factory-mismatch": { retryable: false, side: "chain" },
|
|
175
178
|
"quote-factory-code-unknown": { retryable: false, side: "chain" },
|
|
179
|
+
"quote-cashier-mismatch": { retryable: false, side: "chain" },
|
|
176
180
|
"recovery-declined": { retryable: false, side: "wallet" },
|
|
177
181
|
"recovery-failed": { retryable: false, side: "wallet" },
|
|
178
182
|
"storage-unavailable": { retryable: true, side: "service" },
|
|
@@ -188,6 +192,7 @@ export const ERROR_META = Object.freeze({
|
|
|
188
192
|
"contract-reverted": { retryable: false, side: "chain" },
|
|
189
193
|
"insufficient-funds": { retryable: false, side: "wallet" },
|
|
190
194
|
"sweep-fee-too-high": { retryable: false, side: "chain" },
|
|
195
|
+
"sweep-fee-unknown": { retryable: true, side: "chain" },
|
|
191
196
|
"gas-refused-by-maker": { retryable: false, side: "provider" },
|
|
192
197
|
"gas-not-arrived": { retryable: true, side: "chain" },
|
|
193
198
|
"gas-too-little": { retryable: false, side: "provider" },
|
package/src/config.mjs
CHANGED
|
@@ -59,6 +59,7 @@ const chainConfig = (chain) => ({
|
|
|
59
59
|
escrow: chain.escrow ? {
|
|
60
60
|
address: chain.escrow.address || null,
|
|
61
61
|
mode: chain.escrow.mode || null,
|
|
62
|
+
registry: chain.escrow.registry || null,
|
|
62
63
|
deploymentBlock: Number.isSafeInteger(chain.escrow.deploymentBlock) ? chain.escrow.deploymentBlock : null,
|
|
63
64
|
} : null,
|
|
64
65
|
});
|
package/src/engine.mjs
CHANGED
|
@@ -25,9 +25,9 @@ export * as recoveryFile from "../engine/recovery/recoveryFile.js";
|
|
|
25
25
|
export * as halves from "../engine/atomic/halves.js";
|
|
26
26
|
export * as orderContext from "../engine/atomic/orderContext.js";
|
|
27
27
|
export * as order from "../engine/atomic/order.js";
|
|
28
|
-
// HALF TRANSFER: the byte format and opening are the very same ones the
|
|
29
|
-
//
|
|
30
|
-
//
|
|
28
|
+
// HALF TRANSFER: the byte format and opening are the very same ones the engine's order builder uses. The core
|
|
29
|
+
// keeps no copy of the format: the commitment is computed over those exact bytes, and a second copy would
|
|
30
|
+
// silently drift from the calldata.
|
|
31
31
|
export * as halfenc from "../engine/atomic/halfenc.js";
|
|
32
32
|
// The engine's EVM layer: talking to the chain (order terms, sending, reading) - through this seam.
|
|
33
33
|
export * as evm from "../engine/evm/index.js";
|
|
@@ -37,9 +37,9 @@ export * as evm from "../engine/evm/index.js";
|
|
|
37
37
|
export * as dex from "../engine/evm/dex.js";
|
|
38
38
|
// THE DEAL ENGINE NO LONGER LIVES IN www/js (#32, wave 3): the order flow moved into the package
|
|
39
39
|
// (sdk/src/swap-flow.mjs) and is declared in sdk/index.d.ts. The page reaches it through the bridge, so the
|
|
40
|
-
// mirror no longer carries core/swap-flow.js - what stays in the seam is the ORDER
|
|
41
|
-
//
|
|
42
|
-
|
|
40
|
+
// mirror no longer carries core/swap-flow.js - what stays in the seam is the ORDER QUOTE source and the shared
|
|
41
|
+
// CLAIM GAS LIMIT that the moved flow reads through this same seam. The order side is built by engine/atomic/order.js.
|
|
42
|
+
|
|
43
43
|
export * as rfqSource from "../engine/core/rfqSource.js";
|
|
44
44
|
export * as claimGas from "../engine/evm/claimGas.js";
|
|
45
45
|
export * as escrow from "../engine/evm/escrow.js";
|
package/src/feeEstimate.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
//
|
|
3
3
|
// THE FEE = THE PRICE OF A BYTE × THE SIZE OF THE TRANSACTION. The price belongs to the network, not to the wallet:
|
|
4
4
|
// on Monero it moves with the median block load, so it is not set but ASKED - `get_fee_estimate` returns a price per
|
|
5
|
-
//
|
|
5
|
+
// byte for several priorities. The size is known only after the transaction is assembled (rings, inputs, outputs),
|
|
6
6
|
// so this module answers the PRICE, and `feeForBytes` is the only arithmetic that turns it into a sum.
|
|
7
7
|
//
|
|
8
8
|
// The page used to learn the fee only after signing; a person deciding whether to withdraw should see it before.
|
|
@@ -59,14 +59,21 @@ export async function moneroFeeEstimate({ url, fetchImpl = globalThis.fetch, tim
|
|
|
59
59
|
signal: controller ? controller.signal : undefined,
|
|
60
60
|
});
|
|
61
61
|
} catch (error) {
|
|
62
|
+
if (timer) clearTimeout(timer);
|
|
62
63
|
const aborted = error && (error.name === "AbortError" || error.code === "ABORT_ERR");
|
|
63
64
|
return { ok: false, why: aborted ? "timeout" : "unreachable" };
|
|
64
|
-
}
|
|
65
|
+
}
|
|
66
|
+
if (!response || !response.ok) {
|
|
65
67
|
if (timer) clearTimeout(timer);
|
|
68
|
+
return { ok: false, why: "http", status: response ? response.status : null };
|
|
66
69
|
}
|
|
67
|
-
if (!response || !response.ok) return { ok: false, why: "http", status: response ? response.status : null };
|
|
68
70
|
let body = null;
|
|
69
|
-
|
|
71
|
+
// THE TIMER COVERS THE BODY TOO. The headers do not make the answer complete.
|
|
72
|
+
try { body = await response.json(); } catch {
|
|
73
|
+
if (timer) clearTimeout(timer);
|
|
74
|
+
return { ok: false, why: "not-json" };
|
|
75
|
+
}
|
|
76
|
+
if (timer) clearTimeout(timer);
|
|
70
77
|
if (!body || body.error) return { ok: false, why: "rpc", rpc: body && body.error ? body.error.code ?? null : null };
|
|
71
78
|
const result = body.result || {};
|
|
72
79
|
// THE DAEMON'S OWN UNITS. `fee` and each entry of `fees` are atomic units PER BYTE; `quantization_mask` is the
|