@gardenfi/core 0.3.0-beta.13 → 0.3.0-beta.15

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,7 +1,4 @@
1
- "use strict";var Ds=Object.defineProperty;var $s=(e,t,r)=>t in e?Ds(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var mt=(e,t,r)=>$s(e,typeof t!="symbol"?t+"":t,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const k=require("@catalogfi/utils"),X=require("@gardenfi/orderbook"),me=require("@gardenfi/utils"),He=require("viem"),Hs=require("varuint-bitcoin"),zs=require("tiny-secp256k1"),_i=require("bitcoinjs-lib"),kn=require("@catalogfi/wallets"),Gs=require("bignumber.js");function ln(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 Pn=ln(Hs),at=ln(zs),oe=ln(_i);var ce=(e=>(e.Idle="Idle",e.Initiate="Initiate",e.Redeem="Redeem",e.Refund="Refund",e))(ce||{});function dt(e){return{formatters:void 0,fees:void 0,serializers:void 0,...e}}const wi="2.21.41";let Ot={getDocsUrl:({docsBaseUrl:e,docsPath:t="",docsSlug:r})=>t?`${e??"https://viem.sh"}${t}${r?`#${r}`:""}`:void 0,version:`viem@${wi}`};class Z extends Error{constructor(t,r={}){var u;const n=(()=>{var l;return r.cause instanceof Z?r.cause.details:(l=r.cause)!=null&&l.message?r.cause.message:r.details})(),i=r.cause instanceof Z&&r.cause.docsPath||r.docsPath,a=(u=Ot.getDocsUrl)==null?void 0:u.call(Ot,{...r,docsPath:i}),f=[t||"An error occurred.","",...r.metaMessages?[...r.metaMessages,""]:[],...a?[`Docs: ${a}`]:[],...n?[`Details: ${n}`]:[],...Ot.version?[`Version: ${Ot.version}`]:[]].join(`
2
- `);super(f,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=n,this.docsPath=i,this.metaMessages=r.metaMessages,this.name=r.name??this.name,this.shortMessage=t,this.version=wi}walk(t){return xi(this,t)}}function xi(e,t){return t!=null&&t(e)?e:e&&typeof e=="object"&&"cause"in e&&e.cause!==void 0?xi(e.cause,t):t?null:e}class js extends Z{constructor({max:t,min:r,signed:n,size:i,value:a}){super(`Number "${a}" is not in safe ${i?`${i*8}-bit ${n?"signed":"unsigned"} `:""}integer range ${t?`(${r} to ${t})`:`(above ${r})`}`,{name:"IntegerOutOfRangeError"})}}class Ws extends Z{constructor({givenSize:t,maxSize:r}){super(`Size cannot exceed ${r} bytes. Given size: ${t} bytes.`,{name:"SizeOverflowError"})}}function Yt(e,{strict:t=!0}={}){return!e||typeof e!="string"?!1:t?/^0x[0-9a-fA-F]*$/.test(e):e.startsWith("0x")}function Bt(e){return Yt(e,{strict:!1})?Math.ceil((e.length-2)/2):e.length}function cr(e,{dir:t="left"}={}){let r=typeof e=="string"?e.replace("0x",""):e,n=0;for(let i=0;i<r.length-1&&r[t==="left"?i:r.length-i-1].toString()==="0";i++)n++;return r=t==="left"?r.slice(n):r.slice(0,r.length-n),typeof e=="string"?(r.length===1&&t==="right"&&(r=`${r}0`),`0x${r.length%2===1?`0${r}`:r}`):r}class qs extends Z{constructor({offset:t,position:r,size:n}){super(`Slice ${r==="start"?"starting":"ending"} at offset "${t}" is out-of-bounds (size: ${n}).`,{name:"SliceOffsetOutOfBoundsError"})}}class vi extends Z{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 Rt(e,{dir:t,size:r=32}={}){return typeof e=="string"?Vs(e,{dir:t,size:r}):Ks(e,{dir:t,size:r})}function Vs(e,{dir:t,size:r=32}={}){if(r===null)return e;const n=e.replace("0x","");if(n.length>r*2)throw new vi({size:Math.ceil(n.length/2),targetSize:r,type:"hex"});return`0x${n[t==="right"?"padEnd":"padStart"](r*2,"0")}`}function Ks(e,{dir:t,size:r=32}={}){if(r===null)return e;if(e.length>r)throw new vi({size:e.length,targetSize:r,type:"bytes"});const n=new Uint8Array(r);for(let i=0;i<r;i++){const a=t==="right";n[a?i:r-i-1]=e[a?i:e.length-i-1]}return n}const Ys=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function W(e,t={}){return typeof e=="number"||typeof e=="bigint"?Ei(e,t):typeof e=="string"?Qs(e,t):typeof e=="boolean"?Js(e,t):Ze(e,t)}function Js(e,t={}){const r=`0x${Number(e)}`;return typeof t.size=="number"?(Tt(r,{size:t.size}),Rt(r,{size:t.size})):r}function Ze(e,t={}){let r="";for(let i=0;i<e.length;i++)r+=Ys[e[i]];const n=`0x${r}`;return typeof t.size=="number"?(Tt(n,{size:t.size}),Rt(n,{dir:"right",size:t.size})):n}function Ei(e,t={}){const{signed:r,size:n}=t,i=BigInt(e);let a;n?r?a=(1n<<BigInt(n)*8n-1n)-1n:a=2n**(BigInt(n)*8n)-1n:typeof e=="number"&&(a=BigInt(Number.MAX_SAFE_INTEGER));const f=typeof a=="bigint"&&r?-a-1n:0;if(a&&i>a||i<f){const l=typeof e=="bigint"?"n":"";throw new js({max:a?`${a}${l}`:void 0,min:`${f}${l}`,signed:r,size:n,value:`${e}${l}`})}const u=`0x${(r&&i<0?(1n<<BigInt(n*8))+BigInt(i):i).toString(16)}`;return n?Rt(u,{size:n}):u}const Xs=new TextEncoder;function Qs(e,t={}){const r=Xs.encode(e);return Ze(r,t)}const Zs=new TextEncoder;function Bi(e,t={}){return typeof e=="number"||typeof e=="bigint"?to(e,t):typeof e=="boolean"?eo(e,t):Yt(e)?ft(e,t):Si(e,t)}function eo(e,t={}){const r=new Uint8Array(1);return r[0]=Number(e),typeof t.size=="number"?(Tt(r,{size:t.size}),Rt(r,{size:t.size})):r}const Me={zero:48,nine:57,A:65,F:70,a:97,f:102};function Cn(e){if(e>=Me.zero&&e<=Me.nine)return e-Me.zero;if(e>=Me.A&&e<=Me.F)return e-(Me.A-10);if(e>=Me.a&&e<=Me.f)return e-(Me.a-10)}function ft(e,t={}){let r=e;t.size&&(Tt(r,{size:t.size}),r=Rt(r,{dir:"right",size:t.size}));let n=r.slice(2);n.length%2&&(n=`0${n}`);const i=n.length/2,a=new Uint8Array(i);for(let f=0,u=0;f<i;f++){const l=Cn(n.charCodeAt(u++)),b=Cn(n.charCodeAt(u++));if(l===void 0||b===void 0)throw new Z(`Invalid byte sequence ("${n[u-2]}${n[u-1]}" in "${n}").`);a[f]=l*16+b}return a}function to(e,t){const r=Ei(e,t);return ft(r)}function Si(e,t={}){const r=Zs.encode(e);return typeof t.size=="number"?(Tt(r,{size:t.size}),Rt(r,{dir:"right",size:t.size})):r}function Tt(e,{size:t}){if(Bt(e)>t)throw new Ws({givenSize:Bt(e),maxSize:t})}function xt(e,t={}){const{signed:r}=t;t.size&&Tt(e,{size:t.size});const n=BigInt(e);if(!r)return n;const i=(e.length-2)/2,a=(1n<<BigInt(i)*8n-1n)-1n;return n<=a?n:n-BigInt(`0x${"f".padStart(i*2,"f")}`)-1n}function lr(e,t={}){return Number(xt(e,t))}function hn(e,t){return({exclude:r,format:n})=>({exclude:r,format:i=>{const a=t(i);if(r)for(const f of r)delete a[f];return{...a,...n(i)}},type:e})}const Ai={"0x0":"legacy","0x1":"eip2930","0x2":"eip1559","0x3":"eip4844","0x4":"eip7702"};function dn(e){const t={...e,blockHash:e.blockHash?e.blockHash:null,blockNumber:e.blockNumber?BigInt(e.blockNumber):null,chainId:e.chainId?lr(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?lr(e.nonce):void 0,to:e.to?e.to:null,transactionIndex:e.transactionIndex?Number(e.transactionIndex):null,type:e.type?Ai[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=no(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}const ro=hn("transaction",dn);function no(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 io(e){var r;const t=(r=e.transactions)==null?void 0:r.map(n=>typeof n=="string"?n:dn(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:t,totalDifficulty:e.totalDifficulty?BigInt(e.totalDifficulty):null}}const so=hn("block",io);function oo(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 ao={"0x0":"reverted","0x1":"success"};function fo(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=>oo(r)):null,to:e.to?e.to:null,transactionIndex:e.transactionIndex?lr(e.transactionIndex):null,status:e.status?ao[e.status]:null,type:e.type?Ai[e.type]||e.type:null};return e.blobGasPrice&&(t.blobGasPrice=BigInt(e.blobGasPrice)),e.blobGasUsed&&(t.blobGasUsed=BigInt(e.blobGasUsed)),t}const uo=hn("transactionReceipt",fo),pn=2n**256n-1n;function Jt(e){return`0x${e.reduce((t,r)=>t+r.replace("0x",""),"")}`}class Ln extends Z{constructor({offset:t}){super(`Offset \`${t}\` cannot be negative.`,{name:"NegativeOffsetError"})}}class co extends Z{constructor({length:t,position:r}){super(`Position \`${r}\` is out of bounds (\`0 < position < ${t}\`).`,{name:"PositionOutOfBoundsError"})}}class lo extends Z{constructor({count:t,limit:r}){super(`Recursive read limit of \`${r}\` exceeded (recursive read count: \`${t}\`).`,{name:"RecursiveReadLimitExceededError"})}}const ho={bytes:new Uint8Array,dataView:new DataView(new ArrayBuffer(0)),position:0,positionReadCount:new Map,recursiveReadCount:0,recursiveReadLimit:Number.POSITIVE_INFINITY,assertReadLimit(){if(this.recursiveReadCount>=this.recursiveReadLimit)throw new lo({count:this.recursiveReadCount+1,limit:this.recursiveReadLimit})},assertPosition(e){if(e<0||e>this.bytes.length-1)throw new co({length:this.bytes.length,position:e})},decrementPosition(e){if(e<0)throw new Ln({offset:e});const t=this.position-e;this.assertPosition(t),this.position=t},getReadCount(e){return this.positionReadCount.get(e||this.position)||0},incrementPosition(e){if(e<0)throw new Ln({offset:e});const t=this.position+e;this.assertPosition(t),this.position=t},inspectByte(e){const t=e??this.position;return this.assertPosition(t),this.bytes[t]},inspectBytes(e,t){const r=t??this.position;return this.assertPosition(r+e-1),this.bytes.subarray(r,r+e)},inspectUint8(e){const t=e??this.position;return this.assertPosition(t),this.bytes[t]},inspectUint16(e){const t=e??this.position;return this.assertPosition(t+1),this.dataView.getUint16(t)},inspectUint24(e){const t=e??this.position;return this.assertPosition(t+2),(this.dataView.getUint16(t)<<8)+this.dataView.getUint8(t+2)},inspectUint32(e){const t=e??this.position;return this.assertPosition(t+3),this.dataView.getUint32(t)},pushByte(e){this.assertPosition(this.position),this.bytes[this.position]=e,this.position++},pushBytes(e){this.assertPosition(this.position+e.length-1),this.bytes.set(e,this.position),this.position+=e.length},pushUint8(e){this.assertPosition(this.position),this.bytes[this.position]=e,this.position++},pushUint16(e){this.assertPosition(this.position+1),this.dataView.setUint16(this.position,e),this.position+=2},pushUint24(e){this.assertPosition(this.position+2),this.dataView.setUint16(this.position,e>>8),this.dataView.setUint8(this.position+2,e&255),this.position+=3},pushUint32(e){this.assertPosition(this.position+3),this.dataView.setUint32(this.position,e),this.position+=4},readByte(){this.assertReadLimit(),this._touch();const e=this.inspectByte();return this.position++,e},readBytes(e,t){this.assertReadLimit(),this._touch();const r=this.inspectBytes(e);return this.position+=t??e,r},readUint8(){this.assertReadLimit(),this._touch();const e=this.inspectUint8();return this.position+=1,e},readUint16(){this.assertReadLimit(),this._touch();const e=this.inspectUint16();return this.position+=2,e},readUint24(){this.assertReadLimit(),this._touch();const e=this.inspectUint24();return this.position+=3,e},readUint32(){this.assertReadLimit(),this._touch();const e=this.inspectUint32();return this.position+=4,e},get remaining(){return this.bytes.length-this.position},setPosition(e){const t=this.position;return this.assertPosition(e),this.position=e,()=>this.position=t},_touch(){if(this.recursiveReadLimit===Number.POSITIVE_INFINITY)return;const e=this.getReadCount();this.positionReadCount.set(this.position,e+1),e>0&&this.recursiveReadCount++}};function Ii(e,{recursiveReadLimit:t=8192}={}){const r=Object.create(ho);return r.bytes=e,r.dataView=new DataView(e.buffer,e.byteOffset,e.byteLength),r.positionReadCount=new Map,r.recursiveReadLimit=t,r}function ut(e,t="hex"){const r=Ri(e),n=Ii(new Uint8Array(r.length));return r.encode(n),t==="hex"?Ze(n.bytes):n.bytes}function Ri(e){return Array.isArray(e)?po(e.map(t=>Ri(t))):bo(e)}function po(e){const t=e.reduce((i,a)=>i+a.length,0),r=Ti(t);return{length:t<=55?1+t:1+r+t,encode(i){t<=55?i.pushByte(192+t):(i.pushByte(247+r),r===1?i.pushUint8(t):r===2?i.pushUint16(t):r===3?i.pushUint24(t):i.pushUint32(t));for(const{encode:a}of e)a(i)}}}function bo(e){const t=typeof e=="string"?ft(e):e,r=Ti(t.length);return{length:t.length===1&&t[0]<128?1:t.length<=55?1+t.length:1+r+t.length,encode(i){t.length===1&&t[0]<128?i.pushBytes(t):t.length<=55?(i.pushByte(128+t.length),i.pushBytes(t)):(i.pushByte(183+r),r===1?i.pushUint8(t.length):r===2?i.pushUint16(t.length):r===3?i.pushUint24(t.length):i.pushUint32(t.length),i.pushBytes(t))}}}function Ti(e){if(e<2**8)return 1;if(e<2**16)return 2;if(e<2**24)return 3;if(e<2**32)return 4;throw new Z("Length is too large.")}const yo={ether:-9,wei:9};function go(e,t){let r=e.toString();const n=r.startsWith("-");n&&(r=r.slice(1)),r=r.padStart(t,"0");let[i,a]=[r.slice(0,r.length-t),r.slice(r.length-t)];return a=a.replace(/(0+)$/,""),`${n?"-":""}${i||"0"}${a?`.${a}`:""}`}function Zr(e,t="wei"){return go(e,yo[t])}function mo(e){const t=Object.entries(e).map(([n,i])=>i===void 0||i===!1?null:[n,i]).filter(Boolean),r=t.reduce((n,[i])=>Math.max(n,i.length),0);return t.map(([n,i])=>` ${`${n}:`.padEnd(r+1)} ${i}`).join(`
3
- `)}class _o extends Z{constructor({v:t}){super(`Invalid \`v\` value "${t}". Expected 27 or 28.`,{name:"InvalidLegacyVError"})}}class wo extends Z{constructor({transaction:t}){super("Cannot infer a transaction type from provided transaction.",{metaMessages:["Provided Transaction:","{",mo(t),"}","","To infer the type, either provide:","- a `type` to the Transaction, or","- an EIP-1559 Transaction with `maxFeePerGas`, or","- an EIP-2930 Transaction with `gasPrice` & `accessList`, or","- an EIP-4844 Transaction with `blobs`, `blobVersionedHashes`, `sidecars`, or","- an EIP-7702 Transaction with `authorizationList`, or","- a Legacy Transaction with `gasPrice`"],name:"InvalidSerializableTransactionError"})}}class xo extends Z{constructor({storageKey:t}){super(`Size for storage key "${t}" is invalid. Expected 32 bytes. Got ${Math.floor((t.length-2)/2)} bytes.`,{name:"InvalidStorageKeySizeError"})}}function ki(e){const{kzg:t}=e,r=e.to??(typeof e.blobs[0]=="string"?"hex":"bytes"),n=typeof e.blobs[0]=="string"?e.blobs.map(a=>ft(a)):e.blobs,i=[];for(const a of n)i.push(Uint8Array.from(t.blobToKzgCommitment(a)));return r==="bytes"?i:i.map(a=>Ze(a))}function Pi(e){const{kzg:t}=e,r=e.to??(typeof e.blobs[0]=="string"?"hex":"bytes"),n=typeof e.blobs[0]=="string"?e.blobs.map(f=>ft(f)):e.blobs,i=typeof e.commitments[0]=="string"?e.commitments.map(f=>ft(f)):e.commitments,a=[];for(let f=0;f<n.length;f++){const u=n[f],l=i[f];a.push(Uint8Array.from(t.computeBlobKzgProof(u,l)))}return r==="bytes"?a:a.map(f=>Ze(f))}function On(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function vo(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function bn(e,...t){if(!vo(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${e.length}`)}function hr(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Ci(e,t){bn(e);const r=t.outputLen;if(e.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Eo=e=>new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4)),Fr=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),Oe=(e,t)=>e<<32-t|e>>>t,Fn=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68,Bo=e=>e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255;function Un(e){for(let t=0;t<e.length;t++)e[t]=Bo(e[t])}function So(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function yn(e){return typeof e=="string"&&(e=So(e)),bn(e),e}let Li=class{clone(){return this._cloneInto()}};function Oi(e){const t=n=>e().update(yn(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function Ao(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);const i=BigInt(32),a=BigInt(4294967295),f=Number(r>>i&a),u=Number(r&a),l=n?4:0,b=n?0:4;e.setUint32(t+l,f,n),e.setUint32(t+b,u,n)}const Io=(e,t,r)=>e&t^~e&r,Ro=(e,t,r)=>e&t^e&r^t&r;class To extends Li{constructor(t,r,n,i){super(),this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=Fr(this.buffer)}update(t){hr(this);const{view:r,buffer:n,blockLen:i}=this;t=yn(t);const a=t.length;for(let f=0;f<a;){const u=Math.min(i-this.pos,a-f);if(u===i){const l=Fr(t);for(;i<=a-f;f+=i)this.process(l,f);continue}n.set(t.subarray(f,f+u),this.pos),this.pos+=u,f+=u,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){hr(this),Ci(t,this),this.finished=!0;const{buffer:r,view:n,blockLen:i,isLE:a}=this;let{pos:f}=this;r[f++]=128,this.buffer.subarray(f).fill(0),this.padOffset>i-f&&(this.process(n,0),f=0);for(let m=f;m<i;m++)r[m]=0;Ao(n,i-8,BigInt(this.length*8),a),this.process(n,0);const u=Fr(t),l=this.outputLen;if(l%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const b=l/4,g=this.get();if(b>g.length)throw new Error("_sha2: outputLen bigger than state");for(let m=0;m<b;m++)u.setUint32(4*m,g[m],a)}digest(){const{buffer:t,outputLen:r}=this;this.digestInto(t);const n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:r,buffer:n,length:i,finished:a,destroyed:f,pos:u}=this;return t.length=i,t.pos=u,t.finished=a,t.destroyed=f,i%r&&t.buffer.set(n),t}}const ko=new Uint32Array([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]),Ye=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Je=new Uint32Array(64);class Po extends To{constructor(){super(64,32,8,!1),this.A=Ye[0]|0,this.B=Ye[1]|0,this.C=Ye[2]|0,this.D=Ye[3]|0,this.E=Ye[4]|0,this.F=Ye[5]|0,this.G=Ye[6]|0,this.H=Ye[7]|0}get(){const{A:t,B:r,C:n,D:i,E:a,F:f,G:u,H:l}=this;return[t,r,n,i,a,f,u,l]}set(t,r,n,i,a,f,u,l){this.A=t|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=a|0,this.F=f|0,this.G=u|0,this.H=l|0}process(t,r){for(let m=0;m<16;m++,r+=4)Je[m]=t.getUint32(r,!1);for(let m=16;m<64;m++){const v=Je[m-15],A=Je[m-2],B=Oe(v,7)^Oe(v,18)^v>>>3,P=Oe(A,17)^Oe(A,19)^A>>>10;Je[m]=P+Je[m-7]+B+Je[m-16]|0}let{A:n,B:i,C:a,D:f,E:u,F:l,G:b,H:g}=this;for(let m=0;m<64;m++){const v=Oe(u,6)^Oe(u,11)^Oe(u,25),A=g+v+Io(u,l,b)+ko[m]+Je[m]|0,P=(Oe(n,2)^Oe(n,13)^Oe(n,22))+Ro(n,i,a)|0;g=b,b=l,l=u,u=f+A|0,f=a,a=i,i=n,n=A+P|0}n=n+this.A|0,i=i+this.B|0,a=a+this.C|0,f=f+this.D|0,u=u+this.E|0,l=l+this.F|0,b=b+this.G|0,g=g+this.H|0,this.set(n,i,a,f,u,l,b,g)}roundClean(){Je.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}const Co=Oi(()=>new Po);function Lo(e,t){return Co(Yt(e,{strict:!1})?Bi(e):e)}function Oo(e){const{commitment:t,version:r=1}=e,n=e.to??(typeof t=="string"?"hex":"bytes"),i=Lo(t);return i.set([r],0),n==="bytes"?i:Ze(i)}function Fo(e){const{commitments:t,version:r}=e,n=e.to??(typeof t[0]=="string"?"hex":"bytes"),i=[];for(const a of t)i.push(Oo({commitment:a,to:n,version:r}));return i}const Nn=6,Fi=32,gn=4096,Ui=Fi*gn,Mn=Ui*Nn-1-1*gn*Nn,Ni=1;class Uo extends Z{constructor({maxSize:t,size:r}){super("Blob size is too large.",{metaMessages:[`Max: ${t} bytes`,`Given: ${r} bytes`],name:"BlobSizeTooLargeError"})}}class Mi extends Z{constructor(){super("Blob data must not be empty.",{name:"EmptyBlobError"})}}class No extends Z{constructor({hash:t,size:r}){super(`Versioned hash "${t}" size is invalid.`,{metaMessages:["Expected: 32",`Received: ${r}`],name:"InvalidVersionedHashSizeError"})}}class Mo extends Z{constructor({hash:t,version:r}){super(`Versioned hash "${t}" version is invalid.`,{metaMessages:[`Expected: ${Ni}`,`Received: ${r}`],name:"InvalidVersionedHashVersionError"})}}function Do(e){const t=e.to??(typeof e.data=="string"?"hex":"bytes"),r=typeof e.data=="string"?ft(e.data):e.data,n=Bt(r);if(!n)throw new Mi;if(n>Mn)throw new Uo({maxSize:Mn,size:n});const i=[];let a=!0,f=0;for(;a;){const u=Ii(new Uint8Array(Ui));let l=0;for(;l<gn;){const b=r.slice(f,f+(Fi-1));if(u.pushByte(0),u.pushBytes(b),b.length<31){u.pushByte(128),a=!1;break}l++,f+=31}i.push(u)}return t==="bytes"?i.map(u=>u.bytes):i.map(u=>Ze(u.bytes))}function $o(e){const{data:t,kzg:r,to:n}=e,i=e.blobs??Do({data:t,to:n}),a=e.commitments??ki({blobs:i,kzg:r,to:n}),f=e.proofs??Pi({blobs:i,commitments:a,kzg:r,to:n}),u=[];for(let l=0;l<i.length;l++)u.push({blob:i[l],commitment:a[l],proof:f[l]});return u}function Ho(e){if(!e||e.length===0)return[];const t=[];for(const r of e){const{contractAddress:n,chainId:i,nonce:a,...f}=r;t.push([i?W(i):"0x",n,a?W(a):"0x",...Xt({},f)])}return t}class ct extends Z{constructor({address:t}){super(`Address "${t}" is invalid.`,{metaMessages:["- Address must be a hex value of 20 bytes (40 hex characters).","- Address must match its checksum counterpart."],name:"InvalidAddressError"})}}class wr extends Z{constructor({chainId:t}){super(typeof t=="number"?`Chain ID "${t}" is invalid.`:"Chain ID is invalid.",{name:"InvalidChainIdError"})}}class xr extends Z{constructor({cause:t,maxFeePerGas:r}={}){super(`The fee cap (\`maxFeePerGas\`${r?` = ${Zr(r)} gwei`:""}) cannot be higher than the maximum allowed value (2^256-1).`,{cause:t,name:"FeeCapTooHighError"})}}Object.defineProperty(xr,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/max fee per gas higher than 2\^256-1|fee cap higher than 2\^256-1/});class Di extends Z{constructor({cause:t,maxPriorityFeePerGas:r,maxFeePerGas:n}={}){super([`The provided tip (\`maxPriorityFeePerGas\`${r?` = ${Zr(r)} gwei`:""}) cannot be higher than the fee cap (\`maxFeePerGas\`${n?` = ${Zr(n)} gwei`:""}).`].join(`
4
- `),{cause:t,name:"TipAboveFeeCapError"})}}Object.defineProperty(Di,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/max priority fee per gas higher than max fee per gas|tip higher than fee cap/});class $i extends Map{constructor(t){super(),Object.defineProperty(this,"maxSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.maxSize=t}get(t){const r=super.get(t);return super.has(t)&&r!==void 0&&(this.delete(t),super.set(t,r)),r}set(t,r){if(super.set(t,r),this.maxSize&&this.size>this.maxSize){const n=this.keys().next().value;n&&this.delete(n)}return this}}const ir=BigInt(2**32-1),Dn=BigInt(32);function zo(e,t=!1){return t?{h:Number(e&ir),l:Number(e>>Dn&ir)}:{h:Number(e>>Dn&ir)|0,l:Number(e&ir)|0}}function Go(e,t=!1){let r=new Uint32Array(e.length),n=new Uint32Array(e.length);for(let i=0;i<e.length;i++){const{h:a,l:f}=zo(e[i],t);[r[i],n[i]]=[a,f]}return[r,n]}const jo=(e,t,r)=>e<<r|t>>>32-r,Wo=(e,t,r)=>t<<r|e>>>32-r,qo=(e,t,r)=>t<<r-32|e>>>64-r,Vo=(e,t,r)=>e<<r-32|t>>>64-r,Hi=[],zi=[],Gi=[],Ko=BigInt(0),Ft=BigInt(1),Yo=BigInt(2),Jo=BigInt(7),Xo=BigInt(256),Qo=BigInt(113);for(let e=0,t=Ft,r=1,n=0;e<24;e++){[r,n]=[n,(2*r+3*n)%5],Hi.push(2*(5*n+r)),zi.push((e+1)*(e+2)/2%64);let i=Ko;for(let a=0;a<7;a++)t=(t<<Ft^(t>>Jo)*Qo)%Xo,t&Yo&&(i^=Ft<<(Ft<<BigInt(a))-Ft);Gi.push(i)}const[Zo,ea]=Go(Gi,!0),$n=(e,t,r)=>r>32?qo(e,t,r):jo(e,t,r),Hn=(e,t,r)=>r>32?Vo(e,t,r):Wo(e,t,r);function ta(e,t=24){const r=new Uint32Array(10);for(let n=24-t;n<24;n++){for(let f=0;f<10;f++)r[f]=e[f]^e[f+10]^e[f+20]^e[f+30]^e[f+40];for(let f=0;f<10;f+=2){const u=(f+8)%10,l=(f+2)%10,b=r[l],g=r[l+1],m=$n(b,g,1)^r[u],v=Hn(b,g,1)^r[u+1];for(let A=0;A<50;A+=10)e[f+A]^=m,e[f+A+1]^=v}let i=e[2],a=e[3];for(let f=0;f<24;f++){const u=zi[f],l=$n(i,a,u),b=Hn(i,a,u),g=Hi[f];i=e[g],a=e[g+1],e[g]=l,e[g+1]=b}for(let f=0;f<50;f+=10){for(let u=0;u<10;u++)r[u]=e[f+u];for(let u=0;u<10;u++)e[f+u]^=~r[(u+2)%10]&r[(u+4)%10]}e[0]^=Zo[n],e[1]^=ea[n]}r.fill(0)}class mn extends Li{constructor(t,r,n,i=!1,a=24){if(super(),this.blockLen=t,this.suffix=r,this.outputLen=n,this.enableXOF=i,this.rounds=a,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,On(n),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=Eo(this.state)}keccak(){Fn||Un(this.state32),ta(this.state32,this.rounds),Fn||Un(this.state32),this.posOut=0,this.pos=0}update(t){hr(this);const{blockLen:r,state:n}=this;t=yn(t);const i=t.length;for(let a=0;a<i;){const f=Math.min(r-this.pos,i-a);for(let u=0;u<f;u++)n[this.pos++]^=t[a++];this.pos===r&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:t,suffix:r,pos:n,blockLen:i}=this;t[n]^=r,r&128&&n===i-1&&this.keccak(),t[i-1]^=128,this.keccak()}writeInto(t){hr(this,!1),bn(t),this.finish();const r=this.state,{blockLen:n}=this;for(let i=0,a=t.length;i<a;){this.posOut>=n&&this.keccak();const f=Math.min(n-this.posOut,a-i);t.set(r.subarray(this.posOut,this.posOut+f),i),this.posOut+=f,i+=f}return t}xofInto(t){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(t)}xof(t){return On(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(Ci(t,this),this.finished)throw new Error("digest() was already called");return this.writeInto(t),this.destroy(),t}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(t){const{blockLen:r,suffix:n,outputLen:i,rounds:a,enableXOF:f}=this;return t||(t=new mn(r,n,i,f,a)),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=a,t.suffix=n,t.outputLen=i,t.enableXOF=f,t.destroyed=this.destroyed,t}}const ra=(e,t,r)=>Oi(()=>new mn(t,e,r)),na=ra(1,136,256/8);function ia(e,t){return na(Yt(e,{strict:!1})?Bi(e):e)}const Ur=new $i(8192);function sa(e,t){if(Ur.has(`${e}.${t}`))return Ur.get(`${e}.${t}`);const r=e.substring(2).toLowerCase(),n=ia(Si(r)),i=r.split("");for(let f=0;f<40;f+=2)n[f>>1]>>4>=8&&i[f]&&(i[f]=i[f].toUpperCase()),(n[f>>1]&15)>=8&&i[f+1]&&(i[f+1]=i[f+1].toUpperCase());const a=`0x${i.join("")}`;return Ur.set(`${e}.${t}`,a),a}const oa=/^0x[a-fA-F0-9]{40}$/,Nr=new $i(8192);function lt(e,t){const{strict:r=!0}=t??{},n=`${e}.${r}`;if(Nr.has(n))return Nr.get(n);const i=oa.test(e)?e.toLowerCase()===e?!0:r?sa(e)===e:!0:!1;return Nr.set(n,i),i}function aa(e,t,r,{strict:n}={}){return Yt(e,{strict:!1})?ua(e,t,r,{strict:n}):fa(e,t,r,{strict:n})}function ji(e,t,r){if(Bt(e)!==r-t)throw new qs({offset:r,position:"end",size:Bt(e)})}function fa(e,t,r,{strict:n}={}){const i=e.slice(t,r);return n&&ji(i,t,r),i}function ua(e,t,r,{strict:n}={}){const i=`0x${e.replace("0x","").slice(t*2,r*2)}`;return n&&ji(i,t,r),i}function ca(e){const{authorizationList:t}=e;if(t)for(const r of t){const{contractAddress:n,chainId:i}=r;if(!lt(n))throw new ct({address:n});if(i<0)throw new wr({chainId:i})}_n(e)}function la(e){const{blobVersionedHashes:t}=e;if(t){if(t.length===0)throw new Mi;for(const r of t){const n=Bt(r),i=lr(aa(r,0,1));if(n!==32)throw new No({hash:r,size:n});if(i!==Ni)throw new Mo({hash:r,version:i})}}_n(e)}function _n(e){const{chainId:t,maxPriorityFeePerGas:r,maxFeePerGas:n,to:i}=e;if(t<=0)throw new wr({chainId:t});if(i&&!lt(i))throw new ct({address:i});if(n&&n>pn)throw new xr({maxFeePerGas:n});if(r&&n&&r>n)throw new Di({maxFeePerGas:n,maxPriorityFeePerGas:r})}function ha(e){const{chainId:t,maxPriorityFeePerGas:r,gasPrice:n,maxFeePerGas:i,to:a}=e;if(t<=0)throw new wr({chainId:t});if(a&&!lt(a))throw new ct({address:a});if(r||i)throw new Z("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid EIP-2930 Transaction attribute.");if(n&&n>pn)throw new xr({maxFeePerGas:n})}function da(e){const{chainId:t,maxPriorityFeePerGas:r,gasPrice:n,maxFeePerGas:i,to:a}=e;if(a&&!lt(a))throw new ct({address:a});if(typeof t<"u"&&t<=0)throw new wr({chainId:t});if(r||i)throw new Z("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid Legacy Transaction attribute.");if(n&&n>pn)throw new xr({maxFeePerGas:n})}function pa(e){if(e.type)return e.type;if(typeof e.authorizationList<"u")return"eip7702";if(typeof e.blobs<"u"||typeof e.blobVersionedHashes<"u"||typeof e.maxFeePerBlobGas<"u"||typeof e.sidecars<"u")return"eip4844";if(typeof e.maxFeePerGas<"u"||typeof e.maxPriorityFeePerGas<"u")return"eip1559";if(typeof e.gasPrice<"u")return typeof e.accessList<"u"?"eip2930":"legacy";throw new wo({transaction:e})}function vr(e){if(!e||e.length===0)return[];const t=[];for(let r=0;r<e.length;r++){const{address:n,storageKeys:i}=e[r];for(let a=0;a<i.length;a++)if(i[a].length-2!==64)throw new xo({storageKey:i[a]});if(!lt(n,{strict:!1}))throw new ct({address:n});t.push([n,i])}return t}function ba(e,t){const r=pa(e);return r==="eip1559"?ma(e,t):r==="eip2930"?_a(e,t):r==="eip4844"?ga(e,t):r==="eip7702"?ya(e,t):wa(e,t)}function ya(e,t){const{authorizationList:r,chainId:n,gas:i,nonce:a,to:f,value:u,maxFeePerGas:l,maxPriorityFeePerGas:b,accessList:g,data:m}=e;ca(e);const v=vr(g),A=Ho(r);return Jt(["0x04",ut([W(n),a?W(a):"0x",b?W(b):"0x",l?W(l):"0x",i?W(i):"0x",f??"0x",u?W(u):"0x",m??"0x",v,A,...Xt(e,t)])])}function ga(e,t){const{chainId:r,gas:n,nonce:i,to:a,value:f,maxFeePerBlobGas:u,maxFeePerGas:l,maxPriorityFeePerGas:b,accessList:g,data:m}=e;la(e);let v=e.blobVersionedHashes,A=e.sidecars;if(e.blobs&&(typeof v>"u"||typeof A>"u")){const O=typeof e.blobs[0]=="string"?e.blobs:e.blobs.map(S=>Ze(S)),L=e.kzg,U=ki({blobs:O,kzg:L});if(typeof v>"u"&&(v=Fo({commitments:U})),typeof A>"u"){const S=Pi({blobs:O,commitments:U,kzg:L});A=$o({blobs:O,commitments:U,proofs:S})}}const B=vr(g),P=[W(r),i?W(i):"0x",b?W(b):"0x",l?W(l):"0x",n?W(n):"0x",a??"0x",f?W(f):"0x",m??"0x",B,u?W(u):"0x",v??[],...Xt(e,t)],T=[],C=[],F=[];if(A)for(let O=0;O<A.length;O++){const{blob:L,commitment:U,proof:S}=A[O];T.push(L),C.push(U),F.push(S)}return Jt(["0x03",ut(A?[P,T,C,F]:P)])}function ma(e,t){const{chainId:r,gas:n,nonce:i,to:a,value:f,maxFeePerGas:u,maxPriorityFeePerGas:l,accessList:b,data:g}=e;_n(e);const m=vr(b),v=[W(r),i?W(i):"0x",l?W(l):"0x",u?W(u):"0x",n?W(n):"0x",a??"0x",f?W(f):"0x",g??"0x",m,...Xt(e,t)];return Jt(["0x02",ut(v)])}function _a(e,t){const{chainId:r,gas:n,data:i,nonce:a,to:f,value:u,accessList:l,gasPrice:b}=e;ha(e);const g=vr(l),m=[W(r),a?W(a):"0x",b?W(b):"0x",n?W(n):"0x",f??"0x",u?W(u):"0x",i??"0x",g,...Xt(e,t)];return Jt(["0x01",ut(m)])}function wa(e,t){const{chainId:r=0,gas:n,data:i,nonce:a,to:f,value:u,gasPrice:l}=e;da(e);let b=[a?W(a):"0x",l?W(l):"0x",n?W(n):"0x",f??"0x",u?W(u):"0x",i??"0x"];if(t){const g=(()=>{if(t.v>=35n)return(t.v-35n)/2n>0?t.v:27n+(t.v===35n?0n:1n);if(r>0)return BigInt(r*2)+BigInt(35n+t.v-27n);const A=27n+(t.v===27n?0n:1n);if(t.v!==A)throw new _o({v:t.v});return A})(),m=cr(t.r),v=cr(t.s);b=[...b,W(g),m==="0x00"?"0x":m,v==="0x00"?"0x":v]}else r>0&&(b=[...b,W(r),"0x","0x"]);return ut(b)}function Xt(e,t){const r=t??e,{v:n,yParity:i}=r;if(typeof r.r>"u")return[];if(typeof r.s>"u")return[];if(typeof n>"u"&&typeof i>"u")return[];const a=cr(r.r),f=cr(r.s);return[typeof i=="number"?i?W(1):"0x":n===0n?"0x":n===1n?W(1):n===27n?"0x":W(1),a==="0x00"?"0x":a,f==="0x00"?"0x":f]}const xa={gasPriceOracle:{address:"0x420000000000000000000000000000000000000F"},l1Block:{address:"0x4200000000000000000000000000000000000015"},l2CrossDomainMessenger:{address:"0x4200000000000000000000000000000000000007"},l2Erc721Bridge:{address:"0x4200000000000000000000000000000000000014"},l2StandardBridge:{address:"0x4200000000000000000000000000000000000010"},l2ToL1MessagePasser:{address:"0x4200000000000000000000000000000000000016"}},va={block:so({format(e){var r;return{transactions:(r=e.transactions)==null?void 0:r.map(n=>{if(typeof n=="string")return n;const i=dn(n);return i.typeHex==="0x7e"&&(i.isSystemTx=n.isSystemTx,i.mint=n.mint?xt(n.mint):void 0,i.sourceHash=n.sourceHash,i.type="deposit"),i}),stateRoot:e.stateRoot}}}),transaction:ro({format(e){const t={};return e.type==="0x7e"&&(t.isSystemTx=e.isSystemTx,t.mint=e.mint?xt(e.mint):void 0,t.sourceHash=e.sourceHash,t.type="deposit"),t}}),transactionReceipt:uo({format(e){return{l1GasPrice:e.l1GasPrice?xt(e.l1GasPrice):null,l1GasUsed:e.l1GasUsed?xt(e.l1GasUsed):null,l1Fee:e.l1Fee?xt(e.l1Fee):null,l1FeeScalar:e.l1FeeScalar?Number(e.l1FeeScalar):null}}})};function Ea(e,t){return Aa(e)?Sa(e):ba(e,t)}const Ba={transaction:Ea};function Sa(e){Ia(e);const{sourceHash:t,data:r,from:n,gas:i,isSystemTx:a,mint:f,to:u,value:l}=e,b=[t,n,u??"0x",f?W(f):"0x",l?W(l):"0x",i?W(i):"0x",a?"0x1":"0x",r??"0x"];return Jt(["0x7e",ut(b)])}function Aa(e){return e.type==="deposit"||typeof e.sourceHash<"u"}function Ia(e){const{from:t,to:r}=e;if(t&&!lt(t))throw new ct({address:t});if(r&&!lt(r))throw new ct({address:r})}const dr={contracts:xa,formatters:va,serializers:Ba},Ra=dt({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}}}),Ta=dt({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}),Ut=1,ka=dt({...dr,id:8453,name:"Base",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://mainnet.base.org"]}},blockExplorers:{default:{name:"Basescan",url:"https://basescan.org",apiUrl:"https://api.basescan.org/api"}},contracts:{...dr.contracts,disputeGameFactory:{[Ut]:{address:"0x43edB88C4B80fDD2AdFF2412A7BebF9dF42cB40e"}},l2OutputOracle:{[Ut]:{address:"0x56315b90c40730925ec5485cf004d835058518A0"}},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:5022},portal:{[Ut]:{address:"0x49048044D57e1C92A77f79988d21Fa8fAF74E97e",blockCreated:17482143}},l1StandardBridge:{[Ut]:{address:"0x3154Cf16ccdb4C6d922629664174b904d80F2C35",blockCreated:17482143}}},sourceId:Ut}),Nt=11155111,Pa=dt({...dr,id:84532,network:"base-sepolia",name:"Base Sepolia",nativeCurrency:{name:"Sepolia Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://sepolia.base.org"]}},blockExplorers:{default:{name:"Basescan",url:"https://sepolia.basescan.org",apiUrl:"https://api-sepolia.basescan.org/api"}},contracts:{...dr.contracts,disputeGameFactory:{[Nt]:{address:"0xd6E6dBf4F7EA0ac412fD8b65ED297e64BB7a06E1"}},l2OutputOracle:{[Nt]:{address:"0x84457ca9D0163FbC4bbfe4Dfbb20ba46e48DF254"}},portal:{[Nt]:{address:"0x49f53e41452c74589e85ca1677426ba426459e85",blockCreated:4446677}},l1StandardBridge:{[Nt]:{address:"0xfd0Bf71F60660E2f608ed56e1659C450eB113120",blockCreated:4446677}},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:1059647}},testnet:!0,sourceId:Nt}),Ca=dt({id:80084,name:"Berachain bArtio",nativeCurrency:{decimals:18,name:"BERA Token",symbol:"BERA"},contracts:{multicall3:{address:"0xcA11bde05977b3631167028862bE2a173976CA11",blockCreated:109269}},rpcUrls:{default:{http:["https://bartio.rpc.berachain.com"]}},blockExplorers:{default:{name:"Berachain bArtio Beratrail",url:"https://bartio.beratrail.io"}},testnet:!0}),La=dt({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}}}),Oa=dt({id:11155111,name:"Sepolia",nativeCurrency:{name:"Sepolia Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://sepolia.drpc.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 en(e){return typeof e=="string"&&(e=Buffer.from(e,"hex")),e.length===32?e:e.subarray(1,33)}function _t(e,t){if(!e)throw new Error(t)}function Fa(e){return Buffer.concat([Uint8Array.from([192]),Ua(e)])}function Ua(e){const t=Pn.encodingLength(e.length),r=Buffer.allocUnsafe(t);return Pn.encode(e.length,r),Buffer.concat([r,e])}function Na(e,t){if(e.compare(t)>0){const r=e;e=t,t=r}return[e,t]}const st=e=>e.length===64?e:e.slice(2),Ma=e=>{if(!e)return!1;try{const t=Buffer.from(e,"hex");return at.isPoint(t)}catch{return!1}},Da={...Oa,rpcUrls:{default:{http:["https://ethereum-sepolia-rpc.publicnode.com"]}}},Wi={ethereum:La,arbitrum:Ra,ethereum_sepolia:Da,arbitrum_sepolia:Ta,ethereum_localnet:X.EthereumLocalnet,arbitrum_localnet:X.ArbitrumLocalnet,base_sepolia:Pa,base:ka,bera_testnet:Ca},$a=async(e,t)=>{var n;const r=Wi[e];if(r)try{if(r.id===((n=t.chain)==null?void 0:n.id))return k.Ok({message:"Already on the network",walletClient:t});await t.switchChain({id:r.id});const i=He.createWalletClient({account:t.account,chain:r,transport:He.custom(window.ethereum)});return k.Ok({message:"Switched chain",walletClient:i})}catch(i){if(Ha(i))try{await t.addChain({chain:r});const a=He.createWalletClient({account:t.account,chain:r,transport:He.custom(window.ethereum)});return k.Ok({message:"Added network",walletClient:a})}catch{return k.Err("Failed to add network")}else return k.Err("Failed to switch network")}else return k.Err("Chain not supported")},Ha=e=>typeof e=="object"&&e!==null&&"code"in e&&e.code===4902,qi=(e,t,r,n)=>e+":"+t.toLowerCase()+"::"+r+":"+n.toLowerCase();function za(e,t){if(!e)return!1;const r=t==="mainnet"?oe.networks.bitcoin:oe.networks.testnet;oe.initEccLib(at);try{return oe.address.toOutputScript(e,r),!0}catch{return!1}}var Q=(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.DeadLineExceeded="DeadLineExceeded",e))(Q||{}),ne=(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))(ne||{});const wn=(e,t,r)=>{const n=tn(e.source_swap,t),i=tn(e.destination_swap,r);if(i===ne.RedeemDetected)return Q.RedeemDetected;if(i===ne.Redeemed)return Q.Redeemed;if(n===ne.Refunded)return Q.Refunded;if(n===ne.RefundDetected)return Q.RefundDetected;if(i===ne.Expired)return Q.CounterPartySwapExpired;if(n===ne.Expired)return Q.Expired;if(i===ne.Refunded)return Q.CounterPartyRefunded;if(i===ne.RefundDetected)return Q.CounterPartyRefundDetected;const a=Number(e.create_order.additional_data.deadline);return i===ne.Initiated?Q.CounterPartyInitiated:i===ne.InitiateDetected?Q.CounterPartyInitiateDetected:qt(a,12)?Q.DeadLineExceeded:n===ne.Initiated?Q.Initiated:qt(a,1)?Q.DeadLineExceeded:n===ne.InitiateDetected?Q.InitiateDetected:n===ne.Redeemed?Q.CounterPartyRedeemed:n===ne.RedeemDetected?Q.CounterPartyRedeemDetected:Q.Matched},tn=(e,t)=>{if(e.redeem_tx_hash)return Number(e.redeem_block_number)?ne.Redeemed:ne.RedeemDetected;if(e.refund_tx_hash)return Number(e.refund_block_number)?ne.Refunded:ne.RefundDetected;if(Number(e.initiate_block_number)){const r=Number(e.initiate_block_number)+e.timelock;if(t>r)return ne.Expired}return e.initiate_tx_hash?Number(e.initiate_block_number)?ne.Initiated:ne.InitiateDetected:ne.Idle},Ga=(e,t,r)=>{const n=wn(e,t,r);return xn(n)},xn=e=>{switch(e){case Q.Matched:return ce.Initiate;case Q.CounterPartyInitiated:case Q.CounterPartyInitiateDetected:case Q.RedeemDetected:return ce.Redeem;case Q.Expired:return ce.Refund;default:return ce.Idle}},qt=(e,t=0)=>{const r=Date.now(),n=e*1e3+t*36e5;return r>=n},Vi=e=>e.filter(t=>{const{source_swap:r,create_order:n}=t,{initiate_tx_hash:i,initiate_block_number:a}=r,{deadline:f}=n.additional_data;return i&&Number(a)?!0:i&&!Number(a)?!qt(Number(f),12):i?!0:!qt(Number(f),1)}),ja=[{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 Ki{constructor(t,r,n){this.url=new me.Url("/relayer",r),this.auth=n,this.order=t}async init(t){if(!t.account)return k.Err("No account found");if(t.account.address.toLowerCase()!==this.order.source_swap.initiator.toLowerCase())return k.Err("Account address and order initiator mismatch");const{create_order:r,source_swap:n}=this.order;if(!n.amount||!n.redeemer||!r.timelock||!r.secret_hash)return k.Err("Invalid order");const i=me.with0x(r.secret_hash),a=BigInt(r.timelock),f=me.with0x(n.redeemer),u=BigInt(n.amount);try{const l=await this.auth.getToken();if(l.error)return k.Err(l.error);const b=He.getContract({address:me.with0x(this.order.source_swap.asset),abi:ja,client:t}),g=await b.read.token(),m=await me.checkAllowanceAndApprove(Number(u),g,this.order.source_swap.asset,t);if(m.error)return k.Err(m.error);const v=await b.read.eip712Domain(),A=await t.signTypedData({account:t.account,domain:{name:v[1],version:v[2],chainId:Number(v[3]),verifyingContract:v[4]},types:{Initiate:[{name:"redeemer",type:"address"},{name:"timelock",type:"uint256"},{name:"amount",type:"uint256"},{name:"secretHash",type:"bytes32"}]},primaryType:"Initiate",message:{redeemer:f,timelock:a,amount:u,secretHash:i}}),B=await k.Fetcher.post(this.url.endpoint("initiate"),{body:JSON.stringify({order_id:r.create_id,signature:A,perform_on:"Source"}),headers:{Authorization:me.Authorization(l.val),"Content-Type":"application/json"}});return B.error?k.Err(B.error):B.result?k.Ok(B.result):k.Err("Init: No result found")}catch(l){return console.log("init error :",l),k.Err(String(l))}}async redeem(t,r){try{const n=await this.auth.getToken();if(n.error)return k.Err(n.error);const i=await k.Fetcher.post(this.url.endpoint("redeem"),{body:JSON.stringify({order_id:t,secret:k.trim0x(r),perform_on:"Destination"}),headers:{Authorization:me.Authorization(n.val),"Content-Type":"application/json"}});return i.error?k.Err(i.error):i.result?k.Ok(i.result):k.Err("Redeem: No result found")}catch(n){return k.Err(String(n))}}}const Wa=Buffer.from("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","hex"),qa=Buffer.from("483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8","hex"),Va=Buffer.concat([Wa,qa]),Ka=Buffer.from("0250929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0","hex"),zn={failedToCreateInternalPubkey:"failed to create internal pubkey",failedToTweakPubkey:"failed to tweak pubkey"};function Ya(){const e=_i.crypto.sha256(Buffer.from("GardenHTLC","utf-8")),t=at.pointMultiply(Buffer.concat([Buffer.from("04","hex"),Va]),e);if(!t)throw new Error(zn.failedToCreateInternalPubkey);const r=at.pointAdd(Ka,t);if(!r)throw new Error(zn.failedToCreateInternalPubkey);return en(Buffer.from(r))}const _e={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"},sr=192;oe.initEccLib(at);class Wt{constructor(t,r,n,i,a,f,u,l){this.secretHash=n,this.redeemerPubkey=i,this.initiatorPubkey=a,this.expiry=f,this.signer=t,this.network=u,this.internalPubkey=Ya(),this.initiateAmount=r,this.utxoHashes=l}static async from(t,r,n,i,a,f,u){n=n.startsWith("0x")?n.slice(2):n,_t(n.length===64,_e.secretHashLenMismatch),_t(i.length===64||i.length===66,`initiator ${_e.pubkeyLenMismatch}`),_t(a.length===64||a.length===66,`redeemer ${_e.pubkeyLenMismatch}`),_t(f>0,_e.zeroOrNegativeExpiry);const l=await t.getNetwork();return new Wt(t,r,n,en(a).toString("hex"),en(i).toString("hex"),f,l,u)}address(){const{address:t}=oe.payments.p2tr({internalPubkey:this.internalPubkey,network:this.network,scriptTree:this.leaves()});if(!t)throw new Error(_e.htlcAddressGenerationFailed);return t}id(){return this.address()}async _buildRawTx(t,r){const n=new oe.Transaction;n.version=2;const i=this.address(),a=await this.signer.getProvider();let f=[];if(this.utxoHashes&&this.utxoHashes.length>0)for(const l of this.utxoHashes){const b=await a.getTransaction(l);for(let g=0;g<b.vout.length;g++){const m=b.vout[g];m.scriptpubkey_address===i&&f.push({txid:b.txid,vout:g,value:m.value,status:{confirmed:!1}})}}else f=await a.getUTXOs(i);const u=f.reduce((l,b)=>l+b.value,0);if(u===0)throw new Error(`${i} ${_e.notFunded}`);for(let l=0;l<f.length;l++)n.addInput(Buffer.from(f[l].txid,"hex").reverse(),f[l].vout);return r??(r=await a.suggestFee(i,u,kn.Urgency.MEDIUM)),n.addOutput(oe.address.toOutputScript(t,this.network),u-r),{tx:n,usedUtxos:f}}async buildRawTx(t){return await this._buildRawTx(await this.signer.getAddress(),t)}getOutputScript(){return oe.address.toOutputScript(this.address(),this.network)}async init(t){return t??(t=await(await this.signer.getProvider()).suggestFee(await this.signer.getAddress(),this.initiateAmount,kn.Urgency.MEDIUM)),await this.signer.send(this.address(),this.initiateAmount,t)}async generateInstantRefundSACP(t,r){const{tx:n,usedUtxos:i}=await this._buildRawTx(t,r),a=this.getOutputScript(),f=oe.Transaction.SIGHASH_SINGLE|oe.Transaction.SIGHASH_ANYONECANPAY,u=this.leafHash(2),l=i.map(g=>g.value),b=or(a,i.length);for(let g=0;g<n.ins.length;g++){const m=n.hashForWitnessV1(g,b,l,f,u),v=await this.signer.signSchnorr(m);n.setWitness(g,[v,v,this.instantRefundLeaf(),this.generateControlBlockFor(2)])}return n.toHex()}async instantRefund(t,r){_t(t.length>0,_e.noCounterpartySigs);const{tx:n,usedUtxos:i}=await this.buildRawTx(r);for(const m of i)if(!t.find(v=>v.utxo===m.txid))throw new Error(_e.counterPartySigNotFound(m.txid));const a=this.getOutputScript(),f=oe.Transaction.SIGHASH_DEFAULT,u=this.leafHash(2),l=i.map(m=>m.value),b=or(a,i.length);for(let m=0;m<n.ins.length;m++){const v=n.hashForWitnessV1(m,b,l,f,u);if(!at.verifySchnorr(v,Buffer.from(this.redeemerPubkey,"hex"),Buffer.from(t[m].sig,"hex")))throw new Error(_e.invalidCounterpartySigForUTXO(t[m].utxo));const A=await this.signer.signSchnorr(v),B=Buffer.from(n.ins[m].hash).reverse().toString("hex"),P=t.find(T=>T.utxo===B);if(!P)throw new Error(_e.counterPartySigNotFound(B));n.setWitness(m,[Buffer.from(P.sig,"hex"),A,this.instantRefundLeaf(),this.generateControlBlockFor(2)])}return await(await this.signer.getProvider()).broadcast(n.toHex())}async redeem(t,r,n){_t(oe.crypto.sha256(Buffer.from(t,"hex")).toString("hex")===this.secretHash,_e.secretMismatch);const{tx:i,usedUtxos:a}=await this._buildRawTx(r??await this.signer.getAddress(),n),f=this.leafHash(1),u=a.map(m=>m.value),l=or(this.getOutputScript(),a.length),b=oe.Transaction.SIGHASH_DEFAULT;for(let m=0;m<i.ins.length;m++){const v=i.hashForWitnessV1(m,l,u,b,f),A=await this.signer.signSchnorr(v);i.setWitness(m,[A,Buffer.from(t,"hex"),this.redeemLeaf(),this.generateControlBlockFor(1)])}return await(await this.signer.getProvider()).broadcast(i.toHex())}async refund(t,r){const{tx:n,usedUtxos:i}=await this._buildRawTx(t??await this.signer.getAddress(),r),[a,f]=await this.canRefund(i);if(!a)throw new Error(_e.htlcNotExpired(f));const u=this.leafHash(0),l=i.map(v=>v.value),b=or(this.getOutputScript(),i.length),g=oe.Transaction.SIGHASH_DEFAULT;for(let v=0;v<n.ins.length;v++){n.ins[v].sequence=this.expiry;const A=n.hashForWitnessV1(v,b,l,g,u),B=await this.signer.signSchnorr(A);n.setWitness(v,[B,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 i of t){let a=0;if(i.status.confirmed&&i.status.block_height+this.expiry>n?a=i.status.block_height+this.expiry-n+1:i.status.confirmed||(a=this.expiry+1),a>0)return[!1,a]}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(_e.invalidLeaf)}const n=oe.payments.p2tr({internalPubkey:this.internalPubkey,network:this.network,scriptTree:this.leaves(),redeem:{output:r,redeemVersion:sr}});if(!n.witness)throw new Error(_e.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()),oe.crypto.taggedHash("TapLeaf",Fa(r))}refundLeaf(){return oe.script.fromASM(`
1
+ "use strict";var Gs=Object.defineProperty;var js=(e,t,r)=>t in e?Gs(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var mt=(e,t,r)=>js(e,typeof t!="symbol"?t+"":t,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("@catalogfi/utils"),X=require("@gardenfi/orderbook"),ae=require("@gardenfi/utils"),Bt=require("@catalogfi/wallets"),Ne=require("viem"),Ws=require("varuint-bitcoin"),qs=require("tiny-secp256k1"),wi=require("bitcoinjs-lib"),Vs=require("bignumber.js");function hn(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 Cn=hn(Ws),at=hn(qs),oe=hn(wi);var le=(e=>(e.Idle="Idle",e.Initiate="Initiate",e.Redeem="Redeem",e.Refund="Refund",e))(le||{});function en(e){return typeof e=="string"&&(e=Buffer.from(e,"hex")),e.length===32?e:e.subarray(1,33)}function _t(e,t){if(!e)throw new Error(t)}function Ks(e){return Buffer.concat([Uint8Array.from([192]),Ys(e)])}function Ys(e){const t=Cn.encodingLength(e.length),r=Buffer.allocUnsafe(t);return Cn.encode(e.length,r),Buffer.concat([r,e])}function Js(e,t){if(e.compare(t)>0){const r=e;e=t,t=r}return[e,t]}const st=e=>e.length===64?e:e.slice(2),Xs=e=>{if(!e)return!1;try{const t=Buffer.from(e,"hex");return at.isPoint(t)}catch{return!1}},xi=(e,t,r,n)=>e+":"+t.toLowerCase()+"::"+r+":"+n.toLowerCase();function Qs(e,t){if(!e)return!1;const r=t==="mainnet"?oe.networks.bitcoin:oe.networks.testnet;oe.initEccLib(at);try{return oe.address.toOutputScript(e,r),!0}catch{return!1}}const Zs=e=>{switch(e){case ae.Environment.MAINNET:return Bt.BitcoinNetwork.Mainnet;case ae.Environment.TESTNET:return Bt.BitcoinNetwork.Testnet;default:throw new Error(`Invalid bitcoin network ${e}`)}};var Q=(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.DeadLineExceeded="DeadLineExceeded",e))(Q||{}),ne=(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))(ne||{});const dn=(e,t,r)=>{const n=tn(e.source_swap,t),i=tn(e.destination_swap,r);if(i===ne.RedeemDetected)return Q.RedeemDetected;if(i===ne.Redeemed)return Q.Redeemed;if(n===ne.Refunded)return Q.Refunded;if(n===ne.RefundDetected)return Q.RefundDetected;if(i===ne.Expired)return Q.CounterPartySwapExpired;if(n===ne.Expired)return Q.Expired;if(i===ne.Refunded)return Q.CounterPartyRefunded;if(i===ne.RefundDetected)return Q.CounterPartyRefundDetected;const o=Number(e.create_order.additional_data.deadline);return i===ne.Initiated?Q.CounterPartyInitiated:i===ne.InitiateDetected?Q.CounterPartyInitiateDetected:Vt(o,12)?Q.DeadLineExceeded:n===ne.Initiated?Q.Initiated:Vt(o,1)?Q.DeadLineExceeded:n===ne.InitiateDetected?Q.InitiateDetected:n===ne.Redeemed?Q.CounterPartyRedeemed:n===ne.RedeemDetected?Q.CounterPartyRedeemDetected:Q.Matched},tn=(e,t)=>{if(e.redeem_tx_hash)return Number(e.redeem_block_number)?ne.Redeemed:ne.RedeemDetected;if(e.refund_tx_hash)return Number(e.refund_block_number)?ne.Refunded:ne.RefundDetected;if(Number(e.initiate_block_number)){const r=Number(e.initiate_block_number)+e.timelock;if(t>r)return ne.Expired}return e.initiate_tx_hash?Number(e.initiate_block_number)?ne.Initiated:ne.InitiateDetected:ne.Idle},eo=(e,t,r)=>{const n=dn(e,t,r);return pn(n)},pn=e=>{switch(e){case Q.Matched:return le.Initiate;case Q.CounterPartyInitiated:case Q.CounterPartyInitiateDetected:case Q.RedeemDetected:return le.Redeem;case Q.Expired:return le.Refund;default:return le.Idle}},Vt=(e,t=0)=>{const r=Date.now(),n=e*1e3+t*36e5;return r>=n},to=e=>e.filter(t=>!vi(t)),vi=e=>{const{source_swap:t,create_order:r}=e,{initiate_tx_hash:n,initiate_block_number:i}=t,{deadline:o}=r.additional_data;return n&&Number(i)?!1:n&&!Number(i)?Vt(Number(o),12):n?!1:Vt(Number(o),1)},ro=[{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 Ei{constructor(t,r){this.url=new ae.Url("/relayer",t),this.auth=r}async init(t,r){if(!t.account)return S.Err("No account found");if(t.account.address.toLowerCase()!==r.source_swap.initiator.toLowerCase())return S.Err("Account address and order initiator mismatch");const{create_order:n,source_swap:i}=r;if(!i.amount||!i.redeemer||!n.timelock||!n.secret_hash)return S.Err("Invalid order");const o=ae.with0x(n.secret_hash),u=BigInt(n.timelock),f=ae.with0x(i.redeemer),l=BigInt(i.amount);try{const b=await this.auth.getToken();if(b.error)return S.Err(b.error);const g=Ne.getContract({address:ae.with0x(r.source_swap.asset),abi:ro,client:t}),m=await g.read.token(),v=await ae.checkAllowanceAndApprove(Number(l),m,r.source_swap.asset,t);if(v.error)return S.Err(v.error);const A=await g.read.eip712Domain(),I=await t.signTypedData({account:t.account,domain:{name:A[1],version:A[2],chainId:Number(A[3]),verifyingContract:A[4]},types:{Initiate:[{name:"redeemer",type:"address"},{name:"timelock",type:"uint256"},{name:"amount",type:"uint256"},{name:"secretHash",type:"bytes32"}]},primaryType:"Initiate",message:{redeemer:f,timelock:u,amount:l,secretHash:o}}),k=await S.Fetcher.post(this.url.endpoint("initiate"),{body:JSON.stringify({order_id:n.create_id,signature:I,perform_on:"Source"}),headers:{Authorization:ae.Authorization(b.val),"Content-Type":"application/json"}});return k.error?S.Err(k.error):k.result?S.Ok(k.result):S.Err("Init: No result found")}catch(b){return console.log("init error :",b),S.Err(String(b))}}async redeem(t,r){try{const n=await this.auth.getToken();if(n.error)return S.Err(n.error);const i=await S.Fetcher.post(this.url.endpoint("redeem"),{body:JSON.stringify({order_id:t,secret:S.trim0x(r),perform_on:"Destination"}),headers:{Authorization:ae.Authorization(n.val),"Content-Type":"application/json"}});return i.error?S.Err(i.error):i.result?S.Ok(i.result):S.Err("Redeem: No result found")}catch(n){return S.Err(String(n))}}}const no=Buffer.from("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","hex"),io=Buffer.from("483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8","hex"),so=Buffer.concat([no,io]),oo=Buffer.from("0250929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0","hex"),Pn={failedToCreateInternalPubkey:"failed to create internal pubkey",failedToTweakPubkey:"failed to tweak pubkey"};function ao(){const e=wi.crypto.sha256(Buffer.from("GardenHTLC","utf-8")),t=at.pointMultiply(Buffer.concat([Buffer.from("04","hex"),so]),e);if(!t)throw new Error(Pn.failedToCreateInternalPubkey);const r=at.pointAdd(oo,t);if(!r)throw new Error(Pn.failedToCreateInternalPubkey);return en(Buffer.from(r))}const _e={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"},or=192;oe.initEccLib(at);class qt{constructor(t,r,n,i,o,u,f,l){this.secretHash=n,this.redeemerPubkey=i,this.initiatorPubkey=o,this.expiry=u,this.signer=t,this.network=f,this.internalPubkey=ao(),this.initiateAmount=r,this.utxoHashes=l}static async from(t,r,n,i,o,u,f){n=n.startsWith("0x")?n.slice(2):n,_t(n.length===64,_e.secretHashLenMismatch),_t(i.length===64||i.length===66,`initiator ${_e.pubkeyLenMismatch}`),_t(o.length===64||o.length===66,`redeemer ${_e.pubkeyLenMismatch}`),_t(u>0,_e.zeroOrNegativeExpiry);const l=await t.getNetwork();return new qt(t,r,n,en(o).toString("hex"),en(i).toString("hex"),u,l,f)}address(){const{address:t}=oe.payments.p2tr({internalPubkey:this.internalPubkey,network:this.network,scriptTree:this.leaves()});if(!t)throw new Error(_e.htlcAddressGenerationFailed);return t}id(){return this.address()}async _buildRawTx(t,r){const n=new oe.Transaction;n.version=2;const i=this.address(),o=await this.signer.getProvider();let u=[];if(this.utxoHashes&&this.utxoHashes.length>0)for(const l of this.utxoHashes){const b=await o.getTransaction(l);for(let g=0;g<b.vout.length;g++){const m=b.vout[g];m.scriptpubkey_address===i&&u.push({txid:b.txid,vout:g,value:m.value,status:{confirmed:!1}})}}else u=await o.getUTXOs(i);const f=u.reduce((l,b)=>l+b.value,0);if(f===0)throw new Error(`${i} ${_e.notFunded}`);for(let l=0;l<u.length;l++)n.addInput(Buffer.from(u[l].txid,"hex").reverse(),u[l].vout);return r??(r=await o.suggestFee(i,f,Bt.Urgency.MEDIUM)),n.addOutput(oe.address.toOutputScript(t,this.network),f-r),{tx:n,usedUtxos:u}}async buildRawTx(t){return await this._buildRawTx(await this.signer.getAddress(),t)}getOutputScript(){return oe.address.toOutputScript(this.address(),this.network)}async init(t){return t??(t=await(await this.signer.getProvider()).suggestFee(await this.signer.getAddress(),this.initiateAmount,Bt.Urgency.MEDIUM)),await this.signer.send(this.address(),this.initiateAmount,t)}async generateInstantRefundSACP(t,r){const{tx:n,usedUtxos:i}=await this._buildRawTx(t,r),o=this.getOutputScript(),u=oe.Transaction.SIGHASH_SINGLE|oe.Transaction.SIGHASH_ANYONECANPAY,f=this.leafHash(2),l=i.map(g=>g.value),b=ar(o,i.length);for(let g=0;g<n.ins.length;g++){const m=n.hashForWitnessV1(g,b,l,u,f),v=await this.signer.signSchnorr(m);n.setWitness(g,[v,v,this.instantRefundLeaf(),this.generateControlBlockFor(2)])}return n.toHex()}async instantRefund(t,r){_t(t.length>0,_e.noCounterpartySigs);const{tx:n,usedUtxos:i}=await this.buildRawTx(r);for(const m of i)if(!t.find(v=>v.utxo===m.txid))throw new Error(_e.counterPartySigNotFound(m.txid));const o=this.getOutputScript(),u=oe.Transaction.SIGHASH_DEFAULT,f=this.leafHash(2),l=i.map(m=>m.value),b=ar(o,i.length);for(let m=0;m<n.ins.length;m++){const v=n.hashForWitnessV1(m,b,l,u,f);if(!at.verifySchnorr(v,Buffer.from(this.redeemerPubkey,"hex"),Buffer.from(t[m].sig,"hex")))throw new Error(_e.invalidCounterpartySigForUTXO(t[m].utxo));const A=await this.signer.signSchnorr(v),I=Buffer.from(n.ins[m].hash).reverse().toString("hex"),k=t.find(C=>C.utxo===I);if(!k)throw new Error(_e.counterPartySigNotFound(I));n.setWitness(m,[Buffer.from(k.sig,"hex"),A,this.instantRefundLeaf(),this.generateControlBlockFor(2)])}return await(await this.signer.getProvider()).broadcast(n.toHex())}async redeem(t,r,n){_t(oe.crypto.sha256(Buffer.from(t,"hex")).toString("hex")===this.secretHash,_e.secretMismatch);const{tx:i,usedUtxos:o}=await this._buildRawTx(r??await this.signer.getAddress(),n),u=this.leafHash(1),f=o.map(m=>m.value),l=ar(this.getOutputScript(),o.length),b=oe.Transaction.SIGHASH_DEFAULT;for(let m=0;m<i.ins.length;m++){const v=i.hashForWitnessV1(m,l,f,b,u),A=await this.signer.signSchnorr(v);i.setWitness(m,[A,Buffer.from(t,"hex"),this.redeemLeaf(),this.generateControlBlockFor(1)])}return await(await this.signer.getProvider()).broadcast(i.toHex())}async refund(t,r){const{tx:n,usedUtxos:i}=await this._buildRawTx(t??await this.signer.getAddress(),r),[o,u]=await this.canRefund(i);if(!o)throw new Error(_e.htlcNotExpired(u));const f=this.leafHash(0),l=i.map(v=>v.value),b=ar(this.getOutputScript(),i.length),g=oe.Transaction.SIGHASH_DEFAULT;for(let v=0;v<n.ins.length;v++){n.ins[v].sequence=this.expiry;const A=n.hashForWitnessV1(v,b,l,g,f),I=await this.signer.signSchnorr(A);n.setWitness(v,[I,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 i of t){let o=0;if(i.status.confirmed&&i.status.block_height+this.expiry>n?o=i.status.block_height+this.expiry-n+1:i.status.confirmed||(o=this.expiry+1),o>0)return[!1,o]}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(_e.invalidLeaf)}const n=oe.payments.p2tr({internalPubkey:this.internalPubkey,network:this.network,scriptTree:this.leaves(),redeem:{output:r,redeemVersion:or}});if(!n.witness)throw new Error(_e.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()),oe.crypto.taggedHash("TapLeaf",Ks(r))}refundLeaf(){return oe.script.fromASM(`
5
2
  ${oe.script.number.encode(this.expiry).toString("hex")}
6
3
  OP_CHECKSEQUENCEVERIFY
7
4
  OP_DROP
@@ -20,12 +17,15 @@
20
17
  OP_CHECKSIGADD
21
18
  OP_2
22
19
  OP_NUMEQUAL
23
- `.trim().replace(/\s+/g," "))}leaves(){return[{version:sr,output:this.redeemLeaf()},[{version:sr,output:this.refundLeaf()},{version:sr,output:this.instantRefundLeaf()}]]}generateMerkleProofFor(t){const r=this.leafHash(1),n=this.leafHash(2),i=this.leafHash(0);switch(t){case 1:{const a=Na(i,n);return[oe.crypto.taggedHash("TapBranch",Buffer.concat(a))]}case 0:return[n,r];case 2:return[i,r];default:throw new Error(_e.invalidLeaf)}}}function or(e,t){const r=[];for(let n=0;n<t;n++)r.push(e);return r}class Ja{constructor(){this.cache={}}set(t,r,n,i){const a={txHash:n,timeStamp:Date.now(),btcRedeemUTXO:i};this.cache[`${r}_${t.create_order.create_id}`]=a}get(t,r){return this.cache[`${r}_${t.create_order.create_id}`]||null}remove(t,r){delete this.cache[`${r}_${t.create_order.create_id}`]}}class Xa{constructor(t){if(this.eventListeners=new Map,this.getOrderThreshold=20,this.useRelay=!0,this.refundSacpCache=new Map,this.orderBook=new X.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=new me.Url(t.orderbookURl),this.auth=t.auth,this.orderExecutorCache=new Ja,!t.wallets.evmWallet.account)throw new Error("Account not found in evmWallet");this.evmAddress=t.wallets.evmWallet.account.address,this.blockNumberFetcher=t.blockNumberFetcher}setUseRelay(t){this.useRelay=t}async swap(t){const r=await this.validateAndFillParams(t);if(r.error)return k.Err(r.error);const{sendAddress:n,receiveAddress:i,timelock:a}=r.val;let f=t.nonce;if(!f){const P=await this.orderBook.getOrdersCount(this.evmAddress);if(P.error)return k.Err(P.error);f=P.val+1}const u=this.secretManager.generateSecret(f);if(u.error)return k.Err(u.error);const{strategyId:l,btcAddress:b}=t.additionalData,g={strategy_id:l,...b&&{bitcoin_optional_recipient:b}},m={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:i,source_amount:t.sendAmount,destination_amount:t.receiveAmount,fee:"1",nonce:f.toString(),timelock:a,secret_hash:k.trim0x(u.val.secretHash),min_destination_confirmations:t.minDestinationConfirmations??0,additional_data:g},v=await this.quote.getAttestedQuote(m);if(v.error)return k.Err(v.error);const A=await this.orderBook.createOrder(v.val);if(A.error)return k.Err(A.error);const B=await this.pollOrder(A.val);return B.error?k.Err(B.error):k.Ok(B.val)}async validateAndFillParams(t){if(t.fromAsset.chain===t.toAsset.chain&&t.fromAsset.atomicSwapAddress===t.toAsset.atomicSwapAddress)return k.Err("Source and destination assets cannot be the same");if(X.isMainnet(t.fromAsset.chain)&&!X.isMainnet(t.toAsset.chain)||!X.isMainnet(t.fromAsset.chain)&&X.isMainnet(t.toAsset.chain))return k.Err("Both assets should be on the same network (either mainnet or testnet)");if(X.isBitcoin(t.fromAsset.chain)||X.isBitcoin(t.toAsset.chain)){if(!this.wallets.btcWallet)return k.Err("btcWallet is required for bitcoin chain. Please provide btcWallet in the constructor");if(!t.additionalData.btcAddress)return k.Err("btcAddress in additionalData is required for bitcoin chain")}const r=await this.getAddresses(t.fromAsset.chain);if(r.error)return k.Err(r.error);const n=await this.getAddresses(t.toAsset.chain);if(n.error)return k.Err(n.error);const i=this.validateAmount(t.sendAmount);if(i.error)return k.Err(i.error);const a=this.validateAmount(t.receiveAmount);if(a.error)return k.Err(a.error);if(i<a)return k.Err("Send amount should be greater than receive amount");const f=X.getTimeLock(t.fromAsset.chain);return f?k.Ok({sendAddress:r.val,receiveAddress:n.val,timelock:t.timelock??f}):k.Err("Unsupported chain for timelock")}async getAddresses(t){var n;switch(X.getBlockchainType(t)){case X.BlockchainType.EVM:return this.wallets.evmWallet.account?k.Ok(this.wallets.evmWallet.account.address):k.Err("EVM Wallet not found");case X.BlockchainType.Bitcoin:{const i=await((n=this.wallets.btcWallet)==null?void 0:n.getPublicKey());return!i||!Ma(i)?k.Err("Invalid btc public key"):k.Ok(st(i))}default:return k.Err("Unsupported chain")}}validateAmount(t){if(t==null||t.includes("."))return k.Err("Invalid amount ",t);const r=new Gs(t);return!r.isInteger()||r.isNaN()||r.lt(0)||r.isLessThanOrEqualTo(0)?k.Err("Invalid amount ",t):k.Ok(r)}async pollOrder(t){let r=await this.orderBook.getOrder(t,!0),n=0;for(;n<this.getOrderThreshold;){if(await me.sleep(1e3),n++,r.error){if(!r.error.includes("result is undefined"))return k.Err(r.error)}else if(r.val&&r.val.create_order.create_id.toLowerCase()===t.toLowerCase())return k.Ok(r.val);r=await this.orderBook.getOrder(t,!0)}return k.Err(`Order not found, createOrder id: ${t}`)}async execute(t=5e3){return await this.orderBook.subscribeToOrders(!0,t,async r=>{const n=Vi(r.data),i=await this.assignOrderStatus(n);this.emit("onPendingOrdersChanged",i);for(let a=0;a<i.length;a++){const f=i[a],u=xn(f.status);if(X.isBitcoin(f.source_swap.chain)&&f.status===Q.InitiateDetected){const l=this.getWallet(f.source_swap.chain);if(l.error){this.emit("error",f,l.error);continue}await this.postRefundSACP(f,l.val)}switch(u){case ce.Redeem:{const l=this.secretManager.generateSecret(Number(f.create_order.nonce));if(l.error){this.emit("error",f,l.error);return}switch(X.getBlockchainType(f.destination_swap.chain)){case X.BlockchainType.EVM:{await this.evmRedeem(f,l.val.secret);break}case X.BlockchainType.Bitcoin:{const b=this.getWallet(f.destination_swap.chain);if(b.error){this.emit("error",f,b.error);return}await this.btcRedeem(b.val,f,l.val.secret);break}default:this.emit("error",f,"Unsupported chain: "+f.destination_swap.chain)}break}case ce.Refund:{switch(X.getBlockchainType(f.source_swap.chain)){case X.BlockchainType.EVM:{this.emit("error",f,"EVM refund is automatically done by relay service");break}case X.BlockchainType.Bitcoin:{const l=this.getWallet(f.source_swap.chain);if(l.error){this.emit("error",f,l.error);return}await this.btcRefund(l.val,f);break}default:this.emit("error",f,"Unsupported chain: "+f.source_swap.chain)}break}}}},{per_page:500},!0)}async evmRedeem(t,r){if(this.emit("log",t.create_order.create_id,"executing evm redeem"),this.orderExecutorCache.get(t,ce.Redeem)){this.emit("log",t.create_order.create_id,"already redeemed");return}const a=await new Ki(t,this.orderbookUrl.toString(),this.auth).redeem(t.create_order.create_id,r);if(a.error){this.emit("error",t,a.error),a.error.includes("Order already redeemed")&&this.orderExecutorCache.set(t,ce.Redeem,t.destination_swap.redeem_tx_hash);return}this.orderExecutorCache.set(t,ce.Redeem,a.val),this.emit("success",t,ce.Redeem,a.val)}async btcRedeem(t,r,n){var u,l;const i=this.orderExecutorCache.get(r,ce.Redeem),a=(u=r.destination_swap.initiate_tx_hash.split(",").at(-1))==null?void 0:u.split(":").at(0);if(!a){this.emit("error",r,"Failed to get initiate_tx_hash");return}let f=!1;if(i)if(i.btcRedeemUTXO&&i.btcRedeemUTXO!==a)f=!0,this.emit("log",r.create_order.create_id,"rbf btc redeem");else{this.emit("log",r.create_order.create_id,"btcRedeem: already redeemed");return}else if(r.destination_swap.redeem_tx_hash&&!Number(r.destination_swap.redeem_block_number))try{const b=await(await t.getProvider()).getTransaction(r.destination_swap.redeem_tx_hash);let g=!1;for(const m of b.vin)if(m.txid===a){g=!0;break}if(g){this.orderExecutorCache.set(r,ce.Redeem,r.destination_swap.redeem_tx_hash,a),this.emit("log",r.create_order.create_id,"already a valid redeem");return}f=!0}catch(b){if(b.message.includes("Transaction not found"))f=!0;else{this.emit("error",r,"Failed to get redeem tx: "+b);return}}this.emit("log",r.create_order.create_id,"executing btc redeem");try{const g=await(await Wt.from(t,Number(r.destination_swap.amount),r.create_order.secret_hash,st(r.destination_swap.initiator),st(r.destination_swap.redeemer),r.destination_swap.timelock,f?[a]:[])).redeem(k.trim0x(n),(l=r.create_order.additional_data)==null?void 0:l.bitcoin_optional_recipient);f?this.emit("log",r.create_order.create_id,"rbf: btc redeem success"):this.emit("success",r,ce.Redeem,g),this.orderExecutorCache.set(r,ce.Redeem,g,a)}catch(b){this.emit("error",r,"Failed btc redeem: "+b)}}async btcRefund(t,r){var n;if(!this.orderExecutorCache.get(r,ce.Refund)){this.emit("log",r.create_order.create_id,"executing btc refund");try{const a=await(await Wt.from(t,Number(r.source_swap.amount),r.create_order.secret_hash,st(r.source_swap.initiator),st(r.source_swap.redeemer),r.source_swap.timelock)).refund((n=r.create_order.additional_data)==null?void 0:n.bitcoin_optional_recipient);this.orderExecutorCache.set(r,ce.Refund,a),this.emit("success",r,ce.Refund,a)}catch(i){this.emit("error",r,"Failed btc refund: "+i)}}}getWallet(t){switch(X.getBlockchainType(t)){case X.BlockchainType.EVM:return k.Ok(this.wallets.evmWallet);case X.BlockchainType.Bitcoin:return k.Ok(this.wallets.btcWallet);default:return k.Err("Unsupported chain for wallet")}}async postRefundSACP(t,r){const n=this.refundSacpCache.get(t.create_order.create_id);if((n==null?void 0:n.initTxHash)===t.source_swap.initiate_tx_hash)return;const i=await Wt.from(r,Number(t.source_swap.amount),t.create_order.secret_hash,st(t.source_swap.initiator),st(t.source_swap.redeemer),t.source_swap.timelock),a=t.create_order.additional_data.bitcoin_optional_recipient;if(a)try{const f=await i.generateInstantRefundSACP(a),u=this.orderbookUrl.endpoint("orders/add-instant-refund-sacp");(await k.Fetcher.post(u,{headers:{"Content-Type":"application/json"},body:JSON.stringify({order_id:t.create_order.create_id,instant_refund_tx_bytes:f})})).status==="Ok"&&this.refundSacpCache.set(t.create_order.create_id,{initTxHash:t.source_swap.initiate_tx_hash})}catch(f){this.emit("error",t,"Failed to generate and post SACP: "+f);return}}emit(t,...r){(this.eventListeners.get(t)??[]).forEach(i=>{i(...r)})}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)??[],i=n.indexOf(r);i!==-1&&n.splice(i,1)}async fetchCurrentBlockNumbers(t,r){if(!r||!r.source||!r.destination)return k.Err("Provide wallets to fetch the current block number");const n=X.isBitcoin(t.source_swap.chain)?await me.fetchBitcoinBlockNumber(await r.source.getProvider()):await me.fetchEVMBlockNumber(r.source);if(n.error)return k.Err(n.error);const i=X.isBitcoin(t.destination_swap.chain)?await me.fetchBitcoinBlockNumber(await r.destination.getProvider()):await me.fetchEVMBlockNumber(r.destination);return i.error?k.Err(i.error):k.Ok({source:n.val,destination:i.val})}async assignOrderStatus(t){var i;const r=await((i=this.blockNumberFetcher)==null?void 0:i.fetchBlockNumbers()),n=[];for(let a=0;a<t.length;a++){const f=t[a],u=f.source_swap.chain,l=f.destination_swap.chain,b=this.getWallet(u),g=this.getWallet(l);if(b.error||g.error||!b.val||!g.val){this.emit("error",f,"Source or Destination Wallet not found while executing order");continue}let m=r==null?void 0:r.val[u],v=r==null?void 0:r.val[l];if(!m||!v){const B=await this.fetchCurrentBlockNumbers(f,{source:b.val,destination:g.val});if(B.error){this.emit("error",f,"Error while fetching CurrentBlockNumbers: "+B.error);continue}m=B.val.source,v=B.val.destination}const A=wn(f,m,v);n.push({...f,status:A})}return n}}class Qa{constructor(t,r){this.url=new me.Url("/blocknumber/"+r,t)}async fetchBlockNumbers(){try{const t=await k.Fetcher.get(this.url);return k.Ok(t)}catch(t){return k.Err("Failed to fetch block numbers",t)}}}var Qe=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Za(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function ef(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 i=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,i.get?i:{enumerable:!0,get:function(){return e[n]}})}),r}var Yi={},St={},At={};Object.defineProperty(At,"__esModule",{value:!0});At.testnet=At.bitcoin=void 0;At.bitcoin={messagePrefix:`Bitcoin Signed Message:
20
+ `.trim().replace(/\s+/g," "))}leaves(){return[{version:or,output:this.redeemLeaf()},[{version:or,output:this.refundLeaf()},{version:or,output:this.instantRefundLeaf()}]]}generateMerkleProofFor(t){const r=this.leafHash(1),n=this.leafHash(2),i=this.leafHash(0);switch(t){case 1:{const o=Js(i,n);return[oe.crypto.taggedHash("TapBranch",Buffer.concat(o))]}case 0:return[n,r];case 2:return[i,r];default:throw new Error(_e.invalidLeaf)}}}function ar(e,t){const r=[];for(let n=0;n<t;n++)r.push(e);return r}class fo{constructor(){this.cache={}}set(t,r,n,i){const o={txHash:n,timeStamp:Date.now(),btcRedeemUTXO:i};this.cache[`${r}_${t.create_order.create_id}`]=o}get(t,r){return this.cache[`${r}_${t.create_order.create_id}`]||null}remove(t,r){delete this.cache[`${r}_${t.create_order.create_id}`]}}class Bi{constructor(t,r){this.url=new ae.Url("/blocknumber/"+r,t)}async fetchBlockNumbers(){try{const t=await S.Fetcher.get(this.url);return S.Ok(t)}catch(t){return S.Err("Failed to fetch block numbers",t)}}}const Ln={mainnet:{orderbook:"https://orderbookv2.garden.finance",quote:"https://pricev2.garden.finance",info:"https://infov2.garden.finance"},testnet:{orderbook:"https://orderbook.garden.finance",quote:"https://price.garden.finance",info:"https://info.garden.finance"},localnet:{}};class Si{constructor(t){this.quoteUrl=new ae.Url("/quote",t)}async getQuote(t,r,n=!1){try{const i=this.quoteUrl.addSearchParams({order_pair:t,amount:r.toString(),exact_out:n.toString()}),o=await S.Fetcher.get(i);return o.error?S.Err(o.error):o.result?S.Ok(o.result):S.Err("GetQuote: Unexpected error, result is undefined")}catch(i){return S.Err("GetQuote:",String(i))}}async getAttestedQuote(t){try{const r=await S.Fetcher.post(this.quoteUrl.endpoint("/attested").toString(),{body:JSON.stringify(t),headers:{"Content-Type":"application/json"}});return r.error?S.Err(r.error):r.result?S.Ok(r.result):S.Err("GetAttestedQuote: Unexpected error, result is undefined")}catch(r){return console.log("error :",r),S.Err("GetAttestedQuote:",String(r))}}async getStrategies(){try{const t=await S.Fetcher.get(this.quoteUrl.endpoint("/strategies"));if(t.error)return S.Err(t.error);if(!t.result)return S.Err("GetStrategies: Unexpected error, result is undefined");const r={};for(const n of Object.values(t.result)){const i=xi(n.source_chain,n.source_asset.asset,n.dest_chain,n.dest_asset.asset);r[i]={id:n.id,minAmount:n.min_amount,maxAmount:n.max_amount,fee:n.fee}}return S.Ok(r)}catch(t){return S.Err("GetStrategies:",String(t))}}}var Qe=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function uo(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function co(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 i=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,i.get?i:{enumerable:!0,get:function(){return e[n]}})}),r}var Ai={},St={},At={};Object.defineProperty(At,"__esModule",{value:!0});At.testnet=At.bitcoin=void 0;At.bitcoin={messagePrefix:`Bitcoin Signed Message:
24
21
  `,bech32:"bc",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128};At.testnet={messagePrefix:`Bitcoin Signed Message:
25
- `,bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};var Ji={},Vt={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}};Vt.Null=Vt.Nil;for(var Gn in Vt)Vt[Gn].toJSON=(function(e){return e}).bind(null,Gn);var vn=Vt,ot=vn;function Xi(e){return e.name||e.toString().match(/function (.*?)\s*\(/)[1]}function En(e){return ot.Nil(e)?"":Xi(e.constructor)}function tf(e){return ot.Function(e)?"":ot.String(e)?JSON.stringify(e):e&&ot.Object(e)?"":e}function Bn(e,t){Error.captureStackTrace&&Error.captureStackTrace(e,t)}function pr(e){return ot.Function(e)?e.toJSON?e.toJSON():Xi(e):ot.Array(e)?"Array":e&&ot.Object(e)?"Object":e!==void 0?e:""}function Qi(e,t,r){var n=tf(t);return"Expected "+pr(e)+", got"+(r!==""?" "+r:"")+(n!==""?" "+n:"")}function ze(e,t,r){r=r||En(t),this.message=Qi(e,t,r),Bn(this,ze),this.__type=e,this.__value=t,this.__valueTypeName=r}ze.prototype=Object.create(Error.prototype);ze.prototype.constructor=ze;function rf(e,t,r,n,i){var a='" of type ';return t==="key"&&(a='" with key type '),Qi('property "'+pr(r)+a+pr(e),n,i)}function vt(e,t,r,n,i){e?(i=i||En(n),this.message=rf(e,r,t,n,i)):this.message='Unexpected property "'+t+'"',Bn(this,ze),this.__label=r,this.__property=t,this.__type=e,this.__value=n,this.__valueTypeName=i}vt.prototype=Object.create(Error.prototype);vt.prototype.constructor=ze;function nf(e,t){return new ze(e,{},t)}function sf(e,t,r){return e instanceof vt?(t=t+"."+e.__property,e=new vt(e.__type,t,e.__label,e.__value,e.__valueTypeName)):e instanceof ze&&(e=new vt(e.__type,t,r,e.__value,e.__valueTypeName)),Bn(e),e}var Zi={TfTypeError:ze,TfPropertyTypeError:vt,tfCustomError:nf,tfSubError:sf,tfJSON:pr,getValueTypeName:En},Mr,jn;function of(){if(jn)return Mr;jn=1;var e=vn,t=Zi;function r(S){return Buffer.isBuffer(S)}function n(S){return typeof S=="string"&&/^([0-9a-f]{2})+$/i.test(S)}function i(S,z){var M=S.toJSON();function $(ae){if(!S(ae))return!1;if(ae.length===z)return!0;throw t.tfCustomError(M+"(Length: "+z+")",M+"(Length: "+ae.length+")")}return $.toJSON=function(){return M},$}var a=i.bind(null,e.Array),f=i.bind(null,r),u=i.bind(null,n),l=i.bind(null,e.String);function b(S,z,M){M=M||e.Number;function $(ae,ke){return M(ae,ke)&&ae>S&&ae<z}return $.toJSON=function(){return`${M.toJSON()} between [${S}, ${z}]`},$}var g=Math.pow(2,53)-1;function m(S){return typeof S=="number"&&isFinite(S)}function v(S){return S<<24>>24===S}function A(S){return S<<16>>16===S}function B(S){return(S|0)===S}function P(S){return typeof S=="number"&&S>=-g&&S<=g&&Math.floor(S)===S}function T(S){return(S&255)===S}function C(S){return(S&65535)===S}function F(S){return S>>>0===S}function O(S){return typeof S=="number"&&S>=0&&S<=g&&Math.floor(S)===S}var L={ArrayN:a,Buffer:r,BufferN:f,Finite:m,Hex:n,HexN:u,Int8:v,Int16:A,Int32:B,Int53:P,Range:b,StringN:l,UInt8:T,UInt16:C,UInt32:F,UInt53:O};for(var U in L)L[U].toJSON=(function(S){return S}).bind(null,U);return Mr=L,Mr}var Qt=Zi,he=vn,De=Qt.tfJSON,es=Qt.TfTypeError,ts=Qt.TfPropertyTypeError,Mt=Qt.tfSubError,af=Qt.getValueTypeName,$e={arrayOf:function(t,r){t=Fe(t),r=r||{};function n(i,a){return!he.Array(i)||he.Nil(i)||r.minLength!==void 0&&i.length<r.minLength||r.maxLength!==void 0&&i.length>r.maxLength||r.length!==void 0&&i.length!==r.length?!1:i.every(function(f,u){try{return xe(t,f,a)}catch(l){throw Mt(l,u)}})}return n.toJSON=function(){var i="["+De(t)+"]";return r.length!==void 0?i+="{"+r.length+"}":(r.minLength!==void 0||r.maxLength!==void 0)&&(i+="{"+(r.minLength===void 0?0:r.minLength)+","+(r.maxLength===void 0?1/0:r.maxLength)+"}"),i},n},maybe:function e(t){t=Fe(t);function r(n,i){return he.Nil(n)||t(n,i,e)}return r.toJSON=function(){return"?"+De(t)},r},map:function(t,r){t=Fe(t),r&&(r=Fe(r));function n(i,a){if(!he.Object(i)||he.Nil(i))return!1;for(var f in i){try{r&&xe(r,f,a)}catch(l){throw Mt(l,f,"key")}try{var u=i[f];xe(t,u,a)}catch(l){throw Mt(l,f)}}return!0}return r?n.toJSON=function(){return"{"+De(r)+": "+De(t)+"}"}:n.toJSON=function(){return"{"+De(t)+"}"},n},object:function(t){var r={};for(var n in t)r[n]=Fe(t[n]);function i(a,f){if(!he.Object(a)||he.Nil(a))return!1;var u;try{for(u in r){var l=r[u],b=a[u];xe(l,b,f)}}catch(g){throw Mt(g,u)}if(f){for(u in a)if(!r[u])throw new ts(void 0,u)}return!0}return i.toJSON=function(){return De(r)},i},anyOf:function(){var t=[].slice.call(arguments).map(Fe);function r(n,i){return t.some(function(a){try{return xe(a,n,i)}catch{return!1}})}return r.toJSON=function(){return t.map(De).join("|")},r},allOf:function(){var t=[].slice.call(arguments).map(Fe);function r(n,i){return t.every(function(a){try{return xe(a,n,i)}catch{return!1}})}return r.toJSON=function(){return t.map(De).join(" & ")},r},quacksLike:function(t){function r(n){return t===af(n)}return r.toJSON=function(){return t},r},tuple:function(){var t=[].slice.call(arguments).map(Fe);function r(n,i){return he.Nil(n)||he.Nil(n.length)||i&&n.length!==t.length?!1:t.every(function(a,f){try{return xe(a,n[f],i)}catch(u){throw Mt(u,f)}})}return r.toJSON=function(){return"("+t.map(De).join(", ")+")"},r},value:function(t){function r(n){return n===t}return r.toJSON=function(){return t},r}};$e.oneOf=$e.anyOf;function Fe(e){if(he.String(e))return e[0]==="?"?$e.maybe(e.slice(1)):he[e]||$e.quacksLike(e);if(e&&he.Object(e)){if(he.Array(e)){if(e.length!==1)throw new TypeError("Expected compile() parameter of type Array of length 1");return $e.arrayOf(e[0])}return $e.object(e)}else if(he.Function(e))return e;return $e.value(e)}function xe(e,t,r,n){if(he.Function(e)){if(e(t,r))return!0;throw new es(n||e,t)}return xe(Fe(e),t,r)}for(var Xe in he)xe[Xe]=he[Xe];for(Xe in $e)xe[Xe]=$e[Xe];var Wn=of();for(Xe in Wn)xe[Xe]=Wn[Xe];xe.compile=Fe;xe.TfTypeError=es;xe.TfPropertyTypeError=ts;var ff=xe;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.maybe=e.Boolean=e.Array=e.Buffer256bit=e.Network=e.typeforce=void 0,e.typeforce=ff,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})(Ji);var rn={exports:{}},nn={exports:{}},kt={},Er={};Er.byteLength=lf;Er.toByteArray=df;Er.fromByteArray=yf;var Ue=[],Re=[],uf=typeof Uint8Array<"u"?Uint8Array:Array,Dr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var wt=0,cf=Dr.length;wt<cf;++wt)Ue[wt]=Dr[wt],Re[Dr.charCodeAt(wt)]=wt;Re[45]=62;Re[95]=63;function rs(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 lf(e){var t=rs(e),r=t[0],n=t[1];return(r+n)*3/4-n}function hf(e,t,r){return(t+r)*3/4-r}function df(e){var t,r=rs(e),n=r[0],i=r[1],a=new uf(hf(e,n,i)),f=0,u=i>0?n-4:n,l;for(l=0;l<u;l+=4)t=Re[e.charCodeAt(l)]<<18|Re[e.charCodeAt(l+1)]<<12|Re[e.charCodeAt(l+2)]<<6|Re[e.charCodeAt(l+3)],a[f++]=t>>16&255,a[f++]=t>>8&255,a[f++]=t&255;return i===2&&(t=Re[e.charCodeAt(l)]<<2|Re[e.charCodeAt(l+1)]>>4,a[f++]=t&255),i===1&&(t=Re[e.charCodeAt(l)]<<10|Re[e.charCodeAt(l+1)]<<4|Re[e.charCodeAt(l+2)]>>2,a[f++]=t>>8&255,a[f++]=t&255),a}function pf(e){return Ue[e>>18&63]+Ue[e>>12&63]+Ue[e>>6&63]+Ue[e&63]}function bf(e,t,r){for(var n,i=[],a=t;a<r;a+=3)n=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(e[a+2]&255),i.push(pf(n));return i.join("")}function yf(e){for(var t,r=e.length,n=r%3,i=[],a=16383,f=0,u=r-n;f<u;f+=a)i.push(bf(e,f,f+a>u?u:f+a));return n===1?(t=e[r-1],i.push(Ue[t>>2]+Ue[t<<4&63]+"==")):n===2&&(t=(e[r-2]<<8)+e[r-1],i.push(Ue[t>>10]+Ue[t>>4&63]+Ue[t<<2&63]+"=")),i.join("")}var Sn={};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */Sn.read=function(e,t,r,n,i){var a,f,u=i*8-n-1,l=(1<<u)-1,b=l>>1,g=-7,m=r?i-1:0,v=r?-1:1,A=e[t+m];for(m+=v,a=A&(1<<-g)-1,A>>=-g,g+=u;g>0;a=a*256+e[t+m],m+=v,g-=8);for(f=a&(1<<-g)-1,a>>=-g,g+=n;g>0;f=f*256+e[t+m],m+=v,g-=8);if(a===0)a=1-b;else{if(a===l)return f?NaN:(A?-1:1)*(1/0);f=f+Math.pow(2,n),a=a-b}return(A?-1:1)*f*Math.pow(2,a-n)};Sn.write=function(e,t,r,n,i,a){var f,u,l,b=a*8-i-1,g=(1<<b)-1,m=g>>1,v=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,A=n?0:a-1,B=n?1:-1,P=t<0||t===0&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(u=isNaN(t)?1:0,f=g):(f=Math.floor(Math.log(t)/Math.LN2),t*(l=Math.pow(2,-f))<1&&(f--,l*=2),f+m>=1?t+=v/l:t+=v*Math.pow(2,1-m),t*l>=2&&(f++,l/=2),f+m>=g?(u=0,f=g):f+m>=1?(u=(t*l-1)*Math.pow(2,i),f=f+m):(u=t*Math.pow(2,m-1)*Math.pow(2,i),f=0));i>=8;e[r+A]=u&255,A+=B,u/=256,i-=8);for(f=f<<i|u,b+=i;b>0;e[r+A]=f&255,A+=B,f/=256,b-=8);e[r+A-B]|=P*128};/*!
22
+ `,bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};var Ii={},Kt={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}};Kt.Null=Kt.Nil;for(var On in Kt)Kt[On].toJSON=(function(e){return e}).bind(null,On);var bn=Kt,ot=bn;function Ti(e){return e.name||e.toString().match(/function (.*?)\s*\(/)[1]}function yn(e){return ot.Nil(e)?"":Ti(e.constructor)}function lo(e){return ot.Function(e)?"":ot.String(e)?JSON.stringify(e):e&&ot.Object(e)?"":e}function gn(e,t){Error.captureStackTrace&&Error.captureStackTrace(e,t)}function hr(e){return ot.Function(e)?e.toJSON?e.toJSON():Ti(e):ot.Array(e)?"Array":e&&ot.Object(e)?"Object":e!==void 0?e:""}function Ri(e,t,r){var n=lo(t);return"Expected "+hr(e)+", got"+(r!==""?" "+r:"")+(n!==""?" "+n:"")}function ze(e,t,r){r=r||yn(t),this.message=Ri(e,t,r),gn(this,ze),this.__type=e,this.__value=t,this.__valueTypeName=r}ze.prototype=Object.create(Error.prototype);ze.prototype.constructor=ze;function ho(e,t,r,n,i){var o='" of type ';return t==="key"&&(o='" with key type '),Ri('property "'+hr(r)+o+hr(e),n,i)}function vt(e,t,r,n,i){e?(i=i||yn(n),this.message=ho(e,r,t,n,i)):this.message='Unexpected property "'+t+'"',gn(this,ze),this.__label=r,this.__property=t,this.__type=e,this.__value=n,this.__valueTypeName=i}vt.prototype=Object.create(Error.prototype);vt.prototype.constructor=ze;function po(e,t){return new ze(e,{},t)}function bo(e,t,r){return e instanceof vt?(t=t+"."+e.__property,e=new vt(e.__type,t,e.__label,e.__value,e.__valueTypeName)):e instanceof ze&&(e=new vt(e.__type,t,r,e.__value,e.__valueTypeName)),gn(e),e}var ki={TfTypeError:ze,TfPropertyTypeError:vt,tfCustomError:po,tfSubError:bo,tfJSON:hr,getValueTypeName:yn},Ur,Fn;function yo(){if(Fn)return Ur;Fn=1;var e=bn,t=ki;function r(B){return Buffer.isBuffer(B)}function n(B){return typeof B=="string"&&/^([0-9a-f]{2})+$/i.test(B)}function i(B,z){var M=B.toJSON();function $(fe){if(!B(fe))return!1;if(fe.length===z)return!0;throw t.tfCustomError(M+"(Length: "+z+")",M+"(Length: "+fe.length+")")}return $.toJSON=function(){return M},$}var o=i.bind(null,e.Array),u=i.bind(null,r),f=i.bind(null,n),l=i.bind(null,e.String);function b(B,z,M){M=M||e.Number;function $(fe,ke){return M(fe,ke)&&fe>B&&fe<z}return $.toJSON=function(){return`${M.toJSON()} between [${B}, ${z}]`},$}var g=Math.pow(2,53)-1;function m(B){return typeof B=="number"&&isFinite(B)}function v(B){return B<<24>>24===B}function A(B){return B<<16>>16===B}function I(B){return(B|0)===B}function k(B){return typeof B=="number"&&B>=-g&&B<=g&&Math.floor(B)===B}function C(B){return(B&255)===B}function P(B){return(B&65535)===B}function F(B){return B>>>0===B}function O(B){return typeof B=="number"&&B>=0&&B<=g&&Math.floor(B)===B}var L={ArrayN:o,Buffer:r,BufferN:u,Finite:m,Hex:n,HexN:f,Int8:v,Int16:A,Int32:I,Int53:k,Range:b,StringN:l,UInt8:C,UInt16:P,UInt32:F,UInt53:O};for(var U in L)L[U].toJSON=(function(B){return B}).bind(null,U);return Ur=L,Ur}var Xt=ki,de=bn,De=Xt.tfJSON,Ci=Xt.TfTypeError,Pi=Xt.TfPropertyTypeError,Ft=Xt.tfSubError,go=Xt.getValueTypeName,He={arrayOf:function(t,r){t=Fe(t),r=r||{};function n(i,o){return!de.Array(i)||de.Nil(i)||r.minLength!==void 0&&i.length<r.minLength||r.maxLength!==void 0&&i.length>r.maxLength||r.length!==void 0&&i.length!==r.length?!1:i.every(function(u,f){try{return xe(t,u,o)}catch(l){throw Ft(l,f)}})}return n.toJSON=function(){var i="["+De(t)+"]";return r.length!==void 0?i+="{"+r.length+"}":(r.minLength!==void 0||r.maxLength!==void 0)&&(i+="{"+(r.minLength===void 0?0:r.minLength)+","+(r.maxLength===void 0?1/0:r.maxLength)+"}"),i},n},maybe:function e(t){t=Fe(t);function r(n,i){return de.Nil(n)||t(n,i,e)}return r.toJSON=function(){return"?"+De(t)},r},map:function(t,r){t=Fe(t),r&&(r=Fe(r));function n(i,o){if(!de.Object(i)||de.Nil(i))return!1;for(var u in i){try{r&&xe(r,u,o)}catch(l){throw Ft(l,u,"key")}try{var f=i[u];xe(t,f,o)}catch(l){throw Ft(l,u)}}return!0}return r?n.toJSON=function(){return"{"+De(r)+": "+De(t)+"}"}:n.toJSON=function(){return"{"+De(t)+"}"},n},object:function(t){var r={};for(var n in t)r[n]=Fe(t[n]);function i(o,u){if(!de.Object(o)||de.Nil(o))return!1;var f;try{for(f in r){var l=r[f],b=o[f];xe(l,b,u)}}catch(g){throw Ft(g,f)}if(u){for(f in o)if(!r[f])throw new Pi(void 0,f)}return!0}return i.toJSON=function(){return De(r)},i},anyOf:function(){var t=[].slice.call(arguments).map(Fe);function r(n,i){return t.some(function(o){try{return xe(o,n,i)}catch{return!1}})}return r.toJSON=function(){return t.map(De).join("|")},r},allOf:function(){var t=[].slice.call(arguments).map(Fe);function r(n,i){return t.every(function(o){try{return xe(o,n,i)}catch{return!1}})}return r.toJSON=function(){return t.map(De).join(" & ")},r},quacksLike:function(t){function r(n){return t===go(n)}return r.toJSON=function(){return t},r},tuple:function(){var t=[].slice.call(arguments).map(Fe);function r(n,i){return de.Nil(n)||de.Nil(n.length)||i&&n.length!==t.length?!1:t.every(function(o,u){try{return xe(o,n[u],i)}catch(f){throw Ft(f,u)}})}return r.toJSON=function(){return"("+t.map(De).join(", ")+")"},r},value:function(t){function r(n){return n===t}return r.toJSON=function(){return t},r}};He.oneOf=He.anyOf;function Fe(e){if(de.String(e))return e[0]==="?"?He.maybe(e.slice(1)):de[e]||He.quacksLike(e);if(e&&de.Object(e)){if(de.Array(e)){if(e.length!==1)throw new TypeError("Expected compile() parameter of type Array of length 1");return He.arrayOf(e[0])}return He.object(e)}else if(de.Function(e))return e;return He.value(e)}function xe(e,t,r,n){if(de.Function(e)){if(e(t,r))return!0;throw new Ci(n||e,t)}return xe(Fe(e),t,r)}for(var Xe in de)xe[Xe]=de[Xe];for(Xe in He)xe[Xe]=He[Xe];var Un=yo();for(Xe in Un)xe[Xe]=Un[Xe];xe.compile=Fe;xe.TfTypeError=Ci;xe.TfPropertyTypeError=Pi;var mo=xe;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.maybe=e.Boolean=e.Array=e.Buffer256bit=e.Network=e.typeforce=void 0,e.typeforce=mo,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})(Ii);var rn={exports:{}},nn={exports:{}},Rt={},xr={};xr.byteLength=xo;xr.toByteArray=Eo;xr.fromByteArray=Ao;var Ue=[],Te=[],_o=typeof Uint8Array<"u"?Uint8Array:Array,Nr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var wt=0,wo=Nr.length;wt<wo;++wt)Ue[wt]=Nr[wt],Te[Nr.charCodeAt(wt)]=wt;Te[45]=62;Te[95]=63;function Li(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 xo(e){var t=Li(e),r=t[0],n=t[1];return(r+n)*3/4-n}function vo(e,t,r){return(t+r)*3/4-r}function Eo(e){var t,r=Li(e),n=r[0],i=r[1],o=new _o(vo(e,n,i)),u=0,f=i>0?n-4:n,l;for(l=0;l<f;l+=4)t=Te[e.charCodeAt(l)]<<18|Te[e.charCodeAt(l+1)]<<12|Te[e.charCodeAt(l+2)]<<6|Te[e.charCodeAt(l+3)],o[u++]=t>>16&255,o[u++]=t>>8&255,o[u++]=t&255;return i===2&&(t=Te[e.charCodeAt(l)]<<2|Te[e.charCodeAt(l+1)]>>4,o[u++]=t&255),i===1&&(t=Te[e.charCodeAt(l)]<<10|Te[e.charCodeAt(l+1)]<<4|Te[e.charCodeAt(l+2)]>>2,o[u++]=t>>8&255,o[u++]=t&255),o}function Bo(e){return Ue[e>>18&63]+Ue[e>>12&63]+Ue[e>>6&63]+Ue[e&63]}function So(e,t,r){for(var n,i=[],o=t;o<r;o+=3)n=(e[o]<<16&16711680)+(e[o+1]<<8&65280)+(e[o+2]&255),i.push(Bo(n));return i.join("")}function Ao(e){for(var t,r=e.length,n=r%3,i=[],o=16383,u=0,f=r-n;u<f;u+=o)i.push(So(e,u,u+o>f?f:u+o));return n===1?(t=e[r-1],i.push(Ue[t>>2]+Ue[t<<4&63]+"==")):n===2&&(t=(e[r-2]<<8)+e[r-1],i.push(Ue[t>>10]+Ue[t>>4&63]+Ue[t<<2&63]+"=")),i.join("")}var mn={};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */mn.read=function(e,t,r,n,i){var o,u,f=i*8-n-1,l=(1<<f)-1,b=l>>1,g=-7,m=r?i-1:0,v=r?-1:1,A=e[t+m];for(m+=v,o=A&(1<<-g)-1,A>>=-g,g+=f;g>0;o=o*256+e[t+m],m+=v,g-=8);for(u=o&(1<<-g)-1,o>>=-g,g+=n;g>0;u=u*256+e[t+m],m+=v,g-=8);if(o===0)o=1-b;else{if(o===l)return u?NaN:(A?-1:1)*(1/0);u=u+Math.pow(2,n),o=o-b}return(A?-1:1)*u*Math.pow(2,o-n)};mn.write=function(e,t,r,n,i,o){var u,f,l,b=o*8-i-1,g=(1<<b)-1,m=g>>1,v=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,A=n?0:o-1,I=n?1:-1,k=t<0||t===0&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(f=isNaN(t)?1:0,u=g):(u=Math.floor(Math.log(t)/Math.LN2),t*(l=Math.pow(2,-u))<1&&(u--,l*=2),u+m>=1?t+=v/l:t+=v*Math.pow(2,1-m),t*l>=2&&(u++,l/=2),u+m>=g?(f=0,u=g):u+m>=1?(f=(t*l-1)*Math.pow(2,i),u=u+m):(f=t*Math.pow(2,m-1)*Math.pow(2,i),u=0));i>=8;e[r+A]=f&255,A+=I,f/=256,i-=8);for(u=u<<i|f,b+=i;b>0;e[r+A]=u&255,A+=I,u/=256,b-=8);e[r+A-I]|=k*128};/*!
26
23
  * The buffer module from node.js, for the browser.
27
24
  *
28
25
  * @author Feross Aboukhadijeh <https://feross.org>
29
26
  * @license MIT
30
- */(function(e){const t=Er,r=Sn,n=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;e.Buffer=u,e.SlowBuffer=F,e.INSPECT_MAX_BYTES=50;const i=2147483647;e.kMaxLength=i,u.TYPED_ARRAY_SUPPORT=a(),!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 a(){try{const c=new Uint8Array(1),s={foo:function(){return 42}};return Object.setPrototypeOf(s,Uint8Array.prototype),Object.setPrototypeOf(c,s),c.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 f(c){if(c>i)throw new RangeError('The value "'+c+'" is invalid for option "size"');const s=new Uint8Array(c);return Object.setPrototypeOf(s,u.prototype),s}function u(c,s,o){if(typeof c=="number"){if(typeof s=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return m(c)}return l(c,s,o)}u.poolSize=8192;function l(c,s,o){if(typeof c=="string")return v(c,s);if(ArrayBuffer.isView(c))return B(c);if(c==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof c);if(Ae(c,ArrayBuffer)||c&&Ae(c.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(Ae(c,SharedArrayBuffer)||c&&Ae(c.buffer,SharedArrayBuffer)))return P(c,s,o);if(typeof c=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const h=c.valueOf&&c.valueOf();if(h!=null&&h!==c)return u.from(h,s,o);const y=T(c);if(y)return y;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof c[Symbol.toPrimitive]=="function")return u.from(c[Symbol.toPrimitive]("string"),s,o);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof c)}u.from=function(c,s,o){return l(c,s,o)},Object.setPrototypeOf(u.prototype,Uint8Array.prototype),Object.setPrototypeOf(u,Uint8Array);function b(c){if(typeof c!="number")throw new TypeError('"size" argument must be of type number');if(c<0)throw new RangeError('The value "'+c+'" is invalid for option "size"')}function g(c,s,o){return b(c),c<=0?f(c):s!==void 0?typeof o=="string"?f(c).fill(s,o):f(c).fill(s):f(c)}u.alloc=function(c,s,o){return g(c,s,o)};function m(c){return b(c),f(c<0?0:C(c)|0)}u.allocUnsafe=function(c){return m(c)},u.allocUnsafeSlow=function(c){return m(c)};function v(c,s){if((typeof s!="string"||s==="")&&(s="utf8"),!u.isEncoding(s))throw new TypeError("Unknown encoding: "+s);const o=O(c,s)|0;let h=f(o);const y=h.write(c,s);return y!==o&&(h=h.slice(0,y)),h}function A(c){const s=c.length<0?0:C(c.length)|0,o=f(s);for(let h=0;h<s;h+=1)o[h]=c[h]&255;return o}function B(c){if(Ae(c,Uint8Array)){const s=new Uint8Array(c);return P(s.buffer,s.byteOffset,s.byteLength)}return A(c)}function P(c,s,o){if(s<0||c.byteLength<s)throw new RangeError('"offset" is outside of buffer bounds');if(c.byteLength<s+(o||0))throw new RangeError('"length" is outside of buffer bounds');let h;return s===void 0&&o===void 0?h=new Uint8Array(c):o===void 0?h=new Uint8Array(c,s):h=new Uint8Array(c,s,o),Object.setPrototypeOf(h,u.prototype),h}function T(c){if(u.isBuffer(c)){const s=C(c.length)|0,o=f(s);return o.length===0||c.copy(o,0,0,s),o}if(c.length!==void 0)return typeof c.length!="number"||nt(c.length)?f(0):A(c);if(c.type==="Buffer"&&Array.isArray(c.data))return A(c.data)}function C(c){if(c>=i)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i.toString(16)+" bytes");return c|0}function F(c){return+c!=c&&(c=0),u.alloc(+c)}u.isBuffer=function(s){return s!=null&&s._isBuffer===!0&&s!==u.prototype},u.compare=function(s,o){if(Ae(s,Uint8Array)&&(s=u.from(s,s.offset,s.byteLength)),Ae(o,Uint8Array)&&(o=u.from(o,o.offset,o.byteLength)),!u.isBuffer(s)||!u.isBuffer(o))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(s===o)return 0;let h=s.length,y=o.length;for(let x=0,E=Math.min(h,y);x<E;++x)if(s[x]!==o[x]){h=s[x],y=o[x];break}return h<y?-1:y<h?1:0},u.isEncoding=function(s){switch(String(s).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(s,o){if(!Array.isArray(s))throw new TypeError('"list" argument must be an Array of Buffers');if(s.length===0)return u.alloc(0);let h;if(o===void 0)for(o=0,h=0;h<s.length;++h)o+=s[h].length;const y=u.allocUnsafe(o);let x=0;for(h=0;h<s.length;++h){let E=s[h];if(Ae(E,Uint8Array))x+E.length>y.length?(u.isBuffer(E)||(E=u.from(E)),E.copy(y,x)):Uint8Array.prototype.set.call(y,E,x);else if(u.isBuffer(E))E.copy(y,x);else throw new TypeError('"list" argument must be an Array of Buffers');x+=E.length}return y};function O(c,s){if(u.isBuffer(c))return c.length;if(ArrayBuffer.isView(c)||Ae(c,ArrayBuffer))return c.byteLength;if(typeof c!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof c);const o=c.length,h=arguments.length>2&&arguments[2]===!0;if(!h&&o===0)return 0;let y=!1;for(;;)switch(s){case"ascii":case"latin1":case"binary":return o;case"utf8":case"utf-8":return V(c).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return o*2;case"hex":return o>>>1;case"base64":return Ct(c).length;default:if(y)return h?-1:V(c).length;s=(""+s).toLowerCase(),y=!0}}u.byteLength=O;function L(c,s,o){let h=!1;if((s===void 0||s<0)&&(s=0),s>this.length||((o===void 0||o>this.length)&&(o=this.length),o<=0)||(o>>>=0,s>>>=0,o<=s))return"";for(c||(c="utf8");;)switch(c){case"hex":return Ce(this,s,o);case"utf8":case"utf-8":return Ee(this,s,o);case"ascii":return Pe(this,s,o);case"latin1":case"binary":return We(this,s,o);case"base64":return ue(this,s,o);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return qe(this,s,o);default:if(h)throw new TypeError("Unknown encoding: "+c);c=(c+"").toLowerCase(),h=!0}}u.prototype._isBuffer=!0;function U(c,s,o){const h=c[s];c[s]=c[o],c[o]=h}u.prototype.swap16=function(){const s=this.length;if(s%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let o=0;o<s;o+=2)U(this,o,o+1);return this},u.prototype.swap32=function(){const s=this.length;if(s%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let o=0;o<s;o+=4)U(this,o,o+3),U(this,o+1,o+2);return this},u.prototype.swap64=function(){const s=this.length;if(s%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let o=0;o<s;o+=8)U(this,o,o+7),U(this,o+1,o+6),U(this,o+2,o+5),U(this,o+3,o+4);return this},u.prototype.toString=function(){const s=this.length;return s===0?"":arguments.length===0?Ee(this,0,s):L.apply(this,arguments)},u.prototype.toLocaleString=u.prototype.toString,u.prototype.equals=function(s){if(!u.isBuffer(s))throw new TypeError("Argument must be a Buffer");return this===s?!0:u.compare(this,s)===0},u.prototype.inspect=function(){let s="";const o=e.INSPECT_MAX_BYTES;return s=this.toString("hex",0,o).replace(/(.{2})/g,"$1 ").trim(),this.length>o&&(s+=" ... "),"<Buffer "+s+">"},n&&(u.prototype[n]=u.prototype.inspect),u.prototype.compare=function(s,o,h,y,x){if(Ae(s,Uint8Array)&&(s=u.from(s,s.offset,s.byteLength)),!u.isBuffer(s))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof s);if(o===void 0&&(o=0),h===void 0&&(h=s?s.length:0),y===void 0&&(y=0),x===void 0&&(x=this.length),o<0||h>s.length||y<0||x>this.length)throw new RangeError("out of range index");if(y>=x&&o>=h)return 0;if(y>=x)return-1;if(o>=h)return 1;if(o>>>=0,h>>>=0,y>>>=0,x>>>=0,this===s)return 0;let E=x-y,q=h-o;const ie=Math.min(E,q),re=this.slice(y,x),se=s.slice(o,h);for(let Y=0;Y<ie;++Y)if(re[Y]!==se[Y]){E=re[Y],q=se[Y];break}return E<q?-1:q<E?1:0};function S(c,s,o,h,y){if(c.length===0)return-1;if(typeof o=="string"?(h=o,o=0):o>2147483647?o=2147483647:o<-2147483648&&(o=-2147483648),o=+o,nt(o)&&(o=y?0:c.length-1),o<0&&(o=c.length+o),o>=c.length){if(y)return-1;o=c.length-1}else if(o<0)if(y)o=0;else return-1;if(typeof s=="string"&&(s=u.from(s,h)),u.isBuffer(s))return s.length===0?-1:z(c,s,o,h,y);if(typeof s=="number")return s=s&255,typeof Uint8Array.prototype.indexOf=="function"?y?Uint8Array.prototype.indexOf.call(c,s,o):Uint8Array.prototype.lastIndexOf.call(c,s,o):z(c,[s],o,h,y);throw new TypeError("val must be string, number or Buffer")}function z(c,s,o,h,y){let x=1,E=c.length,q=s.length;if(h!==void 0&&(h=String(h).toLowerCase(),h==="ucs2"||h==="ucs-2"||h==="utf16le"||h==="utf-16le")){if(c.length<2||s.length<2)return-1;x=2,E/=2,q/=2,o/=2}function ie(se,Y){return x===1?se[Y]:se.readUInt16BE(Y*x)}let re;if(y){let se=-1;for(re=o;re<E;re++)if(ie(c,re)===ie(s,se===-1?0:re-se)){if(se===-1&&(se=re),re-se+1===q)return se*x}else se!==-1&&(re-=re-se),se=-1}else for(o+q>E&&(o=E-q),re=o;re>=0;re--){let se=!0;for(let Y=0;Y<q;Y++)if(ie(c,re+Y)!==ie(s,Y)){se=!1;break}if(se)return re}return-1}u.prototype.includes=function(s,o,h){return this.indexOf(s,o,h)!==-1},u.prototype.indexOf=function(s,o,h){return S(this,s,o,h,!0)},u.prototype.lastIndexOf=function(s,o,h){return S(this,s,o,h,!1)};function M(c,s,o,h){o=Number(o)||0;const y=c.length-o;h?(h=Number(h),h>y&&(h=y)):h=y;const x=s.length;h>x/2&&(h=x/2);let E;for(E=0;E<h;++E){const q=parseInt(s.substr(E*2,2),16);if(nt(q))return E;c[o+E]=q}return E}function $(c,s,o,h){return gt(V(s,c.length-o),c,o,h)}function ae(c,s,o,h){return gt(Ke(s),c,o,h)}function ke(c,s,o,h){return gt(Ct(s),c,o,h)}function je(c,s,o,h){return gt(yt(s,c.length-o),c,o,h)}u.prototype.write=function(s,o,h,y){if(o===void 0)y="utf8",h=this.length,o=0;else if(h===void 0&&typeof o=="string")y=o,h=this.length,o=0;else if(isFinite(o))o=o>>>0,isFinite(h)?(h=h>>>0,y===void 0&&(y="utf8")):(y=h,h=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const x=this.length-o;if((h===void 0||h>x)&&(h=x),s.length>0&&(h<0||o<0)||o>this.length)throw new RangeError("Attempt to write outside buffer bounds");y||(y="utf8");let E=!1;for(;;)switch(y){case"hex":return M(this,s,o,h);case"utf8":case"utf-8":return $(this,s,o,h);case"ascii":case"latin1":case"binary":return ae(this,s,o,h);case"base64":return ke(this,s,o,h);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return je(this,s,o,h);default:if(E)throw new TypeError("Unknown encoding: "+y);y=(""+y).toLowerCase(),E=!0}},u.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function ue(c,s,o){return s===0&&o===c.length?t.fromByteArray(c):t.fromByteArray(c.slice(s,o))}function Ee(c,s,o){o=Math.min(c.length,o);const h=[];let y=s;for(;y<o;){const x=c[y];let E=null,q=x>239?4:x>223?3:x>191?2:1;if(y+q<=o){let ie,re,se,Y;switch(q){case 1:x<128&&(E=x);break;case 2:ie=c[y+1],(ie&192)===128&&(Y=(x&31)<<6|ie&63,Y>127&&(E=Y));break;case 3:ie=c[y+1],re=c[y+2],(ie&192)===128&&(re&192)===128&&(Y=(x&15)<<12|(ie&63)<<6|re&63,Y>2047&&(Y<55296||Y>57343)&&(E=Y));break;case 4:ie=c[y+1],re=c[y+2],se=c[y+3],(ie&192)===128&&(re&192)===128&&(se&192)===128&&(Y=(x&15)<<18|(ie&63)<<12|(re&63)<<6|se&63,Y>65535&&Y<1114112&&(E=Y))}}E===null?(E=65533,q=1):E>65535&&(E-=65536,h.push(E>>>10&1023|55296),E=56320|E&1023),h.push(E),y+=q}return rt(h)}const Be=4096;function rt(c){const s=c.length;if(s<=Be)return String.fromCharCode.apply(String,c);let o="",h=0;for(;h<s;)o+=String.fromCharCode.apply(String,c.slice(h,h+=Be));return o}function Pe(c,s,o){let h="";o=Math.min(c.length,o);for(let y=s;y<o;++y)h+=String.fromCharCode(c[y]&127);return h}function We(c,s,o){let h="";o=Math.min(c.length,o);for(let y=s;y<o;++y)h+=String.fromCharCode(c[y]);return h}function Ce(c,s,o){const h=c.length;(!s||s<0)&&(s=0),(!o||o<0||o>h)&&(o=h);let y="";for(let x=s;x<o;++x)y+=Lt[c[x]];return y}function qe(c,s,o){const h=c.slice(s,o);let y="";for(let x=0;x<h.length-1;x+=2)y+=String.fromCharCode(h[x]+h[x+1]*256);return y}u.prototype.slice=function(s,o){const h=this.length;s=~~s,o=o===void 0?h:~~o,s<0?(s+=h,s<0&&(s=0)):s>h&&(s=h),o<0?(o+=h,o<0&&(o=0)):o>h&&(o=h),o<s&&(o=s);const y=this.subarray(s,o);return Object.setPrototypeOf(y,u.prototype),y};function ee(c,s,o){if(c%1!==0||c<0)throw new RangeError("offset is not uint");if(c+s>o)throw new RangeError("Trying to access beyond buffer length")}u.prototype.readUintLE=u.prototype.readUIntLE=function(s,o,h){s=s>>>0,o=o>>>0,h||ee(s,o,this.length);let y=this[s],x=1,E=0;for(;++E<o&&(x*=256);)y+=this[s+E]*x;return y},u.prototype.readUintBE=u.prototype.readUIntBE=function(s,o,h){s=s>>>0,o=o>>>0,h||ee(s,o,this.length);let y=this[s+--o],x=1;for(;o>0&&(x*=256);)y+=this[s+--o]*x;return y},u.prototype.readUint8=u.prototype.readUInt8=function(s,o){return s=s>>>0,o||ee(s,1,this.length),this[s]},u.prototype.readUint16LE=u.prototype.readUInt16LE=function(s,o){return s=s>>>0,o||ee(s,2,this.length),this[s]|this[s+1]<<8},u.prototype.readUint16BE=u.prototype.readUInt16BE=function(s,o){return s=s>>>0,o||ee(s,2,this.length),this[s]<<8|this[s+1]},u.prototype.readUint32LE=u.prototype.readUInt32LE=function(s,o){return s=s>>>0,o||ee(s,4,this.length),(this[s]|this[s+1]<<8|this[s+2]<<16)+this[s+3]*16777216},u.prototype.readUint32BE=u.prototype.readUInt32BE=function(s,o){return s=s>>>0,o||ee(s,4,this.length),this[s]*16777216+(this[s+1]<<16|this[s+2]<<8|this[s+3])},u.prototype.readBigUInt64LE=Ie(function(s){s=s>>>0,I(s,"offset");const o=this[s],h=this[s+7];(o===void 0||h===void 0)&&N(s,this.length-8);const y=o+this[++s]*2**8+this[++s]*2**16+this[++s]*2**24,x=this[++s]+this[++s]*2**8+this[++s]*2**16+h*2**24;return BigInt(y)+(BigInt(x)<<BigInt(32))}),u.prototype.readBigUInt64BE=Ie(function(s){s=s>>>0,I(s,"offset");const o=this[s],h=this[s+7];(o===void 0||h===void 0)&&N(s,this.length-8);const y=o*2**24+this[++s]*2**16+this[++s]*2**8+this[++s],x=this[++s]*2**24+this[++s]*2**16+this[++s]*2**8+h;return(BigInt(y)<<BigInt(32))+BigInt(x)}),u.prototype.readIntLE=function(s,o,h){s=s>>>0,o=o>>>0,h||ee(s,o,this.length);let y=this[s],x=1,E=0;for(;++E<o&&(x*=256);)y+=this[s+E]*x;return x*=128,y>=x&&(y-=Math.pow(2,8*o)),y},u.prototype.readIntBE=function(s,o,h){s=s>>>0,o=o>>>0,h||ee(s,o,this.length);let y=o,x=1,E=this[s+--y];for(;y>0&&(x*=256);)E+=this[s+--y]*x;return x*=128,E>=x&&(E-=Math.pow(2,8*o)),E},u.prototype.readInt8=function(s,o){return s=s>>>0,o||ee(s,1,this.length),this[s]&128?(255-this[s]+1)*-1:this[s]},u.prototype.readInt16LE=function(s,o){s=s>>>0,o||ee(s,2,this.length);const h=this[s]|this[s+1]<<8;return h&32768?h|4294901760:h},u.prototype.readInt16BE=function(s,o){s=s>>>0,o||ee(s,2,this.length);const h=this[s+1]|this[s]<<8;return h&32768?h|4294901760:h},u.prototype.readInt32LE=function(s,o){return s=s>>>0,o||ee(s,4,this.length),this[s]|this[s+1]<<8|this[s+2]<<16|this[s+3]<<24},u.prototype.readInt32BE=function(s,o){return s=s>>>0,o||ee(s,4,this.length),this[s]<<24|this[s+1]<<16|this[s+2]<<8|this[s+3]},u.prototype.readBigInt64LE=Ie(function(s){s=s>>>0,I(s,"offset");const o=this[s],h=this[s+7];(o===void 0||h===void 0)&&N(s,this.length-8);const y=this[s+4]+this[s+5]*2**8+this[s+6]*2**16+(h<<24);return(BigInt(y)<<BigInt(32))+BigInt(o+this[++s]*2**8+this[++s]*2**16+this[++s]*2**24)}),u.prototype.readBigInt64BE=Ie(function(s){s=s>>>0,I(s,"offset");const o=this[s],h=this[s+7];(o===void 0||h===void 0)&&N(s,this.length-8);const y=(o<<24)+this[++s]*2**16+this[++s]*2**8+this[++s];return(BigInt(y)<<BigInt(32))+BigInt(this[++s]*2**24+this[++s]*2**16+this[++s]*2**8+h)}),u.prototype.readFloatLE=function(s,o){return s=s>>>0,o||ee(s,4,this.length),r.read(this,s,!0,23,4)},u.prototype.readFloatBE=function(s,o){return s=s>>>0,o||ee(s,4,this.length),r.read(this,s,!1,23,4)},u.prototype.readDoubleLE=function(s,o){return s=s>>>0,o||ee(s,8,this.length),r.read(this,s,!0,52,8)},u.prototype.readDoubleBE=function(s,o){return s=s>>>0,o||ee(s,8,this.length),r.read(this,s,!1,52,8)};function fe(c,s,o,h,y,x){if(!u.isBuffer(c))throw new TypeError('"buffer" argument must be a Buffer instance');if(s>y||s<x)throw new RangeError('"value" argument is out of bounds');if(o+h>c.length)throw new RangeError("Index out of range")}u.prototype.writeUintLE=u.prototype.writeUIntLE=function(s,o,h,y){if(s=+s,o=o>>>0,h=h>>>0,!y){const q=Math.pow(2,8*h)-1;fe(this,s,o,h,q,0)}let x=1,E=0;for(this[o]=s&255;++E<h&&(x*=256);)this[o+E]=s/x&255;return o+h},u.prototype.writeUintBE=u.prototype.writeUIntBE=function(s,o,h,y){if(s=+s,o=o>>>0,h=h>>>0,!y){const q=Math.pow(2,8*h)-1;fe(this,s,o,h,q,0)}let x=h-1,E=1;for(this[o+x]=s&255;--x>=0&&(E*=256);)this[o+x]=s/E&255;return o+h},u.prototype.writeUint8=u.prototype.writeUInt8=function(s,o,h){return s=+s,o=o>>>0,h||fe(this,s,o,1,255,0),this[o]=s&255,o+1},u.prototype.writeUint16LE=u.prototype.writeUInt16LE=function(s,o,h){return s=+s,o=o>>>0,h||fe(this,s,o,2,65535,0),this[o]=s&255,this[o+1]=s>>>8,o+2},u.prototype.writeUint16BE=u.prototype.writeUInt16BE=function(s,o,h){return s=+s,o=o>>>0,h||fe(this,s,o,2,65535,0),this[o]=s>>>8,this[o+1]=s&255,o+2},u.prototype.writeUint32LE=u.prototype.writeUInt32LE=function(s,o,h){return s=+s,o=o>>>0,h||fe(this,s,o,4,4294967295,0),this[o+3]=s>>>24,this[o+2]=s>>>16,this[o+1]=s>>>8,this[o]=s&255,o+4},u.prototype.writeUint32BE=u.prototype.writeUInt32BE=function(s,o,h){return s=+s,o=o>>>0,h||fe(this,s,o,4,4294967295,0),this[o]=s>>>24,this[o+1]=s>>>16,this[o+2]=s>>>8,this[o+3]=s&255,o+4};function Se(c,s,o,h,y){p(s,h,y,c,o,7);let x=Number(s&BigInt(4294967295));c[o++]=x,x=x>>8,c[o++]=x,x=x>>8,c[o++]=x,x=x>>8,c[o++]=x;let E=Number(s>>BigInt(32)&BigInt(4294967295));return c[o++]=E,E=E>>8,c[o++]=E,E=E>>8,c[o++]=E,E=E>>8,c[o++]=E,o}function Ve(c,s,o,h,y){p(s,h,y,c,o,7);let x=Number(s&BigInt(4294967295));c[o+7]=x,x=x>>8,c[o+6]=x,x=x>>8,c[o+5]=x,x=x>>8,c[o+4]=x;let E=Number(s>>BigInt(32)&BigInt(4294967295));return c[o+3]=E,E=E>>8,c[o+2]=E,E=E>>8,c[o+1]=E,E=E>>8,c[o]=E,o+8}u.prototype.writeBigUInt64LE=Ie(function(s,o=0){return Se(this,s,o,BigInt(0),BigInt("0xffffffffffffffff"))}),u.prototype.writeBigUInt64BE=Ie(function(s,o=0){return Ve(this,s,o,BigInt(0),BigInt("0xffffffffffffffff"))}),u.prototype.writeIntLE=function(s,o,h,y){if(s=+s,o=o>>>0,!y){const ie=Math.pow(2,8*h-1);fe(this,s,o,h,ie-1,-ie)}let x=0,E=1,q=0;for(this[o]=s&255;++x<h&&(E*=256);)s<0&&q===0&&this[o+x-1]!==0&&(q=1),this[o+x]=(s/E>>0)-q&255;return o+h},u.prototype.writeIntBE=function(s,o,h,y){if(s=+s,o=o>>>0,!y){const ie=Math.pow(2,8*h-1);fe(this,s,o,h,ie-1,-ie)}let x=h-1,E=1,q=0;for(this[o+x]=s&255;--x>=0&&(E*=256);)s<0&&q===0&&this[o+x+1]!==0&&(q=1),this[o+x]=(s/E>>0)-q&255;return o+h},u.prototype.writeInt8=function(s,o,h){return s=+s,o=o>>>0,h||fe(this,s,o,1,127,-128),s<0&&(s=255+s+1),this[o]=s&255,o+1},u.prototype.writeInt16LE=function(s,o,h){return s=+s,o=o>>>0,h||fe(this,s,o,2,32767,-32768),this[o]=s&255,this[o+1]=s>>>8,o+2},u.prototype.writeInt16BE=function(s,o,h){return s=+s,o=o>>>0,h||fe(this,s,o,2,32767,-32768),this[o]=s>>>8,this[o+1]=s&255,o+2},u.prototype.writeInt32LE=function(s,o,h){return s=+s,o=o>>>0,h||fe(this,s,o,4,2147483647,-2147483648),this[o]=s&255,this[o+1]=s>>>8,this[o+2]=s>>>16,this[o+3]=s>>>24,o+4},u.prototype.writeInt32BE=function(s,o,h){return s=+s,o=o>>>0,h||fe(this,s,o,4,2147483647,-2147483648),s<0&&(s=4294967295+s+1),this[o]=s>>>24,this[o+1]=s>>>16,this[o+2]=s>>>8,this[o+3]=s&255,o+4},u.prototype.writeBigInt64LE=Ie(function(s,o=0){return Se(this,s,o,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),u.prototype.writeBigInt64BE=Ie(function(s,o=0){return Ve(this,s,o,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Ne(c,s,o,h,y,x){if(o+h>c.length)throw new RangeError("Index out of range");if(o<0)throw new RangeError("Index out of range")}function w(c,s,o,h,y){return s=+s,o=o>>>0,y||Ne(c,s,o,4),r.write(c,s,o,h,23,4),o+4}u.prototype.writeFloatLE=function(s,o,h){return w(this,s,o,!0,h)},u.prototype.writeFloatBE=function(s,o,h){return w(this,s,o,!1,h)};function _(c,s,o,h,y){return s=+s,o=o>>>0,y||Ne(c,s,o,8),r.write(c,s,o,h,52,8),o+8}u.prototype.writeDoubleLE=function(s,o,h){return _(this,s,o,!0,h)},u.prototype.writeDoubleBE=function(s,o,h){return _(this,s,o,!1,h)},u.prototype.copy=function(s,o,h,y){if(!u.isBuffer(s))throw new TypeError("argument should be a Buffer");if(h||(h=0),!y&&y!==0&&(y=this.length),o>=s.length&&(o=s.length),o||(o=0),y>0&&y<h&&(y=h),y===h||s.length===0||this.length===0)return 0;if(o<0)throw new RangeError("targetStart out of bounds");if(h<0||h>=this.length)throw new RangeError("Index out of range");if(y<0)throw new RangeError("sourceEnd out of bounds");y>this.length&&(y=this.length),s.length-o<y-h&&(y=s.length-o+h);const x=y-h;return this===s&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(o,h,y):Uint8Array.prototype.set.call(s,this.subarray(h,y),o),x},u.prototype.fill=function(s,o,h,y){if(typeof s=="string"){if(typeof o=="string"?(y=o,o=0,h=this.length):typeof h=="string"&&(y=h,h=this.length),y!==void 0&&typeof y!="string")throw new TypeError("encoding must be a string");if(typeof y=="string"&&!u.isEncoding(y))throw new TypeError("Unknown encoding: "+y);if(s.length===1){const E=s.charCodeAt(0);(y==="utf8"&&E<128||y==="latin1")&&(s=E)}}else typeof s=="number"?s=s&255:typeof s=="boolean"&&(s=Number(s));if(o<0||this.length<o||this.length<h)throw new RangeError("Out of range index");if(h<=o)return this;o=o>>>0,h=h===void 0?this.length:h>>>0,s||(s=0);let x;if(typeof s=="number")for(x=o;x<h;++x)this[x]=s;else{const E=u.isBuffer(s)?s:u.from(s,y),q=E.length;if(q===0)throw new TypeError('The value "'+s+'" is invalid for argument "value"');for(x=0;x<h-o;++x)this[x+o]=E[x%q]}return this};const R={};function D(c,s,o){R[c]=class extends o{constructor(){super(),Object.defineProperty(this,"message",{value:s.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${c}]`,this.stack,delete this.name}get code(){return c}set code(y){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:y,writable:!0})}toString(){return`${this.name} [${c}]: ${this.message}`}}}D("ERR_BUFFER_OUT_OF_BOUNDS",function(c){return c?`${c} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),D("ERR_INVALID_ARG_TYPE",function(c,s){return`The "${c}" argument must be of type number. Received type ${typeof s}`},TypeError),D("ERR_OUT_OF_RANGE",function(c,s,o){let h=`The value of "${c}" is out of range.`,y=o;return Number.isInteger(o)&&Math.abs(o)>2**32?y=G(String(o)):typeof o=="bigint"&&(y=String(o),(o>BigInt(2)**BigInt(32)||o<-(BigInt(2)**BigInt(32)))&&(y=G(y)),y+="n"),h+=` It must be ${s}. Received ${y}`,h},RangeError);function G(c){let s="",o=c.length;const h=c[0]==="-"?1:0;for(;o>=h+4;o-=3)s=`_${c.slice(o-3,o)}${s}`;return`${c.slice(0,o)}${s}`}function d(c,s,o){I(s,"offset"),(c[s]===void 0||c[s+o]===void 0)&&N(s,c.length-(o+1))}function p(c,s,o,h,y,x){if(c>o||c<s){const E=typeof s=="bigint"?"n":"";let q;throw s===0||s===BigInt(0)?q=`>= 0${E} and < 2${E} ** ${(x+1)*8}${E}`:q=`>= -(2${E} ** ${(x+1)*8-1}${E}) and < 2 ** ${(x+1)*8-1}${E}`,new R.ERR_OUT_OF_RANGE("value",q,c)}d(h,y,x)}function I(c,s){if(typeof c!="number")throw new R.ERR_INVALID_ARG_TYPE(s,"number",c)}function N(c,s,o){throw Math.floor(c)!==c?(I(c,o),new R.ERR_OUT_OF_RANGE("offset","an integer",c)):s<0?new R.ERR_BUFFER_OUT_OF_BOUNDS:new R.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${s}`,c)}const te=/[^+/0-9A-Za-z-_]/g;function j(c){if(c=c.split("=")[0],c=c.trim().replace(te,""),c.length<2)return"";for(;c.length%4!==0;)c=c+"=";return c}function V(c,s){s=s||1/0;let o;const h=c.length;let y=null;const x=[];for(let E=0;E<h;++E){if(o=c.charCodeAt(E),o>55295&&o<57344){if(!y){if(o>56319){(s-=3)>-1&&x.push(239,191,189);continue}else if(E+1===h){(s-=3)>-1&&x.push(239,191,189);continue}y=o;continue}if(o<56320){(s-=3)>-1&&x.push(239,191,189),y=o;continue}o=(y-55296<<10|o-56320)+65536}else y&&(s-=3)>-1&&x.push(239,191,189);if(y=null,o<128){if((s-=1)<0)break;x.push(o)}else if(o<2048){if((s-=2)<0)break;x.push(o>>6|192,o&63|128)}else if(o<65536){if((s-=3)<0)break;x.push(o>>12|224,o>>6&63|128,o&63|128)}else if(o<1114112){if((s-=4)<0)break;x.push(o>>18|240,o>>12&63|128,o>>6&63|128,o&63|128)}else throw new Error("Invalid code point")}return x}function Ke(c){const s=[];for(let o=0;o<c.length;++o)s.push(c.charCodeAt(o)&255);return s}function yt(c,s){let o,h,y;const x=[];for(let E=0;E<c.length&&!((s-=2)<0);++E)o=c.charCodeAt(E),h=o>>8,y=o%256,x.push(y),x.push(h);return x}function Ct(c){return t.toByteArray(j(c))}function gt(c,s,o,h){let y;for(y=0;y<h&&!(y+o>=s.length||y>=c.length);++y)s[y+o]=c[y];return y}function Ae(c,s){return c instanceof s||c!=null&&c.constructor!=null&&c.constructor.name!=null&&c.constructor.name===s.name}function nt(c){return c!==c}const Lt=function(){const c="0123456789abcdef",s=new Array(256);for(let o=0;o<16;++o){const h=o*16;for(let y=0;y<16;++y)s[h+y]=c[o]+c[y]}return s}();function Ie(c){return typeof BigInt>"u"?it:c}function it(){throw new Error("BigInt not supported")}})(kt);/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */(function(e,t){var r=kt,n=r.Buffer;function i(f,u){for(var l in f)u[l]=f[l]}n.from&&n.alloc&&n.allocUnsafe&&n.allocUnsafeSlow?e.exports=r:(i(r,t),t.Buffer=a);function a(f,u,l){return n(f,u,l)}a.prototype=Object.create(n.prototype),i(n,a),a.from=function(f,u,l){if(typeof f=="number")throw new TypeError("Argument must not be a number");return n(f,u,l)},a.alloc=function(f,u,l){if(typeof f!="number")throw new TypeError("Argument must be a number");var b=n(f);return u!==void 0?typeof l=="string"?b.fill(u,l):b.fill(u):b.fill(0),b},a.allocUnsafe=function(f){if(typeof f!="number")throw new TypeError("Argument must be a number");return n(f)},a.allocUnsafeSlow=function(f){if(typeof f!="number")throw new TypeError("Argument must be a number");return r.SlowBuffer(f)}})(nn,nn.exports);var ve=nn.exports,$r=65536,gf=4294967295;function mf(){throw new Error(`Secure random number generation is not supported by this browser.
31
- Use Chrome, Firefox or Internet Explorer 11`)}var _f=ve.Buffer,br=Qe.crypto||Qe.msCrypto;br&&br.getRandomValues?rn.exports=wf:rn.exports=mf;function wf(e,t){if(e>gf)throw new RangeError("requested too many random bytes");var r=_f.allocUnsafe(e);if(e>0)if(e>$r)for(var n=0;n<e;n+=$r)br.getRandomValues(r.slice(n,n+$r));else br.getRandomValues(r);return typeof t=="function"?process.nextTick(function(){t(null,r)}):r}var xf=rn.exports,sn={exports:{}};typeof Object.create=="function"?sn.exports=function(t,r){r&&(t.super_=r,t.prototype=Object.create(r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}))}:sn.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 de=sn.exports,on={exports:{}},An={exports:{}},Et=typeof Reflect=="object"?Reflect:null,qn=Et&&typeof Et.apply=="function"?Et.apply:function(t,r,n){return Function.prototype.apply.call(t,r,n)},fr;Et&&typeof Et.ownKeys=="function"?fr=Et.ownKeys:Object.getOwnPropertySymbols?fr=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:fr=function(t){return Object.getOwnPropertyNames(t)};function vf(e){console&&console.warn&&console.warn(e)}var ns=Number.isNaN||function(t){return t!==t};function K(){K.init.call(this)}An.exports=K;An.exports.once=Af;K.EventEmitter=K;K.prototype._events=void 0;K.prototype._eventsCount=0;K.prototype._maxListeners=void 0;var Vn=10;function Br(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 Vn},set:function(e){if(typeof e!="number"||e<0||ns(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");Vn=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||ns(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 is(e){return e._maxListeners===void 0?K.defaultMaxListeners:e._maxListeners}K.prototype.getMaxListeners=function(){return is(this)};K.prototype.emit=function(t){for(var r=[],n=1;n<arguments.length;n++)r.push(arguments[n]);var i=t==="error",a=this._events;if(a!==void 0)i=i&&a.error===void 0;else if(!i)return!1;if(i){var f;if(r.length>0&&(f=r[0]),f instanceof Error)throw f;var u=new Error("Unhandled error."+(f?" ("+f.message+")":""));throw u.context=f,u}var l=a[t];if(l===void 0)return!1;if(typeof l=="function")qn(l,this,r);else for(var b=l.length,g=us(l,b),n=0;n<b;++n)qn(g[n],this,r);return!0};function ss(e,t,r,n){var i,a,f;if(Br(r),a=e._events,a===void 0?(a=e._events=Object.create(null),e._eventsCount=0):(a.newListener!==void 0&&(e.emit("newListener",t,r.listener?r.listener:r),a=e._events),f=a[t]),f===void 0)f=a[t]=r,++e._eventsCount;else if(typeof f=="function"?f=a[t]=n?[r,f]:[f,r]:n?f.unshift(r):f.push(r),i=is(e),i>0&&f.length>i&&!f.warned){f.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+f.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=f.length,vf(u)}return e}K.prototype.addListener=function(t,r){return ss(this,t,r,!1)};K.prototype.on=K.prototype.addListener;K.prototype.prependListener=function(t,r){return ss(this,t,r,!0)};function Ef(){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 os(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},i=Ef.bind(n);return i.listener=r,n.wrapFn=i,i}K.prototype.once=function(t,r){return Br(r),this.on(t,os(this,t,r)),this};K.prototype.prependOnceListener=function(t,r){return Br(r),this.prependListener(t,os(this,t,r)),this};K.prototype.removeListener=function(t,r){var n,i,a,f,u;if(Br(r),i=this._events,i===void 0)return this;if(n=i[t],n===void 0)return this;if(n===r||n.listener===r)--this._eventsCount===0?this._events=Object.create(null):(delete i[t],i.removeListener&&this.emit("removeListener",t,n.listener||r));else if(typeof n!="function"){for(a=-1,f=n.length-1;f>=0;f--)if(n[f]===r||n[f].listener===r){u=n[f].listener,a=f;break}if(a<0)return this;a===0?n.shift():Bf(n,a),n.length===1&&(i[t]=n[0]),i.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,i;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 a=Object.keys(n),f;for(i=0;i<a.length;++i)f=a[i],f!=="removeListener"&&this.removeAllListeners(f);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(i=r.length-1;i>=0;i--)this.removeListener(t,r[i]);return this};function as(e,t,r){var n=e._events;if(n===void 0)return[];var i=n[t];return i===void 0?[]:typeof i=="function"?r?[i.listener||i]:[i]:r?Sf(i):us(i,i.length)}K.prototype.listeners=function(t){return as(this,t,!0)};K.prototype.rawListeners=function(t){return as(this,t,!1)};K.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):fs.call(e,t)};K.prototype.listenerCount=fs;function fs(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?fr(this._events):[]};function us(e,t){for(var r=new Array(t),n=0;n<t;++n)r[n]=e[n];return r}function Bf(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function Sf(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}function Af(e,t){return new Promise(function(r,n){function i(f){e.removeListener(t,a),n(f)}function a(){typeof e.removeListener=="function"&&e.removeListener("error",i),r([].slice.call(arguments))}cs(e,t,a,{once:!0}),t!=="error"&&If(e,i,{once:!0})})}function If(e,t,r){typeof e.on=="function"&&cs(e,"error",t,r)}function cs(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 i(a){n.once&&e.removeEventListener(t,i),r(a)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e)}var ls=An.exports,hs=ls.EventEmitter;const Rf={},Tf=Object.freeze(Object.defineProperty({__proto__:null,default:Rf},Symbol.toStringTag,{value:"Module"})),In=ef(Tf);var Hr,Kn;function kf(){if(Kn)return Hr;Kn=1;function e(B,P){var T=Object.keys(B);if(Object.getOwnPropertySymbols){var C=Object.getOwnPropertySymbols(B);P&&(C=C.filter(function(F){return Object.getOwnPropertyDescriptor(B,F).enumerable})),T.push.apply(T,C)}return T}function t(B){for(var P=1;P<arguments.length;P++){var T=arguments[P]!=null?arguments[P]:{};P%2?e(Object(T),!0).forEach(function(C){r(B,C,T[C])}):Object.getOwnPropertyDescriptors?Object.defineProperties(B,Object.getOwnPropertyDescriptors(T)):e(Object(T)).forEach(function(C){Object.defineProperty(B,C,Object.getOwnPropertyDescriptor(T,C))})}return B}function r(B,P,T){return P=f(P),P in B?Object.defineProperty(B,P,{value:T,enumerable:!0,configurable:!0,writable:!0}):B[P]=T,B}function n(B,P){if(!(B instanceof P))throw new TypeError("Cannot call a class as a function")}function i(B,P){for(var T=0;T<P.length;T++){var C=P[T];C.enumerable=C.enumerable||!1,C.configurable=!0,"value"in C&&(C.writable=!0),Object.defineProperty(B,f(C.key),C)}}function a(B,P,T){return P&&i(B.prototype,P),Object.defineProperty(B,"prototype",{writable:!1}),B}function f(B){var P=u(B,"string");return typeof P=="symbol"?P:String(P)}function u(B,P){if(typeof B!="object"||B===null)return B;var T=B[Symbol.toPrimitive];if(T!==void 0){var C=T.call(B,P||"default");if(typeof C!="object")return C;throw new TypeError("@@toPrimitive must return a primitive value.")}return(P==="string"?String:Number)(B)}var l=kt,b=l.Buffer,g=In,m=g.inspect,v=m&&m.custom||"inspect";function A(B,P,T){b.prototype.copy.call(B,P,T)}return Hr=function(){function B(){n(this,B),this.head=null,this.tail=null,this.length=0}return a(B,[{key:"push",value:function(T){var C={data:T,next:null};this.length>0?this.tail.next=C:this.head=C,this.tail=C,++this.length}},{key:"unshift",value:function(T){var C={data:T,next:this.head};this.length===0&&(this.tail=C),this.head=C,++this.length}},{key:"shift",value:function(){if(this.length!==0){var T=this.head.data;return this.length===1?this.head=this.tail=null:this.head=this.head.next,--this.length,T}}},{key:"clear",value:function(){this.head=this.tail=null,this.length=0}},{key:"join",value:function(T){if(this.length===0)return"";for(var C=this.head,F=""+C.data;C=C.next;)F+=T+C.data;return F}},{key:"concat",value:function(T){if(this.length===0)return b.alloc(0);for(var C=b.allocUnsafe(T>>>0),F=this.head,O=0;F;)A(F.data,C,O),O+=F.data.length,F=F.next;return C}},{key:"consume",value:function(T,C){var F;return T<this.head.data.length?(F=this.head.data.slice(0,T),this.head.data=this.head.data.slice(T)):T===this.head.data.length?F=this.shift():F=C?this._getString(T):this._getBuffer(T),F}},{key:"first",value:function(){return this.head.data}},{key:"_getString",value:function(T){var C=this.head,F=1,O=C.data;for(T-=O.length;C=C.next;){var L=C.data,U=T>L.length?L.length:T;if(U===L.length?O+=L:O+=L.slice(0,T),T-=U,T===0){U===L.length?(++F,C.next?this.head=C.next:this.head=this.tail=null):(this.head=C,C.data=L.slice(U));break}++F}return this.length-=F,O}},{key:"_getBuffer",value:function(T){var C=b.allocUnsafe(T),F=this.head,O=1;for(F.data.copy(C),T-=F.data.length;F=F.next;){var L=F.data,U=T>L.length?L.length:T;if(L.copy(C,C.length-T,0,U),T-=U,T===0){U===L.length?(++O,F.next?this.head=F.next:this.head=this.tail=null):(this.head=F,F.data=L.slice(U));break}++O}return this.length-=O,C}},{key:v,value:function(T,C){return m(this,t(t({},C),{},{depth:0,customInspect:!1}))}}]),B}(),Hr}function Pf(e,t){var r=this,n=this._readableState&&this._readableState.destroyed,i=this._writableState&&this._writableState.destroyed;return n||i?(t?t(e):e&&(this._writableState?this._writableState.errorEmitted||(this._writableState.errorEmitted=!0,process.nextTick(an,this,e)):process.nextTick(an,this,e)),this):(this._readableState&&(this._readableState.destroyed=!0),this._writableState&&(this._writableState.destroyed=!0),this._destroy(e||null,function(a){!t&&a?r._writableState?r._writableState.errorEmitted?process.nextTick(ur,r):(r._writableState.errorEmitted=!0,process.nextTick(Yn,r,a)):process.nextTick(Yn,r,a):t?(process.nextTick(ur,r),t(a)):process.nextTick(ur,r)}),this)}function Yn(e,t){an(e,t),ur(e)}function ur(e){e._writableState&&!e._writableState.emitClose||e._readableState&&!e._readableState.emitClose||e.emit("close")}function Cf(){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 an(e,t){e.emit("error",t)}function Lf(e,t){var r=e._readableState,n=e._writableState;r&&r.autoDestroy||n&&n.autoDestroy?e.destroy(t):e.emit("error",t)}var ds={destroy:Pf,undestroy:Cf,errorOrDestroy:Lf},pt={};function Of(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var ps={};function Te(e,t,r){r||(r=Error);function n(a,f,u){return typeof t=="string"?t:t(a,f,u)}var i=function(a){Of(f,a);function f(u,l,b){return a.call(this,n(u,l,b))||this}return f}(r);i.prototype.name=r.name,i.prototype.code=e,ps[e]=i}function Jn(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 Ff(e,t,r){return e.substr(0,t.length)===t}function Uf(e,t,r){return(r===void 0||r>e.length)&&(r=e.length),e.substring(r-t.length,r)===t}function Nf(e,t,r){return typeof r!="number"&&(r=0),r+t.length>e.length?!1:e.indexOf(t,r)!==-1}Te("ERR_INVALID_OPT_VALUE",function(e,t){return'The value "'+t+'" is invalid for option "'+e+'"'},TypeError);Te("ERR_INVALID_ARG_TYPE",function(e,t,r){var n;typeof t=="string"&&Ff(t,"not ")?(n="must not be",t=t.replace(/^not /,"")):n="must be";var i;if(Uf(e," argument"))i="The ".concat(e," ").concat(n," ").concat(Jn(t,"type"));else{var a=Nf(e,".")?"property":"argument";i='The "'.concat(e,'" ').concat(a," ").concat(n," ").concat(Jn(t,"type"))}return i+=". Received type ".concat(typeof r),i},TypeError);Te("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF");Te("ERR_METHOD_NOT_IMPLEMENTED",function(e){return"The "+e+" method is not implemented"});Te("ERR_STREAM_PREMATURE_CLOSE","Premature close");Te("ERR_STREAM_DESTROYED",function(e){return"Cannot call "+e+" after a stream was destroyed"});Te("ERR_MULTIPLE_CALLBACK","Callback called multiple times");Te("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable");Te("ERR_STREAM_WRITE_AFTER_END","write after end");Te("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError);Te("ERR_UNKNOWN_ENCODING",function(e){return"Unknown encoding: "+e},TypeError);Te("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event");pt.codes=ps;var Mf=pt.codes.ERR_INVALID_OPT_VALUE;function Df(e,t,r){return e.highWaterMark!=null?e.highWaterMark:t?e[r]:null}function $f(e,t,r,n){var i=Df(t,n,r);if(i!=null){if(!(isFinite(i)&&Math.floor(i)===i)||i<0){var a=n?r:"highWaterMark";throw new Mf(a,i)}return Math.floor(i)}return e.objectMode?16:16*1024}var bs={getHighWaterMark:$f},Hf=zf;function zf(e,t){if(zr("noDeprecation"))return e;var r=!1;function n(){if(!r){if(zr("throwDeprecation"))throw new Error(t);zr("traceDeprecation")?console.trace(t):console.warn(t),r=!0}return e.apply(this,arguments)}return n}function zr(e){try{if(!Qe.localStorage)return!1}catch{return!1}var t=Qe.localStorage[e];return t==null?!1:String(t).toLowerCase()==="true"}var Gr,Xn;function ys(){if(Xn)return Gr;Xn=1,Gr=M;function e(w){var _=this;this.next=null,this.entry=null,this.finish=function(){Ne(_,w)}}var t;M.WritableState=S;var r={deprecate:Hf},n=hs,i=kt.Buffer,a=(typeof Qe<"u"?Qe:typeof window<"u"?window:typeof self<"u"?self:{}).Uint8Array||function(){};function f(w){return i.from(w)}function u(w){return i.isBuffer(w)||w instanceof a}var l=ds,b=bs,g=b.getHighWaterMark,m=pt.codes,v=m.ERR_INVALID_ARG_TYPE,A=m.ERR_METHOD_NOT_IMPLEMENTED,B=m.ERR_MULTIPLE_CALLBACK,P=m.ERR_STREAM_CANNOT_PIPE,T=m.ERR_STREAM_DESTROYED,C=m.ERR_STREAM_NULL_VALUES,F=m.ERR_STREAM_WRITE_AFTER_END,O=m.ERR_UNKNOWN_ENCODING,L=l.errorOrDestroy;de(M,n);function U(){}function S(w,_,R){t=t||It(),w=w||{},typeof R!="boolean"&&(R=_ instanceof t),this.objectMode=!!w.objectMode,R&&(this.objectMode=this.objectMode||!!w.writableObjectMode),this.highWaterMark=g(this,w,"writableHighWaterMark",R),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var D=w.decodeStrings===!1;this.decodeStrings=!D,this.defaultEncoding=w.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(G){rt(_,G)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=w.emitClose!==!1,this.autoDestroy=!!w.autoDestroy,this.bufferedRequestCount=0,this.corkedRequestsFree=new e(this)}S.prototype.getBuffer=function(){for(var _=this.bufferedRequest,R=[];_;)R.push(_),_=_.next;return R},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 z;typeof Symbol=="function"&&Symbol.hasInstance&&typeof Function.prototype[Symbol.hasInstance]=="function"?(z=Function.prototype[Symbol.hasInstance],Object.defineProperty(M,Symbol.hasInstance,{value:function(_){return z.call(this,_)?!0:this!==M?!1:_&&_._writableState instanceof S}})):z=function(_){return _ instanceof this};function M(w){t=t||It();var _=this instanceof t;if(!_&&!z.call(M,this))return new M(w);this._writableState=new S(w,this,_),this.writable=!0,w&&(typeof w.write=="function"&&(this._write=w.write),typeof w.writev=="function"&&(this._writev=w.writev),typeof w.destroy=="function"&&(this._destroy=w.destroy),typeof w.final=="function"&&(this._final=w.final)),n.call(this)}M.prototype.pipe=function(){L(this,new P)};function $(w,_){var R=new F;L(w,R),process.nextTick(_,R)}function ae(w,_,R,D){var G;return R===null?G=new C:typeof R!="string"&&!_.objectMode&&(G=new v("chunk",["string","Buffer"],R)),G?(L(w,G),process.nextTick(D,G),!1):!0}M.prototype.write=function(w,_,R){var D=this._writableState,G=!1,d=!D.objectMode&&u(w);return d&&!i.isBuffer(w)&&(w=f(w)),typeof _=="function"&&(R=_,_=null),d?_="buffer":_||(_=D.defaultEncoding),typeof R!="function"&&(R=U),D.ending?$(this,R):(d||ae(this,D,w,R))&&(D.pendingcb++,G=je(this,D,d,w,_,R)),G},M.prototype.cork=function(){this._writableState.corked++},M.prototype.uncork=function(){var w=this._writableState;w.corked&&(w.corked--,!w.writing&&!w.corked&&!w.bufferProcessing&&w.bufferedRequest&&Ce(this,w))},M.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 O(_);return this._writableState.defaultEncoding=_,this},Object.defineProperty(M.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}});function ke(w,_,R){return!w.objectMode&&w.decodeStrings!==!1&&typeof _=="string"&&(_=i.from(_,R)),_}Object.defineProperty(M.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}});function je(w,_,R,D,G,d){if(!R){var p=ke(_,D,G);D!==p&&(R=!0,G="buffer",D=p)}var I=_.objectMode?1:D.length;_.length+=I;var N=_.length<_.highWaterMark;if(N||(_.needDrain=!0),_.writing||_.corked){var te=_.lastBufferedRequest;_.lastBufferedRequest={chunk:D,encoding:G,isBuf:R,callback:d,next:null},te?te.next=_.lastBufferedRequest:_.bufferedRequest=_.lastBufferedRequest,_.bufferedRequestCount+=1}else ue(w,_,!1,I,D,G,d);return N}function ue(w,_,R,D,G,d,p){_.writelen=D,_.writecb=p,_.writing=!0,_.sync=!0,_.destroyed?_.onwrite(new T("write")):R?w._writev(G,_.onwrite):w._write(G,d,_.onwrite),_.sync=!1}function Ee(w,_,R,D,G){--_.pendingcb,R?(process.nextTick(G,D),process.nextTick(Se,w,_),w._writableState.errorEmitted=!0,L(w,D)):(G(D),w._writableState.errorEmitted=!0,L(w,D),Se(w,_))}function Be(w){w.writing=!1,w.writecb=null,w.length-=w.writelen,w.writelen=0}function rt(w,_){var R=w._writableState,D=R.sync,G=R.writecb;if(typeof G!="function")throw new B;if(Be(R),_)Ee(w,R,D,_,G);else{var d=qe(R)||w.destroyed;!d&&!R.corked&&!R.bufferProcessing&&R.bufferedRequest&&Ce(w,R),D?process.nextTick(Pe,w,R,d,G):Pe(w,R,d,G)}}function Pe(w,_,R,D){R||We(w,_),_.pendingcb--,D(),Se(w,_)}function We(w,_){_.length===0&&_.needDrain&&(_.needDrain=!1,w.emit("drain"))}function Ce(w,_){_.bufferProcessing=!0;var R=_.bufferedRequest;if(w._writev&&R&&R.next){var D=_.bufferedRequestCount,G=new Array(D),d=_.corkedRequestsFree;d.entry=R;for(var p=0,I=!0;R;)G[p]=R,R.isBuf||(I=!1),R=R.next,p+=1;G.allBuffers=I,ue(w,_,!0,_.length,G,"",d.finish),_.pendingcb++,_.lastBufferedRequest=null,d.next?(_.corkedRequestsFree=d.next,d.next=null):_.corkedRequestsFree=new e(_),_.bufferedRequestCount=0}else{for(;R;){var N=R.chunk,te=R.encoding,j=R.callback,V=_.objectMode?1:N.length;if(ue(w,_,!1,V,N,te,j),R=R.next,_.bufferedRequestCount--,_.writing)break}R===null&&(_.lastBufferedRequest=null)}_.bufferedRequest=R,_.bufferProcessing=!1}M.prototype._write=function(w,_,R){R(new A("_write()"))},M.prototype._writev=null,M.prototype.end=function(w,_,R){var D=this._writableState;return typeof w=="function"?(R=w,w=null,_=null):typeof _=="function"&&(R=_,_=null),w!=null&&this.write(w,_),D.corked&&(D.corked=1,this.uncork()),D.ending||Ve(this,D,R),this},Object.defineProperty(M.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}});function qe(w){return w.ending&&w.length===0&&w.bufferedRequest===null&&!w.finished&&!w.writing}function ee(w,_){w._final(function(R){_.pendingcb--,R&&L(w,R),_.prefinished=!0,w.emit("prefinish"),Se(w,_)})}function fe(w,_){!_.prefinished&&!_.finalCalled&&(typeof w._final=="function"&&!_.destroyed?(_.pendingcb++,_.finalCalled=!0,process.nextTick(ee,w,_)):(_.prefinished=!0,w.emit("prefinish")))}function Se(w,_){var R=qe(_);if(R&&(fe(w,_),_.pendingcb===0&&(_.finished=!0,w.emit("finish"),_.autoDestroy))){var D=w._readableState;(!D||D.autoDestroy&&D.endEmitted)&&w.destroy()}return R}function Ve(w,_,R){_.ending=!0,Se(w,_),R&&(_.finished?process.nextTick(R):w.once("finish",R)),_.ended=!0,w.writable=!1}function Ne(w,_,R){var D=w.entry;for(w.entry=null;D;){var G=D.callback;_.pendingcb--,G(R),D=D.next}_.corkedRequestsFree.next=w}return Object.defineProperty(M.prototype,"destroyed",{enumerable:!1,get:function(){return this._writableState===void 0?!1:this._writableState.destroyed},set:function(_){this._writableState&&(this._writableState.destroyed=_)}}),M.prototype.destroy=l.destroy,M.prototype._undestroy=l.undestroy,M.prototype._destroy=function(w,_){_(w)},Gr}var jr,Qn;function It(){if(Qn)return jr;Qn=1;var e=Object.keys||function(b){var g=[];for(var m in b)g.push(m);return g};jr=f;var t=ms(),r=ys();de(f,t);for(var n=e(r.prototype),i=0;i<n.length;i++){var a=n[i];f.prototype[a]||(f.prototype[a]=r.prototype[a])}function f(b){if(!(this instanceof f))return new f(b);t.call(this,b),r.call(this,b),this.allowHalfOpen=!0,b&&(b.readable===!1&&(this.readable=!1),b.writable===!1&&(this.writable=!1),b.allowHalfOpen===!1&&(this.allowHalfOpen=!1,this.once("end",u)))}Object.defineProperty(f.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),Object.defineProperty(f.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(f.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}});function u(){this._writableState.ended||process.nextTick(l,this)}function l(b){b.end()}return Object.defineProperty(f.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)}}),jr}var yr={},Rn=ve.Buffer,Zn=Rn.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 Gf(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 jf(e){var t=Gf(e);if(typeof t!="string"&&(Rn.isEncoding===Zn||!Zn(e)))throw new Error("Unknown encoding: "+e);return t||e}yr.StringDecoder=Zt;function Zt(e){this.encoding=jf(e);var t;switch(this.encoding){case"utf16le":this.text=Jf,this.end=Xf,t=4;break;case"utf8":this.fillLast=Vf,t=4;break;case"base64":this.text=Qf,this.end=Zf,t=3;break;default:this.write=eu,this.end=tu;return}this.lastNeed=0,this.lastTotal=0,this.lastChar=Rn.allocUnsafe(t)}Zt.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||""};Zt.prototype.end=Yf;Zt.prototype.text=Kf;Zt.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 Wr(e){return e<=127?0:e>>5===6?2:e>>4===14?3:e>>3===30?4:e>>6===2?-1:-2}function Wf(e,t,r){var n=t.length-1;if(n<r)return 0;var i=Wr(t[n]);return i>=0?(i>0&&(e.lastNeed=i-1),i):--n<r||i===-2?0:(i=Wr(t[n]),i>=0?(i>0&&(e.lastNeed=i-2),i):--n<r||i===-2?0:(i=Wr(t[n]),i>=0?(i>0&&(i===2?i=0:e.lastNeed=i-3),i):0))}function qf(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 Vf(e){var t=this.lastTotal-this.lastNeed,r=qf(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 Kf(e,t){var r=Wf(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 Yf(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+"�":t}function Jf(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 Xf(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 Qf(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 Zf(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+this.lastChar.toString("base64",0,3-this.lastNeed):t}function eu(e){return e.toString(this.encoding)}function tu(e){return e&&e.length?this.write(e):""}var ei=pt.codes.ERR_STREAM_PREMATURE_CLOSE;function ru(e){var t=!1;return function(){if(!t){t=!0;for(var r=arguments.length,n=new Array(r),i=0;i<r;i++)n[i]=arguments[i];e.apply(this,n)}}}function nu(){}function iu(e){return e.setHeader&&typeof e.abort=="function"}function gs(e,t,r){if(typeof t=="function")return gs(e,null,t);t||(t={}),r=ru(r||nu);var n=t.readable||t.readable!==!1&&e.readable,i=t.writable||t.writable!==!1&&e.writable,a=function(){e.writable||u()},f=e._writableState&&e._writableState.finished,u=function(){i=!1,f=!0,n||r.call(e)},l=e._readableState&&e._readableState.endEmitted,b=function(){n=!1,l=!0,i||r.call(e)},g=function(B){r.call(e,B)},m=function(){var B;if(n&&!l)return(!e._readableState||!e._readableState.ended)&&(B=new ei),r.call(e,B);if(i&&!f)return(!e._writableState||!e._writableState.ended)&&(B=new ei),r.call(e,B)},v=function(){e.req.on("finish",u)};return iu(e)?(e.on("complete",u),e.on("abort",m),e.req?v():e.on("request",v)):i&&!e._writableState&&(e.on("end",a),e.on("close",a)),e.on("end",b),e.on("finish",u),t.error!==!1&&e.on("error",g),e.on("close",m),function(){e.removeListener("complete",u),e.removeListener("abort",m),e.removeListener("request",v),e.req&&e.req.removeListener("finish",u),e.removeListener("end",a),e.removeListener("close",a),e.removeListener("finish",u),e.removeListener("end",b),e.removeListener("error",g),e.removeListener("close",m)}}var Tn=gs,qr,ti;function su(){if(ti)return qr;ti=1;var e;function t(O,L,U){return L=r(L),L in O?Object.defineProperty(O,L,{value:U,enumerable:!0,configurable:!0,writable:!0}):O[L]=U,O}function r(O){var L=n(O,"string");return typeof L=="symbol"?L:String(L)}function n(O,L){if(typeof O!="object"||O===null)return O;var U=O[Symbol.toPrimitive];if(U!==void 0){var S=U.call(O,L||"default");if(typeof S!="object")return S;throw new TypeError("@@toPrimitive must return a primitive value.")}return(L==="string"?String:Number)(O)}var i=Tn,a=Symbol("lastResolve"),f=Symbol("lastReject"),u=Symbol("error"),l=Symbol("ended"),b=Symbol("lastPromise"),g=Symbol("handlePromise"),m=Symbol("stream");function v(O,L){return{value:O,done:L}}function A(O){var L=O[a];if(L!==null){var U=O[m].read();U!==null&&(O[b]=null,O[a]=null,O[f]=null,L(v(U,!1)))}}function B(O){process.nextTick(A,O)}function P(O,L){return function(U,S){O.then(function(){if(L[l]){U(v(void 0,!0));return}L[g](U,S)},S)}}var T=Object.getPrototypeOf(function(){}),C=Object.setPrototypeOf((e={get stream(){return this[m]},next:function(){var L=this,U=this[u];if(U!==null)return Promise.reject(U);if(this[l])return Promise.resolve(v(void 0,!0));if(this[m].destroyed)return new Promise(function($,ae){process.nextTick(function(){L[u]?ae(L[u]):$(v(void 0,!0))})});var S=this[b],z;if(S)z=new Promise(P(S,this));else{var M=this[m].read();if(M!==null)return Promise.resolve(v(M,!1));z=new Promise(this[g])}return this[b]=z,z}},t(e,Symbol.asyncIterator,function(){return this}),t(e,"return",function(){var L=this;return new Promise(function(U,S){L[m].destroy(null,function(z){if(z){S(z);return}U(v(void 0,!0))})})}),e),T),F=function(L){var U,S=Object.create(C,(U={},t(U,m,{value:L,writable:!0}),t(U,a,{value:null,writable:!0}),t(U,f,{value:null,writable:!0}),t(U,u,{value:null,writable:!0}),t(U,l,{value:L._readableState.endEmitted,writable:!0}),t(U,g,{value:function(M,$){var ae=S[m].read();ae?(S[b]=null,S[a]=null,S[f]=null,M(v(ae,!1))):(S[a]=M,S[f]=$)},writable:!0}),U));return S[b]=null,i(L,function(z){if(z&&z.code!=="ERR_STREAM_PREMATURE_CLOSE"){var M=S[f];M!==null&&(S[b]=null,S[a]=null,S[f]=null,M(z)),S[u]=z;return}var $=S[a];$!==null&&(S[b]=null,S[a]=null,S[f]=null,$(v(void 0,!0))),S[l]=!0}),L.on("readable",B.bind(null,S)),S};return qr=F,qr}var Vr,ri;function ou(){return ri||(ri=1,Vr=function(){throw new Error("Readable.from is not available in the browser")}),Vr}var Kr,ni;function ms(){if(ni)return Kr;ni=1,Kr=$;var e;$.ReadableState=M,ls.EventEmitter;var t=function(p,I){return p.listeners(I).length},r=hs,n=kt.Buffer,i=(typeof Qe<"u"?Qe:typeof window<"u"?window:typeof self<"u"?self:{}).Uint8Array||function(){};function a(d){return n.from(d)}function f(d){return n.isBuffer(d)||d instanceof i}var u=In,l;u&&u.debuglog?l=u.debuglog("stream"):l=function(){};var b=kf(),g=ds,m=bs,v=m.getHighWaterMark,A=pt.codes,B=A.ERR_INVALID_ARG_TYPE,P=A.ERR_STREAM_PUSH_AFTER_EOF,T=A.ERR_METHOD_NOT_IMPLEMENTED,C=A.ERR_STREAM_UNSHIFT_AFTER_END_EVENT,F,O,L;de($,r);var U=g.errorOrDestroy,S=["error","close","destroy","pause","resume"];function z(d,p,I){if(typeof d.prependListener=="function")return d.prependListener(p,I);!d._events||!d._events[p]?d.on(p,I):Array.isArray(d._events[p])?d._events[p].unshift(I):d._events[p]=[I,d._events[p]]}function M(d,p,I){e=e||It(),d=d||{},typeof I!="boolean"&&(I=p instanceof e),this.objectMode=!!d.objectMode,I&&(this.objectMode=this.objectMode||!!d.readableObjectMode),this.highWaterMark=v(this,d,"readableHighWaterMark",I),this.buffer=new b,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=d.emitClose!==!1,this.autoDestroy=!!d.autoDestroy,this.destroyed=!1,this.defaultEncoding=d.defaultEncoding||"utf8",this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,d.encoding&&(F||(F=yr.StringDecoder),this.decoder=new F(d.encoding),this.encoding=d.encoding)}function $(d){if(e=e||It(),!(this instanceof $))return new $(d);var p=this instanceof e;this._readableState=new M(d,this,p),this.readable=!0,d&&(typeof d.read=="function"&&(this._read=d.read),typeof d.destroy=="function"&&(this._destroy=d.destroy)),r.call(this)}Object.defineProperty($.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState===void 0?!1:this._readableState.destroyed},set:function(p){this._readableState&&(this._readableState.destroyed=p)}}),$.prototype.destroy=g.destroy,$.prototype._undestroy=g.undestroy,$.prototype._destroy=function(d,p){p(d)},$.prototype.push=function(d,p){var I=this._readableState,N;return I.objectMode?N=!0:typeof d=="string"&&(p=p||I.defaultEncoding,p!==I.encoding&&(d=n.from(d,p),p=""),N=!0),ae(this,d,p,!1,N)},$.prototype.unshift=function(d){return ae(this,d,null,!0,!1)};function ae(d,p,I,N,te){l("readableAddChunk",p);var j=d._readableState;if(p===null)j.reading=!1,rt(d,j);else{var V;if(te||(V=je(j,p)),V)U(d,V);else if(j.objectMode||p&&p.length>0)if(typeof p!="string"&&!j.objectMode&&Object.getPrototypeOf(p)!==n.prototype&&(p=a(p)),N)j.endEmitted?U(d,new C):ke(d,j,p,!0);else if(j.ended)U(d,new P);else{if(j.destroyed)return!1;j.reading=!1,j.decoder&&!I?(p=j.decoder.write(p),j.objectMode||p.length!==0?ke(d,j,p,!1):Ce(d,j)):ke(d,j,p,!1)}else N||(j.reading=!1,Ce(d,j))}return!j.ended&&(j.length<j.highWaterMark||j.length===0)}function ke(d,p,I,N){p.flowing&&p.length===0&&!p.sync?(p.awaitDrain=0,d.emit("data",I)):(p.length+=p.objectMode?1:I.length,N?p.buffer.unshift(I):p.buffer.push(I),p.needReadable&&Pe(d)),Ce(d,p)}function je(d,p){var I;return!f(p)&&typeof p!="string"&&p!==void 0&&!d.objectMode&&(I=new B("chunk",["string","Buffer","Uint8Array"],p)),I}$.prototype.isPaused=function(){return this._readableState.flowing===!1},$.prototype.setEncoding=function(d){F||(F=yr.StringDecoder);var p=new F(d);this._readableState.decoder=p,this._readableState.encoding=this._readableState.decoder.encoding;for(var I=this._readableState.buffer.head,N="";I!==null;)N+=p.write(I.data),I=I.next;return this._readableState.buffer.clear(),N!==""&&this._readableState.buffer.push(N),this._readableState.length=N.length,this};var ue=1073741824;function Ee(d){return d>=ue?d=ue:(d--,d|=d>>>1,d|=d>>>2,d|=d>>>4,d|=d>>>8,d|=d>>>16,d++),d}function Be(d,p){return d<=0||p.length===0&&p.ended?0:p.objectMode?1:d!==d?p.flowing&&p.length?p.buffer.head.data.length:p.length:(d>p.highWaterMark&&(p.highWaterMark=Ee(d)),d<=p.length?d:p.ended?p.length:(p.needReadable=!0,0))}$.prototype.read=function(d){l("read",d),d=parseInt(d,10);var p=this._readableState,I=d;if(d!==0&&(p.emittedReadable=!1),d===0&&p.needReadable&&((p.highWaterMark!==0?p.length>=p.highWaterMark:p.length>0)||p.ended))return l("read: emitReadable",p.length,p.ended),p.length===0&&p.ended?R(this):Pe(this),null;if(d=Be(d,p),d===0&&p.ended)return p.length===0&&R(this),null;var N=p.needReadable;l("need readable",N),(p.length===0||p.length-d<p.highWaterMark)&&(N=!0,l("length less than watermark",N)),p.ended||p.reading?(N=!1,l("reading or ended",N)):N&&(l("do read"),p.reading=!0,p.sync=!0,p.length===0&&(p.needReadable=!0),this._read(p.highWaterMark),p.sync=!1,p.reading||(d=Be(I,p)));var te;return d>0?te=_(d,p):te=null,te===null?(p.needReadable=p.length<=p.highWaterMark,d=0):(p.length-=d,p.awaitDrain=0),p.length===0&&(p.ended||(p.needReadable=!0),I!==d&&p.ended&&R(this)),te!==null&&this.emit("data",te),te};function rt(d,p){if(l("onEofChunk"),!p.ended){if(p.decoder){var I=p.decoder.end();I&&I.length&&(p.buffer.push(I),p.length+=p.objectMode?1:I.length)}p.ended=!0,p.sync?Pe(d):(p.needReadable=!1,p.emittedReadable||(p.emittedReadable=!0,We(d)))}}function Pe(d){var p=d._readableState;l("emitReadable",p.needReadable,p.emittedReadable),p.needReadable=!1,p.emittedReadable||(l("emitReadable",p.flowing),p.emittedReadable=!0,process.nextTick(We,d))}function We(d){var p=d._readableState;l("emitReadable_",p.destroyed,p.length,p.ended),!p.destroyed&&(p.length||p.ended)&&(d.emit("readable"),p.emittedReadable=!1),p.needReadable=!p.flowing&&!p.ended&&p.length<=p.highWaterMark,w(d)}function Ce(d,p){p.readingMore||(p.readingMore=!0,process.nextTick(qe,d,p))}function qe(d,p){for(;!p.reading&&!p.ended&&(p.length<p.highWaterMark||p.flowing&&p.length===0);){var I=p.length;if(l("maybeReadMore read 0"),d.read(0),I===p.length)break}p.readingMore=!1}$.prototype._read=function(d){U(this,new T("_read()"))},$.prototype.pipe=function(d,p){var I=this,N=this._readableState;switch(N.pipesCount){case 0:N.pipes=d;break;case 1:N.pipes=[N.pipes,d];break;default:N.pipes.push(d);break}N.pipesCount+=1,l("pipe count=%d opts=%j",N.pipesCount,p);var te=(!p||p.end!==!1)&&d!==process.stdout&&d!==process.stderr,j=te?Ke:it;N.endEmitted?process.nextTick(j):I.once("end",j),d.on("unpipe",V);function V(c,s){l("onunpipe"),c===I&&s&&s.hasUnpiped===!1&&(s.hasUnpiped=!0,gt())}function Ke(){l("onend"),d.end()}var yt=ee(I);d.on("drain",yt);var Ct=!1;function gt(){l("cleanup"),d.removeListener("close",Lt),d.removeListener("finish",Ie),d.removeListener("drain",yt),d.removeListener("error",nt),d.removeListener("unpipe",V),I.removeListener("end",Ke),I.removeListener("end",it),I.removeListener("data",Ae),Ct=!0,N.awaitDrain&&(!d._writableState||d._writableState.needDrain)&&yt()}I.on("data",Ae);function Ae(c){l("ondata");var s=d.write(c);l("dest.write",s),s===!1&&((N.pipesCount===1&&N.pipes===d||N.pipesCount>1&&G(N.pipes,d)!==-1)&&!Ct&&(l("false write response, pause",N.awaitDrain),N.awaitDrain++),I.pause())}function nt(c){l("onerror",c),it(),d.removeListener("error",nt),t(d,"error")===0&&U(d,c)}z(d,"error",nt);function Lt(){d.removeListener("finish",Ie),it()}d.once("close",Lt);function Ie(){l("onfinish"),d.removeListener("close",Lt),it()}d.once("finish",Ie);function it(){l("unpipe"),I.unpipe(d)}return d.emit("pipe",I),N.flowing||(l("pipe resume"),I.resume()),d};function ee(d){return function(){var I=d._readableState;l("pipeOnDrain",I.awaitDrain),I.awaitDrain&&I.awaitDrain--,I.awaitDrain===0&&t(d,"data")&&(I.flowing=!0,w(d))}}$.prototype.unpipe=function(d){var p=this._readableState,I={hasUnpiped:!1};if(p.pipesCount===0)return this;if(p.pipesCount===1)return d&&d!==p.pipes?this:(d||(d=p.pipes),p.pipes=null,p.pipesCount=0,p.flowing=!1,d&&d.emit("unpipe",this,I),this);if(!d){var N=p.pipes,te=p.pipesCount;p.pipes=null,p.pipesCount=0,p.flowing=!1;for(var j=0;j<te;j++)N[j].emit("unpipe",this,{hasUnpiped:!1});return this}var V=G(p.pipes,d);return V===-1?this:(p.pipes.splice(V,1),p.pipesCount-=1,p.pipesCount===1&&(p.pipes=p.pipes[0]),d.emit("unpipe",this,I),this)},$.prototype.on=function(d,p){var I=r.prototype.on.call(this,d,p),N=this._readableState;return d==="data"?(N.readableListening=this.listenerCount("readable")>0,N.flowing!==!1&&this.resume()):d==="readable"&&!N.endEmitted&&!N.readableListening&&(N.readableListening=N.needReadable=!0,N.flowing=!1,N.emittedReadable=!1,l("on readable",N.length,N.reading),N.length?Pe(this):N.reading||process.nextTick(Se,this)),I},$.prototype.addListener=$.prototype.on,$.prototype.removeListener=function(d,p){var I=r.prototype.removeListener.call(this,d,p);return d==="readable"&&process.nextTick(fe,this),I},$.prototype.removeAllListeners=function(d){var p=r.prototype.removeAllListeners.apply(this,arguments);return(d==="readable"||d===void 0)&&process.nextTick(fe,this),p};function fe(d){var p=d._readableState;p.readableListening=d.listenerCount("readable")>0,p.resumeScheduled&&!p.paused?p.flowing=!0:d.listenerCount("data")>0&&d.resume()}function Se(d){l("readable nexttick read 0"),d.read(0)}$.prototype.resume=function(){var d=this._readableState;return d.flowing||(l("resume"),d.flowing=!d.readableListening,Ve(this,d)),d.paused=!1,this};function Ve(d,p){p.resumeScheduled||(p.resumeScheduled=!0,process.nextTick(Ne,d,p))}function Ne(d,p){l("resume",p.reading),p.reading||d.read(0),p.resumeScheduled=!1,d.emit("resume"),w(d),p.flowing&&!p.reading&&d.read(0)}$.prototype.pause=function(){return l("call pause flowing=%j",this._readableState.flowing),this._readableState.flowing!==!1&&(l("pause"),this._readableState.flowing=!1,this.emit("pause")),this._readableState.paused=!0,this};function w(d){var p=d._readableState;for(l("flow",p.flowing);p.flowing&&d.read()!==null;);}$.prototype.wrap=function(d){var p=this,I=this._readableState,N=!1;d.on("end",function(){if(l("wrapped end"),I.decoder&&!I.ended){var V=I.decoder.end();V&&V.length&&p.push(V)}p.push(null)}),d.on("data",function(V){if(l("wrapped data"),I.decoder&&(V=I.decoder.write(V)),!(I.objectMode&&V==null)&&!(!I.objectMode&&(!V||!V.length))){var Ke=p.push(V);Ke||(N=!0,d.pause())}});for(var te in d)this[te]===void 0&&typeof d[te]=="function"&&(this[te]=function(Ke){return function(){return d[Ke].apply(d,arguments)}}(te));for(var j=0;j<S.length;j++)d.on(S[j],this.emit.bind(this,S[j]));return this._read=function(V){l("wrapped _read",V),N&&(N=!1,d.resume())},this},typeof Symbol=="function"&&($.prototype[Symbol.asyncIterator]=function(){return O===void 0&&(O=su()),O(this)}),Object.defineProperty($.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}}),Object.defineProperty($.prototype,"readableBuffer",{enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}}),Object.defineProperty($.prototype,"readableFlowing",{enumerable:!1,get:function(){return this._readableState.flowing},set:function(p){this._readableState&&(this._readableState.flowing=p)}}),$._fromList=_,Object.defineProperty($.prototype,"readableLength",{enumerable:!1,get:function(){return this._readableState.length}});function _(d,p){if(p.length===0)return null;var I;return p.objectMode?I=p.buffer.shift():!d||d>=p.length?(p.decoder?I=p.buffer.join(""):p.buffer.length===1?I=p.buffer.first():I=p.buffer.concat(p.length),p.buffer.clear()):I=p.buffer.consume(d,p.decoder),I}function R(d){var p=d._readableState;l("endReadable",p.endEmitted),p.endEmitted||(p.ended=!0,process.nextTick(D,p,d))}function D(d,p){if(l("endReadableNT",d.endEmitted,d.length),!d.endEmitted&&d.length===0&&(d.endEmitted=!0,p.readable=!1,p.emit("end"),d.autoDestroy)){var I=p._writableState;(!I||I.autoDestroy&&I.finished)&&p.destroy()}}typeof Symbol=="function"&&($.from=function(d,p){return L===void 0&&(L=ou()),L($,d,p)});function G(d,p){for(var I=0,N=d.length;I<N;I++)if(d[I]===p)return I;return-1}return Kr}var _s=Ge,Sr=pt.codes,au=Sr.ERR_METHOD_NOT_IMPLEMENTED,fu=Sr.ERR_MULTIPLE_CALLBACK,uu=Sr.ERR_TRANSFORM_ALREADY_TRANSFORMING,cu=Sr.ERR_TRANSFORM_WITH_LENGTH_0,Ar=It();de(Ge,Ar);function lu(e,t){var r=this._transformState;r.transforming=!1;var n=r.writecb;if(n===null)return this.emit("error",new fu);r.writechunk=null,r.writecb=null,t!=null&&this.push(t),n(e);var i=this._readableState;i.reading=!1,(i.needReadable||i.length<i.highWaterMark)&&this._read(i.highWaterMark)}function Ge(e){if(!(this instanceof Ge))return new Ge(e);Ar.call(this,e),this._transformState={afterTransform:lu.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",hu)}function hu(){var e=this;typeof this._flush=="function"&&!this._readableState.destroyed?this._flush(function(t,r){ii(e,t,r)}):ii(this,null,null)}Ge.prototype.push=function(e,t){return this._transformState.needTransform=!1,Ar.prototype.push.call(this,e,t)};Ge.prototype._transform=function(e,t,r){r(new au("_transform()"))};Ge.prototype._write=function(e,t,r){var n=this._transformState;if(n.writecb=r,n.writechunk=e,n.writeencoding=t,!n.transforming){var i=this._readableState;(n.needTransform||i.needReadable||i.length<i.highWaterMark)&&this._read(i.highWaterMark)}};Ge.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};Ge.prototype._destroy=function(e,t){Ar.prototype._destroy.call(this,e,function(r){t(r)})};function ii(e,t,r){if(t)return e.emit("error",t);if(r!=null&&e.push(r),e._writableState.length)throw new cu;if(e._transformState.transforming)throw new uu;return e.push(null)}var du=Kt,ws=_s;de(Kt,ws);function Kt(e){if(!(this instanceof Kt))return new Kt(e);ws.call(this,e)}Kt.prototype._transform=function(e,t,r){r(null,e)};var Yr;function pu(e){var t=!1;return function(){t||(t=!0,e.apply(void 0,arguments))}}var xs=pt.codes,bu=xs.ERR_MISSING_ARGS,yu=xs.ERR_STREAM_DESTROYED;function si(e){if(e)throw e}function gu(e){return e.setHeader&&typeof e.abort=="function"}function mu(e,t,r,n){n=pu(n);var i=!1;e.on("close",function(){i=!0}),Yr===void 0&&(Yr=Tn),Yr(e,{readable:t,writable:r},function(f){if(f)return n(f);i=!0,n()});var a=!1;return function(f){if(!i&&!a){if(a=!0,gu(e))return e.abort();if(typeof e.destroy=="function")return e.destroy();n(f||new yu("pipe"))}}}function oi(e){e()}function _u(e,t){return e.pipe(t)}function wu(e){return!e.length||typeof e[e.length-1]!="function"?si:e.pop()}function xu(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];var n=wu(t);if(Array.isArray(t[0])&&(t=t[0]),t.length<2)throw new bu("streams");var i,a=t.map(function(f,u){var l=u<t.length-1,b=u>0;return mu(f,l,b,function(g){i||(i=g),g&&a.forEach(oi),!l&&(a.forEach(oi),n(i))})});return t.reduce(_u)}var vu=xu;(function(e,t){t=e.exports=ms(),t.Stream=t,t.Readable=t,t.Writable=ys(),t.Duplex=It(),t.Transform=_s,t.PassThrough=du,t.finished=Tn,t.pipeline=vu})(on,on.exports);var vs=on.exports,gr=ve.Buffer,Es=vs.Transform,Eu=de;function Bu(e,t){if(!gr.isBuffer(e)&&typeof e!="string")throw new TypeError(t+" must be a string or a buffer")}function et(e){Es.call(this),this._block=gr.allocUnsafe(e),this._blockSize=e,this._blockOffset=0,this._length=[0,0,0,0],this._finalized=!1}Eu(et,Es);et.prototype._transform=function(e,t,r){var n=null;try{this.update(e,t)}catch(i){n=i}r(n)};et.prototype._flush=function(e){var t=null;try{this.push(this.digest())}catch(r){t=r}e(t)};et.prototype.update=function(e,t){if(Bu(e,"Data"),this._finalized)throw new Error("Digest already called");gr.isBuffer(e)||(e=gr.from(e,t));for(var r=this._block,n=0;this._blockOffset+e.length-n>=this._blockSize;){for(var i=this._blockOffset;i<this._blockSize;)r[i++]=e[n++];this._update(),this._blockOffset=0}for(;n<e.length;)r[this._blockOffset++]=e[n++];for(var a=0,f=e.length*8;f>0;++a)this._length[a]+=f,f=this._length[a]/4294967296|0,f>0&&(this._length[a]-=4294967296*f);return this};et.prototype._update=function(){throw new Error("_update is not implemented")};et.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};et.prototype._digest=function(){throw new Error("_digest is not implemented")};var Su=et,Au=de,Bs=Su,Iu=ve.Buffer,Ru=new Array(16);function Ir(){Bs.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878}Au(Ir,Bs);Ir.prototype._update=function(){for(var e=Ru,t=0;t<16;++t)e[t]=this._block.readInt32LE(t*4);var r=this._a,n=this._b,i=this._c,a=this._d;r=pe(r,n,i,a,e[0],3614090360,7),a=pe(a,r,n,i,e[1],3905402710,12),i=pe(i,a,r,n,e[2],606105819,17),n=pe(n,i,a,r,e[3],3250441966,22),r=pe(r,n,i,a,e[4],4118548399,7),a=pe(a,r,n,i,e[5],1200080426,12),i=pe(i,a,r,n,e[6],2821735955,17),n=pe(n,i,a,r,e[7],4249261313,22),r=pe(r,n,i,a,e[8],1770035416,7),a=pe(a,r,n,i,e[9],2336552879,12),i=pe(i,a,r,n,e[10],4294925233,17),n=pe(n,i,a,r,e[11],2304563134,22),r=pe(r,n,i,a,e[12],1804603682,7),a=pe(a,r,n,i,e[13],4254626195,12),i=pe(i,a,r,n,e[14],2792965006,17),n=pe(n,i,a,r,e[15],1236535329,22),r=be(r,n,i,a,e[1],4129170786,5),a=be(a,r,n,i,e[6],3225465664,9),i=be(i,a,r,n,e[11],643717713,14),n=be(n,i,a,r,e[0],3921069994,20),r=be(r,n,i,a,e[5],3593408605,5),a=be(a,r,n,i,e[10],38016083,9),i=be(i,a,r,n,e[15],3634488961,14),n=be(n,i,a,r,e[4],3889429448,20),r=be(r,n,i,a,e[9],568446438,5),a=be(a,r,n,i,e[14],3275163606,9),i=be(i,a,r,n,e[3],4107603335,14),n=be(n,i,a,r,e[8],1163531501,20),r=be(r,n,i,a,e[13],2850285829,5),a=be(a,r,n,i,e[2],4243563512,9),i=be(i,a,r,n,e[7],1735328473,14),n=be(n,i,a,r,e[12],2368359562,20),r=ye(r,n,i,a,e[5],4294588738,4),a=ye(a,r,n,i,e[8],2272392833,11),i=ye(i,a,r,n,e[11],1839030562,16),n=ye(n,i,a,r,e[14],4259657740,23),r=ye(r,n,i,a,e[1],2763975236,4),a=ye(a,r,n,i,e[4],1272893353,11),i=ye(i,a,r,n,e[7],4139469664,16),n=ye(n,i,a,r,e[10],3200236656,23),r=ye(r,n,i,a,e[13],681279174,4),a=ye(a,r,n,i,e[0],3936430074,11),i=ye(i,a,r,n,e[3],3572445317,16),n=ye(n,i,a,r,e[6],76029189,23),r=ye(r,n,i,a,e[9],3654602809,4),a=ye(a,r,n,i,e[12],3873151461,11),i=ye(i,a,r,n,e[15],530742520,16),n=ye(n,i,a,r,e[2],3299628645,23),r=ge(r,n,i,a,e[0],4096336452,6),a=ge(a,r,n,i,e[7],1126891415,10),i=ge(i,a,r,n,e[14],2878612391,15),n=ge(n,i,a,r,e[5],4237533241,21),r=ge(r,n,i,a,e[12],1700485571,6),a=ge(a,r,n,i,e[3],2399980690,10),i=ge(i,a,r,n,e[10],4293915773,15),n=ge(n,i,a,r,e[1],2240044497,21),r=ge(r,n,i,a,e[8],1873313359,6),a=ge(a,r,n,i,e[15],4264355552,10),i=ge(i,a,r,n,e[6],2734768916,15),n=ge(n,i,a,r,e[13],1309151649,21),r=ge(r,n,i,a,e[4],4149444226,6),a=ge(a,r,n,i,e[11],3174756917,10),i=ge(i,a,r,n,e[2],718787259,15),n=ge(n,i,a,r,e[9],3951481745,21),this._a=this._a+r|0,this._b=this._b+n|0,this._c=this._c+i|0,this._d=this._d+a|0};Ir.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=Iu.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 Rr(e,t){return e<<t|e>>>32-t}function pe(e,t,r,n,i,a,f){return Rr(e+(t&r|~t&n)+i+a|0,f)+t|0}function be(e,t,r,n,i,a,f){return Rr(e+(t&n|r&~n)+i+a|0,f)+t|0}function ye(e,t,r,n,i,a,f){return Rr(e+(t^r^n)+i+a|0,f)+t|0}function ge(e,t,r,n,i,a,f){return Rr(e+(r^(t|~n))+i+a|0,f)+t|0}var Tu=Ir,mr=ve.Buffer,Ss=vs.Transform,ku=de;function Pu(e,t){if(!mr.isBuffer(e)&&typeof e!="string")throw new TypeError(t+" must be a string or a buffer")}function tt(e){Ss.call(this),this._block=mr.allocUnsafe(e),this._blockSize=e,this._blockOffset=0,this._length=[0,0,0,0],this._finalized=!1}ku(tt,Ss);tt.prototype._transform=function(e,t,r){var n=null;try{this.update(e,t)}catch(i){n=i}r(n)};tt.prototype._flush=function(e){var t=null;try{this.push(this.digest())}catch(r){t=r}e(t)};tt.prototype.update=function(e,t){if(Pu(e,"Data"),this._finalized)throw new Error("Digest already called");mr.isBuffer(e)||(e=mr.from(e,t));for(var r=this._block,n=0;this._blockOffset+e.length-n>=this._blockSize;){for(var i=this._blockOffset;i<this._blockSize;)r[i++]=e[n++];this._update(),this._blockOffset=0}for(;n<e.length;)r[this._blockOffset++]=e[n++];for(var a=0,f=e.length*8;f>0;++a)this._length[a]+=f,f=this._length[a]/4294967296|0,f>0&&(this._length[a]-=4294967296*f);return this};tt.prototype._update=function(){throw new Error("_update is not implemented")};tt.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};tt.prototype._digest=function(){throw new Error("_digest is not implemented")};var Cu=tt,Jr=kt.Buffer,Lu=de,As=Cu,Ou=new Array(16),Dt=[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],$t=[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],Ht=[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],zt=[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],Gt=[0,1518500249,1859775393,2400959708,2840853838],jt=[1352829926,1548603684,1836072691,2053994217,0];function Tr(){As.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520}Lu(Tr,As);Tr.prototype._update=function(){for(var e=Ou,t=0;t<16;++t)e[t]=this._block.readInt32LE(t*4);for(var r=this._a|0,n=this._b|0,i=this._c|0,a=this._d|0,f=this._e|0,u=this._a|0,l=this._b|0,b=this._c|0,g=this._d|0,m=this._e|0,v=0;v<80;v+=1){var A,B;v<16?(A=ai(r,n,i,a,f,e[Dt[v]],Gt[0],Ht[v]),B=li(u,l,b,g,m,e[$t[v]],jt[0],zt[v])):v<32?(A=fi(r,n,i,a,f,e[Dt[v]],Gt[1],Ht[v]),B=ci(u,l,b,g,m,e[$t[v]],jt[1],zt[v])):v<48?(A=ui(r,n,i,a,f,e[Dt[v]],Gt[2],Ht[v]),B=ui(u,l,b,g,m,e[$t[v]],jt[2],zt[v])):v<64?(A=ci(r,n,i,a,f,e[Dt[v]],Gt[3],Ht[v]),B=fi(u,l,b,g,m,e[$t[v]],jt[3],zt[v])):(A=li(r,n,i,a,f,e[Dt[v]],Gt[4],Ht[v]),B=ai(u,l,b,g,m,e[$t[v]],jt[4],zt[v])),r=f,f=a,a=ht(i,10),i=n,n=A,u=m,m=g,g=ht(b,10),b=l,l=B}var P=this._b+i+g|0;this._b=this._c+a+m|0,this._c=this._d+f+u|0,this._d=this._e+r+l|0,this._e=this._a+n+b|0,this._a=P};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=Jr.alloc?Jr.alloc(20):new Jr(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 ht(e,t){return e<<t|e>>>32-t}function ai(e,t,r,n,i,a,f,u){return ht(e+(t^r^n)+a+f|0,u)+i|0}function fi(e,t,r,n,i,a,f,u){return ht(e+(t&r|~t&n)+a+f|0,u)+i|0}function ui(e,t,r,n,i,a,f,u){return ht(e+((t|~r)^n)+a+f|0,u)+i|0}function ci(e,t,r,n,i,a,f,u){return ht(e+(t&n|r&~n)+a+f|0,u)+i|0}function li(e,t,r,n,i,a,f,u){return ht(e+(t^(r|~n))+a+f|0,u)+i|0}var Fu=Tr,Is={exports:{}},Rs=ve.Buffer;function kr(e,t){this._block=Rs.alloc(e),this._finalSize=t,this._blockSize=e,this._len=0}kr.prototype.update=function(e,t){typeof e=="string"&&(t=t||"utf8",e=Rs.from(e,t));for(var r=this._block,n=this._blockSize,i=e.length,a=this._len,f=0;f<i;){for(var u=a%n,l=Math.min(i-f,n-u),b=0;b<l;b++)r[u+b]=e[f+b];a+=l,f+=l,a%n===0&&this._update(r)}return this._len+=i,this};kr.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,i=(r-n)/4294967296;this._block.writeUInt32BE(i,this._blockSize-8),this._block.writeUInt32BE(n,this._blockSize-4)}this._update(this._block);var a=this._hash();return e?a.toString(e):a};kr.prototype._update=function(){throw new Error("_update must be implemented by subclass")};var Pt=kr,Uu=de,Ts=Pt,Nu=ve.Buffer,Mu=[1518500249,1859775393,-1894007588,-899497514],Du=new Array(80);function er(){this.init(),this._w=Du,Ts.call(this,64,56)}Uu(er,Ts);er.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this};function $u(e){return e<<5|e>>>27}function Hu(e){return e<<30|e>>>2}function zu(e,t,r,n){return e===0?t&r|~t&n:e===2?t&r|t&n|r&n:t^r^n}er.prototype._update=function(e){for(var t=this._w,r=this._a|0,n=this._b|0,i=this._c|0,a=this._d|0,f=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 l=0;l<80;++l){var b=~~(l/20),g=$u(r)+zu(b,n,i,a)+f+t[l]+Mu[b]|0;f=a,a=i,i=Hu(n),n=r,r=g}this._a=r+this._a|0,this._b=n+this._b|0,this._c=i+this._c|0,this._d=a+this._d|0,this._e=f+this._e|0};er.prototype._hash=function(){var e=Nu.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 Gu=er,ju=de,ks=Pt,Wu=ve.Buffer,qu=[1518500249,1859775393,-1894007588,-899497514],Vu=new Array(80);function tr(){this.init(),this._w=Vu,ks.call(this,64,56)}ju(tr,ks);tr.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this};function Ku(e){return e<<1|e>>>31}function Yu(e){return e<<5|e>>>27}function Ju(e){return e<<30|e>>>2}function Xu(e,t,r,n){return e===0?t&r|~t&n:e===2?t&r|t&n|r&n:t^r^n}tr.prototype._update=function(e){for(var t=this._w,r=this._a|0,n=this._b|0,i=this._c|0,a=this._d|0,f=this._e|0,u=0;u<16;++u)t[u]=e.readInt32BE(u*4);for(;u<80;++u)t[u]=Ku(t[u-3]^t[u-8]^t[u-14]^t[u-16]);for(var l=0;l<80;++l){var b=~~(l/20),g=Yu(r)+Xu(b,n,i,a)+f+t[l]+qu[b]|0;f=a,a=i,i=Ju(n),n=r,r=g}this._a=r+this._a|0,this._b=n+this._b|0,this._c=i+this._c|0,this._d=a+this._d|0,this._e=f+this._e|0};tr.prototype._hash=function(){var e=Wu.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 Qu=tr,Zu=de,Ps=Pt,ec=ve.Buffer,tc=[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],rc=new Array(64);function rr(){this.init(),this._w=rc,Ps.call(this,64,56)}Zu(rr,Ps);rr.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 nc(e,t,r){return r^e&(t^r)}function ic(e,t,r){return e&t|r&(e|t)}function sc(e){return(e>>>2|e<<30)^(e>>>13|e<<19)^(e>>>22|e<<10)}function oc(e){return(e>>>6|e<<26)^(e>>>11|e<<21)^(e>>>25|e<<7)}function ac(e){return(e>>>7|e<<25)^(e>>>18|e<<14)^e>>>3}function fc(e){return(e>>>17|e<<15)^(e>>>19|e<<13)^e>>>10}rr.prototype._update=function(e){for(var t=this._w,r=this._a|0,n=this._b|0,i=this._c|0,a=this._d|0,f=this._e|0,u=this._f|0,l=this._g|0,b=this._h|0,g=0;g<16;++g)t[g]=e.readInt32BE(g*4);for(;g<64;++g)t[g]=fc(t[g-2])+t[g-7]+ac(t[g-15])+t[g-16]|0;for(var m=0;m<64;++m){var v=b+oc(f)+nc(f,u,l)+tc[m]+t[m]|0,A=sc(r)+ic(r,n,i)|0;b=l,l=u,u=f,f=a+v|0,a=i,i=n,n=r,r=v+A|0}this._a=r+this._a|0,this._b=n+this._b|0,this._c=i+this._c|0,this._d=a+this._d|0,this._e=f+this._e|0,this._f=u+this._f|0,this._g=l+this._g|0,this._h=b+this._h|0};rr.prototype._hash=function(){var e=ec.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 Cs=rr,uc=de,cc=Cs,lc=Pt,hc=ve.Buffer,dc=new Array(64);function Pr(){this.init(),this._w=dc,lc.call(this,64,56)}uc(Pr,cc);Pr.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};Pr.prototype._hash=function(){var e=hc.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 pc=Pr,bc=de,Ls=Pt,yc=ve.Buffer,hi=[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],gc=new Array(160);function nr(){this.init(),this._w=gc,Ls.call(this,128,112)}bc(nr,Ls);nr.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 di(e,t,r){return r^e&(t^r)}function pi(e,t,r){return e&t|r&(e|t)}function bi(e,t){return(e>>>28|t<<4)^(t>>>2|e<<30)^(t>>>7|e<<25)}function yi(e,t){return(e>>>14|t<<18)^(e>>>18|t<<14)^(t>>>9|e<<23)}function mc(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^e>>>7}function _c(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^(e>>>7|t<<25)}function wc(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^e>>>6}function xc(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^(e>>>6|t<<26)}function le(e,t){return e>>>0<t>>>0?1:0}nr.prototype._update=function(e){for(var t=this._w,r=this._ah|0,n=this._bh|0,i=this._ch|0,a=this._dh|0,f=this._eh|0,u=this._fh|0,l=this._gh|0,b=this._hh|0,g=this._al|0,m=this._bl|0,v=this._cl|0,A=this._dl|0,B=this._el|0,P=this._fl|0,T=this._gl|0,C=this._hl|0,F=0;F<32;F+=2)t[F]=e.readInt32BE(F*4),t[F+1]=e.readInt32BE(F*4+4);for(;F<160;F+=2){var O=t[F-30],L=t[F-15*2+1],U=mc(O,L),S=_c(L,O);O=t[F-2*2],L=t[F-2*2+1];var z=wc(O,L),M=xc(L,O),$=t[F-7*2],ae=t[F-7*2+1],ke=t[F-16*2],je=t[F-16*2+1],ue=S+ae|0,Ee=U+$+le(ue,S)|0;ue=ue+M|0,Ee=Ee+z+le(ue,M)|0,ue=ue+je|0,Ee=Ee+ke+le(ue,je)|0,t[F]=Ee,t[F+1]=ue}for(var Be=0;Be<160;Be+=2){Ee=t[Be],ue=t[Be+1];var rt=pi(r,n,i),Pe=pi(g,m,v),We=bi(r,g),Ce=bi(g,r),qe=yi(f,B),ee=yi(B,f),fe=hi[Be],Se=hi[Be+1],Ve=di(f,u,l),Ne=di(B,P,T),w=C+ee|0,_=b+qe+le(w,C)|0;w=w+Ne|0,_=_+Ve+le(w,Ne)|0,w=w+Se|0,_=_+fe+le(w,Se)|0,w=w+ue|0,_=_+Ee+le(w,ue)|0;var R=Ce+Pe|0,D=We+rt+le(R,Ce)|0;b=l,C=T,l=u,T=P,u=f,P=B,B=A+w|0,f=a+_+le(B,A)|0,a=i,A=v,i=n,v=m,n=r,m=g,g=w+R|0,r=_+D+le(g,w)|0}this._al=this._al+g|0,this._bl=this._bl+m|0,this._cl=this._cl+v|0,this._dl=this._dl+A|0,this._el=this._el+B|0,this._fl=this._fl+P|0,this._gl=this._gl+T|0,this._hl=this._hl+C|0,this._ah=this._ah+r+le(this._al,g)|0,this._bh=this._bh+n+le(this._bl,m)|0,this._ch=this._ch+i+le(this._cl,v)|0,this._dh=this._dh+a+le(this._dl,A)|0,this._eh=this._eh+f+le(this._el,B)|0,this._fh=this._fh+u+le(this._fl,P)|0,this._gh=this._gh+l+le(this._gl,T)|0,this._hh=this._hh+b+le(this._hl,C)|0};nr.prototype._hash=function(){var e=yc.allocUnsafe(64);function t(r,n,i){e.writeInt32BE(r,i),e.writeInt32BE(n,i+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 Os=nr,vc=de,Ec=Os,Bc=Pt,Sc=ve.Buffer,Ac=new Array(160);function Cr(){this.init(),this._w=Ac,Bc.call(this,128,112)}vc(Cr,Ec);Cr.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};Cr.prototype._hash=function(){var e=Sc.allocUnsafe(48);function t(r,n,i){e.writeInt32BE(r,i),e.writeInt32BE(n,i+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 Ic=Cr,bt=Is.exports=function(t){t=t.toLowerCase();var r=bt[t];if(!r)throw new Error(t+" is not supported (we accept pull requests)");return new r};bt.sha=Gu;bt.sha1=Qu;bt.sha224=pc;bt.sha256=Cs;bt.sha384=Ic;bt.sha512=Os;var Rc=Is.exports,Fs=ve.Buffer,Us=In.Transform,Tc=yr.StringDecoder,kc=de;function Le(e){Us.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}kc(Le,Us);Le.prototype.update=function(e,t,r){typeof e=="string"&&(e=Fs.from(e,t));var n=this._update(e);return this.hashMode?this:(r&&(n=this._toString(n,r)),n)};Le.prototype.setAutoPadding=function(){};Le.prototype.getAuthTag=function(){throw new Error("trying to get auth tag in unsupported state")};Le.prototype.setAuthTag=function(){throw new Error("trying to set auth tag in unsupported state")};Le.prototype.setAAD=function(){throw new Error("trying to set aad in unsupported state")};Le.prototype._transform=function(e,t,r){var n;try{this.hashMode?this._update(e):this.push(this._update(e))}catch(i){n=i}finally{r(n)}};Le.prototype._flush=function(e){var t;try{this.push(this.__final())}catch(r){t=r}e(t)};Le.prototype._finalOrDigest=function(e){var t=this.__final()||Fs.alloc(0);return e&&(t=this._toString(t,e,!0)),t};Le.prototype._toString=function(e,t,r){if(this._decoder||(this._decoder=new Tc(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 Pc=Le,Cc=de,Lc=Tu,Oc=Fu,Fc=Rc,Ns=Pc;function Lr(e){Ns.call(this,"digest"),this._hash=e}Cc(Lr,Ns);Lr.prototype._update=function(e){this._hash.update(e)};Lr.prototype._final=function(){return this._hash.digest()};var Uc=function(t){return t=t.toLowerCase(),t==="md5"?new Lc:t==="rmd160"||t==="ripemd160"?new Oc:new Lr(Fc(t))},ar=ve.Buffer;function Nc(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 i=e.charAt(n),a=i.charCodeAt(0);if(t[a]!==255)throw new TypeError(i+" is ambiguous");t[a]=n}var f=e.length,u=e.charAt(0),l=Math.log(f)/Math.log(256),b=Math.log(256)/Math.log(f);function g(A){if((Array.isArray(A)||A instanceof Uint8Array)&&(A=ar.from(A)),!ar.isBuffer(A))throw new TypeError("Expected Buffer");if(A.length===0)return"";for(var B=0,P=0,T=0,C=A.length;T!==C&&A[T]===0;)T++,B++;for(var F=(C-T)*b+1>>>0,O=new Uint8Array(F);T!==C;){for(var L=A[T],U=0,S=F-1;(L!==0||U<P)&&S!==-1;S--,U++)L+=256*O[S]>>>0,O[S]=L%f>>>0,L=L/f>>>0;if(L!==0)throw new Error("Non-zero carry");P=U,T++}for(var z=F-P;z!==F&&O[z]===0;)z++;for(var M=u.repeat(B);z<F;++z)M+=e.charAt(O[z]);return M}function m(A){if(typeof A!="string")throw new TypeError("Expected String");if(A.length===0)return ar.alloc(0);for(var B=0,P=0,T=0;A[B]===u;)P++,B++;for(var C=(A.length-B)*l+1>>>0,F=new Uint8Array(C);B<A.length;){var O=t[A.charCodeAt(B)];if(O===255)return;for(var L=0,U=C-1;(O!==0||L<T)&&U!==-1;U--,L++)O+=f*F[U]>>>0,F[U]=O%256>>>0,O=O/256>>>0;if(O!==0)throw new Error("Non-zero carry");T=L,B++}for(var S=C-T;S!==C&&F[S]===0;)S++;var z=ar.allocUnsafe(P+(C-S));z.fill(0,0,P);for(var M=P;S!==C;)z[M++]=F[S++];return z}function v(A){var B=m(A);if(B)return B;throw new Error("Non-base"+f+" character")}return{encode:g,decodeUnsafe:m,decode:v}}var Mc=Nc,Dc=Mc,$c="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",Hc=Dc($c),Xr=Hc,zc=ve.Buffer,Gc=function(e){function t(a){var f=e(a);return Xr.encode(zc.concat([a,f],a.length+4))}function r(a){var f=a.slice(0,-4),u=a.slice(-4),l=e(f);if(!(u[0]^l[0]|u[1]^l[1]|u[2]^l[2]|u[3]^l[3]))return f}function n(a){var f=Xr.decodeUnsafe(a);if(f)return r(f)}function i(a){var f=Xr.decode(a),u=r(f);if(!u)throw new Error("Invalid checksum");return u}return{encode:t,decode:i,decodeUnsafe:n}},gi=Uc,jc=Gc;function Wc(e){var t=gi("sha256").update(e).digest();return gi("sha256").update(t).digest()}var qc=jc(Wc),fn=qc;function Ms(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 un(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 Vc(e,t){return Ms(fn.decode(e),t)}function Kc(e,t,r){return typeof e=="number"?fn.encode(un(e,t,r)):fn.encode(un(e.version,e.privateKey,e.compressed))}var Yc={decode:Vc,decodeRaw:Ms,encode:Kc,encodeRaw:un},Or={};Object.defineProperty(Or,"__esModule",{value:!0});Or.testEcc=void 0;const H=e=>Buffer.from(e,"hex");function Jc(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=Jc;function J(e){if(!e)throw new Error("ecc library invalid")}Object.defineProperty(St,"__esModule",{value:!0});St.ECPairFactory=St.networks=void 0;const cn=At;St.networks=cn;const we=Ji,Xc=xf,mi=Yc,Qc=Or,Qr=we.typeforce.maybe(we.typeforce.compile({compressed:we.maybe(we.Boolean),network:we.maybe(we.Network)})),Zc=e=>e.length===32?e:e.slice(1,33);function el(e){(0,Qc.testEcc)(e);function t(u){return e.isPoint(u)}function r(u,l){if(we.typeforce(we.Buffer256bit,u),!e.isPrivate(u))throw new TypeError("Private key not in range [1, n)");return we.typeforce(Qr,l),new f(u,void 0,l)}function n(u,l){return we.typeforce(e.isPoint,u),we.typeforce(Qr,l),new f(void 0,u,l)}function i(u,l){const b=mi.decode(u),g=b.version;if(we.Array(l)){if(l=l.filter(m=>g===m.wif).pop(),!l)throw new Error("Unknown network version")}else if(l=l||cn.bitcoin,g!==l.wif)throw new Error("Invalid network version");return r(b.privateKey,{compressed:b.compressed,network:l})}function a(u){we.typeforce(Qr,u),u===void 0&&(u={});const l=u.rng||Xc;let b;do b=l(32),we.typeforce(we.Buffer256bit,b);while(!e.isPrivate(b));return r(b,u)}class f{constructor(l,b,g){mt(this,"__D");mt(this,"__Q");mt(this,"compressed");mt(this,"network");mt(this,"lowR");this.__D=l,this.__Q=b,this.lowR=!1,g===void 0&&(g={}),this.compressed=g.compressed===void 0?!0:g.compressed,this.network=g.network||cn.bitcoin,b!==void 0&&(this.__Q=Buffer.from(e.pointCompress(b,this.compressed)))}get privateKey(){return this.__D}get publicKey(){if(!this.__Q){const l=e.pointFromScalar(this.__D,this.compressed);this.__Q=Buffer.from(l)}return this.__Q}toWIF(){if(!this.__D)throw new Error("Missing private key");return mi.encode(this.network.wif,this.__D,this.compressed)}tweak(l){return this.privateKey?this.tweakFromPrivateKey(l):this.tweakFromPublicKey(l)}sign(l,b){if(!this.__D)throw new Error("Missing private key");if(b===void 0&&(b=this.lowR),b===!1)return Buffer.from(e.sign(l,this.__D));{let g=e.sign(l,this.__D);const m=Buffer.alloc(32,0);let v=0;for(;g[0]>127;)v++,m.writeUIntLE(v,0,6),g=e.sign(l,this.__D,m);return Buffer.from(g)}}signSchnorr(l){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(l,this.privateKey))}verify(l,b){return e.verify(l,this.publicKey,b)}verifySchnorr(l,b){if(!e.verifySchnorr)throw new Error("verifySchnorr not supported by ecc library");return e.verifySchnorr(l,this.publicKey.subarray(1,33),b)}tweakFromPublicKey(l){const b=Zc(this.publicKey),g=e.xOnlyPointAddTweak(b,l);if(!g||g.xOnlyPubkey===null)throw new Error("Cannot tweak public key!");const m=Buffer.from([g.parity===0?2:3]);return n(Buffer.concat([m,g.xOnlyPubkey]),{network:this.network,compressed:this.compressed})}tweakFromPrivateKey(l){const g=this.publicKey[0]===3||this.publicKey[0]===4&&(this.publicKey[64]&1)===1?e.privateNegate(this.privateKey):this.privateKey,m=e.privateAdd(g,l);if(!m)throw new Error("Invalid tweaked private key!");return r(Buffer.from(m),{network:this.network,compressed:this.compressed})}}return{isPoint:t,fromPrivateKey:r,fromPublicKey:n,fromWIF:i,makeRandom:a}}St.ECPairFactory=el;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.networks=e.ECPairFactory=e.default=void 0;var t=St;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}})})(Yi);const tl=Za(Yi);class _r{constructor(t){this.privKey=t}static fromPrivKey(t){return new _r(k.trim0x(t))}static async fromWalletClient(t){if(!t.account)return k.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 account",Version:"1.0.2",Nonce:1n}});return k.Ok(new _r(k.trim0x(He.sha256(r))))}catch(r){return k.Err("Failed to initialize: "+r)}}getMasterPrivKey(){return this.privKey}generateSecret(t){const r=this.signMessage(t),n=He.sha256(me.with0x(r)),i=He.sha256(n);return k.Ok({secret:n,secretHash:i})}signMessage(t){const r=tl(at),n="Garden.fi"+t.toString(),i=Buffer.from(n,"utf8"),a=He.sha256(i),f=Buffer.from(k.trim0x(this.privKey),"hex");if(f.length!==32)throw new Error("Invalid private key length. Expected 32 bytes.");return r.fromPrivateKey(f).sign(Buffer.from(k.trim0x(a),"hex")).toString("hex")}}class rl{constructor(t){this.quoteUrl=new me.Url("/quote",t)}async getQuote(t,r,n=!1){try{const i=this.quoteUrl.addSearchParams({order_pair:t,amount:r.toString(),exact_out:n.toString()}),a=await k.Fetcher.get(i);return a.error?k.Err(a.error):a.result?k.Ok(a.result):k.Err("GetQuote: Unexpected error, result is undefined")}catch(i){return k.Err("GetQuote:",String(i))}}async getAttestedQuote(t){try{const r=await k.Fetcher.post(this.quoteUrl.endpoint("/attested").toString(),{body:JSON.stringify(t),headers:{"Content-Type":"application/json"}});return r.error?k.Err(r.error):r.result?k.Ok(r.result):k.Err("GetAttestedQuote: Unexpected error, result is undefined")}catch(r){return console.log("error :",r),k.Err("GetAttestedQuote:",String(r))}}async getStrategies(){try{const t=await k.Fetcher.get(this.quoteUrl.endpoint("/strategies"));if(t.error)return k.Err(t.error);if(!t.result)return k.Err("GetStrategies: Unexpected error, result is undefined");const r={};for(const n of Object.values(t.result)){const i=qi(n.source_chain,n.source_asset.asset,n.dest_chain,n.dest_asset.asset);r[i]={id:n.id,minAmount:n.min_amount,maxAmount:n.max_amount,fee:n.fee}}return k.Ok(r)}catch(t){return k.Err("GetStrategies:",String(t))}}}exports.BlockNumberFetcher=Qa;exports.EvmRelay=Ki;exports.Garden=Xa;exports.OrderActions=ce;exports.OrderStatus=Q;exports.ParseOrderStatus=wn;exports.ParseSwapStatus=tn;exports.Quote=rl;exports.SecretManager=_r;exports.SwapStatus=ne;exports.constructOrderPair=qi;exports.evmToViemChainMap=Wi;exports.filterDeadlineExpiredOrders=Vi;exports.isExpired=qt;exports.parseAction=Ga;exports.parseActionFromStatus=xn;exports.switchOrAddNetwork=$a;exports.validateBTCAddress=za;
27
+ */(function(e){const t=xr,r=mn,n=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;e.Buffer=f,e.SlowBuffer=F,e.INSPECT_MAX_BYTES=50;const i=2147483647;e.kMaxLength=i,f.TYPED_ARRAY_SUPPORT=o(),!f.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 o(){try{const c=new Uint8Array(1),s={foo:function(){return 42}};return Object.setPrototypeOf(s,Uint8Array.prototype),Object.setPrototypeOf(c,s),c.foo()===42}catch{return!1}}Object.defineProperty(f.prototype,"parent",{enumerable:!0,get:function(){if(f.isBuffer(this))return this.buffer}}),Object.defineProperty(f.prototype,"offset",{enumerable:!0,get:function(){if(f.isBuffer(this))return this.byteOffset}});function u(c){if(c>i)throw new RangeError('The value "'+c+'" is invalid for option "size"');const s=new Uint8Array(c);return Object.setPrototypeOf(s,f.prototype),s}function f(c,s,a){if(typeof c=="number"){if(typeof s=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return m(c)}return l(c,s,a)}f.poolSize=8192;function l(c,s,a){if(typeof c=="string")return v(c,s);if(ArrayBuffer.isView(c))return I(c);if(c==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof c);if(Ae(c,ArrayBuffer)||c&&Ae(c.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(Ae(c,SharedArrayBuffer)||c&&Ae(c.buffer,SharedArrayBuffer)))return k(c,s,a);if(typeof c=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const h=c.valueOf&&c.valueOf();if(h!=null&&h!==c)return f.from(h,s,a);const y=C(c);if(y)return y;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof c[Symbol.toPrimitive]=="function")return f.from(c[Symbol.toPrimitive]("string"),s,a);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof c)}f.from=function(c,s,a){return l(c,s,a)},Object.setPrototypeOf(f.prototype,Uint8Array.prototype),Object.setPrototypeOf(f,Uint8Array);function b(c){if(typeof c!="number")throw new TypeError('"size" argument must be of type number');if(c<0)throw new RangeError('The value "'+c+'" is invalid for option "size"')}function g(c,s,a){return b(c),c<=0?u(c):s!==void 0?typeof a=="string"?u(c).fill(s,a):u(c).fill(s):u(c)}f.alloc=function(c,s,a){return g(c,s,a)};function m(c){return b(c),u(c<0?0:P(c)|0)}f.allocUnsafe=function(c){return m(c)},f.allocUnsafeSlow=function(c){return m(c)};function v(c,s){if((typeof s!="string"||s==="")&&(s="utf8"),!f.isEncoding(s))throw new TypeError("Unknown encoding: "+s);const a=O(c,s)|0;let h=u(a);const y=h.write(c,s);return y!==a&&(h=h.slice(0,y)),h}function A(c){const s=c.length<0?0:P(c.length)|0,a=u(s);for(let h=0;h<s;h+=1)a[h]=c[h]&255;return a}function I(c){if(Ae(c,Uint8Array)){const s=new Uint8Array(c);return k(s.buffer,s.byteOffset,s.byteLength)}return A(c)}function k(c,s,a){if(s<0||c.byteLength<s)throw new RangeError('"offset" is outside of buffer bounds');if(c.byteLength<s+(a||0))throw new RangeError('"length" is outside of buffer bounds');let h;return s===void 0&&a===void 0?h=new Uint8Array(c):a===void 0?h=new Uint8Array(c,s):h=new Uint8Array(c,s,a),Object.setPrototypeOf(h,f.prototype),h}function C(c){if(f.isBuffer(c)){const s=P(c.length)|0,a=u(s);return a.length===0||c.copy(a,0,0,s),a}if(c.length!==void 0)return typeof c.length!="number"||nt(c.length)?u(0):A(c);if(c.type==="Buffer"&&Array.isArray(c.data))return A(c.data)}function P(c){if(c>=i)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i.toString(16)+" bytes");return c|0}function F(c){return+c!=c&&(c=0),f.alloc(+c)}f.isBuffer=function(s){return s!=null&&s._isBuffer===!0&&s!==f.prototype},f.compare=function(s,a){if(Ae(s,Uint8Array)&&(s=f.from(s,s.offset,s.byteLength)),Ae(a,Uint8Array)&&(a=f.from(a,a.offset,a.byteLength)),!f.isBuffer(s)||!f.isBuffer(a))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(s===a)return 0;let h=s.length,y=a.length;for(let x=0,E=Math.min(h,y);x<E;++x)if(s[x]!==a[x]){h=s[x],y=a[x];break}return h<y?-1:y<h?1:0},f.isEncoding=function(s){switch(String(s).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}},f.concat=function(s,a){if(!Array.isArray(s))throw new TypeError('"list" argument must be an Array of Buffers');if(s.length===0)return f.alloc(0);let h;if(a===void 0)for(a=0,h=0;h<s.length;++h)a+=s[h].length;const y=f.allocUnsafe(a);let x=0;for(h=0;h<s.length;++h){let E=s[h];if(Ae(E,Uint8Array))x+E.length>y.length?(f.isBuffer(E)||(E=f.from(E)),E.copy(y,x)):Uint8Array.prototype.set.call(y,E,x);else if(f.isBuffer(E))E.copy(y,x);else throw new TypeError('"list" argument must be an Array of Buffers');x+=E.length}return y};function O(c,s){if(f.isBuffer(c))return c.length;if(ArrayBuffer.isView(c)||Ae(c,ArrayBuffer))return c.byteLength;if(typeof c!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof c);const a=c.length,h=arguments.length>2&&arguments[2]===!0;if(!h&&a===0)return 0;let y=!1;for(;;)switch(s){case"ascii":case"latin1":case"binary":return a;case"utf8":case"utf-8":return V(c).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return a*2;case"hex":return a>>>1;case"base64":return Lt(c).length;default:if(y)return h?-1:V(c).length;s=(""+s).toLowerCase(),y=!0}}f.byteLength=O;function L(c,s,a){let h=!1;if((s===void 0||s<0)&&(s=0),s>this.length||((a===void 0||a>this.length)&&(a=this.length),a<=0)||(a>>>=0,s>>>=0,a<=s))return"";for(c||(c="utf8");;)switch(c){case"hex":return Pe(this,s,a);case"utf8":case"utf-8":return Ee(this,s,a);case"ascii":return Ce(this,s,a);case"latin1":case"binary":return We(this,s,a);case"base64":return ce(this,s,a);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return qe(this,s,a);default:if(h)throw new TypeError("Unknown encoding: "+c);c=(c+"").toLowerCase(),h=!0}}f.prototype._isBuffer=!0;function U(c,s,a){const h=c[s];c[s]=c[a],c[a]=h}f.prototype.swap16=function(){const s=this.length;if(s%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let a=0;a<s;a+=2)U(this,a,a+1);return this},f.prototype.swap32=function(){const s=this.length;if(s%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let a=0;a<s;a+=4)U(this,a,a+3),U(this,a+1,a+2);return this},f.prototype.swap64=function(){const s=this.length;if(s%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let a=0;a<s;a+=8)U(this,a,a+7),U(this,a+1,a+6),U(this,a+2,a+5),U(this,a+3,a+4);return this},f.prototype.toString=function(){const s=this.length;return s===0?"":arguments.length===0?Ee(this,0,s):L.apply(this,arguments)},f.prototype.toLocaleString=f.prototype.toString,f.prototype.equals=function(s){if(!f.isBuffer(s))throw new TypeError("Argument must be a Buffer");return this===s?!0:f.compare(this,s)===0},f.prototype.inspect=function(){let s="";const a=e.INSPECT_MAX_BYTES;return s=this.toString("hex",0,a).replace(/(.{2})/g,"$1 ").trim(),this.length>a&&(s+=" ... "),"<Buffer "+s+">"},n&&(f.prototype[n]=f.prototype.inspect),f.prototype.compare=function(s,a,h,y,x){if(Ae(s,Uint8Array)&&(s=f.from(s,s.offset,s.byteLength)),!f.isBuffer(s))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof s);if(a===void 0&&(a=0),h===void 0&&(h=s?s.length:0),y===void 0&&(y=0),x===void 0&&(x=this.length),a<0||h>s.length||y<0||x>this.length)throw new RangeError("out of range index");if(y>=x&&a>=h)return 0;if(y>=x)return-1;if(a>=h)return 1;if(a>>>=0,h>>>=0,y>>>=0,x>>>=0,this===s)return 0;let E=x-y,q=h-a;const ie=Math.min(E,q),re=this.slice(y,x),se=s.slice(a,h);for(let Y=0;Y<ie;++Y)if(re[Y]!==se[Y]){E=re[Y],q=se[Y];break}return E<q?-1:q<E?1:0};function B(c,s,a,h,y){if(c.length===0)return-1;if(typeof a=="string"?(h=a,a=0):a>2147483647?a=2147483647:a<-2147483648&&(a=-2147483648),a=+a,nt(a)&&(a=y?0:c.length-1),a<0&&(a=c.length+a),a>=c.length){if(y)return-1;a=c.length-1}else if(a<0)if(y)a=0;else return-1;if(typeof s=="string"&&(s=f.from(s,h)),f.isBuffer(s))return s.length===0?-1:z(c,s,a,h,y);if(typeof s=="number")return s=s&255,typeof Uint8Array.prototype.indexOf=="function"?y?Uint8Array.prototype.indexOf.call(c,s,a):Uint8Array.prototype.lastIndexOf.call(c,s,a):z(c,[s],a,h,y);throw new TypeError("val must be string, number or Buffer")}function z(c,s,a,h,y){let x=1,E=c.length,q=s.length;if(h!==void 0&&(h=String(h).toLowerCase(),h==="ucs2"||h==="ucs-2"||h==="utf16le"||h==="utf-16le")){if(c.length<2||s.length<2)return-1;x=2,E/=2,q/=2,a/=2}function ie(se,Y){return x===1?se[Y]:se.readUInt16BE(Y*x)}let re;if(y){let se=-1;for(re=a;re<E;re++)if(ie(c,re)===ie(s,se===-1?0:re-se)){if(se===-1&&(se=re),re-se+1===q)return se*x}else se!==-1&&(re-=re-se),se=-1}else for(a+q>E&&(a=E-q),re=a;re>=0;re--){let se=!0;for(let Y=0;Y<q;Y++)if(ie(c,re+Y)!==ie(s,Y)){se=!1;break}if(se)return re}return-1}f.prototype.includes=function(s,a,h){return this.indexOf(s,a,h)!==-1},f.prototype.indexOf=function(s,a,h){return B(this,s,a,h,!0)},f.prototype.lastIndexOf=function(s,a,h){return B(this,s,a,h,!1)};function M(c,s,a,h){a=Number(a)||0;const y=c.length-a;h?(h=Number(h),h>y&&(h=y)):h=y;const x=s.length;h>x/2&&(h=x/2);let E;for(E=0;E<h;++E){const q=parseInt(s.substr(E*2,2),16);if(nt(q))return E;c[a+E]=q}return E}function $(c,s,a,h){return gt(V(s,c.length-a),c,a,h)}function fe(c,s,a,h){return gt(Ke(s),c,a,h)}function ke(c,s,a,h){return gt(Lt(s),c,a,h)}function je(c,s,a,h){return gt(yt(s,c.length-a),c,a,h)}f.prototype.write=function(s,a,h,y){if(a===void 0)y="utf8",h=this.length,a=0;else if(h===void 0&&typeof a=="string")y=a,h=this.length,a=0;else if(isFinite(a))a=a>>>0,isFinite(h)?(h=h>>>0,y===void 0&&(y="utf8")):(y=h,h=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const x=this.length-a;if((h===void 0||h>x)&&(h=x),s.length>0&&(h<0||a<0)||a>this.length)throw new RangeError("Attempt to write outside buffer bounds");y||(y="utf8");let E=!1;for(;;)switch(y){case"hex":return M(this,s,a,h);case"utf8":case"utf-8":return $(this,s,a,h);case"ascii":case"latin1":case"binary":return fe(this,s,a,h);case"base64":return ke(this,s,a,h);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return je(this,s,a,h);default:if(E)throw new TypeError("Unknown encoding: "+y);y=(""+y).toLowerCase(),E=!0}},f.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function ce(c,s,a){return s===0&&a===c.length?t.fromByteArray(c):t.fromByteArray(c.slice(s,a))}function Ee(c,s,a){a=Math.min(c.length,a);const h=[];let y=s;for(;y<a;){const x=c[y];let E=null,q=x>239?4:x>223?3:x>191?2:1;if(y+q<=a){let ie,re,se,Y;switch(q){case 1:x<128&&(E=x);break;case 2:ie=c[y+1],(ie&192)===128&&(Y=(x&31)<<6|ie&63,Y>127&&(E=Y));break;case 3:ie=c[y+1],re=c[y+2],(ie&192)===128&&(re&192)===128&&(Y=(x&15)<<12|(ie&63)<<6|re&63,Y>2047&&(Y<55296||Y>57343)&&(E=Y));break;case 4:ie=c[y+1],re=c[y+2],se=c[y+3],(ie&192)===128&&(re&192)===128&&(se&192)===128&&(Y=(x&15)<<18|(ie&63)<<12|(re&63)<<6|se&63,Y>65535&&Y<1114112&&(E=Y))}}E===null?(E=65533,q=1):E>65535&&(E-=65536,h.push(E>>>10&1023|55296),E=56320|E&1023),h.push(E),y+=q}return rt(h)}const Be=4096;function rt(c){const s=c.length;if(s<=Be)return String.fromCharCode.apply(String,c);let a="",h=0;for(;h<s;)a+=String.fromCharCode.apply(String,c.slice(h,h+=Be));return a}function Ce(c,s,a){let h="";a=Math.min(c.length,a);for(let y=s;y<a;++y)h+=String.fromCharCode(c[y]&127);return h}function We(c,s,a){let h="";a=Math.min(c.length,a);for(let y=s;y<a;++y)h+=String.fromCharCode(c[y]);return h}function Pe(c,s,a){const h=c.length;(!s||s<0)&&(s=0),(!a||a<0||a>h)&&(a=h);let y="";for(let x=s;x<a;++x)y+=Ot[c[x]];return y}function qe(c,s,a){const h=c.slice(s,a);let y="";for(let x=0;x<h.length-1;x+=2)y+=String.fromCharCode(h[x]+h[x+1]*256);return y}f.prototype.slice=function(s,a){const h=this.length;s=~~s,a=a===void 0?h:~~a,s<0?(s+=h,s<0&&(s=0)):s>h&&(s=h),a<0?(a+=h,a<0&&(a=0)):a>h&&(a=h),a<s&&(a=s);const y=this.subarray(s,a);return Object.setPrototypeOf(y,f.prototype),y};function ee(c,s,a){if(c%1!==0||c<0)throw new RangeError("offset is not uint");if(c+s>a)throw new RangeError("Trying to access beyond buffer length")}f.prototype.readUintLE=f.prototype.readUIntLE=function(s,a,h){s=s>>>0,a=a>>>0,h||ee(s,a,this.length);let y=this[s],x=1,E=0;for(;++E<a&&(x*=256);)y+=this[s+E]*x;return y},f.prototype.readUintBE=f.prototype.readUIntBE=function(s,a,h){s=s>>>0,a=a>>>0,h||ee(s,a,this.length);let y=this[s+--a],x=1;for(;a>0&&(x*=256);)y+=this[s+--a]*x;return y},f.prototype.readUint8=f.prototype.readUInt8=function(s,a){return s=s>>>0,a||ee(s,1,this.length),this[s]},f.prototype.readUint16LE=f.prototype.readUInt16LE=function(s,a){return s=s>>>0,a||ee(s,2,this.length),this[s]|this[s+1]<<8},f.prototype.readUint16BE=f.prototype.readUInt16BE=function(s,a){return s=s>>>0,a||ee(s,2,this.length),this[s]<<8|this[s+1]},f.prototype.readUint32LE=f.prototype.readUInt32LE=function(s,a){return s=s>>>0,a||ee(s,4,this.length),(this[s]|this[s+1]<<8|this[s+2]<<16)+this[s+3]*16777216},f.prototype.readUint32BE=f.prototype.readUInt32BE=function(s,a){return s=s>>>0,a||ee(s,4,this.length),this[s]*16777216+(this[s+1]<<16|this[s+2]<<8|this[s+3])},f.prototype.readBigUInt64LE=Ie(function(s){s=s>>>0,T(s,"offset");const a=this[s],h=this[s+7];(a===void 0||h===void 0)&&N(s,this.length-8);const y=a+this[++s]*2**8+this[++s]*2**16+this[++s]*2**24,x=this[++s]+this[++s]*2**8+this[++s]*2**16+h*2**24;return BigInt(y)+(BigInt(x)<<BigInt(32))}),f.prototype.readBigUInt64BE=Ie(function(s){s=s>>>0,T(s,"offset");const a=this[s],h=this[s+7];(a===void 0||h===void 0)&&N(s,this.length-8);const y=a*2**24+this[++s]*2**16+this[++s]*2**8+this[++s],x=this[++s]*2**24+this[++s]*2**16+this[++s]*2**8+h;return(BigInt(y)<<BigInt(32))+BigInt(x)}),f.prototype.readIntLE=function(s,a,h){s=s>>>0,a=a>>>0,h||ee(s,a,this.length);let y=this[s],x=1,E=0;for(;++E<a&&(x*=256);)y+=this[s+E]*x;return x*=128,y>=x&&(y-=Math.pow(2,8*a)),y},f.prototype.readIntBE=function(s,a,h){s=s>>>0,a=a>>>0,h||ee(s,a,this.length);let y=a,x=1,E=this[s+--y];for(;y>0&&(x*=256);)E+=this[s+--y]*x;return x*=128,E>=x&&(E-=Math.pow(2,8*a)),E},f.prototype.readInt8=function(s,a){return s=s>>>0,a||ee(s,1,this.length),this[s]&128?(255-this[s]+1)*-1:this[s]},f.prototype.readInt16LE=function(s,a){s=s>>>0,a||ee(s,2,this.length);const h=this[s]|this[s+1]<<8;return h&32768?h|4294901760:h},f.prototype.readInt16BE=function(s,a){s=s>>>0,a||ee(s,2,this.length);const h=this[s+1]|this[s]<<8;return h&32768?h|4294901760:h},f.prototype.readInt32LE=function(s,a){return s=s>>>0,a||ee(s,4,this.length),this[s]|this[s+1]<<8|this[s+2]<<16|this[s+3]<<24},f.prototype.readInt32BE=function(s,a){return s=s>>>0,a||ee(s,4,this.length),this[s]<<24|this[s+1]<<16|this[s+2]<<8|this[s+3]},f.prototype.readBigInt64LE=Ie(function(s){s=s>>>0,T(s,"offset");const a=this[s],h=this[s+7];(a===void 0||h===void 0)&&N(s,this.length-8);const y=this[s+4]+this[s+5]*2**8+this[s+6]*2**16+(h<<24);return(BigInt(y)<<BigInt(32))+BigInt(a+this[++s]*2**8+this[++s]*2**16+this[++s]*2**24)}),f.prototype.readBigInt64BE=Ie(function(s){s=s>>>0,T(s,"offset");const a=this[s],h=this[s+7];(a===void 0||h===void 0)&&N(s,this.length-8);const y=(a<<24)+this[++s]*2**16+this[++s]*2**8+this[++s];return(BigInt(y)<<BigInt(32))+BigInt(this[++s]*2**24+this[++s]*2**16+this[++s]*2**8+h)}),f.prototype.readFloatLE=function(s,a){return s=s>>>0,a||ee(s,4,this.length),r.read(this,s,!0,23,4)},f.prototype.readFloatBE=function(s,a){return s=s>>>0,a||ee(s,4,this.length),r.read(this,s,!1,23,4)},f.prototype.readDoubleLE=function(s,a){return s=s>>>0,a||ee(s,8,this.length),r.read(this,s,!0,52,8)},f.prototype.readDoubleBE=function(s,a){return s=s>>>0,a||ee(s,8,this.length),r.read(this,s,!1,52,8)};function ue(c,s,a,h,y,x){if(!f.isBuffer(c))throw new TypeError('"buffer" argument must be a Buffer instance');if(s>y||s<x)throw new RangeError('"value" argument is out of bounds');if(a+h>c.length)throw new RangeError("Index out of range")}f.prototype.writeUintLE=f.prototype.writeUIntLE=function(s,a,h,y){if(s=+s,a=a>>>0,h=h>>>0,!y){const q=Math.pow(2,8*h)-1;ue(this,s,a,h,q,0)}let x=1,E=0;for(this[a]=s&255;++E<h&&(x*=256);)this[a+E]=s/x&255;return a+h},f.prototype.writeUintBE=f.prototype.writeUIntBE=function(s,a,h,y){if(s=+s,a=a>>>0,h=h>>>0,!y){const q=Math.pow(2,8*h)-1;ue(this,s,a,h,q,0)}let x=h-1,E=1;for(this[a+x]=s&255;--x>=0&&(E*=256);)this[a+x]=s/E&255;return a+h},f.prototype.writeUint8=f.prototype.writeUInt8=function(s,a,h){return s=+s,a=a>>>0,h||ue(this,s,a,1,255,0),this[a]=s&255,a+1},f.prototype.writeUint16LE=f.prototype.writeUInt16LE=function(s,a,h){return s=+s,a=a>>>0,h||ue(this,s,a,2,65535,0),this[a]=s&255,this[a+1]=s>>>8,a+2},f.prototype.writeUint16BE=f.prototype.writeUInt16BE=function(s,a,h){return s=+s,a=a>>>0,h||ue(this,s,a,2,65535,0),this[a]=s>>>8,this[a+1]=s&255,a+2},f.prototype.writeUint32LE=f.prototype.writeUInt32LE=function(s,a,h){return s=+s,a=a>>>0,h||ue(this,s,a,4,4294967295,0),this[a+3]=s>>>24,this[a+2]=s>>>16,this[a+1]=s>>>8,this[a]=s&255,a+4},f.prototype.writeUint32BE=f.prototype.writeUInt32BE=function(s,a,h){return s=+s,a=a>>>0,h||ue(this,s,a,4,4294967295,0),this[a]=s>>>24,this[a+1]=s>>>16,this[a+2]=s>>>8,this[a+3]=s&255,a+4};function Se(c,s,a,h,y){p(s,h,y,c,a,7);let x=Number(s&BigInt(4294967295));c[a++]=x,x=x>>8,c[a++]=x,x=x>>8,c[a++]=x,x=x>>8,c[a++]=x;let E=Number(s>>BigInt(32)&BigInt(4294967295));return c[a++]=E,E=E>>8,c[a++]=E,E=E>>8,c[a++]=E,E=E>>8,c[a++]=E,a}function Ve(c,s,a,h,y){p(s,h,y,c,a,7);let x=Number(s&BigInt(4294967295));c[a+7]=x,x=x>>8,c[a+6]=x,x=x>>8,c[a+5]=x,x=x>>8,c[a+4]=x;let E=Number(s>>BigInt(32)&BigInt(4294967295));return c[a+3]=E,E=E>>8,c[a+2]=E,E=E>>8,c[a+1]=E,E=E>>8,c[a]=E,a+8}f.prototype.writeBigUInt64LE=Ie(function(s,a=0){return Se(this,s,a,BigInt(0),BigInt("0xffffffffffffffff"))}),f.prototype.writeBigUInt64BE=Ie(function(s,a=0){return Ve(this,s,a,BigInt(0),BigInt("0xffffffffffffffff"))}),f.prototype.writeIntLE=function(s,a,h,y){if(s=+s,a=a>>>0,!y){const ie=Math.pow(2,8*h-1);ue(this,s,a,h,ie-1,-ie)}let x=0,E=1,q=0;for(this[a]=s&255;++x<h&&(E*=256);)s<0&&q===0&&this[a+x-1]!==0&&(q=1),this[a+x]=(s/E>>0)-q&255;return a+h},f.prototype.writeIntBE=function(s,a,h,y){if(s=+s,a=a>>>0,!y){const ie=Math.pow(2,8*h-1);ue(this,s,a,h,ie-1,-ie)}let x=h-1,E=1,q=0;for(this[a+x]=s&255;--x>=0&&(E*=256);)s<0&&q===0&&this[a+x+1]!==0&&(q=1),this[a+x]=(s/E>>0)-q&255;return a+h},f.prototype.writeInt8=function(s,a,h){return s=+s,a=a>>>0,h||ue(this,s,a,1,127,-128),s<0&&(s=255+s+1),this[a]=s&255,a+1},f.prototype.writeInt16LE=function(s,a,h){return s=+s,a=a>>>0,h||ue(this,s,a,2,32767,-32768),this[a]=s&255,this[a+1]=s>>>8,a+2},f.prototype.writeInt16BE=function(s,a,h){return s=+s,a=a>>>0,h||ue(this,s,a,2,32767,-32768),this[a]=s>>>8,this[a+1]=s&255,a+2},f.prototype.writeInt32LE=function(s,a,h){return s=+s,a=a>>>0,h||ue(this,s,a,4,2147483647,-2147483648),this[a]=s&255,this[a+1]=s>>>8,this[a+2]=s>>>16,this[a+3]=s>>>24,a+4},f.prototype.writeInt32BE=function(s,a,h){return s=+s,a=a>>>0,h||ue(this,s,a,4,2147483647,-2147483648),s<0&&(s=4294967295+s+1),this[a]=s>>>24,this[a+1]=s>>>16,this[a+2]=s>>>8,this[a+3]=s&255,a+4},f.prototype.writeBigInt64LE=Ie(function(s,a=0){return Se(this,s,a,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),f.prototype.writeBigInt64BE=Ie(function(s,a=0){return Ve(this,s,a,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Me(c,s,a,h,y,x){if(a+h>c.length)throw new RangeError("Index out of range");if(a<0)throw new RangeError("Index out of range")}function w(c,s,a,h,y){return s=+s,a=a>>>0,y||Me(c,s,a,4),r.write(c,s,a,h,23,4),a+4}f.prototype.writeFloatLE=function(s,a,h){return w(this,s,a,!0,h)},f.prototype.writeFloatBE=function(s,a,h){return w(this,s,a,!1,h)};function _(c,s,a,h,y){return s=+s,a=a>>>0,y||Me(c,s,a,8),r.write(c,s,a,h,52,8),a+8}f.prototype.writeDoubleLE=function(s,a,h){return _(this,s,a,!0,h)},f.prototype.writeDoubleBE=function(s,a,h){return _(this,s,a,!1,h)},f.prototype.copy=function(s,a,h,y){if(!f.isBuffer(s))throw new TypeError("argument should be a Buffer");if(h||(h=0),!y&&y!==0&&(y=this.length),a>=s.length&&(a=s.length),a||(a=0),y>0&&y<h&&(y=h),y===h||s.length===0||this.length===0)return 0;if(a<0)throw new RangeError("targetStart out of bounds");if(h<0||h>=this.length)throw new RangeError("Index out of range");if(y<0)throw new RangeError("sourceEnd out of bounds");y>this.length&&(y=this.length),s.length-a<y-h&&(y=s.length-a+h);const x=y-h;return this===s&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(a,h,y):Uint8Array.prototype.set.call(s,this.subarray(h,y),a),x},f.prototype.fill=function(s,a,h,y){if(typeof s=="string"){if(typeof a=="string"?(y=a,a=0,h=this.length):typeof h=="string"&&(y=h,h=this.length),y!==void 0&&typeof y!="string")throw new TypeError("encoding must be a string");if(typeof y=="string"&&!f.isEncoding(y))throw new TypeError("Unknown encoding: "+y);if(s.length===1){const E=s.charCodeAt(0);(y==="utf8"&&E<128||y==="latin1")&&(s=E)}}else typeof s=="number"?s=s&255:typeof s=="boolean"&&(s=Number(s));if(a<0||this.length<a||this.length<h)throw new RangeError("Out of range index");if(h<=a)return this;a=a>>>0,h=h===void 0?this.length:h>>>0,s||(s=0);let x;if(typeof s=="number")for(x=a;x<h;++x)this[x]=s;else{const E=f.isBuffer(s)?s:f.from(s,y),q=E.length;if(q===0)throw new TypeError('The value "'+s+'" is invalid for argument "value"');for(x=0;x<h-a;++x)this[x+a]=E[x%q]}return this};const R={};function D(c,s,a){R[c]=class extends a{constructor(){super(),Object.defineProperty(this,"message",{value:s.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${c}]`,this.stack,delete this.name}get code(){return c}set code(y){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:y,writable:!0})}toString(){return`${this.name} [${c}]: ${this.message}`}}}D("ERR_BUFFER_OUT_OF_BOUNDS",function(c){return c?`${c} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),D("ERR_INVALID_ARG_TYPE",function(c,s){return`The "${c}" argument must be of type number. Received type ${typeof s}`},TypeError),D("ERR_OUT_OF_RANGE",function(c,s,a){let h=`The value of "${c}" is out of range.`,y=a;return Number.isInteger(a)&&Math.abs(a)>2**32?y=G(String(a)):typeof a=="bigint"&&(y=String(a),(a>BigInt(2)**BigInt(32)||a<-(BigInt(2)**BigInt(32)))&&(y=G(y)),y+="n"),h+=` It must be ${s}. Received ${y}`,h},RangeError);function G(c){let s="",a=c.length;const h=c[0]==="-"?1:0;for(;a>=h+4;a-=3)s=`_${c.slice(a-3,a)}${s}`;return`${c.slice(0,a)}${s}`}function d(c,s,a){T(s,"offset"),(c[s]===void 0||c[s+a]===void 0)&&N(s,c.length-(a+1))}function p(c,s,a,h,y,x){if(c>a||c<s){const E=typeof s=="bigint"?"n":"";let q;throw s===0||s===BigInt(0)?q=`>= 0${E} and < 2${E} ** ${(x+1)*8}${E}`:q=`>= -(2${E} ** ${(x+1)*8-1}${E}) and < 2 ** ${(x+1)*8-1}${E}`,new R.ERR_OUT_OF_RANGE("value",q,c)}d(h,y,x)}function T(c,s){if(typeof c!="number")throw new R.ERR_INVALID_ARG_TYPE(s,"number",c)}function N(c,s,a){throw Math.floor(c)!==c?(T(c,a),new R.ERR_OUT_OF_RANGE("offset","an integer",c)):s<0?new R.ERR_BUFFER_OUT_OF_BOUNDS:new R.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${s}`,c)}const te=/[^+/0-9A-Za-z-_]/g;function j(c){if(c=c.split("=")[0],c=c.trim().replace(te,""),c.length<2)return"";for(;c.length%4!==0;)c=c+"=";return c}function V(c,s){s=s||1/0;let a;const h=c.length;let y=null;const x=[];for(let E=0;E<h;++E){if(a=c.charCodeAt(E),a>55295&&a<57344){if(!y){if(a>56319){(s-=3)>-1&&x.push(239,191,189);continue}else if(E+1===h){(s-=3)>-1&&x.push(239,191,189);continue}y=a;continue}if(a<56320){(s-=3)>-1&&x.push(239,191,189),y=a;continue}a=(y-55296<<10|a-56320)+65536}else y&&(s-=3)>-1&&x.push(239,191,189);if(y=null,a<128){if((s-=1)<0)break;x.push(a)}else if(a<2048){if((s-=2)<0)break;x.push(a>>6|192,a&63|128)}else if(a<65536){if((s-=3)<0)break;x.push(a>>12|224,a>>6&63|128,a&63|128)}else if(a<1114112){if((s-=4)<0)break;x.push(a>>18|240,a>>12&63|128,a>>6&63|128,a&63|128)}else throw new Error("Invalid code point")}return x}function Ke(c){const s=[];for(let a=0;a<c.length;++a)s.push(c.charCodeAt(a)&255);return s}function yt(c,s){let a,h,y;const x=[];for(let E=0;E<c.length&&!((s-=2)<0);++E)a=c.charCodeAt(E),h=a>>8,y=a%256,x.push(y),x.push(h);return x}function Lt(c){return t.toByteArray(j(c))}function gt(c,s,a,h){let y;for(y=0;y<h&&!(y+a>=s.length||y>=c.length);++y)s[y+a]=c[y];return y}function Ae(c,s){return c instanceof s||c!=null&&c.constructor!=null&&c.constructor.name!=null&&c.constructor.name===s.name}function nt(c){return c!==c}const Ot=function(){const c="0123456789abcdef",s=new Array(256);for(let a=0;a<16;++a){const h=a*16;for(let y=0;y<16;++y)s[h+y]=c[a]+c[y]}return s}();function Ie(c){return typeof BigInt>"u"?it:c}function it(){throw new Error("BigInt not supported")}})(Rt);/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */(function(e,t){var r=Rt,n=r.Buffer;function i(u,f){for(var l in u)f[l]=u[l]}n.from&&n.alloc&&n.allocUnsafe&&n.allocUnsafeSlow?e.exports=r:(i(r,t),t.Buffer=o);function o(u,f,l){return n(u,f,l)}o.prototype=Object.create(n.prototype),i(n,o),o.from=function(u,f,l){if(typeof u=="number")throw new TypeError("Argument must not be a number");return n(u,f,l)},o.alloc=function(u,f,l){if(typeof u!="number")throw new TypeError("Argument must be a number");var b=n(u);return f!==void 0?typeof l=="string"?b.fill(f,l):b.fill(f):b.fill(0),b},o.allocUnsafe=function(u){if(typeof u!="number")throw new TypeError("Argument must be a number");return n(u)},o.allocUnsafeSlow=function(u){if(typeof u!="number")throw new TypeError("Argument must be a number");return r.SlowBuffer(u)}})(nn,nn.exports);var ve=nn.exports,Mr=65536,Io=4294967295;function To(){throw new Error(`Secure random number generation is not supported by this browser.
28
+ Use Chrome, Firefox or Internet Explorer 11`)}var Ro=ve.Buffer,dr=Qe.crypto||Qe.msCrypto;dr&&dr.getRandomValues?rn.exports=ko:rn.exports=To;function ko(e,t){if(e>Io)throw new RangeError("requested too many random bytes");var r=Ro.allocUnsafe(e);if(e>0)if(e>Mr)for(var n=0;n<e;n+=Mr)dr.getRandomValues(r.slice(n,n+Mr));else dr.getRandomValues(r);return typeof t=="function"?process.nextTick(function(){t(null,r)}):r}var Co=rn.exports,sn={exports:{}};typeof Object.create=="function"?sn.exports=function(t,r){r&&(t.super_=r,t.prototype=Object.create(r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}))}:sn.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=sn.exports,on={exports:{}},_n={exports:{}},Et=typeof Reflect=="object"?Reflect:null,Nn=Et&&typeof Et.apply=="function"?Et.apply:function(t,r,n){return Function.prototype.apply.call(t,r,n)},cr;Et&&typeof Et.ownKeys=="function"?cr=Et.ownKeys:Object.getOwnPropertySymbols?cr=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:cr=function(t){return Object.getOwnPropertyNames(t)};function Po(e){console&&console.warn&&console.warn(e)}var Oi=Number.isNaN||function(t){return t!==t};function K(){K.init.call(this)}_n.exports=K;_n.exports.once=Uo;K.EventEmitter=K;K.prototype._events=void 0;K.prototype._eventsCount=0;K.prototype._maxListeners=void 0;var Mn=10;function vr(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 Mn},set:function(e){if(typeof e!="number"||e<0||Oi(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");Mn=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||Oi(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 Fi(e){return e._maxListeners===void 0?K.defaultMaxListeners:e._maxListeners}K.prototype.getMaxListeners=function(){return Fi(this)};K.prototype.emit=function(t){for(var r=[],n=1;n<arguments.length;n++)r.push(arguments[n]);var i=t==="error",o=this._events;if(o!==void 0)i=i&&o.error===void 0;else if(!i)return!1;if(i){var u;if(r.length>0&&(u=r[0]),u instanceof Error)throw u;var f=new Error("Unhandled error."+(u?" ("+u.message+")":""));throw f.context=u,f}var l=o[t];if(l===void 0)return!1;if(typeof l=="function")Nn(l,this,r);else for(var b=l.length,g=$i(l,b),n=0;n<b;++n)Nn(g[n],this,r);return!0};function Ui(e,t,r,n){var i,o,u;if(vr(r),o=e._events,o===void 0?(o=e._events=Object.create(null),e._eventsCount=0):(o.newListener!==void 0&&(e.emit("newListener",t,r.listener?r.listener:r),o=e._events),u=o[t]),u===void 0)u=o[t]=r,++e._eventsCount;else if(typeof u=="function"?u=o[t]=n?[r,u]:[u,r]:n?u.unshift(r):u.push(r),i=Fi(e),i>0&&u.length>i&&!u.warned){u.warned=!0;var f=new Error("Possible EventEmitter memory leak detected. "+u.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");f.name="MaxListenersExceededWarning",f.emitter=e,f.type=t,f.count=u.length,Po(f)}return e}K.prototype.addListener=function(t,r){return Ui(this,t,r,!1)};K.prototype.on=K.prototype.addListener;K.prototype.prependListener=function(t,r){return Ui(this,t,r,!0)};function Lo(){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 Ni(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},i=Lo.bind(n);return i.listener=r,n.wrapFn=i,i}K.prototype.once=function(t,r){return vr(r),this.on(t,Ni(this,t,r)),this};K.prototype.prependOnceListener=function(t,r){return vr(r),this.prependListener(t,Ni(this,t,r)),this};K.prototype.removeListener=function(t,r){var n,i,o,u,f;if(vr(r),i=this._events,i===void 0)return this;if(n=i[t],n===void 0)return this;if(n===r||n.listener===r)--this._eventsCount===0?this._events=Object.create(null):(delete i[t],i.removeListener&&this.emit("removeListener",t,n.listener||r));else if(typeof n!="function"){for(o=-1,u=n.length-1;u>=0;u--)if(n[u]===r||n[u].listener===r){f=n[u].listener,o=u;break}if(o<0)return this;o===0?n.shift():Oo(n,o),n.length===1&&(i[t]=n[0]),i.removeListener!==void 0&&this.emit("removeListener",t,f||r)}return this};K.prototype.off=K.prototype.removeListener;K.prototype.removeAllListeners=function(t){var r,n,i;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 o=Object.keys(n),u;for(i=0;i<o.length;++i)u=o[i],u!=="removeListener"&&this.removeAllListeners(u);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(i=r.length-1;i>=0;i--)this.removeListener(t,r[i]);return this};function Mi(e,t,r){var n=e._events;if(n===void 0)return[];var i=n[t];return i===void 0?[]:typeof i=="function"?r?[i.listener||i]:[i]:r?Fo(i):$i(i,i.length)}K.prototype.listeners=function(t){return Mi(this,t,!0)};K.prototype.rawListeners=function(t){return Mi(this,t,!1)};K.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):Di.call(e,t)};K.prototype.listenerCount=Di;function Di(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?cr(this._events):[]};function $i(e,t){for(var r=new Array(t),n=0;n<t;++n)r[n]=e[n];return r}function Oo(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 i(u){e.removeListener(t,o),n(u)}function o(){typeof e.removeListener=="function"&&e.removeListener("error",i),r([].slice.call(arguments))}Hi(e,t,o,{once:!0}),t!=="error"&&No(e,i,{once:!0})})}function No(e,t,r){typeof e.on=="function"&&Hi(e,"error",t,r)}function Hi(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 i(o){n.once&&e.removeEventListener(t,i),r(o)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e)}var zi=_n.exports,Gi=zi.EventEmitter;const Mo={},Do=Object.freeze(Object.defineProperty({__proto__:null,default:Mo},Symbol.toStringTag,{value:"Module"})),wn=co(Do);var Dr,Dn;function $o(){if(Dn)return Dr;Dn=1;function e(I,k){var C=Object.keys(I);if(Object.getOwnPropertySymbols){var P=Object.getOwnPropertySymbols(I);k&&(P=P.filter(function(F){return Object.getOwnPropertyDescriptor(I,F).enumerable})),C.push.apply(C,P)}return C}function t(I){for(var k=1;k<arguments.length;k++){var C=arguments[k]!=null?arguments[k]:{};k%2?e(Object(C),!0).forEach(function(P){r(I,P,C[P])}):Object.getOwnPropertyDescriptors?Object.defineProperties(I,Object.getOwnPropertyDescriptors(C)):e(Object(C)).forEach(function(P){Object.defineProperty(I,P,Object.getOwnPropertyDescriptor(C,P))})}return I}function r(I,k,C){return k=u(k),k in I?Object.defineProperty(I,k,{value:C,enumerable:!0,configurable:!0,writable:!0}):I[k]=C,I}function n(I,k){if(!(I instanceof k))throw new TypeError("Cannot call a class as a function")}function i(I,k){for(var C=0;C<k.length;C++){var P=k[C];P.enumerable=P.enumerable||!1,P.configurable=!0,"value"in P&&(P.writable=!0),Object.defineProperty(I,u(P.key),P)}}function o(I,k,C){return k&&i(I.prototype,k),Object.defineProperty(I,"prototype",{writable:!1}),I}function u(I){var k=f(I,"string");return typeof k=="symbol"?k:String(k)}function f(I,k){if(typeof I!="object"||I===null)return I;var C=I[Symbol.toPrimitive];if(C!==void 0){var P=C.call(I,k||"default");if(typeof P!="object")return P;throw new TypeError("@@toPrimitive must return a primitive value.")}return(k==="string"?String:Number)(I)}var l=Rt,b=l.Buffer,g=wn,m=g.inspect,v=m&&m.custom||"inspect";function A(I,k,C){b.prototype.copy.call(I,k,C)}return Dr=function(){function I(){n(this,I),this.head=null,this.tail=null,this.length=0}return o(I,[{key:"push",value:function(C){var P={data:C,next:null};this.length>0?this.tail.next=P:this.head=P,this.tail=P,++this.length}},{key:"unshift",value:function(C){var P={data:C,next:this.head};this.length===0&&(this.tail=P),this.head=P,++this.length}},{key:"shift",value:function(){if(this.length!==0){var C=this.head.data;return this.length===1?this.head=this.tail=null:this.head=this.head.next,--this.length,C}}},{key:"clear",value:function(){this.head=this.tail=null,this.length=0}},{key:"join",value:function(C){if(this.length===0)return"";for(var P=this.head,F=""+P.data;P=P.next;)F+=C+P.data;return F}},{key:"concat",value:function(C){if(this.length===0)return b.alloc(0);for(var P=b.allocUnsafe(C>>>0),F=this.head,O=0;F;)A(F.data,P,O),O+=F.data.length,F=F.next;return P}},{key:"consume",value:function(C,P){var F;return C<this.head.data.length?(F=this.head.data.slice(0,C),this.head.data=this.head.data.slice(C)):C===this.head.data.length?F=this.shift():F=P?this._getString(C):this._getBuffer(C),F}},{key:"first",value:function(){return this.head.data}},{key:"_getString",value:function(C){var P=this.head,F=1,O=P.data;for(C-=O.length;P=P.next;){var L=P.data,U=C>L.length?L.length:C;if(U===L.length?O+=L:O+=L.slice(0,C),C-=U,C===0){U===L.length?(++F,P.next?this.head=P.next:this.head=this.tail=null):(this.head=P,P.data=L.slice(U));break}++F}return this.length-=F,O}},{key:"_getBuffer",value:function(C){var P=b.allocUnsafe(C),F=this.head,O=1;for(F.data.copy(P),C-=F.data.length;F=F.next;){var L=F.data,U=C>L.length?L.length:C;if(L.copy(P,P.length-C,0,U),C-=U,C===0){U===L.length?(++O,F.next?this.head=F.next:this.head=this.tail=null):(this.head=F,F.data=L.slice(U));break}++O}return this.length-=O,P}},{key:v,value:function(C,P){return m(this,t(t({},P),{},{depth:0,customInspect:!1}))}}]),I}(),Dr}function Ho(e,t){var r=this,n=this._readableState&&this._readableState.destroyed,i=this._writableState&&this._writableState.destroyed;return n||i?(t?t(e):e&&(this._writableState?this._writableState.errorEmitted||(this._writableState.errorEmitted=!0,process.nextTick(an,this,e)):process.nextTick(an,this,e)),this):(this._readableState&&(this._readableState.destroyed=!0),this._writableState&&(this._writableState.destroyed=!0),this._destroy(e||null,function(o){!t&&o?r._writableState?r._writableState.errorEmitted?process.nextTick(lr,r):(r._writableState.errorEmitted=!0,process.nextTick($n,r,o)):process.nextTick($n,r,o):t?(process.nextTick(lr,r),t(o)):process.nextTick(lr,r)}),this)}function $n(e,t){an(e,t),lr(e)}function lr(e){e._writableState&&!e._writableState.emitClose||e._readableState&&!e._readableState.emitClose||e.emit("close")}function zo(){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 an(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 ji={destroy:Ho,undestroy:zo,errorOrDestroy:Go},dt={};function jo(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var Wi={};function Re(e,t,r){r||(r=Error);function n(o,u,f){return typeof t=="string"?t:t(o,u,f)}var i=function(o){jo(u,o);function u(f,l,b){return o.call(this,n(f,l,b))||this}return u}(r);i.prototype.name=r.name,i.prototype.code=e,Wi[e]=i}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 Wo(e,t,r){return e.substr(0,t.length)===t}function qo(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}Re("ERR_INVALID_OPT_VALUE",function(e,t){return'The value "'+t+'" is invalid for option "'+e+'"'},TypeError);Re("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 i;if(qo(e," argument"))i="The ".concat(e," ").concat(n," ").concat(Hn(t,"type"));else{var o=Vo(e,".")?"property":"argument";i='The "'.concat(e,'" ').concat(o," ").concat(n," ").concat(Hn(t,"type"))}return i+=". Received type ".concat(typeof r),i},TypeError);Re("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF");Re("ERR_METHOD_NOT_IMPLEMENTED",function(e){return"The "+e+" method is not implemented"});Re("ERR_STREAM_PREMATURE_CLOSE","Premature close");Re("ERR_STREAM_DESTROYED",function(e){return"Cannot call "+e+" after a stream was destroyed"});Re("ERR_MULTIPLE_CALLBACK","Callback called multiple times");Re("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable");Re("ERR_STREAM_WRITE_AFTER_END","write after end");Re("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError);Re("ERR_UNKNOWN_ENCODING",function(e){return"Unknown encoding: "+e},TypeError);Re("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event");dt.codes=Wi;var Ko=dt.codes.ERR_INVALID_OPT_VALUE;function Yo(e,t,r){return e.highWaterMark!=null?e.highWaterMark:t?e[r]:null}function Jo(e,t,r,n){var i=Yo(t,n,r);if(i!=null){if(!(isFinite(i)&&Math.floor(i)===i)||i<0){var o=n?r:"highWaterMark";throw new Ko(o,i)}return Math.floor(i)}return e.objectMode?16:16*1024}var qi={getHighWaterMark:Jo},Xo=Qo;function Qo(e,t){if($r("noDeprecation"))return e;var r=!1;function n(){if(!r){if($r("throwDeprecation"))throw new Error(t);$r("traceDeprecation")?console.trace(t):console.warn(t),r=!0}return e.apply(this,arguments)}return n}function $r(e){try{if(!Qe.localStorage)return!1}catch{return!1}var t=Qe.localStorage[e];return t==null?!1:String(t).toLowerCase()==="true"}var Hr,zn;function Vi(){if(zn)return Hr;zn=1,Hr=M;function e(w){var _=this;this.next=null,this.entry=null,this.finish=function(){Me(_,w)}}var t;M.WritableState=B;var r={deprecate:Xo},n=Gi,i=Rt.Buffer,o=(typeof Qe<"u"?Qe:typeof window<"u"?window:typeof self<"u"?self:{}).Uint8Array||function(){};function u(w){return i.from(w)}function f(w){return i.isBuffer(w)||w instanceof o}var l=ji,b=qi,g=b.getHighWaterMark,m=dt.codes,v=m.ERR_INVALID_ARG_TYPE,A=m.ERR_METHOD_NOT_IMPLEMENTED,I=m.ERR_MULTIPLE_CALLBACK,k=m.ERR_STREAM_CANNOT_PIPE,C=m.ERR_STREAM_DESTROYED,P=m.ERR_STREAM_NULL_VALUES,F=m.ERR_STREAM_WRITE_AFTER_END,O=m.ERR_UNKNOWN_ENCODING,L=l.errorOrDestroy;pe(M,n);function U(){}function B(w,_,R){t=t||It(),w=w||{},typeof R!="boolean"&&(R=_ instanceof t),this.objectMode=!!w.objectMode,R&&(this.objectMode=this.objectMode||!!w.writableObjectMode),this.highWaterMark=g(this,w,"writableHighWaterMark",R),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var D=w.decodeStrings===!1;this.decodeStrings=!D,this.defaultEncoding=w.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(G){rt(_,G)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=w.emitClose!==!1,this.autoDestroy=!!w.autoDestroy,this.bufferedRequestCount=0,this.corkedRequestsFree=new e(this)}B.prototype.getBuffer=function(){for(var _=this.bufferedRequest,R=[];_;)R.push(_),_=_.next;return R},function(){try{Object.defineProperty(B.prototype,"buffer",{get:r.deprecate(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch{}}();var z;typeof Symbol=="function"&&Symbol.hasInstance&&typeof Function.prototype[Symbol.hasInstance]=="function"?(z=Function.prototype[Symbol.hasInstance],Object.defineProperty(M,Symbol.hasInstance,{value:function(_){return z.call(this,_)?!0:this!==M?!1:_&&_._writableState instanceof B}})):z=function(_){return _ instanceof this};function M(w){t=t||It();var _=this instanceof t;if(!_&&!z.call(M,this))return new M(w);this._writableState=new B(w,this,_),this.writable=!0,w&&(typeof w.write=="function"&&(this._write=w.write),typeof w.writev=="function"&&(this._writev=w.writev),typeof w.destroy=="function"&&(this._destroy=w.destroy),typeof w.final=="function"&&(this._final=w.final)),n.call(this)}M.prototype.pipe=function(){L(this,new k)};function $(w,_){var R=new F;L(w,R),process.nextTick(_,R)}function fe(w,_,R,D){var G;return R===null?G=new P:typeof R!="string"&&!_.objectMode&&(G=new v("chunk",["string","Buffer"],R)),G?(L(w,G),process.nextTick(D,G),!1):!0}M.prototype.write=function(w,_,R){var D=this._writableState,G=!1,d=!D.objectMode&&f(w);return d&&!i.isBuffer(w)&&(w=u(w)),typeof _=="function"&&(R=_,_=null),d?_="buffer":_||(_=D.defaultEncoding),typeof R!="function"&&(R=U),D.ending?$(this,R):(d||fe(this,D,w,R))&&(D.pendingcb++,G=je(this,D,d,w,_,R)),G},M.prototype.cork=function(){this._writableState.corked++},M.prototype.uncork=function(){var w=this._writableState;w.corked&&(w.corked--,!w.writing&&!w.corked&&!w.bufferProcessing&&w.bufferedRequest&&Pe(this,w))},M.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 O(_);return this._writableState.defaultEncoding=_,this},Object.defineProperty(M.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}});function ke(w,_,R){return!w.objectMode&&w.decodeStrings!==!1&&typeof _=="string"&&(_=i.from(_,R)),_}Object.defineProperty(M.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}});function je(w,_,R,D,G,d){if(!R){var p=ke(_,D,G);D!==p&&(R=!0,G="buffer",D=p)}var T=_.objectMode?1:D.length;_.length+=T;var N=_.length<_.highWaterMark;if(N||(_.needDrain=!0),_.writing||_.corked){var te=_.lastBufferedRequest;_.lastBufferedRequest={chunk:D,encoding:G,isBuf:R,callback:d,next:null},te?te.next=_.lastBufferedRequest:_.bufferedRequest=_.lastBufferedRequest,_.bufferedRequestCount+=1}else ce(w,_,!1,T,D,G,d);return N}function ce(w,_,R,D,G,d,p){_.writelen=D,_.writecb=p,_.writing=!0,_.sync=!0,_.destroyed?_.onwrite(new C("write")):R?w._writev(G,_.onwrite):w._write(G,d,_.onwrite),_.sync=!1}function Ee(w,_,R,D,G){--_.pendingcb,R?(process.nextTick(G,D),process.nextTick(Se,w,_),w._writableState.errorEmitted=!0,L(w,D)):(G(D),w._writableState.errorEmitted=!0,L(w,D),Se(w,_))}function Be(w){w.writing=!1,w.writecb=null,w.length-=w.writelen,w.writelen=0}function rt(w,_){var R=w._writableState,D=R.sync,G=R.writecb;if(typeof G!="function")throw new I;if(Be(R),_)Ee(w,R,D,_,G);else{var d=qe(R)||w.destroyed;!d&&!R.corked&&!R.bufferProcessing&&R.bufferedRequest&&Pe(w,R),D?process.nextTick(Ce,w,R,d,G):Ce(w,R,d,G)}}function Ce(w,_,R,D){R||We(w,_),_.pendingcb--,D(),Se(w,_)}function We(w,_){_.length===0&&_.needDrain&&(_.needDrain=!1,w.emit("drain"))}function Pe(w,_){_.bufferProcessing=!0;var R=_.bufferedRequest;if(w._writev&&R&&R.next){var D=_.bufferedRequestCount,G=new Array(D),d=_.corkedRequestsFree;d.entry=R;for(var p=0,T=!0;R;)G[p]=R,R.isBuf||(T=!1),R=R.next,p+=1;G.allBuffers=T,ce(w,_,!0,_.length,G,"",d.finish),_.pendingcb++,_.lastBufferedRequest=null,d.next?(_.corkedRequestsFree=d.next,d.next=null):_.corkedRequestsFree=new e(_),_.bufferedRequestCount=0}else{for(;R;){var N=R.chunk,te=R.encoding,j=R.callback,V=_.objectMode?1:N.length;if(ce(w,_,!1,V,N,te,j),R=R.next,_.bufferedRequestCount--,_.writing)break}R===null&&(_.lastBufferedRequest=null)}_.bufferedRequest=R,_.bufferProcessing=!1}M.prototype._write=function(w,_,R){R(new A("_write()"))},M.prototype._writev=null,M.prototype.end=function(w,_,R){var D=this._writableState;return typeof w=="function"?(R=w,w=null,_=null):typeof _=="function"&&(R=_,_=null),w!=null&&this.write(w,_),D.corked&&(D.corked=1,this.uncork()),D.ending||Ve(this,D,R),this},Object.defineProperty(M.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}});function qe(w){return w.ending&&w.length===0&&w.bufferedRequest===null&&!w.finished&&!w.writing}function ee(w,_){w._final(function(R){_.pendingcb--,R&&L(w,R),_.prefinished=!0,w.emit("prefinish"),Se(w,_)})}function ue(w,_){!_.prefinished&&!_.finalCalled&&(typeof w._final=="function"&&!_.destroyed?(_.pendingcb++,_.finalCalled=!0,process.nextTick(ee,w,_)):(_.prefinished=!0,w.emit("prefinish")))}function Se(w,_){var R=qe(_);if(R&&(ue(w,_),_.pendingcb===0&&(_.finished=!0,w.emit("finish"),_.autoDestroy))){var D=w._readableState;(!D||D.autoDestroy&&D.endEmitted)&&w.destroy()}return R}function Ve(w,_,R){_.ending=!0,Se(w,_),R&&(_.finished?process.nextTick(R):w.once("finish",R)),_.ended=!0,w.writable=!1}function Me(w,_,R){var D=w.entry;for(w.entry=null;D;){var G=D.callback;_.pendingcb--,G(R),D=D.next}_.corkedRequestsFree.next=w}return Object.defineProperty(M.prototype,"destroyed",{enumerable:!1,get:function(){return this._writableState===void 0?!1:this._writableState.destroyed},set:function(_){this._writableState&&(this._writableState.destroyed=_)}}),M.prototype.destroy=l.destroy,M.prototype._undestroy=l.undestroy,M.prototype._destroy=function(w,_){_(w)},Hr}var zr,Gn;function It(){if(Gn)return zr;Gn=1;var e=Object.keys||function(b){var g=[];for(var m in b)g.push(m);return g};zr=u;var t=Yi(),r=Vi();pe(u,t);for(var n=e(r.prototype),i=0;i<n.length;i++){var o=n[i];u.prototype[o]||(u.prototype[o]=r.prototype[o])}function u(b){if(!(this instanceof u))return new u(b);t.call(this,b),r.call(this,b),this.allowHalfOpen=!0,b&&(b.readable===!1&&(this.readable=!1),b.writable===!1&&(this.writable=!1),b.allowHalfOpen===!1&&(this.allowHalfOpen=!1,this.once("end",f)))}Object.defineProperty(u.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),Object.defineProperty(u.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(u.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}});function f(){this._writableState.ended||process.nextTick(l,this)}function l(b){b.end()}return Object.defineProperty(u.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)}}),zr}var pr={},xn=ve.Buffer,jn=xn.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 Zo(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 ea(e){var t=Zo(e);if(typeof t!="string"&&(xn.isEncoding===jn||!jn(e)))throw new Error("Unknown encoding: "+e);return t||e}pr.StringDecoder=Qt;function Qt(e){this.encoding=ea(e);var t;switch(this.encoding){case"utf16le":this.text=oa,this.end=aa,t=4;break;case"utf8":this.fillLast=na,t=4;break;case"base64":this.text=fa,this.end=ua,t=3;break;default:this.write=ca,this.end=la;return}this.lastNeed=0,this.lastTotal=0,this.lastChar=xn.allocUnsafe(t)}Qt.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||""};Qt.prototype.end=sa;Qt.prototype.text=ia;Qt.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 Gr(e){return e<=127?0:e>>5===6?2:e>>4===14?3:e>>3===30?4:e>>6===2?-1:-2}function ta(e,t,r){var n=t.length-1;if(n<r)return 0;var i=Gr(t[n]);return i>=0?(i>0&&(e.lastNeed=i-1),i):--n<r||i===-2?0:(i=Gr(t[n]),i>=0?(i>0&&(e.lastNeed=i-2),i):--n<r||i===-2?0:(i=Gr(t[n]),i>=0?(i>0&&(i===2?i=0:e.lastNeed=i-3),i):0))}function ra(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 na(e){var t=this.lastTotal-this.lastNeed,r=ra(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 ia(e,t){var r=ta(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 sa(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+"�":t}function oa(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 aa(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 fa(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 ua(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+this.lastChar.toString("base64",0,3-this.lastNeed):t}function ca(e){return e.toString(this.encoding)}function la(e){return e&&e.length?this.write(e):""}var Wn=dt.codes.ERR_STREAM_PREMATURE_CLOSE;function ha(e){var t=!1;return function(){if(!t){t=!0;for(var r=arguments.length,n=new Array(r),i=0;i<r;i++)n[i]=arguments[i];e.apply(this,n)}}}function da(){}function pa(e){return e.setHeader&&typeof e.abort=="function"}function Ki(e,t,r){if(typeof t=="function")return Ki(e,null,t);t||(t={}),r=ha(r||da);var n=t.readable||t.readable!==!1&&e.readable,i=t.writable||t.writable!==!1&&e.writable,o=function(){e.writable||f()},u=e._writableState&&e._writableState.finished,f=function(){i=!1,u=!0,n||r.call(e)},l=e._readableState&&e._readableState.endEmitted,b=function(){n=!1,l=!0,i||r.call(e)},g=function(I){r.call(e,I)},m=function(){var I;if(n&&!l)return(!e._readableState||!e._readableState.ended)&&(I=new Wn),r.call(e,I);if(i&&!u)return(!e._writableState||!e._writableState.ended)&&(I=new Wn),r.call(e,I)},v=function(){e.req.on("finish",f)};return pa(e)?(e.on("complete",f),e.on("abort",m),e.req?v():e.on("request",v)):i&&!e._writableState&&(e.on("end",o),e.on("close",o)),e.on("end",b),e.on("finish",f),t.error!==!1&&e.on("error",g),e.on("close",m),function(){e.removeListener("complete",f),e.removeListener("abort",m),e.removeListener("request",v),e.req&&e.req.removeListener("finish",f),e.removeListener("end",o),e.removeListener("close",o),e.removeListener("finish",f),e.removeListener("end",b),e.removeListener("error",g),e.removeListener("close",m)}}var vn=Ki,jr,qn;function ba(){if(qn)return jr;qn=1;var e;function t(O,L,U){return L=r(L),L in O?Object.defineProperty(O,L,{value:U,enumerable:!0,configurable:!0,writable:!0}):O[L]=U,O}function r(O){var L=n(O,"string");return typeof L=="symbol"?L:String(L)}function n(O,L){if(typeof O!="object"||O===null)return O;var U=O[Symbol.toPrimitive];if(U!==void 0){var B=U.call(O,L||"default");if(typeof B!="object")return B;throw new TypeError("@@toPrimitive must return a primitive value.")}return(L==="string"?String:Number)(O)}var i=vn,o=Symbol("lastResolve"),u=Symbol("lastReject"),f=Symbol("error"),l=Symbol("ended"),b=Symbol("lastPromise"),g=Symbol("handlePromise"),m=Symbol("stream");function v(O,L){return{value:O,done:L}}function A(O){var L=O[o];if(L!==null){var U=O[m].read();U!==null&&(O[b]=null,O[o]=null,O[u]=null,L(v(U,!1)))}}function I(O){process.nextTick(A,O)}function k(O,L){return function(U,B){O.then(function(){if(L[l]){U(v(void 0,!0));return}L[g](U,B)},B)}}var C=Object.getPrototypeOf(function(){}),P=Object.setPrototypeOf((e={get stream(){return this[m]},next:function(){var L=this,U=this[f];if(U!==null)return Promise.reject(U);if(this[l])return Promise.resolve(v(void 0,!0));if(this[m].destroyed)return new Promise(function($,fe){process.nextTick(function(){L[f]?fe(L[f]):$(v(void 0,!0))})});var B=this[b],z;if(B)z=new Promise(k(B,this));else{var M=this[m].read();if(M!==null)return Promise.resolve(v(M,!1));z=new Promise(this[g])}return this[b]=z,z}},t(e,Symbol.asyncIterator,function(){return this}),t(e,"return",function(){var L=this;return new Promise(function(U,B){L[m].destroy(null,function(z){if(z){B(z);return}U(v(void 0,!0))})})}),e),C),F=function(L){var U,B=Object.create(P,(U={},t(U,m,{value:L,writable:!0}),t(U,o,{value:null,writable:!0}),t(U,u,{value:null,writable:!0}),t(U,f,{value:null,writable:!0}),t(U,l,{value:L._readableState.endEmitted,writable:!0}),t(U,g,{value:function(M,$){var fe=B[m].read();fe?(B[b]=null,B[o]=null,B[u]=null,M(v(fe,!1))):(B[o]=M,B[u]=$)},writable:!0}),U));return B[b]=null,i(L,function(z){if(z&&z.code!=="ERR_STREAM_PREMATURE_CLOSE"){var M=B[u];M!==null&&(B[b]=null,B[o]=null,B[u]=null,M(z)),B[f]=z;return}var $=B[o];$!==null&&(B[b]=null,B[o]=null,B[u]=null,$(v(void 0,!0))),B[l]=!0}),L.on("readable",I.bind(null,B)),B};return jr=F,jr}var Wr,Vn;function ya(){return Vn||(Vn=1,Wr=function(){throw new Error("Readable.from is not available in the browser")}),Wr}var qr,Kn;function Yi(){if(Kn)return qr;Kn=1,qr=$;var e;$.ReadableState=M,zi.EventEmitter;var t=function(p,T){return p.listeners(T).length},r=Gi,n=Rt.Buffer,i=(typeof Qe<"u"?Qe:typeof window<"u"?window:typeof self<"u"?self:{}).Uint8Array||function(){};function o(d){return n.from(d)}function u(d){return n.isBuffer(d)||d instanceof i}var f=wn,l;f&&f.debuglog?l=f.debuglog("stream"):l=function(){};var b=$o(),g=ji,m=qi,v=m.getHighWaterMark,A=dt.codes,I=A.ERR_INVALID_ARG_TYPE,k=A.ERR_STREAM_PUSH_AFTER_EOF,C=A.ERR_METHOD_NOT_IMPLEMENTED,P=A.ERR_STREAM_UNSHIFT_AFTER_END_EVENT,F,O,L;pe($,r);var U=g.errorOrDestroy,B=["error","close","destroy","pause","resume"];function z(d,p,T){if(typeof d.prependListener=="function")return d.prependListener(p,T);!d._events||!d._events[p]?d.on(p,T):Array.isArray(d._events[p])?d._events[p].unshift(T):d._events[p]=[T,d._events[p]]}function M(d,p,T){e=e||It(),d=d||{},typeof T!="boolean"&&(T=p instanceof e),this.objectMode=!!d.objectMode,T&&(this.objectMode=this.objectMode||!!d.readableObjectMode),this.highWaterMark=v(this,d,"readableHighWaterMark",T),this.buffer=new b,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=d.emitClose!==!1,this.autoDestroy=!!d.autoDestroy,this.destroyed=!1,this.defaultEncoding=d.defaultEncoding||"utf8",this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,d.encoding&&(F||(F=pr.StringDecoder),this.decoder=new F(d.encoding),this.encoding=d.encoding)}function $(d){if(e=e||It(),!(this instanceof $))return new $(d);var p=this instanceof e;this._readableState=new M(d,this,p),this.readable=!0,d&&(typeof d.read=="function"&&(this._read=d.read),typeof d.destroy=="function"&&(this._destroy=d.destroy)),r.call(this)}Object.defineProperty($.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState===void 0?!1:this._readableState.destroyed},set:function(p){this._readableState&&(this._readableState.destroyed=p)}}),$.prototype.destroy=g.destroy,$.prototype._undestroy=g.undestroy,$.prototype._destroy=function(d,p){p(d)},$.prototype.push=function(d,p){var T=this._readableState,N;return T.objectMode?N=!0:typeof d=="string"&&(p=p||T.defaultEncoding,p!==T.encoding&&(d=n.from(d,p),p=""),N=!0),fe(this,d,p,!1,N)},$.prototype.unshift=function(d){return fe(this,d,null,!0,!1)};function fe(d,p,T,N,te){l("readableAddChunk",p);var j=d._readableState;if(p===null)j.reading=!1,rt(d,j);else{var V;if(te||(V=je(j,p)),V)U(d,V);else if(j.objectMode||p&&p.length>0)if(typeof p!="string"&&!j.objectMode&&Object.getPrototypeOf(p)!==n.prototype&&(p=o(p)),N)j.endEmitted?U(d,new P):ke(d,j,p,!0);else if(j.ended)U(d,new k);else{if(j.destroyed)return!1;j.reading=!1,j.decoder&&!T?(p=j.decoder.write(p),j.objectMode||p.length!==0?ke(d,j,p,!1):Pe(d,j)):ke(d,j,p,!1)}else N||(j.reading=!1,Pe(d,j))}return!j.ended&&(j.length<j.highWaterMark||j.length===0)}function ke(d,p,T,N){p.flowing&&p.length===0&&!p.sync?(p.awaitDrain=0,d.emit("data",T)):(p.length+=p.objectMode?1:T.length,N?p.buffer.unshift(T):p.buffer.push(T),p.needReadable&&Ce(d)),Pe(d,p)}function je(d,p){var T;return!u(p)&&typeof p!="string"&&p!==void 0&&!d.objectMode&&(T=new I("chunk",["string","Buffer","Uint8Array"],p)),T}$.prototype.isPaused=function(){return this._readableState.flowing===!1},$.prototype.setEncoding=function(d){F||(F=pr.StringDecoder);var p=new F(d);this._readableState.decoder=p,this._readableState.encoding=this._readableState.decoder.encoding;for(var T=this._readableState.buffer.head,N="";T!==null;)N+=p.write(T.data),T=T.next;return this._readableState.buffer.clear(),N!==""&&this._readableState.buffer.push(N),this._readableState.length=N.length,this};var ce=1073741824;function Ee(d){return d>=ce?d=ce:(d--,d|=d>>>1,d|=d>>>2,d|=d>>>4,d|=d>>>8,d|=d>>>16,d++),d}function Be(d,p){return d<=0||p.length===0&&p.ended?0:p.objectMode?1:d!==d?p.flowing&&p.length?p.buffer.head.data.length:p.length:(d>p.highWaterMark&&(p.highWaterMark=Ee(d)),d<=p.length?d:p.ended?p.length:(p.needReadable=!0,0))}$.prototype.read=function(d){l("read",d),d=parseInt(d,10);var p=this._readableState,T=d;if(d!==0&&(p.emittedReadable=!1),d===0&&p.needReadable&&((p.highWaterMark!==0?p.length>=p.highWaterMark:p.length>0)||p.ended))return l("read: emitReadable",p.length,p.ended),p.length===0&&p.ended?R(this):Ce(this),null;if(d=Be(d,p),d===0&&p.ended)return p.length===0&&R(this),null;var N=p.needReadable;l("need readable",N),(p.length===0||p.length-d<p.highWaterMark)&&(N=!0,l("length less than watermark",N)),p.ended||p.reading?(N=!1,l("reading or ended",N)):N&&(l("do read"),p.reading=!0,p.sync=!0,p.length===0&&(p.needReadable=!0),this._read(p.highWaterMark),p.sync=!1,p.reading||(d=Be(T,p)));var te;return d>0?te=_(d,p):te=null,te===null?(p.needReadable=p.length<=p.highWaterMark,d=0):(p.length-=d,p.awaitDrain=0),p.length===0&&(p.ended||(p.needReadable=!0),T!==d&&p.ended&&R(this)),te!==null&&this.emit("data",te),te};function rt(d,p){if(l("onEofChunk"),!p.ended){if(p.decoder){var T=p.decoder.end();T&&T.length&&(p.buffer.push(T),p.length+=p.objectMode?1:T.length)}p.ended=!0,p.sync?Ce(d):(p.needReadable=!1,p.emittedReadable||(p.emittedReadable=!0,We(d)))}}function Ce(d){var p=d._readableState;l("emitReadable",p.needReadable,p.emittedReadable),p.needReadable=!1,p.emittedReadable||(l("emitReadable",p.flowing),p.emittedReadable=!0,process.nextTick(We,d))}function We(d){var p=d._readableState;l("emitReadable_",p.destroyed,p.length,p.ended),!p.destroyed&&(p.length||p.ended)&&(d.emit("readable"),p.emittedReadable=!1),p.needReadable=!p.flowing&&!p.ended&&p.length<=p.highWaterMark,w(d)}function Pe(d,p){p.readingMore||(p.readingMore=!0,process.nextTick(qe,d,p))}function qe(d,p){for(;!p.reading&&!p.ended&&(p.length<p.highWaterMark||p.flowing&&p.length===0);){var T=p.length;if(l("maybeReadMore read 0"),d.read(0),T===p.length)break}p.readingMore=!1}$.prototype._read=function(d){U(this,new C("_read()"))},$.prototype.pipe=function(d,p){var T=this,N=this._readableState;switch(N.pipesCount){case 0:N.pipes=d;break;case 1:N.pipes=[N.pipes,d];break;default:N.pipes.push(d);break}N.pipesCount+=1,l("pipe count=%d opts=%j",N.pipesCount,p);var te=(!p||p.end!==!1)&&d!==process.stdout&&d!==process.stderr,j=te?Ke:it;N.endEmitted?process.nextTick(j):T.once("end",j),d.on("unpipe",V);function V(c,s){l("onunpipe"),c===T&&s&&s.hasUnpiped===!1&&(s.hasUnpiped=!0,gt())}function Ke(){l("onend"),d.end()}var yt=ee(T);d.on("drain",yt);var Lt=!1;function gt(){l("cleanup"),d.removeListener("close",Ot),d.removeListener("finish",Ie),d.removeListener("drain",yt),d.removeListener("error",nt),d.removeListener("unpipe",V),T.removeListener("end",Ke),T.removeListener("end",it),T.removeListener("data",Ae),Lt=!0,N.awaitDrain&&(!d._writableState||d._writableState.needDrain)&&yt()}T.on("data",Ae);function Ae(c){l("ondata");var s=d.write(c);l("dest.write",s),s===!1&&((N.pipesCount===1&&N.pipes===d||N.pipesCount>1&&G(N.pipes,d)!==-1)&&!Lt&&(l("false write response, pause",N.awaitDrain),N.awaitDrain++),T.pause())}function nt(c){l("onerror",c),it(),d.removeListener("error",nt),t(d,"error")===0&&U(d,c)}z(d,"error",nt);function Ot(){d.removeListener("finish",Ie),it()}d.once("close",Ot);function Ie(){l("onfinish"),d.removeListener("close",Ot),it()}d.once("finish",Ie);function it(){l("unpipe"),T.unpipe(d)}return d.emit("pipe",T),N.flowing||(l("pipe resume"),T.resume()),d};function ee(d){return function(){var T=d._readableState;l("pipeOnDrain",T.awaitDrain),T.awaitDrain&&T.awaitDrain--,T.awaitDrain===0&&t(d,"data")&&(T.flowing=!0,w(d))}}$.prototype.unpipe=function(d){var p=this._readableState,T={hasUnpiped:!1};if(p.pipesCount===0)return this;if(p.pipesCount===1)return d&&d!==p.pipes?this:(d||(d=p.pipes),p.pipes=null,p.pipesCount=0,p.flowing=!1,d&&d.emit("unpipe",this,T),this);if(!d){var N=p.pipes,te=p.pipesCount;p.pipes=null,p.pipesCount=0,p.flowing=!1;for(var j=0;j<te;j++)N[j].emit("unpipe",this,{hasUnpiped:!1});return this}var V=G(p.pipes,d);return V===-1?this:(p.pipes.splice(V,1),p.pipesCount-=1,p.pipesCount===1&&(p.pipes=p.pipes[0]),d.emit("unpipe",this,T),this)},$.prototype.on=function(d,p){var T=r.prototype.on.call(this,d,p),N=this._readableState;return d==="data"?(N.readableListening=this.listenerCount("readable")>0,N.flowing!==!1&&this.resume()):d==="readable"&&!N.endEmitted&&!N.readableListening&&(N.readableListening=N.needReadable=!0,N.flowing=!1,N.emittedReadable=!1,l("on readable",N.length,N.reading),N.length?Ce(this):N.reading||process.nextTick(Se,this)),T},$.prototype.addListener=$.prototype.on,$.prototype.removeListener=function(d,p){var T=r.prototype.removeListener.call(this,d,p);return d==="readable"&&process.nextTick(ue,this),T},$.prototype.removeAllListeners=function(d){var p=r.prototype.removeAllListeners.apply(this,arguments);return(d==="readable"||d===void 0)&&process.nextTick(ue,this),p};function ue(d){var p=d._readableState;p.readableListening=d.listenerCount("readable")>0,p.resumeScheduled&&!p.paused?p.flowing=!0:d.listenerCount("data")>0&&d.resume()}function Se(d){l("readable nexttick read 0"),d.read(0)}$.prototype.resume=function(){var d=this._readableState;return d.flowing||(l("resume"),d.flowing=!d.readableListening,Ve(this,d)),d.paused=!1,this};function Ve(d,p){p.resumeScheduled||(p.resumeScheduled=!0,process.nextTick(Me,d,p))}function Me(d,p){l("resume",p.reading),p.reading||d.read(0),p.resumeScheduled=!1,d.emit("resume"),w(d),p.flowing&&!p.reading&&d.read(0)}$.prototype.pause=function(){return l("call pause flowing=%j",this._readableState.flowing),this._readableState.flowing!==!1&&(l("pause"),this._readableState.flowing=!1,this.emit("pause")),this._readableState.paused=!0,this};function w(d){var p=d._readableState;for(l("flow",p.flowing);p.flowing&&d.read()!==null;);}$.prototype.wrap=function(d){var p=this,T=this._readableState,N=!1;d.on("end",function(){if(l("wrapped end"),T.decoder&&!T.ended){var V=T.decoder.end();V&&V.length&&p.push(V)}p.push(null)}),d.on("data",function(V){if(l("wrapped data"),T.decoder&&(V=T.decoder.write(V)),!(T.objectMode&&V==null)&&!(!T.objectMode&&(!V||!V.length))){var Ke=p.push(V);Ke||(N=!0,d.pause())}});for(var te in d)this[te]===void 0&&typeof d[te]=="function"&&(this[te]=function(Ke){return function(){return d[Ke].apply(d,arguments)}}(te));for(var j=0;j<B.length;j++)d.on(B[j],this.emit.bind(this,B[j]));return this._read=function(V){l("wrapped _read",V),N&&(N=!1,d.resume())},this},typeof Symbol=="function"&&($.prototype[Symbol.asyncIterator]=function(){return O===void 0&&(O=ba()),O(this)}),Object.defineProperty($.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}}),Object.defineProperty($.prototype,"readableBuffer",{enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}}),Object.defineProperty($.prototype,"readableFlowing",{enumerable:!1,get:function(){return this._readableState.flowing},set:function(p){this._readableState&&(this._readableState.flowing=p)}}),$._fromList=_,Object.defineProperty($.prototype,"readableLength",{enumerable:!1,get:function(){return this._readableState.length}});function _(d,p){if(p.length===0)return null;var T;return p.objectMode?T=p.buffer.shift():!d||d>=p.length?(p.decoder?T=p.buffer.join(""):p.buffer.length===1?T=p.buffer.first():T=p.buffer.concat(p.length),p.buffer.clear()):T=p.buffer.consume(d,p.decoder),T}function R(d){var p=d._readableState;l("endReadable",p.endEmitted),p.endEmitted||(p.ended=!0,process.nextTick(D,p,d))}function D(d,p){if(l("endReadableNT",d.endEmitted,d.length),!d.endEmitted&&d.length===0&&(d.endEmitted=!0,p.readable=!1,p.emit("end"),d.autoDestroy)){var T=p._writableState;(!T||T.autoDestroy&&T.finished)&&p.destroy()}}typeof Symbol=="function"&&($.from=function(d,p){return L===void 0&&(L=ya()),L($,d,p)});function G(d,p){for(var T=0,N=d.length;T<N;T++)if(d[T]===p)return T;return-1}return qr}var Ji=Ge,Er=dt.codes,ga=Er.ERR_METHOD_NOT_IMPLEMENTED,ma=Er.ERR_MULTIPLE_CALLBACK,_a=Er.ERR_TRANSFORM_ALREADY_TRANSFORMING,wa=Er.ERR_TRANSFORM_WITH_LENGTH_0,Br=It();pe(Ge,Br);function xa(e,t){var r=this._transformState;r.transforming=!1;var n=r.writecb;if(n===null)return this.emit("error",new ma);r.writechunk=null,r.writecb=null,t!=null&&this.push(t),n(e);var i=this._readableState;i.reading=!1,(i.needReadable||i.length<i.highWaterMark)&&this._read(i.highWaterMark)}function Ge(e){if(!(this instanceof Ge))return new Ge(e);Br.call(this,e),this._transformState={afterTransform:xa.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",va)}function va(){var e=this;typeof this._flush=="function"&&!this._readableState.destroyed?this._flush(function(t,r){Yn(e,t,r)}):Yn(this,null,null)}Ge.prototype.push=function(e,t){return this._transformState.needTransform=!1,Br.prototype.push.call(this,e,t)};Ge.prototype._transform=function(e,t,r){r(new ga("_transform()"))};Ge.prototype._write=function(e,t,r){var n=this._transformState;if(n.writecb=r,n.writechunk=e,n.writeencoding=t,!n.transforming){var i=this._readableState;(n.needTransform||i.needReadable||i.length<i.highWaterMark)&&this._read(i.highWaterMark)}};Ge.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};Ge.prototype._destroy=function(e,t){Br.prototype._destroy.call(this,e,function(r){t(r)})};function Yn(e,t,r){if(t)return e.emit("error",t);if(r!=null&&e.push(r),e._writableState.length)throw new wa;if(e._transformState.transforming)throw new _a;return e.push(null)}var Ea=Yt,Xi=Ji;pe(Yt,Xi);function Yt(e){if(!(this instanceof Yt))return new Yt(e);Xi.call(this,e)}Yt.prototype._transform=function(e,t,r){r(null,e)};var Vr;function Ba(e){var t=!1;return function(){t||(t=!0,e.apply(void 0,arguments))}}var Qi=dt.codes,Sa=Qi.ERR_MISSING_ARGS,Aa=Qi.ERR_STREAM_DESTROYED;function Jn(e){if(e)throw e}function Ia(e){return e.setHeader&&typeof e.abort=="function"}function Ta(e,t,r,n){n=Ba(n);var i=!1;e.on("close",function(){i=!0}),Vr===void 0&&(Vr=vn),Vr(e,{readable:t,writable:r},function(u){if(u)return n(u);i=!0,n()});var o=!1;return function(u){if(!i&&!o){if(o=!0,Ia(e))return e.abort();if(typeof e.destroy=="function")return e.destroy();n(u||new Aa("pipe"))}}}function Xn(e){e()}function Ra(e,t){return e.pipe(t)}function ka(e){return!e.length||typeof e[e.length-1]!="function"?Jn:e.pop()}function Ca(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];var n=ka(t);if(Array.isArray(t[0])&&(t=t[0]),t.length<2)throw new Sa("streams");var i,o=t.map(function(u,f){var l=f<t.length-1,b=f>0;return Ta(u,l,b,function(g){i||(i=g),g&&o.forEach(Xn),!l&&(o.forEach(Xn),n(i))})});return t.reduce(Ra)}var Pa=Ca;(function(e,t){t=e.exports=Yi(),t.Stream=t,t.Readable=t,t.Writable=Vi(),t.Duplex=It(),t.Transform=Ji,t.PassThrough=Ea,t.finished=vn,t.pipeline=Pa})(on,on.exports);var Zi=on.exports,br=ve.Buffer,es=Zi.Transform,La=pe;function Oa(e,t){if(!br.isBuffer(e)&&typeof e!="string")throw new TypeError(t+" must be a string or a buffer")}function Ze(e){es.call(this),this._block=br.allocUnsafe(e),this._blockSize=e,this._blockOffset=0,this._length=[0,0,0,0],this._finalized=!1}La(Ze,es);Ze.prototype._transform=function(e,t,r){var n=null;try{this.update(e,t)}catch(i){n=i}r(n)};Ze.prototype._flush=function(e){var t=null;try{this.push(this.digest())}catch(r){t=r}e(t)};Ze.prototype.update=function(e,t){if(Oa(e,"Data"),this._finalized)throw new Error("Digest already called");br.isBuffer(e)||(e=br.from(e,t));for(var r=this._block,n=0;this._blockOffset+e.length-n>=this._blockSize;){for(var i=this._blockOffset;i<this._blockSize;)r[i++]=e[n++];this._update(),this._blockOffset=0}for(;n<e.length;)r[this._blockOffset++]=e[n++];for(var o=0,u=e.length*8;u>0;++o)this._length[o]+=u,u=this._length[o]/4294967296|0,u>0&&(this._length[o]-=4294967296*u);return this};Ze.prototype._update=function(){throw new Error("_update is not implemented")};Ze.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};Ze.prototype._digest=function(){throw new Error("_digest is not implemented")};var Fa=Ze,Ua=pe,ts=Fa,Na=ve.Buffer,Ma=new Array(16);function Sr(){ts.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878}Ua(Sr,ts);Sr.prototype._update=function(){for(var e=Ma,t=0;t<16;++t)e[t]=this._block.readInt32LE(t*4);var r=this._a,n=this._b,i=this._c,o=this._d;r=be(r,n,i,o,e[0],3614090360,7),o=be(o,r,n,i,e[1],3905402710,12),i=be(i,o,r,n,e[2],606105819,17),n=be(n,i,o,r,e[3],3250441966,22),r=be(r,n,i,o,e[4],4118548399,7),o=be(o,r,n,i,e[5],1200080426,12),i=be(i,o,r,n,e[6],2821735955,17),n=be(n,i,o,r,e[7],4249261313,22),r=be(r,n,i,o,e[8],1770035416,7),o=be(o,r,n,i,e[9],2336552879,12),i=be(i,o,r,n,e[10],4294925233,17),n=be(n,i,o,r,e[11],2304563134,22),r=be(r,n,i,o,e[12],1804603682,7),o=be(o,r,n,i,e[13],4254626195,12),i=be(i,o,r,n,e[14],2792965006,17),n=be(n,i,o,r,e[15],1236535329,22),r=ye(r,n,i,o,e[1],4129170786,5),o=ye(o,r,n,i,e[6],3225465664,9),i=ye(i,o,r,n,e[11],643717713,14),n=ye(n,i,o,r,e[0],3921069994,20),r=ye(r,n,i,o,e[5],3593408605,5),o=ye(o,r,n,i,e[10],38016083,9),i=ye(i,o,r,n,e[15],3634488961,14),n=ye(n,i,o,r,e[4],3889429448,20),r=ye(r,n,i,o,e[9],568446438,5),o=ye(o,r,n,i,e[14],3275163606,9),i=ye(i,o,r,n,e[3],4107603335,14),n=ye(n,i,o,r,e[8],1163531501,20),r=ye(r,n,i,o,e[13],2850285829,5),o=ye(o,r,n,i,e[2],4243563512,9),i=ye(i,o,r,n,e[7],1735328473,14),n=ye(n,i,o,r,e[12],2368359562,20),r=ge(r,n,i,o,e[5],4294588738,4),o=ge(o,r,n,i,e[8],2272392833,11),i=ge(i,o,r,n,e[11],1839030562,16),n=ge(n,i,o,r,e[14],4259657740,23),r=ge(r,n,i,o,e[1],2763975236,4),o=ge(o,r,n,i,e[4],1272893353,11),i=ge(i,o,r,n,e[7],4139469664,16),n=ge(n,i,o,r,e[10],3200236656,23),r=ge(r,n,i,o,e[13],681279174,4),o=ge(o,r,n,i,e[0],3936430074,11),i=ge(i,o,r,n,e[3],3572445317,16),n=ge(n,i,o,r,e[6],76029189,23),r=ge(r,n,i,o,e[9],3654602809,4),o=ge(o,r,n,i,e[12],3873151461,11),i=ge(i,o,r,n,e[15],530742520,16),n=ge(n,i,o,r,e[2],3299628645,23),r=me(r,n,i,o,e[0],4096336452,6),o=me(o,r,n,i,e[7],1126891415,10),i=me(i,o,r,n,e[14],2878612391,15),n=me(n,i,o,r,e[5],4237533241,21),r=me(r,n,i,o,e[12],1700485571,6),o=me(o,r,n,i,e[3],2399980690,10),i=me(i,o,r,n,e[10],4293915773,15),n=me(n,i,o,r,e[1],2240044497,21),r=me(r,n,i,o,e[8],1873313359,6),o=me(o,r,n,i,e[15],4264355552,10),i=me(i,o,r,n,e[6],2734768916,15),n=me(n,i,o,r,e[13],1309151649,21),r=me(r,n,i,o,e[4],4149444226,6),o=me(o,r,n,i,e[11],3174756917,10),i=me(i,o,r,n,e[2],718787259,15),n=me(n,i,o,r,e[9],3951481745,21),this._a=this._a+r|0,this._b=this._b+n|0,this._c=this._c+i|0,this._d=this._d+o|0};Sr.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=Na.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 Ar(e,t){return e<<t|e>>>32-t}function be(e,t,r,n,i,o,u){return Ar(e+(t&r|~t&n)+i+o|0,u)+t|0}function ye(e,t,r,n,i,o,u){return Ar(e+(t&n|r&~n)+i+o|0,u)+t|0}function ge(e,t,r,n,i,o,u){return Ar(e+(t^r^n)+i+o|0,u)+t|0}function me(e,t,r,n,i,o,u){return Ar(e+(r^(t|~n))+i+o|0,u)+t|0}var Da=Sr,yr=ve.Buffer,rs=Zi.Transform,$a=pe;function Ha(e,t){if(!yr.isBuffer(e)&&typeof e!="string")throw new TypeError(t+" must be a string or a buffer")}function et(e){rs.call(this),this._block=yr.allocUnsafe(e),this._blockSize=e,this._blockOffset=0,this._length=[0,0,0,0],this._finalized=!1}$a(et,rs);et.prototype._transform=function(e,t,r){var n=null;try{this.update(e,t)}catch(i){n=i}r(n)};et.prototype._flush=function(e){var t=null;try{this.push(this.digest())}catch(r){t=r}e(t)};et.prototype.update=function(e,t){if(Ha(e,"Data"),this._finalized)throw new Error("Digest already called");yr.isBuffer(e)||(e=yr.from(e,t));for(var r=this._block,n=0;this._blockOffset+e.length-n>=this._blockSize;){for(var i=this._blockOffset;i<this._blockSize;)r[i++]=e[n++];this._update(),this._blockOffset=0}for(;n<e.length;)r[this._blockOffset++]=e[n++];for(var o=0,u=e.length*8;u>0;++o)this._length[o]+=u,u=this._length[o]/4294967296|0,u>0&&(this._length[o]-=4294967296*u);return this};et.prototype._update=function(){throw new Error("_update is not implemented")};et.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};et.prototype._digest=function(){throw new Error("_digest is not implemented")};var za=et,Kr=Rt.Buffer,Ga=pe,ns=za,ja=new Array(16),Ut=[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],Nt=[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],Mt=[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],Dt=[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],$t=[0,1518500249,1859775393,2400959708,2840853838],Ht=[1352829926,1548603684,1836072691,2053994217,0];function Ir(){ns.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520}Ga(Ir,ns);Ir.prototype._update=function(){for(var e=ja,t=0;t<16;++t)e[t]=this._block.readInt32LE(t*4);for(var r=this._a|0,n=this._b|0,i=this._c|0,o=this._d|0,u=this._e|0,f=this._a|0,l=this._b|0,b=this._c|0,g=this._d|0,m=this._e|0,v=0;v<80;v+=1){var A,I;v<16?(A=Qn(r,n,i,o,u,e[Ut[v]],$t[0],Mt[v]),I=ri(f,l,b,g,m,e[Nt[v]],Ht[0],Dt[v])):v<32?(A=Zn(r,n,i,o,u,e[Ut[v]],$t[1],Mt[v]),I=ti(f,l,b,g,m,e[Nt[v]],Ht[1],Dt[v])):v<48?(A=ei(r,n,i,o,u,e[Ut[v]],$t[2],Mt[v]),I=ei(f,l,b,g,m,e[Nt[v]],Ht[2],Dt[v])):v<64?(A=ti(r,n,i,o,u,e[Ut[v]],$t[3],Mt[v]),I=Zn(f,l,b,g,m,e[Nt[v]],Ht[3],Dt[v])):(A=ri(r,n,i,o,u,e[Ut[v]],$t[4],Mt[v]),I=Qn(f,l,b,g,m,e[Nt[v]],Ht[4],Dt[v])),r=u,u=o,o=ft(i,10),i=n,n=A,f=m,m=g,g=ft(b,10),b=l,l=I}var k=this._b+i+g|0;this._b=this._c+o+m|0,this._c=this._d+u+f|0,this._d=this._e+r+l|0,this._e=this._a+n+b|0,this._a=k};Ir.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=Kr.alloc?Kr.alloc(20):new Kr(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 ft(e,t){return e<<t|e>>>32-t}function Qn(e,t,r,n,i,o,u,f){return ft(e+(t^r^n)+o+u|0,f)+i|0}function Zn(e,t,r,n,i,o,u,f){return ft(e+(t&r|~t&n)+o+u|0,f)+i|0}function ei(e,t,r,n,i,o,u,f){return ft(e+((t|~r)^n)+o+u|0,f)+i|0}function ti(e,t,r,n,i,o,u,f){return ft(e+(t&n|r&~n)+o+u|0,f)+i|0}function ri(e,t,r,n,i,o,u,f){return ft(e+(t^(r|~n))+o+u|0,f)+i|0}var Wa=Ir,is={exports:{}},ss=ve.Buffer;function Tr(e,t){this._block=ss.alloc(e),this._finalSize=t,this._blockSize=e,this._len=0}Tr.prototype.update=function(e,t){typeof e=="string"&&(t=t||"utf8",e=ss.from(e,t));for(var r=this._block,n=this._blockSize,i=e.length,o=this._len,u=0;u<i;){for(var f=o%n,l=Math.min(i-u,n-f),b=0;b<l;b++)r[f+b]=e[u+b];o+=l,u+=l,o%n===0&&this._update(r)}return this._len+=i,this};Tr.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,i=(r-n)/4294967296;this._block.writeUInt32BE(i,this._blockSize-8),this._block.writeUInt32BE(n,this._blockSize-4)}this._update(this._block);var o=this._hash();return e?o.toString(e):o};Tr.prototype._update=function(){throw new Error("_update must be implemented by subclass")};var kt=Tr,qa=pe,os=kt,Va=ve.Buffer,Ka=[1518500249,1859775393,-1894007588,-899497514],Ya=new Array(80);function Zt(){this.init(),this._w=Ya,os.call(this,64,56)}qa(Zt,os);Zt.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this};function Ja(e){return e<<5|e>>>27}function Xa(e){return e<<30|e>>>2}function Qa(e,t,r,n){return e===0?t&r|~t&n:e===2?t&r|t&n|r&n:t^r^n}Zt.prototype._update=function(e){for(var t=this._w,r=this._a|0,n=this._b|0,i=this._c|0,o=this._d|0,u=this._e|0,f=0;f<16;++f)t[f]=e.readInt32BE(f*4);for(;f<80;++f)t[f]=t[f-3]^t[f-8]^t[f-14]^t[f-16];for(var l=0;l<80;++l){var b=~~(l/20),g=Ja(r)+Qa(b,n,i,o)+u+t[l]+Ka[b]|0;u=o,o=i,i=Xa(n),n=r,r=g}this._a=r+this._a|0,this._b=n+this._b|0,this._c=i+this._c|0,this._d=o+this._d|0,this._e=u+this._e|0};Zt.prototype._hash=function(){var e=Va.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 Za=Zt,ef=pe,as=kt,tf=ve.Buffer,rf=[1518500249,1859775393,-1894007588,-899497514],nf=new Array(80);function er(){this.init(),this._w=nf,as.call(this,64,56)}ef(er,as);er.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this};function sf(e){return e<<1|e>>>31}function of(e){return e<<5|e>>>27}function af(e){return e<<30|e>>>2}function ff(e,t,r,n){return e===0?t&r|~t&n:e===2?t&r|t&n|r&n:t^r^n}er.prototype._update=function(e){for(var t=this._w,r=this._a|0,n=this._b|0,i=this._c|0,o=this._d|0,u=this._e|0,f=0;f<16;++f)t[f]=e.readInt32BE(f*4);for(;f<80;++f)t[f]=sf(t[f-3]^t[f-8]^t[f-14]^t[f-16]);for(var l=0;l<80;++l){var b=~~(l/20),g=of(r)+ff(b,n,i,o)+u+t[l]+rf[b]|0;u=o,o=i,i=af(n),n=r,r=g}this._a=r+this._a|0,this._b=n+this._b|0,this._c=i+this._c|0,this._d=o+this._d|0,this._e=u+this._e|0};er.prototype._hash=function(){var e=tf.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 uf=er,cf=pe,fs=kt,lf=ve.Buffer,hf=[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],df=new Array(64);function tr(){this.init(),this._w=df,fs.call(this,64,56)}cf(tr,fs);tr.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 pf(e,t,r){return r^e&(t^r)}function bf(e,t,r){return e&t|r&(e|t)}function yf(e){return(e>>>2|e<<30)^(e>>>13|e<<19)^(e>>>22|e<<10)}function gf(e){return(e>>>6|e<<26)^(e>>>11|e<<21)^(e>>>25|e<<7)}function mf(e){return(e>>>7|e<<25)^(e>>>18|e<<14)^e>>>3}function _f(e){return(e>>>17|e<<15)^(e>>>19|e<<13)^e>>>10}tr.prototype._update=function(e){for(var t=this._w,r=this._a|0,n=this._b|0,i=this._c|0,o=this._d|0,u=this._e|0,f=this._f|0,l=this._g|0,b=this._h|0,g=0;g<16;++g)t[g]=e.readInt32BE(g*4);for(;g<64;++g)t[g]=_f(t[g-2])+t[g-7]+mf(t[g-15])+t[g-16]|0;for(var m=0;m<64;++m){var v=b+gf(u)+pf(u,f,l)+hf[m]+t[m]|0,A=yf(r)+bf(r,n,i)|0;b=l,l=f,f=u,u=o+v|0,o=i,i=n,n=r,r=v+A|0}this._a=r+this._a|0,this._b=n+this._b|0,this._c=i+this._c|0,this._d=o+this._d|0,this._e=u+this._e|0,this._f=f+this._f|0,this._g=l+this._g|0,this._h=b+this._h|0};tr.prototype._hash=function(){var e=lf.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 us=tr,wf=pe,xf=us,vf=kt,Ef=ve.Buffer,Bf=new Array(64);function Rr(){this.init(),this._w=Bf,vf.call(this,64,56)}wf(Rr,xf);Rr.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};Rr.prototype._hash=function(){var e=Ef.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 Sf=Rr,Af=pe,cs=kt,If=ve.Buffer,ni=[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],Tf=new Array(160);function rr(){this.init(),this._w=Tf,cs.call(this,128,112)}Af(rr,cs);rr.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 ii(e,t,r){return r^e&(t^r)}function si(e,t,r){return e&t|r&(e|t)}function oi(e,t){return(e>>>28|t<<4)^(t>>>2|e<<30)^(t>>>7|e<<25)}function ai(e,t){return(e>>>14|t<<18)^(e>>>18|t<<14)^(t>>>9|e<<23)}function Rf(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^e>>>7}function kf(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^(e>>>7|t<<25)}function Cf(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^e>>>6}function Pf(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^(e>>>6|t<<26)}function he(e,t){return e>>>0<t>>>0?1:0}rr.prototype._update=function(e){for(var t=this._w,r=this._ah|0,n=this._bh|0,i=this._ch|0,o=this._dh|0,u=this._eh|0,f=this._fh|0,l=this._gh|0,b=this._hh|0,g=this._al|0,m=this._bl|0,v=this._cl|0,A=this._dl|0,I=this._el|0,k=this._fl|0,C=this._gl|0,P=this._hl|0,F=0;F<32;F+=2)t[F]=e.readInt32BE(F*4),t[F+1]=e.readInt32BE(F*4+4);for(;F<160;F+=2){var O=t[F-30],L=t[F-15*2+1],U=Rf(O,L),B=kf(L,O);O=t[F-2*2],L=t[F-2*2+1];var z=Cf(O,L),M=Pf(L,O),$=t[F-7*2],fe=t[F-7*2+1],ke=t[F-16*2],je=t[F-16*2+1],ce=B+fe|0,Ee=U+$+he(ce,B)|0;ce=ce+M|0,Ee=Ee+z+he(ce,M)|0,ce=ce+je|0,Ee=Ee+ke+he(ce,je)|0,t[F]=Ee,t[F+1]=ce}for(var Be=0;Be<160;Be+=2){Ee=t[Be],ce=t[Be+1];var rt=si(r,n,i),Ce=si(g,m,v),We=oi(r,g),Pe=oi(g,r),qe=ai(u,I),ee=ai(I,u),ue=ni[Be],Se=ni[Be+1],Ve=ii(u,f,l),Me=ii(I,k,C),w=P+ee|0,_=b+qe+he(w,P)|0;w=w+Me|0,_=_+Ve+he(w,Me)|0,w=w+Se|0,_=_+ue+he(w,Se)|0,w=w+ce|0,_=_+Ee+he(w,ce)|0;var R=Pe+Ce|0,D=We+rt+he(R,Pe)|0;b=l,P=C,l=f,C=k,f=u,k=I,I=A+w|0,u=o+_+he(I,A)|0,o=i,A=v,i=n,v=m,n=r,m=g,g=w+R|0,r=_+D+he(g,w)|0}this._al=this._al+g|0,this._bl=this._bl+m|0,this._cl=this._cl+v|0,this._dl=this._dl+A|0,this._el=this._el+I|0,this._fl=this._fl+k|0,this._gl=this._gl+C|0,this._hl=this._hl+P|0,this._ah=this._ah+r+he(this._al,g)|0,this._bh=this._bh+n+he(this._bl,m)|0,this._ch=this._ch+i+he(this._cl,v)|0,this._dh=this._dh+o+he(this._dl,A)|0,this._eh=this._eh+u+he(this._el,I)|0,this._fh=this._fh+f+he(this._fl,k)|0,this._gh=this._gh+l+he(this._gl,C)|0,this._hh=this._hh+b+he(this._hl,P)|0};rr.prototype._hash=function(){var e=If.allocUnsafe(64);function t(r,n,i){e.writeInt32BE(r,i),e.writeInt32BE(n,i+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 ls=rr,Lf=pe,Of=ls,Ff=kt,Uf=ve.Buffer,Nf=new Array(160);function kr(){this.init(),this._w=Nf,Ff.call(this,128,112)}Lf(kr,Of);kr.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};kr.prototype._hash=function(){var e=Uf.allocUnsafe(48);function t(r,n,i){e.writeInt32BE(r,i),e.writeInt32BE(n,i+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 Mf=kr,pt=is.exports=function(t){t=t.toLowerCase();var r=pt[t];if(!r)throw new Error(t+" is not supported (we accept pull requests)");return new r};pt.sha=Za;pt.sha1=uf;pt.sha224=Sf;pt.sha256=us;pt.sha384=Mf;pt.sha512=ls;var Df=is.exports,hs=ve.Buffer,ds=wn.Transform,$f=pr.StringDecoder,Hf=pe;function Le(e){ds.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(Le,ds);Le.prototype.update=function(e,t,r){typeof e=="string"&&(e=hs.from(e,t));var n=this._update(e);return this.hashMode?this:(r&&(n=this._toString(n,r)),n)};Le.prototype.setAutoPadding=function(){};Le.prototype.getAuthTag=function(){throw new Error("trying to get auth tag in unsupported state")};Le.prototype.setAuthTag=function(){throw new Error("trying to set auth tag in unsupported state")};Le.prototype.setAAD=function(){throw new Error("trying to set aad in unsupported state")};Le.prototype._transform=function(e,t,r){var n;try{this.hashMode?this._update(e):this.push(this._update(e))}catch(i){n=i}finally{r(n)}};Le.prototype._flush=function(e){var t;try{this.push(this.__final())}catch(r){t=r}e(t)};Le.prototype._finalOrDigest=function(e){var t=this.__final()||hs.alloc(0);return e&&(t=this._toString(t,e,!0)),t};Le.prototype._toString=function(e,t,r){if(this._decoder||(this._decoder=new $f(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 zf=Le,Gf=pe,jf=Da,Wf=Wa,qf=Df,ps=zf;function Cr(e){ps.call(this,"digest"),this._hash=e}Gf(Cr,ps);Cr.prototype._update=function(e){this._hash.update(e)};Cr.prototype._final=function(){return this._hash.digest()};var Vf=function(t){return t=t.toLowerCase(),t==="md5"?new jf:t==="rmd160"||t==="ripemd160"?new Wf:new Cr(qf(t))},fr=ve.Buffer;function Kf(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 i=e.charAt(n),o=i.charCodeAt(0);if(t[o]!==255)throw new TypeError(i+" is ambiguous");t[o]=n}var u=e.length,f=e.charAt(0),l=Math.log(u)/Math.log(256),b=Math.log(256)/Math.log(u);function g(A){if((Array.isArray(A)||A instanceof Uint8Array)&&(A=fr.from(A)),!fr.isBuffer(A))throw new TypeError("Expected Buffer");if(A.length===0)return"";for(var I=0,k=0,C=0,P=A.length;C!==P&&A[C]===0;)C++,I++;for(var F=(P-C)*b+1>>>0,O=new Uint8Array(F);C!==P;){for(var L=A[C],U=0,B=F-1;(L!==0||U<k)&&B!==-1;B--,U++)L+=256*O[B]>>>0,O[B]=L%u>>>0,L=L/u>>>0;if(L!==0)throw new Error("Non-zero carry");k=U,C++}for(var z=F-k;z!==F&&O[z]===0;)z++;for(var M=f.repeat(I);z<F;++z)M+=e.charAt(O[z]);return M}function m(A){if(typeof A!="string")throw new TypeError("Expected String");if(A.length===0)return fr.alloc(0);for(var I=0,k=0,C=0;A[I]===f;)k++,I++;for(var P=(A.length-I)*l+1>>>0,F=new Uint8Array(P);I<A.length;){var O=t[A.charCodeAt(I)];if(O===255)return;for(var L=0,U=P-1;(O!==0||L<C)&&U!==-1;U--,L++)O+=u*F[U]>>>0,F[U]=O%256>>>0,O=O/256>>>0;if(O!==0)throw new Error("Non-zero carry");C=L,I++}for(var B=P-C;B!==P&&F[B]===0;)B++;var z=fr.allocUnsafe(k+(P-B));z.fill(0,0,k);for(var M=k;B!==P;)z[M++]=F[B++];return z}function v(A){var I=m(A);if(I)return I;throw new Error("Non-base"+u+" character")}return{encode:g,decodeUnsafe:m,decode:v}}var Yf=Kf,Jf=Yf,Xf="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",Qf=Jf(Xf),Yr=Qf,Zf=ve.Buffer,eu=function(e){function t(o){var u=e(o);return Yr.encode(Zf.concat([o,u],o.length+4))}function r(o){var u=o.slice(0,-4),f=o.slice(-4),l=e(u);if(!(f[0]^l[0]|f[1]^l[1]|f[2]^l[2]|f[3]^l[3]))return u}function n(o){var u=Yr.decodeUnsafe(o);if(u)return r(u)}function i(o){var u=Yr.decode(o),f=r(u);if(!f)throw new Error("Invalid checksum");return f}return{encode:t,decode:i,decodeUnsafe:n}},fi=Vf,tu=eu;function ru(e){var t=fi("sha256").update(e).digest();return fi("sha256").update(t).digest()}var nu=tu(ru),fn=nu;function bs(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 un(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 iu(e,t){return bs(fn.decode(e),t)}function su(e,t,r){return typeof e=="number"?fn.encode(un(e,t,r)):fn.encode(un(e.version,e.privateKey,e.compressed))}var ou={decode:iu,decodeRaw:bs,encode:su,encodeRaw:un},Pr={};Object.defineProperty(Pr,"__esModule",{value:!0});Pr.testEcc=void 0;const H=e=>Buffer.from(e,"hex");function au(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")))}Pr.testEcc=au;function J(e){if(!e)throw new Error("ecc library invalid")}Object.defineProperty(St,"__esModule",{value:!0});St.ECPairFactory=St.networks=void 0;const cn=At;St.networks=cn;const we=Ii,fu=Co,ui=ou,uu=Pr,Jr=we.typeforce.maybe(we.typeforce.compile({compressed:we.maybe(we.Boolean),network:we.maybe(we.Network)})),cu=e=>e.length===32?e:e.slice(1,33);function lu(e){(0,uu.testEcc)(e);function t(f){return e.isPoint(f)}function r(f,l){if(we.typeforce(we.Buffer256bit,f),!e.isPrivate(f))throw new TypeError("Private key not in range [1, n)");return we.typeforce(Jr,l),new u(f,void 0,l)}function n(f,l){return we.typeforce(e.isPoint,f),we.typeforce(Jr,l),new u(void 0,f,l)}function i(f,l){const b=ui.decode(f),g=b.version;if(we.Array(l)){if(l=l.filter(m=>g===m.wif).pop(),!l)throw new Error("Unknown network version")}else if(l=l||cn.bitcoin,g!==l.wif)throw new Error("Invalid network version");return r(b.privateKey,{compressed:b.compressed,network:l})}function o(f){we.typeforce(Jr,f),f===void 0&&(f={});const l=f.rng||fu;let b;do b=l(32),we.typeforce(we.Buffer256bit,b);while(!e.isPrivate(b));return r(b,f)}class u{constructor(l,b,g){mt(this,"__D");mt(this,"__Q");mt(this,"compressed");mt(this,"network");mt(this,"lowR");this.__D=l,this.__Q=b,this.lowR=!1,g===void 0&&(g={}),this.compressed=g.compressed===void 0?!0:g.compressed,this.network=g.network||cn.bitcoin,b!==void 0&&(this.__Q=Buffer.from(e.pointCompress(b,this.compressed)))}get privateKey(){return this.__D}get publicKey(){if(!this.__Q){const l=e.pointFromScalar(this.__D,this.compressed);this.__Q=Buffer.from(l)}return this.__Q}toWIF(){if(!this.__D)throw new Error("Missing private key");return ui.encode(this.network.wif,this.__D,this.compressed)}tweak(l){return this.privateKey?this.tweakFromPrivateKey(l):this.tweakFromPublicKey(l)}sign(l,b){if(!this.__D)throw new Error("Missing private key");if(b===void 0&&(b=this.lowR),b===!1)return Buffer.from(e.sign(l,this.__D));{let g=e.sign(l,this.__D);const m=Buffer.alloc(32,0);let v=0;for(;g[0]>127;)v++,m.writeUIntLE(v,0,6),g=e.sign(l,this.__D,m);return Buffer.from(g)}}signSchnorr(l){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(l,this.privateKey))}verify(l,b){return e.verify(l,this.publicKey,b)}verifySchnorr(l,b){if(!e.verifySchnorr)throw new Error("verifySchnorr not supported by ecc library");return e.verifySchnorr(l,this.publicKey.subarray(1,33),b)}tweakFromPublicKey(l){const b=cu(this.publicKey),g=e.xOnlyPointAddTweak(b,l);if(!g||g.xOnlyPubkey===null)throw new Error("Cannot tweak public key!");const m=Buffer.from([g.parity===0?2:3]);return n(Buffer.concat([m,g.xOnlyPubkey]),{network:this.network,compressed:this.compressed})}tweakFromPrivateKey(l){const g=this.publicKey[0]===3||this.publicKey[0]===4&&(this.publicKey[64]&1)===1?e.privateNegate(this.privateKey):this.privateKey,m=e.privateAdd(g,l);if(!m)throw new Error("Invalid tweaked private key!");return r(Buffer.from(m),{network:this.network,compressed:this.compressed})}}return{isPoint:t,fromPrivateKey:r,fromPublicKey:n,fromWIF:i,makeRandom:o}}St.ECPairFactory=lu;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.networks=e.ECPairFactory=e.default=void 0;var t=St;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}})})(Ai);const hu=uo(Ai);class Jt{get isInitialized(){return!!this.privKey}constructor(t,r){this.privKey=t,this.walletClient=r}static fromPrivKey(t){return new Jt(S.trim0x(t))}static fromWalletClient(t){return new Jt(void 0,t)}async initialize(){if(this.privKey)return S.Ok("Already initialized");const t=await this.derivePrivKeyFromWalletClient();return t.error?S.Err(t.error):S.Ok("Initialized")}async derivePrivKeyFromWalletClient(){if(!this.walletClient)return S.Err("No walletClient found");if(!this.walletClient.account)return S.Err("No account found");try{const t=await this.walletClient.signTypedData({account:this.walletClient.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:"GARDEN FINANCE",version:"1"},primaryType:"Data",message:{Message:"Initialize your account",Version:"1.0.2",Nonce:1n}});return S.Ok(S.trim0x(Ne.sha256(t)))}catch(t){return S.Err("Failed to initialize: "+t)}}async getMasterPrivKey(){if(!this.privKey&&!this.walletClient)return S.Err("No private key or wallet client found");if(!this.privKey&&this.walletClient){const t=await this.derivePrivKeyFromWalletClient();if(t.error)return S.Err(t.error);this.privKey=t.val}return this.privKey?S.Ok(this.privKey):S.Err("No private key found")}async generateSecret(t){const r=await this.signMessage(t);if(r.error)return S.Err(r.error);const n=Ne.sha256(ae.with0x(r.val)),i=Ne.sha256(n);return S.Ok({secret:n,secretHash:i})}async signMessage(t){if(!this.privKey){const b=await this.getMasterPrivKey();if(b.error)return S.Err(b.error);this.privKey=b.val}const r=hu(at),n="Garden.fi"+t.toString(),i=Buffer.from(n,"utf8"),o=Ne.sha256(i),u=Buffer.from(S.trim0x(this.privKey),"hex");if(u.length!==32)return S.Err("Invalid private key length. Expected 32 bytes.");const l=r.fromPrivateKey(u).sign(Buffer.from(S.trim0x(o),"hex"));return S.Ok(l.toString("hex"))}}class du{constructor(t){this.eventListeners=new Map,this.getOrderThreshold=20,this.refundSacpCache=new Map,this.environment=t.environment;const r=t.environment===ae.Environment.MAINNET?Ln.mainnet:t.environment===ae.Environment.TESTNET?Ln.testnet:void 0;if(!r)throw new Error("API not found, invalid environment "+t.environment);if(this._auth=new ae.Siwe(new ae.Url(r.orderbook),t.evmWallet,t.siweOpts),this._quote=t.quote??new Si(r.quote),this._orderBook=new X.Orderbook({url:t.orderbookURl??r.orderbook,walletClient:t.evmWallet,auth:this._auth}),this._orderbookUrl=new ae.Url(t.orderbookURl??r.orderbook),this._evmRelay=new Ei(this._orderbookUrl,this._auth),this._secretManager=t.secretManager??Jt.fromWalletClient(t.evmWallet),this.orderExecutorCache=new fo,this._evmWallet=t.evmWallet,!t.evmWallet.account)throw new Error("Account not found in evmWallet");this._blockNumberFetcher=t.blockNumberFetcher??new Bi(r.info,t.environment)}get orderbookUrl(){return this._orderbookUrl.toString()}get evmRelay(){return this._evmRelay}get quote(){return this._quote}get btcWallet(){return this._btcWallet}get orderbook(){return this._orderBook}get blockNumberFetcher(){return this._blockNumberFetcher}get secretManager(){return this._secretManager}async initializeSMandBTCWallet(){if(this._secretManager.isInitialized&&this._btcWallet)return S.Ok(this._btcWallet);const t=await this._secretManager.getMasterPrivKey();if(t.error)return S.Err(t.error);const r=new Bt.BitcoinProvider(Zs(this.environment));return this._btcWallet=Bt.BitcoinWallet.fromPrivateKey(t.val,r),S.Ok(this._btcWallet)}async swap(t){const r=await this.validateAndFillParams(t);if(r.error)return S.Err(r.error);const{sendAddress:n,receiveAddress:i,timelock:o}=r.val;let u=t.nonce;if(!u){if(!this._evmWallet.account)return S.Err("EVM Wallet not found");const k=await this._orderBook.getOrdersCount(this._evmWallet.account.address);if(k.error)return S.Err(k.error);u=k.val+1}const f=await this._secretManager.generateSecret(u);if(f.error)return S.Err(f.error);const{strategyId:l,btcAddress:b}=t.additionalData,g={strategy_id:l,...b&&{bitcoin_optional_recipient:b}},m={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:i,source_amount:t.sendAmount,destination_amount:t.receiveAmount,fee:"1",nonce:u.toString(),timelock:o,secret_hash:S.trim0x(f.val.secretHash),min_destination_confirmations:t.minDestinationConfirmations??0,additional_data:g},v=await this._quote.getAttestedQuote(m);if(v.error)return S.Err(v.error);const A=await this._orderBook.createOrder(v.val);if(A.error)return S.Err(A.error);const I=await this.pollOrder(A.val);return I.error?S.Err(I.error):S.Ok(I.val)}async validateAndFillParams(t){if(!t.additionalData.strategyId)return S.Err("StrategyId is required");if(!t.fromAsset||!t.toAsset)return S.Err("Source and destination assets are required for swap");if(t.fromAsset.chain===t.toAsset.chain&&t.fromAsset.atomicSwapAddress===t.toAsset.atomicSwapAddress)return S.Err("Source and destination assets cannot be the same");if(X.isMainnet(t.fromAsset.chain)&&!X.isMainnet(t.toAsset.chain)||!X.isMainnet(t.fromAsset.chain)&&X.isMainnet(t.toAsset.chain))return S.Err("Both assets should be on the same network (either mainnet or testnet)");const r=this.validateAmount(t.sendAmount);if(r.error)return S.Err(r.error);const n=this.validateAmount(t.receiveAmount);if(n.error)return S.Err(n.error);if(r<n)return S.Err("Send amount should be greater than receive amount");const i=X.getTimeLock(t.fromAsset.chain);if(!i)return S.Err("Unsupported chain for timelock");if(X.isBitcoin(t.fromAsset.chain)||X.isBitcoin(t.toAsset.chain)){if(!t.additionalData.btcAddress)return S.Err("btcAddress in additionalData is required if source or destination chain is bitcoin, it is used as refund or redeem address.");const f=await this.initializeSMandBTCWallet();if(f.error)return S.Err(f.error);if(!this._btcWallet)return S.Err("btcWallet is required for bitcoin chain. Please provide btcWallet in the constructor")}const o=await this.getAddresses(t.fromAsset.chain);if(o.error)return S.Err(o.error);const u=await this.getAddresses(t.toAsset.chain);return u.error?S.Err(u.error):S.Ok({sendAddress:o.val,receiveAddress:u.val,timelock:t.timelock??i})}async getAddresses(t){var n;switch(X.getBlockchainType(t)){case X.BlockchainType.EVM:return this._evmWallet.account?S.Ok(this._evmWallet.account.address):S.Err("EVM Wallet not found");case X.BlockchainType.Bitcoin:{const i=await((n=this._btcWallet)==null?void 0:n.getPublicKey());return!i||!Xs(i)?S.Err("Invalid btc public key"):S.Ok(st(i))}default:return S.Err("Unsupported chain")}}validateAmount(t){if(t==null||t.includes("."))return S.Err("Invalid amount ",t);const r=new Vs(t);return!r.isInteger()||r.isNaN()||r.lt(0)||r.isLessThanOrEqualTo(0)?S.Err("Invalid amount ",t):S.Ok(r)}async pollOrder(t){let r=await this._orderBook.getOrder(t,!0),n=0;for(;n<this.getOrderThreshold;){if(await ae.sleep(1e3),n++,r.error){if(!r.error.includes("result is undefined"))return S.Err(r.error)}else if(r.val&&r.val.create_order.create_id.toLowerCase()===t.toLowerCase())return S.Ok(r.val);r=await this._orderBook.getOrder(t,!0)}return S.Err(`Order not found, createOrder id: ${t}`)}async execute(t=5e3){return await this.initializeSMandBTCWallet(),await this._orderBook.subscribeToOrders(t,async r=>{const n=await this.filterExpiredAndAssignStatus(r.data);if(!n.error){this.emit("onPendingOrdersChanged",n.val),console.log("ordersWithStatus.val :",n.val.length);for(let i=0;i<n.val.length;i++){const o=n.val[i],u=pn(o.status);if(X.isBitcoin(o.source_swap.chain)&&o.status===Q.InitiateDetected){const f=this.getWallet(o.source_swap.chain);if(f.error){this.emit("error",o,f.error);continue}await this.postRefundSACP(o,f.val)}switch(u){case le.Redeem:{const f=await this._secretManager.generateSecret(Number(o.create_order.nonce));if(f.error){this.emit("error",o,f.error);return}switch(X.getBlockchainType(o.destination_swap.chain)){case X.BlockchainType.EVM:{await this.evmRedeem(o,f.val.secret);break}case X.BlockchainType.Bitcoin:{const l=this.getWallet(o.destination_swap.chain);if(l.error){this.emit("error",o,l.error);return}await this.btcRedeem(l.val,o,f.val.secret);break}default:this.emit("error",o,"Unsupported chain: "+o.destination_swap.chain)}break}case le.Refund:{switch(X.getBlockchainType(o.source_swap.chain)){case X.BlockchainType.EVM:{this.emit("error",o,"EVM refund is automatically done by relay service");break}case X.BlockchainType.Bitcoin:{const f=this.getWallet(o.source_swap.chain);if(f.error){this.emit("error",o,f.error);return}await this.btcRefund(f.val,o);break}default:this.emit("error",o,"Unsupported chain: "+o.source_swap.chain)}break}}}}},{per_page:500},!0)}async evmRedeem(t,r){if(this.emit("log",t.create_order.create_id,"executing evm redeem"),this.orderExecutorCache.get(t,le.Redeem)){this.emit("log",t.create_order.create_id,"already redeemed");return}const i=await this._evmRelay.redeem(t.create_order.create_id,r);if(i.error){this.emit("error",t,i.error),i.error.includes("Order already redeemed")&&this.orderExecutorCache.set(t,le.Redeem,t.destination_swap.redeem_tx_hash);return}this.orderExecutorCache.set(t,le.Redeem,i.val),this.emit("success",t,le.Redeem,i.val)}async btcRedeem(t,r,n){var f,l;const i=this.orderExecutorCache.get(r,le.Redeem),o=(f=r.destination_swap.initiate_tx_hash.split(",").at(-1))==null?void 0:f.split(":").at(0);if(!o){this.emit("error",r,"Failed to get initiate_tx_hash");return}let u=!1;if(i)if(i.btcRedeemUTXO&&i.btcRedeemUTXO!==o)u=!0,this.emit("log",r.create_order.create_id,"rbf btc redeem");else{this.emit("log",r.create_order.create_id,"btcRedeem: already redeemed");return}else if(r.destination_swap.redeem_tx_hash&&!Number(r.destination_swap.redeem_block_number))try{const b=await(await t.getProvider()).getTransaction(r.destination_swap.redeem_tx_hash);let g=!1;for(const m of b.vin)if(m.txid===o){g=!0;break}if(g){this.orderExecutorCache.set(r,le.Redeem,r.destination_swap.redeem_tx_hash,o),this.emit("log",r.create_order.create_id,"already a valid redeem");return}u=!0}catch(b){if(b.message.includes("Transaction not found"))u=!0;else{this.emit("error",r,"Failed to get redeem tx: "+b);return}}this.emit("log",r.create_order.create_id,"executing btc redeem");try{const g=await(await qt.from(t,Number(r.destination_swap.amount),r.create_order.secret_hash,st(r.destination_swap.initiator),st(r.destination_swap.redeemer),r.destination_swap.timelock,u?[o]:[])).redeem(S.trim0x(n),(l=r.create_order.additional_data)==null?void 0:l.bitcoin_optional_recipient);u?this.emit("log",r.create_order.create_id,"rbf: btc redeem success"):this.emit("success",r,le.Redeem,g),this.orderExecutorCache.set(r,le.Redeem,g,o)}catch(b){this.emit("error",r,"Failed btc redeem: "+b)}}async btcRefund(t,r){var n;if(!this.orderExecutorCache.get(r,le.Refund)){this.emit("log",r.create_order.create_id,"executing btc refund");try{const o=await(await qt.from(t,Number(r.source_swap.amount),r.create_order.secret_hash,st(r.source_swap.initiator),st(r.source_swap.redeemer),r.source_swap.timelock)).refund((n=r.create_order.additional_data)==null?void 0:n.bitcoin_optional_recipient);this.orderExecutorCache.set(r,le.Refund,o),this.emit("success",r,le.Refund,o)}catch(i){this.emit("error",r,"Failed btc refund: "+i)}}}getWallet(t){switch(X.getBlockchainType(t)){case X.BlockchainType.EVM:return S.Ok(this._evmWallet);case X.BlockchainType.Bitcoin:return S.Ok(this._btcWallet);default:return S.Err("Unsupported chain for wallet")}}async postRefundSACP(t,r){const n=this.refundSacpCache.get(t.create_order.create_id);if((n==null?void 0:n.initTxHash)===t.source_swap.initiate_tx_hash)return;const i=await qt.from(r,Number(t.source_swap.amount),t.create_order.secret_hash,st(t.source_swap.initiator),st(t.source_swap.redeemer),t.source_swap.timelock),o=t.create_order.additional_data.bitcoin_optional_recipient;if(o)try{const u=await i.generateInstantRefundSACP(o),f=this._orderbookUrl.endpoint("orders/add-instant-refund-sacp");(await S.Fetcher.post(f,{headers:{"Content-Type":"application/json"},body:JSON.stringify({order_id:t.create_order.create_id,instant_refund_tx_bytes:u})})).status==="Ok"&&this.refundSacpCache.set(t.create_order.create_id,{initTxHash:t.source_swap.initiate_tx_hash})}catch(u){this.emit("error",t,"Failed to generate and post SACP: "+u);return}}emit(t,...r){(this.eventListeners.get(t)??[]).forEach(i=>{i(...r)})}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)??[],i=n.indexOf(r);i!==-1&&n.splice(i,1)}async fetchCurrentBlockNumbers(t,r){if(!r||!r.source||!r.destination)return S.Err("Provide wallets to fetch the current block number");const n=X.isBitcoin(t.source_swap.chain)?await ae.fetchBitcoinBlockNumber(await r.source.getProvider()):await ae.fetchEVMBlockNumber(r.source);if(n.error)return S.Err(n.error);const i=X.isBitcoin(t.destination_swap.chain)?await ae.fetchBitcoinBlockNumber(await r.destination.getProvider()):await ae.fetchEVMBlockNumber(r.destination);return i.error?S.Err(i.error):S.Ok({source:n.val,destination:i.val})}async filterExpiredAndAssignStatus(t){var i;const r=await((i=this._blockNumberFetcher)==null?void 0:i.fetchBlockNumbers());if(r.error)return S.Err(r.error);const n=[];for(let o=0;o<t.length;o++){const u=t[o];if(vi(u))continue;const f=u.source_swap.chain,l=u.destination_swap.chain,b=r==null?void 0:r.val[f],g=r==null?void 0:r.val[l];if(!b||!g){this.emit("error",u,"Error while fetching CurrentBlockNumbers");continue}const m=dn(u,b,g);n.push({...u,status:m})}return S.Ok(n)}}function bt(e){return{formatters:void 0,fees:void 0,serializers:void 0,...e}}const ys="2.21.41";let zt={getDocsUrl:({docsBaseUrl:e,docsPath:t="",docsSlug:r})=>t?`${e??"https://viem.sh"}${t}${r?`#${r}`:""}`:void 0,version:`viem@${ys}`};class Z extends Error{constructor(t,r={}){var f;const n=(()=>{var l;return r.cause instanceof Z?r.cause.details:(l=r.cause)!=null&&l.message?r.cause.message:r.details})(),i=r.cause instanceof Z&&r.cause.docsPath||r.docsPath,o=(f=zt.getDocsUrl)==null?void 0:f.call(zt,{...r,docsPath:i}),u=[t||"An error occurred.","",...r.metaMessages?[...r.metaMessages,""]:[],...o?[`Docs: ${o}`]:[],...n?[`Details: ${n}`]:[],...zt.version?[`Version: ${zt.version}`]:[]].join(`
29
+ `);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=n,this.docsPath=i,this.metaMessages=r.metaMessages,this.name=r.name??this.name,this.shortMessage=t,this.version=ys}walk(t){return gs(this,t)}}function gs(e,t){return t!=null&&t(e)?e:e&&typeof e=="object"&&"cause"in e&&e.cause!==void 0?gs(e.cause,t):t?null:e}class pu extends Z{constructor({max:t,min:r,signed:n,size:i,value:o}){super(`Number "${o}" is not in safe ${i?`${i*8}-bit ${n?"signed":"unsigned"} `:""}integer range ${t?`(${r} to ${t})`:`(above ${r})`}`,{name:"IntegerOutOfRangeError"})}}class bu extends Z{constructor({givenSize:t,maxSize:r}){super(`Size cannot exceed ${r} bytes. Given size: ${t} bytes.`,{name:"SizeOverflowError"})}}function nr(e,{strict:t=!0}={}){return!e||typeof e!="string"?!1:t?/^0x[0-9a-fA-F]*$/.test(e):e.startsWith("0x")}function Tt(e){return nr(e,{strict:!1})?Math.ceil((e.length-2)/2):e.length}function gr(e,{dir:t="left"}={}){let r=typeof e=="string"?e.replace("0x",""):e,n=0;for(let i=0;i<r.length-1&&r[t==="left"?i:r.length-i-1].toString()==="0";i++)n++;return r=t==="left"?r.slice(n):r.slice(0,r.length-n),typeof e=="string"?(r.length===1&&t==="right"&&(r=`${r}0`),`0x${r.length%2===1?`0${r}`:r}`):r}class yu extends Z{constructor({offset:t,position:r,size:n}){super(`Slice ${r==="start"?"starting":"ending"} at offset "${t}" is out-of-bounds (size: ${n}).`,{name:"SliceOffsetOutOfBoundsError"})}}class ms extends Z{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 Ct(e,{dir:t,size:r=32}={}){return typeof e=="string"?gu(e,{dir:t,size:r}):mu(e,{dir:t,size:r})}function gu(e,{dir:t,size:r=32}={}){if(r===null)return e;const n=e.replace("0x","");if(n.length>r*2)throw new ms({size:Math.ceil(n.length/2),targetSize:r,type:"hex"});return`0x${n[t==="right"?"padEnd":"padStart"](r*2,"0")}`}function mu(e,{dir:t,size:r=32}={}){if(r===null)return e;if(e.length>r)throw new ms({size:e.length,targetSize:r,type:"bytes"});const n=new Uint8Array(r);for(let i=0;i<r;i++){const o=t==="right";n[o?i:r-i-1]=e[o?i:e.length-i-1]}return n}const _u=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function W(e,t={}){return typeof e=="number"||typeof e=="bigint"?_s(e,t):typeof e=="string"?vu(e,t):typeof e=="boolean"?wu(e,t):tt(e,t)}function wu(e,t={}){const r=`0x${Number(e)}`;return typeof t.size=="number"?(Pt(r,{size:t.size}),Ct(r,{size:t.size})):r}function tt(e,t={}){let r="";for(let i=0;i<e.length;i++)r+=_u[e[i]];const n=`0x${r}`;return typeof t.size=="number"?(Pt(n,{size:t.size}),Ct(n,{dir:"right",size:t.size})):n}function _s(e,t={}){const{signed:r,size:n}=t,i=BigInt(e);let o;n?r?o=(1n<<BigInt(n)*8n-1n)-1n:o=2n**(BigInt(n)*8n)-1n:typeof e=="number"&&(o=BigInt(Number.MAX_SAFE_INTEGER));const u=typeof o=="bigint"&&r?-o-1n:0;if(o&&i>o||i<u){const l=typeof e=="bigint"?"n":"";throw new pu({max:o?`${o}${l}`:void 0,min:`${u}${l}`,signed:r,size:n,value:`${e}${l}`})}const f=`0x${(r&&i<0?(1n<<BigInt(n*8))+BigInt(i):i).toString(16)}`;return n?Ct(f,{size:n}):f}const xu=new TextEncoder;function vu(e,t={}){const r=xu.encode(e);return tt(r,t)}const Eu=new TextEncoder;function ws(e,t={}){return typeof e=="number"||typeof e=="bigint"?Su(e,t):typeof e=="boolean"?Bu(e,t):nr(e)?ut(e,t):xs(e,t)}function Bu(e,t={}){const r=new Uint8Array(1);return r[0]=Number(e),typeof t.size=="number"?(Pt(r,{size:t.size}),Ct(r,{size:t.size})):r}const $e={zero:48,nine:57,A:65,F:70,a:97,f:102};function ci(e){if(e>=$e.zero&&e<=$e.nine)return e-$e.zero;if(e>=$e.A&&e<=$e.F)return e-($e.A-10);if(e>=$e.a&&e<=$e.f)return e-($e.a-10)}function ut(e,t={}){let r=e;t.size&&(Pt(r,{size:t.size}),r=Ct(r,{dir:"right",size:t.size}));let n=r.slice(2);n.length%2&&(n=`0${n}`);const i=n.length/2,o=new Uint8Array(i);for(let u=0,f=0;u<i;u++){const l=ci(n.charCodeAt(f++)),b=ci(n.charCodeAt(f++));if(l===void 0||b===void 0)throw new Z(`Invalid byte sequence ("${n[f-2]}${n[f-1]}" in "${n}").`);o[u]=l*16+b}return o}function Su(e,t){const r=_s(e,t);return ut(r)}function xs(e,t={}){const r=Eu.encode(e);return typeof t.size=="number"?(Pt(r,{size:t.size}),Ct(r,{dir:"right",size:t.size})):r}function Pt(e,{size:t}){if(Tt(e)>t)throw new bu({givenSize:Tt(e),maxSize:t})}function xt(e,t={}){const{signed:r}=t;t.size&&Pt(e,{size:t.size});const n=BigInt(e);if(!r)return n;const i=(e.length-2)/2,o=(1n<<BigInt(i)*8n-1n)-1n;return n<=o?n:n-BigInt(`0x${"f".padStart(i*2,"f")}`)-1n}function mr(e,t={}){return Number(xt(e,t))}function En(e,t){return({exclude:r,format:n})=>({exclude:r,format:i=>{const o=t(i);if(r)for(const u of r)delete o[u];return{...o,...n(i)}},type:e})}const vs={"0x0":"legacy","0x1":"eip2930","0x2":"eip1559","0x3":"eip4844","0x4":"eip7702"};function Bn(e){const t={...e,blockHash:e.blockHash?e.blockHash:null,blockNumber:e.blockNumber?BigInt(e.blockNumber):null,chainId:e.chainId?mr(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?mr(e.nonce):void 0,to:e.to?e.to:null,transactionIndex:e.transactionIndex?Number(e.transactionIndex):null,type:e.type?vs[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=Iu(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}const Au=En("transaction",Bn);function Iu(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 Tu(e){var r;const t=(r=e.transactions)==null?void 0:r.map(n=>typeof n=="string"?n:Bn(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:t,totalDifficulty:e.totalDifficulty?BigInt(e.totalDifficulty):null}}const Ru=En("block",Tu);function ku(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 Cu={"0x0":"reverted","0x1":"success"};function Pu(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=>ku(r)):null,to:e.to?e.to:null,transactionIndex:e.transactionIndex?mr(e.transactionIndex):null,status:e.status?Cu[e.status]:null,type:e.type?vs[e.type]||e.type:null};return e.blobGasPrice&&(t.blobGasPrice=BigInt(e.blobGasPrice)),e.blobGasUsed&&(t.blobGasUsed=BigInt(e.blobGasUsed)),t}const Lu=En("transactionReceipt",Pu),Sn=2n**256n-1n;function ir(e){return`0x${e.reduce((t,r)=>t+r.replace("0x",""),"")}`}class li extends Z{constructor({offset:t}){super(`Offset \`${t}\` cannot be negative.`,{name:"NegativeOffsetError"})}}class Ou extends Z{constructor({length:t,position:r}){super(`Position \`${r}\` is out of bounds (\`0 < position < ${t}\`).`,{name:"PositionOutOfBoundsError"})}}class Fu extends Z{constructor({count:t,limit:r}){super(`Recursive read limit of \`${r}\` exceeded (recursive read count: \`${t}\`).`,{name:"RecursiveReadLimitExceededError"})}}const Uu={bytes:new Uint8Array,dataView:new DataView(new ArrayBuffer(0)),position:0,positionReadCount:new Map,recursiveReadCount:0,recursiveReadLimit:Number.POSITIVE_INFINITY,assertReadLimit(){if(this.recursiveReadCount>=this.recursiveReadLimit)throw new Fu({count:this.recursiveReadCount+1,limit:this.recursiveReadLimit})},assertPosition(e){if(e<0||e>this.bytes.length-1)throw new Ou({length:this.bytes.length,position:e})},decrementPosition(e){if(e<0)throw new li({offset:e});const t=this.position-e;this.assertPosition(t),this.position=t},getReadCount(e){return this.positionReadCount.get(e||this.position)||0},incrementPosition(e){if(e<0)throw new li({offset:e});const t=this.position+e;this.assertPosition(t),this.position=t},inspectByte(e){const t=e??this.position;return this.assertPosition(t),this.bytes[t]},inspectBytes(e,t){const r=t??this.position;return this.assertPosition(r+e-1),this.bytes.subarray(r,r+e)},inspectUint8(e){const t=e??this.position;return this.assertPosition(t),this.bytes[t]},inspectUint16(e){const t=e??this.position;return this.assertPosition(t+1),this.dataView.getUint16(t)},inspectUint24(e){const t=e??this.position;return this.assertPosition(t+2),(this.dataView.getUint16(t)<<8)+this.dataView.getUint8(t+2)},inspectUint32(e){const t=e??this.position;return this.assertPosition(t+3),this.dataView.getUint32(t)},pushByte(e){this.assertPosition(this.position),this.bytes[this.position]=e,this.position++},pushBytes(e){this.assertPosition(this.position+e.length-1),this.bytes.set(e,this.position),this.position+=e.length},pushUint8(e){this.assertPosition(this.position),this.bytes[this.position]=e,this.position++},pushUint16(e){this.assertPosition(this.position+1),this.dataView.setUint16(this.position,e),this.position+=2},pushUint24(e){this.assertPosition(this.position+2),this.dataView.setUint16(this.position,e>>8),this.dataView.setUint8(this.position+2,e&255),this.position+=3},pushUint32(e){this.assertPosition(this.position+3),this.dataView.setUint32(this.position,e),this.position+=4},readByte(){this.assertReadLimit(),this._touch();const e=this.inspectByte();return this.position++,e},readBytes(e,t){this.assertReadLimit(),this._touch();const r=this.inspectBytes(e);return this.position+=t??e,r},readUint8(){this.assertReadLimit(),this._touch();const e=this.inspectUint8();return this.position+=1,e},readUint16(){this.assertReadLimit(),this._touch();const e=this.inspectUint16();return this.position+=2,e},readUint24(){this.assertReadLimit(),this._touch();const e=this.inspectUint24();return this.position+=3,e},readUint32(){this.assertReadLimit(),this._touch();const e=this.inspectUint32();return this.position+=4,e},get remaining(){return this.bytes.length-this.position},setPosition(e){const t=this.position;return this.assertPosition(e),this.position=e,()=>this.position=t},_touch(){if(this.recursiveReadLimit===Number.POSITIVE_INFINITY)return;const e=this.getReadCount();this.positionReadCount.set(this.position,e+1),e>0&&this.recursiveReadCount++}};function Es(e,{recursiveReadLimit:t=8192}={}){const r=Object.create(Uu);return r.bytes=e,r.dataView=new DataView(e.buffer,e.byteOffset,e.byteLength),r.positionReadCount=new Map,r.recursiveReadLimit=t,r}function ct(e,t="hex"){const r=Bs(e),n=Es(new Uint8Array(r.length));return r.encode(n),t==="hex"?tt(n.bytes):n.bytes}function Bs(e){return Array.isArray(e)?Nu(e.map(t=>Bs(t))):Mu(e)}function Nu(e){const t=e.reduce((i,o)=>i+o.length,0),r=Ss(t);return{length:t<=55?1+t:1+r+t,encode(i){t<=55?i.pushByte(192+t):(i.pushByte(247+r),r===1?i.pushUint8(t):r===2?i.pushUint16(t):r===3?i.pushUint24(t):i.pushUint32(t));for(const{encode:o}of e)o(i)}}}function Mu(e){const t=typeof e=="string"?ut(e):e,r=Ss(t.length);return{length:t.length===1&&t[0]<128?1:t.length<=55?1+t.length:1+r+t.length,encode(i){t.length===1&&t[0]<128?i.pushBytes(t):t.length<=55?(i.pushByte(128+t.length),i.pushBytes(t)):(i.pushByte(183+r),r===1?i.pushUint8(t.length):r===2?i.pushUint16(t.length):r===3?i.pushUint24(t.length):i.pushUint32(t.length),i.pushBytes(t))}}}function Ss(e){if(e<2**8)return 1;if(e<2**16)return 2;if(e<2**24)return 3;if(e<2**32)return 4;throw new Z("Length is too large.")}const Du={ether:-9,wei:9};function $u(e,t){let r=e.toString();const n=r.startsWith("-");n&&(r=r.slice(1)),r=r.padStart(t,"0");let[i,o]=[r.slice(0,r.length-t),r.slice(r.length-t)];return o=o.replace(/(0+)$/,""),`${n?"-":""}${i||"0"}${o?`.${o}`:""}`}function ln(e,t="wei"){return $u(e,Du[t])}function Hu(e){const t=Object.entries(e).map(([n,i])=>i===void 0||i===!1?null:[n,i]).filter(Boolean),r=t.reduce((n,[i])=>Math.max(n,i.length),0);return t.map(([n,i])=>` ${`${n}:`.padEnd(r+1)} ${i}`).join(`
30
+ `)}class zu extends Z{constructor({v:t}){super(`Invalid \`v\` value "${t}". Expected 27 or 28.`,{name:"InvalidLegacyVError"})}}class Gu extends Z{constructor({transaction:t}){super("Cannot infer a transaction type from provided transaction.",{metaMessages:["Provided Transaction:","{",Hu(t),"}","","To infer the type, either provide:","- a `type` to the Transaction, or","- an EIP-1559 Transaction with `maxFeePerGas`, or","- an EIP-2930 Transaction with `gasPrice` & `accessList`, or","- an EIP-4844 Transaction with `blobs`, `blobVersionedHashes`, `sidecars`, or","- an EIP-7702 Transaction with `authorizationList`, or","- a Legacy Transaction with `gasPrice`"],name:"InvalidSerializableTransactionError"})}}class ju extends Z{constructor({storageKey:t}){super(`Size for storage key "${t}" is invalid. Expected 32 bytes. Got ${Math.floor((t.length-2)/2)} bytes.`,{name:"InvalidStorageKeySizeError"})}}function As(e){const{kzg:t}=e,r=e.to??(typeof e.blobs[0]=="string"?"hex":"bytes"),n=typeof e.blobs[0]=="string"?e.blobs.map(o=>ut(o)):e.blobs,i=[];for(const o of n)i.push(Uint8Array.from(t.blobToKzgCommitment(o)));return r==="bytes"?i:i.map(o=>tt(o))}function Is(e){const{kzg:t}=e,r=e.to??(typeof e.blobs[0]=="string"?"hex":"bytes"),n=typeof e.blobs[0]=="string"?e.blobs.map(u=>ut(u)):e.blobs,i=typeof e.commitments[0]=="string"?e.commitments.map(u=>ut(u)):e.commitments,o=[];for(let u=0;u<n.length;u++){const f=n[u],l=i[u];o.push(Uint8Array.from(t.computeBlobKzgProof(f,l)))}return r==="bytes"?o:o.map(u=>tt(u))}function hi(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function Wu(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function An(e,...t){if(!Wu(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${e.length}`)}function _r(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Ts(e,t){An(e);const r=t.outputLen;if(e.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const qu=e=>new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4)),Xr=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),Oe=(e,t)=>e<<32-t|e>>>t,di=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68,Vu=e=>e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255;function pi(e){for(let t=0;t<e.length;t++)e[t]=Vu(e[t])}function Ku(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function In(e){return typeof e=="string"&&(e=Ku(e)),An(e),e}class Rs{clone(){return this._cloneInto()}}function ks(e){const t=n=>e().update(In(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function Yu(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);const i=BigInt(32),o=BigInt(4294967295),u=Number(r>>i&o),f=Number(r&o),l=n?4:0,b=n?0:4;e.setUint32(t+l,u,n),e.setUint32(t+b,f,n)}const Ju=(e,t,r)=>e&t^~e&r,Xu=(e,t,r)=>e&t^e&r^t&r;class Qu extends Rs{constructor(t,r,n,i){super(),this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=Xr(this.buffer)}update(t){_r(this);const{view:r,buffer:n,blockLen:i}=this;t=In(t);const o=t.length;for(let u=0;u<o;){const f=Math.min(i-this.pos,o-u);if(f===i){const l=Xr(t);for(;i<=o-u;u+=i)this.process(l,u);continue}n.set(t.subarray(u,u+f),this.pos),this.pos+=f,u+=f,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){_r(this),Ts(t,this),this.finished=!0;const{buffer:r,view:n,blockLen:i,isLE:o}=this;let{pos:u}=this;r[u++]=128,this.buffer.subarray(u).fill(0),this.padOffset>i-u&&(this.process(n,0),u=0);for(let m=u;m<i;m++)r[m]=0;Yu(n,i-8,BigInt(this.length*8),o),this.process(n,0);const f=Xr(t),l=this.outputLen;if(l%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const b=l/4,g=this.get();if(b>g.length)throw new Error("_sha2: outputLen bigger than state");for(let m=0;m<b;m++)f.setUint32(4*m,g[m],o)}digest(){const{buffer:t,outputLen:r}=this;this.digestInto(t);const n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:r,buffer:n,length:i,finished:o,destroyed:u,pos:f}=this;return t.length=i,t.pos=f,t.finished=o,t.destroyed=u,i%r&&t.buffer.set(n),t}}const Zu=new Uint32Array([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]),Ye=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Je=new Uint32Array(64);class ec extends Qu{constructor(){super(64,32,8,!1),this.A=Ye[0]|0,this.B=Ye[1]|0,this.C=Ye[2]|0,this.D=Ye[3]|0,this.E=Ye[4]|0,this.F=Ye[5]|0,this.G=Ye[6]|0,this.H=Ye[7]|0}get(){const{A:t,B:r,C:n,D:i,E:o,F:u,G:f,H:l}=this;return[t,r,n,i,o,u,f,l]}set(t,r,n,i,o,u,f,l){this.A=t|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=o|0,this.F=u|0,this.G=f|0,this.H=l|0}process(t,r){for(let m=0;m<16;m++,r+=4)Je[m]=t.getUint32(r,!1);for(let m=16;m<64;m++){const v=Je[m-15],A=Je[m-2],I=Oe(v,7)^Oe(v,18)^v>>>3,k=Oe(A,17)^Oe(A,19)^A>>>10;Je[m]=k+Je[m-7]+I+Je[m-16]|0}let{A:n,B:i,C:o,D:u,E:f,F:l,G:b,H:g}=this;for(let m=0;m<64;m++){const v=Oe(f,6)^Oe(f,11)^Oe(f,25),A=g+v+Ju(f,l,b)+Zu[m]+Je[m]|0,k=(Oe(n,2)^Oe(n,13)^Oe(n,22))+Xu(n,i,o)|0;g=b,b=l,l=f,f=u+A|0,u=o,o=i,i=n,n=A+k|0}n=n+this.A|0,i=i+this.B|0,o=o+this.C|0,u=u+this.D|0,f=f+this.E|0,l=l+this.F|0,b=b+this.G|0,g=g+this.H|0,this.set(n,i,o,u,f,l,b,g)}roundClean(){Je.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}const tc=ks(()=>new ec);function rc(e,t){return tc(nr(e,{strict:!1})?ws(e):e)}function nc(e){const{commitment:t,version:r=1}=e,n=e.to??(typeof t=="string"?"hex":"bytes"),i=rc(t);return i.set([r],0),n==="bytes"?i:tt(i)}function ic(e){const{commitments:t,version:r}=e,n=e.to??(typeof t[0]=="string"?"hex":"bytes"),i=[];for(const o of t)i.push(nc({commitment:o,to:n,version:r}));return i}const bi=6,Cs=32,Tn=4096,Ps=Cs*Tn,yi=Ps*bi-1-1*Tn*bi,Ls=1;class sc extends Z{constructor({maxSize:t,size:r}){super("Blob size is too large.",{metaMessages:[`Max: ${t} bytes`,`Given: ${r} bytes`],name:"BlobSizeTooLargeError"})}}class Os extends Z{constructor(){super("Blob data must not be empty.",{name:"EmptyBlobError"})}}class oc extends Z{constructor({hash:t,size:r}){super(`Versioned hash "${t}" size is invalid.`,{metaMessages:["Expected: 32",`Received: ${r}`],name:"InvalidVersionedHashSizeError"})}}class ac extends Z{constructor({hash:t,version:r}){super(`Versioned hash "${t}" version is invalid.`,{metaMessages:[`Expected: ${Ls}`,`Received: ${r}`],name:"InvalidVersionedHashVersionError"})}}function fc(e){const t=e.to??(typeof e.data=="string"?"hex":"bytes"),r=typeof e.data=="string"?ut(e.data):e.data,n=Tt(r);if(!n)throw new Os;if(n>yi)throw new sc({maxSize:yi,size:n});const i=[];let o=!0,u=0;for(;o;){const f=Es(new Uint8Array(Ps));let l=0;for(;l<Tn;){const b=r.slice(u,u+(Cs-1));if(f.pushByte(0),f.pushBytes(b),b.length<31){f.pushByte(128),o=!1;break}l++,u+=31}i.push(f)}return t==="bytes"?i.map(f=>f.bytes):i.map(f=>tt(f.bytes))}function uc(e){const{data:t,kzg:r,to:n}=e,i=e.blobs??fc({data:t,to:n}),o=e.commitments??As({blobs:i,kzg:r,to:n}),u=e.proofs??Is({blobs:i,commitments:o,kzg:r,to:n}),f=[];for(let l=0;l<i.length;l++)f.push({blob:i[l],commitment:o[l],proof:u[l]});return f}function cc(e){if(!e||e.length===0)return[];const t=[];for(const r of e){const{contractAddress:n,chainId:i,nonce:o,...u}=r;t.push([i?W(i):"0x",n,o?W(o):"0x",...sr({},u)])}return t}class lt extends Z{constructor({address:t}){super(`Address "${t}" is invalid.`,{metaMessages:["- Address must be a hex value of 20 bytes (40 hex characters).","- Address must match its checksum counterpart."],name:"InvalidAddressError"})}}class Lr extends Z{constructor({chainId:t}){super(typeof t=="number"?`Chain ID "${t}" is invalid.`:"Chain ID is invalid.",{name:"InvalidChainIdError"})}}class Or extends Z{constructor({cause:t,maxFeePerGas:r}={}){super(`The fee cap (\`maxFeePerGas\`${r?` = ${ln(r)} gwei`:""}) cannot be higher than the maximum allowed value (2^256-1).`,{cause:t,name:"FeeCapTooHighError"})}}Object.defineProperty(Or,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/max fee per gas higher than 2\^256-1|fee cap higher than 2\^256-1/});class Fs extends Z{constructor({cause:t,maxPriorityFeePerGas:r,maxFeePerGas:n}={}){super([`The provided tip (\`maxPriorityFeePerGas\`${r?` = ${ln(r)} gwei`:""}) cannot be higher than the fee cap (\`maxFeePerGas\`${n?` = ${ln(n)} gwei`:""}).`].join(`
31
+ `),{cause:t,name:"TipAboveFeeCapError"})}}Object.defineProperty(Fs,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/max priority fee per gas higher than max fee per gas|tip higher than fee cap/});class Us extends Map{constructor(t){super(),Object.defineProperty(this,"maxSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.maxSize=t}get(t){const r=super.get(t);return super.has(t)&&r!==void 0&&(this.delete(t),super.set(t,r)),r}set(t,r){if(super.set(t,r),this.maxSize&&this.size>this.maxSize){const n=this.keys().next().value;n&&this.delete(n)}return this}}const ur=BigInt(2**32-1),gi=BigInt(32);function lc(e,t=!1){return t?{h:Number(e&ur),l:Number(e>>gi&ur)}:{h:Number(e>>gi&ur)|0,l:Number(e&ur)|0}}function hc(e,t=!1){let r=new Uint32Array(e.length),n=new Uint32Array(e.length);for(let i=0;i<e.length;i++){const{h:o,l:u}=lc(e[i],t);[r[i],n[i]]=[o,u]}return[r,n]}const dc=(e,t,r)=>e<<r|t>>>32-r,pc=(e,t,r)=>t<<r|e>>>32-r,bc=(e,t,r)=>t<<r-32|e>>>64-r,yc=(e,t,r)=>e<<r-32|t>>>64-r,Ns=[],Ms=[],Ds=[],gc=BigInt(0),Gt=BigInt(1),mc=BigInt(2),_c=BigInt(7),wc=BigInt(256),xc=BigInt(113);for(let e=0,t=Gt,r=1,n=0;e<24;e++){[r,n]=[n,(2*r+3*n)%5],Ns.push(2*(5*n+r)),Ms.push((e+1)*(e+2)/2%64);let i=gc;for(let o=0;o<7;o++)t=(t<<Gt^(t>>_c)*xc)%wc,t&mc&&(i^=Gt<<(Gt<<BigInt(o))-Gt);Ds.push(i)}const[vc,Ec]=hc(Ds,!0),mi=(e,t,r)=>r>32?bc(e,t,r):dc(e,t,r),_i=(e,t,r)=>r>32?yc(e,t,r):pc(e,t,r);function Bc(e,t=24){const r=new Uint32Array(10);for(let n=24-t;n<24;n++){for(let u=0;u<10;u++)r[u]=e[u]^e[u+10]^e[u+20]^e[u+30]^e[u+40];for(let u=0;u<10;u+=2){const f=(u+8)%10,l=(u+2)%10,b=r[l],g=r[l+1],m=mi(b,g,1)^r[f],v=_i(b,g,1)^r[f+1];for(let A=0;A<50;A+=10)e[u+A]^=m,e[u+A+1]^=v}let i=e[2],o=e[3];for(let u=0;u<24;u++){const f=Ms[u],l=mi(i,o,f),b=_i(i,o,f),g=Ns[u];i=e[g],o=e[g+1],e[g]=l,e[g+1]=b}for(let u=0;u<50;u+=10){for(let f=0;f<10;f++)r[f]=e[u+f];for(let f=0;f<10;f++)e[u+f]^=~r[(f+2)%10]&r[(f+4)%10]}e[0]^=vc[n],e[1]^=Ec[n]}r.fill(0)}class Rn extends Rs{constructor(t,r,n,i=!1,o=24){if(super(),this.blockLen=t,this.suffix=r,this.outputLen=n,this.enableXOF=i,this.rounds=o,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,hi(n),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=qu(this.state)}keccak(){di||pi(this.state32),Bc(this.state32,this.rounds),di||pi(this.state32),this.posOut=0,this.pos=0}update(t){_r(this);const{blockLen:r,state:n}=this;t=In(t);const i=t.length;for(let o=0;o<i;){const u=Math.min(r-this.pos,i-o);for(let f=0;f<u;f++)n[this.pos++]^=t[o++];this.pos===r&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:t,suffix:r,pos:n,blockLen:i}=this;t[n]^=r,r&128&&n===i-1&&this.keccak(),t[i-1]^=128,this.keccak()}writeInto(t){_r(this,!1),An(t),this.finish();const r=this.state,{blockLen:n}=this;for(let i=0,o=t.length;i<o;){this.posOut>=n&&this.keccak();const u=Math.min(n-this.posOut,o-i);t.set(r.subarray(this.posOut,this.posOut+u),i),this.posOut+=u,i+=u}return t}xofInto(t){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(t)}xof(t){return hi(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(Ts(t,this),this.finished)throw new Error("digest() was already called");return this.writeInto(t),this.destroy(),t}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(t){const{blockLen:r,suffix:n,outputLen:i,rounds:o,enableXOF:u}=this;return t||(t=new Rn(r,n,i,u,o)),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=o,t.suffix=n,t.outputLen=i,t.enableXOF=u,t.destroyed=this.destroyed,t}}const Sc=(e,t,r)=>ks(()=>new Rn(t,e,r)),Ac=Sc(1,136,256/8);function Ic(e,t){return Ac(nr(e,{strict:!1})?ws(e):e)}const Qr=new Us(8192);function Tc(e,t){if(Qr.has(`${e}.${t}`))return Qr.get(`${e}.${t}`);const r=e.substring(2).toLowerCase(),n=Ic(xs(r)),i=r.split("");for(let u=0;u<40;u+=2)n[u>>1]>>4>=8&&i[u]&&(i[u]=i[u].toUpperCase()),(n[u>>1]&15)>=8&&i[u+1]&&(i[u+1]=i[u+1].toUpperCase());const o=`0x${i.join("")}`;return Qr.set(`${e}.${t}`,o),o}const Rc=/^0x[a-fA-F0-9]{40}$/,Zr=new Us(8192);function ht(e,t){const{strict:r=!0}=t??{},n=`${e}.${r}`;if(Zr.has(n))return Zr.get(n);const i=Rc.test(e)?e.toLowerCase()===e?!0:r?Tc(e)===e:!0:!1;return Zr.set(n,i),i}function kc(e,t,r,{strict:n}={}){return nr(e,{strict:!1})?Pc(e,t,r,{strict:n}):Cc(e,t,r,{strict:n})}function $s(e,t,r){if(Tt(e)!==r-t)throw new yu({offset:r,position:"end",size:Tt(e)})}function Cc(e,t,r,{strict:n}={}){const i=e.slice(t,r);return n&&$s(i,t,r),i}function Pc(e,t,r,{strict:n}={}){const i=`0x${e.replace("0x","").slice(t*2,r*2)}`;return n&&$s(i,t,r),i}function Lc(e){const{authorizationList:t}=e;if(t)for(const r of t){const{contractAddress:n,chainId:i}=r;if(!ht(n))throw new lt({address:n});if(i<0)throw new Lr({chainId:i})}kn(e)}function Oc(e){const{blobVersionedHashes:t}=e;if(t){if(t.length===0)throw new Os;for(const r of t){const n=Tt(r),i=mr(kc(r,0,1));if(n!==32)throw new oc({hash:r,size:n});if(i!==Ls)throw new ac({hash:r,version:i})}}kn(e)}function kn(e){const{chainId:t,maxPriorityFeePerGas:r,maxFeePerGas:n,to:i}=e;if(t<=0)throw new Lr({chainId:t});if(i&&!ht(i))throw new lt({address:i});if(n&&n>Sn)throw new Or({maxFeePerGas:n});if(r&&n&&r>n)throw new Fs({maxFeePerGas:n,maxPriorityFeePerGas:r})}function Fc(e){const{chainId:t,maxPriorityFeePerGas:r,gasPrice:n,maxFeePerGas:i,to:o}=e;if(t<=0)throw new Lr({chainId:t});if(o&&!ht(o))throw new lt({address:o});if(r||i)throw new Z("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid EIP-2930 Transaction attribute.");if(n&&n>Sn)throw new Or({maxFeePerGas:n})}function Uc(e){const{chainId:t,maxPriorityFeePerGas:r,gasPrice:n,maxFeePerGas:i,to:o}=e;if(o&&!ht(o))throw new lt({address:o});if(typeof t<"u"&&t<=0)throw new Lr({chainId:t});if(r||i)throw new Z("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid Legacy Transaction attribute.");if(n&&n>Sn)throw new Or({maxFeePerGas:n})}function Nc(e){if(e.type)return e.type;if(typeof e.authorizationList<"u")return"eip7702";if(typeof e.blobs<"u"||typeof e.blobVersionedHashes<"u"||typeof e.maxFeePerBlobGas<"u"||typeof e.sidecars<"u")return"eip4844";if(typeof e.maxFeePerGas<"u"||typeof e.maxPriorityFeePerGas<"u")return"eip1559";if(typeof e.gasPrice<"u")return typeof e.accessList<"u"?"eip2930":"legacy";throw new Gu({transaction:e})}function Fr(e){if(!e||e.length===0)return[];const t=[];for(let r=0;r<e.length;r++){const{address:n,storageKeys:i}=e[r];for(let o=0;o<i.length;o++)if(i[o].length-2!==64)throw new ju({storageKey:i[o]});if(!ht(n,{strict:!1}))throw new lt({address:n});t.push([n,i])}return t}function Mc(e,t){const r=Nc(e);return r==="eip1559"?Hc(e,t):r==="eip2930"?zc(e,t):r==="eip4844"?$c(e,t):r==="eip7702"?Dc(e,t):Gc(e,t)}function Dc(e,t){const{authorizationList:r,chainId:n,gas:i,nonce:o,to:u,value:f,maxFeePerGas:l,maxPriorityFeePerGas:b,accessList:g,data:m}=e;Lc(e);const v=Fr(g),A=cc(r);return ir(["0x04",ct([W(n),o?W(o):"0x",b?W(b):"0x",l?W(l):"0x",i?W(i):"0x",u??"0x",f?W(f):"0x",m??"0x",v,A,...sr(e,t)])])}function $c(e,t){const{chainId:r,gas:n,nonce:i,to:o,value:u,maxFeePerBlobGas:f,maxFeePerGas:l,maxPriorityFeePerGas:b,accessList:g,data:m}=e;Oc(e);let v=e.blobVersionedHashes,A=e.sidecars;if(e.blobs&&(typeof v>"u"||typeof A>"u")){const O=typeof e.blobs[0]=="string"?e.blobs:e.blobs.map(B=>tt(B)),L=e.kzg,U=As({blobs:O,kzg:L});if(typeof v>"u"&&(v=ic({commitments:U})),typeof A>"u"){const B=Is({blobs:O,commitments:U,kzg:L});A=uc({blobs:O,commitments:U,proofs:B})}}const I=Fr(g),k=[W(r),i?W(i):"0x",b?W(b):"0x",l?W(l):"0x",n?W(n):"0x",o??"0x",u?W(u):"0x",m??"0x",I,f?W(f):"0x",v??[],...sr(e,t)],C=[],P=[],F=[];if(A)for(let O=0;O<A.length;O++){const{blob:L,commitment:U,proof:B}=A[O];C.push(L),P.push(U),F.push(B)}return ir(["0x03",ct(A?[k,C,P,F]:k)])}function Hc(e,t){const{chainId:r,gas:n,nonce:i,to:o,value:u,maxFeePerGas:f,maxPriorityFeePerGas:l,accessList:b,data:g}=e;kn(e);const m=Fr(b),v=[W(r),i?W(i):"0x",l?W(l):"0x",f?W(f):"0x",n?W(n):"0x",o??"0x",u?W(u):"0x",g??"0x",m,...sr(e,t)];return ir(["0x02",ct(v)])}function zc(e,t){const{chainId:r,gas:n,data:i,nonce:o,to:u,value:f,accessList:l,gasPrice:b}=e;Fc(e);const g=Fr(l),m=[W(r),o?W(o):"0x",b?W(b):"0x",n?W(n):"0x",u??"0x",f?W(f):"0x",i??"0x",g,...sr(e,t)];return ir(["0x01",ct(m)])}function Gc(e,t){const{chainId:r=0,gas:n,data:i,nonce:o,to:u,value:f,gasPrice:l}=e;Uc(e);let b=[o?W(o):"0x",l?W(l):"0x",n?W(n):"0x",u??"0x",f?W(f):"0x",i??"0x"];if(t){const g=(()=>{if(t.v>=35n)return(t.v-35n)/2n>0?t.v:27n+(t.v===35n?0n:1n);if(r>0)return BigInt(r*2)+BigInt(35n+t.v-27n);const A=27n+(t.v===27n?0n:1n);if(t.v!==A)throw new zu({v:t.v});return A})(),m=gr(t.r),v=gr(t.s);b=[...b,W(g),m==="0x00"?"0x":m,v==="0x00"?"0x":v]}else r>0&&(b=[...b,W(r),"0x","0x"]);return ct(b)}function sr(e,t){const r=t??e,{v:n,yParity:i}=r;if(typeof r.r>"u")return[];if(typeof r.s>"u")return[];if(typeof n>"u"&&typeof i>"u")return[];const o=gr(r.r),u=gr(r.s);return[typeof i=="number"?i?W(1):"0x":n===0n?"0x":n===1n?W(1):n===27n?"0x":W(1),o==="0x00"?"0x":o,u==="0x00"?"0x":u]}const jc={gasPriceOracle:{address:"0x420000000000000000000000000000000000000F"},l1Block:{address:"0x4200000000000000000000000000000000000015"},l2CrossDomainMessenger:{address:"0x4200000000000000000000000000000000000007"},l2Erc721Bridge:{address:"0x4200000000000000000000000000000000000014"},l2StandardBridge:{address:"0x4200000000000000000000000000000000000010"},l2ToL1MessagePasser:{address:"0x4200000000000000000000000000000000000016"}},Wc={block:Ru({format(e){var r;return{transactions:(r=e.transactions)==null?void 0:r.map(n=>{if(typeof n=="string")return n;const i=Bn(n);return i.typeHex==="0x7e"&&(i.isSystemTx=n.isSystemTx,i.mint=n.mint?xt(n.mint):void 0,i.sourceHash=n.sourceHash,i.type="deposit"),i}),stateRoot:e.stateRoot}}}),transaction:Au({format(e){const t={};return e.type==="0x7e"&&(t.isSystemTx=e.isSystemTx,t.mint=e.mint?xt(e.mint):void 0,t.sourceHash=e.sourceHash,t.type="deposit"),t}}),transactionReceipt:Lu({format(e){return{l1GasPrice:e.l1GasPrice?xt(e.l1GasPrice):null,l1GasUsed:e.l1GasUsed?xt(e.l1GasUsed):null,l1Fee:e.l1Fee?xt(e.l1Fee):null,l1FeeScalar:e.l1FeeScalar?Number(e.l1FeeScalar):null}}})};function qc(e,t){return Yc(e)?Kc(e):Mc(e,t)}const Vc={transaction:qc};function Kc(e){Jc(e);const{sourceHash:t,data:r,from:n,gas:i,isSystemTx:o,mint:u,to:f,value:l}=e,b=[t,n,f??"0x",u?W(u):"0x",l?W(l):"0x",i?W(i):"0x",o?"0x1":"0x",r??"0x"];return ir(["0x7e",ct(b)])}function Yc(e){return e.type==="deposit"||typeof e.sourceHash<"u"}function Jc(e){const{from:t,to:r}=e;if(t&&!ht(t))throw new lt({address:t});if(r&&!ht(r))throw new lt({address:r})}const wr={contracts:jc,formatters:Wc,serializers:Vc},Xc=bt({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}}}),Qc=bt({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}),jt=1,Zc=bt({...wr,id:8453,name:"Base",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://mainnet.base.org"]}},blockExplorers:{default:{name:"Basescan",url:"https://basescan.org",apiUrl:"https://api.basescan.org/api"}},contracts:{...wr.contracts,disputeGameFactory:{[jt]:{address:"0x43edB88C4B80fDD2AdFF2412A7BebF9dF42cB40e"}},l2OutputOracle:{[jt]:{address:"0x56315b90c40730925ec5485cf004d835058518A0"}},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:5022},portal:{[jt]:{address:"0x49048044D57e1C92A77f79988d21Fa8fAF74E97e",blockCreated:17482143}},l1StandardBridge:{[jt]:{address:"0x3154Cf16ccdb4C6d922629664174b904d80F2C35",blockCreated:17482143}}},sourceId:jt}),Wt=11155111,el=bt({...wr,id:84532,network:"base-sepolia",name:"Base Sepolia",nativeCurrency:{name:"Sepolia Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://sepolia.base.org"]}},blockExplorers:{default:{name:"Basescan",url:"https://sepolia.basescan.org",apiUrl:"https://api-sepolia.basescan.org/api"}},contracts:{...wr.contracts,disputeGameFactory:{[Wt]:{address:"0xd6E6dBf4F7EA0ac412fD8b65ED297e64BB7a06E1"}},l2OutputOracle:{[Wt]:{address:"0x84457ca9D0163FbC4bbfe4Dfbb20ba46e48DF254"}},portal:{[Wt]:{address:"0x49f53e41452c74589e85ca1677426ba426459e85",blockCreated:4446677}},l1StandardBridge:{[Wt]:{address:"0xfd0Bf71F60660E2f608ed56e1659C450eB113120",blockCreated:4446677}},multicall3:{address:"0xca11bde05977b3631167028862be2a173976ca11",blockCreated:1059647}},testnet:!0,sourceId:Wt}),tl=bt({id:80084,name:"Berachain bArtio",nativeCurrency:{decimals:18,name:"BERA Token",symbol:"BERA"},contracts:{multicall3:{address:"0xcA11bde05977b3631167028862bE2a173976CA11",blockCreated:109269}},rpcUrls:{default:{http:["https://bartio.rpc.berachain.com"]}},blockExplorers:{default:{name:"Berachain bArtio Beratrail",url:"https://bartio.beratrail.io"}},testnet:!0}),rl=bt({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}}}),nl=bt({id:11155111,name:"Sepolia",nativeCurrency:{name:"Sepolia Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://sepolia.drpc.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}),il={...nl,rpcUrls:{default:{http:["https://ethereum-sepolia-rpc.publicnode.com"]}}},Hs=Ne.defineChain({id:5115,name:"Citrea Testnet",nativeCurrency:{name:"",symbol:"cBTC",decimals:18},rpcUrls:{default:{http:["https://rpc.testnet.citrea.xyz"]}},blockExplorers:{default:{name:"Citrea Explorer",url:"https://explorer.testnet.citrea.xyz",apiUrl:"https://explorer.testnet.citrea.xyz/api/v2/"}},testnet:!0}),zs={ethereum:rl,arbitrum:Xc,ethereum_sepolia:il,arbitrum_sepolia:Qc,ethereum_localnet:X.EthereumLocalnet,arbitrum_localnet:X.ArbitrumLocalnet,base_sepolia:el,base:Zc,bera_testnet:tl,citrea_testnet:Hs},sl=async(e,t)=>{var n;const r=zs[e];if(r)try{if(r.id===((n=t.chain)==null?void 0:n.id))return S.Ok({message:"Already on the network",walletClient:t});await t.switchChain({id:r.id});const i=Ne.createWalletClient({account:t.account,chain:r,transport:Ne.custom(window.ethereum)});return S.Ok({message:"Switched chain",walletClient:i})}catch(i){if(ol(i))try{await t.addChain({chain:r});const o=Ne.createWalletClient({account:t.account,chain:r,transport:Ne.custom(window.ethereum)});return S.Ok({message:"Added network",walletClient:o})}catch{return S.Err("Failed to add network")}else return S.Err("Failed to switch network")}else return S.Err("Chain not supported")},ol=e=>typeof e=="object"&&e!==null&&"code"in e&&e.code===4902;exports.BlockNumberFetcher=Bi;exports.EvmRelay=Ei;exports.Garden=du;exports.OrderActions=le;exports.OrderStatus=Q;exports.ParseOrderStatus=dn;exports.ParseSwapStatus=tn;exports.Quote=Si;exports.SecretManager=Jt;exports.SwapStatus=ne;exports.citreaTestnet=Hs;exports.constructOrderPair=xi;exports.evmToViemChainMap=zs;exports.filterDeadlineExpiredOrders=to;exports.isExpired=Vt;exports.parseAction=eo;exports.parseActionFromStatus=pn;exports.switchOrAddNetwork=sl;exports.validateBTCAddress=Qs;