@ninsei-labs/sdk 0.57.2 → 0.59.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.
Files changed (53) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +82 -32
  3. package/THIRD_PARTY_NOTICES.md +7 -4
  4. package/assets/vendors/MANIFEST.json +1 -9
  5. package/assets/vendors/sdk/sdk-browser.js +4 -6
  6. package/engine/core/config.js +5 -24
  7. package/engine/core/deployments.generated.js +33 -0
  8. package/engine/core/rfqSource.js +6 -133
  9. package/engine/core/swap.js +1 -1
  10. package/engine/evm/index.js +3 -2
  11. package/engine/evm/session.js +46 -277
  12. package/engine/monero/address.js +15 -33
  13. package/engine/monero/keys.js +124 -0
  14. package/engine/monero/mnemonic.js +104 -0
  15. package/engine/monero/scan.js +79 -17
  16. package/engine/monero/wallet.js +31 -68
  17. package/engine/monero/wordlist.en.js +210 -0
  18. package/engine/recovery/restore.js +1 -1
  19. package/engine/sdk/bridge.js +7 -182
  20. package/engine/ui/walletModal.js +7 -27
  21. package/index.d.ts +248 -254
  22. package/package.json +6 -7
  23. package/src/codes.mjs +12 -0
  24. package/src/config.mjs +16 -54
  25. package/src/engine.mjs +3 -0
  26. package/src/index.mjs +25 -46
  27. package/src/order.mjs +2 -2
  28. package/src/public/networks.d.ts +9 -0
  29. package/src/public/networks.mjs +1 -0
  30. package/src/public/recovery.d.ts +17 -1
  31. package/src/public/recovery.mjs +1 -0
  32. package/src/public/xmr.d.ts +8 -0
  33. package/src/public/xmr.mjs +1 -1
  34. package/src/quotePolicy.mjs +58 -0
  35. package/src/quotes.mjs +30 -753
  36. package/src/readyWindow.mjs +76 -0
  37. package/src/record.mjs +4 -0
  38. package/src/recovery-key.mjs +39 -2
  39. package/src/recovery.mjs +11 -28
  40. package/src/relayClaim.mjs +132 -0
  41. package/src/relayFirmClient.mjs +3 -0
  42. package/src/relayQuote.mjs +5 -1
  43. package/src/swap-flow.mjs +49 -5
  44. package/src/swaps.mjs +530 -317
  45. package/src/sweep-action.mjs +73 -0
  46. package/src/sweep.mjs +7 -1
  47. package/src/version.mjs +1 -1
  48. package/src/witness-slice.mjs +84 -0
  49. package/src/xmr-arrival.mjs +378 -9
  50. package/src/xmrAmountPolicy.mjs +35 -0
  51. package/assets/vendors/monero/monero-js-browser.js +0 -58
  52. package/assets/vendors/monero-js/LICENSE +0 -9
  53. package/assets/vendors/walletconnect/wc-browser.js +0 -6202
@@ -3,7 +3,7 @@
3
3
  // Everything below this header is identical to the source.
4
4
 
5
5
  // VM-neutral deployment pins generated from deployments/<vm>/<network>.json. No address table is copied below.
6
- import { DEPLOYMENTS, DEPLOYMENT_CHAINS, DEPLOYMENT_VMS, deploymentFor } from "./deployments.generated.js";
6
+ import { DEPLOYMENTS, DEPLOYMENT_CHAINS, DEPLOYMENT_VMS, FACTORY_HISTORY, deploymentFor } from "./deployments.generated.js";
7
7
 
8
8
  // Demo configuration. Every number a user sees lives here. Values come from the litepaper and are marked as demo data in the UI.
9
9
  //
@@ -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.
@@ -794,7 +790,7 @@ export const KNOWN_FACTORY_CODES = Object.freeze(Object.fromEntries(
794
790
  .map((deployment) => [deployment.network, [...deployment.knownFactoryCodes]]),
795
791
  ));
796
792
 
797
- export { DEPLOYMENTS, DEPLOYMENT_CHAINS, DEPLOYMENT_VMS, deploymentFor };
793
+ export { DEPLOYMENTS, DEPLOYMENT_CHAINS, DEPLOYMENT_VMS, FACTORY_HISTORY, deploymentFor };
798
794
 
799
795
  export function knownFactoryCodesFor(chainOrId) {
800
796
  const id = typeof chainOrId === "string" ? chainOrId : chainOrId && chainOrId.id;
@@ -862,9 +858,8 @@ export function tokenById(idOrChainId, symbolMaybe) {
862
858
  }
863
859
 
864
860
 
865
- // The demo's Monero network. networkType=mainnet because monero-js (the vendored mnemonic/key/address library)
866
- // supports only mainnet address prefixes (see the vendored readme). The monero-ts mode (WebAssembly wallet2) also
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 in the demo are computed by monero-js, the only path (the WASM wallet
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"],
@@ -1,5 +1,6 @@
1
1
  // GENERATED FILE - do not edit. Run: node tools/gen-deployment-pins.mjs --write
2
2
  // Source: deployments/<vm>/<network>.json, copied from the reviewed contract release manifest.
3
+ // Factory history: deployments/history/<vm>/<network>.json, reviewed old factories for recovery.
3
4
  const freeze = (value) => {
4
5
  if (value && typeof value === "object") {
5
6
  Object.freeze(value);
@@ -84,10 +85,42 @@ const DATA = {
84
85
  ]
85
86
  }
86
87
  };
88
+ const HISTORY_DATA = {
89
+ "arbitrum-sepolia": [
90
+ {
91
+ "address": "0x3ee25f12758ec28e5b3045d16132d89cd0bf341f",
92
+ "deploymentBlock": 318911595,
93
+ "release": {
94
+ "tag": "contracts-testnet-2026.10.21"
95
+ },
96
+ "status": "retired"
97
+ },
98
+ {
99
+ "address": "0x69b5a6878b542960af4d239ecc60ad1c9e3e6932",
100
+ "deploymentBlock": 323014007,
101
+ "release": {
102
+ "tag": "contracts-testnet-2026.10.26"
103
+ },
104
+ "status": "retired"
105
+ },
106
+ {
107
+ "address": "0x245d3a4ac4b98d713f6c5130b56cd5d550f8cefe",
108
+ "deploymentBlock": 326005419,
109
+ "release": {
110
+ "tag": "contracts-testnet-2026.11.04",
111
+ "commit": "930366a387c0c696bda6f5c038f23617447ebb78",
112
+ "toolchain": "0.8.38",
113
+ "deployedAt": "2026-11-04T15:00:55.822Z"
114
+ },
115
+ "status": "live"
116
+ }
117
+ ]
118
+ };
87
119
 
88
120
  export const DEPLOYMENTS = freeze(DATA);
89
121
  export const DEPLOYMENT_CHAINS = freeze(Object.keys(DATA).sort());
90
122
  export const DEPLOYMENT_VMS = freeze([...new Set(Object.values(DATA).map((d) => d.vm))].sort());
123
+ export const FACTORY_HISTORY = freeze(HISTORY_DATA);
91
124
 
92
125
  // Accept a network id, a CAIP-2, or an EVM chain id. No fallback to another network: an unknown deployment is null.
93
126
  export function deploymentFor(chainOrId) {
@@ -1,20 +1,10 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/core/rfqSource.js for the SDK package.
2
- // Edit the source under www/js and regenerate the mirror; a drift guard reddens on any difference.
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
- // LIVE INDICATIVE QUOTES FROM OUR PROVIDER - THROUGH THE SDK CORE.
6
- // WHY THROUGH THE CORE, NOT OUR OWN REQUEST. The read rules (zero = "no direction", staleness by the quote own
7
- // stamp, a self-contradicting row) used to live here and, separately, in the core, and two editions of one rule
8
- // diverge silently. So the book now comes from the CORE: watch - quotes.watch, snapshot - quotes.snapshot, and
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
- }
@@ -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-js",
222
+ library: "ninsei-monero-keys",
223
223
  network: e.moneroNetwork || MONERO.networkType,
224
224
  address: e.moneroAddress,
225
225
  subaddress: null,
@@ -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: WalletConnect (www/js/evm/walletconnect.js) - the user's real wallet, real balances.
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, so WalletConnect remains.
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
  }