@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/index.d.ts
CHANGED
|
@@ -94,11 +94,11 @@ export interface NinseiOptions {
|
|
|
94
94
|
*/
|
|
95
95
|
evmCall?: (request: { readonly to: string; readonly data: string }) => Promise<string>;
|
|
96
96
|
/**
|
|
97
|
-
* READING THE CONTRACT CODE FROM OUTSIDE (issue #103): (
|
|
97
|
+
* READING THE CONTRACT CODE FROM OUTSIDE (issue #103): (address) -> hex code. Needed for the factory-code
|
|
98
98
|
* check - `extcodehash` is keccak256 of this code, and the factory a provider names in its registry record is
|
|
99
99
|
* matched against the interface's known builds. Same rule as evmCall: a read, not a node substitution.
|
|
100
100
|
*/
|
|
101
|
-
evmCode?: (
|
|
101
|
+
evmCode?: (address: string) => Promise<string>;
|
|
102
102
|
/**
|
|
103
103
|
* READING THE ESCROW'S LOGS FROM OUTSIDE (issue #40): `({ address, topics, fromBlock, toBlock }) -> logs`, for
|
|
104
104
|
* the MAKER'S DECLINE. The escrow emits `Declined(claimer)` and keeps NO getter that names it, while `status()`
|
|
@@ -393,7 +393,7 @@ export interface WalletAdapter {
|
|
|
393
393
|
* Send a leg transaction (lock, marking ready, claim, refund). The request shape is what this VM calls a transfer;
|
|
394
394
|
* for EVM it is `{ to, data, value }` and the transaction hash in response.
|
|
395
395
|
*/
|
|
396
|
-
send(request: { readonly to: string; readonly data?: string; readonly value?: bigint | number | string }): Promise<string>;
|
|
396
|
+
send(request: { readonly to: string; readonly data?: string; readonly value?: bigint | number | string; readonly gas?: bigint | number | string; readonly chainId?: number; readonly from?: string }): Promise<string>;
|
|
397
397
|
/**
|
|
398
398
|
* The transaction receipt: asked ONCE, returns the receipt or null (not in a block yet). The waiting policy is set
|
|
399
399
|
* by the caller, not the adapter - otherwise two calls would wait differently.
|
|
@@ -684,8 +684,6 @@ export interface FirmRelayOffer {
|
|
|
684
684
|
readonly recoveryKey: string | { readonly mnemonic: string };
|
|
685
685
|
/** A fresh salt the client owns; it must equal `order.salt`. Defaults to `order.salt`. */
|
|
686
686
|
readonly recoverySalt?: string;
|
|
687
|
-
/** The v1 index; it is mutually exclusive with `recoverySalt`. */
|
|
688
|
-
readonly recoveryIndex?: number;
|
|
689
687
|
/** The market's chain and asset, for example `421614:ETH`. Derived when exactly one window matches. */
|
|
690
688
|
readonly market?: string;
|
|
691
689
|
readonly xmrNetwork?: string;
|
|
@@ -713,8 +711,7 @@ export interface FirmRelayAnswer {
|
|
|
713
711
|
readonly jointAddress: string;
|
|
714
712
|
/** The escrow address predicted from the signed quote and the depositor's half. */
|
|
715
713
|
readonly escrow: string;
|
|
716
|
-
readonly recovery: { readonly kind: "salt-v2"; readonly salt: string }
|
|
717
|
-
| { readonly kind: "index-v1"; readonly index: number };
|
|
714
|
+
readonly recovery: { readonly kind: "salt-v2"; readonly salt: string };
|
|
718
715
|
readonly relay: string | null;
|
|
719
716
|
readonly offered: number | null;
|
|
720
717
|
readonly forwarded: Readonly<Record<string, unknown>> | null;
|
|
@@ -1252,14 +1249,8 @@ export interface StartRequest {
|
|
|
1252
1249
|
* kept through the SDK's storage adapter.
|
|
1253
1250
|
*/
|
|
1254
1251
|
recoveryKey?: string | { readonly mnemonic: string };
|
|
1255
|
-
/** The
|
|
1256
|
-
recoveryIndex?: number;
|
|
1257
|
-
/** The per-order salt the caller put into the signed quote. When present, the key uses the v2 salt binding and
|
|
1258
|
-
* no index is reserved; it must equal `order.salt`. */
|
|
1252
|
+
/** The per-order salt the caller put into the signed quote; it must equal `order.salt`. */
|
|
1259
1253
|
recoverySalt?: string | number | bigint;
|
|
1260
|
-
/** The first block for the on-chain number check. Absent - the chain registry's escrow deployment block, and
|
|
1261
|
-
* zero only when the registry has no height. */
|
|
1262
|
-
fromBlock?: string | number;
|
|
1263
1254
|
/** The Monero height the swap starts at. Absent - the SDK asks the configured nodes (`get_info`) and refuses
|
|
1264
1255
|
* the start if none answers on the swap's network. */
|
|
1265
1256
|
restoreHeight?: number;
|
|
@@ -1553,8 +1544,7 @@ export interface SweepFromOrderRequest {
|
|
|
1553
1544
|
readonly edPointLocker: string;
|
|
1554
1545
|
readonly edPointClaimer: string;
|
|
1555
1546
|
readonly edViewPointLocker: string;
|
|
1556
|
-
readonly
|
|
1557
|
-
readonly derivation?: "index-v1" | "salt-v2";
|
|
1547
|
+
readonly derivation?: "salt-v2";
|
|
1558
1548
|
readonly factory?: string;
|
|
1559
1549
|
readonly salt?: string;
|
|
1560
1550
|
readonly side: "locker" | "claimer";
|
|
@@ -1861,6 +1851,7 @@ export type ErrorCode =
|
|
|
1861
1851
|
| "wallet-not-connected"
|
|
1862
1852
|
| "wallet-rejected"
|
|
1863
1853
|
| "wrong-chain"
|
|
1854
|
+
| "wrong-account"
|
|
1864
1855
|
| "quote-unavailable"
|
|
1865
1856
|
| "quote-refused"
|
|
1866
1857
|
/**
|
|
@@ -1920,6 +1911,8 @@ export type ErrorCode =
|
|
|
1920
1911
|
| "xmr-too-late"
|
|
1921
1912
|
| "contract-reverted"
|
|
1922
1913
|
| "insufficient-funds"
|
|
1914
|
+
/** A wallet/node reported a withdrawal fee above the SDK's ceiling; the transfer is refused. */
|
|
1915
|
+
| "sweep-fee-too-high"
|
|
1923
1916
|
/** The maker declines to pay the claim gas; the refusal is shown before the deal (issue #78). */
|
|
1924
1917
|
| "gas-refused-by-maker"
|
|
1925
1918
|
/** The claim gas was ordered but the recipient's balance did not grow. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ninsei-labs/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.56.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -12,21 +12,29 @@
|
|
|
12
12
|
"main": "src/index.mjs",
|
|
13
13
|
"scripts": {
|
|
14
14
|
"check": "node tools/check.mjs",
|
|
15
|
+
"build:sdk": "node tools/build-sdk.mjs",
|
|
16
|
+
"build:sdk:docker": "node tools/build-sdk-docker.mjs",
|
|
15
17
|
"check:syntax": "node tools/check.mjs --only=syntax",
|
|
16
18
|
"check:import": "node tools/check.mjs --only=import",
|
|
17
19
|
"check:surface": "node tools/check.mjs --only=surface",
|
|
18
20
|
"check:mirror": "node tools/check.mjs --only=mirror",
|
|
19
21
|
"check:pack": "node tools/check.mjs --only=pack",
|
|
20
|
-
"check:pack-teeth": "node tools/check-pack-teeth.mjs",
|
|
22
|
+
"check:pack-teeth": "node tools/run-teeth-isolated.mjs tools/check-pack-teeth.mjs",
|
|
21
23
|
"check:secrets": "node tools/check.mjs --only=secrets",
|
|
24
|
+
"check:vendor-bundles": "node tools/check.mjs --only=vendor-bundles",
|
|
25
|
+
"check:dleq-vectors": "node tools/check-dleq-vectors.mjs",
|
|
26
|
+
"check:swap-network": "node tools/check.mjs --only=swap-network",
|
|
27
|
+
"check:quote-ttl": "node tools/check.mjs --only=quote-ttl",
|
|
28
|
+
"check:dleq-oracle": "node tools/check-dleq-oracle.mjs",
|
|
29
|
+
"check:vendor-bundles-teeth": "node tools/run-teeth-isolated.mjs tools/check-vendor-bundles-teeth.mjs",
|
|
22
30
|
"check:types": "node tools/check.mjs --only=types",
|
|
23
|
-
"check:types-teeth": "node tools/check-types-teeth.mjs",
|
|
31
|
+
"check:types-teeth": "node tools/run-teeth-isolated.mjs tools/check-types-teeth.mjs",
|
|
24
32
|
"check:refusals": "node tools/check.mjs --only=refusals",
|
|
25
|
-
"check:refusals-teeth": "node tools/check-refusals-teeth.mjs",
|
|
33
|
+
"check:refusals-teeth": "node tools/run-teeth-isolated.mjs tools/check-refusals-teeth.mjs",
|
|
26
34
|
"check:decline": "node tools/check.mjs --only=decline",
|
|
27
|
-
"check:decline-teeth": "node tools/check-decline-teeth.mjs",
|
|
35
|
+
"check:decline-teeth": "node tools/run-teeth-isolated.mjs tools/check-decline-teeth.mjs",
|
|
28
36
|
"check:terminal": "node tools/check.mjs --only=terminal",
|
|
29
|
-
"check:terminal-teeth": "node tools/check-terminal-teeth.mjs",
|
|
37
|
+
"check:terminal-teeth": "node tools/run-teeth-isolated.mjs tools/check-terminal-teeth.mjs",
|
|
30
38
|
"check:sweep": "node tools/sweep-refusal.test.mjs",
|
|
31
39
|
"check:sweep-half": "node tools/check-sweep-half.mjs",
|
|
32
40
|
"sync:version": "node tools/sync-version.mjs",
|
|
@@ -75,7 +83,8 @@
|
|
|
75
83
|
"check:types-consumer": "node node_modules/typescript/bin/tsc -p tools/ts-consumer/tsconfig.json",
|
|
76
84
|
"check:monero-live": "node tools/check-monero-live.mjs",
|
|
77
85
|
"check:native-amount": "node tools/check-native-amount.mjs",
|
|
78
|
-
"check:ci-boundary": "node tools/check-ci-boundary.mjs"
|
|
86
|
+
"check:ci-boundary": "node tools/check-ci-boundary.mjs",
|
|
87
|
+
"coverage": "node tools/coverage.mjs"
|
|
79
88
|
},
|
|
80
89
|
"types": "./index.d.ts",
|
|
81
90
|
"exports": {
|
|
@@ -85,6 +94,7 @@
|
|
|
85
94
|
"default": "./src/index.mjs"
|
|
86
95
|
},
|
|
87
96
|
"./adapters": {
|
|
97
|
+
"types": "./src/adapters/index.d.ts",
|
|
88
98
|
"default": "./src/adapters/index.mjs"
|
|
89
99
|
},
|
|
90
100
|
"./xmr": {
|
|
@@ -168,6 +178,11 @@
|
|
|
168
178
|
},
|
|
169
179
|
"sideEffects": false,
|
|
170
180
|
"devDependencies": {
|
|
181
|
+
"esbuild": "0.28.2",
|
|
171
182
|
"typescript": "7.0.2"
|
|
183
|
+
},
|
|
184
|
+
"allowScripts": {
|
|
185
|
+
"esbuild": true,
|
|
186
|
+
"keccak": true
|
|
172
187
|
}
|
|
173
188
|
}
|
package/src/actions.mjs
CHANGED
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
// claiming it is revealing your own half (irreversible), for refunding the same reveal. The transaction still
|
|
10
10
|
// looks successful.
|
|
11
11
|
import { SdkError } from "./errors.mjs";
|
|
12
|
-
import * as engine from "./engine.mjs";
|
|
13
12
|
// THE DEAL FLOW IS NOW A PACKAGE MODULE, NOT AN ENGINE FILE (#32, wave 3): www/js/core/swap-flow.js moved to
|
|
14
13
|
// sdk/src/swap-flow.mjs. The actions therefore call the module directly instead of reaching it through the
|
|
15
14
|
// mirror - there is exactly one implementation, and it lives here.
|
|
@@ -54,38 +53,79 @@ const withCodes = async (step, work) => {
|
|
|
54
53
|
}
|
|
55
54
|
};
|
|
56
55
|
|
|
57
|
-
export function createActions({ call = null } = {}) {
|
|
56
|
+
export function createActions({ call = null, blockTime = null } = {}) {
|
|
58
57
|
// WHAT READS THE CHAIN IS ALSO A SEAM, and not only for the checks: the slot check and the signature must go
|
|
59
|
-
// ONE way, otherwise part of the check goes past the wallet and part does not.
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
// ONE way, otherwise part of the check goes past the wallet and part does not. The caller's seam wins; otherwise
|
|
59
|
+
// the action reads through the provider of THE WALLET IT WAS GIVEN, never through the process-wide engine
|
|
60
|
+
// provider of another client.
|
|
61
|
+
const providerOf = (wallet) => {
|
|
62
|
+
try { return wallet && typeof wallet.driver === "function" ? wallet.driver() : null; }
|
|
63
|
+
catch { return null; }
|
|
64
|
+
};
|
|
65
|
+
const readerFor = (wallet) => {
|
|
66
|
+
if (typeof call === "function") return call;
|
|
67
|
+
const provider = providerOf(wallet);
|
|
68
|
+
if (!provider || typeof provider.request !== "function") {
|
|
69
|
+
return async () => { throw new SdkError("wallet-not-connected", { surface: "actions.read" }); };
|
|
70
|
+
}
|
|
71
|
+
return async ({ to, data }) => {
|
|
72
|
+
const result = await provider.request({ method: "eth_call", params: [{ to, data }, "latest"] });
|
|
73
|
+
if (typeof result !== "string" || !result.startsWith("0x")) {
|
|
74
|
+
throw new SdkError("contract-reverted", { surface: "actions.read" });
|
|
75
|
+
}
|
|
76
|
+
return result;
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
// THE LATEST BLOCK TIMESTAMP IS THE CLOCK THE CONTRACT USES. It comes from the same provider as the contract
|
|
80
|
+
// reads; an absent provider or an unreadable block leaves it null, and the time rule is skipped rather than
|
|
81
|
+
// guessed from the device clock or from another instance's provider.
|
|
82
|
+
const clockFor = (wallet) => typeof blockTime === "function" ? blockTime : async () => {
|
|
83
|
+
try {
|
|
84
|
+
const provider = providerOf(wallet);
|
|
85
|
+
if (!provider || typeof provider.request !== "function") return null;
|
|
86
|
+
const block = await provider.request({ method: "eth_getBlockByNumber", params: ["latest", false] });
|
|
87
|
+
const at = Number(block && block.timestamp);
|
|
88
|
+
return Number.isSafeInteger(at) && at > 0 ? at : null;
|
|
89
|
+
} catch { return null; }
|
|
90
|
+
};
|
|
91
|
+
// THE SENDER IS CAPTURED WITH THE OTHER ACTION INPUTS. The adapter reads eth_accounts again at the send boundary,
|
|
92
|
+
// so a wallet switch between this guard and the transaction is a refusal rather than a claim from a foreign
|
|
93
|
+
// account. A wallet that cannot name its account cannot prove which key will reveal the half.
|
|
94
|
+
const senderOf = async (wallet, step) => {
|
|
95
|
+
const sender = typeof wallet.address === "function" ? await wallet.address() : null;
|
|
96
|
+
if (typeof sender !== "string" || !sender.trim()) throw new SdkError("bad-input", { field: "wallet.address", step });
|
|
97
|
+
return sender;
|
|
98
|
+
};
|
|
99
|
+
const deps = (wallet, chainId, from) => ({ call: readerFor(wallet), send: (tx) => wallet.send({ ...tx, chainId, from }), receipt: (h) => wallet.receipt(h), blockTime: clockFor(wallet) });
|
|
62
100
|
return {
|
|
63
101
|
/** Marking "I saw the XMR on the shared address". Without it, claiming is forbidden by the contract. */
|
|
64
102
|
async markReady(request, wallet) {
|
|
65
103
|
requestOrFail(request, []);
|
|
66
104
|
walletOrFail(wallet);
|
|
67
105
|
const { escrow, expect, onStep } = request;
|
|
106
|
+
const sender = await senderOf(wallet, "mark-ready");
|
|
68
107
|
await assertWalletChain(wallet, expect.chainId, "mark-ready");
|
|
69
|
-
return await withCodes("mark-ready", () => flow.markReadyOrder({ escrow, expect, onStep, deps: deps(wallet) }));
|
|
108
|
+
return await withCodes("mark-ready", () => flow.markReadyOrder({ escrow, expect, onStep, deps: deps(wallet, expect.chainId, sender) }));
|
|
70
109
|
},
|
|
71
110
|
/** Claiming: it reveals your own half, so expectations are mandatory. */
|
|
72
111
|
async claim(request, wallet) {
|
|
73
112
|
requestOrFail(request, ["halfClaimer"]);
|
|
74
113
|
walletOrFail(wallet);
|
|
75
114
|
const { escrow, halfClaimer, expect, onStep } = request;
|
|
76
|
-
const sender =
|
|
115
|
+
const sender = await senderOf(wallet, "claim");
|
|
77
116
|
const verdict = claimSenderVerdict({ sender, claimer: request.claimer || (expect && expect.claimer) });
|
|
78
117
|
if (!verdict.ok) throw new SdkError(verdict.code, { field: verdict.field, why: verdict.why, surface: "actions.claim" });
|
|
79
118
|
await assertWalletChain(wallet, expect.chainId, "claim");
|
|
80
|
-
return await withCodes("claim", () => flow.claimOrder({ escrow, halfClaimer, expect, onStep, deps: deps(wallet) }));
|
|
119
|
+
return await withCodes("claim", () => flow.claimOrder({ escrow, halfClaimer, expect, onStep, deps: deps(wallet, expect.chainId, sender) }));
|
|
81
120
|
},
|
|
82
121
|
/** Refunding: it also reveals a half. The core passes the expectations ALWAYS, though the engine does not require them. */
|
|
83
122
|
async refund(request, wallet) {
|
|
84
123
|
requestOrFail(request, ["halfLocker"]);
|
|
85
124
|
walletOrFail(wallet);
|
|
86
125
|
const { escrow, halfLocker, expect, onStep } = request;
|
|
126
|
+
const sender = await senderOf(wallet, "refund");
|
|
87
127
|
await assertWalletChain(wallet, expect.chainId, "refund");
|
|
88
|
-
return await withCodes("refund", () => flow.refundOrder({ escrow, halfLocker, expect, onStep, deps: deps(wallet) }));
|
|
128
|
+
return await withCodes("refund", () => flow.refundOrder({ escrow, halfLocker, expect, onStep, deps: deps(wallet, expect.chainId, sender) }));
|
|
89
129
|
},
|
|
90
130
|
};
|
|
91
131
|
}
|
|
@@ -103,15 +103,34 @@ export function evmWallet(provider, { id = "evm" } = {}) {
|
|
|
103
103
|
// THERE IS DELIBERATELY NO POLLING HERE: `receipt` asks once and returns the receipt, or null if the transaction
|
|
104
104
|
// is not in a block yet. The waiting policy (how long, how often, what on refusal) is set by the caller: a
|
|
105
105
|
// policy of its own inside the adapter would mean two calls wait differently.
|
|
106
|
-
async send({ to, data = "0x", value = 0n, gas = null }) {
|
|
106
|
+
async send({ to, data = "0x", value = 0n, gas = null, chainId = null, from: expectedFrom = null }) {
|
|
107
107
|
if (typeof to !== "string" || !to) throw new SdkError("bad-input", { field: "send.to" });
|
|
108
|
-
const accounts = await provider.request({ method: "eth_accounts" });
|
|
109
|
-
const from = Array.isArray(accounts) ? accounts[0] : null;
|
|
110
|
-
if (!from) throw new SdkError("wallet-not-connected", { step: "send" });
|
|
111
108
|
const hex = (v) => "0x" + BigInt(v).toString(16);
|
|
109
|
+
// THE CHAIN AND THE SENDER ARE READ AT THE SEND BOUNDARY, NOT ONLY AT THE START OF THE ACTION. A wallet can
|
|
110
|
+
// switch networks or accounts between the action's guard and this call; reading both here, refusing a
|
|
111
|
+
// mismatch and putting the values into the transaction makes that switch a refusal instead of a signature
|
|
112
|
+
// from the wrong key or on the wrong chain.
|
|
113
|
+
const gotChain = hexToInt(await provider.request({ method: "eth_chainId" }).catch(() => null));
|
|
114
|
+
if (!Number.isSafeInteger(gotChain) || gotChain <= 0) {
|
|
115
|
+
throw new SdkError("wrong-chain", { vm: "evm", step: "send", want: chainId === null || chainId === undefined ? null : Number(chainId), got: null, why: "unreadable" });
|
|
116
|
+
}
|
|
117
|
+
const wantChain = chainId === null || chainId === undefined ? gotChain : Number(chainId);
|
|
118
|
+
if (!Number.isSafeInteger(wantChain) || wantChain <= 0 || gotChain !== wantChain) {
|
|
119
|
+
throw new SdkError("wrong-chain", { vm: "evm", step: "send", want: wantChain, got: gotChain });
|
|
120
|
+
}
|
|
121
|
+
const accounts = await provider.request({ method: "eth_accounts" });
|
|
122
|
+
const account = Array.isArray(accounts) ? accounts[0] : null;
|
|
123
|
+
if (typeof account !== "string" || !ADDRESS_RE.test(account)) throw new SdkError("wallet-not-connected", { step: "send" });
|
|
124
|
+
if (expectedFrom !== null && expectedFrom !== undefined) {
|
|
125
|
+
const wantFrom = String(expectedFrom).toLowerCase();
|
|
126
|
+
if (!ADDRESS_RE.test(wantFrom)) throw new SdkError("bad-input", { field: "send.from" });
|
|
127
|
+
if (account.toLowerCase() !== wantFrom) {
|
|
128
|
+
throw new SdkError("wrong-account", { vm: "evm", step: "send", want: wantFrom, got: account });
|
|
129
|
+
}
|
|
130
|
+
}
|
|
112
131
|
// GAS IS PASSED IF THE CALLER SET IT: every contract call has its own estimate (marking ready, claiming,
|
|
113
132
|
// refunding), and it comes from the same place as the calldata - the engine's EVM layer.
|
|
114
|
-
const tx = { from, to, data, value: hex(value) };
|
|
133
|
+
const tx = { from: account, to, data, value: hex(value), chainId: hexChainId(gotChain) };
|
|
115
134
|
if (gas !== null && gas !== undefined) tx.gas = hex(gas);
|
|
116
135
|
return await provider.request({ method: "eth_sendTransaction", params: [tx] });
|
|
117
136
|
},
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// DECLARATIONS FOR THE `./adapters` ENTRY.
|
|
2
|
+
//
|
|
3
|
+
// This is the environment seam the interface wires in itself: an EIP-1193 wallet, browser or memory storage, and
|
|
4
|
+
// the two Monero wallet roles. The declarations name exactly what src/adapters/index.mjs re-exports; the test-only
|
|
5
|
+
// Node wallet is intentionally not exported here (it lives in tools/ and is not part of the package contract).
|
|
6
|
+
|
|
7
|
+
import type {
|
|
8
|
+
Eip1193Provider,
|
|
9
|
+
MoneroWalletAdapter,
|
|
10
|
+
StorageAdapter,
|
|
11
|
+
WalletAdapter,
|
|
12
|
+
} from "@ninsei-labs/sdk";
|
|
13
|
+
|
|
14
|
+
export interface EvmWalletOptions {
|
|
15
|
+
/** A short adapter name for the interface; not user-facing text. */
|
|
16
|
+
id?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Wrap an EIP-1193 provider as the SDK's EVM wallet adapter. */
|
|
20
|
+
export declare function evmWallet(provider: Eip1193Provider, options?: EvmWalletOptions): WalletAdapter;
|
|
21
|
+
|
|
22
|
+
/** Browser storage adapter; the scope prefix is the interface's namespace. */
|
|
23
|
+
export declare function localStorageAdapter(scope?: string): StorageAdapter;
|
|
24
|
+
|
|
25
|
+
/** In-memory storage, used by tests and non-browser hosts. */
|
|
26
|
+
export declare function memoryAdapter(initial?: Record<string, string>): StorageAdapter;
|
|
27
|
+
|
|
28
|
+
export interface MoneroWalletOptions {
|
|
29
|
+
/** The monero-ts wallet factory (`createWalletFull` in the browser bundle). */
|
|
30
|
+
createWallet?: (config: Record<string, unknown>) => Promise<unknown>;
|
|
31
|
+
/** A network name accepted by the core: mainnet, stagenet, testnet or fakechain. */
|
|
32
|
+
networkType?: string;
|
|
33
|
+
/** The Monero node or proxy URI. */
|
|
34
|
+
serverUri?: string;
|
|
35
|
+
/** Session password; it protects the in-memory wallet session, not the keys. */
|
|
36
|
+
password?: string;
|
|
37
|
+
/** Extra fields passed to the wallet factory. */
|
|
38
|
+
fields?: Record<string, unknown>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The XMR withdrawal role: sign separately from relay. */
|
|
42
|
+
export interface MoneroWithdrawalWallet {
|
|
43
|
+
open(plan: { readonly address?: string; readonly restoreHeight?: number; readonly networkType?: string } | unknown): Promise<void>;
|
|
44
|
+
sync(): Promise<void>;
|
|
45
|
+
unlockedBalance(): Promise<bigint | number | string>;
|
|
46
|
+
sweepUnlocked(request: { readonly address: string; readonly relay: boolean }): Promise<unknown>;
|
|
47
|
+
fee?(signed: unknown): Promise<string | null>;
|
|
48
|
+
relay(signed: unknown): Promise<readonly string[]>;
|
|
49
|
+
close(): Promise<void>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Build the XMR withdrawal wallet over the caller's monero-ts factory. */
|
|
53
|
+
export declare function moneroWallet(options?: MoneroWalletOptions): MoneroWithdrawalWallet;
|
|
54
|
+
|
|
55
|
+
export interface MoneroWalletAdapterOptions {
|
|
56
|
+
createWallet?: (config: Record<string, unknown>) => Promise<unknown> | null;
|
|
57
|
+
network?: string | null;
|
|
58
|
+
serverUri?: string | null;
|
|
59
|
+
password?: string;
|
|
60
|
+
keys?: Record<string, unknown>;
|
|
61
|
+
restoreHeight?: number;
|
|
62
|
+
expectedAddress?: string | null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Build the SDK wallet adapter over a Monero wallet; it also carries the withdrawal methods. */
|
|
66
|
+
export declare function moneroWalletAdapter(options?: MoneroWalletAdapterOptions): WalletAdapter & Partial<MoneroWalletAdapter>;
|
package/src/adapters/index.mjs
CHANGED
|
@@ -13,9 +13,3 @@ export { moneroWallet } from "./monero.mjs";
|
|
|
13
13
|
// withdrawal role (open/sync/sweepUnlocked/relay); `moneroWalletAdapter` plays the SDK wallet role (vm/connect/
|
|
14
14
|
// address/chainId/unlockedBalance/subscribe/driver). One file for two roles would mix their surfaces.
|
|
15
15
|
export { moneroWalletAdapter } from "./monero-wallet.mjs";
|
|
16
|
-
// A TOOL OF THE TEST CONTOUR - SEPARATE FROM THE PAGE'S WALLET. It signs with its own key (the key comes only
|
|
17
|
-
// from the environment or a file) and refuses to sign on a production network by the engine's marker, so it is
|
|
18
|
-
// only good for local runs. A separate line here also because every file in the directory must be reachable
|
|
19
|
-
// through the package's map: otherwise the adapter exists but cannot be imported.
|
|
20
|
-
export { nodeTestEvmWallet, evmRpcReader, evmRpcProvider, testPrivateKeyFromEnv, isProductionChain, addressOfPrivateKey }
|
|
21
|
-
from "./node-test-evm-wallet.mjs";
|
package/src/codes.mjs
CHANGED
|
@@ -46,6 +46,9 @@ export const ERROR_CODES = [
|
|
|
46
46
|
"wallet-not-connected",
|
|
47
47
|
"wallet-rejected",
|
|
48
48
|
"wrong-chain",
|
|
49
|
+
// THE SENDER CHANGED BETWEEN THE ACTION GUARD AND eth_sendTransaction. A claim or refund reveals a half, so
|
|
50
|
+
// signing from another account would publish the half without paying the claimer; the adapter refuses first.
|
|
51
|
+
"wrong-account",
|
|
49
52
|
"quote-unavailable",
|
|
50
53
|
"quote-refused",
|
|
51
54
|
// A NODE'S ADDRESS DENYLIST REFUSAL (issue #16): the maker's node answers {ok:false, code:"denied-address", why}
|
|
@@ -116,6 +119,10 @@ export const ERROR_CODES = [
|
|
|
116
119
|
"xmr-too-late",
|
|
117
120
|
"contract-reverted",
|
|
118
121
|
"insufficient-funds",
|
|
122
|
+
// A FEE REPORTED BY A WALLET/NODE IS DATA, NOT AN INSTRUCTION. Without a ceiling a malicious node can take
|
|
123
|
+
// most of the withdrawal. The refusal names the fee and the limit so the interface does not present it as a
|
|
124
|
+
// normal transfer.
|
|
125
|
+
"sweep-fee-too-high",
|
|
119
126
|
// CLAIM GAS FOR THE XMR SELLER (issue #78). The seller comes from Monero and has no coin on the EVM side to pay
|
|
120
127
|
// for the claim, so the maker may send it - but only when asked for, and only after the core has CONFIRMED the
|
|
121
128
|
// gas actually arrived. The three codes name the three states the interface must not blur together:
|
|
@@ -149,6 +156,7 @@ export const ERROR_META = Object.freeze({
|
|
|
149
156
|
"wallet-not-connected": { retryable: false, side: "wallet" },
|
|
150
157
|
"wallet-rejected": { retryable: false, side: "wallet" },
|
|
151
158
|
"wrong-chain": { retryable: false, side: "wallet" },
|
|
159
|
+
"wrong-account": { retryable: false, side: "wallet" },
|
|
152
160
|
"quote-unavailable": { retryable: true, side: "provider" },
|
|
153
161
|
"quote-refused": { retryable: false, side: "provider" },
|
|
154
162
|
"address-denied": { retryable: false, side: "caller" },
|
|
@@ -179,6 +187,7 @@ export const ERROR_META = Object.freeze({
|
|
|
179
187
|
"xmr-too-late": { retryable: false, side: "chain" },
|
|
180
188
|
"contract-reverted": { retryable: false, side: "chain" },
|
|
181
189
|
"insufficient-funds": { retryable: false, side: "wallet" },
|
|
190
|
+
"sweep-fee-too-high": { retryable: false, side: "chain" },
|
|
182
191
|
"gas-refused-by-maker": { retryable: false, side: "provider" },
|
|
183
192
|
"gas-not-arrived": { retryable: true, side: "chain" },
|
|
184
193
|
"gas-too-little": { retryable: false, side: "provider" },
|
package/src/index.mjs
CHANGED
|
@@ -206,8 +206,9 @@ export function createNinsei(options) {
|
|
|
206
206
|
// ONE CLIENT, ONE STORE. A second client with another adapter used to replace the module-wide store, so the
|
|
207
207
|
// first client listed the second's swaps and could delete them. Even a client that brought no adapter binds the
|
|
208
208
|
// current one, so a later explicit store cannot take it over.
|
|
209
|
-
|
|
210
|
-
|
|
209
|
+
// ONE CLIENT, ONE STORE - WITHOUT A PROCESS-WIDE EXCLUSIVE BINDING. Each facade gets a store over its own
|
|
210
|
+
// adapter; two clients with different storages coexist and neither can take over the other's records.
|
|
211
|
+
const store = engine.store.createStore(o.storage || engine.store.storage());
|
|
211
212
|
const http = createHttp({ apiBase: config.apiBase, fetchImpl: o.fetch, timeoutMs: config.limits.httpTimeoutMs });
|
|
212
213
|
// THE CHAIN READ AND THE ALLOW-LIST GO INTO THE QUOTE CHECK: without the read the signature certifies itself,
|
|
213
214
|
// so the same evmCall seam the lock and the actions use is handed to the quotes too.
|
|
@@ -294,7 +295,7 @@ export function createNinsei(options) {
|
|
|
294
295
|
// THE PATHS, THE POLL TIMINGS AND THE PASS GO INTO THE START: without the configuration the "server" step
|
|
295
296
|
// would not know where to knock, and without the pass there is nothing to present to the service (and that
|
|
296
297
|
// is a refusal with a CODE, not an invented path).
|
|
297
|
-
swaps: createSwaps({ preflight, http, mode: o.mode, xmrNetwork: o.xmrNetwork, call: o.evmCall,
|
|
298
|
+
swaps: createSwaps({ preflight, http, mode: o.mode, xmrNetwork: o.xmrNetwork, call: o.evmCall, store,
|
|
298
299
|
// THE LOG SEAM FOR THE DECLINE CHECK: the watch asks the escrow for its `Declined` event on every tick, so
|
|
299
300
|
// a declined order stops the wait at once instead of running to `xmr-timeout`.
|
|
300
301
|
logs: o.evmLogs || null,
|
package/src/lock.mjs
CHANGED
|
@@ -98,7 +98,7 @@ export async function send(request, wallet, deps = {}) {
|
|
|
98
98
|
return await evm.fundOrder({
|
|
99
99
|
...canonical,
|
|
100
100
|
call: reader,
|
|
101
|
-
send: (tx) => wallet.send(tx),
|
|
101
|
+
send: (tx) => wallet.send({ ...tx, chainId: canonical.chainId, from: canonical.locker }),
|
|
102
102
|
// NORMALISING THE RECEIPT ARGUMENT'S SHAPE - HERE, AT THE CORE'S BOUNDARY, NOT AT EVERY CALLER.
|
|
103
103
|
//
|
|
104
104
|
// funding.js calls the receipt with an OBJECT { hash } (waitReceipt), while the adapter contract declares
|
package/src/provider/envFile.mjs
CHANGED
|
@@ -18,7 +18,17 @@ import { tmpdir } from "node:os";
|
|
|
18
18
|
// the settings were in place (the quote checks fell exactly on this, and `npm run payout` with them).
|
|
19
19
|
// The reverse order can err in one direction only: on the server there is no .local file at all, and the production
|
|
20
20
|
// one remains the only one. An explicit --env= still outranks everything.
|
|
21
|
-
|
|
21
|
+
// THE `rfq/` PATH IS A SUPPORTED LAYOUT, NOT A COMMENT: the node tree keeps its settings in `rfq/`, while a
|
|
22
|
+
// checkout run from the repository root has the same file one level down. The local file outranks the production
|
|
23
|
+
// file in BOTH layouts; an explicit --env= still outranks the list.
|
|
24
|
+
export const ENV_CANDIDATES = [
|
|
25
|
+
"rfq.env.local",
|
|
26
|
+
"rfq/rfq.env.local",
|
|
27
|
+
"rfq.env",
|
|
28
|
+
"rfq/rfq.env",
|
|
29
|
+
".env.local",
|
|
30
|
+
".env",
|
|
31
|
+
];
|
|
22
32
|
|
|
23
33
|
export function findEnvFile(cwd, candidates = ENV_CANDIDATES) {
|
|
24
34
|
for (const rel of candidates) {
|
package/src/public/order.d.ts
CHANGED
|
@@ -112,6 +112,10 @@ export interface OrderQuote {
|
|
|
112
112
|
readonly xmrAmount: string | number | bigint;
|
|
113
113
|
/** The tip `claim` pays to a third-party sender out of the payout; zero means none. */
|
|
114
114
|
readonly claimTip: string | number | bigint;
|
|
115
|
+
/** The depositor's half commitment and two Monero points, signed with the quote. */
|
|
116
|
+
readonly commitHalfLocker: string;
|
|
117
|
+
readonly edPointLocker: string;
|
|
118
|
+
readonly edViewPointLocker: string;
|
|
115
119
|
/** The escrow factory the domain names as `verifyingContract`. */
|
|
116
120
|
readonly factory: string;
|
|
117
121
|
/** r || s || v over the digest, 65 bytes, with or without the `0x` prefix; v is normalised to 27/28. */
|