@ninsei-labs/sdk 0.60.0 → 0.62.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 (96) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/README.md +81 -18
  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 +6 -10
  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 +17 -42
  14. package/engine/core/finality.js +0 -4
  15. package/engine/core/format.js +1 -5
  16. package/engine/core/preSignGuards.js +0 -4
  17. package/engine/core/rfqSource.js +0 -3
  18. package/engine/core/sellWindow.js +1 -5
  19. package/engine/core/store.js +11 -7
  20. package/engine/core/swap.js +3 -7
  21. package/engine/evm/amounts.js +2 -6
  22. package/engine/evm/asyncRoute.js +3 -7
  23. package/engine/evm/auth.js +0 -4
  24. package/engine/evm/claimGas.js +2 -6
  25. package/engine/evm/dex.js +1 -5
  26. package/engine/evm/escrow.js +0 -4
  27. package/engine/evm/factory.js +1 -5
  28. package/engine/evm/fees.js +62 -4
  29. package/engine/evm/funding.js +73 -71
  30. package/engine/evm/gasReserve.js +10 -4
  31. package/engine/evm/index.js +7 -11
  32. package/engine/evm/injected.js +0 -4
  33. package/engine/evm/permit.js +0 -4
  34. package/engine/evm/prices.js +3 -4
  35. package/engine/evm/session.js +1 -5
  36. package/engine/mock/chain.js +0 -4
  37. package/engine/monero/address.js +4 -5
  38. package/engine/monero/arrivalRead.js +15 -2
  39. package/engine/monero/halvesSweep.js +0 -4
  40. package/engine/monero/keyImage.js +146 -0
  41. package/engine/monero/keys.js +1 -0
  42. package/engine/monero/mnemonic.js +2 -1
  43. package/engine/monero/node.js +1 -4
  44. package/engine/monero/scan.js +12 -2
  45. package/engine/monero/swapKeys.js +0 -4
  46. package/engine/monero/unlock.js +2 -6
  47. package/engine/monero/wallet.js +0 -3
  48. package/engine/recovery/recoveryFile.js +31 -89
  49. package/engine/recovery/restore.js +0 -4
  50. package/engine/sdk/bridge.js +24 -58
  51. package/engine/ui/dom.js +0 -4
  52. package/engine/ui/walletModal.js +0 -4
  53. package/index.d.ts +436 -42
  54. package/package.json +22 -3
  55. package/src/actions.mjs +72 -6
  56. package/src/addressGuard.mjs +16 -0
  57. package/src/codes.mjs +26 -9
  58. package/src/config.mjs +56 -3
  59. package/src/decline.mjs +23 -74
  60. package/src/engine.mjs +17 -26
  61. package/src/firmRequest.mjs +80 -0
  62. package/src/index.mjs +17 -28
  63. package/src/legs/cow.mjs +2 -2
  64. package/src/legs/evm.mjs +20 -12
  65. package/src/legs/kyber-spec.mjs +2 -2
  66. package/src/legs/kyber.mjs +1 -1
  67. package/src/legs/shape.mjs +1 -1
  68. package/src/legs/uniswaprelay.mjs +16 -4
  69. package/src/legs/uniswapx.mjs +29 -7
  70. package/src/levelsWalkSpec.mjs +1 -1
  71. package/src/lock.mjs +18 -37
  72. package/src/provider/envFile.mjs +3 -3
  73. package/src/provider/sign.mjs +3 -3
  74. package/src/public/evm.d.ts +84 -0
  75. package/src/public/evm.mjs +20 -0
  76. package/src/public/order.mjs +1 -1
  77. package/src/public/provider.mjs +1 -1
  78. package/src/public/recovery.d.ts +4 -3
  79. package/src/public/recovery.mjs +1 -1
  80. package/src/public/xmr.d.ts +2 -2
  81. package/src/quoteEip712Spec.mjs +4 -4
  82. package/src/quotes.mjs +52 -11
  83. package/src/recovery-key.mjs +7 -3
  84. package/src/relayClaim.mjs +17 -3
  85. package/src/relayFirmClient.mjs +4 -0
  86. package/src/relayQuote.mjs +1 -0
  87. package/src/sim.mjs +1 -1
  88. package/src/swap-flow.mjs +28 -41
  89. package/src/swaps.mjs +217 -123
  90. package/src/sweep-inputs.mjs +61 -0
  91. package/src/sweep-reconcile.mjs +71 -0
  92. package/src/sweep-restore.mjs +38 -9
  93. package/src/sweep.mjs +164 -10
  94. package/src/version.mjs +1 -1
  95. package/src/wallet.mjs +1 -1
  96. package/src/xmr-arrival.mjs +1053 -57
@@ -32,6 +32,7 @@ function toBytesLE(value, width = SCALAR_BYTES) {
32
32
 
33
33
  function reduce(bytes) {
34
34
  if (bytes.length > 64) throw new Error("scalar is longer than 64 bytes");
35
+ // sc_reduce32 reads the zero-padded input as little-endian before reducing modulo l.
35
36
  const padded = new Uint8Array(64);
36
37
  padded.set(bytes);
37
38
  return toBytesLE(toBigIntLE(padded) % ORDER);
@@ -34,7 +34,7 @@ function wordsToChunk(one, two, three) {
34
34
  const b = WORD_INDEX.get(two);
35
35
  const c = WORD_INDEX.get(three);
36
36
  if (a === undefined || b === undefined || c === undefined) throw new Error("invalid mnemonic word");
37
- // The word order encodes a value in a mixed radix; the inverse is in chunkToWords.
37
+ // Three words encode one little-endian uint32. Both directions use the same base-N offsets.
38
38
  return a + n * (((b - a) % n + n) % n) + n * n * (((c - b) % n + n) % n);
39
39
  }
40
40
 
@@ -46,6 +46,7 @@ function chunkToWords(value) {
46
46
  return [WORDLIST[one], WORDLIST[two], WORDLIST[three]];
47
47
  }
48
48
 
49
+ // The checksum covers the three-letter prefixes of the 24 payload words. The checksum word is not included.
49
50
  function checksumWord(words) {
50
51
  const prefix = words.map((word) => word.slice(0, PREFIX)).join("");
51
52
  return words[crc32(new TextEncoder().encode(prefix)) % words.length];
@@ -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
@@ -79,6 +75,7 @@ export async function getInfo({ force = false } = {}) {
79
75
 
80
76
  function normalize(info) {
81
77
  return {
78
+ // monerod get_info.height is the next block height (top + 1), not the latest mined block.
82
79
  height: info.height,
83
80
  nettype: info.nettype || (info.mainnet ? "mainnet" : info.stagenet ? "stagenet" : "testnet"),
84
81
  offline: !!info.offline,
@@ -138,8 +138,10 @@ export function watchedAddressVerdict({ address, viewSecret, spendPub } = {}) {
138
138
  return { ok: false, code: "bad-input", why: "not-a-monero-address", field: "address" };
139
139
  }
140
140
  if (!keys.network) return { ok: false, code: "bad-input", why: "not-a-primary-address", field: "address" };
141
+ // ARRIVAL DOES NOT NEED THE PRIVATE SPEND KEY. The public spend key is in the address, so a caller that has only
142
+ // the address and the view secret still binds the watched identity; a supplied key is checked against it.
141
143
  const wantedSpend = String(spendPub === undefined || spendPub === null ? "" : spendPub).replace(/^0x/, "").toLowerCase();
142
- if (!wantedSpend || wantedSpend !== keys.spendPub.toLowerCase()) {
144
+ if (wantedSpend && wantedSpend !== keys.spendPub.toLowerCase()) {
143
145
  return { ok: false, code: "xmr-address-mismatch", field: "spendPub" };
144
146
  }
145
147
  const form = viewKeyFormForAddress(viewSecret, keys.viewPub);
@@ -483,7 +485,15 @@ function bindWatched(watched) {
483
485
  const bound = [];
484
486
  for (const entry of watched) {
485
487
  const verdict = watchedAddressVerdict(entry);
486
- if (verdict.ok) bound.push({ entry, bound: verdict });
488
+ // AN INVALID IDENTITY IS NOT AN EMPTY WATCH. Skipping it made scanRange return a complete zero row for an
489
+ // address whose key did not belong to it; the caller could not tell that from "no money".
490
+ if (!verdict.ok) {
491
+ const error = new Error("watched identity is invalid");
492
+ error.code = verdict.code || "bad-input";
493
+ error.params = verdict;
494
+ throw error;
495
+ }
496
+ bound.push({ entry, bound: verdict });
487
497
  }
488
498
  return bound;
489
499
  }
@@ -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,70 +1,31 @@
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
- // The deal recovery file: real cryptography in the browser (WebCrypto).
1
+ // The deal recovery file: WebCrypto AES-GCM, not a stub.
6
2
  //
7
- // Litepaper §5: without a saved recovery file a deal is not funded; if the tab is lost, this file is the only way
8
- // to claim the XMR or refund the ETH (including through a standalone client without the site). So it is real
9
- // AES-GCM, not a stub: the file can be decrypted only with the password the user knows.
3
+ // The file is the only way to claim the XMR or refund the ETH after the tab is lost. It decrypts only with the
4
+ // password the user knows.
10
5
  //
11
6
  // File format (Ninsei-swap-<id>.json.enc):
12
7
  // { v:2, alg:"AES-GCM-256/PBKDF2-SHA256", iter, salt, iv, ciphertext, meta:{id,side,createdAt} }
13
- // Inside ciphertext is the payload (see buildPayload), versioned separately: the envelope version (v) and the
14
- // payload version (version) change independently - encryption and deal content are different things.
15
- //
16
- // WHAT IS IN THE PAYLOAD, AND WHY EXACTLY THIS
17
- // v3: MY HALF of the spend key and MY HALF of the view key (spendHalf, viewHalf) plus the counterparty's PUBLIC
18
- // points (otherSpendPoint, otherViewPoint). No full spend key exists for ANYONE: the address is a sum of halves,
19
- // and only the holder of both can spend. The second half is given by the chain - hence the escrow address is in
20
- // the file too: the sweep reads the revealed half from it. The counterparty's points are public (they are in the
21
- // address and the order anyway), but without them the address cannot be assembled from the halves.
22
- // v2: the mnemonic is the single source of keys: both the spend key and the view key derive from it. Keys are NOT
23
- // duplicated in the payload: a copy of the secret in the file is one more way to lose it and one more reason for
24
- // the fields to drift (the file used to carry both seedHex and the two private keys).
25
- // publicSpendKey /
26
- // publicViewKey /
27
- // address - for checking: if the mnemonic derives another address, the file is corrupt or substituted, and a
28
- // wallet must not be restored from it.
29
- // restoreHeight - the height to start the scan from. Without it the wallet scans Monero history from zero,
30
- // which is tens of hours (measured ~35 blocks/s). The deal's creation height is a correct floor: the XMR lock
31
- // cannot happen earlier.
8
+ // The envelope version (v) and the payload version (version) change independently.
32
9
  //
33
- // WHAT IS NOT IN THE FILE: the spend key in the clear (only inside the ciphertext), a card number, a withdrawal
34
- // address, and anything not needed to complete or roll back the deal.
10
+ // Payload:
11
+ // v3: my spend half and my view half, plus the counterparty's public points. The escrow address is here too, because
12
+ // the sweep reads the revealed half from it.
13
+ // v2: the mnemonic is the single source of keys. The payload also carries the public spend key, the public view key,
14
+ // the address for checking and the scan start height. Without the height the wallet scans from zero.
35
15
  //
36
- // THERE IS NO QUOTE KIND IN THE PAYLOAD, and the payload key set is not checked: a file issued earlier with an
37
- // extra kind key is still read (the extra key just goes unread) and new files are issued without it. The format
38
- // does not change: PAYLOAD_VERSION stays 3 - the quote kind never had to do with the file version.
16
+ // The file does not carry the spend key in clear, a card number or a withdrawal address.
17
+ // A file with an extra kind key is still read. New files do not carry that key.
39
18
 
40
- // THE ENCRYPTION PARAMETERS ARE NAMED EXPLICITLY AND ARE NOT TAKEN FROM WEB-CRYPTO DEFAULTS.
41
- // The tag length and the key length are part of the FORMAT, not an implementation detail: a file issued today must
42
- // be readable years later, so both numbers stand in every call (encrypt/decrypt/deriveKey), live in frozen objects
43
- // and were confirmed by MEASUREMENT: the tag length (ciphertext minus plaintext = 16 bytes) and the derived key
44
- // length (256 bits - proven by decrypting with a key derived separately as 256 bits). The PBKDF2 iteration count
45
- // is also part of the format, but it is DELIBERATELY changeable: it grows with time, and old files are then read
46
- // by their own count (see ITER_MIN below).
47
- //
19
+ // The encryption parameters are explicit, not WebCrypto defaults. The tag length, key length and iteration count are
20
+ // part of the format. The iteration count can grow, and old files are read with their own count (see ITER_MIN).
48
21
  //
49
- // THE ITERATION COUNT: 600,000 - OWASP's recommendation for PBKDF2-HMAC-SHA256, i.e. when FIPS-140 requires
50
- // a "work factor of 600,000 or more" with an internal HMAC-SHA-256 (the numbers come from GPU measurements on an
51
- // RTX 4000, as of December 2022).
52
- // WHY PBKDF2 AND NOT Argon2id/scrypt, WHICH OWASP RANKS HIGHER: a browser offers only what WebCrypto gives, and
53
- // among password-hashing it has ONE - PBKDF2; Argon2id and scrypt are not in the standard. There is nothing to
54
- // choose from, so at least the number correct for PBKDF2 matters.
55
- // WHY 210,000 WAS WRONG: that number is in the OWASP table for PBKDF2-HMAC-SHA512 (220,000), while we use
56
- // HMAC-SHA256 - the count was three times below the recommendation for our own algorithm.
57
- // WHAT THIS DOES NOT GIVE, SO AS NOT TO BE MISLED: iterations raise the price of ONE guess (measured on the
58
- // development machine: 210k - 109 ms, 600k - 283 ms; noticeably more on a weak device in a browser) but do not
59
- // save a weak password: an offline brute force is bounded by the password ENTROPY, not by the count. The 12-char
60
- // minimum remains the weak spot.
22
+ // PBKDF2 is the only password KDF in WebCrypto. Argon2id and scrypt are not available. The count is 600,000 for
23
+ // PBKDF2-HMAC-SHA256. A weak password remains the weak point; iterations raise the cost of one guess.
61
24
  const ITER = 600_000;
62
- // A FLOOR FOR FOREIGN FILES. The iteration count comes FROM THE FILE (otherwise it could not be raised without
63
- // losing old files), so a weak value must meet a refusal: a file below the floor is not decrypted.
25
+ // The iteration count comes from the file, so a weak value must be refused.
64
26
  const ITER_MIN = 100_000;
65
27
  const ITER_MAX = 10_000_000;
66
- // The algorithm identifier is ONE string for the whole module: it used to be written twice (write and read), and a
67
- // divergence between the copies would surface only on a live file.
28
+ // One algorithm identifier for writes and reads.
68
29
  const ALG_ID = "AES-GCM-256/PBKDF2-SHA256";
69
30
  const AES = Object.freeze({ name: "AES-GCM", tagLength: 128, keyBits: 256 });
70
31
  const KDF = Object.freeze({ name: "PBKDF2", hash: "SHA-256" });
@@ -102,20 +63,12 @@ function unb64(str) {
102
63
  return Uint8Array.from(atob(str), (c) => c.charCodeAt(0));
103
64
  }
104
65
 
105
- // THE ITERATION COUNT IS A PARAMETER, NOT A CALL CONSTANT. On encryption it is ITER, on reading it is the number
106
- // FROM THE FILE: the format stores it precisely so the count can be raised without losing already issued files.
107
- // Reading used to take the constant and ignore the iter field entirely - so raising the count would have silently
108
- // broken all old files, and the field in the file would have been decoration.
109
- // AAD: THE HEADER IS UNDER AUTHENTICATION, NOT ONLY THE CIPHERTEXT. AES-GCM checks the integrity of what is passed
110
- // to it as additionalData. Without AAD (as in version 1) only the ciphertext was covered, while `meta` - the deal
111
- // id, side, time, terms hash - sits beside it and could be edited without a trace, and the reader would take the
112
- // substituted value. The string is built by both writer and reader FROM THE SAME FIELDS IN THE SAME ORDER: any
113
- // field edit changes the string and decryption is rejected.
114
- // WHY AN ARRAY, NOT AN OBJECT: key order in an object is a JSON implementation detail and an "identical" object
115
- // can yield different text. And why ?? null: a missing field in the array would give undefined, which is another
116
- // value.
117
- // EXPORTED ON PURPOSE: the string is part of the FORMAT, and checks must build it with the same code, not their
118
- // own copy (a copy would diverge from the format exactly where it costs most).
66
+ // The iteration count is a parameter, not a call constant. Encryption uses ITER; reading uses the count from the
67
+ // file. The format stores it so the count can grow without losing old files.
68
+ // AAD: the header is authenticated, not only the ciphertext. Version 1 has no AAD, so a version-1 file must decrypt
69
+ // without it. The string is built by both writer and reader from the same fields in the same order.
70
+ // An array, not an object: object key order is a JSON implementation detail. Missing fields become null.
71
+ // Exported so checks build the same string, not a copy.
119
72
  export function envelopeAad(envelope) {
120
73
  const m = envelope.meta || {};
121
74
  return JSON.stringify([
@@ -135,21 +88,13 @@ async function deriveKey(passphrase, salt, iterations) {
135
88
  );
136
89
  }
137
90
 
138
- // THE HEIGHT TO START THE RECOVERY SCAN FROM. A pure function: it goes nowhere, so it is checked without a node -
139
- // and that matters, because this is exactly where the height used to get lost.
91
+ // The recovery scan start height. This is a pure function, so a test can run it without a node.
140
92
  //
141
- // WHY TWO SOURCES. The height was taken ONLY from the Monero node, and when the node did not answer, null was
142
- // honestly written into the file. Recovery then scanned history from zero (tens of hours), although the exact deal
143
- // height was at hand: the escrow is created by a transaction and its block is in the receipt. The node is someone
144
- // else's service that may be down (a live proxy returned 502), while the deal is our own and already exists.
93
+ // The height has three sources: the escrow birth height from the receipt, the application's stored height and the
94
+ // Monero node height. The node is an external service and can be down. The deal height is ours and already exists.
145
95
  //
146
- // TAKE THE SMALLER AND STEP BACK A BLOCK. The XMR arrival may land a block earlier than the recorded height, and a
147
- // scan that starts below the money finds it; one that starts above never does. Hence Math.min and minus one, but
148
- // never below one.
149
- // THE THIRD SOURCE - THE APPLICATION. Old deal records have no birthHeight field (it appeared later), but the app
150
- // resolved and stored the height when it registered the watch; the page gets it from its server. This is OUR
151
- // source, so it does not depend on whether the Monero node answers now, and it is what saves already issued
152
- // files: their record has no height at all.
96
+ // Use the smallest source and subtract one block. The XMR arrival can land one block before the recorded height. A
97
+ // scan that starts too high never finds the money.
153
98
  export function scanStartHeight({ escrowBirthHeight = null, serverRestoreHeight = null, nodeHeight = null } = {}) {
154
99
  const known = [escrowBirthHeight, serverRestoreHeight, nodeHeight]
155
100
  .map((v) => Number(v))
@@ -158,15 +103,12 @@ export function scanStartHeight({ escrowBirthHeight = null, serverRestoreHeight
158
103
  return Math.max(1, Math.min(...known) - 1);
159
104
  }
160
105
 
161
- // The payload: everything needed to complete or roll back the deal without the site. restoreHeight is passed by
162
- // the caller - scanStartHeight puts it here, and the module does not go to the network itself so it can be tested
163
- // without a node.
106
+ // The payload. `restoreHeight` is passed by the caller; scanStartHeight computes it. This module never reads the
107
+ // network.
164
108
  export function buildPayload({ swap, swapWallet, escrow, receiveAddress, restoreHeight = null }) {
165
109
  return {
166
110
  magic: FILE_MAGIC,
167
- // THE VERSION REFLECTS THE CONTENT, NOT THE MODULE VERSION. It used to hold PAYLOAD_VERSION, so after halves
168
- // appeared a file built from a mnemonic got number 3 - claiming content it did not have, and the check rightly
169
- // rejected it. The number must tell the truth about the content: a halves file is three, a mnemonic file is two.
111
+ // The version reflects the content, not the module version. A halves file is 3. A mnemonic file is 2.
170
112
  version: swapWallet && swapWallet.spendHalf ? 3 : 2,
171
113
  swapId: swap.id,
172
114
  // The order terms hash FROM THE CONTRACT. It is the file's tie to the chain: knowing the terms, one can check
@@ -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,80 +1,46 @@
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
- // THE PAGE-TO-CORE SHIM: THE ONE PLACE WHERE SCREENS KNOW ABOUT THE SDK (sdk/).
6
- //
7
- // WHY IT EXISTS. The swap logic lives in the core (sdk/, the @ninsei-labs/sdk package) while the page should do
8
- // only markup, screen state and texts. Before this shim every screen called the engine itself and the logic
9
- // spread across two places. Now a screen calls the SHIM, and only it knows about the core.
10
- //
11
- //
12
- // WHAT THE SHIM PASSES TO THE CORE - exactly the seams the core asks for from outside and cannot get itself:
13
- // storage - the page's storage: deals and session are read from where the page puts them (core/store.js);
14
- // evmCall - chain reads WITH THE PAGE'S WALLET: the core has no provider of its own and must not;
15
- // wallet - the page wallet adapter (sdk/src/adapters/evm-wallet.mjs): signing happens only in it.
16
- //
17
- // WHAT THE SHIM DOES NOT DO. It computes neither thresholds nor step order nor the escrow address: method names
18
- // and paths are only those that EXIST in the core, and the decisions stay in the core.
19
- //
20
- // ABOUT THE CORE BEING AVAILABLE TO THE PAGE - IT IS NOW BUILT, NOT WAITING FOR A BUILD.
21
- // * sdk/src/primitives.mjs imports @noble/curves and @noble/hashes by BARE package names, so the page is
22
- // served not the sdk/ source but a BUILT BUNDLE (www/assets/vendors/sdk/sdk-browser.js, the same path as the
23
- // atomic-swap crypto bundle). The bundle exposes the WHOLE FACADE:
24
- // createNinsei (config/wallet/quotes/preflight/swaps/actions/order/sweep/recovery/sim) plus the browser
25
- // adapters (evmWallet, localStorageAdapter/memoryAdapter). So starting a swap (swaps.start) and facade
26
- // quotes ARE available to the page - a "facade not served to the page" refusal is no longer expected.
27
- // * The bundle link carries ?v=<hash>, so the edge cache resets itself after a rebuild.
1
+ // PAGE-TO-CORE SHIM.
28
2
  //
3
+ // Screens use the SDK through this file. The shim passes the page storage, the chain read and the wallet adapter.
4
+ // It computes no thresholds, step order or escrow address.
29
5
  //
30
- // THE ORDER ACTIONS HAVE NO FALLBACK PATH ANY MORE, AND THAT IS A CONSEQUENCE OF THE MOVE. The deal engine used
31
- // to sit on the page and, with the bundle unavailable, the order actions ran on it - "the same functions", as it
32
- // was written here. Now the deal engine is a module OF THE PACKAGE (sdk/src/swap-flow.mjs): there is no second
33
- // copy on the page, so no fallback can exist. The bundle did not load (missing file, old cache, network) - that
34
- // is a NAMED refusal with the cause in the console (sdkBundle below), not silence and not a substitution.
6
+ // The SDK is served as a built bundle at assets/vendors/sdk/sdk-browser.js. The version query resets the cache
7
+ // after a rebuild. The bundle exposes createNinsei and the browser adapters.
35
8
  //
9
+ // There is no page-side fallback. If the bundle does not load, sdkBundle returns null and the caller sees a named
10
+ // refusal.
36
11
 
37
12
  import { chainById, DEFAULT_CHAIN, MONERO, allowedProvidersFor, knownFactoryCodesFor, knownImplementationCodesFor } from "../core/config.js";
38
13
  import { storage as pageStorage } from "../core/store.js";
39
14
  import * as evm from "../evm/index.js";
40
- // ORDER TERMS FOR THE CORE ARE ASSEMBLED FROM DATA, NOT FROM RULES: the windows come from the finality policy
41
- // (core/finality.js), the salt from the engine's generator (evm/funding.js). No deadlines or numbers of its own here.
15
+ // Order terms come from data, not rules: the windows come from the finality policy and the salt from the engine's
16
+ // generator. This file has no deadlines or numbers of its own.
42
17
  import { orderWindows } from "../core/finality.js";
43
18
  import { newSecret } from "../evm/funding.js";
44
- // THE ORDER CALLS - ACTION AND READ - COME FROM THE CORE. The deal engine moved into the package, and the shim
45
- // exposes EXACTLY the same names (markReadyOrder/claimOrder/refundOrder/orderStatus/orderDeadlines), so a screen
46
- // changes only the import source, not the call expression - and the guard that fixes the call site sees the old call.
19
+ // Order actions and reads come from the core. The shim exposes the same names, so a screen changes only its import.
47
20
  //
48
- // THE DEAL LIST AND ITS UPKEEP (the #/swaps screen). States come from the CORE: swaps.list - display, swaps.forget -
49
- // dropping a record. The core needs only the page's storage, and the shim adds no rules of its own.
21
+ // The deal list and its upkeep use core state. The core needs only the page storage.
50
22
  //
51
- // WATCHING IS A PAGE MECHANISM, NOT THE CORE'S: the poll tick lives in app.js, so the focus stays in
52
- // core/swap.js and the screen only declares it to the shim.
23
+ // Watching is a page mechanism. The poll tick lives in app.js, and the screen declares it to the shim.
53
24
  import { setLiveFocus, dealSwapIds, serverRestoreHeightFor, STEP_LABELS,
54
25
  confirmReady as engineConfirmReady, refundEth as engineRefundEth, sweepNow as engineSweepNow,
55
26
  getSwap as engineGetSwap, saveSwap as engineSaveSwap } from "../core/swap.js";
56
- // THE FEE RATE AND THE ORDER STATE - CHAIN READS WITH THE PAGE'S WALLET: the reference panel ("how it works")
57
- // and recovery-file parsing take them. The page gets them FROM HERE, not directly from evm/*.
27
+ // Fee rate and order state are chain reads with the page wallet. The page gets them here, not from evm/*.
58
28
  import { cachedFeeRate } from "../evm/fees.js";
59
- // MONERO ADDRESS AND HEIGHT - DELIBERATE PAGE READS (the progress screen): checking the recipient address
60
- // format and the node height for the scan height in the recovery file. The address logic lives in the core
61
- // (swaps.addressNetwork), here a fallback by the same module; the node height is the page node's read.
29
+ // Monero address and height are deliberate page reads. The address logic lives in the core; the node height is the
30
+ // page node's read.
62
31
  import { networkFromShape } from "../monero/address.js";
63
32
  import { height as nodeHeightValue } from "../monero/node.js";
64
33
 
65
- // THE CORE ADDRESS AS A STRING - THE BUILT BUNDLE SHIPPED WITH THE PACKAGE. A relative URL resolves both in the
66
- // published `engine/` tree and in the page that serves this shim from `www/js/sdk/`; ?v=<hash> keeps the cache fresh.
34
+ // The built bundle shipped with the package. A relative URL resolves in the published engine tree and in the page.
35
+ // The version query keeps the cache fresh.
67
36
  const SDK_BUNDLE = new URL("../../assets/vendors/sdk/sdk-browser.js?v=fa7dc71a", import.meta.url).href;
68
37
 
69
- // A NAMED SEAM FOR CHECKS. The asynchronous path is driven against a
70
- // stand-in order book (the demo network has no provider), and the ordinary escrow funding that follows a settled
71
- // swap can be replaced while that runs, because deploying an escrow factory on a throwaway chain is the stand's
72
- // job, not a check's. The replacement is named, set only by a check, and unset by the same function; production
73
- // never calls it, so the real funding path is what ships.
38
+ // A named seam for checks. A check can replace the funding step while it drives a stand-in order book. Production
39
+ // never calls it, so the real funding path ships.
74
40
  let startSwapOverride = null;
75
41
  export function useStartSwap(fn = null) { startSwapOverride = typeof fn === "function" ? fn : null; return Boolean(startSwapOverride); }
76
42
 
77
- // ONE LOAD PER PAGE. A refusal is a state, not a breakdown: it is named in the console and the caller decides.
43
+ // One load per page. A refusal is a state: it is named in the console and the caller decides.
78
44
  let loading = null;
79
45
  export async function sdkBundle() {
80
46
  if (!loading) {
@@ -82,7 +48,7 @@ export async function sdkBundle() {
82
48
  try { return await import(SDK_BUNDLE); }
83
49
  catch (error) {
84
50
  console.warn("[bridge] the built SDK core was not served to the page (" + ((error && error.message) || error) +
85
- "): actions go by the previous engine call; see www/js/sdk/bridge.js");
51
+ "): no page-side fallback; see www/js/sdk/bridge.js");
86
52
  return null;
87
53
  }
88
54
  })();
@@ -408,7 +374,7 @@ export async function sdkSetDestination(id, address) {
408
374
  }
409
375
 
410
376
  // 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.
377
+ // The fallback is the same address module the SDK uses (engine/monero/address.js): there is no second prefix table.
412
378
  export async function sdkAddressNetwork(address) {
413
379
  const ctx = await instanceFor(undefined);
414
380
  if (ctx) return ctx.sdk.swaps.addressNetwork(address);
@@ -422,8 +388,8 @@ export async function sdkAddressNetwork(address) {
422
388
  // the deal digest and the poll tick, reads and polling of the Monero node (the core has no node);
423
389
  // * prices, fees, gas and the form's DEX leg - SHOWCASE: the numbers are read from the chain by engine
424
390
  // 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);
391
+ // * networkFromShape/networkLabel - the Monero address shape and its name: the same format module the SDK
392
+ // uses (there is no second prefix table);
427
393
  // * createSwap/createReverseSwap/activeSwaps - the RECORD of the demo and reverse deal (the record is kept by
428
394
  // the engine; the core exposes its STATE via swaps.list/swaps.progress).
429
395
  // * 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.