@ninsei-labs/sdk 0.57.2 → 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 +16 -0
- package/README.md +64 -27
- package/THIRD_PARTY_NOTICES.md +2 -2
- package/assets/vendors/MANIFEST.json +1 -9
- package/assets/vendors/sdk/sdk-browser.js +4 -4
- package/engine/core/config.js +3 -22
- package/engine/core/rfqSource.js +6 -133
- package/engine/core/swap.js +1 -1
- package/engine/evm/index.js +3 -2
- package/engine/evm/session.js +46 -277
- 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 +23 -9
- package/engine/monero/wallet.js +31 -68
- package/engine/monero/wordlist.en.js +210 -0
- package/engine/recovery/restore.js +1 -1
- package/engine/sdk/bridge.js +7 -182
- package/engine/ui/walletModal.js +7 -27
- package/index.d.ts +187 -252
- package/package.json +4 -5
- package/src/codes.mjs +12 -0
- package/src/config.mjs +16 -54
- package/src/engine.mjs +3 -0
- package/src/index.mjs +24 -45
- package/src/order.mjs +2 -2
- package/src/public/recovery.d.ts +17 -1
- package/src/public/recovery.mjs +1 -0
- package/src/quotePolicy.mjs +25 -0
- package/src/quotes.mjs +21 -751
- package/src/readyWindow.mjs +76 -0
- package/src/recovery-key.mjs +39 -2
- package/src/recovery.mjs +11 -28
- package/src/relayClaim.mjs +132 -0
- package/src/relayFirmClient.mjs +3 -0
- package/src/relayQuote.mjs +5 -1
- package/src/swap-flow.mjs +49 -5
- package/src/swaps.mjs +301 -307
- package/src/sweep-action.mjs +73 -0
- package/src/sweep.mjs +7 -1
- package/src/version.mjs +1 -1
- package/src/xmr-arrival.mjs +275 -7
- package/src/xmrAmountPolicy.mjs +35 -0
- 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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ninsei-labs/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.58.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -25,7 +25,6 @@
|
|
|
25
25
|
"check:vendor-bundles": "node tools/check.mjs --only=vendor-bundles",
|
|
26
26
|
"check:dleq-vectors": "node tools/check-dleq-vectors.mjs",
|
|
27
27
|
"check:swap-network": "node tools/check.mjs --only=swap-network",
|
|
28
|
-
"check:quote-ttl": "node tools/check.mjs --only=quote-ttl",
|
|
29
28
|
"check:dleq-oracle": "node tools/check-dleq-oracle.mjs",
|
|
30
29
|
"check:vendor-bundles-teeth": "node tools/run-teeth-isolated.mjs tools/check-vendor-bundles-teeth.mjs",
|
|
31
30
|
"check:types": "node tools/check.mjs --only=types",
|
|
@@ -40,14 +39,12 @@
|
|
|
40
39
|
"check:sweep-half": "node tools/check-sweep-half.mjs",
|
|
41
40
|
"sync:version": "node tools/sync-version.mjs",
|
|
42
41
|
"check:restore": "node tools/check-restore.mjs",
|
|
43
|
-
"check:restore-height": "node tools/check-restore-height.mjs",
|
|
44
42
|
"check:wallet-factory": "node tools/check-wallet-factory.mjs",
|
|
45
43
|
"check:xmr-amount": "node tools/check-xmr-amount.mjs",
|
|
46
44
|
"check:sign-preview": "node tools/check-sign-preview.mjs",
|
|
47
45
|
"check:destination": "node tools/check-destination.mjs",
|
|
48
46
|
"check:codes-meta": "node tools/check-codes-meta.mjs",
|
|
49
47
|
"check:arrival-read": "node tools/check-arrival-read.mjs",
|
|
50
|
-
"check:sale-auth": "node tools/check-sale-auth.mjs",
|
|
51
48
|
"check:backup-confirmation": "node tools/check-backup-confirmation.mjs",
|
|
52
49
|
"check:key-view": "node tools/check-key-view.mjs",
|
|
53
50
|
"check:relay-view": "node tools/check-relay-view.mjs",
|
|
@@ -60,6 +57,7 @@
|
|
|
60
57
|
"check:sell-watch": "node tools/check-sell-watch.mjs",
|
|
61
58
|
"check:sell-start": "node tools/check-sell-start.mjs",
|
|
62
59
|
"check:arrival-consensus": "node tools/check-arrival-consensus.mjs",
|
|
60
|
+
"check:arrival-shadow": "node tools/check-arrival-shadow.mjs",
|
|
63
61
|
"check:arrival-real": "node tools/check-arrival-real.mjs",
|
|
64
62
|
"check:order-proof": "node tools/check-order-proof.mjs",
|
|
65
63
|
"check:daemon-address": "node tools/check-daemon-address.mjs",
|
|
@@ -73,6 +71,7 @@
|
|
|
73
71
|
"check:deployment-pins": "node tools/check-deployment-pins.mjs",
|
|
74
72
|
"check:node-probe": "node tools/check-node-probe.mjs",
|
|
75
73
|
"check:recovery-key": "node tools/check.mjs --only=recovery-key",
|
|
74
|
+
"check:monero-keys": "node tools/check.mjs --only=monero-keys",
|
|
76
75
|
"check:recovery-open": "node tools/check-recovery-open.mjs",
|
|
77
76
|
"check:contract-vectors": "node tools/check-contract-vectors.mjs",
|
|
78
77
|
"check:live-contract": "node tools/check-live-contract.mjs",
|
|
@@ -171,7 +170,7 @@
|
|
|
171
170
|
},
|
|
172
171
|
"dependencies": {
|
|
173
172
|
"@hpke/chacha20poly1305": "1.8.0",
|
|
174
|
-
"@hpke/core": "1.
|
|
173
|
+
"@hpke/core": "1.10.0",
|
|
175
174
|
"@hpke/dhkem-x25519": "1.8.0",
|
|
176
175
|
"@noble/curves": "^2.4.0",
|
|
177
176
|
"@noble/hashes": "^2.4.0",
|
package/src/codes.mjs
CHANGED
|
@@ -67,6 +67,9 @@ export const ERROR_CODES = [
|
|
|
67
67
|
"quote-key-mismatch",
|
|
68
68
|
"quote-field-unbound",
|
|
69
69
|
"quote-expired",
|
|
70
|
+
// THE QUOTE ARRIVED WITH LESS THAN THE START MARGIN LEFT. The lock would refuse it seconds later, after the proof
|
|
71
|
+
// and the record work, so the answer is refused as soon as it arrives and the caller can ask again.
|
|
72
|
+
"quote-too-short",
|
|
70
73
|
// WHO OWNS THE KEY - ASKED OF THE CHAIN (maker registry, providerOf). The signature alone proves only that
|
|
71
74
|
// SOME key signed; these four name what the registry (and the interface's policy) said:
|
|
72
75
|
// quote-registry-unchecked - there was no way to ask the chain, so the claim stays unproven;
|
|
@@ -97,6 +100,11 @@ export const ERROR_CODES = [
|
|
|
97
100
|
// through - server-unavailable, while the service answered and did not accept - server-refused (with the
|
|
98
101
|
// status and its own reason). The advice to the interface differs: "retry" versus "investigate".
|
|
99
102
|
"server-refused",
|
|
103
|
+
// THE CLAIM WAS POSTED BUT NO REAL ANSWER CAME BACK. A timeout, a reset or a body without a usable transaction
|
|
104
|
+
// hash leaves the outcome UNKNOWN: the relay may have sent the claim, and the half is already out of the client.
|
|
105
|
+
// It is NOT `server-unavailable` (which would invite a blind retry) and NOT a success: the caller must read the
|
|
106
|
+
// escrow before doing anything else. `params.why` names the lost part (`answer-lost`, `answer-txid`, ...).
|
|
107
|
+
"claim-unknown",
|
|
100
108
|
// THE TRANSACTION WAS SENT BUT THE RECEIPT DOES NOT PROVE AN ESCROW: no receipt yet, no expected OrderCreated,
|
|
101
109
|
// or a receipt from another factory. The tx hash is the handle for a retry read; nothing was saved as funded.
|
|
102
110
|
"funding-pending",
|
|
@@ -119,6 +127,7 @@ export const ERROR_CODES = [
|
|
|
119
127
|
"xmr-no-nodes",
|
|
120
128
|
"xmr-underpaid",
|
|
121
129
|
"xmr-too-late",
|
|
130
|
+
"xmr-address-mismatch",
|
|
122
131
|
"contract-reverted",
|
|
123
132
|
"insufficient-funds",
|
|
124
133
|
// A FEE REPORTED BY A WALLET/NODE IS DATA, NOT AN INSTRUCTION. Without a ceiling a malicious node can take
|
|
@@ -168,6 +177,7 @@ export const ERROR_META = Object.freeze({
|
|
|
168
177
|
"quote-key-mismatch": { retryable: false, side: "provider" },
|
|
169
178
|
"quote-field-unbound": { retryable: false, side: "provider" },
|
|
170
179
|
"quote-expired": { retryable: true, side: "provider" },
|
|
180
|
+
"quote-too-short": { retryable: true, side: "provider" },
|
|
171
181
|
"quote-registry-unchecked": { retryable: true, side: "chain" },
|
|
172
182
|
"quote-key-unknown": { retryable: false, side: "chain" },
|
|
173
183
|
"quote-provider-mismatch": { retryable: false, side: "chain" },
|
|
@@ -182,6 +192,7 @@ export const ERROR_META = Object.freeze({
|
|
|
182
192
|
"storage-unavailable": { retryable: true, side: "service" },
|
|
183
193
|
"server-unavailable": { retryable: true, side: "service" },
|
|
184
194
|
"server-refused": { retryable: false, side: "service" },
|
|
195
|
+
"claim-unknown": { retryable: false, side: "chain" },
|
|
185
196
|
"funding-pending": { retryable: true, side: "chain" },
|
|
186
197
|
"xmr-timeout": { retryable: true, side: "chain" },
|
|
187
198
|
"xmr-locked": { retryable: true, side: "chain" },
|
|
@@ -189,6 +200,7 @@ export const ERROR_META = Object.freeze({
|
|
|
189
200
|
"xmr-no-nodes": { retryable: true, side: "chain" },
|
|
190
201
|
"xmr-underpaid": { retryable: false, side: "chain" },
|
|
191
202
|
"xmr-too-late": { retryable: false, side: "chain" },
|
|
203
|
+
"xmr-address-mismatch": { retryable: false, side: "caller" },
|
|
192
204
|
"contract-reverted": { retryable: false, side: "chain" },
|
|
193
205
|
"insufficient-funds": { retryable: false, side: "wallet" },
|
|
194
206
|
"sweep-fee-too-high": { retryable: false, side: "chain" },
|
package/src/config.mjs
CHANGED
|
@@ -56,10 +56,18 @@ const chainConfig = (chain) => ({
|
|
|
56
56
|
dex: chain.dex ? { routes: chain.dex.routes || [] } : null,
|
|
57
57
|
// THE ESCROW'S BIRTH HEIGHT, when the network has an escrow. A caller can hand it to findSwaps instead of
|
|
58
58
|
// inventing a start block or asking from genesis, which public RPCs refuse.
|
|
59
|
+
//
|
|
60
|
+
// THE VAULT AND THE IMPLEMENTATION PIN TRAVEL WITH THE NETWORK, not only with the deployment record. `quotes`
|
|
61
|
+
// refuses an answer whose `cashier` is not this network's vault, and the funding path fills the order terms
|
|
62
|
+
// from the same projection. A projection that drops the field leaves a client built from a network NAME with
|
|
63
|
+
// no vault at all, so every relay quote ends as `no-pinned-cashier` - a defect in the profile, not in the
|
|
64
|
+
// answer (sdk#291). Nothing else fills these fields: the projection is the one place both facades read.
|
|
59
65
|
escrow: chain.escrow ? {
|
|
60
66
|
address: chain.escrow.address || null,
|
|
61
67
|
mode: chain.escrow.mode || null,
|
|
62
68
|
registry: chain.escrow.registry || null,
|
|
69
|
+
cashier: chain.escrow.cashier || null,
|
|
70
|
+
implementationCodeHash: chain.escrow.implementationCodeHash || null,
|
|
63
71
|
deploymentBlock: Number.isSafeInteger(chain.escrow.deploymentBlock) ? chain.escrow.deploymentBlock : null,
|
|
64
72
|
} : null,
|
|
65
73
|
});
|
|
@@ -76,25 +84,9 @@ const chainConfig = (chain) => ({
|
|
|
76
84
|
// configurability" would become a way to switch the checks off with a single field, which is exactly what the
|
|
77
85
|
// core exists to prevent.
|
|
78
86
|
//
|
|
79
|
-
//
|
|
80
|
-
//
|
|
81
|
-
//
|
|
82
|
-
// WHY THESE PATHS DID NOT EXIST BEFORE AND WHERE THEY COME FROM. The "server" step (recording the swap with us
|
|
83
|
-
// and watching the Monero address) is done with THE SAME requests as the current interface, so the paths are
|
|
84
|
-
// named after its calls, not invented: the watch state - GET /swaps/{id} (www/js/core/chainSource.js:184,
|
|
85
|
-
// fetchSession), the factory record of a swap - POST /evm-swaps (www/js/evm/auth.js:111, saveServerSwap; in app
|
|
86
|
-
// the full path /api/evm-swaps is declared by the template /^\/api\/evm-swaps$/ in app/server.mjs:1230).
|
|
87
|
-
export const DEFAULT_ROUTES = Object.freeze({
|
|
88
|
-
swaps: "/swaps",
|
|
89
|
-
swap: "/swaps/{id}",
|
|
90
|
-
evmSwaps: "/evm-swaps",
|
|
91
|
-
// A quote for an order: the provider's commitment under keys, not a market snapshot.
|
|
92
|
-
orderQuote: "/order-quote",
|
|
93
|
-
// A reverse-mode ticket: the maker supplies the XMR fields, the node answers with a signed quote and its claim tip.
|
|
94
|
-
orderSell: "/order-sell",
|
|
95
|
-
revealedHalf: "/escrow/revealed-half",
|
|
96
|
-
swept: "/swaps/{id}/swept",
|
|
97
|
-
});
|
|
87
|
+
// THE SDK TALKS TO A MAKER THROUGH A RELAY AND READS THE CHAIN THROUGH THE SEAMS THE CALLER BRINGS. It does not
|
|
88
|
+
// carry a client for the old node's HTTP surface: those routes were retired, and a client that still names them
|
|
89
|
+
// would silently make every request against a service that no longer exists.
|
|
98
90
|
|
|
99
91
|
// THE MONERO NODES THE ARRIVAL IS CHECKED AGAINST. Defaults are the list verified on 2026-10-02 (issue #85):
|
|
100
92
|
// mainnet - four public nodes of different operators; stagenet - our node and the one independent public node.
|
|
@@ -146,28 +138,10 @@ const nodesOf = (options, selected) => {
|
|
|
146
138
|
return out;
|
|
147
139
|
};
|
|
148
140
|
|
|
149
|
-
const pathOf = (template, params) => template.replace(/\{([a-z]+)\}/g, (whole, name) => {
|
|
150
|
-
const value = params ? params[name] : undefined;
|
|
151
|
-
if (value === undefined || value === null || value === "") fail("bad-input", { field: "route.param", param: name });
|
|
152
|
-
return encodeURIComponent(String(value));
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
const routesOf = (options) => {
|
|
156
|
-
const custom = (options && options.routes) || {};
|
|
157
|
-
for (const name of Object.keys(custom)) {
|
|
158
|
-
// AN UNKNOWN NAME IS A TYPO, NOT "let's add our own": otherwise the path silently fails to apply, and the
|
|
159
|
-
// call falls back to a default nobody knows about.
|
|
160
|
-
if (!(name in DEFAULT_ROUTES)) fail("bad-input", { field: "routes", unknown: name, known: Object.keys(DEFAULT_ROUTES) });
|
|
161
|
-
if (typeof custom[name] !== "string" || !custom[name]) fail("bad-input", { field: "routes." + name });
|
|
162
|
-
}
|
|
163
|
-
return { ...DEFAULT_ROUTES, ...custom };
|
|
164
|
-
};
|
|
165
|
-
|
|
166
141
|
// THE POLL RATE AND TIMEOUT FOR WATCHING THE MONERO ADDRESS. The defaults come from the engine's settings, not
|
|
167
|
-
// from numbers in the code: the rate is the same as the page's
|
|
168
|
-
//
|
|
169
|
-
//
|
|
170
|
-
// about the money. Both numbers are overridable by the `watch` option.
|
|
142
|
+
// from numbers in the code: the rate is the same as the page's and the timeout is blockTimeReal x confirmTarget,
|
|
143
|
+
// so the wait is never declared expired before the target's confirmations can gather. Both are overridable by
|
|
144
|
+
// the `watch` option.
|
|
171
145
|
const positive = (v) => (Number.isFinite(Number(v)) && Number(v) > 0 ? Number(v) : null);
|
|
172
146
|
const watchOf = (options) => {
|
|
173
147
|
const w = (options && options.watch) || {};
|
|
@@ -209,7 +183,6 @@ export function buildConfig(options) {
|
|
|
209
183
|
const chosen = chains.find((c) => c.id === options.settlement.chain) || null;
|
|
210
184
|
if (!chosen) fail("bad-input", { field: "settlement.chain", known: chains.map((c) => c.id) });
|
|
211
185
|
const rawChain = engine.config.CHAINS.find((c) => c.id === options.settlement.chain) || {};
|
|
212
|
-
const routes = routesOf(options);
|
|
213
186
|
const watch = watchOf(options);
|
|
214
187
|
const endpoints = endpointsOf(rawChain, options);
|
|
215
188
|
const nodes = nodesOf(options, options.xmrNetwork);
|
|
@@ -250,7 +223,6 @@ export function buildConfig(options) {
|
|
|
250
223
|
chains,
|
|
251
224
|
xmrNetworks,
|
|
252
225
|
assetsBase: options.assetsBase,
|
|
253
|
-
apiBase: options.apiBase,
|
|
254
226
|
mode: options.mode,
|
|
255
227
|
limits: {
|
|
256
228
|
// SIZE LIMITS COME WITH THE LIVE QUOTE, NOT FROM A FILE: the provider node declares them, and different
|
|
@@ -269,25 +241,15 @@ export function buildConfig(options) {
|
|
|
269
241
|
xmrConfirmations: engine.config.MONERO.confirmTarget ?? 10,
|
|
270
242
|
xmrBlockTimeSec: Math.round((engine.config.MONERO.blockTimeReal ?? 120000) / 1000),
|
|
271
243
|
readyLeadWarnSec: guards.readyLeadWarnSec ?? null,
|
|
272
|
-
// THE PRICE POLL RATE AND THE REQUEST TIMEOUT - from the engine's settings, not from numbers in the SDK:
|
|
273
|
-
// two numbers in two places would silently diverge, and polling would become more frequent than the
|
|
274
|
-
// backend allows.
|
|
275
|
-
quotePollMs: engine.config.API.pollMs ?? 5000,
|
|
276
|
-
httpTimeoutMs: engine.config.API.timeoutMs ?? 20000,
|
|
277
244
|
},
|
|
278
245
|
routing: { providers: known, prefer },
|
|
279
|
-
// NAMED
|
|
280
|
-
//
|
|
281
|
-
routes: { ...routes },
|
|
246
|
+
// NAMED ADDRESSES: `endpoints` carries the already-resolved values (the default from the registry, the
|
|
247
|
+
// override from the options).
|
|
282
248
|
endpoints,
|
|
283
249
|
// THE NODES THE XMR ARRIVAL IS CHECKED AGAINST - by network, with the defaults from the verified list and any
|
|
284
250
|
// overrides the caller (or the user) brought. `nodesFor` is the pick for one network.
|
|
285
251
|
xmrNodes: nodes,
|
|
286
252
|
nodesFor: (network) => (nodes && nodes[network]) ? nodes[network] : [],
|
|
287
|
-
route: (name, params) => {
|
|
288
|
-
if (!(name in routes)) fail("bad-input", { field: "route", unknown: name, known: Object.keys(routes) });
|
|
289
|
-
return pathOf(routes[name], params);
|
|
290
|
-
},
|
|
291
253
|
codes: { steps: STEP_CODES, checks: CHECK_CODES, errors: ERROR_CODES },
|
|
292
254
|
};
|
|
293
255
|
}
|
package/src/engine.mjs
CHANGED
|
@@ -55,3 +55,6 @@ export * as xmrAddress from "../engine/monero/address.js";
|
|
|
55
55
|
// the engine mirror. check-sdk-engine reddens on any drift, so the two cannot diverge silently.
|
|
56
56
|
export * as xmrUnlock from "../engine/monero/unlock.js";
|
|
57
57
|
export * as xmrScan from "../engine/monero/scan.js";
|
|
58
|
+
// THE ADDRESS AND ITS PUBLIC KEYS, for the arrival check: the view secret and spend key are bound to the address,
|
|
59
|
+
// not merely used as labels.
|
|
60
|
+
export * as xmrArrivalRead from "../engine/monero/arrivalRead.js";
|
package/src/index.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// THE SDK ENTRY POINT. Assembles the facades and holds rules common to all: no DOM, no texts, no windows.
|
|
2
2
|
import { buildConfig } from "./config.mjs";
|
|
3
3
|
import { factoryCodesForChain, implementationCodesForChain } from "./factoryPolicy.mjs";
|
|
4
|
-
import { createHttp } from "./http.mjs";
|
|
5
4
|
import { createQuotes } from "./quotes.mjs";
|
|
6
5
|
import { createPreflight } from "./preflight.mjs";
|
|
7
6
|
import { createRecovery } from "./recovery.mjs";
|
|
@@ -26,7 +25,6 @@ import { ERROR_CODES, ERROR_META, ERROR_SIDES, STEP_CODES, CHECK_CODES } from ".
|
|
|
26
25
|
// value that looks like data. The stage number is named so the interface understands what to expect
|
|
27
26
|
// (sdk/README.md, "Stages").
|
|
28
27
|
const stageOf = {
|
|
29
|
-
"quotes.firm": 2,
|
|
30
28
|
"swaps.start": 2,
|
|
31
29
|
"swaps.list": 2,
|
|
32
30
|
"swaps.get": 2,
|
|
@@ -57,16 +55,18 @@ const normalizeOptions = (options) => {
|
|
|
57
55
|
}
|
|
58
56
|
if (o.fetch !== undefined && typeof o.fetch !== "function") fail("bad-input", { field: "fetch" });
|
|
59
57
|
if (o.now !== undefined && typeof o.now !== "function") fail("bad-input", { field: "now" });
|
|
58
|
+
// THE DIRECT-NODE OPTIONS ARE RETIRED, NOT SILENTLY IGNORED. A caller that still brings `apiBase`, `routes` or
|
|
59
|
+
// `serverAuth` is asking for a surface this release no longer carries; ignoring the field would make the old
|
|
60
|
+
// configuration look accepted while the request never happens.
|
|
61
|
+
for (const retired of ["apiBase", "routes", "serverAuth"]) {
|
|
62
|
+
if (o[retired] !== undefined) fail("bad-input", { field: retired, why: "retired" });
|
|
63
|
+
}
|
|
60
64
|
if (o.routing !== undefined) {
|
|
61
65
|
const r = o.routing;
|
|
62
66
|
if (!r || typeof r !== "object" || (r.prefer !== undefined && !Array.isArray(r.prefer))) fail("bad-input", { field: "routing" });
|
|
63
67
|
}
|
|
64
|
-
// PATHS AND ADDRESSES:
|
|
65
|
-
//
|
|
66
|
-
// a refusal.
|
|
67
|
-
if (o.routes !== undefined && (!o.routes || typeof o.routes !== "object" || Array.isArray(o.routes))) {
|
|
68
|
-
fail("bad-input", { field: "routes" });
|
|
69
|
-
}
|
|
68
|
+
// PATHS AND ADDRESSES: only ADDRESSES remain configurable. The retired node routes are not part of the SDK any
|
|
69
|
+
// more; `endpoints` is checked here and resolved in the configuration.
|
|
70
70
|
if (o.endpoints !== undefined && (!o.endpoints || typeof o.endpoints !== "object" || Array.isArray(o.endpoints))) {
|
|
71
71
|
fail("bad-input", { field: "endpoints" });
|
|
72
72
|
}
|
|
@@ -121,11 +121,6 @@ const normalizeOptions = (options) => {
|
|
|
121
121
|
if (o.denylist !== undefined && o.denylist !== null) {
|
|
122
122
|
if (!Array.isArray(o.denylist) || o.denylist.some((a) => typeof a !== "string")) fail("bad-input", { field: "denylist" });
|
|
123
123
|
}
|
|
124
|
-
// A PASS TO OUR SERVICE - A SEAM FROM OUTSIDE, like the wallet: only a wallet can sign the sign-in message
|
|
125
|
-
// (www/js/evm/auth.js, signIn), and requiring it of the core would mean opening windows and signing messages
|
|
126
|
-
// inside the SDK. The core receives a ready pass and presents it. A missing pass is NOT an option error: the
|
|
127
|
-
// "server" step then answers with the app's refusal (401) under a named code.
|
|
128
|
-
if (o.serverAuth !== undefined && typeof o.serverAuth !== "function") fail("bad-input", { field: "serverAuth" });
|
|
129
124
|
// YOUR OWN SWAP RECORD - A CAPABILITY, NOT A REQUIREMENT. By default the core builds the record and the order
|
|
130
125
|
// side itself (record.mjs + order.mjs) and uses that side both for the record and for the lock terms. The
|
|
131
126
|
// function is for whoever wants to bring THEIR OWN side; it must be a function, otherwise it is a typo, not a
|
|
@@ -143,17 +138,12 @@ const normalizeOptions = (options) => {
|
|
|
143
138
|
return {
|
|
144
139
|
settlement: { chain: settlement.chain, vm: settlement.vm },
|
|
145
140
|
xmrNetwork: o.xmrNetwork,
|
|
146
|
-
apiBase: typeof o.apiBase === "string" && o.apiBase ? o.apiBase : null,
|
|
147
141
|
assetsBase: typeof o.assetsBase === "string" && o.assetsBase ? o.assetsBase : "/",
|
|
148
142
|
mode,
|
|
149
143
|
storage: o.storage || null,
|
|
150
144
|
fetch: o.fetch || null,
|
|
151
145
|
now: o.now || null,
|
|
152
146
|
routing: o.routing || null,
|
|
153
|
-
// PATHS AND ADDRESSES PASS ON AS THEY ARE: their meaning is worked out when the configuration is built,
|
|
154
|
-
// where the registry's defaults live. They must not be dropped here - an override nobody knows about is
|
|
155
|
-
// worse than a refusal.
|
|
156
|
-
routes: o.routes || null,
|
|
157
147
|
endpoints: o.endpoints || null,
|
|
158
148
|
nodes: o.nodes === undefined ? null : o.nodes,
|
|
159
149
|
addNodes: o.addNodes === undefined ? null : o.addNodes,
|
|
@@ -165,7 +155,6 @@ const normalizeOptions = (options) => {
|
|
|
165
155
|
knownFactoryCodes: o.knownFactoryCodes === undefined ? null : o.knownFactoryCodes,
|
|
166
156
|
knownImplementationCodes: o.knownImplementationCodes === undefined ? null : o.knownImplementationCodes,
|
|
167
157
|
denylist: o.denylist === undefined ? null : o.denylist,
|
|
168
|
-
serverAuth: o.serverAuth || null,
|
|
169
158
|
watch: o.watch || null,
|
|
170
159
|
createRecord: o.createRecord || null,
|
|
171
160
|
};
|
|
@@ -176,15 +165,13 @@ export function createNinsei(options) {
|
|
|
176
165
|
const config = buildConfig({
|
|
177
166
|
settlement: o.settlement,
|
|
178
167
|
xmrNetwork: o.xmrNetwork,
|
|
179
|
-
apiBase: o.apiBase,
|
|
180
168
|
assetsBase: o.assetsBase,
|
|
181
169
|
mode: o.mode,
|
|
182
170
|
routing: o.routing,
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
addNodes: o.addNodes,
|
|
171
|
+
endpoints: o.endpoints,
|
|
172
|
+
watch: o.watch,
|
|
173
|
+
nodes: o.nodes,
|
|
174
|
+
addNodes: o.addNodes,
|
|
188
175
|
});
|
|
189
176
|
// THE NETWORK'S PINS REACH THE CORE. The bridge passed them explicitly; a caller with default options did not,
|
|
190
177
|
// so the factory policy was null and the quote could name any factory. An explicit caller list still wins.
|
|
@@ -209,7 +196,6 @@ export function createNinsei(options) {
|
|
|
209
196
|
// ONE CLIENT, ONE STORE - WITHOUT A PROCESS-WIDE EXCLUSIVE BINDING. Each facade gets a store over its own
|
|
210
197
|
// adapter; two clients with different storages coexist and neither can take over the other's records.
|
|
211
198
|
const store = engine.store.createStore(o.storage || engine.store.storage());
|
|
212
|
-
const http = createHttp({ apiBase: config.apiBase, fetchImpl: o.fetch, timeoutMs: config.limits.httpTimeoutMs });
|
|
213
199
|
// THE CHAIN READ AND THE ALLOW-LIST GO INTO THE QUOTE CHECK: without the read the signature certifies itself,
|
|
214
200
|
// so the same evmCall seam the lock and the actions use is handed to the quotes too.
|
|
215
201
|
const providerAllowed = (() => {
|
|
@@ -220,12 +206,12 @@ export function createNinsei(options) {
|
|
|
220
206
|
return (provider) => set.has(String(provider).toLowerCase());
|
|
221
207
|
})();
|
|
222
208
|
// THE DENYLIST IS LOWER-CASED ONCE HERE, so the comparison rule (case-insensitive membership) lives in ONE
|
|
223
|
-
// place and BOTH the quote check (`
|
|
209
|
+
// place and BOTH the quote check (`firmRelay`) and the lock check (`swaps.start`) use it. An empty list is
|
|
224
210
|
// "no policy" (null), not an empty check.
|
|
225
211
|
const denylist = Array.isArray(o.denylist) && o.denylist.length
|
|
226
212
|
? new Set(o.denylist.map((a) => String(a).toLowerCase()))
|
|
227
213
|
: null;
|
|
228
|
-
const quotes = createQuotes({ config,
|
|
214
|
+
const quotes = createQuotes({ config, now: o.now || (() => Date.now()), evmCall: o.evmCall || null,
|
|
229
215
|
evmCode: o.evmCode || null, evmBlock: o.evmBlock || null,
|
|
230
216
|
providerAllowed, knownFactoryCodes, knownImplementationCodes,
|
|
231
217
|
denylist });
|
|
@@ -244,7 +230,7 @@ export function createNinsei(options) {
|
|
|
244
230
|
config,
|
|
245
231
|
wallet,
|
|
246
232
|
preflight,
|
|
247
|
-
recovery: createRecovery(
|
|
233
|
+
recovery: createRecovery(),
|
|
248
234
|
|
|
249
235
|
// THE ORDER: checking the counterparty's side and the joint address. Both checks - BEFORE signing: after it
|
|
250
236
|
// there is nothing to fix.
|
|
@@ -273,17 +259,8 @@ export function createNinsei(options) {
|
|
|
273
259
|
},
|
|
274
260
|
sim,
|
|
275
261
|
quotes: {
|
|
276
|
-
//
|
|
277
|
-
// watch returned; the last listener to leave stops the polling.
|
|
278
|
-
watch: (request, onSnapshot) => quotes.watch(request, onSnapshot),
|
|
279
|
-
snapshot: () => quotes.snapshot(),
|
|
280
|
-
// A firm quote is stage 2: it is signed with a key and lives in the order protocol, not in a market snapshot.
|
|
281
|
-
// A FIRM QUOTE: accepted only with a confirmed provider signature.
|
|
282
|
-
firm: (request) => quotes.firm(request),
|
|
283
|
-
// THE RELAY PATH: one recovery key in, signed orderQuote and its maker view half out.
|
|
262
|
+
// THE ONLY QUOTE PATH: one recovery key in, a signed orderQuote and the maker's view half out.
|
|
284
263
|
firmRelay: (request) => quotes.firmRelay(request),
|
|
285
|
-
// A REVERSE TICKET: the node signs it; its claim tip is checked here before the caller sees it.
|
|
286
|
-
sale: (request) => quotes.sale(request),
|
|
287
264
|
},
|
|
288
265
|
// READING STATE WORKS, STARTING IS NAMED HONESTLY: list/get raise swaps from storage after a page reload;
|
|
289
266
|
// start holds the step order and runs into the step that creates the record (stage 2).
|
|
@@ -292,24 +269,26 @@ export function createNinsei(options) {
|
|
|
292
269
|
// non-existent side), and the network is needed to build the shared Monero address.
|
|
293
270
|
// THE CHAIN READER GOES INTO THE SWAP START: it will check the escrow address, the order state and the fee
|
|
294
271
|
// before signing.
|
|
295
|
-
// THE
|
|
296
|
-
//
|
|
297
|
-
|
|
298
|
-
swaps: createSwaps({ preflight, http, mode: o.mode, xmrNetwork: o.xmrNetwork, call: o.evmCall, now: o.now || null, evmBlock: o.evmBlock || null, store,
|
|
272
|
+
// THE CHAIN READER GOES INTO THE SWAP START: it will check the escrow address, the order state and the fee
|
|
273
|
+
// before signing. The Monero watch reads the chain through the same seam; there is no backend watcher.
|
|
274
|
+
swaps: createSwaps({ preflight, mode: o.mode, xmrNetwork: o.xmrNetwork, call: o.evmCall, now: o.now || null, evmBlock: o.evmBlock || null, store,
|
|
299
275
|
// THE LOG SEAM FOR THE DECLINE CHECK: the watch asks the escrow for its `Declined` event on every tick, so
|
|
300
276
|
// a declined order stops the wait at once instead of running to `xmr-timeout`.
|
|
301
277
|
logs: o.evmLogs || null,
|
|
302
|
-
config,
|
|
278
|
+
config, denylist, watch: o.watch,
|
|
303
279
|
// THE RECORD IS BUILT HERE ITSELF, and one brought from outside is only the caller's preference.
|
|
304
280
|
createRecord: o.createRecord }),
|
|
305
281
|
// XMR WITHDRAWAL: parsing the file and requesting data work; the withdrawal itself is named (the Monero
|
|
306
282
|
// wallet as an adapter).
|
|
307
|
-
sweep: createSweep({
|
|
283
|
+
sweep: createSweep({ call: o.evmCall }),
|
|
308
284
|
});
|
|
309
285
|
}
|
|
310
286
|
|
|
311
287
|
export { SdkError, ERROR_CODES, ERROR_META, ERROR_SIDES, STEP_CODES, CHECK_CODES };
|
|
312
288
|
export { SDK_VERSION } from "./version.mjs";
|
|
289
|
+
// THE QUOTE LIFETIME AND THE START MARGIN ARE ONE PUBLIC DEFAULT. A node imports the lifetime, so its signed quote
|
|
290
|
+
// cannot be shorter than the margin the SDK enforces before it opens the wallet.
|
|
291
|
+
export { LOCK_START_MARGIN_SEC, DEFAULT_ORDER_QUOTE_TTL_SEC } from "./quotePolicy.mjs";
|
|
313
292
|
|
|
314
293
|
// THE LEVEL WALK IS ON THE PACKAGE SURFACE. A maker publishes a level set (chunks of volume with their own prices)
|
|
315
294
|
// and both the node and the client compute a firm price by WALKING it - the client must reach the SAME price before
|
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
|
|
@@ -218,7 +218,7 @@ function acceptedCounterparty({ context, side = null, counterparty = null, stand
|
|
|
218
218
|
if (counterparty && typeof counterparty === "object") {
|
|
219
219
|
const pub = counterparty.pub && typeof counterparty.pub === "object" ? counterparty.pub : {};
|
|
220
220
|
// THE ORDER-QUOTE FIELD NAMES ARE THE ONES THE CORE ITSELF RETURNS (a defect found). The counterparty's side
|
|
221
|
-
// comes from `
|
|
221
|
+
// comes from `firmRelay`, and there the point is called `edPointClaimer`, the view half - `viewHalfClaimer`
|
|
222
222
|
// (rfq/orderQuote.mjs). While only `edPub`/`viewPub` were accepted, the facade's own side was NOT accepted:
|
|
223
223
|
// start answered bad-input { field: "counterparty", missing: ["edPub"] } to its own answer. The engine knew
|
|
224
224
|
// this mapping (sdk/src/swap-flow.mjs: edPub: quote.edPointClaimer). We accept BOTH names.
|
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
|
@@ -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
|
+
}
|