@swapkit/toolboxes 5.2.1 → 5.4.0
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/CHANGELOG.md +23 -0
- package/dist/{chunk-xbdjxeqd.js → chunk-4428244x.js} +1 -1
- package/dist/{chunk-nvfkjbyq.js → chunk-as9fracn.js} +2 -2
- package/dist/chunk-dssawneq.js +1 -0
- package/dist/chunk-qsbf0z90.js +1 -0
- package/dist/chunk-rn33j2bm.js +2 -0
- package/dist/src/aleo/index.js +1 -1
- package/dist/src/aptos/index.js +1 -1
- package/dist/src/cardano/index.js +1 -1
- package/dist/src/cosmos/index.js +1 -1
- package/dist/src/evm/index.js +1 -1
- package/dist/src/hypercore/index.js +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/near/index.js +1 -1
- package/dist/src/radix/index.js +1 -1
- package/dist/src/ripple/index.js +1 -1
- package/dist/src/solana/index.js +1 -1
- package/dist/src/starknet/index.js +1 -1
- package/dist/src/stellar/index.js +1 -1
- package/dist/src/substrate/index.js +1 -1
- package/dist/src/sui/index.js +1 -1
- package/dist/src/ton/index.js +1 -1
- package/dist/src/tron/index.js +1 -1
- package/dist/src/utxo/index.js +1 -1
- package/dist/types/evm/toolbox/baseEVMToolbox.d.ts +2 -2
- package/dist/types/evm/toolbox/evm.d.ts +218 -46
- package/dist/types/evm/toolbox/op.d.ts +4 -4
- package/dist/types/evm/types.d.ts +2 -1
- package/dist/types/tron/helpers/trongrid.d.ts +2 -2
- package/dist/types/tron/types.d.ts +7 -0
- package/dist/types/utxo/__tests__/fixtures/utxo.d.ts +178 -0
- package/dist/types/utxo/helpers/bchaddrjs.d.ts +17 -1
- package/dist/types/utxo/helpers/txSize.d.ts +7 -5
- package/dist/types/utxo/index.d.ts +1 -1
- package/dist/types/utxo/toolbox/bitcoinCash.d.ts +1 -0
- package/dist/types/utxo/toolbox/index.d.ts +1 -1
- package/dist/types/utxo/toolbox/utxo.d.ts +6 -0
- package/dist/types/utxo/toolbox/validators.d.ts +2 -1
- package/dist/types/utxo/toolbox/zcash.d.ts +1 -0
- package/package.json +2 -2
- package/dist/chunk-44m22jy1.js +0 -1
- package/dist/chunk-ye1j5pz2.js +0 -2
- package/dist/chunk-zhn86hw6.js +0 -1
package/dist/src/utxo/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ea as j2,fa as M2}from"../../chunk-nvfkjbyq.js";import"../../chunk-xbdjxeqd.js";import{NetworkDerivationPath as p2}from"@swapkit/helpers";function g(X,$){if(!Number.isInteger($)||$<0)throw RangeError(`${X} must be a non-negative integer, got: ${$}`)}function n({accountIndex:X,chain:$,derivationPath:J}){if(X!==void 0)g("accountIndex",X);let[j,Q,Z]=J??p2[$];return[j,Q,X??Z]}function MX({accountIndex:X,change:$=!1,chain:J,derivationPath:j,index:Q}){return g("index",Q),[...n({accountIndex:X,chain:J,derivationPath:j}),Number($),Q]}function ZX(X){return X[2]??0}function d2({deriveAddress:X,getBalance:$,getUtxos:J}){async function j(G){let{accountIndex:q,count:Y,startIndex:W=0,change:L=!1}=G;if(g("count",Y),Y<1)throw RangeError("count must be at least 1");g("startIndex",W);let U=[];for(let _=0;_<Y;_++){let B=await X({accountIndex:q,change:L,index:W+_});if(B)U.push(B)}return U}async function Q(G){let{gapLimit:q=20,change:Y=!1}=G??{},W=[],L=0,U=0;while(L<q){let _=await X({change:Y,index:U});if(!_)break;if((await $(_.address)).some((M)=>M.getValue("number")>0))W.push(_),L=0;else L++;U++}return W}async function Z(G=20){let[q,Y]=await Promise.all([Q({change:!1,gapLimit:G}),Q({change:!0,gapLimit:G})]),W=[...q,...Y],L=await Promise.all(W.map(async(_)=>{let H=(await $(_.address)).reduce((M,C)=>M+C.getValue("number"),0);return{..._,balance:H}})),U=L.reduce((_,B)=>_+B.balance,0);return{addresses:L,total:U}}async function z(G=20){let[q,Y]=await Promise.all([Q({change:!1,gapLimit:G}),Q({change:!0,gapLimit:G})]),W=[...q,...Y];return(await Promise.all(W.map(async(U)=>{return(await J(U.address)).map((B)=>({...B,address:U.address,derivationIndex:U.index,isChange:U.change}))}))).flat()}return{deriveAddresses:j,getAggregatedBalance:Z,getAggregatedUtxos:z,scanForAddresses:Q}}import{Chain as T,getRPCUrl as r2,RequestClient as AX,SKConfig as n2,SwapKitError as v,warnOnce as i2}from"@swapkit/helpers";import{NETWORKS as GX}from"@swapkit/utxo-signer";async function s2({chain:X,txHash:$}){let J=`${YX(X)}/push/transaction`,j=JSON.stringify({data:$});try{let Q=await AX.post(J,{body:j,headers:{"Content-Type":"application/json"}});if(Q.context.code!==200)throw new v("toolbox_utxo_broadcast_failed",{error:Q.context.error||"Transaction broadcast failed"});return Q.data?.transaction_hash||$}catch(Q){let Z=await r2(X);if(Z){let z=JSON.stringify({id:j2(),jsonrpc:"2.0",method:"sendrawtransaction",params:[$]}),G=await AX.post(Z,{body:z,headers:{"Content-Type":"application/json"}});if(G.error)throw new v("toolbox_utxo_broadcast_failed",{error:G.error?.message});if(G.result.includes('"code":-26'))throw new v("toolbox_utxo_invalid_transaction",{error:"Transaction amount was too low"});return G.result}throw Q}}function YX(X){return`https://api.blockchair.com/${a2(X)}`}function $2(X){switch(X){case T.Bitcoin:return 5;case T.Dogecoin:return 1e4;case T.Litecoin:return 1;case T.Zcash:return 1;default:return 2}}function a2(X){switch(X){case T.BitcoinCash:return"bitcoin-cash";case T.Litecoin:return"litecoin";case T.Dash:return"dash";case T.Dogecoin:return"dogecoin";case T.Zcash:return"zcash";case T.Polkadot:return"polkadot";default:return"bitcoin"}}async function t2(X){try{let{feePerKb:$}=await AX.get(`https://app.bitgo.com/api/v2/${X.toLowerCase()}/tx/fee`),J=$/1000;return Math.max(J,$2(X))}catch{return $2(X)}}async function DX(X,$){let J=await AX.get(`${X}${$?`${X.includes("?")?"&":"?"}key=${$}`:""}`);if(!J||J.context.code!==200)throw new v("toolbox_utxo_api_error",{error:`Failed to query ${X}`});return J.data}async function e2({chain:X,apiKey:$}){let J=await DX(`${YX(X)}/stats`,$);if(typeof J.best_block_height!=="number")throw new v("toolbox_utxo_api_error",{error:"Missing best_block_height in stats response"});return J.best_block_height}async function Q2({address:X,chain:$,apiKey:J}){if(!X)throw new v("toolbox_utxo_invalid_params",{error:"Address is required"});try{return(await DX(`${YX($)}/dashboards/address/${X}?transaction_details=true`,J))[X]}catch{return{address:{balance:0,transaction_count:0},utxo:[]}}}async function X0({address:X,chain:$,apiKey:J}){return(await Q2({address:X,apiKey:J,chain:$}))?.address.balance||0}async function Z2({chain:X,apiKey:$,txHash:J}){if(!J)throw new v("toolbox_utxo_invalid_params",{error:"TxHash is required"});try{return(await DX(`${YX(X)}/raw/transaction/${J}`,$))?.[J]?.raw_transaction||""}catch(j){let Q=j instanceof Error?j.message:String(j);return console.error(`Failed to fetch raw transaction: ${Q}`),""}}var $0=4294967294;async function J0({chain:X,apiKey:$,txHash:J}){if(!J)throw new v("toolbox_utxo_invalid_params",{error:"TxHash is required"});let Q=(await DX(`${YX(X)}/dashboards/transaction/${J}`,$))?.[J];if(!Q)throw new v("toolbox_utxo_tx_not_found",{txHash:J});let{transaction:Z,inputs:z,outputs:G}=Q,q=z.map((W)=>W.spending_sequence),Y=Z.is_rbf===!0||q.some((W)=>W<$0);return{blockId:Z.block_id,confirmed:Z.block_id!==-1,fee:Z.fee,inputs:z,isRBF:Y,outputs:G,sequences:q,size:Z.size,txid:Z.hash,weight:Z.weight}}async function j0({chain:X,address:$,apiKey:J,offset:j=0,limit:Q=30}){return(await DX(`${YX(X)}/outputs?q=recipient(${$}),is_spent(false)&s=value(desc)&fields=is_spent,transaction_hash,index,value,script_hex,block_id,spending_signature_hex&limit=${Q}&offset=${j}`,J)).map(({is_spent:q,script_hex:Y,block_id:W,transaction_hash:L,index:U,value:_,spending_signature_hex:B})=>({hash:L,index:U,is_confirmed:W!==-1,is_spent:q,script_hex:Y,txHex:B,value:_}))}function Q0(X){return X.reduce(($,J)=>$+J.value,0)}function J2(X,$){let J=[...X].sort((j,Q)=>Q.value-j.value);if($){let j=[],Q=0;for(let Z of J)if(j.push(Z),Q+=Z.value,Q>=$)break;return j}return J}async function G2({chain:X,address:$,apiKey:J,targetValue:j,accumulativeValue:Q=0,offset:Z=0,limit:z=30}){if(!$)throw new v("toolbox_utxo_invalid_params",{error:"Address is required"});try{let G=await j0({address:$,apiKey:J,chain:X,limit:z,offset:Z,targetValue:j}),Y=G.length<z,W=G.filter(({is_spent:M})=>!M),L=Q0(W),U=Q+L,_=j&&U>=j;if(Y||_)return J2(W,j);let B=await G2({accumulativeValue:U,address:$,apiKey:J,chain:X,limit:z,offset:Z+z,targetValue:j}),H=[...W,...B];return J2(H,j)}catch(G){let q=G instanceof Error?G.message:String(G);return console.error(`Failed to fetch unspent UTXOs: ${q}`),[]}}async function Z0({address:X,chain:$,apiKey:J,fetchTxHex:j=!0,targetValue:Q}){let Z=await G2({address:X,apiKey:J,chain:$,targetValue:Q}),z=j?await Promise.all(Z.map(({hash:G})=>Z2({apiKey:J,chain:$,txHash:G}))):[];return Z.map(({hash:G,index:q,script_hex:Y,value:W},L)=>({address:X,hash:G,index:q,txHex:j?z[L]:void 0,value:W,witnessUtxo:{script:Buffer.from(Y,"hex"),value:W}}))}function I(X){let $=n2.get("apiKeys").blockchair||"";return i2({condition:!$,id:"no_blockchair_api_key_warning",warning:"No Blockchair API key found. Functionality will be limited."}),{broadcastTx:(J)=>s2({chain:X,txHash:J}),getAddressData:(J)=>Q2({address:J,apiKey:$,chain:X}),getBalance:(J)=>X0({address:J,apiKey:$,chain:X}),getBlockHeight:()=>e2({apiKey:$,chain:X}),getRawTx:(J)=>Z2({apiKey:$,chain:X,txHash:J}),getSuggestedTxFee:()=>t2(X),getTransactionDetails:(J)=>J0({apiKey:$,chain:X,txHash:J}),getUtxos:(J)=>Z0({...J,apiKey:$,chain:X})}}function F1(X){return X}function E1(){return function($){switch($){case T.Bitcoin:return GX.bitcoin;case T.BitcoinCash:return GX.bitcoinCash;case T.Dash:return GX.dash;case T.Litecoin:return GX.litecoin;case T.Dogecoin:return GX.dogecoin;case T.Zcash:return GX.zcash;default:throw new v("toolbox_utxo_not_supported",{chain:$})}}}import{sha256 as U0}from"@noble/hashes/sha2.js";import{createBase58check as _0}from"@scure/base";import{SwapKitError as q2}from"@swapkit/helpers";import{CashAddrType as yX,decodeCashAddr as G0,encodeCashAddr as Y0}from"@swapkit/utxo-signer";var q0={P2PKH:yX.P2PKH,P2SH:yX.P2SH},L0={[yX.P2PKH]:"P2PKH",[yX.P2SH]:"P2SH"};function z0(X,$,J){return Y0({hash:J,prefix:X,type:q0[$]})}function W0(X){let $=G0(X),J=L0[$.type];if(!J)throw Error(`Unknown CashAddr type: ${$.type}`);return{hash:$.hash,prefix:$.prefix,type:J}}var hX={decode:W0,encode:z0};var L2=_0(U0);var z2;((J)=>{J.Mainnet="mainnet";J.Testnet="testnet"})(z2||={});var i={["legacy"]:{["mainnet"]:{["p2pkh"]:0,["p2sh"]:5},["testnet"]:{["p2pkh"]:111,["p2sh"]:196}},["bitpay"]:{["mainnet"]:{["p2pkh"]:28,["p2sh"]:40},["testnet"]:{["p2pkh"]:111,["p2sh"]:196}}};function W2(X){try{return vX(X),!0}catch{return!1}}function U2(X){return vX(X)?.network}function c(X){let $=vX(X);if($?.format==="legacy")return X;return M0($)}function RX(X){let $=vX(X);return D0($)}function vX(X){try{let $=N0(X);if($)return $}catch{}try{let $=B0(X);if($)return $}catch{}throw new q2("toolbox_utxo_invalid_address",{address:X})}function N0(X){try{let $=L2.decode(X);if($.length!==21)throw new q2("toolbox_utxo_invalid_address",{address:X});let J=$[0],j=Array.prototype.slice.call($,1);switch(J){case i.legacy.mainnet.p2pkh:return{format:"legacy",hash:j,network:"mainnet",type:"p2pkh"};case i.legacy.mainnet.p2sh:return{format:"legacy",hash:j,network:"mainnet",type:"p2sh"};case i.legacy.testnet.p2pkh:return{format:"legacy",hash:j,network:"testnet",type:"p2pkh"};case i.legacy.testnet.p2sh:return{format:"legacy",hash:j,network:"testnet",type:"p2sh"};case i.bitpay.mainnet.p2pkh:return{format:"bitpay",hash:j,network:"mainnet",type:"p2pkh"};case i.bitpay.mainnet.p2sh:return{format:"bitpay",hash:j,network:"mainnet",type:"p2sh"};default:return}}catch{return}}function B0(X){if(X.indexOf(":")!==-1)try{return Y2(X)}catch{}else{let $=["bitcoincash","bchtest","bchreg"];for(let J of $)try{return Y2(`${J}:${X}`)}catch{}}return}function Y2(X){try{let{hash:$,prefix:J,type:j}=hX.decode(X);return{format:"cashaddr",hash:Array.prototype.slice.call($,0),network:J==="bitcoincash"?"mainnet":"testnet",type:j==="P2PKH"?"p2pkh":"p2sh"}}catch{return}}function M0(X){let $=i.legacy[X.network][X.type],J=Buffer.alloc(1+X.hash.length);return J[0]=$,J.set(X.hash,1),L2.encode(J)}function D0(X){let $=X.network==="mainnet"?"bitcoincash":"bchtest",J=X.type==="p2pkh"?"P2PKH":"P2SH",j=new Uint8Array(X.hash);return hX.encode($,J,j)}import{Chain as a,SwapKitError as dX}from"@swapkit/helpers";import{SwapKitError as H0}from"@swapkit/helpers";import{Script as C0}from"@swapkit/utxo-signer";var l1=1000,cX=10,uX=2,O0=10,k0=41,b0=107;function R(X){let $=new Uint8Array(Buffer.from(X,"utf8"));return C0.encode(["RETURN",$])}var pX;((J)=>{J.P2PKH="P2PKH";J.P2WPKH="P2WPKH"})(pX||={});var oX={["P2PKH"]:148,["P2WPKH"]:68},SX={["P2PKH"]:34,["P2WPKH"]:31},HX=(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 H0("toolbox_utxo_invalid_address",{address:X})},qX=({inputs:X,outputs:$,feeRate:J})=>{let j=X[0]&&"address"in X[0]&&X[0].address?HX(X[0].address):"P2PKH",Z=(J?X.filter((Y)=>Y.value>=oX["type"in Y&&Y.type?Y.type:"P2PKH"]*Math.ceil(J)):X).reduce((Y,W)=>Y+s(W),0),z=$?.reduce((Y,W)=>Y+wX(W),0)||SX[j],G=cX+Z+z;return j==="P2WPKH"?Math.ceil(G+uX/4):G},s=(X)=>{if("type"in X&&X.type)return oX[X.type];if("address"in X&&X.address)return oX[HX(X.address)];return k0+b0},wX=(X,$)=>{if(X?.script)return O0+X.script.length+(X.script.length>=74?2:1);if($)return SX[$];if("address"in X&&X.address)return SX[HX(X.address)];return SX.P2PKH};function CX(X){switch(X){case a.Bitcoin:case a.BitcoinCash:return 550;case a.Dash:case a.Litecoin:return 5500;case a.Dogecoin:return 1e5;case a.Zcash:return 546;default:throw new dX("toolbox_utxo_not_supported",{chain:X})}}function S({inputs:X,outputs:$,feeRate:J=1,chain:j=a.Bitcoin,changeAddress:Q="",sweep:Z=!1}){let z=CX(j),G=X.filter((M)=>{let C=s(M)*J;return Z?M.value>Math.max(C,z):C<=M.value});if(Z){let M=Math.ceil(J*qX({inputs:G,outputs:$})),C=G.reduce((A,l)=>A+l.value,0),u=C-M;if(u<=z)throw new dX("toolbox_sweep_amount_too_low",{available:C,dustThreshold:z,fee:M});let p=$.findIndex((A)=>("address"in A)&&A.address);if(p===-1)throw new dX("toolbox_utxo_invalid_params",{error:"Sweep requires a recipient output"});return{fee:M,inputs:G,outputs:$.map((A,l)=>l===p?{...A,value:u}:A)}}let W=(X[0]&&"address"in X[0]&&X[0].address?HX(X[0].address):"P2PKH")==="P2WPKH"?Math.ceil(uX/4):0,L=cX+W+$.reduce((M,C)=>M+wX(C),0),U=$.reduce((M,C)=>M+C.value,0),_=L*J,B=0,H=[];for(let M of G){let C=s(M),u=J*C;_+=u,B+=M.value,H.push(M);let p=_+U;if(B<p)continue;let A=B-p,l=J*wX({address:Q,value:0});if(A>l){let IX=l+_,PX=B-(U+Math.ceil(IX));if(PX>Math.max(s({value:0})*J,CX(j)))return{fee:Math.ceil(IX),inputs:H,outputs:$.concat({address:Q,value:PX})}}return{fee:Math.ceil(_),inputs:H,outputs:$}}return{fee:Math.ceil(J*qX({inputs:X,outputs:$}))}}import{Chain as _X,SwapKitError as k1}from"@swapkit/helpers";import{hex as E2}from"@scure/base";import{Chain as x0,derivationPathToString as h0,FeeOption as o0,resolveDerivationPath as c0,SwapKitError as h}from"@swapkit/helpers";import{BCHSigHash as u0,CashAddrPrefix as f2,CashAddrType as A2,encodeCashAddr as y2,NETWORKS as p0,p2pkh as R2,Transaction as v2}from"@swapkit/utxo-signer";import{secp256k1 as V0}from"@noble/curves/secp256k1.js";import{hex as e}from"@scure/base";import{HDKey as D2}from"@scure/bip32";import{mnemonicToSeedSync as iX}from"@scure/bip39";import{AssetValue as rX,applyFeeMultiplier as _2,Chain as P,derivationPathToString as kX,FeeOption as w,NetworkDerivationPath as H2,SwapKitError as V,SwapKitNumber as I0,updateDerivationPath as P0,warnOnce as T0}from"@swapkit/helpers";import{Address as F0,BCHSigHash as sX,CashAddrPrefix as E0,CashAddrType as f0,encodeCashAddr as A0,NETWORKS as zX,p2pkh as N2,p2wpkh as y0,RBF_SEQUENCE as R0,SigHash as C2,Transaction as nX,WIF as O2}from"@swapkit/utxo-signer";import{match as k2}from"ts-pattern";import{validateZcashAddress as OX}from"@swapkit/utxo-signer";function LX(X){return X.replace(/(bchtest:|bitcoincash:)/,"")}function t(X){let $=LX(X);return W2($)&&U2($)==="mainnet"}var mX=[P.Dash,P.Dogecoin,P.Zcash,P.BitcoinCash],KX=[P.Bitcoin];function b2({address:X,chain:$}){return k2($).with(P.BitcoinCash,()=>t(X)).with(P.Zcash,()=>OX(X)).otherwise(()=>{try{return F0(E($)).decode(X),!0}catch{return!1}})}function E(X){return k2(X).with(P.Bitcoin,()=>zX.bitcoin).with(P.BitcoinCash,()=>zX.bitcoinCash).with(P.Dash,()=>zX.dash).with(P.Dogecoin,()=>zX.dogecoin).with(P.Litecoin,()=>zX.litecoin).with(P.Zcash,()=>zX.zcash).exhaustive()}function v0({phrase:X,derivationPath:$,network:J,seed:j}){let Q=j??iX(X),z=D2.fromMasterSeed(Q,J.bip32).derive($);if(!z.privateKey)throw new V("toolbox_utxo_invalid_params",{error:"Could not derive private key from phrase"});return z.privateKey}function B2(X){return V0.getPublicKey(X,!0)}function bX({publicKey:X,chain:$,network:J}){if($===P.BitcoinCash){let Z=N2(X,J);if(!Z.hash)throw new V("toolbox_utxo_invalid_address",{error:"Could not derive BCH address hash"});return A0({hash:Z.hash,prefix:E0.MAINNET,type:f0.P2PKH}).replace(/^bitcoincash:/,"")}let Q=!mX.includes($)?y0(X,J):N2(X,J);if(!Q.address)throw new V("toolbox_utxo_invalid_address",{error:"Could not derive address"});return Q.address}function WX({phrase:X,derivationPath:$,chain:J,wif:j,seed:Q}){let Z=E(J);if(j){let Y=O2(Z).decode(j),W=B2(Y);return{privateKey:Y,publicKey:W}}if(!X)throw new V("toolbox_utxo_invalid_params",{error:"Either phrase or wif must be provided"});let z=$||kX(H2[J]),G=v0({derivationPath:z,network:Z,phrase:X,seed:Q}),q=B2(G);return{privateKey:G,publicKey:q}}function S0(X,$){return O2(E($)).encode(X)}function w0({phrase:X,derivationPath:$,chain:J,seed:j}){let Q=$.split("/");if(Q.length<4)throw new V("toolbox_utxo_invalid_params",{error:`Derivation path must have at least 4 levels (got ${Q.length}): ${$}`});let Z=E(J),z=j??iX(X),G=D2.fromMasterSeed(z,Z.bip32),q=Q.slice(0,4).join("/");return G.derive(q)}function XX({inputs:X,outputs:$,chain:J,tx:j,sender:Q,compiledMemo:Z,enableRBF:z=!1}){let G=E(J),q=!mX.includes(J),Y=z?R0:void 0,W=new Set;for(let L of X){let U=`${L.hash}:${L.index}`;if(W.has(U))throw new V("toolbox_utxo_invalid_params",{error:"Duplicate input detected"});W.add(U);let _=typeof L.hash==="string"?e.decode(L.hash):L.hash;if(q&&L.witnessUtxo)j.addInput({index:L.index,sequence:Y,txid:_,witnessUtxo:{amount:BigInt(L.witnessUtxo.value),script:L.witnessUtxo.script}});else if(L.txHex)j.addInput({index:L.index,nonWitnessUtxo:e.decode(L.txHex),sequence:Y,txid:_,...J===P.BitcoinCash?{sighashType:sX.ALL}:{}});else throw new V("toolbox_utxo_invalid_params",{error:"Input requires either witnessUtxo or txHex for non-segwit chains"})}for(let L of $){let U="address"in L&&L.address?L.address:Q;if(J===P.BitcoinCash)U=c(U);if(L.script){if(Z)j.addOutput({amount:0n,script:Z})}else j.addOutputAddress(U,BigInt(L.value),G)}return{inputs:X,tx:j}}async function UX(X){let $=await I(X).getSuggestedTxFee();return{[w.Average]:$,[w.Fast]:_2($,w.Fast),[w.Fastest]:_2($,w.Fastest)}}async function V2({assetValue:X,recipient:$,memo:J,sender:j,sweep:Q,fetchTxHex:Z=!1},z){let G=X.chain,q=Z||mX.includes(G),Y=X.getBaseValue("number"),W=Q?void 0:z??(await UX(G))[w.Fastest],L=Q||W===void 0?void 0:Math.ceil(Y+W*5000);return{inputs:await I(G).getUtxos({address:j,fetchTxHex:q,targetValue:L}),outputs:[{address:$,value:Q?0:Y},...J?[{address:"",script:R(J),value:0}]:[]]}}async function I2({assetValue:X,recipient:$,memo:J,feeRate:j,sender:Q,fetchTxHex:Z=!1,enableRBF:z=!1,sweep:G}){let q=X.chain,Y=J?R(J):null,W=await V2({assetValue:X,fetchTxHex:Z,memo:J,recipient:$,sender:Q,sweep:G},j),{inputs:L,outputs:U}=S({...W,chain:q,feeRate:j,sweep:G});if(!(L&&U))throw new V("toolbox_utxo_insufficient_balance",{assetValue:X,sender:Q});let _=new nX({allowLegacyWitnessUtxo:!0,allowUnknownOutputs:!!Y,version:1}),{inputs:B,tx:H}=XX({chain:q,compiledMemo:Y,enableRBF:z,inputs:L,outputs:U,sender:Q,tx:_});return{inputs:B,tx:H,utxos:W.inputs}}async function P2({assetValue:X,feeOptionKey:$=w.Fast,feeRate:J,memo:j,sender:Q,recipient:Z,sweep:z}){let G=X.chain,q,Y;if(J!==void 0)q=J,Y=Math.floor(J);else{let L=await UX(G);q=L[w.Fastest],Y=L[$]}let W=await V2({assetValue:X,memo:j,recipient:Z,sender:Q,sweep:z},q);return S({...W,chain:G,feeRate:Y,sweep:z})}function K0(X){return async function({from:J,memo:j,feeRate:Q,feeOptionKey:Z=w.Fast,recipient:z=J,recipients:G=1}){let q=Q??(await UX(X))[Z],W=(await I(X).getUtxos({address:J,fetchTxHex:!1})).filter((H)=>H.value>Math.max(CX(X),s(H)*q));if(!W.length)return rX.from({chain:X});let L=typeof G==="number"?Math.max(G,1):G.length,U=typeof G==="number"||L===0?Array.from({length:L||1},()=>({address:z,value:0})):[...G];if(j)U.push({address:J,script:R(j),value:0});let{outputs:_}=S({chain:X,feeRate:q,inputs:W,outputs:U,sweep:!0}),B=_?.[0]?.value??0;return rX.from({chain:X,value:BigInt(B)})}}function m0(X){return async function(J){let{fee:j}=await P2(J);return rX.from({chain:X,value:I0.fromBigInt(BigInt(j),8).getValue("string")})}}function g0({chain:X,phrase:$,derivationPath:J,seed:j}){let Q=E(X),{privateKey:Z,publicKey:z}=WX({chain:X,derivationPath:J,phrase:$,seed:j}),G=X===P.BitcoinCash?[sX.ALL]:[C2.ALL];return{getAddress:()=>bX({chain:X,network:Q,publicKey:z}),privateKey:Z,publicKey:z,signTransaction:(q)=>{return q.sign(Z,G),q}}}function l0(X,$){return async function({memo:j,recipient:Q,feeOptionKey:Z,feeRate:z,assetValue:G,enableRBF:q=!1,sweep:Y}){let W=await $?.getAddress();if(!($&&W))throw new V("toolbox_utxo_no_signer");if(!Q)throw new V("toolbox_utxo_invalid_params",{error:"Recipient address must be provided"});T0({condition:q&&!KX.includes(X),id:`rbf_not_supported_${X}`,warning:`RBF (Replace-by-Fee) is not reliably supported on ${X}. Transaction will be created without RBF signaling.`});let L=q&&KX.includes(X),U=z||(await UX(X))[Z||w.Fast],{tx:_}=await I2({assetValue:G,enableRBF:L,feeRate:U,memo:j,recipient:Q,sender:W,sweep:Y}),B=await $.signTransaction(_);return B.finalize(),I(X).broadcastTx(e.encode(B.extract()))}}function T2(X){return($)=>b2({address:$,chain:X})}function F2(X){let $=E(X);return function(j){if(!j)throw new V("toolbox_utxo_invalid_params",{error:"Keys must be provided"});return bX({chain:X,network:$,publicKey:j.publicKey})}}function $X({chain:X,...$}){let J="phrase"in $?$.phrase:void 0,j="index"in $?$.index||0:0,Q=J?iX(J):void 0,Z="derivationPath"in $&&$.derivationPath?$.derivationPath:P0(H2[X],{index:j}),z=kX(Z),G=J?g0({chain:X,derivationPath:z,phrase:J,seed:Q}):void 0,q="signer"in $?$.signer:void 0,Y=G||q,W=J?WX({chain:X,derivationPath:z,phrase:J,seed:Q}):void 0;function L(){if(Y)return Y.getAddress();return Promise.resolve(void 0)}function U(N){if(!J)return;let D=n({accountIndex:N,chain:X,derivationPath:Z});return w0({chain:X,derivationPath:kX(D),phrase:J,seed:Q})}let _=U();function B(){if(!_)return;return _.publicExtendedKey}function H({accountIndex:N}={}){let D=N===void 0?_:U(N);if(!D)return;let O=n({accountIndex:N,chain:X,derivationPath:Z});return{accountIndex:ZX(O),path:kX(O),xpub:D.publicExtendedKey}}function M({accountIndex:N,index:D,change:O=!1}){let k=N===void 0?_:U(N);if(!k)return;let b=MX({accountIndex:N,chain:X,change:O,derivationPath:Z,index:D}),y=E(X),m=k.deriveChild(Number(O)).deriveChild(D);if(!m.publicKey)throw new V("toolbox_utxo_invalid_params",{error:"Could not derive public key"});let f=bX({chain:X,network:y,publicKey:m.publicKey}),o=e.encode(m.publicKey);return{accountIndex:ZX(b),address:f,change:O,index:D,path:kX(b),pubkey:o}}async function C(N){if(!KX.includes(X))return{reason:`RBF is not supported on ${X}`,supported:!1};let D=await I(X).getTransactionDetails(N);return{canReplace:D.isRBF&&!D.confirmed,confirmed:D.confirmed,enabled:D.isRBF,fee:D.fee,sequences:D.sequences,supported:!0}}async function u({txid:N,newFeeRate:D,recipient:O,memo:k}){if(!KX.includes(X))throw new V("toolbox_utxo_rbf_not_supported",{chain:X});let b=await I(X).getTransactionDetails(N);if(!b.isRBF)throw new V("toolbox_utxo_tx_not_replaceable",{txid:N});if(b.confirmed)throw new V("toolbox_utxo_tx_already_confirmed",{blockId:b.blockId,txid:N});let y=b.inputs.reduce((F,x)=>F+x.value,0),f=b.outputs.find((F)=>F.recipient===O)?.value||0;if(f===0)throw new V("toolbox_utxo_invalid_params",{error:"Could not determine send amount from original transaction"});let o=await Promise.all(b.inputs.map(async(F)=>{let x=await I(X).getRawTx(F.transaction_hash);return{hash:F.transaction_hash,index:F.index,txHex:x,value:F.value,witnessUtxo:void 0}})),NX=k?R(k):null,TX=qX({feeRate:D,inputs:o.map((F)=>({...F,type:"P2WPKH"})),outputs:[{address:O,value:f}]}),d=Math.ceil(TX*D);if(d<=b.fee)throw new V("toolbox_utxo_rbf_fee_too_low",{newFee:d,originalFee:b.fee});let jX=d-b.fee,QX=f-jX;if(QX<=0)throw new V("toolbox_utxo_rbf_insufficient_change");let r=new nX({allowLegacyWitnessUtxo:!0,version:1}),FX=[{address:O,value:QX},...k?[{address:"",script:R(k),value:0}]:[]],EX=y-QX-d,BX=await L();if(EX>CX(X)&&BX)FX.push({address:BX,value:EX});return XX({chain:X,compiledMemo:NX,inputs:o,outputs:FX,sender:BX||O,tx:r}),{feeDelta:jX,newFee:d,originalFee:b.fee,tx:r}}async function p({txid:N,newFeeRate:D,recipient:O,memo:k}){let{tx:b,originalFee:y,newFee:m}=await u({memo:k,newFeeRate:D,recipient:O,txid:N}),f=await lX(b);f.finalize();let o=await I(X).broadcastTx(e.encode(f.extract()));return{newFee:m,originalFee:y,txid:o}}function A({accountIndex:N,index:D,change:O=!1}){g("index",D);let k=N===void 0?_:U(N);if(!k)return;return k.deriveChild(Number(O)).deriveChild(D).privateKey||void 0}function l({tx:N,inputDerivations:D}){if(!_)throw new V("toolbox_utxo_no_signer");let O=X===P.BitcoinCash?[sX.ALL]:[C2.ALL];for(let k=0;k<D.length;k++){let b=D[k];if(!b)continue;let{derivationIndex:y,isChange:m}=b,f=A({change:m,index:y});if(!f)throw new V("toolbox_utxo_invalid_params",{error:`Could not derive private key for input ${k} at index ${y}`});N.signIdx(f,k,O)}return N}async function IX({utxos:N,recipient:D,assetValue:O,memo:k,feeRate:b,feeOptionKey:y,changeAddress:m,sweep:f}){if(f)throw new V("toolbox_utxo_invalid_params",{error:"Sweep is not supported for transfers from multiple addresses"});if(!_)throw new V("toolbox_utxo_no_signer");let o=b||(await UX(X))[y||w.Fast],NX=k?R(k):null,TX=[{address:D,value:O.getBaseValue("number")}];if(NX)TX.push({address:"",script:NX,value:0});let d=N.map(({hash:F,index:x,value:fX,txHex:u2,witnessUtxo:xX})=>({hash:F,index:x,txHex:u2,value:fX,witnessUtxo:xX?{script:xX.script,value:xX.value}:void 0})),{inputs:jX,outputs:QX}=S({chain:X,feeRate:o,inputs:d,outputs:TX});if(!(jX&&QX))throw new V("toolbox_utxo_insufficient_balance",{assetValue:O,sender:"multiple addresses"});let r=new nX({allowLegacyWitnessUtxo:!0,version:1}),FX=N[0]?.address,EX=m||await L()||FX||D;XX({chain:X,compiledMemo:NX,inputs:jX,outputs:QX,sender:EX,tx:r});let BX=jX.map((F)=>{let x=N.find((fX)=>fX.hash===F.hash&&fX.index===F.index);return x?{derivationIndex:x.derivationIndex,isChange:x.isChange}:{derivationIndex:0,isChange:!1}});return l({inputDerivations:BX,tx:r}),r.finalize(),I(X).broadcastTx(e.encode(r.extract()))}function PX({address:N,gapLimit:D=20}){if(!_)return;for(let O=0;O<D;O++){let k=M({change:!1,index:O}),b=M({change:!0,index:O}),y=k?.address===N?!1:b?.address===N;if(k?.address===N||b?.address===N)return{change:y,index:O}}return}function lX(N){if(!Y)throw new V("toolbox_utxo_no_signer");return Y.signTransaction(N)}async function c2(N){let D=await lX(N);return D.finalize(),await I(X).broadcastTx(e.encode(D.extract()))}return{accumulative:S,broadcastTx:(N)=>I(X).broadcastTx(N),bumpFee:p,calculateTxSize:qX,createKeysForPath:(N)=>WX({...N,chain:X}),createReplacementTransaction:u,createTransaction:I2,deriveAddressAtIndex:M,derivePrivateKeyAtIndex:A,estimateMaxSendableAmount:K0(X),estimateTransactionFee:m0(X),getAddress:L,getAddressFromKeys:F2(X),getBalance:M2(X),getExtendedPublicKey:B,getExtendedPublicKeyInfo:H,getFeeRates:()=>UX(X),getInputsOutputsFee:P2,getNetworkForChain:()=>E(X),getPrivateKeyFromMnemonic:(N)=>S0(WX({...N,chain:X}).privateKey,X),isRBFEnabled:C,keys:W,resolveDerivationIndex:PX,signAndBroadcastTransaction:c2,signTransaction:lX,signTransactionWithMultipleKeys:l,transfer:l0(X,Y),transferFromMultipleAddresses:IX,validateAddress:T2(X)}}var K=x0.BitcoinCash;function gX(X){return LX(RX(X))}function d0(X){let $=E(K);function J(Q){return Q.sign(X.privateKey,[u0.ALL]),Q}function j(){let Q=R2(X.publicKey,$);if(!Q.hash)throw new h("toolbox_utxo_invalid_address",{error:"Could not derive BCH address hash"});let Z=y2({hash:Q.hash,prefix:f2.MAINNET,type:A2.P2PKH});return Promise.resolve(Z.replace(/^bitcoincash:/,""))}return{getAddress:j,signTransaction:J}}function S2(X){let $="phrase"in X?X.phrase:void 0,J="index"in X?X.index||0:0,j="derivationPath"in X?X.derivationPath:void 0,Q=c0({chain:K,derivationPath:j,index:J}),Z=h0(Q),z=$?WX({chain:K,derivationPath:Z,phrase:$}):void 0,G=z?d0(z):("signer"in X)?X.signer:void 0;function q(){return Promise.resolve(G?.getAddress())}let{getBalance:Y,getFeeRates:W,broadcastTx:L,...U}=$X($?{chain:K,derivationPath:Q,phrase:$}:{chain:K});function _(M,C=!0){return Y(LX(RX(M)))}function B(M){if(!G)throw new h("toolbox_utxo_no_signer");return G.signTransaction(M)}async function H(M){let C=await B(M);return C.finalize(),await L(E2.encode(C.extract()))}return{...U,broadcastTx:L,buildTx:n0,createTransaction:w2,getAddress:q,getAddressFromKeys:i0,getBalance:_,getFeeRates:W,signAndBroadcastTransaction:H,signTransaction:B,stripPrefix:LX,stripToCashAddress:gX,transfer:r0({broadcastTx:L,getFeeRates:W,signer:G}),validateAddress:t}}async function w2({assetValue:X,recipient:$,memo:J,feeRate:j,sender:Q,sweep:Z}){if(!t($))throw new h("toolbox_utxo_invalid_address",{address:$});let z=Math.ceil(X.getBaseValue("number")+j*7500),G=await I(K).getUtxos({address:gX(Q),fetchTxHex:!0,targetValue:Z?void 0:z}),q=J?R(J):null,Y=[],W=c($);if(Y.push({address:W,value:Z?0:X.getBaseValue("number")}),q)Y.push({script:q,value:0});let{inputs:L,outputs:U}=S({chain:K,feeRate:j,inputs:G,outputs:Y,sweep:Z});if(!(L&&U))throw new h("toolbox_utxo_insufficient_balance",{assetValue:X,sender:Q});let _=new v2({allowLegacyWitnessUtxo:!0,allowUnknownOutputs:!!q,version:1}),B=c(Q),{inputs:H,tx:M}=XX({chain:K,compiledMemo:q,inputs:L,outputs:U.map((C)=>("address"in C)&&C.address?{...C,address:c(C.address)}:C),sender:B,tx:_});return{inputs:H,tx:M,utxos:L}}function r0({broadcastTx:X,getFeeRates:$,signer:J}){return async function({recipient:Q,assetValue:Z,feeOptionKey:z=o0.Fast,sweep:G,...q}){let Y=await J?.getAddress();if(!(J&&Y))throw new h("toolbox_utxo_no_signer");if(!Q)throw new h("toolbox_utxo_invalid_params",{error:"Recipient address must be provided"});let W=q.feeRate||(await $())[z],{tx:L}=await w2({...q,assetValue:Z,feeRate:W,recipient:Q,sender:Y,sweep:G}),U=await J.signTransaction(L);return U.finalize(),X(E2.encode(U.extract()))}}async function n0({assetValue:X,recipient:$,memo:J,feeRate:j,sender:Q}){let Z=RX($);if(!t(Z))throw new h("toolbox_utxo_invalid_address",{address:Z});let z=Math.ceil(X.getBaseValue("number")+j*7500),G=await I(K).getUtxos({address:gX(Q),fetchTxHex:!0,targetValue:z}),q=Number(j.toFixed(0)),Y=J?R(J):null,W=[];if(W.push({address:c($),value:X.getBaseValue("number")}),Y)W.push({script:Y,value:0});let{inputs:L,outputs:U}=S({chain:K,feeRate:q,inputs:G,outputs:W});if(!(L&&U))throw new h("toolbox_utxo_insufficient_balance",{assetValue:X,sender:Q});let _=new v2({allowLegacyWitnessUtxo:!0,allowUnknownOutputs:!!Y,version:1}),{inputs:B,tx:H}=XX({chain:K,compiledMemo:Y,inputs:L,outputs:U,sender:c(Q),tx:_});return{inputs:B,tx:H,utxos:G}}function i0(X){let $=p0.bitcoinCash,J=R2(X.publicKey,$);if(!J.hash)throw new h("toolbox_utxo_invalid_address",{error:"Could not derive BCH address hash"});return y2({hash:J.hash,prefix:f2.MAINNET,type:A2.P2PKH}).replace(/^bitcoincash:/,"")}import{createBase58check as s0,hex as a0}from"@scure/base";import{HDKey as l2}from"@scure/bip32";import{mnemonicToSeedSync as x2}from"@scure/bip39";import{Chain as VX,derivationPathToString as t0,FeeOption as e0,resolveDerivationPath as X1,SKConfig as eX,SwapKitError as JX}from"@swapkit/helpers";import{Address as $1,createZcashTransaction as J1,getZcashConsensusBranchId as j1,isTransparentZcashAddress as K2,OutScript as Q1,PCZT as Z1,utils as h2,WIF as G1,ZCASH_NETWORK as Y1,ZCASH_TEST_NETWORK as q1,ZcashConsensusBranchId as m2,ZcashPSBT as L1,ZcashSigHash as aX,ZcashVersionGroupId as z1}from"@swapkit/utxo-signer";import{match as W1,P as tX}from"ts-pattern";function X2(){let{isStagenet:X}=eX.get("envs");return X?q1:Y1}var U1=s0(h2.sha256);function _1(X){return U1.encode(X)}function N1({phrase:X,derivationPath:$}){let J=x2(X),Q=l2.fromMasterSeed(J).derive($);if(!Q.privateKey||!Q.publicKey)throw new JX("toolbox_utxo_invalid_params");let{privateKey:Z,publicKey:z}=Q,G=h2.hash160(z),{isStagenet:q}=eX.get("envs"),Y=q?new Uint8Array([29,37]):new Uint8Array([28,184]),W=new Uint8Array(Y.length+G.length);W.set(Y,0),W.set(G,Y.length);let L=_1(W);return{getAddress:()=>Promise.resolve(L),signTransaction:(U)=>{if(U instanceof L1){let _=U.toPCZT();return _.signAllInputs(Z,z,aX.ALL),_.finalizeAllInputs(),Promise.resolve(_.extract())}if(U instanceof Z1)return U.signAllInputs(Z,z,aX.ALL),U.finalizeAllInputs(),Promise.resolve(U.extract());return U.signAllInputs(Z,z,aX.ALL),Promise.resolve(U)}}}function B1({inputs:X,outputs:$,tx:J,sender:j,compiledMemo:Q}){let Z=X2();for(let z of X){let G=$1(Z).decode(j),q=Q1.encode(G);J.addInput({index:z.index,script:q,sequence:4294967295,txid:a0.decode(z.hash),value:BigInt(z.value)})}for(let z of $){let G="address"in z&&z.address?z.address:j,q=z.script;if(q&&!Q)continue;if(q&&Q)J.addOutput({amount:0n,script:Q});else J.addOutputAddress(G,BigInt(z.value),Z)}return{inputs:X,tx:J}}async function M1(){let{isStagenet:X}=eX.get("envs");if(X)return m2.IRONWOOD;try{let $=await I(VX.Zcash).getBlockHeight();return j1($+1)}catch{return m2.IRONWOOD}}async function g2(X){let{assetValue:$,recipient:J,memo:j,feeRate:Q,sender:Z,fetchTxHex:z,sweep:G}=X,q=X2();if(!K2(Z,q))throw new JX("toolbox_utxo_invalid_address",{address:Z});if(!K2(J,q))throw new JX("toolbox_utxo_invalid_address",{address:J,error:"Zcash transaction creation currently supports transparent addresses only"});let Y=j?R(j):null,W=await I(VX.Zcash).getUtxos({address:Z,fetchTxHex:z!==!1}),L=[{address:J,value:G?0:Number($.getBaseValue("string"))},...Y?[{script:Y,value:0}]:[]],{inputs:U,outputs:_}=S({chain:VX.Zcash,changeAddress:Z,feeRate:Q,inputs:W,outputs:L,sweep:G});if(!(U&&_))throw new JX("toolbox_utxo_insufficient_balance",{assetValue:$,sender:Z});let B=J1({consensusBranchId:await M1(),expiryHeight:0,lockTime:0,version:4,versionGroupId:z1.SAPLING}),{tx:H,inputs:M}=B1({compiledMemo:Y,inputs:U,outputs:_,sender:Z,tx:B});return{inputs:M,outputs:_,tx:H}}function o2(X){let $=W1(X).with({signer:tX.not(tX.nullish)},({signer:q})=>q).with({phrase:tX.string},({phrase:q,derivationPath:Y,index:W=0})=>{let L=X1({chain:VX.Zcash,derivationPath:Y,index:W}),U=t0(L);return N1({derivationPath:U,phrase:q})}).otherwise(()=>{return}),J=$X({chain:VX.Zcash,signer:$});async function j(q){if(!$)throw new JX("toolbox_utxo_no_signer");return await $.signTransaction(q)}async function Q(q){let Y=await j(q);return J.broadcastTx(Y.toHex())}async function Z({recipient:q,assetValue:Y,feeOptionKey:W=e0.Fast,sweep:L,...U}){let _=await $?.getAddress();if(!($&&_))throw new JX("toolbox_utxo_no_signer");let B=U.feeRate||(await J.getFeeRates())[W],{tx:H}=await g2({...U,assetValue:Y,feeRate:B,recipient:q,sender:_,sweep:L}),C=(await $.signTransaction(H)).toHex();return J.broadcastTx(C)}function z({phrase:q,derivationPath:Y="m/44'/133'/0'/0/0"}){let W=x2(q),U=l2.fromMasterSeed(W).derive(Y);if(!U.privateKey||!U.publicKey)throw new JX("toolbox_utxo_invalid_params");return{privateKey:U.privateKey,publicKey:U.publicKey}}function G({phrase:q,derivationPath:Y="m/44'/133'/0'/0/0"}){let W=z({derivationPath:Y,phrase:q}),L=X2();return G1(L).encode(W.privateKey)}return{...J,createKeysForPath:z,createTransaction:g2,getPrivateKeyFromMnemonic:G,signAndBroadcastTransaction:Q,signTransaction:j,transfer:Z,validateAddress:OX}}import{hex as D1}from"@scure/base";import{HDKey as H1}from"@scure/bip32";import{derivationPathToString as C1}from"@swapkit/helpers";function O1({xpub:X,chain:$,count:J,startIndex:j=0,accountIndex:Q}){if(g("count",J),J<1)throw RangeError("count must be at least 1");g("startIndex",j);let Z=E($),z=H1.fromExtendedKey(X,Z.bip32),G=n({accountIndex:Q,chain:$}),q=ZX(G),Y=[];for(let W of[!1,!0]){let L=z.deriveChild(Number(W));for(let U=0;U<J;U++){let _=j+U,B=L.deriveChild(_);if(!B.publicKey)continue;let H=MX({accountIndex:Q,chain:$,change:W,index:_});Y.push({accountIndex:q,address:bX({chain:$,network:Z,publicKey:B.publicKey}),change:W,index:_,path:C1(H),pubkey:D1.encode(B.publicKey)})}}return Y}function m8(X,$){switch(X){case _X.BitcoinCash:return S2($||{});case _X.Zcash:return o2($);case _X.Bitcoin:case _X.Dogecoin:case _X.Litecoin:case _X.Dash:return $X({chain:X,...$});default:throw new k1("toolbox_utxo_not_supported",{chain:X})}}export{OX as validateZcashAddress,b2 as validateUtxoAddress,t as validateBchAddress,c as toLegacyAddress,RX as toCashAddress,gX as stripToCashAddress,LX as stripPrefix,mX as nonSegwitChains,W2 as isValidAddress,m8 as getUtxoToolbox,E1 as getUtxoNetwork,I as getUtxoApi,T2 as getUTXOAddressValidator,MX as getUTXOAddressPath,n as getUTXOAccountPath,ZX as getUTXOAccountIndexFromPath,HX as getScriptTypeForAddress,wX as getOutputSize,E as getNetworkForChain,s as getInputSize,CX as getDustThreshold,U2 as detectAddressNetwork,O1 as deriveAddressesFromXpub,o2 as createZcashToolbox,$X as createUTXOToolbox,d2 as createHDWalletHelpers,F1 as createCustomUtxoApi,S2 as createBCHToolbox,R as compileMemo,qX as calculateTxSize,g as assertDerivationIndex,F2 as addressFromKeysGetter,XX as addInputsAndOutputs,S as accumulative,z2 as UtxoNetwork,pX as UTXOScriptType,cX as TX_OVERHEAD,uX as SEGWIT_MARKER_FLAG_WEIGHT,SX as OutputSizes,O0 as OP_RETURN_OVERHEAD,l1 as MIN_TX_FEE,oX as InputSizes};
|
|
1
|
+
import{fa as it,ga as vt}from"../../chunk-as9fracn.js";import"../../chunk-4428244x.js";import{NetworkDerivationPath as en}from"@swapkit/helpers";function R(e,t){if(!Number.isInteger(t)||t<0)throw RangeError(`${e} must be a non-negative integer, got: ${t}`)}function G({accountIndex:e,chain:t,derivationPath:n}){if(e!==void 0)R("accountIndex",e);let[s,r,o]=n??en[t];return[s,r,e??o]}function ye({accountIndex:e,change:t=!1,chain:n,derivationPath:s,index:r}){return R("index",r),[...G({accountIndex:e,chain:n,derivationPath:s}),Number(t),r]}function oe(e){return e[2]??0}function tn({deriveAddress:e,getBalance:t,getUtxos:n}){async function s(i){let{accountIndex:c,count:a,startIndex:l=0,change:u=!1}=i;if(R("count",a),a<1)throw RangeError("count must be at least 1");R("startIndex",l);let d=[];for(let h=0;h<a;h++){let m=await e({accountIndex:c,change:u,index:l+h});if(m)d.push(m)}return d}async function r(i){let{gapLimit:c=20,change:a=!1}=i??{},l=[],u=0,d=0;while(u<c){let h=await e({change:a,index:d});if(!h)break;if((await t(h.address)).some((x)=>x.getValue("number")>0))l.push(h),u=0;else u++;d++}return l}async function o(i=20){let[c,a]=await Promise.all([r({change:!1,gapLimit:i}),r({change:!0,gapLimit:i})]),l=[...c,...a],u=await Promise.all(l.map(async(h)=>{let g=(await t(h.address)).reduce((x,P)=>x+P.getValue("number"),0);return{...h,balance:g}})),d=u.reduce((h,m)=>h+m.balance,0);return{addresses:u,total:d}}async function p(i=20){let[c,a]=await Promise.all([r({change:!1,gapLimit:i}),r({change:!0,gapLimit:i})]),l=[...c,...a];return(await Promise.all(l.map(async(d)=>(await n(d.address)).map((m)=>({...m,address:d.address,derivationIndex:d.index,isChange:d.change}))))).flat()}return{deriveAddresses:s,getAggregatedBalance:o,getAggregatedUtxos:p,scanForAddresses:r}}import{Chain as O,getRPCUrl as nn,RequestClient as Be,SKConfig as rn,SwapKitError as X,warnOnce as sn}from"@swapkit/helpers";import{NETWORKS as ae}from"@swapkit/utxo-signer";async function on({chain:e,txHash:t}){let n=`${ie(e)}/push/transaction`,s=JSON.stringify({data:t});try{let r=await Be.post(n,{body:s,headers:{"Content-Type":"application/json"}});if(r.context.code!==200)throw new X("toolbox_utxo_broadcast_failed",{error:r.context.error||"Transaction broadcast failed"});return r.data?.transaction_hash||t}catch(r){let o=await nn(e);if(o){let p=JSON.stringify({id:it(),jsonrpc:"2.0",method:"sendrawtransaction",params:[t]}),i=await Be.post(o,{body:p,headers:{"Content-Type":"application/json"}});if(i.error)throw new X("toolbox_utxo_broadcast_failed",{error:i.error?.message});if(i.result.includes('"code":-26'))throw new X("toolbox_utxo_invalid_transaction",{error:"Transaction amount was too low"});return i.result}throw r}}function ie(e){return`https://api.blockchair.com/${an(e)}`}function ot(e){switch(e){case O.Bitcoin:return 5;case O.Dogecoin:return 1e4;case O.Litecoin:return 1;case O.Zcash:return 1;default:return 2}}function an(e){switch(e){case O.BitcoinCash:return"bitcoin-cash";case O.Litecoin:return"litecoin";case O.Dash:return"dash";case O.Dogecoin:return"dogecoin";case O.Zcash:return"zcash";case O.Polkadot:return"polkadot";default:return"bitcoin"}}async function cn(e){try{let{feePerKb:t}=await Be.get(`https://app.bitgo.com/api/v2/${e.toLowerCase()}/tx/fee`),n=t/1000;return Math.max(n,ot(e))}catch{return ot(e)}}async function be(e,t){let n=await Be.get(`${e}${t?`${e.includes("?")?"&":"?"}key=${t}`:""}`);if(!n||n.context.code!==200)throw new X("toolbox_utxo_api_error",{error:`Failed to query ${e}`});return n.data}async function un({chain:e,apiKey:t}){let n=await be(`${ie(e)}/stats`,t);if(typeof n.best_block_height!=="number")throw new X("toolbox_utxo_api_error",{error:"Missing best_block_height in stats response"});return n.best_block_height}async function ct({address:e,chain:t,apiKey:n}){if(!e)throw new X("toolbox_utxo_invalid_params",{error:"Address is required"});try{return(await be(`${ie(t)}/dashboards/address/${e}?transaction_details=true`,n))[e]}catch{return{address:{balance:0,transaction_count:0},utxo:[]}}}async function dn({address:e,chain:t,apiKey:n}){return(await ct({address:e,apiKey:n,chain:t}))?.address.balance||0}async function ut({chain:e,apiKey:t,txHash:n}){if(!n)throw new X("toolbox_utxo_invalid_params",{error:"TxHash is required"});try{return(await be(`${ie(e)}/raw/transaction/${n}`,t))?.[n]?.raw_transaction||""}catch(s){let r=s instanceof Error?s.message:String(s);return console.error(`Failed to fetch raw transaction: ${r}`),""}}var pn=4294967294;async function ln({chain:e,apiKey:t,txHash:n}){if(!n)throw new X("toolbox_utxo_invalid_params",{error:"TxHash is required"});let r=(await be(`${ie(e)}/dashboards/transaction/${n}`,t))?.[n];if(!r)throw new X("toolbox_utxo_tx_not_found",{txHash:n});let{transaction:o,inputs:p,outputs:i}=r,c=p.map((l)=>l.spending_sequence),a=o.is_rbf===!0||c.some((l)=>l<pn);return{blockId:o.block_id,confirmed:o.block_id!==-1,fee:o.fee,inputs:p,isRBF:a,outputs:i,sequences:c,size:o.size,txid:o.hash,weight:o.weight}}async function hn({chain:e,address:t,apiKey:n,offset:s=0,limit:r=30}){return(await be(`${ie(e)}/outputs?q=recipient(${t}),is_spent(false)&s=value(desc)&fields=is_spent,transaction_hash,index,value,script_hex,block_id,spending_signature_hex&limit=${r}&offset=${s}`,n)).map(({is_spent:c,script_hex:a,block_id:l,transaction_hash:u,index:d,value:h,spending_signature_hex:m})=>({hash:u,index:d,is_confirmed:l!==-1,is_spent:c,script_hex:a,txHex:m,value:h}))}function fn(e){return e.reduce((t,n)=>t+n.value,0)}function at(e,t){let n=[...e].sort((s,r)=>r.value-s.value);if(t){let s=[],r=0;for(let o of n)if(s.push(o),r+=o.value,r>=t)break;return s}return n}async function dt({chain:e,address:t,apiKey:n,targetValue:s,accumulativeValue:r=0,offset:o=0,limit:p=30}){if(!t)throw new X("toolbox_utxo_invalid_params",{error:"Address is required"});try{let i=await hn({address:t,apiKey:n,chain:e,limit:p,offset:o,targetValue:s}),a=i.length<p,l=i.filter(({is_spent:x})=>!x),u=fn(l),d=r+u,h=s&&d>=s;if(a||h)return at(l,s);let m=await dt({accumulativeValue:d,address:t,apiKey:n,chain:e,limit:p,offset:o+p,targetValue:s}),g=[...l,...m];return at(g,s)}catch(i){let c=i instanceof Error?i.message:String(i);return console.error(`Failed to fetch unspent UTXOs: ${c}`),[]}}async function mn({address:e,chain:t,apiKey:n,fetchTxHex:s=!0,targetValue:r}){let o=await dt({address:e,apiKey:n,chain:t,targetValue:r}),p=s?await Promise.all(o.map(({hash:i})=>ut({apiKey:n,chain:t,txHash:i}))):[];return o.map(({hash:i,index:c,script_hex:a,value:l},u)=>({address:e,hash:i,index:c,txHex:s?p[u]:void 0,value:l,witnessUtxo:{script:Buffer.from(a,"hex"),value:l}}))}function A(e){let t=rn.get("apiKeys").blockchair||"";return sn({condition:!t,id:"no_blockchair_api_key_warning",warning:"No Blockchair API key found. Functionality will be limited."}),{broadcastTx:(n)=>on({chain:e,txHash:n}),getAddressData:(n)=>ct({address:n,apiKey:t,chain:e}),getBalance:(n)=>dn({address:n,apiKey:t,chain:e}),getBlockHeight:()=>un({apiKey:t,chain:e}),getRawTx:(n)=>ut({apiKey:t,chain:e,txHash:n}),getSuggestedTxFee:()=>cn(e),getTransactionDetails:(n)=>ln({apiKey:t,chain:e,txHash:n}),getUtxos:(n)=>mn({...n,apiKey:t,chain:e})}}function Er(e){return e}function Mr(){return function(t){switch(t){case O.Bitcoin:return ae.bitcoin;case O.BitcoinCash:return ae.bitcoinCash;case O.Dash:return ae.dash;case O.Litecoin:return ae.litecoin;case O.Dogecoin:return ae.dogecoin;case O.Zcash:return ae.zcash;default:throw new X("toolbox_utxo_not_supported",{chain:t})}}}import{sha256 as vn}from"@noble/hashes/sha2.js";import{createBase58check as Pn}from"@scure/base";import{SwapKitError as lt}from"@swapkit/helpers";import{CashAddrType as ke,decodeCashAddr as gn,encodeCashAddr as xn}from"@swapkit/utxo-signer";var Tn={P2PKH:ke.P2PKH,P2SH:ke.P2SH},yn={[ke.P2PKH]:"P2PKH",[ke.P2SH]:"P2SH"};function bn(e,t,n){return xn({hash:n,prefix:e,type:Tn[t]})}function wn(e){let t=gn(e),n=yn[t.type];if(!n)throw Error(`Unknown CashAddr type: ${t.type}`);return{hash:t.hash,prefix:t.prefix,type:n}}var Ne={decode:wn,encode:bn};var ht=Pn(vn);var ft;((n)=>{n.Mainnet="mainnet";n.Testnet="testnet"})(ft||={});var j={["legacy"]:{["mainnet"]:{["p2pkh"]:0,["p2sh"]:5},["testnet"]:{["p2pkh"]:111,["p2sh"]:196}},["bitpay"]:{["mainnet"]:{["p2pkh"]:28,["p2sh"]:40},["testnet"]:{["p2pkh"]:111,["p2sh"]:196}}},_n={["p2pkh"]:"pkh",["p2sh"]:"sh"};function Gr(e){return Fe(e)!==void 0}function jr(e){return Ze(e).network}function z(e){let t=Ze(e);if(t.format==="legacy")return e;return On(t)}function Xe(e){let t=Ze(e);return Cn(t)}function Fe(e){if(typeof e!=="string")return;let t=An(e)??Un(e);return t&&{...t,scriptType:_n[t.type]}}function Ze(e){let t=Fe(e);if(!t)throw new lt("toolbox_utxo_invalid_address",{address:e});return t}function An(e){try{let t=ht.decode(e);if(t.length!==21)throw new lt("toolbox_utxo_invalid_address",{address:e});let n=t[0],s=Array.prototype.slice.call(t,1);switch(n){case j.legacy.mainnet.p2pkh:return{format:"legacy",hash:s,network:"mainnet",type:"p2pkh"};case j.legacy.mainnet.p2sh:return{format:"legacy",hash:s,network:"mainnet",type:"p2sh"};case j.legacy.testnet.p2pkh:return{format:"legacy",hash:s,network:"testnet",type:"p2pkh"};case j.legacy.testnet.p2sh:return{format:"legacy",hash:s,network:"testnet",type:"p2sh"};case j.bitpay.mainnet.p2pkh:return{format:"bitpay",hash:s,network:"mainnet",type:"p2pkh"};case j.bitpay.mainnet.p2sh:return{format:"bitpay",hash:s,network:"mainnet",type:"p2sh"};default:return}}catch{return}}function Un(e){if(e.indexOf(":")!==-1)try{return pt(e)}catch{}else{let t=["bitcoincash","bchtest","bchreg"];for(let n of t)try{return pt(`${n}:${e}`)}catch{}}return}function pt(e){try{let{hash:t,prefix:n,type:s}=Ne.decode(e);return{format:"cashaddr",hash:Array.prototype.slice.call(t,0),network:n==="bitcoincash"?"mainnet":"testnet",type:s==="P2PKH"?"p2pkh":"p2sh"}}catch{return}}function On(e){let t=j.legacy[e.network][e.type],n=Buffer.alloc(1+e.hash.length);return n[0]=t,n.set(e.hash,1),ht.encode(n)}function Cn(e){let t=e.network==="mainnet"?"bitcoincash":"bchtest",n=e.type==="p2pkh"?"P2PKH":"P2SH",s=new Uint8Array(e.hash);return Ne.encode(t,n,s)}import{Chain as J,SwapKitError as Ve}from"@swapkit/helpers";import{SwapKitError as Sn,UTXO_SCRIPT_TYPE_LIST as Bn,UTXO_SCRIPT_TYPES as mt,UTXOScriptType as ce}from"@swapkit/helpers";import{Script as kn}from"@swapkit/utxo-signer";import{UTXOScriptType as Tt}from"@swapkit/helpers";var es=1000,Le=10,Xn=2,Fn=10;function F(e){let t=new Uint8Array(Buffer.from(e,"utf8"));return kn.encode(["RETURN",t])}function gt(e){return Object.fromEntries(Bn.map((t)=>[t,mt[t][e]]))}var xt=gt("inputSize"),Ke=gt("outputSize"),ze=(e)=>mt[e].witness,ve=(e)=>{if(e.startsWith("bc1")||e.startsWith("tb1")||e.startsWith("ltc1")||e.startsWith("tltc1"))return ce.P2WPKH;if(e.startsWith("1")||e.startsWith("m")||e.startsWith("n")||e.startsWith("bitcoincash:q")||e.startsWith("bitcoincash:p")||e.startsWith("q")||e.startsWith("p")||e.startsWith("L")||e.startsWith("M")||e.startsWith("3")||e.startsWith("D")||e.startsWith("A")||e.startsWith("9")||e.startsWith("X")||e.startsWith("7")||e.startsWith("y")||e.startsWith("t1")||e.startsWith("t3")||e.startsWith("tm"))return ce.P2PKH;throw new Sn("toolbox_utxo_invalid_address",{address:e})},ue=({inputs:e,outputs:t,feeRate:n})=>{let s=e[0]?we(e[0]):ce.P2PKH,r=n?e.filter((a)=>a.value>=xt["type"in a&&a.type?a.type:ce.P2PKH]*Math.ceil(n)):e,o=0,p=0;for(let a of r)if(o+=Y(a),!ze(we(a)))p++;let i=t?.reduce((a,l)=>a+De(l),0)||Ke[s],c=p<r.length;return Le+o+i+$e(c,p)},we=(e)=>{if("type"in e&&e.type)return e.type;if("address"in e&&e.address)return ve(e.address);return ce.P2PKH},Y=(e)=>xt[we(e)],$e=(e,t)=>e?Math.ceil((Xn+t)/4):0,De=(e,t)=>{if(e?.script)return Fn+e.script.length+(e.script.length>=74?2:1);if(t)return Ke[t];if("address"in e&&e.address)return Ke[ve(e.address)];return Ke[ce.P2PKH]};function Pe(e){switch(e){case J.Bitcoin:case J.BitcoinCash:return 550;case J.Dash:case J.Litecoin:return 5500;case J.Dogecoin:return 1e5;case J.Zcash:return 546;default:throw new Ve("toolbox_utxo_not_supported",{chain:e})}}function K({inputs:e,outputs:t,feeRate:n=1,chain:s=J.Bitcoin,changeAddress:r="",sweep:o=!1}){let p=Pe(s),i=e.filter((g)=>{let x=Y(g)*n;return o?g.value>Math.max(x,p):x<=g.value});if(o){let g=Math.ceil(n*ue({inputs:i,outputs:t})),x=i.reduce((B,W)=>B+W.value,0),P=x-g;if(P<=p)throw new Ve("toolbox_sweep_amount_too_low",{available:x,dustThreshold:p,fee:g});let V=t.findIndex((B)=>("address"in B)&&B.address);if(V===-1)throw new Ve("toolbox_utxo_invalid_params",{error:"Sweep requires a recipient output"});return{fee:g,inputs:i,outputs:t.map((B,W)=>W===V?{...B,value:P}:B)}}let c=Le+t.reduce((g,x)=>g+De(x),0),a=t.reduce((g,x)=>g+x.value,0),l=0,u=0,d=!1,h=0,m=[];for(let g of i){if(l+=Y(g),ze(we(g)))d=!0;else u++;h+=g.value,m.push(g);let x=(c+l+$e(d,u))*n,P=x+a;if(h<P)continue;let V=h-P,B=n*De({address:r,value:0});if(V>B){let W=B+x,me=h-(a+Math.ceil(W));if(me>Math.max(Y({value:0})*n,Pe(s)))return{fee:Math.ceil(W),inputs:m,outputs:t.concat({address:r,value:me})}}return{fee:Math.ceil(x),inputs:m,outputs:t}}return{fee:Math.ceil(n*ue({inputs:e,outputs:t}))}}import{Chain as fe,SwapKitError as Kr}from"@swapkit/helpers";import{hex as Kt}from"@scure/base";import{Chain as Qn,derivationPathToString as er,FeeOption as tr,resolveDerivationPath as nr,SwapKitError as M}from"@swapkit/helpers";import{BCHSigHash as rr,CashAddrPrefix as Dt,CashAddrType as It,encodeCashAddr as Ht,NETWORKS as sr,p2pkh as Rt,Transaction as Wt}from"@swapkit/utxo-signer";import{secp256k1 as Kn}from"@noble/curves/secp256k1.js";import{hex as Q}from"@scure/base";import{HDKey as Pt}from"@scure/bip32";import{mnemonicToSeedSync as Je}from"@scure/bip39";import{AssetValue as je,applyFeeMultiplier as yt,Chain as U,derivationPathToString as Ae,FeeOption as D,NetworkDerivationPath as _t,SwapKitError as w,SwapKitNumber as Dn,updateDerivationPath as In,warnOnce as Hn}from"@swapkit/helpers";import{BCHSigHash as Qe,CashAddrPrefix as Rn,CashAddrType as Wn,encodeCashAddr as En,getAddressScriptType as Mn,NETWORKS as pe,OutScript as Nn,p2pkh as bt,p2wpkh as Zn,RBF_SEQUENCE as Ln,SigHash as At,Transaction as Ye,WIF as Ut}from"@swapkit/utxo-signer";import{match as Ot}from"ts-pattern";import{getZcashAddressType as qe,validateZcashAddress as Ge}from"@swapkit/utxo-signer";function de(e){return e.replace(/(bchtest:|bitcoincash:)/,"")}function Ie(e){if(typeof e!=="string")return null;let t=Fe(de(e));if(!t||t.network!=="mainnet")return null;return t.scriptType}function _e(e){return Ie(e)!==null}var Re=[U.Dash,U.Dogecoin,U.Zcash,U.BitcoinCash],He=[U.Bitcoin];function et({address:e,chain:t}){return Ot(t).with(U.BitcoinCash,()=>Ie(e)).with(U.Zcash,()=>qe(e)).otherwise(()=>Mn(e,S(t)))}function Ct({address:e,chain:t}){return et({address:e,chain:t})!==null}function S(e){return Ot(e).with(U.Bitcoin,()=>pe.bitcoin).with(U.BitcoinCash,()=>pe.bitcoinCash).with(U.Dash,()=>pe.dash).with(U.Dogecoin,()=>pe.dogecoin).with(U.Litecoin,()=>pe.litecoin).with(U.Zcash,()=>pe.zcash).exhaustive()}function zn({phrase:e,derivationPath:t,network:n,seed:s}){let r=s??Je(e),p=Pt.fromMasterSeed(r,n.bip32).derive(t);if(!p.privateKey)throw new w("toolbox_utxo_invalid_params",{error:"Could not derive private key from phrase"});return p.privateKey}function wt(e){return Kn.getPublicKey(e,!0)}function Ue({publicKey:e,chain:t,network:n}){if(t===U.BitcoinCash){let o=bt(e,n);if(!o.hash)throw new w("toolbox_utxo_invalid_address",{error:"Could not derive BCH address hash"});return En({hash:o.hash,prefix:Rn.MAINNET,type:Wn.P2PKH}).replace(/^bitcoincash:/,"")}let r=!Re.includes(t)?Zn(e,n):bt(e,n);if(!r.address)throw new w("toolbox_utxo_invalid_address",{error:"Could not derive address"});return r.address}function le({phrase:e,derivationPath:t,chain:n,wif:s,seed:r}){let o=S(n);if(s){let a=Ut(o).decode(s),l=wt(a);return{privateKey:a,publicKey:l}}if(!e)throw new w("toolbox_utxo_invalid_params",{error:"Either phrase or wif must be provided"});let p=t||Ae(_t[n]),i=zn({derivationPath:p,network:o,phrase:e,seed:r}),c=wt(i);return{privateKey:i,publicKey:c}}function $n(e,t){return Ut(S(t)).encode(e)}function Vn({phrase:e,derivationPath:t,chain:n,seed:s}){let r=t.split("/");if(r.length<4)throw new w("toolbox_utxo_invalid_params",{error:`Derivation path must have at least 4 levels (got ${r.length}): ${t}`});let o=S(n),p=s??Je(e),i=Pt.fromMasterSeed(p,o.bip32),c=r.slice(0,4).join("/");return i.derive(c)}function qn(e){try{let{type:t}=Nn.decode(e);return t==="wpkh"||t==="tr"}catch{return!1}}function ee({inputs:e,outputs:t,chain:n,tx:s,sender:r,compiledMemo:o,enableRBF:p=!1}){let i=S(n),c=!Re.includes(n),a=p?Ln:void 0,l=new Set;for(let u of e){let d=`${u.hash}:${u.index}`;if(l.has(d))throw new w("toolbox_utxo_invalid_params",{error:"Duplicate input detected"});l.add(d);let h=typeof u.hash==="string"?Q.decode(u.hash):u.hash;if(c&&u.witnessUtxo&&qn(u.witnessUtxo.script))s.addInput({index:u.index,sequence:a,txid:h,witnessUtxo:{amount:BigInt(u.witnessUtxo.value),script:u.witnessUtxo.script}});else if(u.txHex)s.addInput({index:u.index,nonWitnessUtxo:Q.decode(u.txHex),sequence:a,txid:h,...n===U.BitcoinCash?{sighashType:Qe.ALL}:{}});else throw new w("toolbox_utxo_invalid_params",{error:`Input ${d} cannot be signed from its witnessUtxo alone: it needs its previous transaction (txHex)`})}for(let u of t){let d="address"in u&&u.address?u.address:r;if(n===U.BitcoinCash)d=z(d);if(u.script)if(o)s.addOutput({amount:0n,script:o});else throw new w("toolbox_utxo_invalid_params",{error:"An output carrying a script needs the compiled memo it carries"});else s.addOutputAddress(d,BigInt(u.value),i)}return{inputs:e,tx:s}}async function he(e){let t=await A(e).getSuggestedTxFee();return{[D.Average]:t,[D.Fast]:yt(t,D.Fast),[D.Fastest]:yt(t,D.Fastest)}}async function St({assetValue:e,recipient:t,memo:n,sender:s,sweep:r,fetchTxHex:o=!1},p,{forEstimateOnly:i=!1}={}){let c=e.chain,a=Re.includes(c)||ve(s)===Tt.P2PKH,l=o||!i&&a,u=e.getBaseValue("number"),d=r?void 0:p??(await he(c))[D.Fastest],h=r||d===void 0?void 0:Math.ceil(u+d*5000);return{inputs:await A(c).getUtxos({address:s,fetchTxHex:l,targetValue:h}),outputs:[{address:t,value:r?0:u},...n?[{address:"",script:F(n),value:0}]:[]]}}async function Bt({assetValue:e,recipient:t,memo:n,feeRate:s,sender:r,fetchTxHex:o=!1,enableRBF:p=!1,sweep:i}){let c=e.chain,a=n?F(n):null,l=await St({assetValue:e,fetchTxHex:o,memo:n,recipient:t,sender:r,sweep:i},s),{inputs:u,outputs:d}=K({...l,chain:c,changeAddress:r,feeRate:s,sweep:i});if(!(u&&d))throw new w("toolbox_utxo_insufficient_balance",{assetValue:e,sender:r});let h=new Ye({allowUnknownOutputs:!!a,version:1}),{inputs:m,tx:g}=ee({chain:c,compiledMemo:a,enableRBF:p,inputs:u,outputs:d,sender:r,tx:h});return{inputs:m,tx:g,utxos:l.inputs}}async function kt({assetValue:e,feeOptionKey:t=D.Fast,feeRate:n,memo:s,sender:r,recipient:o,sweep:p}){let i=e.chain,c,a;if(n!==void 0)c=n,a=Math.floor(n);else{let u=await he(i);c=u[D.Fastest],a=u[t]}let l=await St({assetValue:e,memo:s,recipient:o,sender:r,sweep:p},c,{forEstimateOnly:!0});return K({...l,chain:i,changeAddress:r,feeRate:a,sweep:p})}function Gn(e){return async function({from:n,memo:s,feeRate:r,feeOptionKey:o=D.Fast,recipient:p=n,recipients:i=1}){let c=r??(await he(e))[o],l=(await A(e).getUtxos({address:n,fetchTxHex:!1})).filter((g)=>g.value>Math.max(Pe(e),Y(g)*c));if(!l.length)return je.from({chain:e});let u=typeof i==="number"?Math.max(i,1):i.length,d=typeof i==="number"||u===0?Array.from({length:u||1},()=>({address:p,value:0})):[...i];if(s)d.push({address:n,script:F(s),value:0});let{outputs:h}=K({chain:e,feeRate:c,inputs:l,outputs:d,sweep:!0}),m=h?.[0]?.value??0;return je.from({chain:e,value:BigInt(m)})}}function jn(e){return async function(n){let{fee:s}=await kt(n);return je.from({chain:e,value:Dn.fromBigInt(BigInt(s),8).getValue("string")})}}function Yn({chain:e,phrase:t,derivationPath:n,seed:s}){let r=S(e),{privateKey:o,publicKey:p}=le({chain:e,derivationPath:n,phrase:t,seed:s}),i=e===U.BitcoinCash?[Qe.ALL]:[At.ALL];return{getAddress:()=>Ue({chain:e,network:r,publicKey:p}),privateKey:o,publicKey:p,signTransaction:(c)=>(c.sign(o,i),c)}}function Jn(e,t){return async function({memo:s,recipient:r,feeOptionKey:o,feeRate:p,assetValue:i,enableRBF:c=!1,sweep:a}){let l=await t?.getAddress();if(!(t&&l))throw new w("toolbox_utxo_no_signer");if(!r)throw new w("toolbox_utxo_invalid_params",{error:"Recipient address must be provided"});Hn({condition:c&&!He.includes(e),id:`rbf_not_supported_${e}`,warning:`RBF (Replace-by-Fee) is not reliably supported on ${e}. Transaction will be created without RBF signaling.`});let u=c&&He.includes(e),d=p||(await he(e))[o||D.Fast],{tx:h}=await Bt({assetValue:i,enableRBF:u,feeRate:d,memo:s,recipient:r,sender:l,sweep:a}),m=await t.signTransaction(h);return m.finalize(),A(e).broadcastTx(Q.encode(m.extract()))}}function Xt(e){return(t)=>Ct({address:t,chain:e})}function Ft(e){let t=S(e);return function(s){if(!s)throw new w("toolbox_utxo_invalid_params",{error:"Keys must be provided"});return Ue({chain:e,network:t,publicKey:s.publicKey})}}function te({chain:e,...t}){let n="phrase"in t?t.phrase:void 0,s="index"in t?t.index||0:0,r=n?Je(n):void 0,o="derivationPath"in t&&t.derivationPath?t.derivationPath:In(_t[e],{index:s}),p=Ae(o),i=n?Yn({chain:e,derivationPath:p,phrase:n,seed:r}):void 0,c="signer"in t?t.signer:void 0,a=i||c,l=n?le({chain:e,derivationPath:p,phrase:n,seed:r}):void 0;function u(){if(a)return a.getAddress();return Promise.resolve(void 0)}function d(f){if(!n)return;let T=G({accountIndex:f,chain:e,derivationPath:o});return Vn({chain:e,derivationPath:Ae(T),phrase:n,seed:r})}let h=d();function m(){if(!h)return;return h.publicExtendedKey}function g({accountIndex:f}={}){let T=f===void 0?h:d(f);if(!T)return;let y=G({accountIndex:f,chain:e,derivationPath:o});return{accountIndex:oe(y),path:Ae(y),xpub:T.publicExtendedKey}}function x({accountIndex:f,index:T,change:y=!1}){let v=f===void 0?h:d(f);if(!v)return;let b=ye({accountIndex:f,chain:e,change:y,derivationPath:o,index:T}),k=S(e),H=v.deriveChild(Number(y)).deriveChild(T);if(!H.publicKey)throw new w("toolbox_utxo_invalid_params",{error:"Could not derive public key"});let C=Ue({chain:e,network:k,publicKey:H.publicKey}),N=Q.encode(H.publicKey);return{accountIndex:oe(b),address:C,change:y,index:T,path:Ae(b),pubkey:N}}async function P(f){if(!He.includes(e))return{reason:`RBF is not supported on ${e}`,supported:!1};let T=await A(e).getTransactionDetails(f);return{canReplace:T.isRBF&&!T.confirmed,confirmed:T.confirmed,enabled:T.isRBF,fee:T.fee,sequences:T.sequences,supported:!0}}async function V({txid:f,newFeeRate:T,recipient:y,memo:v}){if(!He.includes(e))throw new w("toolbox_utxo_rbf_not_supported",{chain:e});let b=await A(e).getTransactionDetails(f);if(!b.isRBF)throw new w("toolbox_utxo_tx_not_replaceable",{txid:f});if(b.confirmed)throw new w("toolbox_utxo_tx_already_confirmed",{blockId:b.blockId,txid:f});let k=b.inputs.reduce((_,L)=>_+L.value,0),C=b.outputs.find((_)=>_.recipient===y)?.value||0;if(C===0)throw new w("toolbox_utxo_invalid_params",{error:"Could not determine send amount from original transaction"});let N=await Promise.all(b.inputs.map(async(_)=>{let L=await A(e).getRawTx(_.transaction_hash);return{address:_.recipient,hash:_.transaction_hash,index:_.index,txHex:L,value:_.value,witnessUtxo:void 0}})),E=v?F(v):null,ge=k-C-b.fee,xe=await u(),re=[];if(E)re.push({address:"",script:E,value:0});if(ge>Pe(e)&&xe)re.push({address:xe,value:ge});let Ce=ue({inputs:N.map((_)=>({..._,type:ve(_.address)})),outputs:[{address:y,value:C},...re]}),Z=Math.ceil(Ce*T);if(Z<=b.fee)throw new w("toolbox_utxo_rbf_fee_too_low",{newFee:Z,originalFee:b.fee});let Te=Z-b.fee,q=C-Te;if(q<=0)throw new w("toolbox_utxo_rbf_insufficient_change");let Se=new Ye({allowUnknownOutputs:!!E,version:1}),se=[{address:y,value:q},...re];return ee({chain:e,compiledMemo:E,inputs:N,outputs:se,sender:xe||y,tx:Se}),{feeDelta:Te,newFee:Z,originalFee:b.fee,tx:Se}}async function B({txid:f,newFeeRate:T,recipient:y,memo:v}){let{tx:b,originalFee:k,newFee:H}=await V({memo:v,newFeeRate:T,recipient:y,txid:f}),C=await Ee(b);C.finalize();let N=await A(e).broadcastTx(Q.encode(C.extract()));return{newFee:H,originalFee:k,txid:N}}function W({accountIndex:f,index:T,change:y=!1}){R("index",T);let v=f===void 0?h:d(f);if(!v)return;return v.deriveChild(Number(y)).deriveChild(T).privateKey||void 0}function me({tx:f,inputDerivations:T}){if(!h)throw new w("toolbox_utxo_no_signer");let y=e===U.BitcoinCash?[Qe.ALL]:[At.ALL];for(let v=0;v<T.length;v++){let b=T[v];if(!b)continue;let{derivationIndex:k,isChange:H}=b,C=W({change:H,index:k});if(!C)throw new w("toolbox_utxo_invalid_params",{error:`Could not derive private key for input ${v} at index ${k}`});f.signIdx(C,v,y)}return f}async function Gt({utxos:f,recipient:T,assetValue:y,memo:v,feeRate:b,feeOptionKey:k,changeAddress:H,sweep:C}){if(C)throw new w("toolbox_utxo_invalid_params",{error:"Sweep is not supported for transfers from multiple addresses"});if(!h)throw new w("toolbox_utxo_no_signer");let N=b||(await he(e))[k||D.Fast],E=v?F(v):null,ge=[{address:T,value:y.getBaseValue("number")}];if(E)ge.push({address:"",script:E,value:0});let xe=f.map(({address:se,hash:_,index:L,value:Jt,txHex:Qt,witnessUtxo:Me})=>({address:se,hash:_,index:L,txHex:Qt,value:Jt,witnessUtxo:Me?{script:Me.script,value:Me.value}:void 0})),re=f[0]?.address,Ce=H||await u()||re||T,{inputs:Z,outputs:Te}=K({chain:e,changeAddress:Ce,feeRate:N,inputs:xe,outputs:ge});if(!(Z&&Te))throw new w("toolbox_utxo_insufficient_balance",{assetValue:y,sender:"multiple addresses"});let q=new Ye({allowUnknownOutputs:!!E,version:1});ee({chain:e,compiledMemo:E,inputs:Z,outputs:Te,sender:Ce,tx:q});let Se=Z.map((se)=>{let _=f.find((L)=>L.hash===se.hash&&L.index===se.index);return _?{derivationIndex:_.derivationIndex,isChange:_.isChange}:{derivationIndex:0,isChange:!1}});return me({inputDerivations:Se,tx:q}),q.finalize(),A(e).broadcastTx(Q.encode(q.extract()))}function jt({address:f,gapLimit:T=20}){if(!h)return;for(let y=0;y<T;y++){let v=x({change:!1,index:y}),b=x({change:!0,index:y}),k=v?.address===f?!1:b?.address===f;if(v?.address===f||b?.address===f)return{change:k,index:y}}return}function Ee(f){if(!a)throw new w("toolbox_utxo_no_signer");return a.signTransaction(f)}async function Yt(f){let T=await Ee(f);return T.finalize(),await A(e).broadcastTx(Q.encode(T.extract()))}return{accumulative:K,broadcastTx:(f)=>A(e).broadcastTx(f),bumpFee:B,calculateTxSize:ue,createKeysForPath:(f)=>le({...f,chain:e}),createReplacementTransaction:V,createTransaction:Bt,deriveAddressAtIndex:x,derivePrivateKeyAtIndex:W,estimateMaxSendableAmount:Gn(e),estimateTransactionFee:jn(e),getAddress:u,getAddressFromKeys:Ft(e),getAddressType:(f)=>et({address:f,chain:e}),getBalance:vt(e),getExtendedPublicKey:m,getExtendedPublicKeyInfo:g,getFeeRates:()=>he(e),getInputsOutputsFee:kt,getNetworkForChain:()=>S(e),getPrivateKeyFromMnemonic:(f)=>$n(le({...f,chain:e}).privateKey,e),isRBFEnabled:P,keys:l,resolveDerivationIndex:jt,signAndBroadcastTransaction:Yt,signTransaction:Ee,signTransactionWithMultipleKeys:me,transfer:Jn(e,a),transferFromMultipleAddresses:Gt,validateAddress:Xt(e)}}var I=Qn.BitcoinCash;function We(e){return de(Xe(e))}function or(e){let t=S(I);function n(r){return r.sign(e.privateKey,[rr.ALL]),r}function s(){let r=Rt(e.publicKey,t);if(!r.hash)throw new M("toolbox_utxo_invalid_address",{error:"Could not derive BCH address hash"});let o=Ht({hash:r.hash,prefix:Dt.MAINNET,type:It.P2PKH});return Promise.resolve(o.replace(/^bitcoincash:/,""))}return{getAddress:s,signTransaction:n}}function Et(e){let t="phrase"in e?e.phrase:void 0,n="index"in e?e.index||0:0,s="derivationPath"in e?e.derivationPath:void 0,r=nr({chain:I,derivationPath:s,index:n}),o=er(r),p=t?le({chain:I,derivationPath:o,phrase:t}):void 0,i=p?or(p):("signer"in e)?e.signer:void 0;function c(){return Promise.resolve(i?.getAddress())}let{getBalance:a,getFeeRates:l,broadcastTx:u,...d}=te(t?{chain:I,derivationPath:r,phrase:t}:{chain:I});function h(x,P=!0){return a(de(Xe(x)))}function m(x){if(!i)throw new M("toolbox_utxo_no_signer");return i.signTransaction(x)}async function g(x){let P=await m(x);return P.finalize(),await u(Kt.encode(P.extract()))}return{...d,broadcastTx:u,buildTx:ir,createTransaction:Mt,getAddress:c,getAddressFromKeys:cr,getBalance:h,getFeeRates:l,signAndBroadcastTransaction:g,signTransaction:m,stripPrefix:de,stripToCashAddress:We,transfer:ar({broadcastTx:u,getFeeRates:l,signer:i}),validateAddress:_e}}async function Mt({assetValue:e,recipient:t,memo:n,feeRate:s,sender:r,sweep:o}){if(!_e(t))throw new M("toolbox_utxo_invalid_address",{address:t});let p=Math.ceil(e.getBaseValue("number")+s*7500),i=await A(I).getUtxos({address:We(r),fetchTxHex:!0,targetValue:o?void 0:p}),c=n?F(n):null,a=[],l=z(t);if(a.push({address:l,value:o?0:e.getBaseValue("number")}),c)a.push({script:c,value:0});let{inputs:u,outputs:d}=K({chain:I,feeRate:s,inputs:i,outputs:a,sweep:o});if(!(u&&d))throw new M("toolbox_utxo_insufficient_balance",{assetValue:e,sender:r});let h=new Wt({allowUnknownOutputs:!!c,version:1}),m=z(r),{inputs:g,tx:x}=ee({chain:I,compiledMemo:c,inputs:u,outputs:d.map((P)=>("address"in P)&&P.address?{...P,address:z(P.address)}:P),sender:m,tx:h});return{inputs:g,tx:x,utxos:u}}function ar({broadcastTx:e,getFeeRates:t,signer:n}){return async function({recipient:r,assetValue:o,feeOptionKey:p=tr.Fast,sweep:i,...c}){let a=await n?.getAddress();if(!(n&&a))throw new M("toolbox_utxo_no_signer");if(!r)throw new M("toolbox_utxo_invalid_params",{error:"Recipient address must be provided"});let l=c.feeRate||(await t())[p],{tx:u}=await Mt({...c,assetValue:o,feeRate:l,recipient:r,sender:a,sweep:i}),d=await n.signTransaction(u);return d.finalize(),e(Kt.encode(d.extract()))}}async function ir({assetValue:e,recipient:t,memo:n,feeRate:s,sender:r}){let o=Xe(t);if(!_e(o))throw new M("toolbox_utxo_invalid_address",{address:o});let p=Math.ceil(e.getBaseValue("number")+s*7500),i=await A(I).getUtxos({address:We(r),fetchTxHex:!0,targetValue:p}),c=Number(s.toFixed(0)),a=n?F(n):null,l=[];if(l.push({address:z(t),value:e.getBaseValue("number")}),a)l.push({script:a,value:0});let{inputs:u,outputs:d}=K({chain:I,feeRate:c,inputs:i,outputs:l});if(!(u&&d))throw new M("toolbox_utxo_insufficient_balance",{assetValue:e,sender:r});let h=new Wt({allowUnknownOutputs:!!a,version:1}),{inputs:m,tx:g}=ee({chain:I,compiledMemo:a,inputs:u,outputs:d,sender:z(r),tx:h});return{inputs:m,tx:g,utxos:i}}function cr(e){let t=sr.bitcoinCash,n=Rt(e.publicKey,t);if(!n.hash)throw new M("toolbox_utxo_invalid_address",{error:"Could not derive BCH address hash"});return Ht({hash:n.hash,prefix:Dt.MAINNET,type:It.P2PKH}).replace(/^bitcoincash:/,"")}import{createBase58check as ur,hex as dr}from"@scure/base";import{HDKey as zt}from"@scure/bip32";import{mnemonicToSeedSync as $t}from"@scure/bip39";import{Chain as Oe,derivationPathToString as pr,FeeOption as lr,resolveDerivationPath as hr,SKConfig as rt,SwapKitError as ne}from"@swapkit/helpers";import{Address as fr,createZcashTransaction as mr,getZcashConsensusBranchId as gr,isTransparentZcashAddress as Nt,OutScript as xr,PCZT as Tr,utils as Vt,WIF as yr,ZCASH_NETWORK as br,ZCASH_TEST_NETWORK as wr,ZcashConsensusBranchId as Zt,ZcashPSBT as vr,ZcashSigHash as tt,ZcashVersionGroupId as Pr}from"@swapkit/utxo-signer";import{match as _r,P as nt}from"ts-pattern";function st(){let{isStagenet:e}=rt.get("envs");return e?wr:br}var Ar=ur(Vt.sha256);function Ur(e){return Ar.encode(e)}function Or({phrase:e,derivationPath:t}){let n=$t(e),r=zt.fromMasterSeed(n).derive(t);if(!r.privateKey||!r.publicKey)throw new ne("toolbox_utxo_invalid_params");let{privateKey:o,publicKey:p}=r,i=Vt.hash160(p),{isStagenet:c}=rt.get("envs"),a=c?new Uint8Array([29,37]):new Uint8Array([28,184]),l=new Uint8Array(a.length+i.length);l.set(a,0),l.set(i,a.length);let u=Ur(l);return{getAddress:()=>Promise.resolve(u),signTransaction:(d)=>{if(d instanceof vr){let h=d.toPCZT();return h.signAllInputs(o,p,tt.ALL),h.finalizeAllInputs(),Promise.resolve(h.extract())}if(d instanceof Tr)return d.signAllInputs(o,p,tt.ALL),d.finalizeAllInputs(),Promise.resolve(d.extract());return d.signAllInputs(o,p,tt.ALL),Promise.resolve(d)}}}function Cr({inputs:e,outputs:t,tx:n,sender:s,compiledMemo:r}){let o=st();for(let p of e){let i=fr(o).decode(s),c=xr.encode(i);n.addInput({index:p.index,script:c,sequence:4294967295,txid:dr.decode(p.hash),value:BigInt(p.value)})}for(let p of t){let i="address"in p&&p.address?p.address:s,c=p.script;if(c&&!r)continue;if(c&&r)n.addOutput({amount:0n,script:r});else n.addOutputAddress(i,BigInt(p.value),o)}return{inputs:e,tx:n}}async function Sr(){let{isStagenet:e}=rt.get("envs");if(e)return Zt.IRONWOOD;try{let t=await A(Oe.Zcash).getBlockHeight();return gr(t+1)}catch{return Zt.IRONWOOD}}async function Lt(e){let{assetValue:t,recipient:n,memo:s,feeRate:r,sender:o,fetchTxHex:p,sweep:i}=e,c=st();if(!Nt(o,c))throw new ne("toolbox_utxo_invalid_address",{address:o});if(!Nt(n,c))throw new ne("toolbox_utxo_invalid_address",{address:n,error:"Zcash transaction creation currently supports transparent addresses only"});let a=s?F(s):null,l=await A(Oe.Zcash).getUtxos({address:o,fetchTxHex:p!==!1}),u=[{address:n,value:i?0:Number(t.getBaseValue("string"))},...a?[{script:a,value:0}]:[]],{inputs:d,outputs:h}=K({chain:Oe.Zcash,changeAddress:o,feeRate:r,inputs:l,outputs:u,sweep:i});if(!(d&&h))throw new ne("toolbox_utxo_insufficient_balance",{assetValue:t,sender:o});let m=mr({consensusBranchId:await Sr(),expiryHeight:0,lockTime:0,version:4,versionGroupId:Pr.SAPLING}),{tx:g,inputs:x}=Cr({compiledMemo:a,inputs:d,outputs:h,sender:o,tx:m});return{inputs:x,outputs:h,tx:g}}function qt(e){let t=_r(e).with({signer:nt.not(nt.nullish)},({signer:c})=>c).with({phrase:nt.string},({phrase:c,derivationPath:a,index:l=0})=>{let u=hr({chain:Oe.Zcash,derivationPath:a,index:l}),d=pr(u);return Or({derivationPath:d,phrase:c})}).otherwise(()=>{return}),n=te({chain:Oe.Zcash,signer:t});async function s(c){if(!t)throw new ne("toolbox_utxo_no_signer");return await t.signTransaction(c)}async function r(c){let a=await s(c);return n.broadcastTx(a.toHex())}async function o({recipient:c,assetValue:a,feeOptionKey:l=lr.Fast,sweep:u,...d}){let h=await t?.getAddress();if(!(t&&h))throw new ne("toolbox_utxo_no_signer");let m=d.feeRate||(await n.getFeeRates())[l],{tx:g}=await Lt({...d,assetValue:a,feeRate:m,recipient:c,sender:h,sweep:u}),P=(await t.signTransaction(g)).toHex();return n.broadcastTx(P)}function p({phrase:c,derivationPath:a="m/44'/133'/0'/0/0"}){let l=$t(c),d=zt.fromMasterSeed(l).derive(a);if(!d.privateKey||!d.publicKey)throw new ne("toolbox_utxo_invalid_params");return{privateKey:d.privateKey,publicKey:d.publicKey}}function i({phrase:c,derivationPath:a="m/44'/133'/0'/0/0"}){let l=p({derivationPath:a,phrase:c}),u=st();return yr(u).encode(l.privateKey)}return{...n,createKeysForPath:p,createTransaction:Lt,getPrivateKeyFromMnemonic:i,signAndBroadcastTransaction:r,signTransaction:s,transfer:o,validateAddress:Ge}}import{hex as Br}from"@scure/base";import{HDKey as kr}from"@scure/bip32";import{derivationPathToString as Xr}from"@swapkit/helpers";function Fr({xpub:e,chain:t,count:n,startIndex:s=0,accountIndex:r}){if(R("count",n),n<1)throw RangeError("count must be at least 1");R("startIndex",s);let o=S(t),p=kr.fromExtendedKey(e,o.bip32),i=G({accountIndex:r,chain:t}),c=oe(i),a=[];for(let l of[!1,!0]){let u=p.deriveChild(Number(l));for(let d=0;d<n;d++){let h=s+d,m=u.deriveChild(h);if(!m.publicKey)continue;let g=ye({accountIndex:r,chain:t,change:l,index:h});a.push({accountIndex:c,address:Ue({chain:t,network:o,publicKey:m.publicKey}),change:l,index:h,path:Xr(g),pubkey:Br.encode(m.publicKey)})}}return a}function Qs(e,t){switch(e){case fe.BitcoinCash:return Et(t||{});case fe.Zcash:return qt(t);case fe.Bitcoin:case fe.Dogecoin:case fe.Litecoin:case fe.Dash:return te({chain:e,...t});default:throw new Kr("toolbox_utxo_not_supported",{chain:e})}}export{xt as InputSizes,es as MIN_TX_FEE,Fn as OP_RETURN_OVERHEAD,Ke as OutputSizes,Xn as SEGWIT_MARKER_FLAG_WEIGHT,Le as TX_OVERHEAD,Tt as UTXOScriptType,ft as UtxoNetwork,K as accumulative,ee as addInputsAndOutputs,Ft as addressFromKeysGetter,R as assertDerivationIndex,ue as calculateTxSize,F as compileMemo,Et as createBCHToolbox,Er as createCustomUtxoApi,tn as createHDWalletHelpers,te as createUTXOToolbox,qt as createZcashToolbox,Fr as deriveAddressesFromXpub,jr as detectAddressNetwork,Ie as getBchAddressType,Pe as getDustThreshold,we as getInputScriptType,Y as getInputSize,S as getNetworkForChain,De as getOutputSize,ve as getScriptTypeForAddress,oe as getUTXOAccountIndexFromPath,G as getUTXOAccountPath,ye as getUTXOAddressPath,Xt as getUTXOAddressValidator,et as getUtxoAddressType,A as getUtxoApi,Mr as getUtxoNetwork,Qs as getUtxoToolbox,$e as getWitnessOverhead,qe as getZcashAddressType,ze as isSegwitScriptType,Gr as isValidAddress,Re as nonSegwitChains,de as stripPrefix,We as stripToCashAddress,Xe as toCashAddress,z as toLegacyAddress,Fe as tryDecodeAddress,_e as validateBchAddress,Ct as validateUtxoAddress,Ge as validateZcashAddress};
|
|
@@ -28,9 +28,9 @@ export declare function BaseEVMToolbox<P extends Provider | BrowserProvider, S e
|
|
|
28
28
|
}): {
|
|
29
29
|
approve: ({ assetAddress, spenderAddress, feeOptionKey, amount, gasLimitFallback, from: fromParam, nonce, }: ApproveParams) => Promise<string>;
|
|
30
30
|
approvedAmount: ({ assetAddress, spenderAddress, from }: IsApprovedParams) => Promise<bigint>;
|
|
31
|
-
broadcastTransaction: (
|
|
31
|
+
broadcastTransaction: (signedTx: string) => Promise<import("ethers").TransactionResponse>;
|
|
32
32
|
call: <T>({ callProvider, contractAddress, abi, funcName, funcParams, txOverrides, feeOption, }: CallParams) => Promise<T>;
|
|
33
|
-
createApprovalTx: ({ assetAddress, spenderAddress, amount, from: fromParam }: ApproveParams) => Promise<{
|
|
33
|
+
createApprovalTx: ({ assetAddress, spenderAddress, amount, from: fromParam, nonce, }: ApproveParams) => Promise<{
|
|
34
34
|
value: string;
|
|
35
35
|
to: string;
|
|
36
36
|
data: string;
|