@gardenfi/core 0.2.0-beta.7 → 0.2.0-beta.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.
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
- "use strict";var Mi=Object.defineProperty;var Ui=(e,t,r)=>t in e?Mi(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var it=(e,t,r)=>Ui(e,typeof t!="symbol"?t+"":t,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("@catalogfi/utils"),te=require("@gardenfi/orderbook"),Oe=require("viem"),Di=require("varuint-bitcoin"),$i=require("tiny-secp256k1"),Jr=require("@catalogfi/wallets"),Fn=require("bitcoinjs-lib");function $r(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const Yr=$r(Di),ct=$r($i),de=$r(Fn);var Br=(e=>(e[e.evm=14400]="evm",e[e.btc=288]="btc",e))(Br||{}),Re=(e=>(e.Idle="Idle",e.Initiate="Initiate",e.Redeem="Redeem",e.Refund="Refund",e))(Re||{});const We=e=>e.startsWith("0x")?e:`0x${e}`,Qr=e=>`Bearer ${e}`,Hi=e=>new Promise(t=>setTimeout(t,e)),Ln="2.21.30";let Nt={getDocsUrl:({docsBaseUrl:e,docsPath:t="",docsSlug:r})=>t?`${e??"https://viem.sh"}${t}${r?`#${r}`:""}`:void 0,version:`viem@${Ln}`},Ze=class Rr extends Error{constructor(t,r={}){var n;const o=(()=>{var p;return r.cause instanceof Rr?r.cause.details:(p=r.cause)!=null&&p.message?r.cause.message:r.details})(),s=r.cause instanceof Rr&&r.cause.docsPath||r.docsPath,c=(n=Nt.getDocsUrl)==null?void 0:n.call(Nt,{...r,docsPath:s}),u=[t||"An error occurred.","",...r.metaMessages?[...r.metaMessages,""]:[],...c?[`Docs: ${c}`]:[],...o?[`Details: ${o}`]:[],...Nt.version?[`Version: ${Nt.version}`]:[]].join(`
2
- `);super(u,r.cause?{cause:r.cause}:void 0),Object.defineProperty(this,"details",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docsPath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"metaMessages",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"shortMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"version",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"BaseError"}),this.details=o,this.docsPath=s,this.metaMessages=r.metaMessages,this.name=r.name??this.name,this.shortMessage=t,this.version=Ln}walk(t){return Mn(this,t)}};function Mn(e,t){return t!=null&&t(e)?e:e&&typeof e=="object"&&"cause"in e?Mn(e.cause,t):t?null:e}let Un=class extends Ze{constructor({blockHash:t,blockNumber:r}){let n="Block";t&&(n=`Block at hash "${t}"`),r&&(n=`Block at number "${r}"`),super(`${n} could not be found.`,{name:"BlockNotFoundError"})}},Dn=class extends Ze{constructor({blockHash:t,blockNumber:r,blockTag:n,hash:o,index:s}){let c="Transaction";n&&s!==void 0&&(c=`Transaction at block time "${n}" at index "${s}"`),t&&s!==void 0&&(c=`Transaction at block hash "${t}" at index "${s}"`),r&&s!==void 0&&(c=`Transaction at block number "${r}" at index "${s}"`),o&&(c=`Transaction with hash "${o}"`),super(`${c} could not be found.`,{name:"TransactionNotFoundError"})}};class $n extends Ze{constructor({hash:t}){super(`Transaction receipt with hash "${t}" could not be found. The Transaction may not be processed on a block yet.`,{name:"TransactionReceiptNotFoundError"})}}let ji=class extends Ze{constructor({hash:t}){super(`Timed out while waiting for transaction with hash "${t}" to be confirmed.`,{name:"WaitForTransactionReceiptTimeoutError"})}};function st(e,t,r){const n=e[t.name];if(typeof n=="function")return n;const o=e[r];return typeof o=="function"?o:s=>t(e,s)}const sr=new Map,Xr=new Map;let qi=0;function Sr(e,t,r){const n=++qi,o=()=>sr.get(e)||[],s=()=>{const g=o();sr.set(e,g.filter(w=>w.id!==n))},c=()=>{const g=Xr.get(e);o().length===1&&g&&g(),s()},u=o();if(sr.set(e,[...u,{id:n,fns:t}]),u&&u.length>0)return c;const p={};for(const g in t)p[g]=(...w)=>{var x,T;const R=o();if(R.length!==0)for(const C of R)(T=(x=C.fns)[g])==null||T.call(x,...w)};const y=r(p);return typeof y=="function"&&Xr.set(e,y),c}async function Ir(e){return new Promise(t=>setTimeout(t,e))}function Zr(e,{delay:t=100,retryCount:r=2,shouldRetry:n=()=>!0}={}){return new Promise((o,s)=>{const c=async({count:u=0}={})=>{const p=async({error:y})=>{const g=typeof t=="function"?t({count:u,error:y}):t;g&&await Ir(g),c({count:u+1})};try{const y=await e();o(y)}catch(y){if(u<r&&await n({count:u,error:y}))return p({error:y});s(y)}};c()})}const Tr=(e,t,r)=>JSON.stringify(e,(n,o)=>typeof o=="bigint"?o.toString():o,r);class Wi extends Ze{constructor({max:t,min:r,signed:n,size:o,value:s}){super(`Number "${s}" is not in safe ${o?`${o*8}-bit ${n?"signed":"unsigned"} `:""}integer range ${t?`(${r} to ${t})`:`(above ${r})`}`,{name:"IntegerOutOfRangeError"})}}let Gi=class extends Ze{constructor({givenSize:t,maxSize:r}){super(`Size cannot exceed ${r} bytes. Given size: ${t} bytes.`,{name:"SizeOverflowError"})}};class Hn extends Ze{constructor({size:t,targetSize:r,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} size (${t}) exceeds padding size (${r}).`,{name:"SizeExceedsPaddingSizeError"})}}function zi(e,{dir:t,size:r=32}={}){return typeof e=="string"?Ki(e,{dir:t,size:r}):Vi(e,{dir:t,size:r})}function Ki(e,{dir:t,size:r=32}={}){if(r===null)return e;const n=e.replace("0x","");if(n.length>r*2)throw new Hn({size:Math.ceil(n.length/2),targetSize:r,type:"hex"});return`0x${n[t==="right"?"padEnd":"padStart"](r*2,"0")}`}function Vi(e,{dir:t,size:r=32}={}){if(r===null)return e;if(e.length>r)throw new Hn({size:e.length,targetSize:r,type:"bytes"});const n=new Uint8Array(r);for(let o=0;o<r;o++){const s=t==="right";n[s?o:r-o-1]=e[s?o:e.length-o-1]}return n}function Ut(e,t={}){const{signed:r,size:n}=t,o=BigInt(e);let s;n?r?s=(1n<<BigInt(n)*8n-1n)-1n:s=2n**(BigInt(n)*8n)-1n:typeof e=="number"&&(s=BigInt(Number.MAX_SAFE_INTEGER));const c=typeof s=="bigint"&&r?-s-1n:0;if(s&&o>s||o<c){const p=typeof e=="bigint"?"n":"";throw new Wi({max:s?`${s}${p}`:void 0,min:`${c}${p}`,signed:r,size:n,value:`${e}${p}`})}const u=`0x${(r&&o<0?(1n<<BigInt(n*8))+BigInt(o):o).toString(16)}`;return n?zi(u,{size:n}):u}function Ji(e,{strict:t=!0}={}){return!e||typeof e!="string"?!1:t?/^0x[0-9a-fA-F]*$/.test(e):e.startsWith("0x")}function en(e){return Ji(e,{strict:!1})?Math.ceil((e.length-2)/2):e.length}function Yi(e,{size:t}){if(en(e)>t)throw new Gi({givenSize:en(e),maxSize:t})}function jn(e,t={}){const{signed:r}=t;t.size&&Yi(e,{size:t.size});const n=BigInt(e);if(!r)return n;const o=(e.length-2)/2,s=(1n<<BigInt(o)*8n-1n)-1n;return n<=s?n:n-BigInt(`0x${"f".padStart(o*2,"f")}`)-1n}function kr(e,t={}){return Number(jn(e,t))}const qn={"0x0":"legacy","0x1":"eip2930","0x2":"eip1559","0x3":"eip4844","0x4":"eip7702"};function Wn(e){const t={...e,blockHash:e.blockHash?e.blockHash:null,blockNumber:e.blockNumber?BigInt(e.blockNumber):null,chainId:e.chainId?kr(e.chainId):void 0,gas:e.gas?BigInt(e.gas):void 0,gasPrice:e.gasPrice?BigInt(e.gasPrice):void 0,maxFeePerBlobGas:e.maxFeePerBlobGas?BigInt(e.maxFeePerBlobGas):void 0,maxFeePerGas:e.maxFeePerGas?BigInt(e.maxFeePerGas):void 0,maxPriorityFeePerGas:e.maxPriorityFeePerGas?BigInt(e.maxPriorityFeePerGas):void 0,nonce:e.nonce?kr(e.nonce):void 0,to:e.to?e.to:null,transactionIndex:e.transactionIndex?Number(e.transactionIndex):null,type:e.type?qn[e.type]:void 0,typeHex:e.type?e.type:void 0,value:e.value?BigInt(e.value):void 0,v:e.v?BigInt(e.v):void 0};return e.authorizationList&&(t.authorizationList=Qi(e.authorizationList)),t.yParity=(()=>{if(e.yParity)return Number(e.yParity);if(typeof t.v=="bigint"){if(t.v===0n||t.v===27n)return 0;if(t.v===1n||t.v===28n)return 1;if(t.v>=35n)return t.v%2n===0n?1:0}})(),t.type==="legacy"&&(delete t.accessList,delete t.maxFeePerBlobGas,delete t.maxFeePerGas,delete t.maxPriorityFeePerGas,delete t.yParity),t.type==="eip2930"&&(delete t.maxFeePerBlobGas,delete t.maxFeePerGas,delete t.maxPriorityFeePerGas),t.type==="eip1559"&&delete t.maxFeePerBlobGas,t}function Qi(e){return e.map(t=>({contractAddress:t.address,chainId:Number(t.chainId),nonce:Number(t.nonce),r:t.r,s:t.s,yParity:Number(t.yParity)}))}function Xi(e){var t;const r=(t=e.transactions)==null?void 0:t.map(n=>typeof n=="string"?n:Wn(n));return{...e,baseFeePerGas:e.baseFeePerGas?BigInt(e.baseFeePerGas):null,blobGasUsed:e.blobGasUsed?BigInt(e.blobGasUsed):void 0,difficulty:e.difficulty?BigInt(e.difficulty):void 0,excessBlobGas:e.excessBlobGas?BigInt(e.excessBlobGas):void 0,gasLimit:e.gasLimit?BigInt(e.gasLimit):void 0,gasUsed:e.gasUsed?BigInt(e.gasUsed):void 0,hash:e.hash?e.hash:null,logsBloom:e.logsBloom?e.logsBloom:null,nonce:e.nonce?e.nonce:null,number:e.number?BigInt(e.number):null,size:e.size?BigInt(e.size):void 0,timestamp:e.timestamp?BigInt(e.timestamp):void 0,transactions:r,totalDifficulty:e.totalDifficulty?BigInt(e.totalDifficulty):null}}async function Zi(e,{blockHash:t,blockNumber:r,blockTag:n,includeTransactions:o}={}){var s,c,u;const p=n??"latest",y=o??!1,g=r!==void 0?Ut(r):void 0;let w=null;if(t?w=await e.request({method:"eth_getBlockByHash",params:[t,y]},{dedupe:!0}):w=await e.request({method:"eth_getBlockByNumber",params:[g||p,y]},{dedupe:!!g}),!w)throw new Un({blockHash:t,blockNumber:r});return(((u=(c=(s=e.chain)==null?void 0:s.formatters)==null?void 0:c.block)==null?void 0:u.format)||Xi)(w)}async function ea(e,{blockHash:t,blockNumber:r,blockTag:n,hash:o,index:s}){var c,u,p;const y=n||"latest",g=r!==void 0?Ut(r):void 0;let w=null;if(o?w=await e.request({method:"eth_getTransactionByHash",params:[o]},{dedupe:!0}):t?w=await e.request({method:"eth_getTransactionByBlockHashAndIndex",params:[t,Ut(s)]},{dedupe:!0}):(g||y)&&(w=await e.request({method:"eth_getTransactionByBlockNumberAndIndex",params:[g||y,Ut(s)]},{dedupe:!!g})),!w)throw new Dn({blockHash:t,blockNumber:r,blockTag:y,hash:o,index:s});return(((p=(u=(c=e.chain)==null?void 0:c.formatters)==null?void 0:u.transaction)==null?void 0:p.format)||Wn)(w)}function ta(e,{args:t,eventName:r}={}){return{...e,blockHash:e.blockHash?e.blockHash:null,blockNumber:e.blockNumber?BigInt(e.blockNumber):null,logIndex:e.logIndex?Number(e.logIndex):null,transactionHash:e.transactionHash?e.transactionHash:null,transactionIndex:e.transactionIndex?Number(e.transactionIndex):null,...r?{args:t,eventName:r}:{}}}const ra={"0x0":"reverted","0x1":"success"};function na(e){const t={...e,blockNumber:e.blockNumber?BigInt(e.blockNumber):null,contractAddress:e.contractAddress?e.contractAddress:null,cumulativeGasUsed:e.cumulativeGasUsed?BigInt(e.cumulativeGasUsed):null,effectiveGasPrice:e.effectiveGasPrice?BigInt(e.effectiveGasPrice):null,gasUsed:e.gasUsed?BigInt(e.gasUsed):null,logs:e.logs?e.logs.map(r=>ta(r)):null,to:e.to?e.to:null,transactionIndex:e.transactionIndex?kr(e.transactionIndex):null,status:e.status?ra[e.status]:null,type:e.type?qn[e.type]||e.type:null};return e.blobGasPrice&&(t.blobGasPrice=BigInt(e.blobGasPrice)),e.blobGasUsed&&(t.blobGasUsed=BigInt(e.blobGasUsed)),t}async function tn(e,{hash:t}){var r,n,o;const s=await e.request({method:"eth_getTransactionReceipt",params:[t]},{dedupe:!0});if(!s)throw new $n({hash:t});return(((o=(n=(r=e.chain)==null?void 0:r.formatters)==null?void 0:n.transactionReceipt)==null?void 0:o.format)||na)(s)}function ia(e,{emitOnBegin:t,initialWaitTime:r,interval:n}){let o=!0;const s=()=>o=!1;return(async()=>{let c;t&&(c=await e({unpoll:s}));const u=await(r==null?void 0:r(c))??n;await Ir(u);const p=async()=>{o&&(await e({unpoll:s}),await Ir(n),p())};p()})(),s}const aa=new Map,oa=new Map;function sa(e){const t=(o,s)=>({clear:()=>s.delete(o),get:()=>s.get(o),set:c=>s.set(o,c)}),r=t(e,aa),n=t(e,oa);return{clear:()=>{r.clear(),n.clear()},promise:r,response:n}}async function fa(e,{cacheKey:t,cacheTime:r=Number.POSITIVE_INFINITY}){const n=sa(t),o=n.response.get();if(o&&r>0&&new Date().getTime()-o.created.getTime()<r)return o.data;let s=n.promise.get();s||(s=e(),n.promise.set(s));try{const c=await s;return n.response.set({created:new Date,data:c}),c}finally{n.promise.clear()}}const ua=e=>`blockNumber.${e}`;async function ca(e,{cacheTime:t=e.cacheTime}={}){const r=await fa(()=>e.request({method:"eth_blockNumber"}),{cacheKey:ua(e.uid),cacheTime:t});return BigInt(r)}function la(e,{emitOnBegin:t=!1,emitMissed:r=!1,onBlockNumber:n,onError:o,poll:s,pollingInterval:c=e.pollingInterval}){const u=typeof s<"u"?s:!(e.transport.type==="webSocket"||e.transport.type==="fallback"&&e.transport.transports[0].config.type==="webSocket");let p;return u?(()=>{const y=Tr(["watchBlockNumber",e.uid,t,r,c]);return Sr(y,{onBlockNumber:n,onError:o},g=>ia(async()=>{var w;try{const x=await st(e,ca,"getBlockNumber")({cacheTime:0});if(p){if(x===p)return;if(x-p>1&&r)for(let T=p+1n;T<x;T++)g.onBlockNumber(T,p),p=T}(!p||x>p)&&(g.onBlockNumber(x,p),p=x)}catch(x){(w=g.onError)==null||w.call(g,x)}},{emitOnBegin:t,interval:c}))})():(()=>{const y=Tr(["watchBlockNumber",e.uid,t,r]);return Sr(y,{onBlockNumber:n,onError:o},g=>{let w=!0,x=()=>w=!1;return(async()=>{try{const T=(()=>{if(e.transport.type==="fallback"){const C=e.transport.transports.find(E=>E.config.type==="webSocket");return C?C.value:e.transport}return e.transport})(),{unsubscribe:R}=await T.subscribe({params:["newHeads"],onData(C){var E;if(!w)return;const k=jn((E=C.result)==null?void 0:E.number);g.onBlockNumber(k,p),p=k},onError(C){var E;(E=g.onError)==null||E.call(g,C)}});x=R,w||x()}catch(T){o==null||o(T)}})(),()=>x()})})()}async function ha(e,{confirmations:t=1,hash:r,onReplaced:n,pollingInterval:o=e.pollingInterval,retryCount:s=6,retryDelay:c=({count:p})=>~~(1<<p)*200,timeout:u=18e4}){const p=Tr(["waitForTransactionReceipt",e.uid,r]);let y,g,w,x=!1;return new Promise((T,R)=>{u&&setTimeout(()=>R(new ji({hash:r})),u);const C=Sr(p,{onReplaced:n,resolve:T,reject:R},E=>{const k=st(e,la,"watchBlockNumber")({emitMissed:!0,emitOnBegin:!0,poll:!0,pollingInterval:o,async onBlockNumber(O){const F=L=>{k(),L(),C()};let N=O;if(!x)try{if(w){if(t>1&&(!w.blockNumber||N-w.blockNumber+1n<t))return;F(()=>E.resolve(w));return}if(y||(x=!0,await Zr(async()=>{y=await st(e,ea,"getTransaction")({hash:r}),y.blockNumber&&(N=y.blockNumber)},{delay:c,retryCount:s}),x=!1),w=await st(e,tn,"getTransactionReceipt")({hash:r}),t>1&&(!w.blockNumber||N-w.blockNumber+1n<t))return;F(()=>E.resolve(w))}catch(L){if(L instanceof Dn||L instanceof $n){if(!y){x=!1;return}try{g=y,x=!0;const S=await Zr(()=>st(e,Zi,"getBlock")({blockNumber:N,includeTransactions:!0}),{delay:c,retryCount:s,shouldRetry:({error:U})=>U instanceof Un});x=!1;const j=S.transactions.find(({from:U,nonce:ee})=>U===g.from&&ee===g.nonce);if(!j||(w=await st(e,tn,"getTransactionReceipt")({hash:j.hash}),t>1&&(!w.blockNumber||N-w.blockNumber+1n<t)))return;let D="replaced";j.to===g.to&&j.value===g.value?D="repriced":j.from===j.to&&j.value===0n&&(D="cancelled"),F(()=>{var U;(U=E.onReplaced)==null||U.call(E,{reason:D,replacedTransaction:g,transaction:j,transactionReceipt:w}),E.resolve(w)})}catch(S){F(()=>E.reject(S))}}else F(()=>E.reject(L))}}})})})}const da=async(e,t,r,n)=>{if(!n.account)return P.Err("No account found");const o=Oe.getContract({address:We(t),abi:Oe.erc20Abi,client:n}),s=await n.getAddresses();if(!s[0])return P.Err("No account found");try{const c=await o.read.allowance([We(s[0]),We(r)]);if(BigInt(c)<BigInt(e)){const u=await o.write.approve([We(r),Oe.maxUint256],{account:n.account,chain:n.chain});return(await ha(n,{hash:u})).status!=="success"?P.Err("Failed to approve"):P.Ok(u)}return P.Ok("Already approved")}catch(c){return P.Err("Failed to approve: "+c)}};class Rt extends URL{constructor(t,r){super(t,r)}endpoint(t){t.startsWith("/")||(t=`/${t}`);const r=`${this.pathname!=="/"?this.pathname:""}${t}`;return new Rt(r,this)}socket(){if(this.protocol==="https:")return this.origin.replace("https","wss");if(this.protocol==="http:")return this.origin.replace("http","ws");throw new Error("Invalid protocol")}addSearchParams(t){const r=new URLSearchParams(this.search);for(const n in t)r.set(n,t[n]);return new Rt(`${this.pathname}?${r.toString()}`,this)}}let pa=class{constructor(){this.memory=new Map}getItem(t){return this.memory.has(t)?this.memory.get(t):null}setItem(t,r){this.memory.set(t,r)}removeItem(t){this.memory.has(t)&&this.memory.delete(t)}};function ba(e){return{formatters:void 0,fees:void 0,serializers:void 0,...e}}const ya=ba({id:1,name:"Ethereum",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://cloudflare-eth.com"]}},blockExplorers:{default:{name:"Etherscan",url:"https://etherscan.io",apiUrl:"https://api.etherscan.io/api"}},contracts:{ensRegistry:{address:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"},ensUniversalResolver:{address:"0xce01f8eee7E479C928F8919abD53E553a36CeF67",blockCreated:19258213},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:14353601}}}),ga=[42161,421614],Ar=async e=>{if(!e.chain)return P.Err("No chain found");const t=ga.includes(e.chain.id)?ya:e.chain;return await _a(t)},_a=async e=>{const t=Oe.createPublicClient({chain:e,transport:Oe.http()});try{const r=await t.getBlockNumber();return P.Ok(Number(r))}catch(r){return P.Err("Failed to fetch evm block number",r)}},rn=async e=>{try{const t=await e.getLatestTip();return P.Ok(t)}catch(t){return P.Err("Failed to fetch bitcoin block number",t)}};function Vt(e){return{formatters:void 0,fees:void 0,serializers:void 0,...e}}const ma=Vt({id:42161,name:"Arbitrum One",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://arb1.arbitrum.io/rpc"]}},blockExplorers:{default:{name:"Arbiscan",url:"https://arbiscan.io",apiUrl:"https://api.arbiscan.io/api"}},contracts:{multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:7654707}}}),wa=Vt({id:421614,name:"Arbitrum Sepolia",nativeCurrency:{name:"Arbitrum Sepolia Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://sepolia-rollup.arbitrum.io/rpc"]}},blockExplorers:{default:{name:"Arbiscan",url:"https://sepolia.arbiscan.io",apiUrl:"https://api-sepolia.arbiscan.io/api"}},contracts:{multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:81930}},testnet:!0}),va=Vt({id:1,name:"Ethereum",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://cloudflare-eth.com"]}},blockExplorers:{default:{name:"Etherscan",url:"https://etherscan.io",apiUrl:"https://api.etherscan.io/api"}},contracts:{ensRegistry:{address:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"},ensUniversalResolver:{address:"0xce01f8eee7E479C928F8919abD53E553a36CeF67",blockCreated:19258213},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:14353601}}}),xa=Vt({id:11155111,name:"Sepolia",nativeCurrency:{name:"Sepolia Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://rpc2.sepolia.org"]}},blockExplorers:{default:{name:"Etherscan",url:"https://sepolia.etherscan.io",apiUrl:"https://api-sepolia.etherscan.io/api"}},contracts:{multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:751532},ensRegistry:{address:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"},ensUniversalResolver:{address:"0xc8Af999e38273D658BE1b921b88A9Ddf005769cC",blockCreated:5317080}},testnet:!0});function Cr(e){return typeof e=="string"&&(e=Buffer.from(e,"hex")),e.length===32?e:e.subarray(1,33)}function at(e,t){if(!e)throw new Error(t)}function Ea(e){return Buffer.concat([Uint8Array.from([192]),Ba(e)])}function Ba(e){const t=Yr.encodingLength(e.length),r=Buffer.allocUnsafe(t);return Yr.encode(e.length,r),Buffer.concat([r,e])}function Ra(e,t){if(e.compare(t)>0){const r=e;e=t,t=r}return[e,t]}const Ft=e=>e.length===64?e:e.slice(2),Sa=e=>{if(!e)return!1;try{const t=Buffer.from(e,"hex");return ct.isPoint(t)}catch{return!1}},Ia={ethereum:va,ethereum_arbitrum:ma,ethereum_sepolia:xa,arbitrum_sepolia:wa,ethereum_localnet:te.EthereumLocalnet,arbitrum_localnet:te.ArbitrumLocalnet},Ta=async(e,t)=>{var n;const r=Ia[e];if(r)try{return r.id===((n=t.chain)==null?void 0:n.id)?P.Ok("Already on chain"):(await t.switchChain({id:r.id}),P.Ok("Switched chain"))}catch(o){if(ka(o))try{return await t.addChain({chain:r}),P.Ok("Added and switched chain")}catch{return P.Err("Failed to add network")}else return P.Err("Failed to switch network")}else return P.Err("Chain not supported")},ka=e=>typeof e=="object"&&e!==null&&"code"in e&&e.code===4902;var oe=(e=>(e.Created="Created",e.Matched="Matched",e.InitiateDetected="InitiateDetected",e.Initiated="Initiated",e.CounterPartyInitiateDetected="CounterPartyInitiateDetected",e.CounterPartyInitiated="CounterPartyInitiated",e.RedeemDetected="RedeemDetected",e.Redeemed="Redeemed",e.CounterPartyRedeemDetected="CounterPartyRedeemDetected",e.CounterPartyRedeemed="CounterPartyRedeemed",e.Completed="Completed",e.CounterPartySwapExpired="CounterPartySwapExpired",e.Expired="Expired",e.RefundDetected="RefundDetected",e.Refunded="Refunded",e.CounterPartyRefundDetected="CounterPartyRefundDetected",e.CounterPartyRefunded="CounterPartyRefunded",e.Cancelled="Cancelled",e))(oe||{}),Z=(e=>(e.Idle="Idle",e.InitiateDetected="InitiateDetected",e.Initiated="Initiated",e.RedeemDetected="RedeemDetected",e.Redeemed="Redeemed",e.RefundDetected="RefundDetected",e.Refunded="Refunded",e.Expired="Expired",e))(Z||{});const Gn=(e,t,r)=>{const n=Ht(e.source_swap,t),o=Ht(e.destination_swap,r);return n===Z.RedeemDetected?oe.CounterPartyRedeemDetected:n===Z.Redeemed?oe.CounterPartyRedeemed:o===Z.RedeemDetected?oe.RedeemDetected:o===Z.Redeemed?oe.Redeemed:o===Z.RefundDetected?oe.CounterPartyRefundDetected:o===Z.Refunded?oe.CounterPartyRefunded:n===Z.RefundDetected?oe.RefundDetected:n===Z.Refunded?oe.Refunded:o===Z.Expired?oe.CounterPartySwapExpired:n===Z.Expired?oe.Expired:o===Z.InitiateDetected?oe.CounterPartyInitiateDetected:o===Z.Initiated?oe.CounterPartyInitiated:n===Z.InitiateDetected?oe.InitiateDetected:n===Z.Initiated?oe.Initiated:oe.Matched},Ht=(e,t)=>{if(e.redeem_tx_hash)return e.redeem_block_number?Z.Redeemed:Z.RedeemDetected;if(e.refund_tx_hash)return e.refund_block_number?Z.Refunded:Z.RefundDetected;if(Number(e.initiate_block_number)){const r=Number(e.initiate_block_number)+e.timelock;if(t>r)return Z.Expired}return e.initiate_tx_hash?e.initiate_block_number?Z.Initiated:Z.InitiateDetected:Z.Idle},zn=(e,t,r)=>{switch(Gn(e,t,r)){case oe.Matched:return Re.Initiate;case oe.CounterPartyInitiated:return Re.Redeem;case oe.Expired:return Re.Refund;default:return Re.Idle}},Aa=[{inputs:[{internalType:"address",name:"token_",type:"address"},{internalType:"string",name:"name",type:"string"},{internalType:"string",name:"version",type:"string"}],stateMutability:"nonpayable",type:"constructor"},{inputs:[],name:"InvalidShortString",type:"error"},{inputs:[{internalType:"string",name:"str",type:"string"}],name:"StringTooLong",type:"error"},{anonymous:!1,inputs:[],name:"EIP712DomainChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"orderID",type:"bytes32"},{indexed:!0,internalType:"bytes32",name:"secretHash",type:"bytes32"},{indexed:!1,internalType:"uint256",name:"amount",type:"uint256"}],name:"Initiated",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"orderID",type:"bytes32"},{indexed:!0,internalType:"bytes32",name:"secretHash",type:"bytes32"},{indexed:!1,internalType:"bytes",name:"secret",type:"bytes"}],name:"Redeemed",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"orderID",type:"bytes32"}],name:"Refunded",type:"event"},{inputs:[],name:"eip712Domain",outputs:[{internalType:"bytes1",name:"fields",type:"bytes1"},{internalType:"string",name:"name",type:"string"},{internalType:"string",name:"version",type:"string"},{internalType:"uint256",name:"chainId",type:"uint256"},{internalType:"address",name:"verifyingContract",type:"address"},{internalType:"bytes32",name:"salt",type:"bytes32"},{internalType:"uint256[]",name:"extensions",type:"uint256[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"redeemer",type:"address"},{internalType:"uint256",name:"timelock",type:"uint256"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes32",name:"secretHash",type:"bytes32"}],name:"initiate",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"redeemer",type:"address"},{internalType:"uint256",name:"timelock",type:"uint256"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes32",name:"secretHash",type:"bytes32"},{internalType:"bytes",name:"signature",type:"bytes"}],name:"initiateWithSignature",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"orderID",type:"bytes32"},{internalType:"bytes",name:"signature",type:"bytes"}],name:"instantRefund",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{components:[{internalType:"address",name:"redeemer",type:"address"},{internalType:"uint256",name:"expiry",type:"uint256"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes32",name:"secretHash",type:"bytes32"},{internalType:"bytes",name:"signature",type:"bytes"}],internalType:"struct HTLC.InitWithSig[]",name:"inits",type:"tuple[]"},{components:[{internalType:"bytes32",name:"orderID",type:"bytes32"},{internalType:"bytes",name:"secret",type:"bytes"}],internalType:"struct HTLC.Redeem[]",name:"redeems",type:"tuple[]"},{components:[{internalType:"bytes32",name:"orderID",type:"bytes32"}],internalType:"struct HTLC.Refund[]",name:"refunds",type:"tuple[]"}],name:"multicall",outputs:[{internalType:"bool[]",name:"results",type:"bool[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"",type:"bytes32"}],name:"orders",outputs:[{internalType:"bool",name:"isFulfilled",type:"bool"},{internalType:"address",name:"initiator",type:"address"},{internalType:"address",name:"redeemer",type:"address"},{internalType:"uint256",name:"initiatedAt",type:"uint256"},{internalType:"uint256",name:"timelock",type:"uint256"},{internalType:"uint256",name:"amount",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"orderID",type:"bytes32"},{internalType:"bytes",name:"secret",type:"bytes"}],name:"redeem",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"orderID",type:"bytes32"}],name:"refund",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"token",outputs:[{internalType:"contract IERC20",name:"",type:"address"}],stateMutability:"view",type:"function"}];class Kn{constructor(t,r,n){this.url=new Rt("/relayer",r),this.auth=n,this.order=t}async init(t,r){if(!t.account)return P.Err("No account found");if(t.account.address.toLowerCase()!==this.order.source_swap.initiator.toLowerCase())return P.Err("Account and order initiator mismatch");if(!r){const g=await Ar(t);if(g.error)return P.Err(g.error);r=g.val}if(Ht(this.order.source_swap,r)!==Z.Idle)return P.Err("Invalid swap status");const{create_order:o,source_swap:s}=this.order;if(!s.amount||!s.redeemer||!o.timelock||!o.secret_hash)return P.Err("Invalid order");const c=We(o.secret_hash),u=BigInt(o.timelock),p=We(s.redeemer),y=BigInt(s.amount);try{const g=await this.auth.getToken();if(g.error)return P.Err(g.error);const w=Oe.getContract({address:We(this.order.source_swap.asset),abi:Aa,client:t}),x=await w.read.token(),T=await da(Number(y),x,this.order.source_swap.asset,t);if(T.error)return P.Err(T.error);const R=await w.read.eip712Domain(),C=await t.signTypedData({account:t.account,domain:{name:R[1],version:R[2],chainId:Number(R[3]),verifyingContract:R[4]},types:{Initiate:[{name:"redeemer",type:"address"},{name:"timelock",type:"uint256"},{name:"amount",type:"uint256"},{name:"secretHash",type:"bytes32"}]},primaryType:"Initiate",message:{redeemer:p,timelock:u,amount:y,secretHash:c}}),E=await P.Fetcher.post(this.url.endpoint("initiate"),{body:JSON.stringify({order_id:o.create_id,signature:C,perform_on:"Source"}),headers:{Authorization:Qr(g.val),"Content-Type":"application/json"}});return E.error?P.Err(E.error):E.result?P.Ok(E.result):P.Err("Init: No result found")}catch(g){return console.log("init error :",g),P.Err(String(g))}}async redeem(t,r){try{const n=await this.auth.getToken();if(n.error)return P.Err(n.error);const o=await P.Fetcher.post(this.url.endpoint("redeem"),{body:JSON.stringify({order_id:t,secret:P.trim0x(r),perform_on:"Destination"}),headers:{Authorization:Qr(n.val),"Content-Type":"application/json"}});return o.error?P.Err(o.error):o.result?P.Ok(o.result):P.Err("Redeem: No result found")}catch(n){return P.Err(String(n))}}}const Ca=Buffer.from("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","hex"),Pa=Buffer.from("483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8","hex"),Oa=Buffer.concat([Ca,Pa]),Na=Buffer.from("0250929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0","hex"),nn={failedToCreateInternalPubkey:"failed to create internal pubkey",failedToTweakPubkey:"failed to tweak pubkey"};function Fa(){const e=Fn.crypto.sha256(Buffer.from("GardenHTLC","utf-8")),t=ct.pointMultiply(Buffer.concat([Buffer.from("04","hex"),Oa]),e);if(!t)throw new Error(nn.failedToCreateInternalPubkey);const r=ct.pointAdd(Na,t);if(!r)throw new Error(nn.failedToCreateInternalPubkey);return Cr(Buffer.from(r))}const be={secretMismatch:"invalid secret",secretHashLenMismatch:"secret hash should be 32 bytes",pubkeyLenMismatch:"pubkey should be 32 bytes",zeroOrNegativeExpiry:"expiry should be greater than 0",htlcAddressGenerationFailed:"failed to generate htlc address",notFunded:"address not funded",noCounterpartySigs:"counterparty signatures are required",counterPartySigNotFound:e=>"counterparty signature not found for utxo "+e,invalidCounterpartySigForUTXO:e=>"invalid counterparty signature for utxo "+e,htlcNotExpired:e=>`HTLC not expired, need more ${e} blocks`,controlBlockGenerationFailed:"failed to generate control block",invalidLeaf:"invalid leaf"},Lt=192;de.initEccLib(ct);class jt{constructor(t,r,n,o,s,c,u){this.secretHash=n,this.redeemerPubkey=o,this.initiatorPubkey=s,this.expiry=c,this.signer=t,this.network=u,this.internalPubkey=Fa(),this.initiateAmount=r}static async from(t,r,n,o,s,c){n=n.startsWith("0x")?n.slice(2):n,at(n.length===64,be.secretHashLenMismatch),at(o.length===64||o.length===66,`initiator ${be.pubkeyLenMismatch}`),at(s.length===64||s.length===66,`redeemer ${be.pubkeyLenMismatch}`),at(c>0,be.zeroOrNegativeExpiry);const u=await t.getNetwork();return new jt(t,r,n,Cr(s).toString("hex"),Cr(o).toString("hex"),c,u)}address(){const{address:t}=de.payments.p2tr({internalPubkey:this.internalPubkey,network:this.network,scriptTree:this.leaves()});if(!t)throw new Error(be.htlcAddressGenerationFailed);return t}id(){return this.address()}async _buildRawTx(t,r){const n=new de.Transaction;n.version=2;const o=this.address(),s=await this.signer.getProvider(),c=await s.getUTXOs(o),u=c.reduce((p,y)=>p+y.value,0);if(u===0)throw new Error(`${o} ${be.notFunded}`);for(let p=0;p<c.length;p++)n.addInput(Buffer.from(c[p].txid,"hex").reverse(),c[p].vout);return r??(r=await s.suggestFee(o,u,Jr.Urgency.MEDIUM)),n.addOutput(de.address.toOutputScript(t,this.network),u-r),{tx:n,usedUtxos:c}}async buildRawTx(t){return await this._buildRawTx(await this.signer.getAddress(),t)}getOutputScript(){return de.address.toOutputScript(this.address(),this.network)}async init(t){return t??(t=await(await this.signer.getProvider()).suggestFee(await this.signer.getAddress(),this.initiateAmount,Jr.Urgency.MEDIUM)),await this.signer.send(this.address(),this.initiateAmount,t)}async instantRefund(t,r){at(t.length>0,be.noCounterpartySigs);const{tx:n,usedUtxos:o}=await this.buildRawTx(r);for(const w of o)if(!t.find(x=>x.utxo===w.txid))throw new Error(be.counterPartySigNotFound(w.txid));const s=this.getOutputScript(),c=de.Transaction.SIGHASH_DEFAULT,u=this.leafHash(2),p=o.map(w=>w.value),y=fr(s,o.length);for(let w=0;w<n.ins.length;w++){const x=n.hashForWitnessV1(w,y,p,c,u);if(!ct.verifySchnorr(x,Buffer.from(this.redeemerPubkey,"hex"),Buffer.from(t[w].sig,"hex")))throw new Error(be.invalidCounterpartySigForUTXO(t[w].utxo));const T=await this.signer.signSchnorr(x),R=Buffer.from(n.ins[w].hash).reverse().toString("hex"),C=t.find(E=>E.utxo===R);if(!C)throw new Error(be.counterPartySigNotFound(R));n.setWitness(w,[Buffer.from(C.sig,"hex"),T,this.instantRefundLeaf(),this.generateControlBlockFor(2)])}return await(await this.signer.getProvider()).broadcast(n.toHex())}async redeem(t,r,n){at(de.crypto.sha256(Buffer.from(t,"hex")).toString("hex")===this.secretHash,be.secretMismatch);const{tx:o,usedUtxos:s}=await this._buildRawTx(r??await this.signer.getAddress(),n),c=this.leafHash(1),u=s.map(w=>w.value),p=fr(this.getOutputScript(),s.length),y=de.Transaction.SIGHASH_DEFAULT;for(let w=0;w<o.ins.length;w++){const x=o.hashForWitnessV1(w,p,u,y,c),T=await this.signer.signSchnorr(x);o.setWitness(w,[T,Buffer.from(t,"hex"),this.redeemLeaf(),this.generateControlBlockFor(1)])}return await(await this.signer.getProvider()).broadcast(o.toHex())}async refund(t,r){const{tx:n,usedUtxos:o}=await this._buildRawTx(t??await this.signer.getAddress(),r),[s,c]=await this.canRefund(o);if(!s)throw new Error(be.htlcNotExpired(c));const u=this.leafHash(0),p=o.map(x=>x.value),y=fr(this.getOutputScript(),o.length),g=de.Transaction.SIGHASH_DEFAULT;for(let x=0;x<n.ins.length;x++){n.ins[x].sequence=this.expiry;const T=n.hashForWitnessV1(x,y,p,g,u),R=await this.signer.signSchnorr(T);n.setWitness(x,[R,this.refundLeaf(),this.generateControlBlockFor(0)])}return await(await this.signer.getProvider()).broadcast(n.toHex())}async canRefund(t){const n=await(await this.signer.getProvider()).getLatestTip();for(const o of t){let s=0;if(o.status.confirmed&&o.status.block_height+this.expiry>n?s=o.status.block_height+this.expiry-n+1:o.status.confirmed||(s=this.expiry+1),s>0)return[!1,s]}return[!0,0]}generateControlBlockFor(t){let r;switch(t){case 1:r=this.redeemLeaf();break;case 0:r=this.refundLeaf();break;case 2:r=this.instantRefundLeaf();break;default:throw new Error(be.invalidLeaf)}const n=de.payments.p2tr({internalPubkey:this.internalPubkey,network:this.network,scriptTree:this.leaves(),redeem:{output:r,redeemVersion:Lt}});if(!n.witness)throw new Error(be.controlBlockGenerationFailed);return n.witness[n.witness.length-1]}leafHash(t){let r=this.redeemLeaf();return t===0&&(r=this.refundLeaf()),t===2&&(r=this.instantRefundLeaf()),de.crypto.taggedHash("TapLeaf",Ea(r))}refundLeaf(){return de.script.fromASM(`
1
+ "use strict";var Di=Object.defineProperty;var $i=(e,t,r)=>t in e?Di(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var it=(e,t,r)=>$i(e,typeof t!="symbol"?t+"":t,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("@catalogfi/utils"),te=require("@gardenfi/orderbook"),Oe=require("viem"),Hi=require("varuint-bitcoin"),ji=require("tiny-secp256k1"),Jr=require("@catalogfi/wallets"),Ln=require("bitcoinjs-lib");function $r(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const Yr=$r(Hi),ct=$r(ji),de=$r(Ln);var Br=(e=>(e[e.evm=14400]="evm",e[e.btc=288]="btc",e))(Br||{}),Re=(e=>(e.Idle="Idle",e.Initiate="Initiate",e.Redeem="Redeem",e.Refund="Refund",e))(Re||{});const We=e=>e.startsWith("0x")?e:`0x${e}`,Qr=e=>`Bearer ${e}`,qi=e=>new Promise(t=>setTimeout(t,e)),Mn="2.21.30";let Nt={getDocsUrl:({docsBaseUrl:e,docsPath:t="",docsSlug:r})=>t?`${e??"https://viem.sh"}${t}${r?`#${r}`:""}`:void 0,version:`viem@${Mn}`},Ze=class Rr extends Error{constructor(t,r={}){var n;const o=(()=>{var p;return r.cause instanceof Rr?r.cause.details:(p=r.cause)!=null&&p.message?r.cause.message:r.details})(),s=r.cause instanceof Rr&&r.cause.docsPath||r.docsPath,c=(n=Nt.getDocsUrl)==null?void 0:n.call(Nt,{...r,docsPath:s}),u=[t||"An error occurred.","",...r.metaMessages?[...r.metaMessages,""]:[],...c?[`Docs: ${c}`]:[],...o?[`Details: ${o}`]:[],...Nt.version?[`Version: ${Nt.version}`]:[]].join(`
2
+ `);super(u,r.cause?{cause:r.cause}:void 0),Object.defineProperty(this,"details",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docsPath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"metaMessages",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"shortMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"version",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"BaseError"}),this.details=o,this.docsPath=s,this.metaMessages=r.metaMessages,this.name=r.name??this.name,this.shortMessage=t,this.version=Mn}walk(t){return Un(this,t)}};function Un(e,t){return t!=null&&t(e)?e:e&&typeof e=="object"&&"cause"in e?Un(e.cause,t):t?null:e}let Dn=class extends Ze{constructor({blockHash:t,blockNumber:r}){let n="Block";t&&(n=`Block at hash "${t}"`),r&&(n=`Block at number "${r}"`),super(`${n} could not be found.`,{name:"BlockNotFoundError"})}},$n=class extends Ze{constructor({blockHash:t,blockNumber:r,blockTag:n,hash:o,index:s}){let c="Transaction";n&&s!==void 0&&(c=`Transaction at block time "${n}" at index "${s}"`),t&&s!==void 0&&(c=`Transaction at block hash "${t}" at index "${s}"`),r&&s!==void 0&&(c=`Transaction at block number "${r}" at index "${s}"`),o&&(c=`Transaction with hash "${o}"`),super(`${c} could not be found.`,{name:"TransactionNotFoundError"})}};class Hn extends Ze{constructor({hash:t}){super(`Transaction receipt with hash "${t}" could not be found. The Transaction may not be processed on a block yet.`,{name:"TransactionReceiptNotFoundError"})}}let Wi=class extends Ze{constructor({hash:t}){super(`Timed out while waiting for transaction with hash "${t}" to be confirmed.`,{name:"WaitForTransactionReceiptTimeoutError"})}};function st(e,t,r){const n=e[t.name];if(typeof n=="function")return n;const o=e[r];return typeof o=="function"?o:s=>t(e,s)}const sr=new Map,Xr=new Map;let Gi=0;function Sr(e,t,r){const n=++Gi,o=()=>sr.get(e)||[],s=()=>{const g=o();sr.set(e,g.filter(w=>w.id!==n))},c=()=>{const g=Xr.get(e);o().length===1&&g&&g(),s()},u=o();if(sr.set(e,[...u,{id:n,fns:t}]),u&&u.length>0)return c;const p={};for(const g in t)p[g]=(...w)=>{var x,k;const R=o();if(R.length!==0)for(const C of R)(k=(x=C.fns)[g])==null||k.call(x,...w)};const y=r(p);return typeof y=="function"&&Xr.set(e,y),c}async function Ir(e){return new Promise(t=>setTimeout(t,e))}function Zr(e,{delay:t=100,retryCount:r=2,shouldRetry:n=()=>!0}={}){return new Promise((o,s)=>{const c=async({count:u=0}={})=>{const p=async({error:y})=>{const g=typeof t=="function"?t({count:u,error:y}):t;g&&await Ir(g),c({count:u+1})};try{const y=await e();o(y)}catch(y){if(u<r&&await n({count:u,error:y}))return p({error:y});s(y)}};c()})}const kr=(e,t,r)=>JSON.stringify(e,(n,o)=>typeof o=="bigint"?o.toString():o,r);class zi extends Ze{constructor({max:t,min:r,signed:n,size:o,value:s}){super(`Number "${s}" is not in safe ${o?`${o*8}-bit ${n?"signed":"unsigned"} `:""}integer range ${t?`(${r} to ${t})`:`(above ${r})`}`,{name:"IntegerOutOfRangeError"})}}let Ki=class extends Ze{constructor({givenSize:t,maxSize:r}){super(`Size cannot exceed ${r} bytes. Given size: ${t} bytes.`,{name:"SizeOverflowError"})}};class jn extends Ze{constructor({size:t,targetSize:r,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} size (${t}) exceeds padding size (${r}).`,{name:"SizeExceedsPaddingSizeError"})}}function Vi(e,{dir:t,size:r=32}={}){return typeof e=="string"?Ji(e,{dir:t,size:r}):Yi(e,{dir:t,size:r})}function Ji(e,{dir:t,size:r=32}={}){if(r===null)return e;const n=e.replace("0x","");if(n.length>r*2)throw new jn({size:Math.ceil(n.length/2),targetSize:r,type:"hex"});return`0x${n[t==="right"?"padEnd":"padStart"](r*2,"0")}`}function Yi(e,{dir:t,size:r=32}={}){if(r===null)return e;if(e.length>r)throw new jn({size:e.length,targetSize:r,type:"bytes"});const n=new Uint8Array(r);for(let o=0;o<r;o++){const s=t==="right";n[s?o:r-o-1]=e[s?o:e.length-o-1]}return n}function Ut(e,t={}){const{signed:r,size:n}=t,o=BigInt(e);let s;n?r?s=(1n<<BigInt(n)*8n-1n)-1n:s=2n**(BigInt(n)*8n)-1n:typeof e=="number"&&(s=BigInt(Number.MAX_SAFE_INTEGER));const c=typeof s=="bigint"&&r?-s-1n:0;if(s&&o>s||o<c){const p=typeof e=="bigint"?"n":"";throw new zi({max:s?`${s}${p}`:void 0,min:`${c}${p}`,signed:r,size:n,value:`${e}${p}`})}const u=`0x${(r&&o<0?(1n<<BigInt(n*8))+BigInt(o):o).toString(16)}`;return n?Vi(u,{size:n}):u}function Qi(e,{strict:t=!0}={}){return!e||typeof e!="string"?!1:t?/^0x[0-9a-fA-F]*$/.test(e):e.startsWith("0x")}function en(e){return Qi(e,{strict:!1})?Math.ceil((e.length-2)/2):e.length}function Xi(e,{size:t}){if(en(e)>t)throw new Ki({givenSize:en(e),maxSize:t})}function qn(e,t={}){const{signed:r}=t;t.size&&Xi(e,{size:t.size});const n=BigInt(e);if(!r)return n;const o=(e.length-2)/2,s=(1n<<BigInt(o)*8n-1n)-1n;return n<=s?n:n-BigInt(`0x${"f".padStart(o*2,"f")}`)-1n}function Tr(e,t={}){return Number(qn(e,t))}const Wn={"0x0":"legacy","0x1":"eip2930","0x2":"eip1559","0x3":"eip4844","0x4":"eip7702"};function Gn(e){const t={...e,blockHash:e.blockHash?e.blockHash:null,blockNumber:e.blockNumber?BigInt(e.blockNumber):null,chainId:e.chainId?Tr(e.chainId):void 0,gas:e.gas?BigInt(e.gas):void 0,gasPrice:e.gasPrice?BigInt(e.gasPrice):void 0,maxFeePerBlobGas:e.maxFeePerBlobGas?BigInt(e.maxFeePerBlobGas):void 0,maxFeePerGas:e.maxFeePerGas?BigInt(e.maxFeePerGas):void 0,maxPriorityFeePerGas:e.maxPriorityFeePerGas?BigInt(e.maxPriorityFeePerGas):void 0,nonce:e.nonce?Tr(e.nonce):void 0,to:e.to?e.to:null,transactionIndex:e.transactionIndex?Number(e.transactionIndex):null,type:e.type?Wn[e.type]:void 0,typeHex:e.type?e.type:void 0,value:e.value?BigInt(e.value):void 0,v:e.v?BigInt(e.v):void 0};return e.authorizationList&&(t.authorizationList=Zi(e.authorizationList)),t.yParity=(()=>{if(e.yParity)return Number(e.yParity);if(typeof t.v=="bigint"){if(t.v===0n||t.v===27n)return 0;if(t.v===1n||t.v===28n)return 1;if(t.v>=35n)return t.v%2n===0n?1:0}})(),t.type==="legacy"&&(delete t.accessList,delete t.maxFeePerBlobGas,delete t.maxFeePerGas,delete t.maxPriorityFeePerGas,delete t.yParity),t.type==="eip2930"&&(delete t.maxFeePerBlobGas,delete t.maxFeePerGas,delete t.maxPriorityFeePerGas),t.type==="eip1559"&&delete t.maxFeePerBlobGas,t}function Zi(e){return e.map(t=>({contractAddress:t.address,chainId:Number(t.chainId),nonce:Number(t.nonce),r:t.r,s:t.s,yParity:Number(t.yParity)}))}function ea(e){var t;const r=(t=e.transactions)==null?void 0:t.map(n=>typeof n=="string"?n:Gn(n));return{...e,baseFeePerGas:e.baseFeePerGas?BigInt(e.baseFeePerGas):null,blobGasUsed:e.blobGasUsed?BigInt(e.blobGasUsed):void 0,difficulty:e.difficulty?BigInt(e.difficulty):void 0,excessBlobGas:e.excessBlobGas?BigInt(e.excessBlobGas):void 0,gasLimit:e.gasLimit?BigInt(e.gasLimit):void 0,gasUsed:e.gasUsed?BigInt(e.gasUsed):void 0,hash:e.hash?e.hash:null,logsBloom:e.logsBloom?e.logsBloom:null,nonce:e.nonce?e.nonce:null,number:e.number?BigInt(e.number):null,size:e.size?BigInt(e.size):void 0,timestamp:e.timestamp?BigInt(e.timestamp):void 0,transactions:r,totalDifficulty:e.totalDifficulty?BigInt(e.totalDifficulty):null}}async function ta(e,{blockHash:t,blockNumber:r,blockTag:n,includeTransactions:o}={}){var s,c,u;const p=n??"latest",y=o??!1,g=r!==void 0?Ut(r):void 0;let w=null;if(t?w=await e.request({method:"eth_getBlockByHash",params:[t,y]},{dedupe:!0}):w=await e.request({method:"eth_getBlockByNumber",params:[g||p,y]},{dedupe:!!g}),!w)throw new Dn({blockHash:t,blockNumber:r});return(((u=(c=(s=e.chain)==null?void 0:s.formatters)==null?void 0:c.block)==null?void 0:u.format)||ea)(w)}async function ra(e,{blockHash:t,blockNumber:r,blockTag:n,hash:o,index:s}){var c,u,p;const y=n||"latest",g=r!==void 0?Ut(r):void 0;let w=null;if(o?w=await e.request({method:"eth_getTransactionByHash",params:[o]},{dedupe:!0}):t?w=await e.request({method:"eth_getTransactionByBlockHashAndIndex",params:[t,Ut(s)]},{dedupe:!0}):(g||y)&&(w=await e.request({method:"eth_getTransactionByBlockNumberAndIndex",params:[g||y,Ut(s)]},{dedupe:!!g})),!w)throw new $n({blockHash:t,blockNumber:r,blockTag:y,hash:o,index:s});return(((p=(u=(c=e.chain)==null?void 0:c.formatters)==null?void 0:u.transaction)==null?void 0:p.format)||Gn)(w)}function na(e,{args:t,eventName:r}={}){return{...e,blockHash:e.blockHash?e.blockHash:null,blockNumber:e.blockNumber?BigInt(e.blockNumber):null,logIndex:e.logIndex?Number(e.logIndex):null,transactionHash:e.transactionHash?e.transactionHash:null,transactionIndex:e.transactionIndex?Number(e.transactionIndex):null,...r?{args:t,eventName:r}:{}}}const ia={"0x0":"reverted","0x1":"success"};function aa(e){const t={...e,blockNumber:e.blockNumber?BigInt(e.blockNumber):null,contractAddress:e.contractAddress?e.contractAddress:null,cumulativeGasUsed:e.cumulativeGasUsed?BigInt(e.cumulativeGasUsed):null,effectiveGasPrice:e.effectiveGasPrice?BigInt(e.effectiveGasPrice):null,gasUsed:e.gasUsed?BigInt(e.gasUsed):null,logs:e.logs?e.logs.map(r=>na(r)):null,to:e.to?e.to:null,transactionIndex:e.transactionIndex?Tr(e.transactionIndex):null,status:e.status?ia[e.status]:null,type:e.type?Wn[e.type]||e.type:null};return e.blobGasPrice&&(t.blobGasPrice=BigInt(e.blobGasPrice)),e.blobGasUsed&&(t.blobGasUsed=BigInt(e.blobGasUsed)),t}async function tn(e,{hash:t}){var r,n,o;const s=await e.request({method:"eth_getTransactionReceipt",params:[t]},{dedupe:!0});if(!s)throw new Hn({hash:t});return(((o=(n=(r=e.chain)==null?void 0:r.formatters)==null?void 0:n.transactionReceipt)==null?void 0:o.format)||aa)(s)}function oa(e,{emitOnBegin:t,initialWaitTime:r,interval:n}){let o=!0;const s=()=>o=!1;return(async()=>{let c;t&&(c=await e({unpoll:s}));const u=await(r==null?void 0:r(c))??n;await Ir(u);const p=async()=>{o&&(await e({unpoll:s}),await Ir(n),p())};p()})(),s}const sa=new Map,fa=new Map;function ua(e){const t=(o,s)=>({clear:()=>s.delete(o),get:()=>s.get(o),set:c=>s.set(o,c)}),r=t(e,sa),n=t(e,fa);return{clear:()=>{r.clear(),n.clear()},promise:r,response:n}}async function ca(e,{cacheKey:t,cacheTime:r=Number.POSITIVE_INFINITY}){const n=ua(t),o=n.response.get();if(o&&r>0&&new Date().getTime()-o.created.getTime()<r)return o.data;let s=n.promise.get();s||(s=e(),n.promise.set(s));try{const c=await s;return n.response.set({created:new Date,data:c}),c}finally{n.promise.clear()}}const la=e=>`blockNumber.${e}`;async function ha(e,{cacheTime:t=e.cacheTime}={}){const r=await ca(()=>e.request({method:"eth_blockNumber"}),{cacheKey:la(e.uid),cacheTime:t});return BigInt(r)}function da(e,{emitOnBegin:t=!1,emitMissed:r=!1,onBlockNumber:n,onError:o,poll:s,pollingInterval:c=e.pollingInterval}){const u=typeof s<"u"?s:!(e.transport.type==="webSocket"||e.transport.type==="fallback"&&e.transport.transports[0].config.type==="webSocket");let p;return u?(()=>{const y=kr(["watchBlockNumber",e.uid,t,r,c]);return Sr(y,{onBlockNumber:n,onError:o},g=>oa(async()=>{var w;try{const x=await st(e,ha,"getBlockNumber")({cacheTime:0});if(p){if(x===p)return;if(x-p>1&&r)for(let k=p+1n;k<x;k++)g.onBlockNumber(k,p),p=k}(!p||x>p)&&(g.onBlockNumber(x,p),p=x)}catch(x){(w=g.onError)==null||w.call(g,x)}},{emitOnBegin:t,interval:c}))})():(()=>{const y=kr(["watchBlockNumber",e.uid,t,r]);return Sr(y,{onBlockNumber:n,onError:o},g=>{let w=!0,x=()=>w=!1;return(async()=>{try{const k=(()=>{if(e.transport.type==="fallback"){const C=e.transport.transports.find(E=>E.config.type==="webSocket");return C?C.value:e.transport}return e.transport})(),{unsubscribe:R}=await k.subscribe({params:["newHeads"],onData(C){var E;if(!w)return;const T=qn((E=C.result)==null?void 0:E.number);g.onBlockNumber(T,p),p=T},onError(C){var E;(E=g.onError)==null||E.call(g,C)}});x=R,w||x()}catch(k){o==null||o(k)}})(),()=>x()})})()}async function pa(e,{confirmations:t=1,hash:r,onReplaced:n,pollingInterval:o=e.pollingInterval,retryCount:s=6,retryDelay:c=({count:p})=>~~(1<<p)*200,timeout:u=18e4}){const p=kr(["waitForTransactionReceipt",e.uid,r]);let y,g,w,x=!1;return new Promise((k,R)=>{u&&setTimeout(()=>R(new Wi({hash:r})),u);const C=Sr(p,{onReplaced:n,resolve:k,reject:R},E=>{const T=st(e,da,"watchBlockNumber")({emitMissed:!0,emitOnBegin:!0,poll:!0,pollingInterval:o,async onBlockNumber(O){const F=L=>{T(),L(),C()};let N=O;if(!x)try{if(w){if(t>1&&(!w.blockNumber||N-w.blockNumber+1n<t))return;F(()=>E.resolve(w));return}if(y||(x=!0,await Zr(async()=>{y=await st(e,ra,"getTransaction")({hash:r}),y.blockNumber&&(N=y.blockNumber)},{delay:c,retryCount:s}),x=!1),w=await st(e,tn,"getTransactionReceipt")({hash:r}),t>1&&(!w.blockNumber||N-w.blockNumber+1n<t))return;F(()=>E.resolve(w))}catch(L){if(L instanceof $n||L instanceof Hn){if(!y){x=!1;return}try{g=y,x=!0;const S=await Zr(()=>st(e,ta,"getBlock")({blockNumber:N,includeTransactions:!0}),{delay:c,retryCount:s,shouldRetry:({error:U})=>U instanceof Dn});x=!1;const j=S.transactions.find(({from:U,nonce:ee})=>U===g.from&&ee===g.nonce);if(!j||(w=await st(e,tn,"getTransactionReceipt")({hash:j.hash}),t>1&&(!w.blockNumber||N-w.blockNumber+1n<t)))return;let D="replaced";j.to===g.to&&j.value===g.value?D="repriced":j.from===j.to&&j.value===0n&&(D="cancelled"),F(()=>{var U;(U=E.onReplaced)==null||U.call(E,{reason:D,replacedTransaction:g,transaction:j,transactionReceipt:w}),E.resolve(w)})}catch(S){F(()=>E.reject(S))}}else F(()=>E.reject(L))}}})})})}const ba=async(e,t,r,n)=>{if(!n.account)return P.Err("No account found");console.log("walletClient.chain",n.chain);const o=Oe.getContract({address:We(t),abi:Oe.erc20Abi,client:n}),s=await n.getAddresses();if(!s[0])return P.Err("No account found");try{const c=await o.read.allowance([We(s[0]),We(r)]);if(BigInt(c)<BigInt(e)){const u=await o.write.approve([We(r),Oe.maxUint256],{account:n.account,chain:n.chain});return(await pa(n,{hash:u})).status!=="success"?P.Err("Failed to approve"):P.Ok(u)}return P.Ok("Already approved")}catch(c){return P.Err("Failed to approve: "+c)}};class Rt extends URL{constructor(t,r){super(t,r)}endpoint(t){t.startsWith("/")||(t=`/${t}`);const r=`${this.pathname!=="/"?this.pathname:""}${t}`;return new Rt(r,this)}socket(){if(this.protocol==="https:")return this.origin.replace("https","wss");if(this.protocol==="http:")return this.origin.replace("http","ws");throw new Error("Invalid protocol")}addSearchParams(t){const r=new URLSearchParams(this.search);for(const n in t)r.set(n,t[n]);return new Rt(`${this.pathname}?${r.toString()}`,this)}}class ya{constructor(){this.memory=new Map}getItem(t){return this.memory.has(t)?this.memory.get(t):null}setItem(t,r){this.memory.set(t,r)}removeItem(t){this.memory.has(t)&&this.memory.delete(t)}}function zn(e){return{formatters:void 0,fees:void 0,serializers:void 0,...e}}const ga=zn({id:1,name:"Ethereum",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://cloudflare-eth.com"]}},blockExplorers:{default:{name:"Etherscan",url:"https://etherscan.io",apiUrl:"https://api.etherscan.io/api"}},contracts:{ensRegistry:{address:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"},ensUniversalResolver:{address:"0xce01f8eee7E479C928F8919abD53E553a36CeF67",blockCreated:19258213},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:14353601}}}),_a=zn({id:11155111,name:"Sepolia",nativeCurrency:{name:"Sepolia Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://rpc2.sepolia.org"]}},blockExplorers:{default:{name:"Etherscan",url:"https://sepolia.etherscan.io",apiUrl:"https://api-sepolia.etherscan.io/api"}},contracts:{multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:751532},ensRegistry:{address:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"},ensUniversalResolver:{address:"0xc8Af999e38273D658BE1b921b88A9Ddf005769cC",blockCreated:5317080}},testnet:!0}),rn={42161:ga,421614:_a},Ar=async e=>{if(!e.chain)return P.Err("No chain found");const t=Object.keys(rn).includes(e.chain.id.toString())?rn[e.chain.id]:e.chain;return await ma(t)},ma=async e=>{const t=Oe.createPublicClient({chain:e,transport:Oe.http()});try{const r=await t.getBlockNumber();return P.Ok(Number(r))}catch(r){return P.Err("Failed to fetch evm block number",r)}},nn=async e=>{try{const t=await e.getLatestTip();return P.Ok(t)}catch(t){return P.Err("Failed to fetch bitcoin block number",t)}};function Vt(e){return{formatters:void 0,fees:void 0,serializers:void 0,...e}}const wa=Vt({id:42161,name:"Arbitrum One",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://arb1.arbitrum.io/rpc"]}},blockExplorers:{default:{name:"Arbiscan",url:"https://arbiscan.io",apiUrl:"https://api.arbiscan.io/api"}},contracts:{multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:7654707}}}),va=Vt({id:421614,name:"Arbitrum Sepolia",nativeCurrency:{name:"Arbitrum Sepolia Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://sepolia-rollup.arbitrum.io/rpc"]}},blockExplorers:{default:{name:"Arbiscan",url:"https://sepolia.arbiscan.io",apiUrl:"https://api-sepolia.arbiscan.io/api"}},contracts:{multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:81930}},testnet:!0}),xa=Vt({id:1,name:"Ethereum",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://cloudflare-eth.com"]}},blockExplorers:{default:{name:"Etherscan",url:"https://etherscan.io",apiUrl:"https://api.etherscan.io/api"}},contracts:{ensRegistry:{address:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"},ensUniversalResolver:{address:"0xce01f8eee7E479C928F8919abD53E553a36CeF67",blockCreated:19258213},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:14353601}}}),Ea=Vt({id:11155111,name:"Sepolia",nativeCurrency:{name:"Sepolia Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://rpc2.sepolia.org"]}},blockExplorers:{default:{name:"Etherscan",url:"https://sepolia.etherscan.io",apiUrl:"https://api-sepolia.etherscan.io/api"}},contracts:{multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:751532},ensRegistry:{address:"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"},ensUniversalResolver:{address:"0xc8Af999e38273D658BE1b921b88A9Ddf005769cC",blockCreated:5317080}},testnet:!0});function Cr(e){return typeof e=="string"&&(e=Buffer.from(e,"hex")),e.length===32?e:e.subarray(1,33)}function at(e,t){if(!e)throw new Error(t)}function Ba(e){return Buffer.concat([Uint8Array.from([192]),Ra(e)])}function Ra(e){const t=Yr.encodingLength(e.length),r=Buffer.allocUnsafe(t);return Yr.encode(e.length,r),Buffer.concat([r,e])}function Sa(e,t){if(e.compare(t)>0){const r=e;e=t,t=r}return[e,t]}const Ft=e=>e.length===64?e:e.slice(2),Ia=e=>{if(!e)return!1;try{const t=Buffer.from(e,"hex");return ct.isPoint(t)}catch{return!1}},ka={ethereum:xa,ethereum_arbitrum:wa,ethereum_sepolia:Ea,arbitrum_sepolia:va,ethereum_localnet:te.EthereumLocalnet,arbitrum_localnet:te.ArbitrumLocalnet},Ta=async(e,t)=>{var n;const r=ka[e];if(r)try{return r.id===((n=t.chain)==null?void 0:n.id)?P.Ok("Already on chain"):(await t.switchChain({id:r.id}),P.Ok("Switched chain"))}catch(o){if(Aa(o))try{return await t.addChain({chain:r}),P.Ok("Added and switched chain")}catch{return P.Err("Failed to add network")}else return P.Err("Failed to switch network")}else return P.Err("Chain not supported")},Aa=e=>typeof e=="object"&&e!==null&&"code"in e&&e.code===4902;var oe=(e=>(e.Created="Created",e.Matched="Matched",e.InitiateDetected="InitiateDetected",e.Initiated="Initiated",e.CounterPartyInitiateDetected="CounterPartyInitiateDetected",e.CounterPartyInitiated="CounterPartyInitiated",e.RedeemDetected="RedeemDetected",e.Redeemed="Redeemed",e.CounterPartyRedeemDetected="CounterPartyRedeemDetected",e.CounterPartyRedeemed="CounterPartyRedeemed",e.Completed="Completed",e.CounterPartySwapExpired="CounterPartySwapExpired",e.Expired="Expired",e.RefundDetected="RefundDetected",e.Refunded="Refunded",e.CounterPartyRefundDetected="CounterPartyRefundDetected",e.CounterPartyRefunded="CounterPartyRefunded",e.Cancelled="Cancelled",e))(oe||{}),Z=(e=>(e.Idle="Idle",e.InitiateDetected="InitiateDetected",e.Initiated="Initiated",e.RedeemDetected="RedeemDetected",e.Redeemed="Redeemed",e.RefundDetected="RefundDetected",e.Refunded="Refunded",e.Expired="Expired",e))(Z||{});const Kn=(e,t,r)=>{const n=Ht(e.source_swap,t),o=Ht(e.destination_swap,r);return n===Z.RedeemDetected?oe.CounterPartyRedeemDetected:n===Z.Redeemed?oe.CounterPartyRedeemed:o===Z.RedeemDetected?oe.RedeemDetected:o===Z.Redeemed?oe.Redeemed:o===Z.RefundDetected?oe.CounterPartyRefundDetected:o===Z.Refunded?oe.CounterPartyRefunded:n===Z.RefundDetected?oe.RefundDetected:n===Z.Refunded?oe.Refunded:o===Z.Expired?oe.CounterPartySwapExpired:n===Z.Expired?oe.Expired:o===Z.InitiateDetected?oe.CounterPartyInitiateDetected:o===Z.Initiated?oe.CounterPartyInitiated:n===Z.InitiateDetected?oe.InitiateDetected:n===Z.Initiated?oe.Initiated:oe.Matched},Ht=(e,t)=>{if(e.redeem_tx_hash)return e.redeem_block_number?Z.Redeemed:Z.RedeemDetected;if(e.refund_tx_hash)return e.refund_block_number?Z.Refunded:Z.RefundDetected;if(Number(e.initiate_block_number)){const r=Number(e.initiate_block_number)+e.timelock;if(t>r)return Z.Expired}return e.initiate_tx_hash?e.initiate_block_number?Z.Initiated:Z.InitiateDetected:Z.Idle},Vn=(e,t,r)=>{switch(Kn(e,t,r)){case oe.Matched:return Re.Initiate;case oe.CounterPartyInitiated:return Re.Redeem;case oe.Expired:return Re.Refund;default:return Re.Idle}},Ca=[{inputs:[{internalType:"address",name:"token_",type:"address"},{internalType:"string",name:"name",type:"string"},{internalType:"string",name:"version",type:"string"}],stateMutability:"nonpayable",type:"constructor"},{inputs:[],name:"InvalidShortString",type:"error"},{inputs:[{internalType:"string",name:"str",type:"string"}],name:"StringTooLong",type:"error"},{anonymous:!1,inputs:[],name:"EIP712DomainChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"orderID",type:"bytes32"},{indexed:!0,internalType:"bytes32",name:"secretHash",type:"bytes32"},{indexed:!1,internalType:"uint256",name:"amount",type:"uint256"}],name:"Initiated",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"orderID",type:"bytes32"},{indexed:!0,internalType:"bytes32",name:"secretHash",type:"bytes32"},{indexed:!1,internalType:"bytes",name:"secret",type:"bytes"}],name:"Redeemed",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"orderID",type:"bytes32"}],name:"Refunded",type:"event"},{inputs:[],name:"eip712Domain",outputs:[{internalType:"bytes1",name:"fields",type:"bytes1"},{internalType:"string",name:"name",type:"string"},{internalType:"string",name:"version",type:"string"},{internalType:"uint256",name:"chainId",type:"uint256"},{internalType:"address",name:"verifyingContract",type:"address"},{internalType:"bytes32",name:"salt",type:"bytes32"},{internalType:"uint256[]",name:"extensions",type:"uint256[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"redeemer",type:"address"},{internalType:"uint256",name:"timelock",type:"uint256"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes32",name:"secretHash",type:"bytes32"}],name:"initiate",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"redeemer",type:"address"},{internalType:"uint256",name:"timelock",type:"uint256"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes32",name:"secretHash",type:"bytes32"},{internalType:"bytes",name:"signature",type:"bytes"}],name:"initiateWithSignature",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"orderID",type:"bytes32"},{internalType:"bytes",name:"signature",type:"bytes"}],name:"instantRefund",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{components:[{internalType:"address",name:"redeemer",type:"address"},{internalType:"uint256",name:"expiry",type:"uint256"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes32",name:"secretHash",type:"bytes32"},{internalType:"bytes",name:"signature",type:"bytes"}],internalType:"struct HTLC.InitWithSig[]",name:"inits",type:"tuple[]"},{components:[{internalType:"bytes32",name:"orderID",type:"bytes32"},{internalType:"bytes",name:"secret",type:"bytes"}],internalType:"struct HTLC.Redeem[]",name:"redeems",type:"tuple[]"},{components:[{internalType:"bytes32",name:"orderID",type:"bytes32"}],internalType:"struct HTLC.Refund[]",name:"refunds",type:"tuple[]"}],name:"multicall",outputs:[{internalType:"bool[]",name:"results",type:"bool[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"",type:"bytes32"}],name:"orders",outputs:[{internalType:"bool",name:"isFulfilled",type:"bool"},{internalType:"address",name:"initiator",type:"address"},{internalType:"address",name:"redeemer",type:"address"},{internalType:"uint256",name:"initiatedAt",type:"uint256"},{internalType:"uint256",name:"timelock",type:"uint256"},{internalType:"uint256",name:"amount",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"orderID",type:"bytes32"},{internalType:"bytes",name:"secret",type:"bytes"}],name:"redeem",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"orderID",type:"bytes32"}],name:"refund",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"token",outputs:[{internalType:"contract IERC20",name:"",type:"address"}],stateMutability:"view",type:"function"}];class Jn{constructor(t,r,n){this.url=new Rt("/relayer",r),this.auth=n,this.order=t}async init(t,r){if(!t.account)return P.Err("No account found");if(t.account.address.toLowerCase()!==this.order.source_swap.initiator.toLowerCase())return P.Err("Account and order initiator mismatch");if(!r){const g=await Ar(t);if(g.error)return P.Err(g.error);r=g.val}if(Ht(this.order.source_swap,r)!==Z.Idle)return P.Err("Invalid swap status");const{create_order:o,source_swap:s}=this.order;if(!s.amount||!s.redeemer||!o.timelock||!o.secret_hash)return P.Err("Invalid order");const c=We(o.secret_hash),u=BigInt(o.timelock),p=We(s.redeemer),y=BigInt(s.amount);try{const g=await this.auth.getToken();if(g.error)return P.Err(g.error);const w=Oe.getContract({address:We(this.order.source_swap.asset),abi:Ca,client:t}),x=await w.read.token(),k=await ba(Number(y),x,this.order.source_swap.asset,t);if(k.error)return P.Err(k.error);const R=await w.read.eip712Domain(),C=await t.signTypedData({account:t.account,domain:{name:R[1],version:R[2],chainId:Number(R[3]),verifyingContract:R[4]},types:{Initiate:[{name:"redeemer",type:"address"},{name:"timelock",type:"uint256"},{name:"amount",type:"uint256"},{name:"secretHash",type:"bytes32"}]},primaryType:"Initiate",message:{redeemer:p,timelock:u,amount:y,secretHash:c}}),E=await P.Fetcher.post(this.url.endpoint("initiate"),{body:JSON.stringify({order_id:o.create_id,signature:C,perform_on:"Source"}),headers:{Authorization:Qr(g.val),"Content-Type":"application/json"}});return E.error?P.Err(E.error):E.result?P.Ok(E.result):P.Err("Init: No result found")}catch(g){return console.log("init error :",g),P.Err(String(g))}}async redeem(t,r){try{const n=await this.auth.getToken();if(n.error)return P.Err(n.error);const o=await P.Fetcher.post(this.url.endpoint("redeem"),{body:JSON.stringify({order_id:t,secret:P.trim0x(r),perform_on:"Destination"}),headers:{Authorization:Qr(n.val),"Content-Type":"application/json"}});return o.error?P.Err(o.error):o.result?P.Ok(o.result):P.Err("Redeem: No result found")}catch(n){return P.Err(String(n))}}}const Pa=Buffer.from("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","hex"),Oa=Buffer.from("483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8","hex"),Na=Buffer.concat([Pa,Oa]),Fa=Buffer.from("0250929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0","hex"),an={failedToCreateInternalPubkey:"failed to create internal pubkey",failedToTweakPubkey:"failed to tweak pubkey"};function La(){const e=Ln.crypto.sha256(Buffer.from("GardenHTLC","utf-8")),t=ct.pointMultiply(Buffer.concat([Buffer.from("04","hex"),Na]),e);if(!t)throw new Error(an.failedToCreateInternalPubkey);const r=ct.pointAdd(Fa,t);if(!r)throw new Error(an.failedToCreateInternalPubkey);return Cr(Buffer.from(r))}const be={secretMismatch:"invalid secret",secretHashLenMismatch:"secret hash should be 32 bytes",pubkeyLenMismatch:"pubkey should be 32 bytes",zeroOrNegativeExpiry:"expiry should be greater than 0",htlcAddressGenerationFailed:"failed to generate htlc address",notFunded:"address not funded",noCounterpartySigs:"counterparty signatures are required",counterPartySigNotFound:e=>"counterparty signature not found for utxo "+e,invalidCounterpartySigForUTXO:e=>"invalid counterparty signature for utxo "+e,htlcNotExpired:e=>`HTLC not expired, need more ${e} blocks`,controlBlockGenerationFailed:"failed to generate control block",invalidLeaf:"invalid leaf"},Lt=192;de.initEccLib(ct);class jt{constructor(t,r,n,o,s,c,u){this.secretHash=n,this.redeemerPubkey=o,this.initiatorPubkey=s,this.expiry=c,this.signer=t,this.network=u,this.internalPubkey=La(),this.initiateAmount=r}static async from(t,r,n,o,s,c){n=n.startsWith("0x")?n.slice(2):n,at(n.length===64,be.secretHashLenMismatch),at(o.length===64||o.length===66,`initiator ${be.pubkeyLenMismatch}`),at(s.length===64||s.length===66,`redeemer ${be.pubkeyLenMismatch}`),at(c>0,be.zeroOrNegativeExpiry);const u=await t.getNetwork();return new jt(t,r,n,Cr(s).toString("hex"),Cr(o).toString("hex"),c,u)}address(){const{address:t}=de.payments.p2tr({internalPubkey:this.internalPubkey,network:this.network,scriptTree:this.leaves()});if(!t)throw new Error(be.htlcAddressGenerationFailed);return t}id(){return this.address()}async _buildRawTx(t,r){const n=new de.Transaction;n.version=2;const o=this.address(),s=await this.signer.getProvider(),c=await s.getUTXOs(o),u=c.reduce((p,y)=>p+y.value,0);if(u===0)throw new Error(`${o} ${be.notFunded}`);for(let p=0;p<c.length;p++)n.addInput(Buffer.from(c[p].txid,"hex").reverse(),c[p].vout);return r??(r=await s.suggestFee(o,u,Jr.Urgency.MEDIUM)),n.addOutput(de.address.toOutputScript(t,this.network),u-r),{tx:n,usedUtxos:c}}async buildRawTx(t){return await this._buildRawTx(await this.signer.getAddress(),t)}getOutputScript(){return de.address.toOutputScript(this.address(),this.network)}async init(t){return t??(t=await(await this.signer.getProvider()).suggestFee(await this.signer.getAddress(),this.initiateAmount,Jr.Urgency.MEDIUM)),await this.signer.send(this.address(),this.initiateAmount,t)}async instantRefund(t,r){at(t.length>0,be.noCounterpartySigs);const{tx:n,usedUtxos:o}=await this.buildRawTx(r);for(const w of o)if(!t.find(x=>x.utxo===w.txid))throw new Error(be.counterPartySigNotFound(w.txid));const s=this.getOutputScript(),c=de.Transaction.SIGHASH_DEFAULT,u=this.leafHash(2),p=o.map(w=>w.value),y=fr(s,o.length);for(let w=0;w<n.ins.length;w++){const x=n.hashForWitnessV1(w,y,p,c,u);if(!ct.verifySchnorr(x,Buffer.from(this.redeemerPubkey,"hex"),Buffer.from(t[w].sig,"hex")))throw new Error(be.invalidCounterpartySigForUTXO(t[w].utxo));const k=await this.signer.signSchnorr(x),R=Buffer.from(n.ins[w].hash).reverse().toString("hex"),C=t.find(E=>E.utxo===R);if(!C)throw new Error(be.counterPartySigNotFound(R));n.setWitness(w,[Buffer.from(C.sig,"hex"),k,this.instantRefundLeaf(),this.generateControlBlockFor(2)])}return await(await this.signer.getProvider()).broadcast(n.toHex())}async redeem(t,r,n){at(de.crypto.sha256(Buffer.from(t,"hex")).toString("hex")===this.secretHash,be.secretMismatch);const{tx:o,usedUtxos:s}=await this._buildRawTx(r??await this.signer.getAddress(),n),c=this.leafHash(1),u=s.map(w=>w.value),p=fr(this.getOutputScript(),s.length),y=de.Transaction.SIGHASH_DEFAULT;for(let w=0;w<o.ins.length;w++){const x=o.hashForWitnessV1(w,p,u,y,c),k=await this.signer.signSchnorr(x);o.setWitness(w,[k,Buffer.from(t,"hex"),this.redeemLeaf(),this.generateControlBlockFor(1)])}return await(await this.signer.getProvider()).broadcast(o.toHex())}async refund(t,r){const{tx:n,usedUtxos:o}=await this._buildRawTx(t??await this.signer.getAddress(),r),[s,c]=await this.canRefund(o);if(!s)throw new Error(be.htlcNotExpired(c));const u=this.leafHash(0),p=o.map(x=>x.value),y=fr(this.getOutputScript(),o.length),g=de.Transaction.SIGHASH_DEFAULT;for(let x=0;x<n.ins.length;x++){n.ins[x].sequence=this.expiry;const k=n.hashForWitnessV1(x,y,p,g,u),R=await this.signer.signSchnorr(k);n.setWitness(x,[R,this.refundLeaf(),this.generateControlBlockFor(0)])}return await(await this.signer.getProvider()).broadcast(n.toHex())}async canRefund(t){const n=await(await this.signer.getProvider()).getLatestTip();for(const o of t){let s=0;if(o.status.confirmed&&o.status.block_height+this.expiry>n?s=o.status.block_height+this.expiry-n+1:o.status.confirmed||(s=this.expiry+1),s>0)return[!1,s]}return[!0,0]}generateControlBlockFor(t){let r;switch(t){case 1:r=this.redeemLeaf();break;case 0:r=this.refundLeaf();break;case 2:r=this.instantRefundLeaf();break;default:throw new Error(be.invalidLeaf)}const n=de.payments.p2tr({internalPubkey:this.internalPubkey,network:this.network,scriptTree:this.leaves(),redeem:{output:r,redeemVersion:Lt}});if(!n.witness)throw new Error(be.controlBlockGenerationFailed);return n.witness[n.witness.length-1]}leafHash(t){let r=this.redeemLeaf();return t===0&&(r=this.refundLeaf()),t===2&&(r=this.instantRefundLeaf()),de.crypto.taggedHash("TapLeaf",Ba(r))}refundLeaf(){return de.script.fromASM(`
3
3
  ${de.script.number.encode(this.expiry).toString("hex")}
4
4
  OP_CHECKSEQUENCEVERIFY
5
5
  OP_DROP
@@ -18,12 +18,12 @@
18
18
  OP_CHECKSIGADD
19
19
  OP_2
20
20
  OP_NUMEQUAL
21
- `.trim().replace(/\s+/g," "))}leaves(){return[{version:Lt,output:this.redeemLeaf()},[{version:Lt,output:this.refundLeaf()},{version:Lt,output:this.instantRefundLeaf()}]]}generateMerkleProofFor(t){const r=this.leafHash(1),n=this.leafHash(2),o=this.leafHash(0);switch(t){case 1:{const s=Ra(o,n);return[de.crypto.taggedHash("TapBranch",Buffer.concat(s))]}case 0:return[n,r];case 2:return[o,r];default:throw new Error(be.invalidLeaf)}}}function fr(e,t){const r=[];for(let n=0;n<t;n++)r.push(e);return r}class La{constructor(t,r){this.order=t,this.store=r}getOrder(){return this.order}set(t,r){const n={txHash:r,timeStamp:Date.now()};this.store.setItem(`${t}_${this.order.create_order.create_id}`,JSON.stringify(n))}get(t){const r=this.store.getItem(`${t}_${this.order.create_order.create_id}`);if(!r)return null;const n=JSON.parse(r);return!n.timeStamp||!n.txHash?null:n}remove(t){this.store.removeItem(`${t}_${this.order.create_order.create_id}`)}}class Ma{constructor(t){if(this.eventListeners=new Map,this.getOrderThreshold=20,this.pendingOrdersCount=0,this.useRelay=!0,this.orderBook=new te.Orderbook({url:t.orderbookURl,walletClient:t.wallets.evmWallet,auth:t.auth}),this.quote=t.quote,this.secretManager=t.secretManager,this.wallets=t.wallets,this.orderbookUrl=t.orderbookURl,this.auth=t.auth,this.store=new pa,!t.wallets.evmWallet.account)throw new Error("Account not found in evmWallet");this.evmAddress=t.wallets.evmWallet.account.address}getPendingOrderCount(){return this.pendingOrdersCount}setUseRelay(t){this.useRelay=t}async swap(t){const r=await this.validateAndFillParams(t);if(r.error)return P.Err(r.error);const{sendAddress:n,receiveAddress:o,timelock:s}=r.val,c=await this.orderBook.getOrdersCount(this.evmAddress);if(c.error)return P.Err(c.error);const u=c.val+1,p=this.secretManager.generateSecret(u);if(p.error)return P.Err(p.error);const{strategyId:y,btcAddress:g}=t.additionalData,w={strategy_id:y,...g&&{btcAddress:g}},x={source_chain:t.fromAsset.chain,destination_chain:t.toAsset.chain,source_asset:t.fromAsset.atomicSwapAddress,destination_asset:t.toAsset.atomicSwapAddress,initiator_source_address:n,initiator_destination_address:o,source_amount:t.sendAmount,destination_amount:t.receiveAmount,fee:"1",nonce:u.toString(),timelock:s,secret_hash:P.trim0x(p.val.secretHash),min_destination_confirmations:t.minDestinationConfirmations??0,additional_data:w},T=await this.quote.getAttestedQuote(x);if(T.error)return P.Err(T.error);const R=await this.orderBook.createOrder(T.val);if(R.error)return P.Err(R.error);const C=await this.pollOrder(R.val);return C.error?P.Err(C.error):P.Ok(C.val)}async validateAndFillParams(t){if(t.fromAsset.chain===t.toAsset.chain&&t.fromAsset.atomicSwapAddress===t.toAsset.atomicSwapAddress)return P.Err("Source and destination assets cannot be the same");if(te.isMainnet(t.fromAsset.chain)&&!te.isMainnet(t.toAsset.chain)||!te.isMainnet(t.fromAsset.chain)&&te.isMainnet(t.toAsset.chain))return P.Err("Both assets should be on the same network (either mainnet or testnet)");if(te.isBitcoin(t.fromAsset.chain)||te.isBitcoin(t.toAsset.chain)){if(!this.wallets.btcWallet)return P.Err("btcWallet is required for bitcoin chain. Please provide btcWallet in the constructor");if(!t.additionalData.btcAddress)return P.Err("btcAddress in additionalData is required for bitcoin chain")}const r=await this.getAddresses(t.fromAsset.chain);if(r.error)return P.Err(r.error);const n=await this.getAddresses(t.toAsset.chain);if(n.error)return P.Err(n.error);const o=this.validateAmount(t.sendAmount);if(o.error)return P.Err(o.error);const s=this.validateAmount(t.receiveAmount);if(s.error)return P.Err(s.error);if(o<s)return P.Err("Send amount should be greater than receive amount");const c=this.getTimelock(t.fromAsset.chain);return c?P.Ok({sendAddress:r.val,receiveAddress:n.val,timelock:t.timelock??c}):P.Err("Unsupported chain for timelock")}async getAddresses(t){var n;switch(te.getBlockchainType(t)){case te.BlockchainType.EVM:return this.wallets.evmWallet.account?P.Ok(this.wallets.evmWallet.account.address):P.Err("EVM Wallet not found");case te.BlockchainType.Bitcoin:{const o=await((n=this.wallets.btcWallet)==null?void 0:n.getPublicKey());return!o||!Sa(o)?P.Err("Invalid btc public key"):P.Ok(o)}default:return P.Err("Unsupported chain")}}validateAmount(t){const r=BigInt(t);return t==null||r<=0n||t.includes(".")?P.Err("Invalid amount ",t):P.Ok(r)}getTimelock(t){switch(te.getBlockchainType(t)){case te.BlockchainType.EVM:return Br.evm;case te.BlockchainType.Bitcoin:return Br.btc;default:return}}async pollOrder(t){let r=await this.orderBook.getOrder(t,!0),n=0;for(;n<this.getOrderThreshold;){if(await Hi(1e3),n++,r.error){if(!r.error.includes("result is undefined"))return P.Err(r.error)}else if(r.val&&r.val.create_order.create_id.toLowerCase()===t.toLowerCase())return P.Ok(r.val);r=await this.orderBook.getOrder(t,!0)}return P.Err(`Order not found, createOrder id: ${t}`)}emit(t,...r){(this.eventListeners.get(t)??[]).forEach(o=>{o(...r)})}async execute(t=5e3){return await this.orderBook.subscribeToOrders(!0,t,async r=>{var n,o;this.pendingOrdersCount=r.data.length,this.emit("onPendingOrdersChanged",r.data);for(let s=0;s<r.data.length;s++){const c=r.data[s],u=c.source_swap.chain,p=c.destination_swap.chain,y=this.getWallet(u),g=this.getWallet(p);if(y.error||g.error||!y.val||!g.val){this.emit("error",c,"Source or Destination Wallet not found while executing order");return}const w=await this.fetchCurrentBlockNumbers(c,{source:y.val,destination:g.val});if(w.error){this.emit("error",c,"Error while fetching CurrentBlockNumbers: "+w.error);return}const x=zn(c,w.val.source,w.val.destination),T=new La(c,this.store),R=T.get(x);if(console.log("prevResult :",R),R)continue;switch(te.getBlockchainType(c.destination_swap.chain)){case te.BlockchainType.EVM:switch(x){case Re.Redeem:{console.log("executing evm redeem...");const E=new Kn(c,this.orderbookUrl,this.auth),k=this.secretManager.generateSecret(Number(c.create_order.nonce));if(k.error){this.emit("error",c,k.error);return}const O=await E.redeem(c.create_order.create_id,k.val.secret);if(O.error){this.emit("error",c,O.error);return}this.emit("success",c,Re.Redeem,O.val),T.set(x,O.val);break}case Re.Refund:{this.emit("error",c,"EVM refund is automatically done by relay service");break}}break;case te.BlockchainType.Bitcoin:switch(x){case Re.Redeem:{try{const E=await jt.from(g.val,Number(c.destination_swap.amount),c.create_order.secret_hash,Ft(c.destination_swap.initiator),Ft(c.destination_swap.redeemer),c.destination_swap.timelock),k=this.secretManager.generateSecret(Number(c.create_order.nonce));if(k.error){this.emit("error",c,k.error);return}const O=await E.redeem(P.trim0x(k.val.secret),(n=c.create_order.additional_data)==null?void 0:n.bitcoin_optional_recipient);this.emit("success",c,Re.Redeem,O),T.set(x,O)}catch(E){this.emit("error",c,"Failed btc redeem: "+E)}break}case Re.Refund:{try{const k=await(await jt.from(y.val,Number(c.source_swap.amount),c.create_order.secret_hash,Ft(c.source_swap.initiator),Ft(c.source_swap.redeemer),c.source_swap.timelock)).refund((o=c.create_order.additional_data)==null?void 0:o.bitcoin_optional_recipient);this.emit("success",c,Re.Refund,k),T.set(x,k)}catch(E){this.emit("error",c,"Failed btc refund: "+E)}break}}break;default:this.emit("error",c,"Unsupported chain: "+c.destination_swap.chain)}return}},!0)}getWallet(t){switch(te.getBlockchainType(t)){case te.BlockchainType.EVM:return P.Ok(this.wallets.evmWallet);case te.BlockchainType.Bitcoin:return P.Ok(this.wallets.btcWallet);default:return P.Err("Unsupported chain for wallet")}}on(t,r){const n=this.eventListeners.get(t)??[];n.push(r),this.eventListeners.set(t,n)}off(t,r){const n=this.eventListeners.get(t)??[],o=n.indexOf(r);o!==-1&&n.splice(o,1)}async fetchCurrentBlockNumbers(t,r){if(!r||!r.source||!r.destination)return P.Err("Provide wallets to fetch the current block number");const n=te.isBitcoin(t.source_swap.chain)?await rn(await r.source.getProvider()):await Ar(r.source);if(n.error)return P.Err(n.error);const o=te.isBitcoin(t.destination_swap.chain)?await rn(await r.destination.getProvider()):await Ar(r.destination);return o.error?P.Err(o.error):P.Ok({source:n.val,destination:o.val})}}var ze=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Ua(e){if(e.__esModule)return e;var t=e.default;if(typeof t=="function"){var r=function n(){return this instanceof n?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach(function(n){var o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,o.get?o:{enumerable:!0,get:function(){return e[n]}})}),r}var Vn={},lt={},ht={};Object.defineProperty(ht,"__esModule",{value:!0});ht.testnet=ht.bitcoin=void 0;ht.bitcoin={messagePrefix:`Bitcoin Signed Message:
21
+ `.trim().replace(/\s+/g," "))}leaves(){return[{version:Lt,output:this.redeemLeaf()},[{version:Lt,output:this.refundLeaf()},{version:Lt,output:this.instantRefundLeaf()}]]}generateMerkleProofFor(t){const r=this.leafHash(1),n=this.leafHash(2),o=this.leafHash(0);switch(t){case 1:{const s=Sa(o,n);return[de.crypto.taggedHash("TapBranch",Buffer.concat(s))]}case 0:return[n,r];case 2:return[o,r];default:throw new Error(be.invalidLeaf)}}}function fr(e,t){const r=[];for(let n=0;n<t;n++)r.push(e);return r}class Ma{constructor(t,r){this.order=t,this.store=r}getOrder(){return this.order}set(t,r){const n={txHash:r,timeStamp:Date.now()};this.store.setItem(`${t}_${this.order.create_order.create_id}`,JSON.stringify(n))}get(t){const r=this.store.getItem(`${t}_${this.order.create_order.create_id}`);if(!r)return null;const n=JSON.parse(r);return!n.timeStamp||!n.txHash?null:n}remove(t){this.store.removeItem(`${t}_${this.order.create_order.create_id}`)}}class Ua{constructor(t){if(this.eventListeners=new Map,this.getOrderThreshold=20,this.pendingOrdersCount=0,this.useRelay=!0,this.orderBook=new te.Orderbook({url:t.orderbookURl,walletClient:t.wallets.evmWallet,auth:t.auth}),this.quote=t.quote,this.secretManager=t.secretManager,this.wallets=t.wallets,this.orderbookUrl=t.orderbookURl,this.auth=t.auth,this.store=new ya,!t.wallets.evmWallet.account)throw new Error("Account not found in evmWallet");this.evmAddress=t.wallets.evmWallet.account.address}getPendingOrderCount(){return this.pendingOrdersCount}setUseRelay(t){this.useRelay=t}async swap(t){const r=await this.validateAndFillParams(t);if(r.error)return P.Err(r.error);const{sendAddress:n,receiveAddress:o,timelock:s}=r.val,c=await this.orderBook.getOrdersCount(this.evmAddress);if(c.error)return P.Err(c.error);const u=c.val+1,p=this.secretManager.generateSecret(u);if(p.error)return P.Err(p.error);const{strategyId:y,btcAddress:g}=t.additionalData,w={strategy_id:y,...g&&{btcAddress:g}},x={source_chain:t.fromAsset.chain,destination_chain:t.toAsset.chain,source_asset:t.fromAsset.atomicSwapAddress,destination_asset:t.toAsset.atomicSwapAddress,initiator_source_address:n,initiator_destination_address:o,source_amount:t.sendAmount,destination_amount:t.receiveAmount,fee:"1",nonce:u.toString(),timelock:s,secret_hash:P.trim0x(p.val.secretHash),min_destination_confirmations:t.minDestinationConfirmations??0,additional_data:w},k=await this.quote.getAttestedQuote(x);if(k.error)return P.Err(k.error);const R=await this.orderBook.createOrder(k.val);if(R.error)return P.Err(R.error);const C=await this.pollOrder(R.val);return C.error?P.Err(C.error):P.Ok(C.val)}async validateAndFillParams(t){if(t.fromAsset.chain===t.toAsset.chain&&t.fromAsset.atomicSwapAddress===t.toAsset.atomicSwapAddress)return P.Err("Source and destination assets cannot be the same");if(te.isMainnet(t.fromAsset.chain)&&!te.isMainnet(t.toAsset.chain)||!te.isMainnet(t.fromAsset.chain)&&te.isMainnet(t.toAsset.chain))return P.Err("Both assets should be on the same network (either mainnet or testnet)");if(te.isBitcoin(t.fromAsset.chain)||te.isBitcoin(t.toAsset.chain)){if(!this.wallets.btcWallet)return P.Err("btcWallet is required for bitcoin chain. Please provide btcWallet in the constructor");if(!t.additionalData.btcAddress)return P.Err("btcAddress in additionalData is required for bitcoin chain")}const r=await this.getAddresses(t.fromAsset.chain);if(r.error)return P.Err(r.error);const n=await this.getAddresses(t.toAsset.chain);if(n.error)return P.Err(n.error);const o=this.validateAmount(t.sendAmount);if(o.error)return P.Err(o.error);const s=this.validateAmount(t.receiveAmount);if(s.error)return P.Err(s.error);if(o<s)return P.Err("Send amount should be greater than receive amount");const c=this.getTimelock(t.fromAsset.chain);return c?P.Ok({sendAddress:r.val,receiveAddress:n.val,timelock:t.timelock??c}):P.Err("Unsupported chain for timelock")}async getAddresses(t){var n;switch(te.getBlockchainType(t)){case te.BlockchainType.EVM:return this.wallets.evmWallet.account?P.Ok(this.wallets.evmWallet.account.address):P.Err("EVM Wallet not found");case te.BlockchainType.Bitcoin:{const o=await((n=this.wallets.btcWallet)==null?void 0:n.getPublicKey());return!o||!Ia(o)?P.Err("Invalid btc public key"):P.Ok(o)}default:return P.Err("Unsupported chain")}}validateAmount(t){const r=BigInt(t);return t==null||r<=0n||t.includes(".")?P.Err("Invalid amount ",t):P.Ok(r)}getTimelock(t){switch(te.getBlockchainType(t)){case te.BlockchainType.EVM:return Br.evm;case te.BlockchainType.Bitcoin:return Br.btc;default:return}}async pollOrder(t){let r=await this.orderBook.getOrder(t,!0),n=0;for(;n<this.getOrderThreshold;){if(await qi(1e3),n++,r.error){if(!r.error.includes("result is undefined"))return P.Err(r.error)}else if(r.val&&r.val.create_order.create_id.toLowerCase()===t.toLowerCase())return P.Ok(r.val);r=await this.orderBook.getOrder(t,!0)}return P.Err(`Order not found, createOrder id: ${t}`)}emit(t,...r){(this.eventListeners.get(t)??[]).forEach(o=>{o(...r)})}async execute(t=5e3){return await this.orderBook.subscribeToOrders(!0,t,async r=>{var n,o;this.pendingOrdersCount=r.data.length,this.emit("onPendingOrdersChanged",r.data);for(let s=0;s<r.data.length;s++){const c=r.data[s],u=c.source_swap.chain,p=c.destination_swap.chain,y=this.getWallet(u),g=this.getWallet(p);if(y.error||g.error||!y.val||!g.val){this.emit("error",c,"Source or Destination Wallet not found while executing order");return}const w=await this.fetchCurrentBlockNumbers(c,{source:y.val,destination:g.val});if(w.error){this.emit("error",c,"Error while fetching CurrentBlockNumbers: "+w.error);return}const x=Vn(c,w.val.source,w.val.destination),k=new Ma(c,this.store);if(k.get(x))continue;switch(te.getBlockchainType(c.destination_swap.chain)){case te.BlockchainType.EVM:switch(x){case Re.Redeem:{console.log("executing evm redeem...");const E=new Jn(c,this.orderbookUrl,this.auth),T=this.secretManager.generateSecret(Number(c.create_order.nonce));if(T.error){this.emit("error",c,T.error);return}const O=await E.redeem(c.create_order.create_id,T.val.secret);if(O.error){this.emit("error",c,O.error);return}this.emit("success",c,Re.Redeem,O.val),k.set(x,O.val);break}case Re.Refund:{this.emit("error",c,"EVM refund is automatically done by relay service");break}}break;case te.BlockchainType.Bitcoin:switch(x){case Re.Redeem:{try{const E=await jt.from(g.val,Number(c.destination_swap.amount),c.create_order.secret_hash,Ft(c.destination_swap.initiator),Ft(c.destination_swap.redeemer),c.destination_swap.timelock),T=this.secretManager.generateSecret(Number(c.create_order.nonce));if(T.error){this.emit("error",c,T.error);return}const O=await E.redeem(P.trim0x(T.val.secret),(n=c.create_order.additional_data)==null?void 0:n.bitcoin_optional_recipient);this.emit("success",c,Re.Redeem,O),k.set(x,O)}catch(E){this.emit("error",c,"Failed btc redeem: "+E)}break}case Re.Refund:{try{const T=await(await jt.from(y.val,Number(c.source_swap.amount),c.create_order.secret_hash,Ft(c.source_swap.initiator),Ft(c.source_swap.redeemer),c.source_swap.timelock)).refund((o=c.create_order.additional_data)==null?void 0:o.bitcoin_optional_recipient);this.emit("success",c,Re.Refund,T),k.set(x,T)}catch(E){this.emit("error",c,"Failed btc refund: "+E)}break}}break;default:this.emit("error",c,"Unsupported chain: "+c.destination_swap.chain)}return}},!0)}getWallet(t){switch(te.getBlockchainType(t)){case te.BlockchainType.EVM:return P.Ok(this.wallets.evmWallet);case te.BlockchainType.Bitcoin:return P.Ok(this.wallets.btcWallet);default:return P.Err("Unsupported chain for wallet")}}on(t,r){const n=this.eventListeners.get(t)??[];n.push(r),this.eventListeners.set(t,n)}off(t,r){const n=this.eventListeners.get(t)??[],o=n.indexOf(r);o!==-1&&n.splice(o,1)}async fetchCurrentBlockNumbers(t,r){if(!r||!r.source||!r.destination)return P.Err("Provide wallets to fetch the current block number");const n=te.isBitcoin(t.source_swap.chain)?await nn(await r.source.getProvider()):await Ar(r.source);if(n.error)return P.Err(n.error);const o=te.isBitcoin(t.destination_swap.chain)?await nn(await r.destination.getProvider()):await Ar(r.destination);return o.error?P.Err(o.error):P.Ok({source:n.val,destination:o.val})}}var ze=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Da(e){if(e.__esModule)return e;var t=e.default;if(typeof t=="function"){var r=function n(){return this instanceof n?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach(function(n){var o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,o.get?o:{enumerable:!0,get:function(){return e[n]}})}),r}var Yn={},lt={},ht={};Object.defineProperty(ht,"__esModule",{value:!0});ht.testnet=ht.bitcoin=void 0;ht.bitcoin={messagePrefix:`Bitcoin Signed Message:
22
22
  `,bech32:"bc",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128};ht.testnet={messagePrefix:`Bitcoin Signed Message:
23
- `,bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};var Jn={},St={Array:function(e){return e!=null&&e.constructor===Array},Boolean:function(e){return typeof e=="boolean"},Function:function(e){return typeof e=="function"},Nil:function(e){return e==null},Number:function(e){return typeof e=="number"},Object:function(e){return typeof e=="object"},String:function(e){return typeof e=="string"},"":function(){return!0}};St.Null=St.Nil;for(var an in St)St[an].toJSON=(function(e){return e}).bind(null,an);var Hr=St,Qe=Hr;function Yn(e){return e.name||e.toString().match(/function (.*?)\s*\(/)[1]}function jr(e){return Qe.Nil(e)?"":Yn(e.constructor)}function Da(e){return Qe.Function(e)?"":Qe.String(e)?JSON.stringify(e):e&&Qe.Object(e)?"":e}function qr(e,t){Error.captureStackTrace&&Error.captureStackTrace(e,t)}function qt(e){return Qe.Function(e)?e.toJSON?e.toJSON():Yn(e):Qe.Array(e)?"Array":e&&Qe.Object(e)?"Object":e!==void 0?e:""}function Qn(e,t,r){var n=Da(t);return"Expected "+qt(e)+", got"+(r!==""?" "+r:"")+(n!==""?" "+n:"")}function Me(e,t,r){r=r||jr(t),this.message=Qn(e,t,r),qr(this,Me),this.__type=e,this.__value=t,this.__valueTypeName=r}Me.prototype=Object.create(Error.prototype);Me.prototype.constructor=Me;function $a(e,t,r,n,o){var s='" of type ';return t==="key"&&(s='" with key type '),Qn('property "'+qt(r)+s+qt(e),n,o)}function ft(e,t,r,n,o){e?(o=o||jr(n),this.message=$a(e,r,t,n,o)):this.message='Unexpected property "'+t+'"',qr(this,Me),this.__label=r,this.__property=t,this.__type=e,this.__value=n,this.__valueTypeName=o}ft.prototype=Object.create(Error.prototype);ft.prototype.constructor=Me;function Ha(e,t){return new Me(e,{},t)}function ja(e,t,r){return e instanceof ft?(t=t+"."+e.__property,e=new ft(e.__type,t,e.__label,e.__value,e.__valueTypeName)):e instanceof Me&&(e=new ft(e.__type,t,r,e.__value,e.__valueTypeName)),qr(e),e}var Xn={TfTypeError:Me,TfPropertyTypeError:ft,tfCustomError:Ha,tfSubError:ja,tfJSON:qt,getValueTypeName:jr},ur,on;function qa(){if(on)return ur;on=1;var e=Hr,t=Xn;function r(S){return Buffer.isBuffer(S)}function n(S){return typeof S=="string"&&/^([0-9a-f]{2})+$/i.test(S)}function o(S,j){var D=S.toJSON();function U(ee){if(!S(ee))return!1;if(ee.length===j)return!0;throw t.tfCustomError(D+"(Length: "+j+")",D+"(Length: "+ee.length+")")}return U.toJSON=function(){return D},U}var s=o.bind(null,e.Array),c=o.bind(null,r),u=o.bind(null,n),p=o.bind(null,e.String);function y(S,j,D){D=D||e.Number;function U(ee,Ie){return D(ee,Ie)&&ee>S&&ee<j}return U.toJSON=function(){return`${D.toJSON()} between [${S}, ${j}]`},U}var g=Math.pow(2,53)-1;function w(S){return typeof S=="number"&&isFinite(S)}function x(S){return S<<24>>24===S}function T(S){return S<<16>>16===S}function R(S){return(S|0)===S}function C(S){return typeof S=="number"&&S>=-g&&S<=g&&Math.floor(S)===S}function E(S){return(S&255)===S}function k(S){return(S&65535)===S}function O(S){return S>>>0===S}function F(S){return typeof S=="number"&&S>=0&&S<=g&&Math.floor(S)===S}var N={ArrayN:s,Buffer:r,BufferN:c,Finite:w,Hex:n,HexN:u,Int8:x,Int16:T,Int32:R,Int53:C,Range:y,StringN:p,UInt8:E,UInt16:k,UInt32:O,UInt53:F};for(var L in N)N[L].toJSON=(function(S){return S}).bind(null,L);return ur=N,ur}var Tt=Xn,fe=Hr,Fe=Tt.tfJSON,Zn=Tt.TfTypeError,ei=Tt.TfPropertyTypeError,_t=Tt.tfSubError,Wa=Tt.getValueTypeName,Le={arrayOf:function(t,r){t=Ce(t),r=r||{};function n(o,s){return!fe.Array(o)||fe.Nil(o)||r.minLength!==void 0&&o.length<r.minLength||r.maxLength!==void 0&&o.length>r.maxLength||r.length!==void 0&&o.length!==r.length?!1:o.every(function(c,u){try{return ge(t,c,s)}catch(p){throw _t(p,u)}})}return n.toJSON=function(){var o="["+Fe(t)+"]";return r.length!==void 0?o+="{"+r.length+"}":(r.minLength!==void 0||r.maxLength!==void 0)&&(o+="{"+(r.minLength===void 0?0:r.minLength)+","+(r.maxLength===void 0?1/0:r.maxLength)+"}"),o},n},maybe:function e(t){t=Ce(t);function r(n,o){return fe.Nil(n)||t(n,o,e)}return r.toJSON=function(){return"?"+Fe(t)},r},map:function(t,r){t=Ce(t),r&&(r=Ce(r));function n(o,s){if(!fe.Object(o)||fe.Nil(o))return!1;for(var c in o){try{r&&ge(r,c,s)}catch(p){throw _t(p,c,"key")}try{var u=o[c];ge(t,u,s)}catch(p){throw _t(p,c)}}return!0}return r?n.toJSON=function(){return"{"+Fe(r)+": "+Fe(t)+"}"}:n.toJSON=function(){return"{"+Fe(t)+"}"},n},object:function(t){var r={};for(var n in t)r[n]=Ce(t[n]);function o(s,c){if(!fe.Object(s)||fe.Nil(s))return!1;var u;try{for(u in r){var p=r[u],y=s[u];ge(p,y,c)}}catch(g){throw _t(g,u)}if(c){for(u in s)if(!r[u])throw new ei(void 0,u)}return!0}return o.toJSON=function(){return Fe(r)},o},anyOf:function(){var t=[].slice.call(arguments).map(Ce);function r(n,o){return t.some(function(s){try{return ge(s,n,o)}catch{return!1}})}return r.toJSON=function(){return t.map(Fe).join("|")},r},allOf:function(){var t=[].slice.call(arguments).map(Ce);function r(n,o){return t.every(function(s){try{return ge(s,n,o)}catch{return!1}})}return r.toJSON=function(){return t.map(Fe).join(" & ")},r},quacksLike:function(t){function r(n){return t===Wa(n)}return r.toJSON=function(){return t},r},tuple:function(){var t=[].slice.call(arguments).map(Ce);function r(n,o){return fe.Nil(n)||fe.Nil(n.length)||o&&n.length!==t.length?!1:t.every(function(s,c){try{return ge(s,n[c],o)}catch(u){throw _t(u,c)}})}return r.toJSON=function(){return"("+t.map(Fe).join(", ")+")"},r},value:function(t){function r(n){return n===t}return r.toJSON=function(){return t},r}};Le.oneOf=Le.anyOf;function Ce(e){if(fe.String(e))return e[0]==="?"?Le.maybe(e.slice(1)):fe[e]||Le.quacksLike(e);if(e&&fe.Object(e)){if(fe.Array(e)){if(e.length!==1)throw new TypeError("Expected compile() parameter of type Array of length 1");return Le.arrayOf(e[0])}return Le.object(e)}else if(fe.Function(e))return e;return Le.value(e)}function ge(e,t,r,n){if(fe.Function(e)){if(e(t,r))return!0;throw new Zn(n||e,t)}return ge(Ce(e),t,r)}for(var Ge in fe)ge[Ge]=fe[Ge];for(Ge in Le)ge[Ge]=Le[Ge];var sn=qa();for(Ge in sn)ge[Ge]=sn[Ge];ge.compile=Ce;ge.TfTypeError=Zn;ge.TfPropertyTypeError=ei;var Ga=ge;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.maybe=e.Boolean=e.Array=e.Buffer256bit=e.Network=e.typeforce=void 0,e.typeforce=Ga,e.Network=e.typeforce.compile({messagePrefix:e.typeforce.oneOf(e.typeforce.Buffer,e.typeforce.String),bip32:{public:e.typeforce.UInt32,private:e.typeforce.UInt32},pubKeyHash:e.typeforce.UInt8,scriptHash:e.typeforce.UInt8,wif:e.typeforce.UInt8}),e.Buffer256bit=e.typeforce.BufferN(32),e.Array=e.typeforce.Array,e.Boolean=e.typeforce.Boolean,e.maybe=e.typeforce.maybe})(Jn);var Pr={exports:{}},Or={exports:{}},pt={},Jt={};Jt.byteLength=Va;Jt.toByteArray=Ya;Jt.fromByteArray=Za;var Pe=[],Be=[],za=typeof Uint8Array<"u"?Uint8Array:Array,cr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var ot=0,Ka=cr.length;ot<Ka;++ot)Pe[ot]=cr[ot],Be[cr.charCodeAt(ot)]=ot;Be[45]=62;Be[95]=63;function ti(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");r===-1&&(r=t);var n=r===t?0:4-r%4;return[r,n]}function Va(e){var t=ti(e),r=t[0],n=t[1];return(r+n)*3/4-n}function Ja(e,t,r){return(t+r)*3/4-r}function Ya(e){var t,r=ti(e),n=r[0],o=r[1],s=new za(Ja(e,n,o)),c=0,u=o>0?n-4:n,p;for(p=0;p<u;p+=4)t=Be[e.charCodeAt(p)]<<18|Be[e.charCodeAt(p+1)]<<12|Be[e.charCodeAt(p+2)]<<6|Be[e.charCodeAt(p+3)],s[c++]=t>>16&255,s[c++]=t>>8&255,s[c++]=t&255;return o===2&&(t=Be[e.charCodeAt(p)]<<2|Be[e.charCodeAt(p+1)]>>4,s[c++]=t&255),o===1&&(t=Be[e.charCodeAt(p)]<<10|Be[e.charCodeAt(p+1)]<<4|Be[e.charCodeAt(p+2)]>>2,s[c++]=t>>8&255,s[c++]=t&255),s}function Qa(e){return Pe[e>>18&63]+Pe[e>>12&63]+Pe[e>>6&63]+Pe[e&63]}function Xa(e,t,r){for(var n,o=[],s=t;s<r;s+=3)n=(e[s]<<16&16711680)+(e[s+1]<<8&65280)+(e[s+2]&255),o.push(Qa(n));return o.join("")}function Za(e){for(var t,r=e.length,n=r%3,o=[],s=16383,c=0,u=r-n;c<u;c+=s)o.push(Xa(e,c,c+s>u?u:c+s));return n===1?(t=e[r-1],o.push(Pe[t>>2]+Pe[t<<4&63]+"==")):n===2&&(t=(e[r-2]<<8)+e[r-1],o.push(Pe[t>>10]+Pe[t>>4&63]+Pe[t<<2&63]+"=")),o.join("")}var Wr={};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */Wr.read=function(e,t,r,n,o){var s,c,u=o*8-n-1,p=(1<<u)-1,y=p>>1,g=-7,w=r?o-1:0,x=r?-1:1,T=e[t+w];for(w+=x,s=T&(1<<-g)-1,T>>=-g,g+=u;g>0;s=s*256+e[t+w],w+=x,g-=8);for(c=s&(1<<-g)-1,s>>=-g,g+=n;g>0;c=c*256+e[t+w],w+=x,g-=8);if(s===0)s=1-y;else{if(s===p)return c?NaN:(T?-1:1)*(1/0);c=c+Math.pow(2,n),s=s-y}return(T?-1:1)*c*Math.pow(2,s-n)};Wr.write=function(e,t,r,n,o,s){var c,u,p,y=s*8-o-1,g=(1<<y)-1,w=g>>1,x=o===23?Math.pow(2,-24)-Math.pow(2,-77):0,T=n?0:s-1,R=n?1:-1,C=t<0||t===0&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(u=isNaN(t)?1:0,c=g):(c=Math.floor(Math.log(t)/Math.LN2),t*(p=Math.pow(2,-c))<1&&(c--,p*=2),c+w>=1?t+=x/p:t+=x*Math.pow(2,1-w),t*p>=2&&(c++,p/=2),c+w>=g?(u=0,c=g):c+w>=1?(u=(t*p-1)*Math.pow(2,o),c=c+w):(u=t*Math.pow(2,w-1)*Math.pow(2,o),c=0));o>=8;e[r+T]=u&255,T+=R,u/=256,o-=8);for(c=c<<o|u,y+=o;y>0;e[r+T]=c&255,T+=R,c/=256,y-=8);e[r+T-R]|=C*128};/*!
23
+ `,bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};var Qn={},St={Array:function(e){return e!=null&&e.constructor===Array},Boolean:function(e){return typeof e=="boolean"},Function:function(e){return typeof e=="function"},Nil:function(e){return e==null},Number:function(e){return typeof e=="number"},Object:function(e){return typeof e=="object"},String:function(e){return typeof e=="string"},"":function(){return!0}};St.Null=St.Nil;for(var on in St)St[on].toJSON=(function(e){return e}).bind(null,on);var Hr=St,Qe=Hr;function Xn(e){return e.name||e.toString().match(/function (.*?)\s*\(/)[1]}function jr(e){return Qe.Nil(e)?"":Xn(e.constructor)}function $a(e){return Qe.Function(e)?"":Qe.String(e)?JSON.stringify(e):e&&Qe.Object(e)?"":e}function qr(e,t){Error.captureStackTrace&&Error.captureStackTrace(e,t)}function qt(e){return Qe.Function(e)?e.toJSON?e.toJSON():Xn(e):Qe.Array(e)?"Array":e&&Qe.Object(e)?"Object":e!==void 0?e:""}function Zn(e,t,r){var n=$a(t);return"Expected "+qt(e)+", got"+(r!==""?" "+r:"")+(n!==""?" "+n:"")}function Me(e,t,r){r=r||jr(t),this.message=Zn(e,t,r),qr(this,Me),this.__type=e,this.__value=t,this.__valueTypeName=r}Me.prototype=Object.create(Error.prototype);Me.prototype.constructor=Me;function Ha(e,t,r,n,o){var s='" of type ';return t==="key"&&(s='" with key type '),Zn('property "'+qt(r)+s+qt(e),n,o)}function ft(e,t,r,n,o){e?(o=o||jr(n),this.message=Ha(e,r,t,n,o)):this.message='Unexpected property "'+t+'"',qr(this,Me),this.__label=r,this.__property=t,this.__type=e,this.__value=n,this.__valueTypeName=o}ft.prototype=Object.create(Error.prototype);ft.prototype.constructor=Me;function ja(e,t){return new Me(e,{},t)}function qa(e,t,r){return e instanceof ft?(t=t+"."+e.__property,e=new ft(e.__type,t,e.__label,e.__value,e.__valueTypeName)):e instanceof Me&&(e=new ft(e.__type,t,r,e.__value,e.__valueTypeName)),qr(e),e}var ei={TfTypeError:Me,TfPropertyTypeError:ft,tfCustomError:ja,tfSubError:qa,tfJSON:qt,getValueTypeName:jr},ur,sn;function Wa(){if(sn)return ur;sn=1;var e=Hr,t=ei;function r(S){return Buffer.isBuffer(S)}function n(S){return typeof S=="string"&&/^([0-9a-f]{2})+$/i.test(S)}function o(S,j){var D=S.toJSON();function U(ee){if(!S(ee))return!1;if(ee.length===j)return!0;throw t.tfCustomError(D+"(Length: "+j+")",D+"(Length: "+ee.length+")")}return U.toJSON=function(){return D},U}var s=o.bind(null,e.Array),c=o.bind(null,r),u=o.bind(null,n),p=o.bind(null,e.String);function y(S,j,D){D=D||e.Number;function U(ee,Ie){return D(ee,Ie)&&ee>S&&ee<j}return U.toJSON=function(){return`${D.toJSON()} between [${S}, ${j}]`},U}var g=Math.pow(2,53)-1;function w(S){return typeof S=="number"&&isFinite(S)}function x(S){return S<<24>>24===S}function k(S){return S<<16>>16===S}function R(S){return(S|0)===S}function C(S){return typeof S=="number"&&S>=-g&&S<=g&&Math.floor(S)===S}function E(S){return(S&255)===S}function T(S){return(S&65535)===S}function O(S){return S>>>0===S}function F(S){return typeof S=="number"&&S>=0&&S<=g&&Math.floor(S)===S}var N={ArrayN:s,Buffer:r,BufferN:c,Finite:w,Hex:n,HexN:u,Int8:x,Int16:k,Int32:R,Int53:C,Range:y,StringN:p,UInt8:E,UInt16:T,UInt32:O,UInt53:F};for(var L in N)N[L].toJSON=(function(S){return S}).bind(null,L);return ur=N,ur}var kt=ei,fe=Hr,Fe=kt.tfJSON,ti=kt.TfTypeError,ri=kt.TfPropertyTypeError,_t=kt.tfSubError,Ga=kt.getValueTypeName,Le={arrayOf:function(t,r){t=Ce(t),r=r||{};function n(o,s){return!fe.Array(o)||fe.Nil(o)||r.minLength!==void 0&&o.length<r.minLength||r.maxLength!==void 0&&o.length>r.maxLength||r.length!==void 0&&o.length!==r.length?!1:o.every(function(c,u){try{return ge(t,c,s)}catch(p){throw _t(p,u)}})}return n.toJSON=function(){var o="["+Fe(t)+"]";return r.length!==void 0?o+="{"+r.length+"}":(r.minLength!==void 0||r.maxLength!==void 0)&&(o+="{"+(r.minLength===void 0?0:r.minLength)+","+(r.maxLength===void 0?1/0:r.maxLength)+"}"),o},n},maybe:function e(t){t=Ce(t);function r(n,o){return fe.Nil(n)||t(n,o,e)}return r.toJSON=function(){return"?"+Fe(t)},r},map:function(t,r){t=Ce(t),r&&(r=Ce(r));function n(o,s){if(!fe.Object(o)||fe.Nil(o))return!1;for(var c in o){try{r&&ge(r,c,s)}catch(p){throw _t(p,c,"key")}try{var u=o[c];ge(t,u,s)}catch(p){throw _t(p,c)}}return!0}return r?n.toJSON=function(){return"{"+Fe(r)+": "+Fe(t)+"}"}:n.toJSON=function(){return"{"+Fe(t)+"}"},n},object:function(t){var r={};for(var n in t)r[n]=Ce(t[n]);function o(s,c){if(!fe.Object(s)||fe.Nil(s))return!1;var u;try{for(u in r){var p=r[u],y=s[u];ge(p,y,c)}}catch(g){throw _t(g,u)}if(c){for(u in s)if(!r[u])throw new ri(void 0,u)}return!0}return o.toJSON=function(){return Fe(r)},o},anyOf:function(){var t=[].slice.call(arguments).map(Ce);function r(n,o){return t.some(function(s){try{return ge(s,n,o)}catch{return!1}})}return r.toJSON=function(){return t.map(Fe).join("|")},r},allOf:function(){var t=[].slice.call(arguments).map(Ce);function r(n,o){return t.every(function(s){try{return ge(s,n,o)}catch{return!1}})}return r.toJSON=function(){return t.map(Fe).join(" & ")},r},quacksLike:function(t){function r(n){return t===Ga(n)}return r.toJSON=function(){return t},r},tuple:function(){var t=[].slice.call(arguments).map(Ce);function r(n,o){return fe.Nil(n)||fe.Nil(n.length)||o&&n.length!==t.length?!1:t.every(function(s,c){try{return ge(s,n[c],o)}catch(u){throw _t(u,c)}})}return r.toJSON=function(){return"("+t.map(Fe).join(", ")+")"},r},value:function(t){function r(n){return n===t}return r.toJSON=function(){return t},r}};Le.oneOf=Le.anyOf;function Ce(e){if(fe.String(e))return e[0]==="?"?Le.maybe(e.slice(1)):fe[e]||Le.quacksLike(e);if(e&&fe.Object(e)){if(fe.Array(e)){if(e.length!==1)throw new TypeError("Expected compile() parameter of type Array of length 1");return Le.arrayOf(e[0])}return Le.object(e)}else if(fe.Function(e))return e;return Le.value(e)}function ge(e,t,r,n){if(fe.Function(e)){if(e(t,r))return!0;throw new ti(n||e,t)}return ge(Ce(e),t,r)}for(var Ge in fe)ge[Ge]=fe[Ge];for(Ge in Le)ge[Ge]=Le[Ge];var fn=Wa();for(Ge in fn)ge[Ge]=fn[Ge];ge.compile=Ce;ge.TfTypeError=ti;ge.TfPropertyTypeError=ri;var za=ge;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.maybe=e.Boolean=e.Array=e.Buffer256bit=e.Network=e.typeforce=void 0,e.typeforce=za,e.Network=e.typeforce.compile({messagePrefix:e.typeforce.oneOf(e.typeforce.Buffer,e.typeforce.String),bip32:{public:e.typeforce.UInt32,private:e.typeforce.UInt32},pubKeyHash:e.typeforce.UInt8,scriptHash:e.typeforce.UInt8,wif:e.typeforce.UInt8}),e.Buffer256bit=e.typeforce.BufferN(32),e.Array=e.typeforce.Array,e.Boolean=e.typeforce.Boolean,e.maybe=e.typeforce.maybe})(Qn);var Pr={exports:{}},Or={exports:{}},pt={},Jt={};Jt.byteLength=Ja;Jt.toByteArray=Qa;Jt.fromByteArray=eo;var Pe=[],Be=[],Ka=typeof Uint8Array<"u"?Uint8Array:Array,cr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var ot=0,Va=cr.length;ot<Va;++ot)Pe[ot]=cr[ot],Be[cr.charCodeAt(ot)]=ot;Be[45]=62;Be[95]=63;function ni(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");r===-1&&(r=t);var n=r===t?0:4-r%4;return[r,n]}function Ja(e){var t=ni(e),r=t[0],n=t[1];return(r+n)*3/4-n}function Ya(e,t,r){return(t+r)*3/4-r}function Qa(e){var t,r=ni(e),n=r[0],o=r[1],s=new Ka(Ya(e,n,o)),c=0,u=o>0?n-4:n,p;for(p=0;p<u;p+=4)t=Be[e.charCodeAt(p)]<<18|Be[e.charCodeAt(p+1)]<<12|Be[e.charCodeAt(p+2)]<<6|Be[e.charCodeAt(p+3)],s[c++]=t>>16&255,s[c++]=t>>8&255,s[c++]=t&255;return o===2&&(t=Be[e.charCodeAt(p)]<<2|Be[e.charCodeAt(p+1)]>>4,s[c++]=t&255),o===1&&(t=Be[e.charCodeAt(p)]<<10|Be[e.charCodeAt(p+1)]<<4|Be[e.charCodeAt(p+2)]>>2,s[c++]=t>>8&255,s[c++]=t&255),s}function Xa(e){return Pe[e>>18&63]+Pe[e>>12&63]+Pe[e>>6&63]+Pe[e&63]}function Za(e,t,r){for(var n,o=[],s=t;s<r;s+=3)n=(e[s]<<16&16711680)+(e[s+1]<<8&65280)+(e[s+2]&255),o.push(Xa(n));return o.join("")}function eo(e){for(var t,r=e.length,n=r%3,o=[],s=16383,c=0,u=r-n;c<u;c+=s)o.push(Za(e,c,c+s>u?u:c+s));return n===1?(t=e[r-1],o.push(Pe[t>>2]+Pe[t<<4&63]+"==")):n===2&&(t=(e[r-2]<<8)+e[r-1],o.push(Pe[t>>10]+Pe[t>>4&63]+Pe[t<<2&63]+"=")),o.join("")}var Wr={};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */Wr.read=function(e,t,r,n,o){var s,c,u=o*8-n-1,p=(1<<u)-1,y=p>>1,g=-7,w=r?o-1:0,x=r?-1:1,k=e[t+w];for(w+=x,s=k&(1<<-g)-1,k>>=-g,g+=u;g>0;s=s*256+e[t+w],w+=x,g-=8);for(c=s&(1<<-g)-1,s>>=-g,g+=n;g>0;c=c*256+e[t+w],w+=x,g-=8);if(s===0)s=1-y;else{if(s===p)return c?NaN:(k?-1:1)*(1/0);c=c+Math.pow(2,n),s=s-y}return(k?-1:1)*c*Math.pow(2,s-n)};Wr.write=function(e,t,r,n,o,s){var c,u,p,y=s*8-o-1,g=(1<<y)-1,w=g>>1,x=o===23?Math.pow(2,-24)-Math.pow(2,-77):0,k=n?0:s-1,R=n?1:-1,C=t<0||t===0&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(u=isNaN(t)?1:0,c=g):(c=Math.floor(Math.log(t)/Math.LN2),t*(p=Math.pow(2,-c))<1&&(c--,p*=2),c+w>=1?t+=x/p:t+=x*Math.pow(2,1-w),t*p>=2&&(c++,p/=2),c+w>=g?(u=0,c=g):c+w>=1?(u=(t*p-1)*Math.pow(2,o),c=c+w):(u=t*Math.pow(2,w-1)*Math.pow(2,o),c=0));o>=8;e[r+k]=u&255,k+=R,u/=256,o-=8);for(c=c<<o|u,y+=o;y>0;e[r+k]=c&255,k+=R,c/=256,y-=8);e[r+k-R]|=C*128};/*!
24
24
  * The buffer module from node.js, for the browser.
25
25
  *
26
26
  * @author Feross Aboukhadijeh <https://feross.org>
27
27
  * @license MIT
28
- */(function(e){const t=Jt,r=Wr,n=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;e.Buffer=u,e.SlowBuffer=O,e.INSPECT_MAX_BYTES=50;const o=2147483647;e.kMaxLength=o,u.TYPED_ARRAY_SUPPORT=s(),!u.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function s(){try{const f=new Uint8Array(1),i={foo:function(){return 42}};return Object.setPrototypeOf(i,Uint8Array.prototype),Object.setPrototypeOf(f,i),f.foo()===42}catch{return!1}}Object.defineProperty(u.prototype,"parent",{enumerable:!0,get:function(){if(u.isBuffer(this))return this.buffer}}),Object.defineProperty(u.prototype,"offset",{enumerable:!0,get:function(){if(u.isBuffer(this))return this.byteOffset}});function c(f){if(f>o)throw new RangeError('The value "'+f+'" is invalid for option "size"');const i=new Uint8Array(f);return Object.setPrototypeOf(i,u.prototype),i}function u(f,i,a){if(typeof f=="number"){if(typeof i=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return w(f)}return p(f,i,a)}u.poolSize=8192;function p(f,i,a){if(typeof f=="string")return x(f,i);if(ArrayBuffer.isView(f))return R(f);if(f==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof f);if(xe(f,ArrayBuffer)||f&&xe(f.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(xe(f,SharedArrayBuffer)||f&&xe(f.buffer,SharedArrayBuffer)))return C(f,i,a);if(typeof f=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const l=f.valueOf&&f.valueOf();if(l!=null&&l!==f)return u.from(l,i,a);const b=E(f);if(b)return b;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof f[Symbol.toPrimitive]=="function")return u.from(f[Symbol.toPrimitive]("string"),i,a);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof f)}u.from=function(f,i,a){return p(f,i,a)},Object.setPrototypeOf(u.prototype,Uint8Array.prototype),Object.setPrototypeOf(u,Uint8Array);function y(f){if(typeof f!="number")throw new TypeError('"size" argument must be of type number');if(f<0)throw new RangeError('The value "'+f+'" is invalid for option "size"')}function g(f,i,a){return y(f),f<=0?c(f):i!==void 0?typeof a=="string"?c(f).fill(i,a):c(f).fill(i):c(f)}u.alloc=function(f,i,a){return g(f,i,a)};function w(f){return y(f),c(f<0?0:k(f)|0)}u.allocUnsafe=function(f){return w(f)},u.allocUnsafeSlow=function(f){return w(f)};function x(f,i){if((typeof i!="string"||i==="")&&(i="utf8"),!u.isEncoding(i))throw new TypeError("Unknown encoding: "+i);const a=F(f,i)|0;let l=c(a);const b=l.write(f,i);return b!==a&&(l=l.slice(0,b)),l}function T(f){const i=f.length<0?0:k(f.length)|0,a=c(i);for(let l=0;l<i;l+=1)a[l]=f[l]&255;return a}function R(f){if(xe(f,Uint8Array)){const i=new Uint8Array(f);return C(i.buffer,i.byteOffset,i.byteLength)}return T(f)}function C(f,i,a){if(i<0||f.byteLength<i)throw new RangeError('"offset" is outside of buffer bounds');if(f.byteLength<i+(a||0))throw new RangeError('"length" is outside of buffer bounds');let l;return i===void 0&&a===void 0?l=new Uint8Array(f):a===void 0?l=new Uint8Array(f,i):l=new Uint8Array(f,i,a),Object.setPrototypeOf(l,u.prototype),l}function E(f){if(u.isBuffer(f)){const i=k(f.length)|0,a=c(i);return a.length===0||f.copy(a,0,0,i),a}if(f.length!==void 0)return typeof f.length!="number"||Je(f.length)?c(0):T(f);if(f.type==="Buffer"&&Array.isArray(f.data))return T(f.data)}function k(f){if(f>=o)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+o.toString(16)+" bytes");return f|0}function O(f){return+f!=f&&(f=0),u.alloc(+f)}u.isBuffer=function(i){return i!=null&&i._isBuffer===!0&&i!==u.prototype},u.compare=function(i,a){if(xe(i,Uint8Array)&&(i=u.from(i,i.offset,i.byteLength)),xe(a,Uint8Array)&&(a=u.from(a,a.offset,a.byteLength)),!u.isBuffer(i)||!u.isBuffer(a))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(i===a)return 0;let l=i.length,b=a.length;for(let v=0,B=Math.min(l,b);v<B;++v)if(i[v]!==a[v]){l=i[v],b=a[v];break}return l<b?-1:b<l?1:0},u.isEncoding=function(i){switch(String(i).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},u.concat=function(i,a){if(!Array.isArray(i))throw new TypeError('"list" argument must be an Array of Buffers');if(i.length===0)return u.alloc(0);let l;if(a===void 0)for(a=0,l=0;l<i.length;++l)a+=i[l].length;const b=u.allocUnsafe(a);let v=0;for(l=0;l<i.length;++l){let B=i[l];if(xe(B,Uint8Array))v+B.length>b.length?(u.isBuffer(B)||(B=u.from(B)),B.copy(b,v)):Uint8Array.prototype.set.call(b,B,v);else if(u.isBuffer(B))B.copy(b,v);else throw new TypeError('"list" argument must be an Array of Buffers');v+=B.length}return b};function F(f,i){if(u.isBuffer(f))return f.length;if(ArrayBuffer.isView(f)||xe(f,ArrayBuffer))return f.byteLength;if(typeof f!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof f);const a=f.length,l=arguments.length>2&&arguments[2]===!0;if(!l&&a===0)return 0;let b=!1;for(;;)switch(i){case"ascii":case"latin1":case"binary":return a;case"utf8":case"utf-8":return z(f).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return a*2;case"hex":return a>>>1;case"base64":return yt(f).length;default:if(b)return l?-1:z(f).length;i=(""+i).toLowerCase(),b=!0}}u.byteLength=F;function N(f,i,a){let l=!1;if((i===void 0||i<0)&&(i=0),i>this.length||((a===void 0||a>this.length)&&(a=this.length),a<=0)||(a>>>=0,i>>>=0,a<=i))return"";for(f||(f="utf8");;)switch(f){case"hex":return ke(this,i,a);case"utf8":case"utf-8":return _e(this,i,a);case"ascii":return Te(this,i,a);case"latin1":case"binary":return $e(this,i,a);case"base64":return ae(this,i,a);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return He(this,i,a);default:if(l)throw new TypeError("Unknown encoding: "+f);f=(f+"").toLowerCase(),l=!0}}u.prototype._isBuffer=!0;function L(f,i,a){const l=f[i];f[i]=f[a],f[a]=l}u.prototype.swap16=function(){const i=this.length;if(i%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let a=0;a<i;a+=2)L(this,a,a+1);return this},u.prototype.swap32=function(){const i=this.length;if(i%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let a=0;a<i;a+=4)L(this,a,a+3),L(this,a+1,a+2);return this},u.prototype.swap64=function(){const i=this.length;if(i%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let a=0;a<i;a+=8)L(this,a,a+7),L(this,a+1,a+6),L(this,a+2,a+5),L(this,a+3,a+4);return this},u.prototype.toString=function(){const i=this.length;return i===0?"":arguments.length===0?_e(this,0,i):N.apply(this,arguments)},u.prototype.toLocaleString=u.prototype.toString,u.prototype.equals=function(i){if(!u.isBuffer(i))throw new TypeError("Argument must be a Buffer");return this===i?!0:u.compare(this,i)===0},u.prototype.inspect=function(){let i="";const a=e.INSPECT_MAX_BYTES;return i=this.toString("hex",0,a).replace(/(.{2})/g,"$1 ").trim(),this.length>a&&(i+=" ... "),"<Buffer "+i+">"},n&&(u.prototype[n]=u.prototype.inspect),u.prototype.compare=function(i,a,l,b,v){if(xe(i,Uint8Array)&&(i=u.from(i,i.offset,i.byteLength)),!u.isBuffer(i))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof i);if(a===void 0&&(a=0),l===void 0&&(l=i?i.length:0),b===void 0&&(b=0),v===void 0&&(v=this.length),a<0||l>i.length||b<0||v>this.length)throw new RangeError("out of range index");if(b>=v&&a>=l)return 0;if(b>=v)return-1;if(a>=l)return 1;if(a>>>=0,l>>>=0,b>>>=0,v>>>=0,this===i)return 0;let B=v-b,G=l-a;const re=Math.min(B,G),X=this.slice(b,v),ne=i.slice(a,l);for(let V=0;V<re;++V)if(X[V]!==ne[V]){B=X[V],G=ne[V];break}return B<G?-1:G<B?1:0};function S(f,i,a,l,b){if(f.length===0)return-1;if(typeof a=="string"?(l=a,a=0):a>2147483647?a=2147483647:a<-2147483648&&(a=-2147483648),a=+a,Je(a)&&(a=b?0:f.length-1),a<0&&(a=f.length+a),a>=f.length){if(b)return-1;a=f.length-1}else if(a<0)if(b)a=0;else return-1;if(typeof i=="string"&&(i=u.from(i,l)),u.isBuffer(i))return i.length===0?-1:j(f,i,a,l,b);if(typeof i=="number")return i=i&255,typeof Uint8Array.prototype.indexOf=="function"?b?Uint8Array.prototype.indexOf.call(f,i,a):Uint8Array.prototype.lastIndexOf.call(f,i,a):j(f,[i],a,l,b);throw new TypeError("val must be string, number or Buffer")}function j(f,i,a,l,b){let v=1,B=f.length,G=i.length;if(l!==void 0&&(l=String(l).toLowerCase(),l==="ucs2"||l==="ucs-2"||l==="utf16le"||l==="utf-16le")){if(f.length<2||i.length<2)return-1;v=2,B/=2,G/=2,a/=2}function re(ne,V){return v===1?ne[V]:ne.readUInt16BE(V*v)}let X;if(b){let ne=-1;for(X=a;X<B;X++)if(re(f,X)===re(i,ne===-1?0:X-ne)){if(ne===-1&&(ne=X),X-ne+1===G)return ne*v}else ne!==-1&&(X-=X-ne),ne=-1}else for(a+G>B&&(a=B-G),X=a;X>=0;X--){let ne=!0;for(let V=0;V<G;V++)if(re(f,X+V)!==re(i,V)){ne=!1;break}if(ne)return X}return-1}u.prototype.includes=function(i,a,l){return this.indexOf(i,a,l)!==-1},u.prototype.indexOf=function(i,a,l){return S(this,i,a,l,!0)},u.prototype.lastIndexOf=function(i,a,l){return S(this,i,a,l,!1)};function D(f,i,a,l){a=Number(a)||0;const b=f.length-a;l?(l=Number(l),l>b&&(l=b)):l=b;const v=i.length;l>v/2&&(l=v/2);let B;for(B=0;B<l;++B){const G=parseInt(i.substr(B*2,2),16);if(Je(G))return B;f[a+B]=G}return B}function U(f,i,a,l){return nt(z(i,f.length-a),f,a,l)}function ee(f,i,a,l){return nt(qe(i),f,a,l)}function Ie(f,i,a,l){return nt(yt(i),f,a,l)}function De(f,i,a,l){return nt(rt(i,f.length-a),f,a,l)}u.prototype.write=function(i,a,l,b){if(a===void 0)b="utf8",l=this.length,a=0;else if(l===void 0&&typeof a=="string")b=a,l=this.length,a=0;else if(isFinite(a))a=a>>>0,isFinite(l)?(l=l>>>0,b===void 0&&(b="utf8")):(b=l,l=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const v=this.length-a;if((l===void 0||l>v)&&(l=v),i.length>0&&(l<0||a<0)||a>this.length)throw new RangeError("Attempt to write outside buffer bounds");b||(b="utf8");let B=!1;for(;;)switch(b){case"hex":return D(this,i,a,l);case"utf8":case"utf-8":return U(this,i,a,l);case"ascii":case"latin1":case"binary":return ee(this,i,a,l);case"base64":return Ie(this,i,a,l);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return De(this,i,a,l);default:if(B)throw new TypeError("Unknown encoding: "+b);b=(""+b).toLowerCase(),B=!0}},u.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function ae(f,i,a){return i===0&&a===f.length?t.fromByteArray(f):t.fromByteArray(f.slice(i,a))}function _e(f,i,a){a=Math.min(f.length,a);const l=[];let b=i;for(;b<a;){const v=f[b];let B=null,G=v>239?4:v>223?3:v>191?2:1;if(b+G<=a){let re,X,ne,V;switch(G){case 1:v<128&&(B=v);break;case 2:re=f[b+1],(re&192)===128&&(V=(v&31)<<6|re&63,V>127&&(B=V));break;case 3:re=f[b+1],X=f[b+2],(re&192)===128&&(X&192)===128&&(V=(v&15)<<12|(re&63)<<6|X&63,V>2047&&(V<55296||V>57343)&&(B=V));break;case 4:re=f[b+1],X=f[b+2],ne=f[b+3],(re&192)===128&&(X&192)===128&&(ne&192)===128&&(V=(v&15)<<18|(re&63)<<12|(X&63)<<6|ne&63,V>65535&&V<1114112&&(B=V))}}B===null?(B=65533,G=1):B>65535&&(B-=65536,l.push(B>>>10&1023|55296),B=56320|B&1023),l.push(B),b+=G}return Ve(l)}const me=4096;function Ve(f){const i=f.length;if(i<=me)return String.fromCharCode.apply(String,f);let a="",l=0;for(;l<i;)a+=String.fromCharCode.apply(String,f.slice(l,l+=me));return a}function Te(f,i,a){let l="";a=Math.min(f.length,a);for(let b=i;b<a;++b)l+=String.fromCharCode(f[b]&127);return l}function $e(f,i,a){let l="";a=Math.min(f.length,a);for(let b=i;b<a;++b)l+=String.fromCharCode(f[b]);return l}function ke(f,i,a){const l=f.length;(!i||i<0)&&(i=0),(!a||a<0||a>l)&&(a=l);let b="";for(let v=i;v<a;++v)b+=gt[f[v]];return b}function He(f,i,a){const l=f.slice(i,a);let b="";for(let v=0;v<l.length-1;v+=2)b+=String.fromCharCode(l[v]+l[v+1]*256);return b}u.prototype.slice=function(i,a){const l=this.length;i=~~i,a=a===void 0?l:~~a,i<0?(i+=l,i<0&&(i=0)):i>l&&(i=l),a<0?(a+=l,a<0&&(a=0)):a>l&&(a=l),a<i&&(a=i);const b=this.subarray(i,a);return Object.setPrototypeOf(b,u.prototype),b};function Y(f,i,a){if(f%1!==0||f<0)throw new RangeError("offset is not uint");if(f+i>a)throw new RangeError("Trying to access beyond buffer length")}u.prototype.readUintLE=u.prototype.readUIntLE=function(i,a,l){i=i>>>0,a=a>>>0,l||Y(i,a,this.length);let b=this[i],v=1,B=0;for(;++B<a&&(v*=256);)b+=this[i+B]*v;return b},u.prototype.readUintBE=u.prototype.readUIntBE=function(i,a,l){i=i>>>0,a=a>>>0,l||Y(i,a,this.length);let b=this[i+--a],v=1;for(;a>0&&(v*=256);)b+=this[i+--a]*v;return b},u.prototype.readUint8=u.prototype.readUInt8=function(i,a){return i=i>>>0,a||Y(i,1,this.length),this[i]},u.prototype.readUint16LE=u.prototype.readUInt16LE=function(i,a){return i=i>>>0,a||Y(i,2,this.length),this[i]|this[i+1]<<8},u.prototype.readUint16BE=u.prototype.readUInt16BE=function(i,a){return i=i>>>0,a||Y(i,2,this.length),this[i]<<8|this[i+1]},u.prototype.readUint32LE=u.prototype.readUInt32LE=function(i,a){return i=i>>>0,a||Y(i,4,this.length),(this[i]|this[i+1]<<8|this[i+2]<<16)+this[i+3]*16777216},u.prototype.readUint32BE=u.prototype.readUInt32BE=function(i,a){return i=i>>>0,a||Y(i,4,this.length),this[i]*16777216+(this[i+1]<<16|this[i+2]<<8|this[i+3])},u.prototype.readBigUInt64LE=Ee(function(i){i=i>>>0,I(i,"offset");const a=this[i],l=this[i+7];(a===void 0||l===void 0)&&M(i,this.length-8);const b=a+this[++i]*2**8+this[++i]*2**16+this[++i]*2**24,v=this[++i]+this[++i]*2**8+this[++i]*2**16+l*2**24;return BigInt(b)+(BigInt(v)<<BigInt(32))}),u.prototype.readBigUInt64BE=Ee(function(i){i=i>>>0,I(i,"offset");const a=this[i],l=this[i+7];(a===void 0||l===void 0)&&M(i,this.length-8);const b=a*2**24+this[++i]*2**16+this[++i]*2**8+this[++i],v=this[++i]*2**24+this[++i]*2**16+this[++i]*2**8+l;return(BigInt(b)<<BigInt(32))+BigInt(v)}),u.prototype.readIntLE=function(i,a,l){i=i>>>0,a=a>>>0,l||Y(i,a,this.length);let b=this[i],v=1,B=0;for(;++B<a&&(v*=256);)b+=this[i+B]*v;return v*=128,b>=v&&(b-=Math.pow(2,8*a)),b},u.prototype.readIntBE=function(i,a,l){i=i>>>0,a=a>>>0,l||Y(i,a,this.length);let b=a,v=1,B=this[i+--b];for(;b>0&&(v*=256);)B+=this[i+--b]*v;return v*=128,B>=v&&(B-=Math.pow(2,8*a)),B},u.prototype.readInt8=function(i,a){return i=i>>>0,a||Y(i,1,this.length),this[i]&128?(255-this[i]+1)*-1:this[i]},u.prototype.readInt16LE=function(i,a){i=i>>>0,a||Y(i,2,this.length);const l=this[i]|this[i+1]<<8;return l&32768?l|4294901760:l},u.prototype.readInt16BE=function(i,a){i=i>>>0,a||Y(i,2,this.length);const l=this[i+1]|this[i]<<8;return l&32768?l|4294901760:l},u.prototype.readInt32LE=function(i,a){return i=i>>>0,a||Y(i,4,this.length),this[i]|this[i+1]<<8|this[i+2]<<16|this[i+3]<<24},u.prototype.readInt32BE=function(i,a){return i=i>>>0,a||Y(i,4,this.length),this[i]<<24|this[i+1]<<16|this[i+2]<<8|this[i+3]},u.prototype.readBigInt64LE=Ee(function(i){i=i>>>0,I(i,"offset");const a=this[i],l=this[i+7];(a===void 0||l===void 0)&&M(i,this.length-8);const b=this[i+4]+this[i+5]*2**8+this[i+6]*2**16+(l<<24);return(BigInt(b)<<BigInt(32))+BigInt(a+this[++i]*2**8+this[++i]*2**16+this[++i]*2**24)}),u.prototype.readBigInt64BE=Ee(function(i){i=i>>>0,I(i,"offset");const a=this[i],l=this[i+7];(a===void 0||l===void 0)&&M(i,this.length-8);const b=(a<<24)+this[++i]*2**16+this[++i]*2**8+this[++i];return(BigInt(b)<<BigInt(32))+BigInt(this[++i]*2**24+this[++i]*2**16+this[++i]*2**8+l)}),u.prototype.readFloatLE=function(i,a){return i=i>>>0,a||Y(i,4,this.length),r.read(this,i,!0,23,4)},u.prototype.readFloatBE=function(i,a){return i=i>>>0,a||Y(i,4,this.length),r.read(this,i,!1,23,4)},u.prototype.readDoubleLE=function(i,a){return i=i>>>0,a||Y(i,8,this.length),r.read(this,i,!0,52,8)},u.prototype.readDoubleBE=function(i,a){return i=i>>>0,a||Y(i,8,this.length),r.read(this,i,!1,52,8)};function ie(f,i,a,l,b,v){if(!u.isBuffer(f))throw new TypeError('"buffer" argument must be a Buffer instance');if(i>b||i<v)throw new RangeError('"value" argument is out of bounds');if(a+l>f.length)throw new RangeError("Index out of range")}u.prototype.writeUintLE=u.prototype.writeUIntLE=function(i,a,l,b){if(i=+i,a=a>>>0,l=l>>>0,!b){const G=Math.pow(2,8*l)-1;ie(this,i,a,l,G,0)}let v=1,B=0;for(this[a]=i&255;++B<l&&(v*=256);)this[a+B]=i/v&255;return a+l},u.prototype.writeUintBE=u.prototype.writeUIntBE=function(i,a,l,b){if(i=+i,a=a>>>0,l=l>>>0,!b){const G=Math.pow(2,8*l)-1;ie(this,i,a,l,G,0)}let v=l-1,B=1;for(this[a+v]=i&255;--v>=0&&(B*=256);)this[a+v]=i/B&255;return a+l},u.prototype.writeUint8=u.prototype.writeUInt8=function(i,a,l){return i=+i,a=a>>>0,l||ie(this,i,a,1,255,0),this[a]=i&255,a+1},u.prototype.writeUint16LE=u.prototype.writeUInt16LE=function(i,a,l){return i=+i,a=a>>>0,l||ie(this,i,a,2,65535,0),this[a]=i&255,this[a+1]=i>>>8,a+2},u.prototype.writeUint16BE=u.prototype.writeUInt16BE=function(i,a,l){return i=+i,a=a>>>0,l||ie(this,i,a,2,65535,0),this[a]=i>>>8,this[a+1]=i&255,a+2},u.prototype.writeUint32LE=u.prototype.writeUInt32LE=function(i,a,l){return i=+i,a=a>>>0,l||ie(this,i,a,4,4294967295,0),this[a+3]=i>>>24,this[a+2]=i>>>16,this[a+1]=i>>>8,this[a]=i&255,a+4},u.prototype.writeUint32BE=u.prototype.writeUInt32BE=function(i,a,l){return i=+i,a=a>>>0,l||ie(this,i,a,4,4294967295,0),this[a]=i>>>24,this[a+1]=i>>>16,this[a+2]=i>>>8,this[a+3]=i&255,a+4};function ve(f,i,a,l,b){d(i,l,b,f,a,7);let v=Number(i&BigInt(4294967295));f[a++]=v,v=v>>8,f[a++]=v,v=v>>8,f[a++]=v,v=v>>8,f[a++]=v;let B=Number(i>>BigInt(32)&BigInt(4294967295));return f[a++]=B,B=B>>8,f[a++]=B,B=B>>8,f[a++]=B,B=B>>8,f[a++]=B,a}function je(f,i,a,l,b){d(i,l,b,f,a,7);let v=Number(i&BigInt(4294967295));f[a+7]=v,v=v>>8,f[a+6]=v,v=v>>8,f[a+5]=v,v=v>>8,f[a+4]=v;let B=Number(i>>BigInt(32)&BigInt(4294967295));return f[a+3]=B,B=B>>8,f[a+2]=B,B=B>>8,f[a+1]=B,B=B>>8,f[a]=B,a+8}u.prototype.writeBigUInt64LE=Ee(function(i,a=0){return ve(this,i,a,BigInt(0),BigInt("0xffffffffffffffff"))}),u.prototype.writeBigUInt64BE=Ee(function(i,a=0){return je(this,i,a,BigInt(0),BigInt("0xffffffffffffffff"))}),u.prototype.writeIntLE=function(i,a,l,b){if(i=+i,a=a>>>0,!b){const re=Math.pow(2,8*l-1);ie(this,i,a,l,re-1,-re)}let v=0,B=1,G=0;for(this[a]=i&255;++v<l&&(B*=256);)i<0&&G===0&&this[a+v-1]!==0&&(G=1),this[a+v]=(i/B>>0)-G&255;return a+l},u.prototype.writeIntBE=function(i,a,l,b){if(i=+i,a=a>>>0,!b){const re=Math.pow(2,8*l-1);ie(this,i,a,l,re-1,-re)}let v=l-1,B=1,G=0;for(this[a+v]=i&255;--v>=0&&(B*=256);)i<0&&G===0&&this[a+v+1]!==0&&(G=1),this[a+v]=(i/B>>0)-G&255;return a+l},u.prototype.writeInt8=function(i,a,l){return i=+i,a=a>>>0,l||ie(this,i,a,1,127,-128),i<0&&(i=255+i+1),this[a]=i&255,a+1},u.prototype.writeInt16LE=function(i,a,l){return i=+i,a=a>>>0,l||ie(this,i,a,2,32767,-32768),this[a]=i&255,this[a+1]=i>>>8,a+2},u.prototype.writeInt16BE=function(i,a,l){return i=+i,a=a>>>0,l||ie(this,i,a,2,32767,-32768),this[a]=i>>>8,this[a+1]=i&255,a+2},u.prototype.writeInt32LE=function(i,a,l){return i=+i,a=a>>>0,l||ie(this,i,a,4,2147483647,-2147483648),this[a]=i&255,this[a+1]=i>>>8,this[a+2]=i>>>16,this[a+3]=i>>>24,a+4},u.prototype.writeInt32BE=function(i,a,l){return i=+i,a=a>>>0,l||ie(this,i,a,4,2147483647,-2147483648),i<0&&(i=4294967295+i+1),this[a]=i>>>24,this[a+1]=i>>>16,this[a+2]=i>>>8,this[a+3]=i&255,a+4},u.prototype.writeBigInt64LE=Ee(function(i,a=0){return ve(this,i,a,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),u.prototype.writeBigInt64BE=Ee(function(i,a=0){return je(this,i,a,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Ne(f,i,a,l,b,v){if(a+l>f.length)throw new RangeError("Index out of range");if(a<0)throw new RangeError("Index out of range")}function m(f,i,a,l,b){return i=+i,a=a>>>0,b||Ne(f,i,a,4),r.write(f,i,a,l,23,4),a+4}u.prototype.writeFloatLE=function(i,a,l){return m(this,i,a,!0,l)},u.prototype.writeFloatBE=function(i,a,l){return m(this,i,a,!1,l)};function _(f,i,a,l,b){return i=+i,a=a>>>0,b||Ne(f,i,a,8),r.write(f,i,a,l,52,8),a+8}u.prototype.writeDoubleLE=function(i,a,l){return _(this,i,a,!0,l)},u.prototype.writeDoubleBE=function(i,a,l){return _(this,i,a,!1,l)},u.prototype.copy=function(i,a,l,b){if(!u.isBuffer(i))throw new TypeError("argument should be a Buffer");if(l||(l=0),!b&&b!==0&&(b=this.length),a>=i.length&&(a=i.length),a||(a=0),b>0&&b<l&&(b=l),b===l||i.length===0||this.length===0)return 0;if(a<0)throw new RangeError("targetStart out of bounds");if(l<0||l>=this.length)throw new RangeError("Index out of range");if(b<0)throw new RangeError("sourceEnd out of bounds");b>this.length&&(b=this.length),i.length-a<b-l&&(b=i.length-a+l);const v=b-l;return this===i&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(a,l,b):Uint8Array.prototype.set.call(i,this.subarray(l,b),a),v},u.prototype.fill=function(i,a,l,b){if(typeof i=="string"){if(typeof a=="string"?(b=a,a=0,l=this.length):typeof l=="string"&&(b=l,l=this.length),b!==void 0&&typeof b!="string")throw new TypeError("encoding must be a string");if(typeof b=="string"&&!u.isEncoding(b))throw new TypeError("Unknown encoding: "+b);if(i.length===1){const B=i.charCodeAt(0);(b==="utf8"&&B<128||b==="latin1")&&(i=B)}}else typeof i=="number"?i=i&255:typeof i=="boolean"&&(i=Number(i));if(a<0||this.length<a||this.length<l)throw new RangeError("Out of range index");if(l<=a)return this;a=a>>>0,l=l===void 0?this.length:l>>>0,i||(i=0);let v;if(typeof i=="number")for(v=a;v<l;++v)this[v]=i;else{const B=u.isBuffer(i)?i:u.from(i,b),G=B.length;if(G===0)throw new TypeError('The value "'+i+'" is invalid for argument "value"');for(v=0;v<l-a;++v)this[v+a]=B[v%G]}return this};const A={};function $(f,i,a){A[f]=class extends a{constructor(){super(),Object.defineProperty(this,"message",{value:i.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${f}]`,this.stack,delete this.name}get code(){return f}set code(b){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:b,writable:!0})}toString(){return`${this.name} [${f}]: ${this.message}`}}}$("ERR_BUFFER_OUT_OF_BOUNDS",function(f){return f?`${f} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),$("ERR_INVALID_ARG_TYPE",function(f,i){return`The "${f}" argument must be of type number. Received type ${typeof i}`},TypeError),$("ERR_OUT_OF_RANGE",function(f,i,a){let l=`The value of "${f}" is out of range.`,b=a;return Number.isInteger(a)&&Math.abs(a)>2**32?b=q(String(a)):typeof a=="bigint"&&(b=String(a),(a>BigInt(2)**BigInt(32)||a<-(BigInt(2)**BigInt(32)))&&(b=q(b)),b+="n"),l+=` It must be ${i}. Received ${b}`,l},RangeError);function q(f){let i="",a=f.length;const l=f[0]==="-"?1:0;for(;a>=l+4;a-=3)i=`_${f.slice(a-3,a)}${i}`;return`${f.slice(0,a)}${i}`}function h(f,i,a){I(i,"offset"),(f[i]===void 0||f[i+a]===void 0)&&M(i,f.length-(a+1))}function d(f,i,a,l,b,v){if(f>a||f<i){const B=typeof i=="bigint"?"n":"";let G;throw i===0||i===BigInt(0)?G=`>= 0${B} and < 2${B} ** ${(v+1)*8}${B}`:G=`>= -(2${B} ** ${(v+1)*8-1}${B}) and < 2 ** ${(v+1)*8-1}${B}`,new A.ERR_OUT_OF_RANGE("value",G,f)}h(l,b,v)}function I(f,i){if(typeof f!="number")throw new A.ERR_INVALID_ARG_TYPE(i,"number",f)}function M(f,i,a){throw Math.floor(f)!==f?(I(f,a),new A.ERR_OUT_OF_RANGE("offset","an integer",f)):i<0?new A.ERR_BUFFER_OUT_OF_BOUNDS:new A.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${i}`,f)}const Q=/[^+/0-9A-Za-z-_]/g;function W(f){if(f=f.split("=")[0],f=f.trim().replace(Q,""),f.length<2)return"";for(;f.length%4!==0;)f=f+"=";return f}function z(f,i){i=i||1/0;let a;const l=f.length;let b=null;const v=[];for(let B=0;B<l;++B){if(a=f.charCodeAt(B),a>55295&&a<57344){if(!b){if(a>56319){(i-=3)>-1&&v.push(239,191,189);continue}else if(B+1===l){(i-=3)>-1&&v.push(239,191,189);continue}b=a;continue}if(a<56320){(i-=3)>-1&&v.push(239,191,189),b=a;continue}a=(b-55296<<10|a-56320)+65536}else b&&(i-=3)>-1&&v.push(239,191,189);if(b=null,a<128){if((i-=1)<0)break;v.push(a)}else if(a<2048){if((i-=2)<0)break;v.push(a>>6|192,a&63|128)}else if(a<65536){if((i-=3)<0)break;v.push(a>>12|224,a>>6&63|128,a&63|128)}else if(a<1114112){if((i-=4)<0)break;v.push(a>>18|240,a>>12&63|128,a>>6&63|128,a&63|128)}else throw new Error("Invalid code point")}return v}function qe(f){const i=[];for(let a=0;a<f.length;++a)i.push(f.charCodeAt(a)&255);return i}function rt(f,i){let a,l,b;const v=[];for(let B=0;B<f.length&&!((i-=2)<0);++B)a=f.charCodeAt(B),l=a>>8,b=a%256,v.push(b),v.push(l);return v}function yt(f){return t.toByteArray(W(f))}function nt(f,i,a,l){let b;for(b=0;b<l&&!(b+a>=i.length||b>=f.length);++b)i[b+a]=f[b];return b}function xe(f,i){return f instanceof i||f!=null&&f.constructor!=null&&f.constructor.name!=null&&f.constructor.name===i.name}function Je(f){return f!==f}const gt=function(){const f="0123456789abcdef",i=new Array(256);for(let a=0;a<16;++a){const l=a*16;for(let b=0;b<16;++b)i[l+b]=f[a]+f[b]}return i}();function Ee(f){return typeof BigInt>"u"?Ye:f}function Ye(){throw new Error("BigInt not supported")}})(pt);/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */(function(e,t){var r=pt,n=r.Buffer;function o(c,u){for(var p in c)u[p]=c[p]}n.from&&n.alloc&&n.allocUnsafe&&n.allocUnsafeSlow?e.exports=r:(o(r,t),t.Buffer=s);function s(c,u,p){return n(c,u,p)}s.prototype=Object.create(n.prototype),o(n,s),s.from=function(c,u,p){if(typeof c=="number")throw new TypeError("Argument must not be a number");return n(c,u,p)},s.alloc=function(c,u,p){if(typeof c!="number")throw new TypeError("Argument must be a number");var y=n(c);return u!==void 0?typeof p=="string"?y.fill(u,p):y.fill(u):y.fill(0),y},s.allocUnsafe=function(c){if(typeof c!="number")throw new TypeError("Argument must be a number");return n(c)},s.allocUnsafeSlow=function(c){if(typeof c!="number")throw new TypeError("Argument must be a number");return r.SlowBuffer(c)}})(Or,Or.exports);var we=Or.exports,lr=65536,eo=4294967295;function to(){throw new Error(`Secure random number generation is not supported by this browser.
29
- Use Chrome, Firefox or Internet Explorer 11`)}var ro=we.Buffer,Wt=ze.crypto||ze.msCrypto;Wt&&Wt.getRandomValues?Pr.exports=no:Pr.exports=to;function no(e,t){if(e>eo)throw new RangeError("requested too many random bytes");var r=ro.allocUnsafe(e);if(e>0)if(e>lr)for(var n=0;n<e;n+=lr)Wt.getRandomValues(r.slice(n,n+lr));else Wt.getRandomValues(r);return typeof t=="function"?process.nextTick(function(){t(null,r)}):r}var io=Pr.exports,Nr={exports:{}};typeof Object.create=="function"?Nr.exports=function(t,r){r&&(t.super_=r,t.prototype=Object.create(r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}))}:Nr.exports=function(t,r){if(r){t.super_=r;var n=function(){};n.prototype=r.prototype,t.prototype=new n,t.prototype.constructor=t}};var pe=Nr.exports,Fr={exports:{}},Gr={exports:{}},ut=typeof Reflect=="object"?Reflect:null,fn=ut&&typeof ut.apply=="function"?ut.apply:function(t,r,n){return Function.prototype.apply.call(t,r,n)},Dt;ut&&typeof ut.ownKeys=="function"?Dt=ut.ownKeys:Object.getOwnPropertySymbols?Dt=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:Dt=function(t){return Object.getOwnPropertyNames(t)};function ao(e){console&&console.warn&&console.warn(e)}var ri=Number.isNaN||function(t){return t!==t};function K(){K.init.call(this)}Gr.exports=K;Gr.exports.once=uo;K.EventEmitter=K;K.prototype._events=void 0;K.prototype._eventsCount=0;K.prototype._maxListeners=void 0;var un=10;function Yt(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(K,"defaultMaxListeners",{enumerable:!0,get:function(){return un},set:function(e){if(typeof e!="number"||e<0||ri(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");un=e}});K.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0};K.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||ri(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this};function ni(e){return e._maxListeners===void 0?K.defaultMaxListeners:e._maxListeners}K.prototype.getMaxListeners=function(){return ni(this)};K.prototype.emit=function(t){for(var r=[],n=1;n<arguments.length;n++)r.push(arguments[n]);var o=t==="error",s=this._events;if(s!==void 0)o=o&&s.error===void 0;else if(!o)return!1;if(o){var c;if(r.length>0&&(c=r[0]),c instanceof Error)throw c;var u=new Error("Unhandled error."+(c?" ("+c.message+")":""));throw u.context=c,u}var p=s[t];if(p===void 0)return!1;if(typeof p=="function")fn(p,this,r);else for(var y=p.length,g=fi(p,y),n=0;n<y;++n)fn(g[n],this,r);return!0};function ii(e,t,r,n){var o,s,c;if(Yt(r),s=e._events,s===void 0?(s=e._events=Object.create(null),e._eventsCount=0):(s.newListener!==void 0&&(e.emit("newListener",t,r.listener?r.listener:r),s=e._events),c=s[t]),c===void 0)c=s[t]=r,++e._eventsCount;else if(typeof c=="function"?c=s[t]=n?[r,c]:[c,r]:n?c.unshift(r):c.push(r),o=ni(e),o>0&&c.length>o&&!c.warned){c.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+c.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=c.length,ao(u)}return e}K.prototype.addListener=function(t,r){return ii(this,t,r,!1)};K.prototype.on=K.prototype.addListener;K.prototype.prependListener=function(t,r){return ii(this,t,r,!0)};function oo(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function ai(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},o=oo.bind(n);return o.listener=r,n.wrapFn=o,o}K.prototype.once=function(t,r){return Yt(r),this.on(t,ai(this,t,r)),this};K.prototype.prependOnceListener=function(t,r){return Yt(r),this.prependListener(t,ai(this,t,r)),this};K.prototype.removeListener=function(t,r){var n,o,s,c,u;if(Yt(r),o=this._events,o===void 0)return this;if(n=o[t],n===void 0)return this;if(n===r||n.listener===r)--this._eventsCount===0?this._events=Object.create(null):(delete o[t],o.removeListener&&this.emit("removeListener",t,n.listener||r));else if(typeof n!="function"){for(s=-1,c=n.length-1;c>=0;c--)if(n[c]===r||n[c].listener===r){u=n[c].listener,s=c;break}if(s<0)return this;s===0?n.shift():so(n,s),n.length===1&&(o[t]=n[0]),o.removeListener!==void 0&&this.emit("removeListener",t,u||r)}return this};K.prototype.off=K.prototype.removeListener;K.prototype.removeAllListeners=function(t){var r,n,o;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[t]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[t]),this;if(arguments.length===0){var s=Object.keys(n),c;for(o=0;o<s.length;++o)c=s[o],c!=="removeListener"&&this.removeAllListeners(c);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(r=n[t],typeof r=="function")this.removeListener(t,r);else if(r!==void 0)for(o=r.length-1;o>=0;o--)this.removeListener(t,r[o]);return this};function oi(e,t,r){var n=e._events;if(n===void 0)return[];var o=n[t];return o===void 0?[]:typeof o=="function"?r?[o.listener||o]:[o]:r?fo(o):fi(o,o.length)}K.prototype.listeners=function(t){return oi(this,t,!0)};K.prototype.rawListeners=function(t){return oi(this,t,!1)};K.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):si.call(e,t)};K.prototype.listenerCount=si;function si(e){var t=this._events;if(t!==void 0){var r=t[e];if(typeof r=="function")return 1;if(r!==void 0)return r.length}return 0}K.prototype.eventNames=function(){return this._eventsCount>0?Dt(this._events):[]};function fi(e,t){for(var r=new Array(t),n=0;n<t;++n)r[n]=e[n];return r}function so(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function fo(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}function uo(e,t){return new Promise(function(r,n){function o(c){e.removeListener(t,s),n(c)}function s(){typeof e.removeListener=="function"&&e.removeListener("error",o),r([].slice.call(arguments))}ui(e,t,s,{once:!0}),t!=="error"&&co(e,o,{once:!0})})}function co(e,t,r){typeof e.on=="function"&&ui(e,"error",t,r)}function ui(e,t,r,n){if(typeof e.on=="function")n.once?e.once(t,r):e.on(t,r);else if(typeof e.addEventListener=="function")e.addEventListener(t,function o(s){n.once&&e.removeEventListener(t,o),r(s)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e)}var ci=Gr.exports,li=ci.EventEmitter;const lo={},ho=Object.freeze(Object.defineProperty({__proto__:null,default:lo},Symbol.toStringTag,{value:"Module"})),zr=Ua(ho);var hr,cn;function po(){if(cn)return hr;cn=1;function e(R,C){var E=Object.keys(R);if(Object.getOwnPropertySymbols){var k=Object.getOwnPropertySymbols(R);C&&(k=k.filter(function(O){return Object.getOwnPropertyDescriptor(R,O).enumerable})),E.push.apply(E,k)}return E}function t(R){for(var C=1;C<arguments.length;C++){var E=arguments[C]!=null?arguments[C]:{};C%2?e(Object(E),!0).forEach(function(k){r(R,k,E[k])}):Object.getOwnPropertyDescriptors?Object.defineProperties(R,Object.getOwnPropertyDescriptors(E)):e(Object(E)).forEach(function(k){Object.defineProperty(R,k,Object.getOwnPropertyDescriptor(E,k))})}return R}function r(R,C,E){return C=c(C),C in R?Object.defineProperty(R,C,{value:E,enumerable:!0,configurable:!0,writable:!0}):R[C]=E,R}function n(R,C){if(!(R instanceof C))throw new TypeError("Cannot call a class as a function")}function o(R,C){for(var E=0;E<C.length;E++){var k=C[E];k.enumerable=k.enumerable||!1,k.configurable=!0,"value"in k&&(k.writable=!0),Object.defineProperty(R,c(k.key),k)}}function s(R,C,E){return C&&o(R.prototype,C),Object.defineProperty(R,"prototype",{writable:!1}),R}function c(R){var C=u(R,"string");return typeof C=="symbol"?C:String(C)}function u(R,C){if(typeof R!="object"||R===null)return R;var E=R[Symbol.toPrimitive];if(E!==void 0){var k=E.call(R,C||"default");if(typeof k!="object")return k;throw new TypeError("@@toPrimitive must return a primitive value.")}return(C==="string"?String:Number)(R)}var p=pt,y=p.Buffer,g=zr,w=g.inspect,x=w&&w.custom||"inspect";function T(R,C,E){y.prototype.copy.call(R,C,E)}return hr=function(){function R(){n(this,R),this.head=null,this.tail=null,this.length=0}return s(R,[{key:"push",value:function(E){var k={data:E,next:null};this.length>0?this.tail.next=k:this.head=k,this.tail=k,++this.length}},{key:"unshift",value:function(E){var k={data:E,next:this.head};this.length===0&&(this.tail=k),this.head=k,++this.length}},{key:"shift",value:function(){if(this.length!==0){var E=this.head.data;return this.length===1?this.head=this.tail=null:this.head=this.head.next,--this.length,E}}},{key:"clear",value:function(){this.head=this.tail=null,this.length=0}},{key:"join",value:function(E){if(this.length===0)return"";for(var k=this.head,O=""+k.data;k=k.next;)O+=E+k.data;return O}},{key:"concat",value:function(E){if(this.length===0)return y.alloc(0);for(var k=y.allocUnsafe(E>>>0),O=this.head,F=0;O;)T(O.data,k,F),F+=O.data.length,O=O.next;return k}},{key:"consume",value:function(E,k){var O;return E<this.head.data.length?(O=this.head.data.slice(0,E),this.head.data=this.head.data.slice(E)):E===this.head.data.length?O=this.shift():O=k?this._getString(E):this._getBuffer(E),O}},{key:"first",value:function(){return this.head.data}},{key:"_getString",value:function(E){var k=this.head,O=1,F=k.data;for(E-=F.length;k=k.next;){var N=k.data,L=E>N.length?N.length:E;if(L===N.length?F+=N:F+=N.slice(0,E),E-=L,E===0){L===N.length?(++O,k.next?this.head=k.next:this.head=this.tail=null):(this.head=k,k.data=N.slice(L));break}++O}return this.length-=O,F}},{key:"_getBuffer",value:function(E){var k=y.allocUnsafe(E),O=this.head,F=1;for(O.data.copy(k),E-=O.data.length;O=O.next;){var N=O.data,L=E>N.length?N.length:E;if(N.copy(k,k.length-E,0,L),E-=L,E===0){L===N.length?(++F,O.next?this.head=O.next:this.head=this.tail=null):(this.head=O,O.data=N.slice(L));break}++F}return this.length-=F,k}},{key:x,value:function(E,k){return w(this,t(t({},k),{},{depth:0,customInspect:!1}))}}]),R}(),hr}function bo(e,t){var r=this,n=this._readableState&&this._readableState.destroyed,o=this._writableState&&this._writableState.destroyed;return n||o?(t?t(e):e&&(this._writableState?this._writableState.errorEmitted||(this._writableState.errorEmitted=!0,process.nextTick(Lr,this,e)):process.nextTick(Lr,this,e)),this):(this._readableState&&(this._readableState.destroyed=!0),this._writableState&&(this._writableState.destroyed=!0),this._destroy(e||null,function(s){!t&&s?r._writableState?r._writableState.errorEmitted?process.nextTick($t,r):(r._writableState.errorEmitted=!0,process.nextTick(ln,r,s)):process.nextTick(ln,r,s):t?(process.nextTick($t,r),t(s)):process.nextTick($t,r)}),this)}function ln(e,t){Lr(e,t),$t(e)}function $t(e){e._writableState&&!e._writableState.emitClose||e._readableState&&!e._readableState.emitClose||e.emit("close")}function yo(){this._readableState&&(this._readableState.destroyed=!1,this._readableState.reading=!1,this._readableState.ended=!1,this._readableState.endEmitted=!1),this._writableState&&(this._writableState.destroyed=!1,this._writableState.ended=!1,this._writableState.ending=!1,this._writableState.finalCalled=!1,this._writableState.prefinished=!1,this._writableState.finished=!1,this._writableState.errorEmitted=!1)}function Lr(e,t){e.emit("error",t)}function go(e,t){var r=e._readableState,n=e._writableState;r&&r.autoDestroy||n&&n.autoDestroy?e.destroy(t):e.emit("error",t)}var hi={destroy:bo,undestroy:yo,errorOrDestroy:go},et={};function _o(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var di={};function Se(e,t,r){r||(r=Error);function n(s,c,u){return typeof t=="string"?t:t(s,c,u)}var o=function(s){_o(c,s);function c(u,p,y){return s.call(this,n(u,p,y))||this}return c}(r);o.prototype.name=r.name,o.prototype.code=e,di[e]=o}function hn(e,t){if(Array.isArray(e)){var r=e.length;return e=e.map(function(n){return String(n)}),r>2?"one of ".concat(t," ").concat(e.slice(0,r-1).join(", "),", or ")+e[r-1]:r===2?"one of ".concat(t," ").concat(e[0]," or ").concat(e[1]):"of ".concat(t," ").concat(e[0])}else return"of ".concat(t," ").concat(String(e))}function mo(e,t,r){return e.substr(0,t.length)===t}function wo(e,t,r){return(r===void 0||r>e.length)&&(r=e.length),e.substring(r-t.length,r)===t}function vo(e,t,r){return typeof r!="number"&&(r=0),r+t.length>e.length?!1:e.indexOf(t,r)!==-1}Se("ERR_INVALID_OPT_VALUE",function(e,t){return'The value "'+t+'" is invalid for option "'+e+'"'},TypeError);Se("ERR_INVALID_ARG_TYPE",function(e,t,r){var n;typeof t=="string"&&mo(t,"not ")?(n="must not be",t=t.replace(/^not /,"")):n="must be";var o;if(wo(e," argument"))o="The ".concat(e," ").concat(n," ").concat(hn(t,"type"));else{var s=vo(e,".")?"property":"argument";o='The "'.concat(e,'" ').concat(s," ").concat(n," ").concat(hn(t,"type"))}return o+=". Received type ".concat(typeof r),o},TypeError);Se("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF");Se("ERR_METHOD_NOT_IMPLEMENTED",function(e){return"The "+e+" method is not implemented"});Se("ERR_STREAM_PREMATURE_CLOSE","Premature close");Se("ERR_STREAM_DESTROYED",function(e){return"Cannot call "+e+" after a stream was destroyed"});Se("ERR_MULTIPLE_CALLBACK","Callback called multiple times");Se("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable");Se("ERR_STREAM_WRITE_AFTER_END","write after end");Se("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError);Se("ERR_UNKNOWN_ENCODING",function(e){return"Unknown encoding: "+e},TypeError);Se("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event");et.codes=di;var xo=et.codes.ERR_INVALID_OPT_VALUE;function Eo(e,t,r){return e.highWaterMark!=null?e.highWaterMark:t?e[r]:null}function Bo(e,t,r,n){var o=Eo(t,n,r);if(o!=null){if(!(isFinite(o)&&Math.floor(o)===o)||o<0){var s=n?r:"highWaterMark";throw new xo(s,o)}return Math.floor(o)}return e.objectMode?16:16*1024}var pi={getHighWaterMark:Bo},Ro=So;function So(e,t){if(dr("noDeprecation"))return e;var r=!1;function n(){if(!r){if(dr("throwDeprecation"))throw new Error(t);dr("traceDeprecation")?console.trace(t):console.warn(t),r=!0}return e.apply(this,arguments)}return n}function dr(e){try{if(!ze.localStorage)return!1}catch{return!1}var t=ze.localStorage[e];return t==null?!1:String(t).toLowerCase()==="true"}var pr,dn;function bi(){if(dn)return pr;dn=1,pr=D;function e(m){var _=this;this.next=null,this.entry=null,this.finish=function(){Ne(_,m)}}var t;D.WritableState=S;var r={deprecate:Ro},n=li,o=pt.Buffer,s=(typeof ze<"u"?ze:typeof window<"u"?window:typeof self<"u"?self:{}).Uint8Array||function(){};function c(m){return o.from(m)}function u(m){return o.isBuffer(m)||m instanceof s}var p=hi,y=pi,g=y.getHighWaterMark,w=et.codes,x=w.ERR_INVALID_ARG_TYPE,T=w.ERR_METHOD_NOT_IMPLEMENTED,R=w.ERR_MULTIPLE_CALLBACK,C=w.ERR_STREAM_CANNOT_PIPE,E=w.ERR_STREAM_DESTROYED,k=w.ERR_STREAM_NULL_VALUES,O=w.ERR_STREAM_WRITE_AFTER_END,F=w.ERR_UNKNOWN_ENCODING,N=p.errorOrDestroy;pe(D,n);function L(){}function S(m,_,A){t=t||dt(),m=m||{},typeof A!="boolean"&&(A=_ instanceof t),this.objectMode=!!m.objectMode,A&&(this.objectMode=this.objectMode||!!m.writableObjectMode),this.highWaterMark=g(this,m,"writableHighWaterMark",A),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var $=m.decodeStrings===!1;this.decodeStrings=!$,this.defaultEncoding=m.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(q){Ve(_,q)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=m.emitClose!==!1,this.autoDestroy=!!m.autoDestroy,this.bufferedRequestCount=0,this.corkedRequestsFree=new e(this)}S.prototype.getBuffer=function(){for(var _=this.bufferedRequest,A=[];_;)A.push(_),_=_.next;return A},function(){try{Object.defineProperty(S.prototype,"buffer",{get:r.deprecate(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch{}}();var j;typeof Symbol=="function"&&Symbol.hasInstance&&typeof Function.prototype[Symbol.hasInstance]=="function"?(j=Function.prototype[Symbol.hasInstance],Object.defineProperty(D,Symbol.hasInstance,{value:function(_){return j.call(this,_)?!0:this!==D?!1:_&&_._writableState instanceof S}})):j=function(_){return _ instanceof this};function D(m){t=t||dt();var _=this instanceof t;if(!_&&!j.call(D,this))return new D(m);this._writableState=new S(m,this,_),this.writable=!0,m&&(typeof m.write=="function"&&(this._write=m.write),typeof m.writev=="function"&&(this._writev=m.writev),typeof m.destroy=="function"&&(this._destroy=m.destroy),typeof m.final=="function"&&(this._final=m.final)),n.call(this)}D.prototype.pipe=function(){N(this,new C)};function U(m,_){var A=new O;N(m,A),process.nextTick(_,A)}function ee(m,_,A,$){var q;return A===null?q=new k:typeof A!="string"&&!_.objectMode&&(q=new x("chunk",["string","Buffer"],A)),q?(N(m,q),process.nextTick($,q),!1):!0}D.prototype.write=function(m,_,A){var $=this._writableState,q=!1,h=!$.objectMode&&u(m);return h&&!o.isBuffer(m)&&(m=c(m)),typeof _=="function"&&(A=_,_=null),h?_="buffer":_||(_=$.defaultEncoding),typeof A!="function"&&(A=L),$.ending?U(this,A):(h||ee(this,$,m,A))&&($.pendingcb++,q=De(this,$,h,m,_,A)),q},D.prototype.cork=function(){this._writableState.corked++},D.prototype.uncork=function(){var m=this._writableState;m.corked&&(m.corked--,!m.writing&&!m.corked&&!m.bufferProcessing&&m.bufferedRequest&&ke(this,m))},D.prototype.setDefaultEncoding=function(_){if(typeof _=="string"&&(_=_.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((_+"").toLowerCase())>-1))throw new F(_);return this._writableState.defaultEncoding=_,this},Object.defineProperty(D.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}});function Ie(m,_,A){return!m.objectMode&&m.decodeStrings!==!1&&typeof _=="string"&&(_=o.from(_,A)),_}Object.defineProperty(D.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}});function De(m,_,A,$,q,h){if(!A){var d=Ie(_,$,q);$!==d&&(A=!0,q="buffer",$=d)}var I=_.objectMode?1:$.length;_.length+=I;var M=_.length<_.highWaterMark;if(M||(_.needDrain=!0),_.writing||_.corked){var Q=_.lastBufferedRequest;_.lastBufferedRequest={chunk:$,encoding:q,isBuf:A,callback:h,next:null},Q?Q.next=_.lastBufferedRequest:_.bufferedRequest=_.lastBufferedRequest,_.bufferedRequestCount+=1}else ae(m,_,!1,I,$,q,h);return M}function ae(m,_,A,$,q,h,d){_.writelen=$,_.writecb=d,_.writing=!0,_.sync=!0,_.destroyed?_.onwrite(new E("write")):A?m._writev(q,_.onwrite):m._write(q,h,_.onwrite),_.sync=!1}function _e(m,_,A,$,q){--_.pendingcb,A?(process.nextTick(q,$),process.nextTick(ve,m,_),m._writableState.errorEmitted=!0,N(m,$)):(q($),m._writableState.errorEmitted=!0,N(m,$),ve(m,_))}function me(m){m.writing=!1,m.writecb=null,m.length-=m.writelen,m.writelen=0}function Ve(m,_){var A=m._writableState,$=A.sync,q=A.writecb;if(typeof q!="function")throw new R;if(me(A),_)_e(m,A,$,_,q);else{var h=He(A)||m.destroyed;!h&&!A.corked&&!A.bufferProcessing&&A.bufferedRequest&&ke(m,A),$?process.nextTick(Te,m,A,h,q):Te(m,A,h,q)}}function Te(m,_,A,$){A||$e(m,_),_.pendingcb--,$(),ve(m,_)}function $e(m,_){_.length===0&&_.needDrain&&(_.needDrain=!1,m.emit("drain"))}function ke(m,_){_.bufferProcessing=!0;var A=_.bufferedRequest;if(m._writev&&A&&A.next){var $=_.bufferedRequestCount,q=new Array($),h=_.corkedRequestsFree;h.entry=A;for(var d=0,I=!0;A;)q[d]=A,A.isBuf||(I=!1),A=A.next,d+=1;q.allBuffers=I,ae(m,_,!0,_.length,q,"",h.finish),_.pendingcb++,_.lastBufferedRequest=null,h.next?(_.corkedRequestsFree=h.next,h.next=null):_.corkedRequestsFree=new e(_),_.bufferedRequestCount=0}else{for(;A;){var M=A.chunk,Q=A.encoding,W=A.callback,z=_.objectMode?1:M.length;if(ae(m,_,!1,z,M,Q,W),A=A.next,_.bufferedRequestCount--,_.writing)break}A===null&&(_.lastBufferedRequest=null)}_.bufferedRequest=A,_.bufferProcessing=!1}D.prototype._write=function(m,_,A){A(new T("_write()"))},D.prototype._writev=null,D.prototype.end=function(m,_,A){var $=this._writableState;return typeof m=="function"?(A=m,m=null,_=null):typeof _=="function"&&(A=_,_=null),m!=null&&this.write(m,_),$.corked&&($.corked=1,this.uncork()),$.ending||je(this,$,A),this},Object.defineProperty(D.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}});function He(m){return m.ending&&m.length===0&&m.bufferedRequest===null&&!m.finished&&!m.writing}function Y(m,_){m._final(function(A){_.pendingcb--,A&&N(m,A),_.prefinished=!0,m.emit("prefinish"),ve(m,_)})}function ie(m,_){!_.prefinished&&!_.finalCalled&&(typeof m._final=="function"&&!_.destroyed?(_.pendingcb++,_.finalCalled=!0,process.nextTick(Y,m,_)):(_.prefinished=!0,m.emit("prefinish")))}function ve(m,_){var A=He(_);if(A&&(ie(m,_),_.pendingcb===0&&(_.finished=!0,m.emit("finish"),_.autoDestroy))){var $=m._readableState;(!$||$.autoDestroy&&$.endEmitted)&&m.destroy()}return A}function je(m,_,A){_.ending=!0,ve(m,_),A&&(_.finished?process.nextTick(A):m.once("finish",A)),_.ended=!0,m.writable=!1}function Ne(m,_,A){var $=m.entry;for(m.entry=null;$;){var q=$.callback;_.pendingcb--,q(A),$=$.next}_.corkedRequestsFree.next=m}return Object.defineProperty(D.prototype,"destroyed",{enumerable:!1,get:function(){return this._writableState===void 0?!1:this._writableState.destroyed},set:function(_){this._writableState&&(this._writableState.destroyed=_)}}),D.prototype.destroy=p.destroy,D.prototype._undestroy=p.undestroy,D.prototype._destroy=function(m,_){_(m)},pr}var br,pn;function dt(){if(pn)return br;pn=1;var e=Object.keys||function(y){var g=[];for(var w in y)g.push(w);return g};br=c;var t=gi(),r=bi();pe(c,t);for(var n=e(r.prototype),o=0;o<n.length;o++){var s=n[o];c.prototype[s]||(c.prototype[s]=r.prototype[s])}function c(y){if(!(this instanceof c))return new c(y);t.call(this,y),r.call(this,y),this.allowHalfOpen=!0,y&&(y.readable===!1&&(this.readable=!1),y.writable===!1&&(this.writable=!1),y.allowHalfOpen===!1&&(this.allowHalfOpen=!1,this.once("end",u)))}Object.defineProperty(c.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),Object.defineProperty(c.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(c.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}});function u(){this._writableState.ended||process.nextTick(p,this)}function p(y){y.end()}return Object.defineProperty(c.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState===void 0||this._writableState===void 0?!1:this._readableState.destroyed&&this._writableState.destroyed},set:function(g){this._readableState===void 0||this._writableState===void 0||(this._readableState.destroyed=g,this._writableState.destroyed=g)}}),br}var Gt={},Kr=we.Buffer,bn=Kr.isEncoding||function(e){switch(e=""+e,e&&e.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};function Io(e){if(!e)return"utf8";for(var t;;)switch(e){case"utf8":case"utf-8":return"utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return"utf16le";case"latin1":case"binary":return"latin1";case"base64":case"ascii":case"hex":return e;default:if(t)return;e=(""+e).toLowerCase(),t=!0}}function To(e){var t=Io(e);if(typeof t!="string"&&(Kr.isEncoding===bn||!bn(e)))throw new Error("Unknown encoding: "+e);return t||e}Gt.StringDecoder=kt;function kt(e){this.encoding=To(e);var t;switch(this.encoding){case"utf16le":this.text=No,this.end=Fo,t=4;break;case"utf8":this.fillLast=Co,t=4;break;case"base64":this.text=Lo,this.end=Mo,t=3;break;default:this.write=Uo,this.end=Do;return}this.lastNeed=0,this.lastTotal=0,this.lastChar=Kr.allocUnsafe(t)}kt.prototype.write=function(e){if(e.length===0)return"";var t,r;if(this.lastNeed){if(t=this.fillLast(e),t===void 0)return"";r=this.lastNeed,this.lastNeed=0}else r=0;return r<e.length?t?t+this.text(e,r):this.text(e,r):t||""};kt.prototype.end=Oo;kt.prototype.text=Po;kt.prototype.fillLast=function(e){if(this.lastNeed<=e.length)return e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,e.length),this.lastNeed-=e.length};function yr(e){return e<=127?0:e>>5===6?2:e>>4===14?3:e>>3===30?4:e>>6===2?-1:-2}function ko(e,t,r){var n=t.length-1;if(n<r)return 0;var o=yr(t[n]);return o>=0?(o>0&&(e.lastNeed=o-1),o):--n<r||o===-2?0:(o=yr(t[n]),o>=0?(o>0&&(e.lastNeed=o-2),o):--n<r||o===-2?0:(o=yr(t[n]),o>=0?(o>0&&(o===2?o=0:e.lastNeed=o-3),o):0))}function Ao(e,t,r){if((t[0]&192)!==128)return e.lastNeed=0,"�";if(e.lastNeed>1&&t.length>1){if((t[1]&192)!==128)return e.lastNeed=1,"�";if(e.lastNeed>2&&t.length>2&&(t[2]&192)!==128)return e.lastNeed=2,"�"}}function Co(e){var t=this.lastTotal-this.lastNeed,r=Ao(this,e);if(r!==void 0)return r;if(this.lastNeed<=e.length)return e.copy(this.lastChar,t,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);e.copy(this.lastChar,t,0,e.length),this.lastNeed-=e.length}function Po(e,t){var r=ko(this,e,t);if(!this.lastNeed)return e.toString("utf8",t);this.lastTotal=r;var n=e.length-(r-this.lastNeed);return e.copy(this.lastChar,0,n),e.toString("utf8",t,n)}function Oo(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+"�":t}function No(e,t){if((e.length-t)%2===0){var r=e.toString("utf16le",t);if(r){var n=r.charCodeAt(r.length-1);if(n>=55296&&n<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1],r.slice(0,-1)}return r}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=e[e.length-1],e.toString("utf16le",t,e.length-1)}function Fo(e){var t=e&&e.length?this.write(e):"";if(this.lastNeed){var r=this.lastTotal-this.lastNeed;return t+this.lastChar.toString("utf16le",0,r)}return t}function Lo(e,t){var r=(e.length-t)%3;return r===0?e.toString("base64",t):(this.lastNeed=3-r,this.lastTotal=3,r===1?this.lastChar[0]=e[e.length-1]:(this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1]),e.toString("base64",t,e.length-r))}function Mo(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+this.lastChar.toString("base64",0,3-this.lastNeed):t}function Uo(e){return e.toString(this.encoding)}function Do(e){return e&&e.length?this.write(e):""}var yn=et.codes.ERR_STREAM_PREMATURE_CLOSE;function $o(e){var t=!1;return function(){if(!t){t=!0;for(var r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];e.apply(this,n)}}}function Ho(){}function jo(e){return e.setHeader&&typeof e.abort=="function"}function yi(e,t,r){if(typeof t=="function")return yi(e,null,t);t||(t={}),r=$o(r||Ho);var n=t.readable||t.readable!==!1&&e.readable,o=t.writable||t.writable!==!1&&e.writable,s=function(){e.writable||u()},c=e._writableState&&e._writableState.finished,u=function(){o=!1,c=!0,n||r.call(e)},p=e._readableState&&e._readableState.endEmitted,y=function(){n=!1,p=!0,o||r.call(e)},g=function(R){r.call(e,R)},w=function(){var R;if(n&&!p)return(!e._readableState||!e._readableState.ended)&&(R=new yn),r.call(e,R);if(o&&!c)return(!e._writableState||!e._writableState.ended)&&(R=new yn),r.call(e,R)},x=function(){e.req.on("finish",u)};return jo(e)?(e.on("complete",u),e.on("abort",w),e.req?x():e.on("request",x)):o&&!e._writableState&&(e.on("end",s),e.on("close",s)),e.on("end",y),e.on("finish",u),t.error!==!1&&e.on("error",g),e.on("close",w),function(){e.removeListener("complete",u),e.removeListener("abort",w),e.removeListener("request",x),e.req&&e.req.removeListener("finish",u),e.removeListener("end",s),e.removeListener("close",s),e.removeListener("finish",u),e.removeListener("end",y),e.removeListener("error",g),e.removeListener("close",w)}}var Vr=yi,gr,gn;function qo(){if(gn)return gr;gn=1;var e;function t(F,N,L){return N=r(N),N in F?Object.defineProperty(F,N,{value:L,enumerable:!0,configurable:!0,writable:!0}):F[N]=L,F}function r(F){var N=n(F,"string");return typeof N=="symbol"?N:String(N)}function n(F,N){if(typeof F!="object"||F===null)return F;var L=F[Symbol.toPrimitive];if(L!==void 0){var S=L.call(F,N||"default");if(typeof S!="object")return S;throw new TypeError("@@toPrimitive must return a primitive value.")}return(N==="string"?String:Number)(F)}var o=Vr,s=Symbol("lastResolve"),c=Symbol("lastReject"),u=Symbol("error"),p=Symbol("ended"),y=Symbol("lastPromise"),g=Symbol("handlePromise"),w=Symbol("stream");function x(F,N){return{value:F,done:N}}function T(F){var N=F[s];if(N!==null){var L=F[w].read();L!==null&&(F[y]=null,F[s]=null,F[c]=null,N(x(L,!1)))}}function R(F){process.nextTick(T,F)}function C(F,N){return function(L,S){F.then(function(){if(N[p]){L(x(void 0,!0));return}N[g](L,S)},S)}}var E=Object.getPrototypeOf(function(){}),k=Object.setPrototypeOf((e={get stream(){return this[w]},next:function(){var N=this,L=this[u];if(L!==null)return Promise.reject(L);if(this[p])return Promise.resolve(x(void 0,!0));if(this[w].destroyed)return new Promise(function(U,ee){process.nextTick(function(){N[u]?ee(N[u]):U(x(void 0,!0))})});var S=this[y],j;if(S)j=new Promise(C(S,this));else{var D=this[w].read();if(D!==null)return Promise.resolve(x(D,!1));j=new Promise(this[g])}return this[y]=j,j}},t(e,Symbol.asyncIterator,function(){return this}),t(e,"return",function(){var N=this;return new Promise(function(L,S){N[w].destroy(null,function(j){if(j){S(j);return}L(x(void 0,!0))})})}),e),E),O=function(N){var L,S=Object.create(k,(L={},t(L,w,{value:N,writable:!0}),t(L,s,{value:null,writable:!0}),t(L,c,{value:null,writable:!0}),t(L,u,{value:null,writable:!0}),t(L,p,{value:N._readableState.endEmitted,writable:!0}),t(L,g,{value:function(D,U){var ee=S[w].read();ee?(S[y]=null,S[s]=null,S[c]=null,D(x(ee,!1))):(S[s]=D,S[c]=U)},writable:!0}),L));return S[y]=null,o(N,function(j){if(j&&j.code!=="ERR_STREAM_PREMATURE_CLOSE"){var D=S[c];D!==null&&(S[y]=null,S[s]=null,S[c]=null,D(j)),S[u]=j;return}var U=S[s];U!==null&&(S[y]=null,S[s]=null,S[c]=null,U(x(void 0,!0))),S[p]=!0}),N.on("readable",R.bind(null,S)),S};return gr=O,gr}var _r,_n;function Wo(){return _n||(_n=1,_r=function(){throw new Error("Readable.from is not available in the browser")}),_r}var mr,mn;function gi(){if(mn)return mr;mn=1,mr=U;var e;U.ReadableState=D,ci.EventEmitter;var t=function(d,I){return d.listeners(I).length},r=li,n=pt.Buffer,o=(typeof ze<"u"?ze:typeof window<"u"?window:typeof self<"u"?self:{}).Uint8Array||function(){};function s(h){return n.from(h)}function c(h){return n.isBuffer(h)||h instanceof o}var u=zr,p;u&&u.debuglog?p=u.debuglog("stream"):p=function(){};var y=po(),g=hi,w=pi,x=w.getHighWaterMark,T=et.codes,R=T.ERR_INVALID_ARG_TYPE,C=T.ERR_STREAM_PUSH_AFTER_EOF,E=T.ERR_METHOD_NOT_IMPLEMENTED,k=T.ERR_STREAM_UNSHIFT_AFTER_END_EVENT,O,F,N;pe(U,r);var L=g.errorOrDestroy,S=["error","close","destroy","pause","resume"];function j(h,d,I){if(typeof h.prependListener=="function")return h.prependListener(d,I);!h._events||!h._events[d]?h.on(d,I):Array.isArray(h._events[d])?h._events[d].unshift(I):h._events[d]=[I,h._events[d]]}function D(h,d,I){e=e||dt(),h=h||{},typeof I!="boolean"&&(I=d instanceof e),this.objectMode=!!h.objectMode,I&&(this.objectMode=this.objectMode||!!h.readableObjectMode),this.highWaterMark=x(this,h,"readableHighWaterMark",I),this.buffer=new y,this.length=0,this.pipes=null,this.pipesCount=0,this.flowing=null,this.ended=!1,this.endEmitted=!1,this.reading=!1,this.sync=!0,this.needReadable=!1,this.emittedReadable=!1,this.readableListening=!1,this.resumeScheduled=!1,this.paused=!0,this.emitClose=h.emitClose!==!1,this.autoDestroy=!!h.autoDestroy,this.destroyed=!1,this.defaultEncoding=h.defaultEncoding||"utf8",this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,h.encoding&&(O||(O=Gt.StringDecoder),this.decoder=new O(h.encoding),this.encoding=h.encoding)}function U(h){if(e=e||dt(),!(this instanceof U))return new U(h);var d=this instanceof e;this._readableState=new D(h,this,d),this.readable=!0,h&&(typeof h.read=="function"&&(this._read=h.read),typeof h.destroy=="function"&&(this._destroy=h.destroy)),r.call(this)}Object.defineProperty(U.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState===void 0?!1:this._readableState.destroyed},set:function(d){this._readableState&&(this._readableState.destroyed=d)}}),U.prototype.destroy=g.destroy,U.prototype._undestroy=g.undestroy,U.prototype._destroy=function(h,d){d(h)},U.prototype.push=function(h,d){var I=this._readableState,M;return I.objectMode?M=!0:typeof h=="string"&&(d=d||I.defaultEncoding,d!==I.encoding&&(h=n.from(h,d),d=""),M=!0),ee(this,h,d,!1,M)},U.prototype.unshift=function(h){return ee(this,h,null,!0,!1)};function ee(h,d,I,M,Q){p("readableAddChunk",d);var W=h._readableState;if(d===null)W.reading=!1,Ve(h,W);else{var z;if(Q||(z=De(W,d)),z)L(h,z);else if(W.objectMode||d&&d.length>0)if(typeof d!="string"&&!W.objectMode&&Object.getPrototypeOf(d)!==n.prototype&&(d=s(d)),M)W.endEmitted?L(h,new k):Ie(h,W,d,!0);else if(W.ended)L(h,new C);else{if(W.destroyed)return!1;W.reading=!1,W.decoder&&!I?(d=W.decoder.write(d),W.objectMode||d.length!==0?Ie(h,W,d,!1):ke(h,W)):Ie(h,W,d,!1)}else M||(W.reading=!1,ke(h,W))}return!W.ended&&(W.length<W.highWaterMark||W.length===0)}function Ie(h,d,I,M){d.flowing&&d.length===0&&!d.sync?(d.awaitDrain=0,h.emit("data",I)):(d.length+=d.objectMode?1:I.length,M?d.buffer.unshift(I):d.buffer.push(I),d.needReadable&&Te(h)),ke(h,d)}function De(h,d){var I;return!c(d)&&typeof d!="string"&&d!==void 0&&!h.objectMode&&(I=new R("chunk",["string","Buffer","Uint8Array"],d)),I}U.prototype.isPaused=function(){return this._readableState.flowing===!1},U.prototype.setEncoding=function(h){O||(O=Gt.StringDecoder);var d=new O(h);this._readableState.decoder=d,this._readableState.encoding=this._readableState.decoder.encoding;for(var I=this._readableState.buffer.head,M="";I!==null;)M+=d.write(I.data),I=I.next;return this._readableState.buffer.clear(),M!==""&&this._readableState.buffer.push(M),this._readableState.length=M.length,this};var ae=1073741824;function _e(h){return h>=ae?h=ae:(h--,h|=h>>>1,h|=h>>>2,h|=h>>>4,h|=h>>>8,h|=h>>>16,h++),h}function me(h,d){return h<=0||d.length===0&&d.ended?0:d.objectMode?1:h!==h?d.flowing&&d.length?d.buffer.head.data.length:d.length:(h>d.highWaterMark&&(d.highWaterMark=_e(h)),h<=d.length?h:d.ended?d.length:(d.needReadable=!0,0))}U.prototype.read=function(h){p("read",h),h=parseInt(h,10);var d=this._readableState,I=h;if(h!==0&&(d.emittedReadable=!1),h===0&&d.needReadable&&((d.highWaterMark!==0?d.length>=d.highWaterMark:d.length>0)||d.ended))return p("read: emitReadable",d.length,d.ended),d.length===0&&d.ended?A(this):Te(this),null;if(h=me(h,d),h===0&&d.ended)return d.length===0&&A(this),null;var M=d.needReadable;p("need readable",M),(d.length===0||d.length-h<d.highWaterMark)&&(M=!0,p("length less than watermark",M)),d.ended||d.reading?(M=!1,p("reading or ended",M)):M&&(p("do read"),d.reading=!0,d.sync=!0,d.length===0&&(d.needReadable=!0),this._read(d.highWaterMark),d.sync=!1,d.reading||(h=me(I,d)));var Q;return h>0?Q=_(h,d):Q=null,Q===null?(d.needReadable=d.length<=d.highWaterMark,h=0):(d.length-=h,d.awaitDrain=0),d.length===0&&(d.ended||(d.needReadable=!0),I!==h&&d.ended&&A(this)),Q!==null&&this.emit("data",Q),Q};function Ve(h,d){if(p("onEofChunk"),!d.ended){if(d.decoder){var I=d.decoder.end();I&&I.length&&(d.buffer.push(I),d.length+=d.objectMode?1:I.length)}d.ended=!0,d.sync?Te(h):(d.needReadable=!1,d.emittedReadable||(d.emittedReadable=!0,$e(h)))}}function Te(h){var d=h._readableState;p("emitReadable",d.needReadable,d.emittedReadable),d.needReadable=!1,d.emittedReadable||(p("emitReadable",d.flowing),d.emittedReadable=!0,process.nextTick($e,h))}function $e(h){var d=h._readableState;p("emitReadable_",d.destroyed,d.length,d.ended),!d.destroyed&&(d.length||d.ended)&&(h.emit("readable"),d.emittedReadable=!1),d.needReadable=!d.flowing&&!d.ended&&d.length<=d.highWaterMark,m(h)}function ke(h,d){d.readingMore||(d.readingMore=!0,process.nextTick(He,h,d))}function He(h,d){for(;!d.reading&&!d.ended&&(d.length<d.highWaterMark||d.flowing&&d.length===0);){var I=d.length;if(p("maybeReadMore read 0"),h.read(0),I===d.length)break}d.readingMore=!1}U.prototype._read=function(h){L(this,new E("_read()"))},U.prototype.pipe=function(h,d){var I=this,M=this._readableState;switch(M.pipesCount){case 0:M.pipes=h;break;case 1:M.pipes=[M.pipes,h];break;default:M.pipes.push(h);break}M.pipesCount+=1,p("pipe count=%d opts=%j",M.pipesCount,d);var Q=(!d||d.end!==!1)&&h!==process.stdout&&h!==process.stderr,W=Q?qe:Ye;M.endEmitted?process.nextTick(W):I.once("end",W),h.on("unpipe",z);function z(f,i){p("onunpipe"),f===I&&i&&i.hasUnpiped===!1&&(i.hasUnpiped=!0,nt())}function qe(){p("onend"),h.end()}var rt=Y(I);h.on("drain",rt);var yt=!1;function nt(){p("cleanup"),h.removeListener("close",gt),h.removeListener("finish",Ee),h.removeListener("drain",rt),h.removeListener("error",Je),h.removeListener("unpipe",z),I.removeListener("end",qe),I.removeListener("end",Ye),I.removeListener("data",xe),yt=!0,M.awaitDrain&&(!h._writableState||h._writableState.needDrain)&&rt()}I.on("data",xe);function xe(f){p("ondata");var i=h.write(f);p("dest.write",i),i===!1&&((M.pipesCount===1&&M.pipes===h||M.pipesCount>1&&q(M.pipes,h)!==-1)&&!yt&&(p("false write response, pause",M.awaitDrain),M.awaitDrain++),I.pause())}function Je(f){p("onerror",f),Ye(),h.removeListener("error",Je),t(h,"error")===0&&L(h,f)}j(h,"error",Je);function gt(){h.removeListener("finish",Ee),Ye()}h.once("close",gt);function Ee(){p("onfinish"),h.removeListener("close",gt),Ye()}h.once("finish",Ee);function Ye(){p("unpipe"),I.unpipe(h)}return h.emit("pipe",I),M.flowing||(p("pipe resume"),I.resume()),h};function Y(h){return function(){var I=h._readableState;p("pipeOnDrain",I.awaitDrain),I.awaitDrain&&I.awaitDrain--,I.awaitDrain===0&&t(h,"data")&&(I.flowing=!0,m(h))}}U.prototype.unpipe=function(h){var d=this._readableState,I={hasUnpiped:!1};if(d.pipesCount===0)return this;if(d.pipesCount===1)return h&&h!==d.pipes?this:(h||(h=d.pipes),d.pipes=null,d.pipesCount=0,d.flowing=!1,h&&h.emit("unpipe",this,I),this);if(!h){var M=d.pipes,Q=d.pipesCount;d.pipes=null,d.pipesCount=0,d.flowing=!1;for(var W=0;W<Q;W++)M[W].emit("unpipe",this,{hasUnpiped:!1});return this}var z=q(d.pipes,h);return z===-1?this:(d.pipes.splice(z,1),d.pipesCount-=1,d.pipesCount===1&&(d.pipes=d.pipes[0]),h.emit("unpipe",this,I),this)},U.prototype.on=function(h,d){var I=r.prototype.on.call(this,h,d),M=this._readableState;return h==="data"?(M.readableListening=this.listenerCount("readable")>0,M.flowing!==!1&&this.resume()):h==="readable"&&!M.endEmitted&&!M.readableListening&&(M.readableListening=M.needReadable=!0,M.flowing=!1,M.emittedReadable=!1,p("on readable",M.length,M.reading),M.length?Te(this):M.reading||process.nextTick(ve,this)),I},U.prototype.addListener=U.prototype.on,U.prototype.removeListener=function(h,d){var I=r.prototype.removeListener.call(this,h,d);return h==="readable"&&process.nextTick(ie,this),I},U.prototype.removeAllListeners=function(h){var d=r.prototype.removeAllListeners.apply(this,arguments);return(h==="readable"||h===void 0)&&process.nextTick(ie,this),d};function ie(h){var d=h._readableState;d.readableListening=h.listenerCount("readable")>0,d.resumeScheduled&&!d.paused?d.flowing=!0:h.listenerCount("data")>0&&h.resume()}function ve(h){p("readable nexttick read 0"),h.read(0)}U.prototype.resume=function(){var h=this._readableState;return h.flowing||(p("resume"),h.flowing=!h.readableListening,je(this,h)),h.paused=!1,this};function je(h,d){d.resumeScheduled||(d.resumeScheduled=!0,process.nextTick(Ne,h,d))}function Ne(h,d){p("resume",d.reading),d.reading||h.read(0),d.resumeScheduled=!1,h.emit("resume"),m(h),d.flowing&&!d.reading&&h.read(0)}U.prototype.pause=function(){return p("call pause flowing=%j",this._readableState.flowing),this._readableState.flowing!==!1&&(p("pause"),this._readableState.flowing=!1,this.emit("pause")),this._readableState.paused=!0,this};function m(h){var d=h._readableState;for(p("flow",d.flowing);d.flowing&&h.read()!==null;);}U.prototype.wrap=function(h){var d=this,I=this._readableState,M=!1;h.on("end",function(){if(p("wrapped end"),I.decoder&&!I.ended){var z=I.decoder.end();z&&z.length&&d.push(z)}d.push(null)}),h.on("data",function(z){if(p("wrapped data"),I.decoder&&(z=I.decoder.write(z)),!(I.objectMode&&z==null)&&!(!I.objectMode&&(!z||!z.length))){var qe=d.push(z);qe||(M=!0,h.pause())}});for(var Q in h)this[Q]===void 0&&typeof h[Q]=="function"&&(this[Q]=function(qe){return function(){return h[qe].apply(h,arguments)}}(Q));for(var W=0;W<S.length;W++)h.on(S[W],this.emit.bind(this,S[W]));return this._read=function(z){p("wrapped _read",z),M&&(M=!1,h.resume())},this},typeof Symbol=="function"&&(U.prototype[Symbol.asyncIterator]=function(){return F===void 0&&(F=qo()),F(this)}),Object.defineProperty(U.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}}),Object.defineProperty(U.prototype,"readableBuffer",{enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}}),Object.defineProperty(U.prototype,"readableFlowing",{enumerable:!1,get:function(){return this._readableState.flowing},set:function(d){this._readableState&&(this._readableState.flowing=d)}}),U._fromList=_,Object.defineProperty(U.prototype,"readableLength",{enumerable:!1,get:function(){return this._readableState.length}});function _(h,d){if(d.length===0)return null;var I;return d.objectMode?I=d.buffer.shift():!h||h>=d.length?(d.decoder?I=d.buffer.join(""):d.buffer.length===1?I=d.buffer.first():I=d.buffer.concat(d.length),d.buffer.clear()):I=d.buffer.consume(h,d.decoder),I}function A(h){var d=h._readableState;p("endReadable",d.endEmitted),d.endEmitted||(d.ended=!0,process.nextTick($,d,h))}function $(h,d){if(p("endReadableNT",h.endEmitted,h.length),!h.endEmitted&&h.length===0&&(h.endEmitted=!0,d.readable=!1,d.emit("end"),h.autoDestroy)){var I=d._writableState;(!I||I.autoDestroy&&I.finished)&&d.destroy()}}typeof Symbol=="function"&&(U.from=function(h,d){return N===void 0&&(N=Wo()),N(U,h,d)});function q(h,d){for(var I=0,M=h.length;I<M;I++)if(h[I]===d)return I;return-1}return mr}var _i=Ue,Qt=et.codes,Go=Qt.ERR_METHOD_NOT_IMPLEMENTED,zo=Qt.ERR_MULTIPLE_CALLBACK,Ko=Qt.ERR_TRANSFORM_ALREADY_TRANSFORMING,Vo=Qt.ERR_TRANSFORM_WITH_LENGTH_0,Xt=dt();pe(Ue,Xt);function Jo(e,t){var r=this._transformState;r.transforming=!1;var n=r.writecb;if(n===null)return this.emit("error",new zo);r.writechunk=null,r.writecb=null,t!=null&&this.push(t),n(e);var o=this._readableState;o.reading=!1,(o.needReadable||o.length<o.highWaterMark)&&this._read(o.highWaterMark)}function Ue(e){if(!(this instanceof Ue))return new Ue(e);Xt.call(this,e),this._transformState={afterTransform:Jo.bind(this),needTransform:!1,transforming:!1,writecb:null,writechunk:null,writeencoding:null},this._readableState.needReadable=!0,this._readableState.sync=!1,e&&(typeof e.transform=="function"&&(this._transform=e.transform),typeof e.flush=="function"&&(this._flush=e.flush)),this.on("prefinish",Yo)}function Yo(){var e=this;typeof this._flush=="function"&&!this._readableState.destroyed?this._flush(function(t,r){wn(e,t,r)}):wn(this,null,null)}Ue.prototype.push=function(e,t){return this._transformState.needTransform=!1,Xt.prototype.push.call(this,e,t)};Ue.prototype._transform=function(e,t,r){r(new Go("_transform()"))};Ue.prototype._write=function(e,t,r){var n=this._transformState;if(n.writecb=r,n.writechunk=e,n.writeencoding=t,!n.transforming){var o=this._readableState;(n.needTransform||o.needReadable||o.length<o.highWaterMark)&&this._read(o.highWaterMark)}};Ue.prototype._read=function(e){var t=this._transformState;t.writechunk!==null&&!t.transforming?(t.transforming=!0,this._transform(t.writechunk,t.writeencoding,t.afterTransform)):t.needTransform=!0};Ue.prototype._destroy=function(e,t){Xt.prototype._destroy.call(this,e,function(r){t(r)})};function wn(e,t,r){if(t)return e.emit("error",t);if(r!=null&&e.push(r),e._writableState.length)throw new Vo;if(e._transformState.transforming)throw new Ko;return e.push(null)}var Qo=It,mi=_i;pe(It,mi);function It(e){if(!(this instanceof It))return new It(e);mi.call(this,e)}It.prototype._transform=function(e,t,r){r(null,e)};var wr;function Xo(e){var t=!1;return function(){t||(t=!0,e.apply(void 0,arguments))}}var wi=et.codes,Zo=wi.ERR_MISSING_ARGS,es=wi.ERR_STREAM_DESTROYED;function vn(e){if(e)throw e}function ts(e){return e.setHeader&&typeof e.abort=="function"}function rs(e,t,r,n){n=Xo(n);var o=!1;e.on("close",function(){o=!0}),wr===void 0&&(wr=Vr),wr(e,{readable:t,writable:r},function(c){if(c)return n(c);o=!0,n()});var s=!1;return function(c){if(!o&&!s){if(s=!0,ts(e))return e.abort();if(typeof e.destroy=="function")return e.destroy();n(c||new es("pipe"))}}}function xn(e){e()}function ns(e,t){return e.pipe(t)}function is(e){return!e.length||typeof e[e.length-1]!="function"?vn:e.pop()}function as(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];var n=is(t);if(Array.isArray(t[0])&&(t=t[0]),t.length<2)throw new Zo("streams");var o,s=t.map(function(c,u){var p=u<t.length-1,y=u>0;return rs(c,p,y,function(g){o||(o=g),g&&s.forEach(xn),!p&&(s.forEach(xn),n(o))})});return t.reduce(ns)}var os=as;(function(e,t){t=e.exports=gi(),t.Stream=t,t.Readable=t,t.Writable=bi(),t.Duplex=dt(),t.Transform=_i,t.PassThrough=Qo,t.finished=Vr,t.pipeline=os})(Fr,Fr.exports);var ss=Fr.exports,zt=we.Buffer,vi=ss.Transform,fs=pe;function us(e,t){if(!zt.isBuffer(e)&&typeof e!="string")throw new TypeError(t+" must be a string or a buffer")}function Ke(e){vi.call(this),this._block=zt.allocUnsafe(e),this._blockSize=e,this._blockOffset=0,this._length=[0,0,0,0],this._finalized=!1}fs(Ke,vi);Ke.prototype._transform=function(e,t,r){var n=null;try{this.update(e,t)}catch(o){n=o}r(n)};Ke.prototype._flush=function(e){var t=null;try{this.push(this.digest())}catch(r){t=r}e(t)};Ke.prototype.update=function(e,t){if(us(e,"Data"),this._finalized)throw new Error("Digest already called");zt.isBuffer(e)||(e=zt.from(e,t));for(var r=this._block,n=0;this._blockOffset+e.length-n>=this._blockSize;){for(var o=this._blockOffset;o<this._blockSize;)r[o++]=e[n++];this._update(),this._blockOffset=0}for(;n<e.length;)r[this._blockOffset++]=e[n++];for(var s=0,c=e.length*8;c>0;++s)this._length[s]+=c,c=this._length[s]/4294967296|0,c>0&&(this._length[s]-=4294967296*c);return this};Ke.prototype._update=function(){throw new Error("_update is not implemented")};Ke.prototype.digest=function(e){if(this._finalized)throw new Error("Digest already called");this._finalized=!0;var t=this._digest();e!==void 0&&(t=t.toString(e)),this._block.fill(0),this._blockOffset=0;for(var r=0;r<4;++r)this._length[r]=0;return t};Ke.prototype._digest=function(){throw new Error("_digest is not implemented")};var xi=Ke,cs=pe,Ei=xi,ls=we.Buffer,hs=new Array(16);function Zt(){Ei.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878}cs(Zt,Ei);Zt.prototype._update=function(){for(var e=hs,t=0;t<16;++t)e[t]=this._block.readInt32LE(t*4);var r=this._a,n=this._b,o=this._c,s=this._d;r=ue(r,n,o,s,e[0],3614090360,7),s=ue(s,r,n,o,e[1],3905402710,12),o=ue(o,s,r,n,e[2],606105819,17),n=ue(n,o,s,r,e[3],3250441966,22),r=ue(r,n,o,s,e[4],4118548399,7),s=ue(s,r,n,o,e[5],1200080426,12),o=ue(o,s,r,n,e[6],2821735955,17),n=ue(n,o,s,r,e[7],4249261313,22),r=ue(r,n,o,s,e[8],1770035416,7),s=ue(s,r,n,o,e[9],2336552879,12),o=ue(o,s,r,n,e[10],4294925233,17),n=ue(n,o,s,r,e[11],2304563134,22),r=ue(r,n,o,s,e[12],1804603682,7),s=ue(s,r,n,o,e[13],4254626195,12),o=ue(o,s,r,n,e[14],2792965006,17),n=ue(n,o,s,r,e[15],1236535329,22),r=ce(r,n,o,s,e[1],4129170786,5),s=ce(s,r,n,o,e[6],3225465664,9),o=ce(o,s,r,n,e[11],643717713,14),n=ce(n,o,s,r,e[0],3921069994,20),r=ce(r,n,o,s,e[5],3593408605,5),s=ce(s,r,n,o,e[10],38016083,9),o=ce(o,s,r,n,e[15],3634488961,14),n=ce(n,o,s,r,e[4],3889429448,20),r=ce(r,n,o,s,e[9],568446438,5),s=ce(s,r,n,o,e[14],3275163606,9),o=ce(o,s,r,n,e[3],4107603335,14),n=ce(n,o,s,r,e[8],1163531501,20),r=ce(r,n,o,s,e[13],2850285829,5),s=ce(s,r,n,o,e[2],4243563512,9),o=ce(o,s,r,n,e[7],1735328473,14),n=ce(n,o,s,r,e[12],2368359562,20),r=le(r,n,o,s,e[5],4294588738,4),s=le(s,r,n,o,e[8],2272392833,11),o=le(o,s,r,n,e[11],1839030562,16),n=le(n,o,s,r,e[14],4259657740,23),r=le(r,n,o,s,e[1],2763975236,4),s=le(s,r,n,o,e[4],1272893353,11),o=le(o,s,r,n,e[7],4139469664,16),n=le(n,o,s,r,e[10],3200236656,23),r=le(r,n,o,s,e[13],681279174,4),s=le(s,r,n,o,e[0],3936430074,11),o=le(o,s,r,n,e[3],3572445317,16),n=le(n,o,s,r,e[6],76029189,23),r=le(r,n,o,s,e[9],3654602809,4),s=le(s,r,n,o,e[12],3873151461,11),o=le(o,s,r,n,e[15],530742520,16),n=le(n,o,s,r,e[2],3299628645,23),r=he(r,n,o,s,e[0],4096336452,6),s=he(s,r,n,o,e[7],1126891415,10),o=he(o,s,r,n,e[14],2878612391,15),n=he(n,o,s,r,e[5],4237533241,21),r=he(r,n,o,s,e[12],1700485571,6),s=he(s,r,n,o,e[3],2399980690,10),o=he(o,s,r,n,e[10],4293915773,15),n=he(n,o,s,r,e[1],2240044497,21),r=he(r,n,o,s,e[8],1873313359,6),s=he(s,r,n,o,e[15],4264355552,10),o=he(o,s,r,n,e[6],2734768916,15),n=he(n,o,s,r,e[13],1309151649,21),r=he(r,n,o,s,e[4],4149444226,6),s=he(s,r,n,o,e[11],3174756917,10),o=he(o,s,r,n,e[2],718787259,15),n=he(n,o,s,r,e[9],3951481745,21),this._a=this._a+r|0,this._b=this._b+n|0,this._c=this._c+o|0,this._d=this._d+s|0};Zt.prototype._digest=function(){this._block[this._blockOffset++]=128,this._blockOffset>56&&(this._block.fill(0,this._blockOffset,64),this._update(),this._blockOffset=0),this._block.fill(0,this._blockOffset,56),this._block.writeUInt32LE(this._length[0],56),this._block.writeUInt32LE(this._length[1],60),this._update();var e=ls.allocUnsafe(16);return e.writeInt32LE(this._a,0),e.writeInt32LE(this._b,4),e.writeInt32LE(this._c,8),e.writeInt32LE(this._d,12),e};function er(e,t){return e<<t|e>>>32-t}function ue(e,t,r,n,o,s,c){return er(e+(t&r|~t&n)+o+s|0,c)+t|0}function ce(e,t,r,n,o,s,c){return er(e+(t&n|r&~n)+o+s|0,c)+t|0}function le(e,t,r,n,o,s,c){return er(e+(t^r^n)+o+s|0,c)+t|0}function he(e,t,r,n,o,s,c){return er(e+(r^(t|~n))+o+s|0,c)+t|0}var ds=Zt,vr=pt.Buffer,ps=pe,Bi=xi,bs=new Array(16),mt=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13],wt=[5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11],vt=[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6],xt=[8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11],Et=[0,1518500249,1859775393,2400959708,2840853838],Bt=[1352829926,1548603684,1836072691,2053994217,0];function tr(){Bi.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520}ps(tr,Bi);tr.prototype._update=function(){for(var e=bs,t=0;t<16;++t)e[t]=this._block.readInt32LE(t*4);for(var r=this._a|0,n=this._b|0,o=this._c|0,s=this._d|0,c=this._e|0,u=this._a|0,p=this._b|0,y=this._c|0,g=this._d|0,w=this._e|0,x=0;x<80;x+=1){var T,R;x<16?(T=En(r,n,o,s,c,e[mt[x]],Et[0],vt[x]),R=In(u,p,y,g,w,e[wt[x]],Bt[0],xt[x])):x<32?(T=Bn(r,n,o,s,c,e[mt[x]],Et[1],vt[x]),R=Sn(u,p,y,g,w,e[wt[x]],Bt[1],xt[x])):x<48?(T=Rn(r,n,o,s,c,e[mt[x]],Et[2],vt[x]),R=Rn(u,p,y,g,w,e[wt[x]],Bt[2],xt[x])):x<64?(T=Sn(r,n,o,s,c,e[mt[x]],Et[3],vt[x]),R=Bn(u,p,y,g,w,e[wt[x]],Bt[3],xt[x])):(T=In(r,n,o,s,c,e[mt[x]],Et[4],vt[x]),R=En(u,p,y,g,w,e[wt[x]],Bt[4],xt[x])),r=c,c=s,s=Xe(o,10),o=n,n=T,u=w,w=g,g=Xe(y,10),y=p,p=R}var C=this._b+o+g|0;this._b=this._c+s+w|0,this._c=this._d+c+u|0,this._d=this._e+r+p|0,this._e=this._a+n+y|0,this._a=C};tr.prototype._digest=function(){this._block[this._blockOffset++]=128,this._blockOffset>56&&(this._block.fill(0,this._blockOffset,64),this._update(),this._blockOffset=0),this._block.fill(0,this._blockOffset,56),this._block.writeUInt32LE(this._length[0],56),this._block.writeUInt32LE(this._length[1],60),this._update();var e=vr.alloc?vr.alloc(20):new vr(20);return e.writeInt32LE(this._a,0),e.writeInt32LE(this._b,4),e.writeInt32LE(this._c,8),e.writeInt32LE(this._d,12),e.writeInt32LE(this._e,16),e};function Xe(e,t){return e<<t|e>>>32-t}function En(e,t,r,n,o,s,c,u){return Xe(e+(t^r^n)+s+c|0,u)+o|0}function Bn(e,t,r,n,o,s,c,u){return Xe(e+(t&r|~t&n)+s+c|0,u)+o|0}function Rn(e,t,r,n,o,s,c,u){return Xe(e+((t|~r)^n)+s+c|0,u)+o|0}function Sn(e,t,r,n,o,s,c,u){return Xe(e+(t&n|r&~n)+s+c|0,u)+o|0}function In(e,t,r,n,o,s,c,u){return Xe(e+(t^(r|~n))+s+c|0,u)+o|0}var ys=tr,Ri={exports:{}},Si=we.Buffer;function rr(e,t){this._block=Si.alloc(e),this._finalSize=t,this._blockSize=e,this._len=0}rr.prototype.update=function(e,t){typeof e=="string"&&(t=t||"utf8",e=Si.from(e,t));for(var r=this._block,n=this._blockSize,o=e.length,s=this._len,c=0;c<o;){for(var u=s%n,p=Math.min(o-c,n-u),y=0;y<p;y++)r[u+y]=e[c+y];s+=p,c+=p,s%n===0&&this._update(r)}return this._len+=o,this};rr.prototype.digest=function(e){var t=this._len%this._blockSize;this._block[t]=128,this._block.fill(0,t+1),t>=this._finalSize&&(this._update(this._block),this._block.fill(0));var r=this._len*8;if(r<=4294967295)this._block.writeUInt32BE(r,this._blockSize-4);else{var n=(r&4294967295)>>>0,o=(r-n)/4294967296;this._block.writeUInt32BE(o,this._blockSize-8),this._block.writeUInt32BE(n,this._blockSize-4)}this._update(this._block);var s=this._hash();return e?s.toString(e):s};rr.prototype._update=function(){throw new Error("_update must be implemented by subclass")};var bt=rr,gs=pe,Ii=bt,_s=we.Buffer,ms=[1518500249,1859775393,-1894007588,-899497514],ws=new Array(80);function At(){this.init(),this._w=ws,Ii.call(this,64,56)}gs(At,Ii);At.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this};function vs(e){return e<<5|e>>>27}function xs(e){return e<<30|e>>>2}function Es(e,t,r,n){return e===0?t&r|~t&n:e===2?t&r|t&n|r&n:t^r^n}At.prototype._update=function(e){for(var t=this._w,r=this._a|0,n=this._b|0,o=this._c|0,s=this._d|0,c=this._e|0,u=0;u<16;++u)t[u]=e.readInt32BE(u*4);for(;u<80;++u)t[u]=t[u-3]^t[u-8]^t[u-14]^t[u-16];for(var p=0;p<80;++p){var y=~~(p/20),g=vs(r)+Es(y,n,o,s)+c+t[p]+ms[y]|0;c=s,s=o,o=xs(n),n=r,r=g}this._a=r+this._a|0,this._b=n+this._b|0,this._c=o+this._c|0,this._d=s+this._d|0,this._e=c+this._e|0};At.prototype._hash=function(){var e=_s.allocUnsafe(20);return e.writeInt32BE(this._a|0,0),e.writeInt32BE(this._b|0,4),e.writeInt32BE(this._c|0,8),e.writeInt32BE(this._d|0,12),e.writeInt32BE(this._e|0,16),e};var Bs=At,Rs=pe,Ti=bt,Ss=we.Buffer,Is=[1518500249,1859775393,-1894007588,-899497514],Ts=new Array(80);function Ct(){this.init(),this._w=Ts,Ti.call(this,64,56)}Rs(Ct,Ti);Ct.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this};function ks(e){return e<<1|e>>>31}function As(e){return e<<5|e>>>27}function Cs(e){return e<<30|e>>>2}function Ps(e,t,r,n){return e===0?t&r|~t&n:e===2?t&r|t&n|r&n:t^r^n}Ct.prototype._update=function(e){for(var t=this._w,r=this._a|0,n=this._b|0,o=this._c|0,s=this._d|0,c=this._e|0,u=0;u<16;++u)t[u]=e.readInt32BE(u*4);for(;u<80;++u)t[u]=ks(t[u-3]^t[u-8]^t[u-14]^t[u-16]);for(var p=0;p<80;++p){var y=~~(p/20),g=As(r)+Ps(y,n,o,s)+c+t[p]+Is[y]|0;c=s,s=o,o=Cs(n),n=r,r=g}this._a=r+this._a|0,this._b=n+this._b|0,this._c=o+this._c|0,this._d=s+this._d|0,this._e=c+this._e|0};Ct.prototype._hash=function(){var e=Ss.allocUnsafe(20);return e.writeInt32BE(this._a|0,0),e.writeInt32BE(this._b|0,4),e.writeInt32BE(this._c|0,8),e.writeInt32BE(this._d|0,12),e.writeInt32BE(this._e|0,16),e};var Os=Ct,Ns=pe,ki=bt,Fs=we.Buffer,Ls=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],Ms=new Array(64);function Pt(){this.init(),this._w=Ms,ki.call(this,64,56)}Ns(Pt,ki);Pt.prototype.init=function(){return this._a=1779033703,this._b=3144134277,this._c=1013904242,this._d=2773480762,this._e=1359893119,this._f=2600822924,this._g=528734635,this._h=1541459225,this};function Us(e,t,r){return r^e&(t^r)}function Ds(e,t,r){return e&t|r&(e|t)}function $s(e){return(e>>>2|e<<30)^(e>>>13|e<<19)^(e>>>22|e<<10)}function Hs(e){return(e>>>6|e<<26)^(e>>>11|e<<21)^(e>>>25|e<<7)}function js(e){return(e>>>7|e<<25)^(e>>>18|e<<14)^e>>>3}function qs(e){return(e>>>17|e<<15)^(e>>>19|e<<13)^e>>>10}Pt.prototype._update=function(e){for(var t=this._w,r=this._a|0,n=this._b|0,o=this._c|0,s=this._d|0,c=this._e|0,u=this._f|0,p=this._g|0,y=this._h|0,g=0;g<16;++g)t[g]=e.readInt32BE(g*4);for(;g<64;++g)t[g]=qs(t[g-2])+t[g-7]+js(t[g-15])+t[g-16]|0;for(var w=0;w<64;++w){var x=y+Hs(c)+Us(c,u,p)+Ls[w]+t[w]|0,T=$s(r)+Ds(r,n,o)|0;y=p,p=u,u=c,c=s+x|0,s=o,o=n,n=r,r=x+T|0}this._a=r+this._a|0,this._b=n+this._b|0,this._c=o+this._c|0,this._d=s+this._d|0,this._e=c+this._e|0,this._f=u+this._f|0,this._g=p+this._g|0,this._h=y+this._h|0};Pt.prototype._hash=function(){var e=Fs.allocUnsafe(32);return e.writeInt32BE(this._a,0),e.writeInt32BE(this._b,4),e.writeInt32BE(this._c,8),e.writeInt32BE(this._d,12),e.writeInt32BE(this._e,16),e.writeInt32BE(this._f,20),e.writeInt32BE(this._g,24),e.writeInt32BE(this._h,28),e};var Ai=Pt,Ws=pe,Gs=Ai,zs=bt,Ks=we.Buffer,Vs=new Array(64);function nr(){this.init(),this._w=Vs,zs.call(this,64,56)}Ws(nr,Gs);nr.prototype.init=function(){return this._a=3238371032,this._b=914150663,this._c=812702999,this._d=4144912697,this._e=4290775857,this._f=1750603025,this._g=1694076839,this._h=3204075428,this};nr.prototype._hash=function(){var e=Ks.allocUnsafe(28);return e.writeInt32BE(this._a,0),e.writeInt32BE(this._b,4),e.writeInt32BE(this._c,8),e.writeInt32BE(this._d,12),e.writeInt32BE(this._e,16),e.writeInt32BE(this._f,20),e.writeInt32BE(this._g,24),e};var Js=nr,Ys=pe,Ci=bt,Qs=we.Buffer,Tn=[1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591],Xs=new Array(160);function Ot(){this.init(),this._w=Xs,Ci.call(this,128,112)}Ys(Ot,Ci);Ot.prototype.init=function(){return this._ah=1779033703,this._bh=3144134277,this._ch=1013904242,this._dh=2773480762,this._eh=1359893119,this._fh=2600822924,this._gh=528734635,this._hh=1541459225,this._al=4089235720,this._bl=2227873595,this._cl=4271175723,this._dl=1595750129,this._el=2917565137,this._fl=725511199,this._gl=4215389547,this._hl=327033209,this};function kn(e,t,r){return r^e&(t^r)}function An(e,t,r){return e&t|r&(e|t)}function Cn(e,t){return(e>>>28|t<<4)^(t>>>2|e<<30)^(t>>>7|e<<25)}function Pn(e,t){return(e>>>14|t<<18)^(e>>>18|t<<14)^(t>>>9|e<<23)}function Zs(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^e>>>7}function ef(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^(e>>>7|t<<25)}function tf(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^e>>>6}function rf(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^(e>>>6|t<<26)}function se(e,t){return e>>>0<t>>>0?1:0}Ot.prototype._update=function(e){for(var t=this._w,r=this._ah|0,n=this._bh|0,o=this._ch|0,s=this._dh|0,c=this._eh|0,u=this._fh|0,p=this._gh|0,y=this._hh|0,g=this._al|0,w=this._bl|0,x=this._cl|0,T=this._dl|0,R=this._el|0,C=this._fl|0,E=this._gl|0,k=this._hl|0,O=0;O<32;O+=2)t[O]=e.readInt32BE(O*4),t[O+1]=e.readInt32BE(O*4+4);for(;O<160;O+=2){var F=t[O-30],N=t[O-15*2+1],L=Zs(F,N),S=ef(N,F);F=t[O-2*2],N=t[O-2*2+1];var j=tf(F,N),D=rf(N,F),U=t[O-7*2],ee=t[O-7*2+1],Ie=t[O-16*2],De=t[O-16*2+1],ae=S+ee|0,_e=L+U+se(ae,S)|0;ae=ae+D|0,_e=_e+j+se(ae,D)|0,ae=ae+De|0,_e=_e+Ie+se(ae,De)|0,t[O]=_e,t[O+1]=ae}for(var me=0;me<160;me+=2){_e=t[me],ae=t[me+1];var Ve=An(r,n,o),Te=An(g,w,x),$e=Cn(r,g),ke=Cn(g,r),He=Pn(c,R),Y=Pn(R,c),ie=Tn[me],ve=Tn[me+1],je=kn(c,u,p),Ne=kn(R,C,E),m=k+Y|0,_=y+He+se(m,k)|0;m=m+Ne|0,_=_+je+se(m,Ne)|0,m=m+ve|0,_=_+ie+se(m,ve)|0,m=m+ae|0,_=_+_e+se(m,ae)|0;var A=ke+Te|0,$=$e+Ve+se(A,ke)|0;y=p,k=E,p=u,E=C,u=c,C=R,R=T+m|0,c=s+_+se(R,T)|0,s=o,T=x,o=n,x=w,n=r,w=g,g=m+A|0,r=_+$+se(g,m)|0}this._al=this._al+g|0,this._bl=this._bl+w|0,this._cl=this._cl+x|0,this._dl=this._dl+T|0,this._el=this._el+R|0,this._fl=this._fl+C|0,this._gl=this._gl+E|0,this._hl=this._hl+k|0,this._ah=this._ah+r+se(this._al,g)|0,this._bh=this._bh+n+se(this._bl,w)|0,this._ch=this._ch+o+se(this._cl,x)|0,this._dh=this._dh+s+se(this._dl,T)|0,this._eh=this._eh+c+se(this._el,R)|0,this._fh=this._fh+u+se(this._fl,C)|0,this._gh=this._gh+p+se(this._gl,E)|0,this._hh=this._hh+y+se(this._hl,k)|0};Ot.prototype._hash=function(){var e=Qs.allocUnsafe(64);function t(r,n,o){e.writeInt32BE(r,o),e.writeInt32BE(n,o+4)}return t(this._ah,this._al,0),t(this._bh,this._bl,8),t(this._ch,this._cl,16),t(this._dh,this._dl,24),t(this._eh,this._el,32),t(this._fh,this._fl,40),t(this._gh,this._gl,48),t(this._hh,this._hl,56),e};var Pi=Ot,nf=pe,af=Pi,of=bt,sf=we.Buffer,ff=new Array(160);function ir(){this.init(),this._w=ff,of.call(this,128,112)}nf(ir,af);ir.prototype.init=function(){return this._ah=3418070365,this._bh=1654270250,this._ch=2438529370,this._dh=355462360,this._eh=1731405415,this._fh=2394180231,this._gh=3675008525,this._hh=1203062813,this._al=3238371032,this._bl=914150663,this._cl=812702999,this._dl=4144912697,this._el=4290775857,this._fl=1750603025,this._gl=1694076839,this._hl=3204075428,this};ir.prototype._hash=function(){var e=sf.allocUnsafe(48);function t(r,n,o){e.writeInt32BE(r,o),e.writeInt32BE(n,o+4)}return t(this._ah,this._al,0),t(this._bh,this._bl,8),t(this._ch,this._cl,16),t(this._dh,this._dl,24),t(this._eh,this._el,32),t(this._fh,this._fl,40),e};var uf=ir,tt=Ri.exports=function(t){t=t.toLowerCase();var r=tt[t];if(!r)throw new Error(t+" is not supported (we accept pull requests)");return new r};tt.sha=Bs;tt.sha1=Os;tt.sha224=Js;tt.sha256=Ai;tt.sha384=uf;tt.sha512=Pi;var cf=Ri.exports,Oi=we.Buffer,Ni=zr.Transform,lf=Gt.StringDecoder,hf=pe;function Ae(e){Ni.call(this),this.hashMode=typeof e=="string",this.hashMode?this[e]=this._finalOrDigest:this.final=this._finalOrDigest,this._final&&(this.__final=this._final,this._final=null),this._decoder=null,this._encoding=null}hf(Ae,Ni);Ae.prototype.update=function(e,t,r){typeof e=="string"&&(e=Oi.from(e,t));var n=this._update(e);return this.hashMode?this:(r&&(n=this._toString(n,r)),n)};Ae.prototype.setAutoPadding=function(){};Ae.prototype.getAuthTag=function(){throw new Error("trying to get auth tag in unsupported state")};Ae.prototype.setAuthTag=function(){throw new Error("trying to set auth tag in unsupported state")};Ae.prototype.setAAD=function(){throw new Error("trying to set aad in unsupported state")};Ae.prototype._transform=function(e,t,r){var n;try{this.hashMode?this._update(e):this.push(this._update(e))}catch(o){n=o}finally{r(n)}};Ae.prototype._flush=function(e){var t;try{this.push(this.__final())}catch(r){t=r}e(t)};Ae.prototype._finalOrDigest=function(e){var t=this.__final()||Oi.alloc(0);return e&&(t=this._toString(t,e,!0)),t};Ae.prototype._toString=function(e,t,r){if(this._decoder||(this._decoder=new lf(t),this._encoding=t),this._encoding!==t)throw new Error("can't switch encodings");var n=this._decoder.write(e);return r&&(n+=this._decoder.end()),n};var df=Ae,pf=pe,bf=ds,yf=ys,gf=cf,Fi=df;function ar(e){Fi.call(this,"digest"),this._hash=e}pf(ar,Fi);ar.prototype._update=function(e){this._hash.update(e)};ar.prototype._final=function(){return this._hash.digest()};var _f=function(t){return t=t.toLowerCase(),t==="md5"?new bf:t==="rmd160"||t==="ripemd160"?new yf:new ar(gf(t))},Mt=we.Buffer;function mf(e){if(e.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),r=0;r<t.length;r++)t[r]=255;for(var n=0;n<e.length;n++){var o=e.charAt(n),s=o.charCodeAt(0);if(t[s]!==255)throw new TypeError(o+" is ambiguous");t[s]=n}var c=e.length,u=e.charAt(0),p=Math.log(c)/Math.log(256),y=Math.log(256)/Math.log(c);function g(T){if((Array.isArray(T)||T instanceof Uint8Array)&&(T=Mt.from(T)),!Mt.isBuffer(T))throw new TypeError("Expected Buffer");if(T.length===0)return"";for(var R=0,C=0,E=0,k=T.length;E!==k&&T[E]===0;)E++,R++;for(var O=(k-E)*y+1>>>0,F=new Uint8Array(O);E!==k;){for(var N=T[E],L=0,S=O-1;(N!==0||L<C)&&S!==-1;S--,L++)N+=256*F[S]>>>0,F[S]=N%c>>>0,N=N/c>>>0;if(N!==0)throw new Error("Non-zero carry");C=L,E++}for(var j=O-C;j!==O&&F[j]===0;)j++;for(var D=u.repeat(R);j<O;++j)D+=e.charAt(F[j]);return D}function w(T){if(typeof T!="string")throw new TypeError("Expected String");if(T.length===0)return Mt.alloc(0);for(var R=0,C=0,E=0;T[R]===u;)C++,R++;for(var k=(T.length-R)*p+1>>>0,O=new Uint8Array(k);R<T.length;){var F=t[T.charCodeAt(R)];if(F===255)return;for(var N=0,L=k-1;(F!==0||N<E)&&L!==-1;L--,N++)F+=c*O[L]>>>0,O[L]=F%256>>>0,F=F/256>>>0;if(F!==0)throw new Error("Non-zero carry");E=N,R++}for(var S=k-E;S!==k&&O[S]===0;)S++;var j=Mt.allocUnsafe(C+(k-S));j.fill(0,0,C);for(var D=C;S!==k;)j[D++]=O[S++];return j}function x(T){var R=w(T);if(R)return R;throw new Error("Non-base"+c+" character")}return{encode:g,decodeUnsafe:w,decode:x}}var wf=mf,vf=wf,xf="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",Ef=vf(xf),xr=Ef,Bf=we.Buffer,Rf=function(e){function t(s){var c=e(s);return xr.encode(Bf.concat([s,c],s.length+4))}function r(s){var c=s.slice(0,-4),u=s.slice(-4),p=e(c);if(!(u[0]^p[0]|u[1]^p[1]|u[2]^p[2]|u[3]^p[3]))return c}function n(s){var c=xr.decodeUnsafe(s);if(c)return r(c)}function o(s){var c=xr.decode(s),u=r(c);if(!u)throw new Error("Invalid checksum");return u}return{encode:t,decode:o,decodeUnsafe:n}},On=_f,Sf=Rf;function If(e){var t=On("sha256").update(e).digest();return On("sha256").update(t).digest()}var Tf=Sf(If),Mr=Tf;function Li(e,t){if(t!==void 0&&e[0]!==t)throw new Error("Invalid network version");if(e.length===33)return{version:e[0],privateKey:e.slice(1,33),compressed:!1};if(e.length!==34)throw new Error("Invalid WIF length");if(e[33]!==1)throw new Error("Invalid compression flag");return{version:e[0],privateKey:e.slice(1,33),compressed:!0}}function Ur(e,t,r){var n=new Buffer(r?34:33);return n.writeUInt8(e,0),t.copy(n,1),r&&(n[33]=1),n}function kf(e,t){return Li(Mr.decode(e),t)}function Af(e,t,r){return typeof e=="number"?Mr.encode(Ur(e,t,r)):Mr.encode(Ur(e.version,e.privateKey,e.compressed))}var Cf={decode:kf,decodeRaw:Li,encode:Af,encodeRaw:Ur},or={};Object.defineProperty(or,"__esModule",{value:!0});or.testEcc=void 0;const H=e=>Buffer.from(e,"hex");function Pf(e){J(e.isPoint(H("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),J(!e.isPoint(H("030000000000000000000000000000000000000000000000000000000000000005"))),J(e.isPrivate(H("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),J(e.isPrivate(H("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))),J(!e.isPrivate(H("0000000000000000000000000000000000000000000000000000000000000000"))),J(!e.isPrivate(H("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"))),J(!e.isPrivate(H("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364142"))),J(Buffer.from(e.privateAdd(H("0000000000000000000000000000000000000000000000000000000000000001"),H("0000000000000000000000000000000000000000000000000000000000000000"))).equals(H("0000000000000000000000000000000000000000000000000000000000000001"))),J(e.privateAdd(H("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413e"),H("0000000000000000000000000000000000000000000000000000000000000003"))===null),J(Buffer.from(e.privateAdd(H("e211078564db65c3ce7704f08262b1f38f1ef412ad15b5ac2d76657a63b2c500"),H("b51fbb69051255d1becbd683de5848242a89c229348dd72896a87ada94ae8665"))).equals(H("9730c2ee69edbb958d42db7460bafa18fef9d955325aec99044c81c8282b0a24"))),J(Buffer.from(e.privateNegate(H("0000000000000000000000000000000000000000000000000000000000000001"))).equals(H("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))),J(Buffer.from(e.privateNegate(H("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413e"))).equals(H("0000000000000000000000000000000000000000000000000000000000000003"))),J(Buffer.from(e.privateNegate(H("b1121e4088a66a28f5b6b0f5844943ecd9f610196d7bb83b25214b60452c09af"))).equals(H("4eede1bf775995d70a494f0a7bb6bc11e0b8cccd41cce8009ab1132c8b0a3792"))),J(Buffer.from(e.pointCompress(H("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"),!0)).equals(H("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),J(Buffer.from(e.pointCompress(H("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"),!1)).equals(H("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"))),J(Buffer.from(e.pointCompress(H("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),!0)).equals(H("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),J(Buffer.from(e.pointCompress(H("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),!1)).equals(H("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"))),J(Buffer.from(e.pointFromScalar(H("b1121e4088a66a28f5b6b0f5844943ecd9f610196d7bb83b25214b60452c09af"))).equals(H("02b07ba9dca9523b7ef4bd97703d43d20399eb698e194704791a25ce77a400df99"))),J(e.xOnlyPointAddTweak(H("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),H("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))===null);let t=e.xOnlyPointAddTweak(H("1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b"),H("a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac"));J(Buffer.from(t.xOnlyPubkey).equals(H("e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf"))&&t.parity===1),t=e.xOnlyPointAddTweak(H("2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991"),H("823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47")),J(Buffer.from(t.xOnlyPubkey).equals(H("9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c"))&&t.parity===0),J(Buffer.from(e.sign(H("5e9f0a0d593efdcf78ac923bc3313e4e7d408d574354ee2b3288c0da9fbba6ed"),H("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))).equals(H("54c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed07082304410efa6b2943111b6a4e0aaa7b7db55a07e9861d1fb3cb1f421044a5"))),J(e.verify(H("5e9f0a0d593efdcf78ac923bc3313e4e7d408d574354ee2b3288c0da9fbba6ed"),H("0379be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),H("54c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed07082304410efa6b2943111b6a4e0aaa7b7db55a07e9861d1fb3cb1f421044a5"))),e.signSchnorr&&J(Buffer.from(e.signSchnorr(H("7e2d58d8b3bcdf1abadec7829054f90dda9805aab56c77333024b9d0a508b75c"),H("c90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b14e5c9"),H("c87aa53824b4d7ae2eb035a2b5bbbccc080e76cdc6d1692c4b0b62d798e6d906"))).equals(H("5831aaeed7b44bb74e5eab94ba9d4294c49bcf2a60728d8b4c200f50dd313c1bab745879a5ad954a72c45a91c3a51d3c7adea98d82f8481e0e1e03674a6f3fb7"))),e.verifySchnorr&&J(e.verifySchnorr(H("7e2d58d8b3bcdf1abadec7829054f90dda9805aab56c77333024b9d0a508b75c"),H("dd308afec5777e13121fa72b9cc1b7cc0139715309b086c960e18fd969774eb8"),H("5831aaeed7b44bb74e5eab94ba9d4294c49bcf2a60728d8b4c200f50dd313c1bab745879a5ad954a72c45a91c3a51d3c7adea98d82f8481e0e1e03674a6f3fb7")))}or.testEcc=Pf;function J(e){if(!e)throw new Error("ecc library invalid")}Object.defineProperty(lt,"__esModule",{value:!0});lt.ECPairFactory=lt.networks=void 0;const Dr=ht;lt.networks=Dr;const ye=Jn,Of=io,Nn=Cf,Nf=or,Er=ye.typeforce.maybe(ye.typeforce.compile({compressed:ye.maybe(ye.Boolean),network:ye.maybe(ye.Network)})),Ff=e=>e.length===32?e:e.slice(1,33);function Lf(e){(0,Nf.testEcc)(e);function t(u){return e.isPoint(u)}function r(u,p){if(ye.typeforce(ye.Buffer256bit,u),!e.isPrivate(u))throw new TypeError("Private key not in range [1, n)");return ye.typeforce(Er,p),new c(u,void 0,p)}function n(u,p){return ye.typeforce(e.isPoint,u),ye.typeforce(Er,p),new c(void 0,u,p)}function o(u,p){const y=Nn.decode(u),g=y.version;if(ye.Array(p)){if(p=p.filter(w=>g===w.wif).pop(),!p)throw new Error("Unknown network version")}else if(p=p||Dr.bitcoin,g!==p.wif)throw new Error("Invalid network version");return r(y.privateKey,{compressed:y.compressed,network:p})}function s(u){ye.typeforce(Er,u),u===void 0&&(u={});const p=u.rng||Of;let y;do y=p(32),ye.typeforce(ye.Buffer256bit,y);while(!e.isPrivate(y));return r(y,u)}class c{constructor(p,y,g){it(this,"__D");it(this,"__Q");it(this,"compressed");it(this,"network");it(this,"lowR");this.__D=p,this.__Q=y,this.lowR=!1,g===void 0&&(g={}),this.compressed=g.compressed===void 0?!0:g.compressed,this.network=g.network||Dr.bitcoin,y!==void 0&&(this.__Q=Buffer.from(e.pointCompress(y,this.compressed)))}get privateKey(){return this.__D}get publicKey(){if(!this.__Q){const p=e.pointFromScalar(this.__D,this.compressed);this.__Q=Buffer.from(p)}return this.__Q}toWIF(){if(!this.__D)throw new Error("Missing private key");return Nn.encode(this.network.wif,this.__D,this.compressed)}tweak(p){return this.privateKey?this.tweakFromPrivateKey(p):this.tweakFromPublicKey(p)}sign(p,y){if(!this.__D)throw new Error("Missing private key");if(y===void 0&&(y=this.lowR),y===!1)return Buffer.from(e.sign(p,this.__D));{let g=e.sign(p,this.__D);const w=Buffer.alloc(32,0);let x=0;for(;g[0]>127;)x++,w.writeUIntLE(x,0,6),g=e.sign(p,this.__D,w);return Buffer.from(g)}}signSchnorr(p){if(!this.privateKey)throw new Error("Missing private key");if(!e.signSchnorr)throw new Error("signSchnorr not supported by ecc library");return Buffer.from(e.signSchnorr(p,this.privateKey))}verify(p,y){return e.verify(p,this.publicKey,y)}verifySchnorr(p,y){if(!e.verifySchnorr)throw new Error("verifySchnorr not supported by ecc library");return e.verifySchnorr(p,this.publicKey.subarray(1,33),y)}tweakFromPublicKey(p){const y=Ff(this.publicKey),g=e.xOnlyPointAddTweak(y,p);if(!g||g.xOnlyPubkey===null)throw new Error("Cannot tweak public key!");const w=Buffer.from([g.parity===0?2:3]);return n(Buffer.concat([w,g.xOnlyPubkey]),{network:this.network,compressed:this.compressed})}tweakFromPrivateKey(p){const g=this.publicKey[0]===3||this.publicKey[0]===4&&(this.publicKey[64]&1)===1?e.privateNegate(this.privateKey):this.privateKey,w=e.privateAdd(g,p);if(!w)throw new Error("Invalid tweaked private key!");return r(Buffer.from(w),{network:this.network,compressed:this.compressed})}}return{isPoint:t,fromPrivateKey:r,fromPublicKey:n,fromWIF:o,makeRandom:s}}lt.ECPairFactory=Lf;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.networks=e.ECPairFactory=e.default=void 0;var t=lt;Object.defineProperty(e,"default",{enumerable:!0,get:function(){return t.ECPairFactory}}),Object.defineProperty(e,"ECPairFactory",{enumerable:!0,get:function(){return t.ECPairFactory}}),Object.defineProperty(e,"networks",{enumerable:!0,get:function(){return t.networks}})})(Vn);class Kt{constructor(t){this.privKey=t}static fromPrivKey(t){return new Kt(P.trim0x(t))}static async fromWalletClient(t){if(!t.account)return P.Err("No account found");try{const r=await t.signTypedData({account:t.account,types:{EIP712Domain:[{name:"name",type:"string"},{name:"version",type:"string"}],Data:[{name:"Message",type:"string"},{name:"Version",type:"string"},{name:"Nonce",type:"uint256"}]},domain:{name:"WBTC GARDEN",version:"1"},primaryType:"Data",message:{Message:"Initialize your swap",Version:"1.0.0",Nonce:1n}});return P.Ok(new Kt(P.trim0x(Oe.sha256(r))))}catch(r){return P.Err("Failed to initialize: "+r)}}getMasterPrivKey(){return this.privKey}generateSecret(t){const r=this.signMessage(t),n=Oe.sha256(We(r)),o=Oe.sha256(n);return P.Ok({secret:n,secretHash:o})}signMessage(t){const r=Vn.ECPairFactory(ct),n="Garden.fi"+t.toString(),o=Buffer.from(n,"utf8"),s=Oe.sha256(o),c=Buffer.from(P.trim0x(this.privKey),"hex");if(c.length!==32)throw new Error("Invalid private key length. Expected 32 bytes.");return r.fromPrivateKey(c).sign(Buffer.from(P.trim0x(s),"hex")).toString("hex")}}class Mf{constructor(t){this.quoteUrl=new Rt("/quote",t)}async getQuote(t,r,n=!1){try{const o=this.quoteUrl.addSearchParams({order_pair:t,amount:r.toString(),exact_out:n.toString()}),s=await P.Fetcher.get(o);return s.error?P.Err(s.error):s.result?P.Ok(s.result):P.Err("GetQuote: Unexpected error, result is undefined")}catch(o){return P.Err("GetQuote:",String(o))}}async getAttestedQuote(t){try{const r=await P.Fetcher.post(this.quoteUrl.endpoint("/attested").toString(),{body:JSON.stringify(t),headers:{"Content-Type":"application/json"}});return r.error?P.Err(r.error):r.result?P.Ok(r.result):P.Err("GetAttestedQuote: Unexpected error, result is undefined")}catch(r){return console.log("error :",r),P.Err("GetAttestedQuote:",String(r))}}}exports.EvmRelay=Kn;exports.Garden=Ma;exports.ParseOrderStatus=Gn;exports.ParseSwapStatus=Ht;exports.Quote=Mf;exports.SecretManager=Kt;exports.parseAction=zn;exports.switchOrAddNetwork=Ta;
28
+ */(function(e){const t=Jt,r=Wr,n=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;e.Buffer=u,e.SlowBuffer=O,e.INSPECT_MAX_BYTES=50;const o=2147483647;e.kMaxLength=o,u.TYPED_ARRAY_SUPPORT=s(),!u.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function s(){try{const f=new Uint8Array(1),i={foo:function(){return 42}};return Object.setPrototypeOf(i,Uint8Array.prototype),Object.setPrototypeOf(f,i),f.foo()===42}catch{return!1}}Object.defineProperty(u.prototype,"parent",{enumerable:!0,get:function(){if(u.isBuffer(this))return this.buffer}}),Object.defineProperty(u.prototype,"offset",{enumerable:!0,get:function(){if(u.isBuffer(this))return this.byteOffset}});function c(f){if(f>o)throw new RangeError('The value "'+f+'" is invalid for option "size"');const i=new Uint8Array(f);return Object.setPrototypeOf(i,u.prototype),i}function u(f,i,a){if(typeof f=="number"){if(typeof i=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return w(f)}return p(f,i,a)}u.poolSize=8192;function p(f,i,a){if(typeof f=="string")return x(f,i);if(ArrayBuffer.isView(f))return R(f);if(f==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof f);if(xe(f,ArrayBuffer)||f&&xe(f.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(xe(f,SharedArrayBuffer)||f&&xe(f.buffer,SharedArrayBuffer)))return C(f,i,a);if(typeof f=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const l=f.valueOf&&f.valueOf();if(l!=null&&l!==f)return u.from(l,i,a);const b=E(f);if(b)return b;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof f[Symbol.toPrimitive]=="function")return u.from(f[Symbol.toPrimitive]("string"),i,a);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof f)}u.from=function(f,i,a){return p(f,i,a)},Object.setPrototypeOf(u.prototype,Uint8Array.prototype),Object.setPrototypeOf(u,Uint8Array);function y(f){if(typeof f!="number")throw new TypeError('"size" argument must be of type number');if(f<0)throw new RangeError('The value "'+f+'" is invalid for option "size"')}function g(f,i,a){return y(f),f<=0?c(f):i!==void 0?typeof a=="string"?c(f).fill(i,a):c(f).fill(i):c(f)}u.alloc=function(f,i,a){return g(f,i,a)};function w(f){return y(f),c(f<0?0:T(f)|0)}u.allocUnsafe=function(f){return w(f)},u.allocUnsafeSlow=function(f){return w(f)};function x(f,i){if((typeof i!="string"||i==="")&&(i="utf8"),!u.isEncoding(i))throw new TypeError("Unknown encoding: "+i);const a=F(f,i)|0;let l=c(a);const b=l.write(f,i);return b!==a&&(l=l.slice(0,b)),l}function k(f){const i=f.length<0?0:T(f.length)|0,a=c(i);for(let l=0;l<i;l+=1)a[l]=f[l]&255;return a}function R(f){if(xe(f,Uint8Array)){const i=new Uint8Array(f);return C(i.buffer,i.byteOffset,i.byteLength)}return k(f)}function C(f,i,a){if(i<0||f.byteLength<i)throw new RangeError('"offset" is outside of buffer bounds');if(f.byteLength<i+(a||0))throw new RangeError('"length" is outside of buffer bounds');let l;return i===void 0&&a===void 0?l=new Uint8Array(f):a===void 0?l=new Uint8Array(f,i):l=new Uint8Array(f,i,a),Object.setPrototypeOf(l,u.prototype),l}function E(f){if(u.isBuffer(f)){const i=T(f.length)|0,a=c(i);return a.length===0||f.copy(a,0,0,i),a}if(f.length!==void 0)return typeof f.length!="number"||Je(f.length)?c(0):k(f);if(f.type==="Buffer"&&Array.isArray(f.data))return k(f.data)}function T(f){if(f>=o)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+o.toString(16)+" bytes");return f|0}function O(f){return+f!=f&&(f=0),u.alloc(+f)}u.isBuffer=function(i){return i!=null&&i._isBuffer===!0&&i!==u.prototype},u.compare=function(i,a){if(xe(i,Uint8Array)&&(i=u.from(i,i.offset,i.byteLength)),xe(a,Uint8Array)&&(a=u.from(a,a.offset,a.byteLength)),!u.isBuffer(i)||!u.isBuffer(a))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(i===a)return 0;let l=i.length,b=a.length;for(let v=0,B=Math.min(l,b);v<B;++v)if(i[v]!==a[v]){l=i[v],b=a[v];break}return l<b?-1:b<l?1:0},u.isEncoding=function(i){switch(String(i).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},u.concat=function(i,a){if(!Array.isArray(i))throw new TypeError('"list" argument must be an Array of Buffers');if(i.length===0)return u.alloc(0);let l;if(a===void 0)for(a=0,l=0;l<i.length;++l)a+=i[l].length;const b=u.allocUnsafe(a);let v=0;for(l=0;l<i.length;++l){let B=i[l];if(xe(B,Uint8Array))v+B.length>b.length?(u.isBuffer(B)||(B=u.from(B)),B.copy(b,v)):Uint8Array.prototype.set.call(b,B,v);else if(u.isBuffer(B))B.copy(b,v);else throw new TypeError('"list" argument must be an Array of Buffers');v+=B.length}return b};function F(f,i){if(u.isBuffer(f))return f.length;if(ArrayBuffer.isView(f)||xe(f,ArrayBuffer))return f.byteLength;if(typeof f!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof f);const a=f.length,l=arguments.length>2&&arguments[2]===!0;if(!l&&a===0)return 0;let b=!1;for(;;)switch(i){case"ascii":case"latin1":case"binary":return a;case"utf8":case"utf-8":return z(f).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return a*2;case"hex":return a>>>1;case"base64":return yt(f).length;default:if(b)return l?-1:z(f).length;i=(""+i).toLowerCase(),b=!0}}u.byteLength=F;function N(f,i,a){let l=!1;if((i===void 0||i<0)&&(i=0),i>this.length||((a===void 0||a>this.length)&&(a=this.length),a<=0)||(a>>>=0,i>>>=0,a<=i))return"";for(f||(f="utf8");;)switch(f){case"hex":return Te(this,i,a);case"utf8":case"utf-8":return _e(this,i,a);case"ascii":return ke(this,i,a);case"latin1":case"binary":return $e(this,i,a);case"base64":return ae(this,i,a);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return He(this,i,a);default:if(l)throw new TypeError("Unknown encoding: "+f);f=(f+"").toLowerCase(),l=!0}}u.prototype._isBuffer=!0;function L(f,i,a){const l=f[i];f[i]=f[a],f[a]=l}u.prototype.swap16=function(){const i=this.length;if(i%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let a=0;a<i;a+=2)L(this,a,a+1);return this},u.prototype.swap32=function(){const i=this.length;if(i%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let a=0;a<i;a+=4)L(this,a,a+3),L(this,a+1,a+2);return this},u.prototype.swap64=function(){const i=this.length;if(i%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let a=0;a<i;a+=8)L(this,a,a+7),L(this,a+1,a+6),L(this,a+2,a+5),L(this,a+3,a+4);return this},u.prototype.toString=function(){const i=this.length;return i===0?"":arguments.length===0?_e(this,0,i):N.apply(this,arguments)},u.prototype.toLocaleString=u.prototype.toString,u.prototype.equals=function(i){if(!u.isBuffer(i))throw new TypeError("Argument must be a Buffer");return this===i?!0:u.compare(this,i)===0},u.prototype.inspect=function(){let i="";const a=e.INSPECT_MAX_BYTES;return i=this.toString("hex",0,a).replace(/(.{2})/g,"$1 ").trim(),this.length>a&&(i+=" ... "),"<Buffer "+i+">"},n&&(u.prototype[n]=u.prototype.inspect),u.prototype.compare=function(i,a,l,b,v){if(xe(i,Uint8Array)&&(i=u.from(i,i.offset,i.byteLength)),!u.isBuffer(i))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof i);if(a===void 0&&(a=0),l===void 0&&(l=i?i.length:0),b===void 0&&(b=0),v===void 0&&(v=this.length),a<0||l>i.length||b<0||v>this.length)throw new RangeError("out of range index");if(b>=v&&a>=l)return 0;if(b>=v)return-1;if(a>=l)return 1;if(a>>>=0,l>>>=0,b>>>=0,v>>>=0,this===i)return 0;let B=v-b,G=l-a;const re=Math.min(B,G),X=this.slice(b,v),ne=i.slice(a,l);for(let V=0;V<re;++V)if(X[V]!==ne[V]){B=X[V],G=ne[V];break}return B<G?-1:G<B?1:0};function S(f,i,a,l,b){if(f.length===0)return-1;if(typeof a=="string"?(l=a,a=0):a>2147483647?a=2147483647:a<-2147483648&&(a=-2147483648),a=+a,Je(a)&&(a=b?0:f.length-1),a<0&&(a=f.length+a),a>=f.length){if(b)return-1;a=f.length-1}else if(a<0)if(b)a=0;else return-1;if(typeof i=="string"&&(i=u.from(i,l)),u.isBuffer(i))return i.length===0?-1:j(f,i,a,l,b);if(typeof i=="number")return i=i&255,typeof Uint8Array.prototype.indexOf=="function"?b?Uint8Array.prototype.indexOf.call(f,i,a):Uint8Array.prototype.lastIndexOf.call(f,i,a):j(f,[i],a,l,b);throw new TypeError("val must be string, number or Buffer")}function j(f,i,a,l,b){let v=1,B=f.length,G=i.length;if(l!==void 0&&(l=String(l).toLowerCase(),l==="ucs2"||l==="ucs-2"||l==="utf16le"||l==="utf-16le")){if(f.length<2||i.length<2)return-1;v=2,B/=2,G/=2,a/=2}function re(ne,V){return v===1?ne[V]:ne.readUInt16BE(V*v)}let X;if(b){let ne=-1;for(X=a;X<B;X++)if(re(f,X)===re(i,ne===-1?0:X-ne)){if(ne===-1&&(ne=X),X-ne+1===G)return ne*v}else ne!==-1&&(X-=X-ne),ne=-1}else for(a+G>B&&(a=B-G),X=a;X>=0;X--){let ne=!0;for(let V=0;V<G;V++)if(re(f,X+V)!==re(i,V)){ne=!1;break}if(ne)return X}return-1}u.prototype.includes=function(i,a,l){return this.indexOf(i,a,l)!==-1},u.prototype.indexOf=function(i,a,l){return S(this,i,a,l,!0)},u.prototype.lastIndexOf=function(i,a,l){return S(this,i,a,l,!1)};function D(f,i,a,l){a=Number(a)||0;const b=f.length-a;l?(l=Number(l),l>b&&(l=b)):l=b;const v=i.length;l>v/2&&(l=v/2);let B;for(B=0;B<l;++B){const G=parseInt(i.substr(B*2,2),16);if(Je(G))return B;f[a+B]=G}return B}function U(f,i,a,l){return nt(z(i,f.length-a),f,a,l)}function ee(f,i,a,l){return nt(qe(i),f,a,l)}function Ie(f,i,a,l){return nt(yt(i),f,a,l)}function De(f,i,a,l){return nt(rt(i,f.length-a),f,a,l)}u.prototype.write=function(i,a,l,b){if(a===void 0)b="utf8",l=this.length,a=0;else if(l===void 0&&typeof a=="string")b=a,l=this.length,a=0;else if(isFinite(a))a=a>>>0,isFinite(l)?(l=l>>>0,b===void 0&&(b="utf8")):(b=l,l=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const v=this.length-a;if((l===void 0||l>v)&&(l=v),i.length>0&&(l<0||a<0)||a>this.length)throw new RangeError("Attempt to write outside buffer bounds");b||(b="utf8");let B=!1;for(;;)switch(b){case"hex":return D(this,i,a,l);case"utf8":case"utf-8":return U(this,i,a,l);case"ascii":case"latin1":case"binary":return ee(this,i,a,l);case"base64":return Ie(this,i,a,l);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return De(this,i,a,l);default:if(B)throw new TypeError("Unknown encoding: "+b);b=(""+b).toLowerCase(),B=!0}},u.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function ae(f,i,a){return i===0&&a===f.length?t.fromByteArray(f):t.fromByteArray(f.slice(i,a))}function _e(f,i,a){a=Math.min(f.length,a);const l=[];let b=i;for(;b<a;){const v=f[b];let B=null,G=v>239?4:v>223?3:v>191?2:1;if(b+G<=a){let re,X,ne,V;switch(G){case 1:v<128&&(B=v);break;case 2:re=f[b+1],(re&192)===128&&(V=(v&31)<<6|re&63,V>127&&(B=V));break;case 3:re=f[b+1],X=f[b+2],(re&192)===128&&(X&192)===128&&(V=(v&15)<<12|(re&63)<<6|X&63,V>2047&&(V<55296||V>57343)&&(B=V));break;case 4:re=f[b+1],X=f[b+2],ne=f[b+3],(re&192)===128&&(X&192)===128&&(ne&192)===128&&(V=(v&15)<<18|(re&63)<<12|(X&63)<<6|ne&63,V>65535&&V<1114112&&(B=V))}}B===null?(B=65533,G=1):B>65535&&(B-=65536,l.push(B>>>10&1023|55296),B=56320|B&1023),l.push(B),b+=G}return Ve(l)}const me=4096;function Ve(f){const i=f.length;if(i<=me)return String.fromCharCode.apply(String,f);let a="",l=0;for(;l<i;)a+=String.fromCharCode.apply(String,f.slice(l,l+=me));return a}function ke(f,i,a){let l="";a=Math.min(f.length,a);for(let b=i;b<a;++b)l+=String.fromCharCode(f[b]&127);return l}function $e(f,i,a){let l="";a=Math.min(f.length,a);for(let b=i;b<a;++b)l+=String.fromCharCode(f[b]);return l}function Te(f,i,a){const l=f.length;(!i||i<0)&&(i=0),(!a||a<0||a>l)&&(a=l);let b="";for(let v=i;v<a;++v)b+=gt[f[v]];return b}function He(f,i,a){const l=f.slice(i,a);let b="";for(let v=0;v<l.length-1;v+=2)b+=String.fromCharCode(l[v]+l[v+1]*256);return b}u.prototype.slice=function(i,a){const l=this.length;i=~~i,a=a===void 0?l:~~a,i<0?(i+=l,i<0&&(i=0)):i>l&&(i=l),a<0?(a+=l,a<0&&(a=0)):a>l&&(a=l),a<i&&(a=i);const b=this.subarray(i,a);return Object.setPrototypeOf(b,u.prototype),b};function Y(f,i,a){if(f%1!==0||f<0)throw new RangeError("offset is not uint");if(f+i>a)throw new RangeError("Trying to access beyond buffer length")}u.prototype.readUintLE=u.prototype.readUIntLE=function(i,a,l){i=i>>>0,a=a>>>0,l||Y(i,a,this.length);let b=this[i],v=1,B=0;for(;++B<a&&(v*=256);)b+=this[i+B]*v;return b},u.prototype.readUintBE=u.prototype.readUIntBE=function(i,a,l){i=i>>>0,a=a>>>0,l||Y(i,a,this.length);let b=this[i+--a],v=1;for(;a>0&&(v*=256);)b+=this[i+--a]*v;return b},u.prototype.readUint8=u.prototype.readUInt8=function(i,a){return i=i>>>0,a||Y(i,1,this.length),this[i]},u.prototype.readUint16LE=u.prototype.readUInt16LE=function(i,a){return i=i>>>0,a||Y(i,2,this.length),this[i]|this[i+1]<<8},u.prototype.readUint16BE=u.prototype.readUInt16BE=function(i,a){return i=i>>>0,a||Y(i,2,this.length),this[i]<<8|this[i+1]},u.prototype.readUint32LE=u.prototype.readUInt32LE=function(i,a){return i=i>>>0,a||Y(i,4,this.length),(this[i]|this[i+1]<<8|this[i+2]<<16)+this[i+3]*16777216},u.prototype.readUint32BE=u.prototype.readUInt32BE=function(i,a){return i=i>>>0,a||Y(i,4,this.length),this[i]*16777216+(this[i+1]<<16|this[i+2]<<8|this[i+3])},u.prototype.readBigUInt64LE=Ee(function(i){i=i>>>0,I(i,"offset");const a=this[i],l=this[i+7];(a===void 0||l===void 0)&&M(i,this.length-8);const b=a+this[++i]*2**8+this[++i]*2**16+this[++i]*2**24,v=this[++i]+this[++i]*2**8+this[++i]*2**16+l*2**24;return BigInt(b)+(BigInt(v)<<BigInt(32))}),u.prototype.readBigUInt64BE=Ee(function(i){i=i>>>0,I(i,"offset");const a=this[i],l=this[i+7];(a===void 0||l===void 0)&&M(i,this.length-8);const b=a*2**24+this[++i]*2**16+this[++i]*2**8+this[++i],v=this[++i]*2**24+this[++i]*2**16+this[++i]*2**8+l;return(BigInt(b)<<BigInt(32))+BigInt(v)}),u.prototype.readIntLE=function(i,a,l){i=i>>>0,a=a>>>0,l||Y(i,a,this.length);let b=this[i],v=1,B=0;for(;++B<a&&(v*=256);)b+=this[i+B]*v;return v*=128,b>=v&&(b-=Math.pow(2,8*a)),b},u.prototype.readIntBE=function(i,a,l){i=i>>>0,a=a>>>0,l||Y(i,a,this.length);let b=a,v=1,B=this[i+--b];for(;b>0&&(v*=256);)B+=this[i+--b]*v;return v*=128,B>=v&&(B-=Math.pow(2,8*a)),B},u.prototype.readInt8=function(i,a){return i=i>>>0,a||Y(i,1,this.length),this[i]&128?(255-this[i]+1)*-1:this[i]},u.prototype.readInt16LE=function(i,a){i=i>>>0,a||Y(i,2,this.length);const l=this[i]|this[i+1]<<8;return l&32768?l|4294901760:l},u.prototype.readInt16BE=function(i,a){i=i>>>0,a||Y(i,2,this.length);const l=this[i+1]|this[i]<<8;return l&32768?l|4294901760:l},u.prototype.readInt32LE=function(i,a){return i=i>>>0,a||Y(i,4,this.length),this[i]|this[i+1]<<8|this[i+2]<<16|this[i+3]<<24},u.prototype.readInt32BE=function(i,a){return i=i>>>0,a||Y(i,4,this.length),this[i]<<24|this[i+1]<<16|this[i+2]<<8|this[i+3]},u.prototype.readBigInt64LE=Ee(function(i){i=i>>>0,I(i,"offset");const a=this[i],l=this[i+7];(a===void 0||l===void 0)&&M(i,this.length-8);const b=this[i+4]+this[i+5]*2**8+this[i+6]*2**16+(l<<24);return(BigInt(b)<<BigInt(32))+BigInt(a+this[++i]*2**8+this[++i]*2**16+this[++i]*2**24)}),u.prototype.readBigInt64BE=Ee(function(i){i=i>>>0,I(i,"offset");const a=this[i],l=this[i+7];(a===void 0||l===void 0)&&M(i,this.length-8);const b=(a<<24)+this[++i]*2**16+this[++i]*2**8+this[++i];return(BigInt(b)<<BigInt(32))+BigInt(this[++i]*2**24+this[++i]*2**16+this[++i]*2**8+l)}),u.prototype.readFloatLE=function(i,a){return i=i>>>0,a||Y(i,4,this.length),r.read(this,i,!0,23,4)},u.prototype.readFloatBE=function(i,a){return i=i>>>0,a||Y(i,4,this.length),r.read(this,i,!1,23,4)},u.prototype.readDoubleLE=function(i,a){return i=i>>>0,a||Y(i,8,this.length),r.read(this,i,!0,52,8)},u.prototype.readDoubleBE=function(i,a){return i=i>>>0,a||Y(i,8,this.length),r.read(this,i,!1,52,8)};function ie(f,i,a,l,b,v){if(!u.isBuffer(f))throw new TypeError('"buffer" argument must be a Buffer instance');if(i>b||i<v)throw new RangeError('"value" argument is out of bounds');if(a+l>f.length)throw new RangeError("Index out of range")}u.prototype.writeUintLE=u.prototype.writeUIntLE=function(i,a,l,b){if(i=+i,a=a>>>0,l=l>>>0,!b){const G=Math.pow(2,8*l)-1;ie(this,i,a,l,G,0)}let v=1,B=0;for(this[a]=i&255;++B<l&&(v*=256);)this[a+B]=i/v&255;return a+l},u.prototype.writeUintBE=u.prototype.writeUIntBE=function(i,a,l,b){if(i=+i,a=a>>>0,l=l>>>0,!b){const G=Math.pow(2,8*l)-1;ie(this,i,a,l,G,0)}let v=l-1,B=1;for(this[a+v]=i&255;--v>=0&&(B*=256);)this[a+v]=i/B&255;return a+l},u.prototype.writeUint8=u.prototype.writeUInt8=function(i,a,l){return i=+i,a=a>>>0,l||ie(this,i,a,1,255,0),this[a]=i&255,a+1},u.prototype.writeUint16LE=u.prototype.writeUInt16LE=function(i,a,l){return i=+i,a=a>>>0,l||ie(this,i,a,2,65535,0),this[a]=i&255,this[a+1]=i>>>8,a+2},u.prototype.writeUint16BE=u.prototype.writeUInt16BE=function(i,a,l){return i=+i,a=a>>>0,l||ie(this,i,a,2,65535,0),this[a]=i>>>8,this[a+1]=i&255,a+2},u.prototype.writeUint32LE=u.prototype.writeUInt32LE=function(i,a,l){return i=+i,a=a>>>0,l||ie(this,i,a,4,4294967295,0),this[a+3]=i>>>24,this[a+2]=i>>>16,this[a+1]=i>>>8,this[a]=i&255,a+4},u.prototype.writeUint32BE=u.prototype.writeUInt32BE=function(i,a,l){return i=+i,a=a>>>0,l||ie(this,i,a,4,4294967295,0),this[a]=i>>>24,this[a+1]=i>>>16,this[a+2]=i>>>8,this[a+3]=i&255,a+4};function ve(f,i,a,l,b){d(i,l,b,f,a,7);let v=Number(i&BigInt(4294967295));f[a++]=v,v=v>>8,f[a++]=v,v=v>>8,f[a++]=v,v=v>>8,f[a++]=v;let B=Number(i>>BigInt(32)&BigInt(4294967295));return f[a++]=B,B=B>>8,f[a++]=B,B=B>>8,f[a++]=B,B=B>>8,f[a++]=B,a}function je(f,i,a,l,b){d(i,l,b,f,a,7);let v=Number(i&BigInt(4294967295));f[a+7]=v,v=v>>8,f[a+6]=v,v=v>>8,f[a+5]=v,v=v>>8,f[a+4]=v;let B=Number(i>>BigInt(32)&BigInt(4294967295));return f[a+3]=B,B=B>>8,f[a+2]=B,B=B>>8,f[a+1]=B,B=B>>8,f[a]=B,a+8}u.prototype.writeBigUInt64LE=Ee(function(i,a=0){return ve(this,i,a,BigInt(0),BigInt("0xffffffffffffffff"))}),u.prototype.writeBigUInt64BE=Ee(function(i,a=0){return je(this,i,a,BigInt(0),BigInt("0xffffffffffffffff"))}),u.prototype.writeIntLE=function(i,a,l,b){if(i=+i,a=a>>>0,!b){const re=Math.pow(2,8*l-1);ie(this,i,a,l,re-1,-re)}let v=0,B=1,G=0;for(this[a]=i&255;++v<l&&(B*=256);)i<0&&G===0&&this[a+v-1]!==0&&(G=1),this[a+v]=(i/B>>0)-G&255;return a+l},u.prototype.writeIntBE=function(i,a,l,b){if(i=+i,a=a>>>0,!b){const re=Math.pow(2,8*l-1);ie(this,i,a,l,re-1,-re)}let v=l-1,B=1,G=0;for(this[a+v]=i&255;--v>=0&&(B*=256);)i<0&&G===0&&this[a+v+1]!==0&&(G=1),this[a+v]=(i/B>>0)-G&255;return a+l},u.prototype.writeInt8=function(i,a,l){return i=+i,a=a>>>0,l||ie(this,i,a,1,127,-128),i<0&&(i=255+i+1),this[a]=i&255,a+1},u.prototype.writeInt16LE=function(i,a,l){return i=+i,a=a>>>0,l||ie(this,i,a,2,32767,-32768),this[a]=i&255,this[a+1]=i>>>8,a+2},u.prototype.writeInt16BE=function(i,a,l){return i=+i,a=a>>>0,l||ie(this,i,a,2,32767,-32768),this[a]=i>>>8,this[a+1]=i&255,a+2},u.prototype.writeInt32LE=function(i,a,l){return i=+i,a=a>>>0,l||ie(this,i,a,4,2147483647,-2147483648),this[a]=i&255,this[a+1]=i>>>8,this[a+2]=i>>>16,this[a+3]=i>>>24,a+4},u.prototype.writeInt32BE=function(i,a,l){return i=+i,a=a>>>0,l||ie(this,i,a,4,2147483647,-2147483648),i<0&&(i=4294967295+i+1),this[a]=i>>>24,this[a+1]=i>>>16,this[a+2]=i>>>8,this[a+3]=i&255,a+4},u.prototype.writeBigInt64LE=Ee(function(i,a=0){return ve(this,i,a,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),u.prototype.writeBigInt64BE=Ee(function(i,a=0){return je(this,i,a,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Ne(f,i,a,l,b,v){if(a+l>f.length)throw new RangeError("Index out of range");if(a<0)throw new RangeError("Index out of range")}function m(f,i,a,l,b){return i=+i,a=a>>>0,b||Ne(f,i,a,4),r.write(f,i,a,l,23,4),a+4}u.prototype.writeFloatLE=function(i,a,l){return m(this,i,a,!0,l)},u.prototype.writeFloatBE=function(i,a,l){return m(this,i,a,!1,l)};function _(f,i,a,l,b){return i=+i,a=a>>>0,b||Ne(f,i,a,8),r.write(f,i,a,l,52,8),a+8}u.prototype.writeDoubleLE=function(i,a,l){return _(this,i,a,!0,l)},u.prototype.writeDoubleBE=function(i,a,l){return _(this,i,a,!1,l)},u.prototype.copy=function(i,a,l,b){if(!u.isBuffer(i))throw new TypeError("argument should be a Buffer");if(l||(l=0),!b&&b!==0&&(b=this.length),a>=i.length&&(a=i.length),a||(a=0),b>0&&b<l&&(b=l),b===l||i.length===0||this.length===0)return 0;if(a<0)throw new RangeError("targetStart out of bounds");if(l<0||l>=this.length)throw new RangeError("Index out of range");if(b<0)throw new RangeError("sourceEnd out of bounds");b>this.length&&(b=this.length),i.length-a<b-l&&(b=i.length-a+l);const v=b-l;return this===i&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(a,l,b):Uint8Array.prototype.set.call(i,this.subarray(l,b),a),v},u.prototype.fill=function(i,a,l,b){if(typeof i=="string"){if(typeof a=="string"?(b=a,a=0,l=this.length):typeof l=="string"&&(b=l,l=this.length),b!==void 0&&typeof b!="string")throw new TypeError("encoding must be a string");if(typeof b=="string"&&!u.isEncoding(b))throw new TypeError("Unknown encoding: "+b);if(i.length===1){const B=i.charCodeAt(0);(b==="utf8"&&B<128||b==="latin1")&&(i=B)}}else typeof i=="number"?i=i&255:typeof i=="boolean"&&(i=Number(i));if(a<0||this.length<a||this.length<l)throw new RangeError("Out of range index");if(l<=a)return this;a=a>>>0,l=l===void 0?this.length:l>>>0,i||(i=0);let v;if(typeof i=="number")for(v=a;v<l;++v)this[v]=i;else{const B=u.isBuffer(i)?i:u.from(i,b),G=B.length;if(G===0)throw new TypeError('The value "'+i+'" is invalid for argument "value"');for(v=0;v<l-a;++v)this[v+a]=B[v%G]}return this};const A={};function $(f,i,a){A[f]=class extends a{constructor(){super(),Object.defineProperty(this,"message",{value:i.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${f}]`,this.stack,delete this.name}get code(){return f}set code(b){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:b,writable:!0})}toString(){return`${this.name} [${f}]: ${this.message}`}}}$("ERR_BUFFER_OUT_OF_BOUNDS",function(f){return f?`${f} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),$("ERR_INVALID_ARG_TYPE",function(f,i){return`The "${f}" argument must be of type number. Received type ${typeof i}`},TypeError),$("ERR_OUT_OF_RANGE",function(f,i,a){let l=`The value of "${f}" is out of range.`,b=a;return Number.isInteger(a)&&Math.abs(a)>2**32?b=q(String(a)):typeof a=="bigint"&&(b=String(a),(a>BigInt(2)**BigInt(32)||a<-(BigInt(2)**BigInt(32)))&&(b=q(b)),b+="n"),l+=` It must be ${i}. Received ${b}`,l},RangeError);function q(f){let i="",a=f.length;const l=f[0]==="-"?1:0;for(;a>=l+4;a-=3)i=`_${f.slice(a-3,a)}${i}`;return`${f.slice(0,a)}${i}`}function h(f,i,a){I(i,"offset"),(f[i]===void 0||f[i+a]===void 0)&&M(i,f.length-(a+1))}function d(f,i,a,l,b,v){if(f>a||f<i){const B=typeof i=="bigint"?"n":"";let G;throw i===0||i===BigInt(0)?G=`>= 0${B} and < 2${B} ** ${(v+1)*8}${B}`:G=`>= -(2${B} ** ${(v+1)*8-1}${B}) and < 2 ** ${(v+1)*8-1}${B}`,new A.ERR_OUT_OF_RANGE("value",G,f)}h(l,b,v)}function I(f,i){if(typeof f!="number")throw new A.ERR_INVALID_ARG_TYPE(i,"number",f)}function M(f,i,a){throw Math.floor(f)!==f?(I(f,a),new A.ERR_OUT_OF_RANGE("offset","an integer",f)):i<0?new A.ERR_BUFFER_OUT_OF_BOUNDS:new A.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${i}`,f)}const Q=/[^+/0-9A-Za-z-_]/g;function W(f){if(f=f.split("=")[0],f=f.trim().replace(Q,""),f.length<2)return"";for(;f.length%4!==0;)f=f+"=";return f}function z(f,i){i=i||1/0;let a;const l=f.length;let b=null;const v=[];for(let B=0;B<l;++B){if(a=f.charCodeAt(B),a>55295&&a<57344){if(!b){if(a>56319){(i-=3)>-1&&v.push(239,191,189);continue}else if(B+1===l){(i-=3)>-1&&v.push(239,191,189);continue}b=a;continue}if(a<56320){(i-=3)>-1&&v.push(239,191,189),b=a;continue}a=(b-55296<<10|a-56320)+65536}else b&&(i-=3)>-1&&v.push(239,191,189);if(b=null,a<128){if((i-=1)<0)break;v.push(a)}else if(a<2048){if((i-=2)<0)break;v.push(a>>6|192,a&63|128)}else if(a<65536){if((i-=3)<0)break;v.push(a>>12|224,a>>6&63|128,a&63|128)}else if(a<1114112){if((i-=4)<0)break;v.push(a>>18|240,a>>12&63|128,a>>6&63|128,a&63|128)}else throw new Error("Invalid code point")}return v}function qe(f){const i=[];for(let a=0;a<f.length;++a)i.push(f.charCodeAt(a)&255);return i}function rt(f,i){let a,l,b;const v=[];for(let B=0;B<f.length&&!((i-=2)<0);++B)a=f.charCodeAt(B),l=a>>8,b=a%256,v.push(b),v.push(l);return v}function yt(f){return t.toByteArray(W(f))}function nt(f,i,a,l){let b;for(b=0;b<l&&!(b+a>=i.length||b>=f.length);++b)i[b+a]=f[b];return b}function xe(f,i){return f instanceof i||f!=null&&f.constructor!=null&&f.constructor.name!=null&&f.constructor.name===i.name}function Je(f){return f!==f}const gt=function(){const f="0123456789abcdef",i=new Array(256);for(let a=0;a<16;++a){const l=a*16;for(let b=0;b<16;++b)i[l+b]=f[a]+f[b]}return i}();function Ee(f){return typeof BigInt>"u"?Ye:f}function Ye(){throw new Error("BigInt not supported")}})(pt);/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */(function(e,t){var r=pt,n=r.Buffer;function o(c,u){for(var p in c)u[p]=c[p]}n.from&&n.alloc&&n.allocUnsafe&&n.allocUnsafeSlow?e.exports=r:(o(r,t),t.Buffer=s);function s(c,u,p){return n(c,u,p)}s.prototype=Object.create(n.prototype),o(n,s),s.from=function(c,u,p){if(typeof c=="number")throw new TypeError("Argument must not be a number");return n(c,u,p)},s.alloc=function(c,u,p){if(typeof c!="number")throw new TypeError("Argument must be a number");var y=n(c);return u!==void 0?typeof p=="string"?y.fill(u,p):y.fill(u):y.fill(0),y},s.allocUnsafe=function(c){if(typeof c!="number")throw new TypeError("Argument must be a number");return n(c)},s.allocUnsafeSlow=function(c){if(typeof c!="number")throw new TypeError("Argument must be a number");return r.SlowBuffer(c)}})(Or,Or.exports);var we=Or.exports,lr=65536,to=4294967295;function ro(){throw new Error(`Secure random number generation is not supported by this browser.
29
+ Use Chrome, Firefox or Internet Explorer 11`)}var no=we.Buffer,Wt=ze.crypto||ze.msCrypto;Wt&&Wt.getRandomValues?Pr.exports=io:Pr.exports=ro;function io(e,t){if(e>to)throw new RangeError("requested too many random bytes");var r=no.allocUnsafe(e);if(e>0)if(e>lr)for(var n=0;n<e;n+=lr)Wt.getRandomValues(r.slice(n,n+lr));else Wt.getRandomValues(r);return typeof t=="function"?process.nextTick(function(){t(null,r)}):r}var ao=Pr.exports,Nr={exports:{}};typeof Object.create=="function"?Nr.exports=function(t,r){r&&(t.super_=r,t.prototype=Object.create(r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}))}:Nr.exports=function(t,r){if(r){t.super_=r;var n=function(){};n.prototype=r.prototype,t.prototype=new n,t.prototype.constructor=t}};var pe=Nr.exports,Fr={exports:{}},Gr={exports:{}},ut=typeof Reflect=="object"?Reflect:null,un=ut&&typeof ut.apply=="function"?ut.apply:function(t,r,n){return Function.prototype.apply.call(t,r,n)},Dt;ut&&typeof ut.ownKeys=="function"?Dt=ut.ownKeys:Object.getOwnPropertySymbols?Dt=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:Dt=function(t){return Object.getOwnPropertyNames(t)};function oo(e){console&&console.warn&&console.warn(e)}var ii=Number.isNaN||function(t){return t!==t};function K(){K.init.call(this)}Gr.exports=K;Gr.exports.once=co;K.EventEmitter=K;K.prototype._events=void 0;K.prototype._eventsCount=0;K.prototype._maxListeners=void 0;var cn=10;function Yt(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(K,"defaultMaxListeners",{enumerable:!0,get:function(){return cn},set:function(e){if(typeof e!="number"||e<0||ii(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");cn=e}});K.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0};K.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||ii(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this};function ai(e){return e._maxListeners===void 0?K.defaultMaxListeners:e._maxListeners}K.prototype.getMaxListeners=function(){return ai(this)};K.prototype.emit=function(t){for(var r=[],n=1;n<arguments.length;n++)r.push(arguments[n]);var o=t==="error",s=this._events;if(s!==void 0)o=o&&s.error===void 0;else if(!o)return!1;if(o){var c;if(r.length>0&&(c=r[0]),c instanceof Error)throw c;var u=new Error("Unhandled error."+(c?" ("+c.message+")":""));throw u.context=c,u}var p=s[t];if(p===void 0)return!1;if(typeof p=="function")un(p,this,r);else for(var y=p.length,g=ci(p,y),n=0;n<y;++n)un(g[n],this,r);return!0};function oi(e,t,r,n){var o,s,c;if(Yt(r),s=e._events,s===void 0?(s=e._events=Object.create(null),e._eventsCount=0):(s.newListener!==void 0&&(e.emit("newListener",t,r.listener?r.listener:r),s=e._events),c=s[t]),c===void 0)c=s[t]=r,++e._eventsCount;else if(typeof c=="function"?c=s[t]=n?[r,c]:[c,r]:n?c.unshift(r):c.push(r),o=ai(e),o>0&&c.length>o&&!c.warned){c.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+c.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=c.length,oo(u)}return e}K.prototype.addListener=function(t,r){return oi(this,t,r,!1)};K.prototype.on=K.prototype.addListener;K.prototype.prependListener=function(t,r){return oi(this,t,r,!0)};function so(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function si(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},o=so.bind(n);return o.listener=r,n.wrapFn=o,o}K.prototype.once=function(t,r){return Yt(r),this.on(t,si(this,t,r)),this};K.prototype.prependOnceListener=function(t,r){return Yt(r),this.prependListener(t,si(this,t,r)),this};K.prototype.removeListener=function(t,r){var n,o,s,c,u;if(Yt(r),o=this._events,o===void 0)return this;if(n=o[t],n===void 0)return this;if(n===r||n.listener===r)--this._eventsCount===0?this._events=Object.create(null):(delete o[t],o.removeListener&&this.emit("removeListener",t,n.listener||r));else if(typeof n!="function"){for(s=-1,c=n.length-1;c>=0;c--)if(n[c]===r||n[c].listener===r){u=n[c].listener,s=c;break}if(s<0)return this;s===0?n.shift():fo(n,s),n.length===1&&(o[t]=n[0]),o.removeListener!==void 0&&this.emit("removeListener",t,u||r)}return this};K.prototype.off=K.prototype.removeListener;K.prototype.removeAllListeners=function(t){var r,n,o;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[t]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[t]),this;if(arguments.length===0){var s=Object.keys(n),c;for(o=0;o<s.length;++o)c=s[o],c!=="removeListener"&&this.removeAllListeners(c);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(r=n[t],typeof r=="function")this.removeListener(t,r);else if(r!==void 0)for(o=r.length-1;o>=0;o--)this.removeListener(t,r[o]);return this};function fi(e,t,r){var n=e._events;if(n===void 0)return[];var o=n[t];return o===void 0?[]:typeof o=="function"?r?[o.listener||o]:[o]:r?uo(o):ci(o,o.length)}K.prototype.listeners=function(t){return fi(this,t,!0)};K.prototype.rawListeners=function(t){return fi(this,t,!1)};K.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):ui.call(e,t)};K.prototype.listenerCount=ui;function ui(e){var t=this._events;if(t!==void 0){var r=t[e];if(typeof r=="function")return 1;if(r!==void 0)return r.length}return 0}K.prototype.eventNames=function(){return this._eventsCount>0?Dt(this._events):[]};function ci(e,t){for(var r=new Array(t),n=0;n<t;++n)r[n]=e[n];return r}function fo(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function uo(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}function co(e,t){return new Promise(function(r,n){function o(c){e.removeListener(t,s),n(c)}function s(){typeof e.removeListener=="function"&&e.removeListener("error",o),r([].slice.call(arguments))}li(e,t,s,{once:!0}),t!=="error"&&lo(e,o,{once:!0})})}function lo(e,t,r){typeof e.on=="function"&&li(e,"error",t,r)}function li(e,t,r,n){if(typeof e.on=="function")n.once?e.once(t,r):e.on(t,r);else if(typeof e.addEventListener=="function")e.addEventListener(t,function o(s){n.once&&e.removeEventListener(t,o),r(s)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e)}var hi=Gr.exports,di=hi.EventEmitter;const ho={},po=Object.freeze(Object.defineProperty({__proto__:null,default:ho},Symbol.toStringTag,{value:"Module"})),zr=Da(po);var hr,ln;function bo(){if(ln)return hr;ln=1;function e(R,C){var E=Object.keys(R);if(Object.getOwnPropertySymbols){var T=Object.getOwnPropertySymbols(R);C&&(T=T.filter(function(O){return Object.getOwnPropertyDescriptor(R,O).enumerable})),E.push.apply(E,T)}return E}function t(R){for(var C=1;C<arguments.length;C++){var E=arguments[C]!=null?arguments[C]:{};C%2?e(Object(E),!0).forEach(function(T){r(R,T,E[T])}):Object.getOwnPropertyDescriptors?Object.defineProperties(R,Object.getOwnPropertyDescriptors(E)):e(Object(E)).forEach(function(T){Object.defineProperty(R,T,Object.getOwnPropertyDescriptor(E,T))})}return R}function r(R,C,E){return C=c(C),C in R?Object.defineProperty(R,C,{value:E,enumerable:!0,configurable:!0,writable:!0}):R[C]=E,R}function n(R,C){if(!(R instanceof C))throw new TypeError("Cannot call a class as a function")}function o(R,C){for(var E=0;E<C.length;E++){var T=C[E];T.enumerable=T.enumerable||!1,T.configurable=!0,"value"in T&&(T.writable=!0),Object.defineProperty(R,c(T.key),T)}}function s(R,C,E){return C&&o(R.prototype,C),Object.defineProperty(R,"prototype",{writable:!1}),R}function c(R){var C=u(R,"string");return typeof C=="symbol"?C:String(C)}function u(R,C){if(typeof R!="object"||R===null)return R;var E=R[Symbol.toPrimitive];if(E!==void 0){var T=E.call(R,C||"default");if(typeof T!="object")return T;throw new TypeError("@@toPrimitive must return a primitive value.")}return(C==="string"?String:Number)(R)}var p=pt,y=p.Buffer,g=zr,w=g.inspect,x=w&&w.custom||"inspect";function k(R,C,E){y.prototype.copy.call(R,C,E)}return hr=function(){function R(){n(this,R),this.head=null,this.tail=null,this.length=0}return s(R,[{key:"push",value:function(E){var T={data:E,next:null};this.length>0?this.tail.next=T:this.head=T,this.tail=T,++this.length}},{key:"unshift",value:function(E){var T={data:E,next:this.head};this.length===0&&(this.tail=T),this.head=T,++this.length}},{key:"shift",value:function(){if(this.length!==0){var E=this.head.data;return this.length===1?this.head=this.tail=null:this.head=this.head.next,--this.length,E}}},{key:"clear",value:function(){this.head=this.tail=null,this.length=0}},{key:"join",value:function(E){if(this.length===0)return"";for(var T=this.head,O=""+T.data;T=T.next;)O+=E+T.data;return O}},{key:"concat",value:function(E){if(this.length===0)return y.alloc(0);for(var T=y.allocUnsafe(E>>>0),O=this.head,F=0;O;)k(O.data,T,F),F+=O.data.length,O=O.next;return T}},{key:"consume",value:function(E,T){var O;return E<this.head.data.length?(O=this.head.data.slice(0,E),this.head.data=this.head.data.slice(E)):E===this.head.data.length?O=this.shift():O=T?this._getString(E):this._getBuffer(E),O}},{key:"first",value:function(){return this.head.data}},{key:"_getString",value:function(E){var T=this.head,O=1,F=T.data;for(E-=F.length;T=T.next;){var N=T.data,L=E>N.length?N.length:E;if(L===N.length?F+=N:F+=N.slice(0,E),E-=L,E===0){L===N.length?(++O,T.next?this.head=T.next:this.head=this.tail=null):(this.head=T,T.data=N.slice(L));break}++O}return this.length-=O,F}},{key:"_getBuffer",value:function(E){var T=y.allocUnsafe(E),O=this.head,F=1;for(O.data.copy(T),E-=O.data.length;O=O.next;){var N=O.data,L=E>N.length?N.length:E;if(N.copy(T,T.length-E,0,L),E-=L,E===0){L===N.length?(++F,O.next?this.head=O.next:this.head=this.tail=null):(this.head=O,O.data=N.slice(L));break}++F}return this.length-=F,T}},{key:x,value:function(E,T){return w(this,t(t({},T),{},{depth:0,customInspect:!1}))}}]),R}(),hr}function yo(e,t){var r=this,n=this._readableState&&this._readableState.destroyed,o=this._writableState&&this._writableState.destroyed;return n||o?(t?t(e):e&&(this._writableState?this._writableState.errorEmitted||(this._writableState.errorEmitted=!0,process.nextTick(Lr,this,e)):process.nextTick(Lr,this,e)),this):(this._readableState&&(this._readableState.destroyed=!0),this._writableState&&(this._writableState.destroyed=!0),this._destroy(e||null,function(s){!t&&s?r._writableState?r._writableState.errorEmitted?process.nextTick($t,r):(r._writableState.errorEmitted=!0,process.nextTick(hn,r,s)):process.nextTick(hn,r,s):t?(process.nextTick($t,r),t(s)):process.nextTick($t,r)}),this)}function hn(e,t){Lr(e,t),$t(e)}function $t(e){e._writableState&&!e._writableState.emitClose||e._readableState&&!e._readableState.emitClose||e.emit("close")}function go(){this._readableState&&(this._readableState.destroyed=!1,this._readableState.reading=!1,this._readableState.ended=!1,this._readableState.endEmitted=!1),this._writableState&&(this._writableState.destroyed=!1,this._writableState.ended=!1,this._writableState.ending=!1,this._writableState.finalCalled=!1,this._writableState.prefinished=!1,this._writableState.finished=!1,this._writableState.errorEmitted=!1)}function Lr(e,t){e.emit("error",t)}function _o(e,t){var r=e._readableState,n=e._writableState;r&&r.autoDestroy||n&&n.autoDestroy?e.destroy(t):e.emit("error",t)}var pi={destroy:yo,undestroy:go,errorOrDestroy:_o},et={};function mo(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var bi={};function Se(e,t,r){r||(r=Error);function n(s,c,u){return typeof t=="string"?t:t(s,c,u)}var o=function(s){mo(c,s);function c(u,p,y){return s.call(this,n(u,p,y))||this}return c}(r);o.prototype.name=r.name,o.prototype.code=e,bi[e]=o}function dn(e,t){if(Array.isArray(e)){var r=e.length;return e=e.map(function(n){return String(n)}),r>2?"one of ".concat(t," ").concat(e.slice(0,r-1).join(", "),", or ")+e[r-1]:r===2?"one of ".concat(t," ").concat(e[0]," or ").concat(e[1]):"of ".concat(t," ").concat(e[0])}else return"of ".concat(t," ").concat(String(e))}function wo(e,t,r){return e.substr(0,t.length)===t}function vo(e,t,r){return(r===void 0||r>e.length)&&(r=e.length),e.substring(r-t.length,r)===t}function xo(e,t,r){return typeof r!="number"&&(r=0),r+t.length>e.length?!1:e.indexOf(t,r)!==-1}Se("ERR_INVALID_OPT_VALUE",function(e,t){return'The value "'+t+'" is invalid for option "'+e+'"'},TypeError);Se("ERR_INVALID_ARG_TYPE",function(e,t,r){var n;typeof t=="string"&&wo(t,"not ")?(n="must not be",t=t.replace(/^not /,"")):n="must be";var o;if(vo(e," argument"))o="The ".concat(e," ").concat(n," ").concat(dn(t,"type"));else{var s=xo(e,".")?"property":"argument";o='The "'.concat(e,'" ').concat(s," ").concat(n," ").concat(dn(t,"type"))}return o+=". Received type ".concat(typeof r),o},TypeError);Se("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF");Se("ERR_METHOD_NOT_IMPLEMENTED",function(e){return"The "+e+" method is not implemented"});Se("ERR_STREAM_PREMATURE_CLOSE","Premature close");Se("ERR_STREAM_DESTROYED",function(e){return"Cannot call "+e+" after a stream was destroyed"});Se("ERR_MULTIPLE_CALLBACK","Callback called multiple times");Se("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable");Se("ERR_STREAM_WRITE_AFTER_END","write after end");Se("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError);Se("ERR_UNKNOWN_ENCODING",function(e){return"Unknown encoding: "+e},TypeError);Se("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event");et.codes=bi;var Eo=et.codes.ERR_INVALID_OPT_VALUE;function Bo(e,t,r){return e.highWaterMark!=null?e.highWaterMark:t?e[r]:null}function Ro(e,t,r,n){var o=Bo(t,n,r);if(o!=null){if(!(isFinite(o)&&Math.floor(o)===o)||o<0){var s=n?r:"highWaterMark";throw new Eo(s,o)}return Math.floor(o)}return e.objectMode?16:16*1024}var yi={getHighWaterMark:Ro},So=Io;function Io(e,t){if(dr("noDeprecation"))return e;var r=!1;function n(){if(!r){if(dr("throwDeprecation"))throw new Error(t);dr("traceDeprecation")?console.trace(t):console.warn(t),r=!0}return e.apply(this,arguments)}return n}function dr(e){try{if(!ze.localStorage)return!1}catch{return!1}var t=ze.localStorage[e];return t==null?!1:String(t).toLowerCase()==="true"}var pr,pn;function gi(){if(pn)return pr;pn=1,pr=D;function e(m){var _=this;this.next=null,this.entry=null,this.finish=function(){Ne(_,m)}}var t;D.WritableState=S;var r={deprecate:So},n=di,o=pt.Buffer,s=(typeof ze<"u"?ze:typeof window<"u"?window:typeof self<"u"?self:{}).Uint8Array||function(){};function c(m){return o.from(m)}function u(m){return o.isBuffer(m)||m instanceof s}var p=pi,y=yi,g=y.getHighWaterMark,w=et.codes,x=w.ERR_INVALID_ARG_TYPE,k=w.ERR_METHOD_NOT_IMPLEMENTED,R=w.ERR_MULTIPLE_CALLBACK,C=w.ERR_STREAM_CANNOT_PIPE,E=w.ERR_STREAM_DESTROYED,T=w.ERR_STREAM_NULL_VALUES,O=w.ERR_STREAM_WRITE_AFTER_END,F=w.ERR_UNKNOWN_ENCODING,N=p.errorOrDestroy;pe(D,n);function L(){}function S(m,_,A){t=t||dt(),m=m||{},typeof A!="boolean"&&(A=_ instanceof t),this.objectMode=!!m.objectMode,A&&(this.objectMode=this.objectMode||!!m.writableObjectMode),this.highWaterMark=g(this,m,"writableHighWaterMark",A),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var $=m.decodeStrings===!1;this.decodeStrings=!$,this.defaultEncoding=m.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(q){Ve(_,q)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=m.emitClose!==!1,this.autoDestroy=!!m.autoDestroy,this.bufferedRequestCount=0,this.corkedRequestsFree=new e(this)}S.prototype.getBuffer=function(){for(var _=this.bufferedRequest,A=[];_;)A.push(_),_=_.next;return A},function(){try{Object.defineProperty(S.prototype,"buffer",{get:r.deprecate(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch{}}();var j;typeof Symbol=="function"&&Symbol.hasInstance&&typeof Function.prototype[Symbol.hasInstance]=="function"?(j=Function.prototype[Symbol.hasInstance],Object.defineProperty(D,Symbol.hasInstance,{value:function(_){return j.call(this,_)?!0:this!==D?!1:_&&_._writableState instanceof S}})):j=function(_){return _ instanceof this};function D(m){t=t||dt();var _=this instanceof t;if(!_&&!j.call(D,this))return new D(m);this._writableState=new S(m,this,_),this.writable=!0,m&&(typeof m.write=="function"&&(this._write=m.write),typeof m.writev=="function"&&(this._writev=m.writev),typeof m.destroy=="function"&&(this._destroy=m.destroy),typeof m.final=="function"&&(this._final=m.final)),n.call(this)}D.prototype.pipe=function(){N(this,new C)};function U(m,_){var A=new O;N(m,A),process.nextTick(_,A)}function ee(m,_,A,$){var q;return A===null?q=new T:typeof A!="string"&&!_.objectMode&&(q=new x("chunk",["string","Buffer"],A)),q?(N(m,q),process.nextTick($,q),!1):!0}D.prototype.write=function(m,_,A){var $=this._writableState,q=!1,h=!$.objectMode&&u(m);return h&&!o.isBuffer(m)&&(m=c(m)),typeof _=="function"&&(A=_,_=null),h?_="buffer":_||(_=$.defaultEncoding),typeof A!="function"&&(A=L),$.ending?U(this,A):(h||ee(this,$,m,A))&&($.pendingcb++,q=De(this,$,h,m,_,A)),q},D.prototype.cork=function(){this._writableState.corked++},D.prototype.uncork=function(){var m=this._writableState;m.corked&&(m.corked--,!m.writing&&!m.corked&&!m.bufferProcessing&&m.bufferedRequest&&Te(this,m))},D.prototype.setDefaultEncoding=function(_){if(typeof _=="string"&&(_=_.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((_+"").toLowerCase())>-1))throw new F(_);return this._writableState.defaultEncoding=_,this},Object.defineProperty(D.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}});function Ie(m,_,A){return!m.objectMode&&m.decodeStrings!==!1&&typeof _=="string"&&(_=o.from(_,A)),_}Object.defineProperty(D.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}});function De(m,_,A,$,q,h){if(!A){var d=Ie(_,$,q);$!==d&&(A=!0,q="buffer",$=d)}var I=_.objectMode?1:$.length;_.length+=I;var M=_.length<_.highWaterMark;if(M||(_.needDrain=!0),_.writing||_.corked){var Q=_.lastBufferedRequest;_.lastBufferedRequest={chunk:$,encoding:q,isBuf:A,callback:h,next:null},Q?Q.next=_.lastBufferedRequest:_.bufferedRequest=_.lastBufferedRequest,_.bufferedRequestCount+=1}else ae(m,_,!1,I,$,q,h);return M}function ae(m,_,A,$,q,h,d){_.writelen=$,_.writecb=d,_.writing=!0,_.sync=!0,_.destroyed?_.onwrite(new E("write")):A?m._writev(q,_.onwrite):m._write(q,h,_.onwrite),_.sync=!1}function _e(m,_,A,$,q){--_.pendingcb,A?(process.nextTick(q,$),process.nextTick(ve,m,_),m._writableState.errorEmitted=!0,N(m,$)):(q($),m._writableState.errorEmitted=!0,N(m,$),ve(m,_))}function me(m){m.writing=!1,m.writecb=null,m.length-=m.writelen,m.writelen=0}function Ve(m,_){var A=m._writableState,$=A.sync,q=A.writecb;if(typeof q!="function")throw new R;if(me(A),_)_e(m,A,$,_,q);else{var h=He(A)||m.destroyed;!h&&!A.corked&&!A.bufferProcessing&&A.bufferedRequest&&Te(m,A),$?process.nextTick(ke,m,A,h,q):ke(m,A,h,q)}}function ke(m,_,A,$){A||$e(m,_),_.pendingcb--,$(),ve(m,_)}function $e(m,_){_.length===0&&_.needDrain&&(_.needDrain=!1,m.emit("drain"))}function Te(m,_){_.bufferProcessing=!0;var A=_.bufferedRequest;if(m._writev&&A&&A.next){var $=_.bufferedRequestCount,q=new Array($),h=_.corkedRequestsFree;h.entry=A;for(var d=0,I=!0;A;)q[d]=A,A.isBuf||(I=!1),A=A.next,d+=1;q.allBuffers=I,ae(m,_,!0,_.length,q,"",h.finish),_.pendingcb++,_.lastBufferedRequest=null,h.next?(_.corkedRequestsFree=h.next,h.next=null):_.corkedRequestsFree=new e(_),_.bufferedRequestCount=0}else{for(;A;){var M=A.chunk,Q=A.encoding,W=A.callback,z=_.objectMode?1:M.length;if(ae(m,_,!1,z,M,Q,W),A=A.next,_.bufferedRequestCount--,_.writing)break}A===null&&(_.lastBufferedRequest=null)}_.bufferedRequest=A,_.bufferProcessing=!1}D.prototype._write=function(m,_,A){A(new k("_write()"))},D.prototype._writev=null,D.prototype.end=function(m,_,A){var $=this._writableState;return typeof m=="function"?(A=m,m=null,_=null):typeof _=="function"&&(A=_,_=null),m!=null&&this.write(m,_),$.corked&&($.corked=1,this.uncork()),$.ending||je(this,$,A),this},Object.defineProperty(D.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}});function He(m){return m.ending&&m.length===0&&m.bufferedRequest===null&&!m.finished&&!m.writing}function Y(m,_){m._final(function(A){_.pendingcb--,A&&N(m,A),_.prefinished=!0,m.emit("prefinish"),ve(m,_)})}function ie(m,_){!_.prefinished&&!_.finalCalled&&(typeof m._final=="function"&&!_.destroyed?(_.pendingcb++,_.finalCalled=!0,process.nextTick(Y,m,_)):(_.prefinished=!0,m.emit("prefinish")))}function ve(m,_){var A=He(_);if(A&&(ie(m,_),_.pendingcb===0&&(_.finished=!0,m.emit("finish"),_.autoDestroy))){var $=m._readableState;(!$||$.autoDestroy&&$.endEmitted)&&m.destroy()}return A}function je(m,_,A){_.ending=!0,ve(m,_),A&&(_.finished?process.nextTick(A):m.once("finish",A)),_.ended=!0,m.writable=!1}function Ne(m,_,A){var $=m.entry;for(m.entry=null;$;){var q=$.callback;_.pendingcb--,q(A),$=$.next}_.corkedRequestsFree.next=m}return Object.defineProperty(D.prototype,"destroyed",{enumerable:!1,get:function(){return this._writableState===void 0?!1:this._writableState.destroyed},set:function(_){this._writableState&&(this._writableState.destroyed=_)}}),D.prototype.destroy=p.destroy,D.prototype._undestroy=p.undestroy,D.prototype._destroy=function(m,_){_(m)},pr}var br,bn;function dt(){if(bn)return br;bn=1;var e=Object.keys||function(y){var g=[];for(var w in y)g.push(w);return g};br=c;var t=mi(),r=gi();pe(c,t);for(var n=e(r.prototype),o=0;o<n.length;o++){var s=n[o];c.prototype[s]||(c.prototype[s]=r.prototype[s])}function c(y){if(!(this instanceof c))return new c(y);t.call(this,y),r.call(this,y),this.allowHalfOpen=!0,y&&(y.readable===!1&&(this.readable=!1),y.writable===!1&&(this.writable=!1),y.allowHalfOpen===!1&&(this.allowHalfOpen=!1,this.once("end",u)))}Object.defineProperty(c.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),Object.defineProperty(c.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(c.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}});function u(){this._writableState.ended||process.nextTick(p,this)}function p(y){y.end()}return Object.defineProperty(c.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState===void 0||this._writableState===void 0?!1:this._readableState.destroyed&&this._writableState.destroyed},set:function(g){this._readableState===void 0||this._writableState===void 0||(this._readableState.destroyed=g,this._writableState.destroyed=g)}}),br}var Gt={},Kr=we.Buffer,yn=Kr.isEncoding||function(e){switch(e=""+e,e&&e.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};function ko(e){if(!e)return"utf8";for(var t;;)switch(e){case"utf8":case"utf-8":return"utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return"utf16le";case"latin1":case"binary":return"latin1";case"base64":case"ascii":case"hex":return e;default:if(t)return;e=(""+e).toLowerCase(),t=!0}}function To(e){var t=ko(e);if(typeof t!="string"&&(Kr.isEncoding===yn||!yn(e)))throw new Error("Unknown encoding: "+e);return t||e}Gt.StringDecoder=Tt;function Tt(e){this.encoding=To(e);var t;switch(this.encoding){case"utf16le":this.text=Fo,this.end=Lo,t=4;break;case"utf8":this.fillLast=Po,t=4;break;case"base64":this.text=Mo,this.end=Uo,t=3;break;default:this.write=Do,this.end=$o;return}this.lastNeed=0,this.lastTotal=0,this.lastChar=Kr.allocUnsafe(t)}Tt.prototype.write=function(e){if(e.length===0)return"";var t,r;if(this.lastNeed){if(t=this.fillLast(e),t===void 0)return"";r=this.lastNeed,this.lastNeed=0}else r=0;return r<e.length?t?t+this.text(e,r):this.text(e,r):t||""};Tt.prototype.end=No;Tt.prototype.text=Oo;Tt.prototype.fillLast=function(e){if(this.lastNeed<=e.length)return e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,e.length),this.lastNeed-=e.length};function yr(e){return e<=127?0:e>>5===6?2:e>>4===14?3:e>>3===30?4:e>>6===2?-1:-2}function Ao(e,t,r){var n=t.length-1;if(n<r)return 0;var o=yr(t[n]);return o>=0?(o>0&&(e.lastNeed=o-1),o):--n<r||o===-2?0:(o=yr(t[n]),o>=0?(o>0&&(e.lastNeed=o-2),o):--n<r||o===-2?0:(o=yr(t[n]),o>=0?(o>0&&(o===2?o=0:e.lastNeed=o-3),o):0))}function Co(e,t,r){if((t[0]&192)!==128)return e.lastNeed=0,"�";if(e.lastNeed>1&&t.length>1){if((t[1]&192)!==128)return e.lastNeed=1,"�";if(e.lastNeed>2&&t.length>2&&(t[2]&192)!==128)return e.lastNeed=2,"�"}}function Po(e){var t=this.lastTotal-this.lastNeed,r=Co(this,e);if(r!==void 0)return r;if(this.lastNeed<=e.length)return e.copy(this.lastChar,t,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);e.copy(this.lastChar,t,0,e.length),this.lastNeed-=e.length}function Oo(e,t){var r=Ao(this,e,t);if(!this.lastNeed)return e.toString("utf8",t);this.lastTotal=r;var n=e.length-(r-this.lastNeed);return e.copy(this.lastChar,0,n),e.toString("utf8",t,n)}function No(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+"�":t}function Fo(e,t){if((e.length-t)%2===0){var r=e.toString("utf16le",t);if(r){var n=r.charCodeAt(r.length-1);if(n>=55296&&n<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1],r.slice(0,-1)}return r}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=e[e.length-1],e.toString("utf16le",t,e.length-1)}function Lo(e){var t=e&&e.length?this.write(e):"";if(this.lastNeed){var r=this.lastTotal-this.lastNeed;return t+this.lastChar.toString("utf16le",0,r)}return t}function Mo(e,t){var r=(e.length-t)%3;return r===0?e.toString("base64",t):(this.lastNeed=3-r,this.lastTotal=3,r===1?this.lastChar[0]=e[e.length-1]:(this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1]),e.toString("base64",t,e.length-r))}function Uo(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+this.lastChar.toString("base64",0,3-this.lastNeed):t}function Do(e){return e.toString(this.encoding)}function $o(e){return e&&e.length?this.write(e):""}var gn=et.codes.ERR_STREAM_PREMATURE_CLOSE;function Ho(e){var t=!1;return function(){if(!t){t=!0;for(var r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];e.apply(this,n)}}}function jo(){}function qo(e){return e.setHeader&&typeof e.abort=="function"}function _i(e,t,r){if(typeof t=="function")return _i(e,null,t);t||(t={}),r=Ho(r||jo);var n=t.readable||t.readable!==!1&&e.readable,o=t.writable||t.writable!==!1&&e.writable,s=function(){e.writable||u()},c=e._writableState&&e._writableState.finished,u=function(){o=!1,c=!0,n||r.call(e)},p=e._readableState&&e._readableState.endEmitted,y=function(){n=!1,p=!0,o||r.call(e)},g=function(R){r.call(e,R)},w=function(){var R;if(n&&!p)return(!e._readableState||!e._readableState.ended)&&(R=new gn),r.call(e,R);if(o&&!c)return(!e._writableState||!e._writableState.ended)&&(R=new gn),r.call(e,R)},x=function(){e.req.on("finish",u)};return qo(e)?(e.on("complete",u),e.on("abort",w),e.req?x():e.on("request",x)):o&&!e._writableState&&(e.on("end",s),e.on("close",s)),e.on("end",y),e.on("finish",u),t.error!==!1&&e.on("error",g),e.on("close",w),function(){e.removeListener("complete",u),e.removeListener("abort",w),e.removeListener("request",x),e.req&&e.req.removeListener("finish",u),e.removeListener("end",s),e.removeListener("close",s),e.removeListener("finish",u),e.removeListener("end",y),e.removeListener("error",g),e.removeListener("close",w)}}var Vr=_i,gr,_n;function Wo(){if(_n)return gr;_n=1;var e;function t(F,N,L){return N=r(N),N in F?Object.defineProperty(F,N,{value:L,enumerable:!0,configurable:!0,writable:!0}):F[N]=L,F}function r(F){var N=n(F,"string");return typeof N=="symbol"?N:String(N)}function n(F,N){if(typeof F!="object"||F===null)return F;var L=F[Symbol.toPrimitive];if(L!==void 0){var S=L.call(F,N||"default");if(typeof S!="object")return S;throw new TypeError("@@toPrimitive must return a primitive value.")}return(N==="string"?String:Number)(F)}var o=Vr,s=Symbol("lastResolve"),c=Symbol("lastReject"),u=Symbol("error"),p=Symbol("ended"),y=Symbol("lastPromise"),g=Symbol("handlePromise"),w=Symbol("stream");function x(F,N){return{value:F,done:N}}function k(F){var N=F[s];if(N!==null){var L=F[w].read();L!==null&&(F[y]=null,F[s]=null,F[c]=null,N(x(L,!1)))}}function R(F){process.nextTick(k,F)}function C(F,N){return function(L,S){F.then(function(){if(N[p]){L(x(void 0,!0));return}N[g](L,S)},S)}}var E=Object.getPrototypeOf(function(){}),T=Object.setPrototypeOf((e={get stream(){return this[w]},next:function(){var N=this,L=this[u];if(L!==null)return Promise.reject(L);if(this[p])return Promise.resolve(x(void 0,!0));if(this[w].destroyed)return new Promise(function(U,ee){process.nextTick(function(){N[u]?ee(N[u]):U(x(void 0,!0))})});var S=this[y],j;if(S)j=new Promise(C(S,this));else{var D=this[w].read();if(D!==null)return Promise.resolve(x(D,!1));j=new Promise(this[g])}return this[y]=j,j}},t(e,Symbol.asyncIterator,function(){return this}),t(e,"return",function(){var N=this;return new Promise(function(L,S){N[w].destroy(null,function(j){if(j){S(j);return}L(x(void 0,!0))})})}),e),E),O=function(N){var L,S=Object.create(T,(L={},t(L,w,{value:N,writable:!0}),t(L,s,{value:null,writable:!0}),t(L,c,{value:null,writable:!0}),t(L,u,{value:null,writable:!0}),t(L,p,{value:N._readableState.endEmitted,writable:!0}),t(L,g,{value:function(D,U){var ee=S[w].read();ee?(S[y]=null,S[s]=null,S[c]=null,D(x(ee,!1))):(S[s]=D,S[c]=U)},writable:!0}),L));return S[y]=null,o(N,function(j){if(j&&j.code!=="ERR_STREAM_PREMATURE_CLOSE"){var D=S[c];D!==null&&(S[y]=null,S[s]=null,S[c]=null,D(j)),S[u]=j;return}var U=S[s];U!==null&&(S[y]=null,S[s]=null,S[c]=null,U(x(void 0,!0))),S[p]=!0}),N.on("readable",R.bind(null,S)),S};return gr=O,gr}var _r,mn;function Go(){return mn||(mn=1,_r=function(){throw new Error("Readable.from is not available in the browser")}),_r}var mr,wn;function mi(){if(wn)return mr;wn=1,mr=U;var e;U.ReadableState=D,hi.EventEmitter;var t=function(d,I){return d.listeners(I).length},r=di,n=pt.Buffer,o=(typeof ze<"u"?ze:typeof window<"u"?window:typeof self<"u"?self:{}).Uint8Array||function(){};function s(h){return n.from(h)}function c(h){return n.isBuffer(h)||h instanceof o}var u=zr,p;u&&u.debuglog?p=u.debuglog("stream"):p=function(){};var y=bo(),g=pi,w=yi,x=w.getHighWaterMark,k=et.codes,R=k.ERR_INVALID_ARG_TYPE,C=k.ERR_STREAM_PUSH_AFTER_EOF,E=k.ERR_METHOD_NOT_IMPLEMENTED,T=k.ERR_STREAM_UNSHIFT_AFTER_END_EVENT,O,F,N;pe(U,r);var L=g.errorOrDestroy,S=["error","close","destroy","pause","resume"];function j(h,d,I){if(typeof h.prependListener=="function")return h.prependListener(d,I);!h._events||!h._events[d]?h.on(d,I):Array.isArray(h._events[d])?h._events[d].unshift(I):h._events[d]=[I,h._events[d]]}function D(h,d,I){e=e||dt(),h=h||{},typeof I!="boolean"&&(I=d instanceof e),this.objectMode=!!h.objectMode,I&&(this.objectMode=this.objectMode||!!h.readableObjectMode),this.highWaterMark=x(this,h,"readableHighWaterMark",I),this.buffer=new y,this.length=0,this.pipes=null,this.pipesCount=0,this.flowing=null,this.ended=!1,this.endEmitted=!1,this.reading=!1,this.sync=!0,this.needReadable=!1,this.emittedReadable=!1,this.readableListening=!1,this.resumeScheduled=!1,this.paused=!0,this.emitClose=h.emitClose!==!1,this.autoDestroy=!!h.autoDestroy,this.destroyed=!1,this.defaultEncoding=h.defaultEncoding||"utf8",this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,h.encoding&&(O||(O=Gt.StringDecoder),this.decoder=new O(h.encoding),this.encoding=h.encoding)}function U(h){if(e=e||dt(),!(this instanceof U))return new U(h);var d=this instanceof e;this._readableState=new D(h,this,d),this.readable=!0,h&&(typeof h.read=="function"&&(this._read=h.read),typeof h.destroy=="function"&&(this._destroy=h.destroy)),r.call(this)}Object.defineProperty(U.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState===void 0?!1:this._readableState.destroyed},set:function(d){this._readableState&&(this._readableState.destroyed=d)}}),U.prototype.destroy=g.destroy,U.prototype._undestroy=g.undestroy,U.prototype._destroy=function(h,d){d(h)},U.prototype.push=function(h,d){var I=this._readableState,M;return I.objectMode?M=!0:typeof h=="string"&&(d=d||I.defaultEncoding,d!==I.encoding&&(h=n.from(h,d),d=""),M=!0),ee(this,h,d,!1,M)},U.prototype.unshift=function(h){return ee(this,h,null,!0,!1)};function ee(h,d,I,M,Q){p("readableAddChunk",d);var W=h._readableState;if(d===null)W.reading=!1,Ve(h,W);else{var z;if(Q||(z=De(W,d)),z)L(h,z);else if(W.objectMode||d&&d.length>0)if(typeof d!="string"&&!W.objectMode&&Object.getPrototypeOf(d)!==n.prototype&&(d=s(d)),M)W.endEmitted?L(h,new T):Ie(h,W,d,!0);else if(W.ended)L(h,new C);else{if(W.destroyed)return!1;W.reading=!1,W.decoder&&!I?(d=W.decoder.write(d),W.objectMode||d.length!==0?Ie(h,W,d,!1):Te(h,W)):Ie(h,W,d,!1)}else M||(W.reading=!1,Te(h,W))}return!W.ended&&(W.length<W.highWaterMark||W.length===0)}function Ie(h,d,I,M){d.flowing&&d.length===0&&!d.sync?(d.awaitDrain=0,h.emit("data",I)):(d.length+=d.objectMode?1:I.length,M?d.buffer.unshift(I):d.buffer.push(I),d.needReadable&&ke(h)),Te(h,d)}function De(h,d){var I;return!c(d)&&typeof d!="string"&&d!==void 0&&!h.objectMode&&(I=new R("chunk",["string","Buffer","Uint8Array"],d)),I}U.prototype.isPaused=function(){return this._readableState.flowing===!1},U.prototype.setEncoding=function(h){O||(O=Gt.StringDecoder);var d=new O(h);this._readableState.decoder=d,this._readableState.encoding=this._readableState.decoder.encoding;for(var I=this._readableState.buffer.head,M="";I!==null;)M+=d.write(I.data),I=I.next;return this._readableState.buffer.clear(),M!==""&&this._readableState.buffer.push(M),this._readableState.length=M.length,this};var ae=1073741824;function _e(h){return h>=ae?h=ae:(h--,h|=h>>>1,h|=h>>>2,h|=h>>>4,h|=h>>>8,h|=h>>>16,h++),h}function me(h,d){return h<=0||d.length===0&&d.ended?0:d.objectMode?1:h!==h?d.flowing&&d.length?d.buffer.head.data.length:d.length:(h>d.highWaterMark&&(d.highWaterMark=_e(h)),h<=d.length?h:d.ended?d.length:(d.needReadable=!0,0))}U.prototype.read=function(h){p("read",h),h=parseInt(h,10);var d=this._readableState,I=h;if(h!==0&&(d.emittedReadable=!1),h===0&&d.needReadable&&((d.highWaterMark!==0?d.length>=d.highWaterMark:d.length>0)||d.ended))return p("read: emitReadable",d.length,d.ended),d.length===0&&d.ended?A(this):ke(this),null;if(h=me(h,d),h===0&&d.ended)return d.length===0&&A(this),null;var M=d.needReadable;p("need readable",M),(d.length===0||d.length-h<d.highWaterMark)&&(M=!0,p("length less than watermark",M)),d.ended||d.reading?(M=!1,p("reading or ended",M)):M&&(p("do read"),d.reading=!0,d.sync=!0,d.length===0&&(d.needReadable=!0),this._read(d.highWaterMark),d.sync=!1,d.reading||(h=me(I,d)));var Q;return h>0?Q=_(h,d):Q=null,Q===null?(d.needReadable=d.length<=d.highWaterMark,h=0):(d.length-=h,d.awaitDrain=0),d.length===0&&(d.ended||(d.needReadable=!0),I!==h&&d.ended&&A(this)),Q!==null&&this.emit("data",Q),Q};function Ve(h,d){if(p("onEofChunk"),!d.ended){if(d.decoder){var I=d.decoder.end();I&&I.length&&(d.buffer.push(I),d.length+=d.objectMode?1:I.length)}d.ended=!0,d.sync?ke(h):(d.needReadable=!1,d.emittedReadable||(d.emittedReadable=!0,$e(h)))}}function ke(h){var d=h._readableState;p("emitReadable",d.needReadable,d.emittedReadable),d.needReadable=!1,d.emittedReadable||(p("emitReadable",d.flowing),d.emittedReadable=!0,process.nextTick($e,h))}function $e(h){var d=h._readableState;p("emitReadable_",d.destroyed,d.length,d.ended),!d.destroyed&&(d.length||d.ended)&&(h.emit("readable"),d.emittedReadable=!1),d.needReadable=!d.flowing&&!d.ended&&d.length<=d.highWaterMark,m(h)}function Te(h,d){d.readingMore||(d.readingMore=!0,process.nextTick(He,h,d))}function He(h,d){for(;!d.reading&&!d.ended&&(d.length<d.highWaterMark||d.flowing&&d.length===0);){var I=d.length;if(p("maybeReadMore read 0"),h.read(0),I===d.length)break}d.readingMore=!1}U.prototype._read=function(h){L(this,new E("_read()"))},U.prototype.pipe=function(h,d){var I=this,M=this._readableState;switch(M.pipesCount){case 0:M.pipes=h;break;case 1:M.pipes=[M.pipes,h];break;default:M.pipes.push(h);break}M.pipesCount+=1,p("pipe count=%d opts=%j",M.pipesCount,d);var Q=(!d||d.end!==!1)&&h!==process.stdout&&h!==process.stderr,W=Q?qe:Ye;M.endEmitted?process.nextTick(W):I.once("end",W),h.on("unpipe",z);function z(f,i){p("onunpipe"),f===I&&i&&i.hasUnpiped===!1&&(i.hasUnpiped=!0,nt())}function qe(){p("onend"),h.end()}var rt=Y(I);h.on("drain",rt);var yt=!1;function nt(){p("cleanup"),h.removeListener("close",gt),h.removeListener("finish",Ee),h.removeListener("drain",rt),h.removeListener("error",Je),h.removeListener("unpipe",z),I.removeListener("end",qe),I.removeListener("end",Ye),I.removeListener("data",xe),yt=!0,M.awaitDrain&&(!h._writableState||h._writableState.needDrain)&&rt()}I.on("data",xe);function xe(f){p("ondata");var i=h.write(f);p("dest.write",i),i===!1&&((M.pipesCount===1&&M.pipes===h||M.pipesCount>1&&q(M.pipes,h)!==-1)&&!yt&&(p("false write response, pause",M.awaitDrain),M.awaitDrain++),I.pause())}function Je(f){p("onerror",f),Ye(),h.removeListener("error",Je),t(h,"error")===0&&L(h,f)}j(h,"error",Je);function gt(){h.removeListener("finish",Ee),Ye()}h.once("close",gt);function Ee(){p("onfinish"),h.removeListener("close",gt),Ye()}h.once("finish",Ee);function Ye(){p("unpipe"),I.unpipe(h)}return h.emit("pipe",I),M.flowing||(p("pipe resume"),I.resume()),h};function Y(h){return function(){var I=h._readableState;p("pipeOnDrain",I.awaitDrain),I.awaitDrain&&I.awaitDrain--,I.awaitDrain===0&&t(h,"data")&&(I.flowing=!0,m(h))}}U.prototype.unpipe=function(h){var d=this._readableState,I={hasUnpiped:!1};if(d.pipesCount===0)return this;if(d.pipesCount===1)return h&&h!==d.pipes?this:(h||(h=d.pipes),d.pipes=null,d.pipesCount=0,d.flowing=!1,h&&h.emit("unpipe",this,I),this);if(!h){var M=d.pipes,Q=d.pipesCount;d.pipes=null,d.pipesCount=0,d.flowing=!1;for(var W=0;W<Q;W++)M[W].emit("unpipe",this,{hasUnpiped:!1});return this}var z=q(d.pipes,h);return z===-1?this:(d.pipes.splice(z,1),d.pipesCount-=1,d.pipesCount===1&&(d.pipes=d.pipes[0]),h.emit("unpipe",this,I),this)},U.prototype.on=function(h,d){var I=r.prototype.on.call(this,h,d),M=this._readableState;return h==="data"?(M.readableListening=this.listenerCount("readable")>0,M.flowing!==!1&&this.resume()):h==="readable"&&!M.endEmitted&&!M.readableListening&&(M.readableListening=M.needReadable=!0,M.flowing=!1,M.emittedReadable=!1,p("on readable",M.length,M.reading),M.length?ke(this):M.reading||process.nextTick(ve,this)),I},U.prototype.addListener=U.prototype.on,U.prototype.removeListener=function(h,d){var I=r.prototype.removeListener.call(this,h,d);return h==="readable"&&process.nextTick(ie,this),I},U.prototype.removeAllListeners=function(h){var d=r.prototype.removeAllListeners.apply(this,arguments);return(h==="readable"||h===void 0)&&process.nextTick(ie,this),d};function ie(h){var d=h._readableState;d.readableListening=h.listenerCount("readable")>0,d.resumeScheduled&&!d.paused?d.flowing=!0:h.listenerCount("data")>0&&h.resume()}function ve(h){p("readable nexttick read 0"),h.read(0)}U.prototype.resume=function(){var h=this._readableState;return h.flowing||(p("resume"),h.flowing=!h.readableListening,je(this,h)),h.paused=!1,this};function je(h,d){d.resumeScheduled||(d.resumeScheduled=!0,process.nextTick(Ne,h,d))}function Ne(h,d){p("resume",d.reading),d.reading||h.read(0),d.resumeScheduled=!1,h.emit("resume"),m(h),d.flowing&&!d.reading&&h.read(0)}U.prototype.pause=function(){return p("call pause flowing=%j",this._readableState.flowing),this._readableState.flowing!==!1&&(p("pause"),this._readableState.flowing=!1,this.emit("pause")),this._readableState.paused=!0,this};function m(h){var d=h._readableState;for(p("flow",d.flowing);d.flowing&&h.read()!==null;);}U.prototype.wrap=function(h){var d=this,I=this._readableState,M=!1;h.on("end",function(){if(p("wrapped end"),I.decoder&&!I.ended){var z=I.decoder.end();z&&z.length&&d.push(z)}d.push(null)}),h.on("data",function(z){if(p("wrapped data"),I.decoder&&(z=I.decoder.write(z)),!(I.objectMode&&z==null)&&!(!I.objectMode&&(!z||!z.length))){var qe=d.push(z);qe||(M=!0,h.pause())}});for(var Q in h)this[Q]===void 0&&typeof h[Q]=="function"&&(this[Q]=function(qe){return function(){return h[qe].apply(h,arguments)}}(Q));for(var W=0;W<S.length;W++)h.on(S[W],this.emit.bind(this,S[W]));return this._read=function(z){p("wrapped _read",z),M&&(M=!1,h.resume())},this},typeof Symbol=="function"&&(U.prototype[Symbol.asyncIterator]=function(){return F===void 0&&(F=Wo()),F(this)}),Object.defineProperty(U.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}}),Object.defineProperty(U.prototype,"readableBuffer",{enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}}),Object.defineProperty(U.prototype,"readableFlowing",{enumerable:!1,get:function(){return this._readableState.flowing},set:function(d){this._readableState&&(this._readableState.flowing=d)}}),U._fromList=_,Object.defineProperty(U.prototype,"readableLength",{enumerable:!1,get:function(){return this._readableState.length}});function _(h,d){if(d.length===0)return null;var I;return d.objectMode?I=d.buffer.shift():!h||h>=d.length?(d.decoder?I=d.buffer.join(""):d.buffer.length===1?I=d.buffer.first():I=d.buffer.concat(d.length),d.buffer.clear()):I=d.buffer.consume(h,d.decoder),I}function A(h){var d=h._readableState;p("endReadable",d.endEmitted),d.endEmitted||(d.ended=!0,process.nextTick($,d,h))}function $(h,d){if(p("endReadableNT",h.endEmitted,h.length),!h.endEmitted&&h.length===0&&(h.endEmitted=!0,d.readable=!1,d.emit("end"),h.autoDestroy)){var I=d._writableState;(!I||I.autoDestroy&&I.finished)&&d.destroy()}}typeof Symbol=="function"&&(U.from=function(h,d){return N===void 0&&(N=Go()),N(U,h,d)});function q(h,d){for(var I=0,M=h.length;I<M;I++)if(h[I]===d)return I;return-1}return mr}var wi=Ue,Qt=et.codes,zo=Qt.ERR_METHOD_NOT_IMPLEMENTED,Ko=Qt.ERR_MULTIPLE_CALLBACK,Vo=Qt.ERR_TRANSFORM_ALREADY_TRANSFORMING,Jo=Qt.ERR_TRANSFORM_WITH_LENGTH_0,Xt=dt();pe(Ue,Xt);function Yo(e,t){var r=this._transformState;r.transforming=!1;var n=r.writecb;if(n===null)return this.emit("error",new Ko);r.writechunk=null,r.writecb=null,t!=null&&this.push(t),n(e);var o=this._readableState;o.reading=!1,(o.needReadable||o.length<o.highWaterMark)&&this._read(o.highWaterMark)}function Ue(e){if(!(this instanceof Ue))return new Ue(e);Xt.call(this,e),this._transformState={afterTransform:Yo.bind(this),needTransform:!1,transforming:!1,writecb:null,writechunk:null,writeencoding:null},this._readableState.needReadable=!0,this._readableState.sync=!1,e&&(typeof e.transform=="function"&&(this._transform=e.transform),typeof e.flush=="function"&&(this._flush=e.flush)),this.on("prefinish",Qo)}function Qo(){var e=this;typeof this._flush=="function"&&!this._readableState.destroyed?this._flush(function(t,r){vn(e,t,r)}):vn(this,null,null)}Ue.prototype.push=function(e,t){return this._transformState.needTransform=!1,Xt.prototype.push.call(this,e,t)};Ue.prototype._transform=function(e,t,r){r(new zo("_transform()"))};Ue.prototype._write=function(e,t,r){var n=this._transformState;if(n.writecb=r,n.writechunk=e,n.writeencoding=t,!n.transforming){var o=this._readableState;(n.needTransform||o.needReadable||o.length<o.highWaterMark)&&this._read(o.highWaterMark)}};Ue.prototype._read=function(e){var t=this._transformState;t.writechunk!==null&&!t.transforming?(t.transforming=!0,this._transform(t.writechunk,t.writeencoding,t.afterTransform)):t.needTransform=!0};Ue.prototype._destroy=function(e,t){Xt.prototype._destroy.call(this,e,function(r){t(r)})};function vn(e,t,r){if(t)return e.emit("error",t);if(r!=null&&e.push(r),e._writableState.length)throw new Jo;if(e._transformState.transforming)throw new Vo;return e.push(null)}var Xo=It,vi=wi;pe(It,vi);function It(e){if(!(this instanceof It))return new It(e);vi.call(this,e)}It.prototype._transform=function(e,t,r){r(null,e)};var wr;function Zo(e){var t=!1;return function(){t||(t=!0,e.apply(void 0,arguments))}}var xi=et.codes,es=xi.ERR_MISSING_ARGS,ts=xi.ERR_STREAM_DESTROYED;function xn(e){if(e)throw e}function rs(e){return e.setHeader&&typeof e.abort=="function"}function ns(e,t,r,n){n=Zo(n);var o=!1;e.on("close",function(){o=!0}),wr===void 0&&(wr=Vr),wr(e,{readable:t,writable:r},function(c){if(c)return n(c);o=!0,n()});var s=!1;return function(c){if(!o&&!s){if(s=!0,rs(e))return e.abort();if(typeof e.destroy=="function")return e.destroy();n(c||new ts("pipe"))}}}function En(e){e()}function is(e,t){return e.pipe(t)}function as(e){return!e.length||typeof e[e.length-1]!="function"?xn:e.pop()}function os(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];var n=as(t);if(Array.isArray(t[0])&&(t=t[0]),t.length<2)throw new es("streams");var o,s=t.map(function(c,u){var p=u<t.length-1,y=u>0;return ns(c,p,y,function(g){o||(o=g),g&&s.forEach(En),!p&&(s.forEach(En),n(o))})});return t.reduce(is)}var ss=os;(function(e,t){t=e.exports=mi(),t.Stream=t,t.Readable=t,t.Writable=gi(),t.Duplex=dt(),t.Transform=wi,t.PassThrough=Xo,t.finished=Vr,t.pipeline=ss})(Fr,Fr.exports);var fs=Fr.exports,zt=we.Buffer,Ei=fs.Transform,us=pe;function cs(e,t){if(!zt.isBuffer(e)&&typeof e!="string")throw new TypeError(t+" must be a string or a buffer")}function Ke(e){Ei.call(this),this._block=zt.allocUnsafe(e),this._blockSize=e,this._blockOffset=0,this._length=[0,0,0,0],this._finalized=!1}us(Ke,Ei);Ke.prototype._transform=function(e,t,r){var n=null;try{this.update(e,t)}catch(o){n=o}r(n)};Ke.prototype._flush=function(e){var t=null;try{this.push(this.digest())}catch(r){t=r}e(t)};Ke.prototype.update=function(e,t){if(cs(e,"Data"),this._finalized)throw new Error("Digest already called");zt.isBuffer(e)||(e=zt.from(e,t));for(var r=this._block,n=0;this._blockOffset+e.length-n>=this._blockSize;){for(var o=this._blockOffset;o<this._blockSize;)r[o++]=e[n++];this._update(),this._blockOffset=0}for(;n<e.length;)r[this._blockOffset++]=e[n++];for(var s=0,c=e.length*8;c>0;++s)this._length[s]+=c,c=this._length[s]/4294967296|0,c>0&&(this._length[s]-=4294967296*c);return this};Ke.prototype._update=function(){throw new Error("_update is not implemented")};Ke.prototype.digest=function(e){if(this._finalized)throw new Error("Digest already called");this._finalized=!0;var t=this._digest();e!==void 0&&(t=t.toString(e)),this._block.fill(0),this._blockOffset=0;for(var r=0;r<4;++r)this._length[r]=0;return t};Ke.prototype._digest=function(){throw new Error("_digest is not implemented")};var Bi=Ke,ls=pe,Ri=Bi,hs=we.Buffer,ds=new Array(16);function Zt(){Ri.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878}ls(Zt,Ri);Zt.prototype._update=function(){for(var e=ds,t=0;t<16;++t)e[t]=this._block.readInt32LE(t*4);var r=this._a,n=this._b,o=this._c,s=this._d;r=ue(r,n,o,s,e[0],3614090360,7),s=ue(s,r,n,o,e[1],3905402710,12),o=ue(o,s,r,n,e[2],606105819,17),n=ue(n,o,s,r,e[3],3250441966,22),r=ue(r,n,o,s,e[4],4118548399,7),s=ue(s,r,n,o,e[5],1200080426,12),o=ue(o,s,r,n,e[6],2821735955,17),n=ue(n,o,s,r,e[7],4249261313,22),r=ue(r,n,o,s,e[8],1770035416,7),s=ue(s,r,n,o,e[9],2336552879,12),o=ue(o,s,r,n,e[10],4294925233,17),n=ue(n,o,s,r,e[11],2304563134,22),r=ue(r,n,o,s,e[12],1804603682,7),s=ue(s,r,n,o,e[13],4254626195,12),o=ue(o,s,r,n,e[14],2792965006,17),n=ue(n,o,s,r,e[15],1236535329,22),r=ce(r,n,o,s,e[1],4129170786,5),s=ce(s,r,n,o,e[6],3225465664,9),o=ce(o,s,r,n,e[11],643717713,14),n=ce(n,o,s,r,e[0],3921069994,20),r=ce(r,n,o,s,e[5],3593408605,5),s=ce(s,r,n,o,e[10],38016083,9),o=ce(o,s,r,n,e[15],3634488961,14),n=ce(n,o,s,r,e[4],3889429448,20),r=ce(r,n,o,s,e[9],568446438,5),s=ce(s,r,n,o,e[14],3275163606,9),o=ce(o,s,r,n,e[3],4107603335,14),n=ce(n,o,s,r,e[8],1163531501,20),r=ce(r,n,o,s,e[13],2850285829,5),s=ce(s,r,n,o,e[2],4243563512,9),o=ce(o,s,r,n,e[7],1735328473,14),n=ce(n,o,s,r,e[12],2368359562,20),r=le(r,n,o,s,e[5],4294588738,4),s=le(s,r,n,o,e[8],2272392833,11),o=le(o,s,r,n,e[11],1839030562,16),n=le(n,o,s,r,e[14],4259657740,23),r=le(r,n,o,s,e[1],2763975236,4),s=le(s,r,n,o,e[4],1272893353,11),o=le(o,s,r,n,e[7],4139469664,16),n=le(n,o,s,r,e[10],3200236656,23),r=le(r,n,o,s,e[13],681279174,4),s=le(s,r,n,o,e[0],3936430074,11),o=le(o,s,r,n,e[3],3572445317,16),n=le(n,o,s,r,e[6],76029189,23),r=le(r,n,o,s,e[9],3654602809,4),s=le(s,r,n,o,e[12],3873151461,11),o=le(o,s,r,n,e[15],530742520,16),n=le(n,o,s,r,e[2],3299628645,23),r=he(r,n,o,s,e[0],4096336452,6),s=he(s,r,n,o,e[7],1126891415,10),o=he(o,s,r,n,e[14],2878612391,15),n=he(n,o,s,r,e[5],4237533241,21),r=he(r,n,o,s,e[12],1700485571,6),s=he(s,r,n,o,e[3],2399980690,10),o=he(o,s,r,n,e[10],4293915773,15),n=he(n,o,s,r,e[1],2240044497,21),r=he(r,n,o,s,e[8],1873313359,6),s=he(s,r,n,o,e[15],4264355552,10),o=he(o,s,r,n,e[6],2734768916,15),n=he(n,o,s,r,e[13],1309151649,21),r=he(r,n,o,s,e[4],4149444226,6),s=he(s,r,n,o,e[11],3174756917,10),o=he(o,s,r,n,e[2],718787259,15),n=he(n,o,s,r,e[9],3951481745,21),this._a=this._a+r|0,this._b=this._b+n|0,this._c=this._c+o|0,this._d=this._d+s|0};Zt.prototype._digest=function(){this._block[this._blockOffset++]=128,this._blockOffset>56&&(this._block.fill(0,this._blockOffset,64),this._update(),this._blockOffset=0),this._block.fill(0,this._blockOffset,56),this._block.writeUInt32LE(this._length[0],56),this._block.writeUInt32LE(this._length[1],60),this._update();var e=hs.allocUnsafe(16);return e.writeInt32LE(this._a,0),e.writeInt32LE(this._b,4),e.writeInt32LE(this._c,8),e.writeInt32LE(this._d,12),e};function er(e,t){return e<<t|e>>>32-t}function ue(e,t,r,n,o,s,c){return er(e+(t&r|~t&n)+o+s|0,c)+t|0}function ce(e,t,r,n,o,s,c){return er(e+(t&n|r&~n)+o+s|0,c)+t|0}function le(e,t,r,n,o,s,c){return er(e+(t^r^n)+o+s|0,c)+t|0}function he(e,t,r,n,o,s,c){return er(e+(r^(t|~n))+o+s|0,c)+t|0}var ps=Zt,vr=pt.Buffer,bs=pe,Si=Bi,ys=new Array(16),mt=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13],wt=[5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11],vt=[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6],xt=[8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11],Et=[0,1518500249,1859775393,2400959708,2840853838],Bt=[1352829926,1548603684,1836072691,2053994217,0];function tr(){Si.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520}bs(tr,Si);tr.prototype._update=function(){for(var e=ys,t=0;t<16;++t)e[t]=this._block.readInt32LE(t*4);for(var r=this._a|0,n=this._b|0,o=this._c|0,s=this._d|0,c=this._e|0,u=this._a|0,p=this._b|0,y=this._c|0,g=this._d|0,w=this._e|0,x=0;x<80;x+=1){var k,R;x<16?(k=Bn(r,n,o,s,c,e[mt[x]],Et[0],vt[x]),R=kn(u,p,y,g,w,e[wt[x]],Bt[0],xt[x])):x<32?(k=Rn(r,n,o,s,c,e[mt[x]],Et[1],vt[x]),R=In(u,p,y,g,w,e[wt[x]],Bt[1],xt[x])):x<48?(k=Sn(r,n,o,s,c,e[mt[x]],Et[2],vt[x]),R=Sn(u,p,y,g,w,e[wt[x]],Bt[2],xt[x])):x<64?(k=In(r,n,o,s,c,e[mt[x]],Et[3],vt[x]),R=Rn(u,p,y,g,w,e[wt[x]],Bt[3],xt[x])):(k=kn(r,n,o,s,c,e[mt[x]],Et[4],vt[x]),R=Bn(u,p,y,g,w,e[wt[x]],Bt[4],xt[x])),r=c,c=s,s=Xe(o,10),o=n,n=k,u=w,w=g,g=Xe(y,10),y=p,p=R}var C=this._b+o+g|0;this._b=this._c+s+w|0,this._c=this._d+c+u|0,this._d=this._e+r+p|0,this._e=this._a+n+y|0,this._a=C};tr.prototype._digest=function(){this._block[this._blockOffset++]=128,this._blockOffset>56&&(this._block.fill(0,this._blockOffset,64),this._update(),this._blockOffset=0),this._block.fill(0,this._blockOffset,56),this._block.writeUInt32LE(this._length[0],56),this._block.writeUInt32LE(this._length[1],60),this._update();var e=vr.alloc?vr.alloc(20):new vr(20);return e.writeInt32LE(this._a,0),e.writeInt32LE(this._b,4),e.writeInt32LE(this._c,8),e.writeInt32LE(this._d,12),e.writeInt32LE(this._e,16),e};function Xe(e,t){return e<<t|e>>>32-t}function Bn(e,t,r,n,o,s,c,u){return Xe(e+(t^r^n)+s+c|0,u)+o|0}function Rn(e,t,r,n,o,s,c,u){return Xe(e+(t&r|~t&n)+s+c|0,u)+o|0}function Sn(e,t,r,n,o,s,c,u){return Xe(e+((t|~r)^n)+s+c|0,u)+o|0}function In(e,t,r,n,o,s,c,u){return Xe(e+(t&n|r&~n)+s+c|0,u)+o|0}function kn(e,t,r,n,o,s,c,u){return Xe(e+(t^(r|~n))+s+c|0,u)+o|0}var gs=tr,Ii={exports:{}},ki=we.Buffer;function rr(e,t){this._block=ki.alloc(e),this._finalSize=t,this._blockSize=e,this._len=0}rr.prototype.update=function(e,t){typeof e=="string"&&(t=t||"utf8",e=ki.from(e,t));for(var r=this._block,n=this._blockSize,o=e.length,s=this._len,c=0;c<o;){for(var u=s%n,p=Math.min(o-c,n-u),y=0;y<p;y++)r[u+y]=e[c+y];s+=p,c+=p,s%n===0&&this._update(r)}return this._len+=o,this};rr.prototype.digest=function(e){var t=this._len%this._blockSize;this._block[t]=128,this._block.fill(0,t+1),t>=this._finalSize&&(this._update(this._block),this._block.fill(0));var r=this._len*8;if(r<=4294967295)this._block.writeUInt32BE(r,this._blockSize-4);else{var n=(r&4294967295)>>>0,o=(r-n)/4294967296;this._block.writeUInt32BE(o,this._blockSize-8),this._block.writeUInt32BE(n,this._blockSize-4)}this._update(this._block);var s=this._hash();return e?s.toString(e):s};rr.prototype._update=function(){throw new Error("_update must be implemented by subclass")};var bt=rr,_s=pe,Ti=bt,ms=we.Buffer,ws=[1518500249,1859775393,-1894007588,-899497514],vs=new Array(80);function At(){this.init(),this._w=vs,Ti.call(this,64,56)}_s(At,Ti);At.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this};function xs(e){return e<<5|e>>>27}function Es(e){return e<<30|e>>>2}function Bs(e,t,r,n){return e===0?t&r|~t&n:e===2?t&r|t&n|r&n:t^r^n}At.prototype._update=function(e){for(var t=this._w,r=this._a|0,n=this._b|0,o=this._c|0,s=this._d|0,c=this._e|0,u=0;u<16;++u)t[u]=e.readInt32BE(u*4);for(;u<80;++u)t[u]=t[u-3]^t[u-8]^t[u-14]^t[u-16];for(var p=0;p<80;++p){var y=~~(p/20),g=xs(r)+Bs(y,n,o,s)+c+t[p]+ws[y]|0;c=s,s=o,o=Es(n),n=r,r=g}this._a=r+this._a|0,this._b=n+this._b|0,this._c=o+this._c|0,this._d=s+this._d|0,this._e=c+this._e|0};At.prototype._hash=function(){var e=ms.allocUnsafe(20);return e.writeInt32BE(this._a|0,0),e.writeInt32BE(this._b|0,4),e.writeInt32BE(this._c|0,8),e.writeInt32BE(this._d|0,12),e.writeInt32BE(this._e|0,16),e};var Rs=At,Ss=pe,Ai=bt,Is=we.Buffer,ks=[1518500249,1859775393,-1894007588,-899497514],Ts=new Array(80);function Ct(){this.init(),this._w=Ts,Ai.call(this,64,56)}Ss(Ct,Ai);Ct.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this};function As(e){return e<<1|e>>>31}function Cs(e){return e<<5|e>>>27}function Ps(e){return e<<30|e>>>2}function Os(e,t,r,n){return e===0?t&r|~t&n:e===2?t&r|t&n|r&n:t^r^n}Ct.prototype._update=function(e){for(var t=this._w,r=this._a|0,n=this._b|0,o=this._c|0,s=this._d|0,c=this._e|0,u=0;u<16;++u)t[u]=e.readInt32BE(u*4);for(;u<80;++u)t[u]=As(t[u-3]^t[u-8]^t[u-14]^t[u-16]);for(var p=0;p<80;++p){var y=~~(p/20),g=Cs(r)+Os(y,n,o,s)+c+t[p]+ks[y]|0;c=s,s=o,o=Ps(n),n=r,r=g}this._a=r+this._a|0,this._b=n+this._b|0,this._c=o+this._c|0,this._d=s+this._d|0,this._e=c+this._e|0};Ct.prototype._hash=function(){var e=Is.allocUnsafe(20);return e.writeInt32BE(this._a|0,0),e.writeInt32BE(this._b|0,4),e.writeInt32BE(this._c|0,8),e.writeInt32BE(this._d|0,12),e.writeInt32BE(this._e|0,16),e};var Ns=Ct,Fs=pe,Ci=bt,Ls=we.Buffer,Ms=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],Us=new Array(64);function Pt(){this.init(),this._w=Us,Ci.call(this,64,56)}Fs(Pt,Ci);Pt.prototype.init=function(){return this._a=1779033703,this._b=3144134277,this._c=1013904242,this._d=2773480762,this._e=1359893119,this._f=2600822924,this._g=528734635,this._h=1541459225,this};function Ds(e,t,r){return r^e&(t^r)}function $s(e,t,r){return e&t|r&(e|t)}function Hs(e){return(e>>>2|e<<30)^(e>>>13|e<<19)^(e>>>22|e<<10)}function js(e){return(e>>>6|e<<26)^(e>>>11|e<<21)^(e>>>25|e<<7)}function qs(e){return(e>>>7|e<<25)^(e>>>18|e<<14)^e>>>3}function Ws(e){return(e>>>17|e<<15)^(e>>>19|e<<13)^e>>>10}Pt.prototype._update=function(e){for(var t=this._w,r=this._a|0,n=this._b|0,o=this._c|0,s=this._d|0,c=this._e|0,u=this._f|0,p=this._g|0,y=this._h|0,g=0;g<16;++g)t[g]=e.readInt32BE(g*4);for(;g<64;++g)t[g]=Ws(t[g-2])+t[g-7]+qs(t[g-15])+t[g-16]|0;for(var w=0;w<64;++w){var x=y+js(c)+Ds(c,u,p)+Ms[w]+t[w]|0,k=Hs(r)+$s(r,n,o)|0;y=p,p=u,u=c,c=s+x|0,s=o,o=n,n=r,r=x+k|0}this._a=r+this._a|0,this._b=n+this._b|0,this._c=o+this._c|0,this._d=s+this._d|0,this._e=c+this._e|0,this._f=u+this._f|0,this._g=p+this._g|0,this._h=y+this._h|0};Pt.prototype._hash=function(){var e=Ls.allocUnsafe(32);return e.writeInt32BE(this._a,0),e.writeInt32BE(this._b,4),e.writeInt32BE(this._c,8),e.writeInt32BE(this._d,12),e.writeInt32BE(this._e,16),e.writeInt32BE(this._f,20),e.writeInt32BE(this._g,24),e.writeInt32BE(this._h,28),e};var Pi=Pt,Gs=pe,zs=Pi,Ks=bt,Vs=we.Buffer,Js=new Array(64);function nr(){this.init(),this._w=Js,Ks.call(this,64,56)}Gs(nr,zs);nr.prototype.init=function(){return this._a=3238371032,this._b=914150663,this._c=812702999,this._d=4144912697,this._e=4290775857,this._f=1750603025,this._g=1694076839,this._h=3204075428,this};nr.prototype._hash=function(){var e=Vs.allocUnsafe(28);return e.writeInt32BE(this._a,0),e.writeInt32BE(this._b,4),e.writeInt32BE(this._c,8),e.writeInt32BE(this._d,12),e.writeInt32BE(this._e,16),e.writeInt32BE(this._f,20),e.writeInt32BE(this._g,24),e};var Ys=nr,Qs=pe,Oi=bt,Xs=we.Buffer,Tn=[1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591],Zs=new Array(160);function Ot(){this.init(),this._w=Zs,Oi.call(this,128,112)}Qs(Ot,Oi);Ot.prototype.init=function(){return this._ah=1779033703,this._bh=3144134277,this._ch=1013904242,this._dh=2773480762,this._eh=1359893119,this._fh=2600822924,this._gh=528734635,this._hh=1541459225,this._al=4089235720,this._bl=2227873595,this._cl=4271175723,this._dl=1595750129,this._el=2917565137,this._fl=725511199,this._gl=4215389547,this._hl=327033209,this};function An(e,t,r){return r^e&(t^r)}function Cn(e,t,r){return e&t|r&(e|t)}function Pn(e,t){return(e>>>28|t<<4)^(t>>>2|e<<30)^(t>>>7|e<<25)}function On(e,t){return(e>>>14|t<<18)^(e>>>18|t<<14)^(t>>>9|e<<23)}function ef(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^e>>>7}function tf(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^(e>>>7|t<<25)}function rf(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^e>>>6}function nf(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^(e>>>6|t<<26)}function se(e,t){return e>>>0<t>>>0?1:0}Ot.prototype._update=function(e){for(var t=this._w,r=this._ah|0,n=this._bh|0,o=this._ch|0,s=this._dh|0,c=this._eh|0,u=this._fh|0,p=this._gh|0,y=this._hh|0,g=this._al|0,w=this._bl|0,x=this._cl|0,k=this._dl|0,R=this._el|0,C=this._fl|0,E=this._gl|0,T=this._hl|0,O=0;O<32;O+=2)t[O]=e.readInt32BE(O*4),t[O+1]=e.readInt32BE(O*4+4);for(;O<160;O+=2){var F=t[O-30],N=t[O-15*2+1],L=ef(F,N),S=tf(N,F);F=t[O-2*2],N=t[O-2*2+1];var j=rf(F,N),D=nf(N,F),U=t[O-7*2],ee=t[O-7*2+1],Ie=t[O-16*2],De=t[O-16*2+1],ae=S+ee|0,_e=L+U+se(ae,S)|0;ae=ae+D|0,_e=_e+j+se(ae,D)|0,ae=ae+De|0,_e=_e+Ie+se(ae,De)|0,t[O]=_e,t[O+1]=ae}for(var me=0;me<160;me+=2){_e=t[me],ae=t[me+1];var Ve=Cn(r,n,o),ke=Cn(g,w,x),$e=Pn(r,g),Te=Pn(g,r),He=On(c,R),Y=On(R,c),ie=Tn[me],ve=Tn[me+1],je=An(c,u,p),Ne=An(R,C,E),m=T+Y|0,_=y+He+se(m,T)|0;m=m+Ne|0,_=_+je+se(m,Ne)|0,m=m+ve|0,_=_+ie+se(m,ve)|0,m=m+ae|0,_=_+_e+se(m,ae)|0;var A=Te+ke|0,$=$e+Ve+se(A,Te)|0;y=p,T=E,p=u,E=C,u=c,C=R,R=k+m|0,c=s+_+se(R,k)|0,s=o,k=x,o=n,x=w,n=r,w=g,g=m+A|0,r=_+$+se(g,m)|0}this._al=this._al+g|0,this._bl=this._bl+w|0,this._cl=this._cl+x|0,this._dl=this._dl+k|0,this._el=this._el+R|0,this._fl=this._fl+C|0,this._gl=this._gl+E|0,this._hl=this._hl+T|0,this._ah=this._ah+r+se(this._al,g)|0,this._bh=this._bh+n+se(this._bl,w)|0,this._ch=this._ch+o+se(this._cl,x)|0,this._dh=this._dh+s+se(this._dl,k)|0,this._eh=this._eh+c+se(this._el,R)|0,this._fh=this._fh+u+se(this._fl,C)|0,this._gh=this._gh+p+se(this._gl,E)|0,this._hh=this._hh+y+se(this._hl,T)|0};Ot.prototype._hash=function(){var e=Xs.allocUnsafe(64);function t(r,n,o){e.writeInt32BE(r,o),e.writeInt32BE(n,o+4)}return t(this._ah,this._al,0),t(this._bh,this._bl,8),t(this._ch,this._cl,16),t(this._dh,this._dl,24),t(this._eh,this._el,32),t(this._fh,this._fl,40),t(this._gh,this._gl,48),t(this._hh,this._hl,56),e};var Ni=Ot,af=pe,of=Ni,sf=bt,ff=we.Buffer,uf=new Array(160);function ir(){this.init(),this._w=uf,sf.call(this,128,112)}af(ir,of);ir.prototype.init=function(){return this._ah=3418070365,this._bh=1654270250,this._ch=2438529370,this._dh=355462360,this._eh=1731405415,this._fh=2394180231,this._gh=3675008525,this._hh=1203062813,this._al=3238371032,this._bl=914150663,this._cl=812702999,this._dl=4144912697,this._el=4290775857,this._fl=1750603025,this._gl=1694076839,this._hl=3204075428,this};ir.prototype._hash=function(){var e=ff.allocUnsafe(48);function t(r,n,o){e.writeInt32BE(r,o),e.writeInt32BE(n,o+4)}return t(this._ah,this._al,0),t(this._bh,this._bl,8),t(this._ch,this._cl,16),t(this._dh,this._dl,24),t(this._eh,this._el,32),t(this._fh,this._fl,40),e};var cf=ir,tt=Ii.exports=function(t){t=t.toLowerCase();var r=tt[t];if(!r)throw new Error(t+" is not supported (we accept pull requests)");return new r};tt.sha=Rs;tt.sha1=Ns;tt.sha224=Ys;tt.sha256=Pi;tt.sha384=cf;tt.sha512=Ni;var lf=Ii.exports,Fi=we.Buffer,Li=zr.Transform,hf=Gt.StringDecoder,df=pe;function Ae(e){Li.call(this),this.hashMode=typeof e=="string",this.hashMode?this[e]=this._finalOrDigest:this.final=this._finalOrDigest,this._final&&(this.__final=this._final,this._final=null),this._decoder=null,this._encoding=null}df(Ae,Li);Ae.prototype.update=function(e,t,r){typeof e=="string"&&(e=Fi.from(e,t));var n=this._update(e);return this.hashMode?this:(r&&(n=this._toString(n,r)),n)};Ae.prototype.setAutoPadding=function(){};Ae.prototype.getAuthTag=function(){throw new Error("trying to get auth tag in unsupported state")};Ae.prototype.setAuthTag=function(){throw new Error("trying to set auth tag in unsupported state")};Ae.prototype.setAAD=function(){throw new Error("trying to set aad in unsupported state")};Ae.prototype._transform=function(e,t,r){var n;try{this.hashMode?this._update(e):this.push(this._update(e))}catch(o){n=o}finally{r(n)}};Ae.prototype._flush=function(e){var t;try{this.push(this.__final())}catch(r){t=r}e(t)};Ae.prototype._finalOrDigest=function(e){var t=this.__final()||Fi.alloc(0);return e&&(t=this._toString(t,e,!0)),t};Ae.prototype._toString=function(e,t,r){if(this._decoder||(this._decoder=new hf(t),this._encoding=t),this._encoding!==t)throw new Error("can't switch encodings");var n=this._decoder.write(e);return r&&(n+=this._decoder.end()),n};var pf=Ae,bf=pe,yf=ps,gf=gs,_f=lf,Mi=pf;function ar(e){Mi.call(this,"digest"),this._hash=e}bf(ar,Mi);ar.prototype._update=function(e){this._hash.update(e)};ar.prototype._final=function(){return this._hash.digest()};var mf=function(t){return t=t.toLowerCase(),t==="md5"?new yf:t==="rmd160"||t==="ripemd160"?new gf:new ar(_f(t))},Mt=we.Buffer;function wf(e){if(e.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),r=0;r<t.length;r++)t[r]=255;for(var n=0;n<e.length;n++){var o=e.charAt(n),s=o.charCodeAt(0);if(t[s]!==255)throw new TypeError(o+" is ambiguous");t[s]=n}var c=e.length,u=e.charAt(0),p=Math.log(c)/Math.log(256),y=Math.log(256)/Math.log(c);function g(k){if((Array.isArray(k)||k instanceof Uint8Array)&&(k=Mt.from(k)),!Mt.isBuffer(k))throw new TypeError("Expected Buffer");if(k.length===0)return"";for(var R=0,C=0,E=0,T=k.length;E!==T&&k[E]===0;)E++,R++;for(var O=(T-E)*y+1>>>0,F=new Uint8Array(O);E!==T;){for(var N=k[E],L=0,S=O-1;(N!==0||L<C)&&S!==-1;S--,L++)N+=256*F[S]>>>0,F[S]=N%c>>>0,N=N/c>>>0;if(N!==0)throw new Error("Non-zero carry");C=L,E++}for(var j=O-C;j!==O&&F[j]===0;)j++;for(var D=u.repeat(R);j<O;++j)D+=e.charAt(F[j]);return D}function w(k){if(typeof k!="string")throw new TypeError("Expected String");if(k.length===0)return Mt.alloc(0);for(var R=0,C=0,E=0;k[R]===u;)C++,R++;for(var T=(k.length-R)*p+1>>>0,O=new Uint8Array(T);R<k.length;){var F=t[k.charCodeAt(R)];if(F===255)return;for(var N=0,L=T-1;(F!==0||N<E)&&L!==-1;L--,N++)F+=c*O[L]>>>0,O[L]=F%256>>>0,F=F/256>>>0;if(F!==0)throw new Error("Non-zero carry");E=N,R++}for(var S=T-E;S!==T&&O[S]===0;)S++;var j=Mt.allocUnsafe(C+(T-S));j.fill(0,0,C);for(var D=C;S!==T;)j[D++]=O[S++];return j}function x(k){var R=w(k);if(R)return R;throw new Error("Non-base"+c+" character")}return{encode:g,decodeUnsafe:w,decode:x}}var vf=wf,xf=vf,Ef="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",Bf=xf(Ef),xr=Bf,Rf=we.Buffer,Sf=function(e){function t(s){var c=e(s);return xr.encode(Rf.concat([s,c],s.length+4))}function r(s){var c=s.slice(0,-4),u=s.slice(-4),p=e(c);if(!(u[0]^p[0]|u[1]^p[1]|u[2]^p[2]|u[3]^p[3]))return c}function n(s){var c=xr.decodeUnsafe(s);if(c)return r(c)}function o(s){var c=xr.decode(s),u=r(c);if(!u)throw new Error("Invalid checksum");return u}return{encode:t,decode:o,decodeUnsafe:n}},Nn=mf,If=Sf;function kf(e){var t=Nn("sha256").update(e).digest();return Nn("sha256").update(t).digest()}var Tf=If(kf),Mr=Tf;function Ui(e,t){if(t!==void 0&&e[0]!==t)throw new Error("Invalid network version");if(e.length===33)return{version:e[0],privateKey:e.slice(1,33),compressed:!1};if(e.length!==34)throw new Error("Invalid WIF length");if(e[33]!==1)throw new Error("Invalid compression flag");return{version:e[0],privateKey:e.slice(1,33),compressed:!0}}function Ur(e,t,r){var n=new Buffer(r?34:33);return n.writeUInt8(e,0),t.copy(n,1),r&&(n[33]=1),n}function Af(e,t){return Ui(Mr.decode(e),t)}function Cf(e,t,r){return typeof e=="number"?Mr.encode(Ur(e,t,r)):Mr.encode(Ur(e.version,e.privateKey,e.compressed))}var Pf={decode:Af,decodeRaw:Ui,encode:Cf,encodeRaw:Ur},or={};Object.defineProperty(or,"__esModule",{value:!0});or.testEcc=void 0;const H=e=>Buffer.from(e,"hex");function Of(e){J(e.isPoint(H("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),J(!e.isPoint(H("030000000000000000000000000000000000000000000000000000000000000005"))),J(e.isPrivate(H("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),J(e.isPrivate(H("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))),J(!e.isPrivate(H("0000000000000000000000000000000000000000000000000000000000000000"))),J(!e.isPrivate(H("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"))),J(!e.isPrivate(H("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364142"))),J(Buffer.from(e.privateAdd(H("0000000000000000000000000000000000000000000000000000000000000001"),H("0000000000000000000000000000000000000000000000000000000000000000"))).equals(H("0000000000000000000000000000000000000000000000000000000000000001"))),J(e.privateAdd(H("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413e"),H("0000000000000000000000000000000000000000000000000000000000000003"))===null),J(Buffer.from(e.privateAdd(H("e211078564db65c3ce7704f08262b1f38f1ef412ad15b5ac2d76657a63b2c500"),H("b51fbb69051255d1becbd683de5848242a89c229348dd72896a87ada94ae8665"))).equals(H("9730c2ee69edbb958d42db7460bafa18fef9d955325aec99044c81c8282b0a24"))),J(Buffer.from(e.privateNegate(H("0000000000000000000000000000000000000000000000000000000000000001"))).equals(H("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))),J(Buffer.from(e.privateNegate(H("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413e"))).equals(H("0000000000000000000000000000000000000000000000000000000000000003"))),J(Buffer.from(e.privateNegate(H("b1121e4088a66a28f5b6b0f5844943ecd9f610196d7bb83b25214b60452c09af"))).equals(H("4eede1bf775995d70a494f0a7bb6bc11e0b8cccd41cce8009ab1132c8b0a3792"))),J(Buffer.from(e.pointCompress(H("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"),!0)).equals(H("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),J(Buffer.from(e.pointCompress(H("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"),!1)).equals(H("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"))),J(Buffer.from(e.pointCompress(H("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),!0)).equals(H("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),J(Buffer.from(e.pointCompress(H("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),!1)).equals(H("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"))),J(Buffer.from(e.pointFromScalar(H("b1121e4088a66a28f5b6b0f5844943ecd9f610196d7bb83b25214b60452c09af"))).equals(H("02b07ba9dca9523b7ef4bd97703d43d20399eb698e194704791a25ce77a400df99"))),J(e.xOnlyPointAddTweak(H("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),H("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))===null);let t=e.xOnlyPointAddTweak(H("1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b"),H("a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac"));J(Buffer.from(t.xOnlyPubkey).equals(H("e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf"))&&t.parity===1),t=e.xOnlyPointAddTweak(H("2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991"),H("823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47")),J(Buffer.from(t.xOnlyPubkey).equals(H("9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c"))&&t.parity===0),J(Buffer.from(e.sign(H("5e9f0a0d593efdcf78ac923bc3313e4e7d408d574354ee2b3288c0da9fbba6ed"),H("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140"))).equals(H("54c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed07082304410efa6b2943111b6a4e0aaa7b7db55a07e9861d1fb3cb1f421044a5"))),J(e.verify(H("5e9f0a0d593efdcf78ac923bc3313e4e7d408d574354ee2b3288c0da9fbba6ed"),H("0379be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),H("54c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed07082304410efa6b2943111b6a4e0aaa7b7db55a07e9861d1fb3cb1f421044a5"))),e.signSchnorr&&J(Buffer.from(e.signSchnorr(H("7e2d58d8b3bcdf1abadec7829054f90dda9805aab56c77333024b9d0a508b75c"),H("c90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b14e5c9"),H("c87aa53824b4d7ae2eb035a2b5bbbccc080e76cdc6d1692c4b0b62d798e6d906"))).equals(H("5831aaeed7b44bb74e5eab94ba9d4294c49bcf2a60728d8b4c200f50dd313c1bab745879a5ad954a72c45a91c3a51d3c7adea98d82f8481e0e1e03674a6f3fb7"))),e.verifySchnorr&&J(e.verifySchnorr(H("7e2d58d8b3bcdf1abadec7829054f90dda9805aab56c77333024b9d0a508b75c"),H("dd308afec5777e13121fa72b9cc1b7cc0139715309b086c960e18fd969774eb8"),H("5831aaeed7b44bb74e5eab94ba9d4294c49bcf2a60728d8b4c200f50dd313c1bab745879a5ad954a72c45a91c3a51d3c7adea98d82f8481e0e1e03674a6f3fb7")))}or.testEcc=Of;function J(e){if(!e)throw new Error("ecc library invalid")}Object.defineProperty(lt,"__esModule",{value:!0});lt.ECPairFactory=lt.networks=void 0;const Dr=ht;lt.networks=Dr;const ye=Qn,Nf=ao,Fn=Pf,Ff=or,Er=ye.typeforce.maybe(ye.typeforce.compile({compressed:ye.maybe(ye.Boolean),network:ye.maybe(ye.Network)})),Lf=e=>e.length===32?e:e.slice(1,33);function Mf(e){(0,Ff.testEcc)(e);function t(u){return e.isPoint(u)}function r(u,p){if(ye.typeforce(ye.Buffer256bit,u),!e.isPrivate(u))throw new TypeError("Private key not in range [1, n)");return ye.typeforce(Er,p),new c(u,void 0,p)}function n(u,p){return ye.typeforce(e.isPoint,u),ye.typeforce(Er,p),new c(void 0,u,p)}function o(u,p){const y=Fn.decode(u),g=y.version;if(ye.Array(p)){if(p=p.filter(w=>g===w.wif).pop(),!p)throw new Error("Unknown network version")}else if(p=p||Dr.bitcoin,g!==p.wif)throw new Error("Invalid network version");return r(y.privateKey,{compressed:y.compressed,network:p})}function s(u){ye.typeforce(Er,u),u===void 0&&(u={});const p=u.rng||Nf;let y;do y=p(32),ye.typeforce(ye.Buffer256bit,y);while(!e.isPrivate(y));return r(y,u)}class c{constructor(p,y,g){it(this,"__D");it(this,"__Q");it(this,"compressed");it(this,"network");it(this,"lowR");this.__D=p,this.__Q=y,this.lowR=!1,g===void 0&&(g={}),this.compressed=g.compressed===void 0?!0:g.compressed,this.network=g.network||Dr.bitcoin,y!==void 0&&(this.__Q=Buffer.from(e.pointCompress(y,this.compressed)))}get privateKey(){return this.__D}get publicKey(){if(!this.__Q){const p=e.pointFromScalar(this.__D,this.compressed);this.__Q=Buffer.from(p)}return this.__Q}toWIF(){if(!this.__D)throw new Error("Missing private key");return Fn.encode(this.network.wif,this.__D,this.compressed)}tweak(p){return this.privateKey?this.tweakFromPrivateKey(p):this.tweakFromPublicKey(p)}sign(p,y){if(!this.__D)throw new Error("Missing private key");if(y===void 0&&(y=this.lowR),y===!1)return Buffer.from(e.sign(p,this.__D));{let g=e.sign(p,this.__D);const w=Buffer.alloc(32,0);let x=0;for(;g[0]>127;)x++,w.writeUIntLE(x,0,6),g=e.sign(p,this.__D,w);return Buffer.from(g)}}signSchnorr(p){if(!this.privateKey)throw new Error("Missing private key");if(!e.signSchnorr)throw new Error("signSchnorr not supported by ecc library");return Buffer.from(e.signSchnorr(p,this.privateKey))}verify(p,y){return e.verify(p,this.publicKey,y)}verifySchnorr(p,y){if(!e.verifySchnorr)throw new Error("verifySchnorr not supported by ecc library");return e.verifySchnorr(p,this.publicKey.subarray(1,33),y)}tweakFromPublicKey(p){const y=Lf(this.publicKey),g=e.xOnlyPointAddTweak(y,p);if(!g||g.xOnlyPubkey===null)throw new Error("Cannot tweak public key!");const w=Buffer.from([g.parity===0?2:3]);return n(Buffer.concat([w,g.xOnlyPubkey]),{network:this.network,compressed:this.compressed})}tweakFromPrivateKey(p){const g=this.publicKey[0]===3||this.publicKey[0]===4&&(this.publicKey[64]&1)===1?e.privateNegate(this.privateKey):this.privateKey,w=e.privateAdd(g,p);if(!w)throw new Error("Invalid tweaked private key!");return r(Buffer.from(w),{network:this.network,compressed:this.compressed})}}return{isPoint:t,fromPrivateKey:r,fromPublicKey:n,fromWIF:o,makeRandom:s}}lt.ECPairFactory=Mf;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.networks=e.ECPairFactory=e.default=void 0;var t=lt;Object.defineProperty(e,"default",{enumerable:!0,get:function(){return t.ECPairFactory}}),Object.defineProperty(e,"ECPairFactory",{enumerable:!0,get:function(){return t.ECPairFactory}}),Object.defineProperty(e,"networks",{enumerable:!0,get:function(){return t.networks}})})(Yn);class Kt{constructor(t){this.privKey=t}static fromPrivKey(t){return new Kt(P.trim0x(t))}static async fromWalletClient(t){if(!t.account)return P.Err("No account found");try{const r=await t.signTypedData({account:t.account,types:{EIP712Domain:[{name:"name",type:"string"},{name:"version",type:"string"}],Data:[{name:"Message",type:"string"},{name:"Version",type:"string"},{name:"Nonce",type:"uint256"}]},domain:{name:"WBTC GARDEN",version:"1"},primaryType:"Data",message:{Message:"Initialize your swap",Version:"1.0.0",Nonce:1n}});return P.Ok(new Kt(P.trim0x(Oe.sha256(r))))}catch(r){return P.Err("Failed to initialize: "+r)}}getMasterPrivKey(){return this.privKey}generateSecret(t){const r=this.signMessage(t),n=Oe.sha256(We(r)),o=Oe.sha256(n);return P.Ok({secret:n,secretHash:o})}signMessage(t){const r=Yn.ECPairFactory(ct),n="Garden.fi"+t.toString(),o=Buffer.from(n,"utf8"),s=Oe.sha256(o),c=Buffer.from(P.trim0x(this.privKey),"hex");if(c.length!==32)throw new Error("Invalid private key length. Expected 32 bytes.");return r.fromPrivateKey(c).sign(Buffer.from(P.trim0x(s),"hex")).toString("hex")}}class Uf{constructor(t){this.quoteUrl=new Rt("/quote",t)}async getQuote(t,r,n=!1){try{const o=this.quoteUrl.addSearchParams({order_pair:t,amount:r.toString(),exact_out:n.toString()}),s=await P.Fetcher.get(o);return s.error?P.Err(s.error):s.result?P.Ok(s.result):P.Err("GetQuote: Unexpected error, result is undefined")}catch(o){return P.Err("GetQuote:",String(o))}}async getAttestedQuote(t){try{const r=await P.Fetcher.post(this.quoteUrl.endpoint("/attested").toString(),{body:JSON.stringify(t),headers:{"Content-Type":"application/json"}});return r.error?P.Err(r.error):r.result?P.Ok(r.result):P.Err("GetAttestedQuote: Unexpected error, result is undefined")}catch(r){return console.log("error :",r),P.Err("GetAttestedQuote:",String(r))}}}exports.EvmRelay=Jn;exports.Garden=Ua;exports.ParseOrderStatus=Kn;exports.ParseSwapStatus=Ht;exports.Quote=Uf;exports.SecretManager=Kt;exports.parseAction=Vn;exports.switchOrAddNetwork=Ta;