@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/src/order.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// THREE CHECKS, ALL MANDATORY BEFORE SIGNING - after it there is nothing to fix:
|
|
4
4
|
//
|
|
5
5
|
// 1) the DLEQ proof stands in the CONTEXT OF THIS order: the counterparty proved for our terms, not for others.
|
|
6
|
-
// The context is the same one the quote signature is bound to (see quotes.
|
|
6
|
+
// The context is the same one the quote signature is bound to (see quotes.firmRelay);
|
|
7
7
|
// 2) the proven ed25519 point is THE VERY ONE that will go into the contract and from which the address is
|
|
8
8
|
// assembled. Without this check the counterparty could prove one thing and substitute another: on our side
|
|
9
9
|
// everything would look sound, and the discrepancy would surface when claiming the XMR, with nothing left to
|
|
@@ -137,27 +137,73 @@ export function buildOwnSide(order, onBit) {
|
|
|
137
137
|
return { context, side, spendPoint: norm(side.pub.ed), viewPoint: norm(side.viewPub), encPub: norm(side.enc.pub) };
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
+
/**
|
|
141
|
+
* The same side, with the proof yielding between chunks. The synchronous `buildOwnSide` remains the entry for
|
|
142
|
+
* callers that cannot await; both drain the same engine builder.
|
|
143
|
+
*/
|
|
144
|
+
export async function buildOwnSideChunked(order, options = {}) {
|
|
145
|
+
const context = contextOf(order);
|
|
146
|
+
const side = await builder().newSideChunked(context, false, options);
|
|
147
|
+
return { context, side, spendPoint: norm(side.pub.ed), viewPoint: norm(side.viewPub), encPub: norm(side.enc.pub) };
|
|
148
|
+
}
|
|
149
|
+
|
|
140
150
|
/**
|
|
141
151
|
* OUR SIDE FROM HALVES WE ALREADY HAVE - the one recovery key case. A random side would be a second secret,
|
|
142
152
|
* which is exactly what one key removes. The proof is still bound to this order and built by the same engine
|
|
143
153
|
* builder; only the source of the two numbers changes.
|
|
144
154
|
*/
|
|
145
|
-
|
|
146
|
-
const context = contextOf(order);
|
|
147
|
-
const b = builder();
|
|
155
|
+
function knownHalves(builderInstance, { spendHalf, viewHalf } = {}) {
|
|
148
156
|
const scalar = (value, name) => {
|
|
149
157
|
const n = BigInt(value);
|
|
150
|
-
if (n <= 0n || n >= BigInt(
|
|
158
|
+
if (n <= 0n || n >= BigInt(builderInstance.halves.LIMIT)) throw new SdkError("bad-input", { field: name });
|
|
151
159
|
return n;
|
|
152
160
|
};
|
|
153
161
|
const half = scalar(spendHalf, "spendHalf");
|
|
154
162
|
const view = scalar(viewHalf, "viewHalf");
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
163
|
+
return {
|
|
164
|
+
half, view,
|
|
165
|
+
pub: builderInstance.halves.publicHalves(half),
|
|
166
|
+
viewPub: builderInstance.halves.publicHalves(view).ed,
|
|
167
|
+
encPair: builderInstance.enc.recipientKeyPair(),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function sideFromKnown({ half, view, pub, viewPub, encPair }, proof) {
|
|
159
172
|
const side = { half, pub, viewHalf: view, viewPub, enc: encPair, proof, standIn: false };
|
|
160
|
-
return {
|
|
173
|
+
return { side, spendPoint: norm(pub.ed), viewPoint: norm(viewPub), encPub: norm(encPair.pub) };
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function buildOwnSideFromHalves(order, { spendHalf, viewHalf } = {}) {
|
|
177
|
+
const context = contextOf(order);
|
|
178
|
+
const b = builder();
|
|
179
|
+
const inputs = knownHalves(b, { spendHalf, viewHalf });
|
|
180
|
+
const proof = b.dleq.prove(inputs.half, context);
|
|
181
|
+
const { side, spendPoint, viewPoint, encPub } = sideFromKnown(inputs, proof);
|
|
182
|
+
return { context, side, spendPoint, viewPoint, encPub };
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** The same known-halves side, with the DLEQ proof yielding between chunks. */
|
|
186
|
+
export async function buildOwnSideFromHalvesChunked(order, { spendHalf, viewHalf } = {}, options = {}) {
|
|
187
|
+
const context = contextOf(order);
|
|
188
|
+
const b = builder();
|
|
189
|
+
const inputs = knownHalves(b, { spendHalf, viewHalf });
|
|
190
|
+
const proof = await b.dleq.proveChunked(inputs.half, context, options);
|
|
191
|
+
const { side, spendPoint, viewPoint, encPub } = sideFromKnown(inputs, proof);
|
|
192
|
+
return { context, side, spendPoint, viewPoint, encPub, commitHalf: norm(b.halfCommitment(inputs.half)) };
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* THE SAME LOCAL SIDE WITHOUT A SECOND PROOF. A path that already received a verified proof in the firm request
|
|
197
|
+
* (or in the quote) only needs this side's points, view point, encryption key and half for the record and the
|
|
198
|
+
* commitment. Running `prove` again costs ~3 s and its result is never sent. The returned side deliberately has
|
|
199
|
+
* `proof: null`: callers that need a proof must build it, not receive a plausible-looking empty object.
|
|
200
|
+
*/
|
|
201
|
+
export function buildOwnSideFromHalvesKnown(order, { spendHalf, viewHalf } = {}) {
|
|
202
|
+
const context = contextOf(order);
|
|
203
|
+
const b = builder();
|
|
204
|
+
const inputs = knownHalves(b, { spendHalf, viewHalf });
|
|
205
|
+
const { side, spendPoint, viewPoint, encPub } = sideFromKnown(inputs, null);
|
|
206
|
+
return { context, side, spendPoint, viewPoint, encPub, commitHalf: norm(b.halfCommitment(inputs.half)) };
|
|
161
207
|
}
|
|
162
208
|
|
|
163
209
|
/**
|
|
@@ -167,12 +213,12 @@ export function buildOwnSideFromHalves(order, { spendHalf, viewHalf } = {}) {
|
|
|
167
213
|
* against its point. The sandbox stand-in is built here too and marked: it must not be passed off as a real
|
|
168
214
|
* provider.
|
|
169
215
|
*/
|
|
170
|
-
|
|
216
|
+
function acceptedCounterparty({ context, side = null, counterparty = null, standIn = false, mock = null }) {
|
|
171
217
|
let accepted = null;
|
|
172
218
|
if (counterparty && typeof counterparty === "object") {
|
|
173
219
|
const pub = counterparty.pub && typeof counterparty.pub === "object" ? counterparty.pub : {};
|
|
174
220
|
// THE ORDER-QUOTE FIELD NAMES ARE THE ONES THE CORE ITSELF RETURNS (a defect found). The counterparty's side
|
|
175
|
-
// comes from `
|
|
221
|
+
// comes from `firmRelay`, and there the point is called `edPointClaimer`, the view half - `viewHalfClaimer`
|
|
176
222
|
// (rfq/orderQuote.mjs). While only `edPub`/`viewPub` were accepted, the facade's own side was NOT accepted:
|
|
177
223
|
// start answered bad-input { field: "counterparty", missing: ["edPub"] } to its own answer. The engine knew
|
|
178
224
|
// this mapping (sdk/src/swap-flow.mjs: edPub: quote.edPointClaimer). We accept BOTH names.
|
|
@@ -192,14 +238,14 @@ export function acceptCounterparty({ context, side = null, counterparty = null,
|
|
|
192
238
|
};
|
|
193
239
|
} else if (standIn === true) {
|
|
194
240
|
// THE STAND-IN IS COMPUTED IN THE SAME CONTEXT AS THE ORDER: the string gets nothing appended. The same path
|
|
195
|
-
// as the
|
|
196
|
-
// not what the page runs on.
|
|
197
|
-
const
|
|
198
|
-
accepted = { proof: sameFormAsPoint(
|
|
199
|
-
viewHalf:
|
|
241
|
+
// as the flow (sdk/src/swap-flow.mjs, buildOwnSide) and the check - otherwise what would be checked is
|
|
242
|
+
// not what the page runs on. A chunked caller passes the mock it already built.
|
|
243
|
+
const built = mock || builder().newSide(context, true);
|
|
244
|
+
accepted = { proof: sameFormAsPoint(built.proof), edPub: norm(built.pub.ed), viewPoint: norm(built.viewPub),
|
|
245
|
+
viewHalf: built.viewHalf, half: built.half,
|
|
200
246
|
// THE STAND-IN DOES CARRY A COMMITMENT: it is derived from the half it just built, by the same formula
|
|
201
247
|
// the contract uses. The proof check below is therefore the real one, not a path that skips it.
|
|
202
|
-
commitHalfClaimer: norm(builder().halfCommitment(
|
|
248
|
+
commitHalfClaimer: norm(builder().halfCommitment(built.half)), sealed: null, providerId: null, standIn: true, mock: built };
|
|
203
249
|
} else {
|
|
204
250
|
throw new SdkError("bad-input", { field: "counterparty" });
|
|
205
251
|
}
|
|
@@ -214,6 +260,11 @@ export function acceptCounterparty({ context, side = null, counterparty = null,
|
|
|
214
260
|
// flow the half arrives from the chain via the commit/reveal mechanism, so a locked package honestly answers
|
|
215
261
|
// with a refusal rather than passing itself off as a working key handover.
|
|
216
262
|
const ownEncPriv = accepted.sealed && side && side.enc ? side.enc.priv : null;
|
|
263
|
+
return { accepted, ownEncPriv };
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export function acceptCounterparty({ context, side = null, counterparty = null, standIn = false }) {
|
|
267
|
+
const { accepted, ownEncPriv } = acceptedCounterparty({ context, side, counterparty, standIn });
|
|
217
268
|
let verdict = null;
|
|
218
269
|
try { verdict = builder().verifySide({ proof: accepted.proof, pub: { ed: accepted.edPub }, commitHalfClaimer: accepted.commitHalfClaimer }, context, accepted.sealed, ownEncPriv); }
|
|
219
270
|
catch { throw new SdkError("bad-input", { field: "counterparty" }); }
|
|
@@ -223,25 +274,40 @@ export function acceptCounterparty({ context, side = null, counterparty = null,
|
|
|
223
274
|
return accepted;
|
|
224
275
|
}
|
|
225
276
|
|
|
277
|
+
export async function acceptCounterpartyChunked({ context, side = null, counterparty = null, standIn = false, options = {} }) {
|
|
278
|
+
const mock = (counterparty || standIn !== true) ? null : await builder().newSideChunked(context, true, options);
|
|
279
|
+
const { accepted, ownEncPriv } = acceptedCounterparty({ context, side, counterparty, standIn, mock });
|
|
280
|
+
let verdict = null;
|
|
281
|
+
try { verdict = await builder().verifySideChunked({ proof: accepted.proof, pub: { ed: accepted.edPub }, commitHalfClaimer: accepted.commitHalfClaimer }, context, accepted.sealed, ownEncPriv, options); }
|
|
282
|
+
catch { throw new SdkError("bad-input", { field: "counterparty" }); }
|
|
283
|
+
if (!verdict || verdict.ok !== true) {
|
|
284
|
+
throw new SdkError("quote-refused", { step: "proof", why: verdict && verdict.reason ? "rejected" : "unknown" });
|
|
285
|
+
}
|
|
286
|
+
return accepted;
|
|
287
|
+
}
|
|
288
|
+
|
|
226
289
|
/**
|
|
227
290
|
* THE ORDER STEP AS A WHOLE: your own side (or one already built by the record), the counterparty's side and the
|
|
228
291
|
* joint address. It hands out the fields the record and the recovery file are assembled from; NOT A SINGLE empty
|
|
229
292
|
* value: an address is not assembled without the other's point, and that is a refusal, not an empty string.
|
|
230
293
|
*/
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
const own = side
|
|
294
|
+
function ownSideOf({ order, side, context }) {
|
|
295
|
+
return side
|
|
234
296
|
? { context, side, spendPoint: norm(side.pub && side.pub.ed), viewPoint: norm(side.viewPub),
|
|
235
297
|
encPub: norm(side.enc && side.enc.pub ? side.enc.pub : null) }
|
|
236
298
|
: buildOwnSide(order);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function checkOwnSide(own) {
|
|
237
302
|
const lack = [];
|
|
238
303
|
if (own.side.half === undefined || own.side.half === null) lack.push("half");
|
|
239
304
|
if (own.side.viewHalf === undefined || own.side.viewHalf === null) lack.push("viewHalf");
|
|
240
305
|
if (!isPoint(own.spendPoint)) lack.push("spendPoint");
|
|
241
306
|
if (!isPoint(own.viewPoint)) lack.push("viewPoint");
|
|
242
307
|
if (lack.length) throw new SdkError("bad-input", { field: "side", missing: lack });
|
|
308
|
+
}
|
|
243
309
|
|
|
244
|
-
|
|
310
|
+
function orderStepResult({ own, other, network }) {
|
|
245
311
|
const otherViewPoint = other.viewPoint || (other.viewHalf ? norm(builder().pointOf(other.viewHalf)) : null);
|
|
246
312
|
if (!otherViewPoint) throw new SdkError("bad-input", { field: "counterparty", missing: ["viewPoint"] });
|
|
247
313
|
|
|
@@ -279,3 +345,25 @@ export function orderStep({ order, side = null, counterparty = null, standIn = f
|
|
|
279
345
|
},
|
|
280
346
|
};
|
|
281
347
|
}
|
|
348
|
+
|
|
349
|
+
export function orderStep({ order, side = null, counterparty = null, standIn = false, network = null }) {
|
|
350
|
+
const context = contextOf(order);
|
|
351
|
+
const own = ownSideOf({ order, side, context });
|
|
352
|
+
checkOwnSide(own);
|
|
353
|
+
const other = acceptCounterparty({ context: own.context, side: own.side, counterparty, standIn });
|
|
354
|
+
return orderStepResult({ own, other, network });
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* THE CHUNKED ORDER STEP. Same steps and same result object as `orderStep`, but the proof and the verification
|
|
359
|
+
* yield to the event loop. It exists for a browser that must keep painting; it is not a second rule set.
|
|
360
|
+
*/
|
|
361
|
+
export async function orderStepChunked({ order, side = null, counterparty = null, standIn = false, network = null, options = {} }) {
|
|
362
|
+
const context = contextOf(order);
|
|
363
|
+
const own = side
|
|
364
|
+
? ownSideOf({ order, side, context })
|
|
365
|
+
: await buildOwnSideChunked(order, options);
|
|
366
|
+
checkOwnSide(own);
|
|
367
|
+
const other = await acceptCounterpartyChunked({ context: own.context, side: own.side, counterparty, standIn, options });
|
|
368
|
+
return orderStepResult({ own, other, network });
|
|
369
|
+
}
|
package/src/primitives.mjs
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
// ATOMIC SWAP PRIMITIVES - FROM THE SAME npm PACKAGES AS THE PAGE BUNDLE.
|
|
2
2
|
//
|
|
3
|
-
// The
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
// different cache".
|
|
3
|
+
// The order builder takes exactly five names: ed25519, secp256k1, keccak256, sha3_512, randomBytes. The
|
|
4
|
+
// order-side build modules (www/js/atomic/order.js) do NOT import them themselves - they arrive as parameters.
|
|
5
|
+
// That is what lets the SDK use the same primitives from the same packages instead of dragging a hashed build
|
|
6
|
+
// artefact into the core: a package never has a "version with a different cache".
|
|
8
7
|
//
|
|
9
8
|
// WHY EXACTLY THESE PACKAGES, AND NOT JUST ANY. keccak256 and sha3_512 are DIFFERENT functions, and they must
|
|
10
9
|
// not be confused: the commitment for a half is computed with keccak256 (exactly as Solidity does it), while the
|
package/src/probes.mjs
CHANGED
|
@@ -40,16 +40,22 @@ export async function probeMoneroNode({ url, fetchImpl = globalThis.fetch, timeo
|
|
|
40
40
|
signal: controller ? controller.signal : undefined,
|
|
41
41
|
});
|
|
42
42
|
} catch (error) {
|
|
43
|
+
if (timer) clearTimeout(timer);
|
|
43
44
|
const aborted = error && (error.name === "AbortError" || error.code === "ABORT_ERR");
|
|
44
45
|
return { ok: false, why: aborted ? "timeout" : "unreachable", ms: Date.now() - started };
|
|
45
|
-
} finally {
|
|
46
|
-
if (timer) clearTimeout(timer);
|
|
47
46
|
}
|
|
48
47
|
if (!response || !response.ok) {
|
|
48
|
+
if (timer) clearTimeout(timer);
|
|
49
49
|
return { ok: false, why: "http", status: response ? response.status : null, ms: Date.now() - started };
|
|
50
50
|
}
|
|
51
51
|
let body = null;
|
|
52
|
-
|
|
52
|
+
// THE TIMER COVERS THE BODY TOO. Clearing it when the headers arrived left a node that sent `{` and stopped
|
|
53
|
+
// holding the whole call forever.
|
|
54
|
+
try { body = await response.json(); } catch {
|
|
55
|
+
if (timer) clearTimeout(timer);
|
|
56
|
+
return { ok: false, why: "not-json", ms: Date.now() - started };
|
|
57
|
+
}
|
|
58
|
+
if (timer) clearTimeout(timer);
|
|
53
59
|
if (!body || body.error) {
|
|
54
60
|
return { ok: false, why: "rpc", rpc: body && body.error ? body.error.code ?? null : null, ms: Date.now() - started };
|
|
55
61
|
}
|
package/src/public/networks.d.ts
CHANGED
|
@@ -63,3 +63,48 @@ export declare const CHAINS: readonly Chain[];
|
|
|
63
63
|
export declare const DEX_CHAINS: readonly string[];
|
|
64
64
|
export declare const DEFAULT_CHAIN: string;
|
|
65
65
|
export declare const ASYNC_ROUTE_PROVIDERS: Readonly<Record<string, AsyncRouteProvider>>;
|
|
66
|
+
|
|
67
|
+
/** One contract/program artifact in a deployment manifest. */
|
|
68
|
+
export interface DeploymentArtifact {
|
|
69
|
+
readonly role: string;
|
|
70
|
+
readonly kind: string;
|
|
71
|
+
readonly address: string;
|
|
72
|
+
readonly addressFormat: string;
|
|
73
|
+
readonly codeHash?: string;
|
|
74
|
+
readonly hashKind?: string;
|
|
75
|
+
readonly tx: { readonly kind: string; readonly value: string };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** A VM-neutral deployment pin. Only the EVM artifacts are generated today. */
|
|
79
|
+
export interface DeploymentPin {
|
|
80
|
+
readonly vm: string;
|
|
81
|
+
readonly network: string;
|
|
82
|
+
readonly caip2: string;
|
|
83
|
+
readonly chainRef: string;
|
|
84
|
+
readonly status: "live" | "simulated" | "retired";
|
|
85
|
+
readonly release: {
|
|
86
|
+
readonly tag: string | null;
|
|
87
|
+
readonly commit: string | null;
|
|
88
|
+
readonly toolchain: string | null;
|
|
89
|
+
readonly deployedAt: string | null;
|
|
90
|
+
};
|
|
91
|
+
readonly anchor: { readonly kind: string; readonly value: string };
|
|
92
|
+
readonly artifacts: Readonly<Record<string, DeploymentArtifact>>;
|
|
93
|
+
/** EVM compatibility view used by `ChainConfig.escrow`. */
|
|
94
|
+
readonly escrow: {
|
|
95
|
+
readonly address: string;
|
|
96
|
+
readonly mode: string | null;
|
|
97
|
+
readonly deploymentBlock: number;
|
|
98
|
+
readonly cashier: string;
|
|
99
|
+
readonly registry: string;
|
|
100
|
+
readonly implementationCodeHash: string;
|
|
101
|
+
};
|
|
102
|
+
readonly knownFactoryCodes: readonly string[];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export declare const DEPLOYMENTS: Readonly<Record<string, DeploymentPin>>;
|
|
106
|
+
export declare const DEPLOYMENT_CHAINS: readonly string[];
|
|
107
|
+
export declare const DEPLOYMENT_VMS: readonly string[];
|
|
108
|
+
export declare function deploymentFor(
|
|
109
|
+
chainOrId: string | number | { readonly id?: string; readonly network?: string; readonly caip2?: string } | null,
|
|
110
|
+
): DeploymentPin | null;
|
package/src/public/networks.mjs
CHANGED
|
@@ -6,4 +6,13 @@
|
|
|
6
6
|
//
|
|
7
7
|
// Names only: the engine owns the values. Nothing here is re-implemented.
|
|
8
8
|
|
|
9
|
-
export {
|
|
9
|
+
export {
|
|
10
|
+
ASYNC_ROUTE_PROVIDERS,
|
|
11
|
+
CHAINS,
|
|
12
|
+
DEFAULT_CHAIN,
|
|
13
|
+
DEX_CHAINS,
|
|
14
|
+
DEPLOYMENTS,
|
|
15
|
+
DEPLOYMENT_CHAINS,
|
|
16
|
+
DEPLOYMENT_VMS,
|
|
17
|
+
deploymentFor,
|
|
18
|
+
} from "../../engine/core/config.js";
|
package/src/public/recovery.d.ts
CHANGED
|
@@ -334,7 +334,7 @@ export interface FoundSwap {
|
|
|
334
334
|
readonly transactionHash: string | null;
|
|
335
335
|
readonly blockNumber: number | null;
|
|
336
336
|
readonly logIndex: number | null;
|
|
337
|
-
/** The settlement block timestamp in seconds, when
|
|
337
|
+
/** The settlement block timestamp in seconds, when read through `evmBlockTime` or `evmBlockTimes`; null otherwise. */
|
|
338
338
|
readonly blockTime: number | null;
|
|
339
339
|
/** The settlement asset of the escrow. Current contracts are native-only. */
|
|
340
340
|
readonly settlementToken: "native";
|
|
@@ -420,6 +420,18 @@ export declare function readEscrowEvents(request: {
|
|
|
420
420
|
toBlock?: number | string;
|
|
421
421
|
}): Promise<EscrowEvent[]>;
|
|
422
422
|
|
|
423
|
+
/**
|
|
424
|
+
* Read the same three settlement events without naming any escrow to the RPC.
|
|
425
|
+
*
|
|
426
|
+
* The request carries only the event topics and the block range; the caller filters the returned events by
|
|
427
|
+
* `escrow`. This is the privacy-preserving path for a recovery page.
|
|
428
|
+
*/
|
|
429
|
+
export declare function readEscrowEventsByTopic(request: {
|
|
430
|
+
evmLogs: (request: { topics: (string | null)[][]; fromBlock: number | string; toBlock: number | string }) => Promise<unknown[]>;
|
|
431
|
+
fromBlock?: number | string;
|
|
432
|
+
toBlock?: number | string;
|
|
433
|
+
}): Promise<EscrowEvent[]>;
|
|
434
|
+
|
|
423
435
|
/** Finds orders whose commitment was made from the key's halves. */
|
|
424
436
|
export declare function findSwaps(request: {
|
|
425
437
|
mnemonic: string;
|
|
@@ -436,6 +448,10 @@ export declare function findSwaps(request: {
|
|
|
436
448
|
toBlock?: number | string;
|
|
437
449
|
/** Reads the settlement block timestamp, in seconds: (blockNumber) -> seconds. */
|
|
438
450
|
evmBlockTime?: (blockNumber: number) => Promise<number>;
|
|
451
|
+
/** Reads timestamps once for the unique matched block numbers, in first-seen order. Takes precedence over
|
|
452
|
+
* `evmBlockTime`; never falls back to it. Missing/null entries mean `no-block-time`; Error entries or a rejected
|
|
453
|
+
* batch mean `block-time-read`. Each matched order is retained, including items whose timestamp failed. */
|
|
454
|
+
evmBlockTimes?: (blockNumbers: readonly number[]) => Promise<ReadonlyMap<number, number | null | Error>>;
|
|
439
455
|
/** Reads contract code: (address) -> 0x-hex. Used to read the XMR amount from an order clone. */
|
|
440
456
|
evmCode?: (address: string) => Promise<string>;
|
|
441
457
|
/** The Monero tip at the time of the search: () -> height. */
|
package/src/public/recovery.mjs
CHANGED
package/src/public/xmr.mjs
CHANGED
|
@@ -58,7 +58,7 @@ export {
|
|
|
58
58
|
plainLoopbackAllowed,
|
|
59
59
|
} from "../../engine/monero/daemonAddress.js";
|
|
60
60
|
|
|
61
|
-
// WHAT A TRANSACTION WILL COST: the daemon's price per
|
|
61
|
+
// WHAT A TRANSACTION WILL COST: the daemon's price per byte, by priority, and the arithmetic that turns it into
|
|
62
62
|
// a fee. The page learned the fee only after signing.
|
|
63
63
|
export { moneroFeeEstimate, feeForBytes } from "../feeEstimate.mjs";
|
|
64
64
|
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// THE ONE PLACE THE QUOTE LIFETIME AND ITS START MARGIN ARE NAMED.
|
|
2
|
+
//
|
|
3
|
+
// A firm quote is signed with `validUntil`, and the SDK refuses to start a swap when less than the start margin is left.
|
|
4
|
+
// A node that signs a shorter life than that margin is refusing its own quotes before the wallet is opened. The node
|
|
5
|
+
// imports this default and may override it with its own setting; the SDK keeps the value here so the two cannot drift.
|
|
6
|
+
export const LOCK_START_MARGIN_SEC = 30;
|
|
7
|
+
|
|
8
|
+
/** The default firm quote lifetime, in seconds. A node may override it, but the default is this value. */
|
|
9
|
+
export const DEFAULT_ORDER_QUOTE_TTL_SEC = 60;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* THE QUOTE MUST STILL HAVE ITS START MARGIN WHEN IT ARRIVES. The lock check runs seconds later, after the proof and
|
|
13
|
+
* the record work; a quote that is already at the margin is refused here, before the caller shows a confirmation.
|
|
14
|
+
* Returns `ok:false` for an unreadable clock too: an unknown lifetime is not a reason to show a quote.
|
|
15
|
+
*/
|
|
16
|
+
export function quoteLifeVerdict({ validUntil, nowSec, marginSec = LOCK_START_MARGIN_SEC } = {}) {
|
|
17
|
+
const until = Number(validUntil);
|
|
18
|
+
const now = Number(nowSec);
|
|
19
|
+
const margin = Number(marginSec);
|
|
20
|
+
if (!Number.isSafeInteger(until) || !Number.isSafeInteger(now) || !Number.isSafeInteger(margin) || margin < 0) {
|
|
21
|
+
return { ok: false, code: "quote-too-short", remainingSec: null, marginSec: Number.isSafeInteger(margin) ? margin : null };
|
|
22
|
+
}
|
|
23
|
+
const remainingSec = until - now;
|
|
24
|
+
return { ok: remainingSec > margin, code: remainingSec > margin ? null : "quote-too-short", remainingSec, marginSec: margin };
|
|
25
|
+
}
|