@libp2p/memory 1.1.14-a02cb0461 → 1.1.14-da78fa851

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 mt=Object.defineProperty;var Pn=Object.getOwnPropertyDescriptor;var Ln=Object.getOwnPropertyNames;var An=Object.prototype.hasOwnProperty;var B=(r,e)=>{for(var t in e)mt(r,t,{get:e[t],enumerable:!0})},On=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Ln(e))!An.call(r,o)&&o!==t&&mt(r,o,{get:()=>e[o],enumerable:!(n=Pn(e,o))||n.enumerable});return r};var _n=r=>On(mt({},"__esModule",{value:!0}),r);var Hs={};B(Hs,{memory:()=>js});var ne=class extends Error{static name="ConnectionFailedError";constructor(e="Connection failed"){super(e),this.name="ConnectionFailedError"}};var oe=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var Y=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},Ce=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var Fe=class extends Error{static name="ListenError";constructor(e="Listen error"){super(e),this.name="ListenError"}};var Ve=class extends Event{data;constructor(e,t){super("message",t),this.data=e}},se=class extends Event{error;local;constructor(e,t,n){super("close",n),this.error=t,this.local=e}},$e=class extends se{constructor(e,t){super(!0,e,t)}},We=class extends se{constructor(e,t){super(!1,e,t)}};var vr=Symbol.for("@libp2p/transport");var Er;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(Er||(Er={}));var ie=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:s})=>s!==t),this.#e.set(e,o))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};var Cr=Symbol.for("@libp2p/service-capabilities"),Ys=Symbol.for("@libp2p/service-dependencies");var yt={};B(yt,{base10:()=>kn});var Di=new Uint8Array(0);function Sr(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function V(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function Dr(r){return new TextEncoder().encode(r)}function Ir(r){return new TextDecoder().decode(r)}function Bn(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(t[i]!==255)throw new TypeError(s+" is ambiguous");t[i]=o}var a=r.length,c=r.charAt(0),l=Math.log(a)/Math.log(256),h=Math.log(256)/Math.log(a);function f(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var S=0,d=0,D=0,O=g.length;D!==O&&g[D]===0;)D++,S++;for(var T=(O-D)*h+1>>>0,_=new Uint8Array(T);D!==O;){for(var U=g[D],q=0,z=T-1;(U!==0||q<d)&&z!==-1;z--,q++)U+=256*_[z]>>>0,_[z]=U%a>>>0,U=U/a>>>0;if(U!==0)throw new Error("Non-zero carry");d=q,D++}for(var F=T-d;F!==T&&_[F]===0;)F++;for(var ke=c.repeat(S);F<T;++F)ke+=r.charAt(_[F]);return ke}function x(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var S=0;if(g[S]!==" "){for(var d=0,D=0;g[S]===c;)d++,S++;for(var O=(g.length-S)*l+1>>>0,T=new Uint8Array(O);g[S];){var _=t[g.charCodeAt(S)];if(_===255)return;for(var U=0,q=O-1;(_!==0||U<D)&&q!==-1;q--,U++)_+=a*T[q]>>>0,T[q]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");D=U,S++}if(g[S]!==" "){for(var z=O-D;z!==O&&T[z]===0;)z++;for(var F=new Uint8Array(d+(O-z)),ke=d;z!==O;)F[ke++]=T[z++];return F}}}function b(g){var S=x(g);if(S)return S;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:x,decode:b}}var Nn=Bn,Un=Nn,Pr=Un;var bt=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")}},gt=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 Lr(this,e)}},wt=class{decoders;constructor(e){this.decoders=e}or(e){return Lr(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 Lr(r,e){return new wt({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var xt=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 bt(e,t,n),this.decoder=new gt(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 xt(r,e,t,n)}function j({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=Pr(t,r);return ae({prefix:e,name:r,encode:n,decode:s=>V(o(s))})}function Rn(r,e,t,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*t/8|0),i=0,a=0,c=0;for(let l=0;l<o;++l){let h=e[r[l]];if(h===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|h,i+=t,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=t||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Mn(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 zn(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function C({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let o=zn(n);return ae({prefix:e,name:r,encode(s){return Mn(s,n,t)},decode(s){return Rn(s,o,t,r)}})}var kn=j({prefix:"9",name:"base10",alphabet:"0123456789"});var Et={};B(Et,{base16:()=>Fn,base16upper:()=>Vn});var Fn=C({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Vn=C({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var vt={};B(vt,{base2:()=>$n});var $n=C({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ct={};B(Ct,{base256emoji:()=>Qn});var Ar=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}"),Wn=Ar.reduce((r,e,t)=>(r[t]=e,r),[]),qn=Ar.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function jn(r){return r.reduce((e,t)=>(e+=Wn[t],e),"")}function Hn(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=qn[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var Qn=ae({prefix:"\u{1F680}",name:"base256emoji",encode:jn,decode:Hn});var St={};B(St,{base32:()=>H,base32hex:()=>Kn,base32hexpad:()=>Zn,base32hexpadupper:()=>eo,base32hexupper:()=>Yn,base32pad:()=>Xn,base32padupper:()=>Jn,base32upper:()=>Gn,base32z:()=>to});var H=C({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Gn=C({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Xn=C({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Jn=C({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Kn=C({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Yn=C({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Zn=C({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),eo=C({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),to=C({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Dt={};B(Dt,{base36:()=>Se,base36upper:()=>ro});var Se=j({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),ro=j({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var It={};B(It,{base58btc:()=>R,base58flickr:()=>no});var R=j({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),no=j({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Pt={};B(Pt,{base64:()=>oo,base64pad:()=>so,base64url:()=>Tt,base64urlpad:()=>io});var oo=C({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),so=C({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Tt=C({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),io=C({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Lt={};B(Lt,{base8:()=>ao});var ao=C({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var At={};B(At,{identity:()=>co});var co=ae({prefix:"\0",name:"identity",encode:r=>Ir(r),decode:r=>Dr(r)});var Vi=new TextEncoder,$i=new TextDecoder;var _t={};B(_t,{identity:()=>_o});var fo=Br,Or=128,ho=127,po=~ho,mo=Math.pow(2,31);function Br(r,e,t){e=e||[],t=t||0;for(var n=t;r>=mo;)e[t++]=r&255|Or,r/=128;for(;r&po;)e[t++]=r&255|Or,r>>>=7;return e[t]=r|0,Br.bytes=t-n+1,e}var bo=Ot,go=128,_r=127;function Ot(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Ot.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&_r)<<o:(i&_r)*Math.pow(2,o),o+=7}while(i>=go);return Ot.bytes=s-n,t}var wo=Math.pow(2,7),xo=Math.pow(2,14),yo=Math.pow(2,21),Eo=Math.pow(2,28),vo=Math.pow(2,35),Co=Math.pow(2,42),So=Math.pow(2,49),Do=Math.pow(2,56),Io=Math.pow(2,63),To=function(r){return r<wo?1:r<xo?2:r<yo?3:r<Eo?4:r<vo?5:r<Co?6:r<So?7:r<Do?8:r<Io?9:10},Po={encode:fo,decode:bo,encodingLength:To},Lo=Po,De=Lo;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 fe(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 le(r,t,e,s)}function Nr(r){let e=V(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 le(t,o,i,e)}function Ur(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Sr(r.bytes,t.bytes)}}var le=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};var Rr=0,Ao="identity",Mr=V;function Oo(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 fe(Rr,Mr(r))}var _o={code:Rr,name:Ao,encode:Mr,digest:Oo};var Ut={};B(Ut,{sha256:()=>No,sha512:()=>Uo});var Bo=20;function Nt({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:o}){return new Bt(r,e,t,n,o)}var Bt=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,o,s){this.name=e,this.code=t,this.encode=n,this.minDigestLength=o??Bo,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?zr(n,this.code,t?.truncate):n.then(o=>zr(o,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function zr(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 fe(e,r)}function Fr(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var No=Nt({name:"sha2-256",code:18,encode:Fr("SHA-256")}),Uo=Nt({name:"sha2-512",code:19,encode:Fr("SHA-512")});function Vr(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return Mo(t,Rt(r),e??R.encoder);default:return zo(t,Rt(r),e??H.encoder)}}var $r=new WeakMap;function Rt(r){let e=$r.get(r);if(e==null){let t=new Map;return $r.set(r,t),t}return e}var Q=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==Pe)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==ko)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=fe(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&&Ur(e.multihash,n.multihash)}toString(e){return Vr(this,e)}toJSON(){return{"/":Vr(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??Wr(n,o,s.bytes))}else if(t[Fo]===!0){let{version:n,multihash:o,code:s}=t,i=Nr(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!==Pe)throw new Error(`Version 0 CID must use dag-pb (code: ${Pe}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=Wr(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Pe,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=V(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 le(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[f,x]=Ie(e.subarray(t));return t+=x,f},o=n(),s=Pe;if(o===18?(o=0,t=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=t,a=n(),c=n(),l=t+c,h=l-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:h,size:l}}static parse(e,t){let[n,o]=Ro(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 Rt(s).set(n,e),s}};function Ro(r,e){switch(r[0]){case"Q":{let t=e??R;return[R.prefix,t.decode(`${R.prefix}${r}`)]}case R.prefix:{let t=e??R;return[R.prefix,t.decode(r)]}case H.prefix:{let t=e??H;return[H.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 Mo(r,e,t){let{prefix:n}=t;if(n!==R.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let s=t.encode(r).slice(1);return e.set(n,s),s}else return o}function zo(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 Pe=112,ko=18;function Wr(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 Fo=Symbol.for("@ipld/js-cid/CID");var Le={...At,...vt,...Lt,...yt,...Et,...St,...Dt,...It,...Pt,...Ct},la={...Ut,..._t};function $(r=0){return new Uint8Array(r)}function G(r=0){return new Uint8Array(r)}function jr(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var qr=jr("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Mt=jr("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=G(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Vo={utf8:qr,"utf-8":qr,hex:Le.base16,latin1:Mt,ascii:Mt,binary:Mt,...Le},je=Vo;function M(r,e="utf8"){let t=je[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var P=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},W=class extends Error{static name="ValidationError";name="ValidationError"},Ae=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},He=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function Qe(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 X(r,e="utf8"){let t=je[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}var $o=Math.pow(2,7),Wo=Math.pow(2,14),qo=Math.pow(2,21),zt=Math.pow(2,28),kt=Math.pow(2,35),Ft=Math.pow(2,42),Vt=Math.pow(2,49),v=128,L=127;function he(r){if(r<$o)return 1;if(r<Wo)return 2;if(r<qo)return 3;if(r<zt)return 4;if(r<kt)return 5;if(r<Ft)return 6;if(r<Vt)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function $t(r,e,t=0){switch(he(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 jo(r,e){let t=r[e],n=0;if(n+=t&L,t<v||(t=r[e+1],n+=(t&L)<<7,t<v)||(t=r[e+2],n+=(t&L)<<14,t<v)||(t=r[e+3],n+=(t&L)<<21,t<v)||(t=r[e+4],n+=(t&L)*zt,t<v)||(t=r[e+5],n+=(t&L)*kt,t<v)||(t=r[e+6],n+=(t&L)*Ft,t<v)||(t=r[e+7],n+=(t&L)*Vt,t<v))return n;throw new RangeError("Could not decode varint")}function Ho(r,e){let t=r.get(e),n=0;if(n+=t&L,t<v||(t=r.get(e+1),n+=(t&L)<<7,t<v)||(t=r.get(e+2),n+=(t&L)<<14,t<v)||(t=r.get(e+3),n+=(t&L)<<21,t<v)||(t=r.get(e+4),n+=(t&L)*zt,t<v)||(t=r.get(e+5),n+=(t&L)*kt,t<v)||(t=r.get(e+6),n+=(t&L)*Ft,t<v)||(t=r.get(e+7),n+=(t&L)*Vt,t<v))return n;throw new RangeError("Could not decode varint")}function Wt(r,e=0){return r instanceof Uint8Array?jo(r,e):Ho(r,e)}function J(r,e){e==null&&(e=r.reduce((o,s)=>o+s.length,0));let t=G(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var Ge=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",l=2**(8*o)-1;for(;;){let h=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let x=Number.parseInt(f,e);if(!Number.isNaN(x))return x});if(h===void 0)break;if(s*=e,s+=h,s>l||(i+=1,t!==void 0&&i>t))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let o=n*2;if(n<t.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return t[o]=i[0],t[o+1]=i[1],t[o+2]=i[2],t[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];t[o]=s>>8,t[o+1]=s&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,o]=e(t);if(n===16)return t;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=e(s.subarray(0,i));return t.set(s.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Go=45,Xo=15,Xe=new Ge;function qt(r){if(!(r.length>Xo))return Xe.new(r).parseWith(()=>Xe.readIPv4Addr())}function jt(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Go))return Xe.new(r).parseWith(()=>Xe.readIPv6Addr())}function Je(r){return!!qt(r)}function Qr(r){return!!jt(r)}function Qt(r){return e=>M(e,r)}function Gt(r){return e=>X(e,r)}function de(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function Z(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(e)}function Gr(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=X(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Z(n);return J([t,o],t.length+o.length)}function Xr(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=H.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Z(n);return J([t,o],t.length+o.length)}function Xt(r){let e=r.subarray(0,r.length-2),t=r.subarray(r.length-2),n=M(e,"base32"),o=de(t);return`${n}:${o}`}var Jt=function(r){r=r.toString().trim();let e=new Uint8Array(4);return r.split(/\./g).forEach((t,n)=>{let o=parseInt(t,10);if(isNaN(o)||o<0||o>255)throw new P("Invalid byte value in IP address");e[n]=o}),e},Jr=function(r){let e=0;r=r.toString().trim();let t=r.split(":",8),n;for(n=0;n<t.length;n++){let s=Je(t[n]),i;s&&(i=Jt(t[n]),t[n]=M(i.subarray(0,2),"base16")),i!=null&&++n<8&&t.splice(n,0,M(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 P("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},Kr=function(r){if(r.byteLength!==4)throw new P("IPv4 address was incorrect length");let e=[];for(let t=0;t<r.byteLength;t++)e.push(r[t]);return e.join(".")},Yr=function(r){if(r.byteLength!==16)throw new P("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 P(`Invalid IPv6 address "${t}"`)}};function Zr(r){try{let e=new URL(`http://[${r}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new P(`Invalid IPv6 address "${r}"`)}}var Ht=Object.values(Le).map(r=>r.decoder),Jo=(function(){let r=Ht[0].or(Ht[1]);return Ht.slice(2).forEach(e=>r=r.or(e)),r})();function en(r){return Jo.decode(r)}function tn(r){return e=>r.encoder.encode(e)}function Ko(r){if(parseInt(r).toString()!==r)throw new W("Value must be an integer")}function Yo(r){if(r<0)throw new W("Value must be a positive integer, or zero")}function Zo(r){return e=>{if(e>r)throw new W(`Value must be smaller than or equal to ${r}`)}}function es(...r){return e=>{for(let t of r)t(e)}}var Oe=es(Ko,Yo,Zo(65535));var I=-1,Kt=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let t;if(typeof e=="string"?t=this.protocolsByName.get(e):t=this.protocolsByCode.get(e),t==null)throw new He(`Protocol ${e} was unknown`);return t}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(t=>{this.protocolsByName.set(t,e)})}removeProtocol(e){let t=this.protocolsByCode.get(e);t!=null&&(this.protocolsByCode.delete(t.code),this.protocolsByName.delete(t.name),t.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},N=new Kt,ms=[{code:4,name:"ip4",size:32,valueToBytes:Jt,bytesToValue:Kr,validate:r=>{if(!Je(r))throw new W(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Z,bytesToValue:de,validate:Oe},{code:273,name:"udp",size:16,valueToBytes:Z,bytesToValue:de,validate:Oe},{code:33,name:"dccp",size:16,valueToBytes:Z,bytesToValue:de,validate:Oe},{code:41,name:"ip6",size:128,valueToBytes:Jr,bytesToValue:Yr,stringToValue:Zr,validate:r=>{if(!Qr(r))throw new W(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:I},{code:43,name:"ipcidr",size:8,bytesToValue:Qt("base10"),valueToBytes:Gt("base10")},{code:53,name:"dns",size:I,resolvable:!0},{code:54,name:"dns4",size:I,resolvable:!0},{code:55,name:"dns6",size:I,resolvable:!0},{code:56,name:"dnsaddr",size:I,resolvable:!0},{code:132,name:"sctp",size:16,valueToBytes:Z,bytesToValue:de,validate:Oe},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:I,path:!0,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:I,bytesToValue:Qt("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?Gt("base58btc")(r):Q.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Xt,valueToBytes:Gr},{code:445,name:"onion3",size:296,bytesToValue:Xt,valueToBytes:Xr},{code:446,name:"garlic64",size:I},{code:447,name:"garlic32",size:I},{code:448,name:"tls"},{code:449,name:"sni",size:I},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:I,bytesToValue:tn(Tt),valueToBytes:en},{code:480,name:"http"},{code:481,name:"http-path",size:I,stringToValue:r=>`/${decodeURIComponent(r)}`,valueToString:r=>encodeURIComponent(r.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:I}];ms.forEach(r=>{N.addProtocol(r)});function rn(r){let e=[],t=0;for(;t<r.length;){let n=Wt(r,t),o=N.getProtocol(n),s=he(n),i=bs(o,r,t+s),a=0;i>0&&o.size===I&&(a=he(i));let c=s+a+i,l={code:n,name:o.name,bytes:r.subarray(t,t+c)};if(i>0){let h=t+s+a,f=r.subarray(h,h+i);l.value=o.bytesToValue?.(f)??M(f)}e.push(l),t+=c}return e}function nn(r){let e=0,t=[];for(let n of r){if(n.bytes==null){let o=N.getProtocol(n.code),s=he(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??X(n.value),a=i.byteLength,o.size===I&&(c=he(a)));let l=new Uint8Array(s+c+a),h=0;$t(n.code,l,h),h+=s,i!=null&&(o.size===I&&($t(a,l,h),h+=c),l.set(i,h)),n.bytes=l}t.push(n.bytes),e+=n.bytes.byteLength}return J(t,e)}function on(r){if(r.charAt(0)!=="/")throw new P('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=N.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 P(`Component ${o} was missing value`);t="value"}else if(t==="value"){let l={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new P(`Component ${o} was missing value`);l.value=c.stringToValue?.(n)??n}e.push(l),n="",o="",t="protocol"}}}if(o!==""&&n!=="")throw new P("Incomplete multiaddr");return e}function sn(r){return`/${r.flatMap(e=>{if(e.value==null)return e.name;let t=N.getProtocol(e.code);if(t==null)throw new P(`Unknown protocol code ${e.code}`);return[e.name,t.valueToString?.(e.value)??e.value]}).join("/")}`}function bs(r,e,t){return r.size==null||r.size===0?0:r.size>0?r.size/8:Wt(e,t)}var gs=Symbol.for("nodejs.util.inspect.custom"),ar=Symbol.for("@multiformats/multiaddr"),ws=[53,54,55,56],ir=class extends Error{constructor(e="No available resolver"){super(e),this.name="NoAvailableResolverError"}};function xs(r){if(r==null&&(r="/"),cn(r))return r.getComponents();if(r instanceof Uint8Array)return rn(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),on(r);if(Array.isArray(r))return r;throw new P("Must be a string, Uint8Array, Component[], or another Multiaddr")}var et=class r{[ar]=!0;#e;#t;#r;constructor(e="/",t={}){this.#e=xs(e),t.validate!==!1&&ys(this)}get bytes(){return this.#r==null&&(this.#r=nn(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=sn(this.#e)),this.#t}toJSON(){return this.toString()}toOptions(){let e,t,n,o,s="";for(let{code:a,name:c,value:l}of this.#e)a===42&&(s=`%${l??""}`),ws.includes(a)&&(t="tcp",o=443,n=`${l??""}${s}`,e=a===55?6:4),(a===6||a===273)&&(t=c==="tcp"?"tcp":"udp",o=parseInt(l??"")),(a===4||a===41)&&(t="tcp",n=`${l??""}${s}`,e=a===41?6:4);if(e==null||t==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:e,host:n,transport:t,port:o}}getComponents(){return[...this.#e]}protos(){return this.#e.map(({code:e,value:t})=>{let n=N.getProtocol(e);return{code:e,size:n.size??0,name:n.name,resolvable:!!n.resolvable,path:!!n.path}})}protoCodes(){return this.#e.map(({code:e})=>e)}protoNames(){return this.#e.map(({name:e})=>e)}tuples(){return this.#e.map(({code:e,value:t})=>{if(t==null)return[e];let n=N.getProtocol(e),o=[e];return t!=null&&o.push(n.valueToBytes?.(t)??X(t)),o})}stringTuples(){return this.#e.map(({code:e,value:t})=>t==null?[e]:[e,t])}encapsulate(e){let t=new r(e);return new r([...this.#e,...t.getComponents()],{validate:!1})}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new Ae(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,o),{validate:!1})}decapsulateCode(e){let t;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){t=n;break}return new r(this.#e.slice(0,t),{validate:!1})}getPeerId(){try{let e=[];this.#e.forEach(({code:n,value:o})=>{n===421&&e.push([n,o]),n===290&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?M(R.decode(`z${n}`),"base58btc"):M(Q.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){for(let e of this.#e)if(N.getProtocol(e.code).path)return e.value??null;return null}equals(e){return Qe(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(s=>s.resolvable);if(t==null)return[this];let n=an.get(t.name);if(n==null)throw new ir(`no available resolver for ${t.name}`);return(await n(this,e)).map(s=>K(s))}nodeAddress(){let e=this.toOptions();if(e.transport!=="tcp"&&e.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(){return!(this.#e.length!==2||this.#e[0].code!==4&&this.#e[0].code!==41||this.#e[1].code!==6&&this.#e[1].code!==273)}[gs](){return`Multiaddr(${this.toString()})`}};function ys(r){r.getComponents().forEach(e=>{let t=N.getProtocol(e.code);e.value!=null&&t.validate?.(e.value)})}var Ec=parseInt("0xFFFF",16),vc=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var an=new Map;function cn(r){return!!r?.[ar]}function K(r){return new et(r)}var E=r=>({match:e=>{let t=e[0];return t==null||t.code!==r||t.value!=null?!1:e.slice(1)}}),u=(r,e)=>({match:t=>{let n=t[0];return n?.code!==r||n.value==null||e!=null&&n.value!==e?!1:t.slice(1)}}),p=r=>({match:e=>{let t=r.match(e);return t===!1?e:t}}),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}}),w=(...r)=>({match:e=>{for(let t of r){let n=t.match(e);if(n===!1)return!1;e=n}return e}});function y(...r){function e(o){if(o==null)return!1;let s=o.getComponents();for(let i of r){let a=i.match(s);if(a===!1)return!1;s=a}return s}function t(o){return e(o)!==!1}function n(o){let s=e(o);return s===!1?!1:s.length===0}return{matchers:r,matches:t,exactMatch:n}}var Ds=u(421),lu=y(Ds),rt=u(54),nt=u(55),ot=u(56),ur=u(53),fu=y(rt,p(u(421))),hu=y(nt,p(u(421))),du=y(ot,p(u(421))),pu=y(A(ur,ot,rt,nt),p(u(421))),fn=w(u(4),p(u(43))),hn=w(p(u(42)),u(41),p(u(43))),lr=A(fn,hn),re=A(lr,ur,rt,nt,ot),mu=y(A(lr,w(A(ur,ot,rt,nt),p(u(421))))),bu=y(fn),gu=y(hn),wu=y(lr),fr=w(re,u(6)),Me=w(re,u(273)),xu=y(w(fr,p(u(421)))),yu=y(Me),hr=w(Me,E(460),p(u(421))),st=w(Me,E(461),p(u(421))),Is=A(hr,st),Eu=y(hr),vu=y(st),cr=A(re,fr,Me,hr,st),dn=A(w(cr,E(477),p(u(421)))),Cu=y(dn),pn=A(w(cr,E(478),p(u(421))),w(cr,E(448),p(u(449)),E(477),p(u(421)))),Su=y(pn),mn=w(Me,E(280),p(u(466)),p(u(466)),p(u(421))),Du=y(mn),bn=w(st,E(465),p(u(466)),p(u(466)),p(u(421))),Iu=y(bn),tt=A(dn,pn,w(fr,p(u(421))),w(Is,p(u(421))),w(re,p(u(421))),mn,bn,u(421)),Tu=y(tt),Ts=w(tt,E(290),u(421)),Pu=y(Ts),Ps=A(w(tt,E(290),E(281),p(u(421))),w(tt,E(281),p(u(421))),w(E(281),p(u(421)))),Lu=y(Ps),Ls=A(w(re,u(6),E(480),p(u(421))),w(re,E(480),p(u(421)))),Au=y(Ls),As=w(re,A(w(u(6,"443"),E(480)),w(u(6),E(443)),w(u(6),E(448),E(480)),w(E(448),E(480)),E(448),E(443)),p(u(421))),Ou=y(As),Os=A(w(u(777),p(u(421)))),gn=y(Os),_s=A(w(u(400),p(u(421)))),_u=y(_s);var wn=()=>{let r=new Error("Delay aborted");return r.name="AbortError",r},Bs=new WeakMap;function Ns({clearTimeout:r,setTimeout:e}={}){return(t,{value:n,signal:o}={})=>{if(o?.aborted)return Promise.reject(wn());let s,i,a,c=r??clearTimeout,l=()=>{c(s),a(wn())},h=()=>{o&&o.removeEventListener("abort",l)},f=new Promise((x,b)=>{i=()=>{h(),x(n)},a=b,s=(e??setTimeout)(i,t)});return o&&o.addEventListener("abort",l,{once:!0}),Bs.set(f,()=>{c(s),s=null,i()}),f}}var Us=Ns(),it=Us;function at(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var ct=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},ye=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new ct(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let t=this.head;this.head=t.next=new ct(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var dr=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function ze(r={}){return Rs(t=>{let n=t.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function Rs(r,e){e=e??{};let t=e.onEnd,n=new ye,o,s,i,a=at(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((d,D)=>{s=O=>{s=null,n.push(O);try{d(r(n))}catch(T){D(T)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=at()})}},l=d=>s!=null?s(d):(n.push(d),o),h=d=>(n=new ye,s!=null?s({error:d}):(n.push({error:d}),o)),f=d=>{if(i)return o;if(e?.objectMode!==!0&&d?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:d})},x=d=>i?o:(i=!0,d!=null?h(d):l({done:!0})),b=()=>(n=new ye,x(),{done:!0}),g=d=>(x(d),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:b,throw:g,push:f,end:x,get readableLength(){return n.size},onEmpty:async d=>{let D=d?.signal;if(D?.throwIfAborted(),n.isEmpty())return;let O,T;D!=null&&(O=new Promise((_,U)=>{T=()=>{U(new dr)},D.addEventListener("abort",T)}));try{await Promise.race([a.promise,O])}finally{T!=null&&D!=null&&D?.removeEventListener("abort",T)}}},t==null)return o;let S=o;return o={[Symbol.asyncIterator](){return this},next(){return S.next()},throw(d){return S.throw(d),t!=null&&(t(d),t=void 0),{done:!0}},return(){return S.return(),t!=null&&(t(),t=void 0),{done:!0}},push:f,end(d){return S.end(d),t!=null&&(t(d),t=void 0),o},get readableLength(){return S.readableLength},onEmpty:d=>S.onEmpty(d)},o}function Ms(r){return r.reason}async function xn(r,e,t){if(e==null)return r;let n=t?.translateError??Ms;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 En=Symbol.for("@achingbrain/uint8arraylist");function yn(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 ut(r){return!!r?.[En]}var Ee=class r{bufs;length;[En]=!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(ut(n))t+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(let n of e.reverse())if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.unshift(n);else if(ut(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=yn(this.bufs,e);return t.buf[t.index]}set(e,t){let n=yn(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(ut(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 J(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:J(n,o)}sublist(e,t){let{bufs:n,length:o}=this._subList(e,t),s=new r;return s.length=o,s.bufs=[...n],s}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,e>=c)continue;let l=e>=a&&e<c,h=t>a&&t<=c;if(l&&h){if(e===a&&t===c){n.push(i);break}let f=e-a;n.push(i.subarray(f,f+(t-e)));break}if(l){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(h){if(t===c){n.push(i);break}n.push(i.subarray(0,t-a));break}n.push(i)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!ut(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let f=0;f<s;f++)i[f]=-1;for(let f=0;f<o;f++)i[n[f]]=f;let a=i,c=this.byteLength-n.byteLength,l=n.byteLength-1,h;for(let f=t;f<=c;f+=h){h=0;for(let x=l;x>=0;x--){let b=this.get(f+x);if(n[x]!==b){h=Math.max(1,x-a[b]);break}}if(h===0)return f}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let n=G(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=$(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=$(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=$(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=G(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=$(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=$(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=$(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=$(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=$(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(!Qe(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 pr=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},mr=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},vn=r=>globalThis.DOMException===void 0?new mr(r):new DOMException(r),Cn=r=>{let e=r.reason===void 0?vn("This operation was aborted."):r.reason;return e instanceof Error?e:vn(e)};function br(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=e,i,a,l=new Promise((h,f)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:b}=e;b.aborted&&f(Cn(b)),a=()=>{f(Cn(b))},b.addEventListener("abort",a,{once:!0})}if(t===Number.POSITIVE_INFINITY){r.then(h,f);return}let x=new pr;i=s.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(b){f(b)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?h():o instanceof Error?f(o):(x.message=o??`Promise timed out after ${t} milliseconds`,f(x))},t),(async()=>{try{h(await r)}catch(b){f(b)}})()}).finally(()=>{l.clear(),a&&e.signal&&e.signal.removeEventListener("abort",a)});return l.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},l}var zs=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,resolveImmediately:!1,...t},!(t.count>=0&&(t.count===Number.POSITIVE_INFINITY||Number.isInteger(t.count))))throw new TypeError("The `count` option should be at least 0 or more");t.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:l,removeListener:h}=zs(r),f=(...b)=>{let g=t.multiArgs?b:b[0];t.filter&&!t.filter(g)||(c.push(g),t.count===c.length&&(n(),s(c)))},x=b=>{n(),i(b)};n=()=>{for(let b of a)h(b,f);for(let b of t.rejectionEvents)h(b,x)};for(let b of a)l(b,f);for(let b of t.rejectionEvents)l(b,x);t.signal&&t.signal.addEventListener("abort",()=>{x(t.signal.reason)},{once:!0}),t.resolveImmediately&&s(c)});if(o.cancel=n,typeof t.timeout=="number"){let s=br(o,{milliseconds:t.timeout});return s.cancel=n,s}return o}function gr(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 Fs=Math.pow(2,20)*4,lt=class extends ie{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;constructor(e){super(),this.status="open",this.log=e.log,this.direction=e.direction??"outbound",this.inactivityTimeout=e.inactivityTimeout??12e4,this.maxReadBufferLength=e.maxReadBufferLength??Fs,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new Ee,this.writeBuffer=new Ee,this.readStatus="readable",this.remoteReadStatus="readable",this.writeStatus="writable",this.remoteWriteStatus="writable",this.sendingData=!1,this.writableNeedsDrain=!1,this.timeline={open:Date.now()},this.processSendQueue=this.processSendQueue.bind(this);let t=()=>{this.log.trace("drain event received, continue sending data"),this.writableNeedsDrain=!1,this.processSendQueue()};this.addEventListener("drain",t)}async*[Symbol.asyncIterator](){if(this.readStatus!=="readable"&&this.readStatus!=="paused")return;let e=ze(),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 Y(`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 $e(e))}}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new Y("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 Y("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 Y(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.append(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}onData(e){if(e.byteLength!==0){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("ignoring data - read status %s",this.readStatus);return}this.readBuffer.append(e),this.dispatchReadBuffer()}}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="message"&&this.readBuffer.byteLength>0&&queueMicrotask(()=>{this.dispatchReadBuffer()})}onRemoteReset(){this.log("remote reset"),this.status="reset",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.readBuffer.byteLength===0&&(this.readStatus="closed");let e=new oe;this.dispatchEvent(new We(e))}onTransportClosed(e){this.log("transport closed"),this.readStatus==="readable"&&this.readBuffer.byteLength===0&&(this.readStatus="closed"),this.remoteReadStatus!=="closed"&&(this.remoteReadStatus="closed"),this.remoteWriteStatus!=="closed"&&(this.remoteWriteStatus="closed"),this.writeStatus!=="closed"&&(this.writeStatus="closed"),e!=null?this.abort(e):(this.status==="open"||this.status==="closing")&&(this.timeline.close=Date.now(),this.status="closed",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.dispatchEvent(new se))}onRemoteCloseWrite(){this.remoteWriteStatus!=="closed"&&(this.log.trace("on remote close write"),this.remoteWriteStatus="closed",this.safeDispatchEvent("remoteCloseWrite"),this.writeStatus==="closed"&&this.onTransportClosed())}onRemoteCloseRead(){this.log.trace("on remote close read"),this.remoteReadStatus="closed",this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle"))}processSendQueue(){if(this.writableNeedsDrain)return this.log.trace("not processing send queue as drain is required"),this.checkWriteBufferLength(),!1;if(this.writeBuffer.byteLength===0)return this.log.trace("not processing send queue as no bytes to send"),!0;if(this.sendingData)return this.log.trace("not processing send queue as already sending data"),!0;this.sendingData=!0,this.log.trace("processing send queue with %d queued bytes",this.writeBuffer.byteLength);try{let e=!0,t=this.writeBuffer.byteLength,n=0;for(;this.writeBuffer.byteLength>0;){let o=Math.min(this.maxMessageSize??this.writeBuffer.byteLength,this.writeBuffer.byteLength);if(o===0){e=!1;break}let s=this.writeBuffer.sublist(0,o),i=new Ee(s);this.writeBuffer.consume(s.byteLength);let a=this.sendData(s);if(e=a.canSendMore,n+=a.sentBytes,a.sentBytes!==i.byteLength&&(i.consume(a.sentBytes),this.writeBuffer.prepend(i)),!e)break}return e||(this.log.trace("sent %d/%d bytes, pausing sending because underlying stream is full, %d bytes left in the write buffer",n,t,this.writeBuffer.byteLength),this.writableNeedsDrain=!0,this.checkWriteBufferLength()),this.writeBuffer.byteLength===0&&this.safeDispatchEvent("idle"),e}finally{this.sendingData=!1}}dispatchReadBuffer(){try{if(this.listenerCount("message")===0){this.log.trace("not dispatching pause buffer as there are no listeners for the message event");return}if(this.readBuffer.byteLength===0){this.log.trace("not dispatching pause buffer as there is no data to dispatch");return}if(this.readStatus==="paused"){this.log.trace("not dispatching pause buffer we are paused");return}if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("dropping %d bytes because the readable end is %s",this.readBuffer.byteLength,this.readStatus),this.readBuffer.consume(this.readBuffer.byteLength);return}let e=this.readBuffer.sublist();this.readBuffer.consume(e.byteLength),this.dispatchEvent(new Ve(e))}finally{this.remoteWriteStatus==="closed"&&(this.readStatus="closed"),this.checkReadBufferLength()}}checkReadBufferLength(){this.readBuffer.byteLength>this.maxReadBufferLength&&this.abort(new Ce(`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 Ce(`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 lt{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 gr(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 gr(this,"drain",{...e,rejectionEvents:["close"]})),await this.sendClose(e),this.onTransportClosed())}};function Vs(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 Sn=Vs;function $s(r){return r[Symbol.asyncIterator]!=null}function Ws(r,e){let t=0;if($s(r))return(async function*(){for await(let c of r)yield e(c,t++)})();let n=Sn(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 Dn=Ws;var wr=class extends ft{localPushable;constructor(e){super(e),this.localPushable=e.localPushable,Promise.resolve().then(async()=>{for await(let t of Dn(e.remotePushable,async n=>(e.connection.latency>0&&await it(e.connection.latency),n)))this.onData(t);this.onTransportClosed()}).catch(t=>{this.abort(t)})}sendReset(){this.localPushable.end(new oe)}sendData(e){return this.localPushable.push(e),{sentBytes:e.byteLength,canSendMore:!0}}async sendClose(e){this.localPushable.end(),e?.signal?.throwIfAborted()}sendPause(){}sendResume(){}};function xr(r){return new wr(r)}var ve=new Map,yr=0,ht=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=ze({onEnd(f){s=!0,o.connections.delete(l),i||c.end(f)}}),c=ze({onEnd(f){i=!0,o.connections.delete(h),s||a.end(f)}}),l=xr({connection:this,remoteAddr:K(`${this.init.address}/p2p/${this.components.peerId}`),direction:"outbound",localPushable:a,remotePushable:c,log:t.newScope(`connection:${yr}`),maxMessageSize:this.init.maxMessageSize??65536}),h=xr({connection:this,remoteAddr:K(`${this.init.address}-outgoing/p2p/${e}`),direction:"inbound",localPushable:c,remotePushable:a,log:this.log.newScope(`connection:${yr}`),maxMessageSize:this.init.maxMessageSize??65536});return this.connections.add(l),this.connections.add(h),yr++,await xn(it(this.latency),n),this.init.onConnection(h),l}close(){[...this.connections].forEach(e=>{e.abort(new ne("Memory Connection closed"))})}};var In="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";var Tn=(r=21)=>{let e="",t=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)e+=In[t[r]&63];return e};var dt=class extends ie{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[[,t]]=e.stringTuples(),n=`/memory/${t??Tn()}`;if(t!=null&&ve.has(n))throw new Fe(`Memory address ${n} already in use`);this.connection=new ht(this.components,{...this.init,onConnection:this.onConnection.bind(this),address:n}),this.listenAddr=K(n),ve.set(n,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&&ve.delete(this.listenAddr.toString()),this.shutdownController.abort(),queueMicrotask(()=>{this.safeDispatchEvent("close")})}};var pt=class{components;init;constructor(e,t={}){this.components=e,this.init=t}[vr]=!0;[Symbol.toStringTag]="@libp2p/memory";[Cr]=["@libp2p/transport"];async dial(e,t){t.signal.throwIfAborted();let n=ve.get(`${e.getPeerId()==null?e:e.decapsulate("/p2p")}`);if(n==null)throw new ne(`No memory listener found at ${e}`);let o=await n.dial(this.components.peerId,this.components.logger.forComponent("libp2p:memory"),t.signal);try{return t.signal.throwIfAborted(),await t.upgrader.upgradeOutbound(o,{...t,...this.init.upgraderOptions})}catch(s){throw o.abort(s),s}}createListener(e){return new dt(this.components,{...e,...this.init})}listenFilter(e){return e.filter(t=>gn.exactMatch(t))}dialFilter(e){return this.listenFilter(e)}};function js(r){return e=>new pt(e,r)}return _n(Hs);})();
2
+ "use strict";var Libp2PMemory=(()=>{var at=Object.defineProperty;var Sn=Object.getOwnPropertyDescriptor;var Dn=Object.getOwnPropertyNames;var In=Object.prototype.hasOwnProperty;var B=(r,e)=>{for(var t in e)at(r,t,{get:e[t],enumerable:!0})},Tn=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Dn(e))!In.call(r,o)&&o!==t&&at(r,o,{get:()=>e[o],enumerable:!(n=Sn(e,o))||n.enumerable});return r};var Ln=r=>Tn(at({},"__esModule",{value:!0}),r);var Ms={};B(Ms,{memory:()=>Rs});var Z=class extends Error{static name="ConnectionFailedError";constructor(e="Connection failed"){super(e),this.name="ConnectionFailedError"}};var ee=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var Q=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},ge=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var Pe=class extends Error{static name="ListenError";constructor(e="Listen error"){super(e),this.name="ListenError"}};var Oe=class extends Event{data;constructor(e,t){super("message",t),this.data=e}},te=class extends Event{error;local;constructor(e,t,n){super("close",n),this.error=t,this.local=e}},_e=class extends te{constructor(e,t){super(!0,e,t)}},Be=class extends te{constructor(e,t){super(!1,e,t)}};var wr=Symbol.for("@libp2p/transport");var xr;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(xr||(xr={}));var re=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:s})=>s!==t),this.#e.set(e,o))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};var yr=Symbol.for("@libp2p/service-capabilities"),ks=Symbol.for("@libp2p/service-dependencies");function Ue(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function V(r=0){return new Uint8Array(r)}function k(r=0){return new Uint8Array(r)}var An=Math.pow(2,7),Pn=Math.pow(2,14),On=Math.pow(2,21),ct=Math.pow(2,28),ut=Math.pow(2,35),lt=Math.pow(2,42),ft=Math.pow(2,49),v=128,A=127;function ne(r){if(r<An)return 1;if(r<Pn)return 2;if(r<On)return 3;if(r<ct)return 4;if(r<ut)return 5;if(r<lt)return 6;if(r<ft)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ht(r,e,t=0){switch(ne(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 _n(r,e){let t=r[e],n=0;if(n+=t&A,t<v||(t=r[e+1],n+=(t&A)<<7,t<v)||(t=r[e+2],n+=(t&A)<<14,t<v)||(t=r[e+3],n+=(t&A)<<21,t<v)||(t=r[e+4],n+=(t&A)*ct,t<v)||(t=r[e+5],n+=(t&A)*ut,t<v)||(t=r[e+6],n+=(t&A)*lt,t<v)||(t=r[e+7],n+=(t&A)*ft,t<v))return n;throw new RangeError("Could not decode varint")}function Bn(r,e){let t=r.get(e),n=0;if(n+=t&A,t<v||(t=r.get(e+1),n+=(t&A)<<7,t<v)||(t=r.get(e+2),n+=(t&A)<<14,t<v)||(t=r.get(e+3),n+=(t&A)<<21,t<v)||(t=r.get(e+4),n+=(t&A)*ct,t<v)||(t=r.get(e+5),n+=(t&A)*ut,t<v)||(t=r.get(e+6),n+=(t&A)*lt,t<v)||(t=r.get(e+7),n+=(t&A)*ft,t<v))return n;throw new RangeError("Could not decode varint")}function dt(r,e=0){return r instanceof Uint8Array?_n(r,e):Bn(r,e)}function q(r,e){e==null&&(e=r.reduce((o,s)=>o+s.length,0));let t=k(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var xt={};B(xt,{base10:()=>$n});var Si=new Uint8Array(0);function Er(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 z(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function vr(r){return new TextEncoder().encode(r)}function Cr(r){return new TextDecoder().decode(r)}function Nn(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(t[i]!==255)throw new TypeError(s+" is ambiguous");t[i]=o}var a=r.length,c=r.charAt(0),f=Math.log(a)/Math.log(256),h=Math.log(256)/Math.log(a);function l(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var S=0,p=0,D=0,O=g.length;D!==O&&g[D]===0;)D++,S++;for(var T=(O-D)*h+1>>>0,_=new Uint8Array(T);D!==O;){for(var U=g[D],W=0,N=T-1;(U!==0||W<p)&&N!==-1;N--,W++)U+=256*_[N]>>>0,_[N]=U%a>>>0,U=U/a>>>0;if(U!==0)throw new Error("Non-zero carry");p=W,D++}for(var M=T-p;M!==T&&_[M]===0;)M++;for(var Ae=c.repeat(S);M<T;++M)Ae+=r.charAt(_[M]);return Ae}function w(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var S=0;if(g[S]!==" "){for(var p=0,D=0;g[S]===c;)p++,S++;for(var O=(g.length-S)*f+1>>>0,T=new Uint8Array(O);g[S];){var _=t[g.charCodeAt(S)];if(_===255)return;for(var U=0,W=O-1;(_!==0||U<D)&&W!==-1;W--,U++)_+=a*T[W]>>>0,T[W]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");D=U,S++}if(g[S]!==" "){for(var N=O-D;N!==O&&T[N]===0;)N++;for(var M=new Uint8Array(p+(O-N)),Ae=p;N!==O;)M[Ae++]=T[N++];return M}}}function b(g){var S=w(g);if(S)return S;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:w,decode:b}}var Rn=Nn,Mn=Rn,Dr=Mn;var pt=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},mt=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let o=t.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Ir(this,e)}},bt=class{decoders;constructor(e){this.decoders=e}or(e){return Ir(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 Ir(r,e){return new bt({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var gt=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new pt(e,t,n),this.decoder=new mt(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function oe({name:r,prefix:e,encode:t,decode:n}){return new gt(r,e,t,n)}function j({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=Dr(t,r);return oe({prefix:e,name:r,encode:n,decode:s=>z(o(s))})}function Vn(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 f=0;f<o;++f){let h=e[r[f]];if(h===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|h,i+=t,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=t||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function 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 Fn(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function C({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let o=Fn(n);return oe({prefix:e,name:r,encode(s){return zn(s,n,t)},decode(s){return Vn(s,o,t,r)}})}var $n=j({prefix:"9",name:"base10",alphabet:"0123456789"});var wt={};B(wt,{base16:()=>Wn,base16upper:()=>kn});var Wn=C({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),kn=C({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var yt={};B(yt,{base2:()=>qn});var qn=C({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Et={};B(Et,{base256emoji:()=>Xn});var Tr=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}"),jn=Tr.reduce((r,e,t)=>(r[t]=e,r),[]),Hn=Tr.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function Qn(r){return r.reduce((e,t)=>(e+=jn[t],e),"")}function Gn(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=Hn[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var Xn=oe({prefix:"\u{1F680}",name:"base256emoji",encode:Qn,decode:Gn});var vt={};B(vt,{base32:()=>H,base32hex:()=>Zn,base32hexpad:()=>to,base32hexpadupper:()=>ro,base32hexupper:()=>eo,base32pad:()=>Kn,base32padupper:()=>Yn,base32upper:()=>Jn,base32z:()=>no});var H=C({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Jn=C({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Kn=C({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Yn=C({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Zn=C({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),eo=C({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),to=C({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ro=C({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),no=C({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ct={};B(Ct,{base36:()=>xe,base36upper:()=>oo});var xe=j({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),oo=j({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var St={};B(St,{base58btc:()=>R,base58flickr:()=>so});var R=j({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),so=j({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var It={};B(It,{base64:()=>io,base64pad:()=>ao,base64url:()=>Dt,base64urlpad:()=>co});var io=C({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ao=C({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Dt=C({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),co=C({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Tt={};B(Tt,{base8:()=>uo});var uo=C({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Lt={};B(Lt,{identity:()=>lo});var lo=oe({prefix:"\0",name:"identity",encode:r=>Cr(r),decode:r=>vr(r)});var Fi=new TextEncoder,$i=new TextDecoder;var Pt={};B(Pt,{identity:()=>Uo});var po=Pr,Lr=128,mo=127,bo=~mo,go=Math.pow(2,31);function Pr(r,e,t){e=e||[],t=t||0;for(var n=t;r>=go;)e[t++]=r&255|Lr,r/=128;for(;r&bo;)e[t++]=r&255|Lr,r>>>=7;return e[t]=r|0,Pr.bytes=t-n+1,e}var xo=At,wo=128,Ar=127;function At(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw At.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&Ar)<<o:(i&Ar)*Math.pow(2,o),o+=7}while(i>=wo);return At.bytes=s-n,t}var yo=Math.pow(2,7),Eo=Math.pow(2,14),vo=Math.pow(2,21),Co=Math.pow(2,28),So=Math.pow(2,35),Do=Math.pow(2,42),Io=Math.pow(2,49),To=Math.pow(2,56),Lo=Math.pow(2,63),Ao=function(r){return r<yo?1:r<Eo?2:r<vo?3:r<Co?4:r<So?5:r<Do?6:r<Io?7:r<To?8:r<Lo?9:10},Po={encode:po,decode:xo,encodingLength:Ao},Oo=Po,we=Oo;function ye(r,e=0){return[we.decode(r,e),we.decode.bytes]}function se(r,e,t=0){return we.encode(r,e,t),e}function ie(r){return we.encodingLength(r)}function ce(r,e){let t=e.byteLength,n=ie(r),o=n+ie(t),s=new Uint8Array(o+t);return se(r,s,0),se(t,s,n),s.set(e,o),new ae(r,t,e,s)}function Or(r){let e=z(r),[t,n]=ye(e),[o,s]=ye(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new ae(t,o,i,e)}function _r(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Er(r.bytes,t.bytes)}}var ae=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};var Br=0,_o="identity",Ur=z;function Bo(r,e){if(e?.truncate!=null&&e.truncate!==r.byteLength){if(e.truncate<0||e.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e.truncate)}return ce(Br,Ur(r))}var Uo={code:Br,name:_o,encode:Ur,digest:Bo};var Bt={};B(Bt,{sha256:()=>Ro,sha512:()=>Mo});var No=20;function _t({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:o}){return new Ot(r,e,t,n,o)}var Ot=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,o,s){this.name=e,this.code=t,this.encode=n,this.minDigestLength=o??No,this.maxDigestLength=s}digest(e,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?Nr(n,this.code,t?.truncate):n.then(o=>Nr(o,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function Nr(r,e,t){if(t!=null&&t!==r.byteLength){if(t>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t)}return ce(e,r)}function Mr(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var Ro=_t({name:"sha2-256",code:18,encode:Mr("SHA-256")}),Mo=_t({name:"sha2-512",code:19,encode:Mr("SHA-512")});function Vr(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return zo(t,Ut(r),e??R.encoder);default:return Fo(t,Ut(r),e??H.encoder)}}var zr=new WeakMap;function Ut(r){let e=zr.get(r);if(e==null){let t=new Map;return zr.set(r,t),t}return e}var ue=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==ve)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==$o)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=ce(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&_r(e.multihash,n.multihash)}toString(e){return Vr(this,e)}toJSON(){return{"/":Vr(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??Fr(n,o,s.bytes))}else if(t[Wo]===!0){let{version:n,multihash:o,code:s}=t,i=Or(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!==ve)throw new Error(`Version 0 CID must use dag-pb (code: ${ve}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=Fr(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,ve,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=z(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let s=o.subarray(t.multihashSize-t.digestSize),i=new ae(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[l,w]=ye(e.subarray(t));return t+=w,l},o=n(),s=ve;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(),f=t+c,h=f-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:h,size:f}}static parse(e,t){let[n,o]=Vo(e,t),s=r.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Ut(s).set(n,e),s}};function Vo(r,e){switch(r[0]){case"Q":{let t=e??R;return[R.prefix,t.decode(`${R.prefix}${r}`)]}case R.prefix:{let t=e??R;return[R.prefix,t.decode(r)]}case H.prefix:{let t=e??H;return[H.prefix,t.decode(r)]}case xe.prefix:{let t=e??xe;return[xe.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!==R.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let s=t.encode(r).slice(1);return e.set(n,s),s}else return o}function Fo(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 ve=112,$o=18;function Fr(r,e,t){let n=ie(r),o=n+ie(e),s=new Uint8Array(o+t.byteLength);return se(r,s,0),se(e,s,n),s.set(t,o),s}var Wo=Symbol.for("@ipld/js-cid/CID");var Ce={...Lt,...yt,...Tt,...xt,...wt,...vt,...Ct,...St,...It,...Et},ua={...Bt,...Pt};function Wr(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var $r=Wr("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Nt=Wr("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=k(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),ko={utf8:$r,"utf-8":$r,hex:Ce.base16,latin1:Nt,ascii:Nt,binary:Nt,...Ce},Re=ko;function Se(r,e="utf8"){let t=Re[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function G(r,e="utf8"){let t=Re[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var L=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},F=class extends Error{static name="ValidationError";name="ValidationError"},Me=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Ve=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var ze=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",f=2**(8*o)-1;for(;;){let h=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let w=Number.parseInt(l,e);if(!Number.isNaN(w))return w});if(h===void 0)break;if(s*=e,s+=h,s>f||(i+=1,t!==void 0&&i>t))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let o=n*2;if(n<t.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return t[o]=i[0],t[o+1]=i[1],t[o+2]=i[2],t[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];t[o]=s>>8,t[o+1]=s&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,o]=e(t);if(n===16)return t;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=e(s.subarray(0,i));return t.set(s.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var qo=45,jo=15,Fe=new ze;function kr(r){if(!(r.length>jo))return Fe.new(r).parseWith(()=>Fe.readIPv4Addr())}function qr(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>qo))return Fe.new(r).parseWith(()=>Fe.readIPv6Addr())}function $e(r){return!!kr(r)}function jr(r){return!!qr(r)}function Mt(r){return e=>G(e,r)}function Vt(r){return e=>Se(e,r)}function le(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function X(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(e)}function Hr(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=Se(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=X(n);return q([t,o],t.length+o.length)}function Qr(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=H.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=X(n);return q([t,o],t.length+o.length)}function zt(r){let e=r.subarray(0,r.length-2),t=r.subarray(r.length-2),n=G(e,"base32"),o=le(t);return`${n}:${o}`}var Ft=function(r){r=r.toString().trim();let e=new Uint8Array(4);return r.split(/\./g).forEach((t,n)=>{let o=parseInt(t,10);if(isNaN(o)||o<0||o>255)throw new L("Invalid byte value in IP address");e[n]=o}),e},Gr=function(r){let e=0;r=r.toString().trim();let t=r.split(":",8),n;for(n=0;n<t.length;n++){let s=$e(t[n]),i;s&&(i=Ft(t[n]),t[n]=G(i.subarray(0,2),"base16")),i!=null&&++n<8&&t.splice(n,0,G(i.subarray(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let s=[n,1];for(n=9-t.length;n>0;n--)s.push("0");t.splice.apply(t,s)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){t[n]===""&&(t[n]="0");let s=parseInt(t[n],16);if(isNaN(s)||s<0||s>65535)throw new L("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},Xr=function(r){if(r.byteLength!==4)throw new L("IPv4 address was incorrect length");let e=[];for(let t=0;t<r.byteLength;t++)e.push(r[t]);return e.join(".")},Jr=function(r){if(r.byteLength!==16)throw new L("IPv6 address was incorrect length");let e=[];for(let n=0;n<r.byteLength;n+=2){let o=r[n],s=r[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;e.push(i)}let t=e.join(":");try{let n=new URL(`http://[${t}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new L(`Invalid IPv6 address "${t}"`)}};function Kr(r){try{let e=new URL(`http://[${r}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new L(`Invalid IPv6 address "${r}"`)}}var Rt=Object.values(Ce).map(r=>r.decoder),Ho=(function(){let r=Rt[0].or(Rt[1]);return Rt.slice(2).forEach(e=>r=r.or(e)),r})();function Yr(r){return Ho.decode(r)}function Zr(r){return e=>r.encoder.encode(e)}function Qo(r){if(parseInt(r).toString()!==r)throw new F("Value must be an integer")}function Go(r){if(r<0)throw new F("Value must be a positive integer, or zero")}function Xo(r){return e=>{if(e>r)throw new F(`Value must be smaller than or equal to ${r}`)}}function Jo(...r){return e=>{for(let t of r)t(e)}}var De=Jo(Qo,Go,Xo(65535));var I=-1,$t=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let t;if(typeof e=="string"?t=this.protocolsByName.get(e):t=this.protocolsByCode.get(e),t==null)throw new Ve(`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)}))}},$=new $t,fs=[{code:4,name:"ip4",size:32,valueToBytes:Ft,bytesToValue:Xr,validate:r=>{if(!$e(r))throw new F(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:X,bytesToValue:le,validate:De},{code:273,name:"udp",size:16,valueToBytes:X,bytesToValue:le,validate:De},{code:33,name:"dccp",size:16,valueToBytes:X,bytesToValue:le,validate:De},{code:41,name:"ip6",size:128,valueToBytes:Gr,bytesToValue:Jr,stringToValue:Kr,validate:r=>{if(!jr(r))throw new F(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:I},{code:43,name:"ipcidr",size:8,bytesToValue:Mt("base10"),valueToBytes:Vt("base10")},{code:53,name:"dns",size:I},{code:54,name:"dns4",size:I},{code:55,name:"dns6",size:I},{code:56,name:"dnsaddr",size:I},{code:132,name:"sctp",size:16,valueToBytes:X,bytesToValue:le,validate:De},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:I,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:I,bytesToValue:Mt("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?Vt("base58btc")(r):ue.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:zt,valueToBytes:Hr},{code:445,name:"onion3",size:296,bytesToValue:zt,valueToBytes:Qr},{code:446,name:"garlic64",size:I},{code:447,name:"garlic32",size:I},{code:448,name:"tls"},{code:449,name:"sni",size:I},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:I,bytesToValue:Zr(Dt),valueToBytes:Yr},{code:480,name:"http"},{code:481,name:"http-path",size:I,stringToValue:r=>`/${decodeURIComponent(r)}`,valueToString:r=>encodeURIComponent(r.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:I}];fs.forEach(r=>{$.addProtocol(r)});function en(r){let e=[],t=0;for(;t<r.length;){let n=dt(r,t),o=$.getProtocol(n),s=ne(n),i=hs(o,r,t+s),a=0;i>0&&o.size===I&&(a=ne(i));let c=s+a+i,f={code:n,name:o.name,bytes:r.subarray(t,t+c)};if(i>0){let h=t+s+a,l=r.subarray(h,h+i);f.value=o.bytesToValue?.(l)??G(l)}e.push(f),t+=c}return e}function tn(r){let e=0,t=[];for(let n of r){if(n.bytes==null){let o=$.getProtocol(n.code),s=ne(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??Se(n.value),a=i.byteLength,o.size===I&&(c=ne(a)));let f=new Uint8Array(s+c+a),h=0;ht(n.code,f,h),h+=s,i!=null&&(o.size===I&&(ht(a,f,h),h+=c),f.set(i,h)),n.bytes=f}t.push(n.bytes),e+=n.bytes.byteLength}return q(t,e)}function rn(r){if(r.charAt(0)!=="/")throw new L('String multiaddr must start with "/"');let e=[],t="protocol",n="",o="";for(let s=1;s<r.length;s++){let i=r.charAt(s);i!=="/"&&(t==="protocol"?o+=r.charAt(s):n+=r.charAt(s));let a=s===r.length-1;if(i==="/"||a){let c=$.getProtocol(o);if(t==="protocol"){if(c.size==null||c.size===0){e.push({code:c.code,name:c.name}),n="",o="",t="protocol";continue}else if(a)throw new L(`Component ${o} was missing value`);t="value"}else if(t==="value"){let f={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new L(`Component ${o} was missing value`);f.value=c.stringToValue?.(n)??n}e.push(f),n="",o="",t="protocol"}}}if(o!==""&&n!=="")throw new L("Incomplete multiaddr");return e}function nn(r){return`/${r.flatMap(e=>{if(e.value==null)return e.name;let t=$.getProtocol(e.code);if(t==null)throw new L(`Unknown protocol code ${e.code}`);return[e.name,t.valueToString?.(e.value)??e.value]}).join("/")}`}function hs(r,e,t){return r.size==null||r.size===0?0:r.size>0?r.size/8:dt(e,t)}var ds=Symbol.for("nodejs.util.inspect.custom"),or=Symbol.for("@multiformats/multiaddr");function ps(r){if(r==null&&(r="/"),on(r))return r.getComponents();if(r instanceof Uint8Array)return en(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),rn(r);if(Array.isArray(r))return r;throw new L("Must be a string, Uint8Array, Component[], or another Multiaddr")}var He=class r{[or]=!0;#e;#t;#r;constructor(e="/",t={}){this.#e=ps(e),t.validate!==!1&&ms(this)}get bytes(){return this.#r==null&&(this.#r=tn(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=nn(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 Me(`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 Ue(this.bytes,e.bytes)}[ds](){return`Multiaddr(${this.toString()})`}};function ms(r){r.getComponents().forEach(e=>{let t=$.getProtocol(e.code);e.value!=null&&t.validate?.(e.value)})}function on(r){return!!r?.[or]}function Ie(r){return new He(r)}var y=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)}}),sn=r=>({match:e=>r.match(e)===!1?e:!1}),d=r=>({match:e=>{let t=r.match(e);return t===!1?e:t}}),P=(...r)=>({match:e=>{let t;for(let n of r){let o=n.match(e);o!==!1&&(t==null||o.length<t.length)&&(t=o)}return t??!1}}),x=(...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 bs=u(421),uc=E(bs),Ge=u(54),Xe=u(55),Je=u(56),ir=u(53),lc=E(Ge,d(u(421))),fc=E(Xe,d(u(421))),hc=E(Je,d(u(421))),dc=E(P(ir,Je,Ge,Xe),d(u(421))),an=x(u(4),d(u(43))),cn=x(d(u(42)),u(41),d(u(43))),ar=P(an,cn),Y=P(ar,ir,Ge,Xe,Je),pc=E(P(ar,x(P(ir,Je,Ge,Xe),d(u(421))))),mc=E(an),bc=E(cn),gc=E(ar),cr=x(Y,u(6)),Te=x(Y,u(273)),xc=E(x(cr,d(u(421)))),wc=E(Te),ur=x(Te,y(460),d(u(421))),Ke=x(Te,y(461),d(u(421))),gs=P(ur,Ke),yc=E(ur),Ec=E(Ke),sr=P(Y,cr,Te,ur,Ke),un=P(x(sr,y(477),d(u(421)))),vc=E(un),ln=P(x(sr,y(478),d(u(421))),x(sr,y(448),d(u(449)),y(477),d(u(421)))),Cc=E(ln),fn=x(Te,y(280),d(u(466)),d(u(466)),d(u(421))),Sc=E(fn),hn=x(Ke,y(465),d(u(466)),d(u(466)),d(u(421))),Dc=E(hn),Qe=P(un,ln,x(cr,d(u(421))),x(gs,d(u(421))),x(Y,d(u(421))),fn,hn,u(421)),Ic=E(Qe),xs=x(d(Qe),y(290),sn(y(281)),d(u(421))),Tc=E(xs),ws=P(x(Qe,y(290),y(281),d(u(421))),x(Qe,y(281),d(u(421))),x(y(281),d(u(421)))),Lc=E(ws),ys=P(x(Y,u(6),y(480),d(u(421))),x(Y,y(480),d(u(421)))),Ac=E(ys),Es=x(Y,P(x(u(6,"443"),y(480)),x(u(6),y(443)),x(u(6),y(448),y(480)),x(y(448),y(480)),y(448),y(443)),d(u(421))),Pc=E(Es),vs=P(x(u(777),d(u(421)))),dn=E(vs),Cs=P(x(u(400),d(u(421)))),Oc=E(Cs);var pn=()=>{let r=new Error("Delay aborted");return r.name="AbortError",r},Ss=new WeakMap;function Ds({clearTimeout:r,setTimeout:e}={}){return(t,{value:n,signal:o}={})=>{if(o?.aborted)return Promise.reject(pn());let s,i,a,c=r??clearTimeout,f=()=>{c(s),a(pn())},h=()=>{o&&o.removeEventListener("abort",f)},l=new Promise((w,b)=>{i=()=>{h(),w(n)},a=b,s=(e??setTimeout)(i,t)});return o&&o.addEventListener("abort",f,{once:!0}),Ss.set(l,()=>{c(s),s=null,i()}),l}}var Is=Ds(),Ye=Is;function Ze(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var et=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},pe=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new et(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 et(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 lr=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function Le(r={}){return Ts(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 Ts(r,e){e=e??{};let t=e.onEnd,n=new pe,o,s,i,a=Ze(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((p,D)=>{s=O=>{s=null,n.push(O);try{p(r(n))}catch(T){D(T)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Ze()})}},f=p=>s!=null?s(p):(n.push(p),o),h=p=>(n=new pe,s!=null?s({error:p}):(n.push({error:p}),o)),l=p=>{if(i)return o;if(e?.objectMode!==!0&&p?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:p})},w=p=>i?o:(i=!0,p!=null?h(p):f({done:!0})),b=()=>(n=new pe,w(),{done:!0}),g=p=>(w(p),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:b,throw:g,push:l,end:w,get readableLength(){return n.size},onEmpty:async p=>{let D=p?.signal;if(D?.throwIfAborted(),n.isEmpty())return;let O,T;D!=null&&(O=new Promise((_,U)=>{T=()=>{U(new lr)},D.addEventListener("abort",T)}));try{await Promise.race([a.promise,O])}finally{T!=null&&D!=null&&D?.removeEventListener("abort",T)}}},t==null)return o;let S=o;return o={[Symbol.asyncIterator](){return this},next(){return S.next()},throw(p){return S.throw(p),t!=null&&(t(p),t=void 0),{done:!0}},return(){return S.return(),t!=null&&(t(),t=void 0),{done:!0}},push:l,end(p){return S.end(p),t!=null&&(t(p),t=void 0),o},get readableLength(){return S.readableLength},onEmpty:p=>S.onEmpty(p)},o}function Ls(r){return r.reason}async function mn(r,e,t){if(e==null)return r;let n=t?.translateError??Ls;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 gn=Symbol.for("@achingbrain/uint8arraylist");function bn(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let o=t+n.byteLength;if(e<o)return{buf:n,index:e-t};t=o}throw new RangeError("index is out of bounds")}function tt(r){return!!r?.[gn]}var me=class r{bufs;length;[gn]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(let n of e)if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.push(n);else if(tt(n))t+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(let n of e.reverse())if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.unshift(n);else if(tt(n))t+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}get(e){let t=bn(this.bufs,e);return t.buf[t.index]}set(e,t){let n=bn(this.bufs,e);n.buf[n.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(t+n,e[n]);else if(tt(e))for(let n=0;n<e.length;n++)this.set(t+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:n,length:o}=this._subList(e,t);return q(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:q(n,o)}sublist(e,t){let{bufs:n,length:o}=this._subList(e,t),s=new r;return s.length=o,s.bufs=[...n],s}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,e>=c)continue;let f=e>=a&&e<c,h=t>a&&t<=c;if(f&&h){if(e===a&&t===c){n.push(i);break}let l=e-a;n.push(i.subarray(l,l+(t-e)));break}if(f){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(h){if(t===c){n.push(i);break}n.push(i.subarray(0,t-a));break}n.push(i)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!tt(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let 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,f=n.byteLength-1,h;for(let l=t;l<=c;l+=h){h=0;for(let w=f;w>=0;w--){let b=this.get(l+w);if(n[w]!==b){h=Math.max(1,w-a[b]);break}}if(h===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=k(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){let o=V(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,t,n),this.write(o,e)}getInt32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){let o=V(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,t,n),this.write(o,e)}getBigInt64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){let o=V(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,t,n),this.write(o,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let n=k(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){let o=V(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,t,n),this.write(o,e)}getUint32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){let o=V(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,t,n),this.write(o,e)}getBigUint64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){let o=V(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,t,n),this.write(o,e)}getFloat32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){let o=V(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,t,n),this.write(o,e)}getFloat64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){let o=V(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,t,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof r)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!Ue(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 fr=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},hr=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},xn=r=>globalThis.DOMException===void 0?new hr(r):new DOMException(r),wn=r=>{let e=r.reason===void 0?xn("This operation was aborted."):r.reason;return e instanceof Error?e:xn(e)};function dr(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=e,i,a,f=new Promise((h,l)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:b}=e;b.aborted&&l(wn(b)),a=()=>{l(wn(b))},b.addEventListener("abort",a,{once:!0})}if(t===Number.POSITIVE_INFINITY){r.then(h,l);return}let w=new fr;i=s.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(b){l(b)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?h():o instanceof Error?l(o):(w.message=o??`Promise timed out after ${t} milliseconds`,l(w))},t),(async()=>{try{h(await r)}catch(b){l(b)}})()}).finally(()=>{f.clear(),a&&e.signal&&e.signal.removeEventListener("abort",a)});return f.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},f}var As=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 Ps(r,e,t){let n,o=new Promise((s,i)=>{if(t={rejectionEvents:["error"],multiArgs:!1,resolveImmediately:!1,...t},!(t.count>=0&&(t.count===Number.POSITIVE_INFINITY||Number.isInteger(t.count))))throw new TypeError("The `count` option should be at least 0 or more");t.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:f,removeListener:h}=As(r),l=(...b)=>{let g=t.multiArgs?b:b[0];t.filter&&!t.filter(g)||(c.push(g),t.count===c.length&&(n(),s(c)))},w=b=>{n(),i(b)};n=()=>{for(let b of a)h(b,l);for(let b of t.rejectionEvents)h(b,w)};for(let b of a)f(b,l);for(let b of t.rejectionEvents)f(b,w);t.signal&&t.signal.addEventListener("abort",()=>{w(t.signal.reason)},{once:!0}),t.resolveImmediately&&s(c)});if(o.cancel=n,typeof t.timeout=="number"){let s=dr(o,{milliseconds:t.timeout});return s.cancel=n,s}return o}function pr(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=Ps(r,e,t),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}var Os=Math.pow(2,20)*4,rt=class extends re{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;constructor(e){super(),this.status="open",this.log=e.log,this.direction=e.direction??"outbound",this.inactivityTimeout=e.inactivityTimeout??12e4,this.maxReadBufferLength=e.maxReadBufferLength??Os,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new me,this.writeBuffer=new me,this.readStatus="readable",this.remoteReadStatus="readable",this.writeStatus="writable",this.remoteWriteStatus="writable",this.sendingData=!1,this.writableNeedsDrain=!1,this.timeline={open:Date.now()},this.processSendQueue=this.processSendQueue.bind(this);let t=()=>{this.writableNeedsDrain&&(this.log.trace("drain event received, continue sending data"),this.writableNeedsDrain=!1,this.processSendQueue())};this.addEventListener("drain",t)}async*[Symbol.asyncIterator](){if(this.readStatus!=="readable"&&this.readStatus!=="paused")return;let e=Le(),t=s=>{e.push(s.data)};this.addEventListener("message",t);let n=s=>{e.end(s.error)};this.addEventListener("close",n);let o=()=>{e.end()};this.addEventListener("remoteCloseWrite",o);try{yield*e}finally{this.removeEventListener("message",t),this.removeEventListener("close",n),this.removeEventListener("remoteCloseWrite",o)}}isReadable(){return this.status==="open"}send(e){if(this.writeStatus==="closed"||this.writeStatus==="closing")throw new Q(`Cannot write to a stream that is ${this.writeStatus}`);return this.log.trace("append %d bytes to write buffer",e.byteLength),this.writeBuffer.append(e),this.processSendQueue()}abort(e){if(!(this.status==="aborted"||this.status==="reset"||this.status==="closed")){this.log.error("abort with error - %e",e),this.status="aborted",this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle")),this.writeStatus="closed",this.remoteWriteStatus="closed",this.readStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now();try{this.sendReset(e)}catch(t){this.log("failed to send reset to remote - %e",t)}this.dispatchEvent(new _e(e))}}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new Q("Cannot pause a stream that is closing/closed");this.readStatus!=="paused"&&(this.readStatus="paused",this.sendPause())}resume(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new Q("Cannot resume a stream that is closing/closed");this.readStatus!=="readable"&&(this.readStatus="readable",this.dispatchReadBuffer(),this.sendResume())}push(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new Q(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.append(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}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 ee;this.dispatchEvent(new Be(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 te))}onRemoteCloseWrite(){this.remoteWriteStatus!=="closed"&&(this.log.trace("on remote close write"),this.remoteWriteStatus="closed",this.safeDispatchEvent("remoteCloseWrite"),this.writeStatus==="closed"&&this.onTransportClosed())}onRemoteCloseRead(){this.log.trace("on remote close read"),this.remoteReadStatus="closed",this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle"))}processSendQueue(){if(this.writableNeedsDrain)return this.log.trace("not processing send queue as drain is required"),this.checkWriteBufferLength(),!1;if(this.writeBuffer.byteLength===0)return this.log.trace("not processing send queue as no bytes to send"),!0;if(this.sendingData)return this.log.trace("not processing send queue as already sending data"),!0;this.sendingData=!0,this.log.trace("processing send queue with %d queued bytes",this.writeBuffer.byteLength);try{let e=!0,t=this.writeBuffer.byteLength,n=0;for(;this.writeBuffer.byteLength>0;){let o=Math.min(this.maxMessageSize??this.writeBuffer.byteLength,this.writeBuffer.byteLength);if(o===0){e=!1;break}let s=this.writeBuffer.sublist(0,o),i=new me(s);this.writeBuffer.consume(s.byteLength);let a=this.sendData(s);if(e=a.canSendMore,n+=a.sentBytes,a.sentBytes!==i.byteLength&&(i.consume(a.sentBytes),this.writeBuffer.prepend(i)),!e)break}return e||(this.log.trace("sent %d/%d bytes, pausing sending because underlying stream is full, %d bytes left in the write buffer",n,t,this.writeBuffer.byteLength),this.writableNeedsDrain=!0,this.checkWriteBufferLength()),this.writeBuffer.byteLength===0&&this.safeDispatchEvent("idle"),e}finally{this.sendingData=!1}}dispatchReadBuffer(){try{if(this.listenerCount("message")===0){this.log.trace("not dispatching pause buffer as there are no listeners for the message event");return}if(this.readBuffer.byteLength===0){this.log.trace("not dispatching pause buffer as there is no data to dispatch");return}if(this.readStatus==="paused"){this.log.trace("not dispatching pause buffer we are paused");return}if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("dropping %d bytes because the readable end is %s",this.readBuffer.byteLength,this.readStatus),this.readBuffer.consume(this.readBuffer.byteLength);return}let e=this.readBuffer.sublist();this.readBuffer.consume(e.byteLength),this.dispatchEvent(new Oe(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 ge(`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 ge(`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 nt=class extends rt{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 pr(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 pr(this,"drain",{...e,rejectionEvents:["close"]})),await this.sendClose(e),this.onTransportClosed())}};function _s(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 yn=_s;function Bs(r){return r[Symbol.asyncIterator]!=null}function Us(r,e){let t=0;if(Bs(r))return(async function*(){for await(let c of r)yield e(c,t++)})();let n=yn(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 En=Us;var mr=class extends nt{localPushable;constructor(e){super(e),this.localPushable=e.localPushable,Promise.resolve().then(async()=>{for await(let t of En(e.remotePushable,async n=>(e.connection.latency>0&&await Ye(e.connection.latency),n)))this.onData(t);this.onTransportClosed()}).catch(t=>{this.abort(t)})}sendReset(){this.localPushable.end(new ee)}sendData(e){return this.localPushable.push(e),{sentBytes:e.byteLength,canSendMore:!0}}async sendClose(e){this.localPushable.end(),e?.signal?.throwIfAborted()}sendPause(){}sendResume(){}};function br(r){return new mr(r)}var be=new Map,gr=0,ot=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=Le({onEnd(l){s=!0,o.connections.delete(f),i||c.end(l)}}),c=Le({onEnd(l){i=!0,o.connections.delete(h),s||a.end(l)}}),f=br({connection:this,remoteAddr:Ie(`${this.init.address}/p2p/${this.components.peerId}`),direction:"outbound",localPushable:a,remotePushable:c,log:t.newScope(`connection:${gr}`),maxMessageSize:this.init.maxMessageSize??65536}),h=br({connection:this,remoteAddr:Ie(`${this.init.address}-outgoing/p2p/${e}`),direction:"inbound",localPushable:c,remotePushable:a,log:this.log.newScope(`connection:${gr}`),maxMessageSize:this.init.maxMessageSize??65536});return this.connections.add(f),this.connections.add(h),gr++,await mn(Ye(this.latency),n),this.init.onConnection(h),f}close(){[...this.connections].forEach(e=>{e.abort(new Z("Memory Connection closed"))})}};var vn="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";var Cn=(r=21)=>{let e="",t=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)e+=vn[t[r]&63];return e};var st=class extends re{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??Cn()}`;if(n!=null&&be.has(o))throw new Pe(`Memory address ${o} already in use`);this.connection=new ot(this.components,{...this.init,onConnection:this.onConnection.bind(this),address:o}),this.listenAddr=Ie(o),be.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&&be.delete(this.listenAddr.toString()),this.shutdownController.abort(),queueMicrotask(()=>{this.safeDispatchEvent("close")})}};var it=class{components;init;constructor(e,t={}){this.components=e,this.init=t}[wr]=!0;[Symbol.toStringTag]="@libp2p/memory";[yr]=["@libp2p/transport"];async dial(e,t){t.signal.throwIfAborted();let n=e.getComponents().find(i=>i.code===421)?.value,o=be.get(`${n==null?e:e.decapsulate("/p2p")}`);if(o==null)throw new Z(`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 st(this.components,{...e,...this.init})}listenFilter(e){return e.filter(t=>dn.exactMatch(t))}dialFilter(e){return this.listenFilter(e)}};function Rs(r){return e=>new it(e,r)}return Ln(Ms);})();
3
3
  return Libp2PMemory}));
4
4
  //# sourceMappingURL=index.min.js.map