@libp2p/websockets 9.2.18-cf9aab5c8 → 9.2.19-a02cb0461

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.min.js CHANGED
@@ -1,4 +1,4 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PWebsockets = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PWebsockets=(()=>{var Cn=Object.create;var Ae=Object.defineProperty;var vn=Object.getOwnPropertyDescriptor;var Sn=Object.getOwnPropertyNames;var Dn=Object.getPrototypeOf,In=Object.prototype.hasOwnProperty;var Yt=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),P=(t,e)=>{for(var r in e)Ae(t,r,{get:e[r],enumerable:!0})},er=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Sn(e))!In.call(t,o)&&o!==r&&Ae(t,o,{get:()=>e[o],enumerable:!(n=vn(e,o))||n.enumerable});return t};var Pn=(t,e,r)=>(r=t!=null?Cn(Dn(t)):{},er(e||!t||!t.__esModule?Ae(r,"default",{value:t,enumerable:!0}):r,t)),Tn=t=>er(Ae({},"__esModule",{value:!0}),t);var Zr=Yt(He=>{"use strict";Object.defineProperty(He,"__esModule",{value:!0});var Ht=class{constructor(){this.pullQueue=[],this.pushQueue=[],this.eventHandlers={},this.isPaused=!1,this.isStopped=!1}push(e){if(this.isStopped)return;let r={value:e,done:!1};if(this.pullQueue.length){let n=this.pullQueue.shift();n&&n.resolve(r)}else this.pushQueue.push(Promise.resolve(r)),this.highWaterMark!==void 0&&this.pushQueue.length>=this.highWaterMark&&!this.isPaused&&(this.isPaused=!0,this.eventHandlers.highWater?this.eventHandlers.highWater():console&&console.warn(`EventIterator queue reached ${this.pushQueue.length} items`))}stop(){if(!this.isStopped){this.isStopped=!0,this.remove();for(let e of this.pullQueue)e.resolve({value:void 0,done:!0});this.pullQueue.length=0}}fail(e){if(!this.isStopped)if(this.isStopped=!0,this.remove(),this.pullQueue.length){for(let r of this.pullQueue)r.reject(e);this.pullQueue.length=0}else{let r=Promise.reject(e);r.catch(()=>{}),this.pushQueue.push(r)}}remove(){Promise.resolve().then(()=>{this.removeCallback&&this.removeCallback()})}[Symbol.asyncIterator](){return{next:e=>{let r=this.pushQueue.shift();return r?(this.lowWaterMark!==void 0&&this.pushQueue.length<=this.lowWaterMark&&this.isPaused&&(this.isPaused=!1,this.eventHandlers.lowWater&&this.eventHandlers.lowWater()),r):this.isStopped?Promise.resolve({value:void 0,done:!0}):new Promise((n,o)=>{this.pullQueue.push({resolve:n,reject:o})})},return:()=>(this.isStopped=!0,this.pushQueue.length=0,this.remove(),Promise.resolve({value:void 0,done:!0}))}}},Ve=class{constructor(e,{highWaterMark:r=100,lowWaterMark:n=1}={}){let o=new Ht;o.highWaterMark=r,o.lowWaterMark=n,o.removeCallback=e({push:s=>o.push(s),stop:()=>o.stop(),fail:s=>o.fail(s),on:(s,i)=>{o.eventHandlers[s]=i}})||(()=>{}),this[Symbol.asyncIterator]=()=>o[Symbol.asyncIterator](),Object.freeze(this)}};He.EventIterator=Ve;He.default=Ve});var Yr=Yt(Te=>{"use strict";Object.defineProperty(Te,"__esModule",{value:!0});var Qt=Zr();Te.EventIterator=Qt.EventIterator;function ys(t,e,r){return new Qt.EventIterator(({push:n})=>(this.addEventListener(t,n,e),()=>this.removeEventListener(t,n,e)),r)}Te.subscribe=ys;Te.default=Qt.EventIterator});var Ls={};P(Ls,{webSockets:()=>Ns});var rr=Symbol.for("@libp2p/transport");var tr;(function(t){t[t.FATAL_ALL=0]="FATAL_ALL",t[t.NO_FATAL=1]="NO_FATAL"})(tr||(tr={}));var Ue=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var oe=class extends Error{static name="ConnectionFailedError";constructor(e="Connection failed"){super(e),this.name="ConnectionFailedError"}};var nr=Symbol.for("@libp2p/service-capabilities"),$s=Symbol.for("@libp2p/service-dependencies");var rt={};P(rt,{base10:()=>Rn});var ii=new Uint8Array(0);function or(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function W(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}function sr(t){return new TextEncoder().encode(t)}function ir(t){return new TextDecoder().decode(t)}function On(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<t.length;o++){var s=t.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=t.length,c=t.charAt(0),u=Math.log(a)/Math.log(256),h=Math.log(256)/Math.log(a);function m(x){if(x instanceof Uint8Array||(ArrayBuffer.isView(x)?x=new Uint8Array(x.buffer,x.byteOffset,x.byteLength):Array.isArray(x)&&(x=Uint8Array.from(x))),!(x instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(x.length===0)return"";for(var I=0,J=0,N=0,M=x.length;N!==M&&x[N]===0;)N++,I++;for(var B=(M-N)*h+1>>>0,O=new Uint8Array(B);N!==M;){for(var $=x[N],H=0,L=B-1;($!==0||H<J)&&L!==-1;L--,H++)$+=256*O[L]>>>0,O[L]=$%a>>>0,$=$/a>>>0;if($!==0)throw new Error("Non-zero carry");J=H,N++}for(var F=B-J;F!==B&&O[F]===0;)F++;for(var _e=c.repeat(I);F<B;++F)_e+=t.charAt(O[F]);return _e}function D(x){if(typeof x!="string")throw new TypeError("Expected String");if(x.length===0)return new Uint8Array;var I=0;if(x[I]!==" "){for(var J=0,N=0;x[I]===c;)J++,I++;for(var M=(x.length-I)*u+1>>>0,B=new Uint8Array(M);x[I];){var O=r[x.charCodeAt(I)];if(O===255)return;for(var $=0,H=M-1;(O!==0||$<N)&&H!==-1;H--,$++)O+=a*B[H]>>>0,B[H]=O%256>>>0,O=O/256>>>0;if(O!==0)throw new Error("Non-zero carry");N=$,I++}if(x[I]!==" "){for(var L=M-N;L!==M&&B[L]===0;)L++;for(var F=new Uint8Array(J+(M-L)),_e=J;L!==M;)F[_e++]=B[L++];return F}}}function yn(x){var I=D(x);if(I)return I;throw new Error(`Non-${e} character`)}return{encode:m,decodeUnsafe:D,decode:yn}}var _n=On,An=_n,cr=An;var Ze=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Ye=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return lr(this,e)}},et=class{decoders;constructor(e){this.decoders=e}or(e){return lr(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function lr(t,e){return new et({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var tt=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Ze(e,r,n),this.decoder=new Ye(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function se({name:t,prefix:e,encode:r,decode:n}){return new tt(t,e,r,n)}function Q({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=cr(r,t);return se({prefix:e,name:t,encode:n,decode:s=>W(o(s))})}function Un(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let h=e[t[u]];if(h===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|h,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Nn(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],i+=8;i>r;)i-=r,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function Ln(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function b({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=Ln(n);return se({prefix:e,name:t,encode(s){return Nn(s,n,r)},decode(s){return Un(s,o,r,t)}})}var Rn=Q({prefix:"9",name:"base10",alphabet:"0123456789"});var nt={};P(nt,{base16:()=>Mn,base16upper:()=>Bn});var Mn=b({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Bn=b({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ot={};P(ot,{base2:()=>$n});var $n=b({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var st={};P(st,{base256emoji:()=>Vn});var ur=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),zn=ur.reduce((t,e,r)=>(t[r]=e,t),[]),Fn=ur.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Wn(t){return t.reduce((e,r)=>(e+=zn[r],e),"")}function kn(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Fn[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var Vn=se({prefix:"\u{1F680}",name:"base256emoji",encode:Wn,decode:kn});var it={};P(it,{base32:()=>j,base32hex:()=>qn,base32hexpad:()=>Xn,base32hexpadupper:()=>Jn,base32hexupper:()=>Gn,base32pad:()=>Qn,base32padupper:()=>jn,base32upper:()=>Hn,base32z:()=>Kn});var j=b({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Hn=b({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Qn=b({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),jn=b({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),qn=b({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Gn=b({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Xn=b({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Jn=b({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Kn=b({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var at={};P(at,{base36:()=>me,base36upper:()=>Zn});var me=Q({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Zn=Q({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ct={};P(ct,{base58btc:()=>_,base58flickr:()=>Yn});var _=Q({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Yn=Q({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ut={};P(ut,{base64:()=>eo,base64pad:()=>to,base64url:()=>lt,base64urlpad:()=>ro});var eo=b({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),to=b({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),lt=b({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),ro=b({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var dt={};P(dt,{base8:()=>no});var no=b({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var pt={};P(pt,{identity:()=>oo});var oo=se({prefix:"\0",name:"identity",encode:t=>ir(t),decode:t=>sr(t)});var Ci=new TextEncoder,vi=new TextDecoder;var ht={};P(ht,{identity:()=>To});var ao=fr,dr=128,co=127,lo=~co,uo=Math.pow(2,31);function fr(t,e,r){e=e||[],r=r||0;for(var n=r;t>=uo;)e[r++]=t&255|dr,t/=128;for(;t&lo;)e[r++]=t&255|dr,t>>>=7;return e[r]=t|0,fr.bytes=r-n+1,e}var po=ft,fo=128,pr=127;function ft(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw ft.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&pr)<<o:(i&pr)*Math.pow(2,o),o+=7}while(i>=fo);return ft.bytes=s-n,r}var ho=Math.pow(2,7),mo=Math.pow(2,14),xo=Math.pow(2,21),wo=Math.pow(2,28),go=Math.pow(2,35),Eo=Math.pow(2,42),bo=Math.pow(2,49),yo=Math.pow(2,56),Co=Math.pow(2,63),vo=function(t){return t<ho?1:t<mo?2:t<xo?3:t<wo?4:t<go?5:t<Eo?6:t<bo?7:t<yo?8:t<Co?9:10},So={encode:ao,decode:po,encodingLength:vo},Do=So,xe=Do;function we(t,e=0){return[xe.decode(t,e),xe.decode.bytes]}function ie(t,e,r=0){return xe.encode(t,e,r),e}function ae(t){return xe.encodingLength(t)}function K(t,e){let r=e.byteLength,n=ae(t),o=n+ae(r),s=new Uint8Array(o+r);return ie(t,s,0),ie(r,s,n),s.set(e,o),new ce(t,r,e,s)}function hr(t){let e=W(t),[r,n]=we(e),[o,s]=we(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new ce(r,o,i,e)}function mr(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&or(t.bytes,r.bytes)}}var ce=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};var xr=0,Io="identity",wr=W;function Po(t){return K(xr,wr(t))}var To={code:xr,name:Io,encode:wr,digest:Po};var wt={};P(wt,{sha256:()=>Oo,sha512:()=>_o});function xt({name:t,code:e,encode:r}){return new mt(t,e,r)}var mt=class{name;code;encode;constructor(e,r,n){this.name=e,this.code=r,this.encode=n}digest(e){if(e instanceof Uint8Array){let r=this.encode(e);return r instanceof Uint8Array?K(this.code,r):r.then(n=>K(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Er(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Oo=xt({name:"sha2-256",code:18,encode:Er("SHA-256")}),_o=xt({name:"sha2-512",code:19,encode:Er("SHA-512")});function br(t,e){let{bytes:r,version:n}=t;switch(n){case 0:return Uo(r,gt(t),e??_.encoder);default:return No(r,gt(t),e??j.encoder)}}var yr=new WeakMap;function gt(t){let e=yr.get(t);if(e==null){let r=new Map;return yr.set(t,r),r}return e}var q=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==Ee)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Lo)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=K(e,r);return t.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&mr(e.multihash,n.multihash)}toString(e){return br(this,e)}toJSON(){return{"/":br(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new t(n,o,s,i??Cr(n,o,s.bytes))}else if(r[Ro]===!0){let{version:n,multihash:o,code:s}=r,i=hr(o);return t.create(n,s,i)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==Ee)throw new Error(`Version 0 CID must use dag-pb (code: ${Ee}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=Cr(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Ee,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=W(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new ce(r.multihashCode,r.digestSize,s,o);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[m,D]=we(e.subarray(r));return r+=D,m},o=n(),s=Ee;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),u=r+c,h=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:h,size:u}}static parse(e,r){let[n,o]=Ao(e,r),s=t.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return gt(s).set(n,e),s}};function Ao(t,e){switch(t[0]){case"Q":{let r=e??_;return[_.prefix,r.decode(`${_.prefix}${t}`)]}case _.prefix:{let r=e??_;return[_.prefix,r.decode(t)]}case j.prefix:{let r=e??j;return[j.prefix,r.decode(t)]}case me.prefix:{let r=e??me;return[me.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function Uo(t,e,r){let{prefix:n}=r;if(n!==_.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let s=r.encode(t).slice(1);return e.set(n,s),s}else return o}function No(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let s=r.encode(t);return e.set(n,s),s}else return o}var Ee=112,Lo=18;function Cr(t,e,r){let n=ae(t),o=n+ae(e),s=new Uint8Array(o+r.byteLength);return ie(t,s,0),ie(e,s,n),s.set(r,o),s}var Ro=Symbol.for("@ipld/js-cid/CID");var be={...pt,...ot,...dt,...rt,...nt,...it,...at,...ct,...ut,...st},Qi={...wt,...ht};function ye(t=0){return new Uint8Array(t)}function Sr(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var vr=Sr("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Et=Sr("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=ye(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Mo={utf8:vr,"utf-8":vr,hex:be.base16,latin1:Et,ascii:Et,binary:Et,...be},Le=Mo;function A(t,e="utf8"){let r=Le[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var C=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},k=class extends Error{static name="ValidationError";name="ValidationError"},Ce=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Re=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function Dr(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function z(t,e="utf8"){let r=Le[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}var Bo=Math.pow(2,7),$o=Math.pow(2,14),zo=Math.pow(2,21),bt=Math.pow(2,28),yt=Math.pow(2,35),Ct=Math.pow(2,42),vt=Math.pow(2,49),E=128,v=127;function le(t){if(t<Bo)return 1;if(t<$o)return 2;if(t<zo)return 3;if(t<bt)return 4;if(t<yt)return 5;if(t<Ct)return 6;if(t<vt)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function St(t,e,r=0){switch(le(t)){case 8:e[r++]=t&255|E,t/=128;case 7:e[r++]=t&255|E,t/=128;case 6:e[r++]=t&255|E,t/=128;case 5:e[r++]=t&255|E,t/=128;case 4:e[r++]=t&255|E,t>>>=7;case 3:e[r++]=t&255|E,t>>>=7;case 2:e[r++]=t&255|E,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Fo(t,e){let r=t[e],n=0;if(n+=r&v,r<E||(r=t[e+1],n+=(r&v)<<7,r<E)||(r=t[e+2],n+=(r&v)<<14,r<E)||(r=t[e+3],n+=(r&v)<<21,r<E)||(r=t[e+4],n+=(r&v)*bt,r<E)||(r=t[e+5],n+=(r&v)*yt,r<E)||(r=t[e+6],n+=(r&v)*Ct,r<E)||(r=t[e+7],n+=(r&v)*vt,r<E))return n;throw new RangeError("Could not decode varint")}function Wo(t,e){let r=t.get(e),n=0;if(n+=r&v,r<E||(r=t.get(e+1),n+=(r&v)<<7,r<E)||(r=t.get(e+2),n+=(r&v)<<14,r<E)||(r=t.get(e+3),n+=(r&v)<<21,r<E)||(r=t.get(e+4),n+=(r&v)*bt,r<E)||(r=t.get(e+5),n+=(r&v)*yt,r<E)||(r=t.get(e+6),n+=(r&v)*Ct,r<E)||(r=t.get(e+7),n+=(r&v)*vt,r<E))return n;throw new RangeError("Could not decode varint")}function Dt(t,e=0){return t instanceof Uint8Array?Fo(t,e):Wo(t,e)}function ve(t,e){e==null&&(e=t.reduce((o,s)=>o+s.length,0));let r=ye(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r}var Me=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let r=this.index,n=e();return n===void 0&&(this.index=r),n}parseWith(e){let r=e();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let r=this.readChar();if(r===e)return r})}readSeparator(e,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,r,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let h=this.readAtomically(()=>{let m=this.readChar();if(m===void 0)return;let D=Number.parseInt(m,e);if(!Number.isNaN(D))return D});if(h===void 0)break;if(s*=e,s+=h,s>u||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let r=0;r<e.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[r]=n}return e})}readIPv6Addr(){let e=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=e(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=e(s.subarray(0,i));return r.set(s.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Vo=45,Ho=15,Be=new Me;function It(t){if(!(t.length>Ho))return Be.new(t).parseWith(()=>Be.readIPv4Addr())}function Pt(t){if(t.includes("%")&&(t=t.split("%")[0]),!(t.length>Vo))return Be.new(t).parseWith(()=>Be.readIPv6Addr())}function $e(t){return!!It(t)}function Pr(t){return!!Pt(t)}function Ot(t){return e=>A(e,t)}function _t(t){return e=>z(e,t)}function ue(t){return new DataView(t.buffer).getUint16(t.byteOffset).toString()}function Z(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof t=="string"?parseInt(t):t),new Uint8Array(e)}function Tr(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let r=z(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Z(n);return ve([r,o],r.length+o.length)}function Or(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let r=j.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Z(n);return ve([r,o],r.length+o.length)}function At(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=A(e,"base32"),o=ue(r);return`${n}:${o}`}var Ut=function(t){t=t.toString().trim();let e=new Uint8Array(4);return t.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new C("Invalid byte value in IP address");e[n]=o}),e},_r=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let s=$e(r[n]),i;s&&(i=Ut(r[n]),r[n]=A(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,A(i.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let s=[n,1];for(n=9-r.length;n>0;n--)s.push("0");r.splice.apply(r,s)}let o=new Uint8Array(e+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let s=parseInt(r[n],16);if(isNaN(s)||s<0||s>65535)throw new C("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},Ar=function(t){if(t.byteLength!==4)throw new C("IPv4 address was incorrect length");let e=[];for(let r=0;r<t.byteLength;r++)e.push(t[r]);return e.join(".")},Ur=function(t){if(t.byteLength!==16)throw new C("IPv6 address was incorrect length");let e=[];for(let n=0;n<t.byteLength;n+=2){let o=t[n],s=t[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;e.push(i)}let r=e.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new C(`Invalid IPv6 address "${r}"`)}};function Nr(t){try{let e=new URL(`http://[${t}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new C(`Invalid IPv6 address "${t}"`)}}var Tt=Object.values(be).map(t=>t.decoder),Qo=function(){let t=Tt[0].or(Tt[1]);return Tt.slice(2).forEach(e=>t=t.or(e)),t}();function Lr(t){return Qo.decode(t)}function Rr(t){return e=>t.encoder.encode(e)}function jo(t){if(parseInt(t).toString()!==t)throw new k("Value must be an integer")}function qo(t){if(t<0)throw new k("Value must be a positive integer, or zero")}function Go(t){return e=>{if(e>t)throw new k(`Value must be smaller than or equal to ${t}`)}}function Xo(...t){return e=>{for(let r of t)r(e)}}var Se=Xo(jo,qo,Go(65535));var y=-1,Nt=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let r;if(typeof e=="string"?r=this.protocolsByName.get(e):r=this.protocolsByCode.get(e),r==null)throw new Re(`Protocol ${e} was unknown`);return r}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(r=>{this.protocolsByName.set(r,e)})}removeProtocol(e){let r=this.protocolsByCode.get(e);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},T=new Nt,us=[{code:4,name:"ip4",size:32,valueToBytes:Ut,bytesToValue:Ar,validate:t=>{if(!$e(t))throw new k(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Z,bytesToValue:ue,validate:Se},{code:273,name:"udp",size:16,valueToBytes:Z,bytesToValue:ue,validate:Se},{code:33,name:"dccp",size:16,valueToBytes:Z,bytesToValue:ue,validate:Se},{code:41,name:"ip6",size:128,valueToBytes:_r,bytesToValue:Ur,stringToValue:Nr,validate:t=>{if(!Pr(t))throw new k(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:y},{code:43,name:"ipcidr",size:8,bytesToValue:Ot("base10"),valueToBytes:_t("base10")},{code:53,name:"dns",size:y,resolvable:!0},{code:54,name:"dns4",size:y,resolvable:!0},{code:55,name:"dns6",size:y,resolvable:!0},{code:56,name:"dnsaddr",size:y,resolvable:!0},{code:132,name:"sctp",size:16,valueToBytes:Z,bytesToValue:ue,validate:Se},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:y,path:!0,stringToValue:t=>decodeURIComponent(t),valueToString:t=>encodeURIComponent(t)},{code:421,name:"p2p",aliases:["ipfs"],size:y,bytesToValue:Ot("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?_t("base58btc")(t):q.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:At,valueToBytes:Tr},{code:445,name:"onion3",size:296,bytesToValue:At,valueToBytes:Or},{code:446,name:"garlic64",size:y},{code:447,name:"garlic32",size:y},{code:448,name:"tls"},{code:449,name:"sni",size:y},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:y,bytesToValue:Rr(lt),valueToBytes:Lr},{code:480,name:"http"},{code:481,name:"http-path",size:y,stringToValue:t=>`/${decodeURIComponent(t)}`,valueToString:t=>encodeURIComponent(t.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:y}];us.forEach(t=>{T.addProtocol(t)});function Mr(t){let e=[],r=0;for(;r<t.length;){let n=Dt(t,r),o=T.getProtocol(n),s=le(n),i=ds(o,t,r+s),a=0;i>0&&o.size===y&&(a=le(i));let c=s+a+i,u={code:n,name:o.name,bytes:t.subarray(r,r+c)};if(i>0){let h=r+s+a,m=t.subarray(h,h+i);u.value=o.bytesToValue?.(m)??A(m)}e.push(u),r+=c}return e}function Br(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let o=T.getProtocol(n.code),s=le(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??z(n.value),a=i.byteLength,o.size===y&&(c=le(a)));let u=new Uint8Array(s+c+a),h=0;St(n.code,u,h),h+=s,i!=null&&(o.size===y&&(St(a,u,h),h+=c),u.set(i,h)),n.bytes=u}r.push(n.bytes),e+=n.bytes.byteLength}return ve(r,e)}function $r(t){if(t.charAt(0)!=="/")throw new C('String multiaddr must start with "/"');let e=[],r="protocol",n="",o="";for(let s=1;s<t.length;s++){let i=t.charAt(s);i!=="/"&&(r==="protocol"?o+=t.charAt(s):n+=t.charAt(s));let a=s===t.length-1;if(i==="/"||a){let c=T.getProtocol(o);if(r==="protocol"){if(c.size==null||c.size===0){e.push({code:c.code,name:c.name}),n="",o="",r="protocol";continue}else if(a)throw new C(`Component ${o} was missing value`);r="value"}else if(r==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new C(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}e.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new C("Incomplete multiaddr");return e}function zr(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=T.getProtocol(e.code);if(r==null)throw new C(`Unknown protocol code ${e.code}`);return[e.name,r.valueToString?.(e.value)??e.value]}).join("/")}`}function ds(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:Dt(e,r)}var ps=Symbol.for("nodejs.util.inspect.custom"),Vt=Symbol.for("@multiformats/multiaddr"),fs=[53,54,55,56],kt=class extends Error{constructor(e="No available resolver"){super(e),this.name="NoAvailableResolverError"}};function hs(t){if(t==null&&(t="/"),Wr(t))return t.getComponents();if(t instanceof Uint8Array)return Mr(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),$r(t);if(Array.isArray(t))return t;throw new C("Must be a string, Uint8Array, Component[], or another Multiaddr")}var ke=class t{[Vt]=!0;#e;#t;#r;constructor(e="/",r={}){this.#e=hs(e),r.validate!==!1&&ms(this)}get bytes(){return this.#r==null&&(this.#r=Br(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=zr(this.#e)),this.#t}toJSON(){return this.toString()}toOptions(){let e,r,n,o,s="";for(let{code:a,name:c,value:u}of this.#e)a===42&&(s=`%${u??""}`),fs.includes(a)&&(r="tcp",o=443,n=`${u??""}${s}`,e=a===55?6:4),(a===6||a===273)&&(r=c==="tcp"?"tcp":"udp",o=parseInt(u??"")),(a===4||a===41)&&(r="tcp",n=`${u??""}${s}`,e=a===41?6:4);if(e==null||r==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:e,host:n,transport:r,port:o}}getComponents(){return[...this.#e]}protos(){return this.#e.map(({code:e,value:r})=>{let n=T.getProtocol(e);return{code:e,size:n.size??0,name:n.name,resolvable:!!n.resolvable,path:!!n.path}})}protoCodes(){return this.#e.map(({code:e})=>e)}protoNames(){return this.#e.map(({name:e})=>e)}tuples(){return this.#e.map(({code:e,value:r})=>{if(r==null)return[e];let n=T.getProtocol(e),o=[e];return r!=null&&o.push(n.valueToBytes?.(r)??z(r)),o})}stringTuples(){return this.#e.map(({code:e,value:r})=>r==null?[e]:[e,r])}encapsulate(e){let r=new t(e);return new t([...this.#e,...r.getComponents()],{validate:!1})}decapsulate(e){let r=e.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new Ce(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new t(n.slice(0,o),{validate:!1})}decapsulateCode(e){let r;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){r=n;break}return new t(this.#e.slice(0,r),{validate:!1})}getPeerId(){try{let e=[];this.#e.forEach(({code:n,value:o})=>{n===421&&e.push([n,o]),n===290&&(e=[])});let r=e.pop();if(r?.[1]!=null){let n=r[1];return n[0]==="Q"||n[0]==="1"?A(_.decode(`z${n}`),"base58btc"):A(q.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){for(let e of this.#e)if(T.getProtocol(e.code).path)return e.value??null;return null}equals(e){return Dr(this.bytes,e.bytes)}async resolve(e){let r=this.protos().find(s=>s.resolvable);if(r==null)return[this];let n=Fr.get(r.name);if(n==null)throw new kt(`no available resolver for ${r.name}`);return(await n(this,e)).map(s=>Pe(s))}nodeAddress(){let e=this.toOptions();if(e.transport!=="tcp"&&e.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(){return!(this.#e.length!==2||this.#e[0].code!==4&&this.#e[0].code!==41||this.#e[1].code!==6&&this.#e[1].code!==273)}[ps](){return`Multiaddr(${this.toString()})`}};function ms(t){t.getComponents().forEach(e=>{let r=T.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}var rc=parseInt("0xFFFF",16),nc=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var Fr=new Map;function Wr(t){return!!t?.[Vt]}function Pe(t){return new ke(t)}var bs=[6,53,56,54,55];function Hr(t){return qr("sni",t)?.value}function Qr(t){let e=qr("tcp",t)?.value;return e==null?"":`:${e}`}function qr(t,e){return e.find(r=>r.name===t)}function jr(t){return t.some(({code:e})=>e===448)}function R(t,e){let r=Gr[t.name];if(r==null)throw new Error(`Can't interpret protocol ${t.name}`);let n=r(t,e);return t.code===41?`[${n}]`:n}var Gr={ip4:(t,e)=>t.value,ip6:(t,e)=>e.length===0?t.value:`[${t.value}]`,tcp:(t,e)=>{let r=e.pop();if(r==null)throw new Error("Unexpected end of multiaddr");return`tcp://${R(r,e)}:${t.value}`},udp:(t,e)=>{let r=e.pop();if(r==null)throw new Error("Unexpected end of multiaddr");return`udp://${R(r,e)}:${t.value}`},dnsaddr:(t,e)=>t.value,dns4:(t,e)=>t.value,dns6:(t,e)=>t.value,dns:(t,e)=>t.value,ipfs:(t,e)=>{let r=e.pop();if(r==null)throw new Error("Unexpected end of multiaddr");return`${R(r,e)}`},p2p:(t,e)=>{let r=e.pop();if(r==null)throw new Error("Unexpected end of multiaddr");return`${R(r,e)}`},http:(t,e)=>{let r=jr(e),n=Hr(e),o=Qr(e);if(r&&n!=null)return`https://${n}${o}`;let s=r?"https://":"http://",i=e.pop();if(i==null)throw new Error("Unexpected end of multiaddr");let a=R(i,e);return a=a?.replace("tcp://",""),`${s}${a}`},"http-path":(t,e)=>{let r=e.pop();if(r==null)throw new Error("Unexpected end of multiaddr");let n=R(r,e),o=decodeURIComponent(t.value??"");return`${n}${o}`},tls:(t,e)=>{let r=e.pop();if(r==null)throw new Error("Unexpected end of multiaddr");return R(r,e)},sni:(t,e)=>{let r=e.pop();if(r==null)throw new Error("Unexpected end of multiaddr");return R(r,e)},https:(t,e)=>{let r=e.pop();if(r==null)throw new Error("Unexpected end of multiaddr");let n=R(r,e);return n=n?.replace("tcp://",""),`https://${n}`},ws:(t,e)=>{let r=jr(e),n=Hr(e),o=Qr(e);if(r&&n!=null)return`wss://${n}${o}`;let s=r?"wss://":"ws://",i=e.pop();if(i==null)throw new Error("Unexpected end of multiaddr");let a=R(i,e);return a=a?.replace("tcp://",""),`${s}${a}`},wss:(t,e)=>{let r=e.pop();if(r==null)throw new Error("Unexpected end of multiaddr");let n=R(r,e);return n=n?.replace("tcp://",""),`wss://${n}`}};function Xr(t,e){let n=Pe(t).getComponents(),o=n.pop();if(o==null)throw new Error("Unexpected end of multiaddr");let s=Gr[o.name];if(s==null)throw new Error(`No interpreter found for ${o.name}`);let i=s(o,n)??"";return e?.assumeHttp!==!1&&bs.includes(o.code)&&(i=i.replace(/^.*:\/\//,""),o.value==="443"?i=`https://${i}`:i=`http://${i}`),(i.startsWith("http://")||i.startsWith("https://")||i.startsWith("ws://")||i.startsWith("wss://"))&&(i=new URL(i).toString(),i.endsWith("/")&&(i=i.substring(0,i.length-1))),i}var Jr=async t=>{if(t.readyState>=2)throw new Error("socket closed");t.readyState!==1&&await new Promise((e,r)=>{function n(){t.removeEventListener("open",o),t.removeEventListener("error",s)}function o(){n(),e()}function s(i){n(),r(i.error??new Error(`connect ECONNREFUSED ${t.url}`))}t.addEventListener("open",o),t.addEventListener("error",s)})};var Kr=(t,e)=>(e=e??{},e.closeOnEnd=e.closeOnEnd!==!1,async n=>{for await(let o of n){try{await Jr(t)}catch(s){if(s.message==="socket closed")break;throw s}if(t.readyState===t.CLOSING||t.readyState===t.CLOSED)break;t.send(o)}e.closeOnEnd!=null&&t.readyState<=1&&await new Promise((o,s)=>{t.addEventListener("close",i=>{if(i.wasClean||i.code===1006)o();else{let a=Object.assign(new Error("ws error"),{event:i});s(a)}}),setTimeout(()=>{t.close()})})});var tn=Pn(Yr(),1);function en(t){return t instanceof ArrayBuffer||t?.constructor?.name==="ArrayBuffer"&&typeof t?.byteLength=="number"}var rn=t=>{t.binaryType="arraybuffer";let e=async()=>{await new Promise((s,i)=>{if(n){s();return}if(o!=null){i(o);return}let a=h=>{t.removeEventListener("open",c),t.removeEventListener("error",u),h()},c=()=>{a(s)},u=h=>{a(()=>{i(h.error??new Error(`connect ECONNREFUSED ${t.url}`))})};t.addEventListener("open",c),t.addEventListener("error",u)})},r=async function*(){let s=new tn.EventIterator(({push:i,stop:a,fail:c})=>{let u=m=>{let D=null;typeof m.data=="string"&&(D=z(m.data)),en(m.data)&&(D=new Uint8Array(m.data)),m.data instanceof Uint8Array&&(D=m.data),D!=null&&i(D)},h=m=>{c(m.error??new Error("Socket error"))};return t.addEventListener("message",u),t.addEventListener("error",h),t.addEventListener("close",a),()=>{t.removeEventListener("message",u),t.removeEventListener("error",h),t.removeEventListener("close",a)}},{highWaterMark:1/0});await e();for await(let i of s)yield en(i)?new Uint8Array(i):i}(),n=t.readyState===1,o;return t.addEventListener("open",()=>{n=!0,o=null}),t.addEventListener("close",()=>{n=!1,o=null}),t.addEventListener("error",s=>{n||(o=s.error??new Error(`connect ECONNREFUSED ${t.url}`))}),Object.assign(r,{connected:e})};var nn=(t,e)=>{e=e??{};let r=rn(t),n=e.remoteAddress,o=e.remotePort;if(t.url!=null)try{let i=new URL(t.url);n=i.hostname,o=parseInt(i.port,10)}catch{}if(n==null||o==null)throw new Error("Remote connection did not have address and/or port");return{sink:Kr(t,e),source:r,connected:async()=>{await r.connected()},close:async()=>{(t.readyState===t.CONNECTING||t.readyState===t.OPEN)&&await new Promise(i=>{t.addEventListener("close",()=>{i()}),t.close()})},destroy:()=>{t.terminate!=null?t.terminate():t.close()},remoteAddress:n,remotePort:o,socket:t}};var on=WebSocket;var Cs={"http:":"ws:","https:":"wss:"},sn="ws:",an=(t,e)=>{if(t.startsWith("//")&&(t=`${e?.protocol??sn}${t}`),t.startsWith("/")&&e!=null){let n=e.protocol??sn,o=e.host,s=e.port!=null&&o?.endsWith(`:${e.port}`)!==!0?`:${e.port}`:"";t=`${n}//${o}${s}${t}`}let r=new URL(t);for(let[n,o]of Object.entries(Cs))r.protocol===n&&(r.protocol=o);return r};function cn(t,e){let r=typeof window>"u"?void 0:window.location;e=e??{};let n=an(t,r),o=new on(n.toString(),e.websocket);return nn(o,e)}function jt(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var Qe=class extends Event{type;detail;constructor(e,r){super(e),this.type=e,this.detail=r}};var je=class extends Error{type;code;constructor(e,r,n){super(e??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=r??"ABORT_ERR"}};async function ln(t,e,r){if(e==null)return t;if(e.aborted)return t.catch(()=>{}),Promise.reject(new je(r?.errorMessage,r?.errorCode,r?.errorName));let n,o=new je(r?.errorMessage,r?.errorCode,r?.errorName);try{return await Promise.race([t,new Promise((s,i)=>{n=()=>{i(o)},e.addEventListener("abort",n)})])}finally{n!=null&&e.removeEventListener("abort",n)}}var g=t=>({match:e=>{let r=e[0];return r==null||r.code!==t||r.value!=null?!1:e.slice(1)}}),l=(t,e)=>({match:r=>{let n=r[0];return n?.code!==t||n.value==null||e!=null&&n.value!==e?!1:r.slice(1)}}),d=t=>({match:e=>{let r=t.match(e);return r===!1?e:r}}),S=(...t)=>({match:e=>{let r;for(let n of t){let o=n.match(e);o!==!1&&(r==null||o.length<r.length)&&(r=o)}return r??!1}}),f=(...t)=>({match:e=>{for(let r of t){let n=r.match(e);if(n===!1)return!1;e=n}return e}});function w(...t){function e(o){if(o==null)return!1;let s=o.getComponents();for(let i of t){let a=i.match(s);if(a===!1)return!1;s=a}return s}function r(o){return e(o)!==!1}function n(o){let s=e(o);return s===!1?!1:s.length===0}return{matchers:t,matches:r,exactMatch:n}}var vs=l(421),pl=w(vs),Ge=l(54),Xe=l(55),Je=l(56),Gt=l(53),fl=w(Ge,d(l(421))),hl=w(Xe,d(l(421))),ml=w(Je,d(l(421))),Ss=w(S(Gt,Je,Ge,Xe),d(l(421))),un=f(l(4),d(l(43))),dn=f(d(l(42)),l(41),d(l(43))),Xt=S(un,dn),ne=S(Xt,Gt,Ge,Xe,Je),xl=w(S(Xt,f(S(Gt,Je,Ge,Xe),d(l(421))))),wl=w(un),gl=w(dn),El=w(Xt),Jt=f(ne,l(6)),Oe=f(ne,l(273)),bl=w(f(Jt,d(l(421)))),yl=w(Oe),Kt=f(Oe,g(460),d(l(421))),Ke=f(Oe,g(461),d(l(421))),Ds=S(Kt,Ke),Cl=w(Kt),vl=w(Ke),qt=S(ne,Jt,Oe,Kt,Ke),pn=S(f(qt,g(477),d(l(421)))),fn=w(pn),hn=S(f(qt,g(478),d(l(421))),f(qt,g(448),d(l(449)),g(477),d(l(421)))),mn=w(hn),xn=f(Oe,g(280),d(l(466)),d(l(466)),d(l(421))),Sl=w(xn),wn=f(Ke,g(465),d(l(466)),d(l(466)),d(l(421))),Dl=w(wn),qe=S(pn,hn,f(Jt,d(l(421))),f(Ds,d(l(421))),f(ne,d(l(421))),xn,wn,l(421)),Il=w(qe),Is=f(qe,g(290),l(421)),Pl=w(Is),Ps=S(f(qe,g(290),g(281),d(l(421))),f(qe,g(281),d(l(421))),f(g(281),d(l(421)))),Tl=w(Ps),Ts=S(f(ne,l(6),g(480),d(l(421))),f(ne,g(480),d(l(421)))),Ol=w(Ts),Os=f(ne,S(f(l(6,"443"),g(480)),f(l(6),g(443)),f(l(6),g(448),g(480)),f(g(448),g(480)),g(448),g(443)),d(l(421))),_l=w(Os),_s=S(f(l(777),d(l(421)))),Al=w(_s),As=S(f(l(400),d(l(421)))),Ul=w(As);function gn(t){return t.filter(e=>mn.exactMatch(e)||fn.exactMatch(e))}function En(){throw new Error("WebSocket Servers can not be created in the browser!")}function bn(t,e,r){let n=r.metrics,o=r.metricPrefix??"",s={log:r.logger.forComponent("libp2p:websockets:connection"),async sink(c){try{await t.sink(async function*(){for await(let u of c)u instanceof Uint8Array?yield u:yield u.subarray()}())}catch(u){u.type!=="aborted"&&s.log.error(u)}},source:t.source,remoteAddr:e,timeline:{open:Date.now()},async close(c={}){let u=Date.now();if(c.signal==null){let m=AbortSignal.timeout(500);c={...c,signal:m}}let h=()=>{let{host:m,port:D}=s.remoteAddr.toOptions();s.log("timeout closing stream to %s:%s after %dms, destroying it manually",m,D,Date.now()-u),this.abort(new Ue("Socket close timeout"))};c.signal?.addEventListener("abort",h);try{await t.close()}catch(m){s.log.error("error closing WebSocket gracefully - %e",m),this.abort(m)}finally{c.signal?.removeEventListener("abort",h),s.timeline.close=Date.now()}},abort(c){s.log.error("destroying WebSocket after error - %e",c),t.destroy(),s.timeline.close=Date.now(),n?.increment({[`${o}error`]:!0})}},i=!1,a=t.socket.close.bind(t.socket);return t.socket.close=(...c)=>(i=!0,a(...c)),t.socket.addEventListener("close",c=>{if(s.log('closed %s, code %d, reason "%s", wasClean %s',i?"locally":"by remote",c.code,c.reason,c.wasClean),!c.wasClean){s.abort(new oe(`${i?"Local":"Remote"} did not close WebSocket cleanly`));return}n?.increment({[`${o}close`]:!0}),s.timeline.close=Date.now()},{once:!0}),s}var Zt=class{log;init;logger;metrics;components;constructor(e,r={}){this.log=e.logger.forComponent("libp2p:websockets"),this.logger=e.logger,this.components=e,this.init=r,e.metrics!=null&&(this.metrics={dialerEvents:e.metrics.registerCounterGroup("libp2p_websockets_dialer_events_total",{label:"event",help:"Total count of WebSockets dialer events by type"})})}[rr]=!0;[Symbol.toStringTag]="@libp2p/websockets";[nr]=["@libp2p/transport"];async dial(e,r){this.log("dialing %s",e),r=r??{};let n=await this._connect(e,r),o=bn(n,e,{logger:this.logger,metrics:this.metrics?.dialerEvents});this.log("new outbound connection %s",o.remoteAddr);let s=await r.upgrader.upgradeOutbound(o,r);return this.log("outbound connection %s upgraded",o.remoteAddr),s}async _connect(e,r){r?.signal?.throwIfAborted();let n=e.toOptions();this.log("dialing %s:%s",n.host,n.port);let o=jt(),s=cn(Xr(e),this.init);s.socket.addEventListener("error",()=>{let i=new oe(`Could not connect to ${e.toString()}`);this.log.error("connection error:",i),this.metrics?.dialerEvents.increment({error:!0}),o.reject(i)});try{r.onProgress?.(new Qe("websockets:open-connection")),await ln(Promise.race([s.connected(),o.promise]),r.signal)}catch(i){throw r.signal?.aborted&&this.metrics?.dialerEvents.increment({abort:!0}),s.close().catch(a=>{this.log.error("error closing raw socket",a)}),i}return this.log("connected %s",e),this.metrics?.dialerEvents.increment({connect:!0}),s}createListener(e){return En({logger:this.logger,events:this.components.events,metrics:this.components.metrics},{...this.init,...e})}listenFilter(e){return e=Array.isArray(e)?e:[e],this.init?.filter!=null?this.init?.filter(e):gn(e)}dialFilter(e){return this.listenFilter(e)}};function Ns(t={}){return e=>new Zt(e,t)}return Tn(Ls);})();
2
+ "use strict";var Libp2PWebsockets=(()=>{var ft=Object.defineProperty;var Pn=Object.getOwnPropertyDescriptor;var _n=Object.getOwnPropertyNames;var On=Object.prototype.hasOwnProperty;var B=(r,e)=>{for(var t in e)ft(r,t,{get:e[t],enumerable:!0})},Bn=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of _n(e))!On.call(r,o)&&o!==t&&ft(r,o,{get:()=>e[o],enumerable:!(n=Pn(e,o))||n.enumerable});return r};var Un=r=>Bn(ft({},"__esModule",{value:!0}),r);var Hs={};B(Hs,{webSockets:()=>qs});var ke=class extends Error{static name="ConnectionFailedError";constructor(e="Connection failed"){super(e),this.name="ConnectionFailedError"}};var Me=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var te=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},ve=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var Fe=class extends Event{data;constructor(e,t){super("message",t),this.data=e}},ce=class extends Event{error;local;constructor(e,t,n){super("close",n),this.error=t,this.local=e}},Ve=class extends ce{constructor(e,t){super(!0,e,t)}},$e=class extends ce{constructor(e,t){super(!1,e,t)}};var br=Symbol.for("@libp2p/transport");var mr;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(mr||(mr={}));var ze=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:s})=>s!==t),this.#e.set(e,o))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};var gr=Symbol.for("@libp2p/service-capabilities"),Ks=Symbol.for("@libp2p/service-dependencies");var bt={};B(bt,{base10:()=>$n});var Si=new Uint8Array(0);function wr(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function W(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function xr(r){return new TextEncoder().encode(r)}function yr(r){return new TextDecoder().decode(r)}function Nn(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(t[i]!==255)throw new TypeError(s+" is ambiguous");t[i]=o}var a=r.length,c=r.charAt(0),l=Math.log(a)/Math.log(256),h=Math.log(256)/Math.log(a);function f(b){if(b instanceof Uint8Array||(ArrayBuffer.isView(b)?b=new Uint8Array(b.buffer,b.byteOffset,b.byteLength):Array.isArray(b)&&(b=Uint8Array.from(b))),!(b instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(b.length===0)return"";for(var S=0,d=0,D=0,_=b.length;D!==_&&b[D]===0;)D++,S++;for(var T=(_-D)*h+1>>>0,O=new Uint8Array(T);D!==_;){for(var N=b[D],Q=0,F=T-1;(N!==0||Q<d)&&F!==-1;F--,Q++)N+=256*O[F]>>>0,O[F]=N%a>>>0,N=N/a>>>0;if(N!==0)throw new Error("Non-zero carry");d=Q,D++}for(var z=T-d;z!==T&&O[z]===0;)z++;for(var Re=c.repeat(S);z<T;++z)Re+=r.charAt(O[z]);return Re}function y(b){if(typeof b!="string")throw new TypeError("Expected String");if(b.length===0)return new Uint8Array;var S=0;if(b[S]!==" "){for(var d=0,D=0;b[S]===c;)d++,S++;for(var _=(b.length-S)*l+1>>>0,T=new Uint8Array(_);b[S];){var O=t[b.charCodeAt(S)];if(O===255)return;for(var N=0,Q=_-1;(O!==0||N<D)&&Q!==-1;Q--,N++)O+=a*T[Q]>>>0,T[Q]=O%256>>>0,O=O/256>>>0;if(O!==0)throw new Error("Non-zero carry");D=N,S++}if(b[S]!==" "){for(var F=_-D;F!==_&&T[F]===0;)F++;for(var z=new Uint8Array(d+(_-F)),Re=d;F!==_;)z[Re++]=T[F++];return z}}}function w(b){var S=y(b);if(S)return S;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:y,decode:w}}var Rn=Nn,kn=Rn,vr=kn;var ht=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},dt=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let o=t.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Cr(this,e)}},pt=class{decoders;constructor(e){this.decoders=e}or(e){return Cr(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Cr(r,e){return new pt({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var mt=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new ht(e,t,n),this.decoder=new dt(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function ue({name:r,prefix:e,encode:t,decode:n}){return new mt(r,e,t,n)}function G({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=vr(t,r);return ue({prefix:e,name:r,encode:n,decode:s=>W(o(s))})}function Mn(r,e,t,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*t/8|0),i=0,a=0,c=0;for(let l=0;l<o;++l){let h=e[r[l]];if(h===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|h,i+=t,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=t||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Fn(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>t;)i-=t,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<t-i]),n)for(;(s.length*t&7)!==0;)s+="=";return s}function Vn(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function C({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let o=Vn(n);return ue({prefix:e,name:r,encode(s){return Fn(s,n,t)},decode(s){return Mn(s,o,t,r)}})}var $n=G({prefix:"9",name:"base10",alphabet:"0123456789"});var gt={};B(gt,{base16:()=>zn,base16upper:()=>Wn});var zn=C({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Wn=C({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var wt={};B(wt,{base2:()=>qn});var qn=C({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var xt={};B(xt,{base256emoji:()=>Xn});var Sr=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Hn=Sr.reduce((r,e,t)=>(r[t]=e,r),[]),jn=Sr.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function Qn(r){return r.reduce((e,t)=>(e+=Hn[t],e),"")}function Gn(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=jn[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var Xn=ue({prefix:"\u{1F680}",name:"base256emoji",encode:Qn,decode:Gn});var yt={};B(yt,{base32:()=>X,base32hex:()=>Zn,base32hexpad:()=>to,base32hexpadupper:()=>ro,base32hexupper:()=>eo,base32pad:()=>Kn,base32padupper:()=>Yn,base32upper:()=>Jn,base32z:()=>no});var X=C({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Jn=C({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Kn=C({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Yn=C({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Zn=C({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),eo=C({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),to=C({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ro=C({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),no=C({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Et={};B(Et,{base36:()=>Ce,base36upper:()=>oo});var Ce=G({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),oo=G({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var vt={};B(vt,{base58btc:()=>R,base58flickr:()=>so});var R=G({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),so=G({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var St={};B(St,{base64:()=>io,base64pad:()=>ao,base64url:()=>Ct,base64urlpad:()=>co});var io=C({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ao=C({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ct=C({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),co=C({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Dt={};B(Dt,{base8:()=>uo});var uo=C({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var It={};B(It,{identity:()=>lo});var lo=ue({prefix:"\0",name:"identity",encode:r=>yr(r),decode:r=>xr(r)});var Vi=new TextEncoder,$i=new TextDecoder;var Lt={};B(Lt,{identity:()=>Uo});var po=Tr,Dr=128,mo=127,bo=~mo,go=Math.pow(2,31);function Tr(r,e,t){e=e||[],t=t||0;for(var n=t;r>=go;)e[t++]=r&255|Dr,r/=128;for(;r&bo;)e[t++]=r&255|Dr,r>>>=7;return e[t]=r|0,Tr.bytes=t-n+1,e}var wo=Tt,xo=128,Ir=127;function Tt(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Tt.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&Ir)<<o:(i&Ir)*Math.pow(2,o),o+=7}while(i>=xo);return Tt.bytes=s-n,t}var yo=Math.pow(2,7),Eo=Math.pow(2,14),vo=Math.pow(2,21),Co=Math.pow(2,28),So=Math.pow(2,35),Do=Math.pow(2,42),Io=Math.pow(2,49),To=Math.pow(2,56),Lo=Math.pow(2,63),Ao=function(r){return r<yo?1:r<Eo?2:r<vo?3:r<Co?4:r<So?5:r<Do?6:r<Io?7:r<To?8:r<Lo?9:10},Po={encode:po,decode:wo,encodingLength:Ao},_o=Po,Se=_o;function De(r,e=0){return[Se.decode(r,e),Se.decode.bytes]}function le(r,e,t=0){return Se.encode(r,e,t),e}function fe(r){return Se.encodingLength(r)}function de(r,e){let t=e.byteLength,n=fe(r),o=n+fe(t),s=new Uint8Array(o+t);return le(r,s,0),le(t,s,n),s.set(e,o),new he(r,t,e,s)}function Lr(r){let e=W(r),[t,n]=De(e),[o,s]=De(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new he(t,o,i,e)}function Ar(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&wr(r.bytes,t.bytes)}}var he=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};var Pr=0,Oo="identity",_r=W;function Bo(r,e){if(e?.truncate!=null&&e.truncate!==r.byteLength){if(e.truncate<0||e.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e.truncate)}return de(Pr,_r(r))}var Uo={code:Pr,name:Oo,encode:_r,digest:Bo};var _t={};B(_t,{sha256:()=>Ro,sha512:()=>ko});var No=20;function Pt({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:o}){return new At(r,e,t,n,o)}var At=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,o,s){this.name=e,this.code=t,this.encode=n,this.minDigestLength=o??No,this.maxDigestLength=s}digest(e,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?Or(n,this.code,t?.truncate):n.then(o=>Or(o,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function Or(r,e,t){if(t!=null&&t!==r.byteLength){if(t>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t)}return de(e,r)}function Ur(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var Ro=Pt({name:"sha2-256",code:18,encode:Ur("SHA-256")}),ko=Pt({name:"sha2-512",code:19,encode:Ur("SHA-512")});function Nr(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return Fo(t,Ot(r),e??R.encoder);default:return Vo(t,Ot(r),e??X.encoder)}}var Rr=new WeakMap;function Ot(r){let e=Rr.get(r);if(e==null){let t=new Map;return Rr.set(r,t),t}return e}var J=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==Te)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==$o)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=de(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&Ar(e.multihash,n.multihash)}toString(e){return Nr(this,e)}toJSON(){return{"/":Nr(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:s,bytes:i}=t;return new r(n,o,s,i??kr(n,o,s.bytes))}else if(t[zo]===!0){let{version:n,multihash:o,code:s}=t,i=Lr(o);return r.create(n,s,i)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==Te)throw new Error(`Version 0 CID must use dag-pb (code: ${Te}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=kr(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Te,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=W(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let s=o.subarray(t.multihashSize-t.digestSize),i=new he(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[f,y]=De(e.subarray(t));return t+=y,f},o=n(),s=Te;if(o===18?(o=0,t=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=t,a=n(),c=n(),l=t+c,h=l-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:h,size:l}}static parse(e,t){let[n,o]=Mo(e,t),s=r.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Ot(s).set(n,e),s}};function Mo(r,e){switch(r[0]){case"Q":{let t=e??R;return[R.prefix,t.decode(`${R.prefix}${r}`)]}case R.prefix:{let t=e??R;return[R.prefix,t.decode(r)]}case X.prefix:{let t=e??X;return[X.prefix,t.decode(r)]}case Ce.prefix:{let t=e??Ce;return[Ce.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function Fo(r,e,t){let{prefix:n}=t;if(n!==R.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let s=t.encode(r).slice(1);return e.set(n,s),s}else return o}function Vo(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let s=t.encode(r);return e.set(n,s),s}else return o}var Te=112,$o=18;function kr(r,e,t){let n=fe(r),o=n+fe(e),s=new Uint8Array(o+t.byteLength);return le(r,s,0),le(e,s,n),s.set(t,o),s}var zo=Symbol.for("@ipld/js-cid/CID");var Le={...It,...wt,...Dt,...bt,...gt,...yt,...Et,...vt,...St,...xt},ua={..._t,...Lt};function q(r=0){return new Uint8Array(r)}function K(r=0){return new Uint8Array(r)}function Fr(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Mr=Fr("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Bt=Fr("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=K(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Wo={utf8:Mr,"utf-8":Mr,hex:Le.base16,latin1:Bt,ascii:Bt,binary:Bt,...Le},qe=Wo;function k(r,e="utf8"){let t=qe[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var L=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},H=class extends Error{static name="ValidationError";name="ValidationError"},Ae=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},He=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function je(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function $(r,e="utf8"){let t=qe[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}var qo=Math.pow(2,7),Ho=Math.pow(2,14),jo=Math.pow(2,21),Ut=Math.pow(2,28),Nt=Math.pow(2,35),Rt=Math.pow(2,42),kt=Math.pow(2,49),v=128,A=127;function pe(r){if(r<qo)return 1;if(r<Ho)return 2;if(r<jo)return 3;if(r<Ut)return 4;if(r<Nt)return 5;if(r<Rt)return 6;if(r<kt)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Mt(r,e,t=0){switch(pe(r)){case 8:e[t++]=r&255|v,r/=128;case 7:e[t++]=r&255|v,r/=128;case 6:e[t++]=r&255|v,r/=128;case 5:e[t++]=r&255|v,r/=128;case 4:e[t++]=r&255|v,r>>>=7;case 3:e[t++]=r&255|v,r>>>=7;case 2:e[t++]=r&255|v,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function Qo(r,e){let t=r[e],n=0;if(n+=t&A,t<v||(t=r[e+1],n+=(t&A)<<7,t<v)||(t=r[e+2],n+=(t&A)<<14,t<v)||(t=r[e+3],n+=(t&A)<<21,t<v)||(t=r[e+4],n+=(t&A)*Ut,t<v)||(t=r[e+5],n+=(t&A)*Nt,t<v)||(t=r[e+6],n+=(t&A)*Rt,t<v)||(t=r[e+7],n+=(t&A)*kt,t<v))return n;throw new RangeError("Could not decode varint")}function Go(r,e){let t=r.get(e),n=0;if(n+=t&A,t<v||(t=r.get(e+1),n+=(t&A)<<7,t<v)||(t=r.get(e+2),n+=(t&A)<<14,t<v)||(t=r.get(e+3),n+=(t&A)<<21,t<v)||(t=r.get(e+4),n+=(t&A)*Ut,t<v)||(t=r.get(e+5),n+=(t&A)*Nt,t<v)||(t=r.get(e+6),n+=(t&A)*Rt,t<v)||(t=r.get(e+7),n+=(t&A)*kt,t<v))return n;throw new RangeError("Could not decode varint")}function Ft(r,e=0){return r instanceof Uint8Array?Qo(r,e):Go(r,e)}function Y(r,e){e==null&&(e=r.reduce((o,s)=>o+s.length,0));let t=K(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var Qe=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",l=2**(8*o)-1;for(;;){let h=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let y=Number.parseInt(f,e);if(!Number.isNaN(y))return y});if(h===void 0)break;if(s*=e,s+=h,s>l||(i+=1,t!==void 0&&i>t))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let o=n*2;if(n<t.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return t[o]=i[0],t[o+1]=i[1],t[o+2]=i[2],t[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];t[o]=s>>8,t[o+1]=s&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,o]=e(t);if(n===16)return t;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=e(s.subarray(0,i));return t.set(s.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Jo=45,Ko=15,Ge=new Qe;function Vt(r){if(!(r.length>Ko))return Ge.new(r).parseWith(()=>Ge.readIPv4Addr())}function $t(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Jo))return Ge.new(r).parseWith(()=>Ge.readIPv6Addr())}function Xe(r){return!!Vt(r)}function $r(r){return!!$t(r)}function Wt(r){return e=>k(e,r)}function qt(r){return e=>$(e,r)}function me(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function re(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(e)}function zr(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let t=$(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=re(n);return Y([t,o],t.length+o.length)}function Wr(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let t=X.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=re(n);return Y([t,o],t.length+o.length)}function Ht(r){let e=r.subarray(0,r.length-2),t=r.subarray(r.length-2),n=k(e,"base32"),o=me(t);return`${n}:${o}`}var jt=function(r){r=r.toString().trim();let e=new Uint8Array(4);return r.split(/\./g).forEach((t,n)=>{let o=parseInt(t,10);if(isNaN(o)||o<0||o>255)throw new L("Invalid byte value in IP address");e[n]=o}),e},qr=function(r){let e=0;r=r.toString().trim();let t=r.split(":",8),n;for(n=0;n<t.length;n++){let s=Xe(t[n]),i;s&&(i=jt(t[n]),t[n]=k(i.subarray(0,2),"base16")),i!=null&&++n<8&&t.splice(n,0,k(i.subarray(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let s=[n,1];for(n=9-t.length;n>0;n--)s.push("0");t.splice.apply(t,s)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){t[n]===""&&(t[n]="0");let s=parseInt(t[n],16);if(isNaN(s)||s<0||s>65535)throw new L("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},Hr=function(r){if(r.byteLength!==4)throw new L("IPv4 address was incorrect length");let e=[];for(let t=0;t<r.byteLength;t++)e.push(r[t]);return e.join(".")},jr=function(r){if(r.byteLength!==16)throw new L("IPv6 address was incorrect length");let e=[];for(let n=0;n<r.byteLength;n+=2){let o=r[n],s=r[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;e.push(i)}let t=e.join(":");try{let n=new URL(`http://[${t}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new L(`Invalid IPv6 address "${t}"`)}};function Qr(r){try{let e=new URL(`http://[${r}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new L(`Invalid IPv6 address "${r}"`)}}var zt=Object.values(Le).map(r=>r.decoder),Yo=(function(){let r=zt[0].or(zt[1]);return zt.slice(2).forEach(e=>r=r.or(e)),r})();function Gr(r){return Yo.decode(r)}function Xr(r){return e=>r.encoder.encode(e)}function Zo(r){if(parseInt(r).toString()!==r)throw new H("Value must be an integer")}function es(r){if(r<0)throw new H("Value must be a positive integer, or zero")}function ts(r){return e=>{if(e>r)throw new H(`Value must be smaller than or equal to ${r}`)}}function rs(...r){return e=>{for(let t of r)t(e)}}var Pe=rs(Zo,es,ts(65535));var I=-1,Qt=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let t;if(typeof e=="string"?t=this.protocolsByName.get(e):t=this.protocolsByCode.get(e),t==null)throw new He(`Protocol ${e} was unknown`);return t}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(t=>{this.protocolsByName.set(t,e)})}removeProtocol(e){let t=this.protocolsByCode.get(e);t!=null&&(this.protocolsByCode.delete(t.code),this.protocolsByName.delete(t.name),t.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},U=new Qt,gs=[{code:4,name:"ip4",size:32,valueToBytes:jt,bytesToValue:Hr,validate:r=>{if(!Xe(r))throw new H(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:re,bytesToValue:me,validate:Pe},{code:273,name:"udp",size:16,valueToBytes:re,bytesToValue:me,validate:Pe},{code:33,name:"dccp",size:16,valueToBytes:re,bytesToValue:me,validate:Pe},{code:41,name:"ip6",size:128,valueToBytes:qr,bytesToValue:jr,stringToValue:Qr,validate:r=>{if(!$r(r))throw new H(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:I},{code:43,name:"ipcidr",size:8,bytesToValue:Wt("base10"),valueToBytes:qt("base10")},{code:53,name:"dns",size:I,resolvable:!0},{code:54,name:"dns4",size:I,resolvable:!0},{code:55,name:"dns6",size:I,resolvable:!0},{code:56,name:"dnsaddr",size:I,resolvable:!0},{code:132,name:"sctp",size:16,valueToBytes:re,bytesToValue:me,validate:Pe},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:I,path:!0,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:I,bytesToValue:Wt("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?qt("base58btc")(r):J.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Ht,valueToBytes:zr},{code:445,name:"onion3",size:296,bytesToValue:Ht,valueToBytes:Wr},{code:446,name:"garlic64",size:I},{code:447,name:"garlic32",size:I},{code:448,name:"tls"},{code:449,name:"sni",size:I},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:I,bytesToValue:Xr(Ct),valueToBytes:Gr},{code:480,name:"http"},{code:481,name:"http-path",size:I,stringToValue:r=>`/${decodeURIComponent(r)}`,valueToString:r=>encodeURIComponent(r.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:I}];gs.forEach(r=>{U.addProtocol(r)});function Jr(r){let e=[],t=0;for(;t<r.length;){let n=Ft(r,t),o=U.getProtocol(n),s=pe(n),i=ws(o,r,t+s),a=0;i>0&&o.size===I&&(a=pe(i));let c=s+a+i,l={code:n,name:o.name,bytes:r.subarray(t,t+c)};if(i>0){let h=t+s+a,f=r.subarray(h,h+i);l.value=o.bytesToValue?.(f)??k(f)}e.push(l),t+=c}return e}function Kr(r){let e=0,t=[];for(let n of r){if(n.bytes==null){let o=U.getProtocol(n.code),s=pe(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??$(n.value),a=i.byteLength,o.size===I&&(c=pe(a)));let l=new Uint8Array(s+c+a),h=0;Mt(n.code,l,h),h+=s,i!=null&&(o.size===I&&(Mt(a,l,h),h+=c),l.set(i,h)),n.bytes=l}t.push(n.bytes),e+=n.bytes.byteLength}return Y(t,e)}function Yr(r){if(r.charAt(0)!=="/")throw new L('String multiaddr must start with "/"');let e=[],t="protocol",n="",o="";for(let s=1;s<r.length;s++){let i=r.charAt(s);i!=="/"&&(t==="protocol"?o+=r.charAt(s):n+=r.charAt(s));let a=s===r.length-1;if(i==="/"||a){let c=U.getProtocol(o);if(t==="protocol"){if(c.size==null||c.size===0){e.push({code:c.code,name:c.name}),n="",o="",t="protocol";continue}else if(a)throw new L(`Component ${o} was missing value`);t="value"}else if(t==="value"){let l={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new L(`Component ${o} was missing value`);l.value=c.stringToValue?.(n)??n}e.push(l),n="",o="",t="protocol"}}}if(o!==""&&n!=="")throw new L("Incomplete multiaddr");return e}function Zr(r){return`/${r.flatMap(e=>{if(e.value==null)return e.name;let t=U.getProtocol(e.code);if(t==null)throw new L(`Unknown protocol code ${e.code}`);return[e.name,t.valueToString?.(e.value)??e.value]}).join("/")}`}function ws(r,e,t){return r.size==null||r.size===0?0:r.size>0?r.size/8:Ft(e,t)}var xs=Symbol.for("nodejs.util.inspect.custom"),nr=Symbol.for("@multiformats/multiaddr"),ys=[53,54,55,56],rr=class extends Error{constructor(e="No available resolver"){super(e),this.name="NoAvailableResolverError"}};function Es(r){if(r==null&&(r="/"),tn(r))return r.getComponents();if(r instanceof Uint8Array)return Jr(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),Yr(r);if(Array.isArray(r))return r;throw new L("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Ze=class r{[nr]=!0;#e;#t;#r;constructor(e="/",t={}){this.#e=Es(e),t.validate!==!1&&vs(this)}get bytes(){return this.#r==null&&(this.#r=Kr(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=Zr(this.#e)),this.#t}toJSON(){return this.toString()}toOptions(){let e,t,n,o,s="";for(let{code:a,name:c,value:l}of this.#e)a===42&&(s=`%${l??""}`),ys.includes(a)&&(t="tcp",o=443,n=`${l??""}${s}`,e=a===55?6:4),(a===6||a===273)&&(t=c==="tcp"?"tcp":"udp",o=parseInt(l??"")),(a===4||a===41)&&(t="tcp",n=`${l??""}${s}`,e=a===41?6:4);if(e==null||t==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:e,host:n,transport:t,port:o}}getComponents(){return[...this.#e]}protos(){return this.#e.map(({code:e,value:t})=>{let n=U.getProtocol(e);return{code:e,size:n.size??0,name:n.name,resolvable:!!n.resolvable,path:!!n.path}})}protoCodes(){return this.#e.map(({code:e})=>e)}protoNames(){return this.#e.map(({name:e})=>e)}tuples(){return this.#e.map(({code:e,value:t})=>{if(t==null)return[e];let n=U.getProtocol(e),o=[e];return t!=null&&o.push(n.valueToBytes?.(t)??$(t)),o})}stringTuples(){return this.#e.map(({code:e,value:t})=>t==null?[e]:[e,t])}encapsulate(e){let t=new r(e);return new r([...this.#e,...t.getComponents()],{validate:!1})}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new Ae(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,o),{validate:!1})}decapsulateCode(e){let t;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){t=n;break}return new r(this.#e.slice(0,t),{validate:!1})}getPeerId(){try{let e=[];this.#e.forEach(({code:n,value:o})=>{n===421&&e.push([n,o]),n===290&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?k(R.decode(`z${n}`),"base58btc"):k(J.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){for(let e of this.#e)if(U.getProtocol(e.code).path)return e.value??null;return null}equals(e){return je(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(s=>s.resolvable);if(t==null)return[this];let n=en.get(t.name);if(n==null)throw new rr(`no available resolver for ${t.name}`);return(await n(this,e)).map(s=>Be(s))}nodeAddress(){let e=this.toOptions();if(e.transport!=="tcp"&&e.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(){return!(this.#e.length!==2||this.#e[0].code!==4&&this.#e[0].code!==41||this.#e[1].code!==6&&this.#e[1].code!==273)}[xs](){return`Multiaddr(${this.toString()})`}};function vs(r){r.getComponents().forEach(e=>{let t=U.getProtocol(e.code);e.value!=null&&t.validate?.(e.value)})}var yc=parseInt("0xFFFF",16),Ec=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var en=new Map;function tn(r){return!!r?.[nr]}function Be(r){return new Ze(r)}var Ts=[6,53,56,54,55];function on(r){return cn("sni",r)?.value}function sn(r){let e=cn("tcp",r)?.value;return e==null?"":`:${e}`}function cn(r,e){return e.find(t=>t.name===r)}function an(r){return r.some(({code:e})=>e===448)}function V(r,e){let t=un[r.name];if(t==null)throw new Error(`Can't interpret protocol ${r.name}`);let n=t(r,e);return r.code===41?`[${n}]`:n}var un={ip4:(r,e)=>r.value,ip6:(r,e)=>e.length===0?r.value:`[${r.value}]`,tcp:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");return`tcp://${V(t,e)}:${r.value}`},udp:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");return`udp://${V(t,e)}:${r.value}`},dnsaddr:(r,e)=>r.value,dns4:(r,e)=>r.value,dns6:(r,e)=>r.value,dns:(r,e)=>r.value,ipfs:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");return`${V(t,e)}`},p2p:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");return`${V(t,e)}`},http:(r,e)=>{let t=an(e),n=on(e),o=sn(e);if(t&&n!=null)return`https://${n}${o}`;let s=t?"https://":"http://",i=e.pop();if(i==null)throw new Error("Unexpected end of multiaddr");let a=V(i,e);return a=a?.replace("tcp://",""),`${s}${a}`},"http-path":(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");let n=V(t,e),o=decodeURIComponent(r.value??"");return`${n}${o}`},tls:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");return V(t,e)},sni:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");return V(t,e)},https:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");let n=V(t,e);return n=n?.replace("tcp://",""),`https://${n}`},ws:(r,e)=>{let t=an(e),n=on(e),o=sn(e);if(t&&n!=null)return`wss://${n}${o}`;let s=t?"wss://":"ws://",i=e.pop();if(i==null)throw new Error("Unexpected end of multiaddr");let a=V(i,e);return a=a?.replace("tcp://",""),`${s}${a}`},wss:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");let n=V(t,e);return n=n?.replace("tcp://",""),`wss://${n}`}};function ln(r,e){let n=Be(r).getComponents(),o=n.pop();if(o==null)throw new Error("Unexpected end of multiaddr");let s=un[o.name];if(s==null)throw new Error(`No interpreter found for ${o.name}`);let i=s(o,n)??"";return e?.assumeHttp!==!1&&Ts.includes(o.code)&&(i=i.replace(/^.*:\/\//,""),o.value==="443"?i=`https://${i}`:i=`http://${i}`),(i.startsWith("http://")||i.startsWith("https://")||i.startsWith("ws://")||i.startsWith("wss://"))&&(i=new URL(i).toString(),i.endsWith("/")&&(i=i.substring(0,i.length-1))),i}var or=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},sr=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},fn=r=>globalThis.DOMException===void 0?new sr(r):new DOMException(r),hn=r=>{let e=r.reason===void 0?fn("This operation was aborted."):r.reason;return e instanceof Error?e:fn(e)};function ir(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=e,i,a,l=new Promise((h,f)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:w}=e;w.aborted&&f(hn(w)),a=()=>{f(hn(w))},w.addEventListener("abort",a,{once:!0})}if(t===Number.POSITIVE_INFINITY){r.then(h,f);return}let y=new or;i=s.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(w){f(w)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?h():o instanceof Error?f(o):(y.message=o??`Promise timed out after ${t} milliseconds`,f(y))},t),(async()=>{try{h(await r)}catch(w){f(w)}})()}).finally(()=>{l.clear(),a&&e.signal&&e.signal.removeEventListener("abort",a)});return l.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},l}var Ls=r=>{let e=r.addEventListener||r.on||r.addListener,t=r.removeEventListener||r.off||r.removeListener;if(!e||!t)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(r),removeListener:t.bind(r)}};function As(r,e,t){let n,o=new Promise((s,i)=>{if(t={rejectionEvents:["error"],multiArgs:!1,resolveImmediately:!1,...t},!(t.count>=0&&(t.count===Number.POSITIVE_INFINITY||Number.isInteger(t.count))))throw new TypeError("The `count` option should be at least 0 or more");t.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:l,removeListener:h}=Ls(r),f=(...w)=>{let b=t.multiArgs?w:w[0];t.filter&&!t.filter(b)||(c.push(b),t.count===c.length&&(n(),s(c)))},y=w=>{n(),i(w)};n=()=>{for(let w of a)h(w,f);for(let w of t.rejectionEvents)h(w,y)};for(let w of a)l(w,f);for(let w of t.rejectionEvents)l(w,y);t.signal&&t.signal.addEventListener("abort",()=>{y(t.signal.reason)},{once:!0}),t.resolveImmediately&&s(c)});if(o.cancel=n,typeof t.timeout=="number"){let s=ir(o,{milliseconds:t.timeout});return s.cancel=n,s}return o}function Ue(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=As(r,e,t),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}var et=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var E=r=>({match:e=>{let t=e[0];return t==null||t.code!==r||t.value!=null?!1:e.slice(1)}}),u=(r,e)=>({match:t=>{let n=t[0];return n?.code!==r||n.value==null||e!=null&&n.value!==e?!1:t.slice(1)}}),p=r=>({match:e=>{let t=r.match(e);return t===!1?e:t}}),P=(...r)=>({match:e=>{let t;for(let n of r){let o=n.match(e);o!==!1&&(t==null||o.length<t.length)&&(t=o)}return t??!1}}),g=(...r)=>({match:e=>{for(let t of r){let n=t.match(e);if(n===!1)return!1;e=n}return e}});function x(...r){function e(o){if(o==null)return!1;let s=o.getComponents();for(let i of r){let a=i.match(s);if(a===!1)return!1;s=a}return s}function t(o){return e(o)!==!1}function n(o){let s=e(o);return s===!1?!1:s.length===0}return{matchers:r,matches:t,exactMatch:n}}var Ps=u(421),mu=x(Ps),rt=u(54),nt=u(55),ot=u(56),cr=u(53),bu=x(rt,p(u(421))),gu=x(nt,p(u(421))),wu=x(ot,p(u(421))),_s=x(P(cr,ot,rt,nt),p(u(421))),dn=g(u(4),p(u(43))),pn=g(p(u(42)),u(41),p(u(43))),ur=P(dn,pn),ae=P(ur,cr,rt,nt,ot),xu=x(P(ur,g(P(cr,ot,rt,nt),p(u(421))))),yu=x(dn),Eu=x(pn),vu=x(ur),lr=g(ae,u(6)),Ne=g(ae,u(273)),Cu=x(g(lr,p(u(421)))),Su=x(Ne),fr=g(Ne,E(460),p(u(421))),st=g(Ne,E(461),p(u(421))),Os=P(fr,st),Du=x(fr),Iu=x(st),ar=P(ae,lr,Ne,fr,st),mn=P(g(ar,E(477),p(u(421)))),bn=x(mn),gn=P(g(ar,E(478),p(u(421))),g(ar,E(448),p(u(449)),E(477),p(u(421)))),wn=x(gn),xn=g(Ne,E(280),p(u(466)),p(u(466)),p(u(421))),Tu=x(xn),yn=g(st,E(465),p(u(466)),p(u(466)),p(u(421))),Lu=x(yn),tt=P(mn,gn,g(lr,p(u(421))),g(Os,p(u(421))),g(ae,p(u(421))),xn,yn,u(421)),Au=x(tt),Bs=g(tt,E(290),u(421)),Pu=x(Bs),Us=P(g(tt,E(290),E(281),p(u(421))),g(tt,E(281),p(u(421))),g(E(281),p(u(421)))),_u=x(Us),Ns=P(g(ae,u(6),E(480),p(u(421))),g(ae,E(480),p(u(421)))),Ou=x(Ns),Rs=g(ae,P(g(u(6,"443"),E(480)),g(u(6),E(443)),g(u(6),E(448),E(480)),g(E(448),E(480)),E(448),E(443)),p(u(421))),Bu=x(Rs),ks=P(g(u(777),p(u(421)))),Uu=x(ks),Ms=P(g(u(400),p(u(421)))),Nu=x(Ms);function En(r){return r.filter(e=>wn.exactMatch(e)||bn.exactMatch(e))}function vn(){throw new Error("WebSocket Servers can not be created in the browser!")}var Sn=Symbol.for("@achingbrain/uint8arraylist");function Cn(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let o=t+n.byteLength;if(e<o)return{buf:n,index:e-t};t=o}throw new RangeError("index is out of bounds")}function it(r){return!!r?.[Sn]}var ye=class r{bufs;length;[Sn]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(let n of e)if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.push(n);else if(it(n))t+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(let n of e.reverse())if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.unshift(n);else if(it(n))t+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}get(e){let t=Cn(this.bufs,e);return t.buf[t.index]}set(e,t){let n=Cn(this.bufs,e);n.buf[n.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(t+n,e[n]);else if(it(e))for(let n=0;n<e.length;n++)this.set(t+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:n,length:o}=this._subList(e,t);return Y(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:Y(n,o)}sublist(e,t){let{bufs:n,length:o}=this._subList(e,t),s=new r;return s.length=o,s.bufs=[...n],s}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,e>=c)continue;let l=e>=a&&e<c,h=t>a&&t<=c;if(l&&h){if(e===a&&t===c){n.push(i);break}let f=e-a;n.push(i.subarray(f,f+(t-e)));break}if(l){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(h){if(t===c){n.push(i);break}n.push(i.subarray(0,t-a));break}n.push(i)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!it(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let f=0;f<s;f++)i[f]=-1;for(let f=0;f<o;f++)i[n[f]]=f;let a=i,c=this.byteLength-n.byteLength,l=n.byteLength-1,h;for(let f=t;f<=c;f+=h){h=0;for(let y=l;y>=0;y--){let w=this.get(f+y);if(n[y]!==w){h=Math.max(1,y-a[w]);break}}if(h===0)return f}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let n=K(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){let o=q(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,t,n),this.write(o,e)}getInt32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){let o=q(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,t,n),this.write(o,e)}getBigInt64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){let o=q(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,t,n),this.write(o,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let n=K(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){let o=q(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,t,n),this.write(o,e)}getUint32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){let o=q(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,t,n),this.write(o,e)}getBigUint64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){let o=q(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,t,n),this.write(o,e)}getFloat32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){let o=q(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,t,n),this.write(o,e)}getFloat64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){let o=q(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,t,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof r)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!je(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((o,s)=>o+s.byteLength,0)),n.length=t,n}};function at(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var ct=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},Ee=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new ct(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let t=this.head;this.head=t.next=new ct(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var hr=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function Dn(r={}){return Vs(t=>{let n=t.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function Vs(r,e){e=e??{};let t=e.onEnd,n=new Ee,o,s,i,a=at(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((d,D)=>{s=_=>{s=null,n.push(_);try{d(r(n))}catch(T){D(T)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=at()})}},l=d=>s!=null?s(d):(n.push(d),o),h=d=>(n=new Ee,s!=null?s({error:d}):(n.push({error:d}),o)),f=d=>{if(i)return o;if(e?.objectMode!==!0&&d?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:d})},y=d=>i?o:(i=!0,d!=null?h(d):l({done:!0})),w=()=>(n=new Ee,y(),{done:!0}),b=d=>(y(d),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:w,throw:b,push:f,end:y,get readableLength(){return n.size},onEmpty:async d=>{let D=d?.signal;if(D?.throwIfAborted(),n.isEmpty())return;let _,T;D!=null&&(_=new Promise((O,N)=>{T=()=>{N(new hr)},D.addEventListener("abort",T)}));try{await Promise.race([a.promise,_])}finally{T!=null&&D!=null&&D?.removeEventListener("abort",T)}}},t==null)return o;let S=o;return o={[Symbol.asyncIterator](){return this},next(){return S.next()},throw(d){return S.throw(d),t!=null&&(t(d),t=void 0),{done:!0}},return(){return S.return(),t!=null&&(t(),t=void 0),{done:!0}},push:f,end(d){return S.end(d),t!=null&&(t(d),t=void 0),o},get readableLength(){return S.readableLength},onEmpty:d=>S.onEmpty(d)},o}function In(r,e){let t,n=function(){let o=function(){t=void 0,r()};clearTimeout(t),t=setTimeout(o,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(t)},n}var $s=Math.pow(2,20)*4,ut=class extends ze{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;constructor(e){super(),this.status="open",this.log=e.log,this.direction=e.direction??"outbound",this.inactivityTimeout=e.inactivityTimeout??12e4,this.maxReadBufferLength=e.maxReadBufferLength??$s,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new ye,this.writeBuffer=new ye,this.readStatus="readable",this.remoteReadStatus="readable",this.writeStatus="writable",this.remoteWriteStatus="writable",this.sendingData=!1,this.writableNeedsDrain=!1,this.timeline={open:Date.now()},this.processSendQueue=this.processSendQueue.bind(this);let t=()=>{this.log.trace("drain event received, continue sending data"),this.writableNeedsDrain=!1,this.processSendQueue()};this.addEventListener("drain",t)}async*[Symbol.asyncIterator](){if(this.readStatus!=="readable"&&this.readStatus!=="paused")return;let e=Dn(),t=s=>{e.push(s.data)};this.addEventListener("message",t);let n=s=>{e.end(s.error)};this.addEventListener("close",n);let o=()=>{e.end()};this.addEventListener("remoteCloseWrite",o);try{yield*e}finally{this.removeEventListener("message",t),this.removeEventListener("close",n),this.removeEventListener("remoteCloseWrite",o)}}isReadable(){return this.status==="open"}send(e){if(this.writeStatus==="closed"||this.writeStatus==="closing")throw new te(`Cannot write to a stream that is ${this.writeStatus}`);return this.log.trace("append %d bytes to write buffer",e.byteLength),this.writeBuffer.append(e),this.processSendQueue()}abort(e){if(!(this.status==="aborted"||this.status==="reset"||this.status==="closed")){this.log.error("abort with error - %e",e),this.status="aborted",this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle")),this.writeStatus="closed",this.remoteWriteStatus="closed",this.readStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now();try{this.sendReset(e)}catch(t){this.log("failed to send reset to remote - %e",t)}this.dispatchEvent(new Ve(e))}}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new te("Cannot pause a stream that is closing/closed");this.readStatus!=="paused"&&(this.readStatus="paused",this.sendPause())}resume(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new te("Cannot resume a stream that is closing/closed");this.readStatus!=="readable"&&(this.readStatus="readable",this.dispatchReadBuffer(),this.sendResume())}push(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new te(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.append(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}onData(e){if(e.byteLength!==0){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("ignoring data - read status %s",this.readStatus);return}this.readBuffer.append(e),this.dispatchReadBuffer()}}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="message"&&this.readBuffer.byteLength>0&&queueMicrotask(()=>{this.dispatchReadBuffer()})}onRemoteReset(){this.log("remote reset"),this.status="reset",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.readBuffer.byteLength===0&&(this.readStatus="closed");let e=new Me;this.dispatchEvent(new $e(e))}onTransportClosed(e){this.log("transport closed"),this.readStatus==="readable"&&this.readBuffer.byteLength===0&&(this.readStatus="closed"),this.remoteReadStatus!=="closed"&&(this.remoteReadStatus="closed"),this.remoteWriteStatus!=="closed"&&(this.remoteWriteStatus="closed"),this.writeStatus!=="closed"&&(this.writeStatus="closed"),e!=null?this.abort(e):(this.status==="open"||this.status==="closing")&&(this.timeline.close=Date.now(),this.status="closed",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.dispatchEvent(new ce))}onRemoteCloseWrite(){this.remoteWriteStatus!=="closed"&&(this.log.trace("on remote close write"),this.remoteWriteStatus="closed",this.safeDispatchEvent("remoteCloseWrite"),this.writeStatus==="closed"&&this.onTransportClosed())}onRemoteCloseRead(){this.log.trace("on remote close read"),this.remoteReadStatus="closed",this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle"))}processSendQueue(){if(this.writableNeedsDrain)return this.log.trace("not processing send queue as drain is required"),this.checkWriteBufferLength(),!1;if(this.writeBuffer.byteLength===0)return this.log.trace("not processing send queue as no bytes to send"),!0;if(this.sendingData)return this.log.trace("not processing send queue as already sending data"),!0;this.sendingData=!0,this.log.trace("processing send queue with %d queued bytes",this.writeBuffer.byteLength);try{let e=!0,t=this.writeBuffer.byteLength,n=0;for(;this.writeBuffer.byteLength>0;){let o=Math.min(this.maxMessageSize??this.writeBuffer.byteLength,this.writeBuffer.byteLength);if(o===0){e=!1;break}let s=this.writeBuffer.sublist(0,o),i=new ye(s);this.writeBuffer.consume(s.byteLength);let a=this.sendData(s);if(e=a.canSendMore,n+=a.sentBytes,a.sentBytes!==i.byteLength&&(i.consume(a.sentBytes),this.writeBuffer.prepend(i)),!e)break}return e||(this.log.trace("sent %d/%d bytes, pausing sending because underlying stream is full, %d bytes left in the write buffer",n,t,this.writeBuffer.byteLength),this.writableNeedsDrain=!0,this.checkWriteBufferLength()),this.writeBuffer.byteLength===0&&this.safeDispatchEvent("idle"),e}finally{this.sendingData=!1}}dispatchReadBuffer(){try{if(this.listenerCount("message")===0){this.log.trace("not dispatching pause buffer as there are no listeners for the message event");return}if(this.readBuffer.byteLength===0){this.log.trace("not dispatching pause buffer as there is no data to dispatch");return}if(this.readStatus==="paused"){this.log.trace("not dispatching pause buffer we are paused");return}if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("dropping %d bytes because the readable end is %s",this.readBuffer.byteLength,this.readStatus),this.readBuffer.consume(this.readBuffer.byteLength);return}let e=this.readBuffer.sublist();this.readBuffer.consume(e.byteLength),this.dispatchEvent(new Fe(e))}finally{this.remoteWriteStatus==="closed"&&(this.readStatus="closed"),this.checkReadBufferLength()}}checkReadBufferLength(){this.readBuffer.byteLength>this.maxReadBufferLength&&this.abort(new ve(`Read buffer length of ${this.readBuffer.byteLength} exceeded limit of ${this.maxReadBufferLength}, read status is ${this.readStatus}`))}checkWriteBufferLength(){this.maxWriteBufferLength!=null&&this.writeBuffer.byteLength>this.maxWriteBufferLength&&this.abort(new ve(`Write buffer length of ${this.writeBuffer.byteLength} exceeded limit of ${this.maxWriteBufferLength}, write status is ${this.writeStatus}`))}onMuxerNeedsDrain(){this.writableNeedsDrain=!0}onMuxerDrain(){this.safeDispatchEvent("drain")}};var lt=class extends ut{remoteAddr;metricPrefix;metrics;constructor(e){super(e),this.metricPrefix=e.metricPrefix??"",this.metrics=e.metrics,this.remoteAddr=e.remoteAddr,this.addEventListener("close",t=>{this.metrics?.increment({[`${this.metricPrefix}end`]:!0}),t.error!=null?t.local?this.metrics?.increment({[`${this.metricPrefix}abort`]:!0}):this.metrics?.increment({[`${this.metricPrefix}reset`]:!0}):t.local?this.metrics?.increment({[`${this.metricPrefix}_local_close`]:!0}):this.metrics?.increment({[`${this.metricPrefix}_remote_close`]:!0})})}async close(e){this.status==="open"&&(this.status="closing",this.writeStatus="closing",this.remoteWriteStatus="closing",this.remoteReadStatus="closing",(this.sendingData||this.writeBuffer.byteLength>0)&&(this.log("waiting for write queue to become idle before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await Ue(this,"idle",{...e,rejectionEvents:["close"]})),this.writableNeedsDrain&&(this.log("waiting for write queue to drain before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await Ue(this,"drain",{...e,rejectionEvents:["close"]})),await this.sendClose(e),this.onTransportClosed())}};function Tn(r){let e=new globalThis.AbortController;function t(){e.abort();for(let s of r)s?.removeEventListener!=null&&s.removeEventListener("abort",t)}for(let s of r){if(s?.aborted===!0){t();break}s?.addEventListener!=null&&s.addEventListener("abort",t)}function n(){for(let s of r)s?.removeEventListener!=null&&s.removeEventListener("abort",t)}let o=e.signal;return o.clear=n,o}function Ln(r,e,t){let n,o,s=!1;function i(){let l={signal:o.signal};if(t?.timeout!=null){let h=Tn([o.signal,AbortSignal.timeout(t.timeout)]);l.signal=h}s=!0,Promise.resolve().then(async()=>{await r(l)}).catch(()=>{}).finally(()=>{s=!1,!o.signal.aborted&&(n=setTimeout(i,e))})}let a=In(i,t?.debounce??100),c=!1;return{setInterval:l=>{e!==l&&(e=l,n!=null&&(clearTimeout(n),n=setTimeout(i,e)))},setTimeout:l=>{t??={},t.timeout=l},run:()=>{s||(clearTimeout(n),a())},start:()=>{c||(c=!0,o=new AbortController,o.signal,t?.runImmediately===!0?queueMicrotask(()=>{i()}):n=setTimeout(i,e))},stop:()=>{clearTimeout(n),o?.abort(),c=!1}}}var zs=1024*1024*4,Ws=10,dr=class extends lt{websocket;maxBufferedAmount;checkBufferedAmountTask;constructor(e){super(e),this.websocket=e.websocket,this.maxBufferedAmount=e.maxBufferedAmount??zs,this.checkBufferedAmountTask=Ln(this.checkBufferedAmount.bind(this),e.bufferedAmountPollInterval??Ws),this.websocket.addEventListener("close",t=>{if(this.log('closed - code %d, reason "%s", wasClean %s',t.code,t.reason,t.wasClean),this.checkBufferedAmountTask.stop(),!t.wasClean){this.onRemoteReset();return}this.onTransportClosed()},{once:!0}),this.websocket.addEventListener("message",t=>{try{let n;if(typeof t.data=="string")n=$(t.data);else if(t.data instanceof ArrayBuffer)n=new Uint8Array(t.data,0,t.data.byteLength);else{this.abort(new Error("Incorrect binary type"));return}this.onData(n)}catch(n){this.log.error("error receiving data - %e",n)}})}sendData(e){for(let n of e)this.websocket.send(n);let t=this.websocket.bufferedAmount<this.maxBufferedAmount;return t||this.checkBufferedAmountTask.start(),{sentBytes:e.byteLength,canSendMore:t}}sendReset(){this.websocket.close(1006)}async sendClose(e){this.websocket.close(),e?.signal?.throwIfAborted()}sendPause(){}sendResume(){}checkBufferedAmount(){this.log("buffered amount now %d",this.websocket.bufferedAmount),this.websocket.bufferedAmount===0&&(this.checkBufferedAmountTask.stop(),this.safeDispatchEvent("drain"))}};function An(r){return new dr(r)}var pr=class{log;init;logger;metrics;components;constructor(e,t={}){this.log=e.logger.forComponent("libp2p:websockets"),this.logger=e.logger,this.components=e,this.init=t,e.metrics!=null&&(this.metrics={dialerEvents:e.metrics.registerCounterGroup("libp2p_websockets_dialer_events_total",{label:"event",help:"Total count of WebSockets dialer events by type"})})}[br]=!0;[Symbol.toStringTag]="@libp2p/websockets";[gr]=["@libp2p/transport"];async dial(e,t){this.log("dialing %s",e),t=t??{};let n=An({websocket:await this._connect(e,t),remoteAddr:e,metrics:this.metrics?.dialerEvents,direction:"outbound",log:this.components.logger.forComponent("libp2p:websockets:connection"),maxBufferedAmount:this.init.maxBufferedAmount,bufferedAmountPollInterval:this.init.bufferedAmountPollInterval});this.log("new outbound connection %s",n.remoteAddr);let o=await t.upgrader.upgradeOutbound(n,t);return this.log("outbound connection %s upgraded",n.remoteAddr),o}async _connect(e,t){t?.signal?.throwIfAborted();let n=ln(e);this.log("create websocket connection to %s",n);let o=new WebSocket(n);o.binaryType="arraybuffer";try{t.onProgress?.(new et("websockets:open-connection")),await Ue(o,"open",t)}catch(s){if(t.signal?.aborted)throw this.metrics?.dialerEvents.increment({abort:!0}),new ke(`Could not connect to ${n}`);this.metrics?.dialerEvents.increment({error:!0});try{o.close()}catch{}throw s}return this.log("connected %s",e),this.metrics?.dialerEvents.increment({connect:!0}),o}createListener(e){return vn({logger:this.logger,events:this.components.events,metrics:this.components.metrics},{...this.init,...e})}listenFilter(e){return e=Array.isArray(e)?e:[e],this.init?.filter!=null?this.init?.filter(e):En(e)}dialFilter(e){return this.listenFilter(e)}};function qs(r={}){return e=>new pr(e,r)}return Un(Hs);})();
3
3
  return Libp2PWebsockets}));
4
4
  //# sourceMappingURL=index.min.js.map