@atomiqlabs/sdk 7.0.11 → 8.0.7
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.
- package/README.md +45 -29
- package/dist/SmartChainAssets.d.ts +11 -3
- package/dist/SmartChainAssets.js +7 -3
- package/dist/bitcoin/BitcoinRpcWithAddressIndex.d.ts +68 -0
- package/dist/bitcoin/BitcoinRpcWithAddressIndex.js +2 -0
- package/dist/bitcoin/LightningNetworkApi.d.ts +12 -0
- package/dist/bitcoin/LightningNetworkApi.js +2 -0
- package/dist/bitcoin/coinselect2/accumulative.d.ts +6 -0
- package/dist/bitcoin/coinselect2/accumulative.js +52 -0
- package/dist/bitcoin/coinselect2/blackjack.d.ts +6 -0
- package/dist/bitcoin/coinselect2/blackjack.js +38 -0
- package/dist/bitcoin/coinselect2/index.d.ts +19 -0
- package/dist/bitcoin/coinselect2/index.js +69 -0
- package/dist/bitcoin/coinselect2/utils.d.ts +71 -0
- package/dist/bitcoin/coinselect2/utils.js +123 -0
- package/dist/bitcoin/mempool/MempoolApi.d.ts +350 -0
- package/dist/bitcoin/mempool/MempoolApi.js +311 -0
- package/dist/bitcoin/mempool/MempoolBitcoinBlock.d.ts +44 -0
- package/dist/bitcoin/mempool/MempoolBitcoinBlock.js +48 -0
- package/dist/bitcoin/mempool/MempoolBitcoinRpc.d.ts +119 -0
- package/dist/bitcoin/mempool/MempoolBitcoinRpc.js +361 -0
- package/dist/bitcoin/mempool/synchronizer/MempoolBtcRelaySynchronizer.d.ts +22 -0
- package/dist/bitcoin/mempool/synchronizer/MempoolBtcRelaySynchronizer.js +105 -0
- package/dist/bitcoin/wallet/BitcoinWallet.d.ts +93 -0
- package/dist/bitcoin/wallet/BitcoinWallet.js +273 -0
- package/dist/bitcoin/wallet/IBitcoinWallet.d.ts +28 -0
- package/dist/bitcoin/wallet/IBitcoinWallet.js +20 -0
- package/dist/bitcoin/wallet/MinimalBitcoinWalletInterface.d.ts +21 -0
- package/dist/bitcoin/wallet/MinimalBitcoinWalletInterface.js +2 -0
- package/dist/bitcoin/wallet/MinimalLightningNetworkWalletInterface.d.ts +7 -0
- package/dist/bitcoin/wallet/MinimalLightningNetworkWalletInterface.js +2 -0
- package/dist/bitcoin/wallet/SingleAddressBitcoinWallet.d.ts +40 -0
- package/dist/bitcoin/wallet/SingleAddressBitcoinWallet.js +86 -0
- package/dist/enums/FeeType.d.ts +8 -0
- package/dist/enums/FeeType.js +12 -0
- package/dist/enums/SwapAmountType.d.ts +8 -0
- package/dist/enums/SwapAmountType.js +12 -0
- package/dist/enums/SwapDirection.d.ts +8 -0
- package/dist/enums/SwapDirection.js +12 -0
- package/dist/enums/SwapType.d.ts +14 -0
- package/dist/enums/SwapType.js +18 -0
- package/dist/errors/IntermediaryError.d.ts +9 -0
- package/dist/errors/IntermediaryError.js +26 -0
- package/dist/errors/PaymentAuthError.d.ts +11 -0
- package/dist/errors/PaymentAuthError.js +23 -0
- package/dist/errors/RequestError.d.ts +18 -0
- package/dist/errors/RequestError.js +46 -0
- package/dist/errors/UserError.d.ts +7 -0
- package/dist/errors/UserError.js +15 -0
- package/dist/events/UnifiedSwapEventListener.d.ts +23 -0
- package/dist/events/UnifiedSwapEventListener.js +130 -0
- package/dist/http/HttpUtils.d.ts +27 -0
- package/dist/http/HttpUtils.js +91 -0
- package/dist/http/paramcoders/IParamReader.d.ts +8 -0
- package/dist/http/paramcoders/IParamReader.js +2 -0
- package/dist/http/paramcoders/ParamDecoder.d.ts +44 -0
- package/dist/http/paramcoders/ParamDecoder.js +132 -0
- package/dist/http/paramcoders/ParamEncoder.d.ts +20 -0
- package/dist/http/paramcoders/ParamEncoder.js +31 -0
- package/dist/http/paramcoders/SchemaVerifier.d.ts +26 -0
- package/dist/http/paramcoders/SchemaVerifier.js +145 -0
- package/dist/http/paramcoders/client/ResponseParamDecoder.d.ts +11 -0
- package/dist/http/paramcoders/client/ResponseParamDecoder.js +57 -0
- package/dist/http/paramcoders/client/StreamParamEncoder.d.ts +13 -0
- package/dist/http/paramcoders/client/StreamParamEncoder.js +26 -0
- package/dist/http/paramcoders/client/StreamingFetchPromise.d.ts +16 -0
- package/dist/http/paramcoders/client/StreamingFetchPromise.js +174 -0
- package/dist/index.d.ts +82 -4
- package/dist/index.js +128 -4
- package/dist/intermediaries/Intermediary.d.ts +111 -0
- package/dist/intermediaries/Intermediary.js +115 -0
- package/dist/intermediaries/IntermediaryDiscovery.d.ts +166 -0
- package/dist/intermediaries/IntermediaryDiscovery.js +390 -0
- package/dist/intermediaries/apis/IntermediaryAPI.d.ts +436 -0
- package/dist/intermediaries/apis/IntermediaryAPI.js +600 -0
- package/dist/intermediaries/apis/TrustedIntermediaryAPI.d.ts +154 -0
- package/dist/intermediaries/apis/TrustedIntermediaryAPI.js +136 -0
- package/dist/lnurl/LNURL.d.ts +102 -0
- package/dist/lnurl/LNURL.js +321 -0
- package/dist/prices/RedundantSwapPrice.d.ts +89 -0
- package/dist/prices/RedundantSwapPrice.js +202 -0
- package/dist/prices/SingleSwapPrice.d.ts +31 -0
- package/dist/prices/SingleSwapPrice.js +41 -0
- package/dist/prices/SwapPriceWithChain.d.ts +70 -0
- package/dist/prices/SwapPriceWithChain.js +91 -0
- package/dist/prices/abstract/ICachedSwapPrice.d.ts +28 -0
- package/dist/prices/abstract/ICachedSwapPrice.js +62 -0
- package/dist/prices/abstract/IPriceProvider.d.ts +81 -0
- package/dist/prices/abstract/IPriceProvider.js +74 -0
- package/dist/prices/abstract/ISwapPrice.d.ts +117 -0
- package/dist/prices/abstract/ISwapPrice.js +219 -0
- package/dist/prices/providers/BinancePriceProvider.d.ts +16 -0
- package/dist/prices/providers/BinancePriceProvider.js +23 -0
- package/dist/prices/providers/CoinGeckoPriceProvider.d.ts +17 -0
- package/dist/prices/providers/CoinGeckoPriceProvider.js +23 -0
- package/dist/prices/providers/CoinPaprikaPriceProvider.d.ts +19 -0
- package/dist/prices/providers/CoinPaprikaPriceProvider.js +23 -0
- package/dist/prices/providers/CustomPriceProvider.d.ts +13 -0
- package/dist/prices/providers/CustomPriceProvider.js +24 -0
- package/dist/prices/providers/KrakenPriceProvider.d.ts +29 -0
- package/dist/prices/providers/KrakenPriceProvider.js +36 -0
- package/dist/prices/providers/OKXPriceProvider.d.ts +28 -0
- package/dist/prices/providers/OKXPriceProvider.js +23 -0
- package/dist/prices/providers/abstract/ExchangePriceProvider.d.ts +14 -0
- package/dist/prices/providers/abstract/ExchangePriceProvider.js +18 -0
- package/dist/prices/providers/abstract/HttpPriceProvider.d.ts +7 -0
- package/dist/prices/providers/abstract/HttpPriceProvider.js +12 -0
- package/dist/storage/IUnifiedStorage.d.ts +73 -0
- package/dist/storage/IUnifiedStorage.js +2 -0
- package/dist/storage/UnifiedSwapStorage.d.ts +82 -0
- package/dist/storage/UnifiedSwapStorage.js +83 -0
- package/dist/storage-browser/IndexedDBUnifiedStorage.d.ts +39 -0
- package/dist/storage-browser/IndexedDBUnifiedStorage.js +275 -0
- package/dist/{storage → storage-browser}/LocalStorageManager.d.ts +1 -0
- package/dist/{storage → storage-browser}/LocalStorageManager.js +2 -1
- package/dist/swapper/Swapper.d.ts +533 -0
- package/dist/swapper/Swapper.js +1566 -0
- package/dist/swapper/SwapperFactory.d.ts +87 -0
- package/dist/{SwapperFactory.js → swapper/SwapperFactory.js} +40 -22
- package/dist/swapper/SwapperUtils.d.ts +153 -0
- package/dist/swapper/SwapperUtils.js +420 -0
- package/dist/swapper/SwapperWithChain.d.ts +214 -0
- package/dist/swapper/SwapperWithChain.js +315 -0
- package/dist/swapper/SwapperWithSigner.d.ts +178 -0
- package/dist/swapper/SwapperWithSigner.js +172 -0
- package/dist/swaps/IAddressSwap.d.ts +13 -0
- package/dist/swaps/IAddressSwap.js +13 -0
- package/dist/swaps/IBTCWalletSwap.d.ts +55 -0
- package/dist/swaps/IBTCWalletSwap.js +17 -0
- package/dist/swaps/IClaimableSwap.d.ts +17 -0
- package/dist/swaps/IClaimableSwap.js +14 -0
- package/dist/swaps/IClaimableSwapWrapper.d.ts +5 -0
- package/dist/swaps/IClaimableSwapWrapper.js +2 -0
- package/dist/swaps/IRefundableSwap.d.ts +17 -0
- package/dist/swaps/IRefundableSwap.js +13 -0
- package/dist/swaps/ISwap.d.ts +207 -0
- package/dist/swaps/ISwap.js +264 -0
- package/dist/swaps/ISwapWithGasDrop.d.ts +15 -0
- package/dist/swaps/ISwapWithGasDrop.js +11 -0
- package/dist/swaps/ISwapWrapper.d.ts +153 -0
- package/dist/swaps/ISwapWrapper.js +227 -0
- package/dist/swaps/escrow_swaps/IEscrowSelfInitSwap.d.ts +53 -0
- package/dist/swaps/escrow_swaps/IEscrowSelfInitSwap.js +116 -0
- package/dist/swaps/escrow_swaps/IEscrowSwap.d.ts +70 -0
- package/dist/swaps/escrow_swaps/IEscrowSwap.js +132 -0
- package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.d.ts +85 -0
- package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.js +122 -0
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.d.ts +86 -0
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.js +115 -0
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.d.ts +93 -0
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.js +121 -0
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCWrapper.d.ts +45 -0
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCWrapper.js +65 -0
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.d.ts +263 -0
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.js +933 -0
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.d.ts +110 -0
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.js +307 -0
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.d.ts +236 -0
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.js +898 -0
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.d.ts +125 -0
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.js +393 -0
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.d.ts +245 -0
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.js +841 -0
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.d.ts +120 -0
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.js +294 -0
- package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.d.ts +228 -0
- package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.js +721 -0
- package/dist/swaps/escrow_swaps/tobtc/IToBTCWrapper.d.ts +37 -0
- package/dist/swaps/escrow_swaps/tobtc/IToBTCWrapper.js +93 -0
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.d.ts +86 -0
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.js +213 -0
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.d.ts +170 -0
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.js +520 -0
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.d.ts +50 -0
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.js +109 -0
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.d.ts +93 -0
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.js +217 -0
- package/dist/swaps/spv_swaps/SpvFromBTCSwap.d.ts +315 -0
- package/dist/swaps/spv_swaps/SpvFromBTCSwap.js +1098 -0
- package/dist/swaps/spv_swaps/SpvFromBTCWrapper.d.ts +125 -0
- package/dist/swaps/spv_swaps/SpvFromBTCWrapper.js +631 -0
- package/dist/swaps/trusted/ln/LnForGasSwap.d.ts +107 -0
- package/dist/swaps/trusted/ln/LnForGasSwap.js +343 -0
- package/dist/swaps/trusted/ln/LnForGasWrapper.d.ts +21 -0
- package/dist/swaps/trusted/ln/LnForGasWrapper.js +62 -0
- package/dist/swaps/trusted/onchain/OnchainForGasSwap.d.ts +164 -0
- package/dist/swaps/trusted/onchain/OnchainForGasSwap.js +520 -0
- package/dist/swaps/trusted/onchain/OnchainForGasWrapper.d.ts +48 -0
- package/dist/swaps/trusted/onchain/OnchainForGasWrapper.js +74 -0
- package/dist/types/AmountData.d.ts +9 -0
- package/dist/types/AmountData.js +2 -0
- package/dist/types/CustomPriceFunction.d.ts +5 -0
- package/dist/types/CustomPriceFunction.js +2 -0
- package/dist/types/PriceInfoType.d.ts +28 -0
- package/dist/types/PriceInfoType.js +57 -0
- package/dist/types/SwapExecutionAction.d.ts +7 -0
- package/dist/types/SwapExecutionAction.js +2 -0
- package/dist/types/SwapWithSigner.d.ts +14 -0
- package/dist/types/SwapWithSigner.js +40 -0
- package/dist/types/Token.d.ts +53 -0
- package/dist/types/Token.js +58 -0
- package/dist/types/TokenAmount.d.ts +57 -0
- package/dist/types/TokenAmount.js +47 -0
- package/dist/types/fees/Fee.d.ts +49 -0
- package/dist/types/fees/Fee.js +2 -0
- package/dist/types/fees/FeeBreakdown.d.ts +10 -0
- package/dist/types/fees/FeeBreakdown.js +2 -0
- package/dist/types/fees/PercentagePPM.d.ts +15 -0
- package/dist/types/fees/PercentagePPM.js +17 -0
- package/dist/types/lnurl/LNURLPay.d.ts +54 -0
- package/dist/types/lnurl/LNURLPay.js +28 -0
- package/dist/types/lnurl/LNURLWithdraw.d.ts +42 -0
- package/dist/types/lnurl/LNURLWithdraw.js +24 -0
- package/dist/utils/AutomaticClockDriftCorrection.d.ts +1 -0
- package/dist/utils/AutomaticClockDriftCorrection.js +70 -0
- package/dist/utils/BitcoinUtils.d.ts +13 -0
- package/dist/utils/BitcoinUtils.js +98 -0
- package/dist/utils/BitcoinWalletUtils.d.ts +7 -0
- package/dist/utils/BitcoinWalletUtils.js +14 -0
- package/dist/utils/Logger.d.ts +7 -0
- package/dist/utils/Logger.js +12 -0
- package/dist/utils/RetryUtils.d.ts +21 -0
- package/dist/utils/RetryUtils.js +66 -0
- package/dist/utils/SwapUtils.d.ts +31 -0
- package/dist/utils/SwapUtils.js +18 -0
- package/dist/{Utils.d.ts → utils/TimeoutUtils.d.ts} +9 -3
- package/dist/utils/TimeoutUtils.js +55 -0
- package/dist/utils/TokenUtils.d.ts +11 -0
- package/dist/utils/TokenUtils.js +29 -0
- package/dist/utils/TypeUtils.d.ts +7 -0
- package/dist/utils/TypeUtils.js +2 -0
- package/dist/utils/Utils.d.ts +57 -0
- package/dist/utils/Utils.js +178 -0
- package/package.json +14 -6
- package/src/SmartChainAssets.ts +11 -3
- package/src/bitcoin/BitcoinRpcWithAddressIndex.ts +87 -0
- package/src/bitcoin/LightningNetworkApi.ts +16 -0
- package/src/bitcoin/coinselect2/accumulative.ts +68 -0
- package/src/bitcoin/coinselect2/blackjack.ts +49 -0
- package/src/bitcoin/coinselect2/index.ts +92 -0
- package/src/bitcoin/coinselect2/utils.ts +189 -0
- package/src/bitcoin/mempool/MempoolApi.ts +554 -0
- package/src/bitcoin/mempool/MempoolBitcoinBlock.ts +88 -0
- package/src/bitcoin/mempool/MempoolBitcoinRpc.ts +437 -0
- package/src/bitcoin/mempool/synchronizer/MempoolBtcRelaySynchronizer.ts +134 -0
- package/src/bitcoin/wallet/BitcoinWallet.ts +375 -0
- package/src/bitcoin/wallet/IBitcoinWallet.ts +44 -0
- package/src/bitcoin/wallet/MinimalBitcoinWalletInterface.ts +19 -0
- package/src/bitcoin/wallet/MinimalLightningNetworkWalletInterface.ts +7 -0
- package/src/bitcoin/wallet/SingleAddressBitcoinWallet.ts +108 -0
- package/src/enums/FeeType.ts +9 -0
- package/src/enums/SwapAmountType.ts +9 -0
- package/src/enums/SwapDirection.ts +9 -0
- package/src/enums/SwapType.ts +15 -0
- package/src/errors/IntermediaryError.ts +24 -0
- package/src/errors/PaymentAuthError.ts +26 -0
- package/src/errors/RequestError.ts +51 -0
- package/src/errors/UserError.ts +14 -0
- package/src/events/UnifiedSwapEventListener.ts +171 -0
- package/src/http/HttpUtils.ts +92 -0
- package/src/http/paramcoders/IParamReader.ts +10 -0
- package/src/http/paramcoders/ParamDecoder.ts +142 -0
- package/src/http/paramcoders/ParamEncoder.ts +37 -0
- package/src/http/paramcoders/SchemaVerifier.ts +153 -0
- package/src/http/paramcoders/client/ResponseParamDecoder.ts +58 -0
- package/src/http/paramcoders/client/StreamParamEncoder.ts +29 -0
- package/src/http/paramcoders/client/StreamingFetchPromise.ts +193 -0
- package/src/index.ts +102 -4
- package/src/intermediaries/Intermediary.ts +204 -0
- package/src/intermediaries/IntermediaryDiscovery.ts +485 -0
- package/src/intermediaries/apis/IntermediaryAPI.ts +940 -0
- package/src/intermediaries/apis/TrustedIntermediaryAPI.ts +257 -0
- package/src/lnurl/LNURL.ts +403 -0
- package/src/prices/RedundantSwapPrice.ts +245 -0
- package/src/prices/SingleSwapPrice.ts +47 -0
- package/src/prices/SwapPriceWithChain.ts +157 -0
- package/src/prices/abstract/ICachedSwapPrice.ts +86 -0
- package/src/prices/abstract/IPriceProvider.ts +128 -0
- package/src/prices/abstract/ISwapPrice.ts +328 -0
- package/src/prices/providers/BinancePriceProvider.ts +41 -0
- package/src/prices/providers/CoinGeckoPriceProvider.ts +40 -0
- package/src/prices/providers/CoinPaprikaPriceProvider.ts +44 -0
- package/src/prices/providers/CustomPriceProvider.ts +29 -0
- package/src/prices/providers/KrakenPriceProvider.ts +74 -0
- package/src/prices/providers/OKXPriceProvider.ts +53 -0
- package/src/prices/providers/abstract/ExchangePriceProvider.ts +29 -0
- package/src/prices/providers/abstract/HttpPriceProvider.ts +15 -0
- package/src/storage/IUnifiedStorage.ts +83 -0
- package/src/storage/UnifiedSwapStorage.ts +104 -0
- package/src/storage-browser/IndexedDBUnifiedStorage.ts +328 -0
- package/src/{storage → storage-browser}/LocalStorageManager.ts +2 -1
- package/src/swapper/Swapper.ts +2107 -0
- package/src/{SwapperFactory.ts → swapper/SwapperFactory.ts} +116 -75
- package/src/swapper/SwapperUtils.ts +510 -0
- package/src/swapper/SwapperWithChain.ts +464 -0
- package/src/swapper/SwapperWithSigner.ts +300 -0
- package/src/swaps/IAddressSwap.ts +20 -0
- package/src/swaps/IBTCWalletSwap.ts +77 -0
- package/src/swaps/IClaimableSwap.ts +30 -0
- package/src/swaps/IClaimableSwapWrapper.ts +9 -0
- package/src/swaps/IRefundableSwap.ts +29 -0
- package/src/swaps/ISwap.ts +490 -0
- package/src/swaps/ISwapWithGasDrop.ts +19 -0
- package/src/swaps/ISwapWrapper.ts +344 -0
- package/src/swaps/escrow_swaps/IEscrowSelfInitSwap.ts +168 -0
- package/src/swaps/escrow_swaps/IEscrowSwap.ts +197 -0
- package/src/swaps/escrow_swaps/IEscrowSwapWrapper.ts +210 -0
- package/src/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.ts +150 -0
- package/src/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.ts +219 -0
- package/src/swaps/escrow_swaps/frombtc/IFromBTCWrapper.ts +84 -0
- package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.ts +1082 -0
- package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.ts +429 -0
- package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.ts +1078 -0
- package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.ts +549 -0
- package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.ts +974 -0
- package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.ts +443 -0
- package/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts +860 -0
- package/src/swaps/escrow_swaps/tobtc/IToBTCWrapper.ts +104 -0
- package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.ts +256 -0
- package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.ts +716 -0
- package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.ts +151 -0
- package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.ts +299 -0
- package/src/swaps/spv_swaps/SpvFromBTCSwap.ts +1394 -0
- package/src/swaps/spv_swaps/SpvFromBTCWrapper.ts +796 -0
- package/src/swaps/trusted/ln/LnForGasSwap.ts +402 -0
- package/src/swaps/trusted/ln/LnForGasWrapper.ts +70 -0
- package/src/swaps/trusted/onchain/OnchainForGasSwap.ts +633 -0
- package/src/swaps/trusted/onchain/OnchainForGasWrapper.ts +110 -0
- package/src/types/AmountData.ts +9 -0
- package/src/types/CustomPriceFunction.ts +5 -0
- package/src/types/PriceInfoType.ts +67 -0
- package/src/types/SwapExecutionAction.ts +8 -0
- package/src/types/SwapWithSigner.ts +57 -0
- package/src/types/Token.ts +90 -0
- package/src/types/TokenAmount.ts +110 -0
- package/src/types/fees/Fee.ts +55 -0
- package/src/types/fees/FeeBreakdown.ts +11 -0
- package/src/types/fees/PercentagePPM.ts +24 -0
- package/src/types/lnurl/LNURLPay.ts +72 -0
- package/src/types/lnurl/LNURLWithdraw.ts +55 -0
- package/src/utils/AutomaticClockDriftCorrection.ts +71 -0
- package/src/utils/BitcoinUtils.ts +86 -0
- package/src/utils/BitcoinWalletUtils.ts +16 -0
- package/src/utils/Logger.ts +15 -0
- package/src/utils/RetryUtils.ts +71 -0
- package/src/utils/SwapUtils.ts +38 -0
- package/src/utils/TimeoutUtils.ts +50 -0
- package/src/utils/TokenUtils.ts +25 -0
- package/src/utils/TypeUtils.ts +9 -0
- package/src/utils/Utils.ts +182 -0
- package/dist/SwapperFactory.d.ts +0 -52
- package/dist/Utils.js +0 -37
- package/dist/fs-storage/FileSystemStorageManager.d.ts +0 -15
- package/dist/fs-storage/FileSystemStorageManager.js +0 -60
- package/dist/fs-storage/index.d.ts +0 -1
- package/dist/fs-storage/index.js +0 -17
- package/src/SmartChainAssets.js +0 -75
- package/src/SwapperFactory.js +0 -120
- package/src/Utils.js +0 -37
- package/src/Utils.ts +0 -31
- package/src/fs-storage/FileSystemStorageManager.ts +0 -71
- package/src/fs-storage/index.ts +0 -1
- package/src/index.js +0 -21
- package/src/storage/LocalStorageManager.js +0 -72
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BitcoinWallet = exports.identifyAddressType = void 0;
|
|
4
|
+
const coinselect2_1 = require("../coinselect2");
|
|
5
|
+
const btc_signer_1 = require("@scure/btc-signer");
|
|
6
|
+
const buffer_1 = require("buffer");
|
|
7
|
+
const Utils_1 = require("../../utils/Utils");
|
|
8
|
+
const BitcoinUtils_1 = require("../../utils/BitcoinUtils");
|
|
9
|
+
const Logger_1 = require("../../utils/Logger");
|
|
10
|
+
/**
|
|
11
|
+
* Identifies the address type of a Bitcoin address
|
|
12
|
+
* @category Bitcoin
|
|
13
|
+
*/
|
|
14
|
+
function identifyAddressType(address, network) {
|
|
15
|
+
switch ((0, btc_signer_1.Address)(network).decode(address).type) {
|
|
16
|
+
case "pkh":
|
|
17
|
+
return "p2pkh";
|
|
18
|
+
case "wpkh":
|
|
19
|
+
return "p2wpkh";
|
|
20
|
+
case "tr":
|
|
21
|
+
return "p2tr";
|
|
22
|
+
case "sh":
|
|
23
|
+
return "p2sh-p2wpkh";
|
|
24
|
+
case "wsh":
|
|
25
|
+
return "p2wsh";
|
|
26
|
+
default:
|
|
27
|
+
throw new Error("Unknown address type of " + address);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.identifyAddressType = identifyAddressType;
|
|
31
|
+
const logger = (0, Logger_1.getLogger)("BitcoinWallet: ");
|
|
32
|
+
/**
|
|
33
|
+
* Abstract base class for Bitcoin wallet implementations
|
|
34
|
+
* @category Bitcoin
|
|
35
|
+
*/
|
|
36
|
+
class BitcoinWallet {
|
|
37
|
+
constructor(mempoolApi, network, feeMultiplier = 1.25, feeOverride) {
|
|
38
|
+
this.rpc = mempoolApi;
|
|
39
|
+
this.network = network;
|
|
40
|
+
this.feeMultiplier = feeMultiplier;
|
|
41
|
+
this.feeOverride = feeOverride;
|
|
42
|
+
}
|
|
43
|
+
async getFeeRate() {
|
|
44
|
+
if (this.feeOverride != null) {
|
|
45
|
+
return this.feeOverride;
|
|
46
|
+
}
|
|
47
|
+
return Math.floor((await this.rpc.getFeeRate()) * this.feeMultiplier);
|
|
48
|
+
}
|
|
49
|
+
_sendTransaction(rawHex) {
|
|
50
|
+
return this.rpc.sendRawTransaction(rawHex);
|
|
51
|
+
}
|
|
52
|
+
_getBalance(address) {
|
|
53
|
+
return this.rpc.getAddressBalances(address);
|
|
54
|
+
}
|
|
55
|
+
async _getUtxoPool(sendingAddress, sendingAddressType) {
|
|
56
|
+
const utxos = await this.rpc.getAddressUTXOs(sendingAddress);
|
|
57
|
+
let totalSpendable = 0;
|
|
58
|
+
const outputScript = (0, BitcoinUtils_1.toOutputScript)(this.network, sendingAddress);
|
|
59
|
+
const utxoPool = [];
|
|
60
|
+
for (let utxo of utxos) {
|
|
61
|
+
const value = Number(utxo.value);
|
|
62
|
+
totalSpendable += value;
|
|
63
|
+
utxoPool.push({
|
|
64
|
+
vout: utxo.vout,
|
|
65
|
+
txId: utxo.txid,
|
|
66
|
+
value: value,
|
|
67
|
+
type: sendingAddressType,
|
|
68
|
+
outputScript: outputScript,
|
|
69
|
+
address: sendingAddress,
|
|
70
|
+
cpfp: !utxo.confirmed ? await this.rpc.getCPFPData(utxo.txid).then((result) => {
|
|
71
|
+
if (result.effectiveFeePerVsize == null)
|
|
72
|
+
return;
|
|
73
|
+
return {
|
|
74
|
+
txVsize: result.adjustedVsize,
|
|
75
|
+
txEffectiveFeeRate: result.effectiveFeePerVsize
|
|
76
|
+
};
|
|
77
|
+
}) : undefined,
|
|
78
|
+
confirmed: utxo.confirmed
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
logger.debug("_getUtxoPool(): Total spendable value: " + totalSpendable + " num utxos: " + utxoPool.length);
|
|
82
|
+
return utxoPool;
|
|
83
|
+
}
|
|
84
|
+
async _getPsbt(sendingAccounts, recipient, amount, feeRate) {
|
|
85
|
+
const psbt = new btc_signer_1.Transaction({ PSBTVersion: 0 });
|
|
86
|
+
psbt.addOutput({
|
|
87
|
+
amount: BigInt(amount),
|
|
88
|
+
script: (0, BitcoinUtils_1.toOutputScript)(this.network, recipient)
|
|
89
|
+
});
|
|
90
|
+
return this._fundPsbt(sendingAccounts, psbt, feeRate);
|
|
91
|
+
}
|
|
92
|
+
async _fundPsbt(sendingAccounts, psbt, feeRate) {
|
|
93
|
+
if (feeRate == null)
|
|
94
|
+
feeRate = await this.getFeeRate();
|
|
95
|
+
const utxoPool = (await Promise.all(sendingAccounts.map(acc => this._getUtxoPool(acc.address, acc.addressType)))).flat();
|
|
96
|
+
logger.debug("_fundPsbt(): fee rate: " + feeRate + " utxo pool: ", utxoPool);
|
|
97
|
+
const accountPubkeys = {};
|
|
98
|
+
sendingAccounts.forEach(acc => accountPubkeys[acc.address] = acc.pubkey);
|
|
99
|
+
const requiredInputs = [];
|
|
100
|
+
for (let i = 0; i < psbt.inputsLength; i++) {
|
|
101
|
+
const input = psbt.getInput(i);
|
|
102
|
+
if (input.index == null || input.txid == null)
|
|
103
|
+
throw new Error("Inputs need txid & index!");
|
|
104
|
+
let amount;
|
|
105
|
+
let script;
|
|
106
|
+
if (input.witnessUtxo != null) {
|
|
107
|
+
amount = input.witnessUtxo.amount;
|
|
108
|
+
script = input.witnessUtxo.script;
|
|
109
|
+
}
|
|
110
|
+
else if (input.nonWitnessUtxo != null) {
|
|
111
|
+
amount = input.nonWitnessUtxo.outputs[input.index].amount;
|
|
112
|
+
script = input.nonWitnessUtxo.outputs[input.index].script;
|
|
113
|
+
}
|
|
114
|
+
else
|
|
115
|
+
throw new Error("Either witnessUtxo or nonWitnessUtxo has to be defined!");
|
|
116
|
+
requiredInputs.push({
|
|
117
|
+
txId: buffer_1.Buffer.from(input.txid).toString('hex'),
|
|
118
|
+
vout: input.index,
|
|
119
|
+
value: Number(amount),
|
|
120
|
+
type: (0, BitcoinUtils_1.toCoinselectAddressType)(script)
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
const targets = [];
|
|
124
|
+
for (let i = 0; i < psbt.outputsLength; i++) {
|
|
125
|
+
const output = psbt.getOutput(i);
|
|
126
|
+
if (output.amount == null || output.script == null)
|
|
127
|
+
throw new Error("Outputs need amount & script defined!");
|
|
128
|
+
targets.push({
|
|
129
|
+
value: Number(output.amount),
|
|
130
|
+
script: buffer_1.Buffer.from(output.script)
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
logger.debug("_fundPsbt(): Coinselect targets: ", targets);
|
|
134
|
+
let coinselectResult = (0, coinselect2_1.coinSelect)(utxoPool, targets, feeRate, sendingAccounts[0].addressType, requiredInputs);
|
|
135
|
+
logger.debug("_fundPsbt(): Coinselect result: ", coinselectResult);
|
|
136
|
+
if (coinselectResult.inputs == null || coinselectResult.outputs == null) {
|
|
137
|
+
return {
|
|
138
|
+
fee: coinselectResult.fee
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
// Remove in/outs that are already in the PSBT
|
|
142
|
+
coinselectResult.inputs.splice(0, psbt.inputsLength);
|
|
143
|
+
coinselectResult.outputs.splice(0, psbt.outputsLength);
|
|
144
|
+
const inputAddressIndexes = {};
|
|
145
|
+
coinselectResult.inputs.forEach((input, index) => {
|
|
146
|
+
inputAddressIndexes[input.address] ??= [];
|
|
147
|
+
inputAddressIndexes[input.address].push(index);
|
|
148
|
+
});
|
|
149
|
+
const formattedInputs = await Promise.all(coinselectResult.inputs.map(async (input) => {
|
|
150
|
+
switch (input.type) {
|
|
151
|
+
case "p2tr":
|
|
152
|
+
const parsed = (0, btc_signer_1.p2tr)(buffer_1.Buffer.from(accountPubkeys[input.address], "hex"));
|
|
153
|
+
return {
|
|
154
|
+
txid: input.txId,
|
|
155
|
+
index: input.vout,
|
|
156
|
+
witnessUtxo: {
|
|
157
|
+
script: input.outputScript,
|
|
158
|
+
amount: BigInt(input.value)
|
|
159
|
+
},
|
|
160
|
+
tapInternalKey: parsed.tapInternalKey,
|
|
161
|
+
tapMerkleRoot: parsed.tapMerkleRoot,
|
|
162
|
+
tapLeafScript: parsed.tapLeafScript
|
|
163
|
+
};
|
|
164
|
+
case "p2wpkh":
|
|
165
|
+
return {
|
|
166
|
+
txid: input.txId,
|
|
167
|
+
index: input.vout,
|
|
168
|
+
witnessUtxo: {
|
|
169
|
+
script: input.outputScript,
|
|
170
|
+
amount: BigInt(input.value)
|
|
171
|
+
},
|
|
172
|
+
sighashType: 0x01
|
|
173
|
+
};
|
|
174
|
+
case "p2sh-p2wpkh":
|
|
175
|
+
return {
|
|
176
|
+
txid: input.txId,
|
|
177
|
+
index: input.vout,
|
|
178
|
+
witnessUtxo: {
|
|
179
|
+
script: input.outputScript,
|
|
180
|
+
amount: BigInt(input.value)
|
|
181
|
+
},
|
|
182
|
+
redeemScript: (0, btc_signer_1.p2wpkh)(buffer_1.Buffer.from(accountPubkeys[input.address], "hex"), this.network).script,
|
|
183
|
+
sighashType: 0x01
|
|
184
|
+
};
|
|
185
|
+
case "p2pkh":
|
|
186
|
+
const tx = await this.rpc.getTransaction(input.txId);
|
|
187
|
+
if (tx == null)
|
|
188
|
+
throw new Error("Cannot fetch existing tx " + input.txId);
|
|
189
|
+
return {
|
|
190
|
+
txid: input.txId,
|
|
191
|
+
index: input.vout,
|
|
192
|
+
nonWitnessUtxo: tx.raw,
|
|
193
|
+
sighashType: 0x01
|
|
194
|
+
};
|
|
195
|
+
default:
|
|
196
|
+
throw new Error("Invalid input type: " + input.type);
|
|
197
|
+
}
|
|
198
|
+
}));
|
|
199
|
+
formattedInputs.forEach(input => psbt.addInput(input));
|
|
200
|
+
coinselectResult.outputs.forEach(output => {
|
|
201
|
+
if (output.script == null && output.address == null) {
|
|
202
|
+
//Change output
|
|
203
|
+
psbt.addOutput({
|
|
204
|
+
script: (0, BitcoinUtils_1.toOutputScript)(this.network, sendingAccounts[0].address),
|
|
205
|
+
amount: BigInt(Math.floor(output.value))
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
psbt.addOutput({
|
|
210
|
+
script: output.script ?? (0, BitcoinUtils_1.toOutputScript)(this.network, output.address),
|
|
211
|
+
amount: BigInt(output.value)
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
return {
|
|
216
|
+
psbt,
|
|
217
|
+
fee: coinselectResult.fee,
|
|
218
|
+
inputAddressIndexes
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
async _getSpendableBalance(sendingAccounts, psbt, feeRate) {
|
|
222
|
+
feeRate ??= await this.getFeeRate();
|
|
223
|
+
const utxoPool = (await Promise.all(sendingAccounts.map(acc => this._getUtxoPool(acc.address, acc.addressType)))).flat();
|
|
224
|
+
const requiredInputs = [];
|
|
225
|
+
if (psbt != null)
|
|
226
|
+
for (let i = 0; i < psbt.inputsLength; i++) {
|
|
227
|
+
const input = psbt.getInput(i);
|
|
228
|
+
if (input.index == null || input.txid == null)
|
|
229
|
+
throw new Error("Inputs need txid & index!");
|
|
230
|
+
let amount;
|
|
231
|
+
let script;
|
|
232
|
+
if (input.witnessUtxo != null) {
|
|
233
|
+
amount = input.witnessUtxo.amount;
|
|
234
|
+
script = input.witnessUtxo.script;
|
|
235
|
+
}
|
|
236
|
+
else if (input.nonWitnessUtxo != null) {
|
|
237
|
+
amount = input.nonWitnessUtxo.outputs[input.index].amount;
|
|
238
|
+
script = input.nonWitnessUtxo.outputs[input.index].script;
|
|
239
|
+
}
|
|
240
|
+
else
|
|
241
|
+
throw new Error("Either witnessUtxo or nonWitnessUtxo has to be defined!");
|
|
242
|
+
requiredInputs.push({
|
|
243
|
+
txId: buffer_1.Buffer.from(input.txid).toString('hex'),
|
|
244
|
+
vout: input.index,
|
|
245
|
+
value: Number(amount),
|
|
246
|
+
type: (0, BitcoinUtils_1.toCoinselectAddressType)(script)
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
const additionalOutputs = [];
|
|
250
|
+
if (psbt != null)
|
|
251
|
+
for (let i = 0; i < psbt.outputsLength; i++) {
|
|
252
|
+
const output = psbt.getOutput(i);
|
|
253
|
+
if (output.amount == null || output.script == null)
|
|
254
|
+
throw new Error("Outputs need amount & script!");
|
|
255
|
+
additionalOutputs.push({
|
|
256
|
+
value: Number(output.amount),
|
|
257
|
+
script: buffer_1.Buffer.from(output.script)
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
const target = btc_signer_1.OutScript.encode({
|
|
261
|
+
type: "wsh",
|
|
262
|
+
hash: (0, Utils_1.randomBytes)(32)
|
|
263
|
+
});
|
|
264
|
+
let coinselectResult = (0, coinselect2_1.maxSendable)(utxoPool, { script: buffer_1.Buffer.from(target), type: "p2wsh" }, feeRate, requiredInputs, additionalOutputs);
|
|
265
|
+
logger.debug("_getSpendableBalance(): Max spendable result: ", coinselectResult);
|
|
266
|
+
return {
|
|
267
|
+
feeRate: feeRate,
|
|
268
|
+
balance: BigInt(Math.floor(coinselectResult.value)),
|
|
269
|
+
totalFee: coinselectResult.fee
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
exports.BitcoinWallet = BitcoinWallet;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Transaction } from "@scure/btc-signer";
|
|
2
|
+
/**
|
|
3
|
+
* Type guard to check if an object implements IBitcoinWallet
|
|
4
|
+
* @category Bitcoin
|
|
5
|
+
*/
|
|
6
|
+
export declare function isIBitcoinWallet(val: any): val is IBitcoinWallet;
|
|
7
|
+
/**
|
|
8
|
+
* Interface for Bitcoin wallet operations
|
|
9
|
+
* @category Bitcoin
|
|
10
|
+
*/
|
|
11
|
+
export interface IBitcoinWallet {
|
|
12
|
+
sendTransaction(address: string, amount: bigint, feeRate?: number): Promise<string>;
|
|
13
|
+
fundPsbt(psbt: Transaction, feeRate?: number): Promise<Transaction>;
|
|
14
|
+
signPsbt(psbt: Transaction, signInputs: number[]): Promise<Transaction>;
|
|
15
|
+
getFeeRate(): Promise<number>;
|
|
16
|
+
getTransactionFee(address: string, amount: bigint, feeRate?: number): Promise<number>;
|
|
17
|
+
getFundedPsbtFee(psbt: Transaction, feeRate?: number): Promise<number>;
|
|
18
|
+
getReceiveAddress(): string;
|
|
19
|
+
getBalance(): Promise<{
|
|
20
|
+
confirmedBalance: bigint;
|
|
21
|
+
unconfirmedBalance: bigint;
|
|
22
|
+
}>;
|
|
23
|
+
getSpendableBalance(psbt?: Transaction, feeRate?: number): Promise<{
|
|
24
|
+
balance: bigint;
|
|
25
|
+
feeRate: number;
|
|
26
|
+
totalFee: number;
|
|
27
|
+
}>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isIBitcoinWallet = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Type guard to check if an object implements IBitcoinWallet
|
|
6
|
+
* @category Bitcoin
|
|
7
|
+
*/
|
|
8
|
+
function isIBitcoinWallet(val) {
|
|
9
|
+
return val !== null &&
|
|
10
|
+
typeof (val.sendTransaction) === "function" &&
|
|
11
|
+
typeof (val.fundPsbt) === "function" &&
|
|
12
|
+
typeof (val.signPsbt) === "function" &&
|
|
13
|
+
typeof (val.getFeeRate) === "function" &&
|
|
14
|
+
typeof (val.getTransactionFee) === "function" &&
|
|
15
|
+
typeof (val.getFundedPsbtFee) === "function" &&
|
|
16
|
+
typeof (val.getReceiveAddress) === "function" &&
|
|
17
|
+
typeof (val.getBalance) === "function" &&
|
|
18
|
+
typeof (val.getSpendableBalance) === "function";
|
|
19
|
+
}
|
|
20
|
+
exports.isIBitcoinWallet = isIBitcoinWallet;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Transaction } from "@scure/btc-signer";
|
|
2
|
+
/**
|
|
3
|
+
* A type with minimum possible required data about a bitcoin wallet to be able to estimate fees and produce unsigned
|
|
4
|
+
* PSBTs
|
|
5
|
+
* @category Bitcoin
|
|
6
|
+
*/
|
|
7
|
+
export type MinimalBitcoinWalletInterface = {
|
|
8
|
+
address: string;
|
|
9
|
+
publicKey: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* A type with minimum possible required data about a bitcoin wallet to be able to estimate fees and sign PSBTs
|
|
13
|
+
* @category Bitcoin
|
|
14
|
+
*/
|
|
15
|
+
export type MinimalBitcoinWalletInterfaceWithSigner = MinimalBitcoinWalletInterface & {
|
|
16
|
+
signPsbt: (psbtToSign: {
|
|
17
|
+
psbt: Transaction;
|
|
18
|
+
psbtHex: string;
|
|
19
|
+
psbtBase64: string;
|
|
20
|
+
}, signInputs: number[]) => Promise<Transaction | string>;
|
|
21
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { CoinselectAddressTypes } from "../coinselect2";
|
|
2
|
+
import { BTC_NETWORK } from "@scure/btc-signer/utils";
|
|
3
|
+
import { Transaction } from "@scure/btc-signer";
|
|
4
|
+
import { BitcoinWallet } from "./BitcoinWallet";
|
|
5
|
+
import { BitcoinRpcWithAddressIndex } from "../BitcoinRpcWithAddressIndex";
|
|
6
|
+
/**
|
|
7
|
+
* Bitcoin wallet implementation for single-address scenarios
|
|
8
|
+
* @category Bitcoin
|
|
9
|
+
*/
|
|
10
|
+
export declare class SingleAddressBitcoinWallet extends BitcoinWallet {
|
|
11
|
+
readonly privKey?: Uint8Array;
|
|
12
|
+
readonly pubkey: Uint8Array;
|
|
13
|
+
readonly address: string;
|
|
14
|
+
readonly addressType: CoinselectAddressTypes;
|
|
15
|
+
constructor(mempoolApi: BitcoinRpcWithAddressIndex<any>, network: BTC_NETWORK, addressDataOrWIF: string | {
|
|
16
|
+
address: string;
|
|
17
|
+
publicKey: string;
|
|
18
|
+
}, feeMultiplier?: number, feeOverride?: number);
|
|
19
|
+
protected toBitcoinWalletAccounts(): {
|
|
20
|
+
pubkey: string;
|
|
21
|
+
address: string;
|
|
22
|
+
addressType: CoinselectAddressTypes;
|
|
23
|
+
}[];
|
|
24
|
+
sendTransaction(address: string, amount: bigint, feeRate?: number): Promise<string>;
|
|
25
|
+
fundPsbt(inputPsbt: Transaction, feeRate?: number): Promise<Transaction>;
|
|
26
|
+
signPsbt(psbt: Transaction, signInputs: number[]): Promise<Transaction>;
|
|
27
|
+
getTransactionFee(address: string, amount: bigint, feeRate?: number): Promise<number>;
|
|
28
|
+
getFundedPsbtFee(basePsbt: Transaction, feeRate?: number): Promise<number>;
|
|
29
|
+
getReceiveAddress(): string;
|
|
30
|
+
getBalance(): Promise<{
|
|
31
|
+
confirmedBalance: bigint;
|
|
32
|
+
unconfirmedBalance: bigint;
|
|
33
|
+
}>;
|
|
34
|
+
getSpendableBalance(psbt?: Transaction, feeRate?: number): Promise<{
|
|
35
|
+
balance: bigint;
|
|
36
|
+
feeRate: number;
|
|
37
|
+
totalFee: number;
|
|
38
|
+
}>;
|
|
39
|
+
static generateRandomPrivateKey(network?: BTC_NETWORK): string;
|
|
40
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SingleAddressBitcoinWallet = void 0;
|
|
4
|
+
const utils_1 = require("@scure/btc-signer/utils");
|
|
5
|
+
const btc_signer_1 = require("@scure/btc-signer");
|
|
6
|
+
const buffer_1 = require("buffer");
|
|
7
|
+
const BitcoinWallet_1 = require("./BitcoinWallet");
|
|
8
|
+
/**
|
|
9
|
+
* Bitcoin wallet implementation for single-address scenarios
|
|
10
|
+
* @category Bitcoin
|
|
11
|
+
*/
|
|
12
|
+
class SingleAddressBitcoinWallet extends BitcoinWallet_1.BitcoinWallet {
|
|
13
|
+
constructor(mempoolApi, network, addressDataOrWIF, feeMultiplier = 1.25, feeOverride) {
|
|
14
|
+
super(mempoolApi, network, feeMultiplier, feeOverride);
|
|
15
|
+
if (typeof (addressDataOrWIF) === "string") {
|
|
16
|
+
try {
|
|
17
|
+
this.privKey = (0, btc_signer_1.WIF)(network).decode(addressDataOrWIF);
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
this.privKey = (0, btc_signer_1.WIF)().decode(addressDataOrWIF);
|
|
21
|
+
}
|
|
22
|
+
this.pubkey = (0, utils_1.pubECDSA)(this.privKey);
|
|
23
|
+
const address = (0, btc_signer_1.getAddress)("wpkh", this.privKey, network);
|
|
24
|
+
if (address == null)
|
|
25
|
+
throw new Error("Failed to generate p2wpkh address from the provided private key!");
|
|
26
|
+
this.address = address;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
this.address = addressDataOrWIF.address;
|
|
30
|
+
this.pubkey = buffer_1.Buffer.from(addressDataOrWIF.publicKey, "hex");
|
|
31
|
+
}
|
|
32
|
+
this.addressType = (0, BitcoinWallet_1.identifyAddressType)(this.address, network);
|
|
33
|
+
}
|
|
34
|
+
toBitcoinWalletAccounts() {
|
|
35
|
+
return [{
|
|
36
|
+
pubkey: buffer_1.Buffer.from(this.pubkey).toString("hex"), address: this.address, addressType: this.addressType
|
|
37
|
+
}];
|
|
38
|
+
}
|
|
39
|
+
async sendTransaction(address, amount, feeRate) {
|
|
40
|
+
if (!this.privKey)
|
|
41
|
+
throw new Error("Not supported.");
|
|
42
|
+
const { psbt, fee } = await super._getPsbt(this.toBitcoinWalletAccounts(), address, Number(amount), feeRate);
|
|
43
|
+
if (psbt == null)
|
|
44
|
+
throw new Error(`Not enough funds, required for fee: ${fee} sats!`);
|
|
45
|
+
psbt.sign(this.privKey);
|
|
46
|
+
psbt.finalize();
|
|
47
|
+
const txHex = buffer_1.Buffer.from(psbt.extract()).toString("hex");
|
|
48
|
+
return await super._sendTransaction(txHex);
|
|
49
|
+
}
|
|
50
|
+
async fundPsbt(inputPsbt, feeRate) {
|
|
51
|
+
const { psbt } = await super._fundPsbt(this.toBitcoinWalletAccounts(), inputPsbt, feeRate);
|
|
52
|
+
if (psbt == null) {
|
|
53
|
+
throw new Error("Not enough balance!");
|
|
54
|
+
}
|
|
55
|
+
return psbt;
|
|
56
|
+
}
|
|
57
|
+
async signPsbt(psbt, signInputs) {
|
|
58
|
+
if (!this.privKey)
|
|
59
|
+
throw new Error("Not supported.");
|
|
60
|
+
for (let signInput of signInputs) {
|
|
61
|
+
psbt.signIdx(this.privKey, signInput);
|
|
62
|
+
}
|
|
63
|
+
return psbt;
|
|
64
|
+
}
|
|
65
|
+
async getTransactionFee(address, amount, feeRate) {
|
|
66
|
+
const { fee } = await super._getPsbt(this.toBitcoinWalletAccounts(), address, Number(amount), feeRate);
|
|
67
|
+
return fee;
|
|
68
|
+
}
|
|
69
|
+
async getFundedPsbtFee(basePsbt, feeRate) {
|
|
70
|
+
const { fee } = await super._fundPsbt(this.toBitcoinWalletAccounts(), basePsbt, feeRate);
|
|
71
|
+
return fee;
|
|
72
|
+
}
|
|
73
|
+
getReceiveAddress() {
|
|
74
|
+
return this.address;
|
|
75
|
+
}
|
|
76
|
+
getBalance() {
|
|
77
|
+
return this._getBalance(this.address);
|
|
78
|
+
}
|
|
79
|
+
getSpendableBalance(psbt, feeRate) {
|
|
80
|
+
return this._getSpendableBalance([{ address: this.address, addressType: this.addressType }], psbt, feeRate);
|
|
81
|
+
}
|
|
82
|
+
static generateRandomPrivateKey(network) {
|
|
83
|
+
return (0, btc_signer_1.WIF)(network).encode((0, utils_1.randomPrivateKeyBytes)());
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.SingleAddressBitcoinWallet = SingleAddressBitcoinWallet;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FeeType = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Enum representing types of fees in a swap
|
|
6
|
+
* @category Pricing and LPs
|
|
7
|
+
*/
|
|
8
|
+
var FeeType;
|
|
9
|
+
(function (FeeType) {
|
|
10
|
+
FeeType[FeeType["SWAP"] = 0] = "SWAP";
|
|
11
|
+
FeeType[FeeType["NETWORK_OUTPUT"] = 1] = "NETWORK_OUTPUT";
|
|
12
|
+
})(FeeType = exports.FeeType || (exports.FeeType = {}));
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SwapAmountType = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Enum representing whether the swap amount is exact input or exact output
|
|
6
|
+
* @category Core
|
|
7
|
+
*/
|
|
8
|
+
var SwapAmountType;
|
|
9
|
+
(function (SwapAmountType) {
|
|
10
|
+
SwapAmountType[SwapAmountType["EXACT_IN"] = 1] = "EXACT_IN";
|
|
11
|
+
SwapAmountType[SwapAmountType["EXACT_OUT"] = 0] = "EXACT_OUT";
|
|
12
|
+
})(SwapAmountType = exports.SwapAmountType || (exports.SwapAmountType = {}));
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SwapDirection = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Enum representing the direction of a swap (from or to Bitcoin)
|
|
6
|
+
* @category Core
|
|
7
|
+
*/
|
|
8
|
+
var SwapDirection;
|
|
9
|
+
(function (SwapDirection) {
|
|
10
|
+
SwapDirection[SwapDirection["FROM_BTC"] = 0] = "FROM_BTC";
|
|
11
|
+
SwapDirection[SwapDirection["TO_BTC"] = 1] = "TO_BTC";
|
|
12
|
+
})(SwapDirection = exports.SwapDirection || (exports.SwapDirection = {}));
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enum representing different types of swaps
|
|
3
|
+
* @category Core
|
|
4
|
+
*/
|
|
5
|
+
export declare enum SwapType {
|
|
6
|
+
FROM_BTC = 0,
|
|
7
|
+
FROM_BTCLN = 1,
|
|
8
|
+
TO_BTC = 2,
|
|
9
|
+
TO_BTCLN = 3,
|
|
10
|
+
TRUSTED_FROM_BTC = 4,
|
|
11
|
+
TRUSTED_FROM_BTCLN = 5,
|
|
12
|
+
SPV_VAULT_FROM_BTC = 6,
|
|
13
|
+
FROM_BTCLN_AUTO = 7
|
|
14
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SwapType = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Enum representing different types of swaps
|
|
6
|
+
* @category Core
|
|
7
|
+
*/
|
|
8
|
+
var SwapType;
|
|
9
|
+
(function (SwapType) {
|
|
10
|
+
SwapType[SwapType["FROM_BTC"] = 0] = "FROM_BTC";
|
|
11
|
+
SwapType[SwapType["FROM_BTCLN"] = 1] = "FROM_BTCLN";
|
|
12
|
+
SwapType[SwapType["TO_BTC"] = 2] = "TO_BTC";
|
|
13
|
+
SwapType[SwapType["TO_BTCLN"] = 3] = "TO_BTCLN";
|
|
14
|
+
SwapType[SwapType["TRUSTED_FROM_BTC"] = 4] = "TRUSTED_FROM_BTC";
|
|
15
|
+
SwapType[SwapType["TRUSTED_FROM_BTCLN"] = 5] = "TRUSTED_FROM_BTCLN";
|
|
16
|
+
SwapType[SwapType["SPV_VAULT_FROM_BTC"] = 6] = "SPV_VAULT_FROM_BTC";
|
|
17
|
+
SwapType[SwapType["FROM_BTCLN_AUTO"] = 7] = "FROM_BTCLN_AUTO";
|
|
18
|
+
})(SwapType = exports.SwapType || (exports.SwapType = {}));
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An error or inconsistency in the intermediary's returned data, this will blacklist the intermediary
|
|
3
|
+
* @category Errors
|
|
4
|
+
*/
|
|
5
|
+
export declare class IntermediaryError extends Error {
|
|
6
|
+
recoverable: boolean;
|
|
7
|
+
originalStack?: string;
|
|
8
|
+
constructor(msg: string, originalError?: any, recoverable?: boolean);
|
|
9
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IntermediaryError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* An error or inconsistency in the intermediary's returned data, this will blacklist the intermediary
|
|
6
|
+
* @category Errors
|
|
7
|
+
*/
|
|
8
|
+
class IntermediaryError extends Error {
|
|
9
|
+
constructor(msg, originalError, recoverable = false) {
|
|
10
|
+
if (originalError != null) {
|
|
11
|
+
if (originalError.name != null)
|
|
12
|
+
msg += ": " + originalError.name;
|
|
13
|
+
if (originalError.message != null)
|
|
14
|
+
msg += ": " + originalError.message;
|
|
15
|
+
if (typeof (originalError) === "string")
|
|
16
|
+
msg += ": " + originalError;
|
|
17
|
+
}
|
|
18
|
+
super(msg);
|
|
19
|
+
if (originalError?.stack != null)
|
|
20
|
+
this.originalStack = originalError.stack;
|
|
21
|
+
this.recoverable = recoverable;
|
|
22
|
+
// Set the prototype explicitly.
|
|
23
|
+
Object.setPrototypeOf(this, IntermediaryError.prototype);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.IntermediaryError = IntermediaryError;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An error when the payment authorization returned by the intermediary is invalid
|
|
3
|
+
* @category Errors
|
|
4
|
+
*/
|
|
5
|
+
export declare class PaymentAuthError extends Error {
|
|
6
|
+
code?: number;
|
|
7
|
+
data: any;
|
|
8
|
+
constructor(msg: string, code?: number, data?: any);
|
|
9
|
+
getCode(): number | undefined;
|
|
10
|
+
getData(): any;
|
|
11
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PaymentAuthError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* An error when the payment authorization returned by the intermediary is invalid
|
|
6
|
+
* @category Errors
|
|
7
|
+
*/
|
|
8
|
+
class PaymentAuthError extends Error {
|
|
9
|
+
constructor(msg, code, data) {
|
|
10
|
+
super(msg);
|
|
11
|
+
this.data = data;
|
|
12
|
+
this.code = code;
|
|
13
|
+
// Set the prototype explicitly.
|
|
14
|
+
Object.setPrototypeOf(this, PaymentAuthError.prototype);
|
|
15
|
+
}
|
|
16
|
+
getCode() {
|
|
17
|
+
return this.code;
|
|
18
|
+
}
|
|
19
|
+
getData() {
|
|
20
|
+
return this.data;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.PaymentAuthError = PaymentAuthError;
|