@atomiqlabs/sdk 8.1.8 → 8.3.5

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 (261) hide show
  1. package/dist/bitcoin/coinselect2/utils.d.ts +6 -0
  2. package/dist/bitcoin/wallet/BitcoinWallet.d.ts +41 -5
  3. package/dist/bitcoin/wallet/BitcoinWallet.js +36 -1
  4. package/dist/bitcoin/wallet/IBitcoinWallet.d.ts +52 -2
  5. package/dist/bitcoin/wallet/IBitcoinWallet.js +2 -1
  6. package/dist/bitcoin/wallet/SingleAddressBitcoinWallet.d.ts +42 -7
  7. package/dist/bitcoin/wallet/SingleAddressBitcoinWallet.js +36 -1
  8. package/dist/enums/FeeType.d.ts +8 -1
  9. package/dist/enums/FeeType.js +8 -1
  10. package/dist/enums/SwapAmountType.d.ts +7 -0
  11. package/dist/enums/SwapAmountType.js +7 -0
  12. package/dist/enums/SwapDirection.d.ts +7 -0
  13. package/dist/enums/SwapDirection.js +7 -0
  14. package/dist/enums/SwapType.d.ts +62 -1
  15. package/dist/enums/SwapType.js +62 -1
  16. package/dist/errors/IntermediaryError.d.ts +4 -0
  17. package/dist/errors/IntermediaryError.js +1 -0
  18. package/dist/errors/RequestError.d.ts +15 -1
  19. package/dist/errors/RequestError.js +8 -0
  20. package/dist/errors/UserError.d.ts +1 -0
  21. package/dist/errors/UserError.js +1 -0
  22. package/dist/index.d.ts +5 -5
  23. package/dist/index.js +7 -6
  24. package/dist/intermediaries/Intermediary.d.ts +61 -14
  25. package/dist/intermediaries/Intermediary.js +38 -11
  26. package/dist/intermediaries/IntermediaryDiscovery.d.ts +62 -29
  27. package/dist/intermediaries/IntermediaryDiscovery.js +39 -24
  28. package/dist/prices/RedundantSwapPrice.d.ts +26 -5
  29. package/dist/prices/RedundantSwapPrice.js +22 -2
  30. package/dist/prices/SingleSwapPrice.d.ts +10 -7
  31. package/dist/prices/SingleSwapPrice.js +11 -8
  32. package/dist/prices/SwapPriceWithChain.d.ts +56 -19
  33. package/dist/prices/SwapPriceWithChain.js +62 -25
  34. package/dist/prices/abstract/IPriceProvider.d.ts +4 -4
  35. package/dist/prices/abstract/IPriceProvider.js +1 -1
  36. package/dist/prices/abstract/ISwapPrice.d.ts +95 -46
  37. package/dist/prices/abstract/ISwapPrice.js +104 -56
  38. package/dist/prices/providers/BinancePriceProvider.d.ts +8 -1
  39. package/dist/prices/providers/BinancePriceProvider.js +8 -1
  40. package/dist/prices/providers/CoinGeckoPriceProvider.d.ts +7 -1
  41. package/dist/prices/providers/CoinGeckoPriceProvider.js +7 -1
  42. package/dist/prices/providers/CoinPaprikaPriceProvider.d.ts +7 -1
  43. package/dist/prices/providers/CoinPaprikaPriceProvider.js +7 -1
  44. package/dist/prices/providers/CustomPriceProvider.d.ts +12 -1
  45. package/dist/prices/providers/CustomPriceProvider.js +12 -1
  46. package/dist/prices/providers/KrakenPriceProvider.d.ts +10 -1
  47. package/dist/prices/providers/KrakenPriceProvider.js +10 -1
  48. package/dist/prices/providers/OKXPriceProvider.d.ts +7 -1
  49. package/dist/prices/providers/OKXPriceProvider.js +7 -1
  50. package/dist/prices/providers/abstract/ExchangePriceProvider.d.ts +3 -0
  51. package/dist/prices/providers/abstract/ExchangePriceProvider.js +3 -0
  52. package/dist/storage/IUnifiedStorage.d.ts +19 -7
  53. package/dist/storage/UnifiedSwapStorage.d.ts +33 -3
  54. package/dist/storage/UnifiedSwapStorage.js +29 -1
  55. package/dist/storage-browser/IndexedDBUnifiedStorage.d.ts +31 -7
  56. package/dist/storage-browser/IndexedDBUnifiedStorage.js +29 -6
  57. package/dist/storage-browser/LocalStorageManager.d.ts +25 -1
  58. package/dist/storage-browser/LocalStorageManager.js +25 -1
  59. package/dist/swapper/Swapper.d.ts +380 -226
  60. package/dist/swapper/Swapper.js +383 -349
  61. package/dist/swapper/SwapperFactory.d.ts +66 -18
  62. package/dist/swapper/SwapperFactory.js +24 -3
  63. package/dist/swapper/SwapperUtils.d.ts +75 -28
  64. package/dist/swapper/SwapperUtils.js +107 -60
  65. package/dist/swapper/SwapperWithChain.d.ts +286 -91
  66. package/dist/swapper/SwapperWithChain.js +218 -64
  67. package/dist/swapper/SwapperWithSigner.d.ts +229 -80
  68. package/dist/swapper/SwapperWithSigner.js +190 -44
  69. package/dist/swaps/IAddressSwap.d.ts +12 -3
  70. package/dist/swaps/IAddressSwap.js +3 -2
  71. package/dist/swaps/IBTCWalletSwap.d.ts +26 -8
  72. package/dist/swaps/IBTCWalletSwap.js +3 -2
  73. package/dist/swaps/IClaimableSwap.d.ts +38 -6
  74. package/dist/swaps/IClaimableSwap.js +3 -2
  75. package/dist/swaps/IClaimableSwapWrapper.d.ts +11 -1
  76. package/dist/swaps/IRefundableSwap.d.ts +31 -5
  77. package/dist/swaps/IRefundableSwap.js +3 -2
  78. package/dist/swaps/ISwap.d.ts +162 -24
  79. package/dist/swaps/ISwap.js +92 -35
  80. package/dist/swaps/ISwapWithGasDrop.d.ts +8 -2
  81. package/dist/swaps/ISwapWithGasDrop.js +2 -1
  82. package/dist/swaps/ISwapWrapper.d.ts +161 -52
  83. package/dist/swaps/ISwapWrapper.js +131 -73
  84. package/dist/swaps/escrow_swaps/IEscrowSelfInitSwap.d.ts +51 -6
  85. package/dist/swaps/escrow_swaps/IEscrowSelfInitSwap.js +22 -12
  86. package/dist/swaps/escrow_swaps/IEscrowSwap.d.ts +65 -12
  87. package/dist/swaps/escrow_swaps/IEscrowSwap.js +38 -19
  88. package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.d.ts +39 -9
  89. package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.js +30 -21
  90. package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.d.ts +31 -15
  91. package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.js +33 -18
  92. package/dist/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.d.ts +97 -28
  93. package/dist/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.js +91 -27
  94. package/dist/swaps/escrow_swaps/frombtc/IFromBTCWrapper.d.ts +22 -9
  95. package/dist/swaps/escrow_swaps/frombtc/IFromBTCWrapper.js +24 -11
  96. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.d.ts +278 -60
  97. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.js +519 -241
  98. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.d.ts +77 -26
  99. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.js +132 -50
  100. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.d.ts +313 -52
  101. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.js +544 -194
  102. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.d.ts +87 -26
  103. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.js +147 -58
  104. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.d.ts +222 -55
  105. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.js +462 -244
  106. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.d.ts +77 -23
  107. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.js +116 -46
  108. package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.d.ts +195 -58
  109. package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.js +324 -191
  110. package/dist/swaps/escrow_swaps/tobtc/IToBTCWrapper.d.ts +30 -5
  111. package/dist/swaps/escrow_swaps/tobtc/IToBTCWrapper.js +44 -19
  112. package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.d.ts +61 -20
  113. package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.js +75 -32
  114. package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.d.ts +76 -50
  115. package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.js +106 -101
  116. package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.d.ts +37 -14
  117. package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.js +66 -20
  118. package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.d.ts +46 -17
  119. package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.js +82 -27
  120. package/dist/swaps/spv_swaps/SpvFromBTCSwap.d.ts +350 -88
  121. package/dist/swaps/spv_swaps/SpvFromBTCSwap.js +482 -215
  122. package/dist/swaps/spv_swaps/SpvFromBTCWrapper.d.ts +76 -24
  123. package/dist/swaps/spv_swaps/SpvFromBTCWrapper.js +247 -124
  124. package/dist/swaps/trusted/ln/LnForGasSwap.d.ts +148 -20
  125. package/dist/swaps/trusted/ln/LnForGasSwap.js +175 -45
  126. package/dist/swaps/trusted/ln/LnForGasWrapper.d.ts +29 -10
  127. package/dist/swaps/trusted/ln/LnForGasWrapper.js +30 -11
  128. package/dist/swaps/trusted/onchain/OnchainForGasSwap.d.ts +202 -49
  129. package/dist/swaps/trusted/onchain/OnchainForGasSwap.js +232 -80
  130. package/dist/swaps/trusted/onchain/OnchainForGasWrapper.d.ts +34 -12
  131. package/dist/swaps/trusted/onchain/OnchainForGasWrapper.js +33 -14
  132. package/dist/types/AmountData.d.ts +2 -1
  133. package/dist/types/CustomPriceFunction.d.ts +8 -2
  134. package/dist/types/PriceInfoType.d.ts +4 -4
  135. package/dist/types/PriceInfoType.js +3 -3
  136. package/dist/types/SwapExecutionAction.d.ts +85 -4
  137. package/dist/types/SwapWithSigner.d.ts +5 -2
  138. package/dist/types/SwapWithSigner.js +5 -2
  139. package/dist/types/Token.d.ts +11 -5
  140. package/dist/types/Token.js +6 -3
  141. package/dist/types/TokenAmount.d.ts +3 -0
  142. package/dist/types/TokenAmount.js +2 -0
  143. package/dist/types/fees/Fee.d.ts +3 -2
  144. package/dist/types/fees/FeeBreakdown.d.ts +3 -2
  145. package/dist/types/fees/PercentagePPM.d.ts +4 -2
  146. package/dist/types/fees/PercentagePPM.js +2 -1
  147. package/dist/types/lnurl/LNURLPay.d.ts +20 -12
  148. package/dist/types/lnurl/LNURLPay.js +8 -4
  149. package/dist/types/lnurl/LNURLWithdraw.d.ts +17 -10
  150. package/dist/types/lnurl/LNURLWithdraw.js +8 -4
  151. package/dist/types/wallets/LightningInvoiceCreateService.d.ts +24 -0
  152. package/dist/types/wallets/LightningInvoiceCreateService.js +15 -0
  153. package/dist/types/wallets/MinimalBitcoinWalletInterface.d.ts +3 -1
  154. package/dist/types/wallets/MinimalLightningNetworkWalletInterface.d.ts +4 -2
  155. package/dist/utils/BitcoinUtils.d.ts +1 -0
  156. package/dist/utils/BitcoinUtils.js +5 -1
  157. package/dist/utils/SwapUtils.d.ts +58 -1
  158. package/dist/utils/SwapUtils.js +55 -1
  159. package/dist/utils/TokenUtils.d.ts +10 -2
  160. package/dist/utils/TokenUtils.js +12 -4
  161. package/package.json +3 -3
  162. package/src/bitcoin/coinselect2/utils.ts +6 -0
  163. package/src/bitcoin/wallet/BitcoinWallet.ts +41 -5
  164. package/src/bitcoin/wallet/IBitcoinWallet.ts +57 -2
  165. package/src/bitcoin/wallet/SingleAddressBitcoinWallet.ts +42 -6
  166. package/src/enums/FeeType.ts +8 -1
  167. package/src/enums/SwapAmountType.ts +7 -0
  168. package/src/enums/SwapDirection.ts +7 -0
  169. package/src/enums/SwapType.ts +62 -2
  170. package/src/errors/IntermediaryError.ts +4 -0
  171. package/src/errors/RequestError.ts +15 -1
  172. package/src/errors/UserError.ts +1 -0
  173. package/src/index.ts +12 -5
  174. package/src/intermediaries/Intermediary.ts +61 -14
  175. package/src/intermediaries/IntermediaryDiscovery.ts +69 -34
  176. package/src/prices/RedundantSwapPrice.ts +26 -6
  177. package/src/prices/SingleSwapPrice.ts +11 -8
  178. package/src/prices/SwapPriceWithChain.ts +63 -26
  179. package/src/prices/abstract/IPriceProvider.ts +4 -4
  180. package/src/prices/abstract/ISwapPrice.ts +115 -66
  181. package/src/prices/providers/BinancePriceProvider.ts +8 -1
  182. package/src/prices/providers/CoinGeckoPriceProvider.ts +7 -1
  183. package/src/prices/providers/CoinPaprikaPriceProvider.ts +7 -1
  184. package/src/prices/providers/CustomPriceProvider.ts +12 -1
  185. package/src/prices/providers/KrakenPriceProvider.ts +10 -1
  186. package/src/prices/providers/OKXPriceProvider.ts +7 -1
  187. package/src/prices/providers/abstract/ExchangePriceProvider.ts +3 -0
  188. package/src/storage/IUnifiedStorage.ts +19 -7
  189. package/src/storage/UnifiedSwapStorage.ts +33 -3
  190. package/src/storage-browser/IndexedDBUnifiedStorage.ts +31 -8
  191. package/src/storage-browser/LocalStorageManager.ts +25 -1
  192. package/src/swapper/Swapper.ts +599 -390
  193. package/src/swapper/SwapperFactory.ts +73 -24
  194. package/src/swapper/SwapperUtils.ts +107 -60
  195. package/src/swapper/SwapperWithChain.ts +320 -81
  196. package/src/swapper/SwapperWithSigner.ts +263 -56
  197. package/src/swaps/IAddressSwap.ts +13 -3
  198. package/src/swaps/IBTCWalletSwap.ts +26 -10
  199. package/src/swaps/IClaimableSwap.ts +41 -6
  200. package/src/swaps/IClaimableSwapWrapper.ts +11 -2
  201. package/src/swaps/IRefundableSwap.ts +34 -5
  202. package/src/swaps/ISwap.ts +224 -85
  203. package/src/swaps/ISwapWithGasDrop.ts +8 -2
  204. package/src/swaps/ISwapWrapper.ts +216 -98
  205. package/src/swaps/escrow_swaps/IEscrowSelfInitSwap.ts +64 -18
  206. package/src/swaps/escrow_swaps/IEscrowSwap.ts +83 -37
  207. package/src/swaps/escrow_swaps/IEscrowSwapWrapper.ts +61 -30
  208. package/src/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.ts +37 -19
  209. package/src/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.ts +123 -50
  210. package/src/swaps/escrow_swaps/frombtc/IFromBTCWrapper.ts +24 -11
  211. package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.ts +562 -258
  212. package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.ts +156 -62
  213. package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.ts +592 -227
  214. package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.ts +177 -74
  215. package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.ts +483 -245
  216. package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.ts +141 -59
  217. package/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts +350 -195
  218. package/src/swaps/escrow_swaps/tobtc/IToBTCWrapper.ts +48 -23
  219. package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.ts +87 -40
  220. package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.ts +110 -110
  221. package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.ts +89 -34
  222. package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.ts +101 -31
  223. package/src/swaps/spv_swaps/SpvFromBTCSwap.ts +556 -259
  224. package/src/swaps/spv_swaps/SpvFromBTCWrapper.ts +292 -148
  225. package/src/swaps/trusted/ln/LnForGasSwap.ts +186 -47
  226. package/src/swaps/trusted/ln/LnForGasWrapper.ts +34 -15
  227. package/src/swaps/trusted/onchain/OnchainForGasSwap.ts +262 -88
  228. package/src/swaps/trusted/onchain/OnchainForGasWrapper.ts +41 -19
  229. package/src/types/AmountData.ts +2 -1
  230. package/src/types/CustomPriceFunction.ts +8 -2
  231. package/src/types/PriceInfoType.ts +4 -4
  232. package/src/types/SwapExecutionAction.ts +97 -5
  233. package/src/types/SwapWithSigner.ts +8 -4
  234. package/src/types/Token.ts +12 -5
  235. package/src/types/TokenAmount.ts +3 -0
  236. package/src/types/fees/Fee.ts +3 -2
  237. package/src/types/fees/FeeBreakdown.ts +3 -2
  238. package/src/types/fees/PercentagePPM.ts +4 -2
  239. package/src/types/lnurl/LNURLPay.ts +20 -12
  240. package/src/types/lnurl/LNURLWithdraw.ts +17 -10
  241. package/src/types/wallets/LightningInvoiceCreateService.ts +30 -0
  242. package/src/types/wallets/MinimalBitcoinWalletInterface.ts +3 -1
  243. package/src/types/wallets/MinimalLightningNetworkWalletInterface.ts +4 -2
  244. package/src/utils/BitcoinUtils.ts +5 -0
  245. package/src/utils/SwapUtils.ts +63 -1
  246. package/src/utils/TokenUtils.ts +12 -4
  247. package/dist/bitcoin/BitcoinRpcWithAddressIndex.d.ts +0 -68
  248. package/dist/bitcoin/BitcoinRpcWithAddressIndex.js +0 -2
  249. package/dist/bitcoin/LightningNetworkApi.d.ts +0 -12
  250. package/dist/bitcoin/LightningNetworkApi.js +0 -2
  251. package/dist/bitcoin/mempool/MempoolApi.d.ts +0 -350
  252. package/dist/bitcoin/mempool/MempoolApi.js +0 -311
  253. package/dist/bitcoin/mempool/MempoolBitcoinBlock.d.ts +0 -44
  254. package/dist/bitcoin/mempool/MempoolBitcoinBlock.js +0 -48
  255. package/dist/bitcoin/mempool/MempoolBitcoinRpc.d.ts +0 -119
  256. package/dist/bitcoin/mempool/MempoolBitcoinRpc.js +0 -361
  257. package/dist/bitcoin/mempool/synchronizer/MempoolBtcRelaySynchronizer.d.ts +0 -22
  258. package/dist/bitcoin/mempool/synchronizer/MempoolBtcRelaySynchronizer.js +0 -105
  259. package/dist/errors/PaymentAuthError.d.ts +0 -11
  260. package/dist/errors/PaymentAuthError.js +0 -23
  261. package/src/errors/PaymentAuthError.ts +0 -26
@@ -1,6 +1,7 @@
1
1
  /**
2
- * LNURL-withdraw request parameters
3
- * @category Bitcoin
2
+ * Response of the LNURL-withdraw link
3
+ *
4
+ * @category Lightning
4
5
  */
5
6
  export type LNURLWithdrawParams = {
6
7
  tag: "withdrawRequest";
@@ -14,15 +15,17 @@ export type LNURLWithdrawParams = {
14
15
  payLink?: string;
15
16
  };
16
17
  /**
17
- * LNURL-withdraw parameters with URL
18
- * @category Bitcoin
18
+ * Response of the LNURL-withdraw link with the added original url
19
+ *
20
+ * @category Lightning
19
21
  */
20
22
  export type LNURLWithdrawParamsWithUrl = LNURLWithdrawParams & {
21
23
  url: string;
22
24
  };
23
25
  /**
24
- * LNURL-withdraw specification
25
- * @category Bitcoin
26
+ * Parsed LNURL-withdraw specification
27
+ *
28
+ * @category Lightning
26
29
  */
27
30
  export type LNURLWithdraw = {
28
31
  type: "withdraw";
@@ -31,12 +34,16 @@ export type LNURLWithdraw = {
31
34
  params: LNURLWithdrawParamsWithUrl;
32
35
  };
33
36
  /**
34
- * Type guard for LNURL-withdraw
35
- * @category Bitcoin
37
+ * Type guard for {@link LNURLWithdraw}
38
+ *
39
+ * @category Lightning
40
+ * @internal
36
41
  */
37
42
  export declare function isLNURLWithdraw(value: any): value is LNURLWithdraw;
38
43
  /**
39
- * Type guard for LNURL-withdraw parameters
40
- * @category Bitcoin
44
+ * Type guard for {@link LNURLWithdrawParams}
45
+ *
46
+ * @category Lightning
47
+ * @internal
41
48
  */
42
49
  export declare function isLNURLWithdrawParams(obj: any): obj is LNURLWithdrawParams;
@@ -2,8 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isLNURLWithdrawParams = exports.isLNURLWithdraw = void 0;
4
4
  /**
5
- * Type guard for LNURL-withdraw
6
- * @category Bitcoin
5
+ * Type guard for {@link LNURLWithdraw}
6
+ *
7
+ * @category Lightning
8
+ * @internal
7
9
  */
8
10
  function isLNURLWithdraw(value) {
9
11
  return (typeof value === "object" &&
@@ -15,8 +17,10 @@ function isLNURLWithdraw(value) {
15
17
  }
16
18
  exports.isLNURLWithdraw = isLNURLWithdraw;
17
19
  /**
18
- * Type guard for LNURL-withdraw parameters
19
- * @category Bitcoin
20
+ * Type guard for {@link LNURLWithdrawParams}
21
+ *
22
+ * @category Lightning
23
+ * @internal
20
24
  */
21
25
  function isLNURLWithdrawParams(obj) {
22
26
  return obj.tag === "withdrawRequest";
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Invoice getter callback for the {@link LightningInvoiceCreateService}
3
+ *
4
+ * @category Lightning
5
+ */
6
+ export type LightningWalletCallback = (valueSats: number, abortSignal?: AbortSignal) => Promise<string>;
7
+ /**
8
+ * Service that creates on-demand fixed amount bolt11 lightning network invoices, optionally
9
+ * specifying minimum and maximum swappable sats amount. This used for exact input Smart chain ->
10
+ * Lightning swaps.
11
+ *
12
+ * @category Lightning
13
+ */
14
+ export type LightningInvoiceCreateService = {
15
+ getInvoice: LightningWalletCallback;
16
+ minMsats?: bigint;
17
+ maxMSats?: bigint;
18
+ };
19
+ /**
20
+ * Type guard for {@link LightningInvoiceCreateService}
21
+ *
22
+ * @internal
23
+ */
24
+ export declare function isLightningInvoiceCreateService(obj: any): obj is LightningInvoiceCreateService;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isLightningInvoiceCreateService = void 0;
4
+ /**
5
+ * Type guard for {@link LightningInvoiceCreateService}
6
+ *
7
+ * @internal
8
+ */
9
+ function isLightningInvoiceCreateService(obj) {
10
+ return typeof (obj) === "object" &&
11
+ typeof (obj.getInvoice) === "function" &&
12
+ (obj.minMsats == null || typeof (obj.minMsats) === "bigint") &&
13
+ (obj.maxMSats == null || typeof (obj.maxMSats) === "bigint");
14
+ }
15
+ exports.isLightningInvoiceCreateService = isLightningInvoiceCreateService;
@@ -1,7 +1,8 @@
1
1
  import { Transaction } from "@scure/btc-signer";
2
2
  /**
3
3
  * A type with minimum possible required data about a bitcoin wallet to be able to estimate fees and produce unsigned
4
- * PSBTs
4
+ * funded PSBTs with address's UTXOs
5
+ *
5
6
  * @category Bitcoin
6
7
  */
7
8
  export type MinimalBitcoinWalletInterface = {
@@ -10,6 +11,7 @@ export type MinimalBitcoinWalletInterface = {
10
11
  };
11
12
  /**
12
13
  * A type with minimum possible required data about a bitcoin wallet to be able to estimate fees and sign PSBTs
14
+ *
13
15
  * @category Bitcoin
14
16
  */
15
17
  export type MinimalBitcoinWalletInterfaceWithSigner = MinimalBitcoinWalletInterface & {
@@ -1,6 +1,8 @@
1
1
  /**
2
- * A type with minimum possible required functionality to be usable with lightning network swaps
3
- * @category Bitcoin
2
+ * A type with minimum possible required functionality to be usable with lightning network swaps, i.e.
3
+ * a function to pay bolt11 lightning network invoices.
4
+ *
5
+ * @category Lightning
4
6
  */
5
7
  export type MinimalLightningNetworkWalletInterface = {
6
8
  payInvoice: (bolt11PaymentRequest: string) => Promise<string>;
@@ -4,6 +4,7 @@ import { BTC_NETWORK } from "@scure/btc-signer/utils";
4
4
  import { Buffer } from "buffer";
5
5
  import { Transaction } from "@scure/btc-signer";
6
6
  import { CoinselectAddressTypes } from "../bitcoin/coinselect2";
7
+ export declare function fromOutputScript(network: BTC_NETWORK, outputScriptHex: string): string;
7
8
  export declare function toOutputScript(network: BTC_NETWORK, address: string): Buffer;
8
9
  export declare function toCoinselectAddressType(outputScript: Uint8Array): CoinselectAddressTypes;
9
10
  /**
@@ -1,9 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parsePsbtTransaction = exports.toCoinselectAddressType = exports.toOutputScript = void 0;
3
+ exports.parsePsbtTransaction = exports.toCoinselectAddressType = exports.toOutputScript = exports.fromOutputScript = void 0;
4
4
  const utils_1 = require("@scure/btc-signer/utils");
5
5
  const buffer_1 = require("buffer");
6
6
  const btc_signer_1 = require("@scure/btc-signer");
7
+ function fromOutputScript(network, outputScriptHex) {
8
+ return (0, btc_signer_1.Address)(network).encode(btc_signer_1.OutScript.decode(buffer_1.Buffer.from(outputScriptHex, "hex")));
9
+ }
10
+ exports.fromOutputScript = fromOutputScript;
7
11
  function toOutputScript(network, address) {
8
12
  const outputScript = (0, btc_signer_1.Address)(network).decode(address);
9
13
  switch (outputScript.type) {
@@ -11,7 +11,10 @@ import { OnchainForGasSwap } from "../swaps/trusted/onchain/OnchainForGasSwap";
11
11
  import { LnForGasSwap } from "../swaps/trusted/ln/LnForGasSwap";
12
12
  import { ISwap } from "../swaps/ISwap";
13
13
  /**
14
- * Type mapping from SwapType enum to specific swap class implementations
14
+ * Type mapping from SwapType enum to specific swap class implementations, it is important
15
+ * to pass the chain type generic, since different chains support different swap protocols
16
+ * for some directions.
17
+ *
15
18
  * @category Utilities
16
19
  */
17
20
  export type SwapTypeMapping<T extends ChainType> = {
@@ -26,6 +29,60 @@ export type SwapTypeMapping<T extends ChainType> = {
26
29
  };
27
30
  /**
28
31
  * Type guard to check if a swap is of a specific swap type
32
+ *
29
33
  * @category Utilities
30
34
  */
31
35
  export declare function isSwapType<T extends ChainType, S extends SwapType>(swap: ISwap<T>, swapType: S): swap is SwapTypeMapping<T>[S];
36
+ /**
37
+ * Helper information about various swap protocol and their features:
38
+ * - `requiresInputWallet`: Whether a swap requires a connected wallet on the input chain able to sign
39
+ * arbitrary transaction
40
+ * - `requiresOutputWallet`: Whether a swap requires a connected wallet on the output chain able to sign
41
+ * arbitrary transactions
42
+ * - `supportsGasDrop`: Whether a swap supports the "gas drop" feature, allowing to user to receive a small
43
+ * amount of native token as part of the swap when swapping to smart chains
44
+ *
45
+ * @category Core
46
+ */
47
+ export declare const SwapProtocolInfo: {
48
+ readonly 2: {
49
+ readonly requiresInputWallet: true;
50
+ readonly requiresOutputWallet: false;
51
+ readonly supportsGasDrop: false;
52
+ };
53
+ readonly 3: {
54
+ readonly requiresInputWallet: true;
55
+ readonly requiresOutputWallet: false;
56
+ readonly supportsGasDrop: false;
57
+ };
58
+ readonly 0: {
59
+ readonly requiresInputWallet: false;
60
+ readonly requiresOutputWallet: true;
61
+ readonly supportsGasDrop: false;
62
+ };
63
+ readonly 1: {
64
+ readonly requiresInputWallet: false;
65
+ readonly requiresOutputWallet: true;
66
+ readonly supportsGasDrop: false;
67
+ };
68
+ readonly 6: {
69
+ readonly requiresInputWallet: true;
70
+ readonly requiresOutputWallet: false;
71
+ readonly supportsGasDrop: true;
72
+ };
73
+ readonly 7: {
74
+ readonly requiresInputWallet: false;
75
+ readonly requiresOutputWallet: false;
76
+ readonly supportsGasDrop: true;
77
+ };
78
+ readonly 4: {
79
+ readonly requiresInputWallet: false;
80
+ readonly requiresOutputWallet: false;
81
+ readonly supportsGasDrop: false;
82
+ };
83
+ readonly 5: {
84
+ readonly requiresInputWallet: false;
85
+ readonly requiresOutputWallet: false;
86
+ readonly supportsGasDrop: false;
87
+ };
88
+ };
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isSwapType = void 0;
3
+ exports.SwapProtocolInfo = exports.isSwapType = void 0;
4
4
  const SwapType_1 = require("../enums/SwapType");
5
5
  /**
6
6
  * Type guard to check if a swap is of a specific swap type
7
+ *
7
8
  * @category Utilities
8
9
  */
9
10
  function isSwapType(swap, swapType) {
@@ -16,3 +17,56 @@ function isSwapType(swap, swapType) {
16
17
  return swap.getType() === swapType;
17
18
  }
18
19
  exports.isSwapType = isSwapType;
20
+ /**
21
+ * Helper information about various swap protocol and their features:
22
+ * - `requiresInputWallet`: Whether a swap requires a connected wallet on the input chain able to sign
23
+ * arbitrary transaction
24
+ * - `requiresOutputWallet`: Whether a swap requires a connected wallet on the output chain able to sign
25
+ * arbitrary transactions
26
+ * - `supportsGasDrop`: Whether a swap supports the "gas drop" feature, allowing to user to receive a small
27
+ * amount of native token as part of the swap when swapping to smart chains
28
+ *
29
+ * @category Core
30
+ */
31
+ exports.SwapProtocolInfo = {
32
+ [SwapType_1.SwapType.TO_BTC]: {
33
+ requiresInputWallet: true,
34
+ requiresOutputWallet: false,
35
+ supportsGasDrop: false
36
+ },
37
+ [SwapType_1.SwapType.TO_BTCLN]: {
38
+ requiresInputWallet: true,
39
+ requiresOutputWallet: false,
40
+ supportsGasDrop: false
41
+ },
42
+ [SwapType_1.SwapType.FROM_BTC]: {
43
+ requiresInputWallet: false,
44
+ requiresOutputWallet: true,
45
+ supportsGasDrop: false
46
+ },
47
+ [SwapType_1.SwapType.FROM_BTCLN]: {
48
+ requiresInputWallet: false,
49
+ requiresOutputWallet: true,
50
+ supportsGasDrop: false
51
+ },
52
+ [SwapType_1.SwapType.SPV_VAULT_FROM_BTC]: {
53
+ requiresInputWallet: true,
54
+ requiresOutputWallet: false,
55
+ supportsGasDrop: true
56
+ },
57
+ [SwapType_1.SwapType.FROM_BTCLN_AUTO]: {
58
+ requiresInputWallet: false,
59
+ requiresOutputWallet: false,
60
+ supportsGasDrop: true
61
+ },
62
+ [SwapType_1.SwapType.TRUSTED_FROM_BTC]: {
63
+ requiresInputWallet: false,
64
+ requiresOutputWallet: false,
65
+ supportsGasDrop: false
66
+ },
67
+ [SwapType_1.SwapType.TRUSTED_FROM_BTCLN]: {
68
+ requiresInputWallet: false,
69
+ requiresOutputWallet: false,
70
+ supportsGasDrop: false
71
+ }
72
+ };
@@ -1,11 +1,19 @@
1
1
  import { Token } from "../types/Token";
2
2
  /**
3
3
  * Converts a raw bigint amount to a human-readable string with decimals
4
+ *
5
+ * @param amount Amount in base units
6
+ * @param token Token
7
+ *
4
8
  * @category Utilities
5
9
  */
6
- export declare function toHumanReadableString(amount: bigint, currencySpec: Token): string;
10
+ export declare function toHumanReadableString(amount: bigint, token: Token): string;
7
11
  /**
8
12
  * Parses a human-readable decimal string to a raw bigint amount
13
+ *
14
+ * @param amount Amount in base units
15
+ * @param token Token
16
+ *
9
17
  * @category Utilities
10
18
  */
11
- export declare function fromHumanReadableString(amount: string, currencySpec: Token): bigint | null;
19
+ export declare function fromHumanReadableString(amount: string, token: Token): bigint | null;
@@ -4,23 +4,31 @@ exports.fromHumanReadableString = exports.toHumanReadableString = void 0;
4
4
  const Utils_1 = require("./Utils");
5
5
  /**
6
6
  * Converts a raw bigint amount to a human-readable string with decimals
7
+ *
8
+ * @param amount Amount in base units
9
+ * @param token Token
10
+ *
7
11
  * @category Utilities
8
12
  */
9
- function toHumanReadableString(amount, currencySpec) {
13
+ function toHumanReadableString(amount, token) {
10
14
  if (amount == null)
11
15
  return "";
12
- return (0, Utils_1.toDecimal)(amount, currencySpec.decimals, undefined, currencySpec.displayDecimals);
16
+ return (0, Utils_1.toDecimal)(amount, token.decimals, undefined, token.displayDecimals);
13
17
  }
14
18
  exports.toHumanReadableString = toHumanReadableString;
15
19
  /**
16
20
  * Parses a human-readable decimal string to a raw bigint amount
21
+ *
22
+ * @param amount Amount in base units
23
+ * @param token Token
24
+ *
17
25
  * @category Utilities
18
26
  */
19
- function fromHumanReadableString(amount, currencySpec) {
27
+ function fromHumanReadableString(amount, token) {
20
28
  if (amount === "" || amount == null)
21
29
  return null;
22
30
  try {
23
- return (0, Utils_1.fromDecimal)(amount, currencySpec.decimals);
31
+ return (0, Utils_1.fromDecimal)(amount, token.decimals);
24
32
  }
25
33
  catch (e) {
26
34
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atomiqlabs/sdk",
3
- "version": "8.1.8",
3
+ "version": "8.3.5",
4
4
  "description": "atomiq labs SDK for cross-chain swaps between smart chains and bitcoin",
5
5
  "main": "./dist/index.js",
6
6
  "types:": "./dist/index.d.ts",
@@ -23,9 +23,9 @@
23
23
  "author": "adambor",
24
24
  "license": "ISC",
25
25
  "dependencies": {
26
- "@atomiqlabs/base": "^13.1.4",
26
+ "@atomiqlabs/base": "^13.1.9",
27
27
  "@atomiqlabs/bolt11": "1.6.1",
28
- "@atomiqlabs/btc-mempool": "^1.0.3",
28
+ "@atomiqlabs/btc-mempool": "^1.0.4",
29
29
  "@atomiqlabs/messenger-nostr": "^2.0.0",
30
30
  "@noble/ciphers": "^1.2.1",
31
31
  "@noble/hashes": "^1.7.1",
@@ -25,6 +25,12 @@ const TX_OUTPUT_P2WPKH = 22;
25
25
  const TX_OUTPUT_P2WSH = 34;
26
26
  const TX_OUTPUT_P2TR = 34;
27
27
 
28
+ /**
29
+ * Defines a type of the address used by the wallet, for proper coinselection (as coinselection
30
+ * depends on estimating the cost for spending the input + the cost of adding a change output)
31
+ *
32
+ * @category Bitcoin
33
+ */
28
34
  export type CoinselectAddressTypes = "p2sh-p2wpkh" | "p2wpkh" | "p2wsh" | "p2tr" | "p2pkh";
29
35
 
30
36
  export type CoinselectTxInput = {
@@ -11,6 +11,7 @@ import {BitcoinRpcWithAddressIndex} from "@atomiqlabs/base";
11
11
 
12
12
  /**
13
13
  * UTXO data structure for Bitcoin wallets
14
+ *
14
15
  * @category Bitcoin
15
16
  */
16
17
  export type BitcoinWalletUtxo = {
@@ -29,6 +30,7 @@ export type BitcoinWalletUtxo = {
29
30
 
30
31
  /**
31
32
  * Identifies the address type of a Bitcoin address
33
+ *
32
34
  * @category Bitcoin
33
35
  */
34
36
  export function identifyAddressType(address: string, network: BTC_NETWORK): CoinselectAddressTypes {
@@ -51,15 +53,17 @@ export function identifyAddressType(address: string, network: BTC_NETWORK): Coin
51
53
  const logger = getLogger("BitcoinWallet: ");
52
54
 
53
55
  /**
54
- * Abstract base class for Bitcoin wallet implementations
56
+ * Abstract base class for Bitcoin wallet implementations, using bitcoin rpc with address index
57
+ * as a backend for fetching balances, UTXOs, etc.
58
+ *
55
59
  * @category Bitcoin
56
60
  */
57
61
  export abstract class BitcoinWallet implements IBitcoinWallet {
58
62
 
59
- rpc: BitcoinRpcWithAddressIndex<any>;
60
- network: BTC_NETWORK;
61
- feeMultiplier: number;
62
- feeOverride?: number;
63
+ protected readonly rpc: BitcoinRpcWithAddressIndex<any>;
64
+ protected readonly network: BTC_NETWORK;
65
+ protected feeMultiplier: number;
66
+ protected feeOverride?: number;
63
67
 
64
68
  constructor(mempoolApi: BitcoinRpcWithAddressIndex<any>, network: BTC_NETWORK, feeMultiplier: number = 1.25, feeOverride?: number) {
65
69
  this.rpc = mempoolApi;
@@ -68,6 +72,9 @@ export abstract class BitcoinWallet implements IBitcoinWallet {
68
72
  this.feeOverride = feeOverride;
69
73
  }
70
74
 
75
+ /**
76
+ * @inheritDoc
77
+ */
71
78
  async getFeeRate(): Promise<number> {
72
79
  if(this.feeOverride!=null) {
73
80
  return this.feeOverride;
@@ -75,14 +82,35 @@ export abstract class BitcoinWallet implements IBitcoinWallet {
75
82
  return Math.floor((await this.rpc.getFeeRate())*this.feeMultiplier);
76
83
  }
77
84
 
85
+ /**
86
+ * Internal helper function for sending a raw transaction through the underlying RPC
87
+ *
88
+ * @param rawHex Serialized bitcoin transaction in hexadecimal format
89
+ * @returns txId Transaction ID of the submitted bitcoin transaction
90
+ *
91
+ * @protected
92
+ */
78
93
  protected _sendTransaction(rawHex: string): Promise<string> {
79
94
  return this.rpc.sendRawTransaction(rawHex);
80
95
  }
81
96
 
97
+ /**
98
+ * Internal helper function for fetching the balance of the wallet given a specific bitcoin wallet address
99
+ *
100
+ * @param address
101
+ * @protected
102
+ */
82
103
  protected _getBalance(address: string): Promise<{ confirmedBalance: bigint; unconfirmedBalance: bigint }> {
83
104
  return this.rpc.getAddressBalances(address);
84
105
  }
85
106
 
107
+ /**
108
+ * Internal helper function for fetching the UTXO set of a given wallet address
109
+ *
110
+ * @param sendingAddress
111
+ * @param sendingAddressType
112
+ * @protected
113
+ */
86
114
  protected async _getUtxoPool(
87
115
  sendingAddress: string,
88
116
  sendingAddressType: CoinselectAddressTypes
@@ -121,6 +149,14 @@ export abstract class BitcoinWallet implements IBitcoinWallet {
121
149
  return utxoPool;
122
150
  }
123
151
 
152
+ /**
153
+ *
154
+ * @param sendingAccounts
155
+ * @param recipient
156
+ * @param amount
157
+ * @param feeRate
158
+ * @protected
159
+ */
124
160
  protected async _getPsbt(
125
161
  sendingAccounts: {
126
162
  pubkey: string,
@@ -1,7 +1,8 @@
1
1
  import {Transaction} from "@scure/btc-signer";
2
2
 
3
3
  /**
4
- * Type guard to check if an object implements IBitcoinWallet
4
+ * Type guard to check if an object implements {@link IBitcoinWallet}
5
+ *
5
6
  * @category Bitcoin
6
7
  */
7
8
  export function isIBitcoinWallet(val: any): val is IBitcoinWallet {
@@ -18,24 +19,78 @@ export function isIBitcoinWallet(val: any): val is IBitcoinWallet {
18
19
  }
19
20
 
20
21
  /**
21
- * Interface for Bitcoin wallet operations
22
+ * Interface to be implemented by Bitcoin wallets
23
+ *
22
24
  * @category Bitcoin
23
25
  */
24
26
  export interface IBitcoinWallet {
27
+ /**
28
+ * Signs and broadcasts a transaction sending `amount` of sats to `address`, optionally with the
29
+ * `feeRate` sats/vB fee rate.
30
+ *
31
+ * @param address Destination address of the transaction
32
+ * @param amount Amount of satoshis to send (1 BTC = 100,000,000 sats)
33
+ * @param feeRate Optional fee rate in sats/vB to use for the transaction
34
+ */
25
35
  sendTransaction(address: string, amount: bigint, feeRate?: number): Promise<string>;
36
+
37
+ /**
38
+ * Funds (populates the inputs) for a given PSBT from wallet's UTXO set
39
+ *
40
+ * @param psbt PSBT to add the inputs to
41
+ * @param feeRate Optional fee rate in sats/vB to use for the transaction
42
+ */
26
43
  fundPsbt(psbt: Transaction, feeRate?: number): Promise<Transaction>;
44
+
45
+ /**
46
+ * Signs inputs in the provided PSBT
47
+ *
48
+ * @param psbt A PSBT to sign
49
+ * @param signInputs Indices of the inputs to sign
50
+ */
27
51
  signPsbt(psbt: Transaction, signInputs: number[]): Promise<Transaction>;
28
52
 
53
+ /**
54
+ * Returns the current fee rate in sats/vB
55
+ */
29
56
  getFeeRate(): Promise<number>;
30
57
 
58
+ /**
59
+ * Estimates a total fee in satoshis for a given transaction
60
+ *
61
+ * @param address Destination address of the transaction
62
+ * @param amount Amount of satoshis to send (1 BTC = 100,000,000 sats)
63
+ * @param feeRate Optional fee rate in sats/vB to use for the transaction
64
+ */
31
65
  getTransactionFee(address: string, amount: bigint, feeRate?: number): Promise<number>;
66
+
67
+ /**
68
+ * Estimates a total fee in satoshis for a given transaction as identified by the PSBT
69
+ *
70
+ * @param psbt A PSBT to which additional inputs from wallet's UTXO set will be added and fee estimated
71
+ * @param feeRate Optional fee rate in sats/vB to use for the transaction
72
+ */
32
73
  getFundedPsbtFee(psbt: Transaction, feeRate?: number): Promise<number>;
33
74
 
75
+ /**
76
+ * Returns the bitcoin address suitable for receiving funds
77
+ */
34
78
  getReceiveAddress(): string;
79
+
80
+ /**
81
+ * Returns confirmed and unconfirmed balance in satoshis of the wallet
82
+ */
35
83
  getBalance(): Promise<{
36
84
  confirmedBalance: bigint,
37
85
  unconfirmedBalance: bigint
38
86
  }>;
87
+
88
+ /**
89
+ * Returns the maximum spendable balance in satoshis given a specific PSBT that should be funded
90
+ *
91
+ * @param psbt A PSBT to which additional inputs from wallet's UTXO set will be added and fee estimated
92
+ * @param feeRate Optional fee rate in sats/vB to use for the transaction
93
+ */
39
94
  getSpendableBalance(psbt?: Transaction, feeRate?: number): Promise<{
40
95
  balance: bigint,
41
96
  feeRate: number,