@ninsei-labs/sdk 0.59.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 (62) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +40 -8
  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/deployments.generated.js +1 -17
  15. package/engine/core/finality.js +0 -4
  16. package/engine/core/format.js +0 -4
  17. package/engine/core/preSignGuards.js +0 -4
  18. package/engine/core/rfqSource.js +0 -3
  19. package/engine/core/sellWindow.js +0 -4
  20. package/engine/core/store.js +0 -4
  21. package/engine/core/swap.js +0 -4
  22. package/engine/evm/amounts.js +0 -4
  23. package/engine/evm/asyncRoute.js +0 -4
  24. package/engine/evm/auth.js +0 -4
  25. package/engine/evm/claimGas.js +2 -6
  26. package/engine/evm/dex.js +0 -4
  27. package/engine/evm/escrow.js +0 -4
  28. package/engine/evm/factory.js +0 -4
  29. package/engine/evm/fees.js +0 -4
  30. package/engine/evm/funding.js +2 -5
  31. package/engine/evm/gasReserve.js +0 -4
  32. package/engine/evm/index.js +5 -9
  33. package/engine/evm/injected.js +0 -4
  34. package/engine/evm/permit.js +0 -4
  35. package/engine/evm/prices.js +0 -4
  36. package/engine/evm/session.js +0 -4
  37. package/engine/mock/chain.js +0 -4
  38. package/engine/monero/address.js +0 -3
  39. package/engine/monero/halvesSweep.js +0 -4
  40. package/engine/monero/node.js +0 -4
  41. package/engine/monero/swapKeys.js +0 -4
  42. package/engine/monero/unlock.js +2 -6
  43. package/engine/monero/wallet.js +0 -3
  44. package/engine/recovery/recoveryFile.js +0 -4
  45. package/engine/recovery/restore.js +0 -4
  46. package/engine/sdk/bridge.js +3 -7
  47. package/engine/ui/dom.js +0 -4
  48. package/engine/ui/walletModal.js +0 -4
  49. package/index.d.ts +89 -36
  50. package/package.json +3 -2
  51. package/src/engine.mjs +17 -26
  52. package/src/index.mjs +1 -1
  53. package/src/predictEscrow.mjs +25 -0
  54. package/src/public/recovery.d.ts +1 -1
  55. package/src/quotes.mjs +2 -5
  56. package/src/relayClaim.mjs +17 -3
  57. package/src/relayFirmClient.mjs +18 -0
  58. package/src/swap-flow.mjs +7 -10
  59. package/src/swaps.mjs +349 -76
  60. package/src/sweep.mjs +9 -2
  61. package/src/version.mjs +1 -1
  62. package/src/xmr-arrival.mjs +61 -41
package/CHANGELOG.md CHANGED
@@ -1,3 +1,35 @@
1
+ ## 0.61.0 — 2026-11-14
2
+
3
+ - **BREAKING:** the scalar `claimSender` is retired from `SellStartRequest`, `RelayClaimRequest` and `RelayClaimed`. `claimSenders` is the only sender source; an explicit list replaces the relay-published sender and is never prepended. Pre-list records are migrated on their first claim.
4
+ - A claim window is read from the escrow one last time before it is reported closed: a claim, refund or defund that landed after the last sender slot wins over the closing state. An unreadable final read still returns the named window state.
5
+ - `swaps.watch` refuses `request.escrow` and `verify.address` that redirect the stored record (`bad-input` / `record-mismatch`) before any chain read.
6
+ - A first unread escrow is `claim-window` / `unreadable` when nothing has been sent; after an earlier attempt it remains `claim-unknown` with `escrow-unread`.
7
+ - Relay-level answers `rate_limited`, `bad_request`, `unsupported_version` and `no_quote` are `claim-unknown` (`relay-<code>`), not a sender refusal; the sender keeps its slot.
8
+ - Funding compares `commitHalfLocker`, `edPointLocker` and `edViewPointLocker` with the signed quote before sending, so a locker-half mismatch is refused before the factory.
9
+ - `engine/**` is now the SDK's own source; the generated-mirror headers and the `www/js` source-of-truth comments are gone.
10
+ - The claim guards have a mutation suite in `tools/check-claim-teeth.mjs`, run in CI after `check:guard-teeth`.
11
+ - CI uses Rust 1.100.0 and pnpm 12.21.0; Cargo resolves registry dependencies with a three-day cooldown.
12
+ - The supported version line is `0.61.x`; `package.json` and the baked-in `SDK_VERSION` move to 0.61.0.
13
+
14
+ ## 0.60.1 — 2026-11-13
15
+
16
+ - `claimViaRelay` treats `claimAttempts` as a diagnostic journal, not as a list of senders to skip. A repeated call starts from the first sender again; a previous `sending` or `unknown` entry is waited out for its slot and retried. A legacy future timestamp is capped at one slot, so an old device clock cannot stall recovery. A temporary relay refusal, a process restart or a closed tab no longer removes the seller's no-wallet path.
17
+ - The claim window and `secondsLeft` use the escrow chain's block timestamp (`evmBlock` or the wallet's block provider). A device clock skew can no longer post the half after `t1`, and a missing chain clock returns `claim-window` / `unreadable` instead of falling back to `Date.now()`.
18
+ - `sellWatch` does not report `ready` after `t1`; a ready mark that arrives too late is named as `claim-window-closed`.
19
+ - The witness shadow walks every fixed slice to the common target even after finding a perfect candidate, and `witnessQuorum.ok` requires completed operators with no witness-to-witness disagreement.
20
+ - `sweep.restore` keeps the facade's fetch transport through `createNinsei({ fetch })`, while a per-call `fetchImpl` still wins.
21
+ - The supported version line remains `0.60.x`; `package.json` and the baked-in `SDK_VERSION` move to `0.60.1`.
22
+
23
+ ## 0.60.0 — 2026-11-13
24
+
25
+ - `swaps.watch` keeps the joint Monero address apart from the EVM escrow: the result carries the address the client checked, and the automatic ready mark always signs against the escrow. A typed watch no longer returns the escrow as its `address`; the legacy untyped `request.address` is not read. `verify` remains mandatory, so a watch without the client's own check is refused by name instead of falling back to a retired service answer.
26
+ - The claim window is read from the escrow before a sender is tried: a funded escrow that is already refunded reports `state: "claim-window"` with `reason: "escrow-refunded"`, not `claim-yourself`.
27
+ - `claimViaRelay` writes each sender to the record before its POST. A reload skips a refused or unconfirmed sender, while a `sending` or `unknown` attempt stops with `claim-unknown` and `why: "previous-sender-unknown"` so the half is not sent twice. `timeoutMs` is capped at 120 s, `slotMs` is clamped to 15-30 s, and `pollMs` is at least 250 ms and no longer than the slot.
28
+ - `startSell` stores the client's ordered `claimSenders` once, including the relay-published `claimSender` when present; a later `claimViaRelay({ id })` uses the stored list without repeating it.
29
+ - `sweep.restore` inherits the instance `fetch` transport, and a per-call `fetchImpl` still wins. A retry whose factory prediction cannot be read is `quote-factory-unchecked` with `why: "predict-failed"`, not a missing escrow.
30
+ - The recovery salt is canonicalised before the pending lookup, the arrival shadow raises its target to a witness tip served during the walk, and a failed witness walk is `witness:not-completed` rather than agreement.
31
+ - The supported version line is `0.60.x`; the package version and the baked-in `SDK_VERSION` move together.
32
+
1
33
  ## 0.59.0 — 2026-11-11
2
34
 
3
35
  - `FACTORY_HISTORY` is generated from the reviewed deployment manifests and `deployments/history/<vm>/<network>.json`. It lists the current factory as `live` and older factories as `retired`, each with its deployment block and release tag, so a recovery page can find old orders without a second hand-written address table.
package/README.md CHANGED
@@ -22,7 +22,7 @@ Report suspected vulnerabilities through GitHub's private **Report a vulnerabili
22
22
  The supported versions, scope, response targets, safe-harbor rules and disclosure process are in
23
23
  [`SECURITY.md`](SECURITY.md).
24
24
 
25
- ## State (0.59.0)
25
+ ## State (0.61.0)
26
26
 
27
27
  | Surface | State |
28
28
  |---|---|
@@ -34,7 +34,7 @@ The supported versions, scope, response targets, safe-harbor rules and disclosur
34
34
  | `quotes.firmRelay` | works: a firm quote through a relay, built from one recovery key; the node half is DLEQ-checked |
35
35
  | `swaps.list` / `swaps.get` | read state from storage (and after a page reload) |
36
36
  | `swaps.start` | holds the order: guards → recovery file and the person's confirmation → order → locking funds → **watching the Monero address**; no backend is required; returns the named state `step: "xmr-incoming"` |
37
- | `swaps.watch` | waits for XMR at the joint address with the CLIENT's own check: `verify` carries the joint address, view secret, spend public key and witness nodes. Arrived — returns the fact (amount, confirmations, txid); did not wait — a refusal with `xmr-timeout`; funds barred by `unlock_time` — `xmr-locked`; the maker DECLINED — `SwapDeclinedWatch` (`declined: true`, `terminal: "declined"`), every action off; with expectations and a wallet, places the ready mark after the arrival |
37
+ | `swaps.watch` | waits for XMR at the joint address with the CLIENT's own check: `verify` carries the joint address, view secret, spend public key and witness nodes, and is mandatory — without it the watch refuses with `bad-input`. Arrived — returns the fact (amount, confirmations, txid) and the joint address; did not wait — a refusal with `xmr-timeout`; funds barred by `unlock_time` — `xmr-locked`; the maker DECLINED — `SwapDeclinedWatch` (`declined: true`, `terminal: "declined"`), every action off; with expectations and a wallet, places the ready mark after the arrival against the escrow, never against the Monero address |
38
38
  | `swaps.verifyArrivalShadow` | the staging path for witness-v1: runs the exact walk and the fixed-slice walk side by side, without changing ready or refund. The slice request carries only the grid and slice; a node must name `protocol: "witness-v1"` |
39
39
  | `swaps.startSell` / `swaps.sellClaim` / `swaps.claimViaRelay` | a sell is recorded from the verified relay offer; `sellClaim` claims from the claimer's own wallet, `claimViaRelay` claims with no wallet through the client's ordered sender list, paid by the signed `claimTip` |
40
40
  | `wallet.balances` | works: the native coin and tokens, in minimal units |
@@ -210,22 +210,37 @@ signed by the client:
210
210
 
211
211
  ```js
212
212
  const sell = await sdk.swaps.startSell({ offer });
213
+ const relaySender = offer.claimSender; // GET /v1/relay; the relay origin that answered
213
214
  const claimed = await sdk.swaps.claimViaRelay({ id: sell.id,
214
- claimSenders: [relaySender, ...otherListedMakers] });
215
+ claimSenders: [...(relaySender ? [relaySender] : []), ...otherListedMakers] });
215
216
  if (claimed.state === "claimed") {
216
217
  claimed.txid; // the claim transaction, or null when the escrow itself showed claimed
217
218
  claimed.from; // the sender node's claim sender
218
219
  claimed.tipWei; // the signed tip paid out of the claim
220
+ } else if (claimed.state === "claim-window") {
221
+ claimed.reason; // not-ready | window-closed | settlement-margin | not-funded | unreadable | escrow-refused | escrow-refunded
219
222
  } else {
220
223
  claimed.secondsLeft; // no sender landed it: claim yourself before t1
221
224
  }
222
225
  ```
223
226
 
224
- `claimSenders` is the client's ordered list: the relay's own sender first, then other listed makers. The SDK tries
225
- one sender at a time for a 15-30 s slot. A refusal moves on at once; a txid is not success - the SDK reads the
226
- escrow until it says `claimed` or the slot ends. The deal's maker and its quote-key owner are refused before the
227
- half leaves the client. When the list is exhausted the result is `state: "claim-yourself"` with `t1` and
228
- `secondsLeft`. The old scalar `claimSender` remains a one-element fallback for callers written before the list.
227
+ `claimSenders` is the client's ordered list: the relay's own sender first, then other listed makers. `startSell`
228
+ stores a list only when the caller passes `claimSenders`; otherwise the offer's published `claimSender` becomes a
229
+ one-element list. An explicit list replaces that published sender; it is never prepended. `claimViaRelay({ id })`
230
+ uses the stored list, while a request `claimSenders` replaces it. The old scalar `claimSender` is retired and
231
+ refused by name; the claim result names the sender that landed it as `provider`. The SDK tries one sender at a
232
+ time for a 15-30 s slot. A refusal moves on at once; a txid is not success - the SDK reads the escrow until it
233
+ says `claimed` or the slot ends. The deal's maker and its quote-key owner are refused before the half leaves the
234
+ client. When the list is exhausted the result is `state: "claim-yourself"` with `t1` and `secondsLeft`.
235
+
236
+ The claim window is the escrow's, not the relay's. Before every sender the SDK reads `ready`, `readyBy` and `t1`
237
+ from the chain. Without the ready mark before `readyBy`, at or after `t1`, or inside the 120 s settlement margin
238
+ (plus the sender's slot and time for the seller's own claim), it returns `state: "claim-window"` with a named
239
+ `reason` and posts nothing. An escrow read that fails before any send is `claim-window` / `unreadable`; if an earlier
240
+ attempt may already have sent the half, it is `claim-unknown` with `why: "escrow-unread"`. It is never reported as
241
+ `claim-yourself`. A relay answer such as `claim-not-ready` or `claim-window-closed` stops the list instead of
242
+ passing the half to the next sender. Relay-level answers (`rate_limited`, `bad_request`, `unsupported_version`,
243
+ `no_quote`) are `claim-unknown`, not a sender refusal; the sender keeps its slot and the list continues.
229
244
 
230
245
  `claimViaRelay` reads the sell record made by `startSell` and requires a positive `claimTip`, the escrow and the
231
246
  half. It posts to the relay origin stored with the record; an optional `relayUrl` may repeat that origin but a
@@ -233,6 +248,23 @@ different one is refused. A node refusal keeps its code under `quote-refused.par
233
248
  without a real transaction hash is `claim-unknown`: the claim may have been sent, so the SDK reads the escrow and
234
249
  moves on only after the slot. Only an escrow that reads `claimed` is success.
235
250
 
251
+ Each sender is written to the record before its POST. The log is diagnostic, not a skip list: a later call starts
252
+ at the first sender again. A previous `sending` or `unknown` entry is waited out for its slot and then retried; a
253
+ `refused` or `unconfirmed` entry is retried immediately. This is what makes a temporary relay failure, a restart or
254
+ a closed tab recoverable. A sender's slot starts when it is entered, not when its POST returns; `pollMs` has a
255
+ 250 ms floor and `timeoutMs` a 120 s ceiling. The relay gate also reserves the settlement margin, so `sellWatch` can
256
+ still report its own-wallet `claim-open` while `claimViaRelay` has already stopped. A refunded escrow is
257
+ `claim-window` with `reason: "escrow-refunded"`, not a request to claim; recovery is the next step.
258
+
259
+ `claimAttempts` is append-only and the SDK does not prune it: a long-lived record can grow with every retry. The
260
+ journal is diagnostic, not a spendable state. A host may trim older entries, but it must keep the latest
261
+ `sending` or `unknown` entry: that slot is waited out before the sender is tried again. Do not use the journal as
262
+ proof that a sender is finished.
263
+
264
+ The claim window uses the escrow's chain time, read with `evmBlock` (or the wallet's block provider), not the
265
+ device clock. If neither clock is available, the client refuses with `claim-window` / `unreadable` before the half
266
+ leaves; it does not fall back to `Date.now()`. `secondsLeft` is derived from that same chain time.
267
+
236
268
  `actions.claim` is unchanged: it still sends only from the claimer's own wallet, because the half is revealed by
237
269
  whoever sends the claim.
238
270
 
@@ -3,7 +3,7 @@
3
3
  "note": "Pinned browser bundles. A change to one of these files must be accompanied by a matching SHA-256 here and a rebuild of the page's asset registry.",
4
4
  "bundles": {
5
5
  "sdk/sdk-browser.js": {
6
- "sha256": "563587be187b41651725d0192234b0341ad6d183f23c7e3aac92487360f44a6e",
6
+ "sha256": "b48b18f7a9fe6d3ea28008cba34f28f815697e302279c3274cea96af5696d75c",
7
7
  "source": "sdk/src (facade, adapters, recovery)"
8
8
  }
9
9
  }