@libp2p/memory 2.0.24 → 2.0.25-423335b45

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.Libp2PMemory = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PMemory=(()=>{var pt=Object.defineProperty;var Bn=Object.getOwnPropertyDescriptor;var Un=Object.getOwnPropertyNames;var Nn=Object.prototype.hasOwnProperty;var P=(r,e)=>{for(var t in e)pt(r,t,{get:e[t],enumerable:!0})},Mn=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Un(e))!Nn.call(r,o)&&o!==t&&pt(r,o,{get:()=>e[o],enumerable:!(n=Bn(e,o))||n.enumerable});return r};var Rn=r=>Mn(pt({},"__esModule",{value:!0}),r);var Js={};P(Js,{memory:()=>Xs});var re=class extends Error{static name="ConnectionFailedError";constructor(e="Connection failed"){super(e),this.name="ConnectionFailedError"}};var ne=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var X=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},ve=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var Ne=class extends Error{static name="ListenError";constructor(e="Listen error"){super(e),this.name="ListenError"}};var Me=class extends Event{data;constructor(e,t){super("message",t),this.data=e}},oe=class extends Event{error;local;constructor(e,t,n){super("close",n),this.error=t,this.local=e}},Re=class extends oe{constructor(e,t){super(!0,e,t)}},Ve=class extends oe{constructor(e,t){super(!1,e,t)}};var Tr=Symbol.for("@libp2p/transport");var Ir;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(Ir||(Ir={}));function Vn(r){return typeof r?.handleEvent=="function"}function Fn(r){return(r!==!0&&r!==!1&&r?.once)??!1}var se=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){let o=Fn(n);super.addEventListener(e,i=>{if(o){let a=this.#e.get(i.type);a!=null&&(a=a.filter(({callback:c})=>c!==t),this.#e.set(i.type,a))}Vn(t)?t.handleEvent(i):t(i)},n);let s=this.#e.get(e);s==null&&(s=[],this.#e.set(e,s)),s.push({callback:t,once:o})}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))}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};var Ar=Symbol.for("@libp2p/service-capabilities");function Ce(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=0){return new Uint8Array(r)}function z(r=0){return new Uint8Array(r)}var zn=Math.pow(2,7),$n=Math.pow(2,14),Wn=Math.pow(2,21),mt=Math.pow(2,28),bt=Math.pow(2,35),gt=Math.pow(2,42),wt=Math.pow(2,49),v=128,T=127;function ie(r){if(r<zn)return 1;if(r<$n)return 2;if(r<Wn)return 3;if(r<mt)return 4;if(r<bt)return 5;if(r<gt)return 6;if(r<wt)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function yt(r,e,t=0){switch(ie(r)){case 8:e[t++]=r&255|v,r/=128;case 7:e[t++]=r&255|v,r/=128;case 6:e[t++]=r&255|v,r/=128;case 5:e[t++]=r&255|v,r/=128;case 4:e[t++]=r&255|v,r>>>=7;case 3:e[t++]=r&255|v,r>>>=7;case 2:e[t++]=r&255|v,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function kn(r,e){let t=r[e],n=0;if(n+=t&T,t<v||(t=r[e+1],n+=(t&T)<<7,t<v)||(t=r[e+2],n+=(t&T)<<14,t<v)||(t=r[e+3],n+=(t&T)<<21,t<v)||(t=r[e+4],n+=(t&T)*mt,t<v)||(t=r[e+5],n+=(t&T)*bt,t<v)||(t=r[e+6],n+=(t&T)*gt,t<v)||(t=r[e+7],n+=(t&T)*wt,t<v))return n;throw new RangeError("Could not decode varint")}function jn(r,e){let t=r.get(e),n=0;if(n+=t&T,t<v||(t=r.get(e+1),n+=(t&T)<<7,t<v)||(t=r.get(e+2),n+=(t&T)<<14,t<v)||(t=r.get(e+3),n+=(t&T)<<21,t<v)||(t=r.get(e+4),n+=(t&T)*mt,t<v)||(t=r.get(e+5),n+=(t&T)*bt,t<v)||(t=r.get(e+6),n+=(t&T)*gt,t<v)||(t=r.get(e+7),n+=(t&T)*wt,t<v))return n;throw new RangeError("Could not decode varint")}function xt(r,e=0){return r instanceof Uint8Array?kn(r,e):jn(r,e)}function Hn(r){return r.buffer instanceof ArrayBuffer}function Et(r){return Hn(r)?r:r.slice()}function Qn(r){return r?.buffer instanceof ArrayBuffer}function vt(r){if(Qn(r))return r;let e=r.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function k(r,e){e==null&&(e=r.reduce((o,s)=>o+s.length,0));let t=z(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return vt(t)}var Tt={};P(Tt,{base10:()=>to});var zi=new Uint8Array(0);function Pr(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 U(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return Z(r);if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return Z(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));throw new Error("Unknown type, must be binary type")}function _r(r){let e=new Uint8Array(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}var Lr=4096;function Or(r){let e=r.length;if(e<=Lr)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.subarray(n,n+=Lr));return t}function Gn(r){return r?.buffer instanceof ArrayBuffer}function Z(r){return Gn(r)?r:r.slice()}function Xn(r,e,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),o=0;o<n.length;o++)n[o]=255;for(var s=0;s<r.length;s++){var i=r.charAt(s),a=i.charCodeAt(0);if(n[a]!==255)throw new TypeError(i+" is ambiguous");if(n[a]=s,t){var c=i.toLowerCase().charCodeAt(0),h=i.toUpperCase().charCodeAt(0);c!==a&&(n[c]=s),h!==a&&(n[h]=s)}}var f=r.length,l=r.charAt(0),g=Math.log(f)/Math.log(256),w=Math.log(256)/Math.log(f);function Q(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var S=0,L=0,_=0,O=p.length;_!==O&&p[_]===0;)_++,S++;for(var R=(O-_)*w+1>>>0,B=new Uint8Array(R);_!==O;){for(var V=p[_],G=0,M=R-1;(V!==0||G<L)&&M!==-1;M--,G++)V+=256*B[M]>>>0,B[M]=V%f>>>0,V=V/f>>>0;if(V!==0)throw new Error("Non-zero carry");L=G,_++}for(var W=R-L;W!==R&&B[W]===0;)W++;for(var Ue=l.repeat(S);W<R;++W)Ue+=r.charAt(B[W]);return Ue}function N(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var S=0;if(p[S]!==" "){for(var L=0,_=0;p[S]===l;)L++,S++;for(var O=(p.length-S)*g+1>>>0,R=new Uint8Array(O);p[S];){var B=n[p.charCodeAt(S)];if(B===255)return;for(var V=0,G=O-1;(B!==0||V<_)&&G!==-1;G--,V++)B+=f*R[G]>>>0,R[G]=B%256>>>0,B=B/256>>>0;if(B!==0)throw new Error("Non-zero carry");_=V,S++}if(p[S]!==" "){for(var M=O-_;M!==O&&R[M]===0;)M++;for(var W=new Uint8Array(L+(O-M)),Ue=L;M!==O;)W[Ue++]=R[M++];return W}}}function y(p){var S=N(p);if(S)return S;throw new Error(`Non-${e} character`)}return{encode:Q,decodeUnsafe:N,decode:y}}var Jn=Xn,Yn=Jn,Ur=Yn;var Ct=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")}},St=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 Nr(this,e)}},Dt=class{decoders;constructor(e){this.decoders=e}or(e){return Nr(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 Nr(r,e){return new Dt({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var It=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 Ct(e,t,n),this.decoder=new St(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function ae({name:r,prefix:e,encode:t,decode:n}){return new It(r,e,t,n)}function J({name:r,prefix:e,alphabet:t,caseInsensitive:n=!1}){let{encode:o,decode:s}=Ur(t,r,n);return ae({prefix:e,name:r,encode:o,decode:i=>U(s(i))})}function Kn(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 h=0;h<o;++h){let f=e[r[h]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|f,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 eo(r,e){let t={};for(let n=0;n<r.length;++n)if(t[r[n]]=n,e){let o=r[n].toLowerCase(),s=r[n].toUpperCase();o!==r[n]&&(t[o]=n),s!==r[n]&&(t[s]=n)}return t}function C({name:r,prefix:e,bitsPerChar:t,alphabet:n,caseInsensitive:o=!1}){let s=eo(n,o);return ae({prefix:e,name:r,encode(i){return Zn(i,n,t)},decode(i){return Kn(i,s,t,r)}})}var to=J({prefix:"9",name:"base10",alphabet:"0123456789"});var At={};P(At,{base16:()=>ro,base16upper:()=>no});var ro=C({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),no=C({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var Lt={};P(Lt,{base2:()=>oo});var oo=C({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Pt={};P(Pt,{base256emoji:()=>uo});var Mr=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}"),so=Mr.reduce((r,e,t)=>(r[t]=e,r),[]),io=Mr.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function ao(r){return r.reduce((e,t)=>(e+=so[t],e),"")}function co(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=io[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var uo=ae({prefix:"\u{1F680}",name:"base256emoji",encode:ao,decode:co});var _t={};P(_t,{base32:()=>Y,base32hex:()=>po,base32hexpad:()=>bo,base32hexpadupper:()=>go,base32hexupper:()=>mo,base32pad:()=>lo,base32padupper:()=>ho,base32upper:()=>fo,base32z:()=>wo});var Y=C({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),fo=C({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),lo=C({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),ho=C({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),po=C({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),mo=C({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),bo=C({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),go=C({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),wo=C({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ot={};P(Ot,{base36:()=>Se,base36upper:()=>yo});var Se=J({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),yo=J({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Bt={};P(Bt,{base58btc:()=>$,base58flickr:()=>xo});var $=J({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),xo=J({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Nt={};P(Nt,{base64:()=>Eo,base64pad:()=>vo,base64url:()=>Ut,base64urlpad:()=>Co});var Eo=C({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),vo=C({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ut=C({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Co=C({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Mt={};P(Mt,{base8:()=>So});var So=C({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Rt={};P(Rt,{identity:()=>Do});var Do=ae({prefix:"\0",name:"identity",encode:r=>Or(U(r)),decode:r=>U(_r(r))});var ra=new TextEncoder,na=new TextDecoder;var Ft={};P(Ft,{identity:()=>Go});var Ao=Fr,Rr=128,Lo=127,Po=~Lo,_o=Math.pow(2,31);function Fr(r,e,t){e=e||[],t=t||0;for(var n=t;r>=_o;)e[t++]=r&255|Rr,r/=128;for(;r&Po;)e[t++]=r&255|Rr,r>>>=7;return e[t]=r|0,Fr.bytes=t-n+1,e}var Oo=Vt,Bo=128,Vr=127;function Vt(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Vt.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&Vr)<<o:(i&Vr)*Math.pow(2,o),o+=7}while(i>=Bo);return Vt.bytes=s-n,t}var Uo=Math.pow(2,7),No=Math.pow(2,14),Mo=Math.pow(2,21),Ro=Math.pow(2,28),Vo=Math.pow(2,35),Fo=Math.pow(2,42),zo=Math.pow(2,49),$o=Math.pow(2,56),Wo=Math.pow(2,63),ko=function(r){return r<Uo?1:r<No?2:r<Mo?3:r<Ro?4:r<Vo?5:r<Fo?6:r<zo?7:r<$o?8:r<Wo?9:10},jo={encode:Ao,decode:Oo,encodingLength:ko},qo=jo,De=qo;function Ie(r,e=0){return[De.decode(r,e),De.decode.bytes]}function ce(r,e,t=0){return De.encode(r,e,t),e}function ue(r){return De.encodingLength(r)}function le(r,e){let t=e.byteLength,n=ue(r),o=n+ue(t),s=new Uint8Array(o+t);return ce(r,s,0),ce(t,s,n),s.set(e,o),new fe(r,t,e,s)}function zr(r){let e=U(r),[t,n]=Ie(e),[o,s]=Ie(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new fe(t,o,i,e)}function $r(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Pr(r.bytes,t.bytes)}}var fe=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=Z(n),this.bytes=Z(o)}};var Wr=0,Ho="identity",kr=U;function Qo(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 le(Wr,kr(r))}var Go={code:Wr,name:Ho,encode:kr,digest:Qo};var Wt={};P(Wt,{sha256:()=>Jo,sha512:()=>Yo});var Xo=20;function $t({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:o}){return new zt(r,e,t,n,o)}var zt=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,o,s){this.name=e,this.code=t,this.encode=n,this.minDigestLength=o??Xo,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?jr(n,this.code,t?.truncate):n.then(o=>jr(o,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function jr(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 le(e,r)}function Hr(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var Jo=$t({name:"sha2-256",code:18,encode:Hr("SHA-256")}),Yo=$t({name:"sha2-512",code:19,encode:Hr("SHA-512")});function Qr(r,e){let{bytes:t,version:n}=r;return n===0?Zo(t,kt(r),e??$.encoder):es(t,kt(r),e??Y.encoder)}var Gr=new WeakMap;function kt(r){let e=Gr.get(r);if(e==null){let t=new Map;return Gr.set(r,t),t}return e}var he=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=Z(o),this["/"]=this.bytes}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!==Ae)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==ts)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=le(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&&$r(e.multihash,n.multihash)}toString(e){return Qr(this,e)}toJSON(){return{"/":Qr(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??Xr(n,o,s.bytes))}else if(t[rs]===!0){let{version:n,multihash:o,code:s}=t,i=zr(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!==Ae)throw new Error(`Version 0 CID must use dag-pb (code: ${Ae}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=Xr(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Ae,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=U(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 fe(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[l,g]=Ie(e.subarray(t));return t+=g,l},o=n(),s=Ae;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(),h=t+c,f=h-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:h}}static parse(e,t){let[n,o]=Ko(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 kt(s).set(n,e),s}};function Ko(r,e){switch(r[0]){case"Q":{let t=e??$;return[$.prefix,t.decode(`${$.prefix}${r}`)]}case $.prefix:{let t=e??$;return[$.prefix,t.decode(r)]}case Y.prefix:{let t=e??Y;return[Y.prefix,t.decode(r)]}case Se.prefix:{let t=e??Se;return[Se.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!==$.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 es(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 Ae=112,ts=18;function Xr(r,e,t){let n=ue(r),o=n+ue(e),s=new Uint8Array(o+t.byteLength);return ce(r,s,0),ce(e,s,n),s.set(t,o),s}var rs=Symbol.for("@ipld/js-cid/CID");var Le={...Rt,...Lt,...Mt,...Tt,...At,..._t,...Ot,...Bt,...Nt,...Pt},Da={...Wt,...Ft};function Yr(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Jr=Yr("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),jt=Yr("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=z(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),ns={utf8:Jr,"utf-8":Jr,hex:Le.base16,latin1:jt,ascii:jt,binary:jt,...Le},ze=ns;function de(r,e="utf8"){let t=ze[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function K(r,e="utf8"){let t=ze[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"},j=class extends Error{static name="ValidationError";name="ValidationError"},$e=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},We=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var ke=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",h=2**(8*o)-1;for(;;){let f=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let g=Number.parseInt(l,e);if(!Number.isNaN(g))return g});if(f===void 0)break;if(s*=e,s+=f,s>h||(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 os=45,ss=15,je=new ke;function Kr(r){if(!(r.length>ss))return je.new(r).parseWith(()=>je.readIPv4Addr())}function Zr(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>os))return je.new(r).parseWith(()=>je.readIPv6Addr())}function qe(r){return!!Kr(r)}function en(r){return!!Zr(r)}function Ht(r){return e=>K(e,r)}function Qt(r){return e=>de(e,r)}function pe(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function ee(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(e)}function tn(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=de(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=ee(n);return k([t,o],t.length+o.length)}function rn(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=Y.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=ee(n);return k([t,o],t.length+o.length)}function Gt(r){let e=r.subarray(0,r.length-2),t=r.subarray(r.length-2),n=K(e,"base32"),o=pe(t);return`${n}:${o}`}var Xt=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},nn=function(r){let e=0;r=r.toString().trim();let t=r.split(":",8),n;for(n=0;n<t.length;n++){let s=qe(t[n]),i;s&&(i=Xt(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 I("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},on=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(".")},sn=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 an(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 qt=Object.values(Le).map(r=>r.decoder),is=(function(){let r=qt[0].or(qt[1]);return qt.slice(2).forEach(e=>r=r.or(e)),r})();function cn(r){return is.decode(r)}function un(r){return e=>r.encoder.encode(e)}function as(r){if(parseInt(r).toString()!==r)throw new j("Value must be an integer")}function cs(r){if(r<0)throw new j("Value must be a positive integer, or zero")}function us(r){return e=>{if(e>r)throw new j(`Value must be smaller than or equal to ${r}`)}}function fs(...r){return e=>{for(let t of r)t(e)}}var Pe=fs(as,cs,us(65535));var D=-1,Jt=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 We(`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)}))}},H=new Jt,Ss=[{code:4,name:"ip4",size:32,valueToBytes:Xt,bytesToValue:on,validate:r=>{if(!qe(r))throw new j(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:ee,bytesToValue:pe,validate:Pe},{code:273,name:"udp",size:16,valueToBytes:ee,bytesToValue:pe,validate:Pe},{code:33,name:"dccp",size:16,valueToBytes:ee,bytesToValue:pe,validate:Pe},{code:41,name:"ip6",size:128,valueToBytes:nn,bytesToValue:sn,stringToValue:an,validate:r=>{if(!en(r))throw new j(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:D},{code:43,name:"ipcidr",size:8,bytesToValue:Ht("base10"),valueToBytes:Qt("base10")},{code:53,name:"dns",size:D},{code:54,name:"dns4",size:D},{code:55,name:"dns6",size:D},{code:56,name:"dnsaddr",size:D},{code:132,name:"sctp",size:16,valueToBytes:ee,bytesToValue:pe,validate:Pe},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:D,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:D,bytesToValue:Ht("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?Qt("base58btc")(r):he.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Gt,valueToBytes:tn},{code:445,name:"onion3",size:296,bytesToValue:Gt,valueToBytes:rn},{code:446,name:"garlic64",size:D},{code:447,name:"garlic32",size:D},{code:448,name:"tls"},{code:449,name:"sni",size:D},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:D,bytesToValue:un(Ut),valueToBytes:cn},{code:480,name:"http"},{code:481,name:"http-path",size:D,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:D}];Ss.forEach(r=>{H.addProtocol(r)});function fn(r){let e=[],t=0;for(;t<r.length;){let n=xt(r,t),o=H.getProtocol(n),s=ie(n),i=Ds(o,r,t+s),a=0;i>0&&o.size===D&&(a=ie(i));let c=s+a+i,h={code:n,name:o.name,bytes:Et(r.subarray(t,t+c))};if(i>0){let f=t+s+a,l=r.subarray(f,f+i);h.value=o.bytesToValue?.(l)??K(l)}e.push(h),t+=c}return e}function ln(r){let e=0,t=[];for(let n of r){if(n.bytes==null){let o=H.getProtocol(n.code),s=ie(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??de(n.value),a=i.byteLength,o.size===D&&(c=ie(a)));let h=new Uint8Array(s+c+a),f=0;yt(n.code,h,f),f+=s,i!=null&&(o.size===D&&(yt(a,h,f),f+=c),h.set(i,f)),n.bytes=h}t.push(n.bytes),e+=n.bytes.byteLength}return k(t,e)}function hn(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=H.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 h={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new I(`Component ${o} was missing value`);h.value=c.stringToValue?.(n)??n}e.push(h),n="",o="",t="protocol"}}}if(o!==""&&n!=="")throw new I("Incomplete multiaddr");return e}function dn(r){return`/${r.flatMap(e=>{if(e.value==null)return e.name;let t=H.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 Ds(r,e,t){return r.size==null||r.size===0?0:r.size>0?r.size/8:xt(e,t)}var Is=Symbol.for("nodejs.util.inspect.custom"),dr=Symbol.for("@multiformats/multiaddr");function Ts(r){if(r==null&&(r="/"),pn(r))return r.getComponents();if(r instanceof Uint8Array)return fn(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),hn(r);if(Array.isArray(r))return r;throw new I("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Ye=class r{[dr]=!0;#e;#t;#r;constructor(e="/",t={}){this.#e=Ts(e),t.validate!==!1&&As(this)}get bytes(){return this.#r==null&&(this.#r=ln(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=dn(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 Ce(this.bytes,e.bytes)}[Is](){return`Multiaddr(${this.toString()})`}};function As(r){r.getComponents().forEach(e=>{let t=H.getProtocol(e.code);e.value!=null&&t.validate?.(e.value)})}function pn(r){return!!r?.[dr]}function _e(r){return new Ye(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)}}),mn=r=>({match:e=>r.match(e)===!1?e:!1}),d=r=>({match:e=>{let t=r.match(e);return t===!1?e:t}}),A=(...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}}),m=(...r)=>({match:e=>{for(let t of r){let n=t.match(e);if(n===!1)return!1;e=n}return e}});function E(...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 Ls=u(421),Fc=E(Ls),Ze=u(54),et=u(55),tt=u(56),mr=u(53),zc=E(Ze,d(u(421))),$c=E(et,d(u(421))),Wc=E(tt,d(u(421))),kc=E(A(mr,tt,Ze,et),d(u(421))),bn=m(u(4),d(u(43))),gn=m(d(u(42)),u(41),d(u(43))),br=A(bn,gn),we=A(br,mr,Ze,et,tt),jc=E(A(br,m(A(mr,tt,Ze,et),d(u(421))))),qc=E(bn),Hc=E(gn),Qc=E(br),gr=m(we,u(6)),Oe=m(we,u(273)),Gc=E(m(gr,d(u(421)))),Xc=E(Oe),wr=m(Oe,x(460),d(u(421))),rt=m(Oe,x(461),d(u(421))),Ps=A(wr,rt),Jc=E(wr),Yc=E(rt),pr=A(we,gr,Oe,wr,rt),wn=A(m(pr,x(477),d(u(421)))),Kc=E(wn),yn=A(m(pr,x(478),d(u(421))),m(pr,x(448),d(u(449)),x(477),d(u(421)))),Zc=E(yn),xn=m(Oe,x(280),d(u(466)),d(u(466)),d(u(421))),eu=E(xn),En=m(rt,x(465),d(u(466)),d(u(466)),d(u(421))),tu=E(En),Ke=A(wn,yn,m(gr,d(u(421))),m(Ps,d(u(421))),m(we,d(u(421))),xn,En,u(421)),ru=E(Ke),_s=m(d(Ke),x(290),mn(x(281)),d(u(421))),nu=E(_s),Os=A(m(Ke,x(290),x(281),d(u(421))),m(Ke,x(281),d(u(421))),m(x(281),d(u(421)))),ou=E(Os),Bs=m(we,A(m(u(6,"80")),m(u(6),x(480)),x(480)),d(u(481)),d(u(421))),su=E(Bs),Us=m(we,A(m(u(6,"443")),m(u(6,"443"),x(480)),m(u(6),x(443)),m(u(6),x(448),x(480)),m(x(448),x(480)),x(448),x(443)),d(u(481)),d(u(421))),iu=E(Us),Ns=A(m(u(777),d(u(421)))),vn=E(Ns),Ms=A(m(u(400),d(u(421)))),au=E(Ms);var Cn=Symbol.for("sindresorhus/unlimited-timeout#brand");function Sn(r,e,...t){if(typeof r!="function")throw new TypeError("Expected callback to be a function");e??=0,e=Number(e);let n=!1,o={[Cn]:!0,id:void 0,cleared:!1,ref(){return n=!1,o.id?.ref?.(),o},unref(){return n=!0,o.id?.unref?.(),o}};if(e===Number.POSITIVE_INFINITY||e>Number.MAX_SAFE_INTEGER)return o;(!Number.isFinite(e)||e<0)&&(e=0);let s=performance.now()+e,i=a=>{o.cleared||(a<=2147483647?(o.id=globalThis.setTimeout(()=>{o.cleared||r(...t)},a),n&&o.id?.unref?.()):(o.id=globalThis.setTimeout(()=>{let c=performance.now(),h=Math.max(0,s-c);i(h)},2147483647),n&&o.id?.unref?.()))};return i(e),o}function Dn(r){!r||typeof r!="object"||!r[Cn]||(r.cleared=!0,r.id!==void 0&&(globalThis.clearTimeout(r.id),r.id=void 0))}var Rs=new WeakMap;function Vs({clearTimeout:r,setTimeout:e}={}){return(t,{value:n,signal:o}={})=>{if(o?.aborted)return Promise.reject(o.reason);let s,i,a,c=r??clearTimeout,h=()=>{c(s),a(o.reason)},f=()=>{o&&o.removeEventListener("abort",h)},l=new Promise((g,w)=>{i=()=>{f(),g(n)},a=w,s=(e??setTimeout)(i,t)});return o&&o.addEventListener("abort",h,{once:!0}),Rs.set(l,()=>{c(s),s=null,i()}),l}}var Fs=Vs({setTimeout:Sn,clearTimeout:Dn}),nt=Fs;function ot(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var st=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}},ye=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new st(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 st(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 yr=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function Be(r={}){return zs(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 zs(r,e){e=e??{};let t=e.onEnd,n=new ye,o,s,i,a=ot(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((y,p)=>{s=S=>{s=null,n.push(S);try{y(r(n))}catch(L){p(L)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=ot()})}},h=y=>s!=null?s(y):(n.push(y),o),f=y=>(n=new ye,s!=null?s({error:y}):(n.push({error:y}),o)),l=y=>{if(i)return o;if(e?.objectMode!==!0&&y?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return h({done:!1,value:y})},g=y=>i?o:(i=!0,y!=null?f(y):h({done:!0})),w=()=>(n=new ye,g(),{done:!0}),Q=y=>(g(y),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:w,throw:Q,push:l,end:g,get readableLength(){return n.size},onEmpty:async y=>{let p=y?.signal;if(p?.throwIfAborted(),n.isEmpty())return;let S,L;p!=null&&(S=new Promise((_,O)=>{L=()=>{O(new yr)},p.addEventListener("abort",L)}));try{await Promise.race([a.promise,S])}finally{L!=null&&p!=null&&p?.removeEventListener("abort",L)}}},t==null)return o;let N=o;return o={[Symbol.asyncIterator](){return this},next(){return N.next()},throw(y){return N.throw(y),t!=null&&(t(y),t=void 0),{done:!0}},return(){return N.return(),t!=null&&(t(),t=void 0),{done:!0}},push:l,end(y){return N.end(y),t!=null&&(t(y),t=void 0),o},get readableLength(){return N.readableLength},onEmpty:y=>N.onEmpty(y)},o}function $s(r){return r.reason}async function it(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 Tn=Symbol.for("@achingbrain/uint8arraylist");function In(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 at(r){return!!r?.[Tn]}var xe=class r{bufs;length;[Tn]=!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(at(n)){t+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}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(at(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=In(this.bufs,e);return t.buf[t.index]}set(e,t){let n=In(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(at(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 k(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:k(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 h=e>=a&&e<c,f=t>a&&t<=c;if(h&&f){if(e===a&&t===c){n.push(i);break}let l=e-a;n.push(i.subarray(l,l+(t-e)));break}if(h){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(f){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(!at(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 l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,h=n.byteLength-1,f;for(let l=t;l<=c;l+=f){f=0;for(let g=h;g>=0;g--){let w=this.get(l+g);if(n[g]!==w){f=Math.max(1,g-a[w]);break}}if(f===0)return l}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=z(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=F(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=F(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=F(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=z(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=F(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=F(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=F(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=F(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=F(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(!Ce(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}};var xr=class r extends Error{name="TimeoutError";constructor(e,t){super(e,t),Error.captureStackTrace?.(this,r)}},An=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function Er(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=e,a,c,f=new Promise((l,g)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(i?.aborted){g(An(i));return}if(i&&(c=()=>{g(An(i))},i.addEventListener("abort",c,{once:!0})),r.then(l,g),t===Number.POSITIVE_INFINITY)return;let w=new xr;a=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(Q){g(Q)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?l():o instanceof Error?g(o):(w.message=o??`Promise timed out after ${t} milliseconds`,g(w))},t)}).finally(()=>{f.clear(),c&&i&&i.removeEventListener("abort",c)});return f.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},f}var Ws=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 ks(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:h,removeListener:f}=Ws(r),l=async(...w)=>{let Q=t.multiArgs?w:w[0];if(t.filter)try{if(!await t.filter(Q))return}catch(N){n(),i(N);return}c.push(Q),t.count===c.length&&(n(),s(c))},g=(...w)=>{n(),i(t.rejectionMultiArgs?w:w[0])};n=()=>{for(let w of a)f(w,l);for(let w of t.rejectionEvents)a.includes(w)||f(w,g)};for(let w of a)h(w,l);for(let w of t.rejectionEvents)a.includes(w)||h(w,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=Er(o,{milliseconds:t.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function vr(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=ks(r,e,t),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}var ct=class extends Error{static name="StreamClosedError";name="StreamClosedError"};var js=Math.pow(2,20)*4,ut=class extends se{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??js,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new xe,this.writeBuffer=new xe,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,queueMicrotask(()=>{try{this.processSendQueue()}catch(o){this.log.error("processSendQueue threw - %e",o)}})),this.onDrainPromise?.resolve()};this.addEventListener("drain",t);let n=o=>{this.onDrainPromise?.reject(o.error??new ct)};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()),it(this.onDrainPromise.promise,e?.signal))}async*[Symbol.asyncIterator](){if(this.readStatus!=="readable"&&this.readStatus!=="paused")return;let e=Be(),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 X(`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 Re(e))}}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new X("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 X("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 X(`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 X(`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 ne;this.dispatchEvent(new Ve(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 oe))}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;if(this.writeStatus!=="writable"&&this.writeStatus!=="closing")return this.log.trace("not processing send queue as stream is %s",this.writeStatus),!1;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 xe(s);this.writeBuffer.consume(s.byteLength);let a;try{a=this.sendData(s)}catch(c){throw this.writeBuffer.prepend(i),this.abort(c),c}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 Me(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 ve(`Read buffer length of ${this.readBuffer.byteLength} exceeded limit of ${this.maxReadBufferLength}, read status is ${this.readStatus}`))}checkWriteBufferLength(){this.maxWriteBufferLength!=null&&this.writeBuffer.byteLength>this.maxWriteBufferLength&&this.abort(new ve(`Write buffer length of ${this.writeBuffer.byteLength} exceeded limit of ${this.maxWriteBufferLength}, write status is ${this.writeStatus}`))}onMuxerNeedsDrain(){this.writableNeedsDrain=!0}onMuxerDrain(){this.safeDispatchEvent("drain")}};var ft=class extends ut{remoteAddr;metricPrefix;metrics;constructor(e){super(e),this.metricPrefix=e.metricPrefix??"",this.metrics=e.metrics,this.remoteAddr=e.remoteAddr,this.addEventListener("close",t=>{this.metrics?.increment({[`${this.metricPrefix}end`]:!0}),t.error!=null?t.local?this.metrics?.increment({[`${this.metricPrefix}abort`]:!0}):this.metrics?.increment({[`${this.metricPrefix}reset`]:!0}):t.local?this.metrics?.increment({[`${this.metricPrefix}_local_close`]:!0}):this.metrics?.increment({[`${this.metricPrefix}_remote_close`]:!0})})}async close(e){this.status==="open"&&(this.status="closing",this.writeStatus="closing",this.remoteWriteStatus="closing",this.remoteReadStatus="closing",(this.sendingData||this.writeBuffer.byteLength>0)&&(this.log("waiting for write queue to become idle before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await vr(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 vr(this,"drain",{...e,rejectionEvents:["close"]})),await this.sendClose(e),this.onTransportClosed())}};function qs(r){let[e,t]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:o=>{n.push(o)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[t](){return this}}}var Ln=qs;function Hs(r){return r[Symbol.asyncIterator]!=null}function Qs(r,e){let t=0;if(Hs(r))return(async function*(){for await(let c of r)yield e(c,t++)})();let n=Ln(r),{value:o,done:s}=n.next();if(s===!0)return(function*(){})();let i=e(o,t++);if(typeof i.then=="function")return(async function*(){yield await i;for(let c of n)yield e(c,t++)})();let a=e;return(function*(){yield i;for(let c of n)yield a(c,t++)})()}var Pn=Qs;var Cr=class extends ft{localPushable;constructor(e){super(e),this.localPushable=e.localPushable,Promise.resolve().then(async()=>{for await(let t of Pn(e.remotePushable,async n=>(e.connection.latency>0&&await nt(e.connection.latency),n)))this.onData(t);this.onTransportClosed()}).catch(t=>{this.abort(t)})}sendReset(){this.localPushable.end(new ne)}sendData(e){return this.localPushable.push(e),{sentBytes:e.byteLength,canSendMore:!0}}async sendClose(e){this.localPushable.end(),e?.signal?.throwIfAborted()}sendPause(){}sendResume(){}};function Sr(r){return new Cr(r)}var Ee=new Map,Dr=0,lt=class{latency;components;init;connections;log;constructor(e,t){this.components=e,this.init=t,this.connections=new Set,this.latency=t.latency??0,this.log=e.logger.forComponent("libp2p:memory")}async dial(e,t,n){let o=this,s=!1,i=!1,a=Be({onEnd(l){s=!0,o.connections.delete(h),i||c.end(l)}}),c=Be({onEnd(l){i=!0,o.connections.delete(f),s||a.end(l)}}),h=Sr({connection:this,remoteAddr:_e(`${this.init.address}/p2p/${this.components.peerId}`),direction:"outbound",localPushable:a,remotePushable:c,log:t.newScope(`connection:${Dr}`),maxMessageSize:this.init.maxMessageSize??65536}),f=Sr({connection:this,remoteAddr:_e(`${this.init.address}-outgoing/p2p/${e}`),direction:"inbound",localPushable:c,remotePushable:a,log:this.log.newScope(`connection:${Dr}`),maxMessageSize:this.init.maxMessageSize??65536});return this.connections.add(h),this.connections.add(f),Dr++,await it(nt(this.latency),n),this.init.onConnection(f),h}close(){[...this.connections].forEach(e=>{e.abort(new re("Memory Connection closed"))})}};var _n="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";var On=(r=21)=>{let e="",t=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)e+=_n[t[r]&63];return e};var ht=class extends se{listenAddr;connection;components;init;shutdownController;constructor(e,t){super(),this.components=e,this.init=t,this.shutdownController=new AbortController,this.shutdownController.signal}async listen(e){let n=e.getComponents()[0]?.value,o=`/memory/${n??On()}`;if(n!=null&&Ee.has(o))throw new Ne(`Memory address ${o} already in use`);this.connection=new lt(this.components,{...this.init,onConnection:this.onConnection.bind(this),address:o}),this.listenAddr=_e(o),Ee.set(o,this.connection),queueMicrotask(()=>{this.safeDispatchEvent("listening")})}onConnection(e){this.init.upgrader.upgradeInbound(e,{...this.init.upgraderOptions,signal:this.shutdownController.signal}).catch(t=>{e.abort(t)})}getAddrs(){return this.listenAddr==null?[]:[this.listenAddr]}updateAnnounceAddrs(){}async close(){this.connection?.close(),this.listenAddr!=null&&Ee.delete(this.listenAddr.toString()),this.shutdownController.abort(),queueMicrotask(()=>{this.safeDispatchEvent("close")})}};var dt=class{components;init;constructor(e,t={}){this.components=e,this.init=t}[Tr]=!0;[Symbol.toStringTag]="@libp2p/memory";[Ar]=["@libp2p/transport"];async dial(e,t){t.signal.throwIfAborted();let n=e.getComponents().find(i=>i.code===421)?.value,o=Ee.get(`${n==null?e:e.decapsulate("/p2p")}`);if(o==null)throw new re(`No memory listener found at ${e}`);let s=await o.dial(this.components.peerId,this.components.logger.forComponent("libp2p:memory"),t.signal);try{return t.signal.throwIfAborted(),await t.upgrader.upgradeOutbound(s,{...t,...this.init.upgraderOptions})}catch(i){throw s.abort(i),i}}createListener(e){return new ht(this.components,{...e,...this.init})}listenFilter(e){return e.filter(t=>vn.exactMatch(t))}dialFilter(e){return this.listenFilter(e)}};function Xs(r){return e=>new dt(e,r)}return Rn(Js);})();
2
+ "use strict";var Libp2PMemory=(()=>{var pt=Object.defineProperty;var Bn=Object.getOwnPropertyDescriptor;var Un=Object.getOwnPropertyNames;var Nn=Object.prototype.hasOwnProperty;var P=(r,e)=>{for(var t in e)pt(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&&pt(r,o,{get:()=>e[o],enumerable:!(n=Bn(e,o))||n.enumerable});return r};var Mn=r=>Rn(pt({},"__esModule",{value:!0}),r);var Js={};P(Js,{memory:()=>Xs});var re=class extends Error{static name="ConnectionFailedError";constructor(e="Connection failed"){super(e),this.name="ConnectionFailedError"}};var ne=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var X=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},ve=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var Ne=class extends Error{static name="ListenError";constructor(e="Listen error"){super(e),this.name="ListenError"}};var Re=class extends Event{data;constructor(e,t){super("message",t),this.data=e}},oe=class extends Event{error;local;constructor(e,t,n){super("close",n),this.error=t,this.local=e}},Me=class extends oe{constructor(e,t){super(!0,e,t)}},Ve=class extends oe{constructor(e,t){super(!1,e,t)}};var Tr=Symbol.for("@libp2p/transport");var Ir;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(Ir||(Ir={}));function Vn(r){return typeof r?.handleEvent=="function"}function Fn(r){return(r!==!0&&r!==!1&&r?.once)??!1}var se=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){let o=Fn(n);super.addEventListener(e,i=>{if(o){let a=this.#e.get(i.type);a!=null&&(a=a.filter(({callback:c})=>c!==t),this.#e.set(i.type,a))}Vn(t)?t.handleEvent(i):t(i)},n);let s=this.#e.get(e);s==null&&(s=[],this.#e.set(e,s)),s.push({callback:t,once:o})}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))}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};var Ar=Symbol.for("@libp2p/service-capabilities");function Ce(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=0){return new Uint8Array(r)}function z(r=0){return new Uint8Array(r)}var zn=Math.pow(2,7),$n=Math.pow(2,14),Wn=Math.pow(2,21),mt=Math.pow(2,28),bt=Math.pow(2,35),gt=Math.pow(2,42),wt=Math.pow(2,49),v=128,T=127;function ie(r){if(r<zn)return 1;if(r<$n)return 2;if(r<Wn)return 3;if(r<mt)return 4;if(r<bt)return 5;if(r<gt)return 6;if(r<wt)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function yt(r,e,t=0){switch(ie(r)){case 8:e[t++]=r&255|v,r/=128;case 7:e[t++]=r&255|v,r/=128;case 6:e[t++]=r&255|v,r/=128;case 5:e[t++]=r&255|v,r/=128;case 4:e[t++]=r&255|v,r>>>=7;case 3:e[t++]=r&255|v,r>>>=7;case 2:e[t++]=r&255|v,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function kn(r,e){let t=r[e],n=0;if(n+=t&T,t<v||(t=r[e+1],n+=(t&T)<<7,t<v)||(t=r[e+2],n+=(t&T)<<14,t<v)||(t=r[e+3],n+=(t&T)<<21,t<v)||(t=r[e+4],n+=(t&T)*mt,t<v)||(t=r[e+5],n+=(t&T)*bt,t<v)||(t=r[e+6],n+=(t&T)*gt,t<v)||(t=r[e+7],n+=(t&T)*wt,t<v))return n;throw new RangeError("Could not decode varint")}function jn(r,e){let t=r.get(e),n=0;if(n+=t&T,t<v||(t=r.get(e+1),n+=(t&T)<<7,t<v)||(t=r.get(e+2),n+=(t&T)<<14,t<v)||(t=r.get(e+3),n+=(t&T)<<21,t<v)||(t=r.get(e+4),n+=(t&T)*mt,t<v)||(t=r.get(e+5),n+=(t&T)*bt,t<v)||(t=r.get(e+6),n+=(t&T)*gt,t<v)||(t=r.get(e+7),n+=(t&T)*wt,t<v))return n;throw new RangeError("Could not decode varint")}function xt(r,e=0){return r instanceof Uint8Array?kn(r,e):jn(r,e)}function Hn(r){return r.buffer instanceof ArrayBuffer}function Et(r){return Hn(r)?r:r.slice()}function Qn(r){return r?.buffer instanceof ArrayBuffer}function vt(r){if(Qn(r))return r;let e=r.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function k(r,e){e==null&&(e=r.reduce((o,s)=>o+s.length,0));let t=z(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return vt(t)}var Tt={};P(Tt,{base10:()=>to});var zi=new Uint8Array(0);function Pr(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 U(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return Z(r);if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return Z(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));throw new Error("Unknown type, must be binary type")}function _r(r){let e=new Uint8Array(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}var Lr=4096;function Or(r){let e=r.length;if(e<=Lr)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.subarray(n,n+=Lr));return t}function Gn(r){return r?.buffer instanceof ArrayBuffer}function Z(r){return Gn(r)?r:r.slice()}function Xn(r,e,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),o=0;o<n.length;o++)n[o]=255;for(var s=0;s<r.length;s++){var i=r.charAt(s),a=i.charCodeAt(0);if(n[a]!==255)throw new TypeError(i+" is ambiguous");if(n[a]=s,t){var c=i.toLowerCase().charCodeAt(0),h=i.toUpperCase().charCodeAt(0);c!==a&&(n[c]=s),h!==a&&(n[h]=s)}}var f=r.length,l=r.charAt(0),g=Math.log(f)/Math.log(256),w=Math.log(256)/Math.log(f);function Q(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var S=0,L=0,_=0,O=p.length;_!==O&&p[_]===0;)_++,S++;for(var M=(O-_)*w+1>>>0,B=new Uint8Array(M);_!==O;){for(var V=p[_],G=0,R=M-1;(V!==0||G<L)&&R!==-1;R--,G++)V+=256*B[R]>>>0,B[R]=V%f>>>0,V=V/f>>>0;if(V!==0)throw new Error("Non-zero carry");L=G,_++}for(var W=M-L;W!==M&&B[W]===0;)W++;for(var Ue=l.repeat(S);W<M;++W)Ue+=r.charAt(B[W]);return Ue}function N(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var S=0;if(p[S]!==" "){for(var L=0,_=0;p[S]===l;)L++,S++;for(var O=(p.length-S)*g+1>>>0,M=new Uint8Array(O);p[S];){var B=n[p.charCodeAt(S)];if(B===255)return;for(var V=0,G=O-1;(B!==0||V<_)&&G!==-1;G--,V++)B+=f*M[G]>>>0,M[G]=B%256>>>0,B=B/256>>>0;if(B!==0)throw new Error("Non-zero carry");_=V,S++}if(p[S]!==" "){for(var R=O-_;R!==O&&M[R]===0;)R++;for(var W=new Uint8Array(L+(O-R)),Ue=L;R!==O;)W[Ue++]=M[R++];return W}}}function y(p){var S=N(p);if(S)return S;throw new Error(`Non-${e} character`)}return{encode:Q,decodeUnsafe:N,decode:y}}var Jn=Xn,Yn=Jn,Ur=Yn;var Ct=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")}},St=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 Nr(this,e)}},Dt=class{decoders;constructor(e){this.decoders=e}or(e){return Nr(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 Nr(r,e){return new Dt({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var It=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 Ct(e,t,n),this.decoder=new St(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function ae({name:r,prefix:e,encode:t,decode:n}){return new It(r,e,t,n)}function J({name:r,prefix:e,alphabet:t,caseInsensitive:n=!1}){let{encode:o,decode:s}=Ur(t,r,n);return ae({prefix:e,name:r,encode:o,decode:i=>U(s(i))})}function Kn(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 h=0;h<o;++h){let f=e[r[h]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|f,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 eo(r,e){let t={};for(let n=0;n<r.length;++n)if(t[r[n]]=n,e){let o=r[n].toLowerCase(),s=r[n].toUpperCase();o!==r[n]&&(t[o]=n),s!==r[n]&&(t[s]=n)}return t}function C({name:r,prefix:e,bitsPerChar:t,alphabet:n,caseInsensitive:o=!1}){let s=eo(n,o);return ae({prefix:e,name:r,encode(i){return Zn(i,n,t)},decode(i){return Kn(i,s,t,r)}})}var to=J({prefix:"9",name:"base10",alphabet:"0123456789"});var At={};P(At,{base16:()=>ro,base16upper:()=>no});var ro=C({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),no=C({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var Lt={};P(Lt,{base2:()=>oo});var oo=C({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Pt={};P(Pt,{base256emoji:()=>uo});var Rr=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}"),so=Rr.reduce((r,e,t)=>(r[t]=e,r),[]),io=Rr.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function ao(r){return r.reduce((e,t)=>(e+=so[t],e),"")}function co(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=io[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var uo=ae({prefix:"\u{1F680}",name:"base256emoji",encode:ao,decode:co});var _t={};P(_t,{base32:()=>Y,base32hex:()=>po,base32hexpad:()=>bo,base32hexpadupper:()=>go,base32hexupper:()=>mo,base32pad:()=>lo,base32padupper:()=>ho,base32upper:()=>fo,base32z:()=>wo});var Y=C({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),fo=C({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),lo=C({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),ho=C({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),po=C({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),mo=C({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),bo=C({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),go=C({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),wo=C({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ot={};P(Ot,{base36:()=>Se,base36upper:()=>yo});var Se=J({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),yo=J({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Bt={};P(Bt,{base58btc:()=>$,base58flickr:()=>xo});var $=J({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),xo=J({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Nt={};P(Nt,{base64:()=>Eo,base64pad:()=>vo,base64url:()=>Ut,base64urlpad:()=>Co});var Eo=C({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),vo=C({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ut=C({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Co=C({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Rt={};P(Rt,{base8:()=>So});var So=C({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Mt={};P(Mt,{identity:()=>Do});var Do=ae({prefix:"\0",name:"identity",encode:r=>Or(U(r)),decode:r=>U(_r(r))});var ra=new TextEncoder,na=new TextDecoder;var Ft={};P(Ft,{identity:()=>Go});var Ao=Fr,Mr=128,Lo=127,Po=~Lo,_o=Math.pow(2,31);function Fr(r,e,t){e=e||[],t=t||0;for(var n=t;r>=_o;)e[t++]=r&255|Mr,r/=128;for(;r&Po;)e[t++]=r&255|Mr,r>>>=7;return e[t]=r|0,Fr.bytes=t-n+1,e}var Oo=Vt,Bo=128,Vr=127;function Vt(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Vt.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&Vr)<<o:(i&Vr)*Math.pow(2,o),o+=7}while(i>=Bo);return Vt.bytes=s-n,t}var Uo=Math.pow(2,7),No=Math.pow(2,14),Ro=Math.pow(2,21),Mo=Math.pow(2,28),Vo=Math.pow(2,35),Fo=Math.pow(2,42),zo=Math.pow(2,49),$o=Math.pow(2,56),Wo=Math.pow(2,63),ko=function(r){return r<Uo?1:r<No?2:r<Ro?3:r<Mo?4:r<Vo?5:r<Fo?6:r<zo?7:r<$o?8:r<Wo?9:10},jo={encode:Ao,decode:Oo,encodingLength:ko},qo=jo,De=qo;function Ie(r,e=0){let t=De.decode(r,e),n=De.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&r[e+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[t,n]}function ce(r,e,t=0){return De.encode(r,e,t),e}function ue(r){return De.encodingLength(r)}function le(r,e){let t=e.byteLength,n=ue(r),o=n+ue(t),s=new Uint8Array(o+t);return ce(r,s,0),ce(t,s,n),s.set(e,o),new fe(r,t,e,s)}function zr(r){let e=U(r),[t,n]=Ie(e),[o,s]=Ie(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new fe(t,o,i,e)}function $r(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Pr(r.bytes,t.bytes)}}var fe=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=Z(n),this.bytes=Z(o)}};var Wr=0,Ho="identity",kr=U;function Qo(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 le(Wr,kr(r))}var Go={code:Wr,name:Ho,encode:kr,digest:Qo};var Wt={};P(Wt,{sha256:()=>Jo,sha512:()=>Yo});var Xo=20;function $t({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:o}){return new zt(r,e,t,n,o)}var zt=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,o,s){this.name=e,this.code=t,this.encode=n,this.minDigestLength=o??Xo,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?jr(n,this.code,t?.truncate):n.then(o=>jr(o,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function jr(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 le(e,r)}function Hr(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var Jo=$t({name:"sha2-256",code:18,encode:Hr("SHA-256")}),Yo=$t({name:"sha2-512",code:19,encode:Hr("SHA-512")});function Qr(r,e){let{bytes:t,version:n}=r;return n===0?Zo(t,kt(r),e??$.encoder):es(t,kt(r),e??Y.encoder)}var Gr=new WeakMap;function kt(r){let e=Gr.get(r);if(e==null){let t=new Map;return Gr.set(r,t),t}return e}var he=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=Z(o),this["/"]=this.bytes}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!==Ae)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==ts)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=le(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&&$r(e.multihash,n.multihash)}toString(e){return Qr(this,e)}toJSON(){return{"/":Qr(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??Xr(n,o,s.bytes))}else if(t[rs]===!0){let{version:n,multihash:o,code:s}=t,i=zr(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!==Ae)throw new Error(`Version 0 CID must use dag-pb (code: ${Ae}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=Xr(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Ae,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=U(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 fe(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[l,g]=Ie(e.subarray(t));return t+=g,l},o=n(),s=Ae;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(),h=t+c,f=h-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:h}}static parse(e,t){let[n,o]=Ko(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 kt(s).set(n,e),s}};function Ko(r,e){switch(r[0]){case"Q":{let t=e??$;return[$.prefix,t.decode(`${$.prefix}${r}`)]}case $.prefix:{let t=e??$;return[$.prefix,t.decode(r)]}case Y.prefix:{let t=e??Y;return[Y.prefix,t.decode(r)]}case Se.prefix:{let t=e??Se;return[Se.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!==$.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 es(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 Ae=112,ts=18;function Xr(r,e,t){let n=ue(r),o=n+ue(e),s=new Uint8Array(o+t.byteLength);return ce(r,s,0),ce(e,s,n),s.set(t,o),s}var rs=Symbol.for("@ipld/js-cid/CID");var Le={...Mt,...Lt,...Rt,...Tt,...At,..._t,...Ot,...Bt,...Nt,...Pt},Da={...Wt,...Ft};function Yr(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Jr=Yr("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),jt=Yr("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=z(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),ns={utf8:Jr,"utf-8":Jr,hex:Le.base16,latin1:jt,ascii:jt,binary:jt,...Le},ze=ns;function de(r,e="utf8"){let t=ze[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function K(r,e="utf8"){let t=ze[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"},j=class extends Error{static name="ValidationError";name="ValidationError"},$e=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},We=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var ke=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",h=2**(8*o)-1;for(;;){let f=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let g=Number.parseInt(l,e);if(!Number.isNaN(g))return g});if(f===void 0)break;if(s*=e,s+=f,s>h||(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 os=45,ss=15,je=new ke;function Kr(r){if(!(r.length>ss))return je.new(r).parseWith(()=>je.readIPv4Addr())}function Zr(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>os))return je.new(r).parseWith(()=>je.readIPv6Addr())}function qe(r){return!!Kr(r)}function en(r){return!!Zr(r)}function Ht(r){return e=>K(e,r)}function Qt(r){return e=>de(e,r)}function pe(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function ee(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(e)}function tn(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=de(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=ee(n);return k([t,o],t.length+o.length)}function rn(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=Y.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=ee(n);return k([t,o],t.length+o.length)}function Gt(r){let e=r.subarray(0,r.length-2),t=r.subarray(r.length-2),n=K(e,"base32"),o=pe(t);return`${n}:${o}`}var Xt=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},nn=function(r){let e=0;r=r.toString().trim();let t=r.split(":",8),n;for(n=0;n<t.length;n++){let s=qe(t[n]),i;s&&(i=Xt(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 I("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},on=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(".")},sn=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 an(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 qt=Object.values(Le).map(r=>r.decoder),is=(function(){let r=qt[0].or(qt[1]);return qt.slice(2).forEach(e=>r=r.or(e)),r})();function cn(r){return is.decode(r)}function un(r){return e=>r.encoder.encode(e)}function as(r){if(parseInt(r).toString()!==r)throw new j("Value must be an integer")}function cs(r){if(r<0)throw new j("Value must be a positive integer, or zero")}function us(r){return e=>{if(e>r)throw new j(`Value must be smaller than or equal to ${r}`)}}function fs(...r){return e=>{for(let t of r)t(e)}}var Pe=fs(as,cs,us(65535));var D=-1,Jt=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 We(`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)}))}},H=new Jt,Ss=[{code:4,name:"ip4",size:32,valueToBytes:Xt,bytesToValue:on,validate:r=>{if(!qe(r))throw new j(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:ee,bytesToValue:pe,validate:Pe},{code:273,name:"udp",size:16,valueToBytes:ee,bytesToValue:pe,validate:Pe},{code:33,name:"dccp",size:16,valueToBytes:ee,bytesToValue:pe,validate:Pe},{code:41,name:"ip6",size:128,valueToBytes:nn,bytesToValue:sn,stringToValue:an,validate:r=>{if(!en(r))throw new j(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:D},{code:43,name:"ipcidr",size:8,bytesToValue:Ht("base10"),valueToBytes:Qt("base10")},{code:53,name:"dns",size:D},{code:54,name:"dns4",size:D},{code:55,name:"dns6",size:D},{code:56,name:"dnsaddr",size:D},{code:132,name:"sctp",size:16,valueToBytes:ee,bytesToValue:pe,validate:Pe},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:D,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:D,bytesToValue:Ht("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?Qt("base58btc")(r):he.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Gt,valueToBytes:tn},{code:445,name:"onion3",size:296,bytesToValue:Gt,valueToBytes:rn},{code:446,name:"garlic64",size:D},{code:447,name:"garlic32",size:D},{code:448,name:"tls"},{code:449,name:"sni",size:D},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:D,bytesToValue:un(Ut),valueToBytes:cn},{code:480,name:"http"},{code:481,name:"http-path",size:D,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:D}];Ss.forEach(r=>{H.addProtocol(r)});function fn(r){let e=[],t=0;for(;t<r.length;){let n=xt(r,t),o=H.getProtocol(n),s=ie(n),i=Ds(o,r,t+s),a=0;i>0&&o.size===D&&(a=ie(i));let c=s+a+i,h={code:n,name:o.name,bytes:Et(r.subarray(t,t+c))};if(i>0){let f=t+s+a,l=r.subarray(f,f+i);h.value=o.bytesToValue?.(l)??K(l)}e.push(h),t+=c}return e}function ln(r){let e=0,t=[];for(let n of r){if(n.bytes==null){let o=H.getProtocol(n.code),s=ie(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??de(n.value),a=i.byteLength,o.size===D&&(c=ie(a)));let h=new Uint8Array(s+c+a),f=0;yt(n.code,h,f),f+=s,i!=null&&(o.size===D&&(yt(a,h,f),f+=c),h.set(i,f)),n.bytes=h}t.push(n.bytes),e+=n.bytes.byteLength}return k(t,e)}function hn(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=H.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 h={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new I(`Component ${o} was missing value`);h.value=c.stringToValue?.(n)??n}e.push(h),n="",o="",t="protocol"}}}if(o!==""&&n!=="")throw new I("Incomplete multiaddr");return e}function dn(r){return`/${r.flatMap(e=>{if(e.value==null)return e.name;let t=H.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 Ds(r,e,t){return r.size==null||r.size===0?0:r.size>0?r.size/8:xt(e,t)}var Is=Symbol.for("nodejs.util.inspect.custom"),dr=Symbol.for("@multiformats/multiaddr");function Ts(r){if(r==null&&(r="/"),pn(r))return r.getComponents();if(r instanceof Uint8Array)return fn(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),hn(r);if(Array.isArray(r))return r;throw new I("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Ye=class r{[dr]=!0;#e;#t;#r;constructor(e="/",t={}){this.#e=Ts(e),t.validate!==!1&&As(this)}get bytes(){return this.#r==null&&(this.#r=ln(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=dn(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 Ce(this.bytes,e.bytes)}[Is](){return`Multiaddr(${this.toString()})`}};function As(r){r.getComponents().forEach(e=>{let t=H.getProtocol(e.code);e.value!=null&&t.validate?.(e.value)})}function pn(r){return!!r?.[dr]}function _e(r){return new Ye(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)}}),mn=r=>({match:e=>r.match(e)===!1?e:!1}),d=r=>({match:e=>{let t=r.match(e);return t===!1?e:t}}),A=(...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}}),m=(...r)=>({match:e=>{for(let t of r){let n=t.match(e);if(n===!1)return!1;e=n}return e}});function E(...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 Ls=u(421),Fc=E(Ls),Ze=u(54),et=u(55),tt=u(56),mr=u(53),zc=E(Ze,d(u(421))),$c=E(et,d(u(421))),Wc=E(tt,d(u(421))),kc=E(A(mr,tt,Ze,et),d(u(421))),bn=m(u(4),d(u(43))),gn=m(d(u(42)),u(41),d(u(43))),br=A(bn,gn),we=A(br,mr,Ze,et,tt),jc=E(A(br,m(A(mr,tt,Ze,et),d(u(421))))),qc=E(bn),Hc=E(gn),Qc=E(br),gr=m(we,u(6)),Oe=m(we,u(273)),Gc=E(m(gr,d(u(421)))),Xc=E(Oe),wr=m(Oe,x(460),d(u(421))),rt=m(Oe,x(461),d(u(421))),Ps=A(wr,rt),Jc=E(wr),Yc=E(rt),pr=A(we,gr,Oe,wr,rt),wn=A(m(pr,x(477),d(u(421)))),Kc=E(wn),yn=A(m(pr,x(478),d(u(421))),m(pr,x(448),d(u(449)),x(477),d(u(421)))),Zc=E(yn),xn=m(Oe,x(280),d(u(466)),d(u(466)),d(u(421))),eu=E(xn),En=m(rt,x(465),d(u(466)),d(u(466)),d(u(421))),tu=E(En),Ke=A(wn,yn,m(gr,d(u(421))),m(Ps,d(u(421))),m(we,d(u(421))),xn,En,u(421)),ru=E(Ke),_s=m(d(Ke),x(290),mn(x(281)),d(u(421))),nu=E(_s),Os=A(m(Ke,x(290),x(281),d(u(421))),m(Ke,x(281),d(u(421))),m(x(281),d(u(421)))),ou=E(Os),Bs=m(we,A(m(u(6,"80")),m(u(6),x(480)),x(480)),d(u(481)),d(u(421))),su=E(Bs),Us=m(we,A(m(u(6,"443")),m(u(6,"443"),x(480)),m(u(6),x(443)),m(u(6),x(448),x(480)),m(x(448),x(480)),x(448),x(443)),d(u(481)),d(u(421))),iu=E(Us),Ns=A(m(u(777),d(u(421)))),vn=E(Ns),Rs=A(m(u(400),d(u(421)))),au=E(Rs);var Cn=Symbol.for("sindresorhus/unlimited-timeout#brand");function Sn(r,e,...t){if(typeof r!="function")throw new TypeError("Expected callback to be a function");e??=0,e=Number(e);let n=!1,o={[Cn]:!0,id:void 0,cleared:!1,ref(){return n=!1,o.id?.ref?.(),o},unref(){return n=!0,o.id?.unref?.(),o}};if(e===Number.POSITIVE_INFINITY||e>Number.MAX_SAFE_INTEGER)return o;(!Number.isFinite(e)||e<0)&&(e=0);let s=performance.now()+e,i=a=>{o.cleared||(a<=2147483647?(o.id=globalThis.setTimeout(()=>{o.cleared||r(...t)},a),n&&o.id?.unref?.()):(o.id=globalThis.setTimeout(()=>{let c=performance.now(),h=Math.max(0,s-c);i(h)},2147483647),n&&o.id?.unref?.()))};return i(e),o}function Dn(r){!r||typeof r!="object"||!r[Cn]||(r.cleared=!0,r.id!==void 0&&(globalThis.clearTimeout(r.id),r.id=void 0))}var Ms=new WeakMap;function Vs({clearTimeout:r,setTimeout:e}={}){return(t,{value:n,signal:o}={})=>{if(o?.aborted)return Promise.reject(o.reason);let s,i,a,c=r??clearTimeout,h=()=>{c(s),a(o.reason)},f=()=>{o&&o.removeEventListener("abort",h)},l=new Promise((g,w)=>{i=()=>{f(),g(n)},a=w,s=(e??setTimeout)(i,t)});return o&&o.addEventListener("abort",h,{once:!0}),Ms.set(l,()=>{c(s),s=null,i()}),l}}var Fs=Vs({setTimeout:Sn,clearTimeout:Dn}),nt=Fs;function ot(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var st=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}},ye=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new st(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 st(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 yr=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function Be(r={}){return zs(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 zs(r,e){e=e??{};let t=e.onEnd,n=new ye,o,s,i,a=ot(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((y,p)=>{s=S=>{s=null,n.push(S);try{y(r(n))}catch(L){p(L)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=ot()})}},h=y=>s!=null?s(y):(n.push(y),o),f=y=>(n=new ye,s!=null?s({error:y}):(n.push({error:y}),o)),l=y=>{if(i)return o;if(e?.objectMode!==!0&&y?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return h({done:!1,value:y})},g=y=>i?o:(i=!0,y!=null?f(y):h({done:!0})),w=()=>(n=new ye,g(),{done:!0}),Q=y=>(g(y),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:w,throw:Q,push:l,end:g,get readableLength(){return n.size},onEmpty:async y=>{let p=y?.signal;if(p?.throwIfAborted(),n.isEmpty())return;let S,L;p!=null&&(S=new Promise((_,O)=>{L=()=>{O(new yr)},p.addEventListener("abort",L)}));try{await Promise.race([a.promise,S])}finally{L!=null&&p!=null&&p?.removeEventListener("abort",L)}}},t==null)return o;let N=o;return o={[Symbol.asyncIterator](){return this},next(){return N.next()},throw(y){return N.throw(y),t!=null&&(t(y),t=void 0),{done:!0}},return(){return N.return(),t!=null&&(t(),t=void 0),{done:!0}},push:l,end(y){return N.end(y),t!=null&&(t(y),t=void 0),o},get readableLength(){return N.readableLength},onEmpty:y=>N.onEmpty(y)},o}function $s(r){return r.reason}async function it(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 Tn=Symbol.for("@achingbrain/uint8arraylist");function In(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 at(r){return!!r?.[Tn]}var xe=class r{bufs;length;[Tn]=!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(at(n)){t+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}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(at(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=In(this.bufs,e);return t.buf[t.index]}set(e,t){let n=In(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(at(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 k(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:k(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 h=e>=a&&e<c,f=t>a&&t<=c;if(h&&f){if(e===a&&t===c){n.push(i);break}let l=e-a;n.push(i.subarray(l,l+(t-e)));break}if(h){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(f){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(!at(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 l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,h=n.byteLength-1,f;for(let l=t;l<=c;l+=f){f=0;for(let g=h;g>=0;g--){let w=this.get(l+g);if(n[g]!==w){f=Math.max(1,g-a[w]);break}}if(f===0)return l}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=z(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=F(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=F(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=F(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=z(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=F(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=F(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=F(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=F(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=F(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(!Ce(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}};var xr=class r extends Error{name="TimeoutError";constructor(e,t){super(e,t),Error.captureStackTrace?.(this,r)}},An=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function Er(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=e,a,c,f=new Promise((l,g)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(i?.aborted){g(An(i));return}if(i&&(c=()=>{g(An(i))},i.addEventListener("abort",c,{once:!0})),r.then(l,g),t===Number.POSITIVE_INFINITY)return;let w=new xr;a=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(Q){g(Q)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?l():o instanceof Error?g(o):(w.message=o??`Promise timed out after ${t} milliseconds`,g(w))},t)}).finally(()=>{f.clear(),c&&i&&i.removeEventListener("abort",c)});return f.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},f}var Ws=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 ks(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:h,removeListener:f}=Ws(r),l=async(...w)=>{let Q=t.multiArgs?w:w[0];if(t.filter)try{if(!await t.filter(Q))return}catch(N){n(),i(N);return}c.push(Q),t.count===c.length&&(n(),s(c))},g=(...w)=>{n(),i(t.rejectionMultiArgs?w:w[0])};n=()=>{for(let w of a)f(w,l);for(let w of t.rejectionEvents)a.includes(w)||f(w,g)};for(let w of a)h(w,l);for(let w of t.rejectionEvents)a.includes(w)||h(w,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=Er(o,{milliseconds:t.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function vr(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=ks(r,e,t),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}var ct=class extends Error{static name="StreamClosedError";name="StreamClosedError"};var js=Math.pow(2,20)*4,ut=class extends se{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??js,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new xe,this.writeBuffer=new xe,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,queueMicrotask(()=>{try{this.processSendQueue()}catch(o){this.log.error("processSendQueue threw - %e",o)}})),this.onDrainPromise?.resolve()};this.addEventListener("drain",t);let n=o=>{this.onDrainPromise?.reject(o.error??new ct)};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()),it(this.onDrainPromise.promise,e?.signal))}async*[Symbol.asyncIterator](){if(this.readStatus!=="readable"&&this.readStatus!=="paused")return;let e=Be(),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 X(`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 Me(e))}}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new X("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 X("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 X(`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 X(`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 ne;this.dispatchEvent(new Ve(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 oe))}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;if(this.writeStatus!=="writable"&&this.writeStatus!=="closing")return this.log.trace("not processing send queue as stream is %s",this.writeStatus),!1;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 xe(s);this.writeBuffer.consume(s.byteLength);let a;try{a=this.sendData(s)}catch(c){throw this.writeBuffer.prepend(i),this.abort(c),c}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 Re(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 ve(`Read buffer length of ${this.readBuffer.byteLength} exceeded limit of ${this.maxReadBufferLength}, read status is ${this.readStatus}`))}checkWriteBufferLength(){this.maxWriteBufferLength!=null&&this.writeBuffer.byteLength>this.maxWriteBufferLength&&this.abort(new ve(`Write buffer length of ${this.writeBuffer.byteLength} exceeded limit of ${this.maxWriteBufferLength}, write status is ${this.writeStatus}`))}onMuxerNeedsDrain(){this.writableNeedsDrain=!0}onMuxerDrain(){this.safeDispatchEvent("drain")}};var ft=class extends ut{remoteAddr;metricPrefix;metrics;constructor(e){super(e),this.metricPrefix=e.metricPrefix??"",this.metrics=e.metrics,this.remoteAddr=e.remoteAddr,this.addEventListener("close",t=>{this.metrics?.increment({[`${this.metricPrefix}end`]:!0}),t.error!=null?t.local?this.metrics?.increment({[`${this.metricPrefix}abort`]:!0}):this.metrics?.increment({[`${this.metricPrefix}reset`]:!0}):t.local?this.metrics?.increment({[`${this.metricPrefix}_local_close`]:!0}):this.metrics?.increment({[`${this.metricPrefix}_remote_close`]:!0})})}async close(e){this.status==="open"&&(this.status="closing",this.writeStatus="closing",this.remoteWriteStatus="closing",this.remoteReadStatus="closing",(this.sendingData||this.writeBuffer.byteLength>0)&&(this.log("waiting for write queue to become idle before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await vr(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 vr(this,"drain",{...e,rejectionEvents:["close"]})),await this.sendClose(e),this.onTransportClosed())}};function qs(r){let[e,t]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:o=>{n.push(o)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[t](){return this}}}var Ln=qs;function Hs(r){return r[Symbol.asyncIterator]!=null}function Qs(r,e){let t=0;if(Hs(r))return(async function*(){for await(let c of r)yield e(c,t++)})();let n=Ln(r),{value:o,done:s}=n.next();if(s===!0)return(function*(){})();let i=e(o,t++);if(typeof i.then=="function")return(async function*(){yield await i;for(let c of n)yield e(c,t++)})();let a=e;return(function*(){yield i;for(let c of n)yield a(c,t++)})()}var Pn=Qs;var Cr=class extends ft{localPushable;constructor(e){super(e),this.localPushable=e.localPushable,Promise.resolve().then(async()=>{for await(let t of Pn(e.remotePushable,async n=>(e.connection.latency>0&&await nt(e.connection.latency),n)))this.onData(t);this.onTransportClosed()}).catch(t=>{this.abort(t)})}sendReset(){this.localPushable.end(new ne)}sendData(e){return this.localPushable.push(e),{sentBytes:e.byteLength,canSendMore:!0}}async sendClose(e){this.localPushable.end(),e?.signal?.throwIfAborted()}sendPause(){}sendResume(){}};function Sr(r){return new Cr(r)}var Ee=new Map,Dr=0,lt=class{latency;components;init;connections;log;constructor(e,t){this.components=e,this.init=t,this.connections=new Set,this.latency=t.latency??0,this.log=e.logger.forComponent("libp2p:memory")}async dial(e,t,n){let o=this,s=!1,i=!1,a=Be({onEnd(l){s=!0,o.connections.delete(h),i||c.end(l)}}),c=Be({onEnd(l){i=!0,o.connections.delete(f),s||a.end(l)}}),h=Sr({connection:this,remoteAddr:_e(`${this.init.address}/p2p/${this.components.peerId}`),direction:"outbound",localPushable:a,remotePushable:c,log:t.newScope(`connection:${Dr}`),maxMessageSize:this.init.maxMessageSize??65536}),f=Sr({connection:this,remoteAddr:_e(`${this.init.address}-outgoing/p2p/${e}`),direction:"inbound",localPushable:c,remotePushable:a,log:this.log.newScope(`connection:${Dr}`),maxMessageSize:this.init.maxMessageSize??65536});return this.connections.add(h),this.connections.add(f),Dr++,await it(nt(this.latency),n),this.init.onConnection(f),h}close(){[...this.connections].forEach(e=>{e.abort(new re("Memory Connection closed"))})}};var _n="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";var On=(r=21)=>{let e="",t=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)e+=_n[t[r]&63];return e};var ht=class extends se{listenAddr;connection;components;init;shutdownController;constructor(e,t){super(),this.components=e,this.init=t,this.shutdownController=new AbortController,this.shutdownController.signal}async listen(e){let n=e.getComponents()[0]?.value,o=`/memory/${n??On()}`;if(n!=null&&Ee.has(o))throw new Ne(`Memory address ${o} already in use`);this.connection=new lt(this.components,{...this.init,onConnection:this.onConnection.bind(this),address:o}),this.listenAddr=_e(o),Ee.set(o,this.connection),queueMicrotask(()=>{this.safeDispatchEvent("listening")})}onConnection(e){this.init.upgrader.upgradeInbound(e,{...this.init.upgraderOptions,signal:this.shutdownController.signal}).catch(t=>{e.abort(t)})}getAddrs(){return this.listenAddr==null?[]:[this.listenAddr]}updateAnnounceAddrs(){}async close(){this.connection?.close(),this.listenAddr!=null&&Ee.delete(this.listenAddr.toString()),this.shutdownController.abort(),queueMicrotask(()=>{this.safeDispatchEvent("close")})}};var dt=class{components;init;constructor(e,t={}){this.components=e,this.init=t}[Tr]=!0;[Symbol.toStringTag]="@libp2p/memory";[Ar]=["@libp2p/transport"];async dial(e,t){t.signal.throwIfAborted();let n=e.getComponents().find(i=>i.code===421)?.value,o=Ee.get(`${n==null?e:e.decapsulate("/p2p")}`);if(o==null)throw new re(`No memory listener found at ${e}`);let s=await o.dial(this.components.peerId,this.components.logger.forComponent("libp2p:memory"),t.signal);try{return t.signal.throwIfAborted(),await t.upgrader.upgradeOutbound(s,{...t,...this.init.upgraderOptions})}catch(i){throw s.abort(i),i}}createListener(e){return new ht(this.components,{...e,...this.init})}listenFilter(e){return e.filter(t=>vn.exactMatch(t))}dialFilter(e){return this.listenFilter(e)}};function Xs(r){return e=>new dt(e,r)}return Mn(Js);})();
3
3
  return Libp2PMemory}));
4
4
  //# sourceMappingURL=index.min.js.map