mainnet-js 2.6.1 → 2.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/index.html +1 -1
  2. package/dist/{mainnet-2.6.1.js → mainnet-2.6.3.js} +34 -4
  3. package/dist/module/cache/IndexedDbCache.d.ts +14 -0
  4. package/dist/module/cache/IndexedDbCache.d.ts.map +1 -0
  5. package/dist/module/cache/IndexedDbCache.js +86 -0
  6. package/dist/module/cache/IndexedDbCache.js.map +1 -0
  7. package/dist/module/cache/KeyValueCache.d.ts +9 -0
  8. package/dist/module/cache/KeyValueCache.d.ts.map +1 -0
  9. package/dist/module/cache/KeyValueCache.js +3 -0
  10. package/dist/module/cache/KeyValueCache.js.map +1 -0
  11. package/dist/module/cache/MemoryCache.d.ts +9 -0
  12. package/dist/module/cache/MemoryCache.d.ts.map +1 -0
  13. package/dist/module/cache/MemoryCache.js +21 -0
  14. package/dist/module/cache/MemoryCache.js.map +1 -0
  15. package/dist/module/cache/WebStorageCache.d.ts +9 -0
  16. package/dist/module/cache/WebStorageCache.d.ts.map +1 -0
  17. package/dist/module/cache/WebStorageCache.js +19 -0
  18. package/dist/module/cache/WebStorageCache.js.map +1 -0
  19. package/dist/module/cache/index.d.ts +2 -0
  20. package/dist/module/cache/index.d.ts.map +1 -0
  21. package/dist/module/cache/index.js +2 -0
  22. package/dist/module/cache/index.js.map +1 -0
  23. package/dist/module/cache/interface.d.ts +8 -0
  24. package/dist/module/cache/interface.d.ts.map +1 -0
  25. package/dist/module/cache/interface.js +2 -0
  26. package/dist/module/cache/interface.js.map +1 -0
  27. package/dist/module/config.d.ts +2 -0
  28. package/dist/module/config.d.ts.map +1 -1
  29. package/dist/module/config.js +4 -0
  30. package/dist/module/config.js.map +1 -1
  31. package/dist/module/history/electrumTransformer.d.ts.map +1 -1
  32. package/dist/module/history/electrumTransformer.js +2 -2
  33. package/dist/module/history/electrumTransformer.js.map +1 -1
  34. package/dist/module/network/ElectrumNetworkProvider.d.ts +3 -3
  35. package/dist/module/network/ElectrumNetworkProvider.d.ts.map +1 -1
  36. package/dist/module/network/ElectrumNetworkProvider.js +34 -23
  37. package/dist/module/network/ElectrumNetworkProvider.js.map +1 -1
  38. package/dist/module/network/constant.js +1 -1
  39. package/dist/tsconfig.tsbuildinfo +1 -1
  40. package/package.json +1 -1
  41. package/src/cache/IndexedDbCache.test.ts +15 -0
  42. package/src/cache/IndexedDbCache.ts +127 -0
  43. package/src/cache/KeyValueCache.ts +9 -0
  44. package/src/cache/MemoryCache.test.ts +15 -0
  45. package/src/cache/MemoryCache.ts +18 -0
  46. package/src/cache/WebStorageCache.test.ts +15 -0
  47. package/src/cache/WebStorageCache.ts +24 -0
  48. package/src/cache/index.ts +1 -0
  49. package/src/cache/interface.ts +7 -0
  50. package/src/config.ts +4 -0
  51. package/src/history/electrumTransformer.ts +3 -1
  52. package/src/network/ElectrumNetworkProvider.ts +46 -19
  53. package/src/network/constant.ts +1 -1
  54. package/src/wallet/Wif.test.ts +0 -12
package/dist/index.html CHANGED
@@ -3,7 +3,7 @@
3
3
  <head>
4
4
  <meta charset="utf-8">
5
5
  <title>The Empty Mainnet App</title>
6
- <meta name="viewport" content="width=device-width, initial-scale=1"><script defer src="mainnet-2.6.1.js"></script></head>
6
+ <meta name="viewport" content="width=device-width, initial-scale=1"><script defer src="mainnet-2.6.3.js"></script></head>
7
7
  <body><script>document.addEventListener("DOMContentLoaded", async (event) => Object.assign(globalThis, await __mainnetPromise))</script>
8
8
  </body>
9
9
  </html>
@@ -78,6 +78,36 @@ eval("/**\n * @fileoverview\n * - modified davidshimjs/qrcodejs library for use
78
78
 
79
79
  /***/ }),
80
80
 
81
+ /***/ "./src/cache/IndexedDbCache.ts":
82
+ /*!*************************************!*\
83
+ !*** ./src/cache/IndexedDbCache.ts ***!
84
+ \*************************************/
85
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
86
+
87
+ eval("/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"IndexedDbCache\": () => (/* binding */ IndexedDbCache)\n/* harmony export */ });\n// super thin wrapper around indexedDB, compatible with localStorage API\nclass IndexedDbCache {\n constructor(objectStoreName = \"ElectrumNetworkProviderCache\") {\n this.objectStoreName = objectStoreName;\n this.db = null;\n this.objectStoreName = objectStoreName;\n }\n getDatabaseObjectFromTarget(target) {\n if (!target) {\n return null;\n }\n const targetWithType = target;\n return targetWithType.result;\n }\n throwDatabaseOpenError(reject, database) {\n if (!database) {\n reject(new Error(\"Something went wrong and the database transaction was not opened.\"));\n }\n }\n async init() {\n const db = indexedDB.open(\"ElectrumNetworkProviderCache\", 1);\n this.db = await new Promise((resolve, reject) => {\n const request = db;\n request.onerror = reject;\n request.onsuccess = ({ target }) => {\n const database = this.getDatabaseObjectFromTarget(target);\n this.throwDatabaseOpenError(reject, database);\n resolve(database);\n };\n request.onupgradeneeded = ({ target }) => {\n const database = this.getDatabaseObjectFromTarget(target);\n this.throwDatabaseOpenError(reject, database);\n database?.createObjectStore(this.objectStoreName);\n };\n });\n }\n async setItem(key, value) {\n if (!this.db) {\n throw new Error(\"Database is not initialized\");\n }\n const transaction = this.db.transaction(this.objectStoreName, \"readwrite\");\n const objectStore = transaction.objectStore(this.objectStoreName);\n return new Promise((resolve, reject) => {\n const request = objectStore.put(value, key);\n request.onerror = reject;\n request.onsuccess = () => resolve();\n });\n }\n async getItem(key) {\n if (!this.db) {\n throw new Error(\"Database is not initialized\");\n }\n const transaction = this.db.transaction(this.objectStoreName, \"readonly\");\n const objectStore = transaction.objectStore(this.objectStoreName);\n return new Promise((resolve, reject) => {\n const request = objectStore.get(key);\n request.onerror = reject;\n request.onsuccess = () => resolve(request.result ?? null);\n });\n }\n async removeItem(key) {\n if (!this.db) {\n throw new Error(\"Database is not initialized\");\n }\n const transaction = this.db.transaction(this.objectStoreName, \"readwrite\");\n const objectStore = transaction.objectStore(this.objectStoreName);\n return new Promise((resolve, reject) => {\n const request = objectStore.delete(key);\n request.onerror = reject;\n request.onsuccess = () => resolve();\n });\n }\n async clear() {\n if (!this.db) {\n throw new Error(\"Database is not initialized\");\n }\n const transaction = this.db.transaction(this.objectStoreName, \"readwrite\");\n const objectStore = transaction.objectStore(this.objectStoreName);\n return new Promise((resolve, reject) => {\n const request = objectStore.clear();\n request.onerror = reject;\n request.onsuccess = () => resolve();\n });\n }\n}\n\n\n//# sourceURL=webpack://mainnet-js/./src/cache/IndexedDbCache.ts?");
88
+
89
+ /***/ }),
90
+
91
+ /***/ "./src/cache/MemoryCache.ts":
92
+ /*!**********************************!*\
93
+ !*** ./src/cache/MemoryCache.ts ***!
94
+ \**********************************/
95
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
96
+
97
+ eval("/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"MemoryCache\": () => (/* binding */ MemoryCache)\n/* harmony export */ });\nclass MemoryCache {\n constructor() {\n this.cache = {};\n }\n async init() {\n return;\n }\n async setItem(key, value) {\n this.cache[key] = value;\n }\n async getItem(key) {\n return this.cache[key] ?? null;\n }\n async removeItem(key) {\n delete this.cache[key];\n }\n async clear() {\n this.cache = {};\n }\n}\n\n\n//# sourceURL=webpack://mainnet-js/./src/cache/MemoryCache.ts?");
98
+
99
+ /***/ }),
100
+
101
+ /***/ "./src/cache/WebStorageCache.ts":
102
+ /*!**************************************!*\
103
+ !*** ./src/cache/WebStorageCache.ts ***!
104
+ \**************************************/
105
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
106
+
107
+ eval("/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"WebStorageCache\": () => (/* binding */ WebStorageCache)\n/* harmony export */ });\n// super thin wrapper around localStorage\nclass WebStorageCache {\n async init() {\n return;\n }\n async setItem(key, value) {\n localStorage.setItem(key, value);\n }\n async getItem(key) {\n return localStorage.getItem(key);\n }\n async removeItem(key) {\n localStorage.removeItem(key);\n }\n async clear() {\n localStorage.clear();\n }\n}\n\n\n//# sourceURL=webpack://mainnet-js/./src/cache/WebStorageCache.ts?");
108
+
109
+ /***/ }),
110
+
81
111
  /***/ "./src/chain.ts":
82
112
  /*!**********************!*\
83
113
  !*** ./src/chain.ts ***!
@@ -94,7 +124,7 @@ eval("/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harm
94
124
  \***********************/
95
125
  /***/ ((module, __webpack_exports__, __webpack_require__) => {
96
126
 
97
- 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 */ \"Config\": () => (/* binding */ Config)\n/* harmony export */ });\n/* harmony import */ var _scure_bip39_wordlists_english__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @scure/bip39/wordlists/english */ \"../../node_modules/@scure/bip39/esm/wordlists/english.js\");\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_1__ = __webpack_require__(/*! @bitauth/libauth */ \"../../node_modules/@bitauth/libauth/build/lib/format/hex.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @bitauth/libauth */ \"../../node_modules/@bitauth/libauth/build/lib/crypto/default-crypto-instances.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @bitauth/libauth */ \"../../node_modules/@bitauth/libauth/build/lib/format/utf8.js\");\nvar __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__]);\n_bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__ = (__webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__)[0];\n\n\n\nclass Config {\n // enforces all token-related methods to specify tokenaddr as recepient and change cashaddr\n static { this.EnforceCashTokenReceiptAddresses = false; }\n static { this.DefaultParentDerivationPath = \"m/44'/0'/0'\"; }\n static { this.DefaultIpfsGateway = \"https://dweb.link/ipfs/\"; }\n // default currency for balance and rate conversions\n static { this.DefaultCurrency = \"usd\"; }\n // caches the raw transactions in browser's local storage instead of memory\n static { this.UseLocalStorageCache = false; }\n static { this.DefaultWordlist = _scure_bip39_wordlists_english__WEBPACK_IMPORTED_MODULE_0__.wordlist; }\n static setIpfsGateway(ipfsGateway) {\n this.DefaultIpfsGateway = ipfsGateway;\n }\n static setWordlist(wordlist) {\n let checksum = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__.binToHex)(_bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__.sha256.hash((0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__.utf8ToBin)(wordlist.join(\" \"))));\n if (!Object.values(_constant_js__WEBPACK_IMPORTED_MODULE_4__.WORDLIST_CHECKSUMS).includes(checksum))\n throw Error(\"Error matching provided wordlist to a known list, see @scure/bip39/wordlists\");\n Config.DefaultWordlist = wordlist;\n }\n static getWordlist() {\n return [...Config.DefaultWordlist];\n }\n}\n\n__webpack_async_result__();\n} catch(e) { __webpack_async_result__(e); } });\n\n//# sourceURL=webpack://mainnet-js/./src/config.ts?");
127
+ 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 */ \"Config\": () => (/* binding */ Config)\n/* harmony export */ });\n/* harmony import */ var _scure_bip39_wordlists_english__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @scure/bip39/wordlists/english */ \"../../node_modules/@scure/bip39/esm/wordlists/english.js\");\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_1__ = __webpack_require__(/*! @bitauth/libauth */ \"../../node_modules/@bitauth/libauth/build/lib/format/hex.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @bitauth/libauth */ \"../../node_modules/@bitauth/libauth/build/lib/crypto/default-crypto-instances.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @bitauth/libauth */ \"../../node_modules/@bitauth/libauth/build/lib/format/utf8.js\");\nvar __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__]);\n_bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__ = (__webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__)[0];\n\n\n\nclass Config {\n // enforces all token-related methods to specify tokenaddr as recepient and change cashaddr\n static { this.EnforceCashTokenReceiptAddresses = false; }\n static { this.DefaultParentDerivationPath = \"m/44'/0'/0'\"; }\n static { this.DefaultIpfsGateway = \"https://dweb.link/ipfs/\"; }\n // default currency for balance and rate conversions\n static { this.DefaultCurrency = \"usd\"; }\n // caches the raw transactions in browser's local storage instead of memory\n static { this.UseLocalStorageCache = false; }\n // caches the raw transactions in browser's indexedDB instead of memory\n static { this.UseIndexedDBCache = false; }\n // caches the raw transactions in browser's memory\n static { this.UseMemoryCache = false; }\n static { this.DefaultWordlist = _scure_bip39_wordlists_english__WEBPACK_IMPORTED_MODULE_0__.wordlist; }\n static setIpfsGateway(ipfsGateway) {\n this.DefaultIpfsGateway = ipfsGateway;\n }\n static setWordlist(wordlist) {\n let checksum = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__.binToHex)(_bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__.sha256.hash((0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__.utf8ToBin)(wordlist.join(\" \"))));\n if (!Object.values(_constant_js__WEBPACK_IMPORTED_MODULE_4__.WORDLIST_CHECKSUMS).includes(checksum))\n throw Error(\"Error matching provided wordlist to a known list, see @scure/bip39/wordlists\");\n Config.DefaultWordlist = wordlist;\n }\n static getWordlist() {\n return [...Config.DefaultWordlist];\n }\n}\n\n__webpack_async_result__();\n} catch(e) { __webpack_async_result__(e); } });\n\n//# sourceURL=webpack://mainnet-js/./src/config.ts?");
98
128
 
99
129
  /***/ }),
100
130
 
@@ -154,7 +184,7 @@ eval("__webpack_require__.a(module, async (__webpack_handle_async_dependencies__
154
184
  \********************************************/
155
185
  /***/ ((module, __webpack_exports__, __webpack_require__) => {
156
186
 
157
- 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 */ \"getAddressHistory\": () => (/* binding */ getAddressHistory)\n/* harmony export */ });\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @bitauth/libauth */ \"../../node_modules/@bitauth/libauth/build/lib/message/transaction-encoding.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @bitauth/libauth */ \"../../node_modules/@bitauth/libauth/build/lib/format/hex.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 _bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @bitauth/libauth */ \"../../node_modules/@bitauth/libauth/build/lib/format/error.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 _util_convert_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../util/convert.js */ \"./src/util/convert.ts\");\nvar __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_bitauth_libauth__WEBPACK_IMPORTED_MODULE_0__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_4__, _util_convert_js__WEBPACK_IMPORTED_MODULE_5__]);\n([_bitauth_libauth__WEBPACK_IMPORTED_MODULE_0__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_4__, _util_convert_js__WEBPACK_IMPORTED_MODULE_5__] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);\n\n\nconst getAddressHistory = async ({ address, provider, unit = \"sat\", fromHeight = 0, toHeight = -1, start = 0, count = -1, }) => {\n if (count === -1) {\n count = 1e10;\n }\n const history = (await provider.getHistory(address, fromHeight, toHeight))\n .sort((a, b) => a.height <= 0 || b.height <= 0 ? a.height - b.height : b.height - a.height)\n .slice(start, start + count);\n // fill transaction timestamps by requesting headers from network and parsing them\n const heights = history\n .map((tx) => tx.height)\n .filter((height) => height > 0)\n .filter((value, index, array) => array.indexOf(value) === index);\n const timestampMap = (await Promise.all(heights.map(async (height) => [\n height,\n (await provider.getHeader(height, true)).timestamp,\n ]))).reduce((acc, [height, timestamp]) => ({ ...acc, [height]: timestamp }), {});\n // first load all transactions\n const historicTransactions = await Promise.all(history.map(async (tx) => {\n const txHex = (await provider.getRawTransaction(tx.tx_hash));\n const transactionCommon = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_0__.decodeTransaction)((0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__.hexToBin)(txHex));\n if (typeof transactionCommon === \"string\") {\n throw transactionCommon;\n }\n const transaction = transactionCommon;\n transaction.blockHeight = tx.height;\n transaction.timestamp = timestampMap[tx.height];\n transaction.hash = tx.tx_hash;\n transaction.size = txHex.length / 2;\n return transaction;\n }));\n // then load their prevout transactions\n const prevoutTransactionHashes = historicTransactions\n .map((tx) => tx.inputs.map((input) => (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__.binToHex)(input.outpointTransactionHash)))\n .flat()\n .filter((value, index, array) => array.indexOf(value) === index);\n const prevoutTransactionMap = (await Promise.all(prevoutTransactionHashes.map(async (hash) => {\n const txHex = (await provider.getRawTransaction(hash));\n const transaction = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_0__.decodeTransaction)((0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__.hexToBin)(txHex));\n if (typeof transaction === \"string\") {\n throw transaction;\n }\n return [hash, transaction];\n }))).reduce((acc, [hash, transaction]) => ({\n ...acc,\n [hash]: transaction,\n }), {});\n const decoded = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__.decodeCashAddress)(address);\n if (typeof decoded === \"string\") {\n throw decoded;\n }\n const addressCache = {};\n // map decoded transaction data to TransactionHistoryItem\n const historyItems = historicTransactions.map((tx) => {\n const result = {};\n let inputTotalValue = 0n;\n let outputTotalValue = 0n;\n result.inputs = tx.inputs.map((input) => {\n const prevoutTx = prevoutTransactionMap[(0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__.binToHex)(input.outpointTransactionHash)];\n if (!prevoutTx) {\n throw new Error(\"Could not find prevout transaction\");\n }\n const prevoutOutput = prevoutTx.outputs[input.outpointIndex];\n if (!prevoutOutput) {\n throw new Error(\"Could not find prevout output\");\n }\n const cached = addressCache[prevoutOutput.lockingBytecode];\n let address;\n if (!cached) {\n address = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__.assertSuccess)((0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_4__.lockingBytecodeToCashAddress)({\n bytecode: prevoutOutput.lockingBytecode,\n prefix: decoded.prefix,\n })).address;\n addressCache[prevoutOutput.lockingBytecode] = address;\n }\n else {\n address = cached;\n }\n inputTotalValue += prevoutOutput.valueSatoshis;\n return {\n address: address,\n value: Number(prevoutOutput.valueSatoshis),\n token: prevoutOutput.token\n ? {\n tokenId: (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__.binToHex)(prevoutOutput.token.category),\n amount: prevoutOutput.token.amount,\n capability: prevoutOutput.token.nft?.capability\n ? prevoutOutput.token.nft.capability\n : undefined,\n commitment: prevoutOutput.token.nft?.capability\n ? (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__.binToHex)(prevoutOutput.token.nft.commitment)\n : undefined,\n }\n : undefined,\n };\n });\n result.outputs = tx.outputs.map((output) => {\n const cached = addressCache[output.lockingBytecode];\n let address;\n if (!cached) {\n if (output.valueSatoshis === 0n) {\n address = `OP_RETURN: ${(0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__.binToHex)(output.lockingBytecode)}`;\n }\n else {\n address = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__.assertSuccess)((0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_4__.lockingBytecodeToCashAddress)({\n bytecode: output.lockingBytecode,\n prefix: decoded.prefix,\n })).address;\n addressCache[output.lockingBytecode] = address;\n }\n }\n else {\n address = cached;\n }\n outputTotalValue += output.valueSatoshis;\n return {\n address: address,\n value: Number(output.valueSatoshis),\n token: output.token\n ? {\n tokenId: (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__.binToHex)(output.token.category),\n amount: output.token.amount,\n capability: output.token.nft?.capability\n ? output.token.nft.capability\n : undefined,\n commitment: output.token.nft?.capability\n ? (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__.binToHex)(output.token.nft.commitment)\n : undefined,\n }\n : undefined,\n };\n });\n result.blockHeight = tx.blockHeight;\n result.timestamp = tx.timestamp;\n result.hash = tx.hash;\n result.size = tx.size;\n result.fee = Number(inputTotalValue - outputTotalValue);\n return result;\n });\n // compute value changes\n historyItems.forEach((tx) => {\n let satoshiBalance = 0;\n const ftTokenBalances = {};\n const nftTokenBalances = {};\n tx.inputs.forEach((input) => {\n if (input.address === address) {\n satoshiBalance -= input.value;\n if (input.token?.amount) {\n ftTokenBalances[input.token.tokenId] =\n (ftTokenBalances[input.token.tokenId] || BigInt(0)) -\n input.token.amount;\n }\n if (input.token?.capability) {\n nftTokenBalances[input.token.tokenId] =\n (nftTokenBalances[input.token.tokenId] || BigInt(0)) - 1n;\n }\n }\n });\n tx.outputs.forEach((output) => {\n if (output.address === address) {\n satoshiBalance += Number(output.value);\n if (output.token?.amount) {\n ftTokenBalances[output.token.tokenId] =\n (ftTokenBalances[output.token.tokenId] || BigInt(0)) +\n output.token.amount;\n }\n if (output.token?.capability) {\n nftTokenBalances[output.token.tokenId] =\n (nftTokenBalances[output.token.tokenId] || BigInt(0)) + 1n;\n }\n }\n });\n tx.valueChange = satoshiBalance;\n tx.tokenAmountChanges = Object.entries(ftTokenBalances).map(([tokenId, amount]) => ({\n tokenId,\n amount,\n nftAmount: BigInt(0),\n }));\n for (const [tokenId, nftAmount] of Object.entries(nftTokenBalances)) {\n const tokenChange = tx.tokenAmountChanges.find((tokenChange) => tokenChange.tokenId === tokenId);\n if (tokenChange) {\n tokenChange.nftAmount = nftAmount;\n }\n else {\n tx.tokenAmountChanges.push({\n tokenId,\n amount: BigInt(0),\n nftAmount,\n });\n }\n }\n });\n // order transactions in a way such that receives are always ordered before sends, per block\n historyItems.sort((a, b) => (a.blockHeight <= 0 || b.blockHeight <= 0\n ? a.blockHeight - b.blockHeight\n : b.blockHeight - a.blockHeight) || a.valueChange - b.valueChange);\n // backfill the balances\n let prevBalance = await provider.getBalance(address);\n let prevValueChange = 0;\n historyItems.forEach((tx) => {\n tx.balance = prevBalance - prevValueChange;\n prevBalance = tx.balance;\n prevValueChange = tx.valueChange;\n });\n // convert units if needed\n if (!unit.includes(\"sat\")) {\n for (const tx of historyItems) {\n for (const input of tx.inputs) {\n input.value = await (0,_util_convert_js__WEBPACK_IMPORTED_MODULE_5__.convert)(input.value, \"sat\", unit);\n }\n for (const output of tx.outputs) {\n output.value = await (0,_util_convert_js__WEBPACK_IMPORTED_MODULE_5__.convert)(output.value, \"sat\", unit);\n }\n tx.valueChange = await (0,_util_convert_js__WEBPACK_IMPORTED_MODULE_5__.convert)(tx.valueChange, \"sat\", unit);\n tx.balance = await (0,_util_convert_js__WEBPACK_IMPORTED_MODULE_5__.convert)(tx.balance, \"sat\", unit);\n }\n }\n return historyItems;\n};\n\n__webpack_async_result__();\n} catch(e) { __webpack_async_result__(e); } });\n\n//# sourceURL=webpack://mainnet-js/./src/history/electrumTransformer.ts?");
187
+ 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 */ \"getAddressHistory\": () => (/* binding */ getAddressHistory)\n/* harmony export */ });\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @bitauth/libauth */ \"../../node_modules/@bitauth/libauth/build/lib/message/transaction-encoding.js\");\n/* harmony import */ var _bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @bitauth/libauth */ \"../../node_modules/@bitauth/libauth/build/lib/format/hex.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 _bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @bitauth/libauth */ \"../../node_modules/@bitauth/libauth/build/lib/format/error.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 _bitauth_libauth__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @bitauth/libauth */ \"../../node_modules/@bitauth/libauth/build/lib/vm/instruction-sets/bch/2023/bch-2023-opcodes.js\");\n/* harmony import */ var _util_convert_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../util/convert.js */ \"./src/util/convert.ts\");\nvar __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_bitauth_libauth__WEBPACK_IMPORTED_MODULE_0__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_4__, _util_convert_js__WEBPACK_IMPORTED_MODULE_6__]);\n([_bitauth_libauth__WEBPACK_IMPORTED_MODULE_0__, _bitauth_libauth__WEBPACK_IMPORTED_MODULE_4__, _util_convert_js__WEBPACK_IMPORTED_MODULE_6__] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);\n\n\nconst getAddressHistory = async ({ address, provider, unit = \"sat\", fromHeight = 0, toHeight = -1, start = 0, count = -1, }) => {\n if (count === -1) {\n count = 1e10;\n }\n const history = (await provider.getHistory(address, fromHeight, toHeight))\n .sort((a, b) => a.height <= 0 || b.height <= 0 ? a.height - b.height : b.height - a.height)\n .slice(start, start + count);\n // fill transaction timestamps by requesting headers from network and parsing them\n const heights = history\n .map((tx) => tx.height)\n .filter((height) => height > 0)\n .filter((value, index, array) => array.indexOf(value) === index);\n const timestampMap = (await Promise.all(heights.map(async (height) => [\n height,\n (await provider.getHeader(height, true)).timestamp,\n ]))).reduce((acc, [height, timestamp]) => ({ ...acc, [height]: timestamp }), {});\n // first load all transactions\n const historicTransactions = await Promise.all(history.map(async (tx) => {\n const txHex = (await provider.getRawTransaction(tx.tx_hash));\n const transactionCommon = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_0__.decodeTransaction)((0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__.hexToBin)(txHex));\n if (typeof transactionCommon === \"string\") {\n throw transactionCommon;\n }\n const transaction = transactionCommon;\n transaction.blockHeight = tx.height;\n transaction.timestamp = timestampMap[tx.height];\n transaction.hash = tx.tx_hash;\n transaction.size = txHex.length / 2;\n return transaction;\n }));\n // then load their prevout transactions\n const prevoutTransactionHashes = historicTransactions\n .map((tx) => tx.inputs.map((input) => (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__.binToHex)(input.outpointTransactionHash)))\n .flat()\n .filter((value, index, array) => array.indexOf(value) === index);\n const prevoutTransactionMap = (await Promise.all(prevoutTransactionHashes.map(async (hash) => {\n const txHex = (await provider.getRawTransaction(hash));\n const transaction = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_0__.decodeTransaction)((0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__.hexToBin)(txHex));\n if (typeof transaction === \"string\") {\n throw transaction;\n }\n return [hash, transaction];\n }))).reduce((acc, [hash, transaction]) => ({\n ...acc,\n [hash]: transaction,\n }), {});\n const decoded = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_2__.decodeCashAddress)(address);\n if (typeof decoded === \"string\") {\n throw decoded;\n }\n const addressCache = {};\n // map decoded transaction data to TransactionHistoryItem\n const historyItems = historicTransactions.map((tx) => {\n const result = {};\n let inputTotalValue = 0n;\n let outputTotalValue = 0n;\n result.inputs = tx.inputs.map((input) => {\n const prevoutTx = prevoutTransactionMap[(0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__.binToHex)(input.outpointTransactionHash)];\n if (!prevoutTx) {\n throw new Error(\"Could not find prevout transaction\");\n }\n const prevoutOutput = prevoutTx.outputs[input.outpointIndex];\n if (!prevoutOutput) {\n throw new Error(\"Could not find prevout output\");\n }\n const cached = addressCache[prevoutOutput.lockingBytecode];\n let address;\n if (!cached) {\n address = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__.assertSuccess)((0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_4__.lockingBytecodeToCashAddress)({\n bytecode: prevoutOutput.lockingBytecode,\n prefix: decoded.prefix,\n })).address;\n addressCache[prevoutOutput.lockingBytecode] = address;\n }\n else {\n address = cached;\n }\n inputTotalValue += prevoutOutput.valueSatoshis;\n return {\n address: address,\n value: Number(prevoutOutput.valueSatoshis),\n token: prevoutOutput.token\n ? {\n tokenId: (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__.binToHex)(prevoutOutput.token.category),\n amount: prevoutOutput.token.amount,\n capability: prevoutOutput.token.nft?.capability\n ? prevoutOutput.token.nft.capability\n : undefined,\n commitment: prevoutOutput.token.nft?.capability\n ? (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__.binToHex)(prevoutOutput.token.nft.commitment)\n : undefined,\n }\n : undefined,\n };\n });\n result.outputs = tx.outputs.map((output) => {\n const cached = addressCache[output.lockingBytecode];\n let address;\n if (!cached) {\n if (output.lockingBytecode[0] === _bitauth_libauth__WEBPACK_IMPORTED_MODULE_5__.Opcodes.OP_RETURN) {\n address = `OP_RETURN: ${(0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__.binToHex)(output.lockingBytecode)}`;\n }\n else {\n address = (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_3__.assertSuccess)((0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_4__.lockingBytecodeToCashAddress)({\n bytecode: output.lockingBytecode,\n prefix: decoded.prefix,\n })).address;\n addressCache[output.lockingBytecode] = address;\n }\n }\n else {\n address = cached;\n }\n outputTotalValue += output.valueSatoshis;\n return {\n address: address,\n value: Number(output.valueSatoshis),\n token: output.token\n ? {\n tokenId: (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__.binToHex)(output.token.category),\n amount: output.token.amount,\n capability: output.token.nft?.capability\n ? output.token.nft.capability\n : undefined,\n commitment: output.token.nft?.capability\n ? (0,_bitauth_libauth__WEBPACK_IMPORTED_MODULE_1__.binToHex)(output.token.nft.commitment)\n : undefined,\n }\n : undefined,\n };\n });\n result.blockHeight = tx.blockHeight;\n result.timestamp = tx.timestamp;\n result.hash = tx.hash;\n result.size = tx.size;\n result.fee = Number(inputTotalValue - outputTotalValue);\n return result;\n });\n // compute value changes\n historyItems.forEach((tx) => {\n let satoshiBalance = 0;\n const ftTokenBalances = {};\n const nftTokenBalances = {};\n tx.inputs.forEach((input) => {\n if (input.address === address) {\n satoshiBalance -= input.value;\n if (input.token?.amount) {\n ftTokenBalances[input.token.tokenId] =\n (ftTokenBalances[input.token.tokenId] || BigInt(0)) -\n input.token.amount;\n }\n if (input.token?.capability) {\n nftTokenBalances[input.token.tokenId] =\n (nftTokenBalances[input.token.tokenId] || BigInt(0)) - 1n;\n }\n }\n });\n tx.outputs.forEach((output) => {\n if (output.address === address) {\n satoshiBalance += Number(output.value);\n if (output.token?.amount) {\n ftTokenBalances[output.token.tokenId] =\n (ftTokenBalances[output.token.tokenId] || BigInt(0)) +\n output.token.amount;\n }\n if (output.token?.capability) {\n nftTokenBalances[output.token.tokenId] =\n (nftTokenBalances[output.token.tokenId] || BigInt(0)) + 1n;\n }\n }\n });\n tx.valueChange = satoshiBalance;\n tx.tokenAmountChanges = Object.entries(ftTokenBalances).map(([tokenId, amount]) => ({\n tokenId,\n amount,\n nftAmount: BigInt(0),\n }));\n for (const [tokenId, nftAmount] of Object.entries(nftTokenBalances)) {\n const tokenChange = tx.tokenAmountChanges.find((tokenChange) => tokenChange.tokenId === tokenId);\n if (tokenChange) {\n tokenChange.nftAmount = nftAmount;\n }\n else {\n tx.tokenAmountChanges.push({\n tokenId,\n amount: BigInt(0),\n nftAmount,\n });\n }\n }\n });\n // order transactions in a way such that receives are always ordered before sends, per block\n historyItems.sort((a, b) => (a.blockHeight <= 0 || b.blockHeight <= 0\n ? a.blockHeight - b.blockHeight\n : b.blockHeight - a.blockHeight) || a.valueChange - b.valueChange);\n // backfill the balances\n let prevBalance = await provider.getBalance(address);\n let prevValueChange = 0;\n historyItems.forEach((tx) => {\n tx.balance = prevBalance - prevValueChange;\n prevBalance = tx.balance;\n prevValueChange = tx.valueChange;\n });\n // convert units if needed\n if (!unit.includes(\"sat\")) {\n for (const tx of historyItems) {\n for (const input of tx.inputs) {\n input.value = await (0,_util_convert_js__WEBPACK_IMPORTED_MODULE_6__.convert)(input.value, \"sat\", unit);\n }\n for (const output of tx.outputs) {\n output.value = await (0,_util_convert_js__WEBPACK_IMPORTED_MODULE_6__.convert)(output.value, \"sat\", unit);\n }\n tx.valueChange = await (0,_util_convert_js__WEBPACK_IMPORTED_MODULE_6__.convert)(tx.valueChange, \"sat\", unit);\n tx.balance = await (0,_util_convert_js__WEBPACK_IMPORTED_MODULE_6__.convert)(tx.balance, \"sat\", unit);\n }\n }\n return historyItems;\n};\n\n__webpack_async_result__();\n} catch(e) { __webpack_async_result__(e); } });\n\n//# sourceURL=webpack://mainnet-js/./src/history/electrumTransformer.ts?");
158
188
 
159
189
  /***/ }),
160
190
 
@@ -234,7 +264,7 @@ eval("__webpack_require__.a(module, async (__webpack_handle_async_dependencies__
234
264
  \************************************************/
235
265
  /***/ ((module, __webpack_exports__, __webpack_require__) => {
236
266
 
237
- 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_1__ = __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 _util_transaction_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../util/transaction.js */ \"./src/util/transaction.ts\");\n/* harmony import */ var _config_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../config.js */ \"./src/config.ts\");\n/* harmony import */ var _util_header_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../util/header.js */ \"./src/util/header.ts\");\nvar __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_config_js__WEBPACK_IMPORTED_MODULE_2__, _util_header_js__WEBPACK_IMPORTED_MODULE_3__, _util_transaction_js__WEBPACK_IMPORTED_MODULE_4__]);\n([_config_js__WEBPACK_IMPORTED_MODULE_2__, _util_header_js__WEBPACK_IMPORTED_MODULE_3__, _util_transaction_js__WEBPACK_IMPORTED_MODULE_4__] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);\n\n\n\n\n\n\nclass ElectrumNetworkProvider {\n constructor(electrum, network = _interface_js__WEBPACK_IMPORTED_MODULE_1__.Network.MAINNET, manualConnectionManagement) {\n this.network = network;\n this.manualConnectionManagement = manualConnectionManagement;\n this.subscriptions = 0;\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, \"include_tokens\"));\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: BigInt(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 static { this.rawHeaderCache = {}; }\n async getHeader(height, verbose = false) {\n const key = `header-${this.network}-${height}-${verbose}`;\n if (_config_js__WEBPACK_IMPORTED_MODULE_2__.Config.UseLocalStorageCache) {\n const cached = localStorage.getItem(key);\n if (cached) {\n return verbose ? (0,_util_header_js__WEBPACK_IMPORTED_MODULE_3__.decodeHeader)(JSON.parse(cached)) : JSON.parse(cached);\n }\n }\n else {\n ElectrumNetworkProvider.rawTransactionCache[key];\n }\n const result = (await this.performRequest(\"blockchain.header.get\", height));\n if (_config_js__WEBPACK_IMPORTED_MODULE_2__.Config.UseLocalStorageCache) {\n localStorage.setItem(key, JSON.stringify(result));\n }\n else {\n ElectrumNetworkProvider.rawTransactionCache[key] = result;\n }\n return verbose ? (0,_util_header_js__WEBPACK_IMPORTED_MODULE_3__.decodeHeader)(result) : result;\n }\n async getBlockHeight() {\n return (await this.performRequest(\"blockchain.headers.get_tip\"))\n .height;\n }\n static { this.rawTransactionCache = {}; }\n async getRawTransaction(txHash, verbose = false, loadInputValues = false) {\n const key = `tx-${this.network}-${txHash}-${verbose}-${loadInputValues}`;\n if (_config_js__WEBPACK_IMPORTED_MODULE_2__.Config.UseLocalStorageCache) {\n const cached = localStorage.getItem(key);\n if (cached) {\n return verbose ? JSON.parse(cached) : cached;\n }\n }\n else {\n ElectrumNetworkProvider.rawTransactionCache[key];\n }\n try {\n const transaction = (await this.performRequest(\"blockchain.transaction.get\", txHash, verbose));\n if (_config_js__WEBPACK_IMPORTED_MODULE_2__.Config.UseLocalStorageCache) {\n localStorage.setItem(key, verbose\n ? JSON.stringify(transaction)\n : transaction);\n }\n else {\n ElectrumNetworkProvider.rawTransactionCache[key] = transaction;\n }\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, fromHeight = 0, toHeight = -1) {\n const result = (await this.performRequest(\"blockchain.address.get_history\", cashaddr, fromHeight, toHeight));\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 // watch for block headers and block height, if `skipCurrentHeight` is set, the notification about current block will not arrive\n watchBlocks(callback, skipCurrentHeight = true) {\n let acknowledged = !skipCurrentHeight;\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.connectPromise;\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}\n\n__webpack_async_result__();\n} catch(e) { __webpack_async_result__(e); } });\n\n//# sourceURL=webpack://mainnet-js/./src/network/ElectrumNetworkProvider.ts?");
267
+ 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_5__ = __webpack_require__(/*! ../interface.js */ \"./src/interface.ts\");\n/* harmony import */ var _util_delay_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../util/delay.js */ \"./src/util/delay.ts\");\n/* harmony import */ var _util_transaction_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../util/transaction.js */ \"./src/util/transaction.ts\");\n/* harmony import */ var _config_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../config.js */ \"./src/config.ts\");\n/* harmony import */ var _util_header_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../util/header.js */ \"./src/util/header.ts\");\n/* harmony import */ var _cache_IndexedDbCache_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../cache/IndexedDbCache.js */ \"./src/cache/IndexedDbCache.ts\");\n/* harmony import */ var _cache_WebStorageCache_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../cache/WebStorageCache.js */ \"./src/cache/WebStorageCache.ts\");\n/* harmony import */ var _cache_MemoryCache_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../cache/MemoryCache.js */ \"./src/cache/MemoryCache.ts\");\nvar __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_config_js__WEBPACK_IMPORTED_MODULE_1__, _util_header_js__WEBPACK_IMPORTED_MODULE_6__, _util_transaction_js__WEBPACK_IMPORTED_MODULE_7__]);\n([_config_js__WEBPACK_IMPORTED_MODULE_1__, _util_header_js__WEBPACK_IMPORTED_MODULE_6__, _util_transaction_js__WEBPACK_IMPORTED_MODULE_7__] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);\n\n\n\n\n\n\n\n\n\nclass ElectrumNetworkProvider {\n get cache() {\n if (!_config_js__WEBPACK_IMPORTED_MODULE_1__.Config.UseMemoryCache &&\n !_config_js__WEBPACK_IMPORTED_MODULE_1__.Config.UseLocalStorageCache &&\n !_config_js__WEBPACK_IMPORTED_MODULE_1__.Config.UseIndexedDBCache) {\n this._cache = undefined;\n return this._cache;\n }\n if (_config_js__WEBPACK_IMPORTED_MODULE_1__.Config.UseMemoryCache && !(this._cache instanceof _cache_MemoryCache_js__WEBPACK_IMPORTED_MODULE_2__.MemoryCache)) {\n this._cache = new _cache_IndexedDbCache_js__WEBPACK_IMPORTED_MODULE_3__.IndexedDbCache();\n return this._cache;\n }\n if (_config_js__WEBPACK_IMPORTED_MODULE_1__.Config.UseLocalStorageCache &&\n !(this._cache instanceof _cache_WebStorageCache_js__WEBPACK_IMPORTED_MODULE_4__.WebStorageCache)) {\n this._cache = new _cache_WebStorageCache_js__WEBPACK_IMPORTED_MODULE_4__.WebStorageCache();\n return this._cache;\n }\n if (_config_js__WEBPACK_IMPORTED_MODULE_1__.Config.UseIndexedDBCache && !(this._cache instanceof _cache_IndexedDbCache_js__WEBPACK_IMPORTED_MODULE_3__.IndexedDbCache)) {\n this._cache = new _cache_IndexedDbCache_js__WEBPACK_IMPORTED_MODULE_3__.IndexedDbCache();\n return this._cache;\n }\n return this._cache;\n }\n constructor(electrum, network = _interface_js__WEBPACK_IMPORTED_MODULE_5__.Network.MAINNET, manualConnectionManagement) {\n this.network = network;\n this.manualConnectionManagement = manualConnectionManagement;\n this.subscriptions = 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, \"include_tokens\"));\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: BigInt(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 getHeader(height, verbose = false) {\n const key = `header-${this.network}-${height}-${verbose}`;\n if (this.cache) {\n const cached = await this.cache.getItem(key);\n if (cached) {\n return verbose ? (0,_util_header_js__WEBPACK_IMPORTED_MODULE_6__.decodeHeader)(JSON.parse(cached)) : JSON.parse(cached);\n }\n }\n const result = (await this.performRequest(\"blockchain.header.get\", height));\n if (this.cache) {\n await this.cache.setItem(key, JSON.stringify(result));\n }\n return verbose ? (0,_util_header_js__WEBPACK_IMPORTED_MODULE_6__.decodeHeader)(result) : result;\n }\n async getBlockHeight() {\n return (await this.performRequest(\"blockchain.headers.get_tip\"))\n .height;\n }\n async getRawTransaction(txHash, verbose = false, loadInputValues = false) {\n const key = `tx-${this.network}-${txHash}-${verbose}-${loadInputValues}`;\n if (this.cache) {\n const cached = await this.cache.getItem(key);\n if (cached) {\n return verbose ? JSON.parse(cached) : cached;\n }\n }\n try {\n const transaction = (await this.performRequest(\"blockchain.transaction.get\", txHash, verbose));\n if (this.cache) {\n await this.cache.setItem(key, verbose\n ? JSON.stringify(transaction)\n : transaction);\n }\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_7__.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, fromHeight = 0, toHeight = -1) {\n const result = (await this.performRequest(\"blockchain.address.get_history\", cashaddr, fromHeight, toHeight));\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 // watch for block headers and block height, if `skipCurrentHeight` is set, the notification about current block will not arrive\n watchBlocks(callback, skipCurrentHeight = true) {\n let acknowledged = !skipCurrentHeight;\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 await this.cache?.init();\n return await this.connectPromise;\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_8__.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}\n\n__webpack_async_result__();\n} catch(e) { __webpack_async_result__(e); } });\n\n//# sourceURL=webpack://mainnet-js/./src/network/ElectrumNetworkProvider.ts?");
238
268
 
239
269
  /***/ }),
240
270
 
@@ -254,7 +284,7 @@ eval("__webpack_require__.a(module, async (__webpack_handle_async_dependencies__
254
284
  \*********************************/
255
285
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
256
286
 
257
- eval("/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"ELECTRUM_CASH_PROTOCOL_VERSION\": () => (/* binding */ ELECTRUM_CASH_PROTOCOL_VERSION),\n/* harmony export */ \"clusterParams\": () => (/* binding */ clusterParams),\n/* harmony export */ \"mainnetServers\": () => (/* binding */ mainnetServers),\n/* harmony export */ \"networkTickerMap\": () => (/* binding */ networkTickerMap),\n/* harmony export */ \"regtestServers\": () => (/* binding */ regtestServers),\n/* harmony export */ \"testnetServers\": () => (/* binding */ testnetServers)\n/* harmony export */ });\n/* unused harmony export defaultServers */\n/* harmony import */ var electrum_cash__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! electrum-cash */ \"../../node_modules/electrum-cash/dist/index.mjs.js\");\n\nconst ELECTRUM_CASH_PROTOCOL_VERSION = \"1.5\";\nconst networkTickerMap = {\n mainnet: \"BCH\",\n testnet: \"tBCH\",\n regtest: \"rBCH\",\n};\nconst mainnetServers = [\n \"wss://bch.imaginary.cash:50004\",\n //\"wss://blackie.c3-soft.com:50004\",\n // \"wss://electrum.imaginary.cash:50004\",\n // \"wss://fulcrum.fountainhead.cash\",\n];\n// export const testnetServers = [\n// // \"wss://tbch.loping.net:60004\",\n// \"wss://blackie.c3-soft.com:60004\",\n// // \"wss://testnet.bitcoincash.network:60004\",\n// //,\"wss://unavailable.invalid:50004\"\n// ];\n// testnet4\n// export const testnetServers = [\n// //\"wss://t4fork.c3-soft.com:61004\",\n// \"wss://testnet4.imaginary.cash:50004\",\n// //,\"wss://unavailable.invalid:50004\"\n// ];\n// chipnet\nconst testnetServers = [\n // \"wss://chipnet.imaginary.cash:50004\",\n //\"wss://blackie.c3-soft.com:64004\", // chipnet with protocol 1.5.0\n \"wss://chipnet.bch.ninja:50004\"\n];\nconst regtestServers = [\"ws://127.0.0.1:60003\"];\nconst defaultServers = {\n mainnet: mainnetServers,\n testnet: testnetServers,\n regtest: regtestServers,\n};\nconst clusterParams = {\n mainnet: {\n confidence: 1,\n distribution: 1,\n order: electrum_cash__WEBPACK_IMPORTED_MODULE_0__.ClusterOrder.RANDOM,\n timeout: 45000,\n },\n testnet: {\n confidence: 1,\n distribution: 1,\n order: electrum_cash__WEBPACK_IMPORTED_MODULE_0__.ClusterOrder.RANDOM,\n timeout: 30000,\n },\n regtest: {\n confidence: 1,\n distribution: 1,\n order: electrum_cash__WEBPACK_IMPORTED_MODULE_0__.ClusterOrder.PRIORITY,\n timeout: 3000,\n },\n};\n\n\n//# sourceURL=webpack://mainnet-js/./src/network/constant.ts?");
287
+ eval("/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"ELECTRUM_CASH_PROTOCOL_VERSION\": () => (/* binding */ ELECTRUM_CASH_PROTOCOL_VERSION),\n/* harmony export */ \"clusterParams\": () => (/* binding */ clusterParams),\n/* harmony export */ \"mainnetServers\": () => (/* binding */ mainnetServers),\n/* harmony export */ \"networkTickerMap\": () => (/* binding */ networkTickerMap),\n/* harmony export */ \"regtestServers\": () => (/* binding */ regtestServers),\n/* harmony export */ \"testnetServers\": () => (/* binding */ testnetServers)\n/* harmony export */ });\n/* unused harmony export defaultServers */\n/* harmony import */ var electrum_cash__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! electrum-cash */ \"../../node_modules/electrum-cash/dist/index.mjs.js\");\n\nconst ELECTRUM_CASH_PROTOCOL_VERSION = \"1.5\";\nconst networkTickerMap = {\n mainnet: \"BCH\",\n testnet: \"tBCH\",\n regtest: \"rBCH\",\n};\nconst mainnetServers = [\n \"wss://bch.imaginary.cash:50004\",\n //\"wss://blackie.c3-soft.com:50004\",\n // \"wss://electrum.imaginary.cash:50004\",\n // \"wss://fulcrum.fountainhead.cash\",\n];\n// export const testnetServers = [\n// // \"wss://tbch.loping.net:60004\",\n// \"wss://blackie.c3-soft.com:60004\",\n// // \"wss://testnet.bitcoincash.network:60004\",\n// //,\"wss://unavailable.invalid:50004\"\n// ];\n// testnet4\n// export const testnetServers = [\n// //\"wss://t4fork.c3-soft.com:61004\",\n// \"wss://testnet4.imaginary.cash:50004\",\n// //,\"wss://unavailable.invalid:50004\"\n// ];\n// chipnet\nconst testnetServers = [\n // \"wss://chipnet.imaginary.cash:50004\",\n //\"wss://blackie.c3-soft.com:64004\", // chipnet with protocol 1.5.0\n \"wss://chipnet.bch.ninja:50004\",\n];\nconst regtestServers = [\"ws://127.0.0.1:60003\"];\nconst defaultServers = {\n mainnet: mainnetServers,\n testnet: testnetServers,\n regtest: regtestServers,\n};\nconst clusterParams = {\n mainnet: {\n confidence: 1,\n distribution: 1,\n order: electrum_cash__WEBPACK_IMPORTED_MODULE_0__.ClusterOrder.RANDOM,\n timeout: 45000,\n },\n testnet: {\n confidence: 1,\n distribution: 1,\n order: electrum_cash__WEBPACK_IMPORTED_MODULE_0__.ClusterOrder.RANDOM,\n timeout: 30000,\n },\n regtest: {\n confidence: 1,\n distribution: 1,\n order: electrum_cash__WEBPACK_IMPORTED_MODULE_0__.ClusterOrder.PRIORITY,\n timeout: 3000,\n },\n};\n\n\n//# sourceURL=webpack://mainnet-js/./src/network/constant.ts?");
258
288
 
259
289
  /***/ }),
260
290
 
@@ -0,0 +1,14 @@
1
+ import { CacheProvider } from "./interface";
2
+ export declare class IndexedDbCache implements CacheProvider {
3
+ private objectStoreName;
4
+ private db;
5
+ constructor(objectStoreName?: string);
6
+ private getDatabaseObjectFromTarget;
7
+ private throwDatabaseOpenError;
8
+ init(): Promise<void>;
9
+ setItem(key: string, value: string): Promise<void>;
10
+ getItem(key: string): Promise<string | null>;
11
+ removeItem(key: string): Promise<void>;
12
+ clear(): Promise<void>;
13
+ }
14
+ //# sourceMappingURL=IndexedDbCache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IndexedDbCache.d.ts","sourceRoot":"","sources":["../../../src/cache/IndexedDbCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C,qBAAa,cAAe,YAAW,aAAa;IAIhD,OAAO,CAAC,eAAe;IAHzB,OAAO,CAAC,EAAE,CAA4B;gBAG5B,eAAe,GAAE,MAAuC;IAKlE,OAAO,CAAC,2BAA2B;IAYnC,OAAO,CAAC,sBAAsB;IAaxB,IAAI;IA0BJ,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBlD,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAgB5C,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBtC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAe7B"}
@@ -0,0 +1,86 @@
1
+ // super thin wrapper around indexedDB, compatible with localStorage API
2
+ export class IndexedDbCache {
3
+ constructor(objectStoreName = "ElectrumNetworkProviderCache") {
4
+ this.objectStoreName = objectStoreName;
5
+ this.db = null;
6
+ this.objectStoreName = objectStoreName;
7
+ }
8
+ getDatabaseObjectFromTarget(target) {
9
+ if (!target) {
10
+ return null;
11
+ }
12
+ const targetWithType = target;
13
+ return targetWithType.result;
14
+ }
15
+ throwDatabaseOpenError(reject, database) {
16
+ if (!database) {
17
+ reject(new Error("Something went wrong and the database transaction was not opened."));
18
+ }
19
+ }
20
+ async init() {
21
+ const db = indexedDB.open("ElectrumNetworkProviderCache", 1);
22
+ this.db = await new Promise((resolve, reject) => {
23
+ const request = db;
24
+ request.onerror = reject;
25
+ request.onsuccess = ({ target }) => {
26
+ const database = this.getDatabaseObjectFromTarget(target);
27
+ this.throwDatabaseOpenError(reject, database);
28
+ resolve(database);
29
+ };
30
+ request.onupgradeneeded = ({ target }) => {
31
+ const database = this.getDatabaseObjectFromTarget(target);
32
+ this.throwDatabaseOpenError(reject, database);
33
+ database?.createObjectStore(this.objectStoreName);
34
+ };
35
+ });
36
+ }
37
+ async setItem(key, value) {
38
+ if (!this.db) {
39
+ throw new Error("Database is not initialized");
40
+ }
41
+ const transaction = this.db.transaction(this.objectStoreName, "readwrite");
42
+ const objectStore = transaction.objectStore(this.objectStoreName);
43
+ return new Promise((resolve, reject) => {
44
+ const request = objectStore.put(value, key);
45
+ request.onerror = reject;
46
+ request.onsuccess = () => resolve();
47
+ });
48
+ }
49
+ async getItem(key) {
50
+ if (!this.db) {
51
+ throw new Error("Database is not initialized");
52
+ }
53
+ const transaction = this.db.transaction(this.objectStoreName, "readonly");
54
+ const objectStore = transaction.objectStore(this.objectStoreName);
55
+ return new Promise((resolve, reject) => {
56
+ const request = objectStore.get(key);
57
+ request.onerror = reject;
58
+ request.onsuccess = () => resolve(request.result ?? null);
59
+ });
60
+ }
61
+ async removeItem(key) {
62
+ if (!this.db) {
63
+ throw new Error("Database is not initialized");
64
+ }
65
+ const transaction = this.db.transaction(this.objectStoreName, "readwrite");
66
+ const objectStore = transaction.objectStore(this.objectStoreName);
67
+ return new Promise((resolve, reject) => {
68
+ const request = objectStore.delete(key);
69
+ request.onerror = reject;
70
+ request.onsuccess = () => resolve();
71
+ });
72
+ }
73
+ async clear() {
74
+ if (!this.db) {
75
+ throw new Error("Database is not initialized");
76
+ }
77
+ const transaction = this.db.transaction(this.objectStoreName, "readwrite");
78
+ const objectStore = transaction.objectStore(this.objectStoreName);
79
+ return new Promise((resolve, reject) => {
80
+ const request = objectStore.clear();
81
+ request.onerror = reject;
82
+ request.onsuccess = () => resolve();
83
+ });
84
+ }
85
+ }
86
+ //# sourceMappingURL=IndexedDbCache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IndexedDbCache.js","sourceRoot":"","sources":["../../../src/cache/IndexedDbCache.ts"],"names":[],"mappings":"AAEA,wEAAwE;AACxE,MAAM,OAAO,cAAc;IAGzB,YACU,kBAA0B,8BAA8B;QAAxD,oBAAe,GAAf,eAAe,CAAyC;QAH1D,OAAE,GAAuB,IAAI,CAAC;QAKpC,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;IACzC,CAAC;IAEO,2BAA2B,CACjC,MAA0B;QAE1B,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,cAAc,GAAG,MAA0B,CAAC;QAElD,OAAO,cAAc,CAAC,MAAM,CAAC;IAC/B,CAAC;IAEO,sBAAsB,CAC5B,MAAiC,EACjC,QAA4B;QAE5B,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,CACJ,IAAI,KAAK,CACP,mEAAmE,CACpE,CACF,CAAC;QACJ,CAAC;IACH,CAAC;IAED,KAAK,CAAC,IAAI;QACR,MAAM,EAAE,GAAG,SAAS,CAAC,IAAI,CAAC,8BAA8B,EAAE,CAAC,CAAC,CAAC;QAE7D,IAAI,CAAC,EAAE,GAAG,MAAM,IAAI,OAAO,CAAc,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC3D,MAAM,OAAO,GAAG,EAAE,CAAC;YAEnB,OAAO,CAAC,OAAO,GAAG,MAAM,CAAC;YAEzB,OAAO,CAAC,SAAS,GAAG,CAAC,EAAE,MAAM,EAAS,EAAE,EAAE;gBACxC,MAAM,QAAQ,GAAG,IAAI,CAAC,2BAA2B,CAAC,MAAM,CAAC,CAAC;gBAE1D,IAAI,CAAC,sBAAsB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;gBAE9C,OAAO,CAAC,QAAuB,CAAC,CAAC;YACnC,CAAC,CAAC;YAEF,OAAO,CAAC,eAAe,GAAG,CAAC,EAAE,MAAM,EAAyB,EAAE,EAAE;gBAC9D,MAAM,QAAQ,GAAG,IAAI,CAAC,2BAA2B,CAAC,MAAM,CAAC,CAAC;gBAE1D,IAAI,CAAC,sBAAsB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;gBAE9C,QAAQ,EAAE,iBAAiB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;YACpD,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,GAAW,EAAE,KAAa;QACtC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;QACjD,CAAC;QAED,MAAM,WAAW,GAAG,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,eAAe,EAAE,WAAW,CAAC,CAAC;QAC3E,MAAM,WAAW,GAAG,WAAW,CAAC,WAAW,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QAElE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,MAAM,OAAO,GAAG,WAAW,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;YAE5C,OAAO,CAAC,OAAO,GAAG,MAAM,CAAC;YACzB,OAAO,CAAC,SAAS,GAAG,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC;QACtC,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,GAAW;QACvB,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;QACjD,CAAC;QAED,MAAM,WAAW,GAAG,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;QAC1E,MAAM,WAAW,GAAG,WAAW,CAAC,WAAW,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QAElE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,MAAM,OAAO,GAAG,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAErC,OAAO,CAAC,OAAO,GAAG,MAAM,CAAC;YACzB,OAAO,CAAC,SAAS,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,CAAC;QAC5D,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,GAAW;QAC1B,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;QACjD,CAAC;QAED,MAAM,WAAW,GAAG,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,eAAe,EAAE,WAAW,CAAC,CAAC;QAC3E,MAAM,WAAW,GAAG,WAAW,CAAC,WAAW,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QAElE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,MAAM,OAAO,GAAG,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAExC,OAAO,CAAC,OAAO,GAAG,MAAM,CAAC;YACzB,OAAO,CAAC,SAAS,GAAG,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC;QACtC,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;QACjD,CAAC;QAED,MAAM,WAAW,GAAG,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,eAAe,EAAE,WAAW,CAAC,CAAC;QAC3E,MAAM,WAAW,GAAG,WAAW,CAAC,WAAW,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QAElE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,MAAM,OAAO,GAAG,WAAW,CAAC,KAAK,EAAE,CAAC;YAEpC,OAAO,CAAC,OAAO,GAAG,MAAM,CAAC;YACzB,OAAO,CAAC,SAAS,GAAG,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC;QACtC,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,9 @@
1
+ import { CacheProvider } from "./interface";
2
+ export declare abstract class KeyValueCache implements CacheProvider {
3
+ abstract init(): Promise<void>;
4
+ abstract setItem(key: string, value: string): Promise<void>;
5
+ abstract getItem(key: string): Promise<string | null>;
6
+ abstract removeItem(key: string): Promise<void>;
7
+ abstract clear(): Promise<void>;
8
+ }
9
+ //# sourceMappingURL=KeyValueCache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KeyValueCache.d.ts","sourceRoot":"","sources":["../../../src/cache/KeyValueCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,8BAAsB,aAAc,YAAW,aAAa;IAC1D,QAAQ,CAAC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAC9B,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAC3D,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IACrD,QAAQ,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAC/C,QAAQ,CAAC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAChC"}
@@ -0,0 +1,3 @@
1
+ export class KeyValueCache {
2
+ }
3
+ //# sourceMappingURL=KeyValueCache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KeyValueCache.js","sourceRoot":"","sources":["../../../src/cache/KeyValueCache.ts"],"names":[],"mappings":"AAEA,MAAM,OAAgB,aAAa;CAMlC"}
@@ -0,0 +1,9 @@
1
+ export declare class MemoryCache {
2
+ cache: Record<string, string>;
3
+ init(): Promise<void>;
4
+ setItem(key: string, value: string): Promise<void>;
5
+ getItem(key: string): Promise<string>;
6
+ removeItem(key: string): Promise<void>;
7
+ clear(): Promise<void>;
8
+ }
9
+ //# sourceMappingURL=MemoryCache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MemoryCache.d.ts","sourceRoot":"","sources":["../../../src/cache/MemoryCache.ts"],"names":[],"mappings":"AAAA,qBAAa,WAAW;IACf,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAM;IACpC,IAAI;IAGJ,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAGlC,OAAO,CAAC,GAAG,EAAE,MAAM;IAGnB,UAAU,CAAC,GAAG,EAAE,MAAM;IAGtB,KAAK;CAGZ"}
@@ -0,0 +1,21 @@
1
+ export class MemoryCache {
2
+ constructor() {
3
+ this.cache = {};
4
+ }
5
+ async init() {
6
+ return;
7
+ }
8
+ async setItem(key, value) {
9
+ this.cache[key] = value;
10
+ }
11
+ async getItem(key) {
12
+ return this.cache[key] ?? null;
13
+ }
14
+ async removeItem(key) {
15
+ delete this.cache[key];
16
+ }
17
+ async clear() {
18
+ this.cache = {};
19
+ }
20
+ }
21
+ //# sourceMappingURL=MemoryCache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MemoryCache.js","sourceRoot":"","sources":["../../../src/cache/MemoryCache.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,WAAW;IAAxB;QACS,UAAK,GAA2B,EAAE,CAAC;IAgB5C,CAAC;IAfC,KAAK,CAAC,IAAI;QACR,OAAO;IACT,CAAC;IACD,KAAK,CAAC,OAAO,CAAC,GAAW,EAAE,KAAa;QACtC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IAC1B,CAAC;IACD,KAAK,CAAC,OAAO,CAAC,GAAW;QACvB,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC;IACjC,CAAC;IACD,KAAK,CAAC,UAAU,CAAC,GAAW;QAC1B,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;IACD,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;IAClB,CAAC;CACF"}
@@ -0,0 +1,9 @@
1
+ import { CacheProvider } from "./interface";
2
+ export declare class WebStorageCache implements CacheProvider {
3
+ init(): Promise<void>;
4
+ setItem(key: string, value: string): Promise<void>;
5
+ getItem(key: string): Promise<string | null>;
6
+ removeItem(key: string): Promise<void>;
7
+ clear(): Promise<void>;
8
+ }
9
+ //# sourceMappingURL=WebStorageCache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WebStorageCache.d.ts","sourceRoot":"","sources":["../../../src/cache/WebStorageCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C,qBAAa,eAAgB,YAAW,aAAa;IAC7C,IAAI;IAIJ,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlD,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAI5C,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAItC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B"}
@@ -0,0 +1,19 @@
1
+ // super thin wrapper around localStorage
2
+ export class WebStorageCache {
3
+ async init() {
4
+ return;
5
+ }
6
+ async setItem(key, value) {
7
+ localStorage.setItem(key, value);
8
+ }
9
+ async getItem(key) {
10
+ return localStorage.getItem(key);
11
+ }
12
+ async removeItem(key) {
13
+ localStorage.removeItem(key);
14
+ }
15
+ async clear() {
16
+ localStorage.clear();
17
+ }
18
+ }
19
+ //# sourceMappingURL=WebStorageCache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WebStorageCache.js","sourceRoot":"","sources":["../../../src/cache/WebStorageCache.ts"],"names":[],"mappings":"AAEA,yCAAyC;AACzC,MAAM,OAAO,eAAe;IAC1B,KAAK,CAAC,IAAI;QACR,OAAO;IACT,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,GAAW,EAAE,KAAa;QACtC,YAAY,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,GAAW;QACvB,OAAO,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,GAAW;QAC1B,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,KAAK;QACT,YAAY,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ export * from "./interface.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cache/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./interface.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cache/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1,8 @@
1
+ export interface CacheProvider {
2
+ init(): Promise<void>;
3
+ setItem(key: string, value: string): Promise<void>;
4
+ getItem(key: string): Promise<string | null>;
5
+ removeItem(key: string): Promise<void>;
6
+ clear(): Promise<void>;
7
+ }
8
+ //# sourceMappingURL=interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../src/cache/interface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACtB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnD,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC7C,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interface.js","sourceRoot":"","sources":["../../../src/cache/interface.ts"],"names":[],"mappings":""}
@@ -4,6 +4,8 @@ export declare class Config {
4
4
  static DefaultIpfsGateway: string;
5
5
  static DefaultCurrency: string;
6
6
  static UseLocalStorageCache: boolean;
7
+ static UseIndexedDBCache: boolean;
8
+ static UseMemoryCache: boolean;
7
9
  private static DefaultWordlist;
8
10
  static setIpfsGateway(ipfsGateway: string): void;
9
11
  static setWordlist(wordlist: string[]): void;
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAIA,qBAAa,MAAM;IAEjB,MAAM,CAAC,gCAAgC,UAAS;IAChD,MAAM,CAAC,2BAA2B,SAAiB;IACnD,MAAM,CAAC,kBAAkB,SAA6B;IAEtD,MAAM,CAAC,eAAe,SAAS;IAE/B,MAAM,CAAC,oBAAoB,UAAS;IACpC,OAAO,CAAC,MAAM,CAAC,eAAe,CAAW;WAE3B,cAAc,CAAC,WAAW,EAAE,MAAM;WAIlC,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE;WAS9B,WAAW,IAAI,MAAM,EAAE;CAGtC"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAIA,qBAAa,MAAM;IAEjB,MAAM,CAAC,gCAAgC,UAAS;IAChD,MAAM,CAAC,2BAA2B,SAAiB;IACnD,MAAM,CAAC,kBAAkB,SAA6B;IAEtD,MAAM,CAAC,eAAe,SAAS;IAE/B,MAAM,CAAC,oBAAoB,UAAS;IAEpC,MAAM,CAAC,iBAAiB,UAAS;IAEjC,MAAM,CAAC,cAAc,UAAS;IAC9B,OAAO,CAAC,MAAM,CAAC,eAAe,CAAW;WAE3B,cAAc,CAAC,WAAW,EAAE,MAAM;WAIlC,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE;WAS9B,WAAW,IAAI,MAAM,EAAE;CAGtC"}
@@ -10,6 +10,10 @@ export class Config {
10
10
  static { this.DefaultCurrency = "usd"; }
11
11
  // caches the raw transactions in browser's local storage instead of memory
12
12
  static { this.UseLocalStorageCache = false; }
13
+ // caches the raw transactions in browser's indexedDB instead of memory
14
+ static { this.UseIndexedDBCache = false; }
15
+ // caches the raw transactions in browser's memory
16
+ static { this.UseMemoryCache = false; }
13
17
  static { this.DefaultWordlist = english; }
14
18
  static setIpfsGateway(ipfsGateway) {
15
19
  this.DefaultIpfsGateway = ipfsGateway;
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,OAAO,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE/D,MAAM,OAAO,MAAM;IACjB,2FAA2F;aACpF,qCAAgC,GAAG,KAAK,CAAC;aACzC,gCAA2B,GAAG,aAAa,CAAC;aAC5C,uBAAkB,GAAG,yBAAyB,CAAC;IACtD,oDAAoD;aAC7C,oBAAe,GAAG,KAAK,CAAC;IAC/B,2EAA2E;aACpE,yBAAoB,GAAG,KAAK,CAAC;aACrB,oBAAe,GAAG,OAAO,CAAC;IAElC,MAAM,CAAC,cAAc,CAAC,WAAmB;QAC9C,IAAI,CAAC,kBAAkB,GAAG,WAAW,CAAC;IACxC,CAAC;IAEM,MAAM,CAAC,WAAW,CAAC,QAAkB;QAC1C,IAAI,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACpE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;YACvD,MAAM,KAAK,CACT,8EAA8E,CAC/E,CAAC;QACJ,MAAM,CAAC,eAAe,GAAG,QAAQ,CAAC;IACpC,CAAC;IAEM,MAAM,CAAC,WAAW;QACvB,OAAO,CAAC,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;IACrC,CAAC"}
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,OAAO,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE/D,MAAM,OAAO,MAAM;IACjB,2FAA2F;aACpF,qCAAgC,GAAG,KAAK,CAAC;aACzC,gCAA2B,GAAG,aAAa,CAAC;aAC5C,uBAAkB,GAAG,yBAAyB,CAAC;IACtD,oDAAoD;aAC7C,oBAAe,GAAG,KAAK,CAAC;IAC/B,2EAA2E;aACpE,yBAAoB,GAAG,KAAK,CAAC;IACpC,uEAAuE;aAChE,sBAAiB,GAAG,KAAK,CAAC;IACjC,kDAAkD;aAC3C,mBAAc,GAAG,KAAK,CAAC;aACf,oBAAe,GAAG,OAAO,CAAC;IAElC,MAAM,CAAC,cAAc,CAAC,WAAmB;QAC9C,IAAI,CAAC,kBAAkB,GAAG,WAAW,CAAC;IACxC,CAAC;IAEM,MAAM,CAAC,WAAW,CAAC,QAAkB;QAC1C,IAAI,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACpE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;YACvD,MAAM,KAAK,CACT,8EAA8E,CAC/E,CAAC;QACJ,MAAM,CAAC,eAAe,GAAG,QAAQ,CAAC;IACpC,CAAC;IAEM,MAAM,CAAC,WAAW;QACvB,OAAO,CAAC,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;IACrC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"electrumTransformer.d.ts","sourceRoot":"","sources":["../../../src/history/electrumTransformer.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,eAAe,MAAM,+BAA+B,CAAC;AAG5D,OAAO,EAAE,sBAAsB,EAAY,MAAM,gBAAgB,CAAC;AASlE,eAAO,MAAM,iBAAiB,qEAQ3B;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,eAAe,CAAC;IAC1B,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,KAAG,OAAO,CAAC,sBAAsB,EAAE,CAuRnC,CAAC"}
1
+ {"version":3,"file":"electrumTransformer.d.ts","sourceRoot":"","sources":["../../../src/history/electrumTransformer.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,eAAe,MAAM,+BAA+B,CAAC;AAG5D,OAAO,EAAE,sBAAsB,EAAY,MAAM,gBAAgB,CAAC;AASlE,eAAO,MAAM,iBAAiB,qEAQ3B;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,eAAe,CAAC;IAC1B,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,KAAG,OAAO,CAAC,sBAAsB,EAAE,CAuRnC,CAAC"}
@@ -1,4 +1,4 @@
1
- import { binToHex, decodeTransaction, hexToBin, lockingBytecodeToCashAddress, decodeCashAddress, assertSuccess, } from "@bitauth/libauth";
1
+ import { binToHex, decodeTransaction, hexToBin, lockingBytecodeToCashAddress, decodeCashAddress, assertSuccess, Opcodes, } from "@bitauth/libauth";
2
2
  import { convert } from "../util/convert.js";
3
3
  export const getAddressHistory = async ({ address, provider, unit = "sat", fromHeight = 0, toHeight = -1, start = 0, count = -1, }) => {
4
4
  if (count === -1) {
@@ -99,7 +99,7 @@ export const getAddressHistory = async ({ address, provider, unit = "sat", fromH
99
99
  const cached = addressCache[output.lockingBytecode];
100
100
  let address;
101
101
  if (!cached) {
102
- if (output.valueSatoshis === 0n) {
102
+ if (output.lockingBytecode[0] === Opcodes.OP_RETURN) {
103
103
  address = `OP_RETURN: ${binToHex(output.lockingBytecode)}`;
104
104
  }
105
105
  else {