@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/engine/core/config.js
CHANGED
|
@@ -45,10 +45,6 @@ export const ENDPOINTS = Object.freeze({
|
|
|
45
45
|
sweepOrigin: (BROWSER_DEPLOY && BROWSER_DEPLOY.sweepOrigin) || (NODE_ENV && NODE_ENV.NINSEI_SWEEP_ORIGIN) || LOCAL_ENDPOINTS.sweepOrigin,
|
|
46
46
|
});
|
|
47
47
|
|
|
48
|
-
// THE PAGE'S OWN ADDRESS comes from the environment, not from a constant: WalletConnect compares the metadata url
|
|
49
|
-
// with the page's actual origin, so a hard-coded host breaks the session on any other host.
|
|
50
|
-
const PAGE_ORIGIN = typeof location !== "undefined" ? location.origin : "";
|
|
51
|
-
|
|
52
48
|
// THE EIP-712 SIGNING DOMAIN (name/version) for a signed order quote. It is NOT a brand literal in the signer: it
|
|
53
49
|
// belongs to the registry contract (it returns DOMAIN_SEPARATOR()), so it is taken from the config here. The defaults
|
|
54
50
|
// reproduce today's result byte for byte.
|
|
@@ -862,9 +858,8 @@ export function tokenById(idOrChainId, symbolMaybe) {
|
|
|
862
858
|
}
|
|
863
859
|
|
|
864
860
|
|
|
865
|
-
// The demo's Monero network.
|
|
866
|
-
//
|
|
867
|
-
// handles stagenet.
|
|
861
|
+
// The demo's Monero network. The package's own Monero key module supports the mainnet, stagenet and testnet
|
|
862
|
+
// address prefixes. The monero-ts mode (WebAssembly wallet2) also handles stagenet.
|
|
868
863
|
// The order recipient (claimer) for TESTS on test networks.
|
|
869
864
|
//
|
|
870
865
|
// IMPORTANT: the contract requires locker and claimer to differ, so a payment address must not be given here -
|
|
@@ -944,20 +939,6 @@ export const SWEEP = {
|
|
|
944
939
|
localOrigin: "http://localhost:5195",
|
|
945
940
|
};
|
|
946
941
|
|
|
947
|
-
// ---------------------------------------------------------------------------
|
|
948
|
-
// The EVM wallet: WalletConnect (Reown). projectId is the app's public identifier, visible to any site with
|
|
949
|
-
// WalletConnect (not a secret: it goes into the QR and the relay). The metadata is shown to the user in the wallet.
|
|
950
|
-
// ---------------------------------------------------------------------------
|
|
951
|
-
export const EVM = {
|
|
952
|
-
projectId: "18c13c05b6c0ab011ffff7cee0700e2d",
|
|
953
|
-
metadata: {
|
|
954
|
-
name: "NinseiSwap",
|
|
955
|
-
description: "Non-custodial XMR <-> EVM atomic swap. Demo build: real wallet, real balances, no real funds move.",
|
|
956
|
-
url: PAGE_ORIGIN,
|
|
957
|
-
icons: [],
|
|
958
|
-
},
|
|
959
|
-
};
|
|
960
|
-
|
|
961
942
|
// THERE IS NO FEE RATE HERE - AND THERE MUST NOT BE. The only source of truth is the SIGNED QUOTE. The rate, amount
|
|
962
943
|
// and recipient of the fee are part of the order terms; the factory no longer has feeBps()/feeFor() (the router was
|
|
963
944
|
// removed), and the node does not compare its setting with the chain - it SIGNS it, while the amount comes in the
|
|
@@ -992,7 +973,7 @@ export const DEMO = {
|
|
|
992
973
|
defaultSpeed: 60,
|
|
993
974
|
scenarios: ["happy", "maker_no_lock", "user_no_ready", "maker_stall"],
|
|
994
975
|
defaultScenario: "happy",
|
|
995
|
-
// There is no wallet mode any more: keys
|
|
976
|
+
// There is no wallet mode any more: keys are derived by the package's own Monero module, the only path (the WASM wallet
|
|
996
977
|
// monero-ts moved to the separate sweep domain - its own policy and COOP/COEP).
|
|
997
978
|
// mock - confirmations by a sim timer; live - by the real Monero mainnet height
|
|
998
979
|
chainModes: ["mock", "live"],
|
package/engine/core/rfqSource.js
CHANGED
|
@@ -1,20 +1,10 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
// Everything below this header is identical to the source.
|
|
1
|
+
// THE ORDER-QUOTE MIRROR OF www/js/core/rfqSource.js. The SDK copy drops the indicative quote book that the page
|
|
2
|
+
// still uses: the bridge helpers it called are gone. Keep the order-quote path in sync with the source.
|
|
4
3
|
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
// the shape is translated by the bridge. NO selection rule is left here: the core decides. Core silence or
|
|
10
|
-
// refusal gives an EMPTY book.
|
|
11
|
-
// THE SNAPSHOT SHAPE, in short: no STEPS (one RANGE, one price); one quote KIND - quoteKind is gone, the only
|
|
12
|
-
// firm quote is the order one; rate: 0 means "direction disabled" with a why, and zero is NEVER a price; the
|
|
13
|
-
// network is part of the market identity and is checked against ours; seq and at travel with the quote for
|
|
14
|
-
// freshness; the SIZE is in units of the ASSET (the first pair element).
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
import { API, DEFAULT_CHAIN } from "./config.js";
|
|
4
|
+
// THE ORDER QUOTE FOR THE EXECUTOR FALLBACK. This module no longer carries the indicative quote book: the SDK has
|
|
5
|
+
// no book path, and the bridge helpers it called (`sdkBook`, `sdkBookSnapshot`) are gone. What remains is the
|
|
6
|
+
// order quote the executor asks for when it has to fall back to the provider, and its shape check.
|
|
7
|
+
import { API } from "./config.js";
|
|
18
8
|
|
|
19
9
|
// QUOTE FOR A SPECIFIC ORDER (orderQuote). The request goes THROUGH OUR BACKEND, not straight to the provider
|
|
20
10
|
// node: a direct request would require CORS headers, i.e. a node exposed to the internet. Our backend routes
|
|
@@ -56,120 +46,3 @@ export function checkOrderQuoteShape(quote) {
|
|
|
56
46
|
|
|
57
47
|
let baseOverride = null;
|
|
58
48
|
const apiBase = () => baseOverride || API.base;
|
|
59
|
-
|
|
60
|
-
// WHAT WE ASK THE CORE. The side and SIZE are in units of the ASSET; the network and token let the core pick ITS
|
|
61
|
-
// instance. No numbers appear here: the size comes from the screen, aligned to the provider grid.
|
|
62
|
-
let query = { size: 1, side: "buy", chain: DEFAULT_CHAIN, token: null };
|
|
63
|
-
export function setRfqQuery(next) {
|
|
64
|
-
if (!next) return;
|
|
65
|
-
if (next.side === "buy" || next.side === "sell") query.side = next.side;
|
|
66
|
-
// NO QUOTE KIND IN THE REQUEST anymore: the second kind does not exist.
|
|
67
|
-
if (next.size !== null && next.size !== undefined && Number(next.size) > 0) query.size = Number(next.size);
|
|
68
|
-
else query.size = 1; // no amount entered - ask for one ASSET unit, not "nothing"
|
|
69
|
-
if (typeof next.chain === "string" && next.chain) query.chain = next.chain;
|
|
70
|
-
if (typeof next.token === "string" && next.token) query.token = next.token;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// The current request: the screen needs to know the side and size asked for, else it cannot tell "the provider is
|
|
74
|
-
// silent" from "the provider does not take this size".
|
|
75
|
-
export function rfqQuery() {
|
|
76
|
-
return { ...query };
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// THE SNAPSHOT THE SCREENS READ: { ok, error, data, at }. In data - references and best, while offers and
|
|
80
|
-
// refusals come from rfqOffers(). If the core was never polled or refused, there is no data, shown by ok.
|
|
81
|
-
// Old numbers are not pasted as "live".
|
|
82
|
-
const snapshot = { ok: false, error: null, data: null, at: 0, fetching: false };
|
|
83
|
-
export function rfqSnapshot() {
|
|
84
|
-
return snapshot;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// The pair the user SEES: buying XMR means the pairs XMR/<asset>; selling means the reverse.
|
|
88
|
-
export function pairFacingUser(side = query.side, asset = "ETH") {
|
|
89
|
-
return side === "sell" ? asset.toUpperCase() + "/XMR" : "XMR/" + asset.toUpperCase();
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// PAIR SIDES ARE READ BY POSITION: the first element is the ASSET (the size is measured in it), the second is
|
|
93
|
-
// the CURRENCY (what is paid). Separate functions, because this is a convention.
|
|
94
|
-
export function pairAsset(pair) {
|
|
95
|
-
return String(pair || "").split("/")[0].toUpperCase();
|
|
96
|
-
}
|
|
97
|
-
export function pairCurrency(pair) {
|
|
98
|
-
return String(pair || "").split("/")[1] ? String(pair).split("/")[1].toUpperCase() : "";
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// OFFERS AND REFUSALS - FROM THE CORE SNAPSHOT, NO SECOND SELECTION. The core already split the rows into
|
|
102
|
-
// offers and refusals and named the best. Here they are only transferred: no own filtering, sorting or
|
|
103
|
-
// thresholds. An empty snapshot is an empty book.
|
|
104
|
-
export function rfqOffers() {
|
|
105
|
-
const data = snapshot.ok && snapshot.data ? snapshot.data : null;
|
|
106
|
-
if (!data) return { offers: [], refused: [], seq: null, at: null };
|
|
107
|
-
return {
|
|
108
|
-
offers: data.offers || [],
|
|
109
|
-
refused: data.refused || [],
|
|
110
|
-
seq: data.seq === undefined ? null : data.seq,
|
|
111
|
-
at: data.at === undefined ? null : data.at,
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// CHECKING THE QUOTE NETWORK AGAINST OURS. The network is part of the market identity: arbitrum and
|
|
116
|
-
// arbitrum-sepolia are ONE WORD FOR DIFFERENT MONEY, and a wallet does not move coins between them. The side
|
|
117
|
-
// holding XMR must speak Monero, the other the EVM registry language (its id). We return a verdict, not a
|
|
118
|
-
// throw: one quote refusal does not close the market.
|
|
119
|
-
export function quoteNetworksFit(quote, { monero, evm }) {
|
|
120
|
-
const xmrOnAsset = quote.asset === "XMR";
|
|
121
|
-
const xmrOnCurrency = quote.currency === "XMR";
|
|
122
|
-
if (!xmrOnAsset && !xmrOnCurrency) return { ok: false, stated: quote.networkStated, why: "pair " + quote.pair + " has no XMR on either side" };
|
|
123
|
-
const moneroNet = xmrOnAsset ? quote.assetNetwork : quote.currencyNetwork;
|
|
124
|
-
const evmNet = xmrOnAsset ? quote.currencyNetwork : quote.assetNetwork;
|
|
125
|
-
const moneroSide = xmrOnAsset ? "assetNetwork" : "currencyNetwork";
|
|
126
|
-
const evmSide = xmrOnAsset ? "currencyNetwork" : "assetNetwork";
|
|
127
|
-
if (moneroNet && moneroNet !== monero) {
|
|
128
|
-
return { ok: false, stated: true, why: quote.pair + ": " + moneroSide + " is " + moneroNet + ", but this page pays XMR on " + monero };
|
|
129
|
-
}
|
|
130
|
-
if (evmNet && evmNet !== evm) {
|
|
131
|
-
return { ok: false, stated: true, why: quote.pair + ": " + evmSide + " is " + evmNet + ", but this page settles on " + evm };
|
|
132
|
-
}
|
|
133
|
-
// NOT NAMED - DOES NOT MEAN "OURS". There is nothing to compare, and that is logged, but we do not close the
|
|
134
|
-
// market for it: the rule catches a network NAMED WRONG, not a missing field.
|
|
135
|
-
return { ok: true, stated: quote.networkStated, moneroNet: moneroNet || null, evmNet: evmNet || null, why: null };
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// POLLING GOES THROUGH THE CORE. The bridge hands the core what it needs (network, size, direction) and returns
|
|
139
|
-
// the TRANSLATED snapshot. The core is loaded DYNAMICALLY: this module is also read without a browser, and then
|
|
140
|
-
// the book is simply not requested. A load failure IS a failure, not a reason to take the book elsewhere.
|
|
141
|
-
export async function refreshRfq() {
|
|
142
|
-
if (snapshot.fetching) return snapshot;
|
|
143
|
-
snapshot.fetching = true;
|
|
144
|
-
try {
|
|
145
|
-
const bridge = await import("../sdk/bridge.js");
|
|
146
|
-
await bridge.sdkBook({ chain: query.chain, direction: query.side, token: query.token, size: query.size });
|
|
147
|
-
const next = bridge.sdkBookSnapshot();
|
|
148
|
-
snapshot.ok = next.ok;
|
|
149
|
-
snapshot.error = next.error;
|
|
150
|
-
snapshot.data = next.data;
|
|
151
|
-
snapshot.at = next.at || Date.now();
|
|
152
|
-
} catch (error) {
|
|
153
|
-
// A REFUSAL IS NOT REPLACED BY OLD NUMBERS: showing a stale price as live is worse than saying there is no
|
|
154
|
-
// connection. No data is left at all.
|
|
155
|
-
snapshot.ok = false;
|
|
156
|
-
snapshot.error = String((error && error.message) || error);
|
|
157
|
-
snapshot.data = null;
|
|
158
|
-
snapshot.at = Date.now();
|
|
159
|
-
} finally {
|
|
160
|
-
snapshot.fetching = false;
|
|
161
|
-
}
|
|
162
|
-
return snapshot;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
let timer = null;
|
|
166
|
-
|
|
167
|
-
// ALWAYS POLL. The poll is not to "catch a new price": it confirms the provider is there. The core holds the
|
|
168
|
-
// poll for the subscription; this tick keeps the book updating with the screen. Node silence shows as a missing
|
|
169
|
-
// fresh stamp, not as "the price is the same".
|
|
170
|
-
export function startRfqPolling(chain = null, ms = API.pollMs) {
|
|
171
|
-
if (typeof chain === "string" && chain) query.chain = chain;
|
|
172
|
-
if (timer) return;
|
|
173
|
-
refreshRfq();
|
|
174
|
-
timer = setInterval(() => refreshRfq(), ms);
|
|
175
|
-
}
|
package/engine/core/swap.js
CHANGED
|
@@ -219,7 +219,7 @@ export function halvesWalletOf(swap) {
|
|
|
219
219
|
if (!e.half || !e.viewHalf || !e.counterViewHalf || !e.moneroAddress) return null;
|
|
220
220
|
return {
|
|
221
221
|
source: "halves",
|
|
222
|
-
library: "monero-
|
|
222
|
+
library: "ninsei-monero-keys",
|
|
223
223
|
network: e.moneroNetwork || MONERO.networkType,
|
|
224
224
|
address: e.moneroAddress,
|
|
225
225
|
subaddress: null,
|
package/engine/evm/index.js
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
// Everything below this header is identical to the source.
|
|
4
4
|
|
|
5
5
|
// The wallet used by the demo interface.
|
|
6
|
-
// One implementation:
|
|
6
|
+
// One implementation: the injected EIP-1193 browser wallet (www/js/evm/session.js) - the user's real wallet,
|
|
7
|
+
// real balances. Mobile connectors are loaded by the host page and passed in as the same provider.
|
|
7
8
|
// The built-in demo wallet and its mode switch were removed: we are heading to a real product, not a mockup.
|
|
8
9
|
// Still NO transfers: there is no escrow contract yet and the address is mocked (mock/chain.js), so funding
|
|
9
10
|
// is a simulation (simulateEscrowFunding below); provider.sendTransaction will replace it.
|
|
@@ -51,7 +52,7 @@ import { sendTransaction, readContract, readReceipt, readCode } from "./session.
|
|
|
51
52
|
export { sendTransaction, readContract, readReceipt, readCode };
|
|
52
53
|
|
|
53
54
|
// The browser wallets available here (EIP-6963, falling back to window.ethereum). An empty list is normal:
|
|
54
|
-
// no extension
|
|
55
|
+
// no extension is installed; the host can still bring its own connector and pass its provider to the SDK.
|
|
55
56
|
export function wallets() {
|
|
56
57
|
return discoverWallets();
|
|
57
58
|
}
|