@miradexio/client 0.1.0 → 0.1.2

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 (306) hide show
  1. package/README.md +57 -292
  2. package/dist/address/base58.d.ts.map +1 -1
  3. package/dist/address/base58.js +1 -2
  4. package/dist/address/base58.js.map +1 -1
  5. package/dist/address/bech32.d.ts +0 -8
  6. package/dist/address/bech32.d.ts.map +1 -1
  7. package/dist/address/bech32.js +3 -9
  8. package/dist/address/bech32.js.map +1 -1
  9. package/dist/address/evm.d.ts.map +1 -1
  10. package/dist/address/evm.js +1 -2
  11. package/dist/address/evm.js.map +1 -1
  12. package/dist/address/index.d.ts +0 -6
  13. package/dist/address/index.d.ts.map +1 -1
  14. package/dist/address/index.js +6 -9
  15. package/dist/address/index.js.map +1 -1
  16. package/dist/address/monero.d.ts +0 -10
  17. package/dist/address/monero.d.ts.map +1 -1
  18. package/dist/address/monero.js +4 -10
  19. package/dist/address/monero.js.map +1 -1
  20. package/dist/address/polkadot.d.ts +0 -5
  21. package/dist/address/polkadot.d.ts.map +1 -1
  22. package/dist/address/polkadot.js +2 -6
  23. package/dist/address/polkadot.js.map +1 -1
  24. package/dist/address/ton.d.ts +0 -6
  25. package/dist/address/ton.d.ts.map +1 -1
  26. package/dist/address/ton.js +3 -8
  27. package/dist/address/ton.js.map +1 -1
  28. package/dist/api/index.d.ts +0 -19
  29. package/dist/api/index.d.ts.map +1 -1
  30. package/dist/api/index.js +18 -37
  31. package/dist/api/index.js.map +1 -1
  32. package/dist/atomic-swap/drive.d.ts +0 -13
  33. package/dist/atomic-swap/drive.d.ts.map +1 -1
  34. package/dist/atomic-swap/drive.js +66 -111
  35. package/dist/atomic-swap/drive.js.map +1 -1
  36. package/dist/atomic-swap/extract.d.ts +0 -23
  37. package/dist/atomic-swap/extract.d.ts.map +1 -1
  38. package/dist/atomic-swap/extract.js +6 -16
  39. package/dist/atomic-swap/extract.js.map +1 -1
  40. package/dist/atomic-swap/index.d.ts +0 -7
  41. package/dist/atomic-swap/index.d.ts.map +1 -1
  42. package/dist/atomic-swap/index.js +1 -7
  43. package/dist/atomic-swap/index.js.map +1 -1
  44. package/dist/atomic-swap/monero-sweep/errors.d.ts.map +1 -1
  45. package/dist/atomic-swap/monero-sweep/errors.js +5 -20
  46. package/dist/atomic-swap/monero-sweep/errors.js.map +1 -1
  47. package/dist/atomic-swap/monero-sweep/index.d.ts +0 -13
  48. package/dist/atomic-swap/monero-sweep/index.d.ts.map +1 -1
  49. package/dist/atomic-swap/monero-sweep/index.js +30 -56
  50. package/dist/atomic-swap/monero-sweep/index.js.map +1 -1
  51. package/dist/atomic-swap/monero-sweep/ring-select.d.ts +0 -4
  52. package/dist/atomic-swap/monero-sweep/ring-select.d.ts.map +1 -1
  53. package/dist/atomic-swap/monero-sweep/ring-select.js +9 -21
  54. package/dist/atomic-swap/monero-sweep/ring-select.js.map +1 -1
  55. package/dist/atomic-swap/presign.d.ts +0 -63
  56. package/dist/atomic-swap/presign.d.ts.map +1 -1
  57. package/dist/atomic-swap/presign.js +30 -90
  58. package/dist/atomic-swap/presign.js.map +1 -1
  59. package/dist/atomic-swap/refund.d.ts +0 -18
  60. package/dist/atomic-swap/refund.d.ts.map +1 -1
  61. package/dist/atomic-swap/refund.js +16 -32
  62. package/dist/atomic-swap/refund.js.map +1 -1
  63. package/dist/atomic-swap/run.d.ts +0 -17
  64. package/dist/atomic-swap/run.d.ts.map +1 -1
  65. package/dist/atomic-swap/run.js +11 -25
  66. package/dist/atomic-swap/run.js.map +1 -1
  67. package/dist/atomic-swap/snapshot.d.ts +0 -30
  68. package/dist/atomic-swap/snapshot.d.ts.map +1 -1
  69. package/dist/atomic-swap/snapshot.js +8 -23
  70. package/dist/atomic-swap/snapshot.js.map +1 -1
  71. package/dist/atomic-swap/submit-encsig.d.ts +0 -7
  72. package/dist/atomic-swap/submit-encsig.d.ts.map +1 -1
  73. package/dist/atomic-swap/submit-encsig.js +2 -11
  74. package/dist/atomic-swap/submit-encsig.js.map +1 -1
  75. package/dist/atomic-swap/types.d.ts +2 -55
  76. package/dist/atomic-swap/types.d.ts.map +1 -1
  77. package/dist/atomic-swap/types.js +2 -3
  78. package/dist/atomic-swap/types.js.map +1 -1
  79. package/dist/blockchain/quorum-provider.d.ts +0 -15
  80. package/dist/blockchain/quorum-provider.d.ts.map +1 -1
  81. package/dist/blockchain/quorum-provider.js +7 -9
  82. package/dist/blockchain/quorum-provider.js.map +1 -1
  83. package/dist/cooperative-redeem.d.ts +5 -14
  84. package/dist/cooperative-redeem.d.ts.map +1 -1
  85. package/dist/cooperative-redeem.js +3 -20
  86. package/dist/cooperative-redeem.js.map +1 -1
  87. package/dist/engine/blockchain-querier.d.ts +0 -22
  88. package/dist/engine/blockchain-querier.d.ts.map +1 -1
  89. package/dist/engine/engine-state.d.ts +0 -8
  90. package/dist/engine/engine-state.d.ts.map +1 -1
  91. package/dist/engine/engine-state.js.map +1 -1
  92. package/dist/engine/flow-context.d.ts +0 -20
  93. package/dist/engine/flow-context.d.ts.map +1 -1
  94. package/dist/engine/flow-context.js +17 -41
  95. package/dist/engine/flow-context.js.map +1 -1
  96. package/dist/engine/flows/atomic-flow.d.ts +0 -28
  97. package/dist/engine/flows/atomic-flow.d.ts.map +1 -1
  98. package/dist/engine/flows/atomic-flow.js +64 -121
  99. package/dist/engine/flows/atomic-flow.js.map +1 -1
  100. package/dist/engine/flows/swap-flow.d.ts +0 -19
  101. package/dist/engine/flows/swap-flow.d.ts.map +1 -1
  102. package/dist/engine/flows/swap-flow.js +41 -83
  103. package/dist/engine/flows/swap-flow.js.map +1 -1
  104. package/dist/engine/miradex-engine.d.ts +1 -62
  105. package/dist/engine/miradex-engine.d.ts.map +1 -1
  106. package/dist/engine/miradex-engine.js +18 -50
  107. package/dist/engine/miradex-engine.js.map +1 -1
  108. package/dist/engine/pipeline.d.ts +0 -11
  109. package/dist/engine/pipeline.d.ts.map +1 -1
  110. package/dist/engine/pipeline.js +9 -21
  111. package/dist/engine/pipeline.js.map +1 -1
  112. package/dist/engine/platform.d.ts +0 -160
  113. package/dist/engine/platform.d.ts.map +1 -1
  114. package/dist/engine/platform.js +2 -0
  115. package/dist/engine/platform.js.map +1 -1
  116. package/dist/index.d.ts.map +1 -1
  117. package/dist/index.js +7 -11
  118. package/dist/index.js.map +1 -1
  119. package/dist/interfaces/blockchain.d.ts +1 -13
  120. package/dist/interfaces/blockchain.d.ts.map +1 -1
  121. package/dist/interfaces/blockchain.js +1 -0
  122. package/dist/interfaces/blockchain.js.map +1 -1
  123. package/dist/interfaces/logger.d.ts +0 -6
  124. package/dist/interfaces/logger.d.ts.map +1 -1
  125. package/dist/interfaces/logger.js.map +1 -1
  126. package/dist/lib/bitcoin/deposit-watcher.d.ts +0 -23
  127. package/dist/lib/bitcoin/deposit-watcher.d.ts.map +1 -1
  128. package/dist/lib/bitcoin/deposit-watcher.js +7 -31
  129. package/dist/lib/bitcoin/deposit-watcher.js.map +1 -1
  130. package/dist/lib/bitcoin/script-hash.d.ts.map +1 -1
  131. package/dist/lib/bitcoin/script-hash.js +2 -6
  132. package/dist/lib/bitcoin/script-hash.js.map +1 -1
  133. package/dist/lib/bitcoin/sweep.d.ts +0 -30
  134. package/dist/lib/bitcoin/sweep.d.ts.map +1 -1
  135. package/dist/lib/bitcoin/sweep.js +11 -40
  136. package/dist/lib/bitcoin/sweep.js.map +1 -1
  137. package/dist/lib/bitcoin/tx-verify.d.ts +0 -28
  138. package/dist/lib/bitcoin/tx-verify.d.ts.map +1 -1
  139. package/dist/lib/bitcoin/tx-verify.js +20 -61
  140. package/dist/lib/bitcoin/tx-verify.js.map +1 -1
  141. package/dist/lib/bitcoin/wallet.d.ts +0 -38
  142. package/dist/lib/bitcoin/wallet.d.ts.map +1 -1
  143. package/dist/lib/bitcoin/wallet.js +13 -38
  144. package/dist/lib/bitcoin/wallet.js.map +1 -1
  145. package/dist/lib/crypto/bytes.d.ts +0 -14
  146. package/dist/lib/crypto/bytes.d.ts.map +1 -1
  147. package/dist/lib/crypto/bytes.js +5 -14
  148. package/dist/lib/crypto/bytes.js.map +1 -1
  149. package/dist/lib/crypto/errors.d.ts +0 -5
  150. package/dist/lib/crypto/errors.d.ts.map +1 -1
  151. package/dist/lib/crypto/errors.js +2 -5
  152. package/dist/lib/crypto/errors.js.map +1 -1
  153. package/dist/lib/crypto/libp2p-identity.d.ts +0 -15
  154. package/dist/lib/crypto/libp2p-identity.d.ts.map +1 -1
  155. package/dist/lib/crypto/libp2p-identity.js +16 -28
  156. package/dist/lib/crypto/libp2p-identity.js.map +1 -1
  157. package/dist/lib/crypto/mnemonic.d.ts +0 -9
  158. package/dist/lib/crypto/mnemonic.d.ts.map +1 -1
  159. package/dist/lib/crypto/mnemonic.js +11 -27
  160. package/dist/lib/crypto/mnemonic.js.map +1 -1
  161. package/dist/lib/crypto/platform.d.ts +0 -6
  162. package/dist/lib/crypto/platform.d.ts.map +1 -1
  163. package/dist/lib/crypto/platform.js +2 -6
  164. package/dist/lib/crypto/platform.js.map +1 -1
  165. package/dist/lib/crypto/scalars.d.ts +0 -23
  166. package/dist/lib/crypto/scalars.d.ts.map +1 -1
  167. package/dist/lib/crypto/scalars.js +10 -23
  168. package/dist/lib/crypto/scalars.js.map +1 -1
  169. package/dist/lib/crypto/types.d.ts +0 -4
  170. package/dist/lib/crypto/types.d.ts.map +1 -1
  171. package/dist/lib/crypto/wasm.d.ts +0 -23
  172. package/dist/lib/crypto/wasm.d.ts.map +1 -1
  173. package/dist/lib/crypto/wasm.js +10 -13
  174. package/dist/lib/crypto/wasm.js.map +1 -1
  175. package/dist/lib/default-config.d.ts +1 -59
  176. package/dist/lib/default-config.d.ts.map +1 -1
  177. package/dist/lib/default-config.js +22 -61
  178. package/dist/lib/default-config.js.map +1 -1
  179. package/dist/lib/errors.d.ts +0 -54
  180. package/dist/lib/errors.d.ts.map +1 -1
  181. package/dist/lib/errors.js +12 -35
  182. package/dist/lib/errors.js.map +1 -1
  183. package/dist/lib/keystore.d.ts +0 -24
  184. package/dist/lib/keystore.d.ts.map +1 -1
  185. package/dist/lib/keystore.js +3 -10
  186. package/dist/lib/keystore.js.map +1 -1
  187. package/dist/lib/monero/output-scanner.d.ts +0 -18
  188. package/dist/lib/monero/output-scanner.d.ts.map +1 -1
  189. package/dist/lib/monero/output-scanner.js +17 -40
  190. package/dist/lib/monero/output-scanner.js.map +1 -1
  191. package/dist/lib/monero/rpc.d.ts +0 -64
  192. package/dist/lib/monero/rpc.d.ts.map +1 -1
  193. package/dist/lib/monero/rpc.js +17 -59
  194. package/dist/lib/monero/rpc.js.map +1 -1
  195. package/dist/lib/monero/verify-lock.d.ts +0 -12
  196. package/dist/lib/monero/verify-lock.d.ts.map +1 -1
  197. package/dist/lib/monero/verify-lock.js +9 -24
  198. package/dist/lib/monero/verify-lock.js.map +1 -1
  199. package/dist/lib/monero/verify-sweep.d.ts +0 -20
  200. package/dist/lib/monero/verify-sweep.d.ts.map +1 -1
  201. package/dist/lib/monero/verify-sweep.js +7 -25
  202. package/dist/lib/monero/verify-sweep.js.map +1 -1
  203. package/dist/lib/pow-solver.d.ts.map +1 -1
  204. package/dist/lib/pow-solver.js +3 -8
  205. package/dist/lib/pow-solver.js.map +1 -1
  206. package/dist/lib/retry.d.ts +7 -64
  207. package/dist/lib/retry.d.ts.map +1 -1
  208. package/dist/lib/retry.js +13 -13
  209. package/dist/lib/retry.js.map +1 -1
  210. package/dist/portable.d.ts.map +1 -1
  211. package/dist/portable.js +3 -4
  212. package/dist/portable.js.map +1 -1
  213. package/dist/quote-binding.d.ts +0 -13
  214. package/dist/quote-binding.d.ts.map +1 -1
  215. package/dist/quote-binding.js +3 -18
  216. package/dist/quote-binding.js.map +1 -1
  217. package/dist/swap-executor.d.ts +1 -5
  218. package/dist/swap-executor.d.ts.map +1 -1
  219. package/dist/swap-executor.js +1 -1
  220. package/dist/swap-executor.js.map +1 -1
  221. package/dist/types/api.d.ts +0 -6
  222. package/dist/types/api.d.ts.map +1 -1
  223. package/dist/types/api.js +6 -9
  224. package/dist/types/api.js.map +1 -1
  225. package/dist/types/errors.d.ts +0 -7
  226. package/dist/types/errors.d.ts.map +1 -1
  227. package/dist/types/errors.js +2 -7
  228. package/dist/types/errors.js.map +1 -1
  229. package/dist/types/index.js +1 -1
  230. package/dist/types/index.js.map +1 -1
  231. package/dist/types/keys.d.ts +0 -15
  232. package/dist/types/keys.d.ts.map +1 -1
  233. package/dist/types/protocol.d.ts +0 -51
  234. package/dist/types/protocol.d.ts.map +1 -1
  235. package/dist/types/protocol.js +3 -8
  236. package/dist/types/protocol.js.map +1 -1
  237. package/dist/types/status.d.ts.map +1 -1
  238. package/dist/types/status.js +9 -14
  239. package/dist/types/status.js.map +1 -1
  240. package/dist/types/verification.d.ts +0 -10
  241. package/dist/types/verification.d.ts.map +1 -1
  242. package/dist/types/verification.js +7 -15
  243. package/dist/types/verification.js.map +1 -1
  244. package/dist/verification/chainflip-networks.d.ts +2 -35
  245. package/dist/verification/chainflip-networks.d.ts.map +1 -1
  246. package/dist/verification/chainflip-networks.js +12 -4
  247. package/dist/verification/chainflip-networks.js.map +1 -1
  248. package/dist/verification/chainflip.d.ts +0 -40
  249. package/dist/verification/chainflip.d.ts.map +1 -1
  250. package/dist/verification/chainflip.js +49 -129
  251. package/dist/verification/chainflip.js.map +1 -1
  252. package/dist/verification/constants.d.ts +0 -40
  253. package/dist/verification/constants.d.ts.map +1 -1
  254. package/dist/verification/constants.js +14 -40
  255. package/dist/verification/constants.js.map +1 -1
  256. package/dist/verification/index.d.ts +0 -26
  257. package/dist/verification/index.d.ts.map +1 -1
  258. package/dist/verification/index.js +8 -12
  259. package/dist/verification/index.js.map +1 -1
  260. package/dist/verification/memo.d.ts +0 -15
  261. package/dist/verification/memo.d.ts.map +1 -1
  262. package/dist/verification/memo.js +9 -27
  263. package/dist/verification/memo.js.map +1 -1
  264. package/dist/verification/near-intents.d.ts +0 -63
  265. package/dist/verification/near-intents.d.ts.map +1 -1
  266. package/dist/verification/near-intents.js +25 -67
  267. package/dist/verification/near-intents.js.map +1 -1
  268. package/dist/verification/rate-oracle.d.ts +0 -22
  269. package/dist/verification/rate-oracle.d.ts.map +1 -1
  270. package/dist/verification/rate-oracle.js +6 -11
  271. package/dist/verification/rate-oracle.js.map +1 -1
  272. package/dist/verification/thorchain-networks.d.ts +0 -27
  273. package/dist/verification/thorchain-networks.d.ts.map +1 -1
  274. package/dist/verification/thorchain-networks.js +13 -15
  275. package/dist/verification/thorchain-networks.js.map +1 -1
  276. package/dist/verification/thorchain.d.ts +0 -30
  277. package/dist/verification/thorchain.d.ts.map +1 -1
  278. package/dist/verification/thorchain.js +24 -47
  279. package/dist/verification/thorchain.js.map +1 -1
  280. package/dist/wasm-pins.d.ts +3 -3
  281. package/dist/wasm-pins.js +1 -1
  282. package/dist/wire/near-intents.zod.d.ts +0 -27
  283. package/dist/wire/near-intents.zod.d.ts.map +1 -1
  284. package/dist/wire/near-intents.zod.js +15 -23
  285. package/dist/wire/near-intents.zod.js.map +1 -1
  286. package/dist/wire/server/action.zod.d.ts +0 -10
  287. package/dist/wire/server/action.zod.d.ts.map +1 -1
  288. package/dist/wire/server/action.zod.js +8 -14
  289. package/dist/wire/server/action.zod.js.map +1 -1
  290. package/dist/wire/server/common.zod.d.ts +0 -13
  291. package/dist/wire/server/common.zod.d.ts.map +1 -1
  292. package/dist/wire/server/common.zod.js +6 -14
  293. package/dist/wire/server/common.zod.js.map +1 -1
  294. package/dist/wire/server/swap.zod.d.ts +0 -42
  295. package/dist/wire/server/swap.zod.d.ts.map +1 -1
  296. package/dist/wire/server/swap.zod.js +12 -26
  297. package/dist/wire/server/swap.zod.js.map +1 -1
  298. package/dist/wire/thorchain.zod.d.ts +0 -8
  299. package/dist/wire/thorchain.zod.d.ts.map +1 -1
  300. package/dist/wire/thorchain.zod.js +3 -8
  301. package/dist/wire/thorchain.zod.js.map +1 -1
  302. package/package.json +4 -5
  303. package/wasm/miradex-rust/README.md +3 -4
  304. package/wasm/miradex-rust/miradex_rust.d.ts +4 -6
  305. package/wasm/miradex-rust/miradex_rust.js +4 -6
  306. package/wasm/miradex-rust/miradex_rust_bg.wasm +0 -0
@@ -1,14 +1,10 @@
1
- /**
2
- * Zod-enforced FlowContext schemas.
3
- *
4
- * Three strictness levels:
5
- * FlowContext — base, nullable fields (early phases: keygen, creating-swap)
6
- * PopulatedFlowContext — snapshot-critical fields non-empty (awaiting-deposit, deposit-detected)
7
- * VerifiedFlowContext — populated + verification non-null (signing, funding, confirming, swapping)
8
- *
9
- * Types are inferred from schemas — one source of truth, zero drift.
10
- * Validation uses safeParse — never throws, returns structured errors.
11
- */
1
+ // Three strictness levels:
2
+ // FlowContext - base, nullable (keygen, creating-swap)
3
+ // PopulatedFlowContext - snapshot-critical fields non-empty
4
+ // (awaiting-deposit, deposit-detected)
5
+ // VerifiedFlowContext - populated + verification non-null
6
+ // (signing, funding, confirming, swapping)
7
+ // Types are inferred from the schemas; validation uses safeParse.
12
8
  import { z } from 'zod';
13
9
  const VerificationCheckSchema = z.object({
14
10
  name: z.string(),
@@ -26,36 +22,29 @@ const FlowContextExtraSchema = z.object({
26
22
  text: z.string().min(1, 'extra.text must not be empty'),
27
23
  type: z.enum(EXTRA_TYPES),
28
24
  });
29
- // Used by early phases where data may not be available yet.
30
- // Every field is nullable — the engine builds it up progressively.
25
+ // Every field nullable; the engine builds it up progressively.
31
26
  const FlowContextBaseSchema = z.object({
32
- // Addresses
33
27
  depositAddr: z.string().nullable(),
34
28
  destAddress: z.string().nullable(),
35
29
  refundAddress: z.string().nullable(),
36
30
  keystoreId: z.string().nullable(),
37
- // Amounts
38
31
  depositAmount: z.string().nullable(),
39
32
  fromToken: z.string().nullable(),
40
33
  toToken: z.string().nullable(),
41
34
  expectedOut: z.string().nullable(),
42
35
  amountInUsd: z.string().nullable(),
43
36
  expectedOutUsd: z.string().nullable(),
44
- // Display
45
37
  qr: z.string().nullable(),
46
38
  verification: VerificationResultSchema.nullable(),
47
39
  verificationSourceUrl: z.string().nullable(),
48
40
  expiresAt: z.string().nullable(),
49
41
  depositMemo: z.string().nullable(),
50
- // Identity
51
42
  provider: z.string().nullable(),
52
43
  swapId: z.string().nullable(),
53
44
  swapNumber: z.string().nullable(),
54
- // Contextual
55
45
  extra: FlowContextExtraSchema.nullable(),
56
46
  });
57
- // Used by deposit-ready phases. Critical snapshot fields MUST be
58
- // non-empty strings — Zod rejects "" and null at runtime.
47
+ // Critical snapshot fields must be non-empty for deposit-ready phases.
59
48
  const PopulatedFlowContextSchema = FlowContextBaseSchema.extend({
60
49
  depositAddr: z.string().min(1, 'depositAddr is required for this phase'),
61
50
  destAddress: z.string().min(1, 'destAddress is required for this phase'),
@@ -63,24 +52,18 @@ const PopulatedFlowContextSchema = FlowContextBaseSchema.extend({
63
52
  toToken: z.string().min(1, 'toToken is required for this phase'),
64
53
  qr: z.string().min(1, 'qr is required for this phase'),
65
54
  provider: z.string().min(1, 'provider is required for this phase'),
66
- // `expectedOut` stays nullable here on purpose. It's display-only
67
- // populated from a /quotes round-trip that can legitimately fail
68
- // (transient API hiccup, no maker available for the amount, atomicswap
69
- // provider not in the quote set). The deposit, swap, and refund paths
70
- // do not depend on knowing the exact expected output, so blocking
71
- // `deposit-detected` on it would force the SDK to fail a swap that's
72
- // otherwise progressing fine. UIs already handle null with a "—".
55
+ // expectedOut stays nullable: it's display-only, sourced from /quotes which
56
+ // can fail transiently. Deposit/swap/refund paths don't need it; blocking
57
+ // here would fail an otherwise-fine swap. UIs render null as "-".
73
58
  expectedOut: z.string().nullable(),
74
59
  });
75
- // Used by post-verification phases. Everything populated + verification
76
- // MUST be a valid VerificationResult (non-null).
60
+ // Post-verification: everything populated + verification non-null.
77
61
  const VerifiedFlowContextSchema = PopulatedFlowContextSchema.extend({
78
62
  verification: VerificationResultSchema,
79
63
  });
80
- // Re-export schemas for consumers that need them (tests, browser adapter)
64
+ // Re-exported for tests and adapter implementations.
81
65
  export { FlowContextBaseSchema, PopulatedFlowContextSchema, VerifiedFlowContextSchema, FlowContextExtraSchema, VerificationResultSchema, VerificationCheckSchema, };
82
- // Use safeParse never throw. Return structured error listing every
83
- // missing/invalid field. The engine calls these before emitting phases.
66
+ // Engine calls these before emitting phases; structured error per failure.
84
67
  function buildValidationError(phase, zodError) {
85
68
  const fields = zodError.issues.map((issue) => issue.path.join('.'));
86
69
  const details = zodError.issues.map((issue) => `${issue.path.join('.')}: ${issue.message}`);
@@ -129,18 +112,11 @@ const EMPTY_FLOW_CONTEXT = {
129
112
  swapNumber: null,
130
113
  extra: null,
131
114
  };
132
- /**
133
- * Create a new FlowContext with defaults, overriding with provided values.
134
- * Null values in partial are applied (they mean "not yet known").
135
- */
115
+ // null in `partial` is a valid override and means "not yet known".
136
116
  export function createFlowContext(partial) {
137
117
  return { ...EMPTY_FLOW_CONTEXT, ...partial };
138
118
  }
139
- /**
140
- * Merge an update into an existing FlowContext.
141
- * Only non-undefined keys in partial overwrite. Null IS a valid value
142
- * (it means "reset to unknown").
143
- */
119
+ // Only non-undefined keys overwrite. null means "reset to unknown".
144
120
  export function mergeFlowContext(current, partial) {
145
121
  return { ...current, ...partial };
146
122
  }
@@ -1 +1 @@
1
- {"version":3,"file":"flow-context.js","sourceRoot":"","sources":["../../src/engine/flow-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE;IACnB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;CACnB,CAAC,CAAC;AAEH,MAAM,wBAAwB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE;IACrB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;IACpB,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,uBA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BAAoB,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;AACzE,CAAC;AAED,MAAM,kBAAkB,GAAgB;IACtC,WAAW,EAAE,IAAI;IACjB,WAAW,EAAE,IAAI;IACjB,aAAa,EAAE,IAAI;IACnB,UAAU,EAAE,IAAI;IAChB,aAAa,EAAE,IAAI;IACnB,SAAS,EAAE,IAAI;IACf,OAAO,EAAE,IAAI;IACb,WAAW,EAAE,IAAI;IACjB,WAAW,EAAE,IAAI;IACjB,cAAc,EAAE,IAAI;IACpB,EAAE,EAAE,IAAI;IACR,YAAY,EAAE,IAAI;IAClB,qBAAqB,EAAE,IAAI;IAC3B,SAAS,EAAE,IAAI;IACf,WAAW,EAAE,IAAI;IACjB,QAAQ,EAAE,IAAI;IACd,MAAM,EAAE,IAAI;IACZ,UAAU,EAAE,IAAI;IAChB,KAAK,EAAE,IAAI;CACZ,CAAC;AAEF,mEAAmE;AACnE,MAAM,UAAU,iBAAiB,CAAC,OAA6B;IAC7D,OAAO,EAAE,GAAG,kBAAkB,EAAE,GAAG,OAAO,EAAE,CAAC;AAC/C,CAAC;AAED,oEAAoE;AACpE,MAAM,UAAU,gBAAgB,CAC9B,OAAoB,EACpB,OAA6B;IAE7B,OAAO,EAAE,GAAG,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC;AACpC,CAAC"}
@@ -19,35 +19,13 @@ export declare class AtomicFlow {
19
19
  private flowCtx;
20
20
  private lastProgressKey;
21
21
  private readonly pollMs;
22
- /**
23
- * True once the driver has emitted a terminal phase (`completed`,
24
- * `failed`, `refunded`, etc.). Used to suppress the post-driver
25
- * `requiredAction` re-check that would otherwise trigger a phantom
26
- * second sweep — the server has no scanner for the on-chain XMR sweep,
27
- * so a fresh `getSwapDetail` right after the driver completes still
28
- * reports `requiredAction.type === 'sweep'`.
29
- */
30
22
  private hasReachedTerminal;
31
- /**
32
- * Optional maker pin forwarded to `coreResumeAtomicSwap` via
33
- * `params.variantId`. Set by `start()` from `StartAtomicSwapParams`;
34
- * unused (and irrelevant) on the resume path because the maker is
35
- * already chosen at that point.
36
- */
37
23
  private variantId;
38
24
  constructor(api: ApiClient, platform: PlatformAdapter, config: ResolvedEngineConfig, emitFn: (state: AtomicFlowState) => void, options?: AtomicFlowOptions);
39
25
  private get signal();
40
26
  private get logger();
41
27
  private setFlowContext;
42
- /**
43
- * Validate FlowContext as PopulatedFlowContext.
44
- * On failure, emits a 'failed' phase with structured error and returns null.
45
- */
46
28
  private requirePopulated;
47
- /**
48
- * Validate FlowContext as VerifiedFlowContext.
49
- * On failure, emits a 'failed' phase with structured error and returns null.
50
- */
51
29
  private requireVerified;
52
30
  private emitError;
53
31
  private transition;
@@ -69,12 +47,6 @@ export declare class AtomicFlow {
69
47
  private executeSweep;
70
48
  private executeRefund;
71
49
  private resolveLockAddress;
72
- /**
73
- * Read protocol params from the server response; fall back to the platform
74
- * adapter's optional write-through cache when the server didn't return the
75
- * refund encsig. On success from the server, populate the cache so later
76
- * refunds survive a briefly-unreachable backend.
77
- */
78
50
  private resolveProtocolParams;
79
51
  private cacheProtocolParams;
80
52
  private emitRefundAborted;
@@ -1 +1 @@
1
- {"version":3,"file":"atomic-flow.d.ts","sourceRoot":"","sources":["../../../src/engine/flows/atomic-flow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,KAAK,EAAE,eAAe,EAAmB,MAAM,gBAAgB,CAAC;AACvE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,KAAK,EAAE,eAAe,EAAuB,MAAM,wBAAwB,CAAC;AA2EnF,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,qBAAa,UAAU;IA6BnB,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAA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a;IA8M3B,OAAO,CAAC,kBAAkB;YAcZ,qBAAqB;YAiCrB,mBAAmB;IAiBjC,OAAO,CAAC,iBAAiB;YAUX,iBAAiB;IAuC/B,OAAO,CAAC,YAAY;IAsBpB,OAAO,CAAC,gBAAgB;IAKxB,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,WAAW;IAenB,OAAO,CAAC,6BAA6B;CAItC"}
@@ -27,16 +27,14 @@ function isTransientError(err) {
27
27
  }
28
28
  return false;
29
29
  }
30
- /**
31
- * True iff the protocol params carry enough material for the client to
32
- * construct a refund without sidecar cooperation. Two valid shapes:
33
- * - Legacy/Full: `tx_full_refund_encsig` alone is enough — the client
34
- * builds and broadcasts TxFullRefund spending TxCancel.
35
- * - Partial (amnesty): `tx_partial_refund_encsig` plus the amnesty
36
- * triple (`amnesty_amount_sats`, `tx_partial_refund_fee_sats`) drive
37
- * the partial-refund branch. The amnesty output stays at multisig
38
- * until a separate TxReclaim phase (not yet implemented client-side).
39
- */
30
+ // True if the params carry enough material to refund without the sidecar.
31
+ // Two valid shapes:
32
+ // Legacy/Full: tx_full_refund_encsig alone (client builds + broadcasts
33
+ // TxFullRefund spending TxCancel).
34
+ // Partial: tx_partial_refund_encsig + amnesty triple
35
+ // (amnesty_amount_sats, tx_partial_refund_fee_sats). Amnesty
36
+ // output stays at multisig pending TxReclaim (not implemented
37
+ // client-side yet).
40
38
  function hasRefundEscapeHatch(params) {
41
39
  if (params.tx_full_refund_encsig)
42
40
  return true;
@@ -60,21 +58,13 @@ export class AtomicFlow {
60
58
  flowCtx = null;
61
59
  lastProgressKey = null;
62
60
  pollMs;
63
- /**
64
- * True once the driver has emitted a terminal phase (`completed`,
65
- * `failed`, `refunded`, etc.). Used to suppress the post-driver
66
- * `requiredAction` re-check that would otherwise trigger a phantom
67
- * second sweep — the server has no scanner for the on-chain XMR sweep,
68
- * so a fresh `getSwapDetail` right after the driver completes still
69
- * reports `requiredAction.type === 'sweep'`.
70
- */
61
+ // Set once the driver emits a terminal phase. Suppresses the post-driver
62
+ // requiredAction re-check that would otherwise trigger a phantom second
63
+ // sweep the server has no scanner for the on-chain XMR sweep so a fresh
64
+ // getSwapDetail still reports requiredAction.type === 'sweep'.
71
65
  hasReachedTerminal = false;
72
- /**
73
- * Optional maker pin forwarded to `coreResumeAtomicSwap` via
74
- * `params.variantId`. Set by `start()` from `StartAtomicSwapParams`;
75
- * unused (and irrelevant) on the resume path because the maker is
76
- * already chosen at that point.
77
- */
66
+ // Forwarded to coreResumeAtomicSwap as params.variantId. Set by start();
67
+ // ignored on resume (maker already chosen).
78
68
  variantId;
79
69
  constructor(api, platform, config, emitFn, options) {
80
70
  this.api = api;
@@ -94,10 +84,7 @@ export class AtomicFlow {
94
84
  ? mergeFlowContext(this.flowCtx, partial)
95
85
  : createFlowContext(partial);
96
86
  }
97
- /**
98
- * Validate FlowContext as PopulatedFlowContext.
99
- * On failure, emits a 'failed' phase with structured error and returns null.
100
- */
87
+ // On failure, emits 'failed' with a structured error and returns null.
101
88
  requirePopulated(phase) {
102
89
  if (!this.flowCtx) {
103
90
  this.emitError(phase, 'FlowContext not initialized');
@@ -110,10 +97,7 @@ export class AtomicFlow {
110
97
  this.emitError(phase, result.error.message);
111
98
  return null;
112
99
  }
113
- /**
114
- * Validate FlowContext as VerifiedFlowContext.
115
- * On failure, emits a 'failed' phase with structured error and returns null.
116
- */
100
+ // On failure, emits 'failed' with a structured error and returns null.
117
101
  requireVerified(phase) {
118
102
  if (!this.flowCtx) {
119
103
  this.emitError(phase, 'FlowContext not initialized');
@@ -168,17 +152,14 @@ export class AtomicFlow {
168
152
  this.transition({ phase: 'keygen', snapshot: this.flowCtx, message: 'Initializing keygen...' });
169
153
  await ensureWasm();
170
154
  const network = this.config.network;
171
- // Either reuse an existing keystore (re-quote-after-failure path) or
172
- // generate a fresh one (default path). In both cases the rest of the
173
- // flow is identical from this point forward — same deposit polling,
174
- // same swap creation, same drive loop.
155
+ // Reuse an existing keystore (re-quote-after-failure) or generate a
156
+ // fresh one. Flow is identical past this point.
175
157
  let wallet;
176
158
  if (params.existingKeystoreId !== undefined) {
177
159
  this.setFlowContext({ extra: { text: 'Loading keystore...', type: 'message' } });
178
160
  this.transition({ phase: 'keygen', snapshot: this.flowCtx, message: 'Loading keystore...' });
179
- // Trust: the keystore was created here originally and its keys
180
- // already passed `verifyKeys`. Skipping the API call avoids
181
- // doubling the call's transient-failure surface for a no-op check.
161
+ // Trust the keystore: it was created here and its keys already
162
+ // passed verifyKeys. Re-checking adds a transient-failure surface.
182
163
  this.keystore = await this.platform.loadKeystore(params.existingKeystoreId);
183
164
  this.keystoreId = params.existingKeystoreId;
184
165
  wallet = walletFromWif(this.keystore.btc.wif, network);
@@ -216,16 +197,10 @@ export class AtomicFlow {
216
197
  this.keystoreId = saveResult.id;
217
198
  this.logger.info({ keystoreId: this.keystoreId }, 'Keystore saved');
218
199
  }
219
- // Emit `keystoreId` to engine state IMMEDIATELY, before the slow
220
- // pre-deposit prep work (`estimateFee` mempool.space, `getQuotes`
221
- // swap-engine, `generateQr` wasm). The web app's
222
- // EngineRegistry races a 30 s timeout against `state.atomic.
223
- // snapshot.keystoreId` to decide whether to keep this engine; if
224
- // the slow chain below blows the budget the engine is destroyed
225
- // mid-flight and the user has to retry. Emitting a placeholder
226
- // keystore-saved transition here guarantees the registry binds
227
- // the engine on first save, regardless of subsequent network
228
- // latency.
200
+ // Emit keystoreId before the slow pre-deposit chain (estimateFee,
201
+ // getQuotes, generateQr). EngineRegistry races a 30s timeout against
202
+ // state.atomic.snapshot.keystoreId without this early emit the
203
+ // engine gets destroyed mid-flight on slow networks.
229
204
  this.setFlowContext({ keystoreId: this.keystoreId });
230
205
  this.transition({
231
206
  phase: 'keystore-saved',
@@ -244,12 +219,8 @@ export class AtomicFlow {
244
219
  }
245
220
  catch { /* non-fatal */ }
246
221
  const qr = await this.platform.generateQr(wallet.address);
247
- // Now that the slow chain has finished, populate the full
248
- // FlowContext with the deposit address, expected XMR amount, and
249
- // QR. The first `keystore-saved` transition above was the bare-
250
- // bones state emit needed to keep the registry from destroying
251
- // this engine; this second `setFlowContext` enriches it before
252
- // `awaiting-deposit` validates against `PopulatedFlowContext`.
222
+ // Slow chain done: enrich FlowContext before awaiting-deposit validates
223
+ // against PopulatedFlowContext.
253
224
  this.setFlowContext({
254
225
  depositAddr: wallet.address,
255
226
  depositAmount: requiredBtc,
@@ -258,7 +229,6 @@ export class AtomicFlow {
258
229
  extra: { text: `Send ${requiredBtc} BTC to the address above.`, type: 'message' },
259
230
  });
260
231
  this.checkAborted();
261
- // Validate before emitting awaiting-deposit
262
232
  const populated = this.requirePopulated('awaiting-deposit');
263
233
  if (!populated)
264
234
  return;
@@ -334,15 +304,10 @@ export class AtomicFlow {
334
304
  this.emitTerminal(existingSwapId, detail.status, detail);
335
305
  return;
336
306
  }
337
- // Funding-address UTXO is only meaningful pre-broadcast once the
338
- // swap is `deposited` or beyond, the BTC has already been swept
339
- // into TxLock at the lock address and the funding address is
340
- // empty. Re-querying it on every resume costs 2-15 s on
341
- // testnet/stagenet electrs (cold TLS, multi-server fallback,
342
- // flaky public endpoints) and the result feeds nothing
343
- // downstream once the protocol is past funding. Skip it for
344
- // post-funding statuses so resume settles immediately on the
345
- // current state instead of stalling on a useless network probe.
307
+ // Funding-address UTXO is only meaningful pre-broadcast; once the
308
+ // swap is 'deposited' or past, BTC is in TxLock and the funding
309
+ // address is empty. Re-querying costs 2-15s on flaky public
310
+ // electrs and feeds nothing downstream skip for post-funding.
346
311
  const PRE_FUNDING_STATUSES = new Set([
347
312
  'initializing',
348
313
  'pending',
@@ -353,7 +318,6 @@ export class AtomicFlow {
353
318
  : null;
354
319
  if (deposit)
355
320
  this.deposit = deposit;
356
- // Verify the contract for the resumed swap
357
321
  let verification = null;
358
322
  if (detail.depositAddress && detail.verification) {
359
323
  const { verifyDepositAddress } = await import('../../verification/index.js');
@@ -364,8 +328,7 @@ export class AtomicFlow {
364
328
  refundAddress: this.keystore.swap.refundAddress,
365
329
  toToken: 'XMR',
366
330
  amount: '',
367
- // Lock address lives at the top level of SwapDetail; timelock
368
- // blocks come from the typed atomicswap params when present.
331
+ // lock_address = SwapDetail.depositAddress; timelock from typed params.
369
332
  protocol: detail.depositAddress &&
370
333
  detail.protocolData?.type === 'atomicswap' &&
371
334
  detail.protocolData.params
@@ -379,7 +342,7 @@ export class AtomicFlow {
379
342
  fetchFn: this.config.fetchFn,
380
343
  });
381
344
  }
382
- // Fallback: if server has progressed past verification, trust it
345
+ // Server is past the verification gate; trust it.
383
346
  if (!verification) {
384
347
  verification = { verified: true, provider: 'atomicswap', checks: [], timestamp: Date.now() };
385
348
  }
@@ -390,8 +353,8 @@ export class AtomicFlow {
390
353
  depositAmount: deposit ? (deposit.value / 1e8).toFixed(8) : this.flowCtx?.depositAmount ?? null,
391
354
  extra: { text: `Resuming swap (${detail.status})...`, type: 'message' },
392
355
  });
393
- // For resumed swaps the core will provide verification via progress callbacks.
394
- // Emit as swapping (base FlowContext is sufficient for resume entry).
356
+ // Core supplies verification via progress callbacks on resume; base
357
+ // FlowContext is enough for the entry transition.
395
358
  this.transition({
396
359
  phase: 'creating-swap',
397
360
  snapshot: this.flowCtx,
@@ -402,10 +365,9 @@ export class AtomicFlow {
402
365
  }
403
366
  this.logger.info({ btcAddress }, 'Resume Path B: local keystore');
404
367
  const deposit = await this.platform.fetchUtxo(btcAddress, network);
405
- // Fetch expected XMR output for both branches (required for PopulatedFlowContext).
406
- // Pre-funding resume: there's no deposit yet, so we can't derive the
407
- // amount from on-chain. Read the original amount the swap was started
408
- // with from the keystore metadata (saved by saveKeystore as `label`).
368
+ // expectedOut is required for PopulatedFlowContext. Pre-funding resume
369
+ // has no on-chain deposit, so pull the original amount from the
370
+ // keystore metadata (saveKeystore stores it as `label`).
409
371
  let amountForQuote;
410
372
  if (deposit) {
411
373
  amountForQuote = (deposit.value / 1e8).toFixed(8);
@@ -522,9 +484,8 @@ export class AtomicFlow {
522
484
  throw new Error('keystore must be set before driving swap');
523
485
  }
524
486
  const network = (this.keystore.btc?.network ?? 'mainnet');
525
- // Provide a blockchain provider so the resume path can reconstruct the
526
- // TxLock from on-chain data when recomputing the redeem digest (Fix 1
527
- // on resume). The provider is shared across the driver's lifetime.
487
+ // AV-B.2 (resume): the driver reconstructs TxLock via this provider when
488
+ // recomputing the redeem digest. Shared across the driver's lifetime.
528
489
  const blockchain = await this.platform.createBlockchainProvider(network);
529
490
  const result = await coreResumeAtomicSwap({
530
491
  api: this.api,
@@ -544,13 +505,10 @@ export class AtomicFlow {
544
505
  saveProtocolSnapshot: this.platform.saveProtocolSnapshot,
545
506
  loadProtocolSnapshot: this.platform.loadProtocolSnapshot,
546
507
  });
547
- // If the driver already reached a terminal phase via mapCoreProgress
548
- // (sweep complete, refunded, cancelled, failed, punished), the post-driver
549
- // server re-check is meaningless the server has no scanner for the
550
- // on-chain XMR sweep, so it still reports requiredAction=sweep /
551
- // status=sending right after the client broadcast its sweep tx. Treating
552
- // that as actionable triggers a phantom second executeSweep that emits a
553
- // spurious `completed → sweeping` transition.
508
+ // Skip the server re-check if mapCoreProgress already emitted terminal:
509
+ // the server has no on-chain XMR scanner so it still reports
510
+ // requiredAction=sweep right after our broadcast, which would trigger a
511
+ // phantom second executeSweep and a spurious completed -> sweeping flicker.
554
512
  if (this.hasReachedTerminal)
555
513
  return;
556
514
  let finalStatus = 'completed';
@@ -574,11 +532,9 @@ export class AtomicFlow {
574
532
  this.emitTerminal(result.swapId, finalStatus, undefined);
575
533
  return;
576
534
  }
577
- // Non-terminal status with no immediately-actionable requiredAction
578
- // (e.g., server is still broadcasting TxCancel, or waiting for cancel
579
- // confirmation). Sidecar handles TxCancel automatically; the client just
580
- // needs to watch for the requiredAction to flip to 'refund' (or the
581
- // swap to reach terminal). pollUntilTerminal does both.
535
+ // Non-terminal with no actionable requiredAction (e.g. server still
536
+ // broadcasting TxCancel). Sidecar handles cancel; we wait for the
537
+ // action to flip to 'refund' or the swap to reach terminal.
582
538
  this.setFlowContext({
583
539
  extra: { text: requiredAction?.message ?? 'Waiting for server...', type: 'message' },
584
540
  });
@@ -671,10 +627,9 @@ export class AtomicFlow {
671
627
  phase: 'completed',
672
628
  snapshot: this.flowCtx,
673
629
  outputTxHash: p.txHash ?? null,
674
- // Atomic swaps have no slippage — the buyer receives exactly the
675
- // negotiated rate × deposit amount. Default to the snapshot's
676
- // expectedOut so the receipt shows the actual amount the user got
677
- // even when the in-flight progress event doesn't carry it.
630
+ // Atomic swaps have no slippage; buyer receives exactly rate * deposit.
631
+ // Fall back to expectedOut so the receipt shows the right number even
632
+ // when the progress event doesn't carry it.
678
633
  actualOut: this.flowCtx?.expectedOut ?? '',
679
634
  durationSec: null,
680
635
  });
@@ -708,9 +663,8 @@ export class AtomicFlow {
708
663
  });
709
664
  break;
710
665
  case 'cancelling':
711
- // Intermediate: BTC TxCancel is in flight, the refund will follow.
712
- // Stay in a watching phase so the driver keeps polling until the row
713
- // settles in `refunded` (or `failed` if the refund never lands).
666
+ // TxCancel in flight; refund follows. Stay watching until the row
667
+ // settles in 'refunded' (or 'failed' if the refund never lands).
714
668
  this.setFlowContext({ extra: { text: p.message, type: 'warning' } });
715
669
  this.transition({
716
670
  phase: 'creating-swap',
@@ -720,11 +674,8 @@ export class AtomicFlow {
720
674
  break;
721
675
  case 'withheld':
722
676
  case 'expired':
723
- // Terminal: the deposit window closed (`expired`) or the maker
724
- // refused to release funds (`withheld`). Both are user-visible
725
- // terminal statuses in `TerminalStatus`. Emit a `failed` phase so
726
- // poll consumers (engine driver, TUI exec state) observe a terminal
727
- // transition and resolve.
677
+ // Both are terminal in TerminalStatus. Emit 'failed' so poll
678
+ // consumers see a terminal transition and resolve.
728
679
  this.transition({
729
680
  phase: 'failed',
730
681
  snapshot: this.flowCtx,
@@ -733,12 +684,9 @@ export class AtomicFlow {
733
684
  break;
734
685
  case 'punished': {
735
686
  // Not terminal. Alice published TxPunish (Bob missed the refund
736
- // window), but the sidecar autonomously runs
737
- // `cooperative_xmr_redeem_after_punish` to recover s_a once Alice
738
- // cooperates, the server flips `requiredAction.type` to `sweep` and
739
- // the driver finishes the swap with an XMR sweep that lands the row
740
- // in `completed`. Stay in a watching phase so `drive.ts`'s existing
741
- // sweep branch can pick up the action transition.
687
+ // window), but the sidecar runs cooperative_xmr_redeem_after_punish
688
+ // to recover s_a; the server then flips requiredAction to 'sweep'
689
+ // and drive.ts finishes via the sweep branch.
742
690
  const reason = p.message ||
743
691
  'BTC punished — recovering XMR via cooperative_xmr_redeem_after_punish...';
744
692
  this.setFlowContext({ extra: { text: reason, type: 'warning' } });
@@ -1052,12 +1000,10 @@ export class AtomicFlow {
1052
1000
  }
1053
1001
  return '';
1054
1002
  }
1055
- /**
1056
- * Read protocol params from the server response; fall back to the platform
1057
- * adapter's optional write-through cache when the server didn't return the
1058
- * refund encsig. On success from the server, populate the cache so later
1059
- * refunds survive a briefly-unreachable backend.
1060
- */
1003
+ // Server response first; fall back to the platform adapter's optional
1004
+ // write-through cache when the server omitted the refund encsig. On a
1005
+ // good server response, prime the cache so later refunds survive a brief
1006
+ // backend outage.
1061
1007
  async resolveProtocolParams(swapId, detail) {
1062
1008
  const fromServer = extractProtocolData(detail).params;
1063
1009
  if (fromServer && hasRefundEscapeHatch(fromServer)) {
@@ -1109,17 +1055,14 @@ export class AtomicFlow {
1109
1055
  this.emitTerminal(swapId, detail.status, detail);
1110
1056
  return;
1111
1057
  }
1112
- // Opportunistically prime the protocol cache while the server is
1113
- // reachable. The refund path will use this cache if the server is
1114
- // briefly unreachable later.
1058
+ // Prime the protocol cache while the server is up; the refund path
1059
+ // falls back to it if the server goes down later.
1115
1060
  const polledParams = extractProtocolData(detail).params;
1116
1061
  if (polledParams?.tx_full_refund_encsig) {
1117
1062
  await this.cacheProtocolParams(swapId, polledParams);
1118
1063
  }
1119
- // Server flipped the required action to 'refund' TxCancel has
1120
- // confirmed on-chain and Bob's refund window is open. Auto-trigger
1121
- // the client-side refund so we don't drift toward the punish
1122
- // deadline while idly polling.
1064
+ // 'refund' flip means TxCancel confirmed and the refund window is
1065
+ // open. Auto-trigger so we don't drift toward the punish deadline.
1123
1066
  const action = detail.requiredAction ?? null;
1124
1067
  if (action?.type === 'refund') {
1125
1068
  this.logger.info({ swapId, blocksRemaining: action.blocksRemaining ?? null }, 'Required action flipped to refund — auto-triggering client-side refund');