UNPKG

nexa-wallet-sdk

Version:

Wallet SDK for the Nexa blockchain

1,159 lines (1,095 loc) 144 kB
var $l50U0$libnexats = require("libnexa-ts"); var $l50U0$bip39 = require("bip39"); var $l50U0$vgrunnerelectrumcash = require("@vgrunner/electrum-cash"); var $l50U0$jsbigdecimal = require("js-big-decimal"); function $parcel$export(e, n, v, s) { Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true}); } var $parcel$global = globalThis; function $parcel$defineInteropFlag(a) { Object.defineProperty(a, '__esModule', {value: true, configurable: true}); } function $parcel$interopDefault(a) { return a && a.__esModule ? a.default : a; } var $parcel$modules = {}; var $parcel$inits = {}; var parcelRequire = $parcel$global["parcelRequire3d58"]; if (parcelRequire == null) { parcelRequire = function(id) { if (id in $parcel$modules) { return $parcel$modules[id].exports; } if (id in $parcel$inits) { var init = $parcel$inits[id]; delete $parcel$inits[id]; var module = {id: id, exports: {}}; $parcel$modules[id] = module; init.call(module.exports, module, module.exports); return module.exports; } var err = new Error("Cannot find module '" + id + "'"); err.code = 'MODULE_NOT_FOUND'; throw err; }; parcelRequire.register = function register(id, init) { $parcel$inits[id] = init; }; $parcel$global["parcelRequire3d58"] = parcelRequire; } var parcelRegister = parcelRequire.register; parcelRegister("kNPhA", function(module, exports) { $parcel$export(module.exports, "default", () => $f25029ea39a3086e$export$2e2bcd8739ae039); var $cpiMl = parcelRequire("cpiMl"); var $j6iK9 = parcelRequire("j6iK9"); /** Detect free variable `exports`. */ var freeExports = exports && !exports.nodeType && exports; /** Detect free variable `module`. */ var freeModule = freeExports && true && module && !module.nodeType && module; /** Detect the popular CommonJS extension `module.exports`. */ var moduleExports = freeModule && freeModule.exports === freeExports; /** Built-in value references. */ var Buffer = moduleExports ? (0, $cpiMl.default).Buffer : undefined; /* Built-in method references for those with the same name as other `lodash` methods. */ var nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined; /** * Checks if `value` is a buffer. * * @static * @memberOf _ * @since 4.3.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is a buffer, else `false`. * @example * * _.isBuffer(new Buffer(2)); * // => true * * _.isBuffer(new Uint8Array(2)); * // => false */ var isBuffer = nativeIsBuffer || (0, $j6iK9.default); var $f25029ea39a3086e$export$2e2bcd8739ae039 = isBuffer; }); parcelRegister("cpiMl", function(module, exports) { $parcel$export(module.exports, "default", () => $908662eb8e7c9a57$export$2e2bcd8739ae039); var $hYTRB = parcelRequire("hYTRB"); /** Detect free variable `self`. */ var $908662eb8e7c9a57$var$freeSelf = typeof self == 'object' && self && self.Object === Object && self; /** Used as a reference to the global object. */ var $908662eb8e7c9a57$var$root = (0, $hYTRB.default) || $908662eb8e7c9a57$var$freeSelf || Function('return this')(); var $908662eb8e7c9a57$export$2e2bcd8739ae039 = $908662eb8e7c9a57$var$root; }); parcelRegister("hYTRB", function(module, exports) { $parcel$export(module.exports, "default", () => $d1735f9d9792bc22$export$2e2bcd8739ae039); /** Detect free variable `global` from Node.js. */ var $d1735f9d9792bc22$var$freeGlobal = typeof $parcel$global == 'object' && $parcel$global && $parcel$global.Object === Object && $parcel$global; var $d1735f9d9792bc22$export$2e2bcd8739ae039 = $d1735f9d9792bc22$var$freeGlobal; }); parcelRegister("j6iK9", function(module, exports) { $parcel$export(module.exports, "default", () => $de7d1de29f9a7741$export$2e2bcd8739ae039); /** * This method returns `false`. * * @static * @memberOf _ * @since 4.13.0 * @category Util * @returns {boolean} Returns `false`. * @example * * _.times(2, _.stubFalse); * // => [false, false] */ function $de7d1de29f9a7741$var$stubFalse() { return false; } var $de7d1de29f9a7741$export$2e2bcd8739ae039 = $de7d1de29f9a7741$var$stubFalse; }); $parcel$defineInteropFlag(module.exports); $parcel$export(module.exports, "default", () => $56b18ab116ff33bd$export$2e2bcd8739ae039); $parcel$export(module.exports, "Wallet", () => $b76d3bd5024ccfc0$export$2e2bcd8739ae039); $parcel$export(module.exports, "WatchOnlyWallet", () => $f4ad400261a08cba$export$2e2bcd8739ae039); $parcel$export(module.exports, "AccountType", () => $0d59d2bcffd646c5$export$b8ca5fa4899cbfc7); $parcel$export(module.exports, "TxTokenType", () => $0d59d2bcffd646c5$export$dcc1fb6ad5308e56); $parcel$export(module.exports, "isValidNexaAddress", () => $0d59d2bcffd646c5$export$8d986bd2866fe6ab); $parcel$export(module.exports, "ValidationUtils", () => $a635077caedb9044$export$2e2bcd8739ae039); $parcel$export(module.exports, "BaseAccount", () => $f8a48da5c0b6346a$export$c54c8796e94a37a0); $parcel$export(module.exports, "DefaultAccount", () => $1c49a4fffc97409b$export$2e2bcd8739ae039); $parcel$export(module.exports, "DappAccount", () => $cf960f437fe63027$export$2e2bcd8739ae039); $parcel$export(module.exports, "VaultAccount", () => $0b557605c0e99621$export$2e2bcd8739ae039); $parcel$export(module.exports, "AccountStore", () => $7fcf3b163a95e69a$export$2e2bcd8739ae039); $parcel$export(module.exports, "WalletTransactionCreator", () => $e1896e59040fa3c5$export$2e2bcd8739ae039); $parcel$export(module.exports, "WatchOnlyTransactionCreator", () => $2ce5b75d10954bb1$export$2e2bcd8739ae039); $parcel$export(module.exports, "rostrumProvider", () => $b5bfd17fdf06d231$export$eaa49f0478d81b9d); $parcel$export(module.exports, "AccountKeysUtils", () => $4d68f29c39c1a3e4$export$94f569bf4eb0f6f6); // @ts-ignore var $2dd241e44b9dc3c2$exports = {}; $2dd241e44b9dc3c2$exports = JSON.parse("{\"name\":\"nexa-wallet-sdk\",\"version\":\"0.3.3\",\"type\":\"module\",\"source\":\"src/index.ts\",\"types\":\"dist/index.d.ts\",\"main\":\"dist/index.cjs\",\"module\":\"dist/index.mjs\",\"browser\":\"dist/index.web.mjs\",\"exports\":{\"types\":\"./dist/index.d.ts\",\"node\":{\"import\":\"./dist/index.mjs\",\"require\":\"./dist/index.cjs\"},\"browser\":\"./dist/index.web.mjs\",\"default\":\"./dist/index.mjs\"},\"scripts\":{\"build\":\"parcel build\",\"lint\":\"eslint .\",\"fix-lint\":\"eslint --fix .\",\"dev\":\"parcel watch\",\"test\":\"vitest run\",\"clean\":\"rm -rf dist .parcel-cache\",\"docs\":\"typedoc\"},\"repository\":{\"type\":\"git\",\"url\":\"git+ssh://git@gitlab.com/nexa/wallet-sdk-ts.git\"},\"keywords\":[\"nexa\",\"wallet\",\"web3\",\"crypto\",\"dapp\",\"walletcomms\",\"walletsdk\"],\"contributors\":[{\"name\":\"Dolaned\"},{\"name\":\"Griffith\"},{\"name\":\"Vgrunner\"},{\"name\":\"myendy\"}],\"author\":\"Dolaned\",\"license\":\"MIT\",\"bugs\":{\"url\":\"https://gitlab.com/nexa/wallet-sdk-ts/issues\"},\"homepage\":\"https://gitlab.com/nexa/wallet-sdk-ts#readme\",\"description\":\"Wallet SDK for the Nexa blockchain\",\"devDependencies\":{\"@parcel/packager-ts\":\"^2.15.4\",\"@parcel/transformer-typescript-types\":\"^2.15.4\",\"@types/lodash-es\":\"^4.17.12\",\"@types/node\":\"^22.13.1\",\"eslint\":\"^9.20.1\",\"parcel\":\"^2.15.4\",\"typedoc\":\"^0.28.7\",\"typedoc-plugin-markdown\":\"^4.7.0\",\"typedoc-plugin-rename-defaults\":\"^0.7.3\",\"typescript\":\"^5.8.3\",\"typescript-eslint\":\"^8.24.1\",\"vitest\":\"^3.0.8\"},\"targets\":{\"main\":{\"context\":\"node\",\"outputFormat\":\"commonjs\",\"distDir\":\"dist\",\"isLibrary\":true,\"includeNodeModules\":[\"lodash-es\"]},\"module\":{\"context\":\"node\",\"outputFormat\":\"esmodule\",\"distDir\":\"dist\",\"isLibrary\":true},\"browser\":{\"context\":\"browser\",\"outputFormat\":\"esmodule\",\"distDir\":\"dist\",\"isLibrary\":true}},\"dependencies\":{\"@vgrunner/electrum-cash\":\"^2.0.12\",\"bip39\":\"^3.1.0\",\"js-big-decimal\":\"^2.2.0\",\"libnexa-ts\":\"^1.0.5\",\"lodash-es\":\"^4.17.21\"},\"files\":[\"dist\"],\"directories\":{\"test\":\"tests\"},\"@parcel/resolver-default\":{\"packageExports\":true}}"); const $95d1e8196bc3f78b$export$1f6f962b0b96558 = { WS: 'ws', WSS: 'wss', TCP: "tcp", TCP_TLS: "tcp_tls" }; class $b5bfd17fdf06d231$export$ba81aefc89aef50c { constructor(){} /** * Get Rostum Server Version */ async getVersion() { return await this.execute('server.version'); } /** * Get the block tip of the network / chain we are currently connected to */ async getBlockTip() { return await this.execute('blockchain.headers.tip'); } /** * Get the nexa balance of an address without the token balances * @param address */ async getBalance(address) { return await this.execute('blockchain.address.get_balance', address, 'exclude_tokens'); } /** * Get The transaction history for an address * @param address */ async getTransactionHistory(address) { return await this.execute('blockchain.address.get_history', address); } /** * Get the block height or block has of when the address was first used * @param address */ async getFirstUse(address) { return await this.execute('blockchain.address.get_first_use', address); } /** * Get a single transaction object * @param id * @param verbose */ async getTransaction(id, verbose = true) { return await this.execute('blockchain.transaction.get', id, verbose); } /** * Get a single unspent output including group data * @param outpoint */ async getUtxo(outpoint) { return await this.execute('blockchain.utxo.get', outpoint); } /** * Get Utxos only containing nexa information * @param address */ async getNexaUtxos(address) { return await this.execute('blockchain.address.listunspent', address, 'exclude_tokens'); } /** * Get all the utxo's for a token at an address * @param address * @param token */ async getTokenUtxos(address, token) { let listunspent = await this.execute('token.address.listunspent', address, null, token); return listunspent.unspent; } /** * Get the token balances for an address * @param address * @param token */ async getTokensBalance(address, token) { if (token) return await this.execute('token.address.get_balance', address, null, token); return await this.execute('token.address.get_balance', address); } /** * Get the token genesis for a token * @param token */ async getTokenGenesis(token) { return await this.execute('token.genesis.info', token); } /** * Subscribe to address call back notifications, handy for updating the user when they receive nexa or tokens in * their wallet * @param addresses * @param callback */ async subscribeToAddresses(addresses, callback) { for (const addr of addresses)await this.client?.subscribe(callback, 'blockchain.address.subscribe', addr); } /** * Unsubscribe from address notifications to prevent memory leaks * @param addresses * @param callback */ async unsubscribeFromAddresses(addresses, callback) { for (const addr of addresses)await this.client?.unsubscribe(callback, 'blockchain.address.subscribe', addr); } /** * Broadcast a presigned transaction hash * @param txHex */ async broadcast(txHex) { return await this.execute('blockchain.transaction.broadcast', txHex); } /** * Get the latency of the server connection */ async getLatency() { try { let start = Date.now(); let res = await this.getBlockTip(); if (res) return Date.now() - start; return 0; } catch { return 0; } } /** * Create initial connection with the rostrum server * @param netOrParams - Network identifier or RostrumParams object * @param params - RostrumParams object (for backward compatibility) * @param electrumClient - Optional pre-configured ElectrumClient instance */ async connect(netOrParams, params, electrumClient) { try { let connectionParams; // Handle backward compatibility: connect(params) or connect(network, params) if (netOrParams && typeof netOrParams === 'object' && 'host' in netOrParams && 'port' in netOrParams && 'scheme' in netOrParams) // First parameter is RostrumParams connectionParams = netOrParams; else if (params) // Second parameter contains RostrumParams, ignore network connectionParams = params; else { // Use network to determine default params const network = netOrParams ? (0, $l50U0$libnexats.Networks).get(netOrParams) : (0, $l50U0$libnexats.Networks).mainnet; if (network === (0, $l50U0$libnexats.Networks).mainnet) connectionParams = { host: 'electrum.nexa.org', port: 20004, scheme: (0, $95d1e8196bc3f78b$export$1f6f962b0b96558).WSS }; else if (network === (0, $l50U0$libnexats.Networks).testnet) connectionParams = { host: 'testnet-electrum.nexa.org', port: 30004, scheme: (0, $95d1e8196bc3f78b$export$1f6f962b0b96558).WSS }; else // Default fallback for other networks (like regtest) connectionParams = { host: 'localhost', port: 30004, scheme: (0, $95d1e8196bc3f78b$export$1f6f962b0b96558).WS }; } if (electrumClient) { this.client = electrumClient; if (this.client.connection.status == (0, $l50U0$vgrunnerelectrumcash.ConnectionStatus).DISCONNECTED) await this.client.connect(); } else { this.client = new (0, $l50U0$vgrunnerelectrumcash.ElectrumClient)("com.nexa.wallet-sdk", "1.4.3", connectionParams.host, connectionParams.port, connectionParams.scheme, 30000, 10000, true); await this.client.connect(); } } catch (e) { if (e instanceof Error) console.info(e.message); else console.error(e); throw e; } } /** * Disconnect from the rostrum server * @param force */ async disconnect(force) { try { return await this.client.disconnect(force); } catch (e) { console.log(e); return false; } } /** * internal function to call commands against the rostrum API * @param method * @param parameters * @private */ async execute(method, ...parameters) { let res = await this.client.request(method, ...parameters); if (res instanceof Error) throw res; return res; } } const $b5bfd17fdf06d231$export$eaa49f0478d81b9d = new $b5bfd17fdf06d231$export$ba81aefc89aef50c(); /** * Checks if `value` is `null` or `undefined`. * * @static * @memberOf _ * @since 4.0.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is nullish, else `false`. * @example * * _.isNil(null); * // => true * * _.isNil(void 0); * // => true * * _.isNil(NaN); * // => false */ function $54dde1e65fb8e5b8$var$isNil(value) { return value == null; } var $54dde1e65fb8e5b8$export$2e2bcd8739ae039 = $54dde1e65fb8e5b8$var$isNil; class $f8a48da5c0b6346a$export$c54c8796e94a37a0 { get transactions() { return this._transactions; } constructor(_bip44Account){ this._tokenBalances = {}; this._transactions = new Map(); this._bip44Account = _bip44Account; this._balance = { confirmed: 0, unconfirmed: 0 }; this._tokenBalances = {}; } get balance() { return this._balance; } set balance(value) { this._balance = value; } get tokenBalances() { return this._tokenBalances; } set tokenBalances(value) { this._tokenBalances = value; } async fetchAndClassifyTransactions(transactionAddress, fromHeight) { const transactions = await (0, $0d59d2bcffd646c5$export$a2ed4b531376a5a4)([ transactionAddress ], fromHeight ?? 0); const txPromises = Array.from(transactions.txs.values()).map((tx)=>(0, $0d59d2bcffd646c5$export$9c6f4f51acbc89b9)(tx, [ transactionAddress ])); const txEntities = await Promise.all(txPromises); for (let txEntity of txEntities)this.transactions.set(txEntity.txId, txEntity); return this.transactions; } } class $cf960f437fe63027$export$2e2bcd8739ae039 extends (0, $f8a48da5c0b6346a$export$c54c8796e94a37a0) { constructor(bip44Account, accountIndex, addressKey){ super(bip44Account); this._accountIndex = accountIndex; this._accountKey = addressKey; } // this is used in AccountStore.ts to get the key to be used in the map for this account getAccountStoreKey() { return String(this._bip44Account + '.' + this._accountIndex); } getAccountType() { return (0, $0d59d2bcffd646c5$export$b8ca5fa4899cbfc7).DAPP_ACCOUNT; } getNewAddress() { return this._accountKey.address; } getNewChangeAddress() { return this.getNewAddress(); } get accountIndexes() { return { rIndex: this._accountIndex, cIndex: 0 }; } get accountKeys() { return { receiveKeys: [ this._accountKey ], changeKeys: [] // Empty for single-key accounts }; } async loadBalances() { let balances = await (0, $0d59d2bcffd646c5$export$9e38d26dbd7c33f4)([ this._accountKey ]); let tokenBalances = [ this._accountKey ].map((k)=>k.tokensBalance); super.balance = (0, $0d59d2bcffd646c5$export$a26005fb5b8d1e4a)(balances); super.tokenBalances = (0, $0d59d2bcffd646c5$export$dec515296f176dbe)(tokenBalances); } getKeyFromAddress(address) { if (address !== this._accountKey.address) throw new Error(`Address ${address} does not belong to this account`); return this._accountKey; } async getTransactions(fromHeight, address) { const transactionAddress = address ?? this._accountKey.address; return this.fetchAndClassifyTransactions(transactionAddress, fromHeight); } getAddresses() { return [ this._accountKey ]; } hasChangeAddresses() { return false; } getPrimaryAddressKey() { return this._accountKey; } } class $1c49a4fffc97409b$export$2e2bcd8739ae039 extends (0, $f8a48da5c0b6346a$export$c54c8796e94a37a0) { constructor(bip44Account, accountIndexes, accountKeys){ super(bip44Account); if (accountIndexes.rIndex < 0) throw new Error(`Can not create nexa account with an rindex of ${accountIndexes.rIndex}. must be >= 0.`); if (accountIndexes.cIndex < 0) throw new Error(`Can not create nexa account with an cindex of ${accountIndexes.cIndex}. must be >= 0.`); this._accountIndexes = accountIndexes; this._accountKeys = accountKeys; } // this is used in AccountStore.ts to get the key to be used in the map for this account getAccountStoreKey() { return String(this._bip44Account); } getAccountType() { return (0, $0d59d2bcffd646c5$export$b8ca5fa4899cbfc7).NEXA_ACCOUNT; } getNewAddress() { return this._accountKeys.receiveKeys[this._accountKeys.receiveKeys.length - 1]?.address ?? ''; } getNewChangeAddress() { return this._accountKeys.changeKeys[this._accountKeys.changeKeys.length - 1]?.address ?? ''; } get accountIndexes() { return this._accountIndexes; } get accountKeys() { return this._accountKeys; } async loadBalances() { let balances = await (0, $0d59d2bcffd646c5$export$9e38d26dbd7c33f4)(this._accountKeys.receiveKeys.concat(this._accountKeys.changeKeys)); let tokenBalances = this._accountKeys.receiveKeys.concat(this._accountKeys.changeKeys).map((k)=>k.tokensBalance); super.balance = (0, $0d59d2bcffd646c5$export$a26005fb5b8d1e4a)(balances); super.tokenBalances = (0, $0d59d2bcffd646c5$export$dec515296f176dbe)(tokenBalances); } getKeyFromAddress(address) { const allKeys = this._accountKeys.receiveKeys.concat(this._accountKeys.changeKeys); const keyFound = allKeys.find((key)=>key.address === address); return keyFound; } async getTransactions(fromHeight, address) { let receiveAddresses = this.accountKeys.receiveKeys.map((ak)=>ak.address); let changeAddresses = this.accountKeys.changeKeys.map((ak)=>ak.address); let allAddresses = receiveAddresses.concat(changeAddresses); // If specific address provided, only fetch for that address if (address != null) { const transactions = await (0, $0d59d2bcffd646c5$export$a2ed4b531376a5a4)([ address ], fromHeight ?? 0); const txPromises = Array.from(transactions.txs.values()).map((tx)=>(0, $0d59d2bcffd646c5$export$9c6f4f51acbc89b9)(tx, allAddresses)); const txEntities = await Promise.all(txPromises); for (let txEntity of txEntities)this.transactions.set(txEntity.txId, txEntity); return this.transactions; } // Fetch from both receive and change addresses let rTxs = (0, $0d59d2bcffd646c5$export$a2ed4b531376a5a4)(receiveAddresses, fromHeight ?? 0); let cTxs = (0, $0d59d2bcffd646c5$export$a2ed4b531376a5a4)(changeAddresses, fromHeight ?? 0); let [rData, cData] = await Promise.all([ rTxs, cTxs ]); // Combine transaction data, avoiding duplicates let txHistory = rData.txs; for (let tx of cData.txs.values())txHistory.set(tx.tx_hash, tx); // Classify all transactions in parallel const txPromises = Array.from(txHistory.values()).map((tx)=>(0, $0d59d2bcffd646c5$export$9c6f4f51acbc89b9)(tx, allAddresses)); const txEntities = await Promise.all(txPromises); for (let txEntity of txEntities)this.transactions.set(txEntity.txId, txEntity); return this.transactions; } getAddresses() { return this._accountKeys.receiveKeys.concat(this._accountKeys.changeKeys); } hasChangeAddresses() { return true; // BIP44 accounts always support change addresses } getPrimaryAddressKey() { // For DefaultAccount, return the first receive key as the primary key if (this._accountKeys.receiveKeys.length === 0) throw new Error("No receive keys available in account"); return this._accountKeys.receiveKeys[0]; } } class $0b557605c0e99621$export$2e2bcd8739ae039 extends (0, $f8a48da5c0b6346a$export$c54c8796e94a37a0) { constructor(bip44Account, accountIndex, addressKey){ super(bip44Account); this._accountIndex = accountIndex; this._accountKey = addressKey; } // this is used in AccountStore.ts to get the key to be used in the map for this account getAccountStoreKey() { return String(this._bip44Account + '.' + this._accountIndex); } getAccountType() { return (0, $0d59d2bcffd646c5$export$b8ca5fa4899cbfc7).VAULT_ACCOUNT; } getNewAddress() { return this._accountKey.address; } getNewChangeAddress() { return this.getNewAddress(); } get accountIndexes() { return { rIndex: this._accountIndex, cIndex: 0 }; } get accountKeys() { return { receiveKeys: [ this._accountKey ], changeKeys: [] // Empty for single-key accounts }; } async loadBalances() { let balances = await (0, $0d59d2bcffd646c5$export$9e38d26dbd7c33f4)([ this._accountKey ]); let tokenBalances = [ this._accountKey ].map((k)=>k.tokensBalance); super.balance = (0, $0d59d2bcffd646c5$export$a26005fb5b8d1e4a)(balances); super.tokenBalances = (0, $0d59d2bcffd646c5$export$dec515296f176dbe)(tokenBalances); } getKeyFromAddress(address) { if (address !== this._accountKey.address) throw new Error(`Address ${address} does not belong to this account`); return this._accountKey; } async getTransactions(fromHeight, address) { const transactionAddress = address ?? this._accountKey.address; return this.fetchAndClassifyTransactions(transactionAddress, fromHeight); } getAddresses() { return [ this._accountKey ]; } hasChangeAddresses() { return false; } getPrimaryAddressKey() { return this._accountKey; } } const $bc5ca2c06b1affa3$export$8ba128bc85947a2a = 9223372036854775807n; function $bc5ca2c06b1affa3$export$78d0476e8d098ba7() { return Math.floor(Date.now() / 1000); } function $bc5ca2c06b1affa3$export$c8733ae29fb53302(arg) { return !arg || arg.length === 0; } function $bc5ca2c06b1affa3$export$78e516cc94be797b(amount, decimals) { let val = new (0, ($parcel$interopDefault($l50U0$jsbigdecimal)))(amount).divide(new (0, ($parcel$interopDefault($l50U0$jsbigdecimal)))(Math.pow(10, decimals)), decimals).getPrettyValue(); if (val.match(/\./)) val = val.replace(/\.?0+$/, ''); return val; } function $bc5ca2c06b1affa3$export$9ad78026dec58d6(amount, decimals) { return new (0, ($parcel$interopDefault($l50U0$jsbigdecimal)))(amount).multiply(new (0, ($parcel$interopDefault($l50U0$jsbigdecimal)))(Math.pow(10, decimals))).getValue(); } function $bc5ca2c06b1affa3$export$23010fd5dda8dec1(address) { if ((0, $l50U0$libnexats.CommonUtils).isHexa(address)) return Buffer.from(address, 'hex'); return (0, $l50U0$libnexats.Address).fromString(address).data; } function $bc5ca2c06b1affa3$export$254a5c7330bbfd41(token) { if ((0, $l50U0$libnexats.CommonUtils).isHexa(token)) return token; return $bc5ca2c06b1affa3$export$23010fd5dda8dec1(token).toString('hex'); } var $0d59d2bcffd646c5$export$dcc1fb6ad5308e56 = /*#__PURE__*/ function(TxTokenType) { TxTokenType[TxTokenType["NO_GROUP"] = 0] = "NO_GROUP"; TxTokenType[TxTokenType["CREATE"] = 1] = "CREATE"; TxTokenType[TxTokenType["MINT"] = 2] = "MINT"; TxTokenType[TxTokenType["MELT"] = 3] = "MELT"; TxTokenType[TxTokenType["RENEW"] = 4] = "RENEW"; TxTokenType[TxTokenType["TRANSFER"] = 5] = "TRANSFER"; return TxTokenType; }({}); var $0d59d2bcffd646c5$export$b8ca5fa4899cbfc7 = /*#__PURE__*/ function(AccountType) { AccountType[AccountType["NEXA_ACCOUNT"] = 0] = "NEXA_ACCOUNT"; AccountType[AccountType["VAULT_ACCOUNT"] = 1] = "VAULT_ACCOUNT"; AccountType[AccountType["DAPP_ACCOUNT"] = 2] = "DAPP_ACCOUNT"; return AccountType; }({}); function $0d59d2bcffd646c5$export$8d986bd2866fe6ab(address, network, type = (0, $l50U0$libnexats.AddressType).PayToScriptTemplate) { return (0, $l50U0$libnexats.Address).isValid(address, network, type); } function $0d59d2bcffd646c5$export$11f4ae2b4ff9633d(mnemonic, passphrase) { const seed = $l50U0$bip39.mnemonicToSeedSync(mnemonic, passphrase); const masterKey = (0, $l50U0$libnexats.HDPrivateKey).fromSeed(seed); return masterKey.deriveChild(44, true).deriveChild(29223, true); } function $0d59d2bcffd646c5$export$b3a12d67e2f5f8c9(masterKey, account) { return masterKey.deriveChild(account, true); } function $0d59d2bcffd646c5$export$d6e8eb22902c6b88(accountKey, fromRIndex, rIndex, fromCIndex, cIndex) { if (fromRIndex < 0) throw new Error(`Can not generate keys with fromRIndex ${fromRIndex}. must be >= 0.`); if (fromCIndex < 0) throw new Error(`Can not generate keys with fromCIndex ${fromCIndex}. must be >= 0.`); let receive = accountKey.deriveChild(0, false); let change = accountKey.deriveChild(1, false); let rKeys = [], cKeys = []; for(let index = fromRIndex; index < rIndex; index++){ let k = receive.deriveChild(index, false); let addr = k.privateKey.toAddress().toString(); rKeys.push({ key: k, address: addr, balance: "0", tokensBalance: {} }); } for(let index = fromCIndex; index < cIndex; index++){ let k = change.deriveChild(index, false); let addr = k.privateKey.toAddress().toString(); cKeys.push({ key: k, address: addr, balance: "0", tokensBalance: {} }); } return { receiveKeys: rKeys, changeKeys: cKeys }; } function $0d59d2bcffd646c5$export$1e0ce394ebe84ca9(accountKey, rIndex) { let receive = accountKey.deriveChild(0, false); let k = receive.deriveChild(rIndex, false); let addr = k.privateKey.toAddress().toString(); return { key: k, address: addr, balance: "0", tokensBalance: {} }; } async function $0d59d2bcffd646c5$var$discoverUsedAccountIndexes(deriveKey) { let lastUsed = -1, index = 0, toScan = 20; while(toScan > 0){ toScan--; let rAddr = deriveKey.deriveChild(index, false).privateKey.toAddress().toString(); let isUsed = await $0d59d2bcffd646c5$var$isAddressUsed(rAddr); if (isUsed) { lastUsed = index; toScan = 20; } index++; } // return the last used index, returns -1 if no indexes are used return lastUsed; } async function $0d59d2bcffd646c5$export$4aeb2c92e53ab137(accountKey) { let receiveKey = accountKey.deriveChild(0, false); let changeKey = accountKey.deriveChild(1, false); let rIndexPromise = $0d59d2bcffd646c5$var$discoverUsedAccountIndexes(receiveKey); let cIndexPromise = $0d59d2bcffd646c5$var$discoverUsedAccountIndexes(changeKey); let [rIndex, cIndex] = await Promise.all([ rIndexPromise, cIndexPromise ]); // get the index that is the last used nexa addr let indexes = { rIndex: rIndex, cIndex: cIndex }; return indexes; } async function $0d59d2bcffd646c5$export$f421913908d4303e(masterKey) { let accounts = []; let index = 0; while(true){ const nexaAccountKey = $0d59d2bcffd646c5$export$b3a12d67e2f5f8c9(masterKey, index); const indexes = await $0d59d2bcffd646c5$export$4aeb2c92e53ab137(nexaAccountKey); if (indexes.rIndex < 0 && indexes.cIndex < 0) break; if (indexes.rIndex < 0) indexes.rIndex = 0; if (indexes.cIndex < 0) indexes.cIndex = 0; // make account after break check, otherwise we might push an empty account const nexaAccount = new (0, $1c49a4fffc97409b$export$2e2bcd8739ae039)(index, indexes, $0d59d2bcffd646c5$export$d6e8eb22902c6b88(nexaAccountKey, indexes.rIndex + 1, indexes.rIndex + 20, indexes.cIndex + 1, indexes.cIndex + 20)); await nexaAccount.loadBalances(); accounts.push(nexaAccount); if (index == 0) index = 100; else index++; } if (accounts.length == 0) { // default account was unused but we need to populate at least one account, // make the default account here let defaultNexaAccountKey = $0d59d2bcffd646c5$export$b3a12d67e2f5f8c9(masterKey, 0); // get the last used indexes, -1 means unused let defaultIndexes = { rIndex: 0, cIndex: 0 }; const defaultAccount = new (0, $1c49a4fffc97409b$export$2e2bcd8739ae039)(0, defaultIndexes, $0d59d2bcffd646c5$export$d6e8eb22902c6b88(defaultNexaAccountKey, defaultIndexes.rIndex, defaultIndexes.rIndex + 20, defaultIndexes.cIndex, defaultIndexes.cIndex + 20)); await defaultAccount.loadBalances(); accounts.push(defaultAccount); } return accounts; } async function $0d59d2bcffd646c5$var$findUsedVaultAccounts(masterKey) { // all vaults are in bip44 account 1 let vaultAccountKey = $0d59d2bcffd646c5$export$b3a12d67e2f5f8c9(masterKey, 1); // all vaults are in the external chain let vaultChain = vaultAccountKey.deriveChild(0, false); // get the index that is the last used vault return await $0d59d2bcffd646c5$var$discoverUsedAccountIndexes(vaultChain); } async function $0d59d2bcffd646c5$export$eb24265dd203eccb(masterKey) { let accounts = []; // all vaults are in bip44 account 1 let vaultAccountKey = $0d59d2bcffd646c5$export$b3a12d67e2f5f8c9(masterKey, 1); // find the next unused vault let lastUsedVaultIndex = await $0d59d2bcffd646c5$var$findUsedVaultAccounts(masterKey); // if all vaults unused, generate at least the first vault account if (lastUsedVaultIndex < 0) lastUsedVaultIndex = 0; // for each vault found, make the DefaultAccount for that vault for(let index = 0; index <= lastUsedVaultIndex; index++){ const vaultAccount = new (0, $0b557605c0e99621$export$2e2bcd8739ae039)(1, index, $0d59d2bcffd646c5$export$1e0ce394ebe84ca9(vaultAccountKey, index)); await vaultAccount.loadBalances(); accounts.push(vaultAccount); } return accounts; } async function $0d59d2bcffd646c5$var$findUsedDappAccounts(masterKey) { // all dApp accounts are in bip44 account 2 let dappAccountKey = $0d59d2bcffd646c5$export$b3a12d67e2f5f8c9(masterKey, 2); // all dApp accounts use the external chain let dappChain = dappAccountKey.deriveChild(0, false); // get the index that is the next unused dApp account return await $0d59d2bcffd646c5$var$discoverUsedAccountIndexes(dappChain); } async function $0d59d2bcffd646c5$export$e3d879d0e09f52c3(masterKey) { let accounts = []; // all dApp accounts are in bip44 account 2 let dappAccountKey = $0d59d2bcffd646c5$export$b3a12d67e2f5f8c9(masterKey, 2); // find the next unused dapp account let lastUsedDappIndex = await $0d59d2bcffd646c5$var$findUsedDappAccounts(masterKey); // if all dapp accounts unused, generate at least the first dapp account if (lastUsedDappIndex < 0) lastUsedDappIndex = 0; // for each dApp account found, make the DefaultAccount for that dApp account // for each vault found, make the DefaultAccount for that vault for(let index = 0; index <= lastUsedDappIndex; index++){ const dappAccount = new (0, $cf960f437fe63027$export$2e2bcd8739ae039)(2, index, $0d59d2bcffd646c5$export$1e0ce394ebe84ca9(dappAccountKey, index)); await dappAccount.loadBalances(); accounts.push(dappAccount); } return accounts; } async function $0d59d2bcffd646c5$export$4e4f91181d6bd31c(masterKey) { let accounts = []; // accounts 0, 100+ const nexaAccounts = await $0d59d2bcffd646c5$export$f421913908d4303e(masterKey); // vaults in bip44 account 1 const vaultAccounts = await $0d59d2bcffd646c5$export$eb24265dd203eccb(masterKey); // dApp accounts in bip44 account 2 const dappAccounts = await $0d59d2bcffd646c5$export$e3d879d0e09f52c3(masterKey); // 3 - 99 are reserved and will go here when added accounts = accounts.concat(nexaAccounts); accounts = accounts.concat(vaultAccounts); accounts = accounts.concat(dappAccounts); return accounts; } async function $0d59d2bcffd646c5$var$isAddressUsed(address) { try { let firstUse = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getFirstUse(address); return firstUse.tx_hash && firstUse.tx_hash !== ""; } catch (e) { if (e instanceof Error && e.message.includes("not found")) return false; throw e; } } async function $0d59d2bcffd646c5$var$getKeyTokenBalance(key) { let tokensBalance = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getTokensBalance(key.address); let balance = {}; for(const cToken in tokensBalance.confirmed)if (tokensBalance.confirmed[cToken] != 0) balance[cToken] = { confirmed: BigInt(tokensBalance.confirmed[cToken]).toString(), unconfirmed: "0" }; for(const uToken in tokensBalance.unconfirmed)if (tokensBalance.unconfirmed[uToken] != 0) { if (balance[uToken]) balance[uToken].unconfirmed = BigInt(tokensBalance.unconfirmed[uToken]).toString(); else balance[uToken] = { confirmed: "0", unconfirmed: BigInt(tokensBalance.unconfirmed[uToken]).toString() }; } return balance; } async function $0d59d2bcffd646c5$var$getAndUpdateAddressKeyBalance(key) { let balance = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getBalance(key.address); key.balance = (BigInt(balance.confirmed) + BigInt(balance.unconfirmed)).toString(); key.tokensBalance = await $0d59d2bcffd646c5$var$getKeyTokenBalance(key); return balance; } async function $0d59d2bcffd646c5$export$9e38d26dbd7c33f4(keys) { let promises = []; keys.forEach((key)=>{ let b = $0d59d2bcffd646c5$var$getAndUpdateAddressKeyBalance(key); promises.push(b); }); return await Promise.all(promises); } function $0d59d2bcffd646c5$export$a26005fb5b8d1e4a(balances) { let confirmed = new (0, ($parcel$interopDefault($l50U0$jsbigdecimal)))(0), unconfirmed = new (0, ($parcel$interopDefault($l50U0$jsbigdecimal)))(0); balances.forEach((b)=>{ confirmed = confirmed.add(new (0, ($parcel$interopDefault($l50U0$jsbigdecimal)))(b.confirmed)); unconfirmed = unconfirmed.add(new (0, ($parcel$interopDefault($l50U0$jsbigdecimal)))(b.unconfirmed)); }); return { confirmed: confirmed.getValue(), unconfirmed: unconfirmed.getValue() }; } function $0d59d2bcffd646c5$export$dec515296f176dbe(balances) { let tokensBalance = {}; balances.forEach((b)=>{ for(const key in b)if (tokensBalance[key]) { tokensBalance[key].confirmed = (BigInt(tokensBalance[key].confirmed) + BigInt(b[key].confirmed)).toString(); tokensBalance[key].unconfirmed = (BigInt(tokensBalance[key].unconfirmed) + BigInt(b[key].unconfirmed)).toString(); } else tokensBalance[key] = { confirmed: b[key].confirmed, unconfirmed: b[key].unconfirmed }; }); return tokensBalance; } async function $0d59d2bcffd646c5$export$a2ed4b531376a5a4(addresses, fromHeight) { let index = 0, i = 0, data = new Map(), maxHeight = fromHeight; for (let address of addresses){ i++; let txHistory = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getTransactionHistory(address); if (txHistory && txHistory.length > 0) { index = i; for (let tx of txHistory)if (tx.height === 0 || tx.height > fromHeight) { maxHeight = Math.max(maxHeight, tx.height); data.set(tx.tx_hash, tx); } } } return { index: index, txs: data, lastHeight: maxHeight }; } async function $0d59d2bcffd646c5$var$rescanAddressesHistory(addresses) { let index = 0, i = 0, minHeight = Number.MAX_SAFE_INTEGER; for (let address of addresses){ i++; let txHistory = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getTransactionHistory(address); if (!(0, $54dde1e65fb8e5b8$export$2e2bcd8739ae039)(txHistory)) { index = i; let heights = txHistory.filter((tx)=>tx.height > 0).map((h)=>h.height); if (!(0, $54dde1e65fb8e5b8$export$2e2bcd8739ae039)(heights)) minHeight = Math.min(minHeight, ...heights); } } return { index: index > 0 ? index + 1 : 0, height: minHeight == Number.MAX_SAFE_INTEGER ? 0 : minHeight }; } async function $0d59d2bcffd646c5$export$ef13479e8d3251d7(accountType, masterKey) { if (accountType == 0) { let defaultNexaAccountKey = $0d59d2bcffd646c5$export$b3a12d67e2f5f8c9(masterKey, 0); const defaultIndexes = await $0d59d2bcffd646c5$export$4aeb2c92e53ab137(defaultNexaAccountKey); if (defaultIndexes.rIndex < 0 && defaultIndexes.cIndex < 0) return 0; else // account 0 was not empty for(let index = 100;; index++){ const nexaAccountKey = $0d59d2bcffd646c5$export$b3a12d67e2f5f8c9(masterKey, index); const indexes = await $0d59d2bcffd646c5$export$4aeb2c92e53ab137(nexaAccountKey); if (indexes.rIndex < 0 && indexes.cIndex < 0) return index; } } else if (accountType == 1) { // find the next unused vault const lastUsedVault = await $0d59d2bcffd646c5$var$findUsedVaultAccounts(masterKey); return lastUsedVault + 1; } else if (accountType == 2) { // find the next unused dapp account const lastUsedDappAccount = await $0d59d2bcffd646c5$var$findUsedDappAccounts(masterKey); return lastUsedDappAccount + 1; } else throw new Error("Can not get next account index. Invalid accountType."); } async function $0d59d2bcffd646c5$export$9c6f4f51acbc89b9(txHistory, myAddresses) { let t = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getTransaction(txHistory.tx_hash); let outputs = t.vout.filter((utxo)=>!(0, $54dde1e65fb8e5b8$export$2e2bcd8739ae039)(utxo.scriptPubKey.addresses)); let isOutgoing = t.vin.length > 0 && myAddresses.includes(t.vin[0].addresses[0]); let isIncoming = !isOutgoing || outputs.every((utxo)=>myAddresses.includes(utxo.scriptPubKey.addresses[0])); let isConfirmed = t.height > 0; let txEntry = {}; txEntry.txId = t.txid; txEntry.txIdem = t.txidem; txEntry.height = isConfirmed ? t.height : 0; txEntry.time = isConfirmed ? t.time : (0, $bc5ca2c06b1affa3$export$78d0476e8d098ba7)(); txEntry.fee = t.fee_satoshi; if (isOutgoing && isIncoming) { txEntry.state = 'both'; txEntry.value = "0"; txEntry.payTo = "Payment to yourself"; } else if (isIncoming) { txEntry.state = 'incoming'; let utxos = outputs.filter((utxo)=>myAddresses.includes(utxo.scriptPubKey.addresses[0])); let amount = new (0, ($parcel$interopDefault($l50U0$jsbigdecimal)))(0); utxos.forEach((utxo)=>{ amount = amount.add(new (0, ($parcel$interopDefault($l50U0$jsbigdecimal)))(utxo.value_satoshi)); }); txEntry.value = amount.getValue(); txEntry.payTo = utxos[0].scriptPubKey.addresses[0]; } else if (isOutgoing) { txEntry.state = 'outgoing'; let utxos = outputs.filter((utxo)=>!myAddresses.includes(utxo.scriptPubKey.addresses[0])); let amount = new (0, ($parcel$interopDefault($l50U0$jsbigdecimal)))(0); utxos.forEach((utxo)=>{ amount = amount.add(new (0, ($parcel$interopDefault($l50U0$jsbigdecimal)))(utxo.value_satoshi)); }); txEntry.value = amount.getValue(); txEntry.payTo = utxos[0].scriptPubKey.addresses[0]; } let [txType, txGroup, tokenAmount, extraGroup] = $0d59d2bcffd646c5$var$classifyTokenTransaction(t.vin, outputs, txEntry.state, myAddresses); txEntry.txGroupType = txType; txEntry.token = txGroup; txEntry.tokenAmount = tokenAmount; txEntry.extraGroup = extraGroup; return txEntry; } function $0d59d2bcffd646c5$var$classifyTokenTransaction(vin, vout, txState, myAddresses) { let groupInputs = vin.filter((input)=>!(0, $bc5ca2c06b1affa3$export$c8733ae29fb53302)(input.group)); let groupOutputs = vout.filter((output)=>!(0, $bc5ca2c06b1affa3$export$c8733ae29fb53302)(output.scriptPubKey.group)); if ((0, $bc5ca2c06b1affa3$export$c8733ae29fb53302)(groupInputs) && (0, $bc5ca2c06b1affa3$export$c8733ae29fb53302)(groupOutputs)) return [ 0, "none", "0", "none" ]; let myGroupInputs = groupInputs.filter((input)=>myAddresses.includes(input.addresses[0])); let myGroupOutputs = groupOutputs.filter((output)=>myAddresses.includes(output.scriptPubKey.addresses[0])); if ((0, $bc5ca2c06b1affa3$export$c8733ae29fb53302)(myGroupInputs) && (0, $bc5ca2c06b1affa3$export$c8733ae29fb53302)(myGroupOutputs)) return [ 0, "none", "0", "none" ]; if ((0, $bc5ca2c06b1affa3$export$c8733ae29fb53302)(groupInputs)) { let group = myGroupOutputs.find((output)=>BigInt(output.scriptPubKey.groupQuantity) < 0n)?.scriptPubKey.group ?? "none"; return [ 1, group, "0", "none" ]; } if ((0, $bc5ca2c06b1affa3$export$c8733ae29fb53302)(groupOutputs)) { if (txState === 'incoming') return [ 0, "none", "0", "none" ]; let inputs = myGroupInputs.filter((input)=>BigInt(input.groupQuantity) > 0n); if (!(0, $bc5ca2c06b1affa3$export$c8733ae29fb53302)(inputs)) { let amount = new (0, ($parcel$interopDefault($l50U0$jsbigdecimal)))(0); inputs.forEach((utxo)=>{ amount = amount.add(new (0, ($parcel$interopDefault($l50U0$jsbigdecimal)))(utxo.groupQuantity)); }); let group = inputs[0].group; let extraGroup = myGroupInputs.find((input)=>BigInt(input.groupQuantity) < 0n && inputs[0].group != input.group)?.group ?? "none"; return [ 3, group, amount.getValue(), extraGroup ]; } let group = myGroupInputs.find((input)=>BigInt(input.groupQuantity) < 0n)?.group ?? "none"; let extraGroup = myGroupInputs.find((input)=>BigInt(input.groupQuantity) < 0n && group != input.group)?.group ?? "none"; return [ 3, group, "0", extraGroup ]; } let tokenInputs = groupInputs.filter((input)=>BigInt(input.groupQuantity) > 0n); let tokenOutputs = groupOutputs.filter((output)=>BigInt(output.scriptPubKey.groupQuantity) > 0n); if ((0, $bc5ca2c06b1affa3$export$c8733ae29fb53302)(tokenInputs) && (0, $bc5ca2c06b1affa3$export$c8733ae29fb53302)(tokenOutputs)) { let group = groupInputs.find((input)=>BigInt(input.groupQuantity) < 0n)?.group ?? "none"; let extraGroup = groupOutputs.find((output)=>BigInt(output.scriptPubKey.groupQuantity) < 0n && group != output.scriptPubKey.group)?.scriptPubKey.group ?? "none"; return [ 4, extraGroup !== 'none' ? extraGroup : group, "0", extraGroup !== 'none' ? group : extraGroup ]; } if ((0, $bc5ca2c06b1affa3$export$c8733ae29fb53302)(tokenInputs)) { let group = tokenOutputs[0].scriptPubKey.group; let amount = new (0, ($parcel$interopDefault($l50U0$jsbigdecimal)))(0); tokenOutputs.forEach((utxo)=>{ amount = amount.add(new (0, ($parcel$interopDefault($l50U0$jsbigdecimal)))(utxo.scriptPubKey.groupQuantity)); }); let extraGroup = groupInputs.find((input)=>BigInt(input.groupQuantity) < 0n && group != input.group)?.group ?? "none"; return [ 2, group, amount.getValue(), extraGroup ]; } if ((0, $bc5ca2c06b1affa3$export$c8733ae29fb53302)(tokenOutputs)) { let group = tokenInputs[0].group; let amount = new (0, ($parcel$interopDefault($l50U0$jsbigdecimal)))(0); tokenInputs.forEach((utxo)=>{ amount = amount.add(new (0, ($parcel$interopDefault($l50U0$jsbigdecimal)))(utxo.groupQuantity)); }); let extraGroup = groupInputs.find((input)=>BigInt(input.groupQuantity) < 0n && group != input.group)?.group ?? "none"; return [ 3, group, amount.getValue(), extraGroup ]; } let outQuantitySum = tokenOutputs.map((output)=>BigInt(output.scriptPubKey.groupQuantity)).reduce((a, b)=>a + b, 0n); let inQuantitySum = tokenInputs.map((input)=>BigInt(input.groupQuantity)).reduce((a, b)=>a + b, 0n); if (outQuantitySum > inQuantitySum) { let group = tokenOutputs[0].scriptPubKey.group; let extraGroup = groupInputs.find((input)=>BigInt(input.groupQuantity) < 0n && group != input.group)?.group ?? "none"; return [ 2, group, (outQuantitySum - inQuantitySum).toString(), extraGroup ]; } if (inQuantitySum > outQuantitySum) { let group = tokenInputs[0].group; let extraGroup = groupInputs.find((input)=>BigInt(input.groupQuantity) < 0n && group != input.group)?.group ?? "none"; return [ 3, group, (inQuantitySum - outQuantitySum).toString(), extraGroup ]; } let group = tokenOutputs[0].scriptPubKey.group; let amount = ""; if (txState === 'incoming') amount = tokenOutputs.filter((output)=>myAddresses.includes(output.scriptPubKey.addresses[0])).map((output)=>BigInt(output.scriptPubKey.groupQuantity)).reduce((a, b)=>a + b, 0n).toString(); else if (txState === 'outgoing') amount = tokenOutputs.filter((output)=>!myAddresses.includes(output.scriptPubKey.addresses[0])).map((output)=>BigInt(output.scriptPubKey.groupQuantity)).reduce((a, b)=>a + b, 0n).toString(); else amount = "0"; return [ 5, group, amount, "none" ]; } /** * Checks if `value` is classified as an `Array` object. * * @static * @memberOf _ * @since 0.1.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is an array, else `false`. * @example * * _.isArray([1, 2, 3]); * // => true * * _.isArray(document.body.children); * // => false * * _.isArray('abc'); * // => false * * _.isArray(_.noop); * // => fals