@swapkit/toolboxes 4.0.0-beta.67 → 4.0.1
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/src/cosmos/index.cjs +2 -2
- package/dist/src/cosmos/index.cjs.map +8 -8
- package/dist/src/cosmos/index.js +2 -2
- package/dist/src/cosmos/index.js.map +8 -8
- package/dist/src/evm/index.cjs +2 -2
- package/dist/src/evm/index.cjs.map +13 -13
- package/dist/src/evm/index.js +2 -2
- package/dist/src/evm/index.js.map +13 -13
- package/dist/src/index.cjs +3 -3
- package/dist/src/index.cjs.map +46 -45
- package/dist/src/index.js +3 -3
- package/dist/src/index.js.map +46 -45
- package/dist/src/near/index.cjs +2 -2
- package/dist/src/near/index.cjs.map +8 -8
- package/dist/src/near/index.js +2 -2
- package/dist/src/near/index.js.map +8 -8
- package/dist/src/radix/index.cjs +2 -2
- package/dist/src/radix/index.cjs.map +3 -3
- package/dist/src/radix/index.js +2 -2
- package/dist/src/radix/index.js.map +3 -3
- package/dist/src/ripple/index.cjs +2 -2
- package/dist/src/ripple/index.cjs.map +3 -3
- package/dist/src/ripple/index.js +2 -2
- package/dist/src/ripple/index.js.map +3 -3
- package/dist/src/solana/index.cjs +2 -2
- package/dist/src/solana/index.cjs.map +4 -4
- package/dist/src/solana/index.js +2 -2
- package/dist/src/solana/index.js.map +4 -4
- package/dist/src/substrate/index.cjs +2 -2
- package/dist/src/substrate/index.cjs.map +5 -5
- package/dist/src/substrate/index.js +2 -2
- package/dist/src/substrate/index.js.map +5 -5
- package/dist/src/tron/index.cjs +2 -2
- package/dist/src/tron/index.cjs.map +5 -5
- package/dist/src/tron/index.js +2 -2
- package/dist/src/tron/index.js.map +5 -5
- package/dist/src/utxo/index.cjs +3 -3
- package/dist/src/utxo/index.cjs.map +14 -13
- package/dist/src/utxo/index.js +3 -3
- package/dist/src/utxo/index.js.map +14 -13
- package/dist/types/cosmos/thorchainUtils/addressFormat.d.ts.map +1 -1
- package/dist/types/cosmos/thorchainUtils/messages.d.ts +58 -58
- package/dist/types/cosmos/thorchainUtils/messages.d.ts.map +1 -1
- package/dist/types/cosmos/thorchainUtils/registry.d.ts.map +1 -1
- package/dist/types/cosmos/thorchainUtils/types/client-types.d.ts +2 -5
- package/dist/types/cosmos/thorchainUtils/types/client-types.d.ts.map +1 -1
- package/dist/types/cosmos/toolbox/cosmos.d.ts +19 -41
- package/dist/types/cosmos/toolbox/cosmos.d.ts.map +1 -1
- package/dist/types/cosmos/toolbox/thorchain.d.ts +45 -46
- package/dist/types/cosmos/toolbox/thorchain.d.ts.map +1 -1
- package/dist/types/cosmos/types.d.ts +5 -1
- package/dist/types/cosmos/types.d.ts.map +1 -1
- package/dist/types/cosmos/util.d.ts +12 -13
- package/dist/types/cosmos/util.d.ts.map +1 -1
- package/dist/types/evm/api.d.ts.map +1 -1
- package/dist/types/evm/contracts/op/gasOracle.d.ts.map +1 -1
- package/dist/types/evm/helpers.d.ts +1 -15
- package/dist/types/evm/helpers.d.ts.map +1 -1
- package/dist/types/evm/index.d.ts +1 -1
- package/dist/types/evm/index.d.ts.map +1 -1
- package/dist/types/evm/toolbox/baseEVMToolbox.d.ts +14 -14
- package/dist/types/evm/toolbox/baseEVMToolbox.d.ts.map +1 -1
- package/dist/types/evm/toolbox/evm.d.ts +108 -108
- package/dist/types/evm/toolbox/evm.d.ts.map +1 -1
- package/dist/types/evm/toolbox/index.d.ts +97 -29
- package/dist/types/evm/toolbox/index.d.ts.map +1 -1
- package/dist/types/evm/toolbox/op.d.ts +36 -24
- package/dist/types/evm/toolbox/op.d.ts.map +1 -1
- package/dist/types/evm/types.d.ts +1 -1
- package/dist/types/evm/types.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/near/helpers/core.d.ts +1 -1
- package/dist/types/near/helpers/core.d.ts.map +1 -1
- package/dist/types/near/helpers/gasEstimation.d.ts +5 -5
- package/dist/types/near/helpers/gasEstimation.d.ts.map +1 -1
- package/dist/types/near/helpers/nep141.d.ts.map +1 -1
- package/dist/types/near/index.d.ts +4 -4
- package/dist/types/near/index.d.ts.map +1 -1
- package/dist/types/near/toolbox.d.ts.map +1 -1
- package/dist/types/near/types/contract.d.ts.map +1 -1
- package/dist/types/near/types/nep141.d.ts.map +1 -1
- package/dist/types/near/types/toolbox.d.ts.map +1 -1
- package/dist/types/near/types.d.ts +2 -2
- package/dist/types/near/types.d.ts.map +1 -1
- package/dist/types/radix/index.d.ts +2 -2
- package/dist/types/radix/index.d.ts.map +1 -1
- package/dist/types/ripple/index.d.ts +14 -11
- package/dist/types/ripple/index.d.ts.map +1 -1
- package/dist/types/solana/index.d.ts.map +1 -1
- package/dist/types/solana/toolbox.d.ts +10 -10
- package/dist/types/solana/toolbox.d.ts.map +1 -1
- package/dist/types/substrate/balance.d.ts.map +1 -1
- package/dist/types/substrate/substrate.d.ts +45 -45
- package/dist/types/substrate/substrate.d.ts.map +1 -1
- package/dist/types/substrate/types.d.ts +12 -12
- package/dist/types/substrate/types.d.ts.map +1 -1
- package/dist/types/tron/helpers/trongrid.d.ts.map +1 -1
- package/dist/types/tron/index.d.ts +2 -2
- package/dist/types/tron/index.d.ts.map +1 -1
- package/dist/types/tron/toolbox.d.ts +1 -1
- package/dist/types/tron/toolbox.d.ts.map +1 -1
- package/dist/types/tron/types.d.ts.map +1 -1
- package/dist/types/utxo/helpers/api.d.ts +15 -15
- package/dist/types/utxo/helpers/api.d.ts.map +1 -1
- package/dist/types/utxo/helpers/bchaddrjs.d.ts.map +1 -1
- package/dist/types/utxo/helpers/coinselect.d.ts +4 -4
- package/dist/types/utxo/helpers/coinselect.d.ts.map +1 -1
- package/dist/types/utxo/helpers/txSize.d.ts.map +1 -1
- package/dist/types/utxo/index.d.ts +1 -1
- package/dist/types/utxo/index.d.ts.map +1 -1
- package/dist/types/utxo/toolbox/bitcoinCash.d.ts +26 -38
- package/dist/types/utxo/toolbox/bitcoinCash.d.ts.map +1 -1
- package/dist/types/utxo/toolbox/index.d.ts +3 -3
- package/dist/types/utxo/toolbox/index.d.ts.map +1 -1
- package/dist/types/utxo/toolbox/utxo.d.ts +27 -38
- package/dist/types/utxo/toolbox/utxo.d.ts.map +1 -1
- package/dist/types/utxo/toolbox/validators.d.ts +4 -0
- package/dist/types/utxo/toolbox/validators.d.ts.map +1 -0
- package/dist/types/utxo/toolbox/zcash.d.ts +26 -37
- package/dist/types/utxo/toolbox/zcash.d.ts.map +1 -1
- package/dist/types/utxo/types.d.ts.map +1 -1
- package/package.json +15 -22
package/dist/src/utxo/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var qZ=Object.create;var{getPrototypeOf:LZ,defineProperty:WX,getOwnPropertyNames:WZ}=Object;var BZ=Object.prototype.hasOwnProperty;var PG=(X,Z,G)=>{G=X!=null?qZ(LZ(X)):{};let J=Z||!X||!X.__esModule?WX(G,"default",{value:X,enumerable:!0}):G;for(let j of WZ(X))if(!BZ.call(J,j))WX(J,j,{get:()=>X[j],enumerable:!0});return J};var DZ=(X,Z)=>{for(var G in Z)WX(X,G,{get:Z[G],enumerable:!0,configurable:!0,set:(J)=>Z[G]=()=>J})};var I=(X,Z)=>()=>(X&&(Z=X(X=0)),Z);var KG=((X)=>typeof require!=="undefined"?require:typeof Proxy!=="undefined"?new Proxy(X,{get:(Z,G)=>(typeof require!=="undefined"?require:Z)[G]}):X)(function(X){if(typeof require!=="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+X+'" is not supported')});import{AssetValue as UZ,BaseDecimal as zZ}from"@swapkit/helpers";import{SwapKitApi as YZ}from"@swapkit/helpers/api";function AX(){function X(){let Z=Date.now(),G=BX||Z;return BX=G,Z>BX?Z:G+1}return MZ+X().toString(36)}function kX(X){return async function Z(G,J=!0){return(await YZ.getChainBalance({chain:X,address:G,scamFilter:J})).map(({identifier:$,value:Q,decimal:q})=>{return new UZ({decimal:q||zZ[X],value:Q,identifier:$})})}}var MZ,BX=0;var DX=I(()=>{MZ=typeof process!=="undefined"&&process.pid?process.pid.toString(36):""});import{networks as TZ}from"@bitgo/utxo-lib";import{Chain as C,RequestClient as XX,SKConfig as UX,SwapKitError as P,warnOnce as wX}from"@swapkit/helpers";import{networks as CZ}from"bitcoinjs-lib";import c from"coininfo";async function HZ({chain:X,txHash:Z}){let G=`${ZX(X)}/push/transaction`,J=JSON.stringify({data:Z});try{let j=await XX.post(G,{headers:{"Content-Type":"application/json"},body:J});if(j.context.code!==200)throw new P("toolbox_utxo_broadcast_failed",{error:j.context.error||"Transaction broadcast failed"});return j.data?.transaction_hash||Z}catch(j){let $=UX.get("rpcUrls")[X];if($){let Q=JSON.stringify({jsonrpc:"2.0",method:"sendrawtransaction",params:[Z],id:AX()}),q=await XX.post($,{headers:{"Content-Type":"application/json"},body:Q});if(q.error)throw new P("toolbox_utxo_broadcast_failed",{error:q.error?.message});if(q.result.includes('"code":-26'))throw new P("toolbox_utxo_invalid_transaction",{error:"Transaction amount was too low"});return q.result}throw j}}function ZX(X){return`https://api.blockchair.com/${vZ(X)}`}function PX(X){switch(X){case C.Bitcoin:return 5;case C.Dogecoin:return 1e4;case C.Litecoin:return 1;case C.Zcash:return 1;default:return 2}}function vZ(X){switch(X){case C.BitcoinCash:return"bitcoin-cash";case C.Litecoin:return"litecoin";case C.Dash:return"dash";case C.Dogecoin:return"dogecoin";case C.Zcash:return"zcash";case C.Polkadot:return"polkadot";default:return"bitcoin"}}async function IZ(X){try{let{feePerKb:Z}=await XX.get(`https://app.bitgo.com/api/v2/${X.toLowerCase()}/tx/fee`),G=Z/1000;return Math.max(G,PX(X))}catch(Z){return PX(X)}}async function zX(X,Z){let G=await XX.get(`${X}${Z?`${X.includes("?")?"&":"?"}key=${Z}`:""}`);if(!G||G.context.code!==200)throw new P("toolbox_utxo_api_error",{error:`Failed to query ${X}`});return G.data}async function RX({address:X,chain:Z,apiKey:G}){if(!X)throw new P("toolbox_utxo_invalid_params",{error:"Address is required"});try{return(await zX(`${ZX(Z)}/dashboards/address/${X}?transaction_details=true`,G))[X]}catch(J){return{utxo:[],address:{balance:0,transaction_count:0}}}}async function _Z({address:X,chain:Z,apiKey:G}){return(await RX({address:X,chain:Z,apiKey:G}))?.address.balance||0}async function bX({chain:X,apiKey:Z,txHash:G}){if(!G)throw new P("toolbox_utxo_invalid_params",{error:"TxHash is required"});try{return(await zX(`${ZX(X)}/raw/transaction/${G}`,Z))?.[G]?.raw_transaction||""}catch(J){return console.error("Failed to fetch raw transaction:",J),""}}async function FZ({chain:X,address:Z,apiKey:G,offset:J=0,limit:j=30}){return(await zX(`${ZX(X)}/outputs?q=recipient(${Z}),is_spent(false),value(..2000000000000000)&s=value(desc)&fields=is_spent,transaction_hash,index,value,script_hex,block_id,spending_signature_hex&limit=${j}&offset=${J}`,G)).map(({is_spent:L,script_hex:B,block_id:W,transaction_hash:D,index:z,value:U,spending_signature_hex:Y})=>({hash:D,index:z,value:U,txHex:Y,script_hex:B,is_confirmed:W!==-1,is_spent:L}))}function yZ(X){return X.reduce((Z,G)=>Z+G.value,0)}function KX(X,Z){let G=[...X].sort((J,j)=>j.value-J.value);if(Z){let J=[],j=0;for(let $ of G)if(J.push($),j+=$.value,j>=Z)break;return J}return G}async function fX({chain:X,address:Z,apiKey:G,targetValue:J,accumulativeValue:j=0,offset:$=0,limit:Q=30}){if(!Z)throw new P("toolbox_utxo_invalid_params",{error:"Address is required"});try{let q=await FZ({targetValue:J,chain:X,address:Z,apiKey:G,offset:$,limit:Q}),B=q.length<Q,W=q.filter(({is_spent:T})=>!T),D=yZ(W),z=j+D,U=J&&z>=J;if(B||U)return KX(W,J);let Y=await fX({chain:X,address:Z,apiKey:G,offset:$+Q,limit:Q,accumulativeValue:z,targetValue:J}),H=[...W,...Y];return KX(H,J)}catch(q){return console.error("Failed to fetch unspent UTXOs:",q),[]}}async function NZ({address:X,chain:Z,apiKey:G,fetchTxHex:J=!0,targetValue:j}){let $=await fX({chain:Z,address:X,apiKey:G,targetValue:j}),Q=[];for(let{hash:q,index:L,script_hex:B,value:W}of $){let D;if(J)D=await bX({txHash:q,chain:Z,apiKey:G});Q.push({address:X,hash:q,index:L,txHex:D,value:W,witnessUtxo:{value:W,script:Buffer.from(B,"hex")}})}return Q}function OZ(X){let Z=UX.get("apiKeys").blockchair||"";return wX(!Z,"No Blockchair API key found. Functionality will be limited."),{broadcastTx:(G)=>HZ({txHash:G,chain:X}),getRawTx:(G)=>bX({txHash:G,chain:X,apiKey:Z}),getSuggestedTxFee:()=>IZ(X),getBalance:(G)=>_Z({address:G,chain:X,apiKey:Z}),getAddressData:(G)=>RX({address:G,chain:X,apiKey:Z}),getUtxos:(G)=>NZ({...G,chain:X,apiKey:Z})}}function AZ(X){return X}function v(X){let Z=UX.get("apis")[X];if(Z)return wX(!0,"Using custom UTXO API. Be sure to implement all methods to avoid issues."),Z;return OZ(X)}function y(){return function X(Z){switch(Z){case C.Bitcoin:return CZ.bitcoin;case C.BitcoinCash:return c.bitcoincash.main.toBitcoinJS();case C.Dash:return c.dash.main.toBitcoinJS();case C.Litecoin:return c.litecoin.main.toBitcoinJS();case C.Dogecoin:{let G={private:70615956,public:70617039},J=c.dogecoin.test;return J.versions.bip32=G,c.dogecoin.main.toBitcoinJS()}case C.Zcash:return TZ.zcash;default:throw new P("toolbox_utxo_not_supported",{chain:Z})}}}var EX=I(()=>{DX()});import{SwapKitError as SX}from"@swapkit/helpers";import gX from"bs58check";import xX from"cashaddrjs";function MX(X){try{return GX(X),!0}catch(Z){return!1}}function TX(X){return GX(X)?.network}function S(X){let Z=GX(X);if(Z?.format==="legacy")return X;return KZ(Z)}function p(X){let Z=GX(X);return wZ(Z)}function GX(X){try{let Z=kZ(X);if(Z)return Z}catch(Z){}try{let Z=PZ(X);if(Z)return Z}catch(Z){}throw new SX("toolbox_utxo_invalid_address",{address:X})}function kZ(X){try{let Z=gX.decode(X);if(Z.length!==21)throw new SX("toolbox_utxo_invalid_address",{address:X});let G=Z[0],J=Array.prototype.slice.call(Z,1);switch(G){case M.legacy.mainnet.p2pkh:return{hash:J,format:"legacy",network:"mainnet",type:"p2pkh"};case M.legacy.mainnet.p2sh:return{hash:J,format:"legacy",network:"mainnet",type:"p2sh"};case M.legacy.testnet.p2pkh:return{hash:J,format:"legacy",network:"testnet",type:"p2pkh"};case M.legacy.testnet.p2sh:return{hash:J,format:"legacy",network:"testnet",type:"p2sh"};case M.bitpay.mainnet.p2pkh:return{hash:J,format:"bitpay",network:"mainnet",type:"p2pkh"};case M.bitpay.mainnet.p2sh:return{hash:J,format:"bitpay",network:"mainnet",type:"p2sh"};default:return}}catch(Z){return}}function PZ(X){if(X.indexOf(":")!==-1)try{return VX(X)}catch(Z){}else{let Z=["bitcoincash","bchtest","bchreg"];for(let G of Z)try{return VX(`${G}:${X}`)}catch(J){}}return}function VX(X){try{let{hash:Z,prefix:G,type:J}=xX.decode(X);return{format:"cashaddr",hash:Array.prototype.slice.call(Z,0),network:G==="bitcoincash"?"mainnet":"testnet",type:J==="P2PKH"?"p2pkh":"p2sh"}}catch(Z){return}}function KZ(X){let Z=M.legacy[X.network][X.type],G=Buffer.alloc(1+X.hash.length);return G[0]=Z,G.set(X.hash,1),gX.encode(G)}function wZ(X){let Z=X.network==="mainnet"?"bitcoincash":"bchtest",G=X.type==="p2pkh"?"P2PKH":"P2SH",J=new Uint8Array(X.hash);return xX.encode(Z,G,J)}var YX,M;var mX=I(()=>{((G)=>{G.Mainnet="mainnet";G.Testnet="testnet"})(YX||={});M={["legacy"]:{["mainnet"]:{["p2pkh"]:0,["p2sh"]:5},["testnet"]:{["p2pkh"]:111,["p2sh"]:196}},["bitpay"]:{["mainnet"]:{["p2pkh"]:28,["p2sh"]:40},["testnet"]:{["p2pkh"]:111,["p2sh"]:196}}}});import{Chain as b,SwapKitError as RZ}from"@swapkit/helpers";var JX=(X)=>{switch(X){case b.Bitcoin:case b.BitcoinCash:return 550;case b.Dash:case b.Litecoin:return 5500;case b.Dogecoin:return 1e5;case b.Zcash:return 546;default:throw new RZ("toolbox_utxo_not_supported",{chain:X})}},N=({inputs:X,outputs:Z,feeRate:G=1,chain:J=b.Bitcoin,changeAddress:j=""})=>{let $=Math.ceil(G),Q=X[0]&&"address"in X[0]&&X[0].address?n(X[0].address):"P2PKH",q=X.filter((U)=>K(U)*$<=U.value),L=QX+Z.reduce((U,Y)=>U+u(Y,Q),0),B=Z.reduce((U,Y)=>U+Y.value,0),W=L*$,D=0,z=[];for(let U of q){let Y=K(U),H=$*Y;W+=H,D+=U.value,z.push(U);let T=W+B;if(D<T)continue;let w=D-T,R=$*u({address:"",value:0},Q);if(w>R){let NX=R+W,OX=D-(B+NX);if(OX>Math.max(K({})*$,JX(J)))return{inputs:z,outputs:Z.concat({value:OX,address:j}),fee:NX}}return{inputs:z,outputs:Z,fee:W}}return{fee:$*g({inputs:X,outputs:Z,feeRate:$})}};var lX=I(()=>{x()});import{SwapKitError as bZ}from"@swapkit/helpers";import{opcodes as fZ,script as EZ}from"bitcoinjs-lib";function O(X){let Z=Buffer.from(X,"utf8");return EZ.compile([fZ.OP_RETURN,Z])}var VZ=1000,QX=10,hX=10,SZ=41,gZ=107,$X,jX,o,n=(X)=>{if(X.startsWith("bc1")||X.startsWith("tb1")||X.startsWith("ltc1")||X.startsWith("tltc1"))return"P2WPKH";if(X.startsWith("1")||X.startsWith("m")||X.startsWith("n")||X.startsWith("bitcoincash:q")||X.startsWith("bitcoincash:p")||X.startsWith("q")||X.startsWith("p")||X.startsWith("L")||X.startsWith("M")||X.startsWith("3")||X.startsWith("D")||X.startsWith("A")||X.startsWith("9")||X.startsWith("X")||X.startsWith("7")||X.startsWith("y")||X.startsWith("t1")||X.startsWith("t3")||X.startsWith("tm"))return"P2PKH";throw new bZ("toolbox_utxo_invalid_address",{address:X})},g=({inputs:X,outputs:Z,feeRate:G})=>{let J=X[0]&&"address"in X[0]&&X[0].address?n(X[0].address):"P2PKH",j=X.filter((Q)=>Q.value>=jX["type"in Q?Q.type:"P2PKH"]*Math.ceil(G)).reduce((Q,q)=>Q+K(q),0),$=Z?.reduce((Q,q)=>Q+u(q),0)||o[J];return QX+j+$},K=(X)=>{if("type"in X)return jX[X.type];if("address"in X&&X.address)return jX[n(X.address)];return SZ+gZ},u=(X,Z)=>{if(X?.script)return hX+X.script.length+(X.script.length>=74?2:1);if(Z)return o[Z];return o.P2PKH};var cX=I(()=>{((G)=>{G.P2PKH="P2PKH";G.P2WPKH="P2WPKH"})($X||={});jX={["P2PKH"]:148,["P2WPKH"]:68},o={["P2PKH"]:34,["P2WPKH"]:31}});var x=I(()=>{EX();mX();lX();cX()});import{crypto as xZ,ECPair as uX,bitgo as mZ,networks as lZ,address as nX}from"@bitgo/utxo-lib";import{HDKey as oX}from"@scure/bip32";import{mnemonicToSeedSync as rX}from"@scure/bip39";import{Chain as qX,FeeOption as hZ,NetworkDerivationPath as cZ,SKConfig as pZ,SwapKitError as LX,derivationPathToString as uZ,updateDerivationPath as nZ}from"@swapkit/helpers";import dX from"bs58check";import{P as CX,match as oZ}from"ts-pattern";function HX(){return lZ.zcash}function iX(){return{messagePrefix:`\x18ZCash Signed Message:
|
|
2
|
-
`,bech32:void 0,bip32:{public:76067358,private:76066276},pubKeyHash:28,scriptHash:28,wif:128}}function r(X){try{if(X.startsWith("z"))return console.warn("Shielded Zcash addresses (z-addresses) are not supported. Use transparent addresses (t1/t3) only."),!1;let Z=HX();try{return nX.toOutputScript(X,Z),!0}catch{let G=dX.decode(X);if(G.length<21)return!1;let J=G[0];return J===Z.pubKeyHash||J===Z.scriptHash}}catch{return!1}}function rZ({phrase:X,derivationPath:Z}){let G=rX(X),j=oX.fromMasterSeed(G).derive(Z);if(!j.privateKey)throw new LX("toolbox_utxo_invalid_params");let $=iX(),Q=uX.fromPrivateKey(Buffer.from(j.privateKey),{network:$}),q=xZ.hash160(Q.publicKey),{isStagenet:L}=pZ.get("envs"),B=L?Buffer.from([29,37]):Buffer.from([28,184]),W=Buffer.concat([B,q]),D=dX.encode(W);return{getAddress:()=>Promise.resolve(D),signTransaction:(z)=>{let U=z.signAllInputs(Q);return Promise.resolve(U)}}}function dZ({inputs:X,outputs:Z,psbt:G,sender:J,compiledMemo:j}){for(let $ of X){let Q=!!$.witnessUtxo&&{witnessUtxo:{...$.witnessUtxo,value:BigInt($.value)}},q=!$.witnessUtxo&&{nonWitnessUtxo:$.txHex?Buffer.from($.txHex,"hex"):void 0};G.addInput({hash:$.hash,index:$.index,...Q,...q})}for(let $ of Z){let Q="address"in $&&$.address?$.address:J,q=$.script;if(q&&!j)continue;let L=q?{script:j,value:0n}:{script:nX.toOutputScript(Q,HX()),value:BigInt($.value)};G.addOutput(L)}return{psbt:G,inputs:X}}async function pX(X){let{assetValue:Z,recipient:G,memo:J,feeRate:j,sender:$,fetchTxHex:Q}=X,q=J?O(J):null,L=await v(qX.Zcash).getUtxos({address:$,fetchTxHex:Q!==!1}),B=[{address:G,value:Number(Z.getBaseValue("string"))},...q?[{script:q,value:0}]:[]],{inputs:W,outputs:D}=N({inputs:L,outputs:B,feeRate:j,chain:qX.Zcash,changeAddress:$});if(!(W&&D))throw new LX("toolbox_utxo_insufficient_balance",{sender:$,assetValue:Z});let z=mZ.createPsbtForNetwork({network:HX()},{version:455});z.setVersion(4,!0);let U=Buffer.concat([Buffer.of(252),Buffer.of(5),Buffer.from("BITGO"),Buffer.of(0)]),Y=3370586197,H=Buffer.allocUnsafe(4);H.writeUInt32LE(Y>>>0,0),z.addUnknownKeyValToGlobal({key:U,value:H});let{psbt:T,inputs:w}=await dZ({inputs:W,outputs:D,psbt:z,sender:$,compiledMemo:q});return{inputs:w,outputs:D,psbt:T}}async function vX(X){let Z=await oZ(X).with({signer:CX.not(CX.nullish)},({signer:Q})=>Promise.resolve(Q)).with({phrase:CX.string},({phrase:Q,derivationPath:q,index:L=0})=>{let B=q||cZ[qX.Zcash]||[44,133,0,0,0],W=nZ(B,{index:L}),D=uZ(W);return rZ({phrase:Q,derivationPath:D})}).otherwise(()=>Promise.resolve(void 0)),G=await f({chain:qX.Zcash,signer:Z});async function J({recipient:Q,assetValue:q,feeOptionKey:L=hZ.Fast,...B}){let W=await Z?.getAddress();if(!(Z&&W))throw new LX("toolbox_utxo_no_signer");let D=B.feeRate||(await G.getFeeRates())[L],{psbt:z}=await pX({...B,assetValue:q,feeRate:D,recipient:Q,sender:W}),U=await Z.signTransaction(z);return U.finalizeAllInputs(),G.broadcastTx(U.extractTransaction().toHex())}function j({phrase:Q,derivationPath:q="m/44'/133'/0'/0/0"}){let L=rX(Q),W=oX.fromMasterSeed(L).derive(q);if(!W.privateKey)throw new LX("toolbox_utxo_invalid_params");let D=iX();return uX.fromPrivateKey(Buffer.from(W.privateKey),{network:D})}function $({phrase:Q,derivationPath:q="m/44'/133'/0'/0/0"}){return j({phrase:Q,derivationPath:q}).toWIF()}return{...G,transfer:J,createTransaction:pX,createKeysForPath:j,getPrivateKeyFromMnemonic:$,validateAddress:r}}var d=I(()=>{x();i()});import{AssetValue as IX,Chain as _,DerivationPath as iZ,FeeOption as A,NetworkDerivationPath as aZ,SwapKitError as k,SwapKitNumber as sZ,applyFeeMultiplier as aX,derivationPathToString as tZ,updateDerivationPath as eZ}from"@swapkit/helpers";import{Psbt as XG,address as ZG,initEccLib as eX,payments as sX}from"bitcoinjs-lib";import{ECPairFactory as GG}from"ecpair";import _X from"@bitcoinerlab/secp256k1";import{ECPair as JG,HDNode as QG}from"@psf/bitcoincashjs-lib";import{HDKey as $G}from"@scure/bip32";import{mnemonicToSeedSync as tX}from"@scure/bip39";function XZ({inputs:X,outputs:Z,chain:G,psbt:J,sender:j,compiledMemo:$}){for(let Q of X){let q=!!Q.witnessUtxo&&!a.includes(G)&&{witnessUtxo:Q.witnessUtxo},L=a.includes(G)&&{nonWitnessUtxo:Q.txHex?Buffer.from(Q.txHex,"hex"):void 0};J.addInput({hash:Q.hash,index:Q.index,...q,...L})}for(let Q of Z){let q="address"in Q&&Q.address?Q.address:j,L=Q.script;if(L&&!$)continue;let B=L?{script:$,value:0}:{address:q,value:Q.value};eX(_X),J.addOutput(B)}return{psbt:J,inputs:X}}async function ZZ({assetValue:X,recipient:Z,memo:G,feeRate:J,sender:j,fetchTxHex:$=!1}){let Q=X.chain,q=G?await O(G):null,L=await QZ({assetValue:X,recipient:Z,memo:G,sender:j,fetchTxHex:$}),{inputs:B,outputs:W}=N({...L,feeRate:J,chain:Q});if(!(B&&W))throw new k("toolbox_utxo_insufficient_balance",{sender:j,assetValue:X});let D=await y(),z=new XG({network:D(Q)});if(Q===_.Dogecoin)z.setMaximumFeeRate(650000000);let{psbt:U,inputs:Y}=await XZ({inputs:B,outputs:W,chain:Q,psbt:z,sender:j,compiledMemo:q});return{psbt:U,utxos:L.inputs,inputs:Y}}async function GZ(){let X=await y();return function Z({address:G,chain:J}){if(J===_.BitcoinCash)return E(G);if(J===_.Zcash)return r(G);try{return eX(_X),ZG.toOutputScript(G,X(J)),!0}catch(j){return!1}}}async function jG({chain:X,phrase:Z,derivationPath:G}){let J=(await s(X))({phrase:Z,derivationPath:G});async function j(Q){return await Q.signAllInputs(J),Q}async function $(){return(await FX(X))(J)}return{getAddress:$,signTransaction:j}}async function f({chain:X,...Z}){let G="phrase"in Z?Z.phrase:void 0,J="index"in Z?Z.index||0:0,j=tZ("derivationPath"in Z&&Z.derivationPath?Z.derivationPath:eZ(aZ[X],{index:J})),$=G?await jG({chain:X,phrase:G,derivationPath:j}):("signer"in Z)?Z.signer:void 0;function Q(){return Promise.resolve($?.getAddress())}let q=await FX(X),L=await GZ(),B=await s(X);return{accumulative:N,calculateTxSize:g,getAddressFromKeys:q,getAddress:Q,validateAddress:(W)=>L({address:W,chain:X}),broadcastTx:(W)=>v(X).broadcastTx(W),createTransaction:ZZ,createKeysForPath:B,getFeeRates:()=>t(X),getInputsOutputsFee:JZ,transfer:WG($),getPrivateKeyFromMnemonic:(W)=>{return B(W).toWIF()},getBalance:kX(X),estimateTransactionFee:LG(X),estimateMaxSendableAmount:qG(X)}}async function JZ({assetValue:X,feeOptionKey:Z=A.Fast,feeRate:G,memo:J,sender:j,recipient:$}){let Q=X.chain,q=await QZ({assetValue:X,sender:j,memo:J,recipient:$}),L=G?Math.floor(G):(await t(Q))[Z];return N({...q,feeRate:L,chain:Q})}function qG(X){return async function Z({from:G,memo:J,feeRate:j,feeOptionKey:$=A.Fast,recipients:Q=1}){let q=await v(X).getAddressData(G),L=j?Math.ceil(j):(await t(X))[$],B=q?.utxo.map((Y)=>({...Y,type:"P2PKH",hash:""})).filter((Y)=>Y.value>Math.max(JX(X),K(Y)*L));if(!B?.length)return IX.from({chain:X});let W=IX.from({chain:X,value:B.reduce((Y,H)=>Y+H.value,0)}),D=typeof Q==="number"?Array.from({length:Q},()=>({address:G,value:0})):Q;if(J){let Y=await O(J);D.push({address:G,script:Y,value:0})}let U=g({inputs:B,outputs:D,feeRate:L})*L;return W.sub(U)}}function LG(X){return async(Z)=>{let G=await JZ(Z);return IX.from({chain:X,value:sZ.fromBigInt(BigInt(G.fee),8).getValue("string")})}}async function s(X){let Z=await y();switch(X){case _.BitcoinCash:return function G({phrase:J,derivationPath:j=`${iZ.BCH}/0`,wif:$}){let Q=Z(X);if($)return JG.fromWIF($,Q);if(!J)throw new k("toolbox_utxo_invalid_params",{error:"No phrase provided"});return QG.fromSeedBuffer(Buffer.from(tX(J)),Q).derivePath(j).keyPair};case _.Bitcoin:case _.Dogecoin:case _.Litecoin:case _.Zcash:case _.Dash:return function G({phrase:J,wif:j,derivationPath:$}){if(!(j||J))throw new k("toolbox_utxo_invalid_params",{error:"Either phrase or wif must be provided"});let Q=GG(_X),q=Z(X);if(j)return Q.fromWIF(j,q);let L=tX(J),B=$G.fromMasterSeed(L,q).derive($);if(!B.privateKey)throw new k("toolbox_utxo_invalid_params",{error:"Could not get private key from phrase"});return Q.fromPrivateKey(Buffer.from(B.privateKey),{network:q})};default:throw new k("toolbox_utxo_not_supported",{chain:X})}}async function FX(X){let Z=await y();return function G(J){if(!J)throw new k("toolbox_utxo_invalid_params",{error:"Keys must be provided"});let j=a.includes(X)?sX.p2pkh:sX.p2wpkh,{address:$}=j({pubkey:J.publicKey,network:Z(X)});if(!$)throw new k("toolbox_utxo_invalid_address",{error:"Address not defined"});return $}}function WG(X){return async function Z({memo:G,recipient:J,feeOptionKey:j,feeRate:$,assetValue:Q}){let q=await X?.getAddress(),L=Q.chain;if(!(X&&q))throw new k("toolbox_utxo_no_signer");if(!J)throw new k("toolbox_utxo_invalid_params",{error:"Recipient address must be provided"});let B=$||(await t(L))[j||A.Fast],{psbt:W}=await ZZ({recipient:J,feeRate:B,sender:q,assetValue:Q,memo:G}),D=await X.signTransaction(W);return D.finalizeAllInputs(),v(L).broadcastTx(D.extractTransaction().toHex())}}async function t(X){let Z=await v(X).getSuggestedTxFee();return{[A.Average]:Z,[A.Fast]:aX(Z,A.Fast),[A.Fastest]:aX(Z,A.Fastest)}}async function QZ({assetValue:X,recipient:Z,memo:G,sender:J,fetchTxHex:j=!1}){let $=X.chain,Q=(await t($))[A.Fastest],q=j||a.includes($),L=X.getBaseValue("number"),B=Math.ceil(L+Q*5000);return{inputs:await v($).getUtxos({address:J,fetchTxHex:q,targetValue:B}),outputs:[{address:Z,value:L},...G?[{address:"",script:await O(G),value:0}]:[]]}}var a;var i=I(()=>{DX();x();e();d();a=[_.Dash,_.Dogecoin]});import{Transaction as BG,TransactionBuilder as DG,address as UG}from"@psf/bitcoincashjs-lib";import{Chain as zG,FeeOption as YG,NetworkDerivationPath as MG,SwapKitError as m,derivationPathToString as TG,updateDerivationPath as CG}from"@swapkit/helpers";import{Psbt as HG}from"bitcoinjs-lib";function l(X){return X.replace(/(bchtest:|bitcoincash:)/,"")}function E(X){let Z=l(X);return MX(Z)&&TX(Z)==="mainnet"}function V(X){return l(p(X))}async function vG(X){async function Z({builder:J,utxos:j}){return j.forEach(($,Q)=>{J.sign(Q,X,void 0,65,$.witnessUtxo?.value)}),J.build()}return{getAddress:()=>{let J=X.getAddress(0);return Promise.resolve(V(J))},signTransaction:Z}}async function yX(X){let Z="phrase"in X?X.phrase:void 0,G="index"in X?X.index||0:0,J=TG("derivationPath"in X&&X.derivationPath?X.derivationPath:CG(MG[F],{index:G})),j=Z?(await s(F))({phrase:Z,derivationPath:J}):void 0,$=j?await vG(j):("signer"in X)?X.signer:void 0;function Q(){return Promise.resolve($?.getAddress())}let{getBalance:q,getFeeRates:L,broadcastTx:B,...W}=await f({chain:F});function D(z,U=!0){return q(l(p(z)))}return{...W,getAddress:Q,broadcastTx:B,createTransaction:$Z,buildTx:_G,getAddressFromKeys:FG,getBalance:D,getFeeRates:L,stripPrefix:l,stripToCashAddress:V,validateAddress:E,transfer:IG({getFeeRates:L,broadcastTx:B,signer:$})}}async function $Z({assetValue:X,recipient:Z,memo:G,feeRate:J,sender:j}){if(!E(Z))throw new m("toolbox_utxo_invalid_address",{address:Z});let $=Math.ceil(X.getBaseValue("number")+J*7500),Q=await v(F).getUtxos({address:V(j),fetchTxHex:!0,targetValue:$}),q=G?await O(G):null,L=[];L.push({address:Z,value:X.getBaseValue("number")});let{inputs:B,outputs:W}=N({inputs:Q,outputs:L,feeRate:J,chain:F});if(!(B&&W))throw new m("toolbox_utxo_insufficient_balance",{sender:j,assetValue:X});let D=await y(),z=new DG(D(F));await Promise.all(B.map(async(U)=>{let Y=await v(F).getRawTx(U.hash);z.addInput(BG.fromBuffer(Buffer.from(Y,"hex")),U.index)}));for(let U of W){let Y="address"in U&&U.address?U.address:S(j),H=await y(),T=UG.toOutputScript(S(Y),H(F));z.addOutput(T,U.value)}if(q)z.addOutput(q,0);return{builder:z,utxos:B}}function IG({broadcastTx:X,getFeeRates:Z,signer:G}){return async function J({recipient:j,assetValue:$,feeOptionKey:Q=YG.Fast,...q}){let L=await G?.getAddress();if(!(G&&L))throw new m("toolbox_utxo_no_signer");if(!j)throw new m("toolbox_utxo_invalid_params",{error:"Recipient address must be provided"});let B=q.feeRate||(await Z())[Q],{builder:W,utxos:D}=await $Z({...q,assetValue:$,feeRate:B,recipient:j,sender:L}),U=(await G.signTransaction({builder:W,utxos:D})).toHex();return X(U)}}async function _G({assetValue:X,recipient:Z,memo:G,feeRate:J,sender:j,setSigHashType:$}){let Q=p(Z);if(!E(Q))throw new m("toolbox_utxo_invalid_address",{address:Q});let q=Math.ceil(X.getBaseValue("number")+J*7500),L=await v(F).getUtxos({address:V(j),fetchTxHex:!1,targetValue:q}),B=Number(J.toFixed(0)),W=G?await O(G):null,D=[];if(D.push({address:S(Z),value:X.getBaseValue("number")}),W)D.push({script:W,value:0});let{inputs:z,outputs:U}=N({inputs:L,outputs:D,feeRate:B,chain:F});if(!(z&&U))throw new m("toolbox_utxo_insufficient_balance",{sender:j,assetValue:X});let Y=await y(),H=new HG({network:Y(F)});for(let{hash:T,index:w,witnessUtxo:R}of z)H.addInput({hash:T,index:w,witnessUtxo:R,sighashType:$?65:void 0});for(let T of U){let w="address"in T&&T.address?T.address:S(j),R=T.script?W?{script:W,value:0}:void 0:{address:w,value:T.value};if(R)H.addOutput(R)}return{psbt:H,utxos:L,inputs:z}}function FG(X){let Z=X.getAddress(0);return V(Z)}var F;var e=I(()=>{x();i();F=zG.BitcoinCash});import{Chain as h,SwapKitError as yG}from"@swapkit/helpers";async function NG(X,Z){switch(X){case h.BitcoinCash:return await yX(Z||{});case h.Zcash:return await vX(Z);case h.Bitcoin:case h.Dogecoin:case h.Litecoin:case h.Dash:return await f({chain:X,...Z});default:throw new yG("toolbox_utxo_not_supported",{chain:X})}}var jZ=I(()=>{e();i();d();e();d()});var AG={};DZ(AG,{validateZcashAddress:()=>r,toLegacyAddress:()=>S,toCashAddress:()=>p,stripToCashAddress:()=>V,stripPrefix:()=>l,nonSegwitChains:()=>a,isValidAddress:()=>MX,getUtxoToolbox:()=>NG,getUtxoNetwork:()=>y,getUtxoApi:()=>v,getUTXOAddressValidator:()=>GZ,getScriptTypeForAddress:()=>n,getOutputSize:()=>u,getInputSize:()=>K,getDustThreshold:()=>JX,getCreateKeysForPath:()=>s,detectAddressNetwork:()=>TX,createZcashToolbox:()=>vX,createUTXOToolbox:()=>f,createCustomUtxoApi:()=>AZ,createBCHToolbox:()=>yX,compileMemo:()=>O,calculateTxSize:()=>g,bchValidateAddress:()=>E,addressFromKeysGetter:()=>FX,addInputsAndOutputs:()=>XZ,accumulative:()=>N,UtxoNetwork:()=>YX,UTXOScriptType:()=>$X,TX_OVERHEAD:()=>QX,OutputSizes:()=>o,OP_RETURN_OVERHEAD:()=>hX,MIN_TX_FEE:()=>VZ,InputSizes:()=>jX});var kG=I(()=>{jZ();e();i();d();x()});kG();export{r as validateZcashAddress,S as toLegacyAddress,p as toCashAddress,V as stripToCashAddress,l as stripPrefix,a as nonSegwitChains,MX as isValidAddress,NG as getUtxoToolbox,y as getUtxoNetwork,v as getUtxoApi,GZ as getUTXOAddressValidator,n as getScriptTypeForAddress,u as getOutputSize,K as getInputSize,JX as getDustThreshold,s as getCreateKeysForPath,TX as detectAddressNetwork,vX as createZcashToolbox,f as createUTXOToolbox,AZ as createCustomUtxoApi,yX as createBCHToolbox,O as compileMemo,g as calculateTxSize,E as bchValidateAddress,FX as addressFromKeysGetter,XZ as addInputsAndOutputs,N as accumulative,YX as UtxoNetwork,$X as UTXOScriptType,QX as TX_OVERHEAD,o as OutputSizes,hX as OP_RETURN_OVERHEAD,VZ as MIN_TX_FEE,jX as InputSizes};
|
|
1
|
+
var jZ=Object.create;var{getPrototypeOf:qZ,defineProperty:LX,getOwnPropertyNames:WZ}=Object;var LZ=Object.prototype.hasOwnProperty;var R1=(X,Z,G)=>{G=X!=null?jZ(qZ(X)):{};let J=Z||!X||!X.__esModule?LX(G,"default",{value:X,enumerable:!0}):G;for(let j of WZ(X))if(!LZ.call(J,j))LX(J,j,{get:()=>X[j],enumerable:!0});return J};var BZ=(X,Z)=>{for(var G in Z)LX(X,G,{get:Z[G],enumerable:!0,configurable:!0,set:(J)=>Z[G]=()=>J})};var I=(X,Z)=>()=>(X&&(Z=X(X=0)),Z);var E1=((X)=>typeof require!=="undefined"?require:typeof Proxy!=="undefined"?new Proxy(X,{get:(Z,G)=>(typeof require!=="undefined"?require:Z)[G]}):X)(function(X){if(typeof require!=="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+X+'" is not supported')});import{AssetValue as DZ,BaseDecimal as zZ}from"@swapkit/helpers";import{SwapKitApi as UZ}from"@swapkit/helpers/api";function AX(){function X(){let Z=Date.now(),G=BX||Z;return BX=G,Z>BX?Z:G+1}return YZ+X().toString(36)}function OX(X){return async function Z(G,J=!0){return(await UZ.getChainBalance({address:G,chain:X,scamFilter:J})).map(({identifier:$,value:Q,decimal:q})=>{return new DZ({decimal:q||zZ[X],identifier:$,value:Q})})}}var YZ,BX=0;var DX=I(()=>{YZ=typeof process!=="undefined"&&process.pid?process.pid.toString(36):""});import{networks as MZ}from"@bitgo/utxo-lib";import{Chain as C,getRPCUrl as TZ,RequestClient as e,SKConfig as fX,SwapKitError as w,warnOnce as KX}from"@swapkit/helpers";import{networks as CZ}from"bitcoinjs-lib";import p from"coininfo";async function HZ({chain:X,txHash:Z}){let G=`${XX(X)}/push/transaction`,J=JSON.stringify({data:Z});try{let j=await e.post(G,{body:J,headers:{"Content-Type":"application/json"}});if(j.context.code!==200)throw new w("toolbox_utxo_broadcast_failed",{error:j.context.error||"Transaction broadcast failed"});return j.data?.transaction_hash||Z}catch(j){let $=await TZ(X);if($){let Q=JSON.stringify({id:AX(),jsonrpc:"2.0",method:"sendrawtransaction",params:[Z]}),q=await e.post($,{body:Q,headers:{"Content-Type":"application/json"}});if(q.error)throw new w("toolbox_utxo_broadcast_failed",{error:q.error?.message});if(q.result.includes('"code":-26'))throw new w("toolbox_utxo_invalid_transaction",{error:"Transaction amount was too low"});return q.result}throw j}}function XX(X){return`https://api.blockchair.com/${vZ(X)}`}function wX(X){switch(X){case C.Bitcoin:return 5;case C.Dogecoin:return 1e4;case C.Litecoin:return 1;case C.Zcash:return 1;default:return 2}}function vZ(X){switch(X){case C.BitcoinCash:return"bitcoin-cash";case C.Litecoin:return"litecoin";case C.Dash:return"dash";case C.Dogecoin:return"dogecoin";case C.Zcash:return"zcash";case C.Polkadot:return"polkadot";default:return"bitcoin"}}async function IZ(X){try{let{feePerKb:Z}=await e.get(`https://app.bitgo.com/api/v2/${X.toLowerCase()}/tx/fee`),G=Z/1000;return Math.max(G,wX(X))}catch(Z){return wX(X)}}async function zX(X,Z){let G=await e.get(`${X}${Z?`${X.includes("?")?"&":"?"}key=${Z}`:""}`);if(!G||G.context.code!==200)throw new w("toolbox_utxo_api_error",{error:`Failed to query ${X}`});return G.data}async function bX({address:X,chain:Z,apiKey:G}){if(!X)throw new w("toolbox_utxo_invalid_params",{error:"Address is required"});try{return(await zX(`${XX(Z)}/dashboards/address/${X}?transaction_details=true`,G))[X]}catch(J){return{address:{balance:0,transaction_count:0},utxo:[]}}}async function _Z({address:X,chain:Z,apiKey:G}){return(await bX({address:X,apiKey:G,chain:Z}))?.address.balance||0}async function RX({chain:X,apiKey:Z,txHash:G}){if(!G)throw new w("toolbox_utxo_invalid_params",{error:"TxHash is required"});try{return(await zX(`${XX(X)}/raw/transaction/${G}`,Z))?.[G]?.raw_transaction||""}catch(J){return console.error("Failed to fetch raw transaction:",J),""}}async function FZ({chain:X,address:Z,apiKey:G,offset:J=0,limit:j=30}){return(await zX(`${XX(X)}/outputs?q=recipient(${Z}),is_spent(false),value(..2000000000000000)&s=value(desc)&fields=is_spent,transaction_hash,index,value,script_hex,block_id,spending_signature_hex&limit=${j}&offset=${J}`,G)).map(({is_spent:W,script_hex:B,block_id:L,transaction_hash:D,index:U,value:z,spending_signature_hex:Y})=>({hash:D,index:U,is_confirmed:L!==-1,is_spent:W,script_hex:B,txHex:Y,value:z}))}function yZ(X){return X.reduce((Z,G)=>Z+G.value,0)}function PX(X,Z){let G=[...X].sort((J,j)=>j.value-J.value);if(Z){let J=[],j=0;for(let $ of G)if(J.push($),j+=$.value,j>=Z)break;return J}return G}async function EX({chain:X,address:Z,apiKey:G,targetValue:J,accumulativeValue:j=0,offset:$=0,limit:Q=30}){if(!Z)throw new w("toolbox_utxo_invalid_params",{error:"Address is required"});try{let q=await FZ({address:Z,apiKey:G,chain:X,limit:Q,offset:$,targetValue:J}),B=q.length<Q,L=q.filter(({is_spent:T})=>!T),D=yZ(L),U=j+D,z=J&&U>=J;if(B||z)return PX(L,J);let Y=await EX({accumulativeValue:U,address:Z,apiKey:G,chain:X,limit:Q,offset:$+Q,targetValue:J}),H=[...L,...Y];return PX(H,J)}catch(q){return console.error("Failed to fetch unspent UTXOs:",q),[]}}async function NZ({address:X,chain:Z,apiKey:G,fetchTxHex:J=!0,targetValue:j}){let $=await EX({address:X,apiKey:G,chain:Z,targetValue:j}),Q=[];for(let{hash:q,index:W,script_hex:B,value:L}of $){let D;if(J)D=await RX({apiKey:G,chain:Z,txHash:q});Q.push({address:X,hash:q,index:W,txHex:D,value:L,witnessUtxo:{script:Buffer.from(B,"hex"),value:L}})}return Q}function kZ(X){let Z=fX.get("apiKeys").blockchair||"";return KX({condition:!Z,id:"no_blockchair_api_key_warning",warning:"No Blockchair API key found. Functionality will be limited."}),{broadcastTx:(G)=>HZ({chain:X,txHash:G}),getAddressData:(G)=>bX({address:G,apiKey:Z,chain:X}),getBalance:(G)=>_Z({address:G,apiKey:Z,chain:X}),getRawTx:(G)=>RX({apiKey:Z,chain:X,txHash:G}),getSuggestedTxFee:()=>IZ(X),getUtxos:(G)=>NZ({...G,apiKey:Z,chain:X})}}function AZ(X){return X}function v(X){let Z=fX.get("apis")[X];if(Z)return KX({condition:!0,id:"custom_utxo_api_warning",warning:"Using custom UTXO API. Be sure to implement all methods to avoid issues."}),Z;return kZ(X)}function y(){return function X(Z){switch(Z){case C.Bitcoin:return CZ.bitcoin;case C.BitcoinCash:return p.bitcoincash.main.toBitcoinJS();case C.Dash:return p.dash.main.toBitcoinJS();case C.Litecoin:return p.litecoin.main.toBitcoinJS();case C.Dogecoin:{let G={private:70615956,public:70617039},J=p.dogecoin.test;return J.versions.bip32=G,p.dogecoin.main.toBitcoinJS()}case C.Zcash:return MZ.zcash;default:throw new w("toolbox_utxo_not_supported",{chain:Z})}}}var VX=I(()=>{DX()});import{SwapKitError as gX}from"@swapkit/helpers";import xX from"bs58check";import mX from"cashaddrjs";function YX(X){try{return ZX(X),!0}catch(Z){return!1}}function MX(X){return ZX(X)?.network}function g(X){let Z=ZX(X);if(Z?.format==="legacy")return X;return PZ(Z)}function n(X){let Z=ZX(X);return fZ(Z)}function ZX(X){try{let Z=OZ(X);if(Z)return Z}catch(Z){}try{let Z=wZ(X);if(Z)return Z}catch(Z){}throw new gX("toolbox_utxo_invalid_address",{address:X})}function OZ(X){try{let Z=xX.decode(X);if(Z.length!==21)throw new gX("toolbox_utxo_invalid_address",{address:X});let G=Z[0],J=Array.prototype.slice.call(Z,1);switch(G){case M.legacy.mainnet.p2pkh:return{format:"legacy",hash:J,network:"mainnet",type:"p2pkh"};case M.legacy.mainnet.p2sh:return{format:"legacy",hash:J,network:"mainnet",type:"p2sh"};case M.legacy.testnet.p2pkh:return{format:"legacy",hash:J,network:"testnet",type:"p2pkh"};case M.legacy.testnet.p2sh:return{format:"legacy",hash:J,network:"testnet",type:"p2sh"};case M.bitpay.mainnet.p2pkh:return{format:"bitpay",hash:J,network:"mainnet",type:"p2pkh"};case M.bitpay.mainnet.p2sh:return{format:"bitpay",hash:J,network:"mainnet",type:"p2sh"};default:return}}catch(Z){return}}function wZ(X){if(X.indexOf(":")!==-1)try{return SX(X)}catch(Z){}else{let Z=["bitcoincash","bchtest","bchreg"];for(let G of Z)try{return SX(`${G}:${X}`)}catch(J){}}return}function SX(X){try{let{hash:Z,prefix:G,type:J}=mX.decode(X);return{format:"cashaddr",hash:Array.prototype.slice.call(Z,0),network:G==="bitcoincash"?"mainnet":"testnet",type:J==="P2PKH"?"p2pkh":"p2sh"}}catch(Z){return}}function PZ(X){let Z=M.legacy[X.network][X.type],G=Buffer.alloc(1+X.hash.length);return G[0]=Z,G.set(X.hash,1),xX.encode(G)}function fZ(X){let Z=X.network==="mainnet"?"bitcoincash":"bchtest",G=X.type==="p2pkh"?"P2PKH":"P2SH",J=new Uint8Array(X.hash);return mX.encode(Z,G,J)}var UX,M;var lX=I(()=>{((G)=>{G.Mainnet="mainnet";G.Testnet="testnet"})(UX||={});M={["legacy"]:{["mainnet"]:{["p2pkh"]:0,["p2sh"]:5},["testnet"]:{["p2pkh"]:111,["p2sh"]:196}},["bitpay"]:{["mainnet"]:{["p2pkh"]:28,["p2sh"]:40},["testnet"]:{["p2pkh"]:111,["p2sh"]:196}}}});import{SwapKitError as KZ}from"@swapkit/helpers";import{opcodes as bZ,script as RZ}from"bitcoinjs-lib";function N(X){let Z=Buffer.from(X,"utf8");return RZ.compile([bZ.OP_RETURN,Z])}var EZ=1000,JX=10,hX=10,VZ=41,SZ=107,QX,GX,o,u=(X)=>{if(X.startsWith("bc1")||X.startsWith("tb1")||X.startsWith("ltc1")||X.startsWith("tltc1"))return"P2WPKH";if(X.startsWith("1")||X.startsWith("m")||X.startsWith("n")||X.startsWith("bitcoincash:q")||X.startsWith("bitcoincash:p")||X.startsWith("q")||X.startsWith("p")||X.startsWith("L")||X.startsWith("M")||X.startsWith("3")||X.startsWith("D")||X.startsWith("A")||X.startsWith("9")||X.startsWith("X")||X.startsWith("7")||X.startsWith("y")||X.startsWith("t1")||X.startsWith("t3")||X.startsWith("tm"))return"P2PKH";throw new KZ("toolbox_utxo_invalid_address",{address:X})},x=({inputs:X,outputs:Z,feeRate:G})=>{let J=X[0]&&"address"in X[0]&&X[0].address?u(X[0].address):"P2PKH",j=X.filter((Q)=>Q.value>=GX["type"in Q?Q.type:"P2PKH"]*Math.ceil(G)).reduce((Q,q)=>Q+P(q),0),$=Z?.reduce((Q,q)=>Q+r(q),0)||o[J];return JX+j+$},P=(X)=>{if("type"in X)return GX[X.type];if("address"in X&&X.address)return GX[u(X.address)];return VZ+SZ},r=(X,Z)=>{if(X?.script)return hX+X.script.length+(X.script.length>=74?2:1);if(Z)return o[Z];return o.P2PKH};var TX=I(()=>{((G)=>{G.P2PKH="P2PKH";G.P2WPKH="P2WPKH"})(QX||={});GX={["P2PKH"]:148,["P2WPKH"]:68},o={["P2PKH"]:34,["P2WPKH"]:31}});import{Chain as R,SwapKitError as gZ}from"@swapkit/helpers";function $X(X){switch(X){case R.Bitcoin:case R.BitcoinCash:return 550;case R.Dash:case R.Litecoin:return 5500;case R.Dogecoin:return 1e5;case R.Zcash:return 546;default:throw new gZ("toolbox_utxo_not_supported",{chain:X})}}function k({inputs:X,outputs:Z,feeRate:G=1,chain:J=R.Bitcoin,changeAddress:j=""}){let $=Math.ceil(G),Q=X[0]&&"address"in X[0]&&X[0].address?u(X[0].address):"P2PKH",q=X.filter((z)=>P(z)*$<=z.value),W=JX+Z.reduce((z,Y)=>z+r(Y,Q),0),B=Z.reduce((z,Y)=>z+Y.value,0),L=W*$,D=0,U=[];for(let z of q){let Y=P(z),H=$*Y;L+=H,D+=z.value,U.push(z);let T=L+B;if(D<T)continue;let K=D-T,b=$*r({address:"",value:0},Q);if(K>b){let NX=b+L,kX=D-(B+NX);if(kX>Math.max(P({})*$,$X(J)))return{fee:NX,inputs:U,outputs:Z.concat({address:j,value:kX})}}return{fee:L,inputs:U,outputs:Z}}return{fee:$*x({feeRate:$,inputs:X,outputs:Z})}}var cX=I(()=>{TX()});var m=I(()=>{VX();lX();cX();TX()});import{networks as xZ,address as mZ}from"@bitgo/utxo-lib";import lZ from"bs58check";function E(X){return X.replace(/(bchtest:|bitcoincash:)/,"")}function f(X){let Z=E(X);return YX(Z)&&MX(Z)==="mainnet"}function l(X){try{if(X.startsWith("z"))return console.warn("Shielded Zcash addresses (z-addresses) are not supported. Use transparent addresses (t1/t3) only."),!1;let Z=xZ.zcash;try{return mZ.toOutputScript(X,Z),!0}catch{let G=lZ.decode(X);if(G.length<21)return!1;let J=G[0];return J===Z.pubKeyHash||J===Z.scriptHash}}catch{return!1}}var d=I(()=>{m()});import HX from"@bitcoinerlab/secp256k1";import{ECPair as hZ,HDNode as cZ}from"@psf/bitcoincashjs-lib";import{HDKey as pZ}from"@scure/bip32";import{mnemonicToSeedSync as pX}from"@scure/bip39";import{AssetValue as CX,applyFeeMultiplier as nX,Chain as _,DerivationPath as nZ,derivationPathToString as oZ,FeeOption as A,NetworkDerivationPath as uZ,SwapKitError as O,SwapKitNumber as rZ,updateDerivationPath as dZ}from"@swapkit/helpers";import{address as iZ,initEccLib as uX,Psbt as sZ,payments as oX}from"bitcoinjs-lib";import{ECPairFactory as aZ}from"ecpair";function rX({inputs:X,outputs:Z,chain:G,psbt:J,sender:j,compiledMemo:$}){for(let Q of X){let q=!!Q.witnessUtxo&&!i.includes(G)&&{witnessUtxo:Q.witnessUtxo},W=i.includes(G)&&{nonWitnessUtxo:Q.txHex?Buffer.from(Q.txHex,"hex"):void 0};J.addInput({hash:Q.hash,index:Q.index,...q,...W})}for(let Q of Z){let q="address"in Q&&Q.address?Q.address:j,W=Q.script;if(W&&!$)continue;let B=W?{script:$,value:0}:{address:q,value:Q.value};uX(HX),J.addOutput(B)}return{inputs:X,psbt:J}}async function dX({assetValue:X,recipient:Z,memo:G,feeRate:J,sender:j,fetchTxHex:$=!1}){let Q=X.chain,q=G?await N(G):null,W=await aX({assetValue:X,fetchTxHex:$,memo:G,recipient:Z,sender:j}),{inputs:B,outputs:L}=k({...W,chain:Q,feeRate:J});if(!(B&&L))throw new O("toolbox_utxo_insufficient_balance",{assetValue:X,sender:j});let D=await y(),U=new sZ({network:D(Q)});if(Q===_.Dogecoin)U.setMaximumFeeRate(650000000);let{psbt:z,inputs:Y}=await rX({chain:Q,compiledMemo:q,inputs:B,outputs:L,psbt:U,sender:j});return{inputs:Y,psbt:z,utxos:W.inputs}}async function iX(){let X=await y();return function Z({address:G,chain:J}){if(J===_.BitcoinCash)return f(G);if(J===_.Zcash)return l(G);try{return uX(HX),iZ.toOutputScript(G,X(J)),!0}catch(j){return!1}}}async function tZ({chain:X,phrase:Z,derivationPath:G}){let J=(await s(X))({derivationPath:G,phrase:Z});async function j(Q){return await Q.signAllInputs(J),Q}async function $(){return(await vX(X))(J)}return{getAddress:$,signTransaction:j}}async function V({chain:X,...Z}){let G="phrase"in Z?Z.phrase:void 0,J="index"in Z?Z.index||0:0,j=oZ("derivationPath"in Z&&Z.derivationPath?Z.derivationPath:dZ(uZ[X],{index:J})),$=G?await tZ({chain:X,derivationPath:j,phrase:G}):("signer"in Z)?Z.signer:void 0;function Q(){return Promise.resolve($?.getAddress())}let q=await vX(X),W=await iX(),B=await s(X);return{accumulative:k,broadcastTx:(L)=>v(X).broadcastTx(L),calculateTxSize:x,createKeysForPath:B,createTransaction:dX,estimateMaxSendableAmount:eZ(X),estimateTransactionFee:X1(X),getAddress:Q,getAddressFromKeys:q,getBalance:OX(X),getFeeRates:()=>a(X),getInputsOutputsFee:sX,getPrivateKeyFromMnemonic:(L)=>{return B(L).toWIF()},transfer:Z1($),validateAddress:(L)=>W({address:L,chain:X})}}async function sX({assetValue:X,feeOptionKey:Z=A.Fast,feeRate:G,memo:J,sender:j,recipient:$}){let Q=X.chain,q=await aX({assetValue:X,memo:J,recipient:$,sender:j}),W=G?Math.floor(G):(await a(Q))[Z];return k({...q,chain:Q,feeRate:W})}function eZ(X){return async function Z({from:G,memo:J,feeRate:j,feeOptionKey:$=A.Fast,recipients:Q=1}){let q=await v(X).getAddressData(G),W=j?Math.ceil(j):(await a(X))[$],B=q?.utxo.map((Y)=>({...Y,hash:"",type:"P2PKH"})).filter((Y)=>Y.value>Math.max($X(X),P(Y)*W));if(!B?.length)return CX.from({chain:X});let L=CX.from({chain:X,value:B.reduce((Y,H)=>Y+H.value,0)}),D=typeof Q==="number"?Array.from({length:Q},()=>({address:G,value:0})):Q;if(J){let Y=await N(J);D.push({address:G,script:Y,value:0})}let z=x({feeRate:W,inputs:B,outputs:D})*W;return L.sub(z)}}function X1(X){return async(Z)=>{let G=await sX(Z);return CX.from({chain:X,value:rZ.fromBigInt(BigInt(G.fee),8).getValue("string")})}}async function s(X){let Z=await y();switch(X){case _.BitcoinCash:return function G({phrase:J,derivationPath:j=`${nZ.BCH}/0`,wif:$}){let Q=Z(X);if($)return hZ.fromWIF($,Q);if(!J)throw new O("toolbox_utxo_invalid_params",{error:"No phrase provided"});return cZ.fromSeedBuffer(Buffer.from(pX(J)),Q).derivePath(j).keyPair};case _.Bitcoin:case _.Dogecoin:case _.Litecoin:case _.Zcash:case _.Dash:return function G({phrase:J,wif:j,derivationPath:$}){if(!(j||J))throw new O("toolbox_utxo_invalid_params",{error:"Either phrase or wif must be provided"});let Q=aZ(HX),q=Z(X);if(j)return Q.fromWIF(j,q);let W=pX(J),B=pZ.fromMasterSeed(W,q).derive($);if(!B.privateKey)throw new O("toolbox_utxo_invalid_params",{error:"Could not get private key from phrase"});return Q.fromPrivateKey(Buffer.from(B.privateKey),{network:q})};default:throw new O("toolbox_utxo_not_supported",{chain:X})}}async function vX(X){let Z=await y();return function G(J){if(!J)throw new O("toolbox_utxo_invalid_params",{error:"Keys must be provided"});let j=i.includes(X)?oX.p2pkh:oX.p2wpkh,{address:$}=j({network:Z(X),pubkey:J.publicKey});if(!$)throw new O("toolbox_utxo_invalid_address",{error:"Address not defined"});return $}}function Z1(X){return async function Z({memo:G,recipient:J,feeOptionKey:j,feeRate:$,assetValue:Q}){let q=await X?.getAddress(),W=Q.chain;if(!(X&&q))throw new O("toolbox_utxo_no_signer");if(!J)throw new O("toolbox_utxo_invalid_params",{error:"Recipient address must be provided"});let B=$||(await a(W))[j||A.Fast],{psbt:L}=await dX({assetValue:Q,feeRate:B,memo:G,recipient:J,sender:q}),D=await X.signTransaction(L);return D.finalizeAllInputs(),v(W).broadcastTx(D.extractTransaction().toHex())}}async function a(X){let Z=await v(X).getSuggestedTxFee();return{[A.Average]:Z,[A.Fast]:nX(Z,A.Fast),[A.Fastest]:nX(Z,A.Fastest)}}async function aX({assetValue:X,recipient:Z,memo:G,sender:J,fetchTxHex:j=!1}){let $=X.chain,Q=(await a($))[A.Fastest],q=j||i.includes($),W=X.getBaseValue("number"),B=Math.ceil(W+Q*5000);return{inputs:await v($).getUtxos({address:J,fetchTxHex:q,targetValue:B}),outputs:[{address:Z,value:W},...G?[{address:"",script:await N(G),value:0}]:[]]}}var i;var t=I(()=>{DX();m();d();i=[_.Dash,_.Dogecoin]});import{address as G1,Transaction as J1,TransactionBuilder as Q1}from"@psf/bitcoincashjs-lib";import{Chain as $1,derivationPathToString as j1,FeeOption as q1,NetworkDerivationPath as W1,SwapKitError as h,updateDerivationPath as L1}from"@swapkit/helpers";import{Psbt as B1}from"bitcoinjs-lib";function S(X){return E(n(X))}function D1(X){function Z({builder:J,utxos:j}){return j.forEach(($,Q)=>{J.sign(Q,X,void 0,65,$.witnessUtxo?.value)}),J.build()}return{getAddress:()=>{let J=X.getAddress(0);return Promise.resolve(S(J))},signTransaction:Z}}async function IX(X){let Z="phrase"in X?X.phrase:void 0,G="index"in X?X.index||0:0,J=j1("derivationPath"in X&&X.derivationPath?X.derivationPath:L1(W1[F],{index:G})),j=Z?(await s(F))({derivationPath:J,phrase:Z}):void 0,$=j?D1(j):("signer"in X)?X.signer:void 0;function Q(){return Promise.resolve($?.getAddress())}let{getBalance:q,getFeeRates:W,broadcastTx:B,...L}=await V({chain:F});function D(U,z=!0){return q(E(n(U)))}return{...L,broadcastTx:B,buildTx:U1,createTransaction:tX,getAddress:Q,getAddressFromKeys:Y1,getBalance:D,getFeeRates:W,stripPrefix:E,stripToCashAddress:S,transfer:z1({broadcastTx:B,getFeeRates:W,signer:$}),validateAddress:f}}async function tX({assetValue:X,recipient:Z,memo:G,feeRate:J,sender:j}){if(!f(Z))throw new h("toolbox_utxo_invalid_address",{address:Z});let $=Math.ceil(X.getBaseValue("number")+J*7500),Q=await v(F).getUtxos({address:S(j),fetchTxHex:!0,targetValue:$}),q=G?await N(G):null,W=[];W.push({address:Z,value:X.getBaseValue("number")});let{inputs:B,outputs:L}=k({chain:F,feeRate:J,inputs:Q,outputs:W});if(!(B&&L))throw new h("toolbox_utxo_insufficient_balance",{assetValue:X,sender:j});let D=await y(),U=new Q1(D(F));await Promise.all(B.map(async(z)=>{let Y=await v(F).getRawTx(z.hash);U.addInput(J1.fromBuffer(Buffer.from(Y,"hex")),z.index)}));for(let z of L){let Y="address"in z&&z.address?z.address:g(j),H=await y(),T=G1.toOutputScript(g(Y),H(F));U.addOutput(T,z.value)}if(q)U.addOutput(q,0);return{builder:U,utxos:B}}function z1({broadcastTx:X,getFeeRates:Z,signer:G}){return async function J({recipient:j,assetValue:$,feeOptionKey:Q=q1.Fast,...q}){let W=await G?.getAddress();if(!(G&&W))throw new h("toolbox_utxo_no_signer");if(!j)throw new h("toolbox_utxo_invalid_params",{error:"Recipient address must be provided"});let B=q.feeRate||(await Z())[Q],{builder:L,utxos:D}=await tX({...q,assetValue:$,feeRate:B,recipient:j,sender:W}),z=(await G.signTransaction({builder:L,utxos:D})).toHex();return X(z)}}async function U1({assetValue:X,recipient:Z,memo:G,feeRate:J,sender:j,setSigHashType:$}){let Q=n(Z);if(!f(Q))throw new h("toolbox_utxo_invalid_address",{address:Q});let q=Math.ceil(X.getBaseValue("number")+J*7500),W=await v(F).getUtxos({address:S(j),fetchTxHex:!1,targetValue:q}),B=Number(J.toFixed(0)),L=G?await N(G):null,D=[];if(D.push({address:g(Z),value:X.getBaseValue("number")}),L)D.push({script:L,value:0});let{inputs:U,outputs:z}=k({chain:F,feeRate:B,inputs:W,outputs:D});if(!(U&&z))throw new h("toolbox_utxo_insufficient_balance",{assetValue:X,sender:j});let Y=await y(),H=new B1({network:Y(F)});for(let{hash:T,index:K,witnessUtxo:b}of U)H.addInput({hash:T,index:K,sighashType:$?65:void 0,witnessUtxo:b});for(let T of z){let K="address"in T&&T.address?T.address:g(j),b=T.script?L?{script:L,value:0}:void 0:{address:K,value:T.value};if(b)H.addOutput(b)}return{inputs:U,psbt:H,utxos:W}}function Y1(X){let Z=X.getAddress(0);return S(Z)}var F;var jX=I(()=>{m();t();d();F=$1.BitcoinCash});import{bitgo as M1,crypto as T1,ECPair as XZ,networks as C1,address as H1}from"@bitgo/utxo-lib";import{HDKey as ZZ}from"@scure/bip32";import{mnemonicToSeedSync as GZ}from"@scure/bip39";import{Chain as qX,derivationPathToString as v1,FeeOption as I1,NetworkDerivationPath as _1,SKConfig as F1,SwapKitError as WX,updateDerivationPath as y1}from"@swapkit/helpers";import N1 from"bs58check";import{match as k1,P as _X}from"ts-pattern";function JZ(){return C1.zcash}function QZ(){return{bech32:void 0,bip32:{private:76066276,public:76067358},messagePrefix:`\x18ZCash Signed Message:
|
|
2
|
+
`,pubKeyHash:28,scriptHash:28,wif:128}}function A1({phrase:X,derivationPath:Z}){let G=GZ(X),j=ZZ.fromMasterSeed(G).derive(Z);if(!j.privateKey)throw new WX("toolbox_utxo_invalid_params");let $=QZ(),Q=XZ.fromPrivateKey(Buffer.from(j.privateKey),{network:$}),q=T1.hash160(Q.publicKey),{isStagenet:W}=F1.get("envs"),B=W?Buffer.from([29,37]):Buffer.from([28,184]),L=Buffer.concat([B,q]),D=N1.encode(L);return{getAddress:()=>Promise.resolve(D),signTransaction:(U)=>{let z=U.signAllInputs(Q);return Promise.resolve(z)}}}function O1({inputs:X,outputs:Z,psbt:G,sender:J,compiledMemo:j}){for(let $ of X){let Q=!!$.witnessUtxo&&{witnessUtxo:{...$.witnessUtxo,value:BigInt($.value)}},q=!$.witnessUtxo&&{nonWitnessUtxo:$.txHex?Buffer.from($.txHex,"hex"):void 0};G.addInput({hash:$.hash,index:$.index,...Q,...q})}for(let $ of Z){let Q="address"in $&&$.address?$.address:J,q=$.script;if(q&&!j)continue;let W=q?{script:j,value:0n}:{script:H1.toOutputScript(Q,JZ()),value:BigInt($.value)};G.addOutput(W)}return{inputs:X,psbt:G}}async function eX(X){let{assetValue:Z,recipient:G,memo:J,feeRate:j,sender:$,fetchTxHex:Q}=X,q=J?N(J):null,W=await v(qX.Zcash).getUtxos({address:$,fetchTxHex:Q!==!1}),B=[{address:G,value:Number(Z.getBaseValue("string"))},...q?[{script:q,value:0}]:[]],{inputs:L,outputs:D}=k({chain:qX.Zcash,changeAddress:$,feeRate:j,inputs:W,outputs:B});if(!(L&&D))throw new WX("toolbox_utxo_insufficient_balance",{assetValue:Z,sender:$});let U=M1.createPsbtForNetwork({network:JZ()},{version:455});U.setVersion(4,!0);let z=Buffer.concat([Buffer.of(252),Buffer.of(5),Buffer.from("BITGO"),Buffer.of(0)]),Y=3370586197,H=Buffer.allocUnsafe(4);H.writeUInt32LE(Y>>>0,0),U.addUnknownKeyValToGlobal({key:z,value:H});let{psbt:T,inputs:K}=await O1({compiledMemo:q,inputs:L,outputs:D,psbt:U,sender:$});return{inputs:K,outputs:D,psbt:T}}async function FX(X){let Z=await k1(X).with({signer:_X.not(_X.nullish)},({signer:Q})=>Promise.resolve(Q)).with({phrase:_X.string},({phrase:Q,derivationPath:q,index:W=0})=>{let B=q||_1[qX.Zcash]||[44,133,0,0,0],L=y1(B,{index:W}),D=v1(L);return A1({derivationPath:D,phrase:Q})}).otherwise(()=>Promise.resolve(void 0)),G=await V({chain:qX.Zcash,signer:Z});async function J({recipient:Q,assetValue:q,feeOptionKey:W=I1.Fast,...B}){let L=await Z?.getAddress();if(!(Z&&L))throw new WX("toolbox_utxo_no_signer");let D=B.feeRate||(await G.getFeeRates())[W],{psbt:U}=await eX({...B,assetValue:q,feeRate:D,recipient:Q,sender:L}),z=await Z.signTransaction(U);return z.finalizeAllInputs(),G.broadcastTx(z.extractTransaction().toHex())}function j({phrase:Q,derivationPath:q="m/44'/133'/0'/0/0"}){let W=GZ(Q),L=ZZ.fromMasterSeed(W).derive(q);if(!L.privateKey)throw new WX("toolbox_utxo_invalid_params");let D=QZ();return XZ.fromPrivateKey(Buffer.from(L.privateKey),{network:D})}function $({phrase:Q,derivationPath:q="m/44'/133'/0'/0/0"}){return j({derivationPath:q,phrase:Q}).toWIF()}return{...G,createKeysForPath:j,createTransaction:eX,getPrivateKeyFromMnemonic:$,transfer:J,validateAddress:l}}var yX=I(()=>{m();t();d()});import{Chain as c,SwapKitError as w1}from"@swapkit/helpers";async function P1(X,Z){switch(X){case c.BitcoinCash:return await IX(Z||{});case c.Zcash:return await FX(Z);case c.Bitcoin:case c.Dogecoin:case c.Litecoin:case c.Dash:return await V({chain:X,...Z});default:throw new w1("toolbox_utxo_not_supported",{chain:X})}}var $Z=I(()=>{jX();t();yX();jX();d()});var K1={};BZ(K1,{validateZcashAddress:()=>l,toLegacyAddress:()=>g,toCashAddress:()=>n,stripToCashAddress:()=>S,stripPrefix:()=>E,nonSegwitChains:()=>i,isValidAddress:()=>YX,getUtxoToolbox:()=>P1,getUtxoNetwork:()=>y,getUtxoApi:()=>v,getUTXOAddressValidator:()=>iX,getScriptTypeForAddress:()=>u,getOutputSize:()=>r,getInputSize:()=>P,getDustThreshold:()=>$X,getCreateKeysForPath:()=>s,detectAddressNetwork:()=>MX,createZcashToolbox:()=>FX,createUTXOToolbox:()=>V,createCustomUtxoApi:()=>AZ,createBCHToolbox:()=>IX,compileMemo:()=>N,calculateTxSize:()=>x,bchValidateAddress:()=>f,addressFromKeysGetter:()=>vX,addInputsAndOutputs:()=>rX,accumulative:()=>k,UtxoNetwork:()=>UX,UTXOScriptType:()=>QX,TX_OVERHEAD:()=>JX,OutputSizes:()=>o,OP_RETURN_OVERHEAD:()=>hX,MIN_TX_FEE:()=>EZ,InputSizes:()=>GX});var b1=I(()=>{m();$Z();jX();t();yX()});b1();export{l as validateZcashAddress,g as toLegacyAddress,n as toCashAddress,S as stripToCashAddress,E as stripPrefix,i as nonSegwitChains,YX as isValidAddress,P1 as getUtxoToolbox,y as getUtxoNetwork,v as getUtxoApi,iX as getUTXOAddressValidator,u as getScriptTypeForAddress,r as getOutputSize,P as getInputSize,$X as getDustThreshold,s as getCreateKeysForPath,MX as detectAddressNetwork,FX as createZcashToolbox,V as createUTXOToolbox,AZ as createCustomUtxoApi,IX as createBCHToolbox,N as compileMemo,x as calculateTxSize,f as bchValidateAddress,vX as addressFromKeysGetter,rX as addInputsAndOutputs,k as accumulative,UX as UtxoNetwork,QX as UTXOScriptType,JX as TX_OVERHEAD,o as OutputSizes,hX as OP_RETURN_OVERHEAD,EZ as MIN_TX_FEE,GX as InputSizes};
|
|
3
3
|
|
|
4
|
-
//# debugId=
|
|
4
|
+
//# debugId=DB9056F698812E5B64756E2164756E21
|
|
5
5
|
//# sourceMappingURL=index.js.map
|