@ninsei-labs/sdk 0.56.1 → 0.58.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 +29 -0
- package/LICENSE-POLICY.md +9 -2
- package/README.md +78 -28
- package/THIRD_PARTY_NOTICES.md +176 -2
- package/assets/vendors/MANIFEST.json +1 -13
- 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 +20 -46
- package/engine/core/deployments.generated.js +103 -0
- package/engine/core/rfqSource.js +6 -133
- package/engine/core/swap.js +8 -8
- 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 +5 -6
- package/engine/evm/session.js +48 -279
- package/engine/monero/address.js +15 -33
- package/engine/monero/keys.js +124 -0
- package/engine/monero/mnemonic.js +104 -0
- package/engine/monero/scan.js +121 -28
- package/engine/monero/wallet.js +31 -68
- package/engine/monero/wordlist.en.js +210 -0
- package/engine/recovery/restore.js +9 -9
- package/engine/sdk/bridge.js +9 -187
- package/engine/ui/walletModal.js +7 -27
- package/index.d.ts +234 -262
- package/package.json +7 -6
- package/src/actions.mjs +8 -5
- package/src/codes.mjs +17 -0
- package/src/config.mjs +17 -54
- package/src/engine.mjs +9 -6
- package/src/feeEstimate.mjs +11 -4
- package/src/http.mjs +4 -1
- package/src/index.mjs +24 -45
- package/src/legs/kyber.mjs +23 -0
- package/src/lock.mjs +1 -0
- package/src/order.mjs +110 -22
- 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/recovery.d.ts +17 -1
- package/src/public/recovery.mjs +1 -0
- package/src/public/xmr.mjs +1 -1
- package/src/quotePolicy.mjs +25 -0
- package/src/quotes.mjs +109 -765
- package/src/readyWindow.mjs +76 -0
- package/src/recovery-key.mjs +71 -16
- package/src/recovery.mjs +11 -28
- package/src/relayClaim.mjs +132 -0
- package/src/relayFeatures.mjs +25 -13
- package/src/relayFirmClient.mjs +36 -7
- package/src/relayQuote.mjs +92 -11
- package/src/relayView.mjs +3 -3
- package/src/swap-flow.mjs +146 -60
- package/src/swaps.mjs +521 -357
- package/src/sweep-action.mjs +73 -0
- package/src/sweep-restore.mjs +8 -4
- package/src/sweep.mjs +12 -2
- package/src/version.mjs +1 -1
- package/src/xmr-arrival.mjs +328 -29
- package/src/xmrAmountPolicy.mjs +35 -0
- package/assets/vendors/atomic/atomic-browser.js +0 -24
- package/assets/vendors/monero/monero-js-browser.js +0 -58
- package/assets/vendors/monero-js/LICENSE +0 -9
- package/assets/vendors/walletconnect/wc-browser.js +0 -6202
- 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/atomic/dleq2.js
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
// Everything below this header is identical to the source.
|
|
4
4
|
|
|
5
5
|
// DLEQ ACROSS CURVES: a proof that one scalar stands behind points on secp256k1 and ed25519.
|
|
6
|
-
// Ported from go-dleq (prove.go, verify.go) to @noble/curves.
|
|
6
|
+
// Ported from go-dleq (prove.go, verify.go) to @noble/curves. The upstream project is
|
|
7
|
+
// github.com/athanorlabs/go-dleq at d6fd7c03e213683cbb286d4d5bbba1c7e7e1cfe1 and is licensed LGPL-3.0-only; see
|
|
8
|
+
// THIRD_PARTY_NOTICES.md. This file is distributed under LGPL-3.0-only; the rest of the package remains MIT.
|
|
7
9
|
// THE CHALLENGE IS COMPUTED AS IN THE ORIGINAL: SHA3-512 and WIDE REDUCTION. The old edition used keccak256
|
|
8
10
|
// (32 bytes) reduced mod the order, which was BIASED (~2^-128) and differed from the reference; named by the
|
|
9
11
|
// audit and closed here. Now: a 64-byte hash, read LEAST-SIGNIFICANT first and reduced mod the order, exactly
|
|
@@ -24,8 +26,8 @@
|
|
|
24
26
|
// not the soundness fix: the review could not construct an accepting torsion proof even without it.
|
|
25
27
|
// N3: UNCOMPRESSED secp256k1 POINTS (65-byte 04||x||y) ARE ACCEPTED. The point parser canonicalises them to the
|
|
26
28
|
// compressed form before the challenge, so the transcript is the same; this is leniency, not a second encoding.
|
|
27
|
-
// N4: SCALARS AT OR ABOVE THE ORDER ARE REDUCED, NOT REFUSED, matching the reference.
|
|
28
|
-
//
|
|
29
|
+
// N4: SCALARS AT OR ABOVE THE ORDER ARE REDUCED HERE, NOT REFUSED, matching the reference. The relay spec 12.10
|
|
30
|
+
// is stricter and refuses them on the wire; this verifier still accepts a reduced residue from an older vector.
|
|
29
31
|
// IMPORTANT: the primitives are audited (@noble/curves), THIS implementation is not.
|
|
30
32
|
//
|
|
31
33
|
//
|
|
@@ -138,8 +140,23 @@ export function createDleq2({ ed25519, secp256k1, keccak256, sha3_512, randomByt
|
|
|
138
140
|
const encP = (p) => hexBytes(p.toHex());
|
|
139
141
|
const encS = (s) => hexBytes(bigToHex(s));
|
|
140
142
|
|
|
143
|
+
// THE SAME WORK, TWO WAYS TO DRAIN IT. The synchronous entry points drain the iterator immediately; the
|
|
144
|
+
// chunked entry points await between steps so a browser can paint. There is one implementation of the
|
|
145
|
+
// arithmetic, not a second "async" copy of it.
|
|
146
|
+
function drain(iterator) {
|
|
147
|
+
let step = iterator.next();
|
|
148
|
+
while (!step.done) step = iterator.next();
|
|
149
|
+
return step.value;
|
|
150
|
+
}
|
|
151
|
+
const nextTurn = async (yieldTo) => {
|
|
152
|
+
if (typeof yieldTo === "function") return await yieldTo();
|
|
153
|
+
if (globalThis.scheduler && typeof globalThis.scheduler.yield === "function") return await globalThis.scheduler.yield();
|
|
154
|
+
return await new Promise((resolve) => setTimeout(resolve, 0));
|
|
155
|
+
};
|
|
156
|
+
|
|
141
157
|
// Per-bit commitments: C_i = b_i*G + r_i*G', with sum(r_i*2^i) = 0, so sum(C_i*2^i) = x*G.
|
|
142
|
-
|
|
158
|
+
// The iterator yields after every bit; the chunked caller decides how many yields make one turn.
|
|
159
|
+
function* commitmentsSteps(curve, x) {
|
|
143
160
|
const rs = [], cs = [];
|
|
144
161
|
let sum = 0n, pow = 1n;
|
|
145
162
|
for (let i = 0; i < BITS; i++) {
|
|
@@ -153,20 +170,26 @@ export function createDleq2({ ed25519, secp256k1, keccak256, sha3_512, randomByt
|
|
|
153
170
|
}
|
|
154
171
|
const b = bit(x, i);
|
|
155
172
|
cs.push(addP(mul(curve, b), mul(curve, rs[i], curve.Galt)));
|
|
173
|
+
yield i + 1;
|
|
156
174
|
}
|
|
157
175
|
return { rs, cs };
|
|
158
176
|
}
|
|
177
|
+
function commitments(curve, x) { return drain(commitmentsSteps(curve, x)); }
|
|
159
178
|
function modInv(a, m) {
|
|
160
179
|
let [old_r, r] = [a % m, m], [old_s, s] = [1n, 0n];
|
|
161
180
|
while (r !== 0n) { const q = old_r / r; [old_r, r] = [r, old_r - q * r]; [old_s, s] = [s, old_s - q * s]; }
|
|
162
181
|
if (old_r !== 1n) throw new Error("modInv: not invertible");
|
|
163
182
|
return ((old_s % m) + m) % m;
|
|
164
183
|
}
|
|
165
|
-
function
|
|
184
|
+
function* sumCommitmentsSteps(curve, cs) {
|
|
166
185
|
let sum = cs[0];
|
|
167
|
-
for (let i = 1; i < cs.length; i++)
|
|
186
|
+
for (let i = 1; i < cs.length; i++) {
|
|
187
|
+
sum = addP(sum, mul(curve, 2n ** BigInt(i) % curve.order, cs[i]));
|
|
188
|
+
yield { phase: "sum", done: i, total: cs.length };
|
|
189
|
+
}
|
|
168
190
|
return sum;
|
|
169
191
|
}
|
|
192
|
+
function sumCommitments(curve, cs) { return drain(sumCommitmentsSteps(curve, cs)); }
|
|
170
193
|
|
|
171
194
|
// OR proof "commitment to 0 or to 1" for one bit, on both curves at once.
|
|
172
195
|
//
|
|
@@ -221,13 +244,21 @@ export function createDleq2({ ed25519, secp256k1, keccak256, sha3_512, randomByt
|
|
|
221
244
|
return mul(curve, s).equals(addP(R, mPublic(curve, X, e)));
|
|
222
245
|
}
|
|
223
246
|
|
|
224
|
-
// STEP 1. PREPARATION.
|
|
225
|
-
//
|
|
226
|
-
//
|
|
227
|
-
|
|
247
|
+
// STEP 1. PREPARATION. The commitments depend on the running sum, so the order of the arithmetic is fixed;
|
|
248
|
+
// the iterator yields between bits, which is enough for the chunked caller to keep the page alive. Per-bit
|
|
249
|
+
// data is prepared here - exactly what step 2 needs: the bit, its commitments and its randomness. THE HALF IS
|
|
250
|
+
// NO LONGER HERE, and that is the key property.
|
|
251
|
+
function* prepareProofSteps(x, context) {
|
|
228
252
|
x = typeof x === "bigint" ? x : BigInt(x);
|
|
229
253
|
const XA = mul(curves.A, x), XB = mul(curves.B, x);
|
|
230
|
-
|
|
254
|
+
yield { phase: "prepare", done: 0, total: BITS };
|
|
255
|
+
const itA = commitmentsSteps(curves.A, x), itB = commitmentsSteps(curves.B, x);
|
|
256
|
+
for (let i = 0; i < BITS; i++) {
|
|
257
|
+
const a = itA.next(), b = itB.next();
|
|
258
|
+
if (a.done || b.done) throw new Error("prepareProof: commitments ended early");
|
|
259
|
+
yield { phase: "prepare", done: i + 1, total: BITS };
|
|
260
|
+
}
|
|
261
|
+
const cA = itA.next().value, cB = itB.next().value;
|
|
231
262
|
const bits = [];
|
|
232
263
|
for (let i = 0; i < BITS; i++) {
|
|
233
264
|
bits.push({
|
|
@@ -237,6 +268,7 @@ export function createDleq2({ ed25519, secp256k1, keccak256, sha3_512, randomByt
|
|
|
237
268
|
rA: bigToHex(cA.rs[i]), rB: bigToHex(cB.rs[i]),
|
|
238
269
|
});
|
|
239
270
|
}
|
|
271
|
+
yield { phase: "know", done: BITS, total: BITS };
|
|
240
272
|
return {
|
|
241
273
|
XA: enc(XA), XB: enc(XB), context: String(context == null ? "" : context),
|
|
242
274
|
pokA: knowledgeProof(curves.A, x, XA, context, "A"),
|
|
@@ -244,6 +276,20 @@ export function createDleq2({ ed25519, secp256k1, keccak256, sha3_512, randomByt
|
|
|
244
276
|
bits,
|
|
245
277
|
};
|
|
246
278
|
}
|
|
279
|
+
function prepareProof(x, context) { return drain(prepareProofSteps(x, context)); }
|
|
280
|
+
async function prepareProofChunked(x, context, options = {}) {
|
|
281
|
+
const chunkBits = Number.isSafeInteger(options.chunkBits) && options.chunkBits > 0
|
|
282
|
+
? Math.min(options.chunkBits, BITS) : 8;
|
|
283
|
+
const it = prepareProofSteps(x, context);
|
|
284
|
+
let seen = 0;
|
|
285
|
+
for (;;) {
|
|
286
|
+
const step = it.next();
|
|
287
|
+
if (step.done) return step.value;
|
|
288
|
+
seen += 1;
|
|
289
|
+
if (typeof options.onPrepare === "function") options.onPrepare(step.value);
|
|
290
|
+
if (seen % chunkBits === 0) await nextTurn(options.yieldTo);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
247
293
|
|
|
248
294
|
// STEP 2. PROVE ONE BIT. Called on the prepared data, self-contained, knowing neither the half nor other bits.
|
|
249
295
|
// So the steps are independent and parallelisable.
|
|
@@ -282,6 +328,29 @@ export function createDleq2({ ed25519, secp256k1, keccak256, sha3_512, randomByt
|
|
|
282
328
|
return assembleProof(prepared, parts);
|
|
283
329
|
}
|
|
284
330
|
|
|
331
|
+
// THE CHUNKED PROOF IS THE SAME PROOF, WITH TURNS. Preparation and every bit come from the iterators above;
|
|
332
|
+
// this function only decides when to give the event loop a chance to paint. The page stays responsive while
|
|
333
|
+
// the arithmetic is still the one implementation.
|
|
334
|
+
async function proveChunked(x, context, options = {}) {
|
|
335
|
+
const chunkBits = Number.isSafeInteger(options.chunkBits) && options.chunkBits > 0
|
|
336
|
+
? Math.min(options.chunkBits, BITS) : 4;
|
|
337
|
+
const prepared = await prepareProofChunked(x, context, {
|
|
338
|
+
chunkBits: Number.isSafeInteger(options.prepareChunkBits) && options.prepareChunkBits > 0
|
|
339
|
+
? options.prepareChunkBits : 8,
|
|
340
|
+
yieldTo: options.yieldTo,
|
|
341
|
+
onPrepare: options.onPrepare,
|
|
342
|
+
});
|
|
343
|
+
const parts = [];
|
|
344
|
+
for (let i = 0; i < BITS; i++) {
|
|
345
|
+
parts.push(proveBit(prepared.bits[i], prepared.context));
|
|
346
|
+
if ((i + 1) % chunkBits === 0 || i === BITS - 1) {
|
|
347
|
+
if (typeof options.onBit === "function") options.onBit(i + 1, BITS);
|
|
348
|
+
await nextTurn(options.yieldTo);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
return assembleProof(prepared, parts);
|
|
352
|
+
}
|
|
353
|
+
|
|
285
354
|
// STRICT SUBGROUP CHECK, NOT JUST SMALL ORDER. The old edition checked [8]*P != 0: it rejected a purely
|
|
286
355
|
// small-order point but let a point with a small COMPONENT through, so a degenerate equality passed. Strict:
|
|
287
356
|
// [l]*P = 0. secp256k1 is not checked: cofactor 1, the whole group is prime order.
|
|
@@ -295,7 +364,7 @@ export function createDleq2({ ed25519, secp256k1, keccak256, sha3_512, randomByt
|
|
|
295
364
|
// FORM IS CHECKED BEFORE COUNTING. The old loop ran over the received list length: a short proof proved
|
|
296
365
|
// ANOTHER representation, a long one burned check time. An honest path always sends exactly BITS parts. An
|
|
297
366
|
// unparsable field returns a refusal, not an exception: the caller must get {ok:false}, not crash.
|
|
298
|
-
function
|
|
367
|
+
function* verifySteps(proof, context, options = {}) {
|
|
299
368
|
if (!proof || typeof proof !== "object") return { ok: false, reason: "proof: an object is expected" };
|
|
300
369
|
if (typeof proof.XA !== "string" || typeof proof.XB !== "string") return { ok: false, reason: "proof: no XA or XB" };
|
|
301
370
|
if (!Array.isArray(proof.proofs)) return { ok: false, reason: "proof: no parts list" };
|
|
@@ -305,6 +374,13 @@ export function createDleq2({ ed25519, secp256k1, keccak256, sha3_512, randomByt
|
|
|
305
374
|
let XA, XB, csA, csB;
|
|
306
375
|
try {
|
|
307
376
|
XA = P(curves.A, proof.XA); XB = P(curves.B, proof.XB);
|
|
377
|
+
// THE SUBJECT MUST NOT BE THE EDWARDS IDENTITY. A proof of the identity can be manufactured without
|
|
378
|
+
// contributing a half, and the joint spend point would silently lose this side; Monero/relay spec 12.10
|
|
379
|
+
// forbids it. The secp256k1 side needs no separate branch: @noble refuses the point-at-infinity encoding, so
|
|
380
|
+
// an XA identity is refused as unparsable before this check.
|
|
381
|
+
if (XB.equals(curves.B.P.ZERO)) {
|
|
382
|
+
return { ok: false, reason: "proof: the subject point is the identity" };
|
|
383
|
+
}
|
|
308
384
|
if (!torsionFree(curves.B, XB)) return { ok: false, reason: "proof: XB is not in the prime-order subgroup" };
|
|
309
385
|
} catch (e) {
|
|
310
386
|
return { ok: false, reason: "proof: XA or XB is unparsable (" + String((e && e.message) || e) + ")" };
|
|
@@ -332,8 +408,10 @@ export function createDleq2({ ed25519, secp256k1, keccak256, sha3_512, randomByt
|
|
|
332
408
|
} catch (e) {
|
|
333
409
|
return { ok: false, reason: "proof: " + String((e && e.message) || e) };
|
|
334
410
|
}
|
|
335
|
-
|
|
336
|
-
if (!
|
|
411
|
+
const sumA = yield* sumCommitmentsSteps(curves.A, csA);
|
|
412
|
+
if (!sumA.equals(XA)) return { ok: false, reason: "the commitment sum does not give X on secp256k1" };
|
|
413
|
+
const sumB = yield* sumCommitmentsSteps(curves.B, csB);
|
|
414
|
+
if (!sumB.equals(XB)) return { ok: false, reason: "the commitment sum does not give X on ed25519" };
|
|
337
415
|
for (let i = 0; i < proof.proofs.length; i++) {
|
|
338
416
|
const item = proof.proofs[i];
|
|
339
417
|
try {
|
|
@@ -361,9 +439,32 @@ export function createDleq2({ ed25519, secp256k1, keccak256, sha3_512, randomByt
|
|
|
361
439
|
} catch (e) {
|
|
362
440
|
return { ok: false, reason: "bit " + i + ": fields are unparsable (" + String((e && e.message) || e) + ")" };
|
|
363
441
|
}
|
|
442
|
+
yield { phase: "verify", done: i + 1, total: proof.proofs.length };
|
|
364
443
|
}
|
|
365
444
|
return { ok: true };
|
|
366
445
|
}
|
|
446
|
+
function verify(proof, context, options = {}) { return drain(verifySteps(proof, context, options)); }
|
|
367
447
|
|
|
368
|
-
|
|
448
|
+
// THE CHUNKED VERIFIER IS THE SAME VERIFIER, WITH TURNS. The sum and the bit loop are the expensive parts;
|
|
449
|
+
// the phase-aware chunk keeps the browser paint budget without adding a second verification path.
|
|
450
|
+
async function verifyChunked(proof, context, options = {}) {
|
|
451
|
+
const it = verifySteps(proof, context, options);
|
|
452
|
+
let phase = null, count = 0;
|
|
453
|
+
for (;;) {
|
|
454
|
+
const step = it.next();
|
|
455
|
+
if (step.done) return step.value;
|
|
456
|
+
const nextPhase = step.value && step.value.phase ? step.value.phase : null;
|
|
457
|
+
if (nextPhase !== phase) { phase = nextPhase; count = 0; }
|
|
458
|
+
count += 1;
|
|
459
|
+
if (typeof options.onProgress === "function") options.onProgress(step.value);
|
|
460
|
+
// VERIFY CHUNKS ARE SHORTER THAN PROOF CHUNKS: one verification step is more expensive than one
|
|
461
|
+
// proof bit, and a 50 ms turn is already visible as a stutter. The caller can raise it when it has a
|
|
462
|
+
// larger budget; the default keeps the page within a frame or two.
|
|
463
|
+
const every = phase === "sum" ? 16
|
|
464
|
+
: (Number.isSafeInteger(options.verifyChunkBits) && options.verifyChunkBits > 0
|
|
465
|
+
? Math.min(options.verifyChunkBits, BITS) : 2);
|
|
466
|
+
if (count % every === 0) await nextTurn(options.yieldTo);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
return { BITS, curves, prove, proveChunked, verify, verifyChunked, prepareProof, prepareProofChunked, proveBit, assembleProof, torsionFree };
|
|
369
470
|
}
|
package/engine/atomic/order.js
CHANGED
|
@@ -42,13 +42,24 @@ export function createOrderBuilder({ ed25519, secp256k1, keccak256, sha3_512, ra
|
|
|
42
42
|
return { half, pub, viewHalf, viewPub, enc: encPair, proof, standIn };
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
// THE CHUNKED SIDE IS THE SAME SIDE, WITH TURNS. The halves and the encryption key are cheap; only the DLEQ
|
|
46
|
+
// proof is chunked, through the same generator the synchronous path drains.
|
|
47
|
+
async function newSideChunked(orderContext, standIn = false, options = {}) {
|
|
48
|
+
const half = halves.newHalf();
|
|
49
|
+
const pub = halves.publicHalves(half);
|
|
50
|
+
const viewHalf = halves.newHalf();
|
|
51
|
+
const viewPub = halves.publicHalves(viewHalf).ed;
|
|
52
|
+
const encPair = enc.recipientKeyPair();
|
|
53
|
+
const proof = await dleq.proveChunked(half, orderContext, options);
|
|
54
|
+
return { half, pub, viewHalf, viewPub, enc: encPair, proof, standIn };
|
|
55
|
+
}
|
|
56
|
+
|
|
45
57
|
// Checking the counterparty side IS conditions (1) and (2): its proof, and - if an envelope is given - opening
|
|
46
58
|
// ITS envelope with OUR private key and verifying against ITS public point.
|
|
47
59
|
//
|
|
48
60
|
// KEY ROLES ARE FUNDAMENTAL HERE, and the first version mixed them up: it opened the envelope with the
|
|
49
61
|
// counterparty's own key (which we do not have - the envelope is addressed to them). That check could never pass.
|
|
50
|
-
function
|
|
51
|
-
const proofOk = dleq.verify(side.proof, orderContext);
|
|
62
|
+
function verifySideAfterProof(side, orderContext, sealedPayloadBytes, ownEncPriv, proofOk) {
|
|
52
63
|
if (!proofOk.ok) return { ok: false, reason: "counterparty DLEQ failed: " + proofOk.reason };
|
|
53
64
|
// THE PROVEN POINT MUST BE THE ONE THAT GOES INTO THE ORDER, and this check was missing. A proof confirms that
|
|
54
65
|
// ONE scalar stands behind a pair of points, but not that the proven ed25519 point is the one the joint address
|
|
@@ -90,6 +101,13 @@ export function createOrderBuilder({ ed25519, secp256k1, keccak256, sha3_512, ra
|
|
|
90
101
|
}
|
|
91
102
|
return { ok: true };
|
|
92
103
|
}
|
|
104
|
+
function verifySide(side, orderContext, sealedPayloadBytes, ownEncPriv) {
|
|
105
|
+
return verifySideAfterProof(side, orderContext, sealedPayloadBytes, ownEncPriv, dleq.verify(side.proof, orderContext));
|
|
106
|
+
}
|
|
107
|
+
async function verifySideChunked(side, orderContext, sealedPayloadBytes, ownEncPriv, options = {}) {
|
|
108
|
+
const proofOk = await dleq.verifyChunked(side.proof, orderContext, options);
|
|
109
|
+
return verifySideAfterProof(side, orderContext, sealedPayloadBytes, ownEncPriv, proofOk);
|
|
110
|
+
}
|
|
93
111
|
|
|
94
112
|
// The envelope with our half, encrypted to the counterparty key: what goes to them and to the contract.
|
|
95
113
|
function sealFor(counterparty, ownHalf, orderContext) {
|
|
@@ -134,5 +152,5 @@ export function createOrderBuilder({ ed25519, secp256k1, keccak256, sha3_512, ra
|
|
|
134
152
|
});
|
|
135
153
|
}
|
|
136
154
|
|
|
137
|
-
return { halves, dleq, enc, newSide, verifySide, sealFor, openFrom, jointAddressPoint, pointOf, jointAddress, halfCommitment };
|
|
155
|
+
return { halves, dleq, enc, newSide, newSideChunked, verifySide, verifySideChunked, sealFor, openFrom, jointAddressPoint, pointOf, jointAddress, halfCommitment };
|
|
138
156
|
}
|
package/engine/core/config.js
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
// Edit the source under www/js and regenerate the mirror; a drift guard reddens on any difference.
|
|
3
3
|
// Everything below this header is identical to the source.
|
|
4
4
|
|
|
5
|
+
// VM-neutral deployment pins generated from deployments/<vm>/<network>.json. No address table is copied below.
|
|
6
|
+
import { DEPLOYMENTS, DEPLOYMENT_CHAINS, DEPLOYMENT_VMS, deploymentFor } from "./deployments.generated.js";
|
|
7
|
+
|
|
5
8
|
// Demo configuration. Every number a user sees lives here. Values come from the litepaper and are marked as demo data in the UI.
|
|
6
9
|
//
|
|
7
10
|
// Networks and tokens are one CHAINS structure: each network has its own native token, its own accepted tokens and
|
|
@@ -42,10 +45,6 @@ export const ENDPOINTS = Object.freeze({
|
|
|
42
45
|
sweepOrigin: (BROWSER_DEPLOY && BROWSER_DEPLOY.sweepOrigin) || (NODE_ENV && NODE_ENV.NINSEI_SWEEP_ORIGIN) || LOCAL_ENDPOINTS.sweepOrigin,
|
|
43
46
|
});
|
|
44
47
|
|
|
45
|
-
// THE PAGE'S OWN ADDRESS comes from the environment, not from a constant: WalletConnect compares the metadata url
|
|
46
|
-
// with the page's actual origin, so a hard-coded host breaks the session on any other host.
|
|
47
|
-
const PAGE_ORIGIN = typeof location !== "undefined" ? location.origin : "";
|
|
48
|
-
|
|
49
48
|
// THE EIP-712 SIGNING DOMAIN (name/version) for a signed order quote. It is NOT a brand literal in the signer: it
|
|
50
49
|
// belongs to the registry contract (it returns DOMAIN_SEPARATOR()), so it is taken from the config here. The defaults
|
|
51
50
|
// reproduce today's result byte for byte.
|
|
@@ -363,22 +362,10 @@ export const CHAINS = [
|
|
|
363
362
|
explorerName: "arbiscan (sepolia)",
|
|
364
363
|
gasUsd: 0.01,
|
|
365
364
|
routeType: "atomic",
|
|
366
|
-
// THE
|
|
367
|
-
//
|
|
368
|
-
//
|
|
369
|
-
|
|
370
|
-
// cashier 0x6c6c6da6392a92b8b9c69b3ec234d524cdcfcb57;
|
|
371
|
-
// registry 0xf06ec2b1de69ff5b528ed917edffbee7be6dccc9 (this release deploys it);
|
|
372
|
-
// implementation 0x584b8438204A7CDb207957F5572a7f34E5D526c8, codehash
|
|
373
|
-
// 0x334d6802099fccaef87b9569618ab3c46f6a2f075c2934c0cdbc8d4e4042944b.
|
|
374
|
-
// `OrderCreated` carries xmrAmount; the SDK reads it from the event. PREVIOUS factory before this version:
|
|
375
|
-
// 0x69b5a6878b542960af4d239ecc60ad1c9e3e6932 (height 323014007, cashier
|
|
376
|
-
// 0x05b7433f66f2b75cc7ece9ec00af0fb810f9c9e0).
|
|
377
|
-
// mode: "live" - order creation TOGETHER WITH THE MONEY in one transaction (createOrderAndFund). cashier: the
|
|
378
|
-
// INTERFACE's fee cashier, named in quotes. implementationCodeHash: the escrow implementation the factory
|
|
379
|
-
// carries, checked against the chain. deploymentBlock: the height the factory was created at; a log search for
|
|
380
|
-
// its orders starts here, not at zero, because public RPCs cap a log query at about 10M blocks.
|
|
381
|
-
escrow: { address: "0x6ab0ef3aa67b022d4007550e7556108537debb55", mode: "live", deploymentBlock: 325677796, cashier: "0x6c6c6da6392a92b8b9c69b3ec234d524cdcfcb57", implementationCodeHash: "0x334d6802099fccaef87b9569618ab3c46f6a2f075c2934c0cdbc8d4e4042944b" },
|
|
365
|
+
// THE DEPLOYMENT PIN COMES FROM deployments/evm/<network>.json, generated into deployments.generated.js.
|
|
366
|
+
// A redeploy changes that manifest, not this file: address, cashier, registry, implementation code hash
|
|
367
|
+
// and the factory's birth block all move together.
|
|
368
|
+
escrow: deploymentFor("arbitrum-sepolia").escrow,
|
|
382
369
|
tokens: [
|
|
383
370
|
// Test USDC (Circle): decimals 6 and symbol "USDC" verified on chain by the same node.
|
|
384
371
|
{ symbol: "USDC", address: "0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d", decimals: 6, usd: 1, cls: "ar-token-usdc" },
|
|
@@ -795,13 +782,15 @@ export function allowedProvidersFor(chainOrId) {
|
|
|
795
782
|
// THE LIST OF KNOWN FACTORY BUILDS - INTERFACE POLICY, next to allowedProviders. The value is the extcodehash
|
|
796
783
|
// (keccak256 of the code) of a factory the interface will accept: the factory comes from the PROVIDER REGISTRY
|
|
797
784
|
// record, and its code is compared against this list. Empty for a network = no policy (the factory must still be
|
|
798
|
-
// named by the record and match the signed quote). Filled
|
|
799
|
-
//
|
|
800
|
-
export const KNOWN_FACTORY_CODES =
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
785
|
+
// named by the record and match the signed quote). Filled from the generated deployment pins, per network; a
|
|
786
|
+
// provider's own factory on the same build lands in the same list because the factory has no immutables.
|
|
787
|
+
export const KNOWN_FACTORY_CODES = Object.freeze(Object.fromEntries(
|
|
788
|
+
Object.values(DEPLOYMENTS)
|
|
789
|
+
.filter((deployment) => deployment.status === "live" && deployment.knownFactoryCodes.length > 0)
|
|
790
|
+
.map((deployment) => [deployment.network, [...deployment.knownFactoryCodes]]),
|
|
791
|
+
));
|
|
792
|
+
|
|
793
|
+
export { DEPLOYMENTS, DEPLOYMENT_CHAINS, DEPLOYMENT_VMS, deploymentFor };
|
|
805
794
|
|
|
806
795
|
export function knownFactoryCodesFor(chainOrId) {
|
|
807
796
|
const id = typeof chainOrId === "string" ? chainOrId : chainOrId && chainOrId.id;
|
|
@@ -851,7 +840,7 @@ export function nativeOf(chainId) {
|
|
|
851
840
|
|
|
852
841
|
// A network's WRAPPED native token (WETH/WBNB...), or null. It is what the liquidity leg settles (KyberSwap Limit
|
|
853
842
|
// Order trades ERC20 against ERC20 and cannot deliver native) and what the native leg sells to buy native coin: the
|
|
854
|
-
// engine's composed route (
|
|
843
|
+
// engine's composed route (the package provider layer) turns the token into this wrapped token first, then into native.
|
|
855
844
|
export function wrappedNativeOf(chainId) {
|
|
856
845
|
const c = chainById(chainId);
|
|
857
846
|
return (c.tokens || []).find((t) => t && t.peg === "native") || null;
|
|
@@ -869,9 +858,8 @@ export function tokenById(idOrChainId, symbolMaybe) {
|
|
|
869
858
|
}
|
|
870
859
|
|
|
871
860
|
|
|
872
|
-
// The demo's Monero network.
|
|
873
|
-
//
|
|
874
|
-
// handles stagenet.
|
|
861
|
+
// The demo's Monero network. The package's own Monero key module supports the mainnet, stagenet and testnet
|
|
862
|
+
// address prefixes. The monero-ts mode (WebAssembly wallet2) also handles stagenet.
|
|
875
863
|
// The order recipient (claimer) for TESTS on test networks.
|
|
876
864
|
//
|
|
877
865
|
// IMPORTANT: the contract requires locker and claimer to differ, so a payment address must not be given here -
|
|
@@ -951,20 +939,6 @@ export const SWEEP = {
|
|
|
951
939
|
localOrigin: "http://localhost:5195",
|
|
952
940
|
};
|
|
953
941
|
|
|
954
|
-
// ---------------------------------------------------------------------------
|
|
955
|
-
// The EVM wallet: WalletConnect (Reown). projectId is the app's public identifier, visible to any site with
|
|
956
|
-
// WalletConnect (not a secret: it goes into the QR and the relay). The metadata is shown to the user in the wallet.
|
|
957
|
-
// ---------------------------------------------------------------------------
|
|
958
|
-
export const EVM = {
|
|
959
|
-
projectId: "18c13c05b6c0ab011ffff7cee0700e2d",
|
|
960
|
-
metadata: {
|
|
961
|
-
name: "NinseiSwap",
|
|
962
|
-
description: "Non-custodial XMR <-> EVM atomic swap. Demo build: real wallet, real balances, no real funds move.",
|
|
963
|
-
url: PAGE_ORIGIN,
|
|
964
|
-
icons: [],
|
|
965
|
-
},
|
|
966
|
-
};
|
|
967
|
-
|
|
968
942
|
// THERE IS NO FEE RATE HERE - AND THERE MUST NOT BE. The only source of truth is the SIGNED QUOTE. The rate, amount
|
|
969
943
|
// and recipient of the fee are part of the order terms; the factory no longer has feeBps()/feeFor() (the router was
|
|
970
944
|
// removed), and the node does not compare its setting with the chain - it SIGNS it, while the amount comes in the
|
|
@@ -999,7 +973,7 @@ export const DEMO = {
|
|
|
999
973
|
defaultSpeed: 60,
|
|
1000
974
|
scenarios: ["happy", "maker_no_lock", "user_no_ready", "maker_stall"],
|
|
1001
975
|
defaultScenario: "happy",
|
|
1002
|
-
// There is no wallet mode any more: keys
|
|
976
|
+
// There is no wallet mode any more: keys are derived by the package's own Monero module, the only path (the WASM wallet
|
|
1003
977
|
// monero-ts moved to the separate sweep domain - its own policy and COOP/COEP).
|
|
1004
978
|
// mock - confirmations by a sim timer; live - by the real Monero mainnet height
|
|
1005
979
|
chainModes: ["mock", "live"],
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// GENERATED FILE - do not edit. Run: node tools/gen-deployment-pins.mjs --write
|
|
2
|
+
// Source: deployments/<vm>/<network>.json, copied from the reviewed contract release manifest.
|
|
3
|
+
const freeze = (value) => {
|
|
4
|
+
if (value && typeof value === "object") {
|
|
5
|
+
Object.freeze(value);
|
|
6
|
+
for (const child of Object.values(value)) freeze(child);
|
|
7
|
+
}
|
|
8
|
+
return value;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const DATA = {
|
|
12
|
+
"arbitrum-sepolia": {
|
|
13
|
+
"vm": "evm",
|
|
14
|
+
"network": "arbitrum-sepolia",
|
|
15
|
+
"caip2": "eip155:421614",
|
|
16
|
+
"chainRef": "421614",
|
|
17
|
+
"status": "live",
|
|
18
|
+
"release": {
|
|
19
|
+
"tag": "contracts-testnet-2026.11.04",
|
|
20
|
+
"commit": "930366a387c0c696bda6f5c038f23617447ebb78",
|
|
21
|
+
"toolchain": "0.8.38",
|
|
22
|
+
"deployedAt": "2026-11-04T15:00:55.822Z"
|
|
23
|
+
},
|
|
24
|
+
"anchor": {
|
|
25
|
+
"kind": "block",
|
|
26
|
+
"value": "326005419"
|
|
27
|
+
},
|
|
28
|
+
"artifacts": {
|
|
29
|
+
"factory": {
|
|
30
|
+
"role": "factory",
|
|
31
|
+
"kind": "contract",
|
|
32
|
+
"address": "0x245d3a4ac4b98d713f6c5130b56cd5d550f8cefe",
|
|
33
|
+
"addressFormat": "hex-20",
|
|
34
|
+
"codeHash": "0x1fdfa1c922f660506243cab4c889aa83e22ce27d818bac9c5e4ecbccbdd04906",
|
|
35
|
+
"hashKind": "keccak256",
|
|
36
|
+
"tx": {
|
|
37
|
+
"kind": "hash",
|
|
38
|
+
"value": "0xf62f54cbb0c236edc467652fce8c746c903a5d0ab4ecdd492649d57a92862296"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"cashier": {
|
|
42
|
+
"role": "cashier",
|
|
43
|
+
"kind": "contract",
|
|
44
|
+
"address": "0x40515449159EfbCb5eF5eB9e2E08ba432E150a1C",
|
|
45
|
+
"addressFormat": "hex-20",
|
|
46
|
+
"tx": {
|
|
47
|
+
"kind": "hash",
|
|
48
|
+
"value": "0xf62f54cbb0c236edc467652fce8c746c903a5d0ab4ecdd492649d57a92862296"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"registry": {
|
|
52
|
+
"role": "registry",
|
|
53
|
+
"kind": "contract",
|
|
54
|
+
"address": "0x92191dc3517e15db6468628b1a493576728a9798",
|
|
55
|
+
"addressFormat": "hex-20",
|
|
56
|
+
"tx": {
|
|
57
|
+
"kind": "hash",
|
|
58
|
+
"value": "0x8f60792dac889008ec5678c6f30790730d278518d512a3b19657829896391adf"
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"implementation": {
|
|
62
|
+
"role": "implementation",
|
|
63
|
+
"kind": "contract",
|
|
64
|
+
"address": "0xF88658b53FcB965E580638bbFe048E8f587d6D11",
|
|
65
|
+
"addressFormat": "hex-20",
|
|
66
|
+
"codeHash": "0x7020a1017adbb4d4ce4710f7c632d48a5469a6f3076608e77d5675dee125653c",
|
|
67
|
+
"hashKind": "keccak256",
|
|
68
|
+
"tx": {
|
|
69
|
+
"kind": "hash",
|
|
70
|
+
"value": "0xf62f54cbb0c236edc467652fce8c746c903a5d0ab4ecdd492649d57a92862296"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
"escrow": {
|
|
75
|
+
"address": "0x245d3a4ac4b98d713f6c5130b56cd5d550f8cefe",
|
|
76
|
+
"mode": "live",
|
|
77
|
+
"deploymentBlock": 326005419,
|
|
78
|
+
"cashier": "0x40515449159EfbCb5eF5eB9e2E08ba432E150a1C",
|
|
79
|
+
"registry": "0x92191dc3517e15db6468628b1a493576728a9798",
|
|
80
|
+
"implementationCodeHash": "0x7020a1017adbb4d4ce4710f7c632d48a5469a6f3076608e77d5675dee125653c"
|
|
81
|
+
},
|
|
82
|
+
"knownFactoryCodes": [
|
|
83
|
+
"0x1fdfa1c922f660506243cab4c889aa83e22ce27d818bac9c5e4ecbccbdd04906"
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export const DEPLOYMENTS = freeze(DATA);
|
|
89
|
+
export const DEPLOYMENT_CHAINS = freeze(Object.keys(DATA).sort());
|
|
90
|
+
export const DEPLOYMENT_VMS = freeze([...new Set(Object.values(DATA).map((d) => d.vm))].sort());
|
|
91
|
+
|
|
92
|
+
// Accept a network id, a CAIP-2, or an EVM chain id. No fallback to another network: an unknown deployment is null.
|
|
93
|
+
export function deploymentFor(chainOrId) {
|
|
94
|
+
if (chainOrId === null || chainOrId === undefined) return null;
|
|
95
|
+
const value = typeof chainOrId === "object"
|
|
96
|
+
? chainOrId.id ?? chainOrId.network ?? chainOrId.caip2
|
|
97
|
+
: chainOrId;
|
|
98
|
+
if (value === null || value === undefined) return null;
|
|
99
|
+
if (typeof value === "number" || /^[0-9]+$/.test(String(value))) {
|
|
100
|
+
return Object.values(DEPLOYMENTS).find((d) => Number(d.chainRef) === Number(value)) ?? null;
|
|
101
|
+
}
|
|
102
|
+
return DEPLOYMENTS[value] ?? Object.values(DEPLOYMENTS).find((d) => d.caip2 === value) ?? null;
|
|
103
|
+
}
|