@atomiqlabs/sdk 8.1.8 → 8.3.1

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 (253) hide show
  1. package/dist/bitcoin/wallet/BitcoinWallet.d.ts +41 -5
  2. package/dist/bitcoin/wallet/BitcoinWallet.js +36 -1
  3. package/dist/bitcoin/wallet/IBitcoinWallet.d.ts +52 -2
  4. package/dist/bitcoin/wallet/IBitcoinWallet.js +2 -1
  5. package/dist/bitcoin/wallet/SingleAddressBitcoinWallet.d.ts +42 -7
  6. package/dist/bitcoin/wallet/SingleAddressBitcoinWallet.js +36 -1
  7. package/dist/enums/FeeType.d.ts +7 -0
  8. package/dist/enums/FeeType.js +7 -0
  9. package/dist/enums/SwapAmountType.d.ts +7 -0
  10. package/dist/enums/SwapAmountType.js +7 -0
  11. package/dist/enums/SwapDirection.d.ts +7 -0
  12. package/dist/enums/SwapDirection.js +7 -0
  13. package/dist/enums/SwapType.d.ts +62 -1
  14. package/dist/enums/SwapType.js +62 -1
  15. package/dist/errors/IntermediaryError.d.ts +4 -0
  16. package/dist/errors/IntermediaryError.js +1 -0
  17. package/dist/errors/RequestError.d.ts +15 -1
  18. package/dist/errors/RequestError.js +8 -0
  19. package/dist/errors/UserError.d.ts +1 -0
  20. package/dist/errors/UserError.js +1 -0
  21. package/dist/index.d.ts +4 -5
  22. package/dist/index.js +3 -4
  23. package/dist/intermediaries/Intermediary.d.ts +57 -10
  24. package/dist/intermediaries/Intermediary.js +37 -10
  25. package/dist/intermediaries/IntermediaryDiscovery.d.ts +55 -22
  26. package/dist/intermediaries/IntermediaryDiscovery.js +35 -22
  27. package/dist/prices/RedundantSwapPrice.d.ts +24 -3
  28. package/dist/prices/RedundantSwapPrice.js +21 -1
  29. package/dist/prices/SingleSwapPrice.d.ts +9 -6
  30. package/dist/prices/SingleSwapPrice.js +10 -7
  31. package/dist/prices/SwapPriceWithChain.d.ts +54 -16
  32. package/dist/prices/SwapPriceWithChain.js +58 -20
  33. package/dist/prices/abstract/ISwapPrice.d.ts +94 -45
  34. package/dist/prices/abstract/ISwapPrice.js +103 -55
  35. package/dist/prices/providers/BinancePriceProvider.d.ts +7 -0
  36. package/dist/prices/providers/BinancePriceProvider.js +7 -0
  37. package/dist/prices/providers/CoinGeckoPriceProvider.d.ts +6 -0
  38. package/dist/prices/providers/CoinGeckoPriceProvider.js +6 -0
  39. package/dist/prices/providers/CoinPaprikaPriceProvider.d.ts +6 -0
  40. package/dist/prices/providers/CoinPaprikaPriceProvider.js +6 -0
  41. package/dist/prices/providers/CustomPriceProvider.d.ts +11 -0
  42. package/dist/prices/providers/CustomPriceProvider.js +11 -0
  43. package/dist/prices/providers/KrakenPriceProvider.d.ts +9 -0
  44. package/dist/prices/providers/KrakenPriceProvider.js +9 -0
  45. package/dist/prices/providers/OKXPriceProvider.d.ts +6 -0
  46. package/dist/prices/providers/OKXPriceProvider.js +6 -0
  47. package/dist/prices/providers/abstract/ExchangePriceProvider.d.ts +3 -0
  48. package/dist/prices/providers/abstract/ExchangePriceProvider.js +3 -0
  49. package/dist/storage/IUnifiedStorage.d.ts +19 -7
  50. package/dist/storage/UnifiedSwapStorage.d.ts +33 -3
  51. package/dist/storage/UnifiedSwapStorage.js +29 -1
  52. package/dist/storage-browser/IndexedDBUnifiedStorage.d.ts +31 -7
  53. package/dist/storage-browser/IndexedDBUnifiedStorage.js +29 -6
  54. package/dist/storage-browser/LocalStorageManager.d.ts +25 -1
  55. package/dist/storage-browser/LocalStorageManager.js +25 -1
  56. package/dist/swapper/Swapper.d.ts +302 -221
  57. package/dist/swapper/Swapper.js +376 -344
  58. package/dist/swapper/SwapperFactory.d.ts +41 -17
  59. package/dist/swapper/SwapperFactory.js +23 -2
  60. package/dist/swapper/SwapperUtils.d.ts +75 -28
  61. package/dist/swapper/SwapperUtils.js +107 -60
  62. package/dist/swapper/SwapperWithChain.d.ts +286 -91
  63. package/dist/swapper/SwapperWithChain.js +218 -64
  64. package/dist/swapper/SwapperWithSigner.d.ts +229 -80
  65. package/dist/swapper/SwapperWithSigner.js +190 -44
  66. package/dist/swaps/IAddressSwap.d.ts +10 -1
  67. package/dist/swaps/IAddressSwap.js +2 -1
  68. package/dist/swaps/IBTCWalletSwap.d.ts +24 -6
  69. package/dist/swaps/IBTCWalletSwap.js +2 -1
  70. package/dist/swaps/IClaimableSwap.d.ts +36 -4
  71. package/dist/swaps/IClaimableSwap.js +2 -1
  72. package/dist/swaps/IClaimableSwapWrapper.d.ts +11 -1
  73. package/dist/swaps/IRefundableSwap.d.ts +29 -3
  74. package/dist/swaps/IRefundableSwap.js +2 -1
  75. package/dist/swaps/ISwap.d.ts +159 -21
  76. package/dist/swaps/ISwap.js +90 -33
  77. package/dist/swaps/ISwapWithGasDrop.d.ts +6 -0
  78. package/dist/swaps/ISwapWithGasDrop.js +1 -0
  79. package/dist/swaps/ISwapWrapper.d.ts +157 -48
  80. package/dist/swaps/ISwapWrapper.js +130 -72
  81. package/dist/swaps/escrow_swaps/IEscrowSelfInitSwap.d.ts +49 -6
  82. package/dist/swaps/escrow_swaps/IEscrowSelfInitSwap.js +22 -12
  83. package/dist/swaps/escrow_swaps/IEscrowSwap.d.ts +65 -12
  84. package/dist/swaps/escrow_swaps/IEscrowSwap.js +38 -19
  85. package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.d.ts +39 -9
  86. package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.js +30 -21
  87. package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.d.ts +31 -15
  88. package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.js +33 -18
  89. package/dist/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.d.ts +94 -29
  90. package/dist/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.js +90 -27
  91. package/dist/swaps/escrow_swaps/frombtc/IFromBTCWrapper.d.ts +22 -9
  92. package/dist/swaps/escrow_swaps/frombtc/IFromBTCWrapper.js +24 -11
  93. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.d.ts +275 -58
  94. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.js +516 -239
  95. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.d.ts +76 -25
  96. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.js +131 -49
  97. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.d.ts +311 -51
  98. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.js +542 -193
  99. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.d.ts +87 -26
  100. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.js +147 -58
  101. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.d.ts +209 -53
  102. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.js +449 -242
  103. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.d.ts +77 -23
  104. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.js +116 -46
  105. package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.d.ts +197 -56
  106. package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.js +326 -189
  107. package/dist/swaps/escrow_swaps/tobtc/IToBTCWrapper.d.ts +30 -5
  108. package/dist/swaps/escrow_swaps/tobtc/IToBTCWrapper.js +44 -19
  109. package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.d.ts +60 -19
  110. package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.js +74 -31
  111. package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.d.ts +76 -50
  112. package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.js +106 -101
  113. package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.d.ts +36 -13
  114. package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.js +65 -19
  115. package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.d.ts +46 -17
  116. package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.js +82 -27
  117. package/dist/swaps/spv_swaps/SpvFromBTCSwap.d.ts +328 -92
  118. package/dist/swaps/spv_swaps/SpvFromBTCSwap.js +460 -219
  119. package/dist/swaps/spv_swaps/SpvFromBTCWrapper.d.ts +76 -24
  120. package/dist/swaps/spv_swaps/SpvFromBTCWrapper.js +244 -124
  121. package/dist/swaps/trusted/ln/LnForGasSwap.d.ts +146 -18
  122. package/dist/swaps/trusted/ln/LnForGasSwap.js +173 -43
  123. package/dist/swaps/trusted/ln/LnForGasWrapper.d.ts +29 -10
  124. package/dist/swaps/trusted/ln/LnForGasWrapper.js +30 -11
  125. package/dist/swaps/trusted/onchain/OnchainForGasSwap.d.ts +200 -47
  126. package/dist/swaps/trusted/onchain/OnchainForGasSwap.js +230 -78
  127. package/dist/swaps/trusted/onchain/OnchainForGasWrapper.d.ts +34 -12
  128. package/dist/swaps/trusted/onchain/OnchainForGasWrapper.js +33 -14
  129. package/dist/types/AmountData.d.ts +2 -1
  130. package/dist/types/CustomPriceFunction.d.ts +7 -1
  131. package/dist/types/SwapExecutionAction.d.ts +74 -4
  132. package/dist/types/SwapWithSigner.d.ts +4 -1
  133. package/dist/types/SwapWithSigner.js +5 -2
  134. package/dist/types/Token.d.ts +11 -5
  135. package/dist/types/Token.js +6 -3
  136. package/dist/types/TokenAmount.d.ts +3 -0
  137. package/dist/types/TokenAmount.js +2 -0
  138. package/dist/types/fees/Fee.d.ts +2 -1
  139. package/dist/types/fees/FeeBreakdown.d.ts +2 -1
  140. package/dist/types/fees/PercentagePPM.d.ts +2 -0
  141. package/dist/types/fees/PercentagePPM.js +1 -0
  142. package/dist/types/lnurl/LNURLPay.d.ts +14 -6
  143. package/dist/types/lnurl/LNURLPay.js +6 -2
  144. package/dist/types/lnurl/LNURLWithdraw.d.ts +12 -5
  145. package/dist/types/lnurl/LNURLWithdraw.js +6 -2
  146. package/dist/types/wallets/LightningInvoiceCreateService.d.ts +20 -0
  147. package/dist/types/wallets/LightningInvoiceCreateService.js +15 -0
  148. package/dist/types/wallets/MinimalBitcoinWalletInterface.d.ts +3 -1
  149. package/dist/types/wallets/MinimalLightningNetworkWalletInterface.d.ts +3 -1
  150. package/dist/utils/BitcoinUtils.d.ts +1 -0
  151. package/dist/utils/BitcoinUtils.js +5 -1
  152. package/dist/utils/SwapUtils.d.ts +56 -1
  153. package/dist/utils/SwapUtils.js +53 -1
  154. package/dist/utils/TokenUtils.d.ts +10 -2
  155. package/dist/utils/TokenUtils.js +12 -4
  156. package/package.json +3 -3
  157. package/src/bitcoin/wallet/BitcoinWallet.ts +41 -5
  158. package/src/bitcoin/wallet/IBitcoinWallet.ts +57 -2
  159. package/src/bitcoin/wallet/SingleAddressBitcoinWallet.ts +42 -6
  160. package/src/enums/FeeType.ts +7 -0
  161. package/src/enums/SwapAmountType.ts +7 -0
  162. package/src/enums/SwapDirection.ts +7 -0
  163. package/src/enums/SwapType.ts +62 -2
  164. package/src/errors/IntermediaryError.ts +4 -0
  165. package/src/errors/RequestError.ts +15 -1
  166. package/src/errors/UserError.ts +1 -0
  167. package/src/index.ts +6 -5
  168. package/src/intermediaries/Intermediary.ts +57 -10
  169. package/src/intermediaries/IntermediaryDiscovery.ts +60 -27
  170. package/src/prices/RedundantSwapPrice.ts +24 -4
  171. package/src/prices/SingleSwapPrice.ts +10 -7
  172. package/src/prices/SwapPriceWithChain.ts +59 -21
  173. package/src/prices/abstract/ISwapPrice.ts +114 -65
  174. package/src/prices/providers/BinancePriceProvider.ts +7 -0
  175. package/src/prices/providers/CoinGeckoPriceProvider.ts +6 -0
  176. package/src/prices/providers/CoinPaprikaPriceProvider.ts +6 -0
  177. package/src/prices/providers/CustomPriceProvider.ts +11 -0
  178. package/src/prices/providers/KrakenPriceProvider.ts +9 -0
  179. package/src/prices/providers/OKXPriceProvider.ts +6 -0
  180. package/src/prices/providers/abstract/ExchangePriceProvider.ts +3 -0
  181. package/src/storage/IUnifiedStorage.ts +19 -7
  182. package/src/storage/UnifiedSwapStorage.ts +33 -3
  183. package/src/storage-browser/IndexedDBUnifiedStorage.ts +31 -8
  184. package/src/storage-browser/LocalStorageManager.ts +25 -1
  185. package/src/swapper/Swapper.ts +512 -378
  186. package/src/swapper/SwapperFactory.ts +44 -21
  187. package/src/swapper/SwapperUtils.ts +107 -60
  188. package/src/swapper/SwapperWithChain.ts +320 -81
  189. package/src/swapper/SwapperWithSigner.ts +263 -56
  190. package/src/swaps/IAddressSwap.ts +11 -1
  191. package/src/swaps/IBTCWalletSwap.ts +24 -8
  192. package/src/swaps/IClaimableSwap.ts +39 -4
  193. package/src/swaps/IClaimableSwapWrapper.ts +11 -2
  194. package/src/swaps/IRefundableSwap.ts +32 -3
  195. package/src/swaps/ISwap.ts +221 -82
  196. package/src/swaps/ISwapWithGasDrop.ts +6 -0
  197. package/src/swaps/ISwapWrapper.ts +212 -94
  198. package/src/swaps/escrow_swaps/IEscrowSelfInitSwap.ts +62 -18
  199. package/src/swaps/escrow_swaps/IEscrowSwap.ts +83 -37
  200. package/src/swaps/escrow_swaps/IEscrowSwapWrapper.ts +61 -30
  201. package/src/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.ts +37 -19
  202. package/src/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.ts +120 -51
  203. package/src/swaps/escrow_swaps/frombtc/IFromBTCWrapper.ts +24 -11
  204. package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.ts +559 -256
  205. package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.ts +155 -61
  206. package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.ts +590 -226
  207. package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.ts +177 -74
  208. package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.ts +470 -243
  209. package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.ts +141 -59
  210. package/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts +352 -193
  211. package/src/swaps/escrow_swaps/tobtc/IToBTCWrapper.ts +48 -23
  212. package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.ts +86 -39
  213. package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.ts +110 -110
  214. package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.ts +88 -33
  215. package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.ts +101 -31
  216. package/src/swaps/spv_swaps/SpvFromBTCSwap.ts +534 -263
  217. package/src/swaps/spv_swaps/SpvFromBTCWrapper.ts +289 -148
  218. package/src/swaps/trusted/ln/LnForGasSwap.ts +184 -45
  219. package/src/swaps/trusted/ln/LnForGasWrapper.ts +34 -15
  220. package/src/swaps/trusted/onchain/OnchainForGasSwap.ts +260 -86
  221. package/src/swaps/trusted/onchain/OnchainForGasWrapper.ts +41 -19
  222. package/src/types/AmountData.ts +2 -1
  223. package/src/types/CustomPriceFunction.ts +7 -1
  224. package/src/types/SwapExecutionAction.ts +84 -5
  225. package/src/types/SwapWithSigner.ts +7 -3
  226. package/src/types/Token.ts +12 -5
  227. package/src/types/TokenAmount.ts +3 -0
  228. package/src/types/fees/Fee.ts +2 -1
  229. package/src/types/fees/FeeBreakdown.ts +2 -1
  230. package/src/types/fees/PercentagePPM.ts +2 -0
  231. package/src/types/lnurl/LNURLPay.ts +14 -6
  232. package/src/types/lnurl/LNURLWithdraw.ts +12 -5
  233. package/src/types/wallets/LightningInvoiceCreateService.ts +26 -0
  234. package/src/types/wallets/MinimalBitcoinWalletInterface.ts +3 -1
  235. package/src/types/wallets/MinimalLightningNetworkWalletInterface.ts +3 -1
  236. package/src/utils/BitcoinUtils.ts +5 -0
  237. package/src/utils/SwapUtils.ts +61 -1
  238. package/src/utils/TokenUtils.ts +12 -4
  239. package/dist/bitcoin/BitcoinRpcWithAddressIndex.d.ts +0 -68
  240. package/dist/bitcoin/BitcoinRpcWithAddressIndex.js +0 -2
  241. package/dist/bitcoin/LightningNetworkApi.d.ts +0 -12
  242. package/dist/bitcoin/LightningNetworkApi.js +0 -2
  243. package/dist/bitcoin/mempool/MempoolApi.d.ts +0 -350
  244. package/dist/bitcoin/mempool/MempoolApi.js +0 -311
  245. package/dist/bitcoin/mempool/MempoolBitcoinBlock.d.ts +0 -44
  246. package/dist/bitcoin/mempool/MempoolBitcoinBlock.js +0 -48
  247. package/dist/bitcoin/mempool/MempoolBitcoinRpc.d.ts +0 -119
  248. package/dist/bitcoin/mempool/MempoolBitcoinRpc.js +0 -361
  249. package/dist/bitcoin/mempool/synchronizer/MempoolBtcRelaySynchronizer.d.ts +0 -22
  250. package/dist/bitcoin/mempool/synchronizer/MempoolBtcRelaySynchronizer.js +0 -105
  251. package/dist/errors/PaymentAuthError.d.ts +0 -11
  252. package/dist/errors/PaymentAuthError.js +0 -23
  253. package/src/errors/PaymentAuthError.ts +0 -26
@@ -14,83 +14,219 @@ import { BtcToken, SCToken } from "../../../../types/Token";
14
14
  import { LoggerType } from "../../../../utils/Logger";
15
15
  import { LNURLWithdraw } from "../../../../types/lnurl/LNURLWithdraw";
16
16
  /**
17
- * State enum for FromBTCLN swaps
17
+ * State enum for legacy Lightning -> Smart chain swaps
18
18
  * @category Swaps
19
19
  */
20
20
  export declare enum FromBTCLNSwapState {
21
+ /**
22
+ * Swap has failed as the user didn't settle the HTLC on the destination before expiration
23
+ */
21
24
  FAILED = -4,
25
+ /**
26
+ * Swap has expired for good and there is no way how it can be executed anymore
27
+ */
22
28
  QUOTE_EXPIRED = -3,
29
+ /**
30
+ * A swap is almost expired, and it should be presented to the user as expired, though
31
+ * there is still a chance that it will be processed
32
+ */
23
33
  QUOTE_SOFT_EXPIRED = -2,
34
+ /**
35
+ * Swap HTLC on the destination chain has expired, it is not safe anymore to settle (claim) the
36
+ * swap on the destination smart chain.
37
+ */
24
38
  EXPIRED = -1,
39
+ /**
40
+ * Swap quote was created, use {@link FromBTCLNSwap.getAddress} or {@link FromBTCLNSwap.getHyperlink}
41
+ * to get the bolt11 lightning network invoice to pay to initiate the swap, then use the
42
+ * {@link FromBTCLNSwap.waitForPayment} to wait till the lightning network payment is received
43
+ * by the intermediary (LP)
44
+ */
25
45
  PR_CREATED = 0,
46
+ /**
47
+ * Lightning network payment has been received by the intermediary (LP), the user can now settle
48
+ * the swap on the destination smart chain side with {@link FromBTCLNSwap.commitAndClaim} (if
49
+ * the underlying chain supports it - check with {@link FromBTCLNSwap.canCommitAndClaimInOneShot}),
50
+ * or by calling {@link FromBTCLNSwap.commit} and {@link FromBTCLNSwap.claim} separately.
51
+ */
26
52
  PR_PAID = 1,
53
+ /**
54
+ * Swap escrow HTLC has been created on the destination chain. Continue by claiming it with the
55
+ * {@link FromBTCLNSwap.claim} or {@link FromBTCLNSwap.txsClaim} function.
56
+ */
27
57
  CLAIM_COMMITED = 2,
58
+ /**
59
+ * Swap successfully settled and funds received on the destination chain
60
+ */
28
61
  CLAIM_CLAIMED = 3
29
62
  }
30
63
  export type FromBTCLNSwapInit<T extends SwapData> = IEscrowSelfInitSwapInit<T> & {
31
- pr: string;
32
- secret: string;
64
+ pr?: string;
65
+ secret?: string;
33
66
  initialSwapData: T;
34
67
  lnurl?: string;
35
68
  lnurlK1?: string;
36
69
  lnurlCallback?: string;
37
70
  };
38
71
  export declare function isFromBTCLNSwapInit<T extends SwapData>(obj: any): obj is FromBTCLNSwapInit<T>;
72
+ /**
73
+ * Legacy escrow (HTLC) based swap for Bitcoin Lightning -> Smart chains, requires manual settlement
74
+ * of the swap on the destination network once the lightning network payment is received by the LP.
75
+ *
76
+ * @category Swaps
77
+ */
39
78
  export declare class FromBTCLNSwap<T extends ChainType = ChainType> extends IFromBTCSelfInitSwap<T, FromBTCLNDefinition<T>, FromBTCLNSwapState> implements IAddressSwap, IClaimableSwap<T, FromBTCLNDefinition<T>, FromBTCLNSwapState> {
79
+ protected readonly TYPE = SwapType.FROM_BTCLN;
80
+ /**
81
+ * @internal
82
+ */
40
83
  protected readonly logger: LoggerType;
84
+ /**
85
+ * @internal
86
+ */
41
87
  protected readonly inputToken: BtcToken<true>;
42
- protected readonly TYPE = SwapType.FROM_BTCLN;
43
- protected readonly lnurlFailSignal: AbortController;
44
- protected readonly pr: string;
45
- protected readonly secret: string;
46
- protected initialSwapData: T["Data"];
47
- lnurl?: string;
48
- lnurlK1?: string;
49
- lnurlCallback?: string;
50
- prPosted?: boolean;
51
- protected getSwapData(): T["Data"];
88
+ private readonly lnurlFailSignal;
89
+ private readonly usesClaimHashAsId;
90
+ private readonly initialSwapData;
91
+ /**
92
+ * In case the swap is recovered from on-chain data, the pr saved here is just a payment hash,
93
+ * as it is impossible to retrieve the actual lightning network invoice paid purely from on-chain
94
+ * data
95
+ * @private
96
+ */
97
+ private pr?;
98
+ private secret?;
99
+ private lnurl?;
100
+ private lnurlK1?;
101
+ private lnurlCallback?;
102
+ private prPosted?;
103
+ /**
104
+ * Sets the LNURL data for the swap
105
+ *
106
+ * @internal
107
+ */
108
+ _setLNURLData(lnurl: string, lnurlK1: string, lnurlCallback: string): void;
52
109
  constructor(wrapper: FromBTCLNWrapper<T>, init: FromBTCLNSwapInit<T["Data"]>);
53
110
  constructor(wrapper: FromBTCLNWrapper<T>, obj: any);
111
+ /**
112
+ * @inheritDoc
113
+ * @internal
114
+ */
115
+ protected getSwapData(): T["Data"];
116
+ /**
117
+ * @inheritDoc
118
+ * @internal
119
+ */
54
120
  protected upgradeVersion(): void;
121
+ /**
122
+ * @inheritDoc
123
+ * @internal
124
+ */
55
125
  protected getIdentifierHash(): Buffer;
56
- protected getPaymentHash(): Buffer;
126
+ /**
127
+ * Returns the payment hash of the swap and lightning network invoice, or `null` if not known (i.e. if
128
+ * the swap was recovered from on-chain data, the payment hash might not be known)
129
+ *
130
+ * @internal
131
+ */
132
+ protected getPaymentHash(): Buffer | null;
133
+ /**
134
+ * @inheritDoc
135
+ * @internal
136
+ */
57
137
  protected canCommit(): boolean;
138
+ /**
139
+ * @inheritDoc
140
+ */
58
141
  getInputAddress(): string | null;
59
- getInputTxId(): string;
60
142
  /**
61
- * Returns the lightning network BOLT11 invoice that needs to be paid as an input to the swap
143
+ * @inheritDoc
144
+ */
145
+ getInputTxId(): string | null;
146
+ /**
147
+ * Returns the lightning network BOLT11 invoice that needs to be paid as an input to the swap.
148
+ *
149
+ * In case the swap is recovered from on-chain data, the address returned might be just a payment hash,
150
+ * as it is impossible to retrieve the actual lightning network invoice paid purely from on-chain
151
+ * data.
62
152
  */
63
153
  getAddress(): string;
154
+ /**
155
+ * In case the swap is recovered from on-chain data, the address returned might be just a payment hash,
156
+ * as it is impossible to retrieve the actual lightning network invoice paid purely from on-chain
157
+ * data.
158
+ *
159
+ * @inheritDoc
160
+ */
64
161
  getHyperlink(): string;
65
162
  /**
66
163
  * Returns the timeout time (in UNIX milliseconds) when the swap will definitelly be considered as expired
67
164
  * if the LP doesn't make it expired sooner
68
165
  */
69
166
  getDefinitiveExpiryTime(): number;
167
+ /**
168
+ * Returns timeout time (in UNIX milliseconds) when the swap htlc will expire
169
+ */
170
+ getHtlcTimeoutTime(): number | null;
70
171
  /**
71
172
  * Returns timeout time (in UNIX milliseconds) when the LN invoice will expire
72
173
  */
73
174
  getTimeoutTime(): number;
74
175
  /**
75
- * Returns timeout time (in UNIX milliseconds) when the swap htlc will expire
176
+ * @inheritDoc
76
177
  */
77
- getHtlcTimeoutTime(): number;
78
178
  isFinished(): boolean;
179
+ /**
180
+ * @inheritDoc
181
+ */
79
182
  isClaimable(): boolean;
183
+ /**
184
+ * @inheritDoc
185
+ */
80
186
  isSuccessful(): boolean;
187
+ /**
188
+ * @inheritDoc
189
+ */
81
190
  isFailed(): boolean;
191
+ /**
192
+ * @inheritDoc
193
+ */
82
194
  isQuoteExpired(): boolean;
195
+ /**
196
+ * @inheritDoc
197
+ */
83
198
  isQuoteSoftExpired(): boolean;
199
+ /**
200
+ * @inheritDoc
201
+ * @internal
202
+ */
84
203
  _verifyQuoteDefinitelyExpired(): Promise<boolean>;
85
- verifyQuoteValid(): Promise<boolean>;
204
+ /**
205
+ * @inheritDoc
206
+ * @internal
207
+ */
208
+ _verifyQuoteValid(): Promise<boolean>;
209
+ /**
210
+ * @inheritDoc
211
+ */
86
212
  getInputToken(): BtcToken<true>;
213
+ /**
214
+ * @inheritDoc
215
+ */
87
216
  getInput(): TokenAmount<T["ChainId"], BtcToken<true>>;
217
+ /**
218
+ * @inheritDoc
219
+ */
88
220
  getSmartChainNetworkFee(): Promise<TokenAmount<T["ChainId"], SCToken<T["ChainId"]>, true>>;
221
+ /**
222
+ * @inheritDoc
223
+ */
89
224
  hasEnoughForTxFees(): Promise<{
90
225
  enoughBalance: boolean;
91
226
  balance: TokenAmount<T["ChainId"], SCToken<T["ChainId"]>, true>;
92
227
  required: TokenAmount<T["ChainId"], SCToken<T["ChainId"]>, true>;
93
228
  }>;
229
+ private isValidSecretPreimage;
94
230
  /**
95
231
  * Executes the swap with the provided bitcoin lightning network wallet or LNURL
96
232
  *
@@ -101,6 +237,8 @@ export declare class FromBTCLNSwap<T extends ChainType = ChainType> extends IFro
101
237
  * link, wallet is not required and the LN invoice can be paid externally as well (just pass null or undefined here)
102
238
  * @param callbacks Callbacks to track the progress of the swap
103
239
  * @param options Optional options for the swap like feeRate, AbortSignal, and timeouts/intervals
240
+ * @param secret A swap secret to use for the claim transaction, generally only needed if the swap
241
+ * was recovered from on-chain data, or the pre-image was generated outside the SDK
104
242
  */
105
243
  execute(dstSigner: T["Signer"] | T["NativeSigner"], walletOrLnurlWithdraw?: MinimalLightningNetworkWalletInterface | LNURLWithdraw | string | null | undefined, callbacks?: {
106
244
  onSourceTransactionReceived?: (sourceTxId: string) => void;
@@ -111,14 +249,25 @@ export declare class FromBTCLNSwap<T extends ChainType = ChainType> extends IFro
111
249
  abortSignal?: AbortSignal;
112
250
  lightningTxCheckIntervalSeconds?: number;
113
251
  delayBetweenCommitAndClaimSeconds?: number;
114
- }): Promise<void>;
252
+ }, secret?: string): Promise<void>;
253
+ /**
254
+ * @inheritDoc
255
+ *
256
+ * @param options
257
+ * @param options.skipChecks Skip checks like making sure init signature is still valid and swap
258
+ * wasn't commited yet (this is handled on swap creation, if you commit right after quoting, you
259
+ * can use `skipChecks=true`)
260
+ * @param secret A swap secret to use for the claim transaction, generally only needed if the swap
261
+ * was recovered from on-chain data, or the pre-image was generated outside the SDK
262
+ */
115
263
  txsExecute(options?: {
116
264
  skipChecks?: boolean;
117
- }): Promise<{
265
+ }, secret?: string): Promise<{
118
266
  name: "Payment";
119
267
  description: string;
120
- chain: string;
268
+ chain: "LIGHTNING";
121
269
  txs: {
270
+ type: "BOLT11_PAYMENT_REQUEST";
122
271
  address: string;
123
272
  hyperlink: string;
124
273
  }[];
@@ -137,6 +286,8 @@ export declare class FromBTCLNSwap<T extends ChainType = ChainType> extends IFro
137
286
  * Checks whether the LP received the LN payment and we can continue by committing & claiming the HTLC on-chain
138
287
  *
139
288
  * @param save If the new swap state should be saved
289
+ *
290
+ * @internal
140
291
  */
141
292
  _checkIntermediaryPaymentReceived(save?: boolean): Promise<boolean | null>;
142
293
  /**
@@ -145,108 +296,142 @@ export declare class FromBTCLNSwap<T extends ChainType = ChainType> extends IFro
145
296
  * @param signer Smart chain signer's address initiating the swap
146
297
  * @param data Parsed swap data as returned by the intermediary
147
298
  * @param signature Signature data as returned by the intermediary
148
- * @protected
299
+ *
149
300
  * @throws {IntermediaryError} If the returned are not valid
150
301
  * @throws {SignatureVerificationError} If the returned signature is not valid
151
302
  * @throws {Error} If the swap is already committed on-chain
303
+ *
304
+ * @internal
152
305
  */
153
306
  protected checkIntermediaryReturnedAuthData(signer: string, data: T["Data"], signature: SignatureData): Promise<void>;
154
307
  /**
155
- * Waits till an LN payment is received by the intermediary and client can continue commiting & claiming the HTLC
308
+ * Waits till a lightning network payment is received by the intermediary and client
309
+ * can continue by initiating (committing) & settling (claiming) the HTLC by calling
310
+ * either the {@link commitAndClaim} function (if the underlying chain allows commit
311
+ * and claim in a single transaction - check with {@link canCommitAndClaimInOneShot}).
312
+ * Or call {@link commit} and then {@link claim} separately.
313
+ *
314
+ * If this swap is using an LNURL-withdraw link as input, it automatically posts the
315
+ * generated invoice to the LNURL service to pay it.
156
316
  *
157
317
  * @param onPaymentReceived Callback as for when the LP reports having received the ln payment
158
318
  * @param abortSignal Abort signal to stop waiting for payment
159
- * @param checkIntervalSeconds How often to poll the intermediary for answer
319
+ * @param checkIntervalSeconds How often to poll the intermediary for answer (default 5 seconds)
160
320
  */
161
321
  waitForPayment(onPaymentReceived?: (txId: string) => void, checkIntervalSeconds?: number, abortSignal?: AbortSignal): Promise<boolean>;
162
322
  /**
163
- * Commits the swap on-chain, locking the tokens from the intermediary in an HTLC
323
+ * @inheritDoc
164
324
  *
165
- * @param _signer Signer to sign the transactions with, must be the same as used in the initialization
166
- * @param abortSignal Abort signal to stop waiting for the transaction confirmation and abort
167
- * @param skipChecks Skip checks like making sure init signature is still valid and swap wasn't commited yet
168
- * (this is handled when swap is created (quoted), if you commit right after quoting, you can use skipChecks=true)
169
- * @param onBeforeTxSent
170
325
  * @throws {Error} If invalid signer is provided that doesn't match the swap data
171
326
  */
172
327
  commit(_signer: T["Signer"] | T["NativeSigner"], abortSignal?: AbortSignal, skipChecks?: boolean, onBeforeTxSent?: (txId: string) => void): Promise<string>;
328
+ /**
329
+ * @inheritDoc
330
+ */
173
331
  waitTillCommited(abortSignal?: AbortSignal): Promise<void>;
174
332
  /**
175
333
  * Unsafe txs claim getter without state checking!
176
334
  *
177
335
  * @param _signer
178
- * @private
336
+ * @param secret A swap secret to use for the claim transaction, generally only needed if the swap
337
+ * was recovered from on-chain data, or the pre-image was generated outside the SDK
338
+ *
339
+ * @internal
179
340
  */
180
341
  private _txsClaim;
181
342
  /**
182
- * Returns transactions required for claiming the HTLC and finishing the swap by revealing the HTLC secret
183
- * (hash preimage)
343
+ * @inheritDoc
184
344
  *
185
345
  * @param _signer Optional signer address to use for claiming the swap, can also be different from the initializer
186
- * @throws {Error} If in invalid state (must be CLAIM_COMMITED)
346
+ * @param secret A swap secret to use for the claim transaction, generally only needed if the swap
347
+ * was recovered from on-chain data, or the pre-image was generated outside the SDK
348
+ *
349
+ * @throws {Error} If in invalid state (must be {@link FromBTCLNSwapState.CLAIM_COMMITED})
187
350
  */
188
- txsClaim(_signer?: T["Signer"] | T["NativeSigner"]): Promise<T["TX"][]>;
351
+ txsClaim(_signer?: T["Signer"] | T["NativeSigner"], secret?: string): Promise<T["TX"][]>;
189
352
  /**
190
- * Claims and finishes the swap
353
+ * @inheritDoc
191
354
  *
192
- * @param _signer Signer to sign the transactions with, can also be different to the initializer
193
- * @param abortSignal Abort signal to stop waiting for transaction confirmation
355
+ * @param _signer
356
+ * @param abortSignal
194
357
  * @param onBeforeTxSent
358
+ * @param secret A swap secret to use for the claim transaction, generally only needed if the swap
359
+ * was recovered from on-chain data, or the pre-image was generated outside the SDK
195
360
  */
196
- claim(_signer: T["Signer"] | T["NativeSigner"], abortSignal?: AbortSignal, onBeforeTxSent?: (txId: string) => void): Promise<string>;
361
+ claim(_signer: T["Signer"] | T["NativeSigner"], abortSignal?: AbortSignal, onBeforeTxSent?: (txId: string) => void, secret?: string): Promise<string>;
197
362
  /**
198
- * Waits till the swap is successfully claimed
363
+ * @inheritDoc
199
364
  *
200
- * @param maxWaitTimeSeconds Maximum time in seconds to wait for the swap to be settled
201
- * @param abortSignal AbortSignal
202
- * @throws {Error} If swap is in invalid state (must be BTC_TX_CONFIRMED)
365
+ * @throws {Error} If swap is in invalid state (must be {@link FromBTCLNSwapState.CLAIM_COMMITED})
203
366
  * @throws {Error} If the LP refunded sooner than we were able to claim
204
367
  * @returns {boolean} whether the swap was claimed in time or not
205
368
  */
206
369
  waitTillClaimed(maxWaitTimeSeconds?: number, abortSignal?: AbortSignal): Promise<boolean>;
207
370
  /**
208
- * Estimated transaction fee for commit & claim txs combined
371
+ * Estimated transaction fee for commit & claim transactions combined, required
372
+ * to settle the swap on the smart chain destination side.
373
+ */
374
+ getCommitAndClaimNetworkFee(): Promise<TokenAmount<T["ChainId"], SCToken<T["ChainId"]>, true>>;
375
+ /**
376
+ * Returns whether the underlying chain supports calling commit and claim in a single call,
377
+ * such that you can use the {@link commitAndClaim} function. If not you have to manually
378
+ * call {@link commit} first and then {@link claim}.
209
379
  */
210
- getCommitAndClaimFee(): Promise<bigint>;
211
380
  canCommitAndClaimInOneShot(): boolean;
212
381
  /**
213
382
  * Returns transactions for both commit & claim operation together, such that they can be signed all at once by
214
- * the wallet. CAUTION: transactions must be sent sequentially, such that the claim (2nd) transaction is only
383
+ * the wallet. **WARNING**: transactions must be sent sequentially, such that the claim (2nd) transaction is only
215
384
  * sent after the commit (1st) transaction confirms. Failure to do so can reveal the HTLC pre-image too soon,
216
- * opening a possibility for the LP to steal funds.
385
+ * opening a possibility for the LP to steal funds!
217
386
  *
218
387
  * @param skipChecks Skip checks like making sure init signature is still valid and swap wasn't commited yet
219
388
  * (this is handled when swap is created (quoted), if you commit right after quoting, you can use skipChecks=true)
389
+ * @param secret A swap secret to use for the claim transaction, generally only needed if the swap
390
+ * was recovered from on-chain data, or the pre-image was generated outside the SDK
220
391
  *
221
392
  * @throws {Error} If in invalid state (must be PR_PAID or CLAIM_COMMITED)
222
393
  */
223
- txsCommitAndClaim(skipChecks?: boolean): Promise<T["TX"][]>;
394
+ txsCommitAndClaim(skipChecks?: boolean, secret?: string): Promise<T["TX"][]>;
224
395
  /**
225
- * Commits and claims the swap, in a way that the transactions can be signed together by the underlying provider and
226
- * then sent sequentially
396
+ * Commits and claims the swap, in a way that the transactions can be signed together by the provided signer and
397
+ * then automatically sent sequentially by the SDK. To check if the underlying chain supports this flow check
398
+ * the {@link canCommitAndClaimInOneShot} function.
227
399
  *
228
400
  * @param _signer Signer to sign the transactions with, must be the same as used in the initialization
229
401
  * @param abortSignal Abort signal to stop waiting for the transaction confirmation and abort
230
402
  * @param skipChecks Skip checks like making sure init signature is still valid and swap wasn't commited yet
231
403
  * (this is handled when swap is created (quoted), if you commit right after quoting, you can use skipChecks=true)
232
- * @param onBeforeCommitTxSent
233
- * @param onBeforeClaimTxSent
404
+ * @param onBeforeCommitTxSent Optional callback called before the initialization (commit) transaction is
405
+ * broadcasted
406
+ * @param onBeforeClaimTxSent Optional callback called before the settlement (claim) transaction is
407
+ * broadcasted
408
+ * @param secret A swap secret to use for the claim transaction, generally only needed if the swap
409
+ * was recovered from on-chain data, or the pre-image was generated outside the SDK
410
+ *
234
411
  * @throws {Error} If in invalid state (must be PR_PAID or CLAIM_COMMITED)
235
412
  * @throws {Error} If invalid signer is provided that doesn't match the swap data
236
413
  */
237
- commitAndClaim(_signer: T["Signer"] | T["NativeSigner"], abortSignal?: AbortSignal, skipChecks?: boolean, onBeforeCommitTxSent?: (txId: string) => void, onBeforeClaimTxSent?: (txId: string) => void): Promise<string[]>;
414
+ commitAndClaim(_signer: T["Signer"] | T["NativeSigner"], abortSignal?: AbortSignal, skipChecks?: boolean, onBeforeCommitTxSent?: (txId: string) => void, onBeforeClaimTxSent?: (txId: string) => void, secret?: string): Promise<string[]>;
238
415
  /**
239
- * Is this an LNURL-withdraw swap?
416
+ * Whether this swap uses an LNURL-withdraw link
240
417
  */
241
418
  isLNURL(): boolean;
242
419
  /**
243
- * Gets the used LNURL or null if this is not an LNURL-withdraw swap
420
+ * Gets the used LNURL or `null` if this is not an LNURL-withdraw swap
244
421
  */
245
422
  getLNURL(): string | null;
246
423
  /**
247
- * Pay the generated lightning network invoice with LNURL-withdraw
424
+ * Pay the generated lightning network invoice with an LNURL-withdraw link, this
425
+ * is useful when you want to display a lightning payment QR code and also want to
426
+ * allow payments using LNURL-withdraw NFC cards.
427
+ *
428
+ * Note that the swap needs to be created **without** an LNURL to begin with for this function
429
+ * to work. If this swap is already using an LNURL-withdraw link, this function throws.
248
430
  */
249
431
  settleWithLNURLWithdraw(lnurl: string | LNURLWithdraw): Promise<void>;
432
+ /**
433
+ * @inheritDoc
434
+ */
250
435
  serialize(): any;
251
436
  /**
252
437
  * Checks the swap's state on-chain and compares it to its internal state, updates/changes it according to on-chain
@@ -255,9 +440,41 @@ export declare class FromBTCLNSwap<T extends ChainType = ChainType> extends IFro
255
440
  * @private
256
441
  */
257
442
  private syncStateFromChain;
443
+ /**
444
+ * @inheritDoc
445
+ * @internal
446
+ */
258
447
  _shouldFetchExpiryStatus(): boolean;
259
- _shouldFetchCommitStatus(): boolean;
448
+ /**
449
+ * @inheritDoc
450
+ * @internal
451
+ */
452
+ _shouldFetchOnchainState(): boolean;
453
+ /**
454
+ * Whether an intermediary (LP) should be contacted to get the state of this swap.
455
+ *
456
+ * @internal
457
+ */
260
458
  _shouldCheckIntermediary(): boolean;
459
+ /**
460
+ * @inheritDoc
461
+ * @internal
462
+ */
261
463
  _sync(save?: boolean, quoteDefinitelyExpired?: boolean, commitStatus?: SwapCommitState, skipLpCheck?: boolean): Promise<boolean>;
464
+ /**
465
+ * @inheritDoc
466
+ * @internal
467
+ */
468
+ _forciblySetOnchainState(commitStatus: SwapCommitState): Promise<boolean>;
469
+ /**
470
+ * @inheritDoc
471
+ * @internal
472
+ */
262
473
  _tick(save?: boolean): Promise<boolean>;
474
+ /**
475
+ * Forcibly sets the swap secret pre-image from on-chain data
476
+ *
477
+ * @internal
478
+ */
479
+ _setSwapSecret(secret: string): void;
263
480
  }