@ninsei-labs/sdk 0.60.0 → 0.61.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 (56) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +28 -16
  3. package/assets/vendors/MANIFEST.json +1 -1
  4. package/assets/vendors/sdk/sdk-browser.js +4 -4
  5. package/engine/atomic/dleq2.js +0 -4
  6. package/engine/atomic/halfenc.js +0 -4
  7. package/engine/atomic/halves.js +0 -4
  8. package/engine/atomic/order.js +0 -4
  9. package/engine/atomic/orderContext.js +0 -4
  10. package/engine/atomic/orderHalfCommit.js +0 -4
  11. package/engine/core/chainSource.js +0 -4
  12. package/engine/core/clock.js +0 -4
  13. package/engine/core/config.js +0 -4
  14. package/engine/core/finality.js +0 -4
  15. package/engine/core/format.js +0 -4
  16. package/engine/core/preSignGuards.js +0 -4
  17. package/engine/core/rfqSource.js +0 -3
  18. package/engine/core/sellWindow.js +0 -4
  19. package/engine/core/store.js +0 -4
  20. package/engine/core/swap.js +0 -4
  21. package/engine/evm/amounts.js +0 -4
  22. package/engine/evm/asyncRoute.js +0 -4
  23. package/engine/evm/auth.js +0 -4
  24. package/engine/evm/claimGas.js +2 -6
  25. package/engine/evm/dex.js +0 -4
  26. package/engine/evm/escrow.js +0 -4
  27. package/engine/evm/factory.js +0 -4
  28. package/engine/evm/fees.js +0 -4
  29. package/engine/evm/funding.js +2 -5
  30. package/engine/evm/gasReserve.js +0 -4
  31. package/engine/evm/index.js +5 -9
  32. package/engine/evm/injected.js +0 -4
  33. package/engine/evm/permit.js +0 -4
  34. package/engine/evm/prices.js +0 -4
  35. package/engine/evm/session.js +0 -4
  36. package/engine/mock/chain.js +0 -4
  37. package/engine/monero/address.js +0 -3
  38. package/engine/monero/halvesSweep.js +0 -4
  39. package/engine/monero/node.js +0 -4
  40. package/engine/monero/swapKeys.js +0 -4
  41. package/engine/monero/unlock.js +2 -6
  42. package/engine/monero/wallet.js +0 -3
  43. package/engine/recovery/recoveryFile.js +0 -4
  44. package/engine/recovery/restore.js +0 -4
  45. package/engine/sdk/bridge.js +3 -7
  46. package/engine/ui/dom.js +0 -4
  47. package/engine/ui/walletModal.js +0 -4
  48. package/index.d.ts +24 -23
  49. package/package.json +3 -2
  50. package/src/engine.mjs +17 -26
  51. package/src/public/recovery.d.ts +1 -1
  52. package/src/relayClaim.mjs +17 -3
  53. package/src/swap-flow.mjs +7 -10
  54. package/src/swaps.mjs +157 -70
  55. package/src/version.mjs +1 -1
  56. package/src/xmr-arrival.mjs +14 -16
@@ -1,7 +1,3 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/atomic/dleq2.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.
4
-
5
1
  // DLEQ ACROSS CURVES: a proof that one scalar stands behind points on secp256k1 and ed25519.
6
2
  // Ported from go-dleq (prove.go, verify.go) to @noble/curves. The upstream project is
7
3
  // github.com/athanorlabs/go-dleq at d6fd7c03e213683cbb286d4d5bbba1c7e7e1cfe1 and is licensed LGPL-3.0-only; see
@@ -1,7 +1,3 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/atomic/halfenc.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.
4
-
5
1
  // Transferring a key half: an encrypted half fit for publishing on chain.
6
2
  // WHAT THIS IS. A half x is sent so that: third parties cannot read it (the mask comes from an ECDH shared secret
7
3
  // with the recipient); THE RECIPIENT can check that the ciphertext holds the half matching the published point X by
@@ -1,7 +1,3 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/atomic/halves.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.
4
-
5
1
  // Half of a Monero key for the XMR <-> EVM atomic swap.
6
2
  // The Monero spend key is the sum of two halves: ks = ks_a + ks_b (mod l); spending needs both.
7
3
  // One half must work on edwards25519 (Monero) and secp256k1 (EVM), so the scalar stays below the smaller
@@ -1,7 +1,3 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/atomic/order.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.
4
-
5
1
  // ASSEMBLING ONE ORDER SIDE of an atomic swap: a key half, points, a proof, the encrypted envelope and the
6
2
  // contract commitment.
7
3
  //
@@ -1,7 +1,3 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/atomic/orderContext.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.
4
-
5
1
  // CANONICAL ORDER CONTEXT - what the DLEQ proof binds to.
6
2
  // It is built FROM THE ORDER FIELDS and identically everywhere (app, provider node, any verifier), so a
7
3
  // proof can be checked from the on-chain order alone (docs 27, section 11).
@@ -1,7 +1,3 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/atomic/orderHalfCommit.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.
4
-
5
1
  // COMMITMENT TO A HALF - one formula for all sides.
6
2
  //
7
3
  // WHAT THE CHAIN COMPUTES. `keccak256(x || y)` of the secp256k1 POINT of the half `half*G` - that is, the ADDRESS of that point.
@@ -1,7 +1,3 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/core/chainSource.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.
4
-
5
1
  // DATA SOURCE FOR THE MONERO LEG OF THE SWAP: the demo simulator or the real backend.
6
2
  // TWO LEGS, DIFFERENT READINESS. The EVM leg (escrow, claim, refund) is a SIMULATION (no contract yet): every
7
3
  // reply is marked mock: true and the UI must show it. The Monero leg (has XMR arrived, how many confirmations)
@@ -1,7 +1,3 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/core/clock.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.
4
-
5
1
  // Demo sim-clock.
6
2
  //
7
3
  // Idea: real time is compressed by the speed multiplier. speed=60 means one
@@ -1,7 +1,3 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/core/config.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.
4
-
5
1
  // VM-neutral deployment pins generated from deployments/<vm>/<network>.json. No address table is copied below.
6
2
  import { DEPLOYMENTS, DEPLOYMENT_CHAINS, DEPLOYMENT_VMS, FACTORY_HISTORY, deploymentFor } from "./deployments.generated.js";
7
3
 
@@ -1,7 +1,3 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/core/finality.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.
4
-
5
1
  // STATE MATURITY PER NETWORK: at which level the chain treats a record as final.
6
2
  // One value for all networks is wrong: on base `safe` is ~25 s, on arbitrum ~13 min (measured on live nodes).
7
3
  // On bsc, monad and hyperevm the tags are FORMAL: they answer but lag 0-1 block, so reading by `finalized`
@@ -1,7 +1,3 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/core/format.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.
4
-
5
1
  // Formatting of numbers, time and addresses.
6
2
 
7
3
  const nf = (min, max) => new Intl.NumberFormat("en-US", { minimumFractionDigits: min, maximumFractionDigits: max });
@@ -1,7 +1,3 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/core/preSignGuards.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.
4
-
5
1
  // PRE-SIGNING GUARDS: AN INADMISSIBLE DEAL DOES NOT START.
6
2
  //
7
3
  // WHY A SEPARATE MODULE. The guards used to live apart: one in the route registry (the DEX leg's coverage and
@@ -1,6 +1,3 @@
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.
3
-
4
1
  // THE ORDER QUOTE FOR THE EXECUTOR FALLBACK. This module no longer carries the indicative quote book: the SDK has
5
2
  // no book path, and the bridge helpers it called (`sdkBook`, `sdkBookSnapshot`) are gone. What remains is the
6
3
  // order quote the executor asks for when it has to fall back to the provider, and its shape check.
@@ -1,7 +1,3 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/core/sellWindow.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.
4
-
5
1
  // XMR SELL WINDOW: ONE RULE FOR TWO SIDES, NOT TWO NUMBERS.
6
2
  //
7
3
  // WHY A SEPARATE MODULE. The XMR sell window (a person gives XMR, receives the network native coin) has two
@@ -1,7 +1,3 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/core/store.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.
4
-
5
1
  // Demo state storage.
6
2
  //
7
3
  // Why it exists at all: litepaper §5.1.7 - "the tab can be closed, the browser will restore the state". The swap
@@ -1,7 +1,3 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/core/swap.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.
4
-
5
1
  // The demo core: the deal state over time.
6
2
  //
7
3
  // PRINCIPLE: the state is NOT kept as a "current step". Timestamps and events are kept, and the phase is derived
@@ -1,7 +1,3 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/evm/amounts.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.
4
-
5
1
  // Recalculating balances from the contract raw units into human-readable ones.
6
2
  //
7
3
  // A separate module, because this is money maths and it must be checked without a browser:
@@ -1,7 +1,3 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/evm/asyncRoute.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.
4
-
5
1
  // ASYNCHRONOUS ROUTE PROVIDERS BY NETWORK - "IS THERE A PATH FOR A PERSON WITH NO OWN NATIVE COIN".
6
2
  //
7
3
  // WHY THIS MODULE EXISTS. The declared routes in the registry (www/js/core/config.js: DEX_ROUTES) are ROUTER
@@ -1,7 +1,3 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/evm/auth.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.
4
-
5
1
  // WALLET-SIGNATURE LOGIN AND THE SERVER-SIDE SWAP LIST.
6
2
  // Why: while swap records live only in localStorage, "my list" is tied to the browser. A server-side list
7
3
  // fixes that; binding it to the wallet address keeps other people's swaps hidden.
@@ -1,13 +1,9 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/evm/claimGas.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.
4
-
5
1
  // CLAIM GAS FOR THE XMR SELL (claim): ONE SOURCE OF TRUTH FOR THE CLIENT AND THE NODE.
6
2
  // In a reverse swap the person gives XMR and claims ETH via `claim` on the settlement chain. They have no ETH,
7
3
  // so the node sends the claim gas. The gas rules used to live in TWO places and the numbers differed ~100x, so
8
4
  // a person with one gift could not send the claim. Now this module computes both numbers.
9
- // WHY ONE MODULE UNDER www/js: the formula must be ONE. The EVM engine lives under www/js, and the node imports
10
- // from www/js too; the reverse import is impossible (the browser is never served the node directory).
5
+ // WHY ONE MODULE: the formula must be ONE. The SDK owns the EVM engine, and the node imports it from the package;
6
+ // the browser and the node read the same implementation.
11
7
  // WHAT IS ONE HERE: the claim gas limit, the fee rule (2 x baseFee + tip) and the GIFT SIZE - the same claim
12
8
  // cost plus an EXPLICIT margin for base-fee growth between ticket and claim.
13
9
 
package/engine/evm/dex.js CHANGED
@@ -1,7 +1,3 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/evm/dex.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.
4
-
5
1
  // THE DEX LEG: a Uniswap v3 quote read from the chain. READ ONLY: eth_call, not one transaction.
6
2
  //
7
3
  // WHAT IS REPLACED HERE. The price breakdown used to hold a mock: "Uniswap v3 USDC/WETH 0.05%" and the spread
@@ -1,7 +1,3 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/evm/escrow.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.
4
-
5
1
  // Calls to the NinseiSwap escrow contract (one instance = one order).
6
2
  //
7
3
  // There is no EVM library here: the escrow has three state-moving functions (markReady, claim, refund) and a few
@@ -1,7 +1,3 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/evm/factory.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.
4
-
5
1
  // Calls to the NinseiSwap escrow factory contract.
6
2
  //
7
3
  // There are no EVM libraries in the project and we are not adding any. BOTH FACTORY FUNCTIONS NOW TAKE THE
@@ -1,7 +1,3 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/evm/fees.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.
4
-
5
1
  // The NinseiSwap fee: PART OF THE SIGNED QUOTE (OrderQuote v7), not a contract setting.
6
2
  //
7
3
  // WHERE THE RATE LIVES. Before, it and the recipient were set by the FACTORY (or router) in immutable fields, and
@@ -1,7 +1,3 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/evm/funding.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.
4
-
5
1
  // Funding an order in the escrow contract: real transactions, not a simulation.
6
2
  //
7
3
  // Roles and why:
@@ -255,7 +251,8 @@ export async function fundOrder({ factory, locker, claimer, commitHalfLocker, co
255
251
  // point can be funded beside a proof for another, and the claim reveals a half that does not open the address.
256
252
  const sameValue = (a, b) => String(a === undefined || a === null ? "" : a).replace(/^0x/i, "").toLowerCase()
257
253
  === String(b === undefined || b === null ? "" : b).replace(/^0x/i, "").toLowerCase();
258
- for (const name of ["locker", "claimer", "amount", "readyBy", "t1", "salt", "commitHalfClaimer", "edPointClaimer"]) {
254
+ for (const name of ["locker", "claimer", "amount", "readyBy", "t1", "salt", "commitHalfClaimer", "edPointClaimer",
255
+ "commitHalfLocker", "edPointLocker", "edViewPointLocker"]) {
259
256
  if (!sameValue(quote[name], terms[name])) {
260
257
  throw new Error("the quote and the order terms diverge on field " + name);
261
258
  }
@@ -1,7 +1,3 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/evm/gasReserve.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.
4
-
5
1
  // THE BUYER GAS RESERVE FOR ORDER ACTIONS: THE READINESS MARK AND A POSSIBLE REFUND.
6
2
  //
7
3
  // THE POINT. In a direct swap the person deposits into the escrow, and after the XMR arrives calls markReady itself
@@ -1,9 +1,5 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/evm/index.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.
4
-
5
1
  // The wallet used by the demo interface.
6
- // One implementation: the injected EIP-1193 browser wallet (www/js/evm/session.js) - the user's real wallet,
2
+ // One implementation: the injected EIP-1193 browser wallet (engine/evm/session.js) - the user's real wallet,
7
3
  // real balances. Mobile connectors are loaded by the host page and passed in as the same provider.
8
4
  // The built-in demo wallet and its mode switch were removed: we are heading to a real product, not a mockup.
9
5
  // Still NO transfers: there is no escrow contract yet and the address is mocked (mock/chain.js), so funding
@@ -37,10 +33,10 @@ export * from "./funding.js";
37
33
  // protocol code, not two lookalikes.
38
34
  export * from "./permit.js";
39
35
  // THE ASYNCHRONOUS ROUTE, EXECUTED - through the same engine seam as the decision that chooses it. The page reaches
40
- // it through the bridge; the SDK carries the same module in its engine mirror (tools/build-sdk-engine.mjs).
36
+ // it through the bridge; the SDK owns this module.
41
37
  export * from "./asyncRoute.js";
42
- // THE EXECUTOR IS THE PACKAGE'S PROVIDER LAYER (src/legs/cow.mjs and its siblings). The generated mirror that
43
- // used to execute the route here carried a second submit/status path; it was removed with the order worker.
38
+ // THE EXECUTOR IS THE PACKAGE'S PROVIDER LAYER (src/legs/cow.mjs and its siblings). The old copy that used to
39
+ // execute the route here carried a second submit/status path; it was removed with the order worker.
44
40
 
45
41
  // currentProvider - the wallet provider goes OUT to the SDK core (evm-wallet.mjs) so signing uses the same
46
42
  // key as the page. Screens do not need it; they read status()/isConnected().
@@ -74,7 +70,7 @@ export async function simulateEscrowFunding(tx) {
74
70
  // Replaces simulateEscrowFunding. The difference is fundamental: the simulation invented a hash, here two
75
71
  // real transactions go out - createOrder to the factory and lock(sealedHalf) to the new escrow.
76
72
  //
77
- // Separation is deliberate: cryptography (halves, DLEQ, envelope) lives in www/js/atomic/ and does NOT reach
73
+ // Separation is deliberate: cryptography (halves, DLEQ, envelope) lives in engine/atomic/ and does NOT reach
78
74
  // here. This function gets the ready sealedCommitment and sealedHalf - exactly what goes to the contract.
79
75
  // The caller sets the order of steps: verify the counterparty first, then lock.
80
76
  //
@@ -1,7 +1,3 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/evm/injected.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.
4
-
5
1
  // BROWSER WALLETS: detection by EIP-6963 and connection by EIP-1193.
6
2
  // WHY EIP-6963, NOT window.ethereum.isMetaMask. With two extensions installed, window.ethereum is "whoever was
7
3
  // last", and guessing by flags gives wrong names and icons. EIP-6963 solves this: a wallet announces itself with
@@ -1,7 +1,3 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/evm/permit.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.
4
-
5
1
  // TOKEN ALLOWANCE FOR BUYING WITHOUT OWN ETH: what the token supports and what is missing.
6
2
  //
7
3
  // WHAT IS HERE AND WHAT IS NOT. Only selectors, calldata assembly and an HONEST verdict on whether a signature
@@ -1,7 +1,3 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/evm/prices.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.
4
-
5
1
  // LIVE MARKET NUMBERS FOR THE EVM LEG: the native price (Chainlink on-chain) and the gas cost (RPC).
6
2
  // WHY ON-CHAIN, NOT AN API: the price is a contract call over the same RPC already allowed by the CSP
7
3
  // (connect-src), so no new external domain appears, there are no keys or rate limits, and the feed address is
@@ -1,7 +1,3 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/evm/session.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.
4
-
5
1
  // The EVM wallet: state, balances, network switching and the injected connector.
6
2
 
7
3
  // A browser wallet (MetaMask, Rabby, Coinbase...) found by EIP-6963 connects directly over EIP-1193. The SDK
@@ -1,7 +1,3 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/mock/chain.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.
4
-
5
1
  // Mock chain: the escrow contract on EVM and the Monero leg.
6
2
  //
7
3
  // There are NO real transactions here. Everything returned is marked mock, and the hashes
@@ -1,6 +1,3 @@
1
- // SDK ENGINE MODULE - the demo's sdk/ mirror copies this file byte for byte (tools/build-sdk-engine.mjs).
2
- // The page's own www/js module is a separate copy; edit this package source and regenerate the mirror.
3
-
4
1
  // Monero address checks and assembly: format + real checksum + network prefixes.
5
2
  // A detail easy to get wrong: Monero has its OWN base58 - block-based (8 bytes -> 11 chars, the remainder last).
6
3
  // It is NOT compatible with bitcoin-base58, where a leading '1' means a zero byte; here a block is a NUMBER and
@@ -1,7 +1,3 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/monero/halvesSweep.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.
4
-
5
1
  // KEYS FOR SWEEPING FROM A HALVES FILE. One logic for two consumers: the sweep page (sweep.js) and the
6
2
  // check, so the two cannot drift.
7
3
  // This is the main check of the whole sweep: the contract only verifies that the HASH of the revealed half
@@ -1,7 +1,3 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/monero/node.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.
4
-
5
1
  // The live Monero node: the only real external dependency of the demo.
6
2
  //
7
3
  // The node address is the MONERO.node constant in www/js/core/config.js - the proxy
@@ -1,7 +1,3 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/monero/swapKeys.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.
4
-
5
1
  // JOINT ADDRESS KEYS FROM HALVES.
6
2
  //
7
3
  // THERE IS NO FULL SPEND KEY HERE. Neither side generates the swap wallet whole: each gives ITS half and the
@@ -1,7 +1,3 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/monero/unlock.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.
4
-
5
1
  // OUTPUT UNLOCK TIME (unlock_time). ONE RULE FOR EVERYONE WHO DECIDES "ARRIVAL IS THERE".
6
2
  //
7
3
  // A Monero transaction has an unlock_time field. Zero - "the output is open in the normal order". A non-zero
@@ -13,8 +9,8 @@
13
9
  // on the "done" mark, while the XMR stayed locked.
14
10
  //
15
11
  // WHY THE ONE SOURCE LIVES HERE. The rule is read by the backend indexer through the scan module and by the
16
- // SDK core through the engine mirror. A second copy would mean a second truth about money, so there is no copy:
17
- // the mirror must match this file to the byte, and a divergence between them is caught mechanically, not by a human.
12
+ // SDK core through the engine seam. A second copy would mean a second truth about money, so there is no copy:
13
+ // this module is the one implementation, and both readers use it.
18
14
  export const UNLOCK_TIME_BLOCK_MAX = 500_000_000;
19
15
 
20
16
  // Output state by its unlock_time. The return is a NAMED result, not a boolean: the interface must
@@ -1,6 +1,3 @@
1
- // SDK ENGINE MODULE - the demo's sdk/ mirror copies this file byte for byte (tools/build-sdk-engine.mjs).
2
- // The page's own www/js module is a separate copy; edit this package source and regenerate the mirror.
3
-
4
1
  // The one-shot Monero wallet of a swap.
5
2
  //
6
3
  // Keys are derived by the package's own Monero module (engine/monero/keys.js) from @noble/curves; the 25-word
@@ -1,7 +1,3 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/recovery/recoveryFile.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.
4
-
5
1
  // The deal recovery file: real cryptography in the browser (WebCrypto).
6
2
  //
7
3
  // Litepaper §5: without a saved recovery file a deal is not funded; if the tab is lost, this file is the only way
@@ -1,7 +1,3 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/recovery/restore.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.
4
-
5
1
  // The reverse recovery-file path: file -> wallet that can claim the XMR.
6
2
  // The forward path (file generation) is in recoveryFile.js. Here is why the file exists: recovery when the tab is
7
3
  // lost. Two rules are pinned by CODE, not by a comment:
@@ -1,7 +1,3 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/sdk/bridge.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.
4
-
5
1
  // THE PAGE-TO-CORE SHIM: THE ONE PLACE WHERE SCREENS KNOW ABOUT THE SDK (sdk/).
6
2
  //
7
3
  // WHY IT EXISTS. The swap logic lives in the core (sdk/, the @ninsei-labs/sdk package) while the page should do
@@ -408,7 +404,7 @@ export async function sdkSetDestination(id, address) {
408
404
  }
409
405
 
410
406
  // THE MONERO ADDRESS NETWORK - A CORE SURFACE (it owns the address format): the shim only exposes it to the screen.
411
- // The fallback is the same module that mirrors the core (www/js/monero/address.js): there is no second prefix table.
407
+ // The fallback is the same address module the SDK uses (engine/monero/address.js): there is no second prefix table.
412
408
  export async function sdkAddressNetwork(address) {
413
409
  const ctx = await instanceFor(undefined);
414
410
  if (ctx) return ctx.sdk.swaps.addressNetwork(address);
@@ -422,8 +418,8 @@ export async function sdkAddressNetwork(address) {
422
418
  // the deal digest and the poll tick, reads and polling of the Monero node (the core has no node);
423
419
  // * prices, fees, gas and the form's DEX leg - SHOWCASE: the numbers are read from the chain by engine
424
420
  // modules, and the screen gets them through the seam, not by a second road into the engine;
425
- // * networkFromShape/networkLabel - the Monero address shape and its name: the same format module the core
426
- // mirrors (there is no second prefix table);
421
+ // * networkFromShape/networkLabel - the Monero address shape and its name: the same format module the SDK
422
+ // uses (there is no second prefix table);
427
423
  // * createSwap/createReverseSwap/activeSwaps - the RECORD of the demo and reverse deal (the record is kept by
428
424
  // the engine; the core exposes its STATE via swaps.list/swaps.progress).
429
425
  // * createSwapWallet - THE FORM'S DEAL WALLET (state between screens, ui/formState.js): the page wallet with
package/engine/ui/dom.js CHANGED
@@ -1,7 +1,3 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/ui/dom.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.
4
-
5
1
  // Tiny DOM helpers. No frameworks: the demo must be readable by eye.
6
2
 
7
3
  export function h(tag, attrs = {}, children = []) {
@@ -1,7 +1,3 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/ui/walletModal.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.
4
-
5
1
  // A wallet-connect modal for the injected connector: browser-wallet choice only.
6
2
  // The browser-wallet list comes from outside (setChoices); detection is evm/injected.js by EIP-6963. Here is
7
3
  // only rendering: the CSP bans inline styles, so everything goes through dom.h(), and wallet icons are data: URLs.
package/index.d.ts CHANGED
@@ -169,7 +169,9 @@ export interface NinseiOptions {
169
169
  createRecord?: (request: StartRequest) => Promise<SwapRecord> | SwapRecord;
170
170
  }
171
171
 
172
- /** One durable sender attempt on a sell record, written before the relay POST. */
172
+ /** One durable sender attempt on a sell record, written before the relay POST. This is a diagnostic journal,
173
+ * not a set of senders that must be skipped on a later call. The journal is append-only and is not pruned by the
174
+ * SDK; a host may trim old entries, but must keep the latest `sending`/`unknown` one for its slot wait. */
173
175
  export interface StoredClaimAttempt {
174
176
  readonly sender: string;
175
177
  readonly at?: number;
@@ -682,10 +684,15 @@ export interface SwapsApi {
682
684
  * sender. `claimSenders` is the client's ordered list - the relay's own sender first, then the listed makers -
683
685
  * sent one at a time through the relay (`POST /v1/claims/{sender}/{escrow}`). Each sender gets a 15-30 s slot; a
684
686
  * refusal moves on, a txid or unknown answer is followed by reading the escrow, and only `claimed` on chain is
685
- * success. When the list is exhausted the result is `claim-yourself` with the time left before `t1`.
687
+ * success. A later call starts from the first sender again; a previous `sending`/`unknown` entry is waited out
688
+ * for its slot and retried, so a temporary refusal or a restart is recoverable. When the list is exhausted the
689
+ * result is `claim-yourself` with the time left before `t1`.
686
690
  *
687
- * The deal's maker and its quote-key owner are refused before the half leaves the client. No wallet is created or
688
- * used and no chain transaction is signed. `relayUrl` may restate the stored origin; a different origin is refused.
691
+ * The claim window is read with the escrow's chain clock (`evmBlock`), not the device clock. Without a readable
692
+ * clock the result is `claim-window` / `unreadable` and no half leaves the client. The same applies to an escrow
693
+ * read that fails before any POST; after an earlier attempt it remains `claim-unknown`. The deal's maker and its
694
+ * quote-key owner are refused before the half leaves the client. No wallet is created or used and no chain
695
+ * transaction is signed. `relayUrl` may restate the stored origin; a different origin is refused.
689
696
  */
690
697
  claimViaRelay(request: RelayClaimRequest): Promise<RelayClaimResult>;
691
698
  /**
@@ -990,12 +997,9 @@ export interface SellStartRequest {
990
997
  /** The verified `quotes.firmRelay` answer for the bid side. */
991
998
  readonly offer: FirmRelayAnswer;
992
999
  /**
993
- * Optional legacy single sender stored for a no-ETH claim. The ordered list passed to `claimViaRelay` is the
994
- * authority; this scalar is only a one-element fallback for callers written before the list existed. A sender
995
- * naming the deal's maker or its quote-key owner is refused.
1000
+ * Optional ordered senders stored for a no-ETH claim. An explicit list replaces the relay-published sender;
1001
+ * the published sender is used only when no list is passed. The old scalar is retired.
996
1002
  */
997
- readonly claimSender?: string;
998
- /** The ordered senders stored for a later `claimViaRelay`; the relay's published sender is prepended. */
999
1003
  readonly claimSenders?: readonly string[];
1000
1004
  /** The twelve-word key; required only when no key is stored yet. */
1001
1005
  readonly recoveryKey?: string | { readonly mnemonic: string };
@@ -1019,8 +1023,6 @@ export interface SellStart {
1019
1023
  readonly xmrAmount: string;
1020
1024
  readonly claimTip: string | null;
1021
1025
  readonly orderQuote: Readonly<Record<string, unknown>> | null;
1022
- /** The legacy single sender stored by `startSell`, or null when the client supplies the list at claim time. */
1023
- readonly claimSender: string | null;
1024
1026
  /** The ordered senders stored by `startSell`; empty when the client supplies the list at claim time. */
1025
1027
  readonly claimSenders: readonly string[];
1026
1028
  readonly readyWindow: ReadyWindow | null;
@@ -1039,16 +1041,15 @@ export interface SellClaimRequest {
1039
1041
  /**
1040
1042
  * THE NO-WALLET CLAIM'S INPUTS. `id` names the sell record made by `startSell`; the escrow, half and signed tip
1041
1043
  * come from it. `claimSenders` is the client's ordered list: the relay's own sender first, then the listed makers.
1042
- * Each entry is checked for the deal's maker and its quote-key owner. The old scalar `claimSender` is accepted as a
1043
- * one-element fallback for callers written before the list. `relayUrl` is optional and may only repeat the origin
1044
- * stored with the record - a foreign origin is refused.
1044
+ * Each entry is checked for the deal's maker and its quote-key owner. The old scalar `claimSender` is retired and
1045
+ * refused by name. `relayUrl` is optional and may only repeat the origin stored with the record - a foreign origin
1046
+ * is refused. A second call is allowed after a refusal or an unknown answer: the journal is diagnostic and the
1047
+ * sender list is walked from the beginning once any previous slot ends.
1045
1048
  */
1046
1049
  export interface RelayClaimRequest {
1047
1050
  readonly id: string;
1048
1051
  /** Ordered senders. Tried one at a time; the first that lands a claim on chain wins. */
1049
1052
  readonly claimSenders?: readonly string[];
1050
- /** One-element fallback for a caller written before `claimSenders`; may never name the deal's maker. */
1051
- readonly claimSender?: string;
1052
1053
  readonly relayUrl?: string;
1053
1054
  /** One sender's slot; clamped to 15-30 s. Default 20 s. */
1054
1055
  readonly slotMs?: number;
@@ -1074,7 +1075,6 @@ export interface RelayClaimed {
1074
1075
  readonly id: string;
1075
1076
  /** The sender whose slot found the claim; null when the escrow already read claimed before the first POST. */
1076
1077
  readonly provider: string | null;
1077
- readonly claimSender: string | null;
1078
1078
  readonly escrow: string;
1079
1079
  readonly relayUrl: string;
1080
1080
  /** The txid when an answer carried one; `null` when the claim was found on chain without it. */
@@ -1090,7 +1090,6 @@ export interface RelayClaimYourself {
1090
1090
  readonly reason: "senders-exhausted";
1091
1091
  readonly id: string;
1092
1092
  readonly provider: null;
1093
- readonly claimSender: null;
1094
1093
  readonly escrow: string;
1095
1094
  readonly relayUrl: string;
1096
1095
  readonly txid: null;
@@ -1102,15 +1101,15 @@ export interface RelayClaimYourself {
1102
1101
  }
1103
1102
 
1104
1103
  /**
1105
- * The half was not handed to any sender because the escrow's own claim window is not open. The caller must not
1106
- * retry the relay list: the state, not the sender, is the answer.
1104
+ * The half was not handed to any sender because the escrow's own claim window is not open. For a closed,
1105
+ * not-ready, margin or unfunded state the state is the answer; `unreadable` can be retried once the chain clock
1106
+ * and escrow state are readable again.
1107
1107
  */
1108
1108
  export interface RelayClaimWindow {
1109
1109
  readonly state: "claim-window";
1110
1110
  readonly reason: "not-ready" | "window-closed" | "settlement-margin" | "unreadable" | "not-funded" | "escrow-refused" | "escrow-refunded";
1111
1111
  readonly id: string;
1112
1112
  readonly provider: null;
1113
- readonly claimSender: null;
1114
1113
  readonly escrow: string;
1115
1114
  readonly relayUrl: string;
1116
1115
  readonly txid: null;
@@ -1153,7 +1152,8 @@ export interface SellWatchResult {
1153
1152
  export interface SwapWatchRequest {
1154
1153
  /** The local swap record identifier. */
1155
1154
  readonly id: string;
1156
- /** The escrow address for the ready mark (mandatory when `expect` and `wallet` are passed and the record has none). */
1155
+ /** The escrow address for the ready mark. If the record already names an escrow, a different value is refused as
1156
+ * `bad-input` / `record-mismatch` rather than watched under the same id. */
1157
1157
  readonly escrow?: string;
1158
1158
  /** How often to ask the state. Default - `config.limits.watchPollMs`. */
1159
1159
  readonly pollMs?: number;
@@ -1168,7 +1168,8 @@ export interface SwapWatchRequest {
1168
1168
  /**
1169
1169
  * CLIENT-SIDE ARRIVAL CHECK (issue #85). With this the CLIENT decides: it reads the chain itself and `ready`
1170
1170
  * opens only when two operators agree. The backend's `seen` is then only a notification and does not open the
1171
- * button. `verify` is mandatory: without it the watch refuses with `bad-input`.
1171
+ * button. `verify` is mandatory: without it the watch refuses with `bad-input`. `verify.address` must match the
1172
+ * record's `moneroAddress` when the record has one; a different address is `bad-input` / `record-mismatch`.
1172
1173
  */
1173
1174
  readonly verify?: Omit<XmrArrivalRequest, "minConfirmations">;
1174
1175
  /** The confirmation target before `ready`. Default - `config.limits.xmrConfirmations` (10). */