@swapkit/toolboxes 4.15.7 → 4.15.9

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.
@@ -1 +1 @@
1
- var J0=Object.create;var{getPrototypeOf:Z0,defineProperty:CX,getOwnPropertyNames:N2,getOwnPropertyDescriptor:j0}=Object,M2=Object.prototype.hasOwnProperty;function D2(X){return this[X]}var Q0,G0,t0=(X,$,J)=>{var Z=X!=null&&typeof X==="object";if(Z){var j=$?Q0??=new WeakMap:G0??=new WeakMap,G=j.get(X);if(G)return G}J=X!=null?J0(Z0(X)):{};let q=$||!X||!X.__esModule?CX(J,"default",{value:X,enumerable:!0}):J;for(let Q of N2(X))if(!M2.call(q,Q))CX(q,Q,{get:D2.bind(X,Q),enumerable:!0});if(Z)j.set(X,q);return q},Y0=(X)=>{var $=(_2??=new WeakMap).get(X),J;if($)return $;if($=CX({},"__esModule",{value:!0}),X&&typeof X==="object"||typeof X==="function"){for(var Z of N2(X))if(!M2.call($,Z))CX($,Z,{get:D2.bind(X,Z),enumerable:!(J=j0(X,Z))||J.enumerable})}return _2.set(X,$),$},_2;var q0=(X)=>X;function L0(X,$){this[X]=q0.bind(null,$)}var z0=(X,$)=>{for(var J in $)CX(X,J,{get:$[J],enumerable:!0,configurable:!0,set:L0.bind($,J)})};var y=(X,$)=>()=>(X&&($=X(X=0)),$);function K(X,$){if(!Number.isInteger($)||$<0)throw RangeError(`${X} must be a non-negative integer, got: ${$}`)}function i({accountIndex:X,chain:$,derivationPath:J}){if(X!==void 0)K("accountIndex",X);let Z=[...J?.slice(0,3)??C2.NetworkDerivationPath[$].slice(0,3)];if(X!==void 0)Z[2]=X;return Z}function YX({accountIndex:X,change:$=!1,chain:J,derivationPath:Z,index:j}){return K("index",j),[...i({accountIndex:X,chain:J,derivationPath:Z}),Number($),j]}function JX(X){return X[2]??0}function H2({deriveAddress:X,getBalance:$,getUtxos:J}){async function Z(Q){let{accountIndex:Y,count:z,startIndex:L=0,change:U=!1}=Q;if(K("count",z),z<1)throw RangeError("count must be at least 1");K("startIndex",L);let B=[];for(let _=0;_<z;_++){let M=await X({accountIndex:Y,change:U,index:L+_});if(M)B.push(M)}return B}async function j(Q){let{gapLimit:Y=20,change:z=!1}=Q??{},L=[],U=0,B=0;while(U<Y){let _=await X({change:z,index:B});if(!_)break;if((await $(_.address)).some((f)=>f.getValue("number")>0))L.push(_),U=0;else U++;B++}return L}async function G(Q=20){let[Y,z]=await Promise.all([j({change:!1,gapLimit:Q}),j({change:!0,gapLimit:Q})]),L=[...Y,...z],U=await Promise.all(L.map(async(_)=>{let O=(await $(_.address)).reduce((f,$X)=>f+$X.getValue("number"),0);return{..._,balance:O}})),B=U.reduce((_,M)=>_+M.balance,0);return{addresses:U,total:B}}async function q(Q=20){let[Y,z]=await Promise.all([j({change:!1,gapLimit:Q}),j({change:!0,gapLimit:Q})]),L=[...Y,...z];return(await Promise.all(L.map(async(B)=>{return(await J(B.address)).map((M)=>({...M,address:B.address,derivationIndex:B.index,isChange:B.change}))}))).flat()}return{deriveAddresses:Z,getAggregatedBalance:G,getAggregatedUtxos:q,scanForAddresses:j}}var C2;var HX=y(()=>{C2=require("@swapkit/helpers")});function T2(){function X(){let $=Date.now(),J=iX||$;return iX=J,$>iX?$:J+1}return U0+X().toString(36)}function b2(X){return async function(J,Z=!0){let j=await O2.SwapKitApi.getChainBalance({address:J,chain:X,scamFilter:Z}),{baseDecimal:G}=OX.getChainConfig(X),q=j.map(({identifier:Y,value:z,decimal:L})=>{return new OX.AssetValue({decimal:L||G,identifier:Y,value:z})});if(!q.some((Y)=>Y.isGasAsset))return[OX.AssetValue.from({chain:X}),...q];return q}}var OX,O2,U0,iX=0;var sX=y(()=>{OX=require("@swapkit/helpers"),O2=require("@swapkit/helpers/api"),U0=typeof process<"u"&&process.pid?process.pid.toString(36):""});async function W0({chain:X,txHash:$}){let J=`${TX(X)}/push/transaction`,Z=JSON.stringify({data:$});try{let j=await D.RequestClient.post(J,{body:Z,headers:{"Content-Type":"application/json"}});if(j.context.code!==200)throw new D.SwapKitError("toolbox_utxo_broadcast_failed",{error:j.context.error||"Transaction broadcast failed"});return j.data?.transaction_hash||$}catch(j){let G=await D.getRPCUrl(X);if(G){let q=JSON.stringify({id:T2(),jsonrpc:"2.0",method:"sendrawtransaction",params:[$]}),Q=await D.RequestClient.post(G,{body:q,headers:{"Content-Type":"application/json"}});if(Q.error)throw new D.SwapKitError("toolbox_utxo_broadcast_failed",{error:Q.error?.message});if(Q.result.includes('"code":-26'))throw new D.SwapKitError("toolbox_utxo_invalid_transaction",{error:"Transaction amount was too low"});return Q.result}throw j}}function TX(X){return`https://api.blockchair.com/${B0(X)}`}function V2(X){switch(X){case D.Chain.Bitcoin:return 5;case D.Chain.Dogecoin:return 1e4;case D.Chain.Litecoin:return 1;case D.Chain.Zcash:return 1;default:return 2}}function B0(X){switch(X){case D.Chain.BitcoinCash:return"bitcoin-cash";case D.Chain.Litecoin:return"litecoin";case D.Chain.Dash:return"dash";case D.Chain.Dogecoin:return"dogecoin";case D.Chain.Zcash:return"zcash";case D.Chain.Polkadot:return"polkadot";default:return"bitcoin"}}async function _0(X){try{let{feePerKb:$}=await D.RequestClient.get(`https://app.bitgo.com/api/v2/${X.toLowerCase()}/tx/fee`),J=$/1000;return Math.max(J,V2(X))}catch{return V2(X)}}async function SX(X,$){let J=await D.RequestClient.get(`${X}${$?`${X.includes("?")?"&":"?"}key=${$}`:""}`);if(!J||J.context.code!==200)throw new D.SwapKitError("toolbox_utxo_api_error",{error:`Failed to query ${X}`});return J.data}async function I2({address:X,chain:$,apiKey:J}){if(!X)throw new D.SwapKitError("toolbox_utxo_invalid_params",{error:"Address is required"});try{return(await SX(`${TX($)}/dashboards/address/${X}?transaction_details=true`,J))[X]}catch{return{address:{balance:0,transaction_count:0},utxo:[]}}}async function N0({address:X,chain:$,apiKey:J}){return(await I2({address:X,apiKey:J,chain:$}))?.address.balance||0}async function f2({chain:X,apiKey:$,txHash:J}){if(!J)throw new D.SwapKitError("toolbox_utxo_invalid_params",{error:"TxHash is required"});try{return(await SX(`${TX(X)}/raw/transaction/${J}`,$))?.[J]?.raw_transaction||""}catch(Z){let j=Z instanceof Error?Z.message:String(Z);return console.error(`Failed to fetch raw transaction: ${j}`),""}}async function D0({chain:X,apiKey:$,txHash:J}){if(!J)throw new D.SwapKitError("toolbox_utxo_invalid_params",{error:"TxHash is required"});let j=(await SX(`${TX(X)}/dashboards/transaction/${J}`,$))?.[J];if(!j)throw new D.SwapKitError("toolbox_utxo_tx_not_found",{txHash:J});let{transaction:G,inputs:q,outputs:Q}=j,Y=q.map((L)=>L.spending_sequence),z=G.is_rbf===!0||Y.some((L)=>L<M0);return{blockId:G.block_id,confirmed:G.block_id!==-1,fee:G.fee,inputs:q,isRBF:z,outputs:Q,sequences:Y,size:G.size,txid:G.hash,weight:G.weight}}async function C0({chain:X,address:$,apiKey:J,offset:Z=0,limit:j=30}){return(await SX(`${TX(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=${j}&offset=${Z}`,J)).map(({is_spent:Y,script_hex:z,block_id:L,transaction_hash:U,index:B,value:_,spending_signature_hex:M})=>({hash:U,index:B,is_confirmed:L!==-1,is_spent:Y,script_hex:z,txHex:M,value:_}))}function H0(X){return X.reduce(($,J)=>$+J.value,0)}function k2(X,$){let J=[...X].sort((Z,j)=>j.value-Z.value);if($){let Z=[],j=0;for(let G of J)if(Z.push(G),j+=G.value,j>=$)break;return Z}return J}async function F2({chain:X,address:$,apiKey:J,targetValue:Z,accumulativeValue:j=0,offset:G=0,limit:q=30}){if(!$)throw new D.SwapKitError("toolbox_utxo_invalid_params",{error:"Address is required"});try{let Q=await C0({address:$,apiKey:J,chain:X,limit:q,offset:G,targetValue:Z}),z=Q.length<q,L=Q.filter(({is_spent:f})=>!f),U=H0(L),B=j+U,_=Z&&B>=Z;if(z||_)return k2(L,Z);let M=await F2({accumulativeValue:B,address:$,apiKey:J,chain:X,limit:q,offset:G+q,targetValue:Z}),O=[...L,...M];return k2(O,Z)}catch(Q){let Y=Q instanceof Error?Q.message:String(Q);return console.error(`Failed to fetch unspent UTXOs: ${Y}`),[]}}async function O0({address:X,chain:$,apiKey:J,fetchTxHex:Z=!0,targetValue:j}){let G=await F2({address:X,apiKey:J,chain:$,targetValue:j}),q=[];for(let{hash:Q,index:Y,script_hex:z,value:L}of G){let U;if(Z)U=await f2({apiKey:J,chain:$,txHash:Q});q.push({address:X,hash:Q,index:Y,txHex:U,value:L,witnessUtxo:{script:Buffer.from(z,"hex"),value:L}})}return q}function P(X){let $=D.SKConfig.get("apiKeys").blockchair||"";return D.warnOnce({condition:!$,id:"no_blockchair_api_key_warning",warning:"No Blockchair API key found. Functionality will be limited."}),{broadcastTx:(J)=>W0({chain:X,txHash:J}),getAddressData:(J)=>I2({address:J,apiKey:$,chain:X}),getBalance:(J)=>N0({address:J,apiKey:$,chain:X}),getRawTx:(J)=>f2({apiKey:$,chain:X,txHash:J}),getSuggestedTxFee:()=>_0(X),getTransactionDetails:(J)=>D0({apiKey:$,chain:X,txHash:J}),getUtxos:(J)=>O0({...J,apiKey:$,chain:X})}}function T0(X){return X}function b0(){return function($){switch($){case D.Chain.Bitcoin:return ZX.NETWORKS.bitcoin;case D.Chain.BitcoinCash:return ZX.NETWORKS.bitcoinCash;case D.Chain.Dash:return ZX.NETWORKS.dash;case D.Chain.Litecoin:return ZX.NETWORKS.litecoin;case D.Chain.Dogecoin:return ZX.NETWORKS.dogecoin;case D.Chain.Zcash:return ZX.NETWORKS.zcash;default:throw new D.SwapKitError("toolbox_utxo_not_supported",{chain:$})}}}var D,ZX,M0=4294967294;var E2=y(()=>{sX();D=require("@swapkit/helpers"),ZX=require("@swapkit/utxo-signer")});function I0(X,$,J){return p.encodeCashAddr({hash:J,prefix:X,type:V0[$]})}function f0(X){let $=p.decodeCashAddr(X),J=k0[$.type];if(!J)throw Error(`Unknown CashAddr type: ${$.type}`);return{hash:$.hash,prefix:$.prefix,type:J}}var p,V0,k0,aX;var P2=y(()=>{p=require("@swapkit/utxo-signer"),V0={P2PKH:p.CashAddrType.P2PKH,P2SH:p.CashAddrType.P2SH},k0={[p.CashAddrType.P2PKH]:"P2PKH",[p.CashAddrType.P2SH]:"P2SH"};aX={decode:f0,encode:I0}});function X2(X){try{return KX(X),!0}catch{return!1}}function $2(X){return KX(X)?.network}function u(X){let $=KX(X);if($?.format==="legacy")return X;return P0($)}function bX(X){let $=KX(X);return R0($)}function KX(X){try{let $=F0(X);if($)return $}catch{}try{let $=E0(X);if($)return $}catch{}throw new tX.SwapKitError("toolbox_utxo_invalid_address",{address:X})}function F0(X){try{let $=v2.decode(X);if($.length!==21)throw new tX.SwapKitError("toolbox_utxo_invalid_address",{address:X});let J=$[0],Z=Array.prototype.slice.call($,1);switch(J){case jX.legacy.mainnet.p2pkh:return{format:"legacy",hash:Z,network:"mainnet",type:"p2pkh"};case jX.legacy.mainnet.p2sh:return{format:"legacy",hash:Z,network:"mainnet",type:"p2sh"};case jX.legacy.testnet.p2pkh:return{format:"legacy",hash:Z,network:"testnet",type:"p2pkh"};case jX.legacy.testnet.p2sh:return{format:"legacy",hash:Z,network:"testnet",type:"p2sh"};case jX.bitpay.mainnet.p2pkh:return{format:"bitpay",hash:Z,network:"mainnet",type:"p2pkh"};case jX.bitpay.mainnet.p2sh:return{format:"bitpay",hash:Z,network:"mainnet",type:"p2sh"};default:return}}catch{return}}function E0(X){if(X.indexOf(":")!==-1)try{return R2(X)}catch{}else{let $=["bitcoincash","bchtest","bchreg"];for(let J of $)try{return R2(`${J}:${X}`)}catch{}}return}function R2(X){try{let{hash:$,prefix:J,type:Z}=aX.decode(X);return{format:"cashaddr",hash:Array.prototype.slice.call($,0),network:J==="bitcoincash"?"mainnet":"testnet",type:Z==="P2PKH"?"p2pkh":"p2sh"}}catch{return}}function P0(X){let $=jX.legacy[X.network][X.type],J=Buffer.alloc(1+X.hash.length);return J[0]=$,J.set(X.hash,1),v2.encode(J)}function R0(X){let $=X.network==="mainnet"?"bitcoincash":"bchtest",J=X.type==="p2pkh"?"P2PKH":"P2SH",Z=new Uint8Array(X.hash);return aX.encode($,J,Z)}var y2,A2,tX,v2,eX,jX;var w2=y(()=>{P2();y2=require("@noble/hashes/sha2.js"),A2=require("@scure/base"),tX=require("@swapkit/helpers"),v2=A2.createBase58check(y2.sha256);((J)=>{J.Mainnet="mainnet";J.Testnet="testnet"})(eX||={});jX={["legacy"]:{["mainnet"]:{["p2pkh"]:0,["p2sh"]:5},["testnet"]:{["p2pkh"]:111,["p2sh"]:196}},["bitpay"]:{["mainnet"]:{["p2pkh"]:28,["p2sh"]:40},["testnet"]:{["p2pkh"]:111,["p2sh"]:196}}}});function v(X){let $=new Uint8Array(Buffer.from(X,"utf8"));return K2.Script.encode(["RETURN",$])}var S2,K2,y0=1000,mX=10,lX=2,g2=10,A0=41,v0=107,xX,gX,VX,qX=(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 S2.SwapKitError("toolbox_utxo_invalid_address",{address:X})},QX=({inputs:X,outputs:$,feeRate:J})=>{let Z=X[0]&&"address"in X[0]&&X[0].address?qX(X[0].address):"P2PKH",G=(J?X.filter((z)=>z.value>=gX["type"in z&&z.type?z.type:"P2PKH"]*Math.ceil(J)):X).reduce((z,L)=>z+s(L),0),q=$?.reduce((z,L)=>z+kX(L),0)||VX[Z],Q=mX+G+q;return Z==="P2WPKH"?Math.ceil(Q+lX/4):Q},s=(X)=>{if("type"in X&&X.type)return gX[X.type];if("address"in X&&X.address)return gX[qX(X.address)];return A0+v0},kX=(X,$)=>{if(X?.script)return g2+X.script.length+(X.script.length>=74?2:1);if($)return VX[$];if("address"in X&&X.address)return VX[qX(X.address)];return VX.P2PKH};var J2=y(()=>{S2=require("@swapkit/helpers"),K2=require("@swapkit/utxo-signer");((J)=>{J.P2PKH="P2PKH";J.P2WPKH="P2WPKH"})(xX||={});gX={["P2PKH"]:148,["P2WPKH"]:68},VX={["P2PKH"]:34,["P2WPKH"]:31}});function IX(X){switch(X){case l.Chain.Bitcoin:case l.Chain.BitcoinCash:return 550;case l.Chain.Dash:case l.Chain.Litecoin:return 5500;case l.Chain.Dogecoin:return 1e5;case l.Chain.Zcash:return 546;default:throw new l.SwapKitError("toolbox_utxo_not_supported",{chain:X})}}function g({inputs:X,outputs:$,feeRate:J=1,chain:Z=l.Chain.Bitcoin,changeAddress:j=""}){let G=X[0]&&"address"in X[0]&&X[0].address?qX(X[0].address):"P2PKH",q=X.filter((M)=>s(M)*J<=M.value),Y=G==="P2WPKH"?Math.ceil(lX/4):0,z=mX+Y+$.reduce((M,O)=>M+kX(O),0),L=$.reduce((M,O)=>M+O.value,0),U=z*J,B=0,_=[];for(let M of q){let O=s(M),f=J*O;U+=f,B+=M.value,_.push(M);let $X=U+L;if(B<$X)continue;let dX=B-$X,NX=J*kX({address:j,value:0});if(dX>NX){let MX=NX+U,RX=B-(L+Math.ceil(MX));if(RX>Math.max(s({value:0})*J,IX(Z)))return{fee:Math.ceil(MX),inputs:_,outputs:$.concat({address:j,value:RX})}}return{fee:Math.ceil(U),inputs:_,outputs:$}}return{fee:Math.ceil(J*QX({inputs:X,outputs:$}))}}var l;var m2=y(()=>{J2();l=require("@swapkit/helpers")});var LX=y(()=>{E2();w2();m2();J2()});function GX(X){return X.replace(/(bchtest:|bitcoincash:)/,"")}function a(X){let $=GX(X);return X2($)&&$2($)==="mainnet"}function zX(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 J=hX.Address(hX.ZCASH_NETWORK).decode(X);return J.type==="pkh"||J.type==="sh"}catch{return!1}}var hX;var fX=y(()=>{LX();hX=require("@swapkit/utxo-signer")});function Q2({address:X,chain:$}){return j2.match($).with(W.Chain.BitcoinCash,()=>a(X)).with(W.Chain.Zcash,()=>zX(X)).otherwise(()=>{try{return C.Address(A($)).decode(X),!0}catch{return!1}})}function A(X){return j2.match(X).with(W.Chain.Bitcoin,()=>C.NETWORKS.bitcoin).with(W.Chain.BitcoinCash,()=>C.NETWORKS.bitcoinCash).with(W.Chain.Dash,()=>C.NETWORKS.dash).with(W.Chain.Dogecoin,()=>C.NETWORKS.dogecoin).with(W.Chain.Litecoin,()=>C.NETWORKS.litecoin).with(W.Chain.Zcash,()=>C.NETWORKS.zcash).exhaustive()}function w0({phrase:X,derivationPath:$,network:J,seed:Z}){let j=Z??uX.mnemonicToSeedSync(X),q=Z2.HDKey.fromMasterSeed(j,J.bip32).derive($);if(!q.privateKey)throw new W.SwapKitError("toolbox_utxo_invalid_params",{error:"Could not derive private key from phrase"});return q.privateKey}function l2(X){return x2.secp256k1.getPublicKey(X,!0)}function EX({publicKey:X,chain:$,network:J}){if($===W.Chain.BitcoinCash){let G=C.p2pkh(X,J);if(!G.hash)throw new W.SwapKitError("toolbox_utxo_invalid_address",{error:"Could not derive BCH address hash"});return C.encodeCashAddr({hash:G.hash,prefix:C.CashAddrPrefix.MAINNET,type:C.CashAddrType.P2PKH}).replace(/^bitcoincash:/,"")}let j=!FX.includes($)?C.p2wpkh(X,J):C.p2pkh(X,J);if(!j.address)throw new W.SwapKitError("toolbox_utxo_invalid_address",{error:"Could not derive address"});return j.address}function UX({phrase:X,derivationPath:$,chain:J,wif:Z,seed:j}){let G=A(J);if(Z){let z=C.WIF(G).decode(Z),L=l2(z);return{privateKey:z,publicKey:L}}if(!X)throw new W.SwapKitError("toolbox_utxo_invalid_params",{error:"Either phrase or wif must be provided"});let q=$||W.derivationPathToString(W.NetworkDerivationPath[J]),Q=w0({derivationPath:q,network:G,phrase:X,seed:j}),Y=l2(Q);return{privateKey:Q,publicKey:Y}}function S0(X,$){return C.WIF(A($)).encode(X)}function K0({phrase:X,derivationPath:$,chain:J,seed:Z}){let j=$.split("/");if(j.length<4)throw new W.SwapKitError("toolbox_utxo_invalid_params",{error:`Derivation path must have at least 4 levels (got ${j.length}): ${$}`});let G=A(J),q=Z??uX.mnemonicToSeedSync(X),Q=Z2.HDKey.fromMasterSeed(q,G.bip32),Y=j.slice(0,4).join("/");return Q.derive(Y)}function e({inputs:X,outputs:$,chain:J,tx:Z,sender:j,compiledMemo:G,enableRBF:q=!1}){let Q=A(J),Y=!FX.includes(J),z=q?C.RBF_SEQUENCE:void 0,L=new Set;for(let U of X){let B=`${U.hash}:${U.index}`;if(L.has(B))throw new W.SwapKitError("toolbox_utxo_invalid_params",{error:"Duplicate input detected"});L.add(B);let _=typeof U.hash==="string"?t.hex.decode(U.hash):U.hash;if(Y&&U.witnessUtxo)Z.addInput({index:U.index,sequence:z,txid:_,witnessUtxo:{amount:BigInt(U.witnessUtxo.value),script:U.witnessUtxo.script}});else if(U.txHex)Z.addInput({index:U.index,nonWitnessUtxo:t.hex.decode(U.txHex),sequence:z,txid:_,...J===W.Chain.BitcoinCash?{sighashType:C.BCHSigHash.ALL}:{}});else throw new W.SwapKitError("toolbox_utxo_invalid_params",{error:"Input requires either witnessUtxo or txHex for non-segwit chains"})}for(let U of $){let B="address"in U&&U.address?U.address:j;if(J===W.Chain.BitcoinCash)B=u(B);if(U.script){if(G)Z.addOutput({amount:0n,script:G})}else Z.addOutputAddress(B,BigInt(U.value),Q)}return{inputs:X,tx:Z}}async function WX(X){let $=await P(X).getSuggestedTxFee();return{[W.FeeOption.Average]:$,[W.FeeOption.Fast]:W.applyFeeMultiplier($,W.FeeOption.Fast),[W.FeeOption.Fastest]:W.applyFeeMultiplier($,W.FeeOption.Fastest)}}async function h2({assetValue:X,recipient:$,memo:J,sender:Z,fetchTxHex:j=!1}){let G=X.chain,q=(await WX(G))[W.FeeOption.Fastest],Q=j||FX.includes(G),Y=X.getBaseValue("number"),z=Math.ceil(Y+q*5000);return{inputs:await P(G).getUtxos({address:Z,fetchTxHex:Q,targetValue:z}),outputs:[{address:$,value:Y},...J?[{address:"",script:v(J),value:0}]:[]]}}async function p2({assetValue:X,recipient:$,memo:J,feeRate:Z,sender:j,fetchTxHex:G=!1,enableRBF:q=!1}){let Q=X.chain,Y=J?v(J):null,z=await h2({assetValue:X,fetchTxHex:G,memo:J,recipient:$,sender:j}),{inputs:L,outputs:U}=g({...z,chain:Q,feeRate:Z});if(!(L&&U))throw new W.SwapKitError("toolbox_utxo_insufficient_balance",{assetValue:X,sender:j});let B=new C.Transaction({allowLegacyWitnessUtxo:!0,allowUnknownOutputs:!!Y,version:1}),{inputs:_,tx:M}=e({chain:Q,compiledMemo:Y,enableRBF:q,inputs:L,outputs:U,sender:j,tx:B});return{inputs:_,tx:M,utxos:z.inputs}}async function u2({assetValue:X,feeOptionKey:$=W.FeeOption.Fast,feeRate:J,memo:Z,sender:j,recipient:G}){let q=X.chain,Q=await h2({assetValue:X,memo:Z,recipient:G,sender:j}),Y=J?Math.floor(J):(await WX(q))[$];return g({...Q,chain:q,feeRate:Y})}function g0(X){return async function({from:J,memo:Z,feeRate:j,feeOptionKey:G=W.FeeOption.Fast,recipients:q=1}){let Q=await P(X).getAddressData(J),Y=j?Math.ceil(j):(await WX(X))[G],z=Q?.utxo.map((O)=>({...O,hash:"",type:"P2PKH"})).filter((O)=>O.value>Math.max(IX(X),s(O)*Y));if(!z?.length)return W.AssetValue.from({chain:X});let L=BigInt(z.reduce((O,f)=>O+f.value,0)),U=W.AssetValue.from({chain:X,value:L}),B=typeof q==="number"?Array.from({length:q},()=>({address:J,value:0})):q;if(Z)B.push({address:J,script:v(Z),value:0});let _=QX({inputs:z,outputs:B}),M=W.AssetValue.from({chain:X,value:BigInt(_*Y)});return U.sub(M)}}function m0(X){return async function(J){let{fee:Z}=await u2(J);return W.AssetValue.from({chain:X,value:W.SwapKitNumber.fromBigInt(BigInt(Z),8).getValue("string")})}}function l0({chain:X,phrase:$,derivationPath:J,seed:Z}){let j=A(X),{privateKey:G,publicKey:q}=UX({chain:X,derivationPath:J,phrase:$,seed:Z}),Q=X===W.Chain.BitcoinCash?[C.BCHSigHash.ALL]:[C.SigHash.ALL];return{getAddress:()=>EX({chain:X,network:j,publicKey:q}),privateKey:G,publicKey:q,signTransaction:(Y)=>{return Y.sign(G,Q),Y}}}function x0(X,$){return async function({memo:Z,recipient:j,feeOptionKey:G,feeRate:q,assetValue:Q,enableRBF:Y=!1}){let z=$?.getAddress();if(!($&&z))throw new W.SwapKitError("toolbox_utxo_no_signer");if(!j)throw new W.SwapKitError("toolbox_utxo_invalid_params",{error:"Recipient address must be provided"});W.warnOnce({condition:Y&&!pX.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=Y&&pX.includes(X),U=q||(await WX(X))[G||W.FeeOption.Fast],{tx:B}=await p2({assetValue:Q,enableRBF:L,feeRate:U,memo:Z,recipient:j,sender:z});return $.signTransaction(B),B.finalize(),P(X).broadcastTx(t.hex.encode(B.extract()))}}function G2(X){return($)=>Q2({address:$,chain:X})}function Y2(X){let $=A(X);return function(Z){if(!Z)throw new W.SwapKitError("toolbox_utxo_invalid_params",{error:"Keys must be provided"});return EX({chain:X,network:$,publicKey:Z.publicKey})}}function XX({chain:X,...$}){let J="phrase"in $?$.phrase:void 0,Z="index"in $?$.index||0:0,j=J?uX.mnemonicToSeedSync(J):void 0,G="derivationPath"in $&&$.derivationPath?$.derivationPath:W.updateDerivationPath(W.NetworkDerivationPath[X],{index:Z}),q=W.derivationPathToString(G),Q=J?l0({chain:X,derivationPath:q,phrase:J,seed:j}):void 0,Y="signer"in $?$.signer:void 0,z=J?UX({chain:X,derivationPath:q,phrase:J,seed:j}):void 0;function L(){if(Q)return Promise.resolve(Q.getAddress());if(Y)return Y.getAddress();return Promise.resolve(void 0)}function U(N){if(!J)return;let H=i({accountIndex:N,chain:X,derivationPath:G});return K0({chain:X,derivationPath:W.derivationPathToString(H),phrase:J,seed:j})}let B=U();function _(){if(!B)return;return B.publicExtendedKey}function M({accountIndex:N}={}){let H=N===void 0?B:U(N);if(!H)return;let T=i({accountIndex:N,chain:X,derivationPath:G});return{accountIndex:JX(T),path:W.derivationPathToString(T),xpub:H.publicExtendedKey}}function O({accountIndex:N,index:H,change:T=!1}){let V=N===void 0?B:U(N);if(!V)return;let b=YX({accountIndex:N,chain:X,change:T,derivationPath:G,index:H}),w=A(X),m=V.deriveChild(Number(T)).deriveChild(H);if(!m.publicKey)throw new W.SwapKitError("toolbox_utxo_invalid_params",{error:"Could not derive public key"});let S=EX({chain:X,network:w,publicKey:m.publicKey}),c=t.hex.encode(m.publicKey);return{accountIndex:JX(b),address:S,change:T,index:H,path:W.derivationPathToString(b),pubkey:c}}async function f(N){if(!pX.includes(X))return{reason:`RBF is not supported on ${X}`,supported:!1};let H=await P(X).getTransactionDetails(N);return{canReplace:H.isRBF&&!H.confirmed,confirmed:H.confirmed,enabled:H.isRBF,fee:H.fee,sequences:H.sequences,supported:!0}}async function $X({txid:N,newFeeRate:H,recipient:T,memo:V}){if(!pX.includes(X))throw new W.SwapKitError("toolbox_utxo_rbf_not_supported",{chain:X});let b=await P(X).getTransactionDetails(N);if(!b.isRBF)throw new W.SwapKitError("toolbox_utxo_tx_not_replaceable",{txid:N});if(b.confirmed)throw new W.SwapKitError("toolbox_utxo_tx_already_confirmed",{blockId:b.blockId,txid:N});let w=b.inputs.reduce((R,n)=>R+n.value,0),S=b.outputs.find((R)=>R.recipient===T)?.value||0;if(S===0)throw new W.SwapKitError("toolbox_utxo_invalid_params",{error:"Could not determine send amount from original transaction"});let c=await Promise.all(b.inputs.map(async(R)=>{let n=await P(X).getRawTx(R.transaction_hash);return{hash:R.transaction_hash,index:R.index,txHex:n,value:R.value,witnessUtxo:void 0}})),yX=V?v(V):null,rX=QX({feeRate:H,inputs:c.map((R)=>({...R,type:"P2WPKH"})),outputs:[{address:T,value:S}]}),h=Math.ceil(rX*H);if(h<=b.fee)throw new W.SwapKitError("toolbox_utxo_rbf_fee_too_low",{newFee:h,originalFee:b.fee});let DX=h-b.fee,d=S-DX;if(d<=0)throw new W.SwapKitError("toolbox_utxo_rbf_insufficient_change");let AX=new C.Transaction({allowLegacyWitnessUtxo:!0,version:1}),vX=[{address:T,value:d},...V?[{address:"",script:v(V),value:0}]:[]],wX=w-d-h,r=await L();if(wX>IX(X)&&r)vX.push({address:r,value:wX});return e({chain:X,compiledMemo:yX,inputs:c,outputs:vX,sender:r||T,tx:AX}),{feeDelta:DX,newFee:h,originalFee:b.fee,tx:AX}}async function dX({txid:N,newFeeRate:H,recipient:T,memo:V}){if(!Q)throw new W.SwapKitError("toolbox_utxo_no_signer");let{tx:b,originalFee:w,newFee:m}=await $X({memo:V,newFeeRate:H,recipient:T,txid:N});Q.signTransaction(b),b.finalize();let S=await P(X).broadcastTx(t.hex.encode(b.extract()));return{newFee:m,originalFee:w,txid:S}}function NX({accountIndex:N,index:H,change:T=!1}){K("index",H);let V=N===void 0?B:U(N);if(!V)return;return V.deriveChild(Number(T)).deriveChild(H).privateKey||void 0}function MX({tx:N,inputDerivations:H}){if(!B)throw new W.SwapKitError("toolbox_utxo_no_signer");let T=X===W.Chain.BitcoinCash?[C.BCHSigHash.ALL]:[C.SigHash.ALL];for(let V=0;V<H.length;V++){let b=H[V];if(!b)continue;let{derivationIndex:w,isChange:m}=b,S=NX({change:m,index:w});if(!S)throw new W.SwapKitError("toolbox_utxo_invalid_params",{error:`Could not derive private key for input ${V} at index ${w}`});N.signIdx(S,V,T)}return N}async function RX({utxos:N,recipient:H,assetValue:T,memo:V,feeRate:b,feeOptionKey:w,changeAddress:m}){if(!B)throw new W.SwapKitError("toolbox_utxo_no_signer");let S=b||(await WX(X))[w||W.FeeOption.Fast],c=V?v(V):null,yX=[{address:H,value:T.getBaseValue("number")}];if(c)yX.push({address:"",script:c,value:0});let rX=N.map(({hash:r,index:R,value:n,txHex:$0,witnessUtxo:nX})=>({hash:r,index:R,txHex:$0,value:n,witnessUtxo:nX?{script:nX.script,value:nX.value}:void 0})),{inputs:h,outputs:DX}=g({chain:X,feeRate:S,inputs:rX,outputs:yX});if(!(h&&DX))throw new W.SwapKitError("toolbox_utxo_insufficient_balance",{assetValue:T,sender:"multiple addresses"});let d=new C.Transaction({allowLegacyWitnessUtxo:!0,version:1}),AX=N[0]?.address,vX=m||await L()||AX||H;e({chain:X,compiledMemo:c,inputs:h,outputs:DX,sender:vX,tx:d});let wX=h.map((r)=>{let R=N.find((n)=>n.hash===r.hash&&n.index===r.index);return R?{derivationIndex:R.derivationIndex,isChange:R.isChange}:{derivationIndex:0,isChange:!1}});return MX({inputDerivations:wX,tx:d}),d.finalize(),P(X).broadcastTx(t.hex.encode(d.extract()))}function X0({address:N,gapLimit:H=20}){if(!B)return;for(let T=0;T<H;T++){let V=O({change:!1,index:T}),b=O({change:!0,index:T}),w=V?.address===N?!1:b?.address===N;if(V?.address===N||b?.address===N)return{change:w,index:T}}return}return{accumulative:g,broadcastTx:(N)=>P(X).broadcastTx(N),bumpFee:dX,calculateTxSize:QX,createKeysForPath:(N)=>UX({...N,chain:X}),createReplacementTransaction:$X,createTransaction:p2,deriveAddressAtIndex:O,derivePrivateKeyAtIndex:NX,estimateMaxSendableAmount:g0(X),estimateTransactionFee:m0(X),getAddress:L,getAddressFromKeys:Y2(X),getBalance:b2(X),getExtendedPublicKey:_,getExtendedPublicKeyInfo:M,getFeeRates:()=>WX(X),getInputsOutputsFee:u2,getNetworkForChain:()=>A(X),getPrivateKeyFromMnemonic:(N)=>S0(UX({...N,chain:X}).privateKey,X),isRBFEnabled:f,keys:z,resolveDerivationIndex:X0,signAndBroadcastTransaction:async(N)=>{if(!Q)throw new W.SwapKitError("toolbox_utxo_no_signer");return Q.signTransaction(N),N.finalize(),await P(X).broadcastTx(t.hex.encode(N.extract()))},signTransactionWithMultipleKeys:MX,transfer:x0(X,Q),transferFromMultipleAddresses:RX,validateAddress:G2(X)}}var x2,t,Z2,uX,W,C,j2,FX,pX;var BX=y(()=>{sX();HX();LX();fX();x2=require("@noble/curves/secp256k1.js"),t=require("@scure/base"),Z2=require("@scure/bip32"),uX=require("@scure/bip39"),W=require("@swapkit/helpers"),C=require("@swapkit/utxo-signer"),j2=require("ts-pattern"),FX=[W.Chain.Dash,W.Chain.Dogecoin,W.Chain.Zcash,W.Chain.BitcoinCash],pX=[W.Chain.Bitcoin]});function PX(X){return GX(bX(X))}function h0(X){let $=A(x);function J(j){return j.sign(X.privateKey,[E.BCHSigHash.ALL]),j}function Z(){let j=E.p2pkh(X.publicKey,$);if(!j.hash)throw new F.SwapKitError("toolbox_utxo_invalid_address",{error:"Could not derive BCH address hash"});let G=E.encodeCashAddr({hash:j.hash,prefix:E.CashAddrPrefix.MAINNET,type:E.CashAddrType.P2PKH});return Promise.resolve(G.replace(/^bitcoincash:/,""))}return{getAddress:Z,signTransaction:J}}function q2(X){let $="phrase"in X?X.phrase:void 0,J="index"in X?X.index||0:0,Z=F.derivationPathToString("derivationPath"in X&&X.derivationPath?X.derivationPath:F.updateDerivationPath(F.NetworkDerivationPath[x],{index:J})),j=$?UX({chain:x,derivationPath:Z,phrase:$}):void 0,G=j?h0(j):("signer"in X)?X.signer:void 0;function q(){return Promise.resolve(G?.getAddress())}let{getBalance:Q,getFeeRates:Y,broadcastTx:z,...L}=XX({chain:x});function U(B,_=!0){return Q(GX(bX(B)))}return{...L,broadcastTx:z,buildTx:u0,createTransaction:c2,getAddress:q,getAddressFromKeys:o0,getBalance:U,getFeeRates:Y,stripPrefix:GX,stripToCashAddress:PX,transfer:p0({broadcastTx:z,getFeeRates:Y,signer:G}),validateAddress:a}}async function c2({assetValue:X,recipient:$,memo:J,feeRate:Z,sender:j}){if(!a($))throw new F.SwapKitError("toolbox_utxo_invalid_address",{address:$});let G=Math.ceil(X.getBaseValue("number")+Z*7500),q=await P(x).getUtxos({address:PX(j),fetchTxHex:!0,targetValue:G}),Q=J?v(J):null,Y=[],z=u($);if(Y.push({address:z,value:X.getBaseValue("number")}),Q)Y.push({script:Q,value:0});let{inputs:L,outputs:U}=g({chain:x,feeRate:Z,inputs:q,outputs:Y});if(!(L&&U))throw new F.SwapKitError("toolbox_utxo_insufficient_balance",{assetValue:X,sender:j});let B=new E.Transaction({allowLegacyWitnessUtxo:!0,allowUnknownOutputs:!!Q,version:1}),_=u(j),{inputs:M,tx:O}=e({chain:x,compiledMemo:Q,inputs:L,outputs:U.map((f)=>("address"in f)&&f.address?{...f,address:u(f.address)}:f),sender:_,tx:B});return{inputs:M,tx:O,utxos:L}}function p0({broadcastTx:X,getFeeRates:$,signer:J}){return async function({recipient:j,assetValue:G,feeOptionKey:q=F.FeeOption.Fast,...Q}){let Y=await J?.getAddress();if(!(J&&Y))throw new F.SwapKitError("toolbox_utxo_no_signer");if(!j)throw new F.SwapKitError("toolbox_utxo_invalid_params",{error:"Recipient address must be provided"});let z=Q.feeRate||(await $())[q],{tx:L}=await c2({...Q,assetValue:G,feeRate:z,recipient:j,sender:Y}),U=await J.signTransaction(L);return U.finalize(),X(o2.hex.encode(U.extract()))}}async function u0({assetValue:X,recipient:$,memo:J,feeRate:Z,sender:j}){let G=bX($);if(!a(G))throw new F.SwapKitError("toolbox_utxo_invalid_address",{address:G});let q=Math.ceil(X.getBaseValue("number")+Z*7500),Q=await P(x).getUtxos({address:PX(j),fetchTxHex:!0,targetValue:q}),Y=Number(Z.toFixed(0)),z=J?v(J):null,L=[];if(L.push({address:u($),value:X.getBaseValue("number")}),z)L.push({script:z,value:0});let{inputs:U,outputs:B}=g({chain:x,feeRate:Y,inputs:Q,outputs:L});if(!(U&&B))throw new F.SwapKitError("toolbox_utxo_insufficient_balance",{assetValue:X,sender:j});let _=new E.Transaction({allowLegacyWitnessUtxo:!0,allowUnknownOutputs:!!z,version:1}),{inputs:M,tx:O}=e({chain:x,compiledMemo:z,inputs:U,outputs:B,sender:u(j),tx:_});return{inputs:M,tx:O,utxos:Q}}function o0(X){let $=E.NETWORKS.bitcoinCash,J=E.p2pkh(X.publicKey,$);if(!J.hash)throw new F.SwapKitError("toolbox_utxo_invalid_address",{error:"Could not derive BCH address hash"});return E.encodeCashAddr({hash:J.hash,prefix:E.CashAddrPrefix.MAINNET,type:E.CashAddrType.P2PKH}).replace(/^bitcoincash:/,"")}var o2,F,E,x;var oX=y(()=>{LX();BX();fX();o2=require("@scure/base"),F=require("@swapkit/helpers"),E=require("@swapkit/utxo-signer"),x=F.Chain.BitcoinCash});function r2(){let{isStagenet:X}=I.SKConfig.get("envs");return X?k.ZCASH_TEST_NETWORK:k.ZCASH_NETWORK}function d0(X){return c0.encode(X)}function r0({phrase:X,derivationPath:$}){let J=z2.mnemonicToSeedSync(X),j=L2.HDKey.fromMasterSeed(J).derive($);if(!j.privateKey||!j.publicKey)throw new I.SwapKitError("toolbox_utxo_invalid_params");let{privateKey:G,publicKey:q}=j,Q=k.utils.hash160(q),{isStagenet:Y}=I.SKConfig.get("envs"),z=Y?new Uint8Array([29,37]):new Uint8Array([28,184]),L=new Uint8Array(z.length+Q.length);L.set(z,0),L.set(Q,z.length);let U=d0(L);return{getAddress:()=>Promise.resolve(U),signTransaction:(B)=>{if(B instanceof k.PCZT)return B.signAllInputs(G,q,k.ZcashSigHash.ALL),B.finalizeAllInputs(),Promise.resolve(B.extract());return B.signAllInputs(G,q,k.ZcashSigHash.ALL),Promise.resolve(B)}}}function n0({inputs:X,outputs:$,tx:J,sender:Z,compiledMemo:j}){let G=r2();for(let q of X){let Q=k.Address(G).decode(Z),Y=k.OutScript.encode(Q);J.addInput({index:q.index,script:Y,sequence:4294967295,txid:cX.hex.decode(q.hash),value:BigInt(q.value)})}for(let q of $){let Q="address"in q&&q.address?q.address:Z,Y=q.script;if(Y&&!j)continue;if(Y&&j)J.addOutput({amount:0n,script:j});else J.addOutputAddress(Q,BigInt(q.value),G)}return{inputs:X,tx:J}}async function d2(X){let{assetValue:$,recipient:J,memo:Z,feeRate:j,sender:G,fetchTxHex:q}=X,Q=Z?v(Z):null,Y=await P(I.Chain.Zcash).getUtxos({address:G,fetchTxHex:q!==!1}),z=[{address:J,value:Number($.getBaseValue("string"))},...Q?[{script:Q,value:0}]:[]],{inputs:L,outputs:U}=g({chain:I.Chain.Zcash,changeAddress:G,feeRate:j,inputs:Y,outputs:z});if(!(L&&U))throw new I.SwapKitError("toolbox_utxo_insufficient_balance",{assetValue:$,sender:G});let B=k.createZcashTransaction({consensusBranchId:k.ZcashConsensusBranchId.NU6_1,expiryHeight:0,lockTime:0,version:4,versionGroupId:k.ZcashVersionGroupId.SAPLING}),{tx:_,inputs:M}=n0({compiledMemo:Q,inputs:L,outputs:U,sender:G,tx:B});return{inputs:M,outputs:U,tx:_}}function U2(X){let $=_X.match(X).with({signer:_X.P.not(_X.P.nullish)},({signer:Y})=>Y).with({phrase:_X.P.string},({phrase:Y,derivationPath:z,index:L=0})=>{let U=z||I.NetworkDerivationPath[I.Chain.Zcash]||[44,133,0,0,0],B=I.updateDerivationPath(U,{index:L}),_=I.derivationPathToString(B);return r0({derivationPath:_,phrase:Y})}).otherwise(()=>{return}),J=XX({chain:I.Chain.Zcash,signer:$});async function Z({recipient:Y,assetValue:z,feeOptionKey:L=I.FeeOption.Fast,...U}){let B=await $?.getAddress();if(!($&&B))throw new I.SwapKitError("toolbox_utxo_no_signer");let _=U.feeRate||(await J.getFeeRates())[L],{tx:M}=await d2({...U,assetValue:z,feeRate:_,recipient:Y,sender:B}),f=(await $.signTransaction(M)).toHex();return J.broadcastTx(f)}function j({phrase:Y,derivationPath:z="m/44'/133'/0'/0/0"}){let L=z2.mnemonicToSeedSync(Y),B=L2.HDKey.fromMasterSeed(L).derive(z);if(!B.privateKey||!B.publicKey)throw new I.SwapKitError("toolbox_utxo_invalid_params");return{privateKey:B.privateKey,publicKey:B.publicKey}}function G({phrase:Y,derivationPath:z="m/44'/133'/0'/0/0"}){let L=j({derivationPath:z,phrase:Y}),U=r2();return k.WIF(U).encode(L.privateKey)}function q(Y){return async function(L){if(!Y)throw new I.SwapKitError("toolbox_utxo_no_signer");return await Y.signTransaction(L)}}function Q(Y){return async function(L){if(!Y)throw new I.SwapKitError("toolbox_utxo_no_signer");let U=await Y.signTransaction(L);return J.broadcastTx(U.toHex())}}return{...J,createKeysForPath:j,createTransaction:d2,getPrivateKeyFromMnemonic:G,signAndBroadcastTransaction:Q($),signTransaction:q($),transfer:Z,validateAddress:zX}}var cX,L2,z2,I,k,_X,c0;var W2=y(()=>{LX();BX();fX();cX=require("@scure/base"),L2=require("@scure/bip32"),z2=require("@scure/bip39"),I=require("@swapkit/helpers"),k=require("@swapkit/utxo-signer"),_X=require("ts-pattern");c0=cX.createBase58check(k.utils.sha256)});function a2({xpub:X,chain:$,count:J,startIndex:Z=0,accountIndex:j}){if(K("count",J),J<1)throw RangeError("count must be at least 1");K("startIndex",Z);let G=A($),q=i2.HDKey.fromExtendedKey(X,G.bip32),Q=i({accountIndex:j,chain:$}),Y=JX(Q),z=[];for(let L of[!1,!0]){let U=q.deriveChild(Number(L));for(let B=0;B<J;B++){let _=Z+B,M=U.deriveChild(_);if(!M.publicKey)continue;let O=YX({accountIndex:j,chain:$,change:L,index:_});z.push({accountIndex:Y,address:EX({chain:$,network:G,publicKey:M.publicKey}),change:L,index:_,path:s2.derivationPathToString(O),pubkey:n2.hex.encode(M.publicKey)})}}return z}var n2,i2,s2;var t2=y(()=>{HX();BX();n2=require("@scure/base"),i2=require("@scure/bip32"),s2=require("@swapkit/helpers")});function i0(X,$){switch(X){case o.Chain.BitcoinCash:return q2($||{});case o.Chain.Zcash:return U2($);case o.Chain.Bitcoin:case o.Chain.Dogecoin:case o.Chain.Litecoin:case o.Chain.Dash:return XX({chain:X,...$});default:throw new o.SwapKitError("toolbox_utxo_not_supported",{chain:X})}}var o;var e2=y(()=>{oX();BX();W2();HX();t2();oX();fX();o=require("@swapkit/helpers")});var s0={};z0(s0,{validateZcashAddress:()=>zX,validateUtxoAddress:()=>Q2,validateBchAddress:()=>a,toLegacyAddress:()=>u,toCashAddress:()=>bX,stripToCashAddress:()=>PX,stripPrefix:()=>GX,nonSegwitChains:()=>FX,isValidAddress:()=>X2,getUtxoToolbox:()=>i0,getUtxoNetwork:()=>b0,getUtxoApi:()=>P,getUTXOAddressValidator:()=>G2,getUTXOAddressPath:()=>YX,getUTXOAccountPath:()=>i,getUTXOAccountIndexFromPath:()=>JX,getScriptTypeForAddress:()=>qX,getOutputSize:()=>kX,getNetworkForChain:()=>A,getInputSize:()=>s,getDustThreshold:()=>IX,detectAddressNetwork:()=>$2,deriveAddressesFromXpub:()=>a2,createZcashToolbox:()=>U2,createUTXOToolbox:()=>XX,createHDWalletHelpers:()=>H2,createCustomUtxoApi:()=>T0,createBCHToolbox:()=>q2,compileMemo:()=>v,calculateTxSize:()=>QX,assertDerivationIndex:()=>K,addressFromKeysGetter:()=>Y2,addInputsAndOutputs:()=>e,accumulative:()=>g,UtxoNetwork:()=>eX,UTXOScriptType:()=>xX,TX_OVERHEAD:()=>mX,SEGWIT_MARKER_FLAG_WEIGHT:()=>lX,OutputSizes:()=>VX,OP_RETURN_OVERHEAD:()=>g2,MIN_TX_FEE:()=>y0,InputSizes:()=>gX});module.exports=Y0(s0);var a0=y(()=>{BX();HX();LX();e2();oX();W2()});a0();
1
+ var J0=Object.create;var{getPrototypeOf:Z0,defineProperty:CX,getOwnPropertyNames:M2,getOwnPropertyDescriptor:j0}=Object,D2=Object.prototype.hasOwnProperty;function C2(X){return this[X]}var Q0,G0,t0=(X,$,J)=>{var Z=X!=null&&typeof X==="object";if(Z){var j=$?Q0??=new WeakMap:G0??=new WeakMap,Q=j.get(X);if(Q)return Q}J=X!=null?J0(Z0(X)):{};let q=$||!X||!X.__esModule?CX(J,"default",{value:X,enumerable:!0}):J;for(let G of M2(X))if(!D2.call(q,G))CX(q,G,{get:C2.bind(X,G),enumerable:!0});if(Z)j.set(X,q);return q},Y0=(X)=>{var $=(N2??=new WeakMap).get(X),J;if($)return $;if($=CX({},"__esModule",{value:!0}),X&&typeof X==="object"||typeof X==="function"){for(var Z of M2(X))if(!D2.call($,Z))CX($,Z,{get:C2.bind(X,Z),enumerable:!(J=j0(X,Z))||J.enumerable})}return N2.set(X,$),$},N2;var q0=(X)=>X;function L0(X,$){this[X]=q0.bind(null,$)}var z0=(X,$)=>{for(var J in $)CX(X,J,{get:$[J],enumerable:!0,configurable:!0,set:L0.bind($,J)})};var y=(X,$)=>()=>(X&&($=X(X=0)),$);function K(X,$){if(!Number.isInteger($)||$<0)throw RangeError(`${X} must be a non-negative integer, got: ${$}`)}function i({accountIndex:X,chain:$,derivationPath:J}){if(X!==void 0)K("accountIndex",X);let Z=[...J?.slice(0,3)??H2.NetworkDerivationPath[$].slice(0,3)];if(X!==void 0)Z[2]=X;return Z}function YX({accountIndex:X,change:$=!1,chain:J,derivationPath:Z,index:j}){return K("index",j),[...i({accountIndex:X,chain:J,derivationPath:Z}),Number($),j]}function JX(X){return X[2]??0}function O2({deriveAddress:X,getBalance:$,getUtxos:J}){async function Z(G){let{accountIndex:Y,count:z,startIndex:L=0,change:U=!1}=G;if(K("count",z),z<1)throw RangeError("count must be at least 1");K("startIndex",L);let B=[];for(let _=0;_<z;_++){let N=await X({accountIndex:Y,change:U,index:L+_});if(N)B.push(N)}return B}async function j(G){let{gapLimit:Y=20,change:z=!1}=G??{},L=[],U=0,B=0;while(U<Y){let _=await X({change:z,index:B});if(!_)break;if((await $(_.address)).some((F)=>F.getValue("number")>0))L.push(_),U=0;else U++;B++}return L}async function Q(G=20){let[Y,z]=await Promise.all([j({change:!1,gapLimit:G}),j({change:!0,gapLimit:G})]),L=[...Y,...z],U=await Promise.all(L.map(async(_)=>{let O=(await $(_.address)).reduce((F,$X)=>F+$X.getValue("number"),0);return{..._,balance:O}})),B=U.reduce((_,N)=>_+N.balance,0);return{addresses:U,total:B}}async function q(G=20){let[Y,z]=await Promise.all([j({change:!1,gapLimit:G}),j({change:!0,gapLimit:G})]),L=[...Y,...z];return(await Promise.all(L.map(async(B)=>{return(await J(B.address)).map((N)=>({...N,address:B.address,derivationIndex:B.index,isChange:B.change}))}))).flat()}return{deriveAddresses:Z,getAggregatedBalance:Q,getAggregatedUtxos:q,scanForAddresses:j}}var H2;var HX=y(()=>{H2=require("@swapkit/helpers")});function V2(){function X(){let $=Date.now(),J=iX||$;return iX=J,$>iX?$:J+1}return U0+X().toString(36)}function b2(X){return async function(J,Z=!0){let j=await T2.SwapKitApi.getChainBalance({address:J,chain:X,scamFilter:Z}),{baseDecimal:Q}=OX.getChainConfig(X),q=j.map(({identifier:Y,value:z,decimal:L})=>{return new OX.AssetValue({decimal:L||Q,identifier:Y,value:z})});if(!q.some((Y)=>Y.isGasAsset))return[OX.AssetValue.from({chain:X}),...q];return q}}var OX,T2,U0,iX=0;var sX=y(()=>{OX=require("@swapkit/helpers"),T2=require("@swapkit/helpers/api"),U0=typeof process<"u"&&process.pid?process.pid.toString(36):""});async function W0({chain:X,txHash:$}){let J=`${TX(X)}/push/transaction`,Z=JSON.stringify({data:$});try{let j=await D.RequestClient.post(J,{body:Z,headers:{"Content-Type":"application/json"}});if(j.context.code!==200)throw new D.SwapKitError("toolbox_utxo_broadcast_failed",{error:j.context.error||"Transaction broadcast failed"});return j.data?.transaction_hash||$}catch(j){let Q=await D.getRPCUrl(X);if(Q){let q=JSON.stringify({id:V2(),jsonrpc:"2.0",method:"sendrawtransaction",params:[$]}),G=await D.RequestClient.post(Q,{body:q,headers:{"Content-Type":"application/json"}});if(G.error)throw new D.SwapKitError("toolbox_utxo_broadcast_failed",{error:G.error?.message});if(G.result.includes('"code":-26'))throw new D.SwapKitError("toolbox_utxo_invalid_transaction",{error:"Transaction amount was too low"});return G.result}throw j}}function TX(X){return`https://api.blockchair.com/${B0(X)}`}function k2(X){switch(X){case D.Chain.Bitcoin:return 5;case D.Chain.Dogecoin:return 1e4;case D.Chain.Litecoin:return 1;case D.Chain.Zcash:return 1;default:return 2}}function B0(X){switch(X){case D.Chain.BitcoinCash:return"bitcoin-cash";case D.Chain.Litecoin:return"litecoin";case D.Chain.Dash:return"dash";case D.Chain.Dogecoin:return"dogecoin";case D.Chain.Zcash:return"zcash";case D.Chain.Polkadot:return"polkadot";default:return"bitcoin"}}async function _0(X){try{let{feePerKb:$}=await D.RequestClient.get(`https://app.bitgo.com/api/v2/${X.toLowerCase()}/tx/fee`),J=$/1000;return Math.max(J,k2(X))}catch{return k2(X)}}async function SX(X,$){let J=await D.RequestClient.get(`${X}${$?`${X.includes("?")?"&":"?"}key=${$}`:""}`);if(!J||J.context.code!==200)throw new D.SwapKitError("toolbox_utxo_api_error",{error:`Failed to query ${X}`});return J.data}async function f2({address:X,chain:$,apiKey:J}){if(!X)throw new D.SwapKitError("toolbox_utxo_invalid_params",{error:"Address is required"});try{return(await SX(`${TX($)}/dashboards/address/${X}?transaction_details=true`,J))[X]}catch{return{address:{balance:0,transaction_count:0},utxo:[]}}}async function N0({address:X,chain:$,apiKey:J}){return(await f2({address:X,apiKey:J,chain:$}))?.address.balance||0}async function F2({chain:X,apiKey:$,txHash:J}){if(!J)throw new D.SwapKitError("toolbox_utxo_invalid_params",{error:"TxHash is required"});try{return(await SX(`${TX(X)}/raw/transaction/${J}`,$))?.[J]?.raw_transaction||""}catch(Z){let j=Z instanceof Error?Z.message:String(Z);return console.error(`Failed to fetch raw transaction: ${j}`),""}}async function D0({chain:X,apiKey:$,txHash:J}){if(!J)throw new D.SwapKitError("toolbox_utxo_invalid_params",{error:"TxHash is required"});let j=(await SX(`${TX(X)}/dashboards/transaction/${J}`,$))?.[J];if(!j)throw new D.SwapKitError("toolbox_utxo_tx_not_found",{txHash:J});let{transaction:Q,inputs:q,outputs:G}=j,Y=q.map((L)=>L.spending_sequence),z=Q.is_rbf===!0||Y.some((L)=>L<M0);return{blockId:Q.block_id,confirmed:Q.block_id!==-1,fee:Q.fee,inputs:q,isRBF:z,outputs:G,sequences:Y,size:Q.size,txid:Q.hash,weight:Q.weight}}async function C0({chain:X,address:$,apiKey:J,offset:Z=0,limit:j=30}){return(await SX(`${TX(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=${j}&offset=${Z}`,J)).map(({is_spent:Y,script_hex:z,block_id:L,transaction_hash:U,index:B,value:_,spending_signature_hex:N})=>({hash:U,index:B,is_confirmed:L!==-1,is_spent:Y,script_hex:z,txHex:N,value:_}))}function H0(X){return X.reduce(($,J)=>$+J.value,0)}function I2(X,$){let J=[...X].sort((Z,j)=>j.value-Z.value);if($){let Z=[],j=0;for(let Q of J)if(Z.push(Q),j+=Q.value,j>=$)break;return Z}return J}async function P2({chain:X,address:$,apiKey:J,targetValue:Z,accumulativeValue:j=0,offset:Q=0,limit:q=30}){if(!$)throw new D.SwapKitError("toolbox_utxo_invalid_params",{error:"Address is required"});try{let G=await C0({address:$,apiKey:J,chain:X,limit:q,offset:Q,targetValue:Z}),z=G.length<q,L=G.filter(({is_spent:F})=>!F),U=H0(L),B=j+U,_=Z&&B>=Z;if(z||_)return I2(L,Z);let N=await P2({accumulativeValue:B,address:$,apiKey:J,chain:X,limit:q,offset:Q+q,targetValue:Z}),O=[...L,...N];return I2(O,Z)}catch(G){let Y=G instanceof Error?G.message:String(G);return console.error(`Failed to fetch unspent UTXOs: ${Y}`),[]}}async function O0({address:X,chain:$,apiKey:J,fetchTxHex:Z=!0,targetValue:j}){let Q=await P2({address:X,apiKey:J,chain:$,targetValue:j}),q=[];for(let{hash:G,index:Y,script_hex:z,value:L}of Q){let U;if(Z)U=await F2({apiKey:J,chain:$,txHash:G});q.push({address:X,hash:G,index:Y,txHex:U,value:L,witnessUtxo:{script:Buffer.from(z,"hex"),value:L}})}return q}function E(X){let $=D.SKConfig.get("apiKeys").blockchair||"";return D.warnOnce({condition:!$,id:"no_blockchair_api_key_warning",warning:"No Blockchair API key found. Functionality will be limited."}),{broadcastTx:(J)=>W0({chain:X,txHash:J}),getAddressData:(J)=>f2({address:J,apiKey:$,chain:X}),getBalance:(J)=>N0({address:J,apiKey:$,chain:X}),getRawTx:(J)=>F2({apiKey:$,chain:X,txHash:J}),getSuggestedTxFee:()=>_0(X),getTransactionDetails:(J)=>D0({apiKey:$,chain:X,txHash:J}),getUtxos:(J)=>O0({...J,apiKey:$,chain:X})}}function T0(X){return X}function V0(){return function($){switch($){case D.Chain.Bitcoin:return ZX.NETWORKS.bitcoin;case D.Chain.BitcoinCash:return ZX.NETWORKS.bitcoinCash;case D.Chain.Dash:return ZX.NETWORKS.dash;case D.Chain.Litecoin:return ZX.NETWORKS.litecoin;case D.Chain.Dogecoin:return ZX.NETWORKS.dogecoin;case D.Chain.Zcash:return ZX.NETWORKS.zcash;default:throw new D.SwapKitError("toolbox_utxo_not_supported",{chain:$})}}}var D,ZX,M0=4294967294;var E2=y(()=>{sX();D=require("@swapkit/helpers"),ZX=require("@swapkit/utxo-signer")});function I0(X,$,J){return p.encodeCashAddr({hash:J,prefix:X,type:b0[$]})}function f0(X){let $=p.decodeCashAddr(X),J=k0[$.type];if(!J)throw Error(`Unknown CashAddr type: ${$.type}`);return{hash:$.hash,prefix:$.prefix,type:J}}var p,b0,k0,aX;var R2=y(()=>{p=require("@swapkit/utxo-signer"),b0={P2PKH:p.CashAddrType.P2PKH,P2SH:p.CashAddrType.P2SH},k0={[p.CashAddrType.P2PKH]:"P2PKH",[p.CashAddrType.P2SH]:"P2SH"};aX={decode:f0,encode:I0}});function X2(X){try{return KX(X),!0}catch{return!1}}function $2(X){return KX(X)?.network}function u(X){let $=KX(X);if($?.format==="legacy")return X;return E0($)}function VX(X){let $=KX(X);return R0($)}function KX(X){try{let $=F0(X);if($)return $}catch{}try{let $=P0(X);if($)return $}catch{}throw new tX.SwapKitError("toolbox_utxo_invalid_address",{address:X})}function F0(X){try{let $=w2.decode(X);if($.length!==21)throw new tX.SwapKitError("toolbox_utxo_invalid_address",{address:X});let J=$[0],Z=Array.prototype.slice.call($,1);switch(J){case jX.legacy.mainnet.p2pkh:return{format:"legacy",hash:Z,network:"mainnet",type:"p2pkh"};case jX.legacy.mainnet.p2sh:return{format:"legacy",hash:Z,network:"mainnet",type:"p2sh"};case jX.legacy.testnet.p2pkh:return{format:"legacy",hash:Z,network:"testnet",type:"p2pkh"};case jX.legacy.testnet.p2sh:return{format:"legacy",hash:Z,network:"testnet",type:"p2sh"};case jX.bitpay.mainnet.p2pkh:return{format:"bitpay",hash:Z,network:"mainnet",type:"p2pkh"};case jX.bitpay.mainnet.p2sh:return{format:"bitpay",hash:Z,network:"mainnet",type:"p2sh"};default:return}}catch{return}}function P0(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:Z}=aX.decode(X);return{format:"cashaddr",hash:Array.prototype.slice.call($,0),network:J==="bitcoincash"?"mainnet":"testnet",type:Z==="P2PKH"?"p2pkh":"p2sh"}}catch{return}}function E0(X){let $=jX.legacy[X.network][X.type],J=Buffer.alloc(1+X.hash.length);return J[0]=$,J.set(X.hash,1),w2.encode(J)}function R0(X){let $=X.network==="mainnet"?"bitcoincash":"bchtest",J=X.type==="p2pkh"?"P2PKH":"P2SH",Z=new Uint8Array(X.hash);return aX.encode($,J,Z)}var v2,A2,tX,w2,eX,jX;var S2=y(()=>{R2();v2=require("@noble/hashes/sha2.js"),A2=require("@scure/base"),tX=require("@swapkit/helpers"),w2=A2.createBase58check(v2.sha256);((J)=>{J.Mainnet="mainnet";J.Testnet="testnet"})(eX||={});jX={["legacy"]:{["mainnet"]:{["p2pkh"]:0,["p2sh"]:5},["testnet"]:{["p2pkh"]:111,["p2sh"]:196}},["bitpay"]:{["mainnet"]:{["p2pkh"]:28,["p2sh"]:40},["testnet"]:{["p2pkh"]:111,["p2sh"]:196}}}});function A(X){let $=new Uint8Array(Buffer.from(X,"utf8"));return m2.Script.encode(["RETURN",$])}var K2,m2,y0=1000,gX=10,lX=2,g2=10,v0=41,A0=107,xX,mX,bX,qX=(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 K2.SwapKitError("toolbox_utxo_invalid_address",{address:X})},QX=({inputs:X,outputs:$,feeRate:J})=>{let Z=X[0]&&"address"in X[0]&&X[0].address?qX(X[0].address):"P2PKH",Q=(J?X.filter((z)=>z.value>=mX["type"in z&&z.type?z.type:"P2PKH"]*Math.ceil(J)):X).reduce((z,L)=>z+s(L),0),q=$?.reduce((z,L)=>z+kX(L),0)||bX[Z],G=gX+Q+q;return Z==="P2WPKH"?Math.ceil(G+lX/4):G},s=(X)=>{if("type"in X&&X.type)return mX[X.type];if("address"in X&&X.address)return mX[qX(X.address)];return v0+A0},kX=(X,$)=>{if(X?.script)return g2+X.script.length+(X.script.length>=74?2:1);if($)return bX[$];if("address"in X&&X.address)return bX[qX(X.address)];return bX.P2PKH};var J2=y(()=>{K2=require("@swapkit/helpers"),m2=require("@swapkit/utxo-signer");((J)=>{J.P2PKH="P2PKH";J.P2WPKH="P2WPKH"})(xX||={});mX={["P2PKH"]:148,["P2WPKH"]:68},bX={["P2PKH"]:34,["P2WPKH"]:31}});function IX(X){switch(X){case l.Chain.Bitcoin:case l.Chain.BitcoinCash:return 550;case l.Chain.Dash:case l.Chain.Litecoin:return 5500;case l.Chain.Dogecoin:return 1e5;case l.Chain.Zcash:return 546;default:throw new l.SwapKitError("toolbox_utxo_not_supported",{chain:X})}}function m({inputs:X,outputs:$,feeRate:J=1,chain:Z=l.Chain.Bitcoin,changeAddress:j=""}){let Q=X[0]&&"address"in X[0]&&X[0].address?qX(X[0].address):"P2PKH",q=X.filter((N)=>s(N)*J<=N.value),Y=Q==="P2WPKH"?Math.ceil(lX/4):0,z=gX+Y+$.reduce((N,O)=>N+kX(O),0),L=$.reduce((N,O)=>N+O.value,0),U=z*J,B=0,_=[];for(let N of q){let O=s(N),F=J*O;U+=F,B+=N.value,_.push(N);let $X=U+L;if(B<$X)continue;let dX=B-$X,NX=J*kX({address:j,value:0});if(dX>NX){let MX=NX+U,RX=B-(L+Math.ceil(MX));if(RX>Math.max(s({value:0})*J,IX(Z)))return{fee:Math.ceil(MX),inputs:_,outputs:$.concat({address:j,value:RX})}}return{fee:Math.ceil(U),inputs:_,outputs:$}}return{fee:Math.ceil(J*QX({inputs:X,outputs:$}))}}var l;var l2=y(()=>{J2();l=require("@swapkit/helpers")});var LX=y(()=>{E2();S2();l2();J2()});function GX(X){return X.replace(/(bchtest:|bitcoincash:)/,"")}function a(X){let $=GX(X);return X2($)&&$2($)==="mainnet"}function zX(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 J=hX.Address(hX.ZCASH_NETWORK).decode(X);return J.type==="pkh"||J.type==="sh"}catch{return!1}}var hX;var fX=y(()=>{LX();hX=require("@swapkit/utxo-signer")});function Q2({address:X,chain:$}){return j2.match($).with(W.Chain.BitcoinCash,()=>a(X)).with(W.Chain.Zcash,()=>zX(X)).otherwise(()=>{try{return C.Address(v($)).decode(X),!0}catch{return!1}})}function v(X){return j2.match(X).with(W.Chain.Bitcoin,()=>C.NETWORKS.bitcoin).with(W.Chain.BitcoinCash,()=>C.NETWORKS.bitcoinCash).with(W.Chain.Dash,()=>C.NETWORKS.dash).with(W.Chain.Dogecoin,()=>C.NETWORKS.dogecoin).with(W.Chain.Litecoin,()=>C.NETWORKS.litecoin).with(W.Chain.Zcash,()=>C.NETWORKS.zcash).exhaustive()}function w0({phrase:X,derivationPath:$,network:J,seed:Z}){let j=Z??uX.mnemonicToSeedSync(X),q=Z2.HDKey.fromMasterSeed(j,J.bip32).derive($);if(!q.privateKey)throw new W.SwapKitError("toolbox_utxo_invalid_params",{error:"Could not derive private key from phrase"});return q.privateKey}function x2(X){return h2.secp256k1.getPublicKey(X,!0)}function PX({publicKey:X,chain:$,network:J}){if($===W.Chain.BitcoinCash){let Q=C.p2pkh(X,J);if(!Q.hash)throw new W.SwapKitError("toolbox_utxo_invalid_address",{error:"Could not derive BCH address hash"});return C.encodeCashAddr({hash:Q.hash,prefix:C.CashAddrPrefix.MAINNET,type:C.CashAddrType.P2PKH}).replace(/^bitcoincash:/,"")}let j=!FX.includes($)?C.p2wpkh(X,J):C.p2pkh(X,J);if(!j.address)throw new W.SwapKitError("toolbox_utxo_invalid_address",{error:"Could not derive address"});return j.address}function UX({phrase:X,derivationPath:$,chain:J,wif:Z,seed:j}){let Q=v(J);if(Z){let z=C.WIF(Q).decode(Z),L=x2(z);return{privateKey:z,publicKey:L}}if(!X)throw new W.SwapKitError("toolbox_utxo_invalid_params",{error:"Either phrase or wif must be provided"});let q=$||W.derivationPathToString(W.NetworkDerivationPath[J]),G=w0({derivationPath:q,network:Q,phrase:X,seed:j}),Y=x2(G);return{privateKey:G,publicKey:Y}}function S0(X,$){return C.WIF(v($)).encode(X)}function K0({phrase:X,derivationPath:$,chain:J,seed:Z}){let j=$.split("/");if(j.length<4)throw new W.SwapKitError("toolbox_utxo_invalid_params",{error:`Derivation path must have at least 4 levels (got ${j.length}): ${$}`});let Q=v(J),q=Z??uX.mnemonicToSeedSync(X),G=Z2.HDKey.fromMasterSeed(q,Q.bip32),Y=j.slice(0,4).join("/");return G.derive(Y)}function e({inputs:X,outputs:$,chain:J,tx:Z,sender:j,compiledMemo:Q,enableRBF:q=!1}){let G=v(J),Y=!FX.includes(J),z=q?C.RBF_SEQUENCE:void 0,L=new Set;for(let U of X){let B=`${U.hash}:${U.index}`;if(L.has(B))throw new W.SwapKitError("toolbox_utxo_invalid_params",{error:"Duplicate input detected"});L.add(B);let _=typeof U.hash==="string"?t.hex.decode(U.hash):U.hash;if(Y&&U.witnessUtxo)Z.addInput({index:U.index,sequence:z,txid:_,witnessUtxo:{amount:BigInt(U.witnessUtxo.value),script:U.witnessUtxo.script}});else if(U.txHex)Z.addInput({index:U.index,nonWitnessUtxo:t.hex.decode(U.txHex),sequence:z,txid:_,...J===W.Chain.BitcoinCash?{sighashType:C.BCHSigHash.ALL}:{}});else throw new W.SwapKitError("toolbox_utxo_invalid_params",{error:"Input requires either witnessUtxo or txHex for non-segwit chains"})}for(let U of $){let B="address"in U&&U.address?U.address:j;if(J===W.Chain.BitcoinCash)B=u(B);if(U.script){if(Q)Z.addOutput({amount:0n,script:Q})}else Z.addOutputAddress(B,BigInt(U.value),G)}return{inputs:X,tx:Z}}async function WX(X){let $=await E(X).getSuggestedTxFee();return{[W.FeeOption.Average]:$,[W.FeeOption.Fast]:W.applyFeeMultiplier($,W.FeeOption.Fast),[W.FeeOption.Fastest]:W.applyFeeMultiplier($,W.FeeOption.Fastest)}}async function p2({assetValue:X,recipient:$,memo:J,sender:Z,fetchTxHex:j=!1}){let Q=X.chain,q=(await WX(Q))[W.FeeOption.Fastest],G=j||FX.includes(Q),Y=X.getBaseValue("number"),z=Math.ceil(Y+q*5000);return{inputs:await E(Q).getUtxos({address:Z,fetchTxHex:G,targetValue:z}),outputs:[{address:$,value:Y},...J?[{address:"",script:A(J),value:0}]:[]]}}async function u2({assetValue:X,recipient:$,memo:J,feeRate:Z,sender:j,fetchTxHex:Q=!1,enableRBF:q=!1}){let G=X.chain,Y=J?A(J):null,z=await p2({assetValue:X,fetchTxHex:Q,memo:J,recipient:$,sender:j}),{inputs:L,outputs:U}=m({...z,chain:G,feeRate:Z});if(!(L&&U))throw new W.SwapKitError("toolbox_utxo_insufficient_balance",{assetValue:X,sender:j});let B=new C.Transaction({allowLegacyWitnessUtxo:!0,allowUnknownOutputs:!!Y,version:1}),{inputs:_,tx:N}=e({chain:G,compiledMemo:Y,enableRBF:q,inputs:L,outputs:U,sender:j,tx:B});return{inputs:_,tx:N,utxos:z.inputs}}async function o2({assetValue:X,feeOptionKey:$=W.FeeOption.Fast,feeRate:J,memo:Z,sender:j,recipient:Q}){let q=X.chain,G=await p2({assetValue:X,memo:Z,recipient:Q,sender:j}),Y=J?Math.floor(J):(await WX(q))[$];return m({...G,chain:q,feeRate:Y})}function m0(X){return async function({from:J,memo:Z,feeRate:j,feeOptionKey:Q=W.FeeOption.Fast,recipients:q=1}){let G=await E(X).getAddressData(J),Y=j?Math.ceil(j):(await WX(X))[Q],z=G?.utxo.map((O)=>({...O,hash:"",type:"P2PKH"})).filter((O)=>O.value>Math.max(IX(X),s(O)*Y));if(!z?.length)return W.AssetValue.from({chain:X});let L=BigInt(z.reduce((O,F)=>O+F.value,0)),U=W.AssetValue.from({chain:X,value:L}),B=typeof q==="number"?Array.from({length:q},()=>({address:J,value:0})):q;if(Z)B.push({address:J,script:A(Z),value:0});let _=QX({inputs:z,outputs:B}),N=W.AssetValue.from({chain:X,value:BigInt(_*Y)});return U.sub(N)}}function g0(X){return async function(J){let{fee:Z}=await o2(J);return W.AssetValue.from({chain:X,value:W.SwapKitNumber.fromBigInt(BigInt(Z),8).getValue("string")})}}function l0({chain:X,phrase:$,derivationPath:J,seed:Z}){let j=v(X),{privateKey:Q,publicKey:q}=UX({chain:X,derivationPath:J,phrase:$,seed:Z}),G=X===W.Chain.BitcoinCash?[C.BCHSigHash.ALL]:[C.SigHash.ALL];return{getAddress:()=>PX({chain:X,network:j,publicKey:q}),privateKey:Q,publicKey:q,signTransaction:(Y)=>{return Y.sign(Q,G),Y}}}function x0(X,$){return async function({memo:Z,recipient:j,feeOptionKey:Q,feeRate:q,assetValue:G,enableRBF:Y=!1}){let z=$?.getAddress();if(!($&&z))throw new W.SwapKitError("toolbox_utxo_no_signer");if(!j)throw new W.SwapKitError("toolbox_utxo_invalid_params",{error:"Recipient address must be provided"});W.warnOnce({condition:Y&&!pX.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=Y&&pX.includes(X),U=q||(await WX(X))[Q||W.FeeOption.Fast],{tx:B}=await u2({assetValue:G,enableRBF:L,feeRate:U,memo:Z,recipient:j,sender:z});return $.signTransaction(B),B.finalize(),E(X).broadcastTx(t.hex.encode(B.extract()))}}function G2(X){return($)=>Q2({address:$,chain:X})}function Y2(X){let $=v(X);return function(Z){if(!Z)throw new W.SwapKitError("toolbox_utxo_invalid_params",{error:"Keys must be provided"});return PX({chain:X,network:$,publicKey:Z.publicKey})}}function XX({chain:X,...$}){let J="phrase"in $?$.phrase:void 0,Z="index"in $?$.index||0:0,j=J?uX.mnemonicToSeedSync(J):void 0,Q="derivationPath"in $&&$.derivationPath?$.derivationPath:W.updateDerivationPath(W.NetworkDerivationPath[X],{index:Z}),q=W.derivationPathToString(Q),G=J?l0({chain:X,derivationPath:q,phrase:J,seed:j}):void 0,Y="signer"in $?$.signer:void 0,z=J?UX({chain:X,derivationPath:q,phrase:J,seed:j}):void 0;function L(){if(G)return Promise.resolve(G.getAddress());if(Y)return Y.getAddress();return Promise.resolve(void 0)}function U(M){if(!J)return;let H=i({accountIndex:M,chain:X,derivationPath:Q});return K0({chain:X,derivationPath:W.derivationPathToString(H),phrase:J,seed:j})}let B=U();function _(){if(!B)return;return B.publicExtendedKey}function N({accountIndex:M}={}){let H=M===void 0?B:U(M);if(!H)return;let T=i({accountIndex:M,chain:X,derivationPath:Q});return{accountIndex:JX(T),path:W.derivationPathToString(T),xpub:H.publicExtendedKey}}function O({accountIndex:M,index:H,change:T=!1}){let b=M===void 0?B:U(M);if(!b)return;let V=YX({accountIndex:M,chain:X,change:T,derivationPath:Q,index:H}),w=v(X),g=b.deriveChild(Number(T)).deriveChild(H);if(!g.publicKey)throw new W.SwapKitError("toolbox_utxo_invalid_params",{error:"Could not derive public key"});let S=PX({chain:X,network:w,publicKey:g.publicKey}),c=t.hex.encode(g.publicKey);return{accountIndex:JX(V),address:S,change:T,index:H,path:W.derivationPathToString(V),pubkey:c}}async function F(M){if(!pX.includes(X))return{reason:`RBF is not supported on ${X}`,supported:!1};let H=await E(X).getTransactionDetails(M);return{canReplace:H.isRBF&&!H.confirmed,confirmed:H.confirmed,enabled:H.isRBF,fee:H.fee,sequences:H.sequences,supported:!0}}async function $X({txid:M,newFeeRate:H,recipient:T,memo:b}){if(!pX.includes(X))throw new W.SwapKitError("toolbox_utxo_rbf_not_supported",{chain:X});let V=await E(X).getTransactionDetails(M);if(!V.isRBF)throw new W.SwapKitError("toolbox_utxo_tx_not_replaceable",{txid:M});if(V.confirmed)throw new W.SwapKitError("toolbox_utxo_tx_already_confirmed",{blockId:V.blockId,txid:M});let w=V.inputs.reduce((R,n)=>R+n.value,0),S=V.outputs.find((R)=>R.recipient===T)?.value||0;if(S===0)throw new W.SwapKitError("toolbox_utxo_invalid_params",{error:"Could not determine send amount from original transaction"});let c=await Promise.all(V.inputs.map(async(R)=>{let n=await E(X).getRawTx(R.transaction_hash);return{hash:R.transaction_hash,index:R.index,txHex:n,value:R.value,witnessUtxo:void 0}})),yX=b?A(b):null,rX=QX({feeRate:H,inputs:c.map((R)=>({...R,type:"P2WPKH"})),outputs:[{address:T,value:S}]}),h=Math.ceil(rX*H);if(h<=V.fee)throw new W.SwapKitError("toolbox_utxo_rbf_fee_too_low",{newFee:h,originalFee:V.fee});let DX=h-V.fee,d=S-DX;if(d<=0)throw new W.SwapKitError("toolbox_utxo_rbf_insufficient_change");let vX=new C.Transaction({allowLegacyWitnessUtxo:!0,version:1}),AX=[{address:T,value:d},...b?[{address:"",script:A(b),value:0}]:[]],wX=w-d-h,r=await L();if(wX>IX(X)&&r)AX.push({address:r,value:wX});return e({chain:X,compiledMemo:yX,inputs:c,outputs:AX,sender:r||T,tx:vX}),{feeDelta:DX,newFee:h,originalFee:V.fee,tx:vX}}async function dX({txid:M,newFeeRate:H,recipient:T,memo:b}){if(!G)throw new W.SwapKitError("toolbox_utxo_no_signer");let{tx:V,originalFee:w,newFee:g}=await $X({memo:b,newFeeRate:H,recipient:T,txid:M});G.signTransaction(V),V.finalize();let S=await E(X).broadcastTx(t.hex.encode(V.extract()));return{newFee:g,originalFee:w,txid:S}}function NX({accountIndex:M,index:H,change:T=!1}){K("index",H);let b=M===void 0?B:U(M);if(!b)return;return b.deriveChild(Number(T)).deriveChild(H).privateKey||void 0}function MX({tx:M,inputDerivations:H}){if(!B)throw new W.SwapKitError("toolbox_utxo_no_signer");let T=X===W.Chain.BitcoinCash?[C.BCHSigHash.ALL]:[C.SigHash.ALL];for(let b=0;b<H.length;b++){let V=H[b];if(!V)continue;let{derivationIndex:w,isChange:g}=V,S=NX({change:g,index:w});if(!S)throw new W.SwapKitError("toolbox_utxo_invalid_params",{error:`Could not derive private key for input ${b} at index ${w}`});M.signIdx(S,b,T)}return M}async function RX({utxos:M,recipient:H,assetValue:T,memo:b,feeRate:V,feeOptionKey:w,changeAddress:g}){if(!B)throw new W.SwapKitError("toolbox_utxo_no_signer");let S=V||(await WX(X))[w||W.FeeOption.Fast],c=b?A(b):null,yX=[{address:H,value:T.getBaseValue("number")}];if(c)yX.push({address:"",script:c,value:0});let rX=M.map(({hash:r,index:R,value:n,txHex:$0,witnessUtxo:nX})=>({hash:r,index:R,txHex:$0,value:n,witnessUtxo:nX?{script:nX.script,value:nX.value}:void 0})),{inputs:h,outputs:DX}=m({chain:X,feeRate:S,inputs:rX,outputs:yX});if(!(h&&DX))throw new W.SwapKitError("toolbox_utxo_insufficient_balance",{assetValue:T,sender:"multiple addresses"});let d=new C.Transaction({allowLegacyWitnessUtxo:!0,version:1}),vX=M[0]?.address,AX=g||await L()||vX||H;e({chain:X,compiledMemo:c,inputs:h,outputs:DX,sender:AX,tx:d});let wX=h.map((r)=>{let R=M.find((n)=>n.hash===r.hash&&n.index===r.index);return R?{derivationIndex:R.derivationIndex,isChange:R.isChange}:{derivationIndex:0,isChange:!1}});return MX({inputDerivations:wX,tx:d}),d.finalize(),E(X).broadcastTx(t.hex.encode(d.extract()))}function X0({address:M,gapLimit:H=20}){if(!B)return;for(let T=0;T<H;T++){let b=O({change:!1,index:T}),V=O({change:!0,index:T}),w=b?.address===M?!1:V?.address===M;if(b?.address===M||V?.address===M)return{change:w,index:T}}return}return{accumulative:m,broadcastTx:(M)=>E(X).broadcastTx(M),bumpFee:dX,calculateTxSize:QX,createKeysForPath:(M)=>UX({...M,chain:X}),createReplacementTransaction:$X,createTransaction:u2,deriveAddressAtIndex:O,derivePrivateKeyAtIndex:NX,estimateMaxSendableAmount:m0(X),estimateTransactionFee:g0(X),getAddress:L,getAddressFromKeys:Y2(X),getBalance:b2(X),getExtendedPublicKey:_,getExtendedPublicKeyInfo:N,getFeeRates:()=>WX(X),getInputsOutputsFee:o2,getNetworkForChain:()=>v(X),getPrivateKeyFromMnemonic:(M)=>S0(UX({...M,chain:X}).privateKey,X),isRBFEnabled:F,keys:z,resolveDerivationIndex:X0,signAndBroadcastTransaction:async(M)=>{if(!G)throw new W.SwapKitError("toolbox_utxo_no_signer");return G.signTransaction(M),M.finalize(),await E(X).broadcastTx(t.hex.encode(M.extract()))},signTransactionWithMultipleKeys:MX,transfer:x0(X,G),transferFromMultipleAddresses:RX,validateAddress:G2(X)}}var h2,t,Z2,uX,W,C,j2,FX,pX;var BX=y(()=>{sX();HX();LX();fX();h2=require("@noble/curves/secp256k1.js"),t=require("@scure/base"),Z2=require("@scure/bip32"),uX=require("@scure/bip39"),W=require("@swapkit/helpers"),C=require("@swapkit/utxo-signer"),j2=require("ts-pattern"),FX=[W.Chain.Dash,W.Chain.Dogecoin,W.Chain.Zcash,W.Chain.BitcoinCash],pX=[W.Chain.Bitcoin]});function EX(X){return GX(VX(X))}function h0(X){let $=v(x);function J(j){return j.sign(X.privateKey,[P.BCHSigHash.ALL]),j}function Z(){let j=P.p2pkh(X.publicKey,$);if(!j.hash)throw new f.SwapKitError("toolbox_utxo_invalid_address",{error:"Could not derive BCH address hash"});let Q=P.encodeCashAddr({hash:j.hash,prefix:P.CashAddrPrefix.MAINNET,type:P.CashAddrType.P2PKH});return Promise.resolve(Q.replace(/^bitcoincash:/,""))}return{getAddress:Z,signTransaction:J}}function L2(X){let $="phrase"in X?X.phrase:void 0,J="index"in X?X.index||0:0,Z=f.derivationPathToString("derivationPath"in X&&X.derivationPath?X.derivationPath:f.updateDerivationPath(f.NetworkDerivationPath[x],{index:J})),j=$?UX({chain:x,derivationPath:Z,phrase:$}):void 0,Q=j?h0(j):("signer"in X)?X.signer:void 0;function q(){return Promise.resolve(Q?.getAddress())}let{getBalance:G,getFeeRates:Y,broadcastTx:z,...L}=XX({chain:x});function U(_,N=!0){return G(GX(VX(_)))}async function B(_){if(!Q)throw new f.SwapKitError("toolbox_utxo_no_signer");return Q.signTransaction(_),_.finalize(),await z(q2.hex.encode(_.extract()))}return{...L,broadcastTx:z,buildTx:u0,createTransaction:c2,getAddress:q,getAddressFromKeys:o0,getBalance:U,getFeeRates:Y,signAndBroadcastTransaction:B,stripPrefix:GX,stripToCashAddress:EX,transfer:p0({broadcastTx:z,getFeeRates:Y,signer:Q}),validateAddress:a}}async function c2({assetValue:X,recipient:$,memo:J,feeRate:Z,sender:j}){if(!a($))throw new f.SwapKitError("toolbox_utxo_invalid_address",{address:$});let Q=Math.ceil(X.getBaseValue("number")+Z*7500),q=await E(x).getUtxos({address:EX(j),fetchTxHex:!0,targetValue:Q}),G=J?A(J):null,Y=[],z=u($);if(Y.push({address:z,value:X.getBaseValue("number")}),G)Y.push({script:G,value:0});let{inputs:L,outputs:U}=m({chain:x,feeRate:Z,inputs:q,outputs:Y});if(!(L&&U))throw new f.SwapKitError("toolbox_utxo_insufficient_balance",{assetValue:X,sender:j});let B=new P.Transaction({allowLegacyWitnessUtxo:!0,allowUnknownOutputs:!!G,version:1}),_=u(j),{inputs:N,tx:O}=e({chain:x,compiledMemo:G,inputs:L,outputs:U.map((F)=>("address"in F)&&F.address?{...F,address:u(F.address)}:F),sender:_,tx:B});return{inputs:N,tx:O,utxos:L}}function p0({broadcastTx:X,getFeeRates:$,signer:J}){return async function({recipient:j,assetValue:Q,feeOptionKey:q=f.FeeOption.Fast,...G}){let Y=await J?.getAddress();if(!(J&&Y))throw new f.SwapKitError("toolbox_utxo_no_signer");if(!j)throw new f.SwapKitError("toolbox_utxo_invalid_params",{error:"Recipient address must be provided"});let z=G.feeRate||(await $())[q],{tx:L}=await c2({...G,assetValue:Q,feeRate:z,recipient:j,sender:Y}),U=await J.signTransaction(L);return U.finalize(),X(q2.hex.encode(U.extract()))}}async function u0({assetValue:X,recipient:$,memo:J,feeRate:Z,sender:j}){let Q=VX($);if(!a(Q))throw new f.SwapKitError("toolbox_utxo_invalid_address",{address:Q});let q=Math.ceil(X.getBaseValue("number")+Z*7500),G=await E(x).getUtxos({address:EX(j),fetchTxHex:!0,targetValue:q}),Y=Number(Z.toFixed(0)),z=J?A(J):null,L=[];if(L.push({address:u($),value:X.getBaseValue("number")}),z)L.push({script:z,value:0});let{inputs:U,outputs:B}=m({chain:x,feeRate:Y,inputs:G,outputs:L});if(!(U&&B))throw new f.SwapKitError("toolbox_utxo_insufficient_balance",{assetValue:X,sender:j});let _=new P.Transaction({allowLegacyWitnessUtxo:!0,allowUnknownOutputs:!!z,version:1}),{inputs:N,tx:O}=e({chain:x,compiledMemo:z,inputs:U,outputs:B,sender:u(j),tx:_});return{inputs:N,tx:O,utxos:G}}function o0(X){let $=P.NETWORKS.bitcoinCash,J=P.p2pkh(X.publicKey,$);if(!J.hash)throw new f.SwapKitError("toolbox_utxo_invalid_address",{error:"Could not derive BCH address hash"});return P.encodeCashAddr({hash:J.hash,prefix:P.CashAddrPrefix.MAINNET,type:P.CashAddrType.P2PKH}).replace(/^bitcoincash:/,"")}var q2,f,P,x;var oX=y(()=>{LX();BX();fX();q2=require("@scure/base"),f=require("@swapkit/helpers"),P=require("@swapkit/utxo-signer"),x=f.Chain.BitcoinCash});function r2(){let{isStagenet:X}=I.SKConfig.get("envs");return X?k.ZCASH_TEST_NETWORK:k.ZCASH_NETWORK}function d0(X){return c0.encode(X)}function r0({phrase:X,derivationPath:$}){let J=U2.mnemonicToSeedSync(X),j=z2.HDKey.fromMasterSeed(J).derive($);if(!j.privateKey||!j.publicKey)throw new I.SwapKitError("toolbox_utxo_invalid_params");let{privateKey:Q,publicKey:q}=j,G=k.utils.hash160(q),{isStagenet:Y}=I.SKConfig.get("envs"),z=Y?new Uint8Array([29,37]):new Uint8Array([28,184]),L=new Uint8Array(z.length+G.length);L.set(z,0),L.set(G,z.length);let U=d0(L);return{getAddress:()=>Promise.resolve(U),signTransaction:(B)=>{if(B instanceof k.PCZT)return B.signAllInputs(Q,q,k.ZcashSigHash.ALL),B.finalizeAllInputs(),Promise.resolve(B.extract());return B.signAllInputs(Q,q,k.ZcashSigHash.ALL),Promise.resolve(B)}}}function n0({inputs:X,outputs:$,tx:J,sender:Z,compiledMemo:j}){let Q=r2();for(let q of X){let G=k.Address(Q).decode(Z),Y=k.OutScript.encode(G);J.addInput({index:q.index,script:Y,sequence:4294967295,txid:cX.hex.decode(q.hash),value:BigInt(q.value)})}for(let q of $){let G="address"in q&&q.address?q.address:Z,Y=q.script;if(Y&&!j)continue;if(Y&&j)J.addOutput({amount:0n,script:j});else J.addOutputAddress(G,BigInt(q.value),Q)}return{inputs:X,tx:J}}async function d2(X){let{assetValue:$,recipient:J,memo:Z,feeRate:j,sender:Q,fetchTxHex:q}=X,G=Z?A(Z):null,Y=await E(I.Chain.Zcash).getUtxos({address:Q,fetchTxHex:q!==!1}),z=[{address:J,value:Number($.getBaseValue("string"))},...G?[{script:G,value:0}]:[]],{inputs:L,outputs:U}=m({chain:I.Chain.Zcash,changeAddress:Q,feeRate:j,inputs:Y,outputs:z});if(!(L&&U))throw new I.SwapKitError("toolbox_utxo_insufficient_balance",{assetValue:$,sender:Q});let B=k.createZcashTransaction({consensusBranchId:k.ZcashConsensusBranchId.NU6_1,expiryHeight:0,lockTime:0,version:4,versionGroupId:k.ZcashVersionGroupId.SAPLING}),{tx:_,inputs:N}=n0({compiledMemo:G,inputs:L,outputs:U,sender:Q,tx:B});return{inputs:N,outputs:U,tx:_}}function W2(X){let $=_X.match(X).with({signer:_X.P.not(_X.P.nullish)},({signer:Y})=>Y).with({phrase:_X.P.string},({phrase:Y,derivationPath:z,index:L=0})=>{let U=z||I.NetworkDerivationPath[I.Chain.Zcash]||[44,133,0,0,0],B=I.updateDerivationPath(U,{index:L}),_=I.derivationPathToString(B);return r0({derivationPath:_,phrase:Y})}).otherwise(()=>{return}),J=XX({chain:I.Chain.Zcash,signer:$});async function Z({recipient:Y,assetValue:z,feeOptionKey:L=I.FeeOption.Fast,...U}){let B=await $?.getAddress();if(!($&&B))throw new I.SwapKitError("toolbox_utxo_no_signer");let _=U.feeRate||(await J.getFeeRates())[L],{tx:N}=await d2({...U,assetValue:z,feeRate:_,recipient:Y,sender:B}),F=(await $.signTransaction(N)).toHex();return J.broadcastTx(F)}function j({phrase:Y,derivationPath:z="m/44'/133'/0'/0/0"}){let L=U2.mnemonicToSeedSync(Y),B=z2.HDKey.fromMasterSeed(L).derive(z);if(!B.privateKey||!B.publicKey)throw new I.SwapKitError("toolbox_utxo_invalid_params");return{privateKey:B.privateKey,publicKey:B.publicKey}}function Q({phrase:Y,derivationPath:z="m/44'/133'/0'/0/0"}){let L=j({derivationPath:z,phrase:Y}),U=r2();return k.WIF(U).encode(L.privateKey)}function q(Y){return async function(L){if(!Y)throw new I.SwapKitError("toolbox_utxo_no_signer");return await Y.signTransaction(L)}}function G(Y){return async function(L){if(!Y)throw new I.SwapKitError("toolbox_utxo_no_signer");let U=await Y.signTransaction(L);return J.broadcastTx(U.toHex())}}return{...J,createKeysForPath:j,createTransaction:d2,getPrivateKeyFromMnemonic:Q,signAndBroadcastTransaction:G($),signTransaction:q($),transfer:Z,validateAddress:zX}}var cX,z2,U2,I,k,_X,c0;var B2=y(()=>{LX();BX();fX();cX=require("@scure/base"),z2=require("@scure/bip32"),U2=require("@scure/bip39"),I=require("@swapkit/helpers"),k=require("@swapkit/utxo-signer"),_X=require("ts-pattern");c0=cX.createBase58check(k.utils.sha256)});function a2({xpub:X,chain:$,count:J,startIndex:Z=0,accountIndex:j}){if(K("count",J),J<1)throw RangeError("count must be at least 1");K("startIndex",Z);let Q=v($),q=i2.HDKey.fromExtendedKey(X,Q.bip32),G=i({accountIndex:j,chain:$}),Y=JX(G),z=[];for(let L of[!1,!0]){let U=q.deriveChild(Number(L));for(let B=0;B<J;B++){let _=Z+B,N=U.deriveChild(_);if(!N.publicKey)continue;let O=YX({accountIndex:j,chain:$,change:L,index:_});z.push({accountIndex:Y,address:PX({chain:$,network:Q,publicKey:N.publicKey}),change:L,index:_,path:s2.derivationPathToString(O),pubkey:n2.hex.encode(N.publicKey)})}}return z}var n2,i2,s2;var t2=y(()=>{HX();BX();n2=require("@scure/base"),i2=require("@scure/bip32"),s2=require("@swapkit/helpers")});function i0(X,$){switch(X){case o.Chain.BitcoinCash:return L2($||{});case o.Chain.Zcash:return W2($);case o.Chain.Bitcoin:case o.Chain.Dogecoin:case o.Chain.Litecoin:case o.Chain.Dash:return XX({chain:X,...$});default:throw new o.SwapKitError("toolbox_utxo_not_supported",{chain:X})}}var o;var e2=y(()=>{oX();BX();B2();HX();t2();oX();fX();o=require("@swapkit/helpers")});var s0={};z0(s0,{validateZcashAddress:()=>zX,validateUtxoAddress:()=>Q2,validateBchAddress:()=>a,toLegacyAddress:()=>u,toCashAddress:()=>VX,stripToCashAddress:()=>EX,stripPrefix:()=>GX,nonSegwitChains:()=>FX,isValidAddress:()=>X2,getUtxoToolbox:()=>i0,getUtxoNetwork:()=>V0,getUtxoApi:()=>E,getUTXOAddressValidator:()=>G2,getUTXOAddressPath:()=>YX,getUTXOAccountPath:()=>i,getUTXOAccountIndexFromPath:()=>JX,getScriptTypeForAddress:()=>qX,getOutputSize:()=>kX,getNetworkForChain:()=>v,getInputSize:()=>s,getDustThreshold:()=>IX,detectAddressNetwork:()=>$2,deriveAddressesFromXpub:()=>a2,createZcashToolbox:()=>W2,createUTXOToolbox:()=>XX,createHDWalletHelpers:()=>O2,createCustomUtxoApi:()=>T0,createBCHToolbox:()=>L2,compileMemo:()=>A,calculateTxSize:()=>QX,assertDerivationIndex:()=>K,addressFromKeysGetter:()=>Y2,addInputsAndOutputs:()=>e,accumulative:()=>m,UtxoNetwork:()=>eX,UTXOScriptType:()=>xX,TX_OVERHEAD:()=>gX,SEGWIT_MARKER_FLAG_WEIGHT:()=>lX,OutputSizes:()=>bX,OP_RETURN_OVERHEAD:()=>g2,MIN_TX_FEE:()=>y0,InputSizes:()=>mX});module.exports=Y0(s0);var a0=y(()=>{BX();HX();LX();e2();oX();B2()});a0();
@@ -1 +1 @@
1
- var j0=Object.defineProperty;var Q0=(X)=>X;function G0(X,$){this[X]=Q0.bind(null,$)}var Y0=(X,$)=>{for(var J in $)j0(X,J,{get:$[J],enumerable:!0,configurable:!0,set:G0.bind($,J)})};var F=(X,$)=>()=>(X&&($=X(X=0)),$);var n1=((X)=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(X,{get:($,J)=>(typeof require<"u"?require:$)[J]}):X)(function(X){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+X+'" is not supported')});import{NetworkDerivationPath as q0}from"@swapkit/helpers";function A(X,$){if(!Number.isInteger($)||$<0)throw RangeError(`${X} must be a non-negative integer, got: ${$}`)}function o({accountIndex:X,chain:$,derivationPath:J}){if(X!==void 0)A("accountIndex",X);let Z=[...J?.slice(0,3)??q0[$].slice(0,3)];if(X!==void 0)Z[2]=X;return Z}function ZX({accountIndex:X,change:$=!1,chain:J,derivationPath:Z,index:j}){return A("index",j),[...o({accountIndex:X,chain:J,derivationPath:Z}),Number($),j]}function a(X){return X[2]??0}function W2({deriveAddress:X,getBalance:$,getUtxos:J}){async function Z(G){let{accountIndex:Q,count:L,startIndex:q=0,change:z=!1}=G;if(A("count",L),L<1)throw RangeError("count must be at least 1");A("startIndex",q);let W=[];for(let B=0;B<L;B++){let N=await X({accountIndex:Q,change:z,index:q+B});if(N)W.push(N)}return W}async function j(G){let{gapLimit:Q=20,change:L=!1}=G??{},q=[],z=0,W=0;while(z<Q){let B=await X({change:L,index:W});if(!B)break;if((await $(B.address)).some((b)=>b.getValue("number")>0))q.push(B),z=0;else z++;W++}return q}async function Y(G=20){let[Q,L]=await Promise.all([j({change:!1,gapLimit:G}),j({change:!0,gapLimit:G})]),q=[...Q,...L],z=await Promise.all(q.map(async(B)=>{let D=(await $(B.address)).reduce((b,s)=>b+s.getValue("number"),0);return{...B,balance:D}})),W=z.reduce((B,N)=>B+N.balance,0);return{addresses:z,total:W}}async function U(G=20){let[Q,L]=await Promise.all([j({change:!1,gapLimit:G}),j({change:!0,gapLimit:G})]),q=[...Q,...L];return(await Promise.all(q.map(async(W)=>{return(await J(W.address)).map((N)=>({...N,address:W.address,derivationIndex:W.index,isChange:W.change}))}))).flat()}return{deriveAddresses:Z,getAggregatedBalance:Y,getAggregatedUtxos:U,scanForAddresses:j}}var DX=()=>{};import{AssetValue as B2,getChainConfig as L0}from"@swapkit/helpers";import{SwapKitApi as z0}from"@swapkit/helpers/api";function _2(){function X(){let $=Date.now(),J=nX||$;return nX=J,$>nX?$:J+1}return U0+X().toString(36)}function N2(X){return async function(J,Z=!0){let j=await z0.getChainBalance({address:J,chain:X,scamFilter:Z}),{baseDecimal:Y}=L0(X),U=j.map(({identifier:Q,value:L,decimal:q})=>{return new B2({decimal:q||Y,identifier:Q,value:L})});if(!U.some((Q)=>Q.isGasAsset))return[B2.from({chain:X}),...U];return U}}var U0,nX=0;var iX=F(()=>{U0=typeof process<"u"&&process.pid?process.pid.toString(36):""});import{Chain as f,getRPCUrl as W0,RequestClient as vX,SKConfig as B0,SwapKitError as S,warnOnce as _0}from"@swapkit/helpers";import{NETWORKS as jX}from"@swapkit/utxo-signer";async function N0({chain:X,txHash:$}){let J=`${CX(X)}/push/transaction`,Z=JSON.stringify({data:$});try{let j=await vX.post(J,{body:Z,headers:{"Content-Type":"application/json"}});if(j.context.code!==200)throw new S("toolbox_utxo_broadcast_failed",{error:j.context.error||"Transaction broadcast failed"});return j.data?.transaction_hash||$}catch(j){let Y=await W0(X);if(Y){let U=JSON.stringify({id:_2(),jsonrpc:"2.0",method:"sendrawtransaction",params:[$]}),G=await vX.post(Y,{body:U,headers:{"Content-Type":"application/json"}});if(G.error)throw new S("toolbox_utxo_broadcast_failed",{error:G.error?.message});if(G.result.includes('"code":-26'))throw new S("toolbox_utxo_invalid_transaction",{error:"Transaction amount was too low"});return G.result}throw j}}function CX(X){return`https://api.blockchair.com/${M0(X)}`}function M2(X){switch(X){case f.Bitcoin:return 5;case f.Dogecoin:return 1e4;case f.Litecoin:return 1;case f.Zcash:return 1;default:return 2}}function M0(X){switch(X){case f.BitcoinCash:return"bitcoin-cash";case f.Litecoin:return"litecoin";case f.Dash:return"dash";case f.Dogecoin:return"dogecoin";case f.Zcash:return"zcash";case f.Polkadot:return"polkadot";default:return"bitcoin"}}async function D0(X){try{let{feePerKb:$}=await vX.get(`https://app.bitgo.com/api/v2/${X.toLowerCase()}/tx/fee`),J=$/1000;return Math.max(J,M2(X))}catch{return M2(X)}}async function wX(X,$){let J=await vX.get(`${X}${$?`${X.includes("?")?"&":"?"}key=${$}`:""}`);if(!J||J.context.code!==200)throw new S("toolbox_utxo_api_error",{error:`Failed to query ${X}`});return J.data}async function C2({address:X,chain:$,apiKey:J}){if(!X)throw new S("toolbox_utxo_invalid_params",{error:"Address is required"});try{return(await wX(`${CX($)}/dashboards/address/${X}?transaction_details=true`,J))[X]}catch{return{address:{balance:0,transaction_count:0},utxo:[]}}}async function C0({address:X,chain:$,apiKey:J}){return(await C2({address:X,apiKey:J,chain:$}))?.address.balance||0}async function H2({chain:X,apiKey:$,txHash:J}){if(!J)throw new S("toolbox_utxo_invalid_params",{error:"TxHash is required"});try{return(await wX(`${CX(X)}/raw/transaction/${J}`,$))?.[J]?.raw_transaction||""}catch(Z){let j=Z instanceof Error?Z.message:String(Z);return console.error(`Failed to fetch raw transaction: ${j}`),""}}async function O0({chain:X,apiKey:$,txHash:J}){if(!J)throw new S("toolbox_utxo_invalid_params",{error:"TxHash is required"});let j=(await wX(`${CX(X)}/dashboards/transaction/${J}`,$))?.[J];if(!j)throw new S("toolbox_utxo_tx_not_found",{txHash:J});let{transaction:Y,inputs:U,outputs:G}=j,Q=U.map((q)=>q.spending_sequence),L=Y.is_rbf===!0||Q.some((q)=>q<H0);return{blockId:Y.block_id,confirmed:Y.block_id!==-1,fee:Y.fee,inputs:U,isRBF:L,outputs:G,sequences:Q,size:Y.size,txid:Y.hash,weight:Y.weight}}async function T0({chain:X,address:$,apiKey:J,offset:Z=0,limit:j=30}){return(await wX(`${CX(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=${j}&offset=${Z}`,J)).map(({is_spent:Q,script_hex:L,block_id:q,transaction_hash:z,index:W,value:B,spending_signature_hex:N})=>({hash:z,index:W,is_confirmed:q!==-1,is_spent:Q,script_hex:L,txHex:N,value:B}))}function b0(X){return X.reduce(($,J)=>$+J.value,0)}function D2(X,$){let J=[...X].sort((Z,j)=>j.value-Z.value);if($){let Z=[],j=0;for(let Y of J)if(Z.push(Y),j+=Y.value,j>=$)break;return Z}return J}async function O2({chain:X,address:$,apiKey:J,targetValue:Z,accumulativeValue:j=0,offset:Y=0,limit:U=30}){if(!$)throw new S("toolbox_utxo_invalid_params",{error:"Address is required"});try{let G=await T0({address:$,apiKey:J,chain:X,limit:U,offset:Y,targetValue:Z}),L=G.length<U,q=G.filter(({is_spent:b})=>!b),z=b0(q),W=j+z,B=Z&&W>=Z;if(L||B)return D2(q,Z);let N=await O2({accumulativeValue:W,address:$,apiKey:J,chain:X,limit:U,offset:Y+U,targetValue:Z}),D=[...q,...N];return D2(D,Z)}catch(G){let Q=G instanceof Error?G.message:String(G);return console.error(`Failed to fetch unspent UTXOs: ${Q}`),[]}}async function V0({address:X,chain:$,apiKey:J,fetchTxHex:Z=!0,targetValue:j}){let Y=await O2({address:X,apiKey:J,chain:$,targetValue:j}),U=[];for(let{hash:G,index:Q,script_hex:L,value:q}of Y){let z;if(Z)z=await H2({apiKey:J,chain:$,txHash:G});U.push({address:X,hash:G,index:Q,txHex:z,value:q,witnessUtxo:{script:Buffer.from(L,"hex"),value:q}})}return U}function V(X){let $=B0.get("apiKeys").blockchair||"";return _0({condition:!$,id:"no_blockchair_api_key_warning",warning:"No Blockchair API key found. Functionality will be limited."}),{broadcastTx:(J)=>N0({chain:X,txHash:J}),getAddressData:(J)=>C2({address:J,apiKey:$,chain:X}),getBalance:(J)=>C0({address:J,apiKey:$,chain:X}),getRawTx:(J)=>H2({apiKey:$,chain:X,txHash:J}),getSuggestedTxFee:()=>D0(X),getTransactionDetails:(J)=>O0({apiKey:$,chain:X,txHash:J}),getUtxos:(J)=>V0({...J,apiKey:$,chain:X})}}function k0(X){return X}function I0(){return function($){switch($){case f.Bitcoin:return jX.bitcoin;case f.BitcoinCash:return jX.bitcoinCash;case f.Dash:return jX.dash;case f.Litecoin:return jX.litecoin;case f.Dogecoin:return jX.dogecoin;case f.Zcash:return jX.zcash;default:throw new S("toolbox_utxo_not_supported",{chain:$})}}}var H0=4294967294;var T2=F(()=>{iX()});import{CashAddrType as SX,decodeCashAddr as f0,encodeCashAddr as F0}from"@swapkit/utxo-signer";function R0(X,$,J){return F0({hash:J,prefix:X,type:E0[$]})}function y0(X){let $=f0(X),J=P0[$.type];if(!J)throw Error(`Unknown CashAddr type: ${$.type}`);return{hash:$.hash,prefix:$.prefix,type:J}}var E0,P0,sX;var b2=F(()=>{E0={P2PKH:SX.P2PKH,P2SH:SX.P2SH},P0={[SX.P2PKH]:"P2PKH",[SX.P2SH]:"P2SH"};sX={decode:y0,encode:R0}});import{sha256 as A0}from"@noble/hashes/sha2.js";import{createBase58check as v0}from"@scure/base";import{SwapKitError as k2}from"@swapkit/helpers";function tX(X){try{return KX(X),!0}catch{return!1}}function eX(X){return KX(X)?.network}function l(X){let $=KX(X);if($?.format==="legacy")return X;return K0($)}function HX(X){let $=KX(X);return g0($)}function KX(X){try{let $=w0(X);if($)return $}catch{}try{let $=S0(X);if($)return $}catch{}throw new k2("toolbox_utxo_invalid_address",{address:X})}function w0(X){try{let $=I2.decode(X);if($.length!==21)throw new k2("toolbox_utxo_invalid_address",{address:X});let J=$[0],Z=Array.prototype.slice.call($,1);switch(J){case t.legacy.mainnet.p2pkh:return{format:"legacy",hash:Z,network:"mainnet",type:"p2pkh"};case t.legacy.mainnet.p2sh:return{format:"legacy",hash:Z,network:"mainnet",type:"p2sh"};case t.legacy.testnet.p2pkh:return{format:"legacy",hash:Z,network:"testnet",type:"p2pkh"};case t.legacy.testnet.p2sh:return{format:"legacy",hash:Z,network:"testnet",type:"p2sh"};case t.bitpay.mainnet.p2pkh:return{format:"bitpay",hash:Z,network:"mainnet",type:"p2pkh"};case t.bitpay.mainnet.p2sh:return{format:"bitpay",hash:Z,network:"mainnet",type:"p2sh"};default:return}}catch{return}}function S0(X){if(X.indexOf(":")!==-1)try{return V2(X)}catch{}else{let $=["bitcoincash","bchtest","bchreg"];for(let J of $)try{return V2(`${J}:${X}`)}catch{}}return}function V2(X){try{let{hash:$,prefix:J,type:Z}=sX.decode(X);return{format:"cashaddr",hash:Array.prototype.slice.call($,0),network:J==="bitcoincash"?"mainnet":"testnet",type:Z==="P2PKH"?"p2pkh":"p2sh"}}catch{return}}function K0(X){let $=t.legacy[X.network][X.type],J=Buffer.alloc(1+X.hash.length);return J[0]=$,J.set(X.hash,1),I2.encode(J)}function g0(X){let $=X.network==="mainnet"?"bitcoincash":"bchtest",J=X.type==="p2pkh"?"P2PKH":"P2SH",Z=new Uint8Array(X.hash);return sX.encode($,J,Z)}var I2,aX,t;var f2=F(()=>{b2();I2=v0(A0);((J)=>{J.Mainnet="mainnet";J.Testnet="testnet"})(aX||={});t={["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 m0}from"@swapkit/helpers";import{Script as l0}from"@swapkit/utxo-signer";function P(X){let $=new Uint8Array(Buffer.from(X,"utf8"));return l0.encode(["RETURN",$])}var x0=1000,mX=10,lX=2,F2=10,h0=41,p0=107,xX,gX,OX,QX=(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 m0("toolbox_utxo_invalid_address",{address:X})},e=({inputs:X,outputs:$,feeRate:J})=>{let Z=X[0]&&"address"in X[0]&&X[0].address?QX(X[0].address):"P2PKH",Y=(J?X.filter((L)=>L.value>=gX["type"in L&&L.type?L.type:"P2PKH"]*Math.ceil(J)):X).reduce((L,q)=>L+c(q),0),U=$?.reduce((L,q)=>L+TX(q),0)||OX[Z],G=mX+Y+U;return Z==="P2WPKH"?Math.ceil(G+lX/4):G},c=(X)=>{if("type"in X&&X.type)return gX[X.type];if("address"in X&&X.address)return gX[QX(X.address)];return h0+p0},TX=(X,$)=>{if(X?.script)return F2+X.script.length+(X.script.length>=74?2:1);if($)return OX[$];if("address"in X&&X.address)return OX[QX(X.address)];return OX.P2PKH};var X2=F(()=>{((J)=>{J.P2PKH="P2PKH";J.P2WPKH="P2WPKH"})(xX||={});gX={["P2PKH"]:148,["P2WPKH"]:68},OX={["P2PKH"]:34,["P2WPKH"]:31}});import{Chain as XX,SwapKitError as u0}from"@swapkit/helpers";function bX(X){switch(X){case XX.Bitcoin:case XX.BitcoinCash:return 550;case XX.Dash:case XX.Litecoin:return 5500;case XX.Dogecoin:return 1e5;case XX.Zcash:return 546;default:throw new u0("toolbox_utxo_not_supported",{chain:X})}}function v({inputs:X,outputs:$,feeRate:J=1,chain:Z=XX.Bitcoin,changeAddress:j=""}){let Y=X[0]&&"address"in X[0]&&X[0].address?QX(X[0].address):"P2PKH",U=X.filter((N)=>c(N)*J<=N.value),Q=Y==="P2WPKH"?Math.ceil(lX/4):0,L=mX+Q+$.reduce((N,D)=>N+TX(D),0),q=$.reduce((N,D)=>N+D.value,0),z=L*J,W=0,B=[];for(let N of U){let D=c(N),b=J*D;z+=b,W+=N.value,B.push(N);let s=z+q;if(W<s)continue;let cX=W-s,_X=J*TX({address:j,value:0});if(cX>_X){let NX=_X+z,EX=W-(q+Math.ceil(NX));if(EX>Math.max(c({value:0})*J,bX(Z)))return{fee:Math.ceil(NX),inputs:B,outputs:$.concat({address:j,value:EX})}}return{fee:Math.ceil(z),inputs:B,outputs:$}}return{fee:Math.ceil(J*e({inputs:X,outputs:$}))}}var E2=F(()=>{X2()});var GX=F(()=>{T2();f2();E2();X2()});import{Address as o0,ZCASH_NETWORK as c0}from"@swapkit/utxo-signer";function $X(X){return X.replace(/(bchtest:|bitcoincash:)/,"")}function d(X){let $=$X(X);return tX($)&&eX($)==="mainnet"}function YX(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 J=o0(c0).decode(X);return J.type==="pkh"||J.type==="sh"}catch{return!1}}var VX=F(()=>{GX()});import{secp256k1 as d0}from"@noble/curves/secp256k1.js";import{hex as JX}from"@scure/base";import{HDKey as A2}from"@scure/bip32";import{mnemonicToSeedSync as J2}from"@scure/bip39";import{AssetValue as hX,applyFeeMultiplier as P2,Chain as k,derivationPathToString as kX,FeeOption as K,NetworkDerivationPath as v2,SwapKitError as T,SwapKitNumber as r0,updateDerivationPath as n0,warnOnce as i0}from"@swapkit/helpers";import{Address as s0,BCHSigHash as Z2,CashAddrPrefix as a0,CashAddrType as t0,encodeCashAddr as e0,NETWORKS as qX,p2pkh as R2,p2wpkh as X1,RBF_SEQUENCE as $1,SigHash as w2,Transaction as $2,WIF as S2}from"@swapkit/utxo-signer";import{match as K2}from"ts-pattern";function j2({address:X,chain:$}){return K2($).with(k.BitcoinCash,()=>d(X)).with(k.Zcash,()=>YX(X)).otherwise(()=>{try{return s0(E($)).decode(X),!0}catch{return!1}})}function E(X){return K2(X).with(k.Bitcoin,()=>qX.bitcoin).with(k.BitcoinCash,()=>qX.bitcoinCash).with(k.Dash,()=>qX.dash).with(k.Dogecoin,()=>qX.dogecoin).with(k.Litecoin,()=>qX.litecoin).with(k.Zcash,()=>qX.zcash).exhaustive()}function J1({phrase:X,derivationPath:$,network:J,seed:Z}){let j=Z??J2(X),U=A2.fromMasterSeed(j,J.bip32).derive($);if(!U.privateKey)throw new T("toolbox_utxo_invalid_params",{error:"Could not derive private key from phrase"});return U.privateKey}function y2(X){return d0.getPublicKey(X,!0)}function fX({publicKey:X,chain:$,network:J}){if($===k.BitcoinCash){let Y=R2(X,J);if(!Y.hash)throw new T("toolbox_utxo_invalid_address",{error:"Could not derive BCH address hash"});return e0({hash:Y.hash,prefix:a0.MAINNET,type:t0.P2PKH}).replace(/^bitcoincash:/,"")}let j=!IX.includes($)?X1(X,J):R2(X,J);if(!j.address)throw new T("toolbox_utxo_invalid_address",{error:"Could not derive address"});return j.address}function LX({phrase:X,derivationPath:$,chain:J,wif:Z,seed:j}){let Y=E(J);if(Z){let L=S2(Y).decode(Z),q=y2(L);return{privateKey:L,publicKey:q}}if(!X)throw new T("toolbox_utxo_invalid_params",{error:"Either phrase or wif must be provided"});let U=$||kX(v2[J]),G=J1({derivationPath:U,network:Y,phrase:X,seed:j}),Q=y2(G);return{privateKey:G,publicKey:Q}}function Z1(X,$){return S2(E($)).encode(X)}function j1({phrase:X,derivationPath:$,chain:J,seed:Z}){let j=$.split("/");if(j.length<4)throw new T("toolbox_utxo_invalid_params",{error:`Derivation path must have at least 4 levels (got ${j.length}): ${$}`});let Y=E(J),U=Z??J2(X),G=A2.fromMasterSeed(U,Y.bip32),Q=j.slice(0,4).join("/");return G.derive(Q)}function r({inputs:X,outputs:$,chain:J,tx:Z,sender:j,compiledMemo:Y,enableRBF:U=!1}){let G=E(J),Q=!IX.includes(J),L=U?$1:void 0,q=new Set;for(let z of X){let W=`${z.hash}:${z.index}`;if(q.has(W))throw new T("toolbox_utxo_invalid_params",{error:"Duplicate input detected"});q.add(W);let B=typeof z.hash==="string"?JX.decode(z.hash):z.hash;if(Q&&z.witnessUtxo)Z.addInput({index:z.index,sequence:L,txid:B,witnessUtxo:{amount:BigInt(z.witnessUtxo.value),script:z.witnessUtxo.script}});else if(z.txHex)Z.addInput({index:z.index,nonWitnessUtxo:JX.decode(z.txHex),sequence:L,txid:B,...J===k.BitcoinCash?{sighashType:Z2.ALL}:{}});else throw new T("toolbox_utxo_invalid_params",{error:"Input requires either witnessUtxo or txHex for non-segwit chains"})}for(let z of $){let W="address"in z&&z.address?z.address:j;if(J===k.BitcoinCash)W=l(W);if(z.script){if(Y)Z.addOutput({amount:0n,script:Y})}else Z.addOutputAddress(W,BigInt(z.value),G)}return{inputs:X,tx:Z}}async function zX(X){let $=await V(X).getSuggestedTxFee();return{[K.Average]:$,[K.Fast]:P2($,K.Fast),[K.Fastest]:P2($,K.Fastest)}}async function g2({assetValue:X,recipient:$,memo:J,sender:Z,fetchTxHex:j=!1}){let Y=X.chain,U=(await zX(Y))[K.Fastest],G=j||IX.includes(Y),Q=X.getBaseValue("number"),L=Math.ceil(Q+U*5000);return{inputs:await V(Y).getUtxos({address:Z,fetchTxHex:G,targetValue:L}),outputs:[{address:$,value:Q},...J?[{address:"",script:P(J),value:0}]:[]]}}async function m2({assetValue:X,recipient:$,memo:J,feeRate:Z,sender:j,fetchTxHex:Y=!1,enableRBF:U=!1}){let G=X.chain,Q=J?P(J):null,L=await g2({assetValue:X,fetchTxHex:Y,memo:J,recipient:$,sender:j}),{inputs:q,outputs:z}=v({...L,chain:G,feeRate:Z});if(!(q&&z))throw new T("toolbox_utxo_insufficient_balance",{assetValue:X,sender:j});let W=new $2({allowLegacyWitnessUtxo:!0,allowUnknownOutputs:!!Q,version:1}),{inputs:B,tx:N}=r({chain:G,compiledMemo:Q,enableRBF:U,inputs:q,outputs:z,sender:j,tx:W});return{inputs:B,tx:N,utxos:L.inputs}}async function l2({assetValue:X,feeOptionKey:$=K.Fast,feeRate:J,memo:Z,sender:j,recipient:Y}){let U=X.chain,G=await g2({assetValue:X,memo:Z,recipient:Y,sender:j}),Q=J?Math.floor(J):(await zX(U))[$];return v({...G,chain:U,feeRate:Q})}function Q1(X){return async function({from:J,memo:Z,feeRate:j,feeOptionKey:Y=K.Fast,recipients:U=1}){let G=await V(X).getAddressData(J),Q=j?Math.ceil(j):(await zX(X))[Y],L=G?.utxo.map((D)=>({...D,hash:"",type:"P2PKH"})).filter((D)=>D.value>Math.max(bX(X),c(D)*Q));if(!L?.length)return hX.from({chain:X});let q=BigInt(L.reduce((D,b)=>D+b.value,0)),z=hX.from({chain:X,value:q}),W=typeof U==="number"?Array.from({length:U},()=>({address:J,value:0})):U;if(Z)W.push({address:J,script:P(Z),value:0});let B=e({inputs:L,outputs:W}),N=hX.from({chain:X,value:BigInt(B*Q)});return z.sub(N)}}function G1(X){return async function(J){let{fee:Z}=await l2(J);return hX.from({chain:X,value:r0.fromBigInt(BigInt(Z),8).getValue("string")})}}function Y1({chain:X,phrase:$,derivationPath:J,seed:Z}){let j=E(X),{privateKey:Y,publicKey:U}=LX({chain:X,derivationPath:J,phrase:$,seed:Z}),G=X===k.BitcoinCash?[Z2.ALL]:[w2.ALL];return{getAddress:()=>fX({chain:X,network:j,publicKey:U}),privateKey:Y,publicKey:U,signTransaction:(Q)=>{return Q.sign(Y,G),Q}}}function q1(X,$){return async function({memo:Z,recipient:j,feeOptionKey:Y,feeRate:U,assetValue:G,enableRBF:Q=!1}){let L=$?.getAddress();if(!($&&L))throw new T("toolbox_utxo_no_signer");if(!j)throw new T("toolbox_utxo_invalid_params",{error:"Recipient address must be provided"});i0({condition:Q&&!pX.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 q=Q&&pX.includes(X),z=U||(await zX(X))[Y||K.Fast],{tx:W}=await m2({assetValue:G,enableRBF:q,feeRate:z,memo:Z,recipient:j,sender:L});return $.signTransaction(W),W.finalize(),V(X).broadcastTx(JX.encode(W.extract()))}}function Q2(X){return($)=>j2({address:$,chain:X})}function G2(X){let $=E(X);return function(Z){if(!Z)throw new T("toolbox_utxo_invalid_params",{error:"Keys must be provided"});return fX({chain:X,network:$,publicKey:Z.publicKey})}}function n({chain:X,...$}){let J="phrase"in $?$.phrase:void 0,Z="index"in $?$.index||0:0,j=J?J2(J):void 0,Y="derivationPath"in $&&$.derivationPath?$.derivationPath:n0(v2[X],{index:Z}),U=kX(Y),G=J?Y1({chain:X,derivationPath:U,phrase:J,seed:j}):void 0,Q="signer"in $?$.signer:void 0,L=J?LX({chain:X,derivationPath:U,phrase:J,seed:j}):void 0;function q(){if(G)return Promise.resolve(G.getAddress());if(Q)return Q.getAddress();return Promise.resolve(void 0)}function z(_){if(!J)return;let M=o({accountIndex:_,chain:X,derivationPath:Y});return j1({chain:X,derivationPath:kX(M),phrase:J,seed:j})}let W=z();function B(){if(!W)return;return W.publicExtendedKey}function N({accountIndex:_}={}){let M=_===void 0?W:z(_);if(!M)return;let C=o({accountIndex:_,chain:X,derivationPath:Y});return{accountIndex:a(C),path:kX(C),xpub:M.publicExtendedKey}}function D({accountIndex:_,index:M,change:C=!1}){let O=_===void 0?W:z(_);if(!O)return;let H=ZX({accountIndex:_,chain:X,change:C,derivationPath:Y,index:M}),R=E(X),w=O.deriveChild(Number(C)).deriveChild(M);if(!w.publicKey)throw new T("toolbox_utxo_invalid_params",{error:"Could not derive public key"});let y=fX({chain:X,network:R,publicKey:w.publicKey}),x=JX.encode(w.publicKey);return{accountIndex:a(H),address:y,change:C,index:M,path:kX(H),pubkey:x}}async function b(_){if(!pX.includes(X))return{reason:`RBF is not supported on ${X}`,supported:!1};let M=await V(X).getTransactionDetails(_);return{canReplace:M.isRBF&&!M.confirmed,confirmed:M.confirmed,enabled:M.isRBF,fee:M.fee,sequences:M.sequences,supported:!0}}async function s({txid:_,newFeeRate:M,recipient:C,memo:O}){if(!pX.includes(X))throw new T("toolbox_utxo_rbf_not_supported",{chain:X});let H=await V(X).getTransactionDetails(_);if(!H.isRBF)throw new T("toolbox_utxo_tx_not_replaceable",{txid:_});if(H.confirmed)throw new T("toolbox_utxo_tx_already_confirmed",{blockId:H.blockId,txid:_});let R=H.inputs.reduce((I,u)=>I+u.value,0),y=H.outputs.find((I)=>I.recipient===C)?.value||0;if(y===0)throw new T("toolbox_utxo_invalid_params",{error:"Could not determine send amount from original transaction"});let x=await Promise.all(H.inputs.map(async(I)=>{let u=await V(X).getRawTx(I.transaction_hash);return{hash:I.transaction_hash,index:I.index,txHex:u,value:I.value,witnessUtxo:void 0}})),PX=O?P(O):null,dX=e({feeRate:M,inputs:x.map((I)=>({...I,type:"P2WPKH"})),outputs:[{address:C,value:y}]}),m=Math.ceil(dX*M);if(m<=H.fee)throw new T("toolbox_utxo_rbf_fee_too_low",{newFee:m,originalFee:H.fee});let MX=m-H.fee,h=y-MX;if(h<=0)throw new T("toolbox_utxo_rbf_insufficient_change");let RX=new $2({allowLegacyWitnessUtxo:!0,version:1}),yX=[{address:C,value:h},...O?[{address:"",script:P(O),value:0}]:[]],AX=R-h-m,p=await q();if(AX>bX(X)&&p)yX.push({address:p,value:AX});return r({chain:X,compiledMemo:PX,inputs:x,outputs:yX,sender:p||C,tx:RX}),{feeDelta:MX,newFee:m,originalFee:H.fee,tx:RX}}async function cX({txid:_,newFeeRate:M,recipient:C,memo:O}){if(!G)throw new T("toolbox_utxo_no_signer");let{tx:H,originalFee:R,newFee:w}=await s({memo:O,newFeeRate:M,recipient:C,txid:_});G.signTransaction(H),H.finalize();let y=await V(X).broadcastTx(JX.encode(H.extract()));return{newFee:w,originalFee:R,txid:y}}function _X({accountIndex:_,index:M,change:C=!1}){A("index",M);let O=_===void 0?W:z(_);if(!O)return;return O.deriveChild(Number(C)).deriveChild(M).privateKey||void 0}function NX({tx:_,inputDerivations:M}){if(!W)throw new T("toolbox_utxo_no_signer");let C=X===k.BitcoinCash?[Z2.ALL]:[w2.ALL];for(let O=0;O<M.length;O++){let H=M[O];if(!H)continue;let{derivationIndex:R,isChange:w}=H,y=_X({change:w,index:R});if(!y)throw new T("toolbox_utxo_invalid_params",{error:`Could not derive private key for input ${O} at index ${R}`});_.signIdx(y,O,C)}return _}async function EX({utxos:_,recipient:M,assetValue:C,memo:O,feeRate:H,feeOptionKey:R,changeAddress:w}){if(!W)throw new T("toolbox_utxo_no_signer");let y=H||(await zX(X))[R||K.Fast],x=O?P(O):null,PX=[{address:M,value:C.getBaseValue("number")}];if(x)PX.push({address:"",script:x,value:0});let dX=_.map(({hash:p,index:I,value:u,txHex:Z0,witnessUtxo:rX})=>({hash:p,index:I,txHex:Z0,value:u,witnessUtxo:rX?{script:rX.script,value:rX.value}:void 0})),{inputs:m,outputs:MX}=v({chain:X,feeRate:y,inputs:dX,outputs:PX});if(!(m&&MX))throw new T("toolbox_utxo_insufficient_balance",{assetValue:C,sender:"multiple addresses"});let h=new $2({allowLegacyWitnessUtxo:!0,version:1}),RX=_[0]?.address,yX=w||await q()||RX||M;r({chain:X,compiledMemo:x,inputs:m,outputs:MX,sender:yX,tx:h});let AX=m.map((p)=>{let I=_.find((u)=>u.hash===p.hash&&u.index===p.index);return I?{derivationIndex:I.derivationIndex,isChange:I.isChange}:{derivationIndex:0,isChange:!1}});return NX({inputDerivations:AX,tx:h}),h.finalize(),V(X).broadcastTx(JX.encode(h.extract()))}function J0({address:_,gapLimit:M=20}){if(!W)return;for(let C=0;C<M;C++){let O=D({change:!1,index:C}),H=D({change:!0,index:C}),R=O?.address===_?!1:H?.address===_;if(O?.address===_||H?.address===_)return{change:R,index:C}}return}return{accumulative:v,broadcastTx:(_)=>V(X).broadcastTx(_),bumpFee:cX,calculateTxSize:e,createKeysForPath:(_)=>LX({..._,chain:X}),createReplacementTransaction:s,createTransaction:m2,deriveAddressAtIndex:D,derivePrivateKeyAtIndex:_X,estimateMaxSendableAmount:Q1(X),estimateTransactionFee:G1(X),getAddress:q,getAddressFromKeys:G2(X),getBalance:N2(X),getExtendedPublicKey:B,getExtendedPublicKeyInfo:N,getFeeRates:()=>zX(X),getInputsOutputsFee:l2,getNetworkForChain:()=>E(X),getPrivateKeyFromMnemonic:(_)=>Z1(LX({..._,chain:X}).privateKey,X),isRBFEnabled:b,keys:L,resolveDerivationIndex:J0,signAndBroadcastTransaction:async(_)=>{if(!G)throw new T("toolbox_utxo_no_signer");return G.signTransaction(_),_.finalize(),await V(X).broadcastTx(JX.encode(_.extract()))},signTransactionWithMultipleKeys:NX,transfer:q1(X,G),transferFromMultipleAddresses:EX,validateAddress:Q2(X)}}var IX,pX;var UX=F(()=>{iX();DX();GX();VX();IX=[k.Dash,k.Dogecoin,k.Zcash,k.BitcoinCash],pX=[k.Bitcoin]});import{hex as L1}from"@scure/base";import{Chain as z1,derivationPathToString as U1,FeeOption as W1,NetworkDerivationPath as B1,SwapKitError as i,updateDerivationPath as _1}from"@swapkit/helpers";import{BCHSigHash as N1,CashAddrPrefix as x2,CashAddrType as h2,encodeCashAddr as p2,NETWORKS as M1,p2pkh as u2,Transaction as o2}from"@swapkit/utxo-signer";function FX(X){return $X(HX(X))}function D1(X){let $=E(g);function J(j){return j.sign(X.privateKey,[N1.ALL]),j}function Z(){let j=u2(X.publicKey,$);if(!j.hash)throw new i("toolbox_utxo_invalid_address",{error:"Could not derive BCH address hash"});let Y=p2({hash:j.hash,prefix:x2.MAINNET,type:h2.P2PKH});return Promise.resolve(Y.replace(/^bitcoincash:/,""))}return{getAddress:Z,signTransaction:J}}function Y2(X){let $="phrase"in X?X.phrase:void 0,J="index"in X?X.index||0:0,Z=U1("derivationPath"in X&&X.derivationPath?X.derivationPath:_1(B1[g],{index:J})),j=$?LX({chain:g,derivationPath:Z,phrase:$}):void 0,Y=j?D1(j):("signer"in X)?X.signer:void 0;function U(){return Promise.resolve(Y?.getAddress())}let{getBalance:G,getFeeRates:Q,broadcastTx:L,...q}=n({chain:g});function z(W,B=!0){return G($X(HX(W)))}return{...q,broadcastTx:L,buildTx:H1,createTransaction:c2,getAddress:U,getAddressFromKeys:O1,getBalance:z,getFeeRates:Q,stripPrefix:$X,stripToCashAddress:FX,transfer:C1({broadcastTx:L,getFeeRates:Q,signer:Y}),validateAddress:d}}async function c2({assetValue:X,recipient:$,memo:J,feeRate:Z,sender:j}){if(!d($))throw new i("toolbox_utxo_invalid_address",{address:$});let Y=Math.ceil(X.getBaseValue("number")+Z*7500),U=await V(g).getUtxos({address:FX(j),fetchTxHex:!0,targetValue:Y}),G=J?P(J):null,Q=[],L=l($);if(Q.push({address:L,value:X.getBaseValue("number")}),G)Q.push({script:G,value:0});let{inputs:q,outputs:z}=v({chain:g,feeRate:Z,inputs:U,outputs:Q});if(!(q&&z))throw new i("toolbox_utxo_insufficient_balance",{assetValue:X,sender:j});let W=new o2({allowLegacyWitnessUtxo:!0,allowUnknownOutputs:!!G,version:1}),B=l(j),{inputs:N,tx:D}=r({chain:g,compiledMemo:G,inputs:q,outputs:z.map((b)=>("address"in b)&&b.address?{...b,address:l(b.address)}:b),sender:B,tx:W});return{inputs:N,tx:D,utxos:q}}function C1({broadcastTx:X,getFeeRates:$,signer:J}){return async function({recipient:j,assetValue:Y,feeOptionKey:U=W1.Fast,...G}){let Q=await J?.getAddress();if(!(J&&Q))throw new i("toolbox_utxo_no_signer");if(!j)throw new i("toolbox_utxo_invalid_params",{error:"Recipient address must be provided"});let L=G.feeRate||(await $())[U],{tx:q}=await c2({...G,assetValue:Y,feeRate:L,recipient:j,sender:Q}),z=await J.signTransaction(q);return z.finalize(),X(L1.encode(z.extract()))}}async function H1({assetValue:X,recipient:$,memo:J,feeRate:Z,sender:j}){let Y=HX($);if(!d(Y))throw new i("toolbox_utxo_invalid_address",{address:Y});let U=Math.ceil(X.getBaseValue("number")+Z*7500),G=await V(g).getUtxos({address:FX(j),fetchTxHex:!0,targetValue:U}),Q=Number(Z.toFixed(0)),L=J?P(J):null,q=[];if(q.push({address:l($),value:X.getBaseValue("number")}),L)q.push({script:L,value:0});let{inputs:z,outputs:W}=v({chain:g,feeRate:Q,inputs:G,outputs:q});if(!(z&&W))throw new i("toolbox_utxo_insufficient_balance",{assetValue:X,sender:j});let B=new o2({allowLegacyWitnessUtxo:!0,allowUnknownOutputs:!!L,version:1}),{inputs:N,tx:D}=r({chain:g,compiledMemo:L,inputs:z,outputs:W,sender:l(j),tx:B});return{inputs:N,tx:D,utxos:G}}function O1(X){let $=M1.bitcoinCash,J=u2(X.publicKey,$);if(!J.hash)throw new i("toolbox_utxo_invalid_address",{error:"Could not derive BCH address hash"});return p2({hash:J.hash,prefix:x2.MAINNET,type:h2.P2PKH}).replace(/^bitcoincash:/,"")}var g;var uX=F(()=>{GX();UX();VX();g=z1.BitcoinCash});import{createBase58check as T1,hex as b1}from"@scure/base";import{HDKey as n2}from"@scure/bip32";import{mnemonicToSeedSync as i2}from"@scure/bip39";import{Chain as oX,derivationPathToString as V1,FeeOption as k1,NetworkDerivationPath as I1,SKConfig as s2,SwapKitError as WX,updateDerivationPath as f1}from"@swapkit/helpers";import{Address as F1,createZcashTransaction as E1,OutScript as P1,PCZT as R1,utils as a2,WIF as y1,ZCASH_NETWORK as A1,ZCASH_TEST_NETWORK as v1,ZcashConsensusBranchId as w1,ZcashSigHash as d2,ZcashVersionGroupId as S1}from"@swapkit/utxo-signer";import{match as K1,P as q2}from"ts-pattern";function t2(){let{isStagenet:X}=s2.get("envs");return X?v1:A1}function m1(X){return g1.encode(X)}function l1({phrase:X,derivationPath:$}){let J=i2(X),j=n2.fromMasterSeed(J).derive($);if(!j.privateKey||!j.publicKey)throw new WX("toolbox_utxo_invalid_params");let{privateKey:Y,publicKey:U}=j,G=a2.hash160(U),{isStagenet:Q}=s2.get("envs"),L=Q?new Uint8Array([29,37]):new Uint8Array([28,184]),q=new Uint8Array(L.length+G.length);q.set(L,0),q.set(G,L.length);let z=m1(q);return{getAddress:()=>Promise.resolve(z),signTransaction:(W)=>{if(W instanceof R1)return W.signAllInputs(Y,U,d2.ALL),W.finalizeAllInputs(),Promise.resolve(W.extract());return W.signAllInputs(Y,U,d2.ALL),Promise.resolve(W)}}}function x1({inputs:X,outputs:$,tx:J,sender:Z,compiledMemo:j}){let Y=t2();for(let U of X){let G=F1(Y).decode(Z),Q=P1.encode(G);J.addInput({index:U.index,script:Q,sequence:4294967295,txid:b1.decode(U.hash),value:BigInt(U.value)})}for(let U of $){let G="address"in U&&U.address?U.address:Z,Q=U.script;if(Q&&!j)continue;if(Q&&j)J.addOutput({amount:0n,script:j});else J.addOutputAddress(G,BigInt(U.value),Y)}return{inputs:X,tx:J}}async function r2(X){let{assetValue:$,recipient:J,memo:Z,feeRate:j,sender:Y,fetchTxHex:U}=X,G=Z?P(Z):null,Q=await V(oX.Zcash).getUtxos({address:Y,fetchTxHex:U!==!1}),L=[{address:J,value:Number($.getBaseValue("string"))},...G?[{script:G,value:0}]:[]],{inputs:q,outputs:z}=v({chain:oX.Zcash,changeAddress:Y,feeRate:j,inputs:Q,outputs:L});if(!(q&&z))throw new WX("toolbox_utxo_insufficient_balance",{assetValue:$,sender:Y});let W=E1({consensusBranchId:w1.NU6_1,expiryHeight:0,lockTime:0,version:4,versionGroupId:S1.SAPLING}),{tx:B,inputs:N}=x1({compiledMemo:G,inputs:q,outputs:z,sender:Y,tx:W});return{inputs:N,outputs:z,tx:B}}function L2(X){let $=K1(X).with({signer:q2.not(q2.nullish)},({signer:Q})=>Q).with({phrase:q2.string},({phrase:Q,derivationPath:L,index:q=0})=>{let z=L||I1[oX.Zcash]||[44,133,0,0,0],W=f1(z,{index:q}),B=V1(W);return l1({derivationPath:B,phrase:Q})}).otherwise(()=>{return}),J=n({chain:oX.Zcash,signer:$});async function Z({recipient:Q,assetValue:L,feeOptionKey:q=k1.Fast,...z}){let W=await $?.getAddress();if(!($&&W))throw new WX("toolbox_utxo_no_signer");let B=z.feeRate||(await J.getFeeRates())[q],{tx:N}=await r2({...z,assetValue:L,feeRate:B,recipient:Q,sender:W}),b=(await $.signTransaction(N)).toHex();return J.broadcastTx(b)}function j({phrase:Q,derivationPath:L="m/44'/133'/0'/0/0"}){let q=i2(Q),W=n2.fromMasterSeed(q).derive(L);if(!W.privateKey||!W.publicKey)throw new WX("toolbox_utxo_invalid_params");return{privateKey:W.privateKey,publicKey:W.publicKey}}function Y({phrase:Q,derivationPath:L="m/44'/133'/0'/0/0"}){let q=j({derivationPath:L,phrase:Q}),z=t2();return y1(z).encode(q.privateKey)}function U(Q){return async function(q){if(!Q)throw new WX("toolbox_utxo_no_signer");return await Q.signTransaction(q)}}function G(Q){return async function(q){if(!Q)throw new WX("toolbox_utxo_no_signer");let z=await Q.signTransaction(q);return J.broadcastTx(z.toHex())}}return{...J,createKeysForPath:j,createTransaction:r2,getPrivateKeyFromMnemonic:Y,signAndBroadcastTransaction:G($),signTransaction:U($),transfer:Z,validateAddress:YX}}var g1;var z2=F(()=>{GX();UX();VX();g1=T1(a2.sha256)});import{hex as h1}from"@scure/base";import{HDKey as p1}from"@scure/bip32";import{derivationPathToString as u1}from"@swapkit/helpers";function e2({xpub:X,chain:$,count:J,startIndex:Z=0,accountIndex:j}){if(A("count",J),J<1)throw RangeError("count must be at least 1");A("startIndex",Z);let Y=E($),U=p1.fromExtendedKey(X,Y.bip32),G=o({accountIndex:j,chain:$}),Q=a(G),L=[];for(let q of[!1,!0]){let z=U.deriveChild(Number(q));for(let W=0;W<J;W++){let B=Z+W,N=z.deriveChild(B);if(!N.publicKey)continue;let D=ZX({accountIndex:j,chain:$,change:q,index:B});L.push({accountIndex:Q,address:fX({chain:$,network:Y,publicKey:N.publicKey}),change:q,index:B,path:u1(D),pubkey:h1.encode(N.publicKey)})}}return L}var X0=F(()=>{DX();UX()});import{Chain as BX,SwapKitError as o1}from"@swapkit/helpers";function c1(X,$){switch(X){case BX.BitcoinCash:return Y2($||{});case BX.Zcash:return L2($);case BX.Bitcoin:case BX.Dogecoin:case BX.Litecoin:case BX.Dash:return n({chain:X,...$});default:throw new o1("toolbox_utxo_not_supported",{chain:X})}}var $0=F(()=>{uX();UX();z2();DX();X0();uX();VX()});var d1={};Y0(d1,{validateZcashAddress:()=>YX,validateUtxoAddress:()=>j2,validateBchAddress:()=>d,toLegacyAddress:()=>l,toCashAddress:()=>HX,stripToCashAddress:()=>FX,stripPrefix:()=>$X,nonSegwitChains:()=>IX,isValidAddress:()=>tX,getUtxoToolbox:()=>c1,getUtxoNetwork:()=>I0,getUtxoApi:()=>V,getUTXOAddressValidator:()=>Q2,getUTXOAddressPath:()=>ZX,getUTXOAccountPath:()=>o,getUTXOAccountIndexFromPath:()=>a,getScriptTypeForAddress:()=>QX,getOutputSize:()=>TX,getNetworkForChain:()=>E,getInputSize:()=>c,getDustThreshold:()=>bX,detectAddressNetwork:()=>eX,deriveAddressesFromXpub:()=>e2,createZcashToolbox:()=>L2,createUTXOToolbox:()=>n,createHDWalletHelpers:()=>W2,createCustomUtxoApi:()=>k0,createBCHToolbox:()=>Y2,compileMemo:()=>P,calculateTxSize:()=>e,assertDerivationIndex:()=>A,addressFromKeysGetter:()=>G2,addInputsAndOutputs:()=>r,accumulative:()=>v,UtxoNetwork:()=>aX,UTXOScriptType:()=>xX,TX_OVERHEAD:()=>mX,SEGWIT_MARKER_FLAG_WEIGHT:()=>lX,OutputSizes:()=>OX,OP_RETURN_OVERHEAD:()=>F2,MIN_TX_FEE:()=>x0,InputSizes:()=>gX});var r1=F(()=>{UX();DX();GX();$0();uX();z2()});r1();export{YX as validateZcashAddress,j2 as validateUtxoAddress,d as validateBchAddress,l as toLegacyAddress,HX as toCashAddress,FX as stripToCashAddress,$X as stripPrefix,IX as nonSegwitChains,tX as isValidAddress,c1 as getUtxoToolbox,I0 as getUtxoNetwork,V as getUtxoApi,Q2 as getUTXOAddressValidator,ZX as getUTXOAddressPath,o as getUTXOAccountPath,a as getUTXOAccountIndexFromPath,QX as getScriptTypeForAddress,TX as getOutputSize,E as getNetworkForChain,c as getInputSize,bX as getDustThreshold,eX as detectAddressNetwork,e2 as deriveAddressesFromXpub,L2 as createZcashToolbox,n as createUTXOToolbox,W2 as createHDWalletHelpers,k0 as createCustomUtxoApi,Y2 as createBCHToolbox,P as compileMemo,e as calculateTxSize,A as assertDerivationIndex,G2 as addressFromKeysGetter,r as addInputsAndOutputs,v as accumulative,aX as UtxoNetwork,xX as UTXOScriptType,mX as TX_OVERHEAD,lX as SEGWIT_MARKER_FLAG_WEIGHT,OX as OutputSizes,F2 as OP_RETURN_OVERHEAD,x0 as MIN_TX_FEE,gX as InputSizes};
1
+ var Q0=Object.defineProperty;var G0=(X)=>X;function Y0(X,$){this[X]=G0.bind(null,$)}var q0=(X,$)=>{for(var J in $)Q0(X,J,{get:$[J],enumerable:!0,configurable:!0,set:Y0.bind($,J)})};var F=(X,$)=>()=>(X&&($=X(X=0)),$);var n1=((X)=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(X,{get:($,J)=>(typeof require<"u"?require:$)[J]}):X)(function(X){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+X+'" is not supported')});import{NetworkDerivationPath as L0}from"@swapkit/helpers";function v(X,$){if(!Number.isInteger($)||$<0)throw RangeError(`${X} must be a non-negative integer, got: ${$}`)}function c({accountIndex:X,chain:$,derivationPath:J}){if(X!==void 0)v("accountIndex",X);let Z=[...J?.slice(0,3)??L0[$].slice(0,3)];if(X!==void 0)Z[2]=X;return Z}function ZX({accountIndex:X,change:$=!1,chain:J,derivationPath:Z,index:j}){return v("index",j),[...c({accountIndex:X,chain:J,derivationPath:Z}),Number($),j]}function a(X){return X[2]??0}function W2({deriveAddress:X,getBalance:$,getUtxos:J}){async function Z(Y){let{accountIndex:G,count:L,startIndex:q=0,change:z=!1}=Y;if(v("count",L),L<1)throw RangeError("count must be at least 1");v("startIndex",q);let W=[];for(let B=0;B<L;B++){let _=await X({accountIndex:G,change:z,index:q+B});if(_)W.push(_)}return W}async function j(Y){let{gapLimit:G=20,change:L=!1}=Y??{},q=[],z=0,W=0;while(z<G){let B=await X({change:L,index:W});if(!B)break;if((await $(B.address)).some((V)=>V.getValue("number")>0))q.push(B),z=0;else z++;W++}return q}async function Q(Y=20){let[G,L]=await Promise.all([j({change:!1,gapLimit:Y}),j({change:!0,gapLimit:Y})]),q=[...G,...L],z=await Promise.all(q.map(async(B)=>{let D=(await $(B.address)).reduce((V,s)=>V+s.getValue("number"),0);return{...B,balance:D}})),W=z.reduce((B,_)=>B+_.balance,0);return{addresses:z,total:W}}async function U(Y=20){let[G,L]=await Promise.all([j({change:!1,gapLimit:Y}),j({change:!0,gapLimit:Y})]),q=[...G,...L];return(await Promise.all(q.map(async(W)=>{return(await J(W.address)).map((_)=>({..._,address:W.address,derivationIndex:W.index,isChange:W.change}))}))).flat()}return{deriveAddresses:Z,getAggregatedBalance:Q,getAggregatedUtxos:U,scanForAddresses:j}}var DX=()=>{};import{AssetValue as B2,getChainConfig as z0}from"@swapkit/helpers";import{SwapKitApi as U0}from"@swapkit/helpers/api";function _2(){function X(){let $=Date.now(),J=nX||$;return nX=J,$>nX?$:J+1}return W0+X().toString(36)}function N2(X){return async function(J,Z=!0){let j=await U0.getChainBalance({address:J,chain:X,scamFilter:Z}),{baseDecimal:Q}=z0(X),U=j.map(({identifier:G,value:L,decimal:q})=>{return new B2({decimal:q||Q,identifier:G,value:L})});if(!U.some((G)=>G.isGasAsset))return[B2.from({chain:X}),...U];return U}}var W0,nX=0;var iX=F(()=>{W0=typeof process<"u"&&process.pid?process.pid.toString(36):""});import{Chain as f,getRPCUrl as B0,RequestClient as AX,SKConfig as _0,SwapKitError as S,warnOnce as N0}from"@swapkit/helpers";import{NETWORKS as jX}from"@swapkit/utxo-signer";async function M0({chain:X,txHash:$}){let J=`${CX(X)}/push/transaction`,Z=JSON.stringify({data:$});try{let j=await AX.post(J,{body:Z,headers:{"Content-Type":"application/json"}});if(j.context.code!==200)throw new S("toolbox_utxo_broadcast_failed",{error:j.context.error||"Transaction broadcast failed"});return j.data?.transaction_hash||$}catch(j){let Q=await B0(X);if(Q){let U=JSON.stringify({id:_2(),jsonrpc:"2.0",method:"sendrawtransaction",params:[$]}),Y=await AX.post(Q,{body:U,headers:{"Content-Type":"application/json"}});if(Y.error)throw new S("toolbox_utxo_broadcast_failed",{error:Y.error?.message});if(Y.result.includes('"code":-26'))throw new S("toolbox_utxo_invalid_transaction",{error:"Transaction amount was too low"});return Y.result}throw j}}function CX(X){return`https://api.blockchair.com/${D0(X)}`}function M2(X){switch(X){case f.Bitcoin:return 5;case f.Dogecoin:return 1e4;case f.Litecoin:return 1;case f.Zcash:return 1;default:return 2}}function D0(X){switch(X){case f.BitcoinCash:return"bitcoin-cash";case f.Litecoin:return"litecoin";case f.Dash:return"dash";case f.Dogecoin:return"dogecoin";case f.Zcash:return"zcash";case f.Polkadot:return"polkadot";default:return"bitcoin"}}async function C0(X){try{let{feePerKb:$}=await AX.get(`https://app.bitgo.com/api/v2/${X.toLowerCase()}/tx/fee`),J=$/1000;return Math.max(J,M2(X))}catch{return M2(X)}}async function wX(X,$){let J=await AX.get(`${X}${$?`${X.includes("?")?"&":"?"}key=${$}`:""}`);if(!J||J.context.code!==200)throw new S("toolbox_utxo_api_error",{error:`Failed to query ${X}`});return J.data}async function C2({address:X,chain:$,apiKey:J}){if(!X)throw new S("toolbox_utxo_invalid_params",{error:"Address is required"});try{return(await wX(`${CX($)}/dashboards/address/${X}?transaction_details=true`,J))[X]}catch{return{address:{balance:0,transaction_count:0},utxo:[]}}}async function H0({address:X,chain:$,apiKey:J}){return(await C2({address:X,apiKey:J,chain:$}))?.address.balance||0}async function H2({chain:X,apiKey:$,txHash:J}){if(!J)throw new S("toolbox_utxo_invalid_params",{error:"TxHash is required"});try{return(await wX(`${CX(X)}/raw/transaction/${J}`,$))?.[J]?.raw_transaction||""}catch(Z){let j=Z instanceof Error?Z.message:String(Z);return console.error(`Failed to fetch raw transaction: ${j}`),""}}async function T0({chain:X,apiKey:$,txHash:J}){if(!J)throw new S("toolbox_utxo_invalid_params",{error:"TxHash is required"});let j=(await wX(`${CX(X)}/dashboards/transaction/${J}`,$))?.[J];if(!j)throw new S("toolbox_utxo_tx_not_found",{txHash:J});let{transaction:Q,inputs:U,outputs:Y}=j,G=U.map((q)=>q.spending_sequence),L=Q.is_rbf===!0||G.some((q)=>q<O0);return{blockId:Q.block_id,confirmed:Q.block_id!==-1,fee:Q.fee,inputs:U,isRBF:L,outputs:Y,sequences:G,size:Q.size,txid:Q.hash,weight:Q.weight}}async function V0({chain:X,address:$,apiKey:J,offset:Z=0,limit:j=30}){return(await wX(`${CX(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=${j}&offset=${Z}`,J)).map(({is_spent:G,script_hex:L,block_id:q,transaction_hash:z,index:W,value:B,spending_signature_hex:_})=>({hash:z,index:W,is_confirmed:q!==-1,is_spent:G,script_hex:L,txHex:_,value:B}))}function b0(X){return X.reduce(($,J)=>$+J.value,0)}function D2(X,$){let J=[...X].sort((Z,j)=>j.value-Z.value);if($){let Z=[],j=0;for(let Q of J)if(Z.push(Q),j+=Q.value,j>=$)break;return Z}return J}async function O2({chain:X,address:$,apiKey:J,targetValue:Z,accumulativeValue:j=0,offset:Q=0,limit:U=30}){if(!$)throw new S("toolbox_utxo_invalid_params",{error:"Address is required"});try{let Y=await V0({address:$,apiKey:J,chain:X,limit:U,offset:Q,targetValue:Z}),L=Y.length<U,q=Y.filter(({is_spent:V})=>!V),z=b0(q),W=j+z,B=Z&&W>=Z;if(L||B)return D2(q,Z);let _=await O2({accumulativeValue:W,address:$,apiKey:J,chain:X,limit:U,offset:Q+U,targetValue:Z}),D=[...q,..._];return D2(D,Z)}catch(Y){let G=Y instanceof Error?Y.message:String(Y);return console.error(`Failed to fetch unspent UTXOs: ${G}`),[]}}async function k0({address:X,chain:$,apiKey:J,fetchTxHex:Z=!0,targetValue:j}){let Q=await O2({address:X,apiKey:J,chain:$,targetValue:j}),U=[];for(let{hash:Y,index:G,script_hex:L,value:q}of Q){let z;if(Z)z=await H2({apiKey:J,chain:$,txHash:Y});U.push({address:X,hash:Y,index:G,txHex:z,value:q,witnessUtxo:{script:Buffer.from(L,"hex"),value:q}})}return U}function b(X){let $=_0.get("apiKeys").blockchair||"";return N0({condition:!$,id:"no_blockchair_api_key_warning",warning:"No Blockchair API key found. Functionality will be limited."}),{broadcastTx:(J)=>M0({chain:X,txHash:J}),getAddressData:(J)=>C2({address:J,apiKey:$,chain:X}),getBalance:(J)=>H0({address:J,apiKey:$,chain:X}),getRawTx:(J)=>H2({apiKey:$,chain:X,txHash:J}),getSuggestedTxFee:()=>C0(X),getTransactionDetails:(J)=>T0({apiKey:$,chain:X,txHash:J}),getUtxos:(J)=>k0({...J,apiKey:$,chain:X})}}function I0(X){return X}function f0(){return function($){switch($){case f.Bitcoin:return jX.bitcoin;case f.BitcoinCash:return jX.bitcoinCash;case f.Dash:return jX.dash;case f.Litecoin:return jX.litecoin;case f.Dogecoin:return jX.dogecoin;case f.Zcash:return jX.zcash;default:throw new S("toolbox_utxo_not_supported",{chain:$})}}}var O0=4294967294;var T2=F(()=>{iX()});import{CashAddrType as SX,decodeCashAddr as F0,encodeCashAddr as P0}from"@swapkit/utxo-signer";function y0(X,$,J){return P0({hash:J,prefix:X,type:E0[$]})}function v0(X){let $=F0(X),J=R0[$.type];if(!J)throw Error(`Unknown CashAddr type: ${$.type}`);return{hash:$.hash,prefix:$.prefix,type:J}}var E0,R0,sX;var V2=F(()=>{E0={P2PKH:SX.P2PKH,P2SH:SX.P2SH},R0={[SX.P2PKH]:"P2PKH",[SX.P2SH]:"P2SH"};sX={decode:v0,encode:y0}});import{sha256 as A0}from"@noble/hashes/sha2.js";import{createBase58check as w0}from"@scure/base";import{SwapKitError as k2}from"@swapkit/helpers";function tX(X){try{return KX(X),!0}catch{return!1}}function eX(X){return KX(X)?.network}function l(X){let $=KX(X);if($?.format==="legacy")return X;return m0($)}function HX(X){let $=KX(X);return g0($)}function KX(X){try{let $=S0(X);if($)return $}catch{}try{let $=K0(X);if($)return $}catch{}throw new k2("toolbox_utxo_invalid_address",{address:X})}function S0(X){try{let $=I2.decode(X);if($.length!==21)throw new k2("toolbox_utxo_invalid_address",{address:X});let J=$[0],Z=Array.prototype.slice.call($,1);switch(J){case t.legacy.mainnet.p2pkh:return{format:"legacy",hash:Z,network:"mainnet",type:"p2pkh"};case t.legacy.mainnet.p2sh:return{format:"legacy",hash:Z,network:"mainnet",type:"p2sh"};case t.legacy.testnet.p2pkh:return{format:"legacy",hash:Z,network:"testnet",type:"p2pkh"};case t.legacy.testnet.p2sh:return{format:"legacy",hash:Z,network:"testnet",type:"p2sh"};case t.bitpay.mainnet.p2pkh:return{format:"bitpay",hash:Z,network:"mainnet",type:"p2pkh"};case t.bitpay.mainnet.p2sh:return{format:"bitpay",hash:Z,network:"mainnet",type:"p2sh"};default:return}}catch{return}}function K0(X){if(X.indexOf(":")!==-1)try{return b2(X)}catch{}else{let $=["bitcoincash","bchtest","bchreg"];for(let J of $)try{return b2(`${J}:${X}`)}catch{}}return}function b2(X){try{let{hash:$,prefix:J,type:Z}=sX.decode(X);return{format:"cashaddr",hash:Array.prototype.slice.call($,0),network:J==="bitcoincash"?"mainnet":"testnet",type:Z==="P2PKH"?"p2pkh":"p2sh"}}catch{return}}function m0(X){let $=t.legacy[X.network][X.type],J=Buffer.alloc(1+X.hash.length);return J[0]=$,J.set(X.hash,1),I2.encode(J)}function g0(X){let $=X.network==="mainnet"?"bitcoincash":"bchtest",J=X.type==="p2pkh"?"P2PKH":"P2SH",Z=new Uint8Array(X.hash);return sX.encode($,J,Z)}var I2,aX,t;var f2=F(()=>{V2();I2=w0(A0);((J)=>{J.Mainnet="mainnet";J.Testnet="testnet"})(aX||={});t={["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 l0}from"@swapkit/helpers";import{Script as x0}from"@swapkit/utxo-signer";function E(X){let $=new Uint8Array(Buffer.from(X,"utf8"));return x0.encode(["RETURN",$])}var h0=1000,gX=10,lX=2,F2=10,p0=41,u0=107,xX,mX,OX,QX=(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 l0("toolbox_utxo_invalid_address",{address:X})},e=({inputs:X,outputs:$,feeRate:J})=>{let Z=X[0]&&"address"in X[0]&&X[0].address?QX(X[0].address):"P2PKH",Q=(J?X.filter((L)=>L.value>=mX["type"in L&&L.type?L.type:"P2PKH"]*Math.ceil(J)):X).reduce((L,q)=>L+d(q),0),U=$?.reduce((L,q)=>L+TX(q),0)||OX[Z],Y=gX+Q+U;return Z==="P2WPKH"?Math.ceil(Y+lX/4):Y},d=(X)=>{if("type"in X&&X.type)return mX[X.type];if("address"in X&&X.address)return mX[QX(X.address)];return p0+u0},TX=(X,$)=>{if(X?.script)return F2+X.script.length+(X.script.length>=74?2:1);if($)return OX[$];if("address"in X&&X.address)return OX[QX(X.address)];return OX.P2PKH};var X2=F(()=>{((J)=>{J.P2PKH="P2PKH";J.P2WPKH="P2WPKH"})(xX||={});mX={["P2PKH"]:148,["P2WPKH"]:68},OX={["P2PKH"]:34,["P2WPKH"]:31}});import{Chain as XX,SwapKitError as o0}from"@swapkit/helpers";function VX(X){switch(X){case XX.Bitcoin:case XX.BitcoinCash:return 550;case XX.Dash:case XX.Litecoin:return 5500;case XX.Dogecoin:return 1e5;case XX.Zcash:return 546;default:throw new o0("toolbox_utxo_not_supported",{chain:X})}}function A({inputs:X,outputs:$,feeRate:J=1,chain:Z=XX.Bitcoin,changeAddress:j=""}){let Q=X[0]&&"address"in X[0]&&X[0].address?QX(X[0].address):"P2PKH",U=X.filter((_)=>d(_)*J<=_.value),G=Q==="P2WPKH"?Math.ceil(lX/4):0,L=gX+G+$.reduce((_,D)=>_+TX(D),0),q=$.reduce((_,D)=>_+D.value,0),z=L*J,W=0,B=[];for(let _ of U){let D=d(_),V=J*D;z+=V,W+=_.value,B.push(_);let s=z+q;if(W<s)continue;let cX=W-s,_X=J*TX({address:j,value:0});if(cX>_X){let NX=_X+z,PX=W-(q+Math.ceil(NX));if(PX>Math.max(d({value:0})*J,VX(Z)))return{fee:Math.ceil(NX),inputs:B,outputs:$.concat({address:j,value:PX})}}return{fee:Math.ceil(z),inputs:B,outputs:$}}return{fee:Math.ceil(J*e({inputs:X,outputs:$}))}}var P2=F(()=>{X2()});var GX=F(()=>{T2();f2();P2();X2()});import{Address as c0,ZCASH_NETWORK as d0}from"@swapkit/utxo-signer";function $X(X){return X.replace(/(bchtest:|bitcoincash:)/,"")}function r(X){let $=$X(X);return tX($)&&eX($)==="mainnet"}function YX(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 J=c0(d0).decode(X);return J.type==="pkh"||J.type==="sh"}catch{return!1}}var bX=F(()=>{GX()});import{secp256k1 as r0}from"@noble/curves/secp256k1.js";import{hex as JX}from"@scure/base";import{HDKey as v2}from"@scure/bip32";import{mnemonicToSeedSync as J2}from"@scure/bip39";import{AssetValue as hX,applyFeeMultiplier as E2,Chain as k,derivationPathToString as kX,FeeOption as K,NetworkDerivationPath as A2,SwapKitError as T,SwapKitNumber as n0,updateDerivationPath as i0,warnOnce as s0}from"@swapkit/helpers";import{Address as a0,BCHSigHash as Z2,CashAddrPrefix as t0,CashAddrType as e0,encodeCashAddr as X1,NETWORKS as qX,p2pkh as R2,p2wpkh as $1,RBF_SEQUENCE as J1,SigHash as w2,Transaction as $2,WIF as S2}from"@swapkit/utxo-signer";import{match as K2}from"ts-pattern";function j2({address:X,chain:$}){return K2($).with(k.BitcoinCash,()=>r(X)).with(k.Zcash,()=>YX(X)).otherwise(()=>{try{return a0(P($)).decode(X),!0}catch{return!1}})}function P(X){return K2(X).with(k.Bitcoin,()=>qX.bitcoin).with(k.BitcoinCash,()=>qX.bitcoinCash).with(k.Dash,()=>qX.dash).with(k.Dogecoin,()=>qX.dogecoin).with(k.Litecoin,()=>qX.litecoin).with(k.Zcash,()=>qX.zcash).exhaustive()}function Z1({phrase:X,derivationPath:$,network:J,seed:Z}){let j=Z??J2(X),U=v2.fromMasterSeed(j,J.bip32).derive($);if(!U.privateKey)throw new T("toolbox_utxo_invalid_params",{error:"Could not derive private key from phrase"});return U.privateKey}function y2(X){return r0.getPublicKey(X,!0)}function fX({publicKey:X,chain:$,network:J}){if($===k.BitcoinCash){let Q=R2(X,J);if(!Q.hash)throw new T("toolbox_utxo_invalid_address",{error:"Could not derive BCH address hash"});return X1({hash:Q.hash,prefix:t0.MAINNET,type:e0.P2PKH}).replace(/^bitcoincash:/,"")}let j=!IX.includes($)?$1(X,J):R2(X,J);if(!j.address)throw new T("toolbox_utxo_invalid_address",{error:"Could not derive address"});return j.address}function LX({phrase:X,derivationPath:$,chain:J,wif:Z,seed:j}){let Q=P(J);if(Z){let L=S2(Q).decode(Z),q=y2(L);return{privateKey:L,publicKey:q}}if(!X)throw new T("toolbox_utxo_invalid_params",{error:"Either phrase or wif must be provided"});let U=$||kX(A2[J]),Y=Z1({derivationPath:U,network:Q,phrase:X,seed:j}),G=y2(Y);return{privateKey:Y,publicKey:G}}function j1(X,$){return S2(P($)).encode(X)}function Q1({phrase:X,derivationPath:$,chain:J,seed:Z}){let j=$.split("/");if(j.length<4)throw new T("toolbox_utxo_invalid_params",{error:`Derivation path must have at least 4 levels (got ${j.length}): ${$}`});let Q=P(J),U=Z??J2(X),Y=v2.fromMasterSeed(U,Q.bip32),G=j.slice(0,4).join("/");return Y.derive(G)}function n({inputs:X,outputs:$,chain:J,tx:Z,sender:j,compiledMemo:Q,enableRBF:U=!1}){let Y=P(J),G=!IX.includes(J),L=U?J1:void 0,q=new Set;for(let z of X){let W=`${z.hash}:${z.index}`;if(q.has(W))throw new T("toolbox_utxo_invalid_params",{error:"Duplicate input detected"});q.add(W);let B=typeof z.hash==="string"?JX.decode(z.hash):z.hash;if(G&&z.witnessUtxo)Z.addInput({index:z.index,sequence:L,txid:B,witnessUtxo:{amount:BigInt(z.witnessUtxo.value),script:z.witnessUtxo.script}});else if(z.txHex)Z.addInput({index:z.index,nonWitnessUtxo:JX.decode(z.txHex),sequence:L,txid:B,...J===k.BitcoinCash?{sighashType:Z2.ALL}:{}});else throw new T("toolbox_utxo_invalid_params",{error:"Input requires either witnessUtxo or txHex for non-segwit chains"})}for(let z of $){let W="address"in z&&z.address?z.address:j;if(J===k.BitcoinCash)W=l(W);if(z.script){if(Q)Z.addOutput({amount:0n,script:Q})}else Z.addOutputAddress(W,BigInt(z.value),Y)}return{inputs:X,tx:Z}}async function zX(X){let $=await b(X).getSuggestedTxFee();return{[K.Average]:$,[K.Fast]:E2($,K.Fast),[K.Fastest]:E2($,K.Fastest)}}async function m2({assetValue:X,recipient:$,memo:J,sender:Z,fetchTxHex:j=!1}){let Q=X.chain,U=(await zX(Q))[K.Fastest],Y=j||IX.includes(Q),G=X.getBaseValue("number"),L=Math.ceil(G+U*5000);return{inputs:await b(Q).getUtxos({address:Z,fetchTxHex:Y,targetValue:L}),outputs:[{address:$,value:G},...J?[{address:"",script:E(J),value:0}]:[]]}}async function g2({assetValue:X,recipient:$,memo:J,feeRate:Z,sender:j,fetchTxHex:Q=!1,enableRBF:U=!1}){let Y=X.chain,G=J?E(J):null,L=await m2({assetValue:X,fetchTxHex:Q,memo:J,recipient:$,sender:j}),{inputs:q,outputs:z}=A({...L,chain:Y,feeRate:Z});if(!(q&&z))throw new T("toolbox_utxo_insufficient_balance",{assetValue:X,sender:j});let W=new $2({allowLegacyWitnessUtxo:!0,allowUnknownOutputs:!!G,version:1}),{inputs:B,tx:_}=n({chain:Y,compiledMemo:G,enableRBF:U,inputs:q,outputs:z,sender:j,tx:W});return{inputs:B,tx:_,utxos:L.inputs}}async function l2({assetValue:X,feeOptionKey:$=K.Fast,feeRate:J,memo:Z,sender:j,recipient:Q}){let U=X.chain,Y=await m2({assetValue:X,memo:Z,recipient:Q,sender:j}),G=J?Math.floor(J):(await zX(U))[$];return A({...Y,chain:U,feeRate:G})}function G1(X){return async function({from:J,memo:Z,feeRate:j,feeOptionKey:Q=K.Fast,recipients:U=1}){let Y=await b(X).getAddressData(J),G=j?Math.ceil(j):(await zX(X))[Q],L=Y?.utxo.map((D)=>({...D,hash:"",type:"P2PKH"})).filter((D)=>D.value>Math.max(VX(X),d(D)*G));if(!L?.length)return hX.from({chain:X});let q=BigInt(L.reduce((D,V)=>D+V.value,0)),z=hX.from({chain:X,value:q}),W=typeof U==="number"?Array.from({length:U},()=>({address:J,value:0})):U;if(Z)W.push({address:J,script:E(Z),value:0});let B=e({inputs:L,outputs:W}),_=hX.from({chain:X,value:BigInt(B*G)});return z.sub(_)}}function Y1(X){return async function(J){let{fee:Z}=await l2(J);return hX.from({chain:X,value:n0.fromBigInt(BigInt(Z),8).getValue("string")})}}function q1({chain:X,phrase:$,derivationPath:J,seed:Z}){let j=P(X),{privateKey:Q,publicKey:U}=LX({chain:X,derivationPath:J,phrase:$,seed:Z}),Y=X===k.BitcoinCash?[Z2.ALL]:[w2.ALL];return{getAddress:()=>fX({chain:X,network:j,publicKey:U}),privateKey:Q,publicKey:U,signTransaction:(G)=>{return G.sign(Q,Y),G}}}function L1(X,$){return async function({memo:Z,recipient:j,feeOptionKey:Q,feeRate:U,assetValue:Y,enableRBF:G=!1}){let L=$?.getAddress();if(!($&&L))throw new T("toolbox_utxo_no_signer");if(!j)throw new T("toolbox_utxo_invalid_params",{error:"Recipient address must be provided"});s0({condition:G&&!pX.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 q=G&&pX.includes(X),z=U||(await zX(X))[Q||K.Fast],{tx:W}=await g2({assetValue:Y,enableRBF:q,feeRate:z,memo:Z,recipient:j,sender:L});return $.signTransaction(W),W.finalize(),b(X).broadcastTx(JX.encode(W.extract()))}}function Q2(X){return($)=>j2({address:$,chain:X})}function G2(X){let $=P(X);return function(Z){if(!Z)throw new T("toolbox_utxo_invalid_params",{error:"Keys must be provided"});return fX({chain:X,network:$,publicKey:Z.publicKey})}}function i({chain:X,...$}){let J="phrase"in $?$.phrase:void 0,Z="index"in $?$.index||0:0,j=J?J2(J):void 0,Q="derivationPath"in $&&$.derivationPath?$.derivationPath:i0(A2[X],{index:Z}),U=kX(Q),Y=J?q1({chain:X,derivationPath:U,phrase:J,seed:j}):void 0,G="signer"in $?$.signer:void 0,L=J?LX({chain:X,derivationPath:U,phrase:J,seed:j}):void 0;function q(){if(Y)return Promise.resolve(Y.getAddress());if(G)return G.getAddress();return Promise.resolve(void 0)}function z(N){if(!J)return;let M=c({accountIndex:N,chain:X,derivationPath:Q});return Q1({chain:X,derivationPath:kX(M),phrase:J,seed:j})}let W=z();function B(){if(!W)return;return W.publicExtendedKey}function _({accountIndex:N}={}){let M=N===void 0?W:z(N);if(!M)return;let C=c({accountIndex:N,chain:X,derivationPath:Q});return{accountIndex:a(C),path:kX(C),xpub:M.publicExtendedKey}}function D({accountIndex:N,index:M,change:C=!1}){let O=N===void 0?W:z(N);if(!O)return;let H=ZX({accountIndex:N,chain:X,change:C,derivationPath:Q,index:M}),R=P(X),w=O.deriveChild(Number(C)).deriveChild(M);if(!w.publicKey)throw new T("toolbox_utxo_invalid_params",{error:"Could not derive public key"});let y=fX({chain:X,network:R,publicKey:w.publicKey}),h=JX.encode(w.publicKey);return{accountIndex:a(H),address:y,change:C,index:M,path:kX(H),pubkey:h}}async function V(N){if(!pX.includes(X))return{reason:`RBF is not supported on ${X}`,supported:!1};let M=await b(X).getTransactionDetails(N);return{canReplace:M.isRBF&&!M.confirmed,confirmed:M.confirmed,enabled:M.isRBF,fee:M.fee,sequences:M.sequences,supported:!0}}async function s({txid:N,newFeeRate:M,recipient:C,memo:O}){if(!pX.includes(X))throw new T("toolbox_utxo_rbf_not_supported",{chain:X});let H=await b(X).getTransactionDetails(N);if(!H.isRBF)throw new T("toolbox_utxo_tx_not_replaceable",{txid:N});if(H.confirmed)throw new T("toolbox_utxo_tx_already_confirmed",{blockId:H.blockId,txid:N});let R=H.inputs.reduce((I,o)=>I+o.value,0),y=H.outputs.find((I)=>I.recipient===C)?.value||0;if(y===0)throw new T("toolbox_utxo_invalid_params",{error:"Could not determine send amount from original transaction"});let h=await Promise.all(H.inputs.map(async(I)=>{let o=await b(X).getRawTx(I.transaction_hash);return{hash:I.transaction_hash,index:I.index,txHex:o,value:I.value,witnessUtxo:void 0}})),EX=O?E(O):null,dX=e({feeRate:M,inputs:h.map((I)=>({...I,type:"P2WPKH"})),outputs:[{address:C,value:y}]}),g=Math.ceil(dX*M);if(g<=H.fee)throw new T("toolbox_utxo_rbf_fee_too_low",{newFee:g,originalFee:H.fee});let MX=g-H.fee,p=y-MX;if(p<=0)throw new T("toolbox_utxo_rbf_insufficient_change");let RX=new $2({allowLegacyWitnessUtxo:!0,version:1}),yX=[{address:C,value:p},...O?[{address:"",script:E(O),value:0}]:[]],vX=R-p-g,u=await q();if(vX>VX(X)&&u)yX.push({address:u,value:vX});return n({chain:X,compiledMemo:EX,inputs:h,outputs:yX,sender:u||C,tx:RX}),{feeDelta:MX,newFee:g,originalFee:H.fee,tx:RX}}async function cX({txid:N,newFeeRate:M,recipient:C,memo:O}){if(!Y)throw new T("toolbox_utxo_no_signer");let{tx:H,originalFee:R,newFee:w}=await s({memo:O,newFeeRate:M,recipient:C,txid:N});Y.signTransaction(H),H.finalize();let y=await b(X).broadcastTx(JX.encode(H.extract()));return{newFee:w,originalFee:R,txid:y}}function _X({accountIndex:N,index:M,change:C=!1}){v("index",M);let O=N===void 0?W:z(N);if(!O)return;return O.deriveChild(Number(C)).deriveChild(M).privateKey||void 0}function NX({tx:N,inputDerivations:M}){if(!W)throw new T("toolbox_utxo_no_signer");let C=X===k.BitcoinCash?[Z2.ALL]:[w2.ALL];for(let O=0;O<M.length;O++){let H=M[O];if(!H)continue;let{derivationIndex:R,isChange:w}=H,y=_X({change:w,index:R});if(!y)throw new T("toolbox_utxo_invalid_params",{error:`Could not derive private key for input ${O} at index ${R}`});N.signIdx(y,O,C)}return N}async function PX({utxos:N,recipient:M,assetValue:C,memo:O,feeRate:H,feeOptionKey:R,changeAddress:w}){if(!W)throw new T("toolbox_utxo_no_signer");let y=H||(await zX(X))[R||K.Fast],h=O?E(O):null,EX=[{address:M,value:C.getBaseValue("number")}];if(h)EX.push({address:"",script:h,value:0});let dX=N.map(({hash:u,index:I,value:o,txHex:j0,witnessUtxo:rX})=>({hash:u,index:I,txHex:j0,value:o,witnessUtxo:rX?{script:rX.script,value:rX.value}:void 0})),{inputs:g,outputs:MX}=A({chain:X,feeRate:y,inputs:dX,outputs:EX});if(!(g&&MX))throw new T("toolbox_utxo_insufficient_balance",{assetValue:C,sender:"multiple addresses"});let p=new $2({allowLegacyWitnessUtxo:!0,version:1}),RX=N[0]?.address,yX=w||await q()||RX||M;n({chain:X,compiledMemo:h,inputs:g,outputs:MX,sender:yX,tx:p});let vX=g.map((u)=>{let I=N.find((o)=>o.hash===u.hash&&o.index===u.index);return I?{derivationIndex:I.derivationIndex,isChange:I.isChange}:{derivationIndex:0,isChange:!1}});return NX({inputDerivations:vX,tx:p}),p.finalize(),b(X).broadcastTx(JX.encode(p.extract()))}function Z0({address:N,gapLimit:M=20}){if(!W)return;for(let C=0;C<M;C++){let O=D({change:!1,index:C}),H=D({change:!0,index:C}),R=O?.address===N?!1:H?.address===N;if(O?.address===N||H?.address===N)return{change:R,index:C}}return}return{accumulative:A,broadcastTx:(N)=>b(X).broadcastTx(N),bumpFee:cX,calculateTxSize:e,createKeysForPath:(N)=>LX({...N,chain:X}),createReplacementTransaction:s,createTransaction:g2,deriveAddressAtIndex:D,derivePrivateKeyAtIndex:_X,estimateMaxSendableAmount:G1(X),estimateTransactionFee:Y1(X),getAddress:q,getAddressFromKeys:G2(X),getBalance:N2(X),getExtendedPublicKey:B,getExtendedPublicKeyInfo:_,getFeeRates:()=>zX(X),getInputsOutputsFee:l2,getNetworkForChain:()=>P(X),getPrivateKeyFromMnemonic:(N)=>j1(LX({...N,chain:X}).privateKey,X),isRBFEnabled:V,keys:L,resolveDerivationIndex:Z0,signAndBroadcastTransaction:async(N)=>{if(!Y)throw new T("toolbox_utxo_no_signer");return Y.signTransaction(N),N.finalize(),await b(X).broadcastTx(JX.encode(N.extract()))},signTransactionWithMultipleKeys:NX,transfer:L1(X,Y),transferFromMultipleAddresses:PX,validateAddress:Q2(X)}}var IX,pX;var UX=F(()=>{iX();DX();GX();bX();IX=[k.Dash,k.Dogecoin,k.Zcash,k.BitcoinCash],pX=[k.Bitcoin]});import{hex as x2}from"@scure/base";import{Chain as z1,derivationPathToString as U1,FeeOption as W1,NetworkDerivationPath as B1,SwapKitError as x,updateDerivationPath as _1}from"@swapkit/helpers";import{BCHSigHash as N1,CashAddrPrefix as h2,CashAddrType as p2,encodeCashAddr as u2,NETWORKS as M1,p2pkh as o2,Transaction as c2}from"@swapkit/utxo-signer";function FX(X){return $X(HX(X))}function D1(X){let $=P(m);function J(j){return j.sign(X.privateKey,[N1.ALL]),j}function Z(){let j=o2(X.publicKey,$);if(!j.hash)throw new x("toolbox_utxo_invalid_address",{error:"Could not derive BCH address hash"});let Q=u2({hash:j.hash,prefix:h2.MAINNET,type:p2.P2PKH});return Promise.resolve(Q.replace(/^bitcoincash:/,""))}return{getAddress:Z,signTransaction:J}}function Y2(X){let $="phrase"in X?X.phrase:void 0,J="index"in X?X.index||0:0,Z=U1("derivationPath"in X&&X.derivationPath?X.derivationPath:_1(B1[m],{index:J})),j=$?LX({chain:m,derivationPath:Z,phrase:$}):void 0,Q=j?D1(j):("signer"in X)?X.signer:void 0;function U(){return Promise.resolve(Q?.getAddress())}let{getBalance:Y,getFeeRates:G,broadcastTx:L,...q}=i({chain:m});function z(B,_=!0){return Y($X(HX(B)))}async function W(B){if(!Q)throw new x("toolbox_utxo_no_signer");return Q.signTransaction(B),B.finalize(),await L(x2.encode(B.extract()))}return{...q,broadcastTx:L,buildTx:H1,createTransaction:d2,getAddress:U,getAddressFromKeys:O1,getBalance:z,getFeeRates:G,signAndBroadcastTransaction:W,stripPrefix:$X,stripToCashAddress:FX,transfer:C1({broadcastTx:L,getFeeRates:G,signer:Q}),validateAddress:r}}async function d2({assetValue:X,recipient:$,memo:J,feeRate:Z,sender:j}){if(!r($))throw new x("toolbox_utxo_invalid_address",{address:$});let Q=Math.ceil(X.getBaseValue("number")+Z*7500),U=await b(m).getUtxos({address:FX(j),fetchTxHex:!0,targetValue:Q}),Y=J?E(J):null,G=[],L=l($);if(G.push({address:L,value:X.getBaseValue("number")}),Y)G.push({script:Y,value:0});let{inputs:q,outputs:z}=A({chain:m,feeRate:Z,inputs:U,outputs:G});if(!(q&&z))throw new x("toolbox_utxo_insufficient_balance",{assetValue:X,sender:j});let W=new c2({allowLegacyWitnessUtxo:!0,allowUnknownOutputs:!!Y,version:1}),B=l(j),{inputs:_,tx:D}=n({chain:m,compiledMemo:Y,inputs:q,outputs:z.map((V)=>("address"in V)&&V.address?{...V,address:l(V.address)}:V),sender:B,tx:W});return{inputs:_,tx:D,utxos:q}}function C1({broadcastTx:X,getFeeRates:$,signer:J}){return async function({recipient:j,assetValue:Q,feeOptionKey:U=W1.Fast,...Y}){let G=await J?.getAddress();if(!(J&&G))throw new x("toolbox_utxo_no_signer");if(!j)throw new x("toolbox_utxo_invalid_params",{error:"Recipient address must be provided"});let L=Y.feeRate||(await $())[U],{tx:q}=await d2({...Y,assetValue:Q,feeRate:L,recipient:j,sender:G}),z=await J.signTransaction(q);return z.finalize(),X(x2.encode(z.extract()))}}async function H1({assetValue:X,recipient:$,memo:J,feeRate:Z,sender:j}){let Q=HX($);if(!r(Q))throw new x("toolbox_utxo_invalid_address",{address:Q});let U=Math.ceil(X.getBaseValue("number")+Z*7500),Y=await b(m).getUtxos({address:FX(j),fetchTxHex:!0,targetValue:U}),G=Number(Z.toFixed(0)),L=J?E(J):null,q=[];if(q.push({address:l($),value:X.getBaseValue("number")}),L)q.push({script:L,value:0});let{inputs:z,outputs:W}=A({chain:m,feeRate:G,inputs:Y,outputs:q});if(!(z&&W))throw new x("toolbox_utxo_insufficient_balance",{assetValue:X,sender:j});let B=new c2({allowLegacyWitnessUtxo:!0,allowUnknownOutputs:!!L,version:1}),{inputs:_,tx:D}=n({chain:m,compiledMemo:L,inputs:z,outputs:W,sender:l(j),tx:B});return{inputs:_,tx:D,utxos:Y}}function O1(X){let $=M1.bitcoinCash,J=o2(X.publicKey,$);if(!J.hash)throw new x("toolbox_utxo_invalid_address",{error:"Could not derive BCH address hash"});return u2({hash:J.hash,prefix:h2.MAINNET,type:p2.P2PKH}).replace(/^bitcoincash:/,"")}var m;var uX=F(()=>{GX();UX();bX();m=z1.BitcoinCash});import{createBase58check as T1,hex as V1}from"@scure/base";import{HDKey as i2}from"@scure/bip32";import{mnemonicToSeedSync as s2}from"@scure/bip39";import{Chain as oX,derivationPathToString as b1,FeeOption as k1,NetworkDerivationPath as I1,SKConfig as a2,SwapKitError as WX,updateDerivationPath as f1}from"@swapkit/helpers";import{Address as F1,createZcashTransaction as P1,OutScript as E1,PCZT as R1,utils as t2,WIF as y1,ZCASH_NETWORK as v1,ZCASH_TEST_NETWORK as A1,ZcashConsensusBranchId as w1,ZcashSigHash as r2,ZcashVersionGroupId as S1}from"@swapkit/utxo-signer";import{match as K1,P as q2}from"ts-pattern";function e2(){let{isStagenet:X}=a2.get("envs");return X?A1:v1}function g1(X){return m1.encode(X)}function l1({phrase:X,derivationPath:$}){let J=s2(X),j=i2.fromMasterSeed(J).derive($);if(!j.privateKey||!j.publicKey)throw new WX("toolbox_utxo_invalid_params");let{privateKey:Q,publicKey:U}=j,Y=t2.hash160(U),{isStagenet:G}=a2.get("envs"),L=G?new Uint8Array([29,37]):new Uint8Array([28,184]),q=new Uint8Array(L.length+Y.length);q.set(L,0),q.set(Y,L.length);let z=g1(q);return{getAddress:()=>Promise.resolve(z),signTransaction:(W)=>{if(W instanceof R1)return W.signAllInputs(Q,U,r2.ALL),W.finalizeAllInputs(),Promise.resolve(W.extract());return W.signAllInputs(Q,U,r2.ALL),Promise.resolve(W)}}}function x1({inputs:X,outputs:$,tx:J,sender:Z,compiledMemo:j}){let Q=e2();for(let U of X){let Y=F1(Q).decode(Z),G=E1.encode(Y);J.addInput({index:U.index,script:G,sequence:4294967295,txid:V1.decode(U.hash),value:BigInt(U.value)})}for(let U of $){let Y="address"in U&&U.address?U.address:Z,G=U.script;if(G&&!j)continue;if(G&&j)J.addOutput({amount:0n,script:j});else J.addOutputAddress(Y,BigInt(U.value),Q)}return{inputs:X,tx:J}}async function n2(X){let{assetValue:$,recipient:J,memo:Z,feeRate:j,sender:Q,fetchTxHex:U}=X,Y=Z?E(Z):null,G=await b(oX.Zcash).getUtxos({address:Q,fetchTxHex:U!==!1}),L=[{address:J,value:Number($.getBaseValue("string"))},...Y?[{script:Y,value:0}]:[]],{inputs:q,outputs:z}=A({chain:oX.Zcash,changeAddress:Q,feeRate:j,inputs:G,outputs:L});if(!(q&&z))throw new WX("toolbox_utxo_insufficient_balance",{assetValue:$,sender:Q});let W=P1({consensusBranchId:w1.NU6_1,expiryHeight:0,lockTime:0,version:4,versionGroupId:S1.SAPLING}),{tx:B,inputs:_}=x1({compiledMemo:Y,inputs:q,outputs:z,sender:Q,tx:W});return{inputs:_,outputs:z,tx:B}}function L2(X){let $=K1(X).with({signer:q2.not(q2.nullish)},({signer:G})=>G).with({phrase:q2.string},({phrase:G,derivationPath:L,index:q=0})=>{let z=L||I1[oX.Zcash]||[44,133,0,0,0],W=f1(z,{index:q}),B=b1(W);return l1({derivationPath:B,phrase:G})}).otherwise(()=>{return}),J=i({chain:oX.Zcash,signer:$});async function Z({recipient:G,assetValue:L,feeOptionKey:q=k1.Fast,...z}){let W=await $?.getAddress();if(!($&&W))throw new WX("toolbox_utxo_no_signer");let B=z.feeRate||(await J.getFeeRates())[q],{tx:_}=await n2({...z,assetValue:L,feeRate:B,recipient:G,sender:W}),V=(await $.signTransaction(_)).toHex();return J.broadcastTx(V)}function j({phrase:G,derivationPath:L="m/44'/133'/0'/0/0"}){let q=s2(G),W=i2.fromMasterSeed(q).derive(L);if(!W.privateKey||!W.publicKey)throw new WX("toolbox_utxo_invalid_params");return{privateKey:W.privateKey,publicKey:W.publicKey}}function Q({phrase:G,derivationPath:L="m/44'/133'/0'/0/0"}){let q=j({derivationPath:L,phrase:G}),z=e2();return y1(z).encode(q.privateKey)}function U(G){return async function(q){if(!G)throw new WX("toolbox_utxo_no_signer");return await G.signTransaction(q)}}function Y(G){return async function(q){if(!G)throw new WX("toolbox_utxo_no_signer");let z=await G.signTransaction(q);return J.broadcastTx(z.toHex())}}return{...J,createKeysForPath:j,createTransaction:n2,getPrivateKeyFromMnemonic:Q,signAndBroadcastTransaction:Y($),signTransaction:U($),transfer:Z,validateAddress:YX}}var m1;var z2=F(()=>{GX();UX();bX();m1=T1(t2.sha256)});import{hex as h1}from"@scure/base";import{HDKey as p1}from"@scure/bip32";import{derivationPathToString as u1}from"@swapkit/helpers";function X0({xpub:X,chain:$,count:J,startIndex:Z=0,accountIndex:j}){if(v("count",J),J<1)throw RangeError("count must be at least 1");v("startIndex",Z);let Q=P($),U=p1.fromExtendedKey(X,Q.bip32),Y=c({accountIndex:j,chain:$}),G=a(Y),L=[];for(let q of[!1,!0]){let z=U.deriveChild(Number(q));for(let W=0;W<J;W++){let B=Z+W,_=z.deriveChild(B);if(!_.publicKey)continue;let D=ZX({accountIndex:j,chain:$,change:q,index:B});L.push({accountIndex:G,address:fX({chain:$,network:Q,publicKey:_.publicKey}),change:q,index:B,path:u1(D),pubkey:h1.encode(_.publicKey)})}}return L}var $0=F(()=>{DX();UX()});import{Chain as BX,SwapKitError as o1}from"@swapkit/helpers";function c1(X,$){switch(X){case BX.BitcoinCash:return Y2($||{});case BX.Zcash:return L2($);case BX.Bitcoin:case BX.Dogecoin:case BX.Litecoin:case BX.Dash:return i({chain:X,...$});default:throw new o1("toolbox_utxo_not_supported",{chain:X})}}var J0=F(()=>{uX();UX();z2();DX();$0();uX();bX()});var d1={};q0(d1,{validateZcashAddress:()=>YX,validateUtxoAddress:()=>j2,validateBchAddress:()=>r,toLegacyAddress:()=>l,toCashAddress:()=>HX,stripToCashAddress:()=>FX,stripPrefix:()=>$X,nonSegwitChains:()=>IX,isValidAddress:()=>tX,getUtxoToolbox:()=>c1,getUtxoNetwork:()=>f0,getUtxoApi:()=>b,getUTXOAddressValidator:()=>Q2,getUTXOAddressPath:()=>ZX,getUTXOAccountPath:()=>c,getUTXOAccountIndexFromPath:()=>a,getScriptTypeForAddress:()=>QX,getOutputSize:()=>TX,getNetworkForChain:()=>P,getInputSize:()=>d,getDustThreshold:()=>VX,detectAddressNetwork:()=>eX,deriveAddressesFromXpub:()=>X0,createZcashToolbox:()=>L2,createUTXOToolbox:()=>i,createHDWalletHelpers:()=>W2,createCustomUtxoApi:()=>I0,createBCHToolbox:()=>Y2,compileMemo:()=>E,calculateTxSize:()=>e,assertDerivationIndex:()=>v,addressFromKeysGetter:()=>G2,addInputsAndOutputs:()=>n,accumulative:()=>A,UtxoNetwork:()=>aX,UTXOScriptType:()=>xX,TX_OVERHEAD:()=>gX,SEGWIT_MARKER_FLAG_WEIGHT:()=>lX,OutputSizes:()=>OX,OP_RETURN_OVERHEAD:()=>F2,MIN_TX_FEE:()=>h0,InputSizes:()=>mX});var r1=F(()=>{UX();DX();GX();J0();uX();z2()});r1();export{YX as validateZcashAddress,j2 as validateUtxoAddress,r as validateBchAddress,l as toLegacyAddress,HX as toCashAddress,FX as stripToCashAddress,$X as stripPrefix,IX as nonSegwitChains,tX as isValidAddress,c1 as getUtxoToolbox,f0 as getUtxoNetwork,b as getUtxoApi,Q2 as getUTXOAddressValidator,ZX as getUTXOAddressPath,c as getUTXOAccountPath,a as getUTXOAccountIndexFromPath,QX as getScriptTypeForAddress,TX as getOutputSize,P as getNetworkForChain,d as getInputSize,VX as getDustThreshold,eX as detectAddressNetwork,X0 as deriveAddressesFromXpub,L2 as createZcashToolbox,i as createUTXOToolbox,W2 as createHDWalletHelpers,I0 as createCustomUtxoApi,Y2 as createBCHToolbox,E as compileMemo,e as calculateTxSize,v as assertDerivationIndex,G2 as addressFromKeysGetter,n as addInputsAndOutputs,A as accumulative,aX as UtxoNetwork,xX as UTXOScriptType,gX as TX_OVERHEAD,lX as SEGWIT_MARKER_FLAG_WEIGHT,OX as OutputSizes,F2 as OP_RETURN_OVERHEAD,h0 as MIN_TX_FEE,mX as InputSizes};
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Standard BIP-39 test mnemonic (all-zero index, the "abandon…about" phrase) used
3
+ * across toolbox test suites. Derives to well-known, publicly-documented addresses
4
+ * so test fixtures stay deterministic without requiring a private key file.
5
+ *
6
+ * Do NOT use this phrase for anything other than tests — the resulting keys are
7
+ * known to anyone reading BIP-39 spec examples.
8
+ */
9
+ export declare const TEST_MNEMONIC = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about";
10
+ /**
11
+ * Captures a plain-object snapshot of an ESM namespace import so it can be
12
+ * re-installed via `mock.module(...)` in `afterAll`.
13
+ *
14
+ * Why this exists: bun's `mock.module` mutates the namespace binding in place.
15
+ * If you spread the namespace inside `afterAll` (e.g. `mock.module("foo", () => ({ ...realFoo }))`),
16
+ * you get the **mocked** version, not the real one, because `realFoo` has already been replaced.
17
+ * Taking the snapshot at module load time (before any `mock.module` runs) captures the
18
+ * genuine exports.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * import * as realXrpl from "xrpl";
23
+ * const realXrplSnapshot = snapshotModule(realXrpl);
24
+ *
25
+ * mock.module("xrpl", () => ({ ...realXrplSnapshot, Client: MockClient }));
26
+ *
27
+ * afterAll(() => {
28
+ * mock.module("xrpl", () => realXrplSnapshot);
29
+ * });
30
+ * ```
31
+ */
32
+ export declare function snapshotModule<T extends object>(namespace: T): T;
33
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/__tests__/helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,kGACuE,CAAC;AAElG;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,EAAE,SAAS,EAAE,CAAC,GAAG,CAAC,CAEhE"}
@@ -21,6 +21,7 @@ export declare function createBCHToolbox<T extends typeof Chain.BitcoinCash>(too
21
21
  fast: number;
22
22
  fastest: number;
23
23
  }>;
24
+ signAndBroadcastTransaction: (tx: InstanceType<typeof Transaction>) => Promise<string>;
24
25
  stripPrefix: typeof stripPrefix;
25
26
  stripToCashAddress: typeof stripToCashAddress;
26
27
  transfer: ({ recipient, assetValue, feeOptionKey, ...rest }: UTXOTransferParams) => Promise<string>;
@@ -110,7 +111,6 @@ export declare function createBCHToolbox<T extends typeof Chain.BitcoinCash>(too
110
111
  change: boolean;
111
112
  index: number;
112
113
  } | undefined;
113
- signAndBroadcastTransaction: (tx: InstanceType<typeof Transaction>) => Promise<string>;
114
114
  signTransactionWithMultipleKeys: ({ tx, inputDerivations, }: {
115
115
  tx: InstanceType<typeof Transaction>;
116
116
  inputDerivations: import("..").InputDerivation[];
@@ -1 +1 @@
1
- {"version":3,"file":"bitcoinCash.d.ts","sourceRoot":"","sources":["../../../../src/utxo/toolbox/bitcoinCash.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,EAEL,KAAK,mBAAmB,EAExB,SAAS,EAIV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAOL,WAAW,EACZ,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,YAAY,EAA2D,MAAM,YAAY,CAAC;AACnG,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAC9F,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAElD,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAI/D,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,UAEjD;AA6BD,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,OAAO,KAAK,CAAC,WAAW,EACjE,aAAa,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,cAAc,CAAC,EAAE,mBAAmB,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE;;;;;;0BAsB5E,MAAM;;;;;;;;iEA4EtC,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YA6E44E,CAAC;eAAqB,CAAC;oBAA0B,CAAC;kBAA2B,CAAC;;;;;;YAAowC,CAAC;oBAA0B,CAAC;eAAwB,CAAC;kBAAwB,CAAC;;;;;;;;;;;oBAA/+D,CAAC;eAAoB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAvIz2D;AAED,iBAAe,iBAAiB,CAAC,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,iBAAiB;;;;;;;;;;;;;;GAwCnG;AAiCD,iBAAe,OAAO,CAAC,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,iBAAiB;YA2CvD,QAAQ,EAAE;;;;;;;;;;;;;GAC5C;AAED,iBAAS,kBAAkB,CAAC,IAAI,EAAE;IAAE,SAAS,EAAE,UAAU,CAAA;CAAE,UAa1D"}
1
+ {"version":3,"file":"bitcoinCash.d.ts","sourceRoot":"","sources":["../../../../src/utxo/toolbox/bitcoinCash.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,EAEL,KAAK,mBAAmB,EAExB,SAAS,EAIV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAOL,WAAW,EACZ,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,YAAY,EAA2D,MAAM,YAAY,CAAC;AACnG,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAC9F,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAElD,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAI/D,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,UAEjD;AA6BD,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,OAAO,KAAK,CAAC,WAAW,EACjE,aAAa,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,cAAc,CAAC,EAAE,mBAAmB,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE;;;;;;0BAsB5E,MAAM;;;;;;sCAOM,YAAY,CAAC,OAAO,WAAW,CAAC;;;iEAgF5E,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YA6E+1D,CAAC;eAAqB,CAAC;oBAA0B,CAAC;kBAA2B,CAAC;;;;;;YAAowC,CAAC;oBAA0B,CAAC;eAAwB,CAAC;kBAAwB,CAAC;;;;;;;;;;;oBAA/+D,CAAC;eAAoB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAvI5zC;AAED,iBAAe,iBAAiB,CAAC,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,iBAAiB;;;;;;;;;;;;;;GAwCnG;AAiCD,iBAAe,OAAO,CAAC,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,iBAAiB;YA2CvD,QAAQ,EAAE;;;;;;;;;;;;;GAC5C;AAED,iBAAS,kBAAkB,CAAC,IAAI,EAAE;IAAE,SAAS,EAAE,UAAU,CAAA;CAAE,UAa1D"}
package/package.json CHANGED
@@ -33,8 +33,8 @@
33
33
  "@stricahq/bip32ed25519": "1.1.2",
34
34
  "@stricahq/cbors": "~1.0.2",
35
35
  "@stricahq/typhonjs": "~3.0.1",
36
- "@swapkit/helpers": "4.13.4",
37
- "@swapkit/utxo-signer": "2.1.1",
36
+ "@swapkit/helpers": "4.13.6",
37
+ "@swapkit/utxo-signer": "2.1.2",
38
38
  "@ton/crypto": "~3.3.0",
39
39
  "@ton/ton": "~15.4.0",
40
40
  "bignumber.js": "~9.3.1",
@@ -196,5 +196,5 @@
196
196
  "type-check:go": "tsgo"
197
197
  },
198
198
  "type": "module",
199
- "version": "4.15.7"
199
+ "version": "4.15.9"
200
200
  }