@ninsei-labs/sdk 0.55.4 → 0.56.1
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 +47 -0
- package/README.md +34 -20
- package/assets/vendors/MANIFEST.json +22 -0
- package/assets/vendors/sdk/sdk-browser.js +2058 -2
- package/engine/atomic/dleq2.js +74 -10
- package/engine/core/config.js +14 -14
- package/engine/core/store.js +25 -4
- package/engine/core/swap.js +52 -50
- package/engine/evm/factory.js +13 -20
- package/engine/sdk/bridge.js +1 -1
- package/index.d.ts +9 -16
- package/package.json +22 -7
- package/src/actions.mjs +49 -9
- package/src/adapters/evm-wallet.mjs +24 -5
- package/src/adapters/index.d.ts +66 -0
- package/src/adapters/index.mjs +0 -6
- package/src/codes.mjs +9 -0
- package/src/index.mjs +4 -3
- package/src/lock.mjs +1 -1
- package/src/provider/envFile.mjs +11 -1
- package/src/public/order.d.ts +4 -0
- package/src/public/recovery.d.ts +40 -54
- package/src/public/recovery.mjs +2 -8
- package/src/public/xmr.d.ts +14 -3
- package/src/quoteEip712Spec.mjs +9 -1
- package/src/quotes.mjs +21 -26
- package/src/record.mjs +3 -3
- package/src/recovery-key.mjs +132 -226
- package/src/relayFirmClient.mjs +40 -3
- package/src/relayQuote.mjs +1 -1
- package/src/relayRequest.mjs +12 -3
- package/src/swap-flow.mjs +59 -15
- package/src/swaps.mjs +115 -113
- package/src/sweep-restore.mjs +6 -2
- package/src/sweep.mjs +30 -11
- package/src/version.mjs +1 -1
- package/src/adapters/node-test-evm-wallet.mjs +0 -357
package/src/public/recovery.d.ts
CHANGED
|
@@ -269,14 +269,10 @@ export declare function recoveryFileName(swapId?: string | null): string;
|
|
|
269
269
|
export declare const RECOVERY_KEY_VERSION: number;
|
|
270
270
|
/** Twelve words, by the BIP39 rules. */
|
|
271
271
|
export declare const RECOVERY_KEY_WORDS: number;
|
|
272
|
-
/** The default number of v1 indices one `findSwaps` call scans. */
|
|
273
|
-
export declare const RECOVERY_SCAN_DEFAULT: number;
|
|
274
272
|
/** The store key a browser adapter keeps the key under. */
|
|
275
273
|
export declare const RECOVERY_KEY_STORE: string;
|
|
276
274
|
/** The first line of a plain backup file. */
|
|
277
275
|
export declare const RECOVERY_KEY_FILE_MAGIC: string;
|
|
278
|
-
/** The domain half derivation binds to; the chain id and swap number join it. */
|
|
279
|
-
export declare const RECOVERY_KEY_DOMAIN: string;
|
|
280
276
|
/** The salt-based derivation domain; the chain, factory, role and order salt join it. */
|
|
281
277
|
export declare const RECOVERY_KEY_DOMAIN_V2: string;
|
|
282
278
|
/** The domain of the counterparty's view half, derived from the same one key. */
|
|
@@ -300,7 +296,6 @@ export interface RecoveryKey {
|
|
|
300
296
|
|
|
301
297
|
/** A derived swap number: the halves cross JSON as hex scalars. */
|
|
302
298
|
export interface TakerHalves {
|
|
303
|
-
readonly index: number;
|
|
304
299
|
readonly binding: string;
|
|
305
300
|
readonly spendHalf: string;
|
|
306
301
|
readonly viewHalf: string;
|
|
@@ -311,9 +306,8 @@ export interface TakerHalves {
|
|
|
311
306
|
readonly spendCommitment: string;
|
|
312
307
|
}
|
|
313
308
|
|
|
314
|
-
/** A salt-based derivation:
|
|
315
|
-
export interface TakerHalvesV2 extends
|
|
316
|
-
readonly index: null;
|
|
309
|
+
/** A salt-based derivation: the public order salt is the input. */
|
|
310
|
+
export interface TakerHalvesV2 extends TakerHalves {
|
|
317
311
|
readonly derivation: "salt-v2";
|
|
318
312
|
readonly factory: string;
|
|
319
313
|
readonly role: string;
|
|
@@ -353,10 +347,8 @@ export interface FoundSwap {
|
|
|
353
347
|
* the expected clone. */
|
|
354
348
|
readonly xmrAmount: string | null;
|
|
355
349
|
readonly xmrAmountReason: "event" | "no-code-reader" | "code" | "not-clone" | null;
|
|
356
|
-
/** The
|
|
357
|
-
readonly
|
|
358
|
-
/** Which derivation found this order. v1 orders keep recovering through the index path. */
|
|
359
|
-
readonly derivation: "index-v1" | "salt-v2";
|
|
350
|
+
/** The derivation that found this order. */
|
|
351
|
+
readonly derivation: "salt-v2";
|
|
360
352
|
/** The factory the order was read from; the v2 binding needs it. */
|
|
361
353
|
readonly factory: string;
|
|
362
354
|
readonly side: "locker" | "claimer";
|
|
@@ -379,16 +371,12 @@ export declare function createRecoveryKey(options?: { createdAt?: string | Date
|
|
|
379
371
|
export declare function importRecoveryKey(mnemonic: string, options?: { createdAt?: string | Date }): RecoveryKey;
|
|
380
372
|
/** The short public fingerprint (four hex characters) of the words. */
|
|
381
373
|
export declare function fingerprintOf(mnemonic: string): string;
|
|
382
|
-
/** The binding for a chain and swap number: `ninsei-taker-v1|<chainId>|<index>`. */
|
|
383
|
-
export declare function recoveryBinding(chainId: number, index: number): string;
|
|
384
374
|
/** The salt-based binding: `ninsei-taker-v2|<chainId>|<factory>|<role>|<salt>`. */
|
|
385
375
|
export declare function recoveryBindingV2(request: { chainId: number; factory: string; role?: string; salt: string }): string;
|
|
386
376
|
/** Normalises a 32-byte salt from an event word, a hex string, a bigint or a safe integer. */
|
|
387
377
|
export declare function recoverySaltOf(value: string | number | bigint): string;
|
|
388
378
|
/** A fresh 32-byte public salt for one salt-based order. */
|
|
389
379
|
export declare function newRecoverySalt(): string;
|
|
390
|
-
/** Derives the taker spend and view halves for one swap number. */
|
|
391
|
-
export declare function takerHalves(request: { mnemonic: string; chainId: number; index: number }): TakerHalves;
|
|
392
380
|
/** Derives the taker halves from a public per-order salt; no index is reserved. */
|
|
393
381
|
export declare function takerHalvesV2(request: { mnemonic: string; chainId: number; factory: string; role?: string; salt: string }): TakerHalvesV2;
|
|
394
382
|
/** The stable backup name, with `DO-NOT-DELETE` in it on purpose. */
|
|
@@ -397,51 +385,55 @@ export declare function recoveryKeyFileName(request: { mnemonic?: string; finger
|
|
|
397
385
|
export declare function recoveryKeyText(request: { mnemonic: string; createdAt?: string | Date }): string;
|
|
398
386
|
/** A backup file, optionally encrypted with a passphrase of at least 12 characters. */
|
|
399
387
|
export declare function createRecoveryKeyFile(request: { mnemonic: string; createdAt?: string | Date; passphrase?: string }): Promise<string>;
|
|
400
|
-
/** Reads a plain or encrypted backup file and validates the words.
|
|
388
|
+
/** Reads a plain or encrypted backup file and validates the words. `createdAt` is the file's date: the plain
|
|
389
|
+
* header day at 00:00 UTC, the password envelope's sealed time. */
|
|
401
390
|
export declare function openRecoveryKeyFile(contents: string, passphrase?: string): Promise<RecoveryKey>;
|
|
402
391
|
/** Saves the key through a storage adapter. */
|
|
403
|
-
export declare function saveRecoveryKey(storage: RecoveryKeyStorage, key: RecoveryKey & {
|
|
392
|
+
export declare function saveRecoveryKey(storage: RecoveryKeyStorage, key: RecoveryKey & { backupConfirmed?: boolean }): RecoveryKey;
|
|
404
393
|
/** Reads the key from a storage adapter, or null. */
|
|
405
|
-
export declare function loadRecoveryKey(storage: RecoveryKeyStorage): (RecoveryKey & {
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
394
|
+
export declare function loadRecoveryKey(storage: RecoveryKeyStorage): (RecoveryKey & { backupConfirmed?: boolean }) | null;
|
|
395
|
+
|
|
396
|
+
/** One settlement event read in bulk; the escrow is named by its address. */
|
|
397
|
+
export interface EscrowEvent {
|
|
398
|
+
readonly escrow: string;
|
|
399
|
+
readonly event: "HalfRevealed" | "Ready" | "Declined";
|
|
400
|
+
readonly blockNumber: number | string | null;
|
|
401
|
+
readonly transactionHash: string | null;
|
|
402
|
+
readonly logIndex: number | string | null;
|
|
403
|
+
readonly half?: string;
|
|
404
|
+
readonly byClaimer?: boolean;
|
|
405
|
+
readonly by?: string;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/** The three settlement event topics; exported so a caller does not copy the signatures. */
|
|
409
|
+
export declare const ESCROW_EVENT_TOPICS: {
|
|
410
|
+
readonly halfRevealed: string;
|
|
411
|
+
readonly ready: string;
|
|
412
|
+
readonly declined: string;
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
/** Read HalfRevealed, Ready and Declined for a list of escrows in one log request. */
|
|
416
|
+
export declare function readEscrowEvents(request: {
|
|
417
|
+
escrows: readonly string[];
|
|
418
|
+
evmLogs: (request: { address: readonly string[]; topics: (string | null)[][]; fromBlock: number | string; toBlock: number | string }) => Promise<unknown[]>;
|
|
416
419
|
fromBlock?: number | string;
|
|
417
420
|
toBlock?: number | string;
|
|
418
|
-
}): Promise<
|
|
419
|
-
|
|
420
|
-
export declare function releaseRecoveryIndex(storage: RecoveryKeyStorage, index: number): void;
|
|
421
|
-
/** Retires a number after its order exists on chain. */
|
|
422
|
-
export declare function commitRecoveryIndex(storage: RecoveryKeyStorage, index: number): void;
|
|
421
|
+
}): Promise<EscrowEvent[]>;
|
|
422
|
+
|
|
423
423
|
/** Finds orders whose commitment was made from the key's halves. */
|
|
424
424
|
export declare function findSwaps(request: {
|
|
425
425
|
mnemonic: string;
|
|
426
426
|
chainId: number;
|
|
427
|
-
factory
|
|
427
|
+
/** One factory. When omitted, `factories` must name the chain's history. */
|
|
428
|
+
factory?: string | null;
|
|
429
|
+
/** Every factory of the chain, with its own deployment block; older orders stay searchable. */
|
|
430
|
+
factories?: readonly (string | { readonly address?: string; readonly factory?: string; readonly deploymentBlock?: number | null })[] | null;
|
|
428
431
|
address?: string | null;
|
|
429
432
|
evmLogs: (request: { address: string; topics: (string | null)[]; fromBlock: number | string; toBlock: number | string }) => Promise<unknown[]>;
|
|
430
433
|
fromBlock?: number | string;
|
|
431
434
|
/** The factory's deployment block from the chain registry; used when `fromBlock` is omitted. */
|
|
432
435
|
deploymentBlock?: number | null;
|
|
433
436
|
toBlock?: number | string;
|
|
434
|
-
/** Deprecated and ignored: discovery no longer stops after a run of empty numbers. */
|
|
435
|
-
gap?: number;
|
|
436
|
-
/** The first index to try. Defaults to 0; a continuation passes the previous `nextIndex`. */
|
|
437
|
-
fromIndex?: number;
|
|
438
|
-
/** How many indices this call may try. Defaults to `RECOVERY_SCAN_DEFAULT` (1000), not the allocator ceiling. */
|
|
439
|
-
maxIndex?: number;
|
|
440
|
-
/** Stop the scan between chunks. An aborted scan returns `complete: false`, `incompleteReason: "aborted"` and
|
|
441
|
-
* the `nextIndex` to resume from. */
|
|
442
|
-
signal?: { readonly aborted: boolean } | null;
|
|
443
|
-
/** Called after every chunk and after the last index, with the count and the index just scanned. */
|
|
444
|
-
onProgress?: ((value: { readonly scanned: number; readonly index: number }) => void) | null;
|
|
445
437
|
/** Reads the settlement block timestamp, in seconds: (blockNumber) -> seconds. */
|
|
446
438
|
evmBlockTime?: (blockNumber: number) => Promise<number>;
|
|
447
439
|
/** Reads contract code: (address) -> 0x-hex. Used to read the XMR amount from an order clone. */
|
|
@@ -459,13 +451,7 @@ export declare function findSwaps(request: {
|
|
|
459
451
|
fetchImpl?: typeof fetch;
|
|
460
452
|
}): Promise<{
|
|
461
453
|
swaps: FoundSwap[];
|
|
462
|
-
|
|
463
|
-
/** The last index tried, or null when no index was scanned. */
|
|
464
|
-
searchedUpTo: number | null;
|
|
465
|
-
/** True when every order in the logs was matched, or when the allocator range was searched to its end. */
|
|
454
|
+
/** True when every order in the logs was read. There is no index range to exhaust. */
|
|
466
455
|
complete: boolean;
|
|
467
|
-
/** `max-index` or `aborted` when a bound or the caller stopped the search before every order was matched. */
|
|
468
|
-
incompleteReason?: string;
|
|
469
|
-
/** The next index to pass as `fromIndex`; absent when the search is complete. */
|
|
470
|
-
nextIndex?: number;
|
|
471
456
|
}>;
|
|
457
|
+
|
package/src/public/recovery.mjs
CHANGED
|
@@ -24,7 +24,6 @@ export {
|
|
|
24
24
|
// ONE RECOVERY KEY FOR EVERY SWAP (sdk#79): the taker's key, its derivation, its file and the on-chain search.
|
|
25
25
|
export {
|
|
26
26
|
RECOVERY_KEY_ALG,
|
|
27
|
-
RECOVERY_KEY_DOMAIN,
|
|
28
27
|
RECOVERY_KEY_DOMAIN_V2,
|
|
29
28
|
RECOVERY_KEY_ENVELOPE_VERSION,
|
|
30
29
|
RECOVERY_KEY_FILE_MAGIC,
|
|
@@ -33,25 +32,20 @@ export {
|
|
|
33
32
|
RECOVERY_KEY_VERSION,
|
|
34
33
|
MAKER_VIEW_HALF_DOMAIN,
|
|
35
34
|
RECOVERY_KEY_WORDS,
|
|
36
|
-
RECOVERY_SCAN_DEFAULT,
|
|
37
|
-
commitRecoveryIndex,
|
|
38
35
|
createRecoveryKey,
|
|
39
36
|
createRecoveryKeyFile,
|
|
40
37
|
findSwaps,
|
|
38
|
+
readEscrowEvents,
|
|
39
|
+
ESCROW_EVENT_TOPICS,
|
|
41
40
|
fingerprintOf,
|
|
42
41
|
importRecoveryKey,
|
|
43
42
|
loadRecoveryKey,
|
|
44
43
|
newRecoverySalt,
|
|
45
44
|
openRecoveryKeyFile,
|
|
46
|
-
recoveryBinding,
|
|
47
45
|
recoveryBindingV2,
|
|
48
|
-
recoveryIndexTaken,
|
|
49
46
|
recoverySaltOf,
|
|
50
47
|
recoveryKeyFileName,
|
|
51
48
|
recoveryKeyText,
|
|
52
|
-
releaseRecoveryIndex,
|
|
53
|
-
reserveRecoveryIndex,
|
|
54
49
|
saveRecoveryKey,
|
|
55
|
-
takerHalves,
|
|
56
50
|
takerHalvesV2,
|
|
57
51
|
} from "../recovery-key.mjs";
|
package/src/public/xmr.d.ts
CHANGED
|
@@ -194,10 +194,18 @@ export interface Dleq2ProofPart {
|
|
|
194
194
|
readonly sig: Dleq2Signature;
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
-
/**
|
|
197
|
+
/** A Schnorr proof that the point is a pure multiple of the curve generator. */
|
|
198
|
+
export interface Dleq2KnowledgeProof {
|
|
199
|
+
readonly R: string;
|
|
200
|
+
readonly s: string;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** The proof: the point X on both curves, one knowledge proof per curve, and one part per bit. */
|
|
198
204
|
export interface Dleq2Proof {
|
|
199
205
|
readonly XA: string;
|
|
200
206
|
readonly XB: string;
|
|
207
|
+
readonly pokA: Dleq2KnowledgeProof;
|
|
208
|
+
readonly pokB: Dleq2KnowledgeProof;
|
|
201
209
|
readonly proofs: readonly Dleq2ProofPart[];
|
|
202
210
|
}
|
|
203
211
|
|
|
@@ -216,6 +224,8 @@ export interface Dleq2Prepared {
|
|
|
216
224
|
readonly XA: string;
|
|
217
225
|
readonly XB: string;
|
|
218
226
|
readonly context: string;
|
|
227
|
+
readonly pokA: Dleq2KnowledgeProof;
|
|
228
|
+
readonly pokB: Dleq2KnowledgeProof;
|
|
219
229
|
readonly bits: readonly Dleq2PreparedBit[];
|
|
220
230
|
}
|
|
221
231
|
|
|
@@ -241,8 +251,9 @@ export interface Dleq2 {
|
|
|
241
251
|
readonly curves: { readonly A: Dleq2Curve; readonly B: Dleq2Curve };
|
|
242
252
|
/** The whole proof. `onBit` reports progress every 16 bits and at the last. */
|
|
243
253
|
readonly prove: (x: bigint | string | number, context: string, onBit?: (done: number, total: number) => void) => Dleq2Proof;
|
|
244
|
-
/** Verifies a proof of untrusted shape: form is checked before counting, and every refusal is named.
|
|
245
|
-
|
|
254
|
+
/** Verifies a proof of untrusted shape: form is checked before counting, and every refusal is named.
|
|
255
|
+
* `requireKnowledge` defaults to true; set it to false only to inspect historical proofs. */
|
|
256
|
+
readonly verify: (proof: unknown, context: string, options?: { readonly requireKnowledge?: boolean }) => Dleq2Verdict;
|
|
246
257
|
/** Step 1: the commitments. Sequential by construction. */
|
|
247
258
|
readonly prepareProof: (x: bigint | string | number, context: string) => Dleq2Prepared;
|
|
248
259
|
/** Step 2: one bit, on the prepared data alone - it needs neither the half nor the other bits. */
|
package/src/quoteEip712Spec.mjs
CHANGED
|
@@ -35,19 +35,24 @@
|
|
|
35
35
|
// claimTip - the tip the escrow pays to whoever sends `claim`, out of the payout, in the same
|
|
36
36
|
// transaction (#18). It is inside the signed set so a provider cannot raise it after the
|
|
37
37
|
// taker has seen the quote. Zero means no tip and is the only value a buy uses.
|
|
38
|
+
// commitHalfLocker, - the depositor's half commitment and two Monero points. They used to travel beside the
|
|
39
|
+
// edPointLocker, quote, outside the signature: a taker could show one set and fund another escrow with
|
|
40
|
+
// edViewPointLocker a decoy. The chain now reads them from the signed quote, so one quote names one escrow.
|
|
38
41
|
//
|
|
39
42
|
// The domain's verifyingContract is the escrow FACTORY taken from the order: the contract that will verify the
|
|
40
43
|
// quote in EVM (stage 2). The type order, the domain name and the version are part of the protocol - they may
|
|
41
44
|
// change only together with the quote version.
|
|
42
45
|
export const ORDER_QUOTE_DOMAIN_NAME = "NinseiEscrowFactory";
|
|
43
46
|
export const ORDER_QUOTE_DOMAIN_VERSION = "1";
|
|
47
|
+
// 10: the signed EIP-712 field set grew the depositor's half commitment and two Monero points. They used to be
|
|
48
|
+
// factory arguments outside the signature, which let one quote fund an escrow with decoy locker fields.
|
|
44
49
|
// 9: the signed EIP-712 field set grew `claimTip` (#18) - the tip a third-party sender of `claim` takes from the
|
|
45
50
|
// payout, covered by the provider's signature like every other condition.
|
|
46
51
|
// 8: the field set grew `xmrAmount` (#110 step 3). This is the request-shape generation label, and it moves WITH the
|
|
47
52
|
// field set (see the note above). The DOMAIN name and the domain version string are UNCHANGED by it: they name the
|
|
48
53
|
// domain (the factory address and the chain), which did not change. So here the label and the domain version string
|
|
49
54
|
// move apart, and that is deliberate - the label tracks the message shape, not the domain identity.
|
|
50
|
-
export const ORDER_QUOTE_VERSION =
|
|
55
|
+
export const ORDER_QUOTE_VERSION = 10;
|
|
51
56
|
|
|
52
57
|
// The domain type string is assembled from parts ON PURPOSE. A single literal of it is a phrase of several
|
|
53
58
|
// space-separated words, and the SDK check reads such literals as user-facing text. Do not "simplify" it.
|
|
@@ -77,6 +82,9 @@ export const ORDER_QUOTE_FIELDS = [
|
|
|
77
82
|
["nonce", "uint256"],
|
|
78
83
|
["xmrAmount", "uint256"],
|
|
79
84
|
["claimTip", "uint256"],
|
|
85
|
+
["commitHalfLocker", "bytes32"],
|
|
86
|
+
["edPointLocker", "bytes32"],
|
|
87
|
+
["edViewPointLocker", "bytes32"],
|
|
80
88
|
];
|
|
81
89
|
export const ORDER_QUOTE_TYPE = "OrderQuote(" + ORDER_QUOTE_FIELDS.map((f) => f[1] + " " + f[0]).join(",") + ")";
|
|
82
90
|
|
package/src/quotes.mjs
CHANGED
|
@@ -21,7 +21,7 @@ import * as engine from "./engine.mjs";
|
|
|
21
21
|
import { orderQuoteMissingFields, recoverOrderQuoteKey } from "./quoteEip712.mjs";
|
|
22
22
|
import { claimGasGiftWei } from "../engine/evm/claimGas.js";
|
|
23
23
|
import { parseXmr } from "../engine/core/xmrAmount.js";
|
|
24
|
-
import {
|
|
24
|
+
import { takerHalvesV2, recoverySaltOf } from "./recovery-key.mjs";
|
|
25
25
|
import { acceptCounterparty, buildOwnSideFromHalves, jointAddress } from "./order.mjs";
|
|
26
26
|
import { requestFirmQuote } from "./relayFirmClient.mjs";
|
|
27
27
|
// THE CHAIN READ NEEDED TO ASK THE REGISTRY WHO OWNS THE KEY. The selector is COMPUTED from the signature, not
|
|
@@ -439,8 +439,11 @@ export function createQuotes({ config, http, now = () => Date.now(), evmCall = n
|
|
|
439
439
|
// milliseconds (Date.now), so exactly ONE boundary is converted - "now", not the quote value itself: one
|
|
440
440
|
// unit for the value, one conversion at the input.
|
|
441
441
|
const nowSec = Math.floor(now() / 1000);
|
|
442
|
-
|
|
443
|
-
|
|
442
|
+
// THE TTL IS MANDATORY AND MUST BE IN THE FUTURE. Zero, a fraction, an unsafe integer and a missing value are
|
|
443
|
+
// not "never expires": the relay path already requires a safe future integer, and a direct quote must not be
|
|
444
|
+
// weaker than the same quote after it crosses the relay.
|
|
445
|
+
if (!Number.isSafeInteger(validUntil) || validUntil <= nowSec) {
|
|
446
|
+
fail("quote-expired", { step: "signature", validUntil: quote.validUntil });
|
|
444
447
|
}
|
|
445
448
|
// RECOVER, THEN MATCH THE NAMED KEY. A signature that does not recover is one refusal; a valid signature
|
|
446
449
|
// that recovers to a DIFFERENT address is another (the quote names a key that did not sign it).
|
|
@@ -673,8 +676,11 @@ export function createQuotes({ config, http, now = () => Date.now(), evmCall = n
|
|
|
673
676
|
// milliseconds (Date.now), so exactly ONE boundary is converted - "now", not the quote value itself: one
|
|
674
677
|
// unit for the value, one conversion at the input.
|
|
675
678
|
const nowSec = Math.floor(now() / 1000);
|
|
676
|
-
|
|
677
|
-
|
|
679
|
+
// THE TTL IS MANDATORY AND MUST BE IN THE FUTURE. Zero, a fraction, an unsafe integer and a missing value are
|
|
680
|
+
// not "never expires": the relay path already requires a safe future integer, and a direct quote must not be
|
|
681
|
+
// weaker than the same quote after it crosses the relay.
|
|
682
|
+
if (!Number.isSafeInteger(validUntil) || validUntil <= nowSec) {
|
|
683
|
+
fail("quote-expired", { step: "signature", validUntil: quote.validUntil });
|
|
678
684
|
}
|
|
679
685
|
// RECOVER, THEN MATCH THE NAMED KEY. A signature that does not recover is one refusal; a valid signature
|
|
680
686
|
// that recovers to a DIFFERENT address is another (the quote names a key that did not sign it).
|
|
@@ -889,28 +895,17 @@ export function createQuotes({ config, http, now = () => Date.now(), evmCall = n
|
|
|
889
895
|
: request.recoveryKey && typeof request.recoveryKey.mnemonic === "string" ? request.recoveryKey.mnemonic : null;
|
|
890
896
|
if (!mnemonic) fail("bad-input", { field: "recoveryKey" });
|
|
891
897
|
const saltRequested = request.recoverySalt !== undefined && request.recoverySalt !== null;
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
if (
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
derivation = { kind: "index-v1", index };
|
|
901
|
-
} else {
|
|
902
|
-
if (!order.factory || !/^0x[0-9a-f]{40}$/i.test(String(order.factory))) fail("bad-input", { field: "order.factory" });
|
|
903
|
-
let salt = null;
|
|
904
|
-
try { salt = recoverySaltOf(saltRequested ? request.recoverySalt : order.salt); }
|
|
905
|
-
catch { fail("bad-input", { field: "recoverySalt" }); }
|
|
906
|
-
if (saltRequested) {
|
|
907
|
-
let orderSalt = null;
|
|
908
|
-
try { orderSalt = recoverySaltOf(order.salt); } catch { fail("bad-input", { field: "recoverySalt", why: "order-salt" }); }
|
|
909
|
-
if (salt !== orderSalt) fail("bad-input", { field: "recoverySalt", why: "order-salt" });
|
|
910
|
-
}
|
|
911
|
-
derived = takerHalvesV2({ mnemonic, chainId, factory: order.factory, salt });
|
|
912
|
-
derivation = { kind: "salt-v2", salt };
|
|
898
|
+
if (!order.factory || !/^0x[0-9a-f]{40}$/i.test(String(order.factory))) fail("bad-input", { field: "order.factory" });
|
|
899
|
+
let salt = null;
|
|
900
|
+
try { salt = recoverySaltOf(saltRequested ? request.recoverySalt : order.salt); }
|
|
901
|
+
catch { fail("bad-input", { field: "recoverySalt" }); }
|
|
902
|
+
if (saltRequested) {
|
|
903
|
+
let orderSalt = null;
|
|
904
|
+
try { orderSalt = recoverySaltOf(order.salt); } catch { fail("bad-input", { field: "recoverySalt", why: "order-salt" }); }
|
|
905
|
+
if (salt !== orderSalt) fail("bad-input", { field: "recoverySalt", why: "order-salt" });
|
|
913
906
|
}
|
|
907
|
+
const derived = takerHalvesV2({ mnemonic, chainId, factory: order.factory, salt });
|
|
908
|
+
const derivation = { kind: "salt-v2", salt };
|
|
914
909
|
const own = buildOwnSideFromHalves(order, { spendHalf: derived.spendHalf, viewHalf: derived.viewHalf });
|
|
915
910
|
const xa = secp256k1.Point.fromHex(own.side.proof.XA);
|
|
916
911
|
const clientHalf = {
|
package/src/record.mjs
CHANGED
|
@@ -44,11 +44,11 @@ export function ownSide(order = null, known = null) {
|
|
|
44
44
|
* edPointLocker, edViewPointLocker). The counterparty's half cannot and need not be put in: it will come from
|
|
45
45
|
* the order.
|
|
46
46
|
*/
|
|
47
|
-
export function createRecord(input, { order = null, side: knownSide = null } = {}) {
|
|
47
|
+
export function createRecord(input, { order = null, side: knownSide = null, store = null } = {}) {
|
|
48
48
|
if (!input || typeof input !== "object") throw new SdkError("bad-input", { field: "input" });
|
|
49
49
|
const side = knownSide || ownSide(order);
|
|
50
50
|
let swap = null;
|
|
51
|
-
try { swap = engine.swap.createSwap(input); } catch { throw new SdkError("bad-input", { field: "input" }); }
|
|
51
|
+
try { swap = engine.swap.createSwap(input, store); } catch { throw new SdkError("bad-input", { field: "input" }); }
|
|
52
52
|
const escrow = { ...(swap.escrow || {}),
|
|
53
53
|
// THE HALVES ARE A HEX STRING (a BigInt does not survive JSON), the points are in canonical form: that is how
|
|
54
54
|
// both the slot check against the chain and the address check read them.
|
|
@@ -74,6 +74,6 @@ export function createRecord(input, { order = null, side: knownSide = null } = {
|
|
|
74
74
|
// (www/js/ui/views/confirm.js: swap.orderQuoteId = flow.quoteId).
|
|
75
75
|
const quoteId = input && input.orderQuoteId;
|
|
76
76
|
if (quoteId !== undefined && quoteId !== null && quoteId !== "") record.orderQuoteId = quoteId;
|
|
77
|
-
try { engine.swap.saveSwap(record); } catch { throw new SdkError("storage-unavailable", { step: "save-swap" }); }
|
|
77
|
+
try { engine.swap.saveSwap(record, store); } catch { throw new SdkError("storage-unavailable", { step: "save-swap" }); }
|
|
78
78
|
return { swap: record, side, missing: ["counterparty-half"], nextStep: "order" };
|
|
79
79
|
}
|