import{generateBip39MnemonicasBn,deriveSeedFromBip39MnemonicasAe,deriveHdPrivateNodeFromSeedasIn,deriveHdPathasPn,secp256k1asBe,hash160asNn,encodeCashAddressasss,lockingBytecodeToCashAddressasRn,cashAddressToLockingBytecodeasrs,binToHexasLn,hexToBinasis,utf8ToBinasNe,binToBase64asYt,base64ToBinasVt}from"@bitauth/libauth";varkt={chipnet:{id:"chipnet",label:"chipnet",prefix:"bchtest",beacon:"bchtest:qp8njaa9a3ahg7259s5qajnce526n0rttsq8qwx4jl",beaconScripthash:"e1cdbba719436f49acb4bf245b44df875c6d6b405eda46a9d3e736d138102f3b",tldBeacon:"bchtest:qzc4c76vtw9nd49g6x8nmvc0jz62uvk4dc7hmpmerh",tldBeaconScripthash:"c85db10e106606273422b2733b2a6fb8b35a4d0e7dbfb20cf59bdb0833c008b8",electrum:[{url:"wss://silentmode.st/electrum",ip:"195.184.247.106"},{url:"wss://coinspectrum.duckdns.org:50011",ip:"195.184.247.106"},{url:"wss://chipnet.bch.ninja:50004",ip:"135.148.236.244"},{url:"wss://chipnet.imaginary.cash:50004",ip:"66.29.152.199"},{url:"wss://tbch4.loping.net:62002",ip:"183.89.202.207"}],beaconOnly:/silentmode\.st\/electrum|coinspectrum\.duckdns\.org:50011/,electrumListName:"electrum.bch",rootTldName:"tlds.bch",bootstrapTlds:["bch"],startHeight:2e5,hostingBucket:"bns",nameListUrl:"https://s3.silentmode.st:8600/bns/name-list.json",cdnIndexUrl:"https://dl.silentmode.st/bns-name-index.json",nostrTags:{names:"bns-name-list",tlds:"bns-tld-list"},explorerTx:"https://chipnet.imaginary.cash/tx/",faucets:[{name:"tbch.googol.cash",url:"https://tbch.googol.cash/"},{name:"chipnet.bch.ninja faucet",url:"https://chipnet.bch.ninja/faucet"}],operatorAddress:"bchtest:qzew3dqcsj0guwe5y3uxf9q2xs5ajgy9lca4z093cu",accountPath:"m/44'/145'/0'",bchnRpcPort:48332},mainnet:{id:"mainnet",label:"mainnet",prefix:"bitcoincash",beacon:null,beaconScripthash:null,tldBeacon:null,tldBeaconScripthash:null,electrum:[{url:"wss://bch.imaginary.cash:50004",ip:"67.223.119.97"},{url:"wss://electrum.imaginary.cash:50004",ip:"15.204.113.162"},{url:"wss://electroncash.dk:50004",ip:"87.63.200.138"},{url:"wss://bch.loping.net:50004",ip:"183.89.202.207"},{url:"wss://bch.soul-dev.com:50004",ip:"174.141.196.204"},{url:"wss://cashnode.bch.ninja:50004",ip:"135.148.236.246"}],beaconOnly:/(?!)/,electrumListName:"electrum.bch",rootTldName:"tlds.bch",bootstrapTlds:["bch"],startHeight:null,hostingBucket:"bns-mainnet",nameListUrl:"https://s3.silentmode.st:8600/bns-mainnet/name-list.json",cdnIndexUrl:"https://dl.silentmode.st/bns-mainnet-name-index.json",nostrTags:{names:"bns-mainnet-name-list",tlds:"bns-mainnet-tld-list"},explorerTx:"https://blockchair.com/bitcoin-cash/transaction/",faucets:[],operatorAddress:null,accountPath:"m/44'/145'/0'",bchnRpcPort:8332}},Se="chipnet";functiongn(){lett=typeofglobalThis<"u"?globalThis.BNS_NETWORK:null,e=typeofprocess<"u"&&process.env?process.env.BNS_NETWORK:null;returnString(t||e||Se).trim().toLowerCase()}functionPt(t){if(t&&typeoft=="object")returnt;lete=t||gn(),n=kt[e];if(!n)thrownewError(`unknown network "${e}" (known: ${Object.keys(kt).join(", ")})`);returnn}varT=Pt();functionzt(t=T){lete=Pt(t);if(!e.beaconScripthash||!e.tldBeaconScripthash)thrownewError(`${e.label}: beacon addresses are not pinned yet (see ROADMAP-MAINNET.md \xA76)`);returne}varjo=T.beacon,Yo=T.beaconScripthash,Vo=T.tldBeacon,Xo=T.tldBeaconScripthash,Jo=T.electrum,Qo=kt.chipnet.electrum,Zo=T.electrumListName,ke="BNS1";varTe="bch",mn=/^[a-z0-9-]{1,32}$/,Ee=/^[a-z0-9-]{1,16}$/,yn=/^[a-z0-9-]{1,32}(\.[a-z0-9-]{1,16})?$/;functionwn(t){returnt.includes(".")?t:t+"."+Te}varxn=t=>{lete=newUint8Array(t.length/2);for(letn=0;n<e.length;n++)e[n]=parseInt(t.substr(n*2,2),16);returne},qt=t=>[...newTextEncoder().encode(t)].map(e=>e.toString(16).padStart(2,"0")).join("");functionkn(t){letn=String(t).toLowerCase().trim().replace(/^[a-z]+:\/\//,"").split("/")[0].replace(/\.$/,"").split(".").filter(Boolean);if(n.length===0)thrownewError(`invalid name "${t}"`);leto,s;if(n.length===1?(o=n[0],s=Te):(s=n[n.length-1],o=n[n.length-2]),!mn.test(o)||!Ee.test(s))thrownewError(`invalid name "${t}" (allowed: <label>.<tld>, [a-z0-9-])`);return`${
`),setTimeout(()=>{this.pending.has(o)&&(this.pending.delete(o),r(new Error(`electrumtimeout:${e}`)))},2e4)})}close(){try{this.ws.close()}catch{}}};async function Le(t=Rt,e){let n=[];for(let o of t)try{return await new Zt(o,e).connect()}catch(s){n.push(`${o}:${s?.message??s}`)}throw Fn(t.length,n)}function Fn(t,e){let n=new Error(`noelectrumserverreachable(tried${t}).Theseusenon-standardports,whichsomenetworksandVPNsblock:
${e.join(`
`)}`);returnn.code="NO_ELECTRUM",n.failures=e,n}import{cashAddressToLockingBytecodeas$n,lockingBytecodeToCashAddressasMn,sha256asHn,hash160asps,binToHexasKn,hexToBinasfs}from"@bitauth/libauth";functionDe(t){returnKn(Hn.hash(t).slice().reverse())}functionL(t){lete=$n(t);if(typeofe=="string")thrownewError(`bad address "${t}": ${e}`);returne.bytecode}functionWn(t){returnDe(L(t))}functionz(t){lete=L(t),n=String(t).includes(":")?t.split(":")[0]:T.prefix,o=Mn({bytecode:e,prefix:n,tokenSupport:!0});if(typeofo=="string")thrownewError(`cannot token-encode "${t}": ${o}`);returno.address}asyncfunctionCe(t,e){letn=L(e),o=De(n);return(awaitt.call("blockchain.scripthash.listunspent",[o,"include_tokens"])).map(r=>({txid:r.tx_hash,vout:r.tx_pos,satoshis:BigInt(r.value),height:r.height,address:e,lockingBytecode:n,token:r.token_data?{category:r.token_data.category,amount:BigInt(r.token_data.amount??0),nft:r.token_data.nft?{capability:r.token_data.nft.capability,commitment:r.token_data.nft.commitment}:void0}:void0}))}asyncfunctionj(t,e){letn=[];for(letoofe)n.push(...awaitCe(t,o));returnn}asyncfunctionst(t,e){returnt.call("blockchain.transaction.broadcast",[e])}import{binToHexasDt,hexToBinasX,utf8ToBinasft,binToUtf8asUe,encodeTransactionasGn,decodeTransactionasws}from"@bitauth/libauth";varzn="BNS1",dt=T.beacon,ne=T.tldBeacon,B=600n,N=1000n,W=546n,te="bch",ee=200,qn=/^[a-z0-9-]{1,32}$/,Fe=/^[a-z0-9-]{1,16}$/;functionTt(t){lete=String(t).toLowerCase().trim().replace(/^\.+/,"").replace(/\.+$/,"");if(!Fe.test(e))thrownewError(`invalid TLD "${t}" (allowed: [a-z0-9-]{1,16})`);returne}varLt=classextendsError{constructor(e){super(e),this.name="NoGenesisInputError",this.code="NO_GENESIS_INPUT"}},J=classextendsError{constructor(e,{needSats:n,haveSats:o}={}){super(e),this.name="InsufficientFundsError",this.code="INSUFFICIENT_FUNDS",this.needSats=n,this.haveSats=o}};functionH(t){lete=String(t).toLowerCase().trim().replace(/\.$/,"").split(".").filter(Boolean),n,o;if(e.length===0)thrownewError(`invalid name "${t}"`);if(e.length===1?(n=e[0],o=te):(o=e[e.length-1],n=e[e.length-2]),!qn.test(n)||!Fe.test(o))thrownewError(`invalid name "${t}" (allowed: <label>.<tld>, [a-z0-9-])`);returno===te?n:`${n}.${o}`}functionQ(t){returnt.includes(".")?t:`${t}.${te}`}functionZ(t,e,n){leto=JSON.stringify({o:t,n:e,r:n??{}}),s=ft(zn+o);if(s.length>ee)thrownewError(`records too large (${s.length} > ${ee} bytes)`);returns}functionoe(t,e="REG"){returnee-Z(e,t,{}).length}functionjn(t){returnt.length<=75?Uint8Array.from([t.length,...t]):t.length<=255?Uint8Array.from([76,t.length,...t]):Uint8Array.from([77,t.length&255,t.length>>8&255,...t])}functionet(t){returnUint8Array.from([106,...jn(t)])}functionse(){returnUint8Array.from([65,...newUint8Array(65),33,...newUint8Array(33)])}varYn=t=>!t.token;functionM(t,e,{requireGenesis:n=!0}={}){leto=t.filter(Yn),s=[],r=0n;if(n){leti=o.filter(l=>l.vout===0).sort((l,c)=>c.satoshis>l.satoshis?1:-1);if(i.length===0)thrownewLt("wallet has no coin at output index 0, which CashTokens requires to create a new certificate category \u2014 send a small amount to yourself first (buildPrepTx)");s.push(i[0]),r+=i[0].satoshis}leta=o.filter(i=>!s.some(l=>l.txid===i.txid&&l.vout===i.vout)).sort((i,l)=>l.satoshis>i.satoshis?1:-1);for(letiofa){if(r>=e)break;s.push(i),r+=i.satoshis}return{inputs:s,totalSats:r}}functiongt(t){return{outpointTransactionHash:X(t.txid),outpointIndex:t.vout,sequenceNumber:4294967294,unlockingBytecode:se()}}functionSt(t){return{...gt(t),lockingBytecode:t.lockingBytecode,valueSatoshis:t.satoshis,...t.token?{token:{amount:t.token.amount??0n,category:X(t.token.category),...t.token.nft?{nft:{capability:t.token.nft.capability,commitment:X(t.token.nft.commitment||"")}}:{}}}:{}}}functionut(t){returnGn(t).length}functionre({name:t,ownerAddress:e,ownerTokenAddress:n,changeAddress:o,records:s={},utxos:r,feeAddress:a=null,feeSats:i=0n,tldFeeAddress:l=null,tldFeeSats:c=0n,beaconAddress:h=dt,feeRate:u=1,addressToLockingBytecode:d,cosignU