@swapkit/toolboxes 1.0.0-beta.1 → 1.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cosmos/index.cjs +2 -2
- package/dist/cosmos/index.cjs.map +6 -6
- package/dist/cosmos/index.js +2 -2
- package/dist/cosmos/index.js.map +6 -6
- package/dist/evm/index.cjs +2 -2
- package/dist/evm/index.cjs.map +3 -3
- package/dist/evm/index.js +2 -2
- package/dist/evm/index.js.map +3 -3
- package/dist/ripple/index.cjs +2 -2
- package/dist/ripple/index.cjs.map +3 -3
- package/dist/ripple/index.js +2 -2
- package/dist/ripple/index.js.map +3 -3
- package/dist/solana/index.cjs +2 -2
- package/dist/solana/index.cjs.map +3 -3
- package/dist/solana/index.js +2 -2
- package/dist/solana/index.js.map +3 -3
- package/dist/utxo/index.cjs +2 -2
- package/dist/utxo/index.cjs.map +6 -6
- package/dist/utxo/index.js +2 -2
- package/dist/utxo/index.js.map +6 -6
- package/package.json +5 -7
- package/src/cosmos/thorchainUtils/registry.ts +3 -3
- package/src/cosmos/toolbox/cosmos.ts +5 -5
- package/src/cosmos/toolbox/thorchain.ts +8 -7
- package/src/cosmos/util.ts +3 -3
- package/src/evm/toolbox/baseEVMToolbox.ts +3 -1
- package/src/ripple/index.ts +1 -5
- package/src/solana/toolbox.ts +8 -8
- package/src/utxo/helpers/api.ts +1 -1
- package/src/utxo/helpers/txSize.ts +1 -1
- package/src/utxo/toolbox/bitcoinCash.ts +2 -2
- package/src/utxo/toolbox/utxo.ts +7 -7
- package/src/utxo/types.ts +2 -0
package/dist/utxo/index.js.map
CHANGED
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
"sources": ["../src/utxo/toolbox/index.ts", "../src/utxo/toolbox/bitcoinCash.ts", "../src/utxo/helpers/api.ts", "../src/utxo/helpers/bchaddrjs.ts", "../src/utxo/helpers/coinselect.ts", "../src/utxo/helpers/txSize.ts", "../src/utxo/toolbox/utxo.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"import {\n Chain,\n type ChainSigner,\n type DerivationPathArray,\n type UTXOChain,\n} from \"@swapkit/helpers\";\nimport type { Psbt } from \"bitcoinjs-lib\";\n\nimport type { TransactionBuilderType, TransactionType, UTXOType } from \"../types\";\nimport { createBCHToolbox } from \"./bitcoinCash\";\nimport { createUTXOToolbox } from \"./utxo\";\n\ntype BCHToolbox = Awaited<ReturnType<typeof createBCHToolbox>>;\ntype CommonUTXOToolbox = Awaited<\n ReturnType<typeof createUTXOToolbox<Exclude<UTXOChain, Chain.BitcoinCash>>>\n>;\n\nexport type UTXOToolboxes = {\n [Chain.BitcoinCash]: BCHToolbox;\n [Chain.Bitcoin]: CommonUTXOToolbox;\n [Chain.Dogecoin]: CommonUTXOToolbox;\n [Chain.Litecoin]: CommonUTXOToolbox;\n [Chain.Dash]: CommonUTXOToolbox;\n};\n\nexport type UTXOWallets = {\n [key in keyof UTXOToolboxes]: UTXOToolboxes[key];\n};\n\nexport type UtxoToolboxParams = {\n [Chain.BitcoinCash]: {\n signer: ChainSigner<{ builder: TransactionBuilderType; utxos: UTXOType[] }, TransactionType>;\n };\n [Chain.Bitcoin]: { signer: ChainSigner<Psbt, Psbt> };\n [Chain.Dogecoin]: { signer: ChainSigner<Psbt, Psbt> };\n [Chain.Litecoin]: { signer: ChainSigner<Psbt, Psbt> };\n [Chain.Dash]: { signer: ChainSigner<Psbt, Psbt> };\n};\n\nexport async function getUtxoToolbox<T extends keyof UTXOToolboxes>(\n chain: T,\n params?:\n | UtxoToolboxParams[T]\n | {\n phrase?: string;\n derivationPath?: DerivationPathArray;\n index?: number;\n },\n): Promise<UTXOToolboxes[T]> {\n switch (chain) {\n case Chain.BitcoinCash: {\n const toolbox = await createBCHToolbox(params as UtxoToolboxParams[Chain.BitcoinCash]);\n return toolbox as UTXOToolboxes[T];\n }\n\n case Chain.Bitcoin:\n case Chain.Dogecoin:\n case Chain.Litecoin:\n case Chain.Dash: {\n const toolbox = await createUTXOToolbox({\n chain,\n ...(params as UtxoToolboxParams[Exclude<T, Chain.BitcoinCash>]),\n });\n return toolbox as UTXOToolboxes[Exclude<T, Chain.BitcoinCash>];\n }\n\n default:\n throw new Error(`Chain ${chain} is not supported`);\n }\n}\n\nexport {\n stripToCashAddress,\n stripPrefix,\n bchValidateAddress,\n} from \"./bitcoinCash\";\n",
|
|
6
|
-
"import {\n Chain,\n type ChainSigner,\n type DerivationPathArray,\n FeeOption,\n NetworkDerivationPath,\n derivationPathToString,\n updateDerivationPath,\n} from \"@swapkit/helpers\";\nimport type { UtxoToolboxParams } from \".\";\nimport {\n accumulative,\n UtxoNetwork as bchNetwork,\n compileMemo,\n detectAddressNetwork,\n getUtxoApi,\n getUtxoNetwork,\n isValidAddress,\n toCashAddress,\n toLegacyAddress,\n} from \"../helpers\";\nimport type {\n BchECPair,\n TargetOutput,\n TransactionBuilderType,\n TransactionType,\n UTXOBuildTxParams,\n UTXOTransferParams,\n UTXOType,\n} from \"../types\";\nimport { createUTXOToolbox, getCreateKeysForPath } from \"./utxo\";\n\nconst chain = Chain.BitcoinCash;\n\nexport function stripPrefix(address: string) {\n return address.replace(/(bchtest:|bitcoincash:)/, \"\");\n}\n\nexport function bchValidateAddress(address: string) {\n const strippedAddress = stripPrefix(address);\n return (\n isValidAddress(strippedAddress) && detectAddressNetwork(strippedAddress) === bchNetwork.Mainnet\n );\n}\n\nexport function stripToCashAddress(address: string) {\n return stripPrefix(toCashAddress(address));\n}\n\nasync function createSignerWithKeys(keys: BchECPair) {\n async function signTransaction({\n builder,\n utxos,\n }: { builder: TransactionBuilderType; utxos: UTXOType[] }) {\n utxos.forEach((utxo, index) => {\n builder.sign(index, keys, undefined, 0x41, utxo.witnessUtxo?.value);\n });\n\n return builder.build();\n }\n\n const getAddress = () => {\n const address = keys.getAddress(0);\n return Promise.resolve(stripToCashAddress(address));\n };\n\n return {\n getAddress,\n signTransaction,\n };\n}\n\nexport async function createBCHToolbox<T extends Chain.BitcoinCash>(\n toolboxParams:\n | UtxoToolboxParams[T]\n | {\n phrase?: string;\n derivationPath?: DerivationPathArray;\n index?: number;\n },\n) {\n const phrase = \"phrase\" in toolboxParams ? toolboxParams.phrase : undefined;\n\n const index = \"index\" in toolboxParams ? toolboxParams.index || 0 : 0;\n\n const derivationPath = derivationPathToString(\n \"derivationPath\" in toolboxParams && toolboxParams.derivationPath\n ? toolboxParams.derivationPath\n : updateDerivationPath(NetworkDerivationPath[chain], { index }),\n );\n\n const keys = (await getCreateKeysForPath(chain))({ phrase, derivationPath });\n\n const signer = keys\n ? await createSignerWithKeys(keys)\n : \"signer\" in toolboxParams\n ? toolboxParams.signer\n : undefined;\n\n function getAddress() {\n return Promise.resolve(signer?.getAddress());\n }\n\n const { getBalance, getFeeRates, broadcastTx, ...toolbox } = await createUTXOToolbox({ chain });\n\n function handleGetBalance(address: string, _scamFilter = true) {\n return getBalance(stripPrefix(toCashAddress(address)));\n }\n\n return {\n ...toolbox,\n getAddress,\n broadcastTx,\n createTransaction,\n buildTx,\n getAddressFromKeys,\n getBalance: handleGetBalance,\n getFeeRates,\n stripPrefix,\n stripToCashAddress,\n validateAddress: bchValidateAddress,\n transfer: transfer({ getFeeRates, broadcastTx, signer }),\n };\n}\n\nasync function createTransaction({\n assetValue,\n recipient,\n memo,\n feeRate,\n sender,\n}: UTXOBuildTxParams) {\n const {\n Transaction,\n TransactionBuilder,\n address: bchAddress,\n // @ts-ignore\n } = await import(\"@psf/bitcoincashjs-lib\");\n if (!bchValidateAddress(recipient)) throw new Error(\"Invalid address\");\n const utxos = await getUtxoApi(chain).scanUTXOs({\n address: stripToCashAddress(sender),\n fetchTxHex: true,\n });\n\n const compiledMemo = memo ? await compileMemo(memo) : null;\n\n const targetOutputs: TargetOutput[] = [];\n // output to recipient\n targetOutputs.push({\n address: recipient,\n value: assetValue.getBaseValue(\"number\"),\n });\n const { inputs, outputs } = accumulative({\n inputs: utxos,\n outputs: targetOutputs,\n feeRate,\n chain,\n });\n\n // .inputs and .outputs will be undefined if no solution was found\n if (!(inputs && outputs)) throw new Error(\"Balance insufficient for transaction\");\n const getNetwork = await getUtxoNetwork();\n const builder = new TransactionBuilder(getNetwork(chain));\n\n await Promise.all(\n inputs.map(async (utxo: UTXOType) => {\n const txHex = await getUtxoApi(chain).getRawTx(utxo.hash);\n\n builder.addInput(Transaction.fromBuffer(Buffer.from(txHex, \"hex\")), utxo.index);\n }),\n );\n\n for (const output of outputs) {\n const address =\n \"address\" in output && output.address ? output.address : toLegacyAddress(sender);\n const getNetwork = await getUtxoNetwork();\n const outputScript = bchAddress.toOutputScript(toLegacyAddress(address), getNetwork(chain));\n\n builder.addOutput(outputScript, output.value);\n }\n\n // add output for memo\n if (compiledMemo) {\n builder.addOutput(compiledMemo, 0); // Add OP_RETURN {script, value}\n }\n\n return { builder, utxos: inputs };\n}\n\nfunction transfer({\n broadcastTx,\n getFeeRates,\n signer,\n}: {\n broadcastTx: (txHash: string) => Promise<string>;\n getFeeRates: () => Promise<Record<FeeOption, number>>;\n signer?: ChainSigner<{ builder: TransactionBuilderType; utxos: UTXOType[] }, TransactionType>;\n}) {\n return async function transfer({\n recipient,\n assetValue,\n feeOptionKey = FeeOption.Fast,\n ...rest\n }: UTXOTransferParams) {\n const from = await signer?.getAddress();\n if (!(signer && from)) throw new Error(\"Signer must provider address\");\n if (!recipient) throw new Error(\"Recipient address must be provided\");\n\n const feeRate = rest.feeRate || (await getFeeRates())[feeOptionKey];\n\n // try out if psbt tx is faster/better/nicer\n const { builder, utxos } = await createTransaction({\n ...rest,\n assetValue,\n feeRate,\n recipient,\n sender: from,\n });\n\n const tx = await signer.signTransaction({ builder, utxos });\n const txHex = tx.toHex();\n\n return broadcastTx(txHex);\n };\n}\n\n// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: TODO: refactor\nasync function buildTx({ assetValue, recipient, memo, feeRate, sender }: UTXOBuildTxParams) {\n const { Psbt } = await import(\"bitcoinjs-lib\");\n const recipientCashAddress = toCashAddress(recipient);\n if (!bchValidateAddress(recipientCashAddress)) throw new Error(\"Invalid address\");\n\n const utxos = await getUtxoApi(chain).scanUTXOs({\n address: stripToCashAddress(sender),\n fetchTxHex: true,\n });\n\n const feeRateWhole = Number(feeRate.toFixed(0));\n const compiledMemo = memo ? await compileMemo(memo) : null;\n\n const targetOutputs = [] as TargetOutput[];\n\n // output to recipient\n targetOutputs.push({\n address: toLegacyAddress(recipient),\n value: assetValue.getBaseValue(\"number\"),\n });\n\n //2. add output memo to targets (optional)\n if (compiledMemo) {\n targetOutputs.push({ script: compiledMemo, value: 0 });\n }\n\n const { inputs, outputs } = accumulative({\n inputs: utxos,\n outputs: targetOutputs,\n feeRate: feeRateWhole,\n chain,\n });\n\n // .inputs and .outputs will be undefined if no solution was found\n if (!(inputs && outputs)) throw new Error(\"Balance insufficient for transaction\");\n const getNetwork = await getUtxoNetwork();\n const psbt = new Psbt({ network: getNetwork(chain) }); // Network-specific\n\n for (const { hash, index, witnessUtxo } of inputs) {\n psbt.addInput({ hash, index, witnessUtxo });\n }\n\n // Outputs\n for (const output of outputs) {\n const address =\n \"address\" in output && output.address ? output.address : toLegacyAddress(sender);\n const params = output.script\n ? compiledMemo\n ? { script: compiledMemo, value: 0 }\n : undefined\n : { address, value: output.value };\n\n if (params) {\n psbt.addOutput(params);\n }\n }\n\n return { psbt, utxos, inputs: inputs as UTXOType[] };\n}\n\nfunction getAddressFromKeys(keys: { getAddress: (index?: number) => string }) {\n const address = keys.getAddress(0);\n return stripToCashAddress(address);\n}\n",
|
|
7
|
-
"import { Chain, RequestClient, SKConfig, type UTXOChain, warnOnce } from \"@swapkit/helpers\";\nimport { uniqid } from \"../../utils\";\n\ntype BlockchairParams<T> = T & { chain: Chain; apiKey?: string };\ntype BlockchairFetchUnspentUtxoParams = BlockchairParams<{\n offset?: number;\n limit?: number;\n address: string;\n}>;\n\nasync function broadcastUTXOTx({ chain, txHash }: { chain: Chain; txHash: string }) {\n const rpcUrl = SKConfig.get(\"rpcUrls\")[chain];\n const body = JSON.stringify({\n jsonrpc: \"2.0\",\n method: \"sendrawtransaction\",\n params: [txHash],\n id: uniqid(),\n });\n\n const response = await RequestClient.post<{\n id: string;\n result: string;\n error: { message: string; code?: number } | null;\n }>(rpcUrl, { headers: { \"Content-Type\": \"application/json\" }, body });\n\n if (response.error) {\n throw new Error(`failed to broadcast a transaction: ${response.error?.message}`);\n }\n\n if (response.result.includes('\"code\":-26')) {\n throw new Error(\"Invalid transaction: the transaction amount was too low\");\n }\n\n return response.result;\n}\n\nfunction baseUrl(chain: Chain) {\n return `https://api.blockchair.com/${mapChainToBlockchairChain(chain)}`;\n}\n\nfunction getDefaultTxFeeByChain(chain: Chain) {\n switch (chain) {\n case Chain.Bitcoin:\n return 5;\n case Chain.Dogecoin:\n return 10000;\n case Chain.Litecoin:\n return 1;\n default:\n return 2;\n }\n}\n\nfunction mapChainToBlockchairChain(chain: Chain) {\n switch (chain) {\n case Chain.BitcoinCash:\n return \"bitcoin-cash\";\n case Chain.Litecoin:\n return \"litecoin\";\n case Chain.Dash:\n return \"dash\";\n case Chain.Dogecoin:\n return \"dogecoin\";\n case Chain.Polkadot:\n return \"polkadot\";\n default:\n return \"bitcoin\";\n }\n}\n\nasync function getSuggestedTxFee(chain: Chain) {\n try {\n //Use Bitgo API for fee estimation\n //Refer: https://app.bitgo.com/docs/#operation/v2.tx.getfeeestimate\n const { feePerKb } = await RequestClient.get<{\n feePerKb: number;\n cpfpFeePerKb: number;\n numBlocks: number;\n feeByBlockTarget: { 1: number; 3: number };\n }>(`https://app.bitgo.com/api/v2/${chain.toLowerCase()}/tx/fee`);\n const suggestedFee = feePerKb / 1000;\n\n return Math.max(suggestedFee, getDefaultTxFeeByChain(chain));\n } catch (_error) {\n return getDefaultTxFeeByChain(chain);\n }\n}\n\nasync function blockchairRequest<T>(url: string, apiKey?: string): Promise<T> {\n try {\n const response = await RequestClient.get<BlockchairResponse<T>>(url);\n if (!response || response.context.code !== 200) throw new Error(`failed to query ${url}`);\n\n return response.data as T;\n } catch (error) {\n if (!apiKey) throw error;\n const response = await RequestClient.get<BlockchairResponse<T>>(\n `${url}${apiKey ? `&key=${apiKey}` : \"\"}`,\n );\n\n if (!response || response.context.code !== 200) throw new Error(`failed to query ${url}`);\n\n return response.data as T;\n }\n}\n\nasync function getAddressData({ address, chain, apiKey }: BlockchairParams<{ address?: string }>) {\n if (!address) throw new Error(\"address is required\");\n\n try {\n const response = await blockchairRequest<BlockchairAddressResponse>(\n `${baseUrl(chain)}/dashboards/address/${address}?transaction_details=true`,\n apiKey,\n );\n\n return response[address];\n } catch (_error) {\n return { utxo: [], address: { balance: 0, transaction_count: 0 } };\n }\n}\n\nasync function getUnconfirmedBalance({\n address,\n chain,\n apiKey,\n}: BlockchairParams<{ address?: string }>) {\n const response = await getAddressData({ address, chain, apiKey });\n\n return response?.address.balance || 0;\n}\n\nasync function getRawTx({ chain, apiKey, txHash }: BlockchairParams<{ txHash?: string }>) {\n if (!txHash) throw new Error(\"txHash is required\");\n\n try {\n const rawTxResponse = await blockchairRequest<BlockchairRawTransactionResponse>(\n `${baseUrl(chain)}/raw/transaction/${txHash}`,\n apiKey,\n );\n return rawTxResponse?.[txHash]?.raw_transaction || \"\";\n } catch (error) {\n console.error(error);\n return \"\";\n }\n}\n\nasync function fetchUnspentUtxoBatch({\n chain,\n address,\n apiKey,\n offset = 0,\n limit = 100,\n}: BlockchairFetchUnspentUtxoParams) {\n const response = await blockchairRequest<BlockchairOutputsResponse[]>(\n `${baseUrl(chain)}/outputs?q=is_spent(false),recipient(${address})&limit=${limit}&offset=${offset}`,\n apiKey,\n );\n\n const txs = response\n .filter(({ is_spent }) => !is_spent)\n .map(({ script_hex, block_id, transaction_hash, index, value, spending_signature_hex }) => ({\n hash: transaction_hash,\n index,\n value,\n txHex: spending_signature_hex,\n script_hex,\n is_confirmed: block_id !== -1,\n }));\n\n return txs;\n}\n\nasync function getUnspentUtxos({\n chain,\n address,\n apiKey,\n offset = 0,\n limit = 100,\n}: BlockchairFetchUnspentUtxoParams): Promise<Awaited<ReturnType<typeof fetchUnspentUtxoBatch>>> {\n if (!address) throw new Error(\"address is required\");\n\n try {\n const txs = await fetchUnspentUtxoBatch({ chain, address, apiKey, offset, limit });\n\n if (txs.length <= limit) return txs;\n\n const nextBatch = await getUnspentUtxos({\n chain,\n address,\n apiKey,\n offset: offset + limit,\n limit,\n });\n\n return [...txs, ...nextBatch];\n } catch (error) {\n console.error(error);\n return [];\n }\n}\n\nasync function scanUTXOs({\n address,\n chain,\n apiKey,\n fetchTxHex = true,\n}: BlockchairParams<{ address: string; fetchTxHex?: boolean }>) {\n const utxos = await getUnspentUtxos({ chain, address, apiKey });\n const results = [];\n\n for (const { hash, index, script_hex, value } of utxos) {\n let txHex: string | undefined;\n if (fetchTxHex) {\n txHex = await getRawTx({ txHash: hash, chain, apiKey });\n }\n results.push({\n address,\n hash,\n index,\n txHex,\n value,\n witnessUtxo: { value, script: Buffer.from(script_hex, \"hex\") },\n });\n }\n return results;\n}\n\nfunction utxoApi(chain: UTXOChain) {\n const apiKey = SKConfig.get(\"apiKeys\").blockchair || \"\";\n\n warnOnce(!apiKey, \"No Blockchair API key found. Functionality will be limited.\");\n\n return {\n broadcastTx: (txHash: string) => broadcastUTXOTx({ txHash, chain }),\n getRawTx: (txHash: string) => getRawTx({ txHash, chain, apiKey }),\n getSuggestedTxFee: () => getSuggestedTxFee(chain),\n getBalance: (address: string) => getUnconfirmedBalance({ address, chain, apiKey }),\n getAddressData: (address: string) => getAddressData({ address, chain, apiKey }),\n scanUTXOs: (params: { address: string; fetchTxHex?: boolean }) =>\n scanUTXOs({ ...params, chain, apiKey }),\n };\n}\n\n/**\n * \"Factory\" to ensure typing for custom UTXO APIs\n */\nexport function createCustomUtxoApi(methods: ReturnType<typeof utxoApi>) {\n return methods;\n}\n\nexport function getUtxoApi(chain: UTXOChain) {\n const customUtxoApi = SKConfig.get(\"apis\")[chain];\n\n if (customUtxoApi) {\n warnOnce(true, \"Using custom UTXO API. Be sure to implement all methods to avoid issues.\");\n return customUtxoApi as ReturnType<typeof utxoApi>;\n }\n\n return utxoApi(chain);\n}\n\nexport async function getUtxoNetwork() {\n // @ts-ignore\n const coininfo = await import(\"coininfo\");\n const { networks } = await import(\"bitcoinjs-lib\");\n\n return function getNetwork(chain: Chain) {\n switch (chain) {\n case Chain.Bitcoin:\n return networks.bitcoin;\n case Chain.BitcoinCash:\n return coininfo.bitcoincash.main.toBitcoinJS();\n case Chain.Dash:\n return coininfo.dash.main.toBitcoinJS();\n case Chain.Litecoin:\n return coininfo.litecoin.main.toBitcoinJS();\n\n case Chain.Dogecoin: {\n const bip32 = { private: 0x04358394, public: 0x043587cf };\n const test = coininfo.dogecoin.test;\n test.versions.bip32 = bip32;\n return coininfo.dogecoin.main.toBitcoinJS();\n }\n default:\n throw new Error(\"Invalid chain\");\n }\n };\n}\n\ninterface BlockchairVin {\n txid: string;\n vout: number;\n scriptSig: {\n asm: string;\n hex: string;\n };\n sequence: number;\n}\n\ninterface BlockchairVout {\n value: number;\n n: number;\n scriptPubKey: {\n asm: string;\n hex: string;\n address: string;\n type: string;\n addresses: string[];\n reqSigs: number;\n };\n}\n\ninterface BlockchairTransaction {\n block_id: number;\n hash: string;\n time: string;\n balance_change: number;\n}\n\ninterface BlockchairUtxo {\n block_id: number;\n transaction_hash: string;\n index: number;\n value: number;\n}\n\ninterface BlockchairAddressCoreData {\n type: string;\n script_hex: string;\n balance: number;\n balance_usd: number;\n received: number;\n received_usd: number;\n spent: number;\n spent_usd: number;\n output_count: number;\n unspent_output_count: number;\n first_seen_receiving: string;\n last_seen_receiving: string;\n first_seen_spending: null | string;\n last_seen_spending: null | string;\n transaction_count: number;\n scripthash_type: null | string;\n}\n\ninterface BlockchairInputOutputCommonData {\n block_id: number;\n transaction_id: number;\n index: number;\n transaction_hash: string;\n date: string;\n time: string;\n value: number;\n value_usd: number;\n recipient: string;\n type: string;\n script_hex: string;\n is_from_coinbase: boolean;\n is_spendable: boolean | null;\n is_spent: boolean;\n lifespan: number | null;\n cdd: number | null;\n}\n\ninterface BlockchairSpendingBlockData {\n spending_block_id: number | null;\n spending_transaction_id: number | null;\n spending_index: number | null;\n spending_transaction_hash: string | null;\n spending_date: string | null;\n spending_time: string | null;\n spending_value_usd: number | null;\n spending_sequence: number | null;\n spending_signature_hex: string | null;\n spending_witness: string | null;\n}\n\ninterface BlockchairAddressResponse {\n [key: string]: {\n address: BlockchairAddressCoreData;\n transactions: BlockchairTransaction[];\n utxo: BlockchairUtxo[];\n };\n}\n\ninterface BlockchairOutputsResponse\n extends BlockchairSpendingBlockData,\n BlockchairInputOutputCommonData {}\n\ninterface BlockchairRawTransactionResponse {\n [key: string]: {\n raw_transaction: string;\n decoded_raw_transaction: {\n txid: string;\n hash: string;\n version: number;\n size: number;\n vsize: number;\n weight: number;\n locktime: number;\n vin: BlockchairVin[];\n vout: BlockchairVout[];\n };\n };\n}\n\ninterface BlockchairResponse<T> {\n data: T;\n context: {\n code: number;\n source: string;\n results: number;\n state: number;\n market_price_usd: number;\n cache: {\n live: boolean;\n duration: number;\n since: string;\n until: string;\n time: any;\n };\n api: {\n version: string;\n last_major_update: string;\n next_major_update: null | string;\n documentation: string;\n notice: string;\n };\n servers: string;\n time: number;\n render_time: number;\n full_time: number;\n request_cost: number;\n };\n}\n",
|
|
6
|
+
"import {\n Chain,\n type ChainSigner,\n type DerivationPathArray,\n FeeOption,\n NetworkDerivationPath,\n derivationPathToString,\n updateDerivationPath,\n} from \"@swapkit/helpers\";\nimport type { UtxoToolboxParams } from \".\";\nimport {\n accumulative,\n UtxoNetwork as bchNetwork,\n compileMemo,\n detectAddressNetwork,\n getUtxoApi,\n getUtxoNetwork,\n isValidAddress,\n toCashAddress,\n toLegacyAddress,\n} from \"../helpers\";\nimport type {\n BchECPair,\n TargetOutput,\n TransactionBuilderType,\n TransactionType,\n UTXOBuildTxParams,\n UTXOTransferParams,\n UTXOType,\n} from \"../types\";\nimport { createUTXOToolbox, getCreateKeysForPath } from \"./utxo\";\n\nconst chain = Chain.BitcoinCash;\n\nexport function stripPrefix(address: string) {\n return address.replace(/(bchtest:|bitcoincash:)/, \"\");\n}\n\nexport function bchValidateAddress(address: string) {\n const strippedAddress = stripPrefix(address);\n return (\n isValidAddress(strippedAddress) && detectAddressNetwork(strippedAddress) === bchNetwork.Mainnet\n );\n}\n\nexport function stripToCashAddress(address: string) {\n return stripPrefix(toCashAddress(address));\n}\n\nasync function createSignerWithKeys(keys: BchECPair) {\n async function signTransaction({\n builder,\n utxos,\n }: { builder: TransactionBuilderType; utxos: UTXOType[] }) {\n utxos.forEach((utxo, index) => {\n builder.sign(index, keys, undefined, 0x41, utxo.witnessUtxo?.value);\n });\n\n return builder.build();\n }\n\n const getAddress = () => {\n const address = keys.getAddress(0);\n return Promise.resolve(stripToCashAddress(address));\n };\n\n return {\n getAddress,\n signTransaction,\n };\n}\n\nexport async function createBCHToolbox<T extends Chain.BitcoinCash>(\n toolboxParams:\n | UtxoToolboxParams[T]\n | {\n phrase?: string;\n derivationPath?: DerivationPathArray;\n index?: number;\n },\n) {\n const phrase = \"phrase\" in toolboxParams ? toolboxParams.phrase : undefined;\n\n const index = \"index\" in toolboxParams ? toolboxParams.index || 0 : 0;\n\n const derivationPath = derivationPathToString(\n \"derivationPath\" in toolboxParams && toolboxParams.derivationPath\n ? toolboxParams.derivationPath\n : updateDerivationPath(NetworkDerivationPath[chain], { index }),\n );\n\n const keys = (await getCreateKeysForPath(chain))({ phrase, derivationPath });\n\n const signer = keys\n ? await createSignerWithKeys(keys)\n : \"signer\" in toolboxParams\n ? toolboxParams.signer\n : undefined;\n\n function getAddress() {\n return Promise.resolve(signer?.getAddress());\n }\n\n const { getBalance, getFeeRates, broadcastTx, ...toolbox } = await createUTXOToolbox({ chain });\n\n function handleGetBalance(address: string, _scamFilter = true) {\n return getBalance(stripPrefix(toCashAddress(address)));\n }\n\n return {\n ...toolbox,\n getAddress,\n broadcastTx,\n createTransaction,\n buildTx,\n getAddressFromKeys,\n getBalance: handleGetBalance,\n getFeeRates,\n stripPrefix,\n stripToCashAddress,\n validateAddress: bchValidateAddress,\n transfer: transfer({ getFeeRates, broadcastTx, signer }),\n };\n}\n\nasync function createTransaction({\n assetValue,\n recipient,\n memo,\n feeRate,\n sender,\n}: UTXOBuildTxParams) {\n const {\n Transaction,\n TransactionBuilder,\n address: bchAddress,\n // @ts-ignore\n } = await import(\"@psf/bitcoincashjs-lib\");\n if (!bchValidateAddress(recipient)) throw new Error(\"Invalid address\");\n const utxos = await getUtxoApi(chain).scanUTXOs({\n address: stripToCashAddress(sender),\n fetchTxHex: true,\n });\n\n const compiledMemo = memo ? await compileMemo(memo) : null;\n\n const targetOutputs: TargetOutput[] = [];\n // output to recipient\n targetOutputs.push({\n address: recipient,\n value: assetValue.getBaseValue(\"number\"),\n });\n const { inputs, outputs } = accumulative({\n inputs: utxos,\n outputs: targetOutputs,\n feeRate,\n chain,\n });\n\n // .inputs and .outputs will be undefined if no solution was found\n if (!(inputs && outputs)) throw new Error(\"Balance insufficient for transaction\");\n const getNetwork = await getUtxoNetwork();\n const builder = new TransactionBuilder(getNetwork(chain)) as TransactionBuilderType;\n\n await Promise.all(\n inputs.map(async (utxo: UTXOType) => {\n const txHex = await getUtxoApi(chain).getRawTx(utxo.hash);\n\n builder.addInput(Transaction.fromBuffer(Buffer.from(txHex, \"hex\")), utxo.index);\n }),\n );\n\n for (const output of outputs) {\n const address =\n \"address\" in output && output.address ? output.address : toLegacyAddress(sender);\n const getNetwork = await getUtxoNetwork();\n const outputScript = bchAddress.toOutputScript(toLegacyAddress(address), getNetwork(chain));\n\n builder.addOutput(outputScript, output.value);\n }\n\n // add output for memo\n if (compiledMemo) {\n builder.addOutput(compiledMemo, 0); // Add OP_RETURN {script, value}\n }\n\n return { builder, utxos: inputs };\n}\n\nfunction transfer({\n broadcastTx,\n getFeeRates,\n signer,\n}: {\n broadcastTx: (txHash: string) => Promise<string>;\n getFeeRates: () => Promise<Record<FeeOption, number>>;\n signer?: ChainSigner<{ builder: TransactionBuilderType; utxos: UTXOType[] }, TransactionType>;\n}) {\n return async function transfer({\n recipient,\n assetValue,\n feeOptionKey = FeeOption.Fast,\n ...rest\n }: UTXOTransferParams) {\n const from = await signer?.getAddress();\n if (!(signer && from)) throw new Error(\"Signer must provider address\");\n if (!recipient) throw new Error(\"Recipient address must be provided\");\n\n const feeRate = rest.feeRate || (await getFeeRates())[feeOptionKey];\n\n // try out if psbt tx is faster/better/nicer\n const { builder, utxos } = await createTransaction({\n ...rest,\n assetValue,\n feeRate,\n recipient,\n sender: from,\n });\n\n const tx = await signer.signTransaction({ builder, utxos });\n const txHex = tx.toHex();\n\n return broadcastTx(txHex);\n };\n}\n\n// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: TODO: refactor\nasync function buildTx({ assetValue, recipient, memo, feeRate, sender }: UTXOBuildTxParams) {\n const { Psbt } = (await import(\"bitcoinjs-lib\")).default;\n const recipientCashAddress = toCashAddress(recipient);\n if (!bchValidateAddress(recipientCashAddress)) throw new Error(\"Invalid address\");\n\n const utxos = await getUtxoApi(chain).scanUTXOs({\n address: stripToCashAddress(sender),\n fetchTxHex: true,\n });\n\n const feeRateWhole = Number(feeRate.toFixed(0));\n const compiledMemo = memo ? await compileMemo(memo) : null;\n\n const targetOutputs = [] as TargetOutput[];\n\n // output to recipient\n targetOutputs.push({\n address: toLegacyAddress(recipient),\n value: assetValue.getBaseValue(\"number\"),\n });\n\n //2. add output memo to targets (optional)\n if (compiledMemo) {\n targetOutputs.push({ script: compiledMemo, value: 0 });\n }\n\n const { inputs, outputs } = accumulative({\n inputs: utxos,\n outputs: targetOutputs,\n feeRate: feeRateWhole,\n chain,\n });\n\n // .inputs and .outputs will be undefined if no solution was found\n if (!(inputs && outputs)) throw new Error(\"Balance insufficient for transaction\");\n const getNetwork = await getUtxoNetwork();\n const psbt = new Psbt({ network: getNetwork(chain) }); // Network-specific\n\n for (const { hash, index, witnessUtxo } of inputs) {\n psbt.addInput({ hash, index, witnessUtxo });\n }\n\n // Outputs\n for (const output of outputs) {\n const address =\n \"address\" in output && output.address ? output.address : toLegacyAddress(sender);\n const params = output.script\n ? compiledMemo\n ? { script: compiledMemo, value: 0 }\n : undefined\n : { address, value: output.value };\n\n if (params) {\n psbt.addOutput(params);\n }\n }\n\n return { psbt, utxos, inputs: inputs as UTXOType[] };\n}\n\nfunction getAddressFromKeys(keys: { getAddress: (index?: number) => string }) {\n const address = keys.getAddress(0);\n return stripToCashAddress(address);\n}\n",
|
|
7
|
+
"import { Chain, RequestClient, SKConfig, type UTXOChain, warnOnce } from \"@swapkit/helpers\";\nimport { uniqid } from \"../../utils\";\n\ntype BlockchairParams<T> = T & { chain: Chain; apiKey?: string };\ntype BlockchairFetchUnspentUtxoParams = BlockchairParams<{\n offset?: number;\n limit?: number;\n address: string;\n}>;\n\nasync function broadcastUTXOTx({ chain, txHash }: { chain: Chain; txHash: string }) {\n const rpcUrl = SKConfig.get(\"rpcUrls\")[chain];\n const body = JSON.stringify({\n jsonrpc: \"2.0\",\n method: \"sendrawtransaction\",\n params: [txHash],\n id: uniqid(),\n });\n\n const response = await RequestClient.post<{\n id: string;\n result: string;\n error: { message: string; code?: number } | null;\n }>(rpcUrl, { headers: { \"Content-Type\": \"application/json\" }, body });\n\n if (response.error) {\n throw new Error(`failed to broadcast a transaction: ${response.error?.message}`);\n }\n\n if (response.result.includes('\"code\":-26')) {\n throw new Error(\"Invalid transaction: the transaction amount was too low\");\n }\n\n return response.result;\n}\n\nfunction baseUrl(chain: Chain) {\n return `https://api.blockchair.com/${mapChainToBlockchairChain(chain)}`;\n}\n\nfunction getDefaultTxFeeByChain(chain: Chain) {\n switch (chain) {\n case Chain.Bitcoin:\n return 5;\n case Chain.Dogecoin:\n return 10000;\n case Chain.Litecoin:\n return 1;\n default:\n return 2;\n }\n}\n\nfunction mapChainToBlockchairChain(chain: Chain) {\n switch (chain) {\n case Chain.BitcoinCash:\n return \"bitcoin-cash\";\n case Chain.Litecoin:\n return \"litecoin\";\n case Chain.Dash:\n return \"dash\";\n case Chain.Dogecoin:\n return \"dogecoin\";\n case Chain.Polkadot:\n return \"polkadot\";\n default:\n return \"bitcoin\";\n }\n}\n\nasync function getSuggestedTxFee(chain: Chain) {\n try {\n //Use Bitgo API for fee estimation\n //Refer: https://app.bitgo.com/docs/#operation/v2.tx.getfeeestimate\n const { feePerKb } = await RequestClient.get<{\n feePerKb: number;\n cpfpFeePerKb: number;\n numBlocks: number;\n feeByBlockTarget: { 1: number; 3: number };\n }>(`https://app.bitgo.com/api/v2/${chain.toLowerCase()}/tx/fee`);\n const suggestedFee = feePerKb / 1000;\n\n return Math.max(suggestedFee, getDefaultTxFeeByChain(chain));\n } catch (_error) {\n return getDefaultTxFeeByChain(chain);\n }\n}\n\nasync function blockchairRequest<T>(url: string, apiKey?: string): Promise<T> {\n try {\n const response = await RequestClient.get<BlockchairResponse<T>>(url);\n if (!response || response.context.code !== 200) throw new Error(`failed to query ${url}`);\n\n return response.data as T;\n } catch (error) {\n if (!apiKey) throw error;\n const response = await RequestClient.get<BlockchairResponse<T>>(\n `${url}${apiKey ? `&key=${apiKey}` : \"\"}`,\n );\n\n if (!response || response.context.code !== 200) throw new Error(`failed to query ${url}`);\n\n return response.data as T;\n }\n}\n\nasync function getAddressData({ address, chain, apiKey }: BlockchairParams<{ address?: string }>) {\n if (!address) throw new Error(\"address is required\");\n\n try {\n const response = await blockchairRequest<BlockchairAddressResponse>(\n `${baseUrl(chain)}/dashboards/address/${address}?transaction_details=true`,\n apiKey,\n );\n\n return response[address];\n } catch (_error) {\n return { utxo: [], address: { balance: 0, transaction_count: 0 } };\n }\n}\n\nasync function getUnconfirmedBalance({\n address,\n chain,\n apiKey,\n}: BlockchairParams<{ address?: string }>) {\n const response = await getAddressData({ address, chain, apiKey });\n\n return response?.address.balance || 0;\n}\n\nasync function getRawTx({ chain, apiKey, txHash }: BlockchairParams<{ txHash?: string }>) {\n if (!txHash) throw new Error(\"txHash is required\");\n\n try {\n const rawTxResponse = await blockchairRequest<BlockchairRawTransactionResponse>(\n `${baseUrl(chain)}/raw/transaction/${txHash}`,\n apiKey,\n );\n return rawTxResponse?.[txHash]?.raw_transaction || \"\";\n } catch (error) {\n console.error(error);\n return \"\";\n }\n}\n\nasync function fetchUnspentUtxoBatch({\n chain,\n address,\n apiKey,\n offset = 0,\n limit = 100,\n}: BlockchairFetchUnspentUtxoParams) {\n const response = await blockchairRequest<BlockchairOutputsResponse[]>(\n `${baseUrl(chain)}/outputs?q=is_spent(false),recipient(${address})&limit=${limit}&offset=${offset}`,\n apiKey,\n );\n\n const txs = response\n .filter(({ is_spent }) => !is_spent)\n .map(({ script_hex, block_id, transaction_hash, index, value, spending_signature_hex }) => ({\n hash: transaction_hash,\n index,\n value,\n txHex: spending_signature_hex,\n script_hex,\n is_confirmed: block_id !== -1,\n }));\n\n return txs;\n}\n\nasync function getUnspentUtxos({\n chain,\n address,\n apiKey,\n offset = 0,\n limit = 100,\n}: BlockchairFetchUnspentUtxoParams): Promise<Awaited<ReturnType<typeof fetchUnspentUtxoBatch>>> {\n if (!address) throw new Error(\"address is required\");\n\n try {\n const txs = await fetchUnspentUtxoBatch({ chain, address, apiKey, offset, limit });\n\n if (txs.length <= limit) return txs;\n\n const nextBatch = await getUnspentUtxos({\n chain,\n address,\n apiKey,\n offset: offset + limit,\n limit,\n });\n\n return [...txs, ...nextBatch];\n } catch (error) {\n console.error(error);\n return [];\n }\n}\n\nasync function scanUTXOs({\n address,\n chain,\n apiKey,\n fetchTxHex = true,\n}: BlockchairParams<{ address: string; fetchTxHex?: boolean }>) {\n const utxos = await getUnspentUtxos({ chain, address, apiKey });\n const results = [];\n\n for (const { hash, index, script_hex, value } of utxos) {\n let txHex: string | undefined;\n if (fetchTxHex) {\n txHex = await getRawTx({ txHash: hash, chain, apiKey });\n }\n results.push({\n address,\n hash,\n index,\n txHex,\n value,\n witnessUtxo: { value, script: Buffer.from(script_hex, \"hex\") },\n });\n }\n return results;\n}\n\nfunction utxoApi(chain: UTXOChain) {\n const apiKey = SKConfig.get(\"apiKeys\").blockchair || \"\";\n\n warnOnce(!apiKey, \"No Blockchair API key found. Functionality will be limited.\");\n\n return {\n broadcastTx: (txHash: string) => broadcastUTXOTx({ txHash, chain }),\n getRawTx: (txHash: string) => getRawTx({ txHash, chain, apiKey }),\n getSuggestedTxFee: () => getSuggestedTxFee(chain),\n getBalance: (address: string) => getUnconfirmedBalance({ address, chain, apiKey }),\n getAddressData: (address: string) => getAddressData({ address, chain, apiKey }),\n scanUTXOs: (params: { address: string; fetchTxHex?: boolean }) =>\n scanUTXOs({ ...params, chain, apiKey }),\n };\n}\n\n/**\n * \"Factory\" to ensure typing for custom UTXO APIs\n */\nexport function createCustomUtxoApi(methods: ReturnType<typeof utxoApi>) {\n return methods;\n}\n\nexport function getUtxoApi(chain: UTXOChain) {\n const customUtxoApi = SKConfig.get(\"apis\")[chain];\n\n if (customUtxoApi) {\n warnOnce(true, \"Using custom UTXO API. Be sure to implement all methods to avoid issues.\");\n return customUtxoApi as ReturnType<typeof utxoApi>;\n }\n\n return utxoApi(chain);\n}\n\nexport async function getUtxoNetwork() {\n // @ts-ignore\n const coininfo = await import(\"coininfo\");\n const { networks } = (await import(\"bitcoinjs-lib\")).default;\n\n return function getNetwork(chain: Chain) {\n switch (chain) {\n case Chain.Bitcoin:\n return networks.bitcoin;\n case Chain.BitcoinCash:\n return coininfo.bitcoincash.main.toBitcoinJS();\n case Chain.Dash:\n return coininfo.dash.main.toBitcoinJS();\n case Chain.Litecoin:\n return coininfo.litecoin.main.toBitcoinJS();\n\n case Chain.Dogecoin: {\n const bip32 = { private: 0x04358394, public: 0x043587cf };\n const test = coininfo.dogecoin.test;\n test.versions.bip32 = bip32;\n return coininfo.dogecoin.main.toBitcoinJS();\n }\n default:\n throw new Error(\"Invalid chain\");\n }\n };\n}\n\ninterface BlockchairVin {\n txid: string;\n vout: number;\n scriptSig: {\n asm: string;\n hex: string;\n };\n sequence: number;\n}\n\ninterface BlockchairVout {\n value: number;\n n: number;\n scriptPubKey: {\n asm: string;\n hex: string;\n address: string;\n type: string;\n addresses: string[];\n reqSigs: number;\n };\n}\n\ninterface BlockchairTransaction {\n block_id: number;\n hash: string;\n time: string;\n balance_change: number;\n}\n\ninterface BlockchairUtxo {\n block_id: number;\n transaction_hash: string;\n index: number;\n value: number;\n}\n\ninterface BlockchairAddressCoreData {\n type: string;\n script_hex: string;\n balance: number;\n balance_usd: number;\n received: number;\n received_usd: number;\n spent: number;\n spent_usd: number;\n output_count: number;\n unspent_output_count: number;\n first_seen_receiving: string;\n last_seen_receiving: string;\n first_seen_spending: null | string;\n last_seen_spending: null | string;\n transaction_count: number;\n scripthash_type: null | string;\n}\n\ninterface BlockchairInputOutputCommonData {\n block_id: number;\n transaction_id: number;\n index: number;\n transaction_hash: string;\n date: string;\n time: string;\n value: number;\n value_usd: number;\n recipient: string;\n type: string;\n script_hex: string;\n is_from_coinbase: boolean;\n is_spendable: boolean | null;\n is_spent: boolean;\n lifespan: number | null;\n cdd: number | null;\n}\n\ninterface BlockchairSpendingBlockData {\n spending_block_id: number | null;\n spending_transaction_id: number | null;\n spending_index: number | null;\n spending_transaction_hash: string | null;\n spending_date: string | null;\n spending_time: string | null;\n spending_value_usd: number | null;\n spending_sequence: number | null;\n spending_signature_hex: string | null;\n spending_witness: string | null;\n}\n\ninterface BlockchairAddressResponse {\n [key: string]: {\n address: BlockchairAddressCoreData;\n transactions: BlockchairTransaction[];\n utxo: BlockchairUtxo[];\n };\n}\n\ninterface BlockchairOutputsResponse\n extends BlockchairSpendingBlockData,\n BlockchairInputOutputCommonData {}\n\ninterface BlockchairRawTransactionResponse {\n [key: string]: {\n raw_transaction: string;\n decoded_raw_transaction: {\n txid: string;\n hash: string;\n version: number;\n size: number;\n vsize: number;\n weight: number;\n locktime: number;\n vin: BlockchairVin[];\n vout: BlockchairVout[];\n };\n };\n}\n\ninterface BlockchairResponse<T> {\n data: T;\n context: {\n code: number;\n source: string;\n results: number;\n state: number;\n market_price_usd: number;\n cache: {\n live: boolean;\n duration: number;\n since: string;\n until: string;\n time: any;\n };\n api: {\n version: string;\n last_major_update: string;\n next_major_update: null | string;\n documentation: string;\n notice: string;\n };\n servers: string;\n time: number;\n render_time: number;\n full_time: number;\n request_cost: number;\n };\n}\n",
|
|
8
8
|
"import base58check from \"bs58check\";\n// @ts-expect-error\nimport cashaddr from \"cashaddrjs\";\n\nenum Format {\n Legacy = \"legacy\",\n Bitpay = \"bitpay\",\n Cashaddr = \"cashaddr\",\n}\nenum UtxoNetwork {\n Mainnet = \"mainnet\",\n Testnet = \"testnet\",\n}\nenum Type {\n P2PKH = \"p2pkh\",\n P2SH = \"p2sh\",\n}\n\nconst VERSION_BYTE = {\n [Format.Legacy]: {\n [UtxoNetwork.Mainnet]: {\n [Type.P2PKH]: 0,\n [Type.P2SH]: 5,\n },\n [UtxoNetwork.Testnet]: {\n [Type.P2PKH]: 111,\n [Type.P2SH]: 196,\n },\n },\n [Format.Bitpay]: {\n [UtxoNetwork.Mainnet]: {\n [Type.P2PKH]: 28,\n [Type.P2SH]: 40,\n },\n [UtxoNetwork.Testnet]: {\n [Type.P2PKH]: 111,\n [Type.P2SH]: 196,\n },\n },\n};\n\ntype DecodedType = {\n format: Format;\n network: UtxoNetwork;\n type: Type;\n hash: any;\n};\n\nfunction isValidAddress(input: any) {\n try {\n decodeAddress(input);\n return true;\n } catch (_error) {\n return false;\n }\n}\n\nfunction detectAddressNetwork(address: string) {\n return decodeAddress(address)?.network;\n}\n\nfunction toLegacyAddress(address: string): string {\n const decoded = decodeAddress(address);\n if (decoded?.format === Format.Legacy) {\n return address;\n }\n return encodeAsLegacy(decoded);\n}\n\nfunction toCashAddress(address: string): string {\n const decoded = decodeAddress(address);\n return encodeAsCashaddr(decoded);\n}\n\nfunction decodeAddress(address: string) {\n try {\n return decodeBase58Address(address);\n } catch (_error) {\n // Try to decode as cashaddr if base58 decoding fails.\n }\n try {\n return decodeCashAddress(address);\n } catch (_error) {\n // Try to decode as bitpay if cashaddr decoding fails.\n }\n throw new Error(\"Received an invalid Bitcoin Cash address as input.\");\n}\n\nfunction decodeBase58Address(address: string) {\n try {\n const payload = base58check.decode(address);\n\n // BASE_58_CHECK_PAYLOAD_LENGTH\n if (payload.length !== 21)\n throw new Error(\"Received an invalid Bitcoin Cash address as input.\");\n const versionByte = payload[0];\n const hash = Array.prototype.slice.call(payload, 1);\n\n switch (versionByte) {\n case VERSION_BYTE[Format.Legacy][UtxoNetwork.Mainnet][Type.P2PKH]:\n return { hash, format: Format.Legacy, network: UtxoNetwork.Mainnet, type: Type.P2PKH };\n\n case VERSION_BYTE[Format.Legacy][UtxoNetwork.Mainnet][Type.P2SH]:\n return { hash, format: Format.Legacy, network: UtxoNetwork.Mainnet, type: Type.P2SH };\n\n case VERSION_BYTE[Format.Legacy][UtxoNetwork.Testnet][Type.P2PKH]:\n return { hash, format: Format.Legacy, network: UtxoNetwork.Testnet, type: Type.P2PKH };\n\n case VERSION_BYTE[Format.Legacy][UtxoNetwork.Testnet][Type.P2SH]:\n return { hash, format: Format.Legacy, network: UtxoNetwork.Testnet, type: Type.P2SH };\n\n case VERSION_BYTE[Format.Bitpay][UtxoNetwork.Mainnet][Type.P2PKH]:\n return { hash, format: Format.Bitpay, network: UtxoNetwork.Mainnet, type: Type.P2PKH };\n\n case VERSION_BYTE[Format.Bitpay][UtxoNetwork.Mainnet][Type.P2SH]:\n return { hash, format: Format.Bitpay, network: UtxoNetwork.Mainnet, type: Type.P2SH };\n\n default:\n throw new Error(\"Received an invalid Bitcoin Cash address as input.\");\n }\n } catch (_error) {\n throw new Error(\"Received an invalid Bitcoin Cash address as input.\");\n }\n}\n\nfunction decodeCashAddress(address: string) {\n if (address.indexOf(\":\") !== -1) {\n try {\n return decodeCashAddressWithPrefix(address);\n } catch (_error) {\n // Try to decode as legacy if cashaddr decoding fails.\n }\n } else {\n const prefixes = [\"bitcoincash\", \"bchtest\", \"bchreg\"];\n for (const prefix of prefixes) {\n try {\n return decodeCashAddressWithPrefix(`${prefix}:${address}`);\n } catch (_error) {\n // Try next prefix if decoding fails.\n }\n }\n }\n\n throw new Error(\"Received an invalid Bitcoin Cash address as input.\");\n}\n\nfunction decodeCashAddressWithPrefix(address: string): DecodedType {\n try {\n const { hash, prefix, type } = cashaddr.decode(address);\n\n return {\n format: Format.Cashaddr,\n hash: Array.prototype.slice.call(hash, 0),\n network: prefix === \"bitcoincash\" ? UtxoNetwork.Mainnet : UtxoNetwork.Testnet,\n type: type === \"P2PKH\" ? Type.P2PKH : Type.P2SH,\n };\n } catch (_error) {\n throw new Error(\"Received an invalid Bitcoin Cash address as input.\");\n }\n}\n\nfunction encodeAsLegacy(decoded: DecodedType) {\n const versionByte = VERSION_BYTE[Format.Legacy][decoded.network][decoded.type];\n const buffer = Buffer.alloc(1 + decoded.hash.length);\n buffer[0] = versionByte;\n buffer.set(decoded.hash, 1);\n return base58check.encode(buffer);\n}\n\nfunction encodeAsCashaddr(decoded: DecodedType) {\n const prefix = decoded.network === UtxoNetwork.Mainnet ? \"bitcoincash\" : \"bchtest\";\n const type = decoded.type === Type.P2PKH ? \"P2PKH\" : \"P2SH\";\n const hash = new Uint8Array(decoded.hash);\n return cashaddr.encode(prefix, type, hash);\n}\n\nexport { detectAddressNetwork, isValidAddress, UtxoNetwork, toCashAddress, toLegacyAddress };\n",
|
|
9
9
|
"import { Chain, type UTXOChain } from \"@swapkit/helpers\";\n\nimport {\n TX_OVERHEAD,\n UTXOScriptType,\n calculateTxSize,\n getInputSize,\n getOutputSize,\n getScriptTypeForAddress,\n} from \"../helpers\";\nimport type { TargetOutput, UTXOCalculateTxSizeParams, UTXOType } from \"../types\";\n\nexport const getDustThreshold = (chain: UTXOChain) => {\n switch (chain) {\n case Chain.Bitcoin:\n case Chain.BitcoinCash:\n return 550;\n case Chain.Dash:\n case Chain.Litecoin:\n return 5500;\n case Chain.Dogecoin:\n return 100000;\n default:\n throw new Error(\"Invalid Chain\");\n }\n};\n\nexport const accumulative = ({\n inputs,\n outputs,\n feeRate: initialFeeRate = 1,\n chain = Chain.Bitcoin,\n}: UTXOCalculateTxSizeParams & { outputs: TargetOutput[]; chain: UTXOChain }) => {\n const feeRate = Math.ceil(initialFeeRate);\n\n const newTxType =\n inputs[0] && \"address\" in inputs[0] && inputs[0].address\n ? getScriptTypeForAddress(inputs[0].address)\n : UTXOScriptType.P2PKH;\n // skip input if adding it would cost more than input is worth\n const filteredInputs = inputs.filter((input) => getInputSize(input) * feeRate <= input.value);\n\n const txSizeWithoutInputs =\n TX_OVERHEAD + outputs.reduce((total, output) => total + getOutputSize(output, newTxType), 0);\n\n const amountToSend = outputs.reduce((total, output) => total + output.value, 0);\n\n let fees = txSizeWithoutInputs * feeRate;\n let inputsValue = 0;\n const inputsToUse: typeof inputs = [];\n\n for (const input of filteredInputs) {\n const inputSize = getInputSize(input);\n const inputFee = feeRate * inputSize;\n\n fees += inputFee;\n inputsValue += input.value;\n\n inputsToUse.push(input);\n\n const totalCost = fees + amountToSend;\n\n // we need more inputs\n if (inputsValue < totalCost) continue;\n\n const remainder = inputsValue - totalCost;\n\n const feeForExtraOutput = feeRate * getOutputSize({ address: \"\", value: 0 }, newTxType);\n\n // potential change address\n if (remainder > feeForExtraOutput) {\n const feeAfterExtraOutput = feeForExtraOutput + fees;\n const remainderAfterExtraOutput = inputsValue - (amountToSend + feeAfterExtraOutput);\n\n // is it worth a change output aka can we send it in the future?\n if (\n remainderAfterExtraOutput >\n Math.max(getInputSize({} as UTXOType) * feeRate, getDustThreshold(chain))\n ) {\n return {\n inputs: inputsToUse,\n outputs: outputs.concat({ value: remainderAfterExtraOutput, address: \"\" }),\n fee: feeAfterExtraOutput,\n };\n }\n }\n return {\n inputs: inputsToUse,\n outputs,\n fee: fees,\n };\n }\n\n // We don't have enough inputs, let's calculate transaction fee accrude to the last input\n return { fee: feeRate * calculateTxSize({ inputs, outputs, feeRate }) };\n};\n",
|
|
10
|
-
"import type {\n TargetOutput,\n UTXOCalculateTxSizeParams,\n UTXOInputWithScriptType,\n UTXOType,\n} from \"../types\";\n\n/**\n * Minimum transaction fee\n * 1000 satoshi/kB (similar to current `minrelaytxfee`)\n * @see https://github.com/bitcoin/bitcoin/blob/db88db47278d2e7208c50d16ab10cb355067d071/src/validation.h#L56\n */\nexport const MIN_TX_FEE = 1000;\nexport const TX_OVERHEAD = 4 + 1 + 1 + 4; //10\nexport const OP_RETURN_OVERHEAD = 1 + 8 + 1; //10\nconst TX_INPUT_BASE = 32 + 4 + 1 + 4; // 41\nconst TX_INPUT_PUBKEYHASH = 107;\n\nexport async function compileMemo(memo: string) {\n const { script, opcodes } = await import(\"bitcoinjs-lib\");\n const data = Buffer.from(memo, \"utf8\"); // converts MEMO to buffer\n return script.compile([opcodes.OP_RETURN as number, data]); // Compile OP_RETURN script\n}\n\nexport enum UTXOScriptType {\n P2PKH = \"P2PKH\", // legacy\n // P2SH = 'P2SH', // multisig\n P2WPKH = \"P2WPKH\", // bech32 - native segwit\n // P2TR = \"P2TR\", // taproot\n}\n\nexport const InputSizes: Record<UTXOScriptType, number> = {\n [UTXOScriptType.P2PKH]: 148,\n // [UTXOScriptType.P2SH]: 91,\n [UTXOScriptType.P2WPKH]: 68,\n};\n\nexport const OutputSizes: Record<UTXOScriptType, number> = {\n [UTXOScriptType.P2PKH]: 34,\n // [UTXOScriptType.P2SH]: 91,\n [UTXOScriptType.P2WPKH]: 31,\n};\n\nexport const getScriptTypeForAddress = (address: string) => {\n if (address.startsWith(\"bc1\") || address.startsWith(\"ltc1\")) {\n return UTXOScriptType.P2WPKH;\n }\n // if (address.startsWith('3') || address.startsWith('M')) {\n // return UTXOScriptType.P2SH;\n // }\n if (\n address.startsWith(\"1\") ||\n address.startsWith(\"3\") ||\n address.startsWith(\"L\") ||\n address.startsWith(\"M\") ||\n address.startsWith(\"X\") ||\n address.startsWith(\"D\") ||\n address.startsWith(\"bitcoincash:q\") ||\n address.startsWith(\"q\")\n ) {\n return UTXOScriptType.P2PKH;\n }\n throw new Error(\"Invalid address\");\n};\n\nexport const calculateTxSize = ({ inputs, outputs, feeRate }: UTXOCalculateTxSizeParams) => {\n const newTxType =\n inputs[0] && \"address\" in inputs[0] && inputs[0].address\n ? getScriptTypeForAddress(inputs[0].address)\n : UTXOScriptType.P2PKH;\n const inputSize = inputs\n .filter(\n (utxo) =>\n utxo.value >=\n InputSizes[\"type\" in utxo ? utxo.type : UTXOScriptType.P2PKH] * Math.ceil(feeRate),\n )\n .reduce((total, utxo) => total + getInputSize(utxo), 0);\n\n const outputSize =\n outputs?.reduce((total, output) => total + getOutputSize(output), 0) || OutputSizes[newTxType];\n\n return TX_OVERHEAD + inputSize + outputSize;\n};\n\nexport const getInputSize = (input: UTXOInputWithScriptType | UTXOType) => {\n if (\"type\" in input) {\n return InputSizes[input.type];\n }\n if (\"address\" in input && input.address) {\n return InputSizes[getScriptTypeForAddress(input.address as string)];\n }\n return TX_INPUT_BASE + TX_INPUT_PUBKEYHASH;\n};\n\nexport const getOutputSize = (output: TargetOutput, scriptType?: UTXOScriptType) => {\n if (output?.script) {\n return OP_RETURN_OVERHEAD + output.script.length + (output.script.length >= 74 ? 2 : 1);\n }\n if (scriptType) {\n return OutputSizes[scriptType];\n }\n return OutputSizes[UTXOScriptType.P2PKH];\n};\n",
|
|
11
|
-
"import {\n AssetValue,\n Chain,\n type ChainSigner,\n DerivationPath,\n type DerivationPathArray,\n FeeOption,\n NetworkDerivationPath,\n SwapKitNumber,\n type UTXOChain,\n derivationPathToString,\n updateDerivationPath,\n} from \"@swapkit/helpers\";\nimport type { Psbt } from \"bitcoinjs-lib\";\nimport type { ECPairInterface } from \"ecpair\";\nimport type { UtxoToolboxParams } from \".\";\nimport { getBalance } from \"../../utils\";\nimport {\n UTXOScriptType,\n accumulative,\n calculateTxSize,\n compileMemo,\n getDustThreshold,\n getInputSize,\n getUtxoApi,\n getUtxoNetwork,\n} from \"../helpers\";\nimport type {\n BchECPair,\n TargetOutput,\n UTXOBuildTxParams,\n UTXOTransferParams,\n UTXOType,\n} from \"../types\";\nimport { bchValidateAddress } from \"./bitcoinCash\";\n\nexport const nonSegwitChains = [Chain.Dash, Chain.Dogecoin];\n\nasync function addInputsAndOutputs({\n inputs,\n outputs,\n chain,\n psbt,\n sender,\n compiledMemo,\n}: {\n inputs: UTXOType[];\n outputs: TargetOutput[];\n chain: UTXOChain;\n psbt: Psbt;\n sender: string;\n compiledMemo: Buffer<ArrayBufferLike> | null;\n}) {\n for (const utxo of inputs) {\n const witnessInfo = !!utxo.witnessUtxo &&\n !nonSegwitChains.includes(chain) && { witnessUtxo: utxo.witnessUtxo };\n\n const nonWitnessInfo = nonSegwitChains.includes(chain) && {\n nonWitnessUtxo: utxo.txHex ? Buffer.from(utxo.txHex, \"hex\") : undefined,\n };\n\n psbt.addInput({ hash: utxo.hash, index: utxo.index, ...witnessInfo, ...nonWitnessInfo });\n }\n\n const { initEccLib } = await import(\"bitcoinjs-lib\");\n const secp256k1 = await import(\"@bitcoinerlab/secp256k1\");\n\n for (const output of outputs) {\n const address = \"address\" in output && output.address ? output.address : sender;\n const hasOutputScript = output.script;\n\n if (hasOutputScript && !compiledMemo) {\n continue;\n }\n\n const mappedOutput = hasOutputScript\n ? {\n script: compiledMemo as Buffer<ArrayBufferLike>,\n value: 0,\n }\n : {\n address,\n value: output.value,\n };\n\n initEccLib(secp256k1);\n psbt.addOutput(mappedOutput);\n }\n\n return { psbt, inputs };\n}\n\nasync function createTransaction({\n assetValue,\n recipient,\n memo,\n feeRate,\n sender,\n fetchTxHex = false,\n}: UTXOBuildTxParams): Promise<{\n psbt: Psbt;\n utxos: UTXOType[];\n inputs: UTXOType[];\n}> {\n const chain = assetValue.chain as UTXOChain;\n\n const { Psbt } = await import(\"bitcoinjs-lib\");\n const compiledMemo = memo ? await compileMemo(memo) : null;\n\n const inputsAndOutputs = await getInputsAndTargetOutputs({\n assetValue,\n recipient,\n memo,\n sender,\n fetchTxHex,\n });\n\n const { inputs, outputs } = accumulative({ ...inputsAndOutputs, feeRate, chain });\n\n // .inputs and .outputs will be undefined if no solution was found\n if (!(inputs && outputs)) throw new Error(\"Insufficient Balance for transaction\");\n const getNetwork = await getUtxoNetwork();\n const psbt = new Psbt({ network: getNetwork(chain) });\n\n if (chain === Chain.Dogecoin) psbt.setMaximumFeeRate(650000000);\n\n const { psbt: mappedPsbt, inputs: mappedInputs } = await addInputsAndOutputs({\n inputs,\n outputs,\n chain,\n psbt,\n sender,\n compiledMemo,\n });\n\n return {\n psbt: mappedPsbt,\n utxos: inputsAndOutputs.inputs,\n inputs: mappedInputs,\n };\n}\n\nexport async function getUTXOAddressValidator() {\n const secp256k1 = await import(\"@bitcoinerlab/secp256k1\");\n const { initEccLib, address: btcLibAddress } = await import(\"bitcoinjs-lib\");\n const getNetwork = await getUtxoNetwork();\n\n return function validateAddress({ address, chain }: { address: string; chain: UTXOChain }) {\n if (chain === Chain.BitcoinCash) {\n return bchValidateAddress(address);\n }\n\n try {\n initEccLib(secp256k1);\n btcLibAddress.toOutputScript(address, getNetwork(chain));\n return true;\n } catch (_error) {\n return false;\n }\n };\n}\n\nasync function createSignerWithKeys({\n chain,\n phrase,\n derivationPath,\n}: { chain: UTXOChain; phrase: string; derivationPath: string }) {\n const keyPair = (await getCreateKeysForPath(chain as Chain.Bitcoin))({ phrase, derivationPath });\n\n async function signTransaction(psbt: Psbt) {\n await psbt.signAllInputs(keyPair);\n return psbt;\n }\n\n async function getAddress() {\n const addressGetter = await addressFromKeysGetter(chain);\n return addressGetter(keyPair);\n }\n\n return {\n getAddress,\n signTransaction,\n };\n}\n\nexport async function createUTXOToolbox<T extends UTXOChain>({\n chain,\n ...toolboxParams\n}: (\n | UtxoToolboxParams[T]\n | {\n phrase?: string;\n derivationPath?: DerivationPathArray;\n index?: number;\n }\n) & { chain: T }) {\n const phrase = \"phrase\" in toolboxParams ? toolboxParams.phrase : undefined;\n\n const index = \"index\" in toolboxParams ? toolboxParams.index || 0 : 0;\n\n const derivationPath = derivationPathToString(\n \"derivationPath\" in toolboxParams && toolboxParams.derivationPath\n ? toolboxParams.derivationPath\n : updateDerivationPath(NetworkDerivationPath[chain], { index }),\n );\n\n const signer = phrase\n ? await createSignerWithKeys({ chain, phrase, derivationPath })\n : \"signer\" in toolboxParams\n ? toolboxParams.signer\n : undefined;\n\n function getAddress() {\n return Promise.resolve(signer?.getAddress());\n }\n\n // const { signer } = params || {};\n const getAddressFromKeys = await addressFromKeysGetter(chain);\n const validateAddress = await getUTXOAddressValidator();\n const createKeysForPath = await getCreateKeysForPath(chain);\n\n return {\n accumulative,\n calculateTxSize,\n getAddressFromKeys,\n getAddress,\n validateAddress: (address: string) => validateAddress({ address, chain }),\n broadcastTx: (txHash: string) => getUtxoApi(chain).broadcastTx(txHash),\n createTransaction,\n createKeysForPath,\n getFeeRates: () => getFeeRates(chain),\n getInputsOutputsFee,\n transfer: transfer(signer as UtxoToolboxParams[\"BTC\"][\"signer\"]),\n getPrivateKeyFromMnemonic: (params: { phrase: string; derivationPath: string }) => {\n const keys = createKeysForPath(params);\n return keys.toWIF();\n },\n\n getBalance: getBalance(chain),\n estimateTransactionFee: estimateTransactionFee(chain),\n estimateMaxSendableAmount: estimateMaxSendableAmount(chain),\n };\n}\n\nasync function getInputsOutputsFee({\n assetValue,\n feeOptionKey = FeeOption.Fast,\n feeRate,\n memo,\n sender,\n recipient,\n}: Omit<UTXOBuildTxParams, \"feeRate\"> & {\n feeOptionKey?: FeeOption;\n feeRate?: number;\n}) {\n const chain = assetValue.chain as UTXOChain;\n\n const inputsAndOutputs = await getInputsAndTargetOutputs({\n assetValue,\n sender,\n memo,\n recipient,\n });\n\n const feeRateWhole = feeRate ? Math.floor(feeRate) : (await getFeeRates(chain))[feeOptionKey];\n\n return accumulative({ ...inputsAndOutputs, feeRate: feeRateWhole, chain });\n}\n\nfunction estimateMaxSendableAmount(chain: UTXOChain) {\n return async function estimateMaxSendableAmount({\n from,\n memo,\n feeRate,\n feeOptionKey = FeeOption.Fast,\n recipients = 1,\n }: {\n from: string;\n memo?: string;\n feeRate?: number;\n feeOptionKey?: FeeOption;\n recipients?: number | TargetOutput[];\n }) {\n const addressData = await getUtxoApi(chain).getAddressData(from);\n const feeRateWhole = feeRate ? Math.ceil(feeRate) : (await getFeeRates(chain))[feeOptionKey];\n\n const inputs = addressData?.utxo\n .map((utxo) => ({\n ...utxo,\n // type: utxo.witnessUtxo ? UTXOScriptType.P2WPKH : UTXOScriptType.P2PKH,\n type: UTXOScriptType.P2PKH,\n hash: \"\",\n }))\n .filter(\n (utxo) => utxo.value > Math.max(getDustThreshold(chain), getInputSize(utxo) * feeRateWhole),\n );\n\n if (!inputs?.length) return AssetValue.from({ chain });\n\n const balance = AssetValue.from({\n chain,\n value: inputs.reduce((sum, utxo) => sum + utxo.value, 0),\n });\n\n const outputs =\n typeof recipients === \"number\"\n ? (Array.from({ length: recipients }, () => ({\n address: from,\n value: 0,\n })) as TargetOutput[])\n : recipients;\n\n if (memo) {\n const script = await compileMemo(memo);\n outputs.push({ address: from, script, value: 0 });\n }\n\n const txSize = calculateTxSize({ inputs, outputs, feeRate: feeRateWhole });\n\n const fee = txSize * feeRateWhole;\n\n return balance.sub(fee);\n };\n}\n\nfunction estimateTransactionFee(chain: UTXOChain) {\n return async (params: {\n assetValue: AssetValue;\n recipient: string;\n sender: string;\n memo?: string;\n feeOptionKey?: FeeOption;\n feeRate?: number;\n fetchTxHex?: boolean;\n }) => {\n const inputFees = await getInputsOutputsFee(params);\n\n return AssetValue.from({\n chain,\n value: SwapKitNumber.fromBigInt(BigInt(inputFees.fee), 8).getValue(\"string\"),\n });\n };\n}\n\ntype CreateKeysForPathReturnType = {\n [Chain.BitcoinCash]: BchECPair;\n [Chain.Bitcoin]: ECPairInterface;\n [Chain.Dash]: ECPairInterface;\n [Chain.Dogecoin]: ECPairInterface;\n [Chain.Litecoin]: ECPairInterface;\n};\n\nexport async function getCreateKeysForPath<T extends keyof CreateKeysForPathReturnType>(\n chain: T,\n): Promise<\n (params: {\n wif?: string;\n phrase?: string;\n derivationPath?: string;\n }) => CreateKeysForPathReturnType[T]\n> {\n const { ECPairFactory } = await import(\"ecpair\");\n const secp256k1 = await import(\"@bitcoinerlab/secp256k1\");\n const { HDKey } = await import(\"@scure/bip32\");\n const { mnemonicToSeedSync } = await import(\"@scure/bip39\");\n const getNetwork = await getUtxoNetwork();\n // @ts-ignore\n const { HDNode, ECPair } = await import(\"@psf/bitcoincashjs-lib\");\n\n switch (chain) {\n case Chain.BitcoinCash: {\n return function createKeysForPath({\n phrase,\n derivationPath = `${DerivationPath.BCH}/0`,\n wif,\n }: { wif?: string; phrase?: string; derivationPath?: string }) {\n const network = getNetwork(chain);\n\n if (wif) {\n return ECPair.fromWIF(wif, network) as BchECPair;\n }\n if (!phrase) throw new Error(\"No phrase provided\");\n\n const masterHDNode = HDNode.fromSeedBuffer(\n Buffer.from(mnemonicToSeedSync(phrase)),\n network,\n );\n const keyPair = masterHDNode.derivePath(derivationPath).keyPair;\n\n return keyPair as BchECPair;\n } as (params: {\n wif?: string;\n phrase?: string;\n derivationPath?: string;\n }) => CreateKeysForPathReturnType[T];\n }\n case Chain.Bitcoin:\n case Chain.Dogecoin:\n case Chain.Litecoin:\n case Chain.Dash: {\n return function createKeysForPath({\n phrase,\n wif,\n derivationPath,\n }: { phrase?: string; wif?: string; derivationPath: string }) {\n if (!(wif || phrase)) throw new Error(\"Either phrase or wif must be provided\");\n\n const factory = ECPairFactory(secp256k1);\n const network = getNetwork(chain);\n\n if (wif) return factory.fromWIF(wif, network);\n\n const seed = mnemonicToSeedSync(phrase as string);\n const master = HDKey.fromMasterSeed(seed, network).derive(derivationPath);\n if (!master.privateKey) throw new Error(\"Could not get private key from phrase\");\n\n return factory.fromPrivateKey(Buffer.from(master.privateKey), { network });\n } as (params: {\n wif?: string;\n phrase?: string;\n derivationPath?: string;\n }) => CreateKeysForPathReturnType[T];\n }\n default:\n throw new Error(`Chain ${chain} is not supported`);\n }\n}\n\nexport async function addressFromKeysGetter(chain: UTXOChain) {\n const { payments } = await import(\"bitcoinjs-lib\");\n const getNetwork = await getUtxoNetwork();\n\n return function getAddressFromKeys(keys: ECPairInterface | BchECPair) {\n if (!keys) throw new Error(\"Keys must be provided\");\n\n const method = nonSegwitChains.includes(chain) ? payments.p2pkh : payments.p2wpkh;\n const { address } = method({ pubkey: keys.publicKey as Buffer, network: getNetwork(chain) });\n if (!address) throw new Error(\"Address not defined\");\n\n return address;\n };\n}\n\nfunction transfer(signer?: ChainSigner<Psbt, Psbt>) {\n return async function transfer({\n memo,\n recipient,\n feeOptionKey,\n feeRate,\n assetValue,\n }: UTXOTransferParams) {\n const from = await signer?.getAddress();\n\n const chain = assetValue.chain as UTXOChain;\n\n if (!(signer && from)) throw new Error(\"From address must be provided\");\n if (!recipient) throw new Error(\"Recipient address must be provided\");\n const txFeeRate = feeRate || (await getFeeRates(chain))[feeOptionKey || FeeOption.Fast];\n\n const { psbt } = await createTransaction({\n recipient,\n feeRate: txFeeRate,\n sender: from,\n assetValue,\n memo,\n });\n const signedPsbt = await signer.signTransaction(psbt);\n signedPsbt.finalizeAllInputs(); // Finalise inputs\n // TX extracted and formatted to hex\n return getUtxoApi(chain).broadcastTx(signedPsbt.extractTransaction().toHex());\n };\n}\n\nasync function getFeeRates(chain: UTXOChain) {\n const suggestedFeeRate = await getUtxoApi(chain).getSuggestedTxFee();\n\n return {\n [FeeOption.Average]: suggestedFeeRate,\n [FeeOption.Fast]: suggestedFeeRate * 1.5,\n [FeeOption.Fastest]: suggestedFeeRate * 2.0,\n };\n}\n\nasync function getInputsAndTargetOutputs({\n assetValue,\n recipient,\n memo,\n sender,\n fetchTxHex: fetchTxOverwrite = false,\n}: Omit<UTXOBuildTxParams, \"feeRate\">) {\n const chain = assetValue.chain as UTXOChain;\n\n const fetchTxHex = fetchTxOverwrite || nonSegwitChains.includes(chain);\n\n const inputs = await getUtxoApi(chain).scanUTXOs({ address: sender, fetchTxHex });\n\n //1. add output amount and recipient to targets\n //2. add output memo to targets (optional)\n\n return {\n inputs,\n outputs: [\n { address: recipient, value: Number(assetValue.bigIntValue) },\n ...(memo ? [{ address: \"\", script: await compileMemo(memo), value: 0 }] : []),\n ],\n };\n}\n"
|
|
10
|
+
"import type {\n TargetOutput,\n UTXOCalculateTxSizeParams,\n UTXOInputWithScriptType,\n UTXOType,\n} from \"../types\";\n\n/**\n * Minimum transaction fee\n * 1000 satoshi/kB (similar to current `minrelaytxfee`)\n * @see https://github.com/bitcoin/bitcoin/blob/db88db47278d2e7208c50d16ab10cb355067d071/src/validation.h#L56\n */\nexport const MIN_TX_FEE = 1000;\nexport const TX_OVERHEAD = 4 + 1 + 1 + 4; //10\nexport const OP_RETURN_OVERHEAD = 1 + 8 + 1; //10\nconst TX_INPUT_BASE = 32 + 4 + 1 + 4; // 41\nconst TX_INPUT_PUBKEYHASH = 107;\n\nexport async function compileMemo(memo: string) {\n const { script, opcodes } = (await import(\"bitcoinjs-lib\")).default;\n const data = Buffer.from(memo, \"utf8\"); // converts MEMO to buffer\n return script.compile([opcodes.OP_RETURN as number, data]); // Compile OP_RETURN script\n}\n\nexport enum UTXOScriptType {\n P2PKH = \"P2PKH\", // legacy\n // P2SH = 'P2SH', // multisig\n P2WPKH = \"P2WPKH\", // bech32 - native segwit\n // P2TR = \"P2TR\", // taproot\n}\n\nexport const InputSizes: Record<UTXOScriptType, number> = {\n [UTXOScriptType.P2PKH]: 148,\n // [UTXOScriptType.P2SH]: 91,\n [UTXOScriptType.P2WPKH]: 68,\n};\n\nexport const OutputSizes: Record<UTXOScriptType, number> = {\n [UTXOScriptType.P2PKH]: 34,\n // [UTXOScriptType.P2SH]: 91,\n [UTXOScriptType.P2WPKH]: 31,\n};\n\nexport const getScriptTypeForAddress = (address: string) => {\n if (address.startsWith(\"bc1\") || address.startsWith(\"ltc1\")) {\n return UTXOScriptType.P2WPKH;\n }\n // if (address.startsWith('3') || address.startsWith('M')) {\n // return UTXOScriptType.P2SH;\n // }\n if (\n address.startsWith(\"1\") ||\n address.startsWith(\"3\") ||\n address.startsWith(\"L\") ||\n address.startsWith(\"M\") ||\n address.startsWith(\"X\") ||\n address.startsWith(\"D\") ||\n address.startsWith(\"bitcoincash:q\") ||\n address.startsWith(\"q\")\n ) {\n return UTXOScriptType.P2PKH;\n }\n throw new Error(\"Invalid address\");\n};\n\nexport const calculateTxSize = ({ inputs, outputs, feeRate }: UTXOCalculateTxSizeParams) => {\n const newTxType =\n inputs[0] && \"address\" in inputs[0] && inputs[0].address\n ? getScriptTypeForAddress(inputs[0].address)\n : UTXOScriptType.P2PKH;\n const inputSize = inputs\n .filter(\n (utxo) =>\n utxo.value >=\n InputSizes[\"type\" in utxo ? utxo.type : UTXOScriptType.P2PKH] * Math.ceil(feeRate),\n )\n .reduce((total, utxo) => total + getInputSize(utxo), 0);\n\n const outputSize =\n outputs?.reduce((total, output) => total + getOutputSize(output), 0) || OutputSizes[newTxType];\n\n return TX_OVERHEAD + inputSize + outputSize;\n};\n\nexport const getInputSize = (input: UTXOInputWithScriptType | UTXOType) => {\n if (\"type\" in input) {\n return InputSizes[input.type];\n }\n if (\"address\" in input && input.address) {\n return InputSizes[getScriptTypeForAddress(input.address as string)];\n }\n return TX_INPUT_BASE + TX_INPUT_PUBKEYHASH;\n};\n\nexport const getOutputSize = (output: TargetOutput, scriptType?: UTXOScriptType) => {\n if (output?.script) {\n return OP_RETURN_OVERHEAD + output.script.length + (output.script.length >= 74 ? 2 : 1);\n }\n if (scriptType) {\n return OutputSizes[scriptType];\n }\n return OutputSizes[UTXOScriptType.P2PKH];\n};\n",
|
|
11
|
+
"import {\n AssetValue,\n Chain,\n type ChainSigner,\n DerivationPath,\n type DerivationPathArray,\n FeeOption,\n NetworkDerivationPath,\n SwapKitNumber,\n type UTXOChain,\n derivationPathToString,\n updateDerivationPath,\n} from \"@swapkit/helpers\";\nimport type { Psbt } from \"bitcoinjs-lib\";\nimport type { ECPairInterface } from \"ecpair\";\nimport type { UtxoToolboxParams } from \".\";\nimport { getBalance } from \"../../utils\";\nimport {\n UTXOScriptType,\n accumulative,\n calculateTxSize,\n compileMemo,\n getDustThreshold,\n getInputSize,\n getUtxoApi,\n getUtxoNetwork,\n} from \"../helpers\";\nimport type {\n BchECPair,\n TargetOutput,\n UTXOBuildTxParams,\n UTXOTransferParams,\n UTXOType,\n} from \"../types\";\nimport { bchValidateAddress } from \"./bitcoinCash\";\n\nexport const nonSegwitChains = [Chain.Dash, Chain.Dogecoin];\n\nasync function addInputsAndOutputs({\n inputs,\n outputs,\n chain,\n psbt,\n sender,\n compiledMemo,\n}: {\n inputs: UTXOType[];\n outputs: TargetOutput[];\n chain: UTXOChain;\n psbt: Psbt;\n sender: string;\n compiledMemo: Buffer<ArrayBufferLike> | null;\n}) {\n for (const utxo of inputs) {\n const witnessInfo = !!utxo.witnessUtxo &&\n !nonSegwitChains.includes(chain) && { witnessUtxo: utxo.witnessUtxo };\n\n const nonWitnessInfo = nonSegwitChains.includes(chain) && {\n nonWitnessUtxo: utxo.txHex ? Buffer.from(utxo.txHex, \"hex\") : undefined,\n };\n\n psbt.addInput({ hash: utxo.hash, index: utxo.index, ...witnessInfo, ...nonWitnessInfo });\n }\n\n const { initEccLib } = (await import(\"bitcoinjs-lib\")).default;\n const secp256k1 = (await import(\"@bitcoinerlab/secp256k1\")).default;\n\n for (const output of outputs) {\n const address = \"address\" in output && output.address ? output.address : sender;\n const hasOutputScript = output.script;\n\n if (hasOutputScript && !compiledMemo) {\n continue;\n }\n\n const mappedOutput = hasOutputScript\n ? {\n script: compiledMemo as Buffer<ArrayBufferLike>,\n value: 0,\n }\n : {\n address,\n value: output.value,\n };\n\n initEccLib(secp256k1);\n psbt.addOutput(mappedOutput);\n }\n\n return { psbt, inputs };\n}\n\nasync function createTransaction({\n assetValue,\n recipient,\n memo,\n feeRate,\n sender,\n fetchTxHex = false,\n}: UTXOBuildTxParams): Promise<{\n psbt: Psbt;\n utxos: UTXOType[];\n inputs: UTXOType[];\n}> {\n const chain = assetValue.chain as UTXOChain;\n\n const { Psbt } = (await import(\"bitcoinjs-lib\")).default;\n const compiledMemo = memo ? await compileMemo(memo) : null;\n\n const inputsAndOutputs = await getInputsAndTargetOutputs({\n assetValue,\n recipient,\n memo,\n sender,\n fetchTxHex,\n });\n\n const { inputs, outputs } = accumulative({ ...inputsAndOutputs, feeRate, chain });\n\n // .inputs and .outputs will be undefined if no solution was found\n if (!(inputs && outputs)) throw new Error(\"Insufficient Balance for transaction\");\n const getNetwork = await getUtxoNetwork();\n const psbt = new Psbt({ network: getNetwork(chain) });\n\n if (chain === Chain.Dogecoin) psbt.setMaximumFeeRate(650000000);\n\n const { psbt: mappedPsbt, inputs: mappedInputs } = await addInputsAndOutputs({\n inputs,\n outputs,\n chain,\n psbt,\n sender,\n compiledMemo,\n });\n\n return {\n psbt: mappedPsbt,\n utxos: inputsAndOutputs.inputs,\n inputs: mappedInputs,\n };\n}\n\nexport async function getUTXOAddressValidator() {\n const secp256k1 = (await import(\"@bitcoinerlab/secp256k1\")).default;\n const { initEccLib, address: btcLibAddress } = (await import(\"bitcoinjs-lib\")).default;\n const getNetwork = await getUtxoNetwork();\n\n return function validateAddress({ address, chain }: { address: string; chain: UTXOChain }) {\n if (chain === Chain.BitcoinCash) {\n return bchValidateAddress(address);\n }\n\n try {\n initEccLib(secp256k1);\n btcLibAddress.toOutputScript(address, getNetwork(chain));\n return true;\n } catch (_error) {\n return false;\n }\n };\n}\n\nasync function createSignerWithKeys({\n chain,\n phrase,\n derivationPath,\n}: { chain: UTXOChain; phrase: string; derivationPath: string }) {\n const keyPair = (await getCreateKeysForPath(chain as Chain.Bitcoin))({ phrase, derivationPath });\n\n async function signTransaction(psbt: Psbt) {\n await psbt.signAllInputs(keyPair);\n return psbt;\n }\n\n async function getAddress() {\n const addressGetter = await addressFromKeysGetter(chain);\n return addressGetter(keyPair);\n }\n\n return {\n getAddress,\n signTransaction,\n };\n}\n\nexport async function createUTXOToolbox<T extends UTXOChain>({\n chain,\n ...toolboxParams\n}: (\n | UtxoToolboxParams[T]\n | {\n phrase?: string;\n derivationPath?: DerivationPathArray;\n index?: number;\n }\n) & { chain: T }) {\n const phrase = \"phrase\" in toolboxParams ? toolboxParams.phrase : undefined;\n\n const index = \"index\" in toolboxParams ? toolboxParams.index || 0 : 0;\n\n const derivationPath = derivationPathToString(\n \"derivationPath\" in toolboxParams && toolboxParams.derivationPath\n ? toolboxParams.derivationPath\n : updateDerivationPath(NetworkDerivationPath[chain], { index }),\n );\n\n const signer = phrase\n ? await createSignerWithKeys({ chain, phrase, derivationPath })\n : \"signer\" in toolboxParams\n ? toolboxParams.signer\n : undefined;\n\n function getAddress() {\n return Promise.resolve(signer?.getAddress());\n }\n\n // const { signer } = params || {};\n const getAddressFromKeys = await addressFromKeysGetter(chain);\n const validateAddress = await getUTXOAddressValidator();\n const createKeysForPath = await getCreateKeysForPath(chain);\n\n return {\n accumulative,\n calculateTxSize,\n getAddressFromKeys,\n getAddress,\n validateAddress: (address: string) => validateAddress({ address, chain }),\n broadcastTx: (txHash: string) => getUtxoApi(chain).broadcastTx(txHash),\n createTransaction,\n createKeysForPath,\n getFeeRates: () => getFeeRates(chain),\n getInputsOutputsFee,\n transfer: transfer(signer as UtxoToolboxParams[\"BTC\"][\"signer\"]),\n getPrivateKeyFromMnemonic: (params: { phrase: string; derivationPath: string }) => {\n const keys = createKeysForPath(params);\n return keys.toWIF();\n },\n\n getBalance: getBalance(chain),\n estimateTransactionFee: estimateTransactionFee(chain),\n estimateMaxSendableAmount: estimateMaxSendableAmount(chain),\n };\n}\n\nasync function getInputsOutputsFee({\n assetValue,\n feeOptionKey = FeeOption.Fast,\n feeRate,\n memo,\n sender,\n recipient,\n}: Omit<UTXOBuildTxParams, \"feeRate\"> & {\n feeOptionKey?: FeeOption;\n feeRate?: number;\n}) {\n const chain = assetValue.chain as UTXOChain;\n\n const inputsAndOutputs = await getInputsAndTargetOutputs({\n assetValue,\n sender,\n memo,\n recipient,\n });\n\n const feeRateWhole = feeRate ? Math.floor(feeRate) : (await getFeeRates(chain))[feeOptionKey];\n\n return accumulative({ ...inputsAndOutputs, feeRate: feeRateWhole, chain });\n}\n\nfunction estimateMaxSendableAmount(chain: UTXOChain) {\n return async function estimateMaxSendableAmount({\n from,\n memo,\n feeRate,\n feeOptionKey = FeeOption.Fast,\n recipients = 1,\n }: {\n from: string;\n memo?: string;\n feeRate?: number;\n feeOptionKey?: FeeOption;\n recipients?: number | TargetOutput[];\n }) {\n const addressData = await getUtxoApi(chain).getAddressData(from);\n const feeRateWhole = feeRate ? Math.ceil(feeRate) : (await getFeeRates(chain))[feeOptionKey];\n\n const inputs = addressData?.utxo\n .map((utxo) => ({\n ...utxo,\n // type: utxo.witnessUtxo ? UTXOScriptType.P2WPKH : UTXOScriptType.P2PKH,\n type: UTXOScriptType.P2PKH,\n hash: \"\",\n }))\n .filter(\n (utxo) => utxo.value > Math.max(getDustThreshold(chain), getInputSize(utxo) * feeRateWhole),\n );\n\n if (!inputs?.length) return AssetValue.from({ chain });\n\n const balance = AssetValue.from({\n chain,\n value: inputs.reduce((sum, utxo) => sum + utxo.value, 0),\n });\n\n const outputs =\n typeof recipients === \"number\"\n ? (Array.from({ length: recipients }, () => ({\n address: from,\n value: 0,\n })) as TargetOutput[])\n : recipients;\n\n if (memo) {\n const script = await compileMemo(memo);\n outputs.push({ address: from, script, value: 0 });\n }\n\n const txSize = calculateTxSize({ inputs, outputs, feeRate: feeRateWhole });\n\n const fee = txSize * feeRateWhole;\n\n return balance.sub(fee);\n };\n}\n\nfunction estimateTransactionFee(chain: UTXOChain) {\n return async (params: {\n assetValue: AssetValue;\n recipient: string;\n sender: string;\n memo?: string;\n feeOptionKey?: FeeOption;\n feeRate?: number;\n fetchTxHex?: boolean;\n }) => {\n const inputFees = await getInputsOutputsFee(params);\n\n return AssetValue.from({\n chain,\n value: SwapKitNumber.fromBigInt(BigInt(inputFees.fee), 8).getValue(\"string\"),\n });\n };\n}\n\ntype CreateKeysForPathReturnType = {\n [Chain.BitcoinCash]: BchECPair;\n [Chain.Bitcoin]: ECPairInterface;\n [Chain.Dash]: ECPairInterface;\n [Chain.Dogecoin]: ECPairInterface;\n [Chain.Litecoin]: ECPairInterface;\n};\n\nexport async function getCreateKeysForPath<T extends keyof CreateKeysForPathReturnType>(\n chain: T,\n): Promise<\n (params: {\n wif?: string;\n phrase?: string;\n derivationPath?: string;\n }) => CreateKeysForPathReturnType[T]\n> {\n const { ECPairFactory } = await import(\"ecpair\");\n const secp256k1 = (await import(\"@bitcoinerlab/secp256k1\")).default;\n const { HDKey } = await import(\"@scure/bip32\");\n const { mnemonicToSeedSync } = await import(\"@scure/bip39\");\n const getNetwork = await getUtxoNetwork();\n // @ts-ignore\n const { HDNode, ECPair } = await import(\"@psf/bitcoincashjs-lib\");\n\n switch (chain) {\n case Chain.BitcoinCash: {\n return function createKeysForPath({\n phrase,\n derivationPath = `${DerivationPath.BCH}/0`,\n wif,\n }: { wif?: string; phrase?: string; derivationPath?: string }) {\n const network = getNetwork(chain);\n\n if (wif) {\n return ECPair.fromWIF(wif, network) as BchECPair;\n }\n if (!phrase) throw new Error(\"No phrase provided\");\n\n const masterHDNode = HDNode.fromSeedBuffer(\n Buffer.from(mnemonicToSeedSync(phrase)),\n network,\n );\n const keyPair = masterHDNode.derivePath(derivationPath).keyPair;\n\n return keyPair as BchECPair;\n } as (params: {\n wif?: string;\n phrase?: string;\n derivationPath?: string;\n }) => CreateKeysForPathReturnType[T];\n }\n case Chain.Bitcoin:\n case Chain.Dogecoin:\n case Chain.Litecoin:\n case Chain.Dash: {\n return function createKeysForPath({\n phrase,\n wif,\n derivationPath,\n }: { phrase?: string; wif?: string; derivationPath: string }) {\n if (!(wif || phrase)) throw new Error(\"Either phrase or wif must be provided\");\n\n const factory = ECPairFactory(secp256k1);\n const network = getNetwork(chain);\n\n if (wif) return factory.fromWIF(wif, network);\n\n const seed = mnemonicToSeedSync(phrase as string);\n const master = HDKey.fromMasterSeed(seed, network).derive(derivationPath);\n if (!master.privateKey) throw new Error(\"Could not get private key from phrase\");\n\n return factory.fromPrivateKey(Buffer.from(master.privateKey), { network });\n } as (params: {\n wif?: string;\n phrase?: string;\n derivationPath?: string;\n }) => CreateKeysForPathReturnType[T];\n }\n default:\n throw new Error(`Chain ${chain} is not supported`);\n }\n}\n\nexport async function addressFromKeysGetter(chain: UTXOChain) {\n const { payments } = (await import(\"bitcoinjs-lib\")).default;\n const getNetwork = await getUtxoNetwork();\n\n return function getAddressFromKeys(keys: ECPairInterface | BchECPair) {\n if (!keys) throw new Error(\"Keys must be provided\");\n\n const method = nonSegwitChains.includes(chain) ? payments.p2pkh : payments.p2wpkh;\n const { address } = method({ pubkey: keys.publicKey as Buffer, network: getNetwork(chain) });\n if (!address) throw new Error(\"Address not defined\");\n\n return address;\n };\n}\n\nfunction transfer(signer?: ChainSigner<Psbt, Psbt>) {\n return async function transfer({\n memo,\n recipient,\n feeOptionKey,\n feeRate,\n assetValue,\n }: UTXOTransferParams) {\n const from = await signer?.getAddress();\n\n const chain = assetValue.chain as UTXOChain;\n\n if (!(signer && from)) throw new Error(\"From address must be provided\");\n if (!recipient) throw new Error(\"Recipient address must be provided\");\n const txFeeRate = feeRate || (await getFeeRates(chain))[feeOptionKey || FeeOption.Fast];\n\n const { psbt } = await createTransaction({\n recipient,\n feeRate: txFeeRate,\n sender: from,\n assetValue,\n memo,\n });\n const signedPsbt = await signer.signTransaction(psbt);\n signedPsbt.finalizeAllInputs(); // Finalise inputs\n // TX extracted and formatted to hex\n return getUtxoApi(chain).broadcastTx(signedPsbt.extractTransaction().toHex());\n };\n}\n\nasync function getFeeRates(chain: UTXOChain) {\n const suggestedFeeRate = await getUtxoApi(chain).getSuggestedTxFee();\n\n return {\n [FeeOption.Average]: suggestedFeeRate,\n [FeeOption.Fast]: suggestedFeeRate * 1.5,\n [FeeOption.Fastest]: suggestedFeeRate * 2.0,\n };\n}\n\nasync function getInputsAndTargetOutputs({\n assetValue,\n recipient,\n memo,\n sender,\n fetchTxHex: fetchTxOverwrite = false,\n}: Omit<UTXOBuildTxParams, \"feeRate\">) {\n const chain = assetValue.chain as UTXOChain;\n\n const fetchTxHex = fetchTxOverwrite || nonSegwitChains.includes(chain);\n\n const inputs = await getUtxoApi(chain).scanUTXOs({ address: sender, fetchTxHex });\n\n //1. add output amount and recipient to targets\n //2. add output memo to targets (optional)\n\n return {\n inputs,\n outputs: [\n { address: recipient, value: Number(assetValue.bigIntValue) },\n ...(memo ? [{ address: \"\", script: await compileMemo(memo), value: 0 }] : []),\n ],\n };\n}\n"
|
|
12
12
|
],
|
|
13
|
-
"mappings": "uGAAA,WACE,yBCDF,gBACE,gBAGA,4BACA,6BACA,2BACA,0BCPF,gBAAS,mBAAO,cAAe,cAA0B,0BAUzD,eAAe,EAAe,EAAG,QAAO,UAA4C,CAClF,IAAM,EAAS,EAAS,IAAI,SAAS,EAAE,GACjC,EAAO,KAAK,UAAU,CAC1B,QAAS,MACT,OAAQ,qBACR,OAAQ,CAAC,CAAM,EACf,GAAI,GAAO,CACb,CAAC,EAEK,EAAW,MAAM,EAAc,KAIlC,EAAQ,CAAE,QAAS,CAAE,eAAgB,kBAAmB,EAAG,MAAK,CAAC,EAEpE,GAAI,EAAS,MACX,MAAM,IAAI,MAAM,sCAAsC,EAAS,OAAO,SAAS,EAGjF,GAAI,EAAS,OAAO,SAAS,YAAY,EACvC,MAAM,IAAI,MAAM,yDAAyD,EAG3E,OAAO,EAAS,OAGlB,SAAS,CAAO,CAAC,EAAc,CAC7B,MAAO,8BAA8B,GAA0B,CAAK,IAGtE,SAAS,EAAsB,CAAC,EAAc,CAC5C,OAAQ,QACD,EAAM,QACT,MAAO,QACJ,EAAM,SACT,MAAO,UACJ,EAAM,SACT,MAAO,WAEP,MAAO,IAIb,SAAS,EAAyB,CAAC,EAAc,CAC/C,OAAQ,QACD,EAAM,YACT,MAAO,oBACJ,EAAM,SACT,MAAO,gBACJ,EAAM,KACT,MAAO,YACJ,EAAM,SACT,MAAO,gBACJ,EAAM,SACT,MAAO,mBAEP,MAAO,WAIb,e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AK,UAAU,CAAM,EAIzB,MAAO,CAAE,OAAM,QAAO,OAAQ,CAAqB,EAGrD,SAAS,EAAkB,CAAC,EAAkD,CAC5E,IAAM,EAAU,EAAK,WAAW,CAAC,EACjC,OAAO,EAAmB,CAAO,ED1PnC,eAAsB,EAA6C,CACjE,EACA,EAO2B,CAC3B,OAAQ,QACD,EAAM,YAET,OADgB,MAAM,GAAiB,CAA8C,OAIlF,EAAM,aACN,EAAM,cACN,EAAM,cACN,EAAM,KAKT,OAJgB,MAAM,EAAkB,CACtC,WACI,CACN,CAAC,UAKD,MAAM,IAAI,MAAM,SAAS,oBAAwB",
|
|
14
|
+
"debugId": "1A09C092016276FC64756E2164756E21",
|
|
15
15
|
"names": []
|
|
16
16
|
}
|
package/package.json
CHANGED
|
@@ -20,7 +20,10 @@
|
|
|
20
20
|
"@scure/base": "1.2.4",
|
|
21
21
|
"@scure/bip32": "1.6.2",
|
|
22
22
|
"@scure/bip39": "1.5.4",
|
|
23
|
-
"@
|
|
23
|
+
"@solana/spl-memo": "0.2.5",
|
|
24
|
+
"@solana/spl-token": "0.4.13",
|
|
25
|
+
"@solana/web3.js": "1.98.2",
|
|
26
|
+
"@swapkit/helpers": "3.0.0-beta.9",
|
|
24
27
|
"base64-js": "1.5.1",
|
|
25
28
|
"bitcoinjs-lib": "6.1.7",
|
|
26
29
|
"bs58check": "4.0.0",
|
|
@@ -34,11 +37,6 @@
|
|
|
34
37
|
"ts-pattern": "5.7.0",
|
|
35
38
|
"xrpl": "4.2.0"
|
|
36
39
|
},
|
|
37
|
-
"peerDependencies": {
|
|
38
|
-
"@solana/spl-memo": "0.2.5",
|
|
39
|
-
"@solana/spl-token": "0.4.13",
|
|
40
|
-
"@solana/web3.js": "1.98.0"
|
|
41
|
-
},
|
|
42
40
|
"devDependencies": {
|
|
43
41
|
"@nomicfoundation/hardhat-ethers": "3.0.8",
|
|
44
42
|
"@nomicfoundation/hardhat-toolbox": "5.0.0",
|
|
@@ -107,5 +105,5 @@
|
|
|
107
105
|
"type-check:go": "tsgo"
|
|
108
106
|
},
|
|
109
107
|
"type": "module",
|
|
110
|
-
"version": "1.0.0-beta.
|
|
108
|
+
"version": "1.0.0-beta.10"
|
|
111
109
|
}
|
|
@@ -3,8 +3,8 @@ import { base64ToBech32, bech32ToBase64 } from "./addressFormat";
|
|
|
3
3
|
|
|
4
4
|
export async function createDefaultRegistry() {
|
|
5
5
|
const { $root } = await import("./types/MsgCompiled");
|
|
6
|
-
const { Registry } = await import("@cosmjs/proto-signing");
|
|
7
|
-
const { defaultRegistryTypes } = await import("@cosmjs/stargate");
|
|
6
|
+
const { Registry } = (await import("@cosmjs/proto-signing")).default;
|
|
7
|
+
const { defaultRegistryTypes } = (await import("@cosmjs/stargate")).default;
|
|
8
8
|
|
|
9
9
|
return new Registry([
|
|
10
10
|
...defaultRegistryTypes,
|
|
@@ -14,7 +14,7 @@ export async function createDefaultRegistry() {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export async function createDefaultAminoTypes(chain: Chain.THORChain | Chain.Maya) {
|
|
17
|
-
const { AminoTypes } = await import("@cosmjs/stargate");
|
|
17
|
+
const { AminoTypes } = (await import("@cosmjs/stargate")).default;
|
|
18
18
|
const aminoTypePrefix = chain === Chain.THORChain ? "thorchain" : "mayachain";
|
|
19
19
|
|
|
20
20
|
return new AminoTypes({
|
|
@@ -52,8 +52,8 @@ export async function getSignerFromPhrase({
|
|
|
52
52
|
| { chain: Chain; index?: number }
|
|
53
53
|
| { derivationPath: string }
|
|
54
54
|
)) {
|
|
55
|
-
const { DirectSecp256k1HdWallet } = await import("@cosmjs/proto-signing");
|
|
56
|
-
const { stringToPath } = await import("@cosmjs/crypto");
|
|
55
|
+
const { DirectSecp256k1HdWallet } = (await import("@cosmjs/proto-signing")).default;
|
|
56
|
+
const { stringToPath } = (await import("@cosmjs/crypto")).default;
|
|
57
57
|
|
|
58
58
|
const derivationPath =
|
|
59
59
|
"derivationPath" in derivationParams
|
|
@@ -73,7 +73,7 @@ export async function getSignerFromPrivateKey({
|
|
|
73
73
|
privateKey: Uint8Array;
|
|
74
74
|
prefix: string;
|
|
75
75
|
}) {
|
|
76
|
-
const { DirectSecp256k1Wallet } = await import("@cosmjs/proto-signing");
|
|
76
|
+
const { DirectSecp256k1Wallet } = (await import("@cosmjs/proto-signing")).default;
|
|
77
77
|
|
|
78
78
|
return DirectSecp256k1Wallet.fromKey(privateKey, prefix);
|
|
79
79
|
}
|
|
@@ -97,7 +97,7 @@ export function verifySignature(getAccount: (address: string) => Promise<Account
|
|
|
97
97
|
}) {
|
|
98
98
|
const account = await getAccount(address);
|
|
99
99
|
if (!account?.pubkey) throw new SwapKitError("toolbox_cosmos_verify_signature_no_pubkey");
|
|
100
|
-
const { Secp256k1Signature, Secp256k1 } = await import("@cosmjs/crypto");
|
|
100
|
+
const { Secp256k1Signature, Secp256k1 } = (await import("@cosmjs/crypto")).default;
|
|
101
101
|
|
|
102
102
|
const secpSignature = Secp256k1Signature.fromFixedLength(base64.decode(signature));
|
|
103
103
|
return Secp256k1.verifySignature(secpSignature, base64.decode(message), account.pubkey.value);
|
|
@@ -197,7 +197,7 @@ export async function createCosmosToolbox({ chain, ...toolboxParams }: CosmosToo
|
|
|
197
197
|
index,
|
|
198
198
|
}),
|
|
199
199
|
getSignerFromPrivateKey: async (privateKey: Uint8Array) => {
|
|
200
|
-
const { DirectSecp256k1Wallet } = await import("@cosmjs/proto-signing");
|
|
200
|
+
const { DirectSecp256k1Wallet } = (await import("@cosmjs/proto-signing")).default;
|
|
201
201
|
return DirectSecp256k1Wallet.fromKey(privateKey, chainPrefix);
|
|
202
202
|
},
|
|
203
203
|
createPrivateKeyFromPhrase: createPrivateKeyFromPhrase(derivationPath),
|
|
@@ -43,8 +43,8 @@ function secp256k1HdWalletFromMnemonic({
|
|
|
43
43
|
derivationPath?: string;
|
|
44
44
|
}) {
|
|
45
45
|
return async function secp256k1HdWalletFromMnemonic(mnemonic: string, index = 0) {
|
|
46
|
-
const { Secp256k1HdWallet } = await import("@cosmjs/amino");
|
|
47
|
-
const { stringToPath } = await import("@cosmjs/crypto");
|
|
46
|
+
const { Secp256k1HdWallet } = (await import("@cosmjs/amino")).default;
|
|
47
|
+
const { stringToPath } = (await import("@cosmjs/crypto")).default;
|
|
48
48
|
|
|
49
49
|
return Secp256k1HdWallet.fromMnemonic(mnemonic, {
|
|
50
50
|
hdPaths: [stringToPath(`${derivationPath}/${index}`)],
|
|
@@ -114,8 +114,8 @@ function broadcastMultisigTx({
|
|
|
114
114
|
threshold: number,
|
|
115
115
|
bodyBytes: Uint8Array,
|
|
116
116
|
) {
|
|
117
|
-
const { encodeSecp256k1Pubkey, pubkeyToAddress } = await import("@cosmjs/amino");
|
|
118
|
-
const { makeMultisignedTxBytes } = await import("@cosmjs/stargate");
|
|
117
|
+
const { encodeSecp256k1Pubkey, pubkeyToAddress } = (await import("@cosmjs/amino")).default;
|
|
118
|
+
const { makeMultisignedTxBytes } = (await import("@cosmjs/stargate")).default;
|
|
119
119
|
|
|
120
120
|
const { sequence, fee } = JSON.parse(tx);
|
|
121
121
|
const multisigPubkey = await createMultisig(membersPubKeys, threshold);
|
|
@@ -142,7 +142,8 @@ function broadcastMultisigTx({
|
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
async function createMultisig(pubKeys: string[], threshold: number, noSortPubKeys = true) {
|
|
145
|
-
const { createMultisigThresholdPubkey, encodeSecp256k1Pubkey } = await import("@cosmjs/amino")
|
|
145
|
+
const { createMultisigThresholdPubkey, encodeSecp256k1Pubkey } = (await import("@cosmjs/amino"))
|
|
146
|
+
.default;
|
|
146
147
|
return createMultisigThresholdPubkey(
|
|
147
148
|
pubKeys.map((pubKey) => encodeSecp256k1Pubkey(base64.decode(pubKey))),
|
|
148
149
|
threshold,
|
|
@@ -161,7 +162,7 @@ async function signWithPrivateKey({
|
|
|
161
162
|
privateKey: Uint8Array;
|
|
162
163
|
message: string;
|
|
163
164
|
}) {
|
|
164
|
-
const { Secp256k1 } = await import("@cosmjs/crypto");
|
|
165
|
+
const { Secp256k1 } = (await import("@cosmjs/crypto")).default;
|
|
165
166
|
|
|
166
167
|
const signature = await Secp256k1.createSignature(base64.decode(message), privateKey);
|
|
167
168
|
return base64.encode(Buffer.concat([signature.r(32), signature.s(32)]));
|
|
@@ -301,7 +302,7 @@ export async function createThorchainToolbox({
|
|
|
301
302
|
signWithPrivateKey,
|
|
302
303
|
transfer,
|
|
303
304
|
pubkeyToAddress: async (pubkey: Pubkey) => {
|
|
304
|
-
const { pubkeyToAddress } = await import("@cosmjs/amino");
|
|
305
|
+
const { pubkeyToAddress } = (await import("@cosmjs/amino")).default;
|
|
305
306
|
return pubkeyToAddress(pubkey, chainPrefix);
|
|
306
307
|
},
|
|
307
308
|
};
|
package/src/cosmos/util.ts
CHANGED
|
@@ -69,7 +69,7 @@ export const getDenomWithChain = ({ symbol, chain }: AssetValue) => {
|
|
|
69
69
|
};
|
|
70
70
|
|
|
71
71
|
export async function createStargateClient(url: string) {
|
|
72
|
-
const { StargateClient } = await import("@cosmjs/stargate");
|
|
72
|
+
const { StargateClient } = (await import("@cosmjs/stargate")).default;
|
|
73
73
|
|
|
74
74
|
return StargateClient.connect(url);
|
|
75
75
|
}
|
|
@@ -79,7 +79,7 @@ export async function createSigningStargateClient(
|
|
|
79
79
|
signer: any,
|
|
80
80
|
optionsOrBaseGas: string | SigningStargateClientOptions = {},
|
|
81
81
|
) {
|
|
82
|
-
const { SigningStargateClient, GasPrice } = await import("@cosmjs/stargate");
|
|
82
|
+
const { SigningStargateClient, GasPrice } = (await import("@cosmjs/stargate")).default;
|
|
83
83
|
const gasPrice = typeof optionsOrBaseGas === "string" ? optionsOrBaseGas : "0.0003uatom";
|
|
84
84
|
const options = typeof optionsOrBaseGas === "string" ? {} : optionsOrBaseGas;
|
|
85
85
|
|
|
@@ -93,7 +93,7 @@ export async function createOfflineStargateClient(
|
|
|
93
93
|
wallet: OfflineSigner,
|
|
94
94
|
registry?: SigningStargateClientOptions,
|
|
95
95
|
) {
|
|
96
|
-
const { SigningStargateClient } = await import("@cosmjs/stargate");
|
|
96
|
+
const { SigningStargateClient } = (await import("@cosmjs/stargate")).default;
|
|
97
97
|
|
|
98
98
|
return SigningStargateClient.offline(wallet, registry);
|
|
99
99
|
}
|
|
@@ -538,6 +538,7 @@ function getEstimateGasLimit({ provider, signer }: ToolboxWrapParams) {
|
|
|
538
538
|
assetValue,
|
|
539
539
|
recipient,
|
|
540
540
|
memo,
|
|
541
|
+
data,
|
|
541
542
|
sender,
|
|
542
543
|
funcName,
|
|
543
544
|
funcParams,
|
|
@@ -547,6 +548,7 @@ function getEstimateGasLimit({ provider, signer }: ToolboxWrapParams) {
|
|
|
547
548
|
funcName?: string;
|
|
548
549
|
funcParams?: unknown[];
|
|
549
550
|
txOverrides?: EVMTxParams;
|
|
551
|
+
data?: string;
|
|
550
552
|
}) {
|
|
551
553
|
// const value = assetValue.getBaseValue("bigint");
|
|
552
554
|
const value = assetValue.bigIntValue;
|
|
@@ -573,7 +575,7 @@ function getEstimateGasLimit({ provider, signer }: ToolboxWrapParams) {
|
|
|
573
575
|
from: sender,
|
|
574
576
|
to: recipient,
|
|
575
577
|
value,
|
|
576
|
-
data: memo ? hexlify(toUtf8Bytes(memo)) : undefined,
|
|
578
|
+
data: data ? data : memo ? hexlify(toUtf8Bytes(memo)) : undefined,
|
|
577
579
|
});
|
|
578
580
|
};
|
|
579
581
|
}
|
package/src/ripple/index.ts
CHANGED
|
@@ -3,7 +3,6 @@ import {
|
|
|
3
3
|
BaseDecimal,
|
|
4
4
|
Chain,
|
|
5
5
|
type ChainSigner,
|
|
6
|
-
type GenericCreateTransactionParams,
|
|
7
6
|
type GenericTransferParams,
|
|
8
7
|
SKConfig,
|
|
9
8
|
SwapKitError,
|
|
@@ -111,10 +110,7 @@ export const getRippleToolbox = async (params: RippleToolboxParams = {}) => {
|
|
|
111
110
|
recipient,
|
|
112
111
|
memo,
|
|
113
112
|
sender,
|
|
114
|
-
}:
|
|
115
|
-
if (!signer) {
|
|
116
|
-
throw new SwapKitError({ errorKey: "toolbox_ripple_signer_not_found" });
|
|
117
|
-
}
|
|
113
|
+
}: { assetValue: AssetValue; recipient: string; sender?: string; memo?: string }) => {
|
|
118
114
|
if (!rippleValidateAddress(recipient)) {
|
|
119
115
|
throw new SwapKitError({ errorKey: "core_transaction_invalid_recipient_address" });
|
|
120
116
|
}
|
package/src/solana/toolbox.ts
CHANGED
|
@@ -27,7 +27,7 @@ import { getBalance } from "../utils";
|
|
|
27
27
|
type SolanaSigner = SolanaProvider | Signer;
|
|
28
28
|
|
|
29
29
|
export async function getSolanaAddressValidator() {
|
|
30
|
-
const { PublicKey } = await import("@solana/web3.js");
|
|
30
|
+
const { PublicKey } = (await import("@solana/web3.js")).default;
|
|
31
31
|
|
|
32
32
|
return (address: string) => {
|
|
33
33
|
try {
|
|
@@ -116,7 +116,7 @@ function estimateTransactionFee(getConnection: () => Promise<Connection>) {
|
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
async function getConnection() {
|
|
119
|
-
const { Connection } = await import("@solana/web3.js");
|
|
119
|
+
const { Connection } = (await import("@solana/web3.js")).default;
|
|
120
120
|
return new Connection(SKConfig.get("rpcUrls").SOL, "confirmed");
|
|
121
121
|
}
|
|
122
122
|
|
|
@@ -131,7 +131,7 @@ function createAssetTransaction(getConnection: () => Promise<Connection>) {
|
|
|
131
131
|
const fromPubkey = await getPubkeyFromAddress(sender);
|
|
132
132
|
|
|
133
133
|
if (assetValue.isGasAsset) {
|
|
134
|
-
const { Transaction, SystemProgram, PublicKey } = await import("@solana/web3.js");
|
|
134
|
+
const { Transaction, SystemProgram, PublicKey } = (await import("@solana/web3.js")).default;
|
|
135
135
|
|
|
136
136
|
return new Transaction().add(
|
|
137
137
|
SystemProgram.transfer({
|
|
@@ -180,7 +180,7 @@ async function createSolanaTokenTransaction({
|
|
|
180
180
|
createAssociatedTokenAccountInstruction,
|
|
181
181
|
createTransferCheckedInstruction,
|
|
182
182
|
} = await import("@solana/spl-token");
|
|
183
|
-
const { Transaction, PublicKey } = await import("@solana/web3.js");
|
|
183
|
+
const { Transaction, PublicKey } = (await import("@solana/web3.js")).default;
|
|
184
184
|
|
|
185
185
|
const transaction = new Transaction();
|
|
186
186
|
const tokenPublicKey = new PublicKey(tokenAddress);
|
|
@@ -268,7 +268,7 @@ function createTransaction(getConnection: () => Promise<Connection>) {
|
|
|
268
268
|
async function createTransactionFromInstructions({
|
|
269
269
|
instructions,
|
|
270
270
|
}: { instructions: TransactionInstruction[]; isProgramDerivedAddress?: boolean }) {
|
|
271
|
-
const { Transaction } = await import("@solana/web3.js");
|
|
271
|
+
const { Transaction } = (await import("@solana/web3.js")).default;
|
|
272
272
|
const transaction = new Transaction().add(...instructions);
|
|
273
273
|
|
|
274
274
|
if (!transaction) {
|
|
@@ -316,7 +316,7 @@ function broadcastTransaction(getConnection: () => Promise<Connection>) {
|
|
|
316
316
|
|
|
317
317
|
function signTransaction(getConnection: () => Promise<Connection>, signer?: SolanaSigner) {
|
|
318
318
|
return async (transaction: Transaction | VersionedTransaction) => {
|
|
319
|
-
const { VersionedTransaction } = await import("@solana/web3.js");
|
|
319
|
+
const { VersionedTransaction } = (await import("@solana/web3.js")).default;
|
|
320
320
|
if (!signer) {
|
|
321
321
|
throw new SwapKitError("toolbox_solana_no_signer");
|
|
322
322
|
}
|
|
@@ -345,7 +345,7 @@ export async function createKeysForPath({
|
|
|
345
345
|
}: { phrase: string; derivationPath?: string }) {
|
|
346
346
|
const { HDKey } = await import("micro-key-producer/slip10.js");
|
|
347
347
|
const { mnemonicToSeedSync } = await import("@scure/bip39");
|
|
348
|
-
const { Keypair } = await import("@solana/web3.js");
|
|
348
|
+
const { Keypair } = (await import("@solana/web3.js")).default;
|
|
349
349
|
const seed = mnemonicToSeedSync(phrase);
|
|
350
350
|
const hdKey = HDKey.fromMasterSeed(seed);
|
|
351
351
|
|
|
@@ -357,6 +357,6 @@ function getAddressFromPubKey(publicKey: PublicKey) {
|
|
|
357
357
|
}
|
|
358
358
|
|
|
359
359
|
async function getPubkeyFromAddress(address: string) {
|
|
360
|
-
const { PublicKey } = await import("@solana/web3.js");
|
|
360
|
+
const { PublicKey } = (await import("@solana/web3.js")).default;
|
|
361
361
|
return new PublicKey(address);
|
|
362
362
|
}
|
package/src/utxo/helpers/api.ts
CHANGED
|
@@ -262,7 +262,7 @@ export function getUtxoApi(chain: UTXOChain) {
|
|
|
262
262
|
export async function getUtxoNetwork() {
|
|
263
263
|
// @ts-ignore
|
|
264
264
|
const coininfo = await import("coininfo");
|
|
265
|
-
const { networks } = await import("bitcoinjs-lib");
|
|
265
|
+
const { networks } = (await import("bitcoinjs-lib")).default;
|
|
266
266
|
|
|
267
267
|
return function getNetwork(chain: Chain) {
|
|
268
268
|
switch (chain) {
|
|
@@ -17,7 +17,7 @@ const TX_INPUT_BASE = 32 + 4 + 1 + 4; // 41
|
|
|
17
17
|
const TX_INPUT_PUBKEYHASH = 107;
|
|
18
18
|
|
|
19
19
|
export async function compileMemo(memo: string) {
|
|
20
|
-
const { script, opcodes } = await import("bitcoinjs-lib");
|
|
20
|
+
const { script, opcodes } = (await import("bitcoinjs-lib")).default;
|
|
21
21
|
const data = Buffer.from(memo, "utf8"); // converts MEMO to buffer
|
|
22
22
|
return script.compile([opcodes.OP_RETURN as number, data]); // Compile OP_RETURN script
|
|
23
23
|
}
|