mainnet-js 1.0.7 → 1.0.9
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/dist/index.html +1 -1
- package/dist/{mainnet-1.0.7.js → mainnet-1.0.9.js} +19 -9
- package/dist/module/config.d.ts +4 -0
- package/dist/module/config.d.ts.map +1 -0
- package/dist/module/config.js +5 -0
- package/dist/module/config.js.map +1 -0
- package/dist/module/index.d.ts +1 -0
- package/dist/module/index.d.ts.map +1 -1
- package/dist/module/index.js +2 -0
- package/dist/module/index.js.map +1 -1
- package/dist/module/mine/mine.d.ts.map +1 -1
- package/dist/module/mine/mine.js +2 -2
- package/dist/module/mine/mine.js.map +1 -1
- package/dist/module/network/ElectrumNetworkProvider.d.ts +6 -2
- package/dist/module/network/ElectrumNetworkProvider.d.ts.map +1 -1
- package/dist/module/network/ElectrumNetworkProvider.js +69 -45
- package/dist/module/network/ElectrumNetworkProvider.js.map +1 -1
- package/dist/module/network/interface.d.ts +11 -8
- package/dist/module/network/interface.d.ts.map +1 -1
- package/dist/module/transaction/Wif.d.ts +1 -1
- package/dist/module/transaction/Wif.d.ts.map +1 -1
- package/dist/module/transaction/Wif.js +17 -9
- package/dist/module/transaction/Wif.js.map +1 -1
- package/dist/module/util/deriveCashaddr.d.ts +1 -0
- package/dist/module/util/deriveCashaddr.d.ts.map +1 -1
- package/dist/module/util/deriveCashaddr.js +5 -0
- package/dist/module/util/deriveCashaddr.js.map +1 -1
- package/dist/module/util/index.d.ts +1 -0
- package/dist/module/util/index.d.ts.map +1 -1
- package/dist/module/util/index.js +1 -0
- package/dist/module/util/index.js.map +1 -1
- package/dist/module/wallet/Util.d.ts.map +1 -1
- package/dist/module/wallet/Util.js +1 -0
- package/dist/module/wallet/Util.js.map +1 -1
- package/dist/module/wallet/Wif.d.ts +3 -0
- package/dist/module/wallet/Wif.d.ts.map +1 -1
- package/dist/module/wallet/Wif.js +20 -26
- package/dist/module/wallet/Wif.js.map +1 -1
- package/dist/module/wallet/interface.d.ts +1 -0
- package/dist/module/wallet/interface.d.ts.map +1 -1
- package/dist/module/wallet/model.d.ts.map +1 -1
- package/dist/module/wallet/model.js +4 -3
- package/dist/module/wallet/model.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/config.ts +4 -0
- package/src/index.ts +3 -0
- package/src/mine/mine.ts +3 -2
- package/src/network/ElectrumNetworkProvider.ts +99 -51
- package/src/network/interface.ts +12 -12
- package/src/transaction/Wif.ts +25 -10
- package/src/util/deriveCashaddr.ts +6 -0
- package/src/util/index.ts +1 -0
- package/src/wallet/Cashtokens.test.ts +149 -6
- package/src/wallet/Util.ts +1 -0
- package/src/wallet/Wif.test.ts +5 -4
- package/src/wallet/Wif.ts +35 -27
- package/src/wallet/interface.ts +1 -0
- package/src/wallet/model.ts +6 -3
|
@@ -948,6 +948,16 @@ eval("/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harm
|
|
|
948
948
|
|
|
949
949
|
/***/ }),
|
|
950
950
|
|
|
951
|
+
/***/ "./src/config.ts":
|
|
952
|
+
/*!***********************!*\
|
|
953
|
+
!*** ./src/config.ts ***!
|
|
954
|
+
\***********************/
|
|
955
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
956
|
+
|
|
957
|
+
eval("/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"Config\": () => (/* binding */ Config)\n/* harmony export */ });\nclass Config {\n}\n// enforces all token-related methods to specify tokenaddr as recepient and change cashaddr\nConfig.EnforceCashTokenReceiptAddresses = false;\n\n\n//# sourceURL=webpack://mainnet-js/./src/config.ts?");
|
|
958
|
+
|
|
959
|
+
/***/ }),
|
|
960
|
+
|
|
951
961
|
/***/ "./src/constant.ts":
|
|
952
962
|
/*!*************************!*\
|
|
953
963
|
!*** ./src/constant.ts ***!
|
|
@@ -1044,7 +1054,7 @@ eval("__webpack_require__.a(module, async (__webpack_handle_async_dependencies__
|
|
|
1044
1054
|
\**********************/
|
|
1045
1055
|
/***/ ((module, __webpack_exports__, __webpack_require__) => {
|
|
1046
1056
|
|
|
1047
|
-
eval("__webpack_require__.a(module, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {\n__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"BCMR\": () => (/* reexport safe */ _wallet_Bcmr_js__WEBPACK_IMPORTED_MODULE_6__.BCMR),\n/* harmony export */ \"BalanceResponse\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_16__.BalanceResponse),\n/* harmony export */ \"BaseWallet\": () => (/* reexport safe */ _wallet_Base_js__WEBPACK_IMPORTED_MODULE_9__.BaseWallet),\n/* harmony export */ \"BigNumber\": () => (/* reexport safe */ _slp_index_js__WEBPACK_IMPORTED_MODULE_2__.BigNumber),\n/* harmony export */ \"CONST\": () => (/* reexport module object */ _constant_js__WEBPACK_IMPORTED_MODULE_19__),\n/* harmony export */ \"Connection\": () => (/* reexport safe */ _network_index_js__WEBPACK_IMPORTED_MODULE_7__.Connection),\n/* harmony export */ \"DefaultProvider\": () => (/* reexport safe */ _network_configuration_js__WEBPACK_IMPORTED_MODULE_12__.DefaultProvider),\n/* harmony export */ \"ExchangeRate\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_16__.ExchangeRate),\n/* harmony export */ \"GsppProvider\": () => (/* reexport safe */ _slp_index_js__WEBPACK_IMPORTED_MODULE_2__.GsppProvider),\n/* harmony export */ \"IndexedDBProvider\": () => (/* reexport safe */ _db_index_js__WEBPACK_IMPORTED_MODULE_0__.IndexedDBProvider),\n/* harmony export */ \"Mainnet\": () => (/* reexport module object */ _util_index_js__WEBPACK_IMPORTED_MODULE_16__),\n/* harmony export */ \"NFTCapability\": () => (/* reexport safe */ _interface_js__WEBPACK_IMPORTED_MODULE_20__.NFTCapability),\n/* harmony export */ \"Network\": () => (/* reexport safe */ _interface_js__WEBPACK_IMPORTED_MODULE_20__.Network),\n/* harmony export */ \"NetworkType\": () => (/* reexport safe */ _enum_js__WEBPACK_IMPORTED_MODULE_13__.NetworkType),\n/* harmony export */ \"OpReturnData\": () => (/* reexport safe */ _wallet_model_js__WEBPACK_IMPORTED_MODULE_15__.OpReturnData),\n/* harmony export */ \"RegTestWallet\": () => (/* reexport safe */ _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_10__.RegTestWallet),\n/* harmony export */ \"RegTestWatchWallet\": () => (/* reexport safe */ _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_10__.RegTestWatchWallet),\n/* harmony export */ \"RegTestWifWallet\": () => (/* reexport safe */ _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_10__.RegTestWifWallet),\n/* harmony export */ \"RuntimePlatform\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_16__.RuntimePlatform),\n/* harmony export */ \"SendRequest\": () => (/* reexport safe */ _wallet_model_js__WEBPACK_IMPORTED_MODULE_15__.SendRequest),\n/* harmony export */ \"SendResponse\": () => (/* reexport safe */ _wallet_model_js__WEBPACK_IMPORTED_MODULE_15__.SendResponse),\n/* harmony export */ \"SignedMessage\": () => (/* reexport safe */ _message_signed_js__WEBPACK_IMPORTED_MODULE_8__.SignedMessage),\n/* harmony export */ \"SlpDbProvider\": () => (/* reexport safe */ _slp_index_js__WEBPACK_IMPORTED_MODULE_2__.SlpDbProvider),\n/* harmony export */ \"SlpTokenType\": () => (/* reexport safe */ _slp_index_js__WEBPACK_IMPORTED_MODULE_2__.SlpTokenType),\n/* harmony export */ \"SqlProvider\": () => (/* reexport safe */ _db_index_js__WEBPACK_IMPORTED_MODULE_0__.SqlProvider),\n/* harmony export */ \"TestNetWallet\": () => (/* reexport safe */ _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_10__.TestNetWallet),\n/* harmony export */ \"TestNetWatchWallet\": () => (/* reexport safe */ _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_10__.TestNetWatchWallet),\n/* harmony export */ \"TestNetWifWallet\": () => (/* reexport safe */ _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_10__.TestNetWifWallet),\n/* harmony export */ \"TokenBurnRequest\": () => (/* reexport safe */ _wallet_model_js__WEBPACK_IMPORTED_MODULE_15__.TokenBurnRequest),\n/* harmony export */ \"TokenGenesisRequest\": () => (/* reexport safe */ _wallet_model_js__WEBPACK_IMPORTED_MODULE_15__.TokenGenesisRequest),\n/* harmony export */ \"TokenMintRequest\": () => (/* reexport safe */ _wallet_model_js__WEBPACK_IMPORTED_MODULE_15__.TokenMintRequest),\n/* harmony export */ \"TokenSendRequest\": () => (/* reexport safe */ _wallet_model_js__WEBPACK_IMPORTED_MODULE_15__.TokenSendRequest),\n/* harmony export */ \"UnitEnum\": () => (/* reexport safe */ _enum_js__WEBPACK_IMPORTED_MODULE_13__.UnitEnum),\n/* harmony export */ \"UtxoItem\": () => (/* reexport safe */ _wallet_model_js__WEBPACK_IMPORTED_MODULE_15__.UtxoItem),\n/* harmony export */ \"UtxoResponse\": () => (/* reexport safe */ _wallet_model_js__WEBPACK_IMPORTED_MODULE_15__.UtxoResponse),\n/* harmony export */ \"Wallet\": () => (/* reexport safe */ _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_10__.Wallet),\n/* harmony export */ \"WalletTypeEnum\": () => (/* reexport safe */ _wallet_enum_js__WEBPACK_IMPORTED_MODULE_14__.WalletTypeEnum),\n/* harmony export */ \"WatchWallet\": () => (/* reexport safe */ _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_10__.WatchWallet),\n/* harmony export */ \"Webhook\": () => (/* reexport safe */ _webhook_index_js__WEBPACK_IMPORTED_MODULE_5__.Webhook),\n/* harmony export */ \"WebhookBch\": () => (/* reexport safe */ _webhook_index_js__WEBPACK_IMPORTED_MODULE_5__.WebhookBch),\n/* harmony export */ \"WebhookRecurrence\": () => (/* reexport safe */ _webhook_index_js__WEBPACK_IMPORTED_MODULE_5__.WebhookRecurrence),\n/* harmony export */ \"WebhookSlp\": () => (/* reexport safe */ _webhook_index_js__WEBPACK_IMPORTED_MODULE_5__.WebhookSlp),\n/* harmony export */ \"WebhookType\": () => (/* reexport safe */ _webhook_index_js__WEBPACK_IMPORTED_MODULE_5__.WebhookType),\n/* harmony export */ \"WebhookWorker\": () => (/* reexport safe */ _webhook_index_js__WEBPACK_IMPORTED_MODULE_5__.WebhookWorker),\n/* harmony export */ \"WifWallet\": () => (/* reexport safe */ _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_10__.WifWallet),\n/* harmony export */ \"XPubKey\": () => (/* reexport safe */ _wallet_model_js__WEBPACK_IMPORTED_MODULE_15__.XPubKey),\n/* harmony export */ \"amountInSatoshi\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_16__.amountInSatoshi),\n/* harmony export */ \"asSendRequestObject\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_16__.asSendRequestObject),\n/* harmony export */ \"atob\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_16__.atob),\n/* harmony export */ \"balanceFromSatoshi\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_16__.balanceFromSatoshi),\n/* harmony export */ \"balanceResponseFromSatoshi\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_16__.balanceResponseFromSatoshi),\n/* harmony export */ \"binToBase64\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_16__.binToBase64),\n/* harmony export */ \"binToHex\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_16__.binToHex),\n/* harmony export */ \"btoa\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_16__.btoa),\n/* harmony export */ \"convert\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_16__.convert),\n/* harmony export */ \"convertObject\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_16__.convertObject),\n/* harmony export */ \"createSlpWallet\": () => (/* reexport safe */ _wallet_createWallet_js__WEBPACK_IMPORTED_MODULE_11__.createSlpWallet),\n/* harmony export */ \"createSlpWalletResponse\": () => (/* reexport safe */ _wallet_createWallet_js__WEBPACK_IMPORTED_MODULE_11__.createSlpWalletResponse),\n/* harmony export */ \"createWallet\": () => (/* reexport safe */ _wallet_createWallet_js__WEBPACK_IMPORTED_MODULE_11__.createWallet),\n/* harmony export */ \"createWalletResponse\": () => (/* reexport safe */ _wallet_createWallet_js__WEBPACK_IMPORTED_MODULE_11__.createWalletResponse),\n/* harmony export */ \"cube\": () => (/* binding */ cube),\n/* harmony export */ \"delay\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_16__.delay),\n/* harmony export */ \"derivePublicKeyHash\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_16__.derivePublicKeyHash),\n/* harmony export */ \"derivedNetwork\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_16__.derivedNetwork),\n/* harmony export */ \"disconnectProviders\": () => (/* reexport safe */ _network_index_js__WEBPACK_IMPORTED_MODULE_7__.disconnectProviders),\n/* harmony export */ \"expect\": () => (/* reexport safe */ _test_expect_js__WEBPACK_IMPORTED_MODULE_3__.expect),\n/* harmony export */ \"getAddrsByXpubKey\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_16__.getAddrsByXpubKey),\n/* harmony export */ \"getAddrsByXpubKeyObject\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_16__.getAddrsByXpubKeyObject),\n/* harmony export */ \"getNetworkProvider\": () => (/* reexport safe */ _network_index_js__WEBPACK_IMPORTED_MODULE_7__.getNetworkProvider),\n/* harmony export */ \"getRandomInt\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_16__.getRandomInt),\n/* harmony export */ \"getRuntimePlatform\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_16__.getRuntimePlatform),\n/* harmony export */ \"getUsdRate\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_16__.getUsdRate),\n/* harmony export */ \"getXPubKey\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_16__.getXPubKey),\n/* harmony export */ \"getXpubKeyInfo\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_16__.getXpubKeyInfo),\n/* harmony export */ \"getXpubKeyInfoObject\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_16__.getXpubKeyInfoObject),\n/* harmony export */ \"hash160\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_16__.hash160),\n/* harmony export */ \"hexToBin\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_16__.hexToBin),\n/* harmony export */ \"initProviders\": () => (/* reexport safe */ _network_index_js__WEBPACK_IMPORTED_MODULE_7__.initProviders),\n/* harmony export */ \"isCashAddress\": () => (/* reexport safe */ _util_bchaddr_js__WEBPACK_IMPORTED_MODULE_21__.isCashAddress),\n/* harmony export */ \"isSlpAddress\": () => (/* reexport safe */ _util_bchaddr_js__WEBPACK_IMPORTED_MODULE_21__.isSlpAddress),\n/* harmony export */ \"isValidAddress\": () => (/* reexport safe */ _util_bchaddr_js__WEBPACK_IMPORTED_MODULE_21__.isValidAddress),\n/* harmony export */ \"libauth\": () => (/* reexport module object */ _libauth_js__WEBPACK_IMPORTED_MODULE_17__),\n/* harmony export */ \"mine\": () => (/* reexport safe */ _mine_index_js__WEBPACK_IMPORTED_MODULE_1__.mine),\n/* harmony export */ \"namedWallet\": () => (/* reexport safe */ _wallet_createWallet_js__WEBPACK_IMPORTED_MODULE_11__.namedWallet),\n/* harmony export */ \"namedWalletExists\": () => (/* reexport safe */ _wallet_createWallet_js__WEBPACK_IMPORTED_MODULE_11__.namedWalletExists),\n/* harmony export */ \"qrAddress\": () => (/* reexport safe */ _qr_Qr_js__WEBPACK_IMPORTED_MODULE_18__.qrAddress),\n/* harmony export */ \"randomValues\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_16__.randomValues),\n/* harmony export */ \"removeAxiosMock\": () => (/* reexport safe */ _test_axios_js__WEBPACK_IMPORTED_MODULE_4__.removeAxiosMock),\n/* harmony export */ \"replaceNamedWallet\": () => (/* reexport safe */ _wallet_createWallet_js__WEBPACK_IMPORTED_MODULE_11__.replaceNamedWallet),\n/* harmony export */ \"sanitizeAddress\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_16__.sanitizeAddress),\n/* harmony export */ \"sanitizeUnit\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_16__.sanitizeUnit),\n/* harmony export */ \"setupAxiosMock\": () => (/* reexport safe */ _test_axios_js__WEBPACK_IMPORTED_MODULE_4__.setupAxiosMock),\n/* harmony export */ \"sha256\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_16__.sha256),\n/* harmony export */ \"sumUtxoValue\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_16__.sumUtxoValue),\n/* harmony export */ \"toCashAddress\": () => (/* reexport safe */ _util_bchaddr_js__WEBPACK_IMPORTED_MODULE_21__.toCashAddress),\n/* harmony export */ \"toSlpAddress\": () => (/* reexport safe */ _util_bchaddr_js__WEBPACK_IMPORTED_MODULE_21__.toSlpAddress),\n/* harmony export */ \"utf8ToBin\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_16__.utf8ToBin),\n/* harmony export */ \"walletClassMap\": () => (/* reexport safe */ _wallet_createWallet_js__WEBPACK_IMPORTED_MODULE_11__.walletClassMap),\n/* harmony export */ \"walletFromId\": () => (/* reexport safe */ _wallet_createWallet_js__WEBPACK_IMPORTED_MODULE_11__.walletFromId)\n/* harmony export */ });\n/* harmony import */ var _db_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./db/index.js */ \"./src/db/index.ts\");\n/* harmony import */ var _mine_index_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./mine/index.js */ \"./src/mine/index.ts\");\n/* harmony import */ var _slp_index_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./slp/index.js */ \"./src/slp/index.ts\");\n/* harmony import */ var _test_expect_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./test/expect.js */ \"./src/test/expect.ts\");\n/* harmony import */ var _test_axios_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./test/axios.js */ \"./src/test/axios.ts\");\n/* harmony import */ var _webhook_index_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./webhook/index.js */ \"./src/webhook/index.ts\");\n/* harmony import */ var _wallet_Bcmr_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./wallet/Bcmr.js */ \"./src/wallet/Bcmr.ts\");\n/* harmony import */ var _network_index_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./network/index.js */ \"./src/network/index.ts\");\n/* harmony import */ var _message_signed_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./message/signed.js */ \"./src/message/signed.ts\");\n/* harmony import */ var _wallet_Base_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./wallet/Base.js */ \"./src/wallet/Base.ts\");\n/* harmony import */ var _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./wallet/Wif.js */ \"./src/wallet/Wif.ts\");\n/* harmony import */ var _wallet_createWallet_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./wallet/createWallet.js */ \"./src/wallet/createWallet.ts\");\n/* harmony import */ var _network_configuration_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./network/configuration.js */ \"./src/network/configuration.ts\");\n/* harmony import */ var _enum_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./enum.js */ \"./src/enum.ts\");\n/* harmony import */ var _wallet_enum_js__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./wallet/enum.js */ \"./src/wallet/enum.ts\");\n/* harmony import */ var _wallet_model_js__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./wallet/model.js */ \"./src/wallet/model.ts\");\n/* harmony import */ var _util_index_js__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ./util/index.js */ \"./src/util/index.ts\");\n/* harmony import */ var _libauth_js__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ./libauth.js */ \"./src/libauth.ts\");\n/* harmony import */ var _qr_Qr_js__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ./qr/Qr.js */ \"./src/qr/Qr.ts\");\n/* harmony import */ var _constant_js__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! ./constant.js */ \"./src/constant.ts\");\n/* harmony import */ var _interface_js__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(/*! ./interface.js */ \"./src/interface.ts\");\n/* harmony import */ var _util_bchaddr_js__WEBPACK_IMPORTED_MODULE_21__ = __webpack_require__(/*! ./util/bchaddr.js */ \"./src/util/bchaddr.ts\");\nvar __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_slp_index_js__WEBPACK_IMPORTED_MODULE_2__, _webhook_index_js__WEBPACK_IMPORTED_MODULE_5__, _wallet_Bcmr_js__WEBPACK_IMPORTED_MODULE_6__, _network_index_js__WEBPACK_IMPORTED_MODULE_7__, _message_signed_js__WEBPACK_IMPORTED_MODULE_8__, _wallet_Base_js__WEBPACK_IMPORTED_MODULE_9__, _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_10__, _wallet_createWallet_js__WEBPACK_IMPORTED_MODULE_11__, _network_configuration_js__WEBPACK_IMPORTED_MODULE_12__, _enum_js__WEBPACK_IMPORTED_MODULE_13__, _wallet_model_js__WEBPACK_IMPORTED_MODULE_15__, _util_index_js__WEBPACK_IMPORTED_MODULE_16__, _libauth_js__WEBPACK_IMPORTED_MODULE_17__, _qr_Qr_js__WEBPACK_IMPORTED_MODULE_18__]);\n([_slp_index_js__WEBPACK_IMPORTED_MODULE_2__, _webhook_index_js__WEBPACK_IMPORTED_MODULE_5__, _wallet_Bcmr_js__WEBPACK_IMPORTED_MODULE_6__, _network_index_js__WEBPACK_IMPORTED_MODULE_7__, _message_signed_js__WEBPACK_IMPORTED_MODULE_8__, _wallet_Base_js__WEBPACK_IMPORTED_MODULE_9__, _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_10__, _wallet_createWallet_js__WEBPACK_IMPORTED_MODULE_11__, _network_configuration_js__WEBPACK_IMPORTED_MODULE_12__, _enum_js__WEBPACK_IMPORTED_MODULE_13__, _wallet_model_js__WEBPACK_IMPORTED_MODULE_15__, _util_index_js__WEBPACK_IMPORTED_MODULE_16__, _libauth_js__WEBPACK_IMPORTED_MODULE_17__, _qr_Qr_js__WEBPACK_IMPORTED_MODULE_18__] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);\n\n\n\n\n\n\n\n\n\n\n\n\n// provider\n\n// Enum\n\n\n// models\n\n// utils\n\n\n\n// libauth\n\n// qr\n\n// constants\n\n\n// interfaces\n\n// TODO move this up to util (Mainnet) ?\n\nfunction cube(x) {\n return x * x * x;\n}\n\n__webpack_async_result__();\n} catch(e) { __webpack_async_result__(e); } });\n\n//# sourceURL=webpack://mainnet-js/./src/index.ts?");
|
|
1057
|
+
eval("__webpack_require__.a(module, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {\n__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"BCMR\": () => (/* reexport safe */ _wallet_Bcmr_js__WEBPACK_IMPORTED_MODULE_6__.BCMR),\n/* harmony export */ \"BalanceResponse\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_17__.BalanceResponse),\n/* harmony export */ \"BaseWallet\": () => (/* reexport safe */ _wallet_Base_js__WEBPACK_IMPORTED_MODULE_9__.BaseWallet),\n/* harmony export */ \"BigNumber\": () => (/* reexport safe */ _slp_index_js__WEBPACK_IMPORTED_MODULE_2__.BigNumber),\n/* harmony export */ \"CONST\": () => (/* reexport module object */ _constant_js__WEBPACK_IMPORTED_MODULE_20__),\n/* harmony export */ \"Config\": () => (/* reexport safe */ _config_js__WEBPACK_IMPORTED_MODULE_13__.Config),\n/* harmony export */ \"Connection\": () => (/* reexport safe */ _network_index_js__WEBPACK_IMPORTED_MODULE_7__.Connection),\n/* harmony export */ \"DefaultProvider\": () => (/* reexport safe */ _network_configuration_js__WEBPACK_IMPORTED_MODULE_12__.DefaultProvider),\n/* harmony export */ \"ExchangeRate\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_17__.ExchangeRate),\n/* harmony export */ \"GsppProvider\": () => (/* reexport safe */ _slp_index_js__WEBPACK_IMPORTED_MODULE_2__.GsppProvider),\n/* harmony export */ \"IndexedDBProvider\": () => (/* reexport safe */ _db_index_js__WEBPACK_IMPORTED_MODULE_0__.IndexedDBProvider),\n/* harmony export */ \"Mainnet\": () => (/* reexport module object */ _util_index_js__WEBPACK_IMPORTED_MODULE_17__),\n/* harmony export */ \"NFTCapability\": () => (/* reexport safe */ _interface_js__WEBPACK_IMPORTED_MODULE_21__.NFTCapability),\n/* harmony export */ \"Network\": () => (/* reexport safe */ _interface_js__WEBPACK_IMPORTED_MODULE_21__.Network),\n/* harmony export */ \"NetworkType\": () => (/* reexport safe */ _enum_js__WEBPACK_IMPORTED_MODULE_14__.NetworkType),\n/* harmony export */ \"OpReturnData\": () => (/* reexport safe */ _wallet_model_js__WEBPACK_IMPORTED_MODULE_16__.OpReturnData),\n/* harmony export */ \"RegTestWallet\": () => (/* reexport safe */ _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_10__.RegTestWallet),\n/* harmony export */ \"RegTestWatchWallet\": () => (/* reexport safe */ _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_10__.RegTestWatchWallet),\n/* harmony export */ \"RegTestWifWallet\": () => (/* reexport safe */ _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_10__.RegTestWifWallet),\n/* harmony export */ \"RuntimePlatform\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_17__.RuntimePlatform),\n/* harmony export */ \"SendRequest\": () => (/* reexport safe */ _wallet_model_js__WEBPACK_IMPORTED_MODULE_16__.SendRequest),\n/* harmony export */ \"SendResponse\": () => (/* reexport safe */ _wallet_model_js__WEBPACK_IMPORTED_MODULE_16__.SendResponse),\n/* harmony export */ \"SignedMessage\": () => (/* reexport safe */ _message_signed_js__WEBPACK_IMPORTED_MODULE_8__.SignedMessage),\n/* harmony export */ \"SlpDbProvider\": () => (/* reexport safe */ _slp_index_js__WEBPACK_IMPORTED_MODULE_2__.SlpDbProvider),\n/* harmony export */ \"SlpTokenType\": () => (/* reexport safe */ _slp_index_js__WEBPACK_IMPORTED_MODULE_2__.SlpTokenType),\n/* harmony export */ \"SqlProvider\": () => (/* reexport safe */ _db_index_js__WEBPACK_IMPORTED_MODULE_0__.SqlProvider),\n/* harmony export */ \"TestNetWallet\": () => (/* reexport safe */ _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_10__.TestNetWallet),\n/* harmony export */ \"TestNetWatchWallet\": () => (/* reexport safe */ _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_10__.TestNetWatchWallet),\n/* harmony export */ \"TestNetWifWallet\": () => (/* reexport safe */ _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_10__.TestNetWifWallet),\n/* harmony export */ \"TokenBurnRequest\": () => (/* reexport safe */ _wallet_model_js__WEBPACK_IMPORTED_MODULE_16__.TokenBurnRequest),\n/* harmony export */ \"TokenGenesisRequest\": () => (/* reexport safe */ _wallet_model_js__WEBPACK_IMPORTED_MODULE_16__.TokenGenesisRequest),\n/* harmony export */ \"TokenMintRequest\": () => (/* reexport safe */ _wallet_model_js__WEBPACK_IMPORTED_MODULE_16__.TokenMintRequest),\n/* harmony export */ \"TokenSendRequest\": () => (/* reexport safe */ _wallet_model_js__WEBPACK_IMPORTED_MODULE_16__.TokenSendRequest),\n/* harmony export */ \"UnitEnum\": () => (/* reexport safe */ _enum_js__WEBPACK_IMPORTED_MODULE_14__.UnitEnum),\n/* harmony export */ \"UtxoItem\": () => (/* reexport safe */ _wallet_model_js__WEBPACK_IMPORTED_MODULE_16__.UtxoItem),\n/* harmony export */ \"UtxoResponse\": () => (/* reexport safe */ _wallet_model_js__WEBPACK_IMPORTED_MODULE_16__.UtxoResponse),\n/* harmony export */ \"Wallet\": () => (/* reexport safe */ _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_10__.Wallet),\n/* harmony export */ \"WalletTypeEnum\": () => (/* reexport safe */ _wallet_enum_js__WEBPACK_IMPORTED_MODULE_15__.WalletTypeEnum),\n/* harmony export */ \"WatchWallet\": () => (/* reexport safe */ _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_10__.WatchWallet),\n/* harmony export */ \"Webhook\": () => (/* reexport safe */ _webhook_index_js__WEBPACK_IMPORTED_MODULE_5__.Webhook),\n/* harmony export */ \"WebhookBch\": () => (/* reexport safe */ _webhook_index_js__WEBPACK_IMPORTED_MODULE_5__.WebhookBch),\n/* harmony export */ \"WebhookRecurrence\": () => (/* reexport safe */ _webhook_index_js__WEBPACK_IMPORTED_MODULE_5__.WebhookRecurrence),\n/* harmony export */ \"WebhookSlp\": () => (/* reexport safe */ _webhook_index_js__WEBPACK_IMPORTED_MODULE_5__.WebhookSlp),\n/* harmony export */ \"WebhookType\": () => (/* reexport safe */ _webhook_index_js__WEBPACK_IMPORTED_MODULE_5__.WebhookType),\n/* harmony export */ \"WebhookWorker\": () => (/* reexport safe */ _webhook_index_js__WEBPACK_IMPORTED_MODULE_5__.WebhookWorker),\n/* harmony export */ \"WifWallet\": () => (/* reexport safe */ _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_10__.WifWallet),\n/* harmony export */ \"XPubKey\": () => (/* reexport safe */ _wallet_model_js__WEBPACK_IMPORTED_MODULE_16__.XPubKey),\n/* harmony export */ \"amountInSatoshi\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_17__.amountInSatoshi),\n/* harmony export */ \"asSendRequestObject\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_17__.asSendRequestObject),\n/* harmony export */ \"atob\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_17__.atob),\n/* harmony export */ \"balanceFromSatoshi\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_17__.balanceFromSatoshi),\n/* harmony export */ \"balanceResponseFromSatoshi\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_17__.balanceResponseFromSatoshi),\n/* harmony export */ \"binToBase64\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_17__.binToBase64),\n/* harmony export */ \"binToHex\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_17__.binToHex),\n/* harmony export */ \"btoa\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_17__.btoa),\n/* harmony export */ \"checkTokenaddr\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_17__.checkTokenaddr),\n/* harmony export */ \"convert\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_17__.convert),\n/* harmony export */ \"convertObject\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_17__.convertObject),\n/* harmony export */ \"createSlpWallet\": () => (/* reexport safe */ _wallet_createWallet_js__WEBPACK_IMPORTED_MODULE_11__.createSlpWallet),\n/* harmony export */ \"createSlpWalletResponse\": () => (/* reexport safe */ _wallet_createWallet_js__WEBPACK_IMPORTED_MODULE_11__.createSlpWalletResponse),\n/* harmony export */ \"createWallet\": () => (/* reexport safe */ _wallet_createWallet_js__WEBPACK_IMPORTED_MODULE_11__.createWallet),\n/* harmony export */ \"createWalletResponse\": () => (/* reexport safe */ _wallet_createWallet_js__WEBPACK_IMPORTED_MODULE_11__.createWalletResponse),\n/* harmony export */ \"cube\": () => (/* binding */ cube),\n/* harmony export */ \"delay\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_17__.delay),\n/* harmony export */ \"deriveCashaddr\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_17__.deriveCashaddr),\n/* harmony export */ \"derivePublicKeyHash\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_17__.derivePublicKeyHash),\n/* harmony export */ \"deriveTokenaddr\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_17__.deriveTokenaddr),\n/* harmony export */ \"derivedNetwork\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_17__.derivedNetwork),\n/* harmony export */ \"disconnectProviders\": () => (/* reexport safe */ _network_index_js__WEBPACK_IMPORTED_MODULE_7__.disconnectProviders),\n/* harmony export */ \"expect\": () => (/* reexport safe */ _test_expect_js__WEBPACK_IMPORTED_MODULE_3__.expect),\n/* harmony export */ \"getAddrsByXpubKey\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_17__.getAddrsByXpubKey),\n/* harmony export */ \"getAddrsByXpubKeyObject\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_17__.getAddrsByXpubKeyObject),\n/* harmony export */ \"getNetworkProvider\": () => (/* reexport safe */ _network_index_js__WEBPACK_IMPORTED_MODULE_7__.getNetworkProvider),\n/* harmony export */ \"getRandomInt\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_17__.getRandomInt),\n/* harmony export */ \"getRuntimePlatform\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_17__.getRuntimePlatform),\n/* harmony export */ \"getUsdRate\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_17__.getUsdRate),\n/* harmony export */ \"getXPubKey\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_17__.getXPubKey),\n/* harmony export */ \"getXpubKeyInfo\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_17__.getXpubKeyInfo),\n/* harmony export */ \"getXpubKeyInfoObject\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_17__.getXpubKeyInfoObject),\n/* harmony export */ \"hash160\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_17__.hash160),\n/* harmony export */ \"hexToBin\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_17__.hexToBin),\n/* harmony export */ \"initProviders\": () => (/* reexport safe */ _network_index_js__WEBPACK_IMPORTED_MODULE_7__.initProviders),\n/* harmony export */ \"isCashAddress\": () => (/* reexport safe */ _util_bchaddr_js__WEBPACK_IMPORTED_MODULE_22__.isCashAddress),\n/* harmony export */ \"isSlpAddress\": () => (/* reexport safe */ _util_bchaddr_js__WEBPACK_IMPORTED_MODULE_22__.isSlpAddress),\n/* harmony export */ \"isTokenaddr\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_17__.isTokenaddr),\n/* harmony export */ \"isValidAddress\": () => (/* reexport safe */ _util_bchaddr_js__WEBPACK_IMPORTED_MODULE_22__.isValidAddress),\n/* harmony export */ \"libauth\": () => (/* reexport module object */ _libauth_js__WEBPACK_IMPORTED_MODULE_18__),\n/* harmony export */ \"mine\": () => (/* reexport safe */ _mine_index_js__WEBPACK_IMPORTED_MODULE_1__.mine),\n/* harmony export */ \"namedWallet\": () => (/* reexport safe */ _wallet_createWallet_js__WEBPACK_IMPORTED_MODULE_11__.namedWallet),\n/* harmony export */ \"namedWalletExists\": () => (/* reexport safe */ _wallet_createWallet_js__WEBPACK_IMPORTED_MODULE_11__.namedWalletExists),\n/* harmony export */ \"qrAddress\": () => (/* reexport safe */ _qr_Qr_js__WEBPACK_IMPORTED_MODULE_19__.qrAddress),\n/* harmony export */ \"randomValues\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_17__.randomValues),\n/* harmony export */ \"removeAxiosMock\": () => (/* reexport safe */ _test_axios_js__WEBPACK_IMPORTED_MODULE_4__.removeAxiosMock),\n/* harmony export */ \"replaceNamedWallet\": () => (/* reexport safe */ _wallet_createWallet_js__WEBPACK_IMPORTED_MODULE_11__.replaceNamedWallet),\n/* harmony export */ \"sanitizeAddress\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_17__.sanitizeAddress),\n/* harmony export */ \"sanitizeUnit\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_17__.sanitizeUnit),\n/* harmony export */ \"setupAxiosMock\": () => (/* reexport safe */ _test_axios_js__WEBPACK_IMPORTED_MODULE_4__.setupAxiosMock),\n/* harmony export */ \"sha256\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_17__.sha256),\n/* harmony export */ \"sumUtxoValue\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_17__.sumUtxoValue),\n/* harmony export */ \"toCashAddress\": () => (/* reexport safe */ _util_bchaddr_js__WEBPACK_IMPORTED_MODULE_22__.toCashAddress),\n/* harmony export */ \"toCashaddr\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_17__.toCashaddr),\n/* harmony export */ \"toSlpAddress\": () => (/* reexport safe */ _util_bchaddr_js__WEBPACK_IMPORTED_MODULE_22__.toSlpAddress),\n/* harmony export */ \"toTokenaddr\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_17__.toTokenaddr),\n/* harmony export */ \"utf8ToBin\": () => (/* reexport safe */ _util_index_js__WEBPACK_IMPORTED_MODULE_17__.utf8ToBin),\n/* harmony export */ \"walletClassMap\": () => (/* reexport safe */ _wallet_createWallet_js__WEBPACK_IMPORTED_MODULE_11__.walletClassMap),\n/* harmony export */ \"walletFromId\": () => (/* reexport safe */ _wallet_createWallet_js__WEBPACK_IMPORTED_MODULE_11__.walletFromId)\n/* harmony export */ });\n/* harmony import */ var _db_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./db/index.js */ \"./src/db/index.ts\");\n/* harmony import */ var _mine_index_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./mine/index.js */ \"./src/mine/index.ts\");\n/* harmony import */ var _slp_index_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./slp/index.js */ \"./src/slp/index.ts\");\n/* harmony import */ var _test_expect_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./test/expect.js */ \"./src/test/expect.ts\");\n/* harmony import */ var _test_axios_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./test/axios.js */ \"./src/test/axios.ts\");\n/* harmony import */ var _webhook_index_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./webhook/index.js */ \"./src/webhook/index.ts\");\n/* harmony import */ var _wallet_Bcmr_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./wallet/Bcmr.js */ \"./src/wallet/Bcmr.ts\");\n/* harmony import */ var _network_index_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./network/index.js */ \"./src/network/index.ts\");\n/* harmony import */ var _message_signed_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./message/signed.js */ \"./src/message/signed.ts\");\n/* harmony import */ var _wallet_Base_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./wallet/Base.js */ \"./src/wallet/Base.ts\");\n/* harmony import */ var _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./wallet/Wif.js */ \"./src/wallet/Wif.ts\");\n/* harmony import */ var _wallet_createWallet_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./wallet/createWallet.js */ \"./src/wallet/createWallet.ts\");\n/* harmony import */ var _network_configuration_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./network/configuration.js */ \"./src/network/configuration.ts\");\n/* harmony import */ var _config_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./config.js */ \"./src/config.ts\");\n/* harmony import */ var _enum_js__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./enum.js */ \"./src/enum.ts\");\n/* harmony import */ var _wallet_enum_js__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./wallet/enum.js */ \"./src/wallet/enum.ts\");\n/* harmony import */ var _wallet_model_js__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ./wallet/model.js */ \"./src/wallet/model.ts\");\n/* harmony import */ var _util_index_js__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ./util/index.js */ \"./src/util/index.ts\");\n/* harmony import */ var _libauth_js__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ./libauth.js */ \"./src/libauth.ts\");\n/* harmony import */ var _qr_Qr_js__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! ./qr/Qr.js */ \"./src/qr/Qr.ts\");\n/* harmony import */ var _constant_js__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(/*! ./constant.js */ \"./src/constant.ts\");\n/* harmony import */ var _interface_js__WEBPACK_IMPORTED_MODULE_21__ = __webpack_require__(/*! ./interface.js */ \"./src/interface.ts\");\n/* harmony import */ var _util_bchaddr_js__WEBPACK_IMPORTED_MODULE_22__ = __webpack_require__(/*! ./util/bchaddr.js */ \"./src/util/bchaddr.ts\");\nvar __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_slp_index_js__WEBPACK_IMPORTED_MODULE_2__, _webhook_index_js__WEBPACK_IMPORTED_MODULE_5__, _wallet_Bcmr_js__WEBPACK_IMPORTED_MODULE_6__, _network_index_js__WEBPACK_IMPORTED_MODULE_7__, _message_signed_js__WEBPACK_IMPORTED_MODULE_8__, _wallet_Base_js__WEBPACK_IMPORTED_MODULE_9__, _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_10__, _wallet_createWallet_js__WEBPACK_IMPORTED_MODULE_11__, _network_configuration_js__WEBPACK_IMPORTED_MODULE_12__, _enum_js__WEBPACK_IMPORTED_MODULE_14__, _wallet_model_js__WEBPACK_IMPORTED_MODULE_16__, _util_index_js__WEBPACK_IMPORTED_MODULE_17__, _libauth_js__WEBPACK_IMPORTED_MODULE_18__, _qr_Qr_js__WEBPACK_IMPORTED_MODULE_19__]);\n([_slp_index_js__WEBPACK_IMPORTED_MODULE_2__, _webhook_index_js__WEBPACK_IMPORTED_MODULE_5__, _wallet_Bcmr_js__WEBPACK_IMPORTED_MODULE_6__, _network_index_js__WEBPACK_IMPORTED_MODULE_7__, _message_signed_js__WEBPACK_IMPORTED_MODULE_8__, _wallet_Base_js__WEBPACK_IMPORTED_MODULE_9__, _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_10__, _wallet_createWallet_js__WEBPACK_IMPORTED_MODULE_11__, _network_configuration_js__WEBPACK_IMPORTED_MODULE_12__, _enum_js__WEBPACK_IMPORTED_MODULE_14__, _wallet_model_js__WEBPACK_IMPORTED_MODULE_16__, _util_index_js__WEBPACK_IMPORTED_MODULE_17__, _libauth_js__WEBPACK_IMPORTED_MODULE_18__, _qr_Qr_js__WEBPACK_IMPORTED_MODULE_19__] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);\n\n\n\n\n\n\n\n\n\n\n\n\n// provider\n\n// config\n\n// Enum\n\n\n// models\n\n// utils\n\n\n\n// libauth\n\n// qr\n\n// constants\n\n\n// interfaces\n\n// TODO move this up to util (Mainnet) ?\n\nfunction cube(x) {\n return x * x * x;\n}\n\n__webpack_async_result__();\n} catch(e) { __webpack_async_result__(e); } });\n\n//# sourceURL=webpack://mainnet-js/./src/index.ts?");
|
|
1048
1058
|
|
|
1049
1059
|
/***/ }),
|
|
1050
1060
|
|
|
@@ -1094,7 +1104,7 @@ eval("/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harm
|
|
|
1094
1104
|
\**************************/
|
|
1095
1105
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
1096
1106
|
|
|
1097
|
-
eval("/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"mine\": () => (/* binding */ mine)\n/* harmony export */ });\n/* harmony import */ var _util_browserNotSupported_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../util/browserNotSupported.js */ \"./src/util/browserNotSupported.ts\");\n/* harmony import */ var child_process__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! child_process */ \"?67af\");\n/* harmony import */ var child_process__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(child_process__WEBPACK_IMPORTED_MODULE_0__);\n\n\n/**\n * Mine blocks to a regtest address\n *\n * @param cashaddr - the address to mine to\n * @param blocks - the number of blocks to mine\n *\n * @remarks\n * This function assumes a local regtest bitcoin node with RPC_* matching the docker configuration\n */\nasync function mine({ cashaddr, blocks, }) {\n // node only\n (0,_util_browserNotSupported_js__WEBPACK_IMPORTED_MODULE_1__.browserNotSupported)();\n const generateArgs = [\n `exec`,\n `bitcoind`,\n `bitcoin-cli`,\n `--rpcconnect=${process.env.RPC_HOST}`,\n `--rpcuser=${process.env.RPC_USER}`,\n `--rpcpassword=${process.env.RPC_PASS}`,\n `--rpcport=${process.env.RPC_PORT}`,\n `generatetoaddress`,\n blocks,\n cashaddr,\n ];\n const cli = (
|
|
1107
|
+
eval("/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"mine\": () => (/* binding */ mine)\n/* harmony export */ });\n/* harmony import */ var _util_browserNotSupported_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../util/browserNotSupported.js */ \"./src/util/browserNotSupported.ts\");\n/* harmony import */ var child_process__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! child_process */ \"?67af\");\n/* harmony import */ var child_process__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(child_process__WEBPACK_IMPORTED_MODULE_0__);\n\n\n/**\n * Mine blocks to a regtest address\n *\n * @param cashaddr - the address to mine to\n * @param blocks - the number of blocks to mine\n *\n * @remarks\n * This function assumes a local regtest bitcoin node with RPC_* matching the docker configuration\n */\nasync function mine({ cashaddr, blocks, }) {\n // node only\n (0,_util_browserNotSupported_js__WEBPACK_IMPORTED_MODULE_1__.browserNotSupported)();\n const generateArgs = [\n `exec`,\n `bitcoind`,\n `bitcoin-cli`,\n `--rpcconnect=${process.env.RPC_HOST}`,\n `--rpcuser=${process.env.RPC_USER}`,\n `--rpcpassword=${process.env.RPC_PASS}`,\n `--rpcport=${process.env.RPC_PORT}`,\n `generatetoaddress`,\n blocks,\n cashaddr,\n ];\n const cli = child_process__WEBPACK_IMPORTED_MODULE_0___default().spawnSync(`docker`, generateArgs);\n if (cli.stderr.length > 0) {\n return console.log(\"Mine Error: \" + cli.stderr.toString());\n }\n return JSON.parse(cli.stdout.toString());\n}\n\n\n//# sourceURL=webpack://mainnet-js/./src/mine/mine.ts?");
|
|
1098
1108
|
|
|
1099
1109
|
/***/ }),
|
|
1100
1110
|
|
|
@@ -1114,7 +1124,7 @@ eval("__webpack_require__.a(module, async (__webpack_handle_async_dependencies__
|
|
|
1114
1124
|
\************************************************/
|
|
1115
1125
|
/***/ ((module, __webpack_exports__, __webpack_require__) => {
|
|
1116
1126
|
|
|
1117
|
-
eval("__webpack_require__.a(module, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* binding */ ElectrumNetworkProvider)\n/* harmony export */ });\n/* harmony import */ var electrum_cash__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! electrum-cash */ \"../../node_modules/electrum-cash/dist/index.mjs.js\");\n/* harmony import */ var _interface_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../interface.js */ \"./src/interface.ts\");\n/* harmony import */ var _util_delay_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../util/delay.js */ \"./src/util/delay.ts\");\n/* harmony import */ var async_mutex__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! async-mutex */ \"../../node_modules/async-mutex/index.mjs\");\n/* harmony import */ var _util_transaction_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../util/transaction.js */ \"./src/util/transaction.ts\");\nvar __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_util_transaction_js__WEBPACK_IMPORTED_MODULE_3__]);\n_util_transaction_js__WEBPACK_IMPORTED_MODULE_3__ = (__webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__)[0];\n\n\n\n\n\nclass ElectrumNetworkProvider {\n constructor(electrum, network = _interface_js__WEBPACK_IMPORTED_MODULE_2__.Network.MAINNET, manualConnectionManagement) {\n this.network = network;\n this.manualConnectionManagement = manualConnectionManagement;\n this.subscriptions = 0;\n this.mutex = new async_mutex__WEBPACK_IMPORTED_MODULE_1__.Mutex();\n this.blockHeight = 0;\n if (electrum) {\n this.electrum = electrum;\n this.connectPromise = this.getConnectPromise();\n }\n else {\n throw new Error(`A electrum-cash cluster or client is required.`);\n }\n }\n async getConnectPromise(_timeout = 3000) {\n // connects to the electrum cash and waits until the connection is ready to accept requests\n let timeoutHandle;\n await Promise.race([\n new Promise(async (resolve) => {\n this.connectPromise = undefined;\n if (this.electrum instanceof electrum_cash__WEBPACK_IMPORTED_MODULE_0__.ElectrumCluster) {\n try {\n await this.connectCluster();\n }\n catch (e) {\n console.warn(`Unable to connect to one or more electrum-cash hosts: ${JSON.stringify(e)}`);\n }\n resolve(await this.readyCluster());\n }\n else {\n resolve(await this.connectClient());\n }\n }),\n // new Promise(\n // (_resolve, reject) =>\n // (timeoutHandle = setTimeout(() => {\n // reject(\n // new Error(`Timeout connecting to electrum network: ${this.network}`)\n // );\n // }, _timeout))\n // ),\n ]);\n clearTimeout(timeoutHandle);\n }\n async getUtxos(cashaddr) {\n const result = (await this.performRequest(\"blockchain.address.listunspent\", cashaddr));\n if (this.network === _interface_js__WEBPACK_IMPORTED_MODULE_2__.Network.MAINNET) {\n return result.map((utxo) => ({\n txid: utxo.tx_hash,\n vout: utxo.tx_pos,\n satoshis: utxo.value,\n height: utxo.height,\n }));\n }\n return result.map((utxo) => ({\n txid: utxo.tx_hash,\n vout: utxo.tx_pos,\n satoshis: utxo.value,\n height: utxo.height,\n token: utxo.token_data\n ? {\n amount: Number(utxo.token_data.amount),\n tokenId: utxo.token_data.category,\n capability: utxo.token_data.nft?.capability,\n commitment: utxo.token_data.nft?.commitment,\n }\n : undefined,\n }));\n }\n async getBalance(cashaddr) {\n const result = (await this.performRequest(\"blockchain.address.get_balance\", cashaddr));\n return result.confirmed + result.unconfirmed;\n }\n async getBlockHeight() {\n if (!this.blockHeight) {\n return new Promise(async (resolve) => {\n await this.subscribeToHeaders((header) => {\n this.blockHeight = header.height;\n });\n resolve(this.blockHeight);\n });\n }\n return this.blockHeight;\n }\n async getRawTransaction(txHash, verbose = false) {\n const key = `${this.network}-${txHash}-${verbose}`;\n if (ElectrumNetworkProvider.rawTransactionCache[key]) {\n return ElectrumNetworkProvider.rawTransactionCache[key];\n }\n try {\n const result = await this.performRequest(\"blockchain.transaction.get\", txHash, verbose);\n ElectrumNetworkProvider.rawTransactionCache[key] = result;\n return result;\n }\n catch (error) {\n if (error.message.indexOf(\"No such mempool or blockchain transaction.\") > -1)\n throw Error(`Could not decode transaction ${txHash}. It might not exist on the current blockchain (${this.network}).`);\n else\n throw error;\n }\n }\n // gets the decoded transaction in human readable form\n async getRawTransactionObject(txHash) {\n return (await this.getRawTransaction(txHash, true));\n }\n async sendRawTransaction(txHex, awaitPropagation = true) {\n return new Promise(async (resolve, reject) => {\n let txHash = await (0,_util_transaction_js__WEBPACK_IMPORTED_MODULE_3__.getTransactionHash)(txHex);\n if (!awaitPropagation) {\n this.performRequest(\"blockchain.transaction.broadcast\", txHex);\n resolve(txHash);\n }\n else {\n const waitForTransactionCallback = async (data) => {\n if (data && data[0] === txHash) {\n this.unsubscribeFromTransaction(txHash, waitForTransactionCallback);\n resolve(txHash);\n }\n };\n this.subscribeToTransaction(txHash, waitForTransactionCallback);\n this.performRequest(\"blockchain.transaction.broadcast\", txHex).catch((error) => {\n this.unsubscribeFromTransaction(txHash, waitForTransactionCallback);\n reject(error);\n });\n }\n });\n }\n // Get transaction history of a given cashaddr\n async getHistory(cashaddr) {\n const result = (await this.performRequest(\"blockchain.address.get_history\", cashaddr));\n return result;\n }\n // Get the minimum fee a low-priority transaction must pay in order to be accepted to the daemon's memory pool.\n async getRelayFee() {\n const result = (await this.performRequest(\"blockchain.relayfee\"));\n return result;\n }\n watchAddressStatus(cashaddr, callback) {\n const watchAddressStatusCallback = async (data) => {\n // subscription acknowledgement is the latest known status or null if no status is known\n // status is an array: [ cashaddr, statusHash ]\n if (data instanceof Array) {\n const addr = data[0];\n if (addr !== cashaddr) {\n return;\n }\n const status = data[1];\n callback(status);\n }\n };\n this.subscribeToAddress(cashaddr, watchAddressStatusCallback);\n return async () => {\n await this.unsubscribeFromAddress(cashaddr, watchAddressStatusCallback);\n };\n }\n // public watchAddress(\n // cashaddr: string,\n // callback: (txHash: string) => void\n // ): CancelWatchFn {\n // const watchAddressCallback = async (data) => {\n // // subscription acknowledgement is the latest known status or null if no status is known\n // // status is an array: [ cashaddr, [tx_hashes] ]\n // if (data instanceof Array) {\n // let addr = data[0] as string;\n // if (addr !== cashaddr) {\n // return;\n // }\n // for (const txHash of data[1]) {\n // if (!txHash) {\n // // data[1] can be null eventually if there are no tx for this address\n // continue;\n // }\n // callback(txHash);\n // }\n // }\n // };\n // this.subscribeToAddressTransactions(cashaddr, watchAddressCallback);\n // return async () => {\n // await this.unsubscribeFromAddressTransactions(\n // cashaddr,\n // watchAddressCallback\n // );\n // };\n // }\n // public watchAddressTransactions(\n // cashaddr: string,\n // callback: (tx: ElectrumRawTransaction) => void\n // ): CancelWatchFn {\n // return this.watchAddress(cashaddr, async (txHash: string) => {\n // const tx = await this.getRawTransactionObject(txHash);\n // callback(tx);\n // });\n // }\n // Wait for the next block or a block at given blockchain height.\n watchBlocks(callback) {\n let acknowledged = false;\n const waitForBlockCallback = (_header) => {\n if (!acknowledged) {\n acknowledged = true;\n return;\n }\n _header = _header instanceof Array ? _header[0] : _header;\n callback(_header);\n };\n this.subscribeToHeaders(waitForBlockCallback);\n return async () => {\n this.unsubscribeFromHeaders(waitForBlockCallback);\n };\n }\n // Wait for the next block or a block at given blockchain height.\n async waitForBlock(height) {\n return new Promise(async (resolve) => {\n const cancelWatch = this.watchBlocks(async (header) => {\n if (height === undefined || header.height >= height) {\n await cancelWatch();\n resolve(header);\n }\n });\n });\n }\n // subscribe to notifications sent when new block is found, the block header is sent to callback\n async subscribeToHeaders(callback) {\n await this.subscribeRequest(\"blockchain.headers.subscribe\", callback);\n }\n // unsubscribe to notifications sent when new block is found\n async unsubscribeFromHeaders(callback) {\n await this.unsubscribeRequest(\"blockchain.headers.subscribe\", callback);\n }\n async subscribeToAddress(cashaddr, callback) {\n await this.subscribeRequest(\"blockchain.address.subscribe\", callback, cashaddr);\n }\n async unsubscribeFromAddress(cashaddr, callback) {\n await this.unsubscribeRequest(\"blockchain.address.subscribe\", callback, cashaddr);\n }\n async subscribeToAddressTransactions(cashaddr, callback) {\n await this.subscribeRequest(\"blockchain.address.transactions.subscribe\", callback, cashaddr);\n }\n async unsubscribeFromAddressTransactions(cashaddr, callback) {\n await this.unsubscribeRequest(\"blockchain.address.transactions.subscribe\", callback, cashaddr);\n }\n async subscribeToTransaction(txHash, callback) {\n await this.subscribeRequest(\"blockchain.transaction.subscribe\", callback, txHash);\n }\n async unsubscribeFromTransaction(txHash, callback) {\n await this.unsubscribeRequest(\"blockchain.transaction.subscribe\", callback, txHash);\n }\n async performRequest(name, ...parameters) {\n await this.ready();\n const requestTimeout = new Promise(function (_resolve, reject) {\n setTimeout(function () {\n reject(\"electrum-cash request timed out, retrying\");\n }, 30000);\n }).catch(function (e) {\n throw e;\n });\n const request = this.electrum.request(name, ...parameters);\n return await Promise.race([request, requestTimeout])\n .then((value) => {\n if (value instanceof Error)\n throw value;\n let result = value;\n return result;\n })\n .catch(async () => {\n // console.warn(\n // \"initial electrum-cash request attempt timed out, retrying...\"\n // );\n return await Promise.race([request, requestTimeout])\n .then((value) => {\n if (value instanceof Error)\n throw value;\n let result = value;\n return result;\n })\n .catch(function (e) {\n throw e;\n });\n });\n }\n async subscribeRequest(methodName, callback, ...parameters) {\n await this.ready();\n const result = await this.electrum.subscribe(callback, methodName, ...parameters);\n this.subscriptions++;\n return result;\n }\n async unsubscribeRequest(methodName, callback, ...parameters) {\n await this.ready();\n const result = this.electrum.unsubscribe(callback, methodName, ...parameters);\n this.subscriptions--;\n return result;\n }\n async ready() {\n return (await this.connect());\n }\n async connect() {\n return await this.mutex.runExclusive(async () => {\n return await this.connectPromise;\n });\n }\n disconnect() {\n if (this.subscriptions > 0) {\n // console.warn(\n // `Trying to disconnect a network provider with ${this.subscriptions} active subscriptions. This is in most cases a bad idea.`\n // );\n }\n return this.isElectrumClient()\n ? this.disconnectClient()\n : this.disconnectCluster();\n }\n isElectrumClient() {\n return this.electrum.hasOwnProperty(\"connection\");\n }\n async readyClient(timeout) {\n timeout = typeof timeout !== \"undefined\" ? timeout : 3000;\n let connectPromise = async () => {\n while (this.electrum.connection.status !==\n electrum_cash__WEBPACK_IMPORTED_MODULE_0__.ConnectionStatus.CONNECTED) {\n await (0,_util_delay_js__WEBPACK_IMPORTED_MODULE_4__.delay)(100);\n }\n return true;\n };\n return connectPromise;\n }\n async readyCluster(timeout) {\n timeout;\n return this.electrum.ready();\n }\n async connectCluster() {\n return this.electrum.startup();\n }\n async connectClient() {\n let connectionPromise = async () => {\n try {\n return await this.electrum.connect();\n }\n catch (e) {\n console.warn(`Warning: Failed to connect to client on ${this.network} at ${this.electrum.connection.host}.`, e);\n return;\n }\n };\n return [await connectionPromise()];\n }\n async disconnectCluster() {\n return this.electrum.shutdown();\n }\n async disconnectClient() {\n return [await this.electrum.disconnect(true)];\n }\n}\nElectrumNetworkProvider.rawTransactionCache = {};\n\n__webpack_async_result__();\n} catch(e) { __webpack_async_result__(e); } });\n\n//# sourceURL=webpack://mainnet-js/./src/network/ElectrumNetworkProvider.ts?");
|
|
1127
|
+
eval("__webpack_require__.a(module, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* binding */ ElectrumNetworkProvider)\n/* harmony export */ });\n/* harmony import */ var electrum_cash__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! electrum-cash */ \"../../node_modules/electrum-cash/dist/index.mjs.js\");\n/* harmony import */ var _interface_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../interface.js */ \"./src/interface.ts\");\n/* harmony import */ var _util_delay_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../util/delay.js */ \"./src/util/delay.ts\");\n/* harmony import */ var async_mutex__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! async-mutex */ \"../../node_modules/async-mutex/index.mjs\");\n/* harmony import */ var _util_transaction_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../util/transaction.js */ \"./src/util/transaction.ts\");\n/* harmony import */ var _constant_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./constant.js */ \"./src/network/constant.ts\");\nvar __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_util_transaction_js__WEBPACK_IMPORTED_MODULE_4__]);\n_util_transaction_js__WEBPACK_IMPORTED_MODULE_4__ = (__webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__)[0];\n\n\n\n\n\n\nclass ElectrumNetworkProvider {\n constructor(electrum, network = _interface_js__WEBPACK_IMPORTED_MODULE_2__.Network.MAINNET, manualConnectionManagement) {\n this.network = network;\n this.manualConnectionManagement = manualConnectionManagement;\n this.subscriptions = 0;\n this.mutex = new async_mutex__WEBPACK_IMPORTED_MODULE_1__.Mutex();\n this.blockHeight = 0;\n if (electrum) {\n this.electrum = electrum;\n this.connectPromise = this.getConnectPromise();\n if (this.electrum instanceof electrum_cash__WEBPACK_IMPORTED_MODULE_0__.ElectrumCluster) {\n this.version = this.electrum.version;\n }\n else {\n this.version = this.electrum.connection.version;\n }\n }\n else {\n throw new Error(`A electrum-cash cluster or client is required.`);\n }\n }\n async getConnectPromise(_timeout = 3000) {\n // connects to the electrum cash and waits until the connection is ready to accept requests\n let timeoutHandle;\n await Promise.race([\n new Promise(async (resolve) => {\n this.connectPromise = undefined;\n if (this.electrum instanceof electrum_cash__WEBPACK_IMPORTED_MODULE_0__.ElectrumCluster) {\n try {\n await this.connectCluster();\n }\n catch (e) {\n console.warn(`Unable to connect to one or more electrum-cash hosts: ${JSON.stringify(e)}`);\n }\n resolve(await this.readyCluster());\n }\n else {\n resolve(await this.connectClient());\n }\n }),\n // new Promise(\n // (_resolve, reject) =>\n // (timeoutHandle = setTimeout(() => {\n // reject(\n // new Error(`Timeout connecting to electrum network: ${this.network}`)\n // );\n // }, _timeout))\n // ),\n ]);\n clearTimeout(timeoutHandle);\n }\n async getUtxos(cashaddr) {\n const result = (await this.performRequest(\"blockchain.address.listunspent\", cashaddr));\n if (this.network === _interface_js__WEBPACK_IMPORTED_MODULE_2__.Network.MAINNET) {\n return result.map((utxo) => ({\n txid: utxo.tx_hash,\n vout: utxo.tx_pos,\n satoshis: utxo.value,\n height: utxo.height,\n }));\n }\n return result.map((utxo) => ({\n txid: utxo.tx_hash,\n vout: utxo.tx_pos,\n satoshis: utxo.value,\n height: utxo.height,\n token: utxo.token_data\n ? {\n amount: Number(utxo.token_data.amount),\n tokenId: utxo.token_data.category,\n capability: utxo.token_data.nft?.capability,\n commitment: utxo.token_data.nft?.commitment,\n }\n : undefined,\n }));\n }\n async getBalance(cashaddr) {\n const result = (await this.performRequest(\"blockchain.address.get_balance\", cashaddr));\n return result.confirmed + result.unconfirmed;\n }\n async getBlockHeight() {\n if (this.version !== _constant_js__WEBPACK_IMPORTED_MODULE_3__.ELECTRUM_CASH_PROTOCOL_VERSION_MAINNET) {\n return (await this.performRequest(\"blockchain.headers.get_tip\"))\n .height;\n }\n // TODO: remove after enough elecrum servers upgrade to at least v 1.5.0\n if (!this.blockHeight) {\n return new Promise(async (resolve) => {\n await this.subscribeToHeaders((header) => {\n this.blockHeight = header.height;\n });\n resolve(this.blockHeight);\n });\n }\n return this.blockHeight;\n }\n async getRawTransaction(txHash, verbose = false, loadInputValues = false) {\n const key = `${this.network}-${txHash}-${verbose}-${loadInputValues}`;\n if (ElectrumNetworkProvider.rawTransactionCache[key]) {\n return ElectrumNetworkProvider.rawTransactionCache[key];\n }\n try {\n const transaction = (await this.performRequest(\"blockchain.transaction.get\", txHash, verbose));\n ElectrumNetworkProvider.rawTransactionCache[key] = transaction;\n if (verbose && loadInputValues) {\n // get unique transaction hashes\n const hashes = [...new Set(transaction.vin.map((val) => val.txid))];\n const transactions = await Promise.all(hashes.map((hash) => this.getRawTransactionObject(hash, false)));\n const transactionMap = new Map();\n transactions.forEach((val) => transactionMap.set(val.hash, val));\n transaction.vin.forEach((input) => {\n const output = transactionMap\n .get(input.txid)\n .vout.find((val) => val.n === input.vout);\n input.address = output.scriptPubKey.addresses[0];\n input.value = output.value;\n input.tokenData = output.tokenData;\n });\n }\n return transaction;\n }\n catch (error) {\n if (error.message.indexOf(\"No such mempool or blockchain transaction.\") > -1)\n throw Error(`Could not decode transaction ${txHash}. It might not exist on the current blockchain (${this.network}).`);\n else\n throw error;\n }\n }\n // gets the decoded transaction in human readable form\n async getRawTransactionObject(txHash, loadInputValues = false) {\n return (await this.getRawTransaction(txHash, true, loadInputValues));\n }\n async sendRawTransaction(txHex, awaitPropagation = true) {\n return new Promise(async (resolve, reject) => {\n let txHash = await (0,_util_transaction_js__WEBPACK_IMPORTED_MODULE_4__.getTransactionHash)(txHex);\n if (!awaitPropagation) {\n this.performRequest(\"blockchain.transaction.broadcast\", txHex);\n resolve(txHash);\n }\n else {\n const waitForTransactionCallback = async (data) => {\n if (data && data[0] === txHash) {\n this.unsubscribeFromTransaction(txHash, waitForTransactionCallback);\n resolve(txHash);\n }\n };\n this.subscribeToTransaction(txHash, waitForTransactionCallback);\n this.performRequest(\"blockchain.transaction.broadcast\", txHex).catch((error) => {\n this.unsubscribeFromTransaction(txHash, waitForTransactionCallback);\n reject(error);\n });\n }\n });\n }\n // Get transaction history of a given cashaddr\n async getHistory(cashaddr) {\n const result = (await this.performRequest(\"blockchain.address.get_history\", cashaddr));\n return result;\n }\n // Get the minimum fee a low-priority transaction must pay in order to be accepted to the daemon's memory pool.\n async getRelayFee() {\n const result = (await this.performRequest(\"blockchain.relayfee\"));\n return result;\n }\n watchAddressStatus(cashaddr, callback) {\n const watchAddressStatusCallback = async (data) => {\n // subscription acknowledgement is the latest known status or null if no status is known\n // status is an array: [ cashaddr, statusHash ]\n if (data instanceof Array) {\n const addr = data[0];\n if (addr !== cashaddr) {\n return;\n }\n const status = data[1];\n callback(status);\n }\n };\n this.subscribeToAddress(cashaddr, watchAddressStatusCallback);\n return async () => {\n await this.unsubscribeFromAddress(cashaddr, watchAddressStatusCallback);\n };\n }\n watchAddress(cashaddr, callback) {\n const historyMap = {};\n this.getHistory(cashaddr).then((history) => history.forEach((val) => (historyMap[val.tx_hash] = true)));\n const watchAddressStatusCallback = async () => {\n const newHistory = await this.getHistory(cashaddr);\n // sort history to put unconfirmed transactions in the beginning, then transactions in block height descenting order\n const txHashes = newHistory\n .sort((a, b) => a.height <= 0 || b.height <= 0 ? -1 : b.height - a.height)\n .map((val) => val.tx_hash);\n for (const hash of txHashes) {\n if (!(hash in historyMap)) {\n historyMap[hash] = true;\n callback(hash);\n // exit early to prevent further map lookups\n break;\n }\n }\n };\n return this.watchAddressStatus(cashaddr, watchAddressStatusCallback);\n }\n watchAddressTransactions(cashaddr, callback) {\n return this.watchAddress(cashaddr, async (txHash) => {\n const tx = await this.getRawTransactionObject(txHash);\n callback(tx);\n });\n }\n watchAddressTokenTransactions(cashaddr, callback) {\n return this.watchAddress(cashaddr, async (txHash) => {\n const tx = await this.getRawTransactionObject(txHash, true);\n if (tx.vin.some((val) => val.tokenData) ||\n tx.vout.some((val) => val.tokenData)) {\n callback(tx);\n }\n });\n }\n // Wait for the next block or a block at given blockchain height.\n watchBlocks(callback) {\n let acknowledged = false;\n const waitForBlockCallback = (_header) => {\n if (!acknowledged) {\n acknowledged = true;\n return;\n }\n _header = _header instanceof Array ? _header[0] : _header;\n callback(_header);\n };\n this.subscribeToHeaders(waitForBlockCallback);\n return async () => {\n this.unsubscribeFromHeaders(waitForBlockCallback);\n };\n }\n // Wait for the next block or a block at given blockchain height.\n async waitForBlock(height) {\n return new Promise(async (resolve) => {\n const cancelWatch = this.watchBlocks(async (header) => {\n if (height === undefined || header.height >= height) {\n await cancelWatch();\n resolve(header);\n }\n });\n });\n }\n // subscribe to notifications sent when new block is found, the block header is sent to callback\n async subscribeToHeaders(callback) {\n await this.subscribeRequest(\"blockchain.headers.subscribe\", callback);\n }\n // unsubscribe to notifications sent when new block is found\n async unsubscribeFromHeaders(callback) {\n await this.unsubscribeRequest(\"blockchain.headers.subscribe\", callback);\n }\n async subscribeToAddress(cashaddr, callback) {\n await this.subscribeRequest(\"blockchain.address.subscribe\", callback, cashaddr);\n }\n async unsubscribeFromAddress(cashaddr, callback) {\n await this.unsubscribeRequest(\"blockchain.address.subscribe\", callback, cashaddr);\n }\n async subscribeToAddressTransactions(cashaddr, callback) {\n await this.subscribeRequest(\"blockchain.address.transactions.subscribe\", callback, cashaddr);\n }\n async unsubscribeFromAddressTransactions(cashaddr, callback) {\n await this.unsubscribeRequest(\"blockchain.address.transactions.subscribe\", callback, cashaddr);\n }\n async subscribeToTransaction(txHash, callback) {\n await this.subscribeRequest(\"blockchain.transaction.subscribe\", callback, txHash);\n }\n async unsubscribeFromTransaction(txHash, callback) {\n await this.unsubscribeRequest(\"blockchain.transaction.subscribe\", callback, txHash);\n }\n async performRequest(name, ...parameters) {\n await this.ready();\n const requestTimeout = new Promise(function (_resolve, reject) {\n setTimeout(function () {\n reject(\"electrum-cash request timed out, retrying\");\n }, 30000);\n }).catch(function (e) {\n throw e;\n });\n const request = this.electrum.request(name, ...parameters);\n return await Promise.race([request, requestTimeout])\n .then((value) => {\n if (value instanceof Error)\n throw value;\n let result = value;\n return result;\n })\n .catch(async () => {\n // console.warn(\n // \"initial electrum-cash request attempt timed out, retrying...\"\n // );\n return await Promise.race([request, requestTimeout])\n .then((value) => {\n if (value instanceof Error)\n throw value;\n let result = value;\n return result;\n })\n .catch(function (e) {\n throw e;\n });\n });\n }\n async subscribeRequest(methodName, callback, ...parameters) {\n await this.ready();\n const result = await this.electrum.subscribe(callback, methodName, ...parameters);\n this.subscriptions++;\n return result;\n }\n async unsubscribeRequest(methodName, callback, ...parameters) {\n await this.ready();\n const result = this.electrum.unsubscribe(callback, methodName, ...parameters);\n this.subscriptions--;\n return result;\n }\n async ready() {\n return (await this.connect());\n }\n async connect() {\n return await this.mutex.runExclusive(async () => {\n return await this.connectPromise;\n });\n }\n disconnect() {\n if (this.subscriptions > 0) {\n // console.warn(\n // `Trying to disconnect a network provider with ${this.subscriptions} active subscriptions. This is in most cases a bad idea.`\n // );\n }\n return this.isElectrumClient()\n ? this.disconnectClient()\n : this.disconnectCluster();\n }\n isElectrumClient() {\n return this.electrum.hasOwnProperty(\"connection\");\n }\n async readyClient(timeout) {\n timeout = typeof timeout !== \"undefined\" ? timeout : 3000;\n let connectPromise = async () => {\n while (this.electrum.connection.status !==\n electrum_cash__WEBPACK_IMPORTED_MODULE_0__.ConnectionStatus.CONNECTED) {\n await (0,_util_delay_js__WEBPACK_IMPORTED_MODULE_5__.delay)(100);\n }\n return true;\n };\n return connectPromise;\n }\n async readyCluster(timeout) {\n timeout;\n return this.electrum.ready();\n }\n async connectCluster() {\n return this.electrum.startup();\n }\n async connectClient() {\n let connectionPromise = async () => {\n try {\n return await this.electrum.connect();\n }\n catch (e) {\n console.warn(`Warning: Failed to connect to client on ${this.network} at ${this.electrum.connection.host}.`, e);\n return;\n }\n };\n return [await connectionPromise()];\n }\n async disconnectCluster() {\n return this.electrum.shutdown();\n }\n async disconnectClient() {\n return [await this.electrum.disconnect(true)];\n }\n}\nElectrumNetworkProvider.rawTransactionCache = {};\n\n__webpack_async_result__();\n} catch(e) { __webpack_async_result__(e); } });\n\n//# sourceURL=webpack://mainnet-js/./src/network/ElectrumNetworkProvider.ts?");
|
|
1118
1128
|
|
|
1119
1129
|
/***/ }),
|
|
1120
1130
|
|
|
@@ -1294,7 +1304,7 @@ eval("/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harm
|
|
|
1294
1304
|
\********************************/
|
|
1295
1305
|
/***/ ((module, __webpack_exports__, __webpack_require__) => {
|
|
1296
1306
|
|
|
1297
|
-
eval("__webpack_require__.a(module, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"buildEncodedTransaction\": () => (/* binding */ buildEncodedTransaction),\n/* harmony export */ \"getFeeAmount\": () => (/* binding */ getFeeAmount),\n/* harmony export */ \"getSuitableUtxos\": () => (/* binding */ getSuitableUtxos)\n/* harmony export */ });\n/* unused harmony exports buildP2pkhNonHdTransaction, prepareInputs, prepareOutputs, prepareOpReturnOutput, prepareTokenOutputs */\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/schema/authentication-template.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/compiler/standard/p2pkh.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/compiler/compiler-bch/compiler-bch.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/address/locking-bytecode.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/transaction/generate-transaction.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/format/hex.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/message/transaction-encoding.js\");\n/* harmony import */ var _interface_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ../interface.js */ \"./src/interface.ts\");\n/* harmony import */ var _allocateFee_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./allocateFee.js */ \"./src/transaction/allocateFee.ts\");\n/* harmony import */ var _constant_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../constant.js */ \"./src/constant.ts\");\n/* harmony import */ var _wallet_model_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ../wallet/model.js */ \"./src/wallet/model.ts\");\n/* harmony import */ var _util_amountInSatoshi_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ../util/amountInSatoshi.js */ \"./src/util/amountInSatoshi.ts\");\n/* harmony import */ var _util_sumSendRequestAmounts_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../util/sumSendRequestAmounts.js */ \"./src/util/sumSendRequestAmounts.ts\");\n/* harmony import */ var _util_sumUtxoValue_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../util/sumUtxoValue.js */ \"./src/util/sumUtxoValue.ts\");\n/* harmony import */ var _wallet_enum_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../wallet/enum.js */ \"./src/wallet/enum.ts\");\nvar __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__, _util_sumSendRequestAmounts_js__WEBPACK_IMPORTED_MODULE_5__, _allocateFee_js__WEBPACK_IMPORTED_MODULE_6__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_8__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_9__, _wallet_model_js__WEBPACK_IMPORTED_MODULE_11__, _util_amountInSatoshi_js__WEBPACK_IMPORTED_MODULE_12__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_14__]);\n([_bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__, _util_sumSendRequestAmounts_js__WEBPACK_IMPORTED_MODULE_5__, _allocateFee_js__WEBPACK_IMPORTED_MODULE_6__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_8__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_9__, _wallet_model_js__WEBPACK_IMPORTED_MODULE_11__, _util_amountInSatoshi_js__WEBPACK_IMPORTED_MODULE_12__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_14__] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);\n// Unstable?\n\n\n\n\n\n\n\n\n\n// Build a transaction for a p2pkh transaction for a non HD wallet\nasync function buildP2pkhNonHdTransaction(inputs, outputs, signingKey, fee = 0, discardChange = false, slpOutputs = [], feePaidBy = _wallet_enum_js__WEBPACK_IMPORTED_MODULE_0__.FeePaidByEnum.change, changeAddress = \"\") {\n if (!signingKey) {\n throw new Error(\"Missing signing key when building transaction\");\n }\n const template = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__.importAuthenticationTemplate)(_bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__.authenticationTemplateP2pkhNonHd);\n if (typeof template === \"string\") {\n throw new Error(\"Transaction template error\");\n }\n const compiler = await (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__.authenticationTemplateToCompilerBCH)(template);\n const inputAmount = await (0,_util_sumUtxoValue_js__WEBPACK_IMPORTED_MODULE_4__.sumUtxoValue)(inputs);\n const sendAmount = await (0,_util_sumSendRequestAmounts_js__WEBPACK_IMPORTED_MODULE_5__.sumSendRequestAmounts)(outputs);\n const changeAmount = BigInt(inputAmount) - BigInt(sendAmount) - BigInt(fee);\n outputs = (0,_allocateFee_js__WEBPACK_IMPORTED_MODULE_6__.allocateFee)(outputs, fee, feePaidBy, changeAmount);\n let lockedOutputs = await prepareOutputs(outputs, inputs);\n if (discardChange !== true) {\n if (changeAmount > _constant_js__WEBPACK_IMPORTED_MODULE_7__.DUST_UTXO_THRESHOLD) {\n let changeLockingBytecode;\n if (changeAddress) {\n changeLockingBytecode = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_8__.cashAddressToLockingBytecode)(changeAddress);\n }\n else {\n // Get the change locking bytecode\n changeLockingBytecode = compiler.generateBytecode({\n scriptId: \"lock\",\n data: {\n keys: { privateKeys: { key: signingKey } },\n },\n });\n }\n if (typeof changeLockingBytecode === \"string\") {\n throw new Error(changeLockingBytecode);\n }\n lockedOutputs.push({\n lockingBytecode: changeLockingBytecode.bytecode,\n valueSatoshis: BigInt(changeAmount),\n });\n }\n }\n let signedInputs = prepareInputs(inputs, compiler, signingKey);\n const result = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_9__.generateTransaction)({\n inputs: signedInputs,\n locktime: 0,\n outputs: [...slpOutputs, ...lockedOutputs],\n version: 2,\n });\n return result;\n}\nfunction prepareInputs(inputs, compiler, signingKey) {\n let signedInputs = [];\n for (const i of inputs) {\n const utxoTxnValue = i.satoshis;\n const utxoIndex = i.vout;\n // slice will create a clone of the array\n let utxoOutpointTransactionHash = new Uint8Array(i.txid.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)));\n // reverse the cloned copy\n // utxoOutpointTransactionHash.reverse();\n if (!utxoOutpointTransactionHash || utxoIndex === undefined) {\n throw new Error(\"Missing unspent outpoint when building transaction\");\n }\n const libAuthToken = i.token && {\n amount: BigInt(i.token.amount),\n category: (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_10__.hexToBin)(i.token.tokenId),\n nft: i.token.capability || i.token.commitment\n ? {\n capability: i.token.capability,\n commitment: i.token.commitment && (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_10__.hexToBin)(i.token.commitment),\n }\n : undefined,\n };\n let newInput = {\n outpointIndex: utxoIndex,\n outpointTransactionHash: utxoOutpointTransactionHash,\n sequenceNumber: 0,\n unlockingBytecode: {\n compiler,\n data: {\n keys: { privateKeys: { key: signingKey } },\n },\n valueSatoshis: BigInt(utxoTxnValue),\n script: \"unlock\",\n token: libAuthToken,\n },\n };\n signedInputs.push(newInput);\n }\n return signedInputs;\n}\n/**\n * prepareOutputs - create outputs for a transaction from a list of send requests\n *\n * a wrapper function\n *\n * @returns A promise to a list of unspent outputs\n */\nasync function prepareOutputs(outputs, inputs) {\n let lockedOutputs = [];\n for (const output of outputs) {\n if (output instanceof _wallet_model_js__WEBPACK_IMPORTED_MODULE_11__.TokenSendRequest) {\n lockedOutputs.push(prepareTokenOutputs(output, inputs));\n continue;\n }\n if (output instanceof _wallet_model_js__WEBPACK_IMPORTED_MODULE_11__.OpReturnData) {\n lockedOutputs.push(prepareOpReturnOutput(output));\n continue;\n }\n const outputLockingBytecode = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_8__.cashAddressToLockingBytecode)(output.cashaddr);\n if (typeof outputLockingBytecode === \"string\")\n throw new Error(outputLockingBytecode);\n const sendAmount = await (0,_util_amountInSatoshi_js__WEBPACK_IMPORTED_MODULE_12__.amountInSatoshi)(output.value, output.unit);\n if (sendAmount % 1 !== 0) {\n throw Error(`Cannot send ${sendAmount} satoshis, (fractional sats do not exist, yet), please use an integer number.`);\n }\n const lockedOutput = {\n lockingBytecode: outputLockingBytecode.bytecode,\n valueSatoshis: BigInt(sendAmount),\n };\n lockedOutputs.push(lockedOutput);\n }\n return lockedOutputs;\n}\n/**\n * prepareOpReturnOutput - create an output for OP_RETURN data\n *\n * @returns A promise to a list of unspent outputs\n */\nfunction prepareOpReturnOutput(request) {\n return {\n lockingBytecode: request.buffer,\n valueSatoshis: BigInt(0),\n };\n}\n/**\n * prepareOpReturnOutput - create an output for token data\n *\n * @returns A libauth Output\n */\nfunction prepareTokenOutputs(request, inputs) {\n const token = request;\n const isGenesis = !request.tokenId || request._isGenesis;\n let satValue = 0;\n if (isGenesis) {\n const genesisInputs = inputs.filter((val) => val.vout === 0);\n if (genesisInputs.length === 0) {\n throw new Error(\"No suitable inputs with vout=0 available for new token genesis\");\n }\n token.tokenId = genesisInputs[0].txid;\n satValue = request.value || 1000;\n request._isGenesis = true;\n }\n else {\n const tokenInputs = inputs.filter((val) => val.token?.tokenId === request.tokenId);\n if (!tokenInputs.length) {\n throw new Error(`No token utxos available to send ${request.tokenId}`);\n }\n if (!token.capability && tokenInputs[0].token?.capability) {\n token.capability = tokenInputs[0].token.capability;\n }\n if (!token.commitment && tokenInputs[0].token?.commitment) {\n token.commitment = tokenInputs[0].token.commitment;\n }\n if (token.capability === _interface_js__WEBPACK_IMPORTED_MODULE_13__.NFTCapability.none &&\n token.commitment !== tokenInputs[0].token?.commitment) {\n throw new Error(\"Can not change the commitment of an immutable token\");\n }\n satValue = request.value || tokenInputs[0].satoshis;\n }\n let outputLockingBytecode = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_8__.cashAddressToLockingBytecode)(request.cashaddr);\n if (typeof outputLockingBytecode === \"string\")\n throw new Error(outputLockingBytecode);\n const libAuthToken = {\n amount: BigInt(token.amount),\n category: (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_10__.hexToBin)(token.tokenId),\n nft: token.capability || token.commitment\n ? {\n capability: token.capability,\n commitment: token.commitment && (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_10__.hexToBin)(token.commitment),\n }\n : undefined,\n };\n return {\n lockingBytecode: outputLockingBytecode.bytecode,\n valueSatoshis: BigInt(satValue),\n token: libAuthToken,\n };\n}\n/**\n * getSuitableUtxos - Filter a list of unspent transaction outputs to the minimum needed to complete a transaction\n *\n * a intermediate function\n *\n * @param unspentOutputs An unfiltered list of available unspent transaction outputs\n *\n * @returns A promise to a list of unspent outputs\n */\nasync function getSuitableUtxos(inputs, amountRequired, bestHeight, feePaidBy, requests) {\n let suitableUtxos = [];\n let amountAvailable = BigInt(0);\n const tokenAmountsRequired = [];\n const tokenRequests = requests.filter((val) => val instanceof _wallet_model_js__WEBPACK_IMPORTED_MODULE_11__.TokenSendRequest);\n const tokenIds = tokenRequests\n .map((val) => val.tokenId)\n .filter((value, index, array) => array.indexOf(value) === index);\n for (let tokenId of tokenIds) {\n const requiredAmount = tokenRequests\n .map((val) => val.amount)\n .reduce((prev, cur) => prev + cur, 0);\n tokenAmountsRequired.push({ tokenId, requiredAmount });\n }\n let filteredInputs = inputs.slice(0);\n // find suitable token inputs first\n for (const { tokenId, requiredAmount } of tokenAmountsRequired) {\n let tokenAmountAvailable = 0;\n for (const input of inputs) {\n if (input.token?.tokenId === tokenId) {\n suitableUtxos.push(input);\n const inputIndex = filteredInputs.indexOf(input);\n filteredInputs = filteredInputs.filter((_, index) => inputIndex !== index);\n tokenAmountAvailable += input.token.amount;\n amountAvailable += BigInt(input.satoshis);\n if (tokenAmountAvailable >= requiredAmount) {\n break;\n }\n }\n }\n }\n // find plain outputs\n for (const u of filteredInputs) {\n if (u.token) {\n // continue;\n }\n if (u.coinbase && u.height && bestHeight) {\n let age = bestHeight - u.height;\n if (age > 100) {\n suitableUtxos.push(u);\n amountAvailable += BigInt(u.satoshis);\n }\n }\n else {\n suitableUtxos.push(u);\n amountAvailable += BigInt(u.satoshis);\n }\n // if amountRequired is not given, assume it is a max spend request, skip this condition\n if (amountRequired && amountAvailable > amountRequired) {\n break;\n }\n }\n // if the fee is split with a feePaidBy option, skip checking change.\n if (feePaidBy && feePaidBy != _wallet_enum_js__WEBPACK_IMPORTED_MODULE_0__.FeePaidByEnum.change) {\n return suitableUtxos;\n }\n // If the amount needed is met, or no amount is given, return\n if (typeof amountRequired === \"undefined\") {\n return suitableUtxos;\n }\n else if (amountAvailable < amountRequired) {\n let e = Error(`Amount required was not met, ${amountRequired} satoshis needed, ${amountAvailable} satoshis available`);\n e[\"data\"] = {\n required: amountRequired,\n available: amountAvailable,\n };\n throw e;\n }\n else {\n return suitableUtxos;\n }\n}\nasync function getFeeAmount({ utxos, sendRequests, privateKey, relayFeePerByteInSatoshi, slpOutputs, feePaidBy, }) {\n // build transaction\n if (utxos) {\n // Build the transaction to get the approximate size\n let draftTransaction = await buildEncodedTransaction(utxos, sendRequests, privateKey, 0, //DUST_UTXO_THRESHOLD\n false, slpOutputs, feePaidBy);\n return draftTransaction.length * relayFeePerByteInSatoshi + 1;\n }\n else {\n throw Error(\"The available inputs in the wallet cannot satisfy this send request\");\n }\n}\n// Build encoded transaction\nasync function buildEncodedTransaction(fundingUtxos, sendRequests, privateKey, fee = 0, discardChange = false, slpOutputs = [], feePaidBy = _wallet_enum_js__WEBPACK_IMPORTED_MODULE_0__.FeePaidByEnum.change, changeAddress = \"\") {\n let txn = await buildP2pkhNonHdTransaction(fundingUtxos, sendRequests, privateKey, fee, discardChange, slpOutputs, feePaidBy, changeAddress);\n // submit transaction\n if (txn.success) {\n return (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_14__.encodeTransaction)(txn.transaction);\n }\n else {\n throw Error(\"Error building transaction with fee\");\n }\n}\n\n__webpack_async_result__();\n} catch(e) { __webpack_async_result__(e); } });\n\n//# sourceURL=webpack://mainnet-js/./src/transaction/Wif.ts?");
|
|
1307
|
+
eval("__webpack_require__.a(module, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"buildEncodedTransaction\": () => (/* binding */ buildEncodedTransaction),\n/* harmony export */ \"getFeeAmount\": () => (/* binding */ getFeeAmount),\n/* harmony export */ \"getSuitableUtxos\": () => (/* binding */ getSuitableUtxos)\n/* harmony export */ });\n/* unused harmony exports buildP2pkhNonHdTransaction, prepareInputs, prepareOutputs, prepareOpReturnOutput, prepareTokenOutputs */\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/schema/authentication-template.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/compiler/standard/p2pkh.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/compiler/compiler-bch/compiler-bch.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/address/locking-bytecode.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/transaction/generate-transaction.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/format/hex.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/message/transaction-encoding.js\");\n/* harmony import */ var _interface_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ../interface.js */ \"./src/interface.ts\");\n/* harmony import */ var _allocateFee_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./allocateFee.js */ \"./src/transaction/allocateFee.ts\");\n/* harmony import */ var _constant_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../constant.js */ \"./src/constant.ts\");\n/* harmony import */ var _wallet_model_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ../wallet/model.js */ \"./src/wallet/model.ts\");\n/* harmony import */ var _util_amountInSatoshi_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ../util/amountInSatoshi.js */ \"./src/util/amountInSatoshi.ts\");\n/* harmony import */ var _util_sumSendRequestAmounts_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../util/sumSendRequestAmounts.js */ \"./src/util/sumSendRequestAmounts.ts\");\n/* harmony import */ var _util_sumUtxoValue_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../util/sumUtxoValue.js */ \"./src/util/sumUtxoValue.ts\");\n/* harmony import */ var _wallet_enum_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../wallet/enum.js */ \"./src/wallet/enum.ts\");\nvar __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__, _util_sumSendRequestAmounts_js__WEBPACK_IMPORTED_MODULE_5__, _allocateFee_js__WEBPACK_IMPORTED_MODULE_6__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_8__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_9__, _wallet_model_js__WEBPACK_IMPORTED_MODULE_11__, _util_amountInSatoshi_js__WEBPACK_IMPORTED_MODULE_12__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_14__]);\n([_bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__, _util_sumSendRequestAmounts_js__WEBPACK_IMPORTED_MODULE_5__, _allocateFee_js__WEBPACK_IMPORTED_MODULE_6__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_8__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_9__, _wallet_model_js__WEBPACK_IMPORTED_MODULE_11__, _util_amountInSatoshi_js__WEBPACK_IMPORTED_MODULE_12__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_14__] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);\n// Unstable?\n\n\n\n\n\n\n\n\n\n// Build a transaction for a p2pkh transaction for a non HD wallet\nasync function buildP2pkhNonHdTransaction(inputs, outputs, signingKey, fee = 0, discardChange = false, slpOutputs = [], feePaidBy = _wallet_enum_js__WEBPACK_IMPORTED_MODULE_0__.FeePaidByEnum.change, changeAddress = \"\") {\n if (!signingKey) {\n throw new Error(\"Missing signing key when building transaction\");\n }\n const template = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__.importAuthenticationTemplate)(_bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__.authenticationTemplateP2pkhNonHd);\n if (typeof template === \"string\") {\n throw new Error(\"Transaction template error\");\n }\n const compiler = await (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__.authenticationTemplateToCompilerBCH)(template);\n const inputAmount = await (0,_util_sumUtxoValue_js__WEBPACK_IMPORTED_MODULE_4__.sumUtxoValue)(inputs);\n const sendAmount = await (0,_util_sumSendRequestAmounts_js__WEBPACK_IMPORTED_MODULE_5__.sumSendRequestAmounts)(outputs);\n const changeAmount = BigInt(inputAmount) - BigInt(sendAmount) - BigInt(fee);\n outputs = (0,_allocateFee_js__WEBPACK_IMPORTED_MODULE_6__.allocateFee)(outputs, fee, feePaidBy, changeAmount);\n let lockedOutputs = await prepareOutputs(outputs, inputs);\n if (discardChange !== true) {\n if (changeAmount > _constant_js__WEBPACK_IMPORTED_MODULE_7__.DUST_UTXO_THRESHOLD) {\n let changeLockingBytecode;\n if (changeAddress) {\n changeLockingBytecode = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_8__.cashAddressToLockingBytecode)(changeAddress);\n }\n else {\n // Get the change locking bytecode\n changeLockingBytecode = compiler.generateBytecode({\n scriptId: \"lock\",\n data: {\n keys: { privateKeys: { key: signingKey } },\n },\n });\n }\n if (typeof changeLockingBytecode === \"string\") {\n throw new Error(changeLockingBytecode);\n }\n lockedOutputs.push({\n lockingBytecode: changeLockingBytecode.bytecode,\n valueSatoshis: BigInt(changeAmount),\n });\n }\n }\n let signedInputs = prepareInputs(inputs, compiler, signingKey);\n const result = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_9__.generateTransaction)({\n inputs: signedInputs,\n locktime: 0,\n outputs: [...slpOutputs, ...lockedOutputs],\n version: 2,\n });\n return result;\n}\nfunction prepareInputs(inputs, compiler, signingKey) {\n let signedInputs = [];\n for (const i of inputs) {\n const utxoTxnValue = i.satoshis;\n const utxoIndex = i.vout;\n // slice will create a clone of the array\n let utxoOutpointTransactionHash = new Uint8Array(i.txid.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)));\n // reverse the cloned copy\n // utxoOutpointTransactionHash.reverse();\n if (!utxoOutpointTransactionHash || utxoIndex === undefined) {\n throw new Error(\"Missing unspent outpoint when building transaction\");\n }\n const libAuthToken = i.token && {\n amount: BigInt(i.token.amount),\n category: (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_10__.hexToBin)(i.token.tokenId),\n nft: i.token.capability || i.token.commitment\n ? {\n capability: i.token.capability,\n commitment: i.token.commitment && (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_10__.hexToBin)(i.token.commitment),\n }\n : undefined,\n };\n let newInput = {\n outpointIndex: utxoIndex,\n outpointTransactionHash: utxoOutpointTransactionHash,\n sequenceNumber: 0,\n unlockingBytecode: {\n compiler,\n data: {\n keys: { privateKeys: { key: signingKey } },\n },\n valueSatoshis: BigInt(utxoTxnValue),\n script: \"unlock\",\n token: libAuthToken,\n },\n };\n signedInputs.push(newInput);\n }\n return signedInputs;\n}\n/**\n * prepareOutputs - create outputs for a transaction from a list of send requests\n *\n * a wrapper function\n *\n * @returns A promise to a list of unspent outputs\n */\nasync function prepareOutputs(outputs, inputs) {\n let lockedOutputs = [];\n for (const output of outputs) {\n if (output instanceof _wallet_model_js__WEBPACK_IMPORTED_MODULE_11__.TokenSendRequest) {\n lockedOutputs.push(prepareTokenOutputs(output, inputs));\n continue;\n }\n if (output instanceof _wallet_model_js__WEBPACK_IMPORTED_MODULE_11__.OpReturnData) {\n lockedOutputs.push(prepareOpReturnOutput(output));\n continue;\n }\n const outputLockingBytecode = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_8__.cashAddressToLockingBytecode)(output.cashaddr);\n if (typeof outputLockingBytecode === \"string\")\n throw new Error(outputLockingBytecode);\n const sendAmount = await (0,_util_amountInSatoshi_js__WEBPACK_IMPORTED_MODULE_12__.amountInSatoshi)(output.value, output.unit);\n if (sendAmount % 1 !== 0) {\n throw Error(`Cannot send ${sendAmount} satoshis, (fractional sats do not exist, yet), please use an integer number.`);\n }\n const lockedOutput = {\n lockingBytecode: outputLockingBytecode.bytecode,\n valueSatoshis: BigInt(sendAmount),\n };\n lockedOutputs.push(lockedOutput);\n }\n return lockedOutputs;\n}\n/**\n * prepareOpReturnOutput - create an output for OP_RETURN data\n *\n * @returns A promise to a list of unspent outputs\n */\nfunction prepareOpReturnOutput(request) {\n return {\n lockingBytecode: request.buffer,\n valueSatoshis: BigInt(0),\n };\n}\n/**\n * prepareOpReturnOutput - create an output for token data\n *\n * @returns A libauth Output\n */\nfunction prepareTokenOutputs(request, inputs) {\n const token = request;\n const isGenesis = !request.tokenId || request._isGenesis;\n let satValue = 0;\n if (isGenesis) {\n const genesisInputs = inputs.filter((val) => val.vout === 0);\n if (genesisInputs.length === 0) {\n throw new Error(\"No suitable inputs with vout=0 available for new token genesis\");\n }\n token.tokenId = genesisInputs[0].txid;\n satValue = request.value || 1000;\n request._isGenesis = true;\n }\n else {\n const tokenInputs = inputs.filter((val) => val.token?.tokenId === request.tokenId);\n if (!tokenInputs.length) {\n throw new Error(`No token utxos available to send ${request.tokenId}`);\n }\n if (!token.capability && tokenInputs[0].token?.capability) {\n token.capability = tokenInputs[0].token.capability;\n }\n if (!token.commitment && tokenInputs[0].token?.commitment) {\n token.commitment = tokenInputs[0].token.commitment;\n }\n if (tokenInputs[0].token?.capability === _interface_js__WEBPACK_IMPORTED_MODULE_13__.NFTCapability.none &&\n tokenInputs[0].token?.commitment !== token.commitment) {\n throw new Error(\"Can not change the commitment of an immutable token\");\n }\n satValue = request.value || tokenInputs[0].satoshis;\n }\n let outputLockingBytecode = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_8__.cashAddressToLockingBytecode)(request.cashaddr);\n if (typeof outputLockingBytecode === \"string\")\n throw new Error(outputLockingBytecode);\n const libAuthToken = {\n amount: BigInt(token.amount),\n category: (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_10__.hexToBin)(token.tokenId),\n nft: token.capability || token.commitment\n ? {\n capability: token.capability,\n commitment: token.commitment && (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_10__.hexToBin)(token.commitment),\n }\n : undefined,\n };\n return {\n lockingBytecode: outputLockingBytecode.bytecode,\n valueSatoshis: BigInt(satValue),\n token: libAuthToken,\n };\n}\n/**\n * getSuitableUtxos - Filter a list of unspent transaction outputs to the minimum needed to complete a transaction\n *\n * a intermediate function\n *\n * @param unspentOutputs An unfiltered list of available unspent transaction outputs\n *\n * @returns A promise to a list of unspent outputs\n */\nasync function getSuitableUtxos(inputs, amountRequired, bestHeight, feePaidBy, requests, ensureUtxos = []) {\n let suitableUtxos = [];\n let amountAvailable = BigInt(0);\n const tokenAmountsRequired = [];\n const tokenRequests = requests.filter((val) => val instanceof _wallet_model_js__WEBPACK_IMPORTED_MODULE_11__.TokenSendRequest);\n // if we do a new token genesis, we shall filter all token utxos out\n const isTokenGenesis = tokenRequests.some((val) => !val.tokenId || val._isGenesis);\n const bchOnlyTransfer = tokenRequests.length === 0;\n let filteredInputs = isTokenGenesis || bchOnlyTransfer\n ? inputs.slice(0).filter((val) => !val.token)\n : inputs.slice();\n const tokenIds = tokenRequests\n .map((val) => val.tokenId)\n .filter((value, index, array) => array.indexOf(value) === index);\n for (let tokenId of tokenIds) {\n const requiredAmount = tokenRequests\n .map((val) => val.amount)\n .reduce((prev, cur) => prev + cur, 0);\n tokenAmountsRequired.push({ tokenId, requiredAmount });\n }\n // find suitable token inputs first\n for (const { tokenId, requiredAmount } of tokenAmountsRequired) {\n let tokenAmountAvailable = 0;\n for (const input of inputs) {\n if (input.token?.tokenId === tokenId) {\n suitableUtxos.push(input);\n const inputIndex = filteredInputs.indexOf(input);\n filteredInputs = filteredInputs.filter((_, index) => inputIndex !== index);\n tokenAmountAvailable += input.token.amount;\n amountAvailable += BigInt(input.satoshis);\n if (tokenAmountAvailable >= requiredAmount) {\n break;\n }\n }\n }\n }\n // find plain bch outputs\n for (const u of filteredInputs) {\n if (u.token) {\n continue;\n }\n if (u.coinbase && u.height && bestHeight) {\n let age = bestHeight - u.height;\n if (age > 100) {\n suitableUtxos.push(u);\n amountAvailable += BigInt(u.satoshis);\n }\n }\n else {\n suitableUtxos.push(u);\n amountAvailable += BigInt(u.satoshis);\n }\n // if amountRequired is not given, assume it is a max spend request, skip this condition\n if (amountRequired && amountAvailable > amountRequired) {\n break;\n }\n }\n const addEnsured = (suitableUtxos) => {\n return [...suitableUtxos, ...ensureUtxos].filter((val, index, array) => array.indexOf(val) === index);\n };\n // if the fee is split with a feePaidBy option, skip checking change.\n if (feePaidBy && feePaidBy != _wallet_enum_js__WEBPACK_IMPORTED_MODULE_0__.FeePaidByEnum.change) {\n return addEnsured(suitableUtxos);\n }\n // If the amount needed is met, or no amount is given, return\n if (typeof amountRequired === \"undefined\") {\n return addEnsured(suitableUtxos);\n }\n else if (amountAvailable < amountRequired) {\n let e = Error(`Amount required was not met, ${amountRequired} satoshis needed, ${amountAvailable} satoshis available`);\n e[\"data\"] = {\n required: amountRequired,\n available: amountAvailable,\n };\n throw e;\n }\n else {\n return addEnsured(suitableUtxos);\n }\n}\nasync function getFeeAmount({ utxos, sendRequests, privateKey, relayFeePerByteInSatoshi, slpOutputs, feePaidBy, }) {\n // build transaction\n if (utxos) {\n // Build the transaction to get the approximate size\n let draftTransaction = await buildEncodedTransaction(utxos, sendRequests, privateKey, 0, //DUST_UTXO_THRESHOLD\n false, slpOutputs, feePaidBy);\n return draftTransaction.length * relayFeePerByteInSatoshi + 1;\n }\n else {\n throw Error(\"The available inputs in the wallet cannot satisfy this send request\");\n }\n}\n// Build encoded transaction\nasync function buildEncodedTransaction(fundingUtxos, sendRequests, privateKey, fee = 0, discardChange = false, slpOutputs = [], feePaidBy = _wallet_enum_js__WEBPACK_IMPORTED_MODULE_0__.FeePaidByEnum.change, changeAddress = \"\") {\n let txn = await buildP2pkhNonHdTransaction(fundingUtxos, sendRequests, privateKey, fee, discardChange, slpOutputs, feePaidBy, changeAddress);\n // submit transaction\n if (txn.success) {\n return (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_14__.encodeTransaction)(txn.transaction);\n }\n else {\n throw Error(\"Error building transaction with fee\");\n }\n}\n\n__webpack_async_result__();\n} catch(e) { __webpack_async_result__(e); } });\n\n//# sourceURL=webpack://mainnet-js/./src/transaction/Wif.ts?");
|
|
1298
1308
|
|
|
1299
1309
|
/***/ }),
|
|
1300
1310
|
|
|
@@ -1414,7 +1424,7 @@ eval("/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harm
|
|
|
1414
1424
|
\************************************/
|
|
1415
1425
|
/***/ ((module, __webpack_exports__, __webpack_require__) => {
|
|
1416
1426
|
|
|
1417
|
-
eval("__webpack_require__.a(module, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"deriveCashaddr\": () => (/* binding */ deriveCashaddr),\n/* harmony export */ \"deriveTokenaddr\": () => (/* binding */ deriveTokenaddr)
|
|
1427
|
+
eval("__webpack_require__.a(module, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"checkTokenaddr\": () => (/* binding */ checkTokenaddr),\n/* harmony export */ \"deriveCashaddr\": () => (/* binding */ deriveCashaddr),\n/* harmony export */ \"deriveTokenaddr\": () => (/* binding */ deriveTokenaddr),\n/* harmony export */ \"isTokenaddr\": () => (/* binding */ isTokenaddr),\n/* harmony export */ \"toCashaddr\": () => (/* binding */ toCashaddr),\n/* harmony export */ \"toTokenaddr\": () => (/* binding */ toTokenaddr)\n/* harmony export */ });\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/crypto/default-crypto-instances.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/address/cash-address.js\");\n/* harmony import */ var _hash160_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./hash160.js */ \"./src/util/hash160.ts\");\nvar __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_bitauth_libauth__WEBPACK_IMPORTED_MODULE_0__, _hash160_js__WEBPACK_IMPORTED_MODULE_1__]);\n([_bitauth_libauth__WEBPACK_IMPORTED_MODULE_0__, _hash160_js__WEBPACK_IMPORTED_MODULE_1__] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);\n\n\nfunction deriveCashaddr(privateKey, networkPrefix) {\n let publicKey = _bitauth_libauth__WEBPACK_IMPORTED_MODULE_0__.secp256k1.derivePublicKeyCompressed(privateKey);\n if (typeof publicKey === \"string\") {\n throw new Error(publicKey);\n }\n let pkh = (0,_hash160_js__WEBPACK_IMPORTED_MODULE_1__.hash160)(publicKey);\n return (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__.encodeCashAddress)(networkPrefix, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__.CashAddressType.p2pkh, pkh);\n}\nfunction deriveTokenaddr(key, networkPrefix) {\n let publicKeyHash;\n // private key\n if (key.length === 32) {\n let publicKeyCompressed = _bitauth_libauth__WEBPACK_IMPORTED_MODULE_0__.secp256k1.derivePublicKeyCompressed(key);\n if (typeof publicKeyCompressed === \"string\") {\n throw new Error(publicKeyCompressed);\n }\n publicKeyHash = (0,_hash160_js__WEBPACK_IMPORTED_MODULE_1__.hash160)(publicKeyCompressed);\n }\n else if (key.length === 65) {\n // uncompressed public key\n let publicKeyCompressed = _bitauth_libauth__WEBPACK_IMPORTED_MODULE_0__.secp256k1.compressPublicKey(key);\n if (typeof publicKeyCompressed === \"string\") {\n throw new Error(publicKeyCompressed);\n }\n publicKeyHash = (0,_hash160_js__WEBPACK_IMPORTED_MODULE_1__.hash160)(publicKeyCompressed);\n }\n else if (key.length === 33) {\n // compressed public key\n publicKeyHash = (0,_hash160_js__WEBPACK_IMPORTED_MODULE_1__.hash160)(key);\n }\n else if (key.length === 20) {\n // public key hash\n publicKeyHash = key;\n }\n else {\n throw new Error(\"Unsupported type of key\");\n }\n return (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__.encodeCashAddress)(networkPrefix, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__.CashAddressType.p2pkhWithTokens, publicKeyHash);\n}\nfunction toCashaddr(tokenaddr) {\n let result;\n // If the address has a prefix decode it as is\n if (tokenaddr.includes(\":\")) {\n result = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__.decodeCashAddressFormat)(tokenaddr);\n }\n // otherwise, derive the network from the tokenaddr without prefix\n else {\n result = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__.decodeCashAddressFormatWithoutPrefix)(tokenaddr);\n }\n if (typeof result === \"string\")\n throw new Error(result);\n return (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__.encodeCashAddress)(result.prefix, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__.CashAddressType.p2pkh, result.payload);\n}\nfunction toTokenaddr(cashaddr) {\n let result;\n // If the address has a prefix decode it as is\n if (cashaddr.includes(\":\")) {\n result = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__.decodeCashAddressFormat)(cashaddr);\n }\n // otherwise, derive the network from the cashaddr without prefix\n else {\n result = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__.decodeCashAddressFormatWithoutPrefix)(cashaddr);\n }\n if (typeof result === \"string\")\n throw new Error(result);\n return (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__.encodeCashAddress)(result.prefix, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__.CashAddressType.p2pkhWithTokens, result.payload);\n}\nfunction isTokenaddr(address) {\n let result;\n // If the address has a prefix decode it as is\n if (address.includes(\":\")) {\n result = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__.decodeCashAddressFormat)(address);\n }\n // otherwise, derive the network from the address without prefix\n else {\n result = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__.decodeCashAddressFormatWithoutPrefix)(address);\n }\n if (typeof result === \"string\")\n throw new Error(result);\n return ([\n _bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__.CashAddressVersionByte.p2pkhWithTokens,\n _bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__.CashAddressVersionByte.p2sh20WithTokens,\n _bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__.CashAddressVersionByte.p2sh32WithTokens,\n ].indexOf(result.version) !== -1);\n}\nfunction checkTokenaddr(cashaddr, enforce) {\n if (enforce && !isTokenaddr(cashaddr)) {\n throw new Error(\"Error trying to send to a non-tokenaware cash address\");\n }\n}\n\n__webpack_async_result__();\n} catch(e) { __webpack_async_result__(e); } });\n\n//# sourceURL=webpack://mainnet-js/./src/util/deriveCashaddr.ts?");
|
|
1418
1428
|
|
|
1419
1429
|
/***/ }),
|
|
1420
1430
|
|
|
@@ -1514,7 +1524,7 @@ eval("__webpack_require__.a(module, async (__webpack_handle_async_dependencies__
|
|
|
1514
1524
|
\***************************/
|
|
1515
1525
|
/***/ ((module, __webpack_exports__, __webpack_require__) => {
|
|
1516
1526
|
|
|
1517
|
-
eval("__webpack_require__.a(module, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {\n__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"BalanceResponse\": () => (/* reexport safe */ _balanceObjectFromSatoshi_js__WEBPACK_IMPORTED_MODULE_22__.BalanceResponse),\n/* harmony export */ \"ExchangeRate\": () => (/* reexport safe */ _rate_ExchangeRate_js__WEBPACK_IMPORTED_MODULE_15__.ExchangeRate),\n/* harmony export */ \"RuntimePlatform\": () => (/* reexport safe */ _getRuntimePlatform_js__WEBPACK_IMPORTED_MODULE_12__.RuntimePlatform),\n/* harmony export */ \"amountInSatoshi\": () => (/* reexport safe */ _amountInSatoshi_js__WEBPACK_IMPORTED_MODULE_0__.amountInSatoshi),\n/* harmony export */ \"asSendRequestObject\": () => (/* reexport safe */ _asSendRequestObject_js__WEBPACK_IMPORTED_MODULE_1__.asSendRequestObject),\n/* harmony export */ \"atob\": () => (/* reexport safe */ _base64_js__WEBPACK_IMPORTED_MODULE_2__.atob),\n/* harmony export */ \"balanceFromSatoshi\": () => (/* reexport safe */ _balanceObjectFromSatoshi_js__WEBPACK_IMPORTED_MODULE_22__.balanceFromSatoshi),\n/* harmony export */ \"balanceResponseFromSatoshi\": () => (/* reexport safe */ _balanceObjectFromSatoshi_js__WEBPACK_IMPORTED_MODULE_22__.balanceResponseFromSatoshi),\n/* harmony export */ \"binToBase64\": () => (/* reexport safe */ _bitauth_libauth__WEBPACK_IMPORTED_MODULE_5__.binToBase64),\n/* harmony export */ \"binToHex\": () => (/* reexport safe */ _bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__.binToHex),\n/* harmony export */ \"btoa\": () => (/* reexport safe */ _base64_js__WEBPACK_IMPORTED_MODULE_2__.btoa),\n/* harmony export */ \"convert\": () => (/* reexport safe */ _convert_js__WEBPACK_IMPORTED_MODULE_7__.convert),\n/* harmony export */ \"convertObject\": () => (/* reexport safe */ _convert_js__WEBPACK_IMPORTED_MODULE_7__.convertObject),\n/* harmony export */ \"delay\": () => (/* reexport safe */ _delay_js__WEBPACK_IMPORTED_MODULE_8__.delay),\n/* harmony export */ \"derivePublicKeyHash\": () => (/* reexport safe */ _derivePublicKeyHash_js__WEBPACK_IMPORTED_MODULE_10__.derivePublicKeyHash),\n/* harmony export */ \"derivedNetwork\": () => (/* reexport safe */ _deriveNetwork_js__WEBPACK_IMPORTED_MODULE_9__.derivedNetwork),\n/* harmony export */ \"getAddrsByXpubKey\": () => (/* reexport safe */ _util_getAddrsByXpubKey_js__WEBPACK_IMPORTED_MODULE_11__.getAddrsByXpubKey),\n/* harmony export */ \"getAddrsByXpubKeyObject\": () => (/* reexport safe */ _util_getAddrsByXpubKey_js__WEBPACK_IMPORTED_MODULE_11__.getAddrsByXpubKeyObject),\n/* harmony export */ \"getRandomInt\": () => (/* reexport safe */ _randomInt_js__WEBPACK_IMPORTED_MODULE_18__.getRandomInt),\n/* harmony export */ \"getRuntimePlatform\": () => (/* reexport safe */ _getRuntimePlatform_js__WEBPACK_IMPORTED_MODULE_12__.getRuntimePlatform),\n/* harmony export */ \"getUsdRate\": () => (/* reexport safe */ _getUsdRate_js__WEBPACK_IMPORTED_MODULE_13__.getUsdRate),\n/* harmony export */ \"getXPubKey\": () => (/* reexport safe */ _util_getXPubKey_js__WEBPACK_IMPORTED_MODULE_19__.getXPubKey),\n/* harmony export */ \"getXpubKeyInfo\": () => (/* reexport safe */ _util_getAddrsByXpubKey_js__WEBPACK_IMPORTED_MODULE_11__.getXpubKeyInfo),\n/* harmony export */ \"getXpubKeyInfoObject\": () => (/* reexport safe */ _util_getAddrsByXpubKey_js__WEBPACK_IMPORTED_MODULE_11__.getXpubKeyInfoObject),\n/* harmony export */ \"hash160\": () => (/* reexport safe */ _hash160_js__WEBPACK_IMPORTED_MODULE_14__.hash160),\n/* harmony export */ \"hexToBin\": () => (/* reexport safe */ _bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__.hexToBin),\n/* harmony export */ \"randomValues\": () => (/* reexport module object */ _randomValues_js__WEBPACK_IMPORTED_MODULE_20__),\n/* harmony export */ \"sanitizeAddress\": () => (/* reexport safe */ _sanitizeAddress_js__WEBPACK_IMPORTED_MODULE_16__.sanitizeAddress),\n/* harmony export */ \"sanitizeUnit\": () => (/* reexport safe */ _sanitizeUnit_js__WEBPACK_IMPORTED_MODULE_17__.sanitizeUnit),\n/* harmony export */ \"sha256\": () => (/* reexport safe */ _bitauth_libauth__WEBPACK_IMPORTED_MODULE_6__.sha256),\n/* harmony export */ \"sumUtxoValue\": () => (/* reexport safe */ _sumUtxoValue_js__WEBPACK_IMPORTED_MODULE_21__.sumUtxoValue),\n/* harmony export */ \"utf8ToBin\": () => (/* reexport safe */ _bitauth_libauth__WEBPACK_IMPORTED_MODULE_4__.utf8ToBin)\n/* harmony export */ });\n/* harmony import */ var _amountInSatoshi_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./amountInSatoshi.js */ \"./src/util/amountInSatoshi.ts\");\n/* harmony import */ var _asSendRequestObject_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./asSendRequestObject.js */ \"./src/util/asSendRequestObject.ts\");\n/* harmony import */ var _base64_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./base64.js */ \"./src/util/base64.ts\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/format/hex.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/format/utf8.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/format/base64.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/crypto/default-crypto-instances.js\");\n/* harmony import */ var _convert_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./convert.js */ \"./src/util/convert.ts\");\n/* harmony import */ var _delay_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./delay.js */ \"./src/util/delay.ts\");\n/* harmony import */ var _deriveNetwork_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./deriveNetwork.js */ \"./src/util/deriveNetwork.ts\");\n/* harmony import */ var _derivePublicKeyHash_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./derivePublicKeyHash.js */ \"./src/util/derivePublicKeyHash.ts\");\n/* harmony import */ var _util_getAddrsByXpubKey_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ../util/getAddrsByXpubKey.js */ \"./src/util/getAddrsByXpubKey.ts\");\n/* harmony import */ var _getRuntimePlatform_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./getRuntimePlatform.js */ \"./src/util/getRuntimePlatform.ts\");\n/* harmony import */ var _getUsdRate_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./getUsdRate.js */ \"./src/util/getUsdRate.ts\");\n/* harmony import */ var _hash160_js__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./hash160.js */ \"./src/util/hash160.ts\");\n/* harmony import */ var _rate_ExchangeRate_js__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ../rate/ExchangeRate.js */ \"./src/rate/ExchangeRate.ts\");\n/* harmony import */ var _sanitizeAddress_js__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ./sanitizeAddress.js */ \"./src/util/sanitizeAddress.ts\");\n/* harmony import */ var _sanitizeUnit_js__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ./sanitizeUnit.js */ \"./src/util/sanitizeUnit.ts\");\n/* harmony import */ var _randomInt_js__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ./randomInt.js */ \"./src/util/randomInt.ts\");\n/* harmony import */ var _util_getXPubKey_js__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! ../util/getXPubKey.js */ \"./src/util/getXPubKey.ts\");\n/* harmony import */ var _randomValues_js__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(/*! ./randomValues.js */ \"./src/util/randomValues.ts\");\n/* harmony import */ var _sumUtxoValue_js__WEBPACK_IMPORTED_MODULE_21__ = __webpack_require__(/*! ./sumUtxoValue.js */ \"./src/util/sumUtxoValue.ts\");\n/* harmony import */ var _balanceObjectFromSatoshi_js__WEBPACK_IMPORTED_MODULE_22__ = __webpack_require__(/*! ./balanceObjectFromSatoshi.js */ \"./src/util/balanceObjectFromSatoshi.ts\");\nvar __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_amountInSatoshi_js__WEBPACK_IMPORTED_MODULE_0__, _asSendRequestObject_js__WEBPACK_IMPORTED_MODULE_1__, _base64_js__WEBPACK_IMPORTED_MODULE_2__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_6__, _convert_js__WEBPACK_IMPORTED_MODULE_7__, _deriveNetwork_js__WEBPACK_IMPORTED_MODULE_9__, _derivePublicKeyHash_js__WEBPACK_IMPORTED_MODULE_10__, _util_getAddrsByXpubKey_js__WEBPACK_IMPORTED_MODULE_11__, _hash160_js__WEBPACK_IMPORTED_MODULE_14__, _sanitizeAddress_js__WEBPACK_IMPORTED_MODULE_16__, _util_getXPubKey_js__WEBPACK_IMPORTED_MODULE_19__, _balanceObjectFromSatoshi_js__WEBPACK_IMPORTED_MODULE_22__]);\n([_amountInSatoshi_js__WEBPACK_IMPORTED_MODULE_0__, _asSendRequestObject_js__WEBPACK_IMPORTED_MODULE_1__, _base64_js__WEBPACK_IMPORTED_MODULE_2__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_6__, _convert_js__WEBPACK_IMPORTED_MODULE_7__, _deriveNetwork_js__WEBPACK_IMPORTED_MODULE_9__, _derivePublicKeyHash_js__WEBPACK_IMPORTED_MODULE_10__, _util_getAddrsByXpubKey_js__WEBPACK_IMPORTED_MODULE_11__, _hash160_js__WEBPACK_IMPORTED_MODULE_14__, _sanitizeAddress_js__WEBPACK_IMPORTED_MODULE_16__, _util_getXPubKey_js__WEBPACK_IMPORTED_MODULE_19__, _balanceObjectFromSatoshi_js__WEBPACK_IMPORTED_MODULE_22__] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n__webpack_async_result__();\n} catch(e) { __webpack_async_result__(e); } });\n\n//# sourceURL=webpack://mainnet-js/./src/util/index.ts?");
|
|
1527
|
+
eval("__webpack_require__.a(module, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {\n__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"BalanceResponse\": () => (/* reexport safe */ _balanceObjectFromSatoshi_js__WEBPACK_IMPORTED_MODULE_23__.BalanceResponse),\n/* harmony export */ \"ExchangeRate\": () => (/* reexport safe */ _rate_ExchangeRate_js__WEBPACK_IMPORTED_MODULE_16__.ExchangeRate),\n/* harmony export */ \"RuntimePlatform\": () => (/* reexport safe */ _getRuntimePlatform_js__WEBPACK_IMPORTED_MODULE_13__.RuntimePlatform),\n/* harmony export */ \"amountInSatoshi\": () => (/* reexport safe */ _amountInSatoshi_js__WEBPACK_IMPORTED_MODULE_0__.amountInSatoshi),\n/* harmony export */ \"asSendRequestObject\": () => (/* reexport safe */ _asSendRequestObject_js__WEBPACK_IMPORTED_MODULE_1__.asSendRequestObject),\n/* harmony export */ \"atob\": () => (/* reexport safe */ _base64_js__WEBPACK_IMPORTED_MODULE_2__.atob),\n/* harmony export */ \"balanceFromSatoshi\": () => (/* reexport safe */ _balanceObjectFromSatoshi_js__WEBPACK_IMPORTED_MODULE_23__.balanceFromSatoshi),\n/* harmony export */ \"balanceResponseFromSatoshi\": () => (/* reexport safe */ _balanceObjectFromSatoshi_js__WEBPACK_IMPORTED_MODULE_23__.balanceResponseFromSatoshi),\n/* harmony export */ \"binToBase64\": () => (/* reexport safe */ _bitauth_libauth__WEBPACK_IMPORTED_MODULE_5__.binToBase64),\n/* harmony export */ \"binToHex\": () => (/* reexport safe */ _bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__.binToHex),\n/* harmony export */ \"btoa\": () => (/* reexport safe */ _base64_js__WEBPACK_IMPORTED_MODULE_2__.btoa),\n/* harmony export */ \"checkTokenaddr\": () => (/* reexport safe */ _deriveCashaddr_js__WEBPACK_IMPORTED_MODULE_11__.checkTokenaddr),\n/* harmony export */ \"convert\": () => (/* reexport safe */ _convert_js__WEBPACK_IMPORTED_MODULE_7__.convert),\n/* harmony export */ \"convertObject\": () => (/* reexport safe */ _convert_js__WEBPACK_IMPORTED_MODULE_7__.convertObject),\n/* harmony export */ \"delay\": () => (/* reexport safe */ _delay_js__WEBPACK_IMPORTED_MODULE_8__.delay),\n/* harmony export */ \"deriveCashaddr\": () => (/* reexport safe */ _deriveCashaddr_js__WEBPACK_IMPORTED_MODULE_11__.deriveCashaddr),\n/* harmony export */ \"derivePublicKeyHash\": () => (/* reexport safe */ _derivePublicKeyHash_js__WEBPACK_IMPORTED_MODULE_10__.derivePublicKeyHash),\n/* harmony export */ \"deriveTokenaddr\": () => (/* reexport safe */ _deriveCashaddr_js__WEBPACK_IMPORTED_MODULE_11__.deriveTokenaddr),\n/* harmony export */ \"derivedNetwork\": () => (/* reexport safe */ _deriveNetwork_js__WEBPACK_IMPORTED_MODULE_9__.derivedNetwork),\n/* harmony export */ \"getAddrsByXpubKey\": () => (/* reexport safe */ _util_getAddrsByXpubKey_js__WEBPACK_IMPORTED_MODULE_12__.getAddrsByXpubKey),\n/* harmony export */ \"getAddrsByXpubKeyObject\": () => (/* reexport safe */ _util_getAddrsByXpubKey_js__WEBPACK_IMPORTED_MODULE_12__.getAddrsByXpubKeyObject),\n/* harmony export */ \"getRandomInt\": () => (/* reexport safe */ _randomInt_js__WEBPACK_IMPORTED_MODULE_19__.getRandomInt),\n/* harmony export */ \"getRuntimePlatform\": () => (/* reexport safe */ _getRuntimePlatform_js__WEBPACK_IMPORTED_MODULE_13__.getRuntimePlatform),\n/* harmony export */ \"getUsdRate\": () => (/* reexport safe */ _getUsdRate_js__WEBPACK_IMPORTED_MODULE_14__.getUsdRate),\n/* harmony export */ \"getXPubKey\": () => (/* reexport safe */ _util_getXPubKey_js__WEBPACK_IMPORTED_MODULE_20__.getXPubKey),\n/* harmony export */ \"getXpubKeyInfo\": () => (/* reexport safe */ _util_getAddrsByXpubKey_js__WEBPACK_IMPORTED_MODULE_12__.getXpubKeyInfo),\n/* harmony export */ \"getXpubKeyInfoObject\": () => (/* reexport safe */ _util_getAddrsByXpubKey_js__WEBPACK_IMPORTED_MODULE_12__.getXpubKeyInfoObject),\n/* harmony export */ \"hash160\": () => (/* reexport safe */ _hash160_js__WEBPACK_IMPORTED_MODULE_15__.hash160),\n/* harmony export */ \"hexToBin\": () => (/* reexport safe */ _bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__.hexToBin),\n/* harmony export */ \"isTokenaddr\": () => (/* reexport safe */ _deriveCashaddr_js__WEBPACK_IMPORTED_MODULE_11__.isTokenaddr),\n/* harmony export */ \"randomValues\": () => (/* reexport module object */ _randomValues_js__WEBPACK_IMPORTED_MODULE_21__),\n/* harmony export */ \"sanitizeAddress\": () => (/* reexport safe */ _sanitizeAddress_js__WEBPACK_IMPORTED_MODULE_17__.sanitizeAddress),\n/* harmony export */ \"sanitizeUnit\": () => (/* reexport safe */ _sanitizeUnit_js__WEBPACK_IMPORTED_MODULE_18__.sanitizeUnit),\n/* harmony export */ \"sha256\": () => (/* reexport safe */ _bitauth_libauth__WEBPACK_IMPORTED_MODULE_6__.sha256),\n/* harmony export */ \"sumUtxoValue\": () => (/* reexport safe */ _sumUtxoValue_js__WEBPACK_IMPORTED_MODULE_22__.sumUtxoValue),\n/* harmony export */ \"toCashaddr\": () => (/* reexport safe */ _deriveCashaddr_js__WEBPACK_IMPORTED_MODULE_11__.toCashaddr),\n/* harmony export */ \"toTokenaddr\": () => (/* reexport safe */ _deriveCashaddr_js__WEBPACK_IMPORTED_MODULE_11__.toTokenaddr),\n/* harmony export */ \"utf8ToBin\": () => (/* reexport safe */ _bitauth_libauth__WEBPACK_IMPORTED_MODULE_4__.utf8ToBin)\n/* harmony export */ });\n/* harmony import */ var _amountInSatoshi_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./amountInSatoshi.js */ \"./src/util/amountInSatoshi.ts\");\n/* harmony import */ var _asSendRequestObject_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./asSendRequestObject.js */ \"./src/util/asSendRequestObject.ts\");\n/* harmony import */ var _base64_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./base64.js */ \"./src/util/base64.ts\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/format/hex.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/format/utf8.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/format/base64.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/crypto/default-crypto-instances.js\");\n/* harmony import */ var _convert_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./convert.js */ \"./src/util/convert.ts\");\n/* harmony import */ var _delay_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./delay.js */ \"./src/util/delay.ts\");\n/* harmony import */ var _deriveNetwork_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./deriveNetwork.js */ \"./src/util/deriveNetwork.ts\");\n/* harmony import */ var _derivePublicKeyHash_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./derivePublicKeyHash.js */ \"./src/util/derivePublicKeyHash.ts\");\n/* harmony import */ var _deriveCashaddr_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./deriveCashaddr.js */ \"./src/util/deriveCashaddr.ts\");\n/* harmony import */ var _util_getAddrsByXpubKey_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ../util/getAddrsByXpubKey.js */ \"./src/util/getAddrsByXpubKey.ts\");\n/* harmony import */ var _getRuntimePlatform_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./getRuntimePlatform.js */ \"./src/util/getRuntimePlatform.ts\");\n/* harmony import */ var _getUsdRate_js__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./getUsdRate.js */ \"./src/util/getUsdRate.ts\");\n/* harmony import */ var _hash160_js__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./hash160.js */ \"./src/util/hash160.ts\");\n/* harmony import */ var _rate_ExchangeRate_js__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ../rate/ExchangeRate.js */ \"./src/rate/ExchangeRate.ts\");\n/* harmony import */ var _sanitizeAddress_js__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ./sanitizeAddress.js */ \"./src/util/sanitizeAddress.ts\");\n/* harmony import */ var _sanitizeUnit_js__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ./sanitizeUnit.js */ \"./src/util/sanitizeUnit.ts\");\n/* harmony import */ var _randomInt_js__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! ./randomInt.js */ \"./src/util/randomInt.ts\");\n/* harmony import */ var _util_getXPubKey_js__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(/*! ../util/getXPubKey.js */ \"./src/util/getXPubKey.ts\");\n/* harmony import */ var _randomValues_js__WEBPACK_IMPORTED_MODULE_21__ = __webpack_require__(/*! ./randomValues.js */ \"./src/util/randomValues.ts\");\n/* harmony import */ var _sumUtxoValue_js__WEBPACK_IMPORTED_MODULE_22__ = __webpack_require__(/*! ./sumUtxoValue.js */ \"./src/util/sumUtxoValue.ts\");\n/* harmony import */ var _balanceObjectFromSatoshi_js__WEBPACK_IMPORTED_MODULE_23__ = __webpack_require__(/*! ./balanceObjectFromSatoshi.js */ \"./src/util/balanceObjectFromSatoshi.ts\");\nvar __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_amountInSatoshi_js__WEBPACK_IMPORTED_MODULE_0__, _asSendRequestObject_js__WEBPACK_IMPORTED_MODULE_1__, _base64_js__WEBPACK_IMPORTED_MODULE_2__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_6__, _convert_js__WEBPACK_IMPORTED_MODULE_7__, _deriveNetwork_js__WEBPACK_IMPORTED_MODULE_9__, _derivePublicKeyHash_js__WEBPACK_IMPORTED_MODULE_10__, _deriveCashaddr_js__WEBPACK_IMPORTED_MODULE_11__, _util_getAddrsByXpubKey_js__WEBPACK_IMPORTED_MODULE_12__, _hash160_js__WEBPACK_IMPORTED_MODULE_15__, _sanitizeAddress_js__WEBPACK_IMPORTED_MODULE_17__, _util_getXPubKey_js__WEBPACK_IMPORTED_MODULE_20__, _balanceObjectFromSatoshi_js__WEBPACK_IMPORTED_MODULE_23__]);\n([_amountInSatoshi_js__WEBPACK_IMPORTED_MODULE_0__, _asSendRequestObject_js__WEBPACK_IMPORTED_MODULE_1__, _base64_js__WEBPACK_IMPORTED_MODULE_2__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_6__, _convert_js__WEBPACK_IMPORTED_MODULE_7__, _deriveNetwork_js__WEBPACK_IMPORTED_MODULE_9__, _derivePublicKeyHash_js__WEBPACK_IMPORTED_MODULE_10__, _deriveCashaddr_js__WEBPACK_IMPORTED_MODULE_11__, _util_getAddrsByXpubKey_js__WEBPACK_IMPORTED_MODULE_12__, _hash160_js__WEBPACK_IMPORTED_MODULE_15__, _sanitizeAddress_js__WEBPACK_IMPORTED_MODULE_17__, _util_getXPubKey_js__WEBPACK_IMPORTED_MODULE_20__, _balanceObjectFromSatoshi_js__WEBPACK_IMPORTED_MODULE_23__] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n__webpack_async_result__();\n} catch(e) { __webpack_async_result__(e); } });\n\n//# sourceURL=webpack://mainnet-js/./src/util/index.ts?");
|
|
1518
1528
|
|
|
1519
1529
|
/***/ }),
|
|
1520
1530
|
|
|
@@ -1644,7 +1654,7 @@ eval("__webpack_require__.a(module, async (__webpack_handle_async_dependencies__
|
|
|
1644
1654
|
\****************************/
|
|
1645
1655
|
/***/ ((module, __webpack_exports__, __webpack_require__) => {
|
|
1646
1656
|
|
|
1647
|
-
eval("__webpack_require__.a(module, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"RegTestUtil\": () => (/* binding */ RegTestUtil),\n/* harmony export */ \"RegTestWatchUtil\": () => (/* binding */ RegTestWatchUtil),\n/* harmony export */ \"RegTestWifUtil\": () => (/* binding */ RegTestWifUtil),\n/* harmony export */ \"TestNetUtil\": () => (/* binding */ TestNetUtil),\n/* harmony export */ \"TestNetWatchUtil\": () => (/* binding */ TestNetWatchUtil),\n/* harmony export */ \"TestNetWifUtil\": () => (/* binding */ TestNetWifUtil),\n/* harmony export */ \"Util\": () => (/* binding */ Util),\n/* harmony export */ \"WatchUtil\": () => (/* binding */ WatchUtil),\n/* harmony export */ \"WifUtil\": () => (/* binding */ WifUtil)\n/* harmony export */ });\n/* harmony import */ var _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../wallet/Wif.js */ \"./src/wallet/Wif.ts\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/format/hex.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/message/transaction-encoding.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/address/locking-bytecode.js\");\n/* harmony import */ var _chain_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../chain.js */ \"./src/chain.ts\");\n/* harmony import */ var _util_transaction_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../util/transaction.js */ \"./src/util/transaction.ts\");\nvar __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_wallet_Wif_js__WEBPACK_IMPORTED_MODULE_0__, _util_transaction_js__WEBPACK_IMPORTED_MODULE_1__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_4__]);\n([_wallet_Wif_js__WEBPACK_IMPORTED_MODULE_0__, _util_transaction_js__WEBPACK_IMPORTED_MODULE_1__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_4__] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);\n\n\n\n\n/**\n * Class with various wallet utilities.\n */\nclass Util {\n /**\n * Initializes a wallet Util class.\n *\n * @param wallet A wallet object\n */\n constructor(wallet) {\n this.wallet = wallet;\n }\n static get walletType() {\n return _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_0__.Wallet;\n }\n async getTransactionHash(rawTransactionHex) {\n return (0,_util_transaction_js__WEBPACK_IMPORTED_MODULE_1__.getTransactionHash)(rawTransactionHex);\n }\n static async getTransactionHash(rawTransactionHex) {\n return (0,_util_transaction_js__WEBPACK_IMPORTED_MODULE_1__.getTransactionHash)(rawTransactionHex);\n }\n async decodeTransaction(transactionHashOrHex, loadInputValues = false) {\n let transactionHex;\n let transactionBin;\n let txHash;\n // raw transaction\n if (transactionHashOrHex.length > 64) {\n txHash = await this.getTransactionHash(transactionHashOrHex);\n transactionBin = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__.hexToBin)(transactionHashOrHex);\n transactionHex = transactionHashOrHex;\n }\n else {\n // tx hash, look up the raw transaction\n txHash = transactionHashOrHex;\n transactionHex = await this.wallet.provider.getRawTransaction(txHash);\n transactionBin = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__.hexToBin)(transactionHex);\n }\n const result = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__.decodeTransaction)(transactionBin);\n if (typeof result === \"string\") {\n throw Error(result);\n }\n const transaction = this.mapToElectrumRawTransaction(result, txHash, transactionHex);\n if (loadInputValues) {\n // get unique transaction hashes\n const hashes = [...new Set(transaction.vin.map((val) => val.txid))];\n const transactions = await Promise.all(hashes.map((hash) => this.decodeTransaction(hash, false)));\n const transactionMap = new Map();\n transactions.forEach((val) => transactionMap.set(val.hash, val));\n transaction.vin.forEach((input) => {\n const output = transactionMap\n .get(input.txid)\n .vout.find((val) => val.n === input.vout);\n input.address = output.scriptPubKey.addresses[0];\n input.value = output.value;\n });\n }\n return transaction;\n }\n mapToElectrumRawTransaction(transaction, txHash, txHex) {\n let result = {};\n result.vin = transaction.inputs.map((input) => {\n return {\n scriptSig: {\n hex: (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__.binToHex)(input.unlockingBytecode),\n },\n sequence: input.sequenceNumber,\n txid: (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__.binToHex)(input.outpointTransactionHash),\n vout: input.outpointIndex,\n };\n });\n result.vout = transaction.outputs.map((output, index) => {\n return {\n n: index,\n scriptPubKey: {\n addresses: [\n (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_4__.lockingBytecodeToCashAddress)(output.lockingBytecode, this.wallet.networkPrefix).toString(),\n ],\n hex: (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__.binToHex)(output.lockingBytecode),\n },\n value: Number(output.valueSatoshis) / _chain_js__WEBPACK_IMPORTED_MODULE_5__.bchParam.subUnits,\n };\n });\n result.locktime = transaction.locktime;\n result.version = transaction.version;\n result.hash = txHash;\n result.hex = txHex;\n result.txid = txHash;\n result.size = txHex.length / 2;\n return result;\n }\n static async decodeTransaction(transactionHashOrHex, loadInputValues = false) {\n return new this.walletType().util.decodeTransaction(transactionHashOrHex, loadInputValues);\n }\n}\n//#region Specific wallet classes\n/**\n * Class to manage an slp enabled testnet wallet.\n */\nclass TestNetUtil extends Util {\n static get walletType() {\n return _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_0__.TestNetWallet;\n }\n}\n/**\n * Class to manage an slp enabled regtest wallet.\n */\nclass RegTestUtil extends Util {\n static get walletType() {\n return _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_0__.RegTestWallet;\n }\n}\n/**\n * Class to manage a bitcoin cash wif wallet.\n */\nclass WifUtil extends Util {\n static get walletType() {\n return _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_0__.WifWallet;\n }\n}\n/**\n * Class to manage a testnet wif wallet.\n */\nclass TestNetWifUtil extends Util {\n static get walletType() {\n return _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_0__.TestNetWifWallet;\n }\n}\n/**\n * Class to manage a regtest wif wallet.\n */\nclass RegTestWifUtil extends Util {\n static get walletType() {\n return _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_0__.RegTestWifWallet;\n }\n}\n/**\n * Class to manage a bitcoin cash watch wallet.\n */\nclass WatchUtil extends Util {\n static get walletType() {\n return _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_0__.WatchWallet;\n }\n}\n/**\n * Class to manage a testnet watch wallet.\n */\nclass TestNetWatchUtil extends Util {\n static get walletType() {\n return _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_0__.TestNetWatchWallet;\n }\n}\n/**\n * Class to manage a regtest watch wallet.\n */\nclass RegTestWatchUtil extends Util {\n static get walletType() {\n return _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_0__.RegTestWatchWallet;\n }\n}\n//#endregion\n\n__webpack_async_result__();\n} catch(e) { __webpack_async_result__(e); } });\n\n//# sourceURL=webpack://mainnet-js/./src/wallet/Util.ts?");
|
|
1657
|
+
eval("__webpack_require__.a(module, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"RegTestUtil\": () => (/* binding */ RegTestUtil),\n/* harmony export */ \"RegTestWatchUtil\": () => (/* binding */ RegTestWatchUtil),\n/* harmony export */ \"RegTestWifUtil\": () => (/* binding */ RegTestWifUtil),\n/* harmony export */ \"TestNetUtil\": () => (/* binding */ TestNetUtil),\n/* harmony export */ \"TestNetWatchUtil\": () => (/* binding */ TestNetWatchUtil),\n/* harmony export */ \"TestNetWifUtil\": () => (/* binding */ TestNetWifUtil),\n/* harmony export */ \"Util\": () => (/* binding */ Util),\n/* harmony export */ \"WatchUtil\": () => (/* binding */ WatchUtil),\n/* harmony export */ \"WifUtil\": () => (/* binding */ WifUtil)\n/* harmony export */ });\n/* harmony import */ var _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../wallet/Wif.js */ \"./src/wallet/Wif.ts\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/format/hex.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/message/transaction-encoding.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/address/locking-bytecode.js\");\n/* harmony import */ var _chain_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../chain.js */ \"./src/chain.ts\");\n/* harmony import */ var _util_transaction_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../util/transaction.js */ \"./src/util/transaction.ts\");\nvar __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_wallet_Wif_js__WEBPACK_IMPORTED_MODULE_0__, _util_transaction_js__WEBPACK_IMPORTED_MODULE_1__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_4__]);\n([_wallet_Wif_js__WEBPACK_IMPORTED_MODULE_0__, _util_transaction_js__WEBPACK_IMPORTED_MODULE_1__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_4__] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);\n\n\n\n\n/**\n * Class with various wallet utilities.\n */\nclass Util {\n /**\n * Initializes a wallet Util class.\n *\n * @param wallet A wallet object\n */\n constructor(wallet) {\n this.wallet = wallet;\n }\n static get walletType() {\n return _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_0__.Wallet;\n }\n async getTransactionHash(rawTransactionHex) {\n return (0,_util_transaction_js__WEBPACK_IMPORTED_MODULE_1__.getTransactionHash)(rawTransactionHex);\n }\n static async getTransactionHash(rawTransactionHex) {\n return (0,_util_transaction_js__WEBPACK_IMPORTED_MODULE_1__.getTransactionHash)(rawTransactionHex);\n }\n async decodeTransaction(transactionHashOrHex, loadInputValues = false) {\n let transactionHex;\n let transactionBin;\n let txHash;\n // raw transaction\n if (transactionHashOrHex.length > 64) {\n txHash = await this.getTransactionHash(transactionHashOrHex);\n transactionBin = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__.hexToBin)(transactionHashOrHex);\n transactionHex = transactionHashOrHex;\n }\n else {\n // tx hash, look up the raw transaction\n txHash = transactionHashOrHex;\n transactionHex = await this.wallet.provider.getRawTransaction(txHash);\n transactionBin = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__.hexToBin)(transactionHex);\n }\n const result = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__.decodeTransaction)(transactionBin);\n if (typeof result === \"string\") {\n throw Error(result);\n }\n const transaction = this.mapToElectrumRawTransaction(result, txHash, transactionHex);\n if (loadInputValues) {\n // get unique transaction hashes\n const hashes = [...new Set(transaction.vin.map((val) => val.txid))];\n const transactions = await Promise.all(hashes.map((hash) => this.decodeTransaction(hash, false)));\n const transactionMap = new Map();\n transactions.forEach((val) => transactionMap.set(val.hash, val));\n transaction.vin.forEach((input) => {\n const output = transactionMap\n .get(input.txid)\n .vout.find((val) => val.n === input.vout);\n input.address = output.scriptPubKey.addresses[0];\n input.value = output.value;\n input.tokenData = output.tokenData;\n });\n }\n return transaction;\n }\n mapToElectrumRawTransaction(transaction, txHash, txHex) {\n let result = {};\n result.vin = transaction.inputs.map((input) => {\n return {\n scriptSig: {\n hex: (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__.binToHex)(input.unlockingBytecode),\n },\n sequence: input.sequenceNumber,\n txid: (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__.binToHex)(input.outpointTransactionHash),\n vout: input.outpointIndex,\n };\n });\n result.vout = transaction.outputs.map((output, index) => {\n return {\n n: index,\n scriptPubKey: {\n addresses: [\n (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_4__.lockingBytecodeToCashAddress)(output.lockingBytecode, this.wallet.networkPrefix).toString(),\n ],\n hex: (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__.binToHex)(output.lockingBytecode),\n },\n value: Number(output.valueSatoshis) / _chain_js__WEBPACK_IMPORTED_MODULE_5__.bchParam.subUnits,\n };\n });\n result.locktime = transaction.locktime;\n result.version = transaction.version;\n result.hash = txHash;\n result.hex = txHex;\n result.txid = txHash;\n result.size = txHex.length / 2;\n return result;\n }\n static async decodeTransaction(transactionHashOrHex, loadInputValues = false) {\n return new this.walletType().util.decodeTransaction(transactionHashOrHex, loadInputValues);\n }\n}\n//#region Specific wallet classes\n/**\n * Class to manage an slp enabled testnet wallet.\n */\nclass TestNetUtil extends Util {\n static get walletType() {\n return _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_0__.TestNetWallet;\n }\n}\n/**\n * Class to manage an slp enabled regtest wallet.\n */\nclass RegTestUtil extends Util {\n static get walletType() {\n return _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_0__.RegTestWallet;\n }\n}\n/**\n * Class to manage a bitcoin cash wif wallet.\n */\nclass WifUtil extends Util {\n static get walletType() {\n return _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_0__.WifWallet;\n }\n}\n/**\n * Class to manage a testnet wif wallet.\n */\nclass TestNetWifUtil extends Util {\n static get walletType() {\n return _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_0__.TestNetWifWallet;\n }\n}\n/**\n * Class to manage a regtest wif wallet.\n */\nclass RegTestWifUtil extends Util {\n static get walletType() {\n return _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_0__.RegTestWifWallet;\n }\n}\n/**\n * Class to manage a bitcoin cash watch wallet.\n */\nclass WatchUtil extends Util {\n static get walletType() {\n return _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_0__.WatchWallet;\n }\n}\n/**\n * Class to manage a testnet watch wallet.\n */\nclass TestNetWatchUtil extends Util {\n static get walletType() {\n return _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_0__.TestNetWatchWallet;\n }\n}\n/**\n * Class to manage a regtest watch wallet.\n */\nclass RegTestWatchUtil extends Util {\n static get walletType() {\n return _wallet_Wif_js__WEBPACK_IMPORTED_MODULE_0__.RegTestWatchWallet;\n }\n}\n//#endregion\n\n__webpack_async_result__();\n} catch(e) { __webpack_async_result__(e); } });\n\n//# sourceURL=webpack://mainnet-js/./src/wallet/Util.ts?");
|
|
1648
1658
|
|
|
1649
1659
|
/***/ }),
|
|
1650
1660
|
|
|
@@ -1654,7 +1664,7 @@ eval("__webpack_require__.a(module, async (__webpack_handle_async_dependencies__
|
|
|
1654
1664
|
\***************************/
|
|
1655
1665
|
/***/ ((module, __webpack_exports__, __webpack_require__) => {
|
|
1656
1666
|
|
|
1657
|
-
eval("__webpack_require__.a(module, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"RegTestWallet\": () => (/* binding */ RegTestWallet),\n/* harmony export */ \"RegTestWatchWallet\": () => (/* binding */ RegTestWatchWallet),\n/* harmony export */ \"RegTestWifWallet\": () => (/* binding */ RegTestWifWallet),\n/* harmony export */ \"TestNetWallet\": () => (/* binding */ TestNetWallet),\n/* harmony export */ \"TestNetWatchWallet\": () => (/* binding */ TestNetWatchWallet),\n/* harmony export */ \"TestNetWifWallet\": () => (/* binding */ TestNetWifWallet),\n/* harmony export */ \"Wallet\": () => (/* binding */ Wallet),\n/* harmony export */ \"WatchWallet\": () => (/* binding */ WatchWallet),\n/* harmony export */ \"WifWallet\": () => (/* binding */ WifWallet)\n/* harmony export */ });\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/key/hd-key.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_33__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/crypto/default-crypto-instances.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/format/hex.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/key/key-utils.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_23__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/key/wallet-import-format.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_35__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/address/cash-address.js\");\n/* harmony import */ var bip39__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! bip39 */ \"../../node_modules/bip39/src/index.js\");\n/* harmony import */ var _enum_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../enum.js */ \"./src/enum.ts\");\n/* harmony import */ var _interface_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../interface.js */ \"./src/interface.ts\");\n/* harmony import */ var _Base_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Base.js */ \"./src/wallet/Base.ts\");\n/* harmony import */ var _enum_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./enum.js */ \"./src/wallet/enum.ts\");\n/* harmony import */ var _model_js__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(/*! ./model.js */ \"./src/wallet/model.ts\");\n/* harmony import */ var _transaction_Wif_js__WEBPACK_IMPORTED_MODULE_29__ = __webpack_require__(/*! ../transaction/Wif.js */ \"./src/transaction/Wif.ts\");\n/* harmony import */ var _util_asSendRequestObject_js__WEBPACK_IMPORTED_MODULE_30__ = __webpack_require__(/*! ../util/asSendRequestObject.js */ \"./src/util/asSendRequestObject.ts\");\n/* harmony import */ var _util_balanceObjectFromSatoshi_js__WEBPACK_IMPORTED_MODULE_25__ = __webpack_require__(/*! ../util/balanceObjectFromSatoshi.js */ \"./src/util/balanceObjectFromSatoshi.ts\");\n/* harmony import */ var _util_checkWifNetwork_js__WEBPACK_IMPORTED_MODULE_22__ = __webpack_require__(/*! ../util/checkWifNetwork.js */ \"./src/util/checkWifNetwork.ts\");\n/* harmony import */ var _util_deriveCashaddr_js__WEBPACK_IMPORTED_MODULE_21__ = __webpack_require__(/*! ../util/deriveCashaddr.js */ \"./src/util/deriveCashaddr.ts\");\n/* harmony import */ var _util_derivePublicKeyHash_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ../util/derivePublicKeyHash.js */ \"./src/util/derivePublicKeyHash.ts\");\n/* harmony import */ var _util_checkForEmptySeed_js__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ../util/checkForEmptySeed.js */ \"./src/util/checkForEmptySeed.ts\");\n/* harmony import */ var _util_sanitizeUnit_js__WEBPACK_IMPORTED_MODULE_24__ = __webpack_require__(/*! ../util/sanitizeUnit.js */ \"./src/util/sanitizeUnit.ts\");\n/* harmony import */ var _util_sumUtxoValue_js__WEBPACK_IMPORTED_MODULE_26__ = __webpack_require__(/*! ../util/sumUtxoValue.js */ \"./src/util/sumUtxoValue.ts\");\n/* harmony import */ var _util_sumSendRequestAmounts_js__WEBPACK_IMPORTED_MODULE_31__ = __webpack_require__(/*! ../util/sumSendRequestAmounts.js */ \"./src/util/sumSendRequestAmounts.ts\");\n/* harmony import */ var _network_getRelayFeeCache_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../network/getRelayFeeCache.js */ \"./src/network/getRelayFeeCache.ts\");\n/* harmony import */ var _Slp_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./Slp.js */ \"./src/wallet/Slp.ts\");\n/* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! axios */ \"../../node_modules/axios/index.js\");\n/* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(axios__WEBPACK_IMPORTED_MODULE_2__);\n/* harmony import */ var _util_bchaddr_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ../util/bchaddr.js */ \"../../node_modules/bchaddrjs-slp/src/bchaddr.js\");\n/* harmony import */ var _util_bchaddr_js__WEBPACK_IMPORTED_MODULE_13___default = /*#__PURE__*/__webpack_require__.n(_util_bchaddr_js__WEBPACK_IMPORTED_MODULE_13__);\n/* harmony import */ var _Util_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./Util.js */ \"./src/wallet/Util.ts\");\n/* harmony import */ var _network_index_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../network/index.js */ \"./src/network/default.ts\");\n/* harmony import */ var _util_randomBytes_js__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ../util/randomBytes.js */ \"./src/util/randomBytes.ts\");\n/* harmony import */ var _message_index_js__WEBPACK_IMPORTED_MODULE_34__ = __webpack_require__(/*! ../message/index.js */ \"./src/message/signed.ts\");\n/* harmony import */ var _util_amountInSatoshi_js__WEBPACK_IMPORTED_MODULE_27__ = __webpack_require__(/*! ../util/amountInSatoshi.js */ \"./src/util/amountInSatoshi.ts\");\n/* harmony import */ var _util_getXPubKey_js__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ../util/getXPubKey.js */ \"./src/util/getXPubKey.ts\");\n/* harmony import */ var _constant_js__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! ../constant.js */ \"./src/constant.ts\");\n/* harmony import */ var _history_electrumTransformer_js__WEBPACK_IMPORTED_MODULE_32__ = __webpack_require__(/*! ../history/electrumTransformer.js */ \"./src/history/electrumTransformer.ts\");\n/* harmony import */ var _Bcmr_js__WEBPACK_IMPORTED_MODULE_28__ = __webpack_require__(/*! ./Bcmr.js */ \"./src/wallet/Bcmr.ts\");\n/* harmony import */ var _qr_Qr_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../qr/Qr.js */ \"./src/qr/Qr.ts\");\nvar __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_Base_js__WEBPACK_IMPORTED_MODULE_3__, _enum_js__WEBPACK_IMPORTED_MODULE_4__, _Slp_js__WEBPACK_IMPORTED_MODULE_6__, _Util_js__WEBPACK_IMPORTED_MODULE_7__, _network_index_js__WEBPACK_IMPORTED_MODULE_9__, _qr_Qr_js__WEBPACK_IMPORTED_MODULE_10__, _util_derivePublicKeyHash_js__WEBPACK_IMPORTED_MODULE_12__, _util_checkForEmptySeed_js__WEBPACK_IMPORTED_MODULE_16__, _util_getXPubKey_js__WEBPACK_IMPORTED_MODULE_17__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_18__, _model_js__WEBPACK_IMPORTED_MODULE_20__, _util_deriveCashaddr_js__WEBPACK_IMPORTED_MODULE_21__, _util_checkWifNetwork_js__WEBPACK_IMPORTED_MODULE_22__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_23__, _util_balanceObjectFromSatoshi_js__WEBPACK_IMPORTED_MODULE_25__, _util_amountInSatoshi_js__WEBPACK_IMPORTED_MODULE_27__, _Bcmr_js__WEBPACK_IMPORTED_MODULE_28__, _transaction_Wif_js__WEBPACK_IMPORTED_MODULE_29__, _util_asSendRequestObject_js__WEBPACK_IMPORTED_MODULE_30__, _util_sumSendRequestAmounts_js__WEBPACK_IMPORTED_MODULE_31__, _history_electrumTransformer_js__WEBPACK_IMPORTED_MODULE_32__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_33__, _message_index_js__WEBPACK_IMPORTED_MODULE_34__]);\n([_Base_js__WEBPACK_IMPORTED_MODULE_3__, _enum_js__WEBPACK_IMPORTED_MODULE_4__, _Slp_js__WEBPACK_IMPORTED_MODULE_6__, _Util_js__WEBPACK_IMPORTED_MODULE_7__, _network_index_js__WEBPACK_IMPORTED_MODULE_9__, _qr_Qr_js__WEBPACK_IMPORTED_MODULE_10__, _util_derivePublicKeyHash_js__WEBPACK_IMPORTED_MODULE_12__, _util_checkForEmptySeed_js__WEBPACK_IMPORTED_MODULE_16__, _util_getXPubKey_js__WEBPACK_IMPORTED_MODULE_17__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_18__, _model_js__WEBPACK_IMPORTED_MODULE_20__, _util_deriveCashaddr_js__WEBPACK_IMPORTED_MODULE_21__, _util_checkWifNetwork_js__WEBPACK_IMPORTED_MODULE_22__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_23__, _util_balanceObjectFromSatoshi_js__WEBPACK_IMPORTED_MODULE_25__, _util_amountInSatoshi_js__WEBPACK_IMPORTED_MODULE_27__, _Bcmr_js__WEBPACK_IMPORTED_MODULE_28__, _transaction_Wif_js__WEBPACK_IMPORTED_MODULE_29__, _util_asSendRequestObject_js__WEBPACK_IMPORTED_MODULE_30__, _util_sumSendRequestAmounts_js__WEBPACK_IMPORTED_MODULE_31__, _history_electrumTransformer_js__WEBPACK_IMPORTED_MODULE_32__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_33__, _message_index_js__WEBPACK_IMPORTED_MODULE_34__] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);\n//#region Imports\n// Stable\n\n// Unstable?\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n//#endregion Imports\n/**\n * Class to manage a bitcoin cash wallet.\n */\nclass Wallet extends _Base_js__WEBPACK_IMPORTED_MODULE_3__.BaseWallet {\n //#endregion\n //#region Constructors and Statics\n constructor(name = \"\", network = _enum_js__WEBPACK_IMPORTED_MODULE_4__.NetworkType.Mainnet, walletType = _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Seed) {\n super(name, network, walletType);\n this.derivationPath = \"m/44'/0'/0'/0/0\";\n this.parentDerivationPath = \"m/44'/0'/0'\";\n this._slpAware = false; // a flag which activates utxo checking against an external slp indexer\n this._slpSemiAware = false; // a flag which requires an utxo to have more than 546 sats to be spendable and counted in the balance\n this.fromId = async (walletId) => {\n let [walletType, networkGiven, arg1] = walletId.split(\":\");\n if (this.network != networkGiven) {\n throw Error(`Network prefix ${networkGiven} to a ${this.network} wallet`);\n }\n // \"wif:regtest:cNfsPtqN2bMRS7vH5qd8tR8GMvgXyL5BjnGAKgZ8DYEiCrCCQcP6\"\n if (walletType === \"wif\") {\n return this.fromWIF(arg1);\n }\n return super.fromId(walletId);\n };\n this.networkPrefix = _enum_js__WEBPACK_IMPORTED_MODULE_4__.prefixFromNetworkMap[this.network];\n }\n //#region Accessors\n // interface to slp functions. see Slp.ts\n get slp() {\n if (!this._slp) {\n this._slp = new _Slp_js__WEBPACK_IMPORTED_MODULE_6__.Slp(this);\n this._slpAware = true;\n }\n return this._slp;\n }\n // interface to slp functions. see Slp.ts\n static get slp() {\n return _Slp_js__WEBPACK_IMPORTED_MODULE_6__.Slp;\n }\n // interface to util functions. see Util.ts\n get util() {\n if (!this._util) {\n this._util = new _Util_js__WEBPACK_IMPORTED_MODULE_7__.Util(this);\n }\n return this._util;\n }\n // interface to util util. see Util.Util\n static get util() {\n return _Util_js__WEBPACK_IMPORTED_MODULE_7__.Util;\n }\n slpAware(value = true) {\n this._slpAware = value;\n return this;\n }\n slpSemiAware(value = true) {\n this._slpSemiAware = value;\n return this;\n }\n getNetworkProvider(network = _interface_js__WEBPACK_IMPORTED_MODULE_8__.Network.MAINNET) {\n return (0,_network_index_js__WEBPACK_IMPORTED_MODULE_9__.getNetworkProvider)(network);\n }\n /**\n * getTokenDepositAddress - get a cashtoken aware wallet deposit address\n *\n * @returns The cashtoken aware deposit address as a string\n */\n getTokenDepositAddress() {\n return this.tokenaddr;\n }\n /**\n * getDepositQr - get an address qrcode, encoded for display on the web\n *\n * @returns The qrcode for the token aware address\n */\n getTokenDepositQr() {\n return (0,_qr_Qr_js__WEBPACK_IMPORTED_MODULE_10__.qrAddress)(this.getTokenDepositAddress());\n }\n /**\n * explorerUrl Web url to a transaction on a block explorer\n *\n * @param txId transaction Id\n * @returns Url string\n */\n explorerUrl(txId) {\n const explorerUrlMap = {\n mainnet: \"https://blockchair.com/bitcoin-cash/transaction/\",\n testnet: \"https://www.blockchain.com/bch-testnet/tx/\",\n regtest: \"\",\n };\n return explorerUrlMap[this.network] + txId;\n }\n // Return wallet info\n getInfo() {\n return {\n cashaddr: this.cashaddr,\n tokenaddr: this.tokenaddr,\n isTestnet: this.isTestnet,\n name: this.name,\n network: this.network,\n seed: this.mnemonic ? this.getSeed().seed : undefined,\n derivationPath: this.mnemonic ? this.getSeed().derivationPath : undefined,\n parentDerivationPath: this.mnemonic\n ? this.getSeed().parentDerivationPath\n : undefined,\n parentXPubKey: this.parentXPubKey ? this.parentXPubKey : undefined,\n publicKey: this.publicKey ? (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_11__.binToHex)(this.publicKey) : undefined,\n publicKeyHash: (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_11__.binToHex)(this.publicKeyHash),\n privateKey: this.privateKey ? (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_11__.binToHex)(this.privateKey) : undefined,\n privateKeyWif: this.privateKeyWif,\n walletId: this.toString(),\n walletDbEntry: this.toDbString(),\n };\n }\n // returns the public key hash for an address\n getPublicKey(hex = false) {\n if (this.publicKey) {\n return hex ? (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_11__.binToHex)(this.publicKey) : this.publicKey;\n }\n else {\n throw Error(\"The public key for this wallet is not known, perhaps the wallet was created to watch the *hash* of a public key? i.e. a cashaddress.\");\n }\n }\n // returns the public key hash for an address\n getPublicKeyCompressed(hex = false) {\n if (this.publicKeyCompressed) {\n return hex\n ? (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_11__.binToHex)(this.publicKeyCompressed)\n : this.publicKeyCompressed;\n }\n else {\n throw Error(\"The compressed public key for this wallet is not known, perhaps the wallet was created to watch the *hash* of a public key? i.e. a cashaddress.\");\n }\n }\n // returns the public key hash for an address\n getPublicKeyHash(hex = false) {\n if (this.publicKeyHash) {\n return hex ? (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_11__.binToHex)(this.publicKeyHash) : this.publicKeyHash;\n }\n else {\n throw Error(\"The public key hash for this wallet is not known. If this wallet was created from the constructor directly, calling the deriveInfo() function may help. \");\n }\n }\n /**\n * fromWIF - create a wallet using the private key supplied in `Wallet Import Format`\n *\n * @param wif WIF encoded private key string\n *\n * @returns instantiated wallet\n */\n static async fromWIF(wif) {\n return new this().fromWIF(wif);\n }\n /**\n * fromCashaddr - create a watch-only wallet in the network derived from the address\n *\n * such kind of wallet does not have a private key and is unable to spend any funds\n * however it still allows to use many utility functions such as getting and watching balance, etc.\n *\n * @param address cashaddress of a wallet\n *\n * @returns instantiated wallet\n */\n static async fromCashaddr(address) {\n const prefix = (0,_util_derivePublicKeyHash_js__WEBPACK_IMPORTED_MODULE_12__.derivePrefix)(address);\n const networkType = _enum_js__WEBPACK_IMPORTED_MODULE_4__.networkPrefixMap[prefix];\n return new this(\"\", networkType, _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Watch).watchOnly(address);\n }\n /**\n * fromTokenaddr - create a watch-only wallet in the network derived from the address\n *\n * such kind of wallet does not have a private key and is unable to spend any funds\n * however it still allows to use many utility functions such as getting and watching balance, etc.\n *\n * @param address token aware cashaddress of a wallet\n *\n * @returns instantiated wallet\n */\n static async fromTokenaddr(address) {\n const prefix = (0,_util_derivePublicKeyHash_js__WEBPACK_IMPORTED_MODULE_12__.derivePrefix)(address);\n const networkType = _enum_js__WEBPACK_IMPORTED_MODULE_4__.networkPrefixMap[prefix];\n return new this(\"\", networkType, _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Watch).watchOnly(address);\n }\n /**\n * fromSlpaddr - create an SLP aware watch-only wallet in the network derived from the address\n *\n * such kind of wallet does not have a private key and is unable to spend any funds\n * however it still allows to use many utility functions such as getting and watching balance, etc.\n *\n * @param address slpaddress of a wallet\n *\n * @returns instantiated wallet\n */\n static async fromSlpaddr(address) {\n return this.fromCashaddr((0,_util_bchaddr_js__WEBPACK_IMPORTED_MODULE_13__.toCashAddress)(address));\n }\n //#endregion Constructors and Statics\n //#region Protected implementations\n async generate() {\n if (this.walletType === _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Wif) {\n return await this._generateWif();\n }\n else if (this.walletType === _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Watch) {\n return this;\n }\n else if (this.walletType === _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Hd) {\n throw Error(\"Not implemented\");\n }\n else if (this.walletType === _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Seed) {\n return await this._generateMnemonic();\n }\n else {\n console.log(this.walletType);\n throw Error(`Could not determine walletType: ${this.walletType}`);\n }\n }\n async _generateWif() {\n if (!this.privateKey) {\n this.privateKey = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_14__.generatePrivateKey)(() => (0,_util_randomBytes_js__WEBPACK_IMPORTED_MODULE_15__.generateRandomBytes)(32));\n }\n return this.deriveInfo();\n }\n async _generateMnemonic() {\n this.mnemonic = (0,bip39__WEBPACK_IMPORTED_MODULE_0__.generateMnemonic)();\n if (this.mnemonic.length == 0)\n throw Error(\"refusing to create wallet from empty mnemonic\");\n let seed = (0,bip39__WEBPACK_IMPORTED_MODULE_0__.mnemonicToSeedSync)(this.mnemonic);\n (0,_util_checkForEmptySeed_js__WEBPACK_IMPORTED_MODULE_16__.checkForEmptySeed)(seed);\n let network = this.isTestnet ? \"testnet\" : \"mainnet\";\n this.parentXPubKey = await (0,_util_getXPubKey_js__WEBPACK_IMPORTED_MODULE_17__.getXPubKey)(seed, this.parentDerivationPath, network);\n let hdNode = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_18__.deriveHdPrivateNodeFromSeed)(seed);\n if (!hdNode.valid) {\n throw Error(\"Invalid private key derived from mnemonic seed\");\n }\n let zerothChild = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_18__.deriveHdPath)(hdNode, this.derivationPath);\n if (typeof zerothChild === \"string\") {\n throw Error(zerothChild);\n }\n this.privateKey = zerothChild.privateKey;\n this.walletType = _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Seed;\n return await this.deriveInfo();\n }\n async getXPubKeys(paths) {\n if (this.mnemonic) {\n if (paths) {\n let xPubKeys = await this.deriveHdPaths(paths);\n return [xPubKeys];\n }\n else {\n return await this.deriveHdPaths(_constant_js__WEBPACK_IMPORTED_MODULE_19__.DERIVATION_PATHS);\n }\n }\n else {\n throw Error(\"xpubkeys can only be derived from seed type wallets.\");\n }\n }\n // Initialize wallet from a mnemonic phrase\n async fromSeed(mnemonic, derivationPath) {\n this.mnemonic = mnemonic;\n if (this.mnemonic.length == 0)\n throw Error(\"refusing to create wallet from empty mnemonic\");\n let seed = (0,bip39__WEBPACK_IMPORTED_MODULE_0__.mnemonicToSeedSync)(this.mnemonic);\n (0,_util_checkForEmptySeed_js__WEBPACK_IMPORTED_MODULE_16__.checkForEmptySeed)(seed);\n let hdNode = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_18__.deriveHdPrivateNodeFromSeed)(seed);\n if (!hdNode.valid) {\n throw Error(\"Invalid private key derived from mnemonic seed\");\n }\n if (derivationPath) {\n this.derivationPath = derivationPath;\n // If the derivation path is for the first account child, set the parent derivation path\n let path = derivationPath.split(\"/\");\n if (path.slice(-2).join(\"/\") == \"0/0\") {\n this.parentDerivationPath = path.slice(0, -2).join(\"/\");\n }\n }\n let zerothChild = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_18__.deriveHdPath)(hdNode, this.derivationPath);\n if (typeof zerothChild === \"string\") {\n throw Error(zerothChild);\n }\n this.privateKey = zerothChild.privateKey;\n let network = this.isTestnet ? \"testnet\" : \"mainnet\";\n this.parentXPubKey = await (0,_util_getXPubKey_js__WEBPACK_IMPORTED_MODULE_17__.getXPubKey)(seed, this.parentDerivationPath, network);\n this.walletType = _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Seed;\n await this.deriveInfo();\n return this;\n }\n // Get common xpub paths from zerothChild privateKey\n async deriveHdPaths(hdPaths) {\n if (!this.mnemonic)\n throw Error(\"refusing to create wallet from empty mnemonic\");\n let seed = (0,bip39__WEBPACK_IMPORTED_MODULE_0__.mnemonicToSeedSync)(this.mnemonic);\n (0,_util_checkForEmptySeed_js__WEBPACK_IMPORTED_MODULE_16__.checkForEmptySeed)(seed);\n let hdNode = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_18__.deriveHdPrivateNodeFromSeed)(seed);\n if (!hdNode.valid) {\n throw Error(\"Invalid private key derived from mnemonic seed\");\n }\n let result = [];\n for (const path of hdPaths) {\n if (path === \"m\") {\n throw Error(\"Storing or sharing of parent public key may lead to loss of funds. Storing or sharing *root* parent public keys is strongly discouraged, although all parent keys have risk. See: https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#implications\");\n }\n let childNode = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_18__.deriveHdPath)(hdNode, path);\n if (typeof childNode === \"string\") {\n throw Error(childNode);\n }\n let node = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_18__.deriveHdPublicNode)(childNode);\n if (typeof node === \"string\") {\n throw Error(node);\n }\n let xPubKey = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_18__.encodeHdPublicKey)({\n network: this.network,\n node: node,\n });\n let key = new _model_js__WEBPACK_IMPORTED_MODULE_20__.XPubKey({\n path: path,\n xPubKey: xPubKey,\n });\n result.push(await key.ready());\n }\n return await Promise.all(result).then((result) => {\n return result;\n });\n }\n // Initialize a watch only wallet from a cash addr\n async watchOnly(address) {\n this.walletType = _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Watch;\n let addressComponents = address.split(\":\");\n let addressPrefix, addressBase;\n if (addressComponents.length === 1) {\n addressBase = addressComponents.shift();\n addressPrefix = (0,_util_derivePublicKeyHash_js__WEBPACK_IMPORTED_MODULE_12__.derivePrefix)(addressBase);\n }\n else {\n addressPrefix = addressComponents.shift();\n addressBase = addressComponents.shift();\n if (addressPrefix in _enum_js__WEBPACK_IMPORTED_MODULE_4__.networkPrefixMap) {\n if (_enum_js__WEBPACK_IMPORTED_MODULE_4__.networkPrefixMap[addressPrefix] != this.network) {\n throw Error(`a ${addressPrefix} address cannot be watched from a ${this.network} Wallet`);\n }\n }\n }\n this.cashaddr = `${addressPrefix}:${addressBase}`;\n this.address = this.cashaddr;\n this.publicKeyHash = (0,_util_derivePublicKeyHash_js__WEBPACK_IMPORTED_MODULE_12__.derivePublicKeyHash)(this.cashaddr);\n this.tokenaddr = (0,_util_deriveCashaddr_js__WEBPACK_IMPORTED_MODULE_21__.deriveTokenaddr)(this.publicKeyHash, this.networkPrefix);\n return this;\n }\n // Initialize wallet from Wallet Import Format\n async fromWIF(secret) {\n (0,_util_checkWifNetwork_js__WEBPACK_IMPORTED_MODULE_22__.checkWifNetwork)(secret, this.network);\n let wifResult = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_23__.decodePrivateKeyWif)(secret);\n if (typeof wifResult === \"string\") {\n throw Error(wifResult);\n }\n let resultData = wifResult;\n this.privateKey = resultData.privateKey;\n this.privateKeyWif = secret;\n this.walletType = _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Wif;\n await this.deriveInfo();\n return this;\n }\n async newRandom(name, dbName) {\n dbName = dbName ? dbName : this.networkPrefix;\n return super.newRandom(name, dbName);\n }\n async named(name, dbName, forceNew = false) {\n dbName = dbName ? dbName : this.networkPrefix;\n return super.named(name, dbName, forceNew);\n }\n async replaceNamed(name, walletId, dbName) {\n dbName = dbName ? dbName : this.networkPrefix;\n return super.replaceNamed(name, walletId, dbName);\n }\n async namedExists(name, dbName) {\n dbName = dbName ? dbName : this.networkPrefix;\n return super.namedExists(name, dbName);\n }\n //#endregion Protected Implementations\n //#region Serialization\n // Returns the serialized wallet as a string\n // If storing in a database, set asNamed to false to store secrets\n // In all other cases, the a named wallet is deserialized from the database\n // by the name key\n toString() {\n const result = super.toString();\n if (result)\n return result;\n if (this.walletType === _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Wif) {\n return `${this.walletType}:${this.network}:${this.privateKeyWif}`;\n }\n throw Error(\"toString unsupported wallet type\");\n }\n //\n toDbString() {\n const result = super.toDbString();\n if (result)\n return result;\n if (this.walletType === _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Wif) {\n return `${this.walletType}:${this.network}:${this.privateKeyWif}`;\n }\n throw Error(\"toDbString unsupported wallet type\");\n }\n //#endregion Serialization\n //#region Funds\n //\n async getAddressUtxos(address) {\n if (!address) {\n address = this.cashaddr;\n }\n if (this._slpAware) {\n const [bchUtxos, slpOutpoints] = await Promise.all([\n this.provider.getUtxos(address),\n this.slp.getSlpOutpoints(),\n ]);\n return bchUtxos.filter((bchutxo) => slpOutpoints.findIndex((slpOutpoint) => `${bchutxo.txid}:${bchutxo.vout}` === slpOutpoint) === -1);\n }\n else if (this._slpSemiAware) {\n const bchUtxos = await this.provider.getUtxos(address);\n return bchUtxos.filter((bchutxo) => bchutxo.satoshis > _constant_js__WEBPACK_IMPORTED_MODULE_19__.DUST_UTXO_THRESHOLD);\n }\n else {\n return await this.provider.getUtxos(address);\n }\n }\n /**\n * utxos Get unspent outputs for the wallet\n *\n */\n async getUtxos() {\n if (!this.cashaddr) {\n throw Error(\"Attempted to get utxos without an address\");\n }\n let utxos = await this.getAddressUtxos(this.cashaddr);\n let resp = new _model_js__WEBPACK_IMPORTED_MODULE_20__.UtxoResponse();\n resp.utxos = await Promise.all(utxos.map(async (o) => {\n return _model_js__WEBPACK_IMPORTED_MODULE_20__.UtxoItem.fromElectrum(o);\n }));\n return resp;\n }\n // gets wallet balance in sats, bch and usd\n async getBalance(rawUnit, usdPriceCache = true) {\n if (rawUnit) {\n const unit = (0,_util_sanitizeUnit_js__WEBPACK_IMPORTED_MODULE_24__.sanitizeUnit)(rawUnit);\n return await (0,_util_balanceObjectFromSatoshi_js__WEBPACK_IMPORTED_MODULE_25__.balanceFromSatoshi)(await this.getBalanceFromProvider(), unit, usdPriceCache);\n }\n else {\n return await (0,_util_balanceObjectFromSatoshi_js__WEBPACK_IMPORTED_MODULE_25__.balanceResponseFromSatoshi)(await this.getBalanceFromProvider(), usdPriceCache);\n }\n }\n // Gets balance by summing value in all utxos in stats\n async getBalanceFromUtxos() {\n const utxos = (await this.getAddressUtxos(this.cashaddr)).filter((val) => val.token === undefined);\n return (0,_util_sumUtxoValue_js__WEBPACK_IMPORTED_MODULE_26__.sumUtxoValue)(utxos);\n }\n // Gets balance from fulcrum\n async getBalanceFromProvider() {\n // Fulcrum reports balance of all utxos, including tokens, which is undesirable\n // // TODO not sure why getting the balance from a provider doesn't work\n // if (this._slpAware || this._slpSemiAware) {\n // return await this.getBalanceFromUtxos();\n // } else {\n // return await this.provider!.getBalance(this.cashaddr!);\n // }\n // FIXME\n return this.getBalanceFromUtxos();\n }\n // // waiting for any transaction hash of this wallet\n // // commented out until fulcrum supports new method https://github.com/cculianu/Fulcrum/pull/89\n // public watchAddress(callback: (txHash: string) => void): CancelWatchFn {\n // return (this.provider! as ElectrumNetworkProvider).watchAddress(\n // this.getDepositAddress(),\n // callback\n // );\n // }\n // // waiting for any transaction of this wallet\n // // commented out until fulcrum supports new method https://github.com/cculianu/Fulcrum/pull/89\n // public watchAddressTransactions(\n // callback: (tx: ElectrumRawTransaction) => void\n // ): CancelWatchFn {\n // return (this.provider! as ElectrumNetworkProvider).watchAddressTransactions(\n // this.getDepositAddress(),\n // callback\n // );\n // }\n // sets up a callback to be called upon wallet's balance change\n // can be cancelled by calling the function returned from this one\n watchBalance(callback) {\n return this.provider.watchAddressStatus(this.getDepositAddress(), async (_status) => {\n const balance = (await this.getBalance());\n callback(balance);\n });\n }\n // sets up a callback to be called upon wallet's BCH or USD balance change\n // if BCH balance does not change, the callback will be triggered every\n // @param `usdPriceRefreshInterval` milliseconds by polling for new BCH USD price\n // Since we want to be most sensitive to usd value change, we do not use the cached exchange rates\n // can be cancelled by calling the function returned from this one\n watchBalanceUsd(callback, usdPriceRefreshInterval = 30000) {\n let usdPrice = -1;\n const _callback = async () => {\n const balance = (await this.getBalance(undefined, false));\n if (usdPrice !== balance.usd) {\n usdPrice = balance.usd;\n callback(balance);\n }\n };\n const watchCancel = this.provider.watchAddressStatus(this.getDepositAddress(), _callback);\n const interval = setInterval(_callback, usdPriceRefreshInterval);\n return async () => {\n await watchCancel();\n clearInterval(interval);\n };\n }\n // waits for address balance to be greater than or equal to the target value\n // this call halts the execution\n async waitForBalance(value, rawUnit = _enum_js__WEBPACK_IMPORTED_MODULE_4__.UnitEnum.BCH) {\n return new Promise(async (resolve) => {\n const watchCancel = this.watchBalance(async (balance) => {\n const satoshiBalance = await (0,_util_amountInSatoshi_js__WEBPACK_IMPORTED_MODULE_27__.amountInSatoshi)(value, rawUnit);\n if (balance.sat >= satoshiBalance) {\n await watchCancel();\n resolve(balance);\n }\n });\n });\n }\n // sets up a callback to be called upon wallet's token balance change\n // can be cancelled by calling the function returned from this one\n watchTokenBalance(tokenId, callback) {\n let previous = undefined;\n return this.provider.watchAddressStatus(this.getDepositAddress(), async (_status) => {\n const balance = await this.getTokenBalance(tokenId);\n if (previous != balance) {\n callback(balance);\n }\n previous = balance;\n });\n }\n // waits for address token balance to be greater than or equal to the target amount\n // this call halts the execution\n async waitForTokenBalance(tokenId, amount) {\n return new Promise(async (resolve) => {\n const watchCancel = this.watchTokenBalance(tokenId, async (balance) => {\n if (balance >= amount) {\n await watchCancel();\n resolve(balance);\n }\n });\n });\n }\n async getTokenInfo(tokenId) {\n return _Bcmr_js__WEBPACK_IMPORTED_MODULE_28__.BCMR.getTokenInfo(tokenId);\n }\n async _getMaxAmountToSend(params = {\n outputCount: 1,\n options: {},\n }) {\n if (!this.privateKey) {\n throw Error(\"Couldn't get network or private key for wallet.\");\n }\n if (!this.cashaddr) {\n throw Error(\"attempted to send without a cashaddr\");\n }\n if (params.options && params.options.slpAware) {\n this._slpAware = true;\n }\n if (params.options && params.options.slpSemiAware) {\n this._slpSemiAware = true;\n }\n let feePaidBy;\n if (params.options && params.options.feePaidBy) {\n feePaidBy = params.options.feePaidBy;\n }\n else {\n feePaidBy = _enum_js__WEBPACK_IMPORTED_MODULE_5__.FeePaidByEnum.change;\n }\n // get inputs\n let utxos;\n if (params.options && params.options.utxoIds) {\n utxos = params.options.utxoIds.map((utxoId) => _model_js__WEBPACK_IMPORTED_MODULE_20__.UtxoItem.fromId(utxoId).asElectrum());\n }\n else {\n utxos = (await this.getAddressUtxos(this.cashaddr)).filter((utxo) => !utxo.token);\n }\n // Get current height to assure recently mined coins are not spent.\n const bestHeight = await this.provider.getBlockHeight();\n // simulate outputs using the sender's address\n const sendRequest = new _model_js__WEBPACK_IMPORTED_MODULE_20__.SendRequest({\n cashaddr: this.cashaddr,\n value: 100,\n unit: \"sat\",\n });\n const sendRequests = Array(params.outputCount)\n .fill(0)\n .map(() => sendRequest);\n const fundingUtxos = await (0,_transaction_Wif_js__WEBPACK_IMPORTED_MODULE_29__.getSuitableUtxos)(utxos, undefined, bestHeight, feePaidBy, sendRequests);\n const relayFeePerByteInSatoshi = await (0,_network_getRelayFeeCache_js__WEBPACK_IMPORTED_MODULE_1__.getRelayFeeCache)(this.provider);\n const fee = await (0,_transaction_Wif_js__WEBPACK_IMPORTED_MODULE_29__.getFeeAmount)({\n utxos: fundingUtxos,\n sendRequests: sendRequests,\n privateKey: this.privateKey,\n relayFeePerByteInSatoshi: relayFeePerByteInSatoshi,\n slpOutputs: [],\n feePaidBy: feePaidBy,\n });\n const spendableAmount = (0,_util_sumUtxoValue_js__WEBPACK_IMPORTED_MODULE_26__.sumUtxoValue)(fundingUtxos);\n let result = spendableAmount - fee;\n if (result < 0) {\n result = 0;\n }\n return { value: result, utxos: fundingUtxos };\n }\n async getMaxAmountToSend(params = {\n outputCount: 1,\n options: {},\n }) {\n const { value: result } = await this._getMaxAmountToSend(params);\n return await (0,_util_balanceObjectFromSatoshi_js__WEBPACK_IMPORTED_MODULE_25__.balanceResponseFromSatoshi)(result);\n }\n /**\n * send Send some amount to an address\n * this function processes the send requests, encodes the transaction, sends it to the network\n * @returns (depending on the options parameter) the transaction id, new address balance and a link to the transaction on the blockchain explorer\n *\n * This is a first class function with REST analog, maintainers should strive to keep backward-compatibility\n *\n */\n async send(requests, options) {\n let { encodedTransaction, tokenIds } = await this.encodeTransaction(requests, undefined, options);\n const awaitTransactionPropagation = !options ||\n options.awaitTransactionPropagation === undefined ||\n options.awaitTransactionPropagation;\n const txId = await this.submitTransaction(encodedTransaction, awaitTransactionPropagation);\n let resp = new _model_js__WEBPACK_IMPORTED_MODULE_20__.SendResponse({});\n resp.txId = txId;\n const queryBalance = !options || options.queryBalance === undefined || options.queryBalance;\n if (queryBalance) {\n resp.balance = (await this.getBalance());\n }\n resp.explorerUrl = this.explorerUrl(resp.txId);\n resp.tokenIds = tokenIds;\n return resp;\n }\n /**\n * sendMax Send all available funds to a destination cash address\n *\n * @param {string} cashaddr destination cash address\n * @param {SendRequestOptionsI} options Options of the send requests\n *\n * @returns (depending on the options parameter) the transaction id, new address balance and a link to the transaction on the blockchain explorer\n */\n async sendMax(cashaddr, options) {\n const txId = await this.sendMaxRaw(cashaddr, options);\n const queryBalance = !options || options.queryBalance === undefined || options.queryBalance;\n return {\n txId: txId,\n balance: queryBalance\n ? (await this.getBalance())\n : undefined,\n explorerUrl: this.explorerUrl(txId),\n };\n }\n /**\n * sendMaxRaw (internal) Send all available funds to a destination cash address\n *\n * @param {string} cashaddr destination cash address\n * @param {SendRequestOptionsI} options Options of the send requests\n *\n * @returns the transaction id sent to the network\n */\n async sendMaxRaw(cashaddr, options) {\n let { value: maxSpendableAmount, utxos } = await this._getMaxAmountToSend({\n outputCount: 1,\n options: options,\n });\n if (!options) {\n options = {};\n }\n options.utxoIds = utxos;\n let sendRequest = new _model_js__WEBPACK_IMPORTED_MODULE_20__.SendRequest({\n cashaddr: cashaddr,\n value: maxSpendableAmount,\n unit: \"sat\",\n });\n const { encodedTransaction } = await this.encodeTransaction([sendRequest], true, options);\n const awaitTransactionPropagation = !options ||\n options.awaitTransactionPropagation === undefined ||\n options.awaitTransactionPropagation;\n const txId = await this.submitTransaction(encodedTransaction, awaitTransactionPropagation);\n return txId;\n }\n /**\n * encodeTransaction Encode and sign a transaction given a list of sendRequests, options and estimate fees.\n * @param {SendRequest[]} sendRequests SendRequests\n * @param {boolean} discardChange=false\n * @param {SendRequestOptionsI} options Options of the send requests\n */\n async encodeTransaction(requests, discardChange = false, options) {\n let sendRequests = (0,_util_asSendRequestObject_js__WEBPACK_IMPORTED_MODULE_30__.asSendRequestObject)(requests);\n if (!this.privateKey) {\n throw new Error(`Wallet ${this.name} is missing either a network or private key`);\n }\n if (!this.cashaddr) {\n throw Error(\"attempted to send without a cashaddr\");\n }\n if (options && options.slpAware) {\n this._slpAware = true;\n }\n if (options && options.slpSemiAware) {\n this._slpSemiAware = true;\n }\n let feePaidBy;\n if (options && options.feePaidBy) {\n feePaidBy = options.feePaidBy;\n }\n else {\n feePaidBy = _enum_js__WEBPACK_IMPORTED_MODULE_5__.FeePaidByEnum.change;\n }\n let changeAddress;\n if (options && options.changeAddress) {\n changeAddress = options.changeAddress;\n }\n else {\n changeAddress = \"\";\n }\n let checkTokenQuantities = true;\n if (options && options.checkTokenQuantities === false) {\n checkTokenQuantities = false;\n }\n // get inputs from options or query all inputs\n let utxos;\n if (options && options.utxoIds) {\n utxos = options.utxoIds.map((utxoId) => typeof utxoId === \"string\"\n ? _model_js__WEBPACK_IMPORTED_MODULE_20__.UtxoItem.fromId(utxoId).asElectrum()\n : utxoId);\n }\n else {\n utxos = await this.getAddressUtxos(this.cashaddr);\n }\n const addTokenChangeOutputs = (inputs, outputs) => {\n // allow for implicit token burn if the total amount sent is less than user had\n // allow for token genesis, creating more tokens than we had before (0)\n if (!checkTokenQuantities) {\n return;\n }\n const allTokenInputs = inputs.filter((val) => val.token);\n const allTokenOutputs = outputs.filter((val) => val instanceof _model_js__WEBPACK_IMPORTED_MODULE_20__.TokenSendRequest);\n const tokenIds = allTokenOutputs\n .map((val) => val.tokenId)\n .filter((val, idx, arr) => arr.indexOf(val) === idx);\n for (let tokenId of tokenIds) {\n const tokenInputs = allTokenInputs.filter((val) => val.token?.tokenId === tokenId);\n const inputAmountSum = tokenInputs.reduce((prev, cur) => prev + cur.token.amount, 0);\n const tokenOutputs = allTokenOutputs.filter((val) => val.tokenId === tokenId);\n const outputAmountSum = tokenOutputs.reduce((prev, cur) => prev + cur.amount, 0);\n const change = inputAmountSum - outputAmountSum;\n if (change < 0) {\n throw new Error(\"Not enough token amount to send\");\n }\n if (change > 0) {\n outputs.push(new _model_js__WEBPACK_IMPORTED_MODULE_20__.TokenSendRequest({\n cashaddr: changeAddress || this.cashaddr,\n amount: change,\n tokenId: tokenId,\n commitment: tokenOutputs[0].commitment,\n capability: tokenOutputs[0].capability,\n value: tokenOutputs[0].value,\n }));\n }\n }\n };\n addTokenChangeOutputs(utxos, sendRequests);\n const bestHeight = await this.provider.getBlockHeight();\n const spendAmount = await (0,_util_sumSendRequestAmounts_js__WEBPACK_IMPORTED_MODULE_31__.sumSendRequestAmounts)(sendRequests);\n if (utxos.length === 0) {\n throw Error(\"There were no Unspent Outputs\");\n }\n if (typeof spendAmount !== \"bigint\") {\n throw Error(\"Couldn't get spend amount when building transaction\");\n }\n const relayFeePerByteInSatoshi = await (0,_network_getRelayFeeCache_js__WEBPACK_IMPORTED_MODULE_1__.getRelayFeeCache)(this.provider);\n const feeEstimate = await (0,_transaction_Wif_js__WEBPACK_IMPORTED_MODULE_29__.getFeeAmount)({\n utxos: utxos,\n sendRequests: sendRequests,\n privateKey: this.privateKey,\n relayFeePerByteInSatoshi: relayFeePerByteInSatoshi,\n slpOutputs: [],\n feePaidBy: feePaidBy,\n });\n const fundingUtxos = await (0,_transaction_Wif_js__WEBPACK_IMPORTED_MODULE_29__.getSuitableUtxos)(utxos, BigInt(spendAmount) + BigInt(feeEstimate), bestHeight, feePaidBy, sendRequests);\n if (fundingUtxos.length === 0) {\n throw Error(\"The available inputs couldn't satisfy the request with fees\");\n }\n const fee = await (0,_transaction_Wif_js__WEBPACK_IMPORTED_MODULE_29__.getFeeAmount)({\n utxos: fundingUtxos,\n sendRequests: sendRequests,\n privateKey: this.privateKey,\n relayFeePerByteInSatoshi: relayFeePerByteInSatoshi,\n slpOutputs: [],\n feePaidBy: feePaidBy,\n });\n const encodedTransaction = await (0,_transaction_Wif_js__WEBPACK_IMPORTED_MODULE_29__.buildEncodedTransaction)(fundingUtxos, sendRequests, this.privateKey, fee, discardChange, [], feePaidBy, changeAddress);\n const tokenIds = [\n ...fundingUtxos\n .filter((val) => val.token?.tokenId)\n .map((val) => val.token.tokenId),\n ...sendRequests\n .filter((val) => val instanceof _model_js__WEBPACK_IMPORTED_MODULE_20__.TokenSendRequest)\n .map((val) => val.tokenId),\n ].filter((value, index, array) => array.indexOf(value) === index);\n return { encodedTransaction, tokenIds: tokenIds };\n }\n // Submit a raw transaction\n async submitTransaction(transaction, awaitPropagation = true) {\n if (!this.provider) {\n throw Error(\"Wallet network provider was not initialized\");\n }\n let rawTransaction = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_11__.binToHex)(transaction);\n return await this.provider.sendRawTransaction(rawTransaction, awaitPropagation);\n }\n // gets transaction history of this wallet\n async getRawHistory() {\n return await this.provider.getHistory(this.cashaddr);\n }\n // gets transaction history of this wallet\n async getHistory(unit, start, count, collapseChange) {\n return (0,_history_electrumTransformer_js__WEBPACK_IMPORTED_MODULE_32__.getAddressHistory)(this.cashaddr, this.provider, unit, start, count, collapseChange);\n }\n // gets last transaction of this wallet\n async getLastTransaction(confirmedOnly = false) {\n let history = await this.getRawHistory();\n if (confirmedOnly) {\n history = history.filter((val) => val.height > 0);\n }\n if (!history.length) {\n return null;\n }\n const [lastTx] = history.slice(-1);\n return this.provider.getRawTransactionObject(lastTx.tx_hash);\n }\n // waits for next transaction, program execution is halted\n async waitForTransaction(options = {\n getTransactionInfo: true,\n getBalance: false,\n txHash: undefined,\n }) {\n if (options.getTransactionInfo === undefined) {\n options.getTransactionInfo = true;\n }\n return new Promise(async (resolve) => {\n let txHashSeen = false;\n const makeResponse = async (txHash) => {\n const response = {};\n const promises = [undefined, undefined];\n if (options.getBalance === true) {\n promises[0] = this.getBalance();\n }\n if (options.getTransactionInfo === true) {\n if (!txHash) {\n promises[1] = this.getLastTransaction();\n }\n else {\n promises[1] = this.provider.getRawTransactionObject(txHash);\n }\n }\n const result = await Promise.all(promises);\n response.balance = result[0];\n response.transactionInfo = result[1];\n return response;\n };\n // waiting for a specific transaction to propagate\n if (options.txHash) {\n const waitForTransactionCallback = async (data) => {\n if (data && data[0] === options.txHash) {\n txHashSeen = true;\n this.provider.unsubscribeFromTransaction(options.txHash, waitForTransactionCallback);\n resolve(makeResponse(options.txHash));\n }\n };\n this.provider.subscribeToTransaction(options.txHash, waitForTransactionCallback);\n return;\n }\n // waiting for any address transaction\n const watchCancel = this.provider.watchAddressStatus(this.getDepositAddress(), async (_status) => {\n watchCancel();\n resolve(makeResponse());\n });\n });\n }\n /**\n * watchBlocks Watch network blocks\n *\n * @param callback callback with a block header object\n *\n * @returns a function which will cancel watching upon evaluation\n */\n watchBlocks(callback) {\n return this.provider.watchBlocks(callback);\n }\n /**\n * waitForBlock Wait for a network block\n *\n * @param height if specified waits for this exact blockchain height, otherwise resolves with the next block\n *\n */\n async waitForBlock(height) {\n return this.provider.waitForBlock(height);\n }\n //#endregion Funds\n //#region Private implementation details\n async deriveInfo() {\n const publicKey = _bitauth_libauth__WEBPACK_IMPORTED_MODULE_33__.secp256k1.derivePublicKeyUncompressed(this.privateKey);\n if (typeof publicKey === \"string\") {\n throw new Error(publicKey);\n }\n this.publicKey = publicKey;\n const publicKeyCompressed = _bitauth_libauth__WEBPACK_IMPORTED_MODULE_33__.secp256k1.derivePublicKeyCompressed(this.privateKey);\n if (typeof publicKeyCompressed === \"string\") {\n throw new Error(publicKeyCompressed);\n }\n this.publicKeyCompressed = publicKeyCompressed;\n const networkType = this.network === _enum_js__WEBPACK_IMPORTED_MODULE_4__.NetworkType.Regtest ? _enum_js__WEBPACK_IMPORTED_MODULE_4__.NetworkType.Testnet : this.network;\n this.privateKeyWif = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_23__.encodePrivateKeyWif)(this.privateKey, networkType);\n (0,_util_checkWifNetwork_js__WEBPACK_IMPORTED_MODULE_22__.checkWifNetwork)(this.privateKeyWif, this.network);\n this.cashaddr = (0,_util_deriveCashaddr_js__WEBPACK_IMPORTED_MODULE_21__.deriveCashaddr)(this.privateKey, this.networkPrefix);\n this.tokenaddr = (0,_util_deriveCashaddr_js__WEBPACK_IMPORTED_MODULE_21__.deriveTokenaddr)(this.privateKey, this.networkPrefix);\n this.address = this.cashaddr;\n this.publicKeyHash = (0,_util_derivePublicKeyHash_js__WEBPACK_IMPORTED_MODULE_12__.derivePublicKeyHash)(this.cashaddr);\n return this;\n }\n //#endregion Private implementation details\n //#region Signing\n // Convenience wrapper to sign interface\n async sign(message) {\n return await Wallet.signedMessage.sign(message, this.privateKey);\n }\n // Convenience wrapper to verify interface\n async verify(message, sig, publicKey) {\n return await Wallet.signedMessage.verify(message, sig, this.cashaddr, publicKey);\n }\n //#endregion Signing\n //#region Cashtokens\n /**\n * Create new cashtoken, both funglible and/or non-fungible (NFT)\n * Refer to spec https://github.com/bitjson/cashtokens\n * @param {number} genesisRequest.amount amount of *fungible* tokens to create\n * @param {NFTCapability?} genesisRequest.capability capability of new NFT\n * @param {string?} genesisRequest.commitment NFT commitment message\n * @param {string?} genesisRequest.cashaddr cash address to send the created token UTXO to; if undefined will default to your address\n * @param {number?} genesisRequest.value satoshi value to send alongside with tokens; if undefined will default to 1000 satoshi\n */\n async tokenGenesis(genesisRequest) {\n return this.send(new _model_js__WEBPACK_IMPORTED_MODULE_20__.TokenSendRequest({\n cashaddr: genesisRequest.cashaddr || this.cashaddr,\n amount: genesisRequest.amount,\n value: genesisRequest.value,\n capability: genesisRequest.capability,\n commitment: genesisRequest.commitment,\n tokenId: \"\",\n }), {\n checkTokenQuantities: false,\n queryBalance: false,\n });\n }\n /**\n * Mint new NFT cashtokens using an existing minting token\n * Refer to spec https://github.com/bitjson/cashtokens\n * @param {string} tokenId tokenId of an NFT to mint\n * @param {TokenMintRequest | TokenMintRequest[]} mintRequests mint requests with new token properties and recipients\n * @param {NFTCapability?} mintRequest.capability capability of new NFT\n * @param {string?} mintRequest.commitment NFT commitment message\n * @param {string?} mintRequest.cashaddr cash address to send the created token UTXO to; if undefined will default to your address\n * @param {number?} mintRequest.value satoshi value to send alongside with tokens; if undefined will default to 1000 satoshi\n * @param {boolean?} deductTokenAmount if minting token contains fungible amount, deduct from it by amount of minted tokens\n */\n async tokenMint(tokenId, mintRequests, deductTokenAmount = false) {\n if (!Array.isArray(mintRequests)) {\n mintRequests = [mintRequests];\n }\n const utxos = await this.getAddressUtxos(this.cashaddr);\n const nftUtxos = utxos.filter((val) => val.token?.tokenId === tokenId &&\n val.token?.capability != _interface_js__WEBPACK_IMPORTED_MODULE_8__.NFTCapability.none);\n if (!nftUtxos.length) {\n throw new Error(\"You do not have any token UTXOs with minting capability for specified tokenId\");\n }\n const newAmount = deductTokenAmount && nftUtxos[0].token.amount > 0\n ? nftUtxos[0].token.amount - mintRequests.length\n : nftUtxos[0].token.amount;\n const safeNewAmount = Math.max(0, newAmount);\n const mintingInput = new _model_js__WEBPACK_IMPORTED_MODULE_20__.TokenSendRequest({\n cashaddr: this.cashaddr,\n tokenId: tokenId,\n capability: nftUtxos[0].token.capability,\n commitment: nftUtxos[0].token.commitment,\n amount: safeNewAmount,\n value: nftUtxos[0].satoshis,\n });\n return this.send([\n mintingInput,\n ...mintRequests.map((val) => new _model_js__WEBPACK_IMPORTED_MODULE_20__.TokenSendRequest({\n cashaddr: val.cashaddr || this.cashaddr,\n amount: 0,\n tokenId: tokenId,\n value: val.value,\n capability: val.capability,\n commitment: val.commitment,\n })),\n ], {\n checkTokenQuantities: false,\n queryBalance: false,\n });\n }\n /**\n * Perform an explicit token burning by spending a token utxo to an OP_RETURN\n *\n * Behaves differently for fungible and non-fungible tokens:\n * * NFTs are always \"destroyed\"\n * * FTs' amount is reduced by the amount specified, if 0 FT amount is left and no NFT present, the token is \"destroyed\"\n *\n * Refer to spec https://github.com/bitjson/cashtokens\n * @param {string} burnRequest.tokenId tokenId of a token to burn\n * @param {NFTCapability} burnRequest.capability capability of the NFT token to select, optional\n * @param {string?} burnRequest.commitment commitment of the NFT token to select, optional\n * @param {number?} burnRequest.amount amount of fungible tokens to burn, optional\n * @param {string?} burnRequest.cashaddr address to return token and satoshi change to\n * @param {string?} message optional message to include in OP_RETURN\n */\n async tokenBurn(burnRequest, message) {\n const utxos = await this.getAddressUtxos(this.cashaddr);\n const tokenUtxos = utxos.filter((val) => val.token?.tokenId === burnRequest.tokenId &&\n val.token?.capability === burnRequest.capability &&\n val.token?.commitment === burnRequest.commitment &&\n val.token?.capability === burnRequest.capability);\n if (!tokenUtxos.length) {\n throw new Error(\"You do not have suitable token UTXOs to perform burn\");\n }\n const totalFungibleAmount = tokenUtxos.reduce((prev, cur) => prev + (cur.token?.amount || 0), 0);\n const fungibleBurnAmount = burnRequest.amount && burnRequest.amount > 0 ? burnRequest.amount : 0;\n const hasNFT = burnRequest.capability || burnRequest.commitment;\n let utxoIds = [];\n let changeSendRequests;\n if (hasNFT) {\n // does not have FT tokens, let us destroy the token completely\n if (totalFungibleAmount === 0) {\n changeSendRequests = [];\n utxoIds.push(tokenUtxos[0]);\n }\n else {\n // if there are FT, reduce their amount\n const newAmount = totalFungibleAmount - fungibleBurnAmount;\n const safeNewAmount = Math.max(0, newAmount);\n changeSendRequests = [\n new _model_js__WEBPACK_IMPORTED_MODULE_20__.TokenSendRequest({\n cashaddr: burnRequest.cashaddr || this.cashaddr,\n tokenId: burnRequest.tokenId,\n capability: burnRequest.capability,\n commitment: burnRequest.commitment,\n amount: safeNewAmount,\n value: tokenUtxos[0].satoshis,\n }),\n ];\n }\n }\n else {\n // if we are burning last fughible tokens, let us destroy the token completely\n if (totalFungibleAmount === fungibleBurnAmount) {\n changeSendRequests = [];\n utxoIds.push(tokenUtxos[0]);\n }\n else {\n // reduce the FT amount\n const newAmount = totalFungibleAmount - fungibleBurnAmount;\n const safeNewAmount = Math.max(0, newAmount);\n changeSendRequests = [\n new _model_js__WEBPACK_IMPORTED_MODULE_20__.TokenSendRequest({\n cashaddr: burnRequest.cashaddr || this.cashaddr,\n tokenId: burnRequest.tokenId,\n amount: safeNewAmount,\n value: tokenUtxos[0].satoshis,\n }),\n ];\n }\n }\n const opReturn = _model_js__WEBPACK_IMPORTED_MODULE_20__.OpReturnData.fromString(message || \"\");\n return this.send([opReturn, ...changeSendRequests], {\n checkTokenQuantities: false,\n queryBalance: false,\n utxoIds: utxoIds.length > 0 ? utxoIds : undefined,\n });\n }\n /**\n * getTokenUtxos Get unspent token outputs for the wallet\n * will return utxos only for the specified token if `tokenId` provided\n * @param {string?} tokenId tokenId (category) to filter utxos by, if not set will return utxos from all tokens\n * @returns {UtxoI[]} token utxos\n */\n async getTokenUtxos(tokenId) {\n const utxos = await this.getAddressUtxos(this.address);\n return utxos.filter((val) => tokenId ? val.token?.tokenId === tokenId : val.token);\n }\n /**\n * getTokenBalance Gets fungible token balance\n * for NFT token balance see @ref getNftTokenBalance\n * @param {string} tokenId tokenId to get balance for\n * @returns {number} fungible token balance\n */\n async getTokenBalance(tokenId) {\n const utxos = await this.getAddressUtxos(this.cashaddr);\n return (0,_util_sumUtxoValue_js__WEBPACK_IMPORTED_MODULE_26__.sumTokenAmounts)(utxos, tokenId);\n }\n /**\n * getNftTokenBalance Gets non-fungible token (NFT) balance for a particula tokenId\n * disregards fungible token balances\n * for fungible token balance see @ref getTokenBalance\n * @param {string} tokenId tokenId to get balance for\n * @returns {number} non-fungible token balance\n */\n async getNftTokenBalance(tokenId) {\n const utxos = await this.getTokenUtxos(tokenId);\n return utxos.length;\n }\n /**\n * getAllTokenBalances Gets all fungible token balances in this wallet\n * @returns {Object} a map [tokenId => balance] for all tokens in this wallet\n */\n async getAllTokenBalances() {\n const result = {};\n const utxos = await this.getTokenUtxos();\n for (const utxo of utxos) {\n if (!result[utxo.token.tokenId]) {\n result[utxo.token.tokenId] = 0;\n }\n result[utxo.token.tokenId] += utxo.token.amount;\n }\n return result;\n }\n /**\n * getAllNftTokenBalances Gets all non-fungible token (NFT) balances in this wallet\n * @returns {Object} a map [tokenId => balance] for all NFTs in this wallet\n */\n async getAllNftTokenBalances() {\n const result = {};\n const utxos = await this.getTokenUtxos();\n for (const utxo of utxos) {\n if (!result[utxo.token.tokenId]) {\n result[utxo.token.tokenId] = 0;\n }\n result[utxo.token.tokenId] += 1;\n }\n return result;\n }\n}\nWallet.signedMessage = new _message_index_js__WEBPACK_IMPORTED_MODULE_34__.SignedMessage();\n/**\n * Class to manage a testnet wallet.\n */\nclass TestNetWallet extends Wallet {\n constructor(name = \"\") {\n super(name, _enum_js__WEBPACK_IMPORTED_MODULE_4__.NetworkType.Testnet);\n }\n // will receive 10000 testnet satoshi, rate limits apply\n async getTestnetSatoshis() {\n try {\n const response = await axios__WEBPACK_IMPORTED_MODULE_2___default().post(`${TestNetWallet.faucetServer}/faucet/get_testnet_bch`, { cashaddr: this.cashaddr });\n const data = response.data;\n return data.txId;\n }\n catch (e) {\n // console.log(e);\n // console.log(e.response ? e.response.data : \"\");\n throw e;\n }\n }\n // be nice and return them back\n async returnTestnetSatoshis() {\n try {\n const response = await axios__WEBPACK_IMPORTED_MODULE_2___default().post(`${TestNetWallet.faucetServer}/faucet/get_addresses`);\n const data = response.data;\n return await this.slpAware().sendMax(data.bchtest);\n }\n catch (e) {\n console.log(e);\n console.log(e.response ? e.response.data : \"\");\n throw e;\n }\n }\n // will receive 10 testnet tokens, rate limits apply\n async getTestnetSlp(tokenId) {\n try {\n const response = await axios__WEBPACK_IMPORTED_MODULE_2___default().post(`${TestNetWallet.faucetServer}/faucet/get_testnet_slp`, { slpaddr: this.slp.slpaddr, tokenId: tokenId });\n const data = response.data;\n return data.txId;\n }\n catch (e) {\n //console.log(e);\n //console.log(e.response ? e.response.data : \"\");\n throw e;\n }\n }\n // be nice and return them back\n async returnTestnetSlp(tokenId) {\n try {\n const response = await axios__WEBPACK_IMPORTED_MODULE_2___default().post(`${TestNetWallet.faucetServer}/faucet/get_addresses`);\n const data = response.data;\n return await this.slp.sendMax(data.slptest, tokenId);\n }\n catch (e) {\n console.log(e);\n console.log(e.response ? e.response.data : \"\");\n throw e;\n }\n }\n // interface to static slp functions. see Slp.ts\n static get slp() {\n return _Slp_js__WEBPACK_IMPORTED_MODULE_6__.TestNetSlp;\n }\n // interface to static util functions. see Util.ts\n static get util() {\n return _Util_js__WEBPACK_IMPORTED_MODULE_7__.TestNetUtil;\n }\n}\nTestNetWallet.networkPrefix = _bitauth_libauth__WEBPACK_IMPORTED_MODULE_35__.CashAddressNetworkPrefix.testnet;\nTestNetWallet.faucetServer = \"https://rest-unstable.mainnet.cash\";\n/**\n * Class to manage a regtest wallet.\n */\nclass RegTestWallet extends Wallet {\n constructor(name = \"\") {\n super(name, _enum_js__WEBPACK_IMPORTED_MODULE_4__.NetworkType.Regtest);\n }\n // interface to static slp functions. see Slp.ts\n static get slp() {\n return _Slp_js__WEBPACK_IMPORTED_MODULE_6__.RegTestSlp;\n }\n // interface to static util functions. see Util.ts\n static get util() {\n return _Util_js__WEBPACK_IMPORTED_MODULE_7__.RegTestUtil;\n }\n}\nRegTestWallet.networkPrefix = _bitauth_libauth__WEBPACK_IMPORTED_MODULE_35__.CashAddressNetworkPrefix.regtest;\n/**\n * Class to manage a bitcoin cash wif wallet.\n */\nclass WifWallet extends Wallet {\n constructor(name = \"\") {\n super(name, _enum_js__WEBPACK_IMPORTED_MODULE_4__.NetworkType.Mainnet, _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Wif);\n }\n // interface to static slp functions. see Slp.ts\n static get slp() {\n return _Slp_js__WEBPACK_IMPORTED_MODULE_6__.WifSlp;\n }\n // interface to static util functions. see Util.ts\n static get util() {\n return _Util_js__WEBPACK_IMPORTED_MODULE_7__.WifUtil;\n }\n}\nWifWallet.networkPrefix = _bitauth_libauth__WEBPACK_IMPORTED_MODULE_35__.CashAddressNetworkPrefix.mainnet;\nWifWallet.walletType = _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Wif;\n/**\n * Class to manage a testnet wif wallet.\n */\nclass TestNetWifWallet extends Wallet {\n constructor(name = \"\") {\n super(name, _enum_js__WEBPACK_IMPORTED_MODULE_4__.NetworkType.Testnet, _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Wif);\n }\n // interface to static slp functions. see Slp.ts\n static get slp() {\n return _Slp_js__WEBPACK_IMPORTED_MODULE_6__.TestNetWifSlp;\n }\n // interface to static util functions. see Util.ts\n static get util() {\n return _Util_js__WEBPACK_IMPORTED_MODULE_7__.TestNetWifUtil;\n }\n}\nTestNetWifWallet.networkPrefix = _bitauth_libauth__WEBPACK_IMPORTED_MODULE_35__.CashAddressNetworkPrefix.testnet;\nTestNetWifWallet.walletType = _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Wif;\n/**\n * Class to manage a regtest wif wallet.\n */\nclass RegTestWifWallet extends Wallet {\n constructor(name = \"\") {\n super(name, _enum_js__WEBPACK_IMPORTED_MODULE_4__.NetworkType.Regtest, _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Wif);\n }\n // interface to static slp functions. see Slp.ts\n static get slp() {\n return _Slp_js__WEBPACK_IMPORTED_MODULE_6__.RegTestWifSlp;\n }\n // interface to static util functions. see Util.ts\n static get util() {\n return _Util_js__WEBPACK_IMPORTED_MODULE_7__.RegTestWifUtil;\n }\n}\nRegTestWifWallet.networkPrefix = _bitauth_libauth__WEBPACK_IMPORTED_MODULE_35__.CashAddressNetworkPrefix.regtest;\nRegTestWifWallet.walletType = _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Wif;\n/**\n * Class to manage a bitcoin cash watch wallet.\n */\nclass WatchWallet extends Wallet {\n constructor(name = \"\") {\n super(name, _enum_js__WEBPACK_IMPORTED_MODULE_4__.NetworkType.Mainnet, _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Watch);\n }\n // interface to static slp functions. see Slp.ts\n static get slp() {\n return _Slp_js__WEBPACK_IMPORTED_MODULE_6__.WatchSlp;\n }\n // interface to static util functions. see Util.ts\n static get util() {\n return _Util_js__WEBPACK_IMPORTED_MODULE_7__.WatchUtil;\n }\n}\nWatchWallet.networkPrefix = _bitauth_libauth__WEBPACK_IMPORTED_MODULE_35__.CashAddressNetworkPrefix.mainnet;\nWatchWallet.walletType = _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Watch;\n/**\n * Class to manage a testnet watch wallet.\n */\nclass TestNetWatchWallet extends Wallet {\n constructor(name = \"\") {\n super(name, _enum_js__WEBPACK_IMPORTED_MODULE_4__.NetworkType.Testnet, _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Watch);\n }\n // interface to static slp functions. see Slp.ts\n static get slp() {\n return _Slp_js__WEBPACK_IMPORTED_MODULE_6__.TestNetWatchSlp;\n }\n // interface to static util functions. see Util.ts\n static get util() {\n return _Util_js__WEBPACK_IMPORTED_MODULE_7__.TestNetWatchUtil;\n }\n}\nTestNetWatchWallet.networkPrefix = _bitauth_libauth__WEBPACK_IMPORTED_MODULE_35__.CashAddressNetworkPrefix.testnet;\nTestNetWatchWallet.walletType = _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Watch;\n/**\n * Class to manage a regtest watch wallet.\n */\nclass RegTestWatchWallet extends Wallet {\n constructor(name = \"\") {\n super(name, _enum_js__WEBPACK_IMPORTED_MODULE_4__.NetworkType.Regtest, _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Watch);\n }\n // interface to static slp functions. see Slp.ts\n static get slp() {\n return _Slp_js__WEBPACK_IMPORTED_MODULE_6__.RegTestWatchSlp;\n }\n // interface to static util functions. see Util.ts\n static get util() {\n return _Util_js__WEBPACK_IMPORTED_MODULE_7__.RegTestWatchUtil;\n }\n}\nRegTestWatchWallet.networkPrefix = _bitauth_libauth__WEBPACK_IMPORTED_MODULE_35__.CashAddressNetworkPrefix.regtest;\nRegTestWatchWallet.walletType = _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Watch;\n\n__webpack_async_result__();\n} catch(e) { __webpack_async_result__(e); } });\n\n//# sourceURL=webpack://mainnet-js/./src/wallet/Wif.ts?");
|
|
1667
|
+
eval("__webpack_require__.a(module, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"RegTestWallet\": () => (/* binding */ RegTestWallet),\n/* harmony export */ \"RegTestWatchWallet\": () => (/* binding */ RegTestWatchWallet),\n/* harmony export */ \"RegTestWifWallet\": () => (/* binding */ RegTestWifWallet),\n/* harmony export */ \"TestNetWallet\": () => (/* binding */ TestNetWallet),\n/* harmony export */ \"TestNetWatchWallet\": () => (/* binding */ TestNetWatchWallet),\n/* harmony export */ \"TestNetWifWallet\": () => (/* binding */ TestNetWifWallet),\n/* harmony export */ \"Wallet\": () => (/* binding */ Wallet),\n/* harmony export */ \"WatchWallet\": () => (/* binding */ WatchWallet),\n/* harmony export */ \"WifWallet\": () => (/* binding */ WifWallet)\n/* harmony export */ });\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/key/hd-key.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_33__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/crypto/default-crypto-instances.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/format/hex.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/key/key-utils.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_23__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/key/wallet-import-format.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_35__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/address/cash-address.js\");\n/* harmony import */ var bip39__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! bip39 */ \"../../node_modules/bip39/src/index.js\");\n/* harmony import */ var _enum_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../enum.js */ \"./src/enum.ts\");\n/* harmony import */ var _interface_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../interface.js */ \"./src/interface.ts\");\n/* harmony import */ var _Base_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Base.js */ \"./src/wallet/Base.ts\");\n/* harmony import */ var _enum_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./enum.js */ \"./src/wallet/enum.ts\");\n/* harmony import */ var _model_js__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(/*! ./model.js */ \"./src/wallet/model.ts\");\n/* harmony import */ var _transaction_Wif_js__WEBPACK_IMPORTED_MODULE_29__ = __webpack_require__(/*! ../transaction/Wif.js */ \"./src/transaction/Wif.ts\");\n/* harmony import */ var _util_asSendRequestObject_js__WEBPACK_IMPORTED_MODULE_30__ = __webpack_require__(/*! ../util/asSendRequestObject.js */ \"./src/util/asSendRequestObject.ts\");\n/* harmony import */ var _util_balanceObjectFromSatoshi_js__WEBPACK_IMPORTED_MODULE_25__ = __webpack_require__(/*! ../util/balanceObjectFromSatoshi.js */ \"./src/util/balanceObjectFromSatoshi.ts\");\n/* harmony import */ var _util_checkWifNetwork_js__WEBPACK_IMPORTED_MODULE_22__ = __webpack_require__(/*! ../util/checkWifNetwork.js */ \"./src/util/checkWifNetwork.ts\");\n/* harmony import */ var _util_deriveCashaddr_js__WEBPACK_IMPORTED_MODULE_21__ = __webpack_require__(/*! ../util/deriveCashaddr.js */ \"./src/util/deriveCashaddr.ts\");\n/* harmony import */ var _util_derivePublicKeyHash_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ../util/derivePublicKeyHash.js */ \"./src/util/derivePublicKeyHash.ts\");\n/* harmony import */ var _util_checkForEmptySeed_js__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ../util/checkForEmptySeed.js */ \"./src/util/checkForEmptySeed.ts\");\n/* harmony import */ var _util_sanitizeUnit_js__WEBPACK_IMPORTED_MODULE_24__ = __webpack_require__(/*! ../util/sanitizeUnit.js */ \"./src/util/sanitizeUnit.ts\");\n/* harmony import */ var _util_sumUtxoValue_js__WEBPACK_IMPORTED_MODULE_26__ = __webpack_require__(/*! ../util/sumUtxoValue.js */ \"./src/util/sumUtxoValue.ts\");\n/* harmony import */ var _util_sumSendRequestAmounts_js__WEBPACK_IMPORTED_MODULE_31__ = __webpack_require__(/*! ../util/sumSendRequestAmounts.js */ \"./src/util/sumSendRequestAmounts.ts\");\n/* harmony import */ var _network_getRelayFeeCache_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../network/getRelayFeeCache.js */ \"./src/network/getRelayFeeCache.ts\");\n/* harmony import */ var _Slp_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./Slp.js */ \"./src/wallet/Slp.ts\");\n/* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! axios */ \"../../node_modules/axios/index.js\");\n/* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(axios__WEBPACK_IMPORTED_MODULE_2__);\n/* harmony import */ var _util_bchaddr_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ../util/bchaddr.js */ \"../../node_modules/bchaddrjs-slp/src/bchaddr.js\");\n/* harmony import */ var _util_bchaddr_js__WEBPACK_IMPORTED_MODULE_13___default = /*#__PURE__*/__webpack_require__.n(_util_bchaddr_js__WEBPACK_IMPORTED_MODULE_13__);\n/* harmony import */ var _Util_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./Util.js */ \"./src/wallet/Util.ts\");\n/* harmony import */ var _network_index_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../network/index.js */ \"./src/network/default.ts\");\n/* harmony import */ var _util_randomBytes_js__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ../util/randomBytes.js */ \"./src/util/randomBytes.ts\");\n/* harmony import */ var _message_index_js__WEBPACK_IMPORTED_MODULE_34__ = __webpack_require__(/*! ../message/index.js */ \"./src/message/signed.ts\");\n/* harmony import */ var _util_amountInSatoshi_js__WEBPACK_IMPORTED_MODULE_27__ = __webpack_require__(/*! ../util/amountInSatoshi.js */ \"./src/util/amountInSatoshi.ts\");\n/* harmony import */ var _util_getXPubKey_js__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ../util/getXPubKey.js */ \"./src/util/getXPubKey.ts\");\n/* harmony import */ var _constant_js__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! ../constant.js */ \"./src/constant.ts\");\n/* harmony import */ var _history_electrumTransformer_js__WEBPACK_IMPORTED_MODULE_32__ = __webpack_require__(/*! ../history/electrumTransformer.js */ \"./src/history/electrumTransformer.ts\");\n/* harmony import */ var _Bcmr_js__WEBPACK_IMPORTED_MODULE_28__ = __webpack_require__(/*! ./Bcmr.js */ \"./src/wallet/Bcmr.ts\");\n/* harmony import */ var _qr_Qr_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../qr/Qr.js */ \"./src/qr/Qr.ts\");\nvar __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_Base_js__WEBPACK_IMPORTED_MODULE_3__, _enum_js__WEBPACK_IMPORTED_MODULE_4__, _Slp_js__WEBPACK_IMPORTED_MODULE_6__, _Util_js__WEBPACK_IMPORTED_MODULE_7__, _network_index_js__WEBPACK_IMPORTED_MODULE_9__, _qr_Qr_js__WEBPACK_IMPORTED_MODULE_10__, _util_derivePublicKeyHash_js__WEBPACK_IMPORTED_MODULE_12__, _util_checkForEmptySeed_js__WEBPACK_IMPORTED_MODULE_16__, _util_getXPubKey_js__WEBPACK_IMPORTED_MODULE_17__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_18__, _model_js__WEBPACK_IMPORTED_MODULE_20__, _util_deriveCashaddr_js__WEBPACK_IMPORTED_MODULE_21__, _util_checkWifNetwork_js__WEBPACK_IMPORTED_MODULE_22__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_23__, _util_balanceObjectFromSatoshi_js__WEBPACK_IMPORTED_MODULE_25__, _util_amountInSatoshi_js__WEBPACK_IMPORTED_MODULE_27__, _Bcmr_js__WEBPACK_IMPORTED_MODULE_28__, _transaction_Wif_js__WEBPACK_IMPORTED_MODULE_29__, _util_asSendRequestObject_js__WEBPACK_IMPORTED_MODULE_30__, _util_sumSendRequestAmounts_js__WEBPACK_IMPORTED_MODULE_31__, _history_electrumTransformer_js__WEBPACK_IMPORTED_MODULE_32__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_33__, _message_index_js__WEBPACK_IMPORTED_MODULE_34__]);\n([_Base_js__WEBPACK_IMPORTED_MODULE_3__, _enum_js__WEBPACK_IMPORTED_MODULE_4__, _Slp_js__WEBPACK_IMPORTED_MODULE_6__, _Util_js__WEBPACK_IMPORTED_MODULE_7__, _network_index_js__WEBPACK_IMPORTED_MODULE_9__, _qr_Qr_js__WEBPACK_IMPORTED_MODULE_10__, _util_derivePublicKeyHash_js__WEBPACK_IMPORTED_MODULE_12__, _util_checkForEmptySeed_js__WEBPACK_IMPORTED_MODULE_16__, _util_getXPubKey_js__WEBPACK_IMPORTED_MODULE_17__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_18__, _model_js__WEBPACK_IMPORTED_MODULE_20__, _util_deriveCashaddr_js__WEBPACK_IMPORTED_MODULE_21__, _util_checkWifNetwork_js__WEBPACK_IMPORTED_MODULE_22__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_23__, _util_balanceObjectFromSatoshi_js__WEBPACK_IMPORTED_MODULE_25__, _util_amountInSatoshi_js__WEBPACK_IMPORTED_MODULE_27__, _Bcmr_js__WEBPACK_IMPORTED_MODULE_28__, _transaction_Wif_js__WEBPACK_IMPORTED_MODULE_29__, _util_asSendRequestObject_js__WEBPACK_IMPORTED_MODULE_30__, _util_sumSendRequestAmounts_js__WEBPACK_IMPORTED_MODULE_31__, _history_electrumTransformer_js__WEBPACK_IMPORTED_MODULE_32__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_33__, _message_index_js__WEBPACK_IMPORTED_MODULE_34__] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);\n//#region Imports\n// Stable\n\n// Unstable?\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n//#endregion Imports\n/**\n * Class to manage a bitcoin cash wallet.\n */\nclass Wallet extends _Base_js__WEBPACK_IMPORTED_MODULE_3__.BaseWallet {\n //#endregion\n //#region Constructors and Statics\n constructor(name = \"\", network = _enum_js__WEBPACK_IMPORTED_MODULE_4__.NetworkType.Mainnet, walletType = _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Seed) {\n super(name, network, walletType);\n this.derivationPath = \"m/44'/0'/0'/0/0\";\n this.parentDerivationPath = \"m/44'/0'/0'\";\n this._slpAware = false; // a flag which activates utxo checking against an external slp indexer\n this._slpSemiAware = false; // a flag which requires an utxo to have more than 546 sats to be spendable and counted in the balance\n this.fromId = async (walletId) => {\n let [walletType, networkGiven, arg1] = walletId.split(\":\");\n if (this.network != networkGiven) {\n throw Error(`Network prefix ${networkGiven} to a ${this.network} wallet`);\n }\n // \"wif:regtest:cNfsPtqN2bMRS7vH5qd8tR8GMvgXyL5BjnGAKgZ8DYEiCrCCQcP6\"\n if (walletType === \"wif\") {\n return this.fromWIF(arg1);\n }\n return super.fromId(walletId);\n };\n this.networkPrefix = _enum_js__WEBPACK_IMPORTED_MODULE_4__.prefixFromNetworkMap[this.network];\n }\n //#region Accessors\n // interface to slp functions. see Slp.ts\n get slp() {\n if (!this._slp) {\n this._slp = new _Slp_js__WEBPACK_IMPORTED_MODULE_6__.Slp(this);\n this._slpAware = true;\n }\n return this._slp;\n }\n // interface to slp functions. see Slp.ts\n static get slp() {\n return _Slp_js__WEBPACK_IMPORTED_MODULE_6__.Slp;\n }\n // interface to util functions. see Util.ts\n get util() {\n if (!this._util) {\n this._util = new _Util_js__WEBPACK_IMPORTED_MODULE_7__.Util(this);\n }\n return this._util;\n }\n // interface to util util. see Util.Util\n static get util() {\n return _Util_js__WEBPACK_IMPORTED_MODULE_7__.Util;\n }\n slpAware(value = true) {\n this._slpAware = value;\n return this;\n }\n slpSemiAware(value = true) {\n this._slpSemiAware = value;\n return this;\n }\n getNetworkProvider(network = _interface_js__WEBPACK_IMPORTED_MODULE_8__.Network.MAINNET) {\n return (0,_network_index_js__WEBPACK_IMPORTED_MODULE_9__.getNetworkProvider)(network);\n }\n /**\n * getTokenDepositAddress - get a cashtoken aware wallet deposit address\n *\n * @returns The cashtoken aware deposit address as a string\n */\n getTokenDepositAddress() {\n return this.tokenaddr;\n }\n /**\n * getDepositQr - get an address qrcode, encoded for display on the web\n *\n * @returns The qrcode for the token aware address\n */\n getTokenDepositQr() {\n return (0,_qr_Qr_js__WEBPACK_IMPORTED_MODULE_10__.qrAddress)(this.getTokenDepositAddress());\n }\n /**\n * explorerUrl Web url to a transaction on a block explorer\n *\n * @param txId transaction Id\n * @returns Url string\n */\n explorerUrl(txId) {\n const explorerUrlMap = {\n mainnet: \"https://blockchair.com/bitcoin-cash/transaction/\",\n testnet: \"https://www.blockchain.com/bch-testnet/tx/\",\n regtest: \"\",\n };\n return explorerUrlMap[this.network] + txId;\n }\n // Return wallet info\n getInfo() {\n return {\n cashaddr: this.cashaddr,\n tokenaddr: this.tokenaddr,\n isTestnet: this.isTestnet,\n name: this.name,\n network: this.network,\n seed: this.mnemonic ? this.getSeed().seed : undefined,\n derivationPath: this.mnemonic ? this.getSeed().derivationPath : undefined,\n parentDerivationPath: this.mnemonic\n ? this.getSeed().parentDerivationPath\n : undefined,\n parentXPubKey: this.parentXPubKey ? this.parentXPubKey : undefined,\n publicKey: this.publicKey ? (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_11__.binToHex)(this.publicKey) : undefined,\n publicKeyHash: (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_11__.binToHex)(this.publicKeyHash),\n privateKey: this.privateKey ? (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_11__.binToHex)(this.privateKey) : undefined,\n privateKeyWif: this.privateKeyWif,\n walletId: this.toString(),\n walletDbEntry: this.toDbString(),\n };\n }\n // returns the public key hash for an address\n getPublicKey(hex = false) {\n if (this.publicKey) {\n return hex ? (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_11__.binToHex)(this.publicKey) : this.publicKey;\n }\n else {\n throw Error(\"The public key for this wallet is not known, perhaps the wallet was created to watch the *hash* of a public key? i.e. a cashaddress.\");\n }\n }\n // returns the public key hash for an address\n getPublicKeyCompressed(hex = false) {\n if (this.publicKeyCompressed) {\n return hex\n ? (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_11__.binToHex)(this.publicKeyCompressed)\n : this.publicKeyCompressed;\n }\n else {\n throw Error(\"The compressed public key for this wallet is not known, perhaps the wallet was created to watch the *hash* of a public key? i.e. a cashaddress.\");\n }\n }\n // returns the public key hash for an address\n getPublicKeyHash(hex = false) {\n if (this.publicKeyHash) {\n return hex ? (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_11__.binToHex)(this.publicKeyHash) : this.publicKeyHash;\n }\n else {\n throw Error(\"The public key hash for this wallet is not known. If this wallet was created from the constructor directly, calling the deriveInfo() function may help. \");\n }\n }\n /**\n * fromWIF - create a wallet using the private key supplied in `Wallet Import Format`\n *\n * @param wif WIF encoded private key string\n *\n * @returns instantiated wallet\n */\n static async fromWIF(wif) {\n return new this().fromWIF(wif);\n }\n /**\n * fromCashaddr - create a watch-only wallet in the network derived from the address\n *\n * such kind of wallet does not have a private key and is unable to spend any funds\n * however it still allows to use many utility functions such as getting and watching balance, etc.\n *\n * @param address cashaddress of a wallet\n *\n * @returns instantiated wallet\n */\n static async fromCashaddr(address) {\n const prefix = (0,_util_derivePublicKeyHash_js__WEBPACK_IMPORTED_MODULE_12__.derivePrefix)(address);\n const networkType = _enum_js__WEBPACK_IMPORTED_MODULE_4__.networkPrefixMap[prefix];\n return new this(\"\", networkType, _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Watch).watchOnly(address);\n }\n /**\n * fromTokenaddr - create a watch-only wallet in the network derived from the address\n *\n * such kind of wallet does not have a private key and is unable to spend any funds\n * however it still allows to use many utility functions such as getting and watching balance, etc.\n *\n * @param address token aware cashaddress of a wallet\n *\n * @returns instantiated wallet\n */\n static async fromTokenaddr(address) {\n const prefix = (0,_util_derivePublicKeyHash_js__WEBPACK_IMPORTED_MODULE_12__.derivePrefix)(address);\n const networkType = _enum_js__WEBPACK_IMPORTED_MODULE_4__.networkPrefixMap[prefix];\n return new this(\"\", networkType, _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Watch).watchOnly(address);\n }\n /**\n * fromSlpaddr - create an SLP aware watch-only wallet in the network derived from the address\n *\n * such kind of wallet does not have a private key and is unable to spend any funds\n * however it still allows to use many utility functions such as getting and watching balance, etc.\n *\n * @param address slpaddress of a wallet\n *\n * @returns instantiated wallet\n */\n static async fromSlpaddr(address) {\n return this.fromCashaddr((0,_util_bchaddr_js__WEBPACK_IMPORTED_MODULE_13__.toCashAddress)(address));\n }\n //#endregion Constructors and Statics\n //#region Protected implementations\n async generate() {\n if (this.walletType === _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Wif) {\n return await this._generateWif();\n }\n else if (this.walletType === _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Watch) {\n return this;\n }\n else if (this.walletType === _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Hd) {\n throw Error(\"Not implemented\");\n }\n else if (this.walletType === _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Seed) {\n return await this._generateMnemonic();\n }\n else {\n console.log(this.walletType);\n throw Error(`Could not determine walletType: ${this.walletType}`);\n }\n }\n async _generateWif() {\n if (!this.privateKey) {\n this.privateKey = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_14__.generatePrivateKey)(() => (0,_util_randomBytes_js__WEBPACK_IMPORTED_MODULE_15__.generateRandomBytes)(32));\n }\n return this.deriveInfo();\n }\n async _generateMnemonic() {\n this.mnemonic = (0,bip39__WEBPACK_IMPORTED_MODULE_0__.generateMnemonic)();\n if (this.mnemonic.length == 0)\n throw Error(\"refusing to create wallet from empty mnemonic\");\n let seed = (0,bip39__WEBPACK_IMPORTED_MODULE_0__.mnemonicToSeedSync)(this.mnemonic);\n (0,_util_checkForEmptySeed_js__WEBPACK_IMPORTED_MODULE_16__.checkForEmptySeed)(seed);\n let network = this.isTestnet ? \"testnet\" : \"mainnet\";\n this.parentXPubKey = await (0,_util_getXPubKey_js__WEBPACK_IMPORTED_MODULE_17__.getXPubKey)(seed, this.parentDerivationPath, network);\n let hdNode = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_18__.deriveHdPrivateNodeFromSeed)(seed);\n if (!hdNode.valid) {\n throw Error(\"Invalid private key derived from mnemonic seed\");\n }\n let zerothChild = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_18__.deriveHdPath)(hdNode, this.derivationPath);\n if (typeof zerothChild === \"string\") {\n throw Error(zerothChild);\n }\n this.privateKey = zerothChild.privateKey;\n this.walletType = _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Seed;\n return await this.deriveInfo();\n }\n async getXPubKeys(paths) {\n if (this.mnemonic) {\n if (paths) {\n let xPubKeys = await this.deriveHdPaths(paths);\n return [xPubKeys];\n }\n else {\n return await this.deriveHdPaths(_constant_js__WEBPACK_IMPORTED_MODULE_19__.DERIVATION_PATHS);\n }\n }\n else {\n throw Error(\"xpubkeys can only be derived from seed type wallets.\");\n }\n }\n // Initialize wallet from a mnemonic phrase\n async fromSeed(mnemonic, derivationPath) {\n this.mnemonic = mnemonic;\n if (this.mnemonic.length == 0)\n throw Error(\"refusing to create wallet from empty mnemonic\");\n let seed = (0,bip39__WEBPACK_IMPORTED_MODULE_0__.mnemonicToSeedSync)(this.mnemonic);\n (0,_util_checkForEmptySeed_js__WEBPACK_IMPORTED_MODULE_16__.checkForEmptySeed)(seed);\n let hdNode = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_18__.deriveHdPrivateNodeFromSeed)(seed);\n if (!hdNode.valid) {\n throw Error(\"Invalid private key derived from mnemonic seed\");\n }\n if (derivationPath) {\n this.derivationPath = derivationPath;\n // If the derivation path is for the first account child, set the parent derivation path\n let path = derivationPath.split(\"/\");\n if (path.slice(-2).join(\"/\") == \"0/0\") {\n this.parentDerivationPath = path.slice(0, -2).join(\"/\");\n }\n }\n let zerothChild = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_18__.deriveHdPath)(hdNode, this.derivationPath);\n if (typeof zerothChild === \"string\") {\n throw Error(zerothChild);\n }\n this.privateKey = zerothChild.privateKey;\n let network = this.isTestnet ? \"testnet\" : \"mainnet\";\n this.parentXPubKey = await (0,_util_getXPubKey_js__WEBPACK_IMPORTED_MODULE_17__.getXPubKey)(seed, this.parentDerivationPath, network);\n this.walletType = _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Seed;\n await this.deriveInfo();\n return this;\n }\n // Get common xpub paths from zerothChild privateKey\n async deriveHdPaths(hdPaths) {\n if (!this.mnemonic)\n throw Error(\"refusing to create wallet from empty mnemonic\");\n let seed = (0,bip39__WEBPACK_IMPORTED_MODULE_0__.mnemonicToSeedSync)(this.mnemonic);\n (0,_util_checkForEmptySeed_js__WEBPACK_IMPORTED_MODULE_16__.checkForEmptySeed)(seed);\n let hdNode = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_18__.deriveHdPrivateNodeFromSeed)(seed);\n if (!hdNode.valid) {\n throw Error(\"Invalid private key derived from mnemonic seed\");\n }\n let result = [];\n for (const path of hdPaths) {\n if (path === \"m\") {\n throw Error(\"Storing or sharing of parent public key may lead to loss of funds. Storing or sharing *root* parent public keys is strongly discouraged, although all parent keys have risk. See: https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#implications\");\n }\n let childNode = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_18__.deriveHdPath)(hdNode, path);\n if (typeof childNode === \"string\") {\n throw Error(childNode);\n }\n let node = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_18__.deriveHdPublicNode)(childNode);\n if (typeof node === \"string\") {\n throw Error(node);\n }\n let xPubKey = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_18__.encodeHdPublicKey)({\n network: this.network,\n node: node,\n });\n let key = new _model_js__WEBPACK_IMPORTED_MODULE_20__.XPubKey({\n path: path,\n xPubKey: xPubKey,\n });\n result.push(await key.ready());\n }\n return await Promise.all(result).then((result) => {\n return result;\n });\n }\n // Initialize a watch only wallet from a cash addr\n async watchOnly(address) {\n this.walletType = _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Watch;\n let addressComponents = address.split(\":\");\n let addressPrefix, addressBase;\n if (addressComponents.length === 1) {\n addressBase = addressComponents.shift();\n addressPrefix = (0,_util_derivePublicKeyHash_js__WEBPACK_IMPORTED_MODULE_12__.derivePrefix)(addressBase);\n }\n else {\n addressPrefix = addressComponents.shift();\n addressBase = addressComponents.shift();\n if (addressPrefix in _enum_js__WEBPACK_IMPORTED_MODULE_4__.networkPrefixMap) {\n if (_enum_js__WEBPACK_IMPORTED_MODULE_4__.networkPrefixMap[addressPrefix] != this.network) {\n throw Error(`a ${addressPrefix} address cannot be watched from a ${this.network} Wallet`);\n }\n }\n }\n this.cashaddr = `${addressPrefix}:${addressBase}`;\n this.address = this.cashaddr;\n this.publicKeyHash = (0,_util_derivePublicKeyHash_js__WEBPACK_IMPORTED_MODULE_12__.derivePublicKeyHash)(this.cashaddr);\n this.tokenaddr = (0,_util_deriveCashaddr_js__WEBPACK_IMPORTED_MODULE_21__.deriveTokenaddr)(this.publicKeyHash, this.networkPrefix);\n return this;\n }\n // Initialize wallet from Wallet Import Format\n async fromWIF(secret) {\n (0,_util_checkWifNetwork_js__WEBPACK_IMPORTED_MODULE_22__.checkWifNetwork)(secret, this.network);\n let wifResult = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_23__.decodePrivateKeyWif)(secret);\n if (typeof wifResult === \"string\") {\n throw Error(wifResult);\n }\n let resultData = wifResult;\n this.privateKey = resultData.privateKey;\n this.privateKeyWif = secret;\n this.walletType = _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Wif;\n await this.deriveInfo();\n return this;\n }\n async newRandom(name, dbName) {\n dbName = dbName ? dbName : this.networkPrefix;\n return super.newRandom(name, dbName);\n }\n async named(name, dbName, forceNew = false) {\n dbName = dbName ? dbName : this.networkPrefix;\n return super.named(name, dbName, forceNew);\n }\n async replaceNamed(name, walletId, dbName) {\n dbName = dbName ? dbName : this.networkPrefix;\n return super.replaceNamed(name, walletId, dbName);\n }\n async namedExists(name, dbName) {\n dbName = dbName ? dbName : this.networkPrefix;\n return super.namedExists(name, dbName);\n }\n //#endregion Protected Implementations\n //#region Serialization\n // Returns the serialized wallet as a string\n // If storing in a database, set asNamed to false to store secrets\n // In all other cases, the a named wallet is deserialized from the database\n // by the name key\n toString() {\n const result = super.toString();\n if (result)\n return result;\n if (this.walletType === _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Wif) {\n return `${this.walletType}:${this.network}:${this.privateKeyWif}`;\n }\n throw Error(\"toString unsupported wallet type\");\n }\n //\n toDbString() {\n const result = super.toDbString();\n if (result)\n return result;\n if (this.walletType === _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Wif) {\n return `${this.walletType}:${this.network}:${this.privateKeyWif}`;\n }\n throw Error(\"toDbString unsupported wallet type\");\n }\n //#endregion Serialization\n //#region Funds\n //\n async getAddressUtxos(address) {\n if (!address) {\n address = this.cashaddr;\n }\n if (this._slpAware) {\n const [bchUtxos, slpOutpoints] = await Promise.all([\n this.provider.getUtxos(address),\n this.slp.getSlpOutpoints(),\n ]);\n return bchUtxos.filter((bchutxo) => slpOutpoints.findIndex((slpOutpoint) => `${bchutxo.txid}:${bchutxo.vout}` === slpOutpoint) === -1);\n }\n else if (this._slpSemiAware) {\n const bchUtxos = await this.provider.getUtxos(address);\n return bchUtxos.filter((bchutxo) => bchutxo.satoshis > _constant_js__WEBPACK_IMPORTED_MODULE_19__.DUST_UTXO_THRESHOLD);\n }\n else {\n return await this.provider.getUtxos(address);\n }\n }\n /**\n * utxos Get unspent outputs for the wallet\n *\n */\n async getUtxos() {\n if (!this.cashaddr) {\n throw Error(\"Attempted to get utxos without an address\");\n }\n let utxos = await this.getAddressUtxos(this.cashaddr);\n let resp = new _model_js__WEBPACK_IMPORTED_MODULE_20__.UtxoResponse();\n resp.utxos = await Promise.all(utxos.map(async (o) => {\n return _model_js__WEBPACK_IMPORTED_MODULE_20__.UtxoItem.fromElectrum(o);\n }));\n return resp;\n }\n // gets wallet balance in sats, bch and usd\n async getBalance(rawUnit, usdPriceCache = true) {\n if (rawUnit) {\n const unit = (0,_util_sanitizeUnit_js__WEBPACK_IMPORTED_MODULE_24__.sanitizeUnit)(rawUnit);\n return await (0,_util_balanceObjectFromSatoshi_js__WEBPACK_IMPORTED_MODULE_25__.balanceFromSatoshi)(await this.getBalanceFromProvider(), unit, usdPriceCache);\n }\n else {\n return await (0,_util_balanceObjectFromSatoshi_js__WEBPACK_IMPORTED_MODULE_25__.balanceResponseFromSatoshi)(await this.getBalanceFromProvider(), usdPriceCache);\n }\n }\n // Gets balance by summing value in all utxos in stats\n async getBalanceFromUtxos() {\n const utxos = (await this.getAddressUtxos(this.cashaddr)).filter((val) => val.token === undefined);\n return (0,_util_sumUtxoValue_js__WEBPACK_IMPORTED_MODULE_26__.sumUtxoValue)(utxos);\n }\n // Gets balance from fulcrum\n async getBalanceFromProvider() {\n // Fulcrum reports balance of all utxos, including tokens, which is undesirable\n // // TODO not sure why getting the balance from a provider doesn't work\n // if (this._slpAware || this._slpSemiAware) {\n // return await this.getBalanceFromUtxos();\n // } else {\n // return await this.provider!.getBalance(this.cashaddr!);\n // }\n // FIXME\n return this.getBalanceFromUtxos();\n }\n // watching for any transaction hash of this wallet\n watchAddress(callback) {\n return this.provider.watchAddress(this.getDepositAddress(), callback);\n }\n // watching for any transaction of this wallet\n watchAddressTransactions(callback) {\n return this.provider.watchAddressTransactions(this.getDepositAddress(), callback);\n }\n // watching for cashtoken transaction of this wallet\n watchAddressTokenTransactions(callback) {\n return this.provider.watchAddressTokenTransactions(this.getDepositAddress(), callback);\n }\n // sets up a callback to be called upon wallet's balance change\n // can be cancelled by calling the function returned from this one\n watchBalance(callback) {\n return this.provider.watchAddressStatus(this.getDepositAddress(), async (_status) => {\n const balance = (await this.getBalance());\n callback(balance);\n });\n }\n // sets up a callback to be called upon wallet's BCH or USD balance change\n // if BCH balance does not change, the callback will be triggered every\n // @param `usdPriceRefreshInterval` milliseconds by polling for new BCH USD price\n // Since we want to be most sensitive to usd value change, we do not use the cached exchange rates\n // can be cancelled by calling the function returned from this one\n watchBalanceUsd(callback, usdPriceRefreshInterval = 30000) {\n let usdPrice = -1;\n const _callback = async () => {\n const balance = (await this.getBalance(undefined, false));\n if (usdPrice !== balance.usd) {\n usdPrice = balance.usd;\n callback(balance);\n }\n };\n const watchCancel = this.provider.watchAddressStatus(this.getDepositAddress(), _callback);\n const interval = setInterval(_callback, usdPriceRefreshInterval);\n return async () => {\n await watchCancel();\n clearInterval(interval);\n };\n }\n // waits for address balance to be greater than or equal to the target value\n // this call halts the execution\n async waitForBalance(value, rawUnit = _enum_js__WEBPACK_IMPORTED_MODULE_4__.UnitEnum.BCH) {\n return new Promise(async (resolve) => {\n const watchCancel = this.watchBalance(async (balance) => {\n const satoshiBalance = await (0,_util_amountInSatoshi_js__WEBPACK_IMPORTED_MODULE_27__.amountInSatoshi)(value, rawUnit);\n if (balance.sat >= satoshiBalance) {\n await watchCancel();\n resolve(balance);\n }\n });\n });\n }\n // sets up a callback to be called upon wallet's token balance change\n // can be cancelled by calling the function returned from this one\n watchTokenBalance(tokenId, callback) {\n let previous = undefined;\n return this.provider.watchAddressStatus(this.getDepositAddress(), async (_status) => {\n const balance = await this.getTokenBalance(tokenId);\n if (previous != balance) {\n callback(balance);\n }\n previous = balance;\n });\n }\n // waits for address token balance to be greater than or equal to the target amount\n // this call halts the execution\n async waitForTokenBalance(tokenId, amount) {\n return new Promise(async (resolve) => {\n const watchCancel = this.watchTokenBalance(tokenId, async (balance) => {\n if (balance >= amount) {\n await watchCancel();\n resolve(balance);\n }\n });\n });\n }\n async getTokenInfo(tokenId) {\n return _Bcmr_js__WEBPACK_IMPORTED_MODULE_28__.BCMR.getTokenInfo(tokenId);\n }\n async _getMaxAmountToSend(params = {\n outputCount: 1,\n options: {},\n }) {\n if (!this.privateKey) {\n throw Error(\"Couldn't get network or private key for wallet.\");\n }\n if (!this.cashaddr) {\n throw Error(\"attempted to send without a cashaddr\");\n }\n if (params.options && params.options.slpAware) {\n this._slpAware = true;\n }\n if (params.options && params.options.slpSemiAware) {\n this._slpSemiAware = true;\n }\n let feePaidBy;\n if (params.options && params.options.feePaidBy) {\n feePaidBy = params.options.feePaidBy;\n }\n else {\n feePaidBy = _enum_js__WEBPACK_IMPORTED_MODULE_5__.FeePaidByEnum.change;\n }\n // get inputs\n let utxos;\n if (params.options && params.options.utxoIds) {\n utxos = params.options.utxoIds.map((utxoId) => _model_js__WEBPACK_IMPORTED_MODULE_20__.UtxoItem.fromId(utxoId).asElectrum());\n }\n else {\n utxos = (await this.getAddressUtxos(this.cashaddr)).filter((utxo) => !utxo.token);\n }\n // Get current height to assure recently mined coins are not spent.\n const bestHeight = await this.provider.getBlockHeight();\n // simulate outputs using the sender's address\n const sendRequest = new _model_js__WEBPACK_IMPORTED_MODULE_20__.SendRequest({\n cashaddr: this.cashaddr,\n value: 100,\n unit: \"sat\",\n });\n const sendRequests = Array(params.outputCount)\n .fill(0)\n .map(() => sendRequest);\n const fundingUtxos = await (0,_transaction_Wif_js__WEBPACK_IMPORTED_MODULE_29__.getSuitableUtxos)(utxos, undefined, bestHeight, feePaidBy, sendRequests);\n const relayFeePerByteInSatoshi = await (0,_network_getRelayFeeCache_js__WEBPACK_IMPORTED_MODULE_1__.getRelayFeeCache)(this.provider);\n const fee = await (0,_transaction_Wif_js__WEBPACK_IMPORTED_MODULE_29__.getFeeAmount)({\n utxos: fundingUtxos,\n sendRequests: sendRequests,\n privateKey: this.privateKey,\n relayFeePerByteInSatoshi: relayFeePerByteInSatoshi,\n slpOutputs: [],\n feePaidBy: feePaidBy,\n });\n const spendableAmount = (0,_util_sumUtxoValue_js__WEBPACK_IMPORTED_MODULE_26__.sumUtxoValue)(fundingUtxos);\n let result = spendableAmount - fee;\n if (result < 0) {\n result = 0;\n }\n return { value: result, utxos: fundingUtxos };\n }\n async getMaxAmountToSend(params = {\n outputCount: 1,\n options: {},\n }) {\n const { value: result } = await this._getMaxAmountToSend(params);\n return await (0,_util_balanceObjectFromSatoshi_js__WEBPACK_IMPORTED_MODULE_25__.balanceResponseFromSatoshi)(result);\n }\n /**\n * send Send some amount to an address\n * this function processes the send requests, encodes the transaction, sends it to the network\n * @returns (depending on the options parameter) the transaction id, new address balance and a link to the transaction on the blockchain explorer\n *\n * This is a first class function with REST analog, maintainers should strive to keep backward-compatibility\n *\n */\n async send(requests, options) {\n let { encodedTransaction, tokenIds } = await this.encodeTransaction(requests, undefined, options);\n const awaitTransactionPropagation = !options ||\n options.awaitTransactionPropagation === undefined ||\n options.awaitTransactionPropagation;\n const txId = await this.submitTransaction(encodedTransaction, awaitTransactionPropagation);\n let resp = new _model_js__WEBPACK_IMPORTED_MODULE_20__.SendResponse({});\n resp.txId = txId;\n const queryBalance = !options || options.queryBalance === undefined || options.queryBalance;\n if (queryBalance) {\n resp.balance = (await this.getBalance());\n }\n resp.explorerUrl = this.explorerUrl(resp.txId);\n resp.tokenIds = tokenIds;\n return resp;\n }\n /**\n * sendMax Send all available funds to a destination cash address\n *\n * @param {string} cashaddr destination cash address\n * @param {SendRequestOptionsI} options Options of the send requests\n *\n * @returns (depending on the options parameter) the transaction id, new address balance and a link to the transaction on the blockchain explorer\n */\n async sendMax(cashaddr, options) {\n const txId = await this.sendMaxRaw(cashaddr, options);\n const queryBalance = !options || options.queryBalance === undefined || options.queryBalance;\n return {\n txId: txId,\n balance: queryBalance\n ? (await this.getBalance())\n : undefined,\n explorerUrl: this.explorerUrl(txId),\n };\n }\n /**\n * sendMaxRaw (internal) Send all available funds to a destination cash address\n *\n * @param {string} cashaddr destination cash address\n * @param {SendRequestOptionsI} options Options of the send requests\n *\n * @returns the transaction id sent to the network\n */\n async sendMaxRaw(cashaddr, options) {\n let { value: maxSpendableAmount, utxos } = await this._getMaxAmountToSend({\n outputCount: 1,\n options: options,\n });\n if (!options) {\n options = {};\n }\n options.utxoIds = utxos;\n let sendRequest = new _model_js__WEBPACK_IMPORTED_MODULE_20__.SendRequest({\n cashaddr: cashaddr,\n value: maxSpendableAmount,\n unit: \"sat\",\n });\n const { encodedTransaction } = await this.encodeTransaction([sendRequest], true, options);\n const awaitTransactionPropagation = !options ||\n options.awaitTransactionPropagation === undefined ||\n options.awaitTransactionPropagation;\n const txId = await this.submitTransaction(encodedTransaction, awaitTransactionPropagation);\n return txId;\n }\n /**\n * encodeTransaction Encode and sign a transaction given a list of sendRequests, options and estimate fees.\n * @param {SendRequest[]} sendRequests SendRequests\n * @param {boolean} discardChange=false\n * @param {SendRequestOptionsI} options Options of the send requests\n */\n async encodeTransaction(requests, discardChange = false, options) {\n let sendRequests = (0,_util_asSendRequestObject_js__WEBPACK_IMPORTED_MODULE_30__.asSendRequestObject)(requests);\n if (!this.privateKey) {\n throw new Error(`Wallet ${this.name} is missing either a network or private key`);\n }\n if (!this.cashaddr) {\n throw Error(\"attempted to send without a cashaddr\");\n }\n if (options && options.slpAware) {\n this._slpAware = true;\n }\n if (options && options.slpSemiAware) {\n this._slpSemiAware = true;\n }\n let feePaidBy;\n if (options && options.feePaidBy) {\n feePaidBy = options.feePaidBy;\n }\n else {\n feePaidBy = _enum_js__WEBPACK_IMPORTED_MODULE_5__.FeePaidByEnum.change;\n }\n let changeAddress;\n if (options && options.changeAddress) {\n changeAddress = options.changeAddress;\n }\n else {\n changeAddress = \"\";\n }\n let checkTokenQuantities = true;\n if (options && options.checkTokenQuantities === false) {\n checkTokenQuantities = false;\n }\n // get inputs from options or query all inputs\n let utxos;\n if (options && options.utxoIds) {\n utxos = options.utxoIds.map((utxoId) => typeof utxoId === \"string\"\n ? _model_js__WEBPACK_IMPORTED_MODULE_20__.UtxoItem.fromId(utxoId).asElectrum()\n : utxoId);\n }\n else {\n utxos = await this.getAddressUtxos(this.cashaddr);\n }\n const addTokenChangeOutputs = (inputs, outputs) => {\n // allow for implicit token burn if the total amount sent is less than user had\n // allow for token genesis, creating more tokens than we had before (0)\n if (!checkTokenQuantities) {\n return;\n }\n const allTokenInputs = inputs.filter((val) => val.token);\n const allTokenOutputs = outputs.filter((val) => val instanceof _model_js__WEBPACK_IMPORTED_MODULE_20__.TokenSendRequest);\n const tokenIds = allTokenOutputs\n .map((val) => val.tokenId)\n .filter((val, idx, arr) => arr.indexOf(val) === idx);\n for (let tokenId of tokenIds) {\n const tokenInputs = allTokenInputs.filter((val) => val.token?.tokenId === tokenId);\n const inputAmountSum = tokenInputs.reduce((prev, cur) => prev + cur.token.amount, 0);\n const tokenOutputs = allTokenOutputs.filter((val) => val.tokenId === tokenId);\n const outputAmountSum = tokenOutputs.reduce((prev, cur) => prev + cur.amount, 0);\n const change = inputAmountSum - outputAmountSum;\n if (change < 0) {\n throw new Error(\"Not enough token amount to send\");\n }\n if (change > 0) {\n outputs.push(new _model_js__WEBPACK_IMPORTED_MODULE_20__.TokenSendRequest({\n cashaddr: changeAddress || this.tokenaddr,\n amount: change,\n tokenId: tokenId,\n commitment: tokenOutputs[0].commitment,\n capability: tokenOutputs[0].capability,\n value: tokenOutputs[0].value,\n }));\n }\n }\n };\n addTokenChangeOutputs(utxos, sendRequests);\n const bestHeight = await this.provider.getBlockHeight();\n const spendAmount = await (0,_util_sumSendRequestAmounts_js__WEBPACK_IMPORTED_MODULE_31__.sumSendRequestAmounts)(sendRequests);\n if (utxos.length === 0) {\n throw Error(\"There were no Unspent Outputs\");\n }\n if (typeof spendAmount !== \"bigint\") {\n throw Error(\"Couldn't get spend amount when building transaction\");\n }\n const relayFeePerByteInSatoshi = await (0,_network_getRelayFeeCache_js__WEBPACK_IMPORTED_MODULE_1__.getRelayFeeCache)(this.provider);\n const feeEstimate = await (0,_transaction_Wif_js__WEBPACK_IMPORTED_MODULE_29__.getFeeAmount)({\n utxos: utxos,\n sendRequests: sendRequests,\n privateKey: this.privateKey,\n relayFeePerByteInSatoshi: relayFeePerByteInSatoshi,\n slpOutputs: [],\n feePaidBy: feePaidBy,\n });\n const fundingUtxos = await (0,_transaction_Wif_js__WEBPACK_IMPORTED_MODULE_29__.getSuitableUtxos)(utxos, BigInt(spendAmount) + BigInt(feeEstimate), bestHeight, feePaidBy, sendRequests, options?.ensureUtxos || []);\n if (fundingUtxos.length === 0) {\n throw Error(\"The available inputs couldn't satisfy the request with fees\");\n }\n const fee = await (0,_transaction_Wif_js__WEBPACK_IMPORTED_MODULE_29__.getFeeAmount)({\n utxos: fundingUtxos,\n sendRequests: sendRequests,\n privateKey: this.privateKey,\n relayFeePerByteInSatoshi: relayFeePerByteInSatoshi,\n slpOutputs: [],\n feePaidBy: feePaidBy,\n });\n const encodedTransaction = await (0,_transaction_Wif_js__WEBPACK_IMPORTED_MODULE_29__.buildEncodedTransaction)(fundingUtxos, sendRequests, this.privateKey, fee, discardChange, [], feePaidBy, changeAddress);\n const tokenIds = [\n ...fundingUtxos\n .filter((val) => val.token?.tokenId)\n .map((val) => val.token.tokenId),\n ...sendRequests\n .filter((val) => val instanceof _model_js__WEBPACK_IMPORTED_MODULE_20__.TokenSendRequest)\n .map((val) => val.tokenId),\n ].filter((value, index, array) => array.indexOf(value) === index);\n return { encodedTransaction, tokenIds: tokenIds };\n }\n // Submit a raw transaction\n async submitTransaction(transaction, awaitPropagation = true) {\n if (!this.provider) {\n throw Error(\"Wallet network provider was not initialized\");\n }\n let rawTransaction = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_11__.binToHex)(transaction);\n return await this.provider.sendRawTransaction(rawTransaction, awaitPropagation);\n }\n // gets transaction history of this wallet\n async getRawHistory() {\n return await this.provider.getHistory(this.cashaddr);\n }\n // gets transaction history of this wallet\n async getHistory(unit, start, count, collapseChange) {\n return (0,_history_electrumTransformer_js__WEBPACK_IMPORTED_MODULE_32__.getAddressHistory)(this.cashaddr, this.provider, unit, start, count, collapseChange);\n }\n // gets last transaction of this wallet\n async getLastTransaction(confirmedOnly = false) {\n let history = await this.getRawHistory();\n if (confirmedOnly) {\n history = history.filter((val) => val.height > 0);\n }\n if (!history.length) {\n return null;\n }\n const [lastTx] = history.slice(-1);\n return this.provider.getRawTransactionObject(lastTx.tx_hash);\n }\n // waits for next transaction, program execution is halted\n async waitForTransaction(options = {\n getTransactionInfo: true,\n getBalance: false,\n txHash: undefined,\n }) {\n if (options.getTransactionInfo === undefined) {\n options.getTransactionInfo = true;\n }\n return new Promise(async (resolve) => {\n let txHashSeen = false;\n const makeResponse = async (txHash) => {\n const response = {};\n const promises = [undefined, undefined];\n if (options.getBalance === true) {\n promises[0] = this.getBalance();\n }\n if (options.getTransactionInfo === true) {\n if (!txHash) {\n promises[1] = this.getLastTransaction();\n }\n else {\n promises[1] = this.provider.getRawTransactionObject(txHash);\n }\n }\n const result = await Promise.all(promises);\n response.balance = result[0];\n response.transactionInfo = result[1];\n return response;\n };\n // waiting for a specific transaction to propagate\n if (options.txHash) {\n const waitForTransactionCallback = async (data) => {\n if (data && data[0] === options.txHash) {\n txHashSeen = true;\n this.provider.unsubscribeFromTransaction(options.txHash, waitForTransactionCallback);\n resolve(makeResponse(options.txHash));\n }\n };\n this.provider.subscribeToTransaction(options.txHash, waitForTransactionCallback);\n return;\n }\n // waiting for any address transaction\n const watchCancel = this.provider.watchAddressStatus(this.getDepositAddress(), async (_status) => {\n watchCancel();\n resolve(makeResponse());\n });\n });\n }\n /**\n * watchBlocks Watch network blocks\n *\n * @param callback callback with a block header object\n *\n * @returns a function which will cancel watching upon evaluation\n */\n watchBlocks(callback) {\n return this.provider.watchBlocks(callback);\n }\n /**\n * waitForBlock Wait for a network block\n *\n * @param height if specified waits for this exact blockchain height, otherwise resolves with the next block\n *\n */\n async waitForBlock(height) {\n return this.provider.waitForBlock(height);\n }\n //#endregion Funds\n //#region Private implementation details\n async deriveInfo() {\n const publicKey = _bitauth_libauth__WEBPACK_IMPORTED_MODULE_33__.secp256k1.derivePublicKeyUncompressed(this.privateKey);\n if (typeof publicKey === \"string\") {\n throw new Error(publicKey);\n }\n this.publicKey = publicKey;\n const publicKeyCompressed = _bitauth_libauth__WEBPACK_IMPORTED_MODULE_33__.secp256k1.derivePublicKeyCompressed(this.privateKey);\n if (typeof publicKeyCompressed === \"string\") {\n throw new Error(publicKeyCompressed);\n }\n this.publicKeyCompressed = publicKeyCompressed;\n const networkType = this.network === _enum_js__WEBPACK_IMPORTED_MODULE_4__.NetworkType.Regtest ? _enum_js__WEBPACK_IMPORTED_MODULE_4__.NetworkType.Testnet : this.network;\n this.privateKeyWif = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_23__.encodePrivateKeyWif)(this.privateKey, networkType);\n (0,_util_checkWifNetwork_js__WEBPACK_IMPORTED_MODULE_22__.checkWifNetwork)(this.privateKeyWif, this.network);\n this.cashaddr = (0,_util_deriveCashaddr_js__WEBPACK_IMPORTED_MODULE_21__.deriveCashaddr)(this.privateKey, this.networkPrefix);\n this.tokenaddr = (0,_util_deriveCashaddr_js__WEBPACK_IMPORTED_MODULE_21__.deriveTokenaddr)(this.privateKey, this.networkPrefix);\n this.address = this.cashaddr;\n this.publicKeyHash = (0,_util_derivePublicKeyHash_js__WEBPACK_IMPORTED_MODULE_12__.derivePublicKeyHash)(this.cashaddr);\n return this;\n }\n //#endregion Private implementation details\n //#region Signing\n // Convenience wrapper to sign interface\n async sign(message) {\n return await Wallet.signedMessage.sign(message, this.privateKey);\n }\n // Convenience wrapper to verify interface\n async verify(message, sig, publicKey) {\n return await Wallet.signedMessage.verify(message, sig, this.cashaddr, publicKey);\n }\n //#endregion Signing\n //#region Cashtokens\n /**\n * Create new cashtoken, both funglible and/or non-fungible (NFT)\n * Refer to spec https://github.com/bitjson/cashtokens\n * @param {number} genesisRequest.amount amount of *fungible* tokens to create\n * @param {NFTCapability?} genesisRequest.capability capability of new NFT\n * @param {string?} genesisRequest.commitment NFT commitment message\n * @param {string?} genesisRequest.cashaddr cash address to send the created token UTXO to; if undefined will default to your address\n * @param {number?} genesisRequest.value satoshi value to send alongside with tokens; if undefined will default to 1000 satoshi\n */\n async tokenGenesis(genesisRequest) {\n return this.send(new _model_js__WEBPACK_IMPORTED_MODULE_20__.TokenSendRequest({\n cashaddr: genesisRequest.cashaddr || this.tokenaddr,\n amount: genesisRequest.amount,\n value: genesisRequest.value,\n capability: genesisRequest.capability,\n commitment: genesisRequest.commitment,\n tokenId: \"\",\n }), {\n checkTokenQuantities: false,\n queryBalance: false,\n });\n }\n /**\n * Mint new NFT cashtokens using an existing minting token\n * Refer to spec https://github.com/bitjson/cashtokens\n * @param {string} tokenId tokenId of an NFT to mint\n * @param {TokenMintRequest | TokenMintRequest[]} mintRequests mint requests with new token properties and recipients\n * @param {NFTCapability?} mintRequest.capability capability of new NFT\n * @param {string?} mintRequest.commitment NFT commitment message\n * @param {string?} mintRequest.cashaddr cash address to send the created token UTXO to; if undefined will default to your address\n * @param {number?} mintRequest.value satoshi value to send alongside with tokens; if undefined will default to 1000 satoshi\n * @param {boolean?} deductTokenAmount if minting token contains fungible amount, deduct from it by amount of minted tokens\n */\n async tokenMint(tokenId, mintRequests, deductTokenAmount = false) {\n if (!Array.isArray(mintRequests)) {\n mintRequests = [mintRequests];\n }\n const utxos = await this.getAddressUtxos(this.cashaddr);\n const nftUtxos = utxos.filter((val) => val.token?.tokenId === tokenId &&\n val.token?.capability != _interface_js__WEBPACK_IMPORTED_MODULE_8__.NFTCapability.none);\n if (!nftUtxos.length) {\n throw new Error(\"You do not have any token UTXOs with minting capability for specified tokenId\");\n }\n const newAmount = deductTokenAmount && nftUtxos[0].token.amount > 0\n ? nftUtxos[0].token.amount - mintRequests.length\n : nftUtxos[0].token.amount;\n const safeNewAmount = Math.max(0, newAmount);\n const mintingInput = new _model_js__WEBPACK_IMPORTED_MODULE_20__.TokenSendRequest({\n cashaddr: this.tokenaddr,\n tokenId: tokenId,\n capability: nftUtxos[0].token.capability,\n commitment: nftUtxos[0].token.commitment,\n amount: safeNewAmount,\n value: nftUtxos[0].satoshis,\n });\n return this.send([\n mintingInput,\n ...mintRequests.map((val) => new _model_js__WEBPACK_IMPORTED_MODULE_20__.TokenSendRequest({\n cashaddr: val.cashaddr || this.tokenaddr,\n amount: 0,\n tokenId: tokenId,\n value: val.value,\n capability: val.capability,\n commitment: val.commitment,\n })),\n ], {\n checkTokenQuantities: false,\n queryBalance: false,\n });\n }\n /**\n * Perform an explicit token burning by spending a token utxo to an OP_RETURN\n *\n * Behaves differently for fungible and non-fungible tokens:\n * * NFTs are always \"destroyed\"\n * * FTs' amount is reduced by the amount specified, if 0 FT amount is left and no NFT present, the token is \"destroyed\"\n *\n * Refer to spec https://github.com/bitjson/cashtokens\n * @param {string} burnRequest.tokenId tokenId of a token to burn\n * @param {NFTCapability} burnRequest.capability capability of the NFT token to select, optional\n * @param {string?} burnRequest.commitment commitment of the NFT token to select, optional\n * @param {number?} burnRequest.amount amount of fungible tokens to burn, optional\n * @param {string?} burnRequest.cashaddr address to return token and satoshi change to\n * @param {string?} message optional message to include in OP_RETURN\n */\n async tokenBurn(burnRequest, message) {\n const utxos = await this.getAddressUtxos(this.cashaddr);\n const tokenUtxos = utxos.filter((val) => val.token?.tokenId === burnRequest.tokenId &&\n val.token?.capability === burnRequest.capability &&\n val.token?.commitment === burnRequest.commitment &&\n val.token?.capability === burnRequest.capability);\n if (!tokenUtxos.length) {\n throw new Error(\"You do not have suitable token UTXOs to perform burn\");\n }\n const totalFungibleAmount = tokenUtxos.reduce((prev, cur) => prev + (cur.token?.amount || 0), 0);\n const fungibleBurnAmount = burnRequest.amount && burnRequest.amount > 0 ? burnRequest.amount : 0;\n const hasNFT = burnRequest.capability || burnRequest.commitment;\n let utxoIds = [];\n let changeSendRequests;\n if (hasNFT) {\n // does not have FT tokens, let us destroy the token completely\n if (totalFungibleAmount === 0) {\n changeSendRequests = [];\n utxoIds.push(tokenUtxos[0]);\n }\n else {\n // if there are FT, reduce their amount\n const newAmount = totalFungibleAmount - fungibleBurnAmount;\n const safeNewAmount = Math.max(0, newAmount);\n changeSendRequests = [\n new _model_js__WEBPACK_IMPORTED_MODULE_20__.TokenSendRequest({\n cashaddr: burnRequest.cashaddr || this.tokenaddr,\n tokenId: burnRequest.tokenId,\n capability: burnRequest.capability,\n commitment: burnRequest.commitment,\n amount: safeNewAmount,\n value: tokenUtxos[0].satoshis,\n }),\n ];\n }\n }\n else {\n // if we are burning last fughible tokens, let us destroy the token completely\n if (totalFungibleAmount === fungibleBurnAmount) {\n changeSendRequests = [];\n utxoIds.push(tokenUtxos[0]);\n }\n else {\n // reduce the FT amount\n const newAmount = totalFungibleAmount - fungibleBurnAmount;\n const safeNewAmount = Math.max(0, newAmount);\n changeSendRequests = [\n new _model_js__WEBPACK_IMPORTED_MODULE_20__.TokenSendRequest({\n cashaddr: burnRequest.cashaddr || this.tokenaddr,\n tokenId: burnRequest.tokenId,\n amount: safeNewAmount,\n value: tokenUtxos[0].satoshis,\n }),\n ];\n }\n }\n const opReturn = _model_js__WEBPACK_IMPORTED_MODULE_20__.OpReturnData.fromString(message || \"\");\n return this.send([opReturn, ...changeSendRequests], {\n checkTokenQuantities: false,\n queryBalance: false,\n ensureUtxos: utxoIds.length > 0 ? utxoIds : undefined,\n });\n }\n /**\n * getTokenUtxos Get unspent token outputs for the wallet\n * will return utxos only for the specified token if `tokenId` provided\n * @param {string?} tokenId tokenId (category) to filter utxos by, if not set will return utxos from all tokens\n * @returns {UtxoI[]} token utxos\n */\n async getTokenUtxos(tokenId) {\n const utxos = await this.getAddressUtxos(this.address);\n return utxos.filter((val) => tokenId ? val.token?.tokenId === tokenId : val.token);\n }\n /**\n * getTokenBalance Gets fungible token balance\n * for NFT token balance see @ref getNftTokenBalance\n * @param {string} tokenId tokenId to get balance for\n * @returns {number} fungible token balance\n */\n async getTokenBalance(tokenId) {\n const utxos = await this.getAddressUtxos(this.cashaddr);\n return (0,_util_sumUtxoValue_js__WEBPACK_IMPORTED_MODULE_26__.sumTokenAmounts)(utxos, tokenId);\n }\n /**\n * getNftTokenBalance Gets non-fungible token (NFT) balance for a particula tokenId\n * disregards fungible token balances\n * for fungible token balance see @ref getTokenBalance\n * @param {string} tokenId tokenId to get balance for\n * @returns {number} non-fungible token balance\n */\n async getNftTokenBalance(tokenId) {\n const utxos = await this.getTokenUtxos(tokenId);\n return utxos.length;\n }\n /**\n * getAllTokenBalances Gets all fungible token balances in this wallet\n * @returns {Object} a map [tokenId => balance] for all tokens in this wallet\n */\n async getAllTokenBalances() {\n const result = {};\n const utxos = await this.getTokenUtxos();\n for (const utxo of utxos) {\n if (!result[utxo.token.tokenId]) {\n result[utxo.token.tokenId] = 0;\n }\n result[utxo.token.tokenId] += utxo.token.amount;\n }\n return result;\n }\n /**\n * getAllNftTokenBalances Gets all non-fungible token (NFT) balances in this wallet\n * @returns {Object} a map [tokenId => balance] for all NFTs in this wallet\n */\n async getAllNftTokenBalances() {\n const result = {};\n const utxos = await this.getTokenUtxos();\n for (const utxo of utxos) {\n if (!result[utxo.token.tokenId]) {\n result[utxo.token.tokenId] = 0;\n }\n result[utxo.token.tokenId] += 1;\n }\n return result;\n }\n}\nWallet.signedMessage = new _message_index_js__WEBPACK_IMPORTED_MODULE_34__.SignedMessage();\n/**\n * Class to manage a testnet wallet.\n */\nclass TestNetWallet extends Wallet {\n constructor(name = \"\") {\n super(name, _enum_js__WEBPACK_IMPORTED_MODULE_4__.NetworkType.Testnet);\n }\n // will receive 10000 testnet satoshi, rate limits apply\n async getTestnetSatoshis() {\n try {\n const response = await axios__WEBPACK_IMPORTED_MODULE_2___default().post(`${TestNetWallet.faucetServer}/faucet/get_testnet_bch`, { cashaddr: this.cashaddr });\n const data = response.data;\n return data.txId;\n }\n catch (e) {\n // console.log(e);\n // console.log(e.response ? e.response.data : \"\");\n throw e;\n }\n }\n // be nice and return them back\n async returnTestnetSatoshis() {\n try {\n const response = await axios__WEBPACK_IMPORTED_MODULE_2___default().post(`${TestNetWallet.faucetServer}/faucet/get_addresses`);\n const data = response.data;\n return await this.slpAware().sendMax(data.bchtest);\n }\n catch (e) {\n console.log(e);\n console.log(e.response ? e.response.data : \"\");\n throw e;\n }\n }\n // will receive 10 testnet tokens, rate limits apply\n async getTestnetSlp(tokenId) {\n try {\n const response = await axios__WEBPACK_IMPORTED_MODULE_2___default().post(`${TestNetWallet.faucetServer}/faucet/get_testnet_slp`, { slpaddr: this.slp.slpaddr, tokenId: tokenId });\n const data = response.data;\n return data.txId;\n }\n catch (e) {\n //console.log(e);\n //console.log(e.response ? e.response.data : \"\");\n throw e;\n }\n }\n // be nice and return them back\n async returnTestnetSlp(tokenId) {\n try {\n const response = await axios__WEBPACK_IMPORTED_MODULE_2___default().post(`${TestNetWallet.faucetServer}/faucet/get_addresses`);\n const data = response.data;\n return await this.slp.sendMax(data.slptest, tokenId);\n }\n catch (e) {\n console.log(e);\n console.log(e.response ? e.response.data : \"\");\n throw e;\n }\n }\n // interface to static slp functions. see Slp.ts\n static get slp() {\n return _Slp_js__WEBPACK_IMPORTED_MODULE_6__.TestNetSlp;\n }\n // interface to static util functions. see Util.ts\n static get util() {\n return _Util_js__WEBPACK_IMPORTED_MODULE_7__.TestNetUtil;\n }\n}\nTestNetWallet.networkPrefix = _bitauth_libauth__WEBPACK_IMPORTED_MODULE_35__.CashAddressNetworkPrefix.testnet;\nTestNetWallet.faucetServer = \"https://rest-unstable.mainnet.cash\";\n/**\n * Class to manage a regtest wallet.\n */\nclass RegTestWallet extends Wallet {\n constructor(name = \"\") {\n super(name, _enum_js__WEBPACK_IMPORTED_MODULE_4__.NetworkType.Regtest);\n }\n // interface to static slp functions. see Slp.ts\n static get slp() {\n return _Slp_js__WEBPACK_IMPORTED_MODULE_6__.RegTestSlp;\n }\n // interface to static util functions. see Util.ts\n static get util() {\n return _Util_js__WEBPACK_IMPORTED_MODULE_7__.RegTestUtil;\n }\n}\nRegTestWallet.networkPrefix = _bitauth_libauth__WEBPACK_IMPORTED_MODULE_35__.CashAddressNetworkPrefix.regtest;\n/**\n * Class to manage a bitcoin cash wif wallet.\n */\nclass WifWallet extends Wallet {\n constructor(name = \"\") {\n super(name, _enum_js__WEBPACK_IMPORTED_MODULE_4__.NetworkType.Mainnet, _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Wif);\n }\n // interface to static slp functions. see Slp.ts\n static get slp() {\n return _Slp_js__WEBPACK_IMPORTED_MODULE_6__.WifSlp;\n }\n // interface to static util functions. see Util.ts\n static get util() {\n return _Util_js__WEBPACK_IMPORTED_MODULE_7__.WifUtil;\n }\n}\nWifWallet.networkPrefix = _bitauth_libauth__WEBPACK_IMPORTED_MODULE_35__.CashAddressNetworkPrefix.mainnet;\nWifWallet.walletType = _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Wif;\n/**\n * Class to manage a testnet wif wallet.\n */\nclass TestNetWifWallet extends Wallet {\n constructor(name = \"\") {\n super(name, _enum_js__WEBPACK_IMPORTED_MODULE_4__.NetworkType.Testnet, _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Wif);\n }\n // interface to static slp functions. see Slp.ts\n static get slp() {\n return _Slp_js__WEBPACK_IMPORTED_MODULE_6__.TestNetWifSlp;\n }\n // interface to static util functions. see Util.ts\n static get util() {\n return _Util_js__WEBPACK_IMPORTED_MODULE_7__.TestNetWifUtil;\n }\n}\nTestNetWifWallet.networkPrefix = _bitauth_libauth__WEBPACK_IMPORTED_MODULE_35__.CashAddressNetworkPrefix.testnet;\nTestNetWifWallet.walletType = _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Wif;\n/**\n * Class to manage a regtest wif wallet.\n */\nclass RegTestWifWallet extends Wallet {\n constructor(name = \"\") {\n super(name, _enum_js__WEBPACK_IMPORTED_MODULE_4__.NetworkType.Regtest, _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Wif);\n }\n // interface to static slp functions. see Slp.ts\n static get slp() {\n return _Slp_js__WEBPACK_IMPORTED_MODULE_6__.RegTestWifSlp;\n }\n // interface to static util functions. see Util.ts\n static get util() {\n return _Util_js__WEBPACK_IMPORTED_MODULE_7__.RegTestWifUtil;\n }\n}\nRegTestWifWallet.networkPrefix = _bitauth_libauth__WEBPACK_IMPORTED_MODULE_35__.CashAddressNetworkPrefix.regtest;\nRegTestWifWallet.walletType = _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Wif;\n/**\n * Class to manage a bitcoin cash watch wallet.\n */\nclass WatchWallet extends Wallet {\n constructor(name = \"\") {\n super(name, _enum_js__WEBPACK_IMPORTED_MODULE_4__.NetworkType.Mainnet, _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Watch);\n }\n // interface to static slp functions. see Slp.ts\n static get slp() {\n return _Slp_js__WEBPACK_IMPORTED_MODULE_6__.WatchSlp;\n }\n // interface to static util functions. see Util.ts\n static get util() {\n return _Util_js__WEBPACK_IMPORTED_MODULE_7__.WatchUtil;\n }\n}\nWatchWallet.networkPrefix = _bitauth_libauth__WEBPACK_IMPORTED_MODULE_35__.CashAddressNetworkPrefix.mainnet;\nWatchWallet.walletType = _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Watch;\n/**\n * Class to manage a testnet watch wallet.\n */\nclass TestNetWatchWallet extends Wallet {\n constructor(name = \"\") {\n super(name, _enum_js__WEBPACK_IMPORTED_MODULE_4__.NetworkType.Testnet, _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Watch);\n }\n // interface to static slp functions. see Slp.ts\n static get slp() {\n return _Slp_js__WEBPACK_IMPORTED_MODULE_6__.TestNetWatchSlp;\n }\n // interface to static util functions. see Util.ts\n static get util() {\n return _Util_js__WEBPACK_IMPORTED_MODULE_7__.TestNetWatchUtil;\n }\n}\nTestNetWatchWallet.networkPrefix = _bitauth_libauth__WEBPACK_IMPORTED_MODULE_35__.CashAddressNetworkPrefix.testnet;\nTestNetWatchWallet.walletType = _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Watch;\n/**\n * Class to manage a regtest watch wallet.\n */\nclass RegTestWatchWallet extends Wallet {\n constructor(name = \"\") {\n super(name, _enum_js__WEBPACK_IMPORTED_MODULE_4__.NetworkType.Regtest, _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Watch);\n }\n // interface to static slp functions. see Slp.ts\n static get slp() {\n return _Slp_js__WEBPACK_IMPORTED_MODULE_6__.RegTestWatchSlp;\n }\n // interface to static util functions. see Util.ts\n static get util() {\n return _Util_js__WEBPACK_IMPORTED_MODULE_7__.RegTestWatchUtil;\n }\n}\nRegTestWatchWallet.networkPrefix = _bitauth_libauth__WEBPACK_IMPORTED_MODULE_35__.CashAddressNetworkPrefix.regtest;\nRegTestWatchWallet.walletType = _enum_js__WEBPACK_IMPORTED_MODULE_5__.WalletTypeEnum.Watch;\n\n__webpack_async_result__();\n} catch(e) { __webpack_async_result__(e); } });\n\n//# sourceURL=webpack://mainnet-js/./src/wallet/Wif.ts?");
|
|
1658
1668
|
|
|
1659
1669
|
/***/ }),
|
|
1660
1670
|
|
|
@@ -1684,7 +1694,7 @@ eval("/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harm
|
|
|
1684
1694
|
\*****************************/
|
|
1685
1695
|
/***/ ((module, __webpack_exports__, __webpack_require__) => {
|
|
1686
1696
|
|
|
1687
|
-
eval("__webpack_require__.a(module, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"OpReturnData\": () => (/* binding */ OpReturnData),\n/* harmony export */ \"SendRequest\": () => (/* binding */ SendRequest),\n/* harmony export */ \"SendResponse\": () => (/* binding */ SendResponse),\n/* harmony export */ \"TokenBurnRequest\": () => (/* binding */ TokenBurnRequest),\n/* harmony export */ \"TokenGenesisRequest\": () => (/* binding */ TokenGenesisRequest),\n/* harmony export */ \"TokenMintRequest\": () => (/* binding */ TokenMintRequest),\n/* harmony export */ \"TokenSendRequest\": () => (/* binding */ TokenSendRequest),\n/* harmony export */ \"UtxoItem\": () => (/* binding */ UtxoItem),\n/* harmony export */ \"UtxoResponse\": () => (/* binding */ UtxoResponse),\n/* harmony export */ \"XPubKey\": () => (/* binding */ XPubKey)\n/* harmony export */ });\n/* harmony import */ var
|
|
1697
|
+
eval("__webpack_require__.a(module, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"OpReturnData\": () => (/* binding */ OpReturnData),\n/* harmony export */ \"SendRequest\": () => (/* binding */ SendRequest),\n/* harmony export */ \"SendResponse\": () => (/* binding */ SendResponse),\n/* harmony export */ \"TokenBurnRequest\": () => (/* binding */ TokenBurnRequest),\n/* harmony export */ \"TokenGenesisRequest\": () => (/* binding */ TokenGenesisRequest),\n/* harmony export */ \"TokenMintRequest\": () => (/* binding */ TokenMintRequest),\n/* harmony export */ \"TokenSendRequest\": () => (/* binding */ TokenSendRequest),\n/* harmony export */ \"UtxoItem\": () => (/* binding */ UtxoItem),\n/* harmony export */ \"UtxoResponse\": () => (/* binding */ UtxoResponse),\n/* harmony export */ \"XPubKey\": () => (/* binding */ XPubKey)\n/* harmony export */ });\n/* harmony import */ var _util_balanceObjectFromSatoshi_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../util/balanceObjectFromSatoshi.js */ \"./src/util/balanceObjectFromSatoshi.ts\");\n/* harmony import */ var _util_sanitizeUnit_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../util/sanitizeUnit.js */ \"./src/util/sanitizeUnit.ts\");\n/* harmony import */ var _constant_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../constant.js */ \"./src/constant.ts\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @bitauth/libauth */ \"./node_modules/@bitauth/libauth/build/lib/format/utf8.js\");\n/* harmony import */ var _config_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../config.js */ \"./src/config.ts\");\n/* harmony import */ var _util_deriveCashaddr_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../util/deriveCashaddr.js */ \"./src/util/deriveCashaddr.ts\");\n/* provided dependency */ var Buffer = __webpack_require__(/*! buffer */ \"../../node_modules/buffer/index.js\")[\"Buffer\"];\nvar __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_util_deriveCashaddr_js__WEBPACK_IMPORTED_MODULE_1__, _util_balanceObjectFromSatoshi_js__WEBPACK_IMPORTED_MODULE_5__]);\n([_util_deriveCashaddr_js__WEBPACK_IMPORTED_MODULE_1__, _util_balanceObjectFromSatoshi_js__WEBPACK_IMPORTED_MODULE_5__] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);\n\n\n\n\n\n\nclass SendRequest {\n constructor({ cashaddr, value, unit, }) {\n this.cashaddr = cashaddr;\n this.value = value;\n this.unit = (0,_util_sanitizeUnit_js__WEBPACK_IMPORTED_MODULE_0__.sanitizeUnit)(unit);\n }\n}\nclass TokenGenesisRequest {\n constructor({ amount, capability, commitment, cashaddr, value, }) {\n this.amount = amount;\n this.capability = capability;\n this.commitment = commitment;\n this.cashaddr = cashaddr;\n this.value = value;\n }\n}\nclass TokenBurnRequest {\n constructor({ tokenId, capability, commitment, amount, cashaddr, }) {\n this.tokenId = tokenId;\n this.capability = capability;\n this.commitment = commitment;\n this.amount = amount;\n this.cashaddr = cashaddr;\n }\n}\nclass TokenSendRequest {\n constructor({ cashaddr, value, amount, tokenId, capability, commitment, }) {\n (0,_util_deriveCashaddr_js__WEBPACK_IMPORTED_MODULE_1__.checkTokenaddr)(cashaddr, _config_js__WEBPACK_IMPORTED_MODULE_2__.Config.EnforceCashTokenReceiptAddresses);\n this.cashaddr = cashaddr;\n this.value = value;\n this.amount = amount || 0;\n this.tokenId = tokenId;\n this.capability = capability;\n this.commitment = commitment;\n }\n}\nclass TokenMintRequest {\n constructor({ capability, commitment, cashaddr, value, }) {\n this.capability = capability;\n this.commitment = commitment;\n this.cashaddr = cashaddr;\n this.value = value;\n }\n}\nclass OpReturnData {\n constructor(buffer) {\n this.buffer = Buffer.from(buffer);\n }\n /**\n * from - Construct OP_RETURN data from arbitrary data type\n *\n * @param string UTF-8 encoded string message to be converted to OP_RETURN data\n *\n * @returns class instance\n */\n static from(data) {\n return this.fromArray([data]);\n }\n /**\n * fromString - Accept data as a simple UTF-8 string message and append an OP_RETURN and PUSH_DATA1 opcodes to it\n *\n * @param string UTF-8 encoded string message to be converted to OP_RETURN data\n *\n * @returns class instance\n */\n static fromString(string) {\n return this.fromArray([string]);\n }\n /**\n * buffer - Accept OP_RETURN data as a binary buffer.\n * If buffer lacks the OP_RETURN and OP_PUSHDATA opcodes, they will be prepended.\n *\n * @param buffer Data buffer to be assigned to the OP_RETURN outpit\n *\n * @returns class instance\n */\n static fromBuffer(buffer) {\n if (buffer[0] !== 0x6a) {\n return this.fromArray([buffer]);\n }\n return new this(buffer);\n }\n /**\n * buffer - Accept OP_RETURN data as a binary buffer.\n * If buffer lacks the OP_RETURN and OP_PUSHDATA opcodes, they will be prepended.\n *\n * @param buffer Data buffer to be assigned to the OP_RETURN outpit\n *\n * @returns class instance\n */\n static fromUint8Array(uint8Array) {\n if (uint8Array[0] !== 0x6a) {\n return this.fromArray([uint8Array]);\n }\n return new this(Buffer.from(uint8Array));\n }\n /**\n * fromArray - Accept array of data\n *\n * @param array Array of Buffer or UTF-8 encoded string messages to be converted to OP_RETURN data\n *\n * @returns class instance\n */\n static fromArray(array) {\n let data = Buffer.from([0x6a]); // OP_RETURN\n for (const element of array) {\n let length;\n let elementData;\n let lengthData;\n if (typeof element === \"string\") {\n elementData = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__.utf8ToBin)(element);\n length = elementData.length;\n }\n else if (element instanceof Buffer) {\n elementData = element;\n length = elementData.length;\n }\n else if (element instanceof Uint8Array) {\n elementData = Buffer.from(element);\n length = elementData.length;\n }\n else {\n throw new Error(\"Wrong data array element\");\n }\n if (length < 75) {\n lengthData = [length];\n }\n else if (length < 220) {\n lengthData = [0x4c, length];\n }\n else {\n throw new Error(\"OP_RETURN data can not exceed 220 bytes in size\");\n }\n data = Buffer.from([...data, ...[lengthData], ...elementData]);\n }\n if (data.length > 220) {\n throw new Error(\"OP_RETURN data can not exceed 220 bytes in size\");\n }\n return new this(data);\n }\n}\nclass UtxoItem {\n constructor({ index, value, txId, }) {\n this.value = value;\n this.txId = txId;\n this.index = index;\n this.utxoId = this.toString();\n }\n toString() {\n return [this.txId, this.index, this.value].join(_constant_js__WEBPACK_IMPORTED_MODULE_4__.DELIMITER);\n }\n static fromId(utxoId) {\n let [txid, vout, satoshis] = utxoId.split(_constant_js__WEBPACK_IMPORTED_MODULE_4__.DELIMITER);\n return new this({\n txId: txid,\n index: parseInt(vout),\n value: parseInt(satoshis),\n });\n }\n static fromElectrum(u) {\n return new this({\n txId: u.txid,\n index: u.vout,\n value: u.satoshis,\n });\n }\n asElectrum() {\n return {\n txid: this.txId,\n vout: this.index,\n satoshis: this.value,\n };\n }\n}\nclass UtxoResponse {\n}\nclass SendResponse {\n constructor({ txId, balance, explorerUrl, }) {\n this.txId = txId;\n this.balance = new _util_balanceObjectFromSatoshi_js__WEBPACK_IMPORTED_MODULE_5__.BalanceResponse(balance);\n this.explorerUrl = explorerUrl;\n }\n}\nclass XPubKey {\n constructor({ path, xPubKey }) {\n this.path = path;\n this.xPubKey = xPubKey;\n }\n async ready() {\n await this.xPubKey;\n return this.asObject();\n }\n asObject() {\n return {\n path: this.path,\n xPubKey: this.xPubKey,\n };\n }\n}\n\n__webpack_async_result__();\n} catch(e) { __webpack_async_result__(e); } });\n\n//# sourceURL=webpack://mainnet-js/./src/wallet/model.ts?");
|
|
1688
1698
|
|
|
1689
1699
|
/***/ }),
|
|
1690
1700
|
|