@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/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
|
|
@@ -363,22 +366,10 @@ export const CHAINS = [
|
|
|
363
366
|
explorerName: "arbiscan (sepolia)",
|
|
364
367
|
gasUsd: 0.01,
|
|
365
368
|
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" },
|
|
369
|
+
// THE DEPLOYMENT PIN COMES FROM deployments/evm/<network>.json, generated into deployments.generated.js.
|
|
370
|
+
// A redeploy changes that manifest, not this file: address, cashier, registry, implementation code hash
|
|
371
|
+
// and the factory's birth block all move together.
|
|
372
|
+
escrow: deploymentFor("arbitrum-sepolia").escrow,
|
|
382
373
|
tokens: [
|
|
383
374
|
// Test USDC (Circle): decimals 6 and symbol "USDC" verified on chain by the same node.
|
|
384
375
|
{ symbol: "USDC", address: "0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d", decimals: 6, usd: 1, cls: "ar-token-usdc" },
|
|
@@ -795,13 +786,15 @@ export function allowedProvidersFor(chainOrId) {
|
|
|
795
786
|
// THE LIST OF KNOWN FACTORY BUILDS - INTERFACE POLICY, next to allowedProviders. The value is the extcodehash
|
|
796
787
|
// (keccak256 of the code) of a factory the interface will accept: the factory comes from the PROVIDER REGISTRY
|
|
797
788
|
// 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
|
-
|
|
789
|
+
// named by the record and match the signed quote). Filled from the generated deployment pins, per network; a
|
|
790
|
+
// provider's own factory on the same build lands in the same list because the factory has no immutables.
|
|
791
|
+
export const KNOWN_FACTORY_CODES = Object.freeze(Object.fromEntries(
|
|
792
|
+
Object.values(DEPLOYMENTS)
|
|
793
|
+
.filter((deployment) => deployment.status === "live" && deployment.knownFactoryCodes.length > 0)
|
|
794
|
+
.map((deployment) => [deployment.network, [...deployment.knownFactoryCodes]]),
|
|
795
|
+
));
|
|
796
|
+
|
|
797
|
+
export { DEPLOYMENTS, DEPLOYMENT_CHAINS, DEPLOYMENT_VMS, deploymentFor };
|
|
805
798
|
|
|
806
799
|
export function knownFactoryCodesFor(chainOrId) {
|
|
807
800
|
const id = typeof chainOrId === "string" ? chainOrId : chainOrId && chainOrId.id;
|
|
@@ -851,7 +844,7 @@ export function nativeOf(chainId) {
|
|
|
851
844
|
|
|
852
845
|
// A network's WRAPPED native token (WETH/WBNB...), or null. It is what the liquidity leg settles (KyberSwap Limit
|
|
853
846
|
// 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 (
|
|
847
|
+
// engine's composed route (the package provider layer) turns the token into this wrapped token first, then into native.
|
|
855
848
|
export function wrappedNativeOf(chainId) {
|
|
856
849
|
const c = chainById(chainId);
|
|
857
850
|
return (c.tokens || []).find((t) => t && t.peg === "native") || null;
|
|
@@ -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
|
+
}
|
package/engine/core/swap.js
CHANGED
|
@@ -132,7 +132,7 @@ export function createSwap(input, store = null) {
|
|
|
132
132
|
//
|
|
133
133
|
// WHAT THE REVERSE DEAL DOES DIFFERENTLY. On the buy flow the PAGE funds the escrow, and the counterparty's half
|
|
134
134
|
// is only learned after settlement. On the sell flow the PROVIDER funds the escrow, the page merely requests the
|
|
135
|
-
// order, and it computes ITS OWN halves (atomic/order
|
|
135
|
+
// order, and it computes ITS OWN halves (atomic/order.js, newMakerMaterial). So fields are named by side:
|
|
136
136
|
// our half is `half`, and the DEPOSITOR's (provider's) point and view half are counterSpendPoint/counterView*.
|
|
137
137
|
// The page does not know the depositor's SPEND half and must not: the contract publishes it on settlement, and
|
|
138
138
|
// only then does the sweep of our own XMR open up (see refundHalfRevealed).
|
|
@@ -519,17 +519,17 @@ export function derive(swap, now = nowReal()) {
|
|
|
519
519
|
}
|
|
520
520
|
} else if (live && readyAt === null && chainReadyByMs !== null && nowReal() >= chainReadyByMs
|
|
521
521
|
&& (chainT1Ms === null || nowReal() < chainT1Ms)) {
|
|
522
|
-
// THE DEAD ZONE IS
|
|
523
|
-
// `
|
|
524
|
-
//
|
|
522
|
+
// THE DEAD ZONE IS ABOUT THE REFUND, NOT THE CLAIM. `refund()` rejects a call before `t1` when
|
|
523
|
+
// `block.timestamp >= readyBy` and `ready` is false; the claim is open at `readyBy` even without the mark. The
|
|
524
|
+
// screen must not offer a refund that reverts.
|
|
525
525
|
phase = "dead_zone";
|
|
526
526
|
phaseLabel = "Ready deadline passed - the refund opens at T1";
|
|
527
527
|
can.ready = false;
|
|
528
528
|
can.refund = false;
|
|
529
529
|
can.refundByAnyone = false;
|
|
530
|
-
note = "The ready() deadline has passed without your confirmation
|
|
531
|
-
"
|
|
532
|
-
"
|
|
530
|
+
note = "The ready() deadline has passed without your confirmation. The maker can claim now, and the escrow " +
|
|
531
|
+
"refuses a refund before T1 while the mark is absent. The refund opens at T1 and returns your ETH and " +
|
|
532
|
+
"publishes your half. " +
|
|
533
533
|
(chainT1Ms !== null ? "T1: " + new Date(chainT1Ms).toISOString() + "." : "");
|
|
534
534
|
} else if (live && readyAt === null) {
|
|
535
535
|
// Live mode: Monero-leg states come from the backend. The simulated EVM-leg timeouts (T0/T1, watchtower)
|
package/engine/evm/asyncRoute.js
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
// refuses native as an order asset). So a wrapped provider is NEVER chosen as the sole provider for a native need:
|
|
19
19
|
// it is a LIQUIDITY leg, and the route to native is a COMPOSITION of two orders - the liquidity leg (token -> WETH)
|
|
20
20
|
// and a native leg on a native-capable provider (WETH -> native coin, CoW). The choice returns a route record or a
|
|
21
|
-
// composition; the composition is EXECUTED
|
|
21
|
+
// composition; the composition is EXECUTED by the package provider layer, which pays the second leg's own fee out of the
|
|
22
22
|
// reserve so the person is not sent into a composition that leaves them short of the deposit.
|
|
23
23
|
//
|
|
24
24
|
// IT MIRRORS THE PACKAGE'S PROVIDER LAYER ON PURPOSE. The move to async lives in the SDK package
|
package/engine/evm/claimGas.js
CHANGED
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
// cost plus an EXPLICIT margin for base-fee growth between ticket and claim.
|
|
13
13
|
|
|
14
14
|
// THE CLAIM GAS LIMIT IS ONE NUMBER ON BOTH SIDES. MEASURED: an honest claim costs 120 721 gas on a live chain,
|
|
15
|
-
// more than the old 120 000, which cut off legitimate claims. The limit has a margin: 200 000.
|
|
15
|
+
// more than the old 120 000, which cut off legitimate claims. The limit has a margin: 200 000. The Arbitrum L1
|
|
16
|
+
// share of a tipped claim was not part of that measurement.
|
|
16
17
|
export const CLAIM_GAS_LIMIT = 200_000n;
|
|
17
18
|
|
|
18
19
|
// THE TIP FLOOR IS NETWORK POLICY, NOT A CONSTANT IN THE SENDING CODE. A fixed 1 gwei minimum inflated
|
package/engine/evm/escrow.js
CHANGED
|
@@ -142,26 +142,31 @@ export function encodeRead(name) {
|
|
|
142
142
|
return sel;
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
+
const strictWord = (returnedHex, what, words) => {
|
|
146
|
+
if (typeof returnedHex !== "string" || !/^0x[0-9a-fA-F]*$/.test(returnedHex)) {
|
|
147
|
+
throw new Error("invalid " + what + ": " + returnedHex);
|
|
148
|
+
}
|
|
149
|
+
const hex = returnedHex.slice(2);
|
|
150
|
+
if (hex.length !== words * 64) throw new Error("short answer " + what + ": " + returnedHex);
|
|
151
|
+
return hex.toLowerCase();
|
|
152
|
+
};
|
|
153
|
+
|
|
145
154
|
// Parse a bytes32 answer: one word.
|
|
146
155
|
export function decodeBytes32(returnedHex, what = "value") {
|
|
147
|
-
|
|
148
|
-
if (hex.length < 64) throw new Error("short answer " + what + ": " + returnedHex);
|
|
149
|
-
return "0x" + hex.slice(0, 64).toLowerCase();
|
|
156
|
+
return "0x" + strictWord(returnedHex, what, 1);
|
|
150
157
|
}
|
|
151
158
|
|
|
152
159
|
// Parse the t1() answer: one word, uint64 inside uint256.
|
|
153
160
|
export function decodeUint64(returnedHex, what = "value") {
|
|
154
|
-
const hex =
|
|
155
|
-
|
|
156
|
-
const v = BigInt("0x" + hex.slice(0, 64));
|
|
161
|
+
const hex = strictWord(returnedHex, what, 1);
|
|
162
|
+
const v = BigInt("0x" + hex);
|
|
157
163
|
if (v > 18446744073709551615n) throw new Error("answer " + what + " does not fit in uint64: " + v);
|
|
158
164
|
return Number(v);
|
|
159
165
|
}
|
|
160
166
|
|
|
161
167
|
// Parse the status() answer: four 32-byte words - three flags and the balance.
|
|
162
168
|
export function decodeStatus(returnedHex) {
|
|
163
|
-
const hex =
|
|
164
|
-
if (hex.length < 256) throw new Error("short status() answer: " + returnedHex);
|
|
169
|
+
const hex = strictWord(returnedHex, "status()", 4);
|
|
165
170
|
const word = (i) => hex.slice(i * 64, (i + 1) * 64);
|
|
166
171
|
return {
|
|
167
172
|
isFunded: BigInt("0x" + word(0)) !== 0n,
|
package/engine/evm/factory.js
CHANGED
|
@@ -129,11 +129,18 @@ export function encodeCreateOrderAndFund(quote) {
|
|
|
129
129
|
return FACTORY_METHODS.createOrderAndFund + quoteCallArgs(quote);
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
+
const strictWord = (returnedHex, what, words = 1) => {
|
|
133
|
+
if (typeof returnedHex !== "string" || !/^0x[0-9a-fA-F]*$/.test(returnedHex)) {
|
|
134
|
+
throw new Error("invalid " + what + ": " + returnedHex);
|
|
135
|
+
}
|
|
136
|
+
const hex = returnedHex.slice(2);
|
|
137
|
+
if (hex.length !== words * 64) throw new Error("short answer: " + returnedHex);
|
|
138
|
+
return hex.toLowerCase();
|
|
139
|
+
};
|
|
140
|
+
|
|
132
141
|
// predict() answer - one address in a 32-byte word.
|
|
133
142
|
export function decodeAddress(returnedHex) {
|
|
134
|
-
|
|
135
|
-
if (hex.length < 64) throw new Error("short answer: " + returnedHex);
|
|
136
|
-
return "0x" + hex.slice(24, 64);
|
|
143
|
+
return "0x" + strictWord(returnedHex, "predict()").slice(24, 64);
|
|
137
144
|
}
|
|
138
145
|
|
|
139
146
|
|
|
@@ -167,9 +174,7 @@ export function decodeImplementation(returnedHex) {
|
|
|
167
174
|
|
|
168
175
|
// implementationCodeHash() - one bytes32 word.
|
|
169
176
|
export function decodeImplementationCodeHash(returnedHex) {
|
|
170
|
-
|
|
171
|
-
if (hex.length < 64) throw new Error("short answer from implementationCodeHash(): " + returnedHex);
|
|
172
|
-
return "0x" + hex.slice(0, 64).toLowerCase();
|
|
177
|
+
return "0x" + strictWord(returnedHex, "implementationCodeHash()");
|
|
173
178
|
}
|
|
174
179
|
|
|
175
180
|
// VERDICT ON THE IMPLEMENTATION - the same three conditions the factory checks:
|
package/engine/evm/funding.js
CHANGED
|
@@ -213,7 +213,7 @@ async function waitReceipt(receiptReader, hash, { tries = 12, delayMs = 1500 } =
|
|
|
213
213
|
|
|
214
214
|
// The full funding path. Steps are returned outward so the interface can show each one: predict is a free call,
|
|
215
215
|
// createOrder and lock are transactions in the user's wallet.
|
|
216
|
-
export async function fundOrder({ factory, locker, claimer, commitHalfLocker, commitHalfClaimer, edPointLocker, edPointClaimer, edViewPointLocker, salt: providedSalt, amountWei, amountLabel, claimWindowSeconds, readyWindowSeconds, readyBy, t1, quote, call, send, receipt, onStep }) {
|
|
216
|
+
export async function fundOrder({ factory, locker, claimer, commitHalfLocker, commitHalfClaimer, edPointLocker, edPointClaimer, edViewPointLocker, salt: providedSalt, amountWei, amountLabel, claimWindowSeconds, readyWindowSeconds, readyBy, t1, quote, call, send, receipt, onStep, onPredicted }) {
|
|
217
217
|
if (!factory) throw new Error("no escrow factory address set for this network");
|
|
218
218
|
if (!locker) throw new Error("no EVM wallet connected: there is nobody to deposit");
|
|
219
219
|
if (!claimer) throw new Error("the order recipient (claimer) is not set");
|
|
@@ -245,7 +245,9 @@ export async function fundOrder({ factory, locker, claimer, commitHalfLocker, co
|
|
|
245
245
|
// code. Here that is guaranteed because both predict and createOrderAndFund are built from THE SAME terms: they
|
|
246
246
|
// can diverge only if one of the two places is edited alone. They already did once (the preimage was missing from
|
|
247
247
|
// the prediction); the cure is a shared source of fields, not care.
|
|
248
|
-
// THE DEPOSITOR'S FIELDS GO AS SEPARATE FACTORY ARGUMENTS
|
|
248
|
+
// THE DEPOSITOR'S FIELDS GO AS SEPARATE FACTORY ARGUMENTS, BUT THEY ARE IN THE SIGNED SET. Since quote protocol v10
|
|
249
|
+
// the factory signs them; the overwrite below must reproduce the signed values, or the digest check rejects the
|
|
250
|
+
// creation.
|
|
249
251
|
const quoteEnc = { ...quote, commitHalfLocker: terms.commitHalfLocker, edPointLocker: terms.edPointLocker, edViewPointLocker: terms.edViewPointLocker };
|
|
250
252
|
// QUOTE AND TERMS ARE ABOUT ONE THING: a divergence moves the escrow address and signs the wrong order.
|
|
251
253
|
// THE COUNTERPARTY'S SPEND HALF IS PART OF THAT ONE THING. The proof is checked against the counterparty side,
|
|
@@ -284,7 +286,6 @@ export async function fundOrder({ factory, locker, claimer, commitHalfLocker, co
|
|
|
284
286
|
}
|
|
285
287
|
const escrowState = escrowStateVerdict({ status: stateRead.status, error: stateRead.error, address: escrow });
|
|
286
288
|
if (escrowState.blocks) throw new Error("signature not started: " + escrowState.reason);
|
|
287
|
-
|
|
288
289
|
// 2) ONE TRANSACTION: creating the order TOGETHER with the deposit.
|
|
289
290
|
//
|
|
290
291
|
// It used to be two steps (createOrder, then lock) with two defects, both seen live: the wallet estimated the
|
|
@@ -312,6 +313,10 @@ export async function fundOrder({ factory, locker, claimer, commitHalfLocker, co
|
|
|
312
313
|
// WHICH FACTORY DOOR THE DEPOSIT GOES THROUGH. There is ONE path: createOrderAndFund, where the wallet that
|
|
313
314
|
// sends the transaction becomes the locker. The sender may not change the order terms - the quote signature
|
|
314
315
|
// covers THE SAME digest the escrow checks.
|
|
316
|
+
// THE PREDICTED ADDRESS IS WRITTEN TO THE CALLER'S RECORD BEFORE THE TRANSACTION. A receipt can take longer than
|
|
317
|
+
// the process that sent it; a record saved only after the wait leaves nothing to resume from, and the retry asks
|
|
318
|
+
// for a second deposit. The callback runs after every refusal and immediately before the send.
|
|
319
|
+
if (typeof onPredicted === "function") await onPredicted({ escrow, salt, terms });
|
|
315
320
|
const createData = encodeCreateOrderAndFund(quoteEnc);
|
|
316
321
|
const createHash = await send({
|
|
317
322
|
to: factory,
|