@libp2p/websockets 10.1.0-8cebf6322 → 10.1.0-e2bdc7e63

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 at=Object.defineProperty;var Bn=Object.getOwnPropertyDescriptor;var Un=Object.getOwnPropertyNames;var Nn=Object.prototype.hasOwnProperty;var B=(r,e)=>{for(var t in e)at(r,t,{get:e[t],enumerable:!0})},Rn=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Un(e))!Nn.call(r,o)&&o!==t&&at(r,o,{get:()=>e[o],enumerable:!(n=Bn(e,o))||n.enumerable});return r};var Mn=r=>Rn(at({},"__esModule",{value:!0}),r);var js={};B(js,{webSockets:()=>Ws});var Pe=class extends Error{static name="ConnectionFailedError";constructor(e="Connection failed"){super(e),this.name="ConnectionFailedError"}};var Oe=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var H=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},me=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var _e=class extends Event{data;constructor(e,t){super("message",t),this.data=e}},re=class extends Event{error;local;constructor(e,t,n){super("close",n),this.error=t,this.local=e}},Be=class extends re{constructor(e,t){super(!0,e,t)}},Ue=class extends re{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 Ne=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"),Ys=Symbol.for("@libp2p/service-dependencies");function Re(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 k(r=0){return new Uint8Array(r)}function q(r=0){return new Uint8Array(r)}var Vn=Math.pow(2,7),kn=Math.pow(2,14),Fn=Math.pow(2,21),ct=Math.pow(2,28),ut=Math.pow(2,35),lt=Math.pow(2,42),ft=Math.pow(2,49),C=128,A=127;function ne(r){if(r<Vn)return 1;if(r<kn)return 2;if(r<Fn)return 3;if(r<ct)return 4;if(r<ut)return 5;if(r<lt)return 6;if(r<ft)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function dt(r,e,t=0){switch(ne(r)){case 8:e[t++]=r&255|C,r/=128;case 7:e[t++]=r&255|C,r/=128;case 6:e[t++]=r&255|C,r/=128;case 5:e[t++]=r&255|C,r/=128;case 4:e[t++]=r&255|C,r>>>=7;case 3:e[t++]=r&255|C,r>>>=7;case 2:e[t++]=r&255|C,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function $n(r,e){let t=r[e],n=0;if(n+=t&A,t<C||(t=r[e+1],n+=(t&A)<<7,t<C)||(t=r[e+2],n+=(t&A)<<14,t<C)||(t=r[e+3],n+=(t&A)<<21,t<C)||(t=r[e+4],n+=(t&A)*ct,t<C)||(t=r[e+5],n+=(t&A)*ut,t<C)||(t=r[e+6],n+=(t&A)*lt,t<C)||(t=r[e+7],n+=(t&A)*ft,t<C))return n;throw new RangeError("Could not decode varint")}function zn(r,e){let t=r.get(e),n=0;if(n+=t&A,t<C||(t=r.get(e+1),n+=(t&A)<<7,t<C)||(t=r.get(e+2),n+=(t&A)<<14,t<C)||(t=r.get(e+3),n+=(t&A)<<21,t<C)||(t=r.get(e+4),n+=(t&A)*ct,t<C)||(t=r.get(e+5),n+=(t&A)*ut,t<C)||(t=r.get(e+6),n+=(t&A)*lt,t<C)||(t=r.get(e+7),n+=(t&A)*ft,t<C))return n;throw new RangeError("Could not decode varint")}function ht(r,e=0){return r instanceof Uint8Array?$n(r,e):zn(r,e)}function Q(r,e){e==null&&(e=r.reduce((o,s)=>o+s.length,0));let t=q(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var wt={};B(wt,{base10:()=>Yn});var Pi=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 F(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 jn(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(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var y=0,b=0,D=0,O=m.length;D!==O&&m[D]===0;)D++,y++;for(var I=(O-D)*h+1>>>0,_=new Uint8Array(I);D!==O;){for(var U=m[D],j=0,N=I-1;(U!==0||j<b)&&N!==-1;N--,j++)U+=256*_[N]>>>0,_[N]=U%a>>>0,U=U/a>>>0;if(U!==0)throw new Error("Non-zero carry");b=j,D++}for(var V=I-b;V!==I&&_[V]===0;)V++;for(var Ae=c.repeat(y);V<I;++V)Ae+=r.charAt(_[V]);return Ae}function g(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var y=0;if(m[y]!==" "){for(var b=0,D=0;m[y]===c;)b++,y++;for(var O=(m.length-y)*l+1>>>0,I=new Uint8Array(O);m[y];){var _=t[m.charCodeAt(y)];if(_===255)return;for(var U=0,j=O-1;(_!==0||U<D)&&j!==-1;j--,U++)_+=a*I[j]>>>0,I[j]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");D=U,y++}if(m[y]!==" "){for(var N=O-D;N!==O&&I[N]===0;)N++;for(var V=new Uint8Array(b+(O-N)),Ae=b;N!==O;)V[Ae++]=I[N++];return V}}}function u(m){var y=g(m);if(y)return y;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:g,decode:u}}var Hn=jn,qn=Hn,vr=qn;var pt=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")}},mt=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)}},bt=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 bt({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var gt=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 pt(e,t,n),this.decoder=new mt(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function oe({name:r,prefix:e,encode:t,decode:n}){return new gt(r,e,t,n)}function G({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=vr(t,r);return oe({prefix:e,name:r,encode:n,decode:s=>F(o(s))})}function Qn(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 Gn(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 Xn(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function S({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let o=Xn(n);return oe({prefix:e,name:r,encode(s){return Gn(s,n,t)},decode(s){return Qn(s,o,t,r)}})}var Yn=G({prefix:"9",name:"base10",alphabet:"0123456789"});var xt={};B(xt,{base16:()=>Jn,base16upper:()=>Kn});var Jn=S({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Kn=S({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var yt={};B(yt,{base2:()=>Zn});var Zn=S({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Et={};B(Et,{base256emoji:()=>oo});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}"),eo=Sr.reduce((r,e,t)=>(r[t]=e,r),[]),to=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 ro(r){return r.reduce((e,t)=>(e+=eo[t],e),"")}function no(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=to[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var oo=oe({prefix:"\u{1F680}",name:"base256emoji",encode:ro,decode:no});var vt={};B(vt,{base32:()=>X,base32hex:()=>co,base32hexpad:()=>lo,base32hexpadupper:()=>fo,base32hexupper:()=>uo,base32pad:()=>io,base32padupper:()=>ao,base32upper:()=>so,base32z:()=>ho});var X=S({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),so=S({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),io=S({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ao=S({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),co=S({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),uo=S({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),lo=S({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),fo=S({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ho=S({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ct={};B(Ct,{base36:()=>be,base36upper:()=>po});var be=G({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),po=G({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var St={};B(St,{base58btc:()=>M,base58flickr:()=>mo});var M=G({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),mo=G({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Tt={};B(Tt,{base64:()=>bo,base64pad:()=>go,base64url:()=>Dt,base64urlpad:()=>wo});var bo=S({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),go=S({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Dt=S({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),wo=S({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var It={};B(It,{base8:()=>xo});var xo=S({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Lt={};B(Lt,{identity:()=>yo});var yo=oe({prefix:"\0",name:"identity",encode:r=>yr(r),decode:r=>xr(r)});var qi=new TextEncoder,Qi=new TextDecoder;var Pt={};B(Pt,{identity:()=>Wo});var Co=Ir,Dr=128,So=127,Do=~So,To=Math.pow(2,31);function Ir(r,e,t){e=e||[],t=t||0;for(var n=t;r>=To;)e[t++]=r&255|Dr,r/=128;for(;r&Do;)e[t++]=r&255|Dr,r>>>=7;return e[t]=r|0,Ir.bytes=t-n+1,e}var Io=At,Lo=128,Tr=127;function At(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw At.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&Tr)<<o:(i&Tr)*Math.pow(2,o),o+=7}while(i>=Lo);return At.bytes=s-n,t}var Ao=Math.pow(2,7),Po=Math.pow(2,14),Oo=Math.pow(2,21),_o=Math.pow(2,28),Bo=Math.pow(2,35),Uo=Math.pow(2,42),No=Math.pow(2,49),Ro=Math.pow(2,56),Mo=Math.pow(2,63),Vo=function(r){return r<Ao?1:r<Po?2:r<Oo?3:r<_o?4:r<Bo?5:r<Uo?6:r<No?7:r<Ro?8:r<Mo?9:10},ko={encode:Co,decode:Io,encodingLength:Vo},Fo=ko,ge=Fo;function we(r,e=0){return[ge.decode(r,e),ge.decode.bytes]}function se(r,e,t=0){return ge.encode(r,e,t),e}function ie(r){return ge.encodingLength(r)}function ce(r,e){let t=e.byteLength,n=ie(r),o=n+ie(t),s=new Uint8Array(o+t);return se(r,s,0),se(t,s,n),s.set(e,o),new ae(r,t,e,s)}function Lr(r){let e=F(r),[t,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 ae(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 ae=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,$o="identity",Or=F;function zo(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 ce(Pr,Or(r))}var Wo={code:Pr,name:$o,encode:Or,digest:zo};var Bt={};B(Bt,{sha256:()=>Ho,sha512:()=>qo});var jo=20;function _t({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:o}){return new Ot(r,e,t,n,o)}var Ot=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,o,s){this.name=e,this.code=t,this.encode=n,this.minDigestLength=o??jo,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?_r(n,this.code,t?.truncate):n.then(o=>_r(o,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function _r(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 ce(e,r)}function Ur(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var Ho=_t({name:"sha2-256",code:18,encode:Ur("SHA-256")}),qo=_t({name:"sha2-512",code:19,encode:Ur("SHA-512")});function Nr(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return Go(t,Ut(r),e??M.encoder);default:return Xo(t,Ut(r),e??X.encoder)}}var Rr=new WeakMap;function Ut(r){let e=Rr.get(r);if(e==null){let t=new Map;return Rr.set(r,t),t}return e}var ue=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!==ye)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Yo)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=ce(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??Mr(n,o,s.bytes))}else if(t[Jo]===!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!==ye)throw new Error(`Version 0 CID must use dag-pb (code: ${ye}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=Mr(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,ye,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=F(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 ae(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,g]=we(e.subarray(t));return t+=g,f},o=n(),s=ye;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]=Qo(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 Ut(s).set(n,e),s}};function Qo(r,e){switch(r[0]){case"Q":{let t=e??M;return[M.prefix,t.decode(`${M.prefix}${r}`)]}case M.prefix:{let t=e??M;return[M.prefix,t.decode(r)]}case X.prefix:{let t=e??X;return[X.prefix,t.decode(r)]}case be.prefix:{let t=e??be;return[be.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 Go(r,e,t){let{prefix:n}=t;if(n!==M.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 Xo(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 ye=112,Yo=18;function Mr(r,e,t){let n=ie(r),o=n+ie(e),s=new Uint8Array(o+t.byteLength);return se(r,s,0),se(e,s,n),s.set(t,o),s}var Jo=Symbol.for("@ipld/js-cid/CID");var Ee={...Lt,...yt,...It,...wt,...xt,...vt,...Ct,...St,...Tt,...Et},ma={...Bt,...Pt};function kr(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Vr=kr("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Nt=kr("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=q(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Ko={utf8:Vr,"utf-8":Vr,hex:Ee.base16,latin1:Nt,ascii:Nt,binary:Nt,...Ee},Ve=Ko;function J(r,e="utf8"){let t=Ve[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function K(r,e="utf8"){let t=Ve[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"},$=class extends Error{static name="ValidationError";name="ValidationError"},ke=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Fe=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var $e=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 g=Number.parseInt(f,e);if(!Number.isNaN(g))return g});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 Zo=45,es=15,ze=new $e;function Fr(r){if(!(r.length>es))return ze.new(r).parseWith(()=>ze.readIPv4Addr())}function $r(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Zo))return ze.new(r).parseWith(()=>ze.readIPv6Addr())}function We(r){return!!Fr(r)}function zr(r){return!!$r(r)}function Mt(r){return e=>K(e,r)}function Vt(r){return e=>J(e,r)}function le(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function Z(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(e)}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!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let t=J(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 Q([t,o],t.length+o.length)}function jr(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=Z(n);return Q([t,o],t.length+o.length)}function kt(r){let e=r.subarray(0,r.length-2),t=r.subarray(r.length-2),n=K(e,"base32"),o=le(t);return`${n}:${o}`}var Ft=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},Hr=function(r){let e=0;r=r.toString().trim();let t=r.split(":",8),n;for(n=0;n<t.length;n++){let s=We(t[n]),i;s&&(i=Ft(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},qr=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(".")},Qr=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 Gr(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 Rt=Object.values(Ee).map(r=>r.decoder),ts=(function(){let r=Rt[0].or(Rt[1]);return Rt.slice(2).forEach(e=>r=r.or(e)),r})();function Xr(r){return ts.decode(r)}function Yr(r){return e=>r.encoder.encode(e)}function rs(r){if(parseInt(r).toString()!==r)throw new $("Value must be an integer")}function ns(r){if(r<0)throw new $("Value must be a positive integer, or zero")}function os(r){return e=>{if(e>r)throw new $(`Value must be smaller than or equal to ${r}`)}}function ss(...r){return e=>{for(let t of r)t(e)}}var ve=ss(rs,ns,os(65535));var T=-1,$t=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 Fe(`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)}))}},W=new $t,ys=[{code:4,name:"ip4",size:32,valueToBytes:Ft,bytesToValue:qr,validate:r=>{if(!We(r))throw new $(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Z,bytesToValue:le,validate:ve},{code:273,name:"udp",size:16,valueToBytes:Z,bytesToValue:le,validate:ve},{code:33,name:"dccp",size:16,valueToBytes:Z,bytesToValue:le,validate:ve},{code:41,name:"ip6",size:128,valueToBytes:Hr,bytesToValue:Qr,stringToValue:Gr,validate:r=>{if(!zr(r))throw new $(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:T},{code:43,name:"ipcidr",size:8,bytesToValue:Mt("base10"),valueToBytes:Vt("base10")},{code:53,name:"dns",size:T},{code:54,name:"dns4",size:T},{code:55,name:"dns6",size:T},{code:56,name:"dnsaddr",size:T},{code:132,name:"sctp",size:16,valueToBytes:Z,bytesToValue:le,validate:ve},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:T,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:T,bytesToValue:Mt("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?Vt("base58btc")(r):ue.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:kt,valueToBytes:Wr},{code:445,name:"onion3",size:296,bytesToValue:kt,valueToBytes:jr},{code:446,name:"garlic64",size:T},{code:447,name:"garlic32",size:T},{code:448,name:"tls"},{code:449,name:"sni",size:T},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:T,bytesToValue:Yr(Dt),valueToBytes:Xr},{code:480,name:"http"},{code:481,name:"http-path",size:T,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:T}];ys.forEach(r=>{W.addProtocol(r)});function Jr(r){let e=[],t=0;for(;t<r.length;){let n=ht(r,t),o=W.getProtocol(n),s=ne(n),i=Es(o,r,t+s),a=0;i>0&&o.size===T&&(a=ne(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=W.getProtocol(n.code),s=ne(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??J(n.value),a=i.byteLength,o.size===T&&(c=ne(a)));let l=new Uint8Array(s+c+a),h=0;dt(n.code,l,h),h+=s,i!=null&&(o.size===T&&(dt(a,l,h),h+=c),l.set(i,h)),n.bytes=l}t.push(n.bytes),e+=n.bytes.byteLength}return Q(t,e)}function Zr(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=W.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 en(r){return`/${r.flatMap(e=>{if(e.value==null)return e.name;let t=W.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 Es(r,e,t){return r.size==null||r.size===0?0:r.size>0?r.size/8:ht(e,t)}var vs=Symbol.for("nodejs.util.inspect.custom"),Zt=Symbol.for("@multiformats/multiaddr");function Cs(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="/"),Zr(r);if(Array.isArray(r))return r;throw new L("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Ge=class r{[Zt]=!0;#e;#t;#r;constructor(e="/",t={}){this.#e=Cs(e),t.validate!==!1&&Ss(this)}get bytes(){return this.#r==null&&(this.#r=Kr(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=en(this.#e)),this.#t}toJSON(){return this.toString()}getComponents(){return[...this.#e.map(e=>({...e}))]}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 ke(`Address ${this.toString()} does not contain subaddress: ${t}`);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})}equals(e){return Re(this.bytes,e.bytes)}[vs](){return`Multiaddr(${this.toString()})`}};function Ss(r){r.getComponents().forEach(e=>{let t=W.getProtocol(e.code);e.value!=null&&t.validate?.(e.value)})}function tn(r){return!!r?.[Zt]}function rn(r){return new Ge(r)}var E=r=>({match:e=>{let t=e[0];return t==null||t.code!==r||t.value!=null?!1:e.slice(1)}}),d=(r,e)=>({match:t=>{let n=t[0];return n?.code!==r||n.value==null||e!=null&&n.value!==e?!1:t.slice(1)}}),nn=r=>({match:e=>r.match(e)===!1?e:!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}}),w=(...r)=>({match:e=>{for(let t of r){let n=t.match(e);if(n===!1)return!1;e=n}return e}});function v(...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 Ds=d(421),mc=v(Ds),Ye=d(54),Je=d(55),Ke=d(56),tr=d(53),bc=v(Ye,p(d(421))),gc=v(Je,p(d(421))),wc=v(Ke,p(d(421))),xc=v(P(tr,Ke,Ye,Je),p(d(421))),on=w(d(4),p(d(43))),sn=w(p(d(42)),d(41),p(d(43))),rr=P(on,sn),te=P(rr,tr,Ye,Je,Ke),yc=v(P(rr,w(P(tr,Ke,Ye,Je),p(d(421))))),Ec=v(on),vc=v(sn),Cc=v(rr),nr=w(te,d(6)),Le=w(te,d(273)),Sc=v(w(nr,p(d(421)))),Dc=v(Le),or=w(Le,E(460),p(d(421))),Ze=w(Le,E(461),p(d(421))),Ts=P(or,Ze),Tc=v(or),Ic=v(Ze),er=P(te,nr,Le,or,Ze),an=P(w(er,E(477),p(d(421)))),cn=v(an),un=P(w(er,E(478),p(d(421))),w(er,E(448),p(d(449)),E(477),p(d(421)))),ln=v(un),fn=w(Le,E(280),p(d(466)),p(d(466)),p(d(421))),Lc=v(fn),dn=w(Ze,E(465),p(d(466)),p(d(466)),p(d(421))),Ac=v(dn),Xe=P(an,un,w(nr,p(d(421))),w(Ts,p(d(421))),w(te,p(d(421))),fn,dn,d(421)),Pc=v(Xe),Is=w(p(Xe),E(290),nn(E(281)),p(d(421))),Oc=v(Is),Ls=P(w(Xe,E(290),E(281),p(d(421))),w(Xe,E(281),p(d(421))),w(E(281),p(d(421)))),_c=v(Ls),As=P(w(te,d(6),E(480),p(d(421))),w(te,E(480),p(d(421)))),Bc=v(As),Ps=w(te,P(w(d(6,"443"),E(480)),w(d(6),E(443)),w(d(6),E(448),E(480)),w(E(448),E(480)),E(448),E(443)),p(d(421))),Uc=v(Ps),Os=P(w(d(777),p(d(421)))),Nc=v(Os),_s=P(w(d(400),p(d(421)))),Rc=v(_s);var Bs=[6,53,56,54,55];function hn(r){return bn("sni",r)?.value}function pn(r){let e=bn("tcp",r)?.value;return e==null?"":`:${e}`}function bn(r,e){return e.find(t=>t.name===r)}function mn(r){return r.some(({code:e})=>e===448)}function R(r,e){let t=gn[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 gn={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://${R(t,e)}:${r.value}`},udp:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");return`udp://${R(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`${R(t,e)}`},p2p:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");return`${R(t,e)}`},http:(r,e)=>{let t=mn(e),n=hn(e),o=pn(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=R(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=R(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 R(t,e)},sni:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");return R(t,e)},https:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");let n=R(t,e);return n=n?.replace("tcp://",""),`https://${n}`},ws:(r,e)=>{let t=mn(e),n=hn(e),o=pn(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=R(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=R(t,e);return n=n?.replace("tcp://",""),`wss://${n}`}};function wn(r,e){let n=rn(r).getComponents(),o=n.pop();if(o==null)throw new Error("Unexpected end of multiaddr");let s=gn[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 sr=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},ir=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},xn=r=>globalThis.DOMException===void 0?new ir(r):new DOMException(r),yn=r=>{let e=r.reason===void 0?xn("This operation was aborted."):r.reason;return e instanceof Error?e:xn(e)};function ar(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:u}=e;u.aborted&&f(yn(u)),a=()=>{f(yn(u))},u.addEventListener("abort",a,{once:!0})}if(t===Number.POSITIVE_INFINITY){r.then(h,f);return}let g=new sr;i=s.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(u){f(u)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?h():o instanceof Error?f(o):(g.message=o??`Promise timed out after ${t} milliseconds`,f(g))},t),(async()=>{try{h(await r)}catch(u){f(u)}})()}).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 Us=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 Ns(r,e,t){let n,o=new Promise((s,i)=>{if(t={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!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}=Us(r),f=async(...u)=>{let m=t.multiArgs?u:u[0];if(t.filter)try{if(!await t.filter(m))return}catch(y){n(),i(y);return}c.push(m),t.count===c.length&&(n(),s(c))},g=(...u)=>{n(),i(t.rejectionMultiArgs?u:u[0])};n=()=>{for(let u of a)h(u,f);for(let u of t.rejectionEvents)a.includes(u)||h(u,g)};for(let u of a)l(u,f);for(let u of t.rejectionEvents)a.includes(u)||l(u,g);t.signal&&t.signal.addEventListener("abort",()=>{g(t.signal.reason)},{once:!0}),t.resolveImmediately&&s(c)});if(o.cancel=n,typeof t.timeout=="number"){let s=ar(o,{milliseconds:t.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function En(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=Ns(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}};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 tt(r){return!!r?.[Sn]}var he=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(tt(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(tt(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(tt(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 Q(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:Q(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(!tt(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 g=l;g>=0;g--){let u=this.get(f+g);if(n[g]!==u){h=Math.max(1,g-a[u]);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=q(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=k(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=k(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=k(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=q(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=k(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=k(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=k(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=k(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=k(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(!Re(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 rt(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var nt=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}},pe=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new nt(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 nt(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 cr=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 Rs(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 Rs(r,e){e=e??{};let t=e.onEnd,n=new pe,o,s,i,a=rt(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((b,D)=>{s=O=>{s=null,n.push(O);try{b(r(n))}catch(I){D(I)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=rt()})}},l=b=>s!=null?s(b):(n.push(b),o),h=b=>(n=new pe,s!=null?s({error:b}):(n.push({error:b}),o)),f=b=>{if(i)return o;if(e?.objectMode!==!0&&b?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:b})},g=b=>i?o:(i=!0,b!=null?h(b):l({done:!0})),u=()=>(n=new pe,g(),{done:!0}),m=b=>(g(b),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:u,throw:m,push:f,end:g,get readableLength(){return n.size},onEmpty:async b=>{let D=b?.signal;if(D?.throwIfAborted(),n.isEmpty())return;let O,I;D!=null&&(O=new Promise((_,U)=>{I=()=>{U(new cr)},D.addEventListener("abort",I)}));try{await Promise.race([a.promise,O])}finally{I!=null&&D!=null&&D?.removeEventListener("abort",I)}}},t==null)return o;let y=o;return o={[Symbol.asyncIterator](){return this},next(){return y.next()},throw(b){return y.throw(b),t!=null&&(t(b),t=void 0),{done:!0}},return(){return y.return(),t!=null&&(t(),t=void 0),{done:!0}},push:f,end(b){return y.end(b),t!=null&&(t(b),t=void 0),o},get readableLength(){return y.readableLength},onEmpty:b=>y.onEmpty(b)},o}var ur=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},lr=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Tn=r=>globalThis.DOMException===void 0?new lr(r):new DOMException(r),In=r=>{let e=r.reason===void 0?Tn("This operation was aborted."):r.reason;return e instanceof Error?e:Tn(e)};function fr(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:u}=e;u.aborted&&f(In(u)),a=()=>{f(In(u))},u.addEventListener("abort",a,{once:!0})}if(t===Number.POSITIVE_INFINITY){r.then(h,f);return}let g=new ur;i=s.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(u){f(u)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?h():o instanceof Error?f(o):(g.message=o??`Promise timed out after ${t} milliseconds`,f(g))},t),(async()=>{try{h(await r)}catch(u){f(u)}})()}).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 Ms=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 Vs(r,e,t){let n,o=new Promise((s,i)=>{if(t={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!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}=Ms(r),f=async(...u)=>{let m=t.multiArgs?u:u[0];if(t.filter)try{if(!await t.filter(m))return}catch(y){n(),i(y);return}c.push(m),t.count===c.length&&(n(),s(c))},g=(...u)=>{n(),i(t.rejectionMultiArgs?u:u[0])};n=()=>{for(let u of a)h(u,f);for(let u of t.rejectionEvents)a.includes(u)||h(u,g)};for(let u of a)l(u,f);for(let u of t.rejectionEvents)a.includes(u)||l(u,g);t.signal&&t.signal.addEventListener("abort",()=>{g(t.signal.reason)},{once:!0}),t.resolveImmediately&&s(c)});if(o.cancel=n,typeof t.timeout=="number"){let s=fr(o,{milliseconds:t.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function dr(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=Vs(r,e,t),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function Ln(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 ot=class extends Error{static name="StreamClosedError";name="StreamClosedError"};function ks(r){return r.reason}async function An(r,e,t){if(e==null)return r;let n=t?.translateError??ks;if(e.aborted)return r.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([r,new Promise((s,i)=>{o=()=>{i(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var Fs=Math.pow(2,20)*4,st=class extends Ne{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;onDrainPromise;constructor(e){super(),this.status="open",this.log=e.log,this.direction=e.direction??"outbound",this.inactivityTimeout=e.inactivityTimeout??12e4,this.maxReadBufferLength=e.maxReadBufferLength??Fs,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new he,this.writeBuffer=new he,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.writableNeedsDrain&&(this.log.trace("drain event received, continue sending data"),this.writableNeedsDrain=!1,this.processSendQueue()),this.onDrainPromise?.resolve()};this.addEventListener("drain",t);let n=o=>{this.onDrainPromise?.reject(o.error??new ot)};this.addEventListener("close",n)}get readBufferLength(){return this.readBuffer.byteLength}get writeBufferLength(){return this.writeBuffer.byteLength}async onDrain(e){return this.writableNeedsDrain!==!0?Promise.resolve():(this.onDrainPromise==null&&(this.onDrainPromise=Promise.withResolvers()),An(this.onDrainPromise.promise,e?.signal))}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 H(`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 Be(e))}}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new H("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 H("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 H(`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)}}unshift(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new H(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.prepend(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 Oe;this.dispatchEvent(new Ue(e))}onTransportClosed(e){this.log("transport closed"),this.readStatus==="readable"&&this.readBuffer.byteLength===0&&(this.log("close readable end after transport closed and read buffer is empty"),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 re))}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 he(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 _e(e))}finally{this.readBuffer.byteLength===0&&this.remoteWriteStatus==="closed"&&(this.log("close readable end after dispatching read buffer and remote writable end is closed"),this.readStatus="closed"),this.checkReadBufferLength()}}checkReadBufferLength(){this.readBuffer.byteLength>this.maxReadBufferLength&&this.abort(new me(`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 me(`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 it=class extends st{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 dr(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 dr(this,"drain",{...e,rejectionEvents:["close"]})),await this.sendClose(e),this.onTransportClosed())}};function Pn(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 On(r,e,t){let n,o,s=!1;function i(){let l={signal:o.signal};if(t?.timeout!=null){let h=Pn([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=Ln(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 $s=1024*1024*4,zs=10,hr=class extends it{websocket;maxBufferedAmount;checkBufferedAmountTask;constructor(e){super(e),this.websocket=e.websocket,this.maxBufferedAmount=e.maxBufferedAmount??$s,this.checkBufferedAmountTask=On(this.checkBufferedAmount.bind(this),e.bufferedAmountPollInterval??zs),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=J(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 _n(r){return new hr(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=_n({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=wn(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 En(o,"open",t)}catch(s){if(t.signal?.aborted)throw this.metrics?.dialerEvents.increment({abort:!0}),new Pe(`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.filter(t=>cn.exactMatch(t)||ln.exactMatch(t))}dialFilter(e){return this.listenFilter(e)}};function Ws(r={}){return e=>new pr(e,r)}return Mn(js);})();
2
+ "use strict";var Libp2PWebsockets=(()=>{var ct=Object.defineProperty;var Ln=Object.getOwnPropertyDescriptor;var In=Object.getOwnPropertyNames;var An=Object.prototype.hasOwnProperty;var B=(r,e)=>{for(var t in e)ct(r,t,{get:e[t],enumerable:!0})},Pn=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of In(e))!An.call(r,o)&&o!==t&&ct(r,o,{get:()=>e[o],enumerable:!(n=Ln(e,o))||n.enumerable});return r};var _n=r=>Pn(ct({},"__esModule",{value:!0}),r);var Rs={};B(Rs,{webSockets:()=>Ns});var _e=class extends Error{static name="ConnectionFailedError";constructor(e="Connection failed"){super(e),this.name="ConnectionFailedError"}};var Oe=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var q=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},me=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var Be=class extends Event{data;constructor(e,t){super("message",t),this.data=e}},re=class extends Event{error;local;constructor(e,t,n){super("close",n),this.error=t,this.local=e}},Ue=class extends re{constructor(e,t){super(!0,e,t)}},Ne=class extends re{constructor(e,t){super(!1,e,t)}};var hr=Symbol.for("@libp2p/transport");var dr;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(dr||(dr={}));var Re=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 pr=Symbol.for("@libp2p/service-capabilities"),zs=Symbol.for("@libp2p/service-dependencies");function Me(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 V(r=0){return new Uint8Array(r)}function H(r=0){return new Uint8Array(r)}var On=Math.pow(2,7),Bn=Math.pow(2,14),Un=Math.pow(2,21),ut=Math.pow(2,28),lt=Math.pow(2,35),ft=Math.pow(2,42),dt=Math.pow(2,49),C=128,A=127;function ne(r){if(r<On)return 1;if(r<Bn)return 2;if(r<Un)return 3;if(r<ut)return 4;if(r<lt)return 5;if(r<ft)return 6;if(r<dt)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ht(r,e,t=0){switch(ne(r)){case 8:e[t++]=r&255|C,r/=128;case 7:e[t++]=r&255|C,r/=128;case 6:e[t++]=r&255|C,r/=128;case 5:e[t++]=r&255|C,r/=128;case 4:e[t++]=r&255|C,r>>>=7;case 3:e[t++]=r&255|C,r>>>=7;case 2:e[t++]=r&255|C,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function Nn(r,e){let t=r[e],n=0;if(n+=t&A,t<C||(t=r[e+1],n+=(t&A)<<7,t<C)||(t=r[e+2],n+=(t&A)<<14,t<C)||(t=r[e+3],n+=(t&A)<<21,t<C)||(t=r[e+4],n+=(t&A)*ut,t<C)||(t=r[e+5],n+=(t&A)*lt,t<C)||(t=r[e+6],n+=(t&A)*ft,t<C)||(t=r[e+7],n+=(t&A)*dt,t<C))return n;throw new RangeError("Could not decode varint")}function Rn(r,e){let t=r.get(e),n=0;if(n+=t&A,t<C||(t=r.get(e+1),n+=(t&A)<<7,t<C)||(t=r.get(e+2),n+=(t&A)<<14,t<C)||(t=r.get(e+3),n+=(t&A)<<21,t<C)||(t=r.get(e+4),n+=(t&A)*ut,t<C)||(t=r.get(e+5),n+=(t&A)*lt,t<C)||(t=r.get(e+6),n+=(t&A)*ft,t<C)||(t=r.get(e+7),n+=(t&A)*dt,t<C))return n;throw new RangeError("Could not decode varint")}function pt(r,e=0){return r instanceof Uint8Array?Nn(r,e):Rn(r,e)}function Q(r,e){e==null&&(e=r.reduce((o,s)=>o+s.length,0));let t=H(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var xt={};B(xt,{base10:()=>jn});var vi=new Uint8Array(0);function mr(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){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 br(r){return new TextEncoder().encode(r)}function gr(r){return new TextDecoder().decode(r)}function kn(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),d=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 v=0,p=0,D=0,_=b.length;D!==_&&b[D]===0;)D++,v++;for(var L=(_-D)*d+1>>>0,O=new Uint8Array(L);D!==_;){for(var U=b[D],j=0,N=L-1;(U!==0||j<p)&&N!==-1;N--,j++)U+=256*O[N]>>>0,O[N]=U%a>>>0,U=U/a>>>0;if(U!==0)throw new Error("Non-zero carry");p=j,D++}for(var k=L-p;k!==L&&O[k]===0;)k++;for(var Pe=c.repeat(v);k<L;++k)Pe+=r.charAt(O[k]);return Pe}function E(b){if(typeof b!="string")throw new TypeError("Expected String");if(b.length===0)return new Uint8Array;var v=0;if(b[v]!==" "){for(var p=0,D=0;b[v]===c;)p++,v++;for(var _=(b.length-v)*l+1>>>0,L=new Uint8Array(_);b[v];){var O=t[b.charCodeAt(v)];if(O===255)return;for(var U=0,j=_-1;(O!==0||U<D)&&j!==-1;j--,U++)O+=a*L[j]>>>0,L[j]=O%256>>>0,O=O/256>>>0;if(O!==0)throw new Error("Non-zero carry");D=U,v++}if(b[v]!==" "){for(var N=_-D;N!==_&&L[N]===0;)N++;for(var k=new Uint8Array(p+(_-N)),Pe=p;N!==_;)k[Pe++]=L[N++];return k}}}function m(b){var v=E(b);if(v)return v;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:E,decode:m}}var Vn=kn,$n=Vn,xr=$n;var mt=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")}},bt=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 yr(this,e)}},gt=class{decoders;constructor(e){this.decoders=e}or(e){return yr(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 yr(r,e){return new gt({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var wt=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 mt(e,t,n),this.decoder=new bt(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function oe({name:r,prefix:e,encode:t,decode:n}){return new wt(r,e,t,n)}function G({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=xr(t,r);return oe({prefix:e,name:r,encode:n,decode:s=>$(o(s))})}function Fn(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 d=e[r[l]];if(d===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|d,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 zn(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 Wn(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function S({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let o=Wn(n);return oe({prefix:e,name:r,encode(s){return zn(s,n,t)},decode(s){return Fn(s,o,t,r)}})}var jn=G({prefix:"9",name:"base10",alphabet:"0123456789"});var yt={};B(yt,{base16:()=>qn,base16upper:()=>Hn});var qn=S({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Hn=S({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Et={};B(Et,{base2:()=>Qn});var Qn=S({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var vt={};B(vt,{base256emoji:()=>Yn});var Er=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}"),Gn=Er.reduce((r,e,t)=>(r[t]=e,r),[]),Xn=Er.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function Jn(r){return r.reduce((e,t)=>(e+=Gn[t],e),"")}function Kn(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=Xn[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var Yn=oe({prefix:"\u{1F680}",name:"base256emoji",encode:Jn,decode:Kn});var Ct={};B(Ct,{base32:()=>X,base32hex:()=>ro,base32hexpad:()=>oo,base32hexpadupper:()=>so,base32hexupper:()=>no,base32pad:()=>eo,base32padupper:()=>to,base32upper:()=>Zn,base32z:()=>io});var X=S({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Zn=S({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),eo=S({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),to=S({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ro=S({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),no=S({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),oo=S({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),so=S({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),io=S({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var St={};B(St,{base36:()=>be,base36upper:()=>ao});var be=G({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),ao=G({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Dt={};B(Dt,{base58btc:()=>M,base58flickr:()=>co});var M=G({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),co=G({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Lt={};B(Lt,{base64:()=>uo,base64pad:()=>lo,base64url:()=>Tt,base64urlpad:()=>fo});var uo=S({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),lo=S({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Tt=S({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),fo=S({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var It={};B(It,{base8:()=>ho});var ho=S({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var At={};B(At,{identity:()=>po});var po=oe({prefix:"\0",name:"identity",encode:r=>gr(r),decode:r=>br(r)});var ki=new TextEncoder,Vi=new TextDecoder;var _t={};B(_t,{identity:()=>Mo});var go=Sr,vr=128,wo=127,xo=~wo,yo=Math.pow(2,31);function Sr(r,e,t){e=e||[],t=t||0;for(var n=t;r>=yo;)e[t++]=r&255|vr,r/=128;for(;r&xo;)e[t++]=r&255|vr,r>>>=7;return e[t]=r|0,Sr.bytes=t-n+1,e}var Eo=Pt,vo=128,Cr=127;function Pt(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Pt.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&Cr)<<o:(i&Cr)*Math.pow(2,o),o+=7}while(i>=vo);return Pt.bytes=s-n,t}var Co=Math.pow(2,7),So=Math.pow(2,14),Do=Math.pow(2,21),To=Math.pow(2,28),Lo=Math.pow(2,35),Io=Math.pow(2,42),Ao=Math.pow(2,49),Po=Math.pow(2,56),_o=Math.pow(2,63),Oo=function(r){return r<Co?1:r<So?2:r<Do?3:r<To?4:r<Lo?5:r<Io?6:r<Ao?7:r<Po?8:r<_o?9:10},Bo={encode:go,decode:Eo,encodingLength:Oo},Uo=Bo,ge=Uo;function we(r,e=0){return[ge.decode(r,e),ge.decode.bytes]}function se(r,e,t=0){return ge.encode(r,e,t),e}function ie(r){return ge.encodingLength(r)}function ce(r,e){let t=e.byteLength,n=ie(r),o=n+ie(t),s=new Uint8Array(o+t);return se(r,s,0),se(t,s,n),s.set(e,o),new ae(r,t,e,s)}function Dr(r){let e=$(r),[t,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 ae(t,o,i,e)}function Tr(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&mr(r.bytes,t.bytes)}}var ae=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};var Lr=0,No="identity",Ir=$;function Ro(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 ce(Lr,Ir(r))}var Mo={code:Lr,name:No,encode:Ir,digest:Ro};var Ut={};B(Ut,{sha256:()=>Vo,sha512:()=>$o});var ko=20;function Bt({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:o}){return new Ot(r,e,t,n,o)}var Ot=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,o,s){this.name=e,this.code=t,this.encode=n,this.minDigestLength=o??ko,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?Ar(n,this.code,t?.truncate):n.then(o=>Ar(o,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function Ar(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 ce(e,r)}function _r(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var Vo=Bt({name:"sha2-256",code:18,encode:_r("SHA-256")}),$o=Bt({name:"sha2-512",code:19,encode:_r("SHA-512")});function Or(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return zo(t,Nt(r),e??M.encoder);default:return Wo(t,Nt(r),e??X.encoder)}}var Br=new WeakMap;function Nt(r){let e=Br.get(r);if(e==null){let t=new Map;return Br.set(r,t),t}return e}var ue=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!==ye)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==jo)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=ce(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&&Tr(e.multihash,n.multihash)}toString(e){return Or(this,e)}toJSON(){return{"/":Or(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??Ur(n,o,s.bytes))}else if(t[qo]===!0){let{version:n,multihash:o,code:s}=t,i=Dr(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!==ye)throw new Error(`Version 0 CID must use dag-pb (code: ${ye}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=Ur(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,ye,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=$(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 ae(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,E]=we(e.subarray(t));return t+=E,f},o=n(),s=ye;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,d=l-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:d,size:l}}static parse(e,t){let[n,o]=Fo(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 Nt(s).set(n,e),s}};function Fo(r,e){switch(r[0]){case"Q":{let t=e??M;return[M.prefix,t.decode(`${M.prefix}${r}`)]}case M.prefix:{let t=e??M;return[M.prefix,t.decode(r)]}case X.prefix:{let t=e??X;return[X.prefix,t.decode(r)]}case be.prefix:{let t=e??be;return[be.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 zo(r,e,t){let{prefix:n}=t;if(n!==M.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 Wo(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 ye=112,jo=18;function Ur(r,e,t){let n=ie(r),o=n+ie(e),s=new Uint8Array(o+t.byteLength);return se(r,s,0),se(e,s,n),s.set(t,o),s}var qo=Symbol.for("@ipld/js-cid/CID");var Ee={...At,...Et,...It,...xt,...yt,...Ct,...St,...Dt,...Lt,...vt},aa={...Ut,..._t};function Rr(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Nr=Rr("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Rt=Rr("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=H(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Ho={utf8:Nr,"utf-8":Nr,hex:Ee.base16,latin1:Rt,ascii:Rt,binary:Rt,...Ee},Ve=Ho;function K(r,e="utf8"){let t=Ve[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function Y(r,e="utf8"){let t=Ve[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var I=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},F=class extends Error{static name="ValidationError";name="ValidationError"},$e=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Fe=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var ze=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 d=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let E=Number.parseInt(f,e);if(!Number.isNaN(E))return E});if(d===void 0)break;if(s*=e,s+=d,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 Qo=45,Go=15,We=new ze;function Mr(r){if(!(r.length>Go))return We.new(r).parseWith(()=>We.readIPv4Addr())}function kr(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Qo))return We.new(r).parseWith(()=>We.readIPv6Addr())}function je(r){return!!Mr(r)}function Vr(r){return!!kr(r)}function kt(r){return e=>Y(e,r)}function Vt(r){return e=>K(e,r)}function le(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function Z(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(e)}function $r(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=K(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 Q([t,o],t.length+o.length)}function Fr(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=Z(n);return Q([t,o],t.length+o.length)}function $t(r){let e=r.subarray(0,r.length-2),t=r.subarray(r.length-2),n=Y(e,"base32"),o=le(t);return`${n}:${o}`}var Ft=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 I("Invalid byte value in IP address");e[n]=o}),e},zr=function(r){let e=0;r=r.toString().trim();let t=r.split(":",8),n;for(n=0;n<t.length;n++){let s=je(t[n]),i;s&&(i=Ft(t[n]),t[n]=Y(i.subarray(0,2),"base16")),i!=null&&++n<8&&t.splice(n,0,Y(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 I("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},Wr=function(r){if(r.byteLength!==4)throw new I("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 I("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 I(`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 I(`Invalid IPv6 address "${r}"`)}}var Mt=Object.values(Ee).map(r=>r.decoder),Xo=(function(){let r=Mt[0].or(Mt[1]);return Mt.slice(2).forEach(e=>r=r.or(e)),r})();function Hr(r){return Xo.decode(r)}function Qr(r){return e=>r.encoder.encode(e)}function Jo(r){if(parseInt(r).toString()!==r)throw new F("Value must be an integer")}function Ko(r){if(r<0)throw new F("Value must be a positive integer, or zero")}function Yo(r){return e=>{if(e>r)throw new F(`Value must be smaller than or equal to ${r}`)}}function Zo(...r){return e=>{for(let t of r)t(e)}}var ve=Zo(Jo,Ko,Yo(65535));var T=-1,zt=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 Fe(`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)}))}},W=new zt,ps=[{code:4,name:"ip4",size:32,valueToBytes:Ft,bytesToValue:Wr,validate:r=>{if(!je(r))throw new F(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Z,bytesToValue:le,validate:ve},{code:273,name:"udp",size:16,valueToBytes:Z,bytesToValue:le,validate:ve},{code:33,name:"dccp",size:16,valueToBytes:Z,bytesToValue:le,validate:ve},{code:41,name:"ip6",size:128,valueToBytes:zr,bytesToValue:jr,stringToValue:qr,validate:r=>{if(!Vr(r))throw new F(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:T},{code:43,name:"ipcidr",size:8,bytesToValue:kt("base10"),valueToBytes:Vt("base10")},{code:53,name:"dns",size:T},{code:54,name:"dns4",size:T},{code:55,name:"dns6",size:T},{code:56,name:"dnsaddr",size:T},{code:132,name:"sctp",size:16,valueToBytes:Z,bytesToValue:le,validate:ve},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:T,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:T,bytesToValue:kt("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?Vt("base58btc")(r):ue.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:$t,valueToBytes:$r},{code:445,name:"onion3",size:296,bytesToValue:$t,valueToBytes:Fr},{code:446,name:"garlic64",size:T},{code:447,name:"garlic32",size:T},{code:448,name:"tls"},{code:449,name:"sni",size:T},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:T,bytesToValue:Qr(Tt),valueToBytes:Hr},{code:480,name:"http"},{code:481,name:"http-path",size:T,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:T}];ps.forEach(r=>{W.addProtocol(r)});function Gr(r){let e=[],t=0;for(;t<r.length;){let n=pt(r,t),o=W.getProtocol(n),s=ne(n),i=ms(o,r,t+s),a=0;i>0&&o.size===T&&(a=ne(i));let c=s+a+i,l={code:n,name:o.name,bytes:r.subarray(t,t+c)};if(i>0){let d=t+s+a,f=r.subarray(d,d+i);l.value=o.bytesToValue?.(f)??Y(f)}e.push(l),t+=c}return e}function Xr(r){let e=0,t=[];for(let n of r){if(n.bytes==null){let o=W.getProtocol(n.code),s=ne(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??K(n.value),a=i.byteLength,o.size===T&&(c=ne(a)));let l=new Uint8Array(s+c+a),d=0;ht(n.code,l,d),d+=s,i!=null&&(o.size===T&&(ht(a,l,d),d+=c),l.set(i,d)),n.bytes=l}t.push(n.bytes),e+=n.bytes.byteLength}return Q(t,e)}function Jr(r){if(r.charAt(0)!=="/")throw new I('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=W.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 I(`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 I(`Component ${o} was missing value`);l.value=c.stringToValue?.(n)??n}e.push(l),n="",o="",t="protocol"}}}if(o!==""&&n!=="")throw new I("Incomplete multiaddr");return e}function Kr(r){return`/${r.flatMap(e=>{if(e.value==null)return e.name;let t=W.getProtocol(e.code);if(t==null)throw new I(`Unknown protocol code ${e.code}`);return[e.name,t.valueToString?.(e.value)??e.value]}).join("/")}`}function ms(r,e,t){return r.size==null||r.size===0?0:r.size>0?r.size/8:pt(e,t)}var bs=Symbol.for("nodejs.util.inspect.custom"),er=Symbol.for("@multiformats/multiaddr");function gs(r){if(r==null&&(r="/"),Yr(r))return r.getComponents();if(r instanceof Uint8Array)return Gr(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),Jr(r);if(Array.isArray(r))return r;throw new I("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Xe=class r{[er]=!0;#e;#t;#r;constructor(e="/",t={}){this.#e=gs(e),t.validate!==!1&&ws(this)}get bytes(){return this.#r==null&&(this.#r=Xr(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=Kr(this.#e)),this.#t}toJSON(){return this.toString()}getComponents(){return[...this.#e.map(e=>({...e}))]}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 $e(`Address ${this.toString()} does not contain subaddress: ${t}`);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})}equals(e){return Me(this.bytes,e.bytes)}[bs](){return`Multiaddr(${this.toString()})`}};function ws(r){r.getComponents().forEach(e=>{let t=W.getProtocol(e.code);e.value!=null&&t.validate?.(e.value)})}function Yr(r){return!!r?.[er]}function Zr(r){return new Xe(r)}var x=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)}}),en=r=>({match:e=>r.match(e)===!1?e:!1}),h=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 y(...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 xs=u(421),ac=y(xs),Ke=u(54),Ye=u(55),Ze=u(56),rr=u(53),cc=y(Ke,h(u(421))),uc=y(Ye,h(u(421))),lc=y(Ze,h(u(421))),fc=y(P(rr,Ze,Ke,Ye),h(u(421))),tn=g(u(4),h(u(43))),rn=g(h(u(42)),u(41),h(u(43))),nr=P(tn,rn),te=P(nr,rr,Ke,Ye,Ze),dc=y(P(nr,g(P(rr,Ze,Ke,Ye),h(u(421))))),hc=y(tn),pc=y(rn),mc=y(nr),or=g(te,u(6)),Ie=g(te,u(273)),bc=y(g(or,h(u(421)))),gc=y(Ie),sr=g(Ie,x(460),h(u(421))),et=g(Ie,x(461),h(u(421))),ys=P(sr,et),wc=y(sr),xc=y(et),tr=P(te,or,Ie,sr,et),nn=P(g(tr,x(477),h(u(421)))),on=y(nn),sn=P(g(tr,x(478),h(u(421))),g(tr,x(448),h(u(449)),x(477),h(u(421)))),an=y(sn),cn=g(Ie,x(280),h(u(466)),h(u(466)),h(u(421))),yc=y(cn),un=g(et,x(465),h(u(466)),h(u(466)),h(u(421))),Ec=y(un),Je=P(nn,sn,g(or,h(u(421))),g(ys,h(u(421))),g(te,h(u(421))),cn,un,u(421)),vc=y(Je),Es=g(h(Je),x(290),en(x(281)),h(u(421))),Cc=y(Es),vs=P(g(Je,x(290),x(281),h(u(421))),g(Je,x(281),h(u(421))),g(x(281),h(u(421)))),Sc=y(vs),Cs=P(g(te,u(6),x(480),h(u(421))),g(te,x(480),h(u(421)))),Dc=y(Cs),Ss=g(te,P(g(u(6,"443"),x(480)),g(u(6),x(443)),g(u(6),x(448),x(480)),g(x(448),x(480)),x(448),x(443)),h(u(421))),Tc=y(Ss),Ds=P(g(u(777),h(u(421)))),Lc=y(Ds),Ts=P(g(u(400),h(u(421)))),Ic=y(Ts);var Ls=[6,53,56,54,55];function ln(r){return hn("sni",r)?.value}function fn(r){let e=hn("tcp",r)?.value;return e==null?"":`:${e}`}function hn(r,e){return e.find(t=>t.name===r)}function dn(r){return r.some(({code:e})=>e===448)}function R(r,e){let t=pn[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 pn={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://${R(t,e)}:${r.value}`},udp:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");return`udp://${R(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`${R(t,e)}`},p2p:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");return`${R(t,e)}`},http:(r,e)=>{let t=dn(e),n=ln(e),o=fn(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=R(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=R(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 R(t,e)},sni:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");return R(t,e)},https:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");let n=R(t,e);return n=n?.replace("tcp://",""),`https://${n}`},ws:(r,e)=>{let t=dn(e),n=ln(e),o=fn(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=R(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=R(t,e);return n=n?.replace("tcp://",""),`wss://${n}`}};function mn(r,e){let n=Zr(r).getComponents(),o=n.pop();if(o==null)throw new Error("Unexpected end of multiaddr");let s=pn[o.name];if(s==null)throw new Error(`No interpreter found for ${o.name}`);let i=s(o,n)??"";return e?.assumeHttp!==!1&&Ls.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 ir=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},ar=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},bn=r=>globalThis.DOMException===void 0?new ar(r):new DOMException(r),gn=r=>{let e=r.reason===void 0?bn("This operation was aborted."):r.reason;return e instanceof Error?e:bn(e)};function cr(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=e,i,a,l=new Promise((d,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:m}=e;m.aborted&&f(gn(m)),a=()=>{f(gn(m))},m.addEventListener("abort",a,{once:!0})}if(t===Number.POSITIVE_INFINITY){r.then(d,f);return}let E=new ir;i=s.setTimeout.call(void 0,()=>{if(n){try{d(n())}catch(m){f(m)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?d():o instanceof Error?f(o):(E.message=o??`Promise timed out after ${t} milliseconds`,f(E))},t),(async()=>{try{d(await r)}catch(m){f(m)}})()}).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 Is=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,rejectionMultiArgs:!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:d}=Is(r),f=async(...m)=>{let b=t.multiArgs?m:m[0];if(t.filter)try{if(!await t.filter(b))return}catch(v){n(),i(v);return}c.push(b),t.count===c.length&&(n(),s(c))},E=(...m)=>{n(),i(t.rejectionMultiArgs?m:m[0])};n=()=>{for(let m of a)d(m,f);for(let m of t.rejectionEvents)a.includes(m)||d(m,E)};for(let m of a)l(m,f);for(let m of t.rejectionEvents)a.includes(m)||l(m,E);t.signal&&t.signal.addEventListener("abort",()=>{E(t.signal.reason)},{once:!0}),t.resolveImmediately&&s(c)});if(o.cancel=n,typeof t.timeout=="number"){let s=cr(o,{milliseconds:t.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function Ae(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 tt=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};function wn(){throw new Error("WebSocket Servers can not be created in the browser!")}var yn=Symbol.for("@achingbrain/uint8arraylist");function xn(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 rt(r){return!!r?.[yn]}var he=class r{bufs;length;[yn]=!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(rt(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(rt(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=xn(this.bufs,e);return t.buf[t.index]}set(e,t){let n=xn(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(rt(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 Q(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:Q(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,d=t>a&&t<=c;if(l&&d){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(d){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(!rt(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,d;for(let f=t;f<=c;f+=d){d=0;for(let E=l;E>=0;E--){let m=this.get(f+E);if(n[E]!==m){d=Math.max(1,E-a[m]);break}}if(d===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=H(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=V(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=V(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=V(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=H(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=V(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=V(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=V(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=V(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=V(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(!Me(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 nt(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var ot=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}},pe=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new ot(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 ot(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 ur=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function En(r={}){return Ps(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 Ps(r,e){e=e??{};let t=e.onEnd,n=new pe,o,s,i,a=nt(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((p,D)=>{s=_=>{s=null,n.push(_);try{p(r(n))}catch(L){D(L)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=nt()})}},l=p=>s!=null?s(p):(n.push(p),o),d=p=>(n=new pe,s!=null?s({error:p}):(n.push({error:p}),o)),f=p=>{if(i)return o;if(e?.objectMode!==!0&&p?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:p})},E=p=>i?o:(i=!0,p!=null?d(p):l({done:!0})),m=()=>(n=new pe,E(),{done:!0}),b=p=>(E(p),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:m,throw:b,push:f,end:E,get readableLength(){return n.size},onEmpty:async p=>{let D=p?.signal;if(D?.throwIfAborted(),n.isEmpty())return;let _,L;D!=null&&(_=new Promise((O,U)=>{L=()=>{U(new ur)},D.addEventListener("abort",L)}));try{await Promise.race([a.promise,_])}finally{L!=null&&D!=null&&D?.removeEventListener("abort",L)}}},t==null)return o;let v=o;return o={[Symbol.asyncIterator](){return this},next(){return v.next()},throw(p){return v.throw(p),t!=null&&(t(p),t=void 0),{done:!0}},return(){return v.return(),t!=null&&(t(),t=void 0),{done:!0}},push:f,end(p){return v.end(p),t!=null&&(t(p),t=void 0),o},get readableLength(){return v.readableLength},onEmpty:p=>v.onEmpty(p)},o}function vn(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 st=class extends Error{static name="StreamClosedError";name="StreamClosedError"};function _s(r){return r.reason}async function Cn(r,e,t){if(e==null)return r;let n=t?.translateError??_s;if(e.aborted)return r.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([r,new Promise((s,i)=>{o=()=>{i(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var Os=Math.pow(2,20)*4,it=class extends Re{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;onDrainPromise;constructor(e){super(),this.status="open",this.log=e.log,this.direction=e.direction??"outbound",this.inactivityTimeout=e.inactivityTimeout??12e4,this.maxReadBufferLength=e.maxReadBufferLength??Os,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new he,this.writeBuffer=new he,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.writableNeedsDrain&&(this.log.trace("drain event received, continue sending data"),this.writableNeedsDrain=!1,this.processSendQueue()),this.onDrainPromise?.resolve()};this.addEventListener("drain",t);let n=o=>{this.onDrainPromise?.reject(o.error??new st)};this.addEventListener("close",n)}get readBufferLength(){return this.readBuffer.byteLength}get writeBufferLength(){return this.writeBuffer.byteLength}async onDrain(e){return this.writableNeedsDrain!==!0?Promise.resolve():(this.onDrainPromise==null&&(this.onDrainPromise=Promise.withResolvers()),Cn(this.onDrainPromise.promise,e?.signal))}async*[Symbol.asyncIterator](){if(this.readStatus!=="readable"&&this.readStatus!=="paused")return;let e=En(),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 q(`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 Ue(e))}}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new q("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 q("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 q(`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)}}unshift(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new q(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.prepend(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 Oe;this.dispatchEvent(new Ne(e))}onTransportClosed(e){this.log("transport closed"),this.readStatus==="readable"&&this.readBuffer.byteLength===0&&(this.log("close readable end after transport closed and read buffer is empty"),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 re))}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 he(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 Be(e))}finally{this.readBuffer.byteLength===0&&this.remoteWriteStatus==="closed"&&(this.log("close readable end after dispatching read buffer and remote writable end is closed"),this.readStatus="closed"),this.checkReadBufferLength()}}checkReadBufferLength(){this.readBuffer.byteLength>this.maxReadBufferLength&&this.abort(new me(`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 me(`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 at=class extends it{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 Ae(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 Ae(this,"drain",{...e,rejectionEvents:["close"]})),await this.sendClose(e),this.onTransportClosed())}};function Sn(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 Dn(r,e,t){let n,o,s=!1;function i(){let l={signal:o.signal};if(t?.timeout!=null){let d=Sn([o.signal,AbortSignal.timeout(t.timeout)]);l.signal=d}s=!0,Promise.resolve().then(async()=>{await r(l)}).catch(()=>{}).finally(()=>{s=!1,!o.signal.aborted&&(n=setTimeout(i,e))})}let a=vn(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 Bs=1024*1024*4,Us=10,lr=class extends at{websocket;maxBufferedAmount;checkBufferedAmountTask;constructor(e){super(e),this.websocket=e.websocket,this.maxBufferedAmount=e.maxBufferedAmount??Bs,this.checkBufferedAmountTask=Dn(this.checkBufferedAmount.bind(this),e.bufferedAmountPollInterval??Us),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=K(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 Tn(r){return new lr(r)}var fr=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"})})}[hr]=!0;[Symbol.toStringTag]="@libp2p/websockets";[pr]=["@libp2p/transport"];async dial(e,t){this.log("dialing %s",e),t=t??{};let n=Tn({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=mn(e);this.log("create websocket connection to %s",n);let o=new WebSocket(n);o.binaryType="arraybuffer";try{t.onProgress?.(new tt("websockets:open-connection")),await Ae(o,"open",t)}catch(s){if(t.signal?.aborted)throw this.metrics?.dialerEvents.increment({abort:!0}),new _e(`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 wn({logger:this.logger,events:this.components.events,metrics:this.components.metrics},{...this.init,...e})}listenFilter(e){return e.filter(t=>on.exactMatch(t)||an.exactMatch(t))}dialFilter(e){return this.listenFilter(e)}};function Ns(r={}){return e=>new fr(e,r)}return _n(Rs);})();
3
3
  return Libp2PWebsockets}));
4
4
  //# sourceMappingURL=index.min.js.map