@libp2p/webrtc 4.1.1-151bc46fb → 4.1.1-3319ff41e

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.min.js CHANGED
@@ -13,7 +13,7 @@ if (cid) {
13
13
  // Make sure to use cid instead of value
14
14
  doSomethingWithCID(cid)
15
15
  }
16
- `});var l0=re(()=>{c0();Bi();dr();Pl();Ao()});var Vl,b6,u0=re(()=>{Pp();Mp();Fp();Vp();Hp();Cl();Kp();_l();$p();Wp();e0();n0();o0();s0();l0();Vl={...vl,...Al,...Dl,...Sl,...Bl,...kl,...Il,...Tl,...Rl,...Nl},b6={...Ml,...Fl}});function Tn(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}var Ti=re(()=>{});function _i(r=0){return globalThis.Buffer!=null&&globalThis.Buffer.allocUnsafe!=null?Tn(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}var Hl=re(()=>{Ti()});function h0(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var f0,Kl,P2,Ri,$l=re(()=>{u0();Hl();f0=h0("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Kl=h0("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=_i(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),P2={utf8:f0,"utf-8":f0,hex:Vl.base16,latin1:Kl,ascii:Kl,binary:Kl,...Vl},Ri=P2});var d0={};Q(d0,{toString:()=>M2});function M2(r,e="utf8"){let t=Ri[e];if(!t)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}var p0=re(()=>{$l()});var m0={};Q(m0,{fromString:()=>F2});function F2(r,e="utf8"){let t=Ri[e];if(!t)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?Tn(globalThis.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}var g0=re(()=>{$l();Ti()});var b0={};Q(b0,{concat:()=>V2});function V2(r,e){e||(e=r.reduce((o,s)=>o+s.length,0));let t=_i(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return Tn(t)}var y0=re(()=>{Hl();Ti()});var Wl=Ke((T6,D0)=>{"use strict";var w0=gp(),_n=kp(),{names:So}=Ip(),{toString:Ni}=(p0(),Co(d0)),{fromString:H2}=(g0(),Co(m0)),{concat:K2}=(y0(),Co(b0)),Rn={};for(let r in So){let e=r;Rn[So[e]]=e}Object.freeze(Rn);function $2(r){if(!(r instanceof Uint8Array))throw new Error("must be passed a Uint8Array");return Ni(r,"base16")}function q2(r){return H2(r,"base16")}function W2(r){if(!(r instanceof Uint8Array))throw new Error("must be passed a Uint8Array");return Ni(w0.encode("base58btc",r)).slice(1)}function z2(r){let e=r instanceof Uint8Array?Ni(r):r;return w0.decode("z"+e)}function x0(r){if(!(r instanceof Uint8Array))throw new Error("multihash must be a Uint8Array");if(r.length<2)throw new Error("multihash too short. must be > 2 bytes.");let e=_n.decode(r);if(!v0(e))throw new Error(`multihash unknown function code: 0x${e.toString(16)}`);r=r.slice(_n.decode.bytes);let t=_n.decode(r);if(t<0)throw new Error(`multihash invalid length: ${t}`);if(r=r.slice(_n.decode.bytes),r.length!==t)throw new Error(`multihash length inconsistent: 0x${Ni(r,"base16")}`);return{code:e,name:Rn[e],length:t,digest:r}}function G2(r,e,t){if(!r||e===void 0)throw new Error("multihash encode requires at least two args: digest, code");let n=E0(e);if(!(r instanceof Uint8Array))throw new Error("digest should be a Uint8Array");if(t==null&&(t=r.length),t&&r.length!==t)throw new Error("digest length should be equal to specified length.");let o=_n.encode(n),s=_n.encode(t);return K2([o,s,r],o.length+s.length+r.length)}function E0(r){let e=r;if(typeof r=="string"){if(So[r]===void 0)throw new Error(`Unrecognized hash function named: ${r}`);e=So[r]}if(typeof e!="number")throw new Error(`Hash function code should be a number. Got: ${e}`);if(Rn[e]===void 0&&!ql(e))throw new Error(`Unrecognized function code: ${e}`);return e}function ql(r){return r>0&&r<16}function v0(r){return!!(ql(r)||Rn[r])}function A0(r){x0(r)}function j2(r){return A0(r),r.subarray(0,2)}D0.exports={names:So,codes:Rn,toHexString:$2,fromHexString:q2,toB58String:W2,fromB58String:z2,decode:x0,encode:G2,coerceCode:E0,isAppCode:ql,validate:A0,prefix:j2,isValidCode:v0}});var o1={};Q(o1,{webRTC:()=>n1,webRTCDirect:()=>r1});var Pi=Symbol.for("@libp2p/peer-id");var Io=Symbol.for("@libp2p/transport");var ou;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(ou||(ou={}));var L=class extends Error{code;props;constructor(e,t,n){super(e),this.code=t,this.name=n?.name??"CodeError",this.props=n??{}}};var To=(r,...e)=>{try{[...e]}catch{}};var _o=class extends EventTarget{#e=new Map;constructor(){super(),To(1/0,this)}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 z0(e,t))}},Mi=class extends Event{detail;constructor(e,t){super(e,t),this.detail=t?.detail}},z0=globalThis.CustomEvent??Mi;var Hr=Symbol.for("@libp2p/service-capabilities"),su=Symbol.for("@libp2p/service-dependencies");var $i={};Q($i,{base58btc:()=>ge,base58flickr:()=>J0});var U1=new Uint8Array(0);function iu(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 Ct(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 au(r){return new TextEncoder().encode(r)}function cu(r){return new TextDecoder().decode(r)}function G0(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),u=Math.log(256)/Math.log(a);function f(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var h=0,p=0,y=0,E=d.length;y!==E&&d[y]===0;)y++,h++;for(var b=(E-y)*u+1>>>0,v=new Uint8Array(b);y!==E;){for(var x=d[y],D=0,A=b-1;(x!==0||D<p)&&A!==-1;A--,D++)x+=256*v[A]>>>0,v[A]=x%a>>>0,x=x/a>>>0;if(x!==0)throw new Error("Non-zero carry");p=D,y++}for(var S=b-p;S!==b&&v[S]===0;)S++;for(var _=c.repeat(h);S<b;++S)_+=r.charAt(v[S]);return _}function g(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var h=0;if(d[h]!==" "){for(var p=0,y=0;d[h]===c;)p++,h++;for(var E=(d.length-h)*l+1>>>0,b=new Uint8Array(E);d[h];){var v=t[d.charCodeAt(h)];if(v===255)return;for(var x=0,D=E-1;(v!==0||x<y)&&D!==-1;D--,x++)v+=a*b[D]>>>0,b[D]=v%256>>>0,v=v/256>>>0;if(v!==0)throw new Error("Non-zero carry");y=x,h++}if(d[h]!==" "){for(var A=E-y;A!==E&&b[A]===0;)A++;for(var S=new Uint8Array(p+(E-A)),_=p;A!==E;)S[_++]=b[A++];return S}}}function m(d){var h=g(d);if(h)return h;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:g,decode:m}}var j0=G0,Y0=j0,uu=Y0;var Fi=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")}},Vi=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),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 fu(this,e)}},Hi=class{decoders;constructor(e){this.decoders=e}or(e){return fu(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 fu(r,e){return new Hi({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Ki=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 Fi(e,t,n),this.decoder=new Vi(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Kr({name:r,prefix:e,encode:t,decode:n}){return new Ki(r,e,t,n)}function Yt({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=uu(t,r);return Kr({prefix:e,name:r,encode:n,decode:s=>Ct(o(s))})}function Z0(r,e,t,n){let o={};for(let u=0;u<e.length;++u)o[e[u]]=u;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*t/8|0),a=0,c=0,l=0;for(let u=0;u<s;++u){let f=o[r[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<t|f,a+=t,a>=8&&(a-=8,i[l++]=255&c>>a)}if(a>=t||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return i}function X0(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;)s+="=";return s}function de({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return Kr({prefix:e,name:r,encode(o){return X0(o,n,t)},decode(o){return Z0(o,n,t,r)}})}var ge=Yt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),J0=Yt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var qi={};Q(qi,{base10:()=>Q0});var Q0=Yt({prefix:"9",name:"base10",alphabet:"0123456789"});var Wi={};Q(Wi,{base16:()=>em,base16upper:()=>tm});var em=de({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),tm=de({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var zi={};Q(zi,{base2:()=>rm});var rm=de({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Gi={};Q(Gi,{base256emoji:()=>am});var hu=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}"),nm=hu.reduce((r,e,t)=>(r[t]=e,r),[]),om=hu.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function sm(r){return r.reduce((e,t)=>(e+=nm[t],e),"")}function im(r){let e=[];for(let t of r){let n=om[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var am=Kr({prefix:"\u{1F680}",name:"base256emoji",encode:sm,decode:im});var ji={};Q(ji,{base32:()=>It,base32hex:()=>fm,base32hexpad:()=>dm,base32hexpadupper:()=>pm,base32hexupper:()=>hm,base32pad:()=>lm,base32padupper:()=>um,base32upper:()=>cm,base32z:()=>mm});var It=de({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),cm=de({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),lm=de({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),um=de({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),fm=de({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),hm=de({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),dm=de({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),pm=de({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),mm=de({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Yi={};Q(Yi,{base36:()=>gm,base36upper:()=>bm});var gm=Yt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),bm=Yt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ji={};Q(Ji,{base64:()=>Zi,base64pad:()=>ym,base64url:()=>Xi,base64urlpad:()=>wm});var Zi=de({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ym=de({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Xi=de({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),wm=de({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Qi={};Q(Qi,{base8:()=>xm});var xm=de({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ea={};Q(ea,{identity:()=>Em});var Em=Kr({prefix:"\0",name:"identity",encode:r=>cu(r),decode:r=>au(r)});var X1=new TextEncoder,J1=new TextDecoder;var ra={};Q(ra,{identity:()=>Tt});var Dm=mu,du=128,Sm=127,Bm=~Sm,km=Math.pow(2,31);function mu(r,e,t){e=e||[],t=t||0;for(var n=t;r>=km;)e[t++]=r&255|du,r/=128;for(;r&Bm;)e[t++]=r&255|du,r>>>=7;return e[t]=r|0,mu.bytes=t-n+1,e}var Cm=ta,Im=128,pu=127;function ta(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw ta.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&pu)<<o:(i&pu)*Math.pow(2,o),o+=7}while(i>=Im);return ta.bytes=s-n,t}var Tm=Math.pow(2,7),_m=Math.pow(2,14),Rm=Math.pow(2,21),Nm=Math.pow(2,28),Lm=Math.pow(2,35),Um=Math.pow(2,42),Om=Math.pow(2,49),Pm=Math.pow(2,56),Mm=Math.pow(2,63),Fm=function(r){return r<Tm?1:r<_m?2:r<Rm?3:r<Nm?4:r<Lm?5:r<Um?6:r<Om?7:r<Pm?8:r<Mm?9:10},Vm={encode:Dm,decode:Cm,encodingLength:Fm},Hm=Vm,Ln=Hm;function Un(r,e=0){return[Ln.decode(r,e),Ln.decode.bytes]}function $r(r,e,t=0){return Ln.encode(r,e,t),e}function qr(r){return Ln.encodingLength(r)}function bt(r,e){let t=e.byteLength,n=qr(r),o=n+qr(t),s=new Uint8Array(o+t);return $r(r,s,0),$r(t,s,n),s.set(e,o),new Wr(r,t,e,s)}function gr(r){let e=Ct(r),[t,n]=Un(e),[o,s]=Un(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Wr(t,o,i,e)}function gu(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&iu(r.bytes,t.bytes)}}var Wr=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};var bu=0,Km="identity",yu=Ct;function $m(r){return bt(bu,yu(r))}var Tt={code:bu,name:Km,encode:yu,digest:$m};var sa={};Q(sa,{sha256:()=>_e,sha512:()=>qm});function oa({name:r,code:e,encode:t}){return new na(r,e,t)}var na=class{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?bt(this.code,t):t.then(n=>bt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function xu(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var _e=oa({name:"sha2-256",code:18,encode:xu("SHA-256")}),qm=oa({name:"sha2-512",code:19,encode:xu("SHA-512")});function Eu(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return zm(t,ia(r),e??ge.encoder);default:return Gm(t,ia(r),e??It.encoder)}}var vu=new WeakMap;function ia(r){let e=vu.get(r);if(e==null){let t=new Map;return vu.set(r,t),t}return e}var Xe=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!==On)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==jm)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=bt(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&&gu(e.multihash,n.multihash)}toString(e){return Eu(this,e)}toJSON(){return{"/":Eu(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??Au(n,o,s.bytes))}else if(t[Ym]===!0){let{version:n,multihash:o,code:s}=t,i=gr(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!==On)throw new Error(`Version 0 CID must use dag-pb (code: ${On}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=Au(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,On,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=Ct(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 Wr(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[f,g]=Un(e.subarray(t));return t+=g,f},o=n(),s=On;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,u=l-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:u,size:l}}static parse(e,t){let[n,o]=Wm(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 ia(s).set(n,e),s}};function Wm(r,e){switch(r[0]){case"Q":{let t=e??ge;return[ge.prefix,t.decode(`${ge.prefix}${r}`)]}case ge.prefix:{let t=e??ge;return[ge.prefix,t.decode(r)]}case It.prefix:{let t=e??It;return[It.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function zm(r,e,t){let{prefix:n}=t;if(n!==ge.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 Gm(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 On=112,jm=18;function Au(r,e,t){let n=qr(r),o=n+qr(e),s=new Uint8Array(o+t.byteLength);return $r(r,s,0),$r(e,s,n),s.set(t,o),s}var Ym=Symbol.for("@ipld/js-cid/CID");var yt={...ea,...zi,...Qi,...qi,...Wi,...ji,...Yi,...$i,...Ji,...Gi},wE={...sa,...ra};function Ae(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 De(r=0){return new Uint8Array(r)}function Se(r=0){return new Uint8Array(r)}function Su(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Du=Su("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),aa=Su("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=Se(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Zm={utf8:Du,"utf-8":Du,hex:yt.base16,latin1:aa,ascii:aa,binary:aa,...yt},No=Zm;function J(r,e="utf8"){let t=No[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function W(r,e="utf8"){let t=No[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var ku=Symbol.for("nodejs.util.inspect.custom"),Bu=Object.values(yt).map(r=>r.decoder).reduce((r,e)=>r.or(e),yt.identity.decoder),Cu=114,ua=36,fa=37,Pn=class{type;multihash;privateKey;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,this.privateKey=e.privateKey,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Pi]=!0;toString(){return this.string==null&&(this.string=ge.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return Xe.createV1(Cu,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return Ae(this.multihash.bytes,e);if(typeof e=="string")return yr(e).equals(this);if(e?.multihash?.bytes!=null)return Ae(this.multihash.bytes,e.multihash.bytes);throw new Error("not valid Id")}[ku](){return`PeerId(${this.toString()})`}},zr=class extends Pn{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Gr=class extends Pn{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.multihash.digest}},jr=class extends Pn{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.multihash.digest}},ca=2336,la=class{type="url";multihash;privateKey;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Tt.digest(J(this.url))}[ku](){return`PeerId(${this.url})`}[Pi]=!0;toString(){return this.toCID().toString()}toCID(){return Xe.createV1(ca,this.multihash)}toBytes(){return this.toCID().bytes}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=W(e)),e.toString()===this.toString())}};function yr(r,e){if(e=e??Bu,r.charAt(0)==="1"||r.charAt(0)==="Q"){let t=gr(ge.decode(`z${r}`));return r.startsWith("12D")?new Gr({multihash:t}):r.startsWith("16U")?new jr({multihash:t}):new zr({multihash:t})}return Xm(Bu.decode(r))}function Xm(r){try{let e=gr(r);if(e.code===Tt.code){if(e.digest.length===ua)return new Gr({multihash:e});if(e.digest.length===fa)return new jr({multihash:e})}if(e.code===_e.code)return new zr({multihash:e})}catch{return Jm(Xe.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function Jm(r){if(r==null||r.multihash==null||r.version==null||r.version===1&&r.code!==Cu&&r.code!==ca)throw new Error("Supplied PeerID CID is invalid");if(r.code===ca){let t=W(r.multihash.digest);return new la(new URL(t))}let e=r.multihash;if(e.code===_e.code)return new zr({multihash:r.multihash});if(e.code===Tt.code){if(e.digest.length===ua)return new Gr({multihash:r.multihash});if(e.digest.length===fa)return new jr({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function ha(r,e){return r.length===ua?new Gr({multihash:bt(Tt.code,r),privateKey:e}):r.length===fa?new jr({multihash:bt(Tt.code,r),privateKey:e}):new zr({multihash:await _e.digest(r),publicKey:r,privateKey:e})}var eg=Math.pow(2,7),tg=Math.pow(2,14),rg=Math.pow(2,21),da=Math.pow(2,28),pa=Math.pow(2,35),ma=Math.pow(2,42),ga=Math.pow(2,49),ne=128,Pe=127;function we(r){if(r<eg)return 1;if(r<tg)return 2;if(r<rg)return 3;if(r<da)return 4;if(r<pa)return 5;if(r<ma)return 6;if(r<ga)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ba(r,e,t=0){switch(we(r)){case 8:e[t++]=r&255|ne,r/=128;case 7:e[t++]=r&255|ne,r/=128;case 6:e[t++]=r&255|ne,r/=128;case 5:e[t++]=r&255|ne,r/=128;case 4:e[t++]=r&255|ne,r>>>=7;case 3:e[t++]=r&255|ne,r>>>=7;case 2:e[t++]=r&255|ne,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function ng(r,e,t=0){switch(we(r)){case 8:e.set(t++,r&255|ne),r/=128;case 7:e.set(t++,r&255|ne),r/=128;case 6:e.set(t++,r&255|ne),r/=128;case 5:e.set(t++,r&255|ne),r/=128;case 4:e.set(t++,r&255|ne),r>>>=7;case 3:e.set(t++,r&255|ne),r>>>=7;case 2:e.set(t++,r&255|ne),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function ya(r,e){let t=r[e],n=0;if(n+=t&Pe,t<ne||(t=r[e+1],n+=(t&Pe)<<7,t<ne)||(t=r[e+2],n+=(t&Pe)<<14,t<ne)||(t=r[e+3],n+=(t&Pe)<<21,t<ne)||(t=r[e+4],n+=(t&Pe)*da,t<ne)||(t=r[e+5],n+=(t&Pe)*pa,t<ne)||(t=r[e+6],n+=(t&Pe)*ma,t<ne)||(t=r[e+7],n+=(t&Pe)*ga,t<ne))return n;throw new RangeError("Could not decode varint")}function og(r,e){let t=r.get(e),n=0;if(n+=t&Pe,t<ne||(t=r.get(e+1),n+=(t&Pe)<<7,t<ne)||(t=r.get(e+2),n+=(t&Pe)<<14,t<ne)||(t=r.get(e+3),n+=(t&Pe)<<21,t<ne)||(t=r.get(e+4),n+=(t&Pe)*da,t<ne)||(t=r.get(e+5),n+=(t&Pe)*pa,t<ne)||(t=r.get(e+6),n+=(t&Pe)*ma,t<ne)||(t=r.get(e+7),n+=(t&Pe)*ga,t<ne))return n;throw new RangeError("Could not decode varint")}function wt(r,e,t=0){return e==null&&(e=Se(we(r))),e instanceof Uint8Array?ba(r,e,t):ng(r,e,t)}function nt(r,e=0){return r instanceof Uint8Array?ya(r,e):og(r,e)}function xe(r,e){e==null&&(e=r.reduce((o,s)=>o+s.length,0));let t=Se(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var Lo=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 u=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let g=Number.parseInt(f,e);if(!Number.isNaN(g))return g});if(u===void 0)break;if(s*=e,s+=u,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 Iu=45,ig=15,Yr=new Lo;function wa(r){if(!(r.length>ig))return Yr.new(r).parseWith(()=>Yr.readIPv4Addr())}function xa(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Iu))return Yr.new(r).parseWith(()=>Yr.readIPv6Addr())}function Uo(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Iu))return Yr.new(r).parseWith(()=>Yr.readIPAddr())}var QE=parseInt("0xFFFF",16),e8=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Oo(r){return!!wa(r)}function Po(r){return!!xa(r)}function Mo(r){return!!Uo(r)}var Ru=Oo,fg=Po,Ea=function(r){let e=0;if(r=r.toString().trim(),Ru(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(fg(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let s=Ru(t[n]),i;s&&(i=Ea(t[n]),t[n]=W(i.slice(0,2),"base16")),i!=null&&++n<8&&t.splice(n,0,W(i.slice(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++){let s=parseInt(t[n],16);o[e++]=s>>8&255,o[e++]=s&255}return o}throw new Error("invalid ip address")},Nu=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let o=[];for(let s=0;s<t;s++)o.push(r[e+s]);return o.join(".")}if(t===16){let o=[];for(let s=0;s<t;s+=2)o.push(n.getUint16(e+s).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var Zr={},va={},dg=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,-1,"http-path"],[777,-1,"memory"]];dg.forEach(r=>{let e=pg(...r);va[e.code]=e,Zr[e.name]=e});function pg(r,e,t,n,o){return{code:r,size:e,name:t,resolvable:!!n,path:!!o}}function oe(r){if(typeof r=="number"){if(va[r]!=null)return va[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(Zr[r]!=null)return Zr[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var P8=oe("ip4"),M8=oe("ip6"),F8=oe("ipcidr");function Ba(r,e){switch(oe(r).code){case 4:case 41:return gg(e);case 42:return Sa(e);case 6:case 273:case 33:case 132:return Ou(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Sa(e);case 421:return xg(e);case 444:return Uu(e);case 445:return Uu(e);case 466:return wg(e);case 481:return globalThis.encodeURIComponent(Sa(e));default:return W(e,"base16")}}function ka(r,e){switch(oe(r).code){case 4:return Lu(e);case 41:return Lu(e);case 42:return Da(e);case 6:case 273:case 33:case 132:return Ca(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Da(e);case 421:return bg(e);case 444:return Eg(e);case 445:return vg(e);case 466:return yg(e);case 481:return Da(globalThis.decodeURIComponent(e));default:return J(e,"base16")}}var Aa=Object.values(yt).map(r=>r.decoder),mg=function(){let r=Aa[0].or(Aa[1]);return Aa.slice(2).forEach(e=>r=r.or(e)),r}();function Lu(r){if(!Mo(r))throw new Error("invalid ip address");return Ea(r)}function gg(r){let e=Nu(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!Mo(e))throw new Error("invalid ip address");return e}function Ca(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function Ou(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Da(r){let e=J(r),t=Uint8Array.from(wt(e.length));return xe([t,e],t.length+e.length)}function Sa(r){let e=nt(r);if(r=r.slice(we(e)),r.length!==e)throw new Error("inconsistent lengths");return W(r)}function bg(r){let e;r[0]==="Q"||r[0]==="1"?e=gr(ge.decode(`z${r}`)).bytes:e=Xe.parse(r).multihash.bytes;let t=Uint8Array.from(wt(e.length));return xe([t,e],t.length+e.length)}function yg(r){let e=mg.decode(r),t=Uint8Array.from(wt(e.length));return xe([t,e],t.length+e.length)}function wg(r){let e=nt(r),t=r.slice(we(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+W(t,"base64url")}function xg(r){let e=nt(r),t=r.slice(we(e));if(t.length!==e)throw new Error("inconsistent lengths");return W(t,"base58btc")}function Eg(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=It.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=Ca(n);return xe([t,o],t.length+o.length)}function vg(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=It.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=Ca(n);return xe([t,o],t.length+o.length)}function Uu(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=W(e,"base32"),o=Ou(t);return`${n}:${o}`}function Pu(r){r=Ia(r);let e=[],t=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let s=0;s<o.length;s++){let i=o[s],a=oe(i);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(s++,s>=o.length)throw Fu("invalid address: "+r);if(a.path===!0){n=Ia(o.slice(s).join("/")),e.push([a.code,ka(a.code,n)]),t.push([a.code,n]);break}let c=ka(a.code,o[s]);e.push([a.code,c]),t.push([a.code,Ba(a.code,c)])}return{string:Mu(t),bytes:_a(e),tuples:e,stringTuples:t,path:n}}function Ta(r){let e=[],t=[],n=null,o=0;for(;o<r.length;){let s=nt(r,o),i=we(s),a=oe(s),c=Ag(a,r.slice(o+i));if(c===0){e.push([s]),t.push([s]),o+=i;continue}let l=r.slice(o+i,o+i+c);if(o+=c+i,o>r.length)throw Fu("Invalid address Uint8Array: "+W(r,"base16"));e.push([s,l]);let u=Ba(s,l);if(t.push([s,u]),a.path===!0){n=u;break}}return{bytes:Uint8Array.from(r),string:Mu(t),tuples:e,stringTuples:t,path:n}}function Mu(r){let e=[];return r.map(t=>{let n=oe(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),Ia(e.join("/"))}function _a(r){return xe(r.map(e=>{let t=oe(e[0]),n=Uint8Array.from(wt(t.code));return e.length>1&&e[1]!=null&&(n=xe([n,e[1]])),n}))}function Ag(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=nt(e instanceof Uint8Array?e:Uint8Array.from(e));return t+we(t)}}function Ia(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}function Fu(r){return new Error("Error parsing address: "+r)}var Dg=Symbol.for("nodejs.util.inspect.custom"),Ra=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Sg=[oe("dns").code,oe("dns4").code,oe("dns6").code,oe("dnsaddr").code],Fo=class r{bytes;#e;#t;#r;#n;[Ra]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=Ta(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=Pu(e)}else if(Hu(e))t=Ta(e.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=t.bytes,this.#e=t.string,this.#t=t.tuples,this.#r=t.stringTuples,this.#n=t.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let e,t,n,o,s="",i=oe("tcp"),a=oe("udp"),c=oe("ip4"),l=oe("ip6"),u=oe("dns6"),f=oe("ip6zone");for(let[m,d]of this.stringTuples())m===f.code&&(s=`%${d??""}`),Sg.includes(m)&&(t=i.name,o=443,n=`${d??""}${s}`,e=m===u.code?6:4),(m===i.code||m===a.code)&&(t=oe(m).name,o=parseInt(d??"")),(m===c.code||m===l.code)&&(t=oe(m).name,n=`${d??""}${s}`,e=m===l.code?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}}protos(){return this.#t.map(([e])=>Object.assign({},oe(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>oe(e).name)}tuples(){return this.#t}stringTuples(){return this.#r}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,o))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(_a(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,o])=>{n===Zr.p2p.code&&e.push([n,o]),n===Zr["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?W(ge.decode(`z${n}`),"base58btc"):W(Xe.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(e){return Ae(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(s=>s.resolvable);if(t==null)return[this];let n=Vu.get(t.name);if(n==null)throw new L(`no available resolver for ${t.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,e)).map(s=>ot(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(e){let t=(e??this).protos();return!(t.length!==2||t[0].code!==4&&t[0].code!==41||t[1].code!==6&&t[1].code!==273)}[Dg](){return`Multiaddr(${this.#e})`}};var Vu=new Map;function Hu(r){return!!r?.[Ra]}function ot(r){return new Fo(r)}var Bg=r=>r.toString().split("/").slice(1),Fn=r=>({match:e=>e.length<1?!1:r(e[0])?e.slice(1):!1,pattern:"fn"}),ee=r=>({match:e=>Fn(t=>t===r).match(e),pattern:r}),Ko=()=>({match:r=>Fn(e=>typeof e=="string").match(r),pattern:"{string}"}),$o=()=>({match:r=>Fn(e=>!isNaN(parseInt(e))).match(r),pattern:"{number}"}),Re=()=>({match:r=>{if(r.length<2||r[0]!=="p2p"&&r[0]!=="ipfs")return!1;if(r[1].startsWith("Q")||r[1].startsWith("1"))try{ge.decode(`z${r[1]}`)}catch{return!1}else return!1;return r.slice(2)},pattern:"/p2p/{peerid}"}),Vo=()=>({match:r=>{if(r.length<2||r[0]!=="certhash")return!1;try{Xi.decode(r[1])}catch{return!1}return r.slice(2)},pattern:"/certhash/{certhash}"}),Be=r=>({match:e=>{let t=r.match(e);return t===!1?e:t},pattern:`optional(${r.pattern})`}),Je=(...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},pattern:`or(${r.map(e=>e.pattern).join(", ")})`}),ie=(...r)=>({match:e=>{for(let t of r){let n=t.match(e);if(n===!1)return!1;e=n}return e},pattern:`and(${r.map(e=>e.pattern).join(", ")})`});function be(...r){function e(o){let s=Bg(o);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{matches:t,exactMatch:n}}var La=ie(ee("dns4"),Ko()),Ua=ie(ee("dns6"),Ko()),Oa=ie(ee("dnsaddr"),Ko()),Ku=ie(ee("dns"),Ko()),pv=be(La),mv=be(Ua),gv=be(Oa),bv=be(Je(Ku,Oa,La,Ua)),$u=ie(ee("ip4"),Fn(Oo)),qu=ie(ee("ip6"),Fn(Po)),Wu=Je($u,qu),xt=Je(Wu,Ku,La,Ua,Oa),yv=be(xt),wv=be($u),xv=be(qu),Ev=be(Wu),Pa=ie(xt,ee("tcp"),$o()),Vn=ie(xt,ee("udp"),$o()),vv=be(Pa),Av=be(Vn),Ma=ie(Vn,ee("quic")),qo=ie(Vn,ee("quic-v1")),kg=Je(Ma,qo),Dv=be(Ma),Sv=be(qo),Na=Je(xt,Pa,Vn,Ma,qo),zu=Je(ie(Na,ee("ws"),Be(Re()))),Bv=be(zu),Gu=Je(ie(Na,ee("wss"),Be(Re())),ie(Na,ee("tls"),ee("ws"),Be(Re()))),kv=be(Gu),ju=ie(Vn,ee("webrtc-direct"),Be(Vo()),Be(Vo()),Be(Re())),Yu=be(ju),Zu=ie(qo,ee("webtransport"),Be(Vo()),Be(Vo()),Be(Re())),Cv=be(Zu),Ho=Je(zu,Gu,ie(Pa,Be(Re())),ie(kg,Be(Re())),ie(xt,Be(Re())),ju,Zu,Re()),Iv=be(Ho),Cg=ie(Ho,ee("p2p-circuit"),Re()),Tv=be(Cg),Ig=Je(ie(Ho,ee("p2p-circuit"),ee("webrtc"),Be(Re())),ie(Ho,ee("webrtc"),Be(Re())),ee("webrtc")),Xu=be(Ig),Tg=Je(ie(xt,ee("tcp"),$o(),ee("http"),Be(Re())),ie(xt,ee("http"),Be(Re()))),_v=be(Tg),_g=Je(ie(xt,ee("tcp"),Je(ie(ee("443"),ee("http")),ie($o(),ee("https"))),Be(Re())),ie(xt,ee("tls"),ee("http"),Be(Re())),ie(xt,ee("https"),Be(Re()))),Rv=be(_g);var Ge;(function(r){r.ERR_ALREADY_ABORTED="ERR_ALREADY_ABORTED",r.ERR_DATA_CHANNEL="ERR_DATA_CHANNEL",r.ERR_CONNECTION_CLOSED="ERR_CONNECTION_CLOSED",r.ERR_HASH_NOT_SUPPORTED="ERR_HASH_NOT_SUPPORTED",r.ERR_INVALID_MULTIADDR="ERR_INVALID_MULTIADDR",r.ERR_INVALID_FINGERPRINT="ERR_INVALID_FINGERPRINT",r.ERR_INVALID_PARAMETERS="ERR_INVALID_PARAMETERS",r.ERR_NOT_IMPLEMENTED="ERR_NOT_IMPLEMENTED",r.ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS="ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS",r.ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS="ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS"})(Ge||(Ge={}));var Zt=class extends L{constructor(e,t){super(`WebRTC transport error: ${e}`,t??""),this.name="WebRTCTransportError"}};var Fa=class extends Zt{constructor(e,t){super(`[stream: ${e}] data channel error: ${t}`,Ge.ERR_DATA_CHANNEL),this.name="WebRTC/DataChannelError"}};function Wa(r,e){return new Fa(r,e)}var Va=class extends Zt{constructor(e){super(`There was a problem with the Multiaddr which was passed in: ${e}`,Ge.ERR_INVALID_MULTIADDR),this.name="WebRTC/InappropriateMultiaddrError"}};function Wo(r){return new Va(r)}var Ha=class extends Zt{constructor(e){super(`There was a problem with a provided argument: ${e}`,Ge.ERR_INVALID_PARAMETERS),this.name="WebRTC/InvalidArgumentError"}};function Hn(r){return new Ha(r)}var Ka=class extends Zt{constructor(e,t){super(`Invalid fingerprint "${e}" within ${t}`,Ge.ERR_INVALID_FINGERPRINT),this.name="WebRTC/InvalidFingerprintError"}};function za(r,e){return new Ka(r,e)}var $a=class extends Zt{constructor(e){super(`A method (${e}) was called though it has been intentionally left unimplemented.`,Ge.ERR_NOT_IMPLEMENTED),this.name="WebRTC/UnimplementedError"}};function Ju(r){return new $a(r)}var qa=class extends Zt{constructor(e){super(`unsupported hash algorithm: ${e}`,Ge.ERR_HASH_NOT_SUPPORTED),this.name="WebRTC/UnsupportedHashAlgorithmError"}};function Qu(r){return new qa(r)}var ef=function(r,e,t){if(t||arguments.length===2)for(var n=0,o=e.length,s;n<o;n++)(s||!(n in e))&&(s||(s=Array.prototype.slice.call(e,0,n)),s[n]=e[n]);return r.concat(s||Array.prototype.slice.call(e))},Rg=function(){function r(e,t,n){this.name=e,this.version=t,this.os=n,this.type="browser"}return r}();var Ng=function(){function r(e){this.version=e,this.type="node",this.name="node",this.os=process.platform}return r}();var Lg=function(){function r(e,t,n,o){this.name=e,this.version=t,this.os=n,this.bot=o,this.type="bot-device"}return r}();var Ug=function(){function r(){this.type="bot",this.bot=!0,this.name="bot",this.version=null,this.os=null}return r}();var Og=function(){function r(){this.type="react-native",this.name="react-native",this.version=null,this.os=null}return r}();var Pg=/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/,Mg=/(nuhk|curl|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask\ Jeeves\/Teoma|ia_archiver)/,tf=3,Fg=[["aol",/AOLShield\/([0-9\._]+)/],["edge",/Edge\/([0-9\._]+)/],["edge-ios",/EdgiOS\/([0-9\._]+)/],["yandexbrowser",/YaBrowser\/([0-9\._]+)/],["kakaotalk",/KAKAOTALK\s([0-9\.]+)/],["samsung",/SamsungBrowser\/([0-9\.]+)/],["silk",/\bSilk\/([0-9._-]+)\b/],["miui",/MiuiBrowser\/([0-9\.]+)$/],["beaker",/BeakerBrowser\/([0-9\.]+)/],["edge-chromium",/EdgA?\/([0-9\.]+)/],["chromium-webview",/(?!Chrom.*OPR)wv\).*Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["chrome",/(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["phantomjs",/PhantomJS\/([0-9\.]+)(:?\s|$)/],["crios",/CriOS\/([0-9\.]+)(:?\s|$)/],["firefox",/Firefox\/([0-9\.]+)(?:\s|$)/],["fxios",/FxiOS\/([0-9\.]+)/],["opera-mini",/Opera Mini.*Version\/([0-9\.]+)/],["opera",/Opera\/([0-9\.]+)(?:\s|$)/],["opera",/OPR\/([0-9\.]+)(:?\s|$)/],["pie",/^Microsoft Pocket Internet Explorer\/(\d+\.\d+)$/],["pie",/^Mozilla\/\d\.\d+\s\(compatible;\s(?:MSP?IE|MSInternet Explorer) (\d+\.\d+);.*Windows CE.*\)$/],["netfront",/^Mozilla\/\d\.\d+.*NetFront\/(\d.\d)/],["ie",/Trident\/7\.0.*rv\:([0-9\.]+).*\).*Gecko$/],["ie",/MSIE\s([0-9\.]+);.*Trident\/[4-7].0/],["ie",/MSIE\s(7\.0)/],["bb10",/BB10;\sTouch.*Version\/([0-9\.]+)/],["android",/Android\s([0-9\.]+)/],["ios",/Version\/([0-9\._]+).*Mobile.*Safari.*/],["safari",/Version\/([0-9\._]+).*Safari/],["facebook",/FB[AS]V\/([0-9\.]+)/],["instagram",/Instagram\s([0-9\.]+)/],["ios-webview",/AppleWebKit\/([0-9\.]+).*Mobile/],["ios-webview",/AppleWebKit\/([0-9\.]+).*Gecko\)$/],["curl",/^curl\/([0-9\.]+)$/],["searchbot",Pg]],rf=[["iOS",/iP(hone|od|ad)/],["Android OS",/Android/],["BlackBerry OS",/BlackBerry|BB10/],["Windows Mobile",/IEMobile/],["Amazon OS",/Kindle/],["Windows 3.11",/Win16/],["Windows 95",/(Windows 95)|(Win95)|(Windows_95)/],["Windows 98",/(Windows 98)|(Win98)/],["Windows 2000",/(Windows NT 5.0)|(Windows 2000)/],["Windows XP",/(Windows NT 5.1)|(Windows XP)/],["Windows Server 2003",/(Windows NT 5.2)/],["Windows Vista",/(Windows NT 6.0)/],["Windows 7",/(Windows NT 6.1)/],["Windows 8",/(Windows NT 6.2)/],["Windows 8.1",/(Windows NT 6.3)/],["Windows 10",/(Windows NT 10.0)/],["Windows ME",/Windows ME/],["Windows CE",/Windows CE|WinCE|Microsoft Pocket Internet Explorer/],["Open BSD",/OpenBSD/],["Sun OS",/SunOS/],["Chrome OS",/CrOS/],["Linux",/(Linux)|(X11)/],["Mac OS",/(Mac_PowerPC)|(Macintosh)/],["QNX",/QNX/],["BeOS",/BeOS/],["OS/2",/OS\/2/]];function of(r){return r?nf(r):typeof document>"u"&&typeof navigator<"u"&&navigator.product==="ReactNative"?new Og:typeof navigator<"u"?nf(navigator.userAgent):Kg()}function Vg(r){return r!==""&&Fg.reduce(function(e,t){var n=t[0],o=t[1];if(e)return e;var s=o.exec(r);return!!s&&[n,s]},!1)}function nf(r){var e=Vg(r);if(!e)return null;var t=e[0],n=e[1];if(t==="searchbot")return new Ug;var o=n[1]&&n[1].split(".").join("_").split("_").slice(0,3);o?o.length<tf&&(o=ef(ef([],o,!0),$g(tf-o.length),!0)):o=[];var s=o.join("."),i=Hg(r),a=Mg.exec(r);return a&&a[1]?new Lg(t,s,i,a[1]):new Rg(t,s,i)}function Hg(r){for(var e=0,t=rf.length;e<t;e++){var n=rf[e],o=n[0],s=n[1],i=s.exec(r);if(i)return o}return null}function Kg(){var r=typeof process<"u"&&process.version;return r?new Ng(process.version.slice(1)):null}function $g(r){for(var e=[],t=0;t<r;t++)e.push("0");return e}function pe(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var Xr=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Ga=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},sf=r=>globalThis.DOMException===void 0?new Ga(r):new DOMException(r),af=r=>{let e=r.reason===void 0?sf("This operation was aborted."):r.reason;return e instanceof Error?e:sf(e)};function wr(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=e,i,c=new Promise((l,u)=>{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:g}=e;g.aborted&&u(af(g)),g.addEventListener("abort",()=>{u(af(g))})}if(t===Number.POSITIVE_INFINITY){r.then(l,u);return}let f=new Xr;i=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(g){u(g)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?l():o instanceof Error?u(o):(f.message=o??`Promise timed out after ${t} milliseconds`,u(f))},t),(async()=>{try{l(await r)}catch(g){u(g)}})()}).finally(()=>{c.clear()});return c.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},c}var cf=["stun:stun.l.google.com:19302","stun:stun1.l.google.com:19302","stun:stun2.l.google.com:19302","stun:stun3.l.google.com:19302","stun:stun4.l.google.com:19302","stun:global.stun.twilio.com:3478","stun:stun.cloudflare.com:3478","stun:stun.services.mozilla.com:3478","stun:stun.1und1.de:3478"];var lf=of(),Kn=lf!=null&&lf.name==="firefox",zo=async function*(){},Go=async r=>{},qg=30*1e3;function uf(r,e,t=qg,n){r.readyState==="open"&&Promise.resolve().then(async()=>{if(r.bufferedAmount>0){n.log("%s drain channel with %d buffered bytes",e,r.bufferedAmount);let o=pe(),s=!1;r.bufferedAmountLowThreshold=0;let i=()=>{s||(n.log("%s drain channel closed before drain",e),o.resolve())};r.addEventListener("close",i,{once:!0}),r.addEventListener("bufferedamountlow",()=>{s=!0,r.removeEventListener("close",i),o.resolve()}),await wr(o.promise,{milliseconds:t})}}).then(async()=>{r.readyState==="open"&&r.close()}).catch(o=>{n.log.error("error closing outbound stream",o)})}async function $n(r){return r=r??{},typeof r=="function"&&(r=await r()),r.iceServers=r.iceServers??cf.map(e=>({urls:[e]})),r}var xr=class{log;peerConnection;remoteAddr;timeline;metrics;source=zo();sink=Go;constructor(e,t){this.log=e.logger.forComponent("libp2p:webrtc:maconn"),this.remoteAddr=t.remoteAddr,this.timeline=t.timeline,this.peerConnection=t.peerConnection;let n=this.peerConnection.connectionState;this.peerConnection.onconnectionstatechange=()=>{this.log.trace("peer connection state change",this.peerConnection.connectionState,"initial state",n),(this.peerConnection.connectionState==="disconnected"||this.peerConnection.connectionState==="failed"||this.peerConnection.connectionState==="closed")&&(this.timeline.close=Date.now())}}async close(e){this.log.trace("closing connection"),this.peerConnection.close(),this.timeline.close=Date.now(),this.metrics?.increment({close:!0})}abort(e){this.log.error("closing connection due to error",e),this.peerConnection.close(),this.timeline.close=Date.now(),this.metrics?.increment({abort:!0})}};var jo=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||e-1&e)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}},Jr=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new jo(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 jo(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 ja=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function Xt(r={}){return Wg(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 Wg(r,e){e=e??{};let t=e.onEnd,n=new Jr,o,s,i,a=pe(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((p,y)=>{s=E=>{s=null,n.push(E);try{p(r(n))}catch(b){y(b)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=pe()})}},l=p=>s!=null?s(p):(n.push(p),o),u=p=>(n=new Jr,s!=null?s({error:p}):(n.push({error:p}),o)),f=p=>{if(i)return o;if(e?.objectMode!==!0&&p?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:p})},g=p=>i?o:(i=!0,p!=null?u(p):l({done:!0})),m=()=>(n=new Jr,g(),{done:!0}),d=p=>(g(p),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:m,throw:d,push:f,end:g,get readableLength(){return n.size},onEmpty:async p=>{let y=p?.signal;if(y?.throwIfAborted(),n.isEmpty())return;let E,b;y!=null&&(E=new Promise((v,x)=>{b=()=>{x(new ja)},y.addEventListener("abort",b)}));try{await Promise.race([a.promise,E])}finally{b!=null&&y!=null&&y?.removeEventListener("abort",b)}}},t==null)return o;let h=o;return o={[Symbol.asyncIterator](){return this},next(){return h.next()},throw(p){return h.throw(p),t!=null&&(t(p),t=void 0),{done:!0}},return(){return h.return(),t!=null&&(t(),t=void 0),{done:!0}},push:f,end(p){return h.end(p),t!=null&&(t(p),t=void 0),o},get readableLength(){return h.readableLength},onEmpty:p=>h.onEmpty(p)},o}var Yo=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=t??"ABORT_ERR"}};async function _t(r,e,t){if(e==null)return r;if(e.aborted)return Promise.reject(new Yo(t?.errorMessage,t?.errorCode));let n,o=new Yo(t?.errorMessage,t?.errorCode);try{return await Promise.race([r,new Promise((s,i)=>{n=()=>{i(o)},e.addEventListener("abort",n)})])}finally{n!=null&&e.removeEventListener("abort",n)}}var hf=Symbol.for("@achingbrain/uint8arraylist");function ff(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 Zo(r){return!!r?.[hf]}var ue=class r{bufs;length;[hf]=!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(Zo(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(Zo(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=ff(this.bufs,e);return t.buf[t.index]}set(e,t){let n=ff(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(Zo(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 xe(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:xe(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,u=t>a&&t<=c;if(l&&u){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(u){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(!Zo(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,u;for(let f=t;f<=c;f+=u){u=0;for(let g=l;g>=0;g--){let m=this.get(f+g);if(n[g]!==m){u=Math.max(1,g-a[m]);break}}if(u===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=Se(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=De(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=De(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=De(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=Se(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=De(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=De(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=De(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=De(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=De(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(!Ae(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((o,s)=>o+s.byteLength,0)),n.length=t,n}};function df(r){if(r!=null){if(typeof r[Symbol.iterator]=="function")return r[Symbol.iterator]();if(typeof r[Symbol.asyncIterator]=="function")return r[Symbol.asyncIterator]();if(typeof r.next=="function")return r}throw new Error("argument is not an iterator or iterable")}function pf(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function mf(r,e){let t=df(r).return?.();pf(t)&&t.catch(n=>{e.error("could not cause iterator to return",n)})}var zg="ERR_STREAM_RESET",Gg="ERR_SINK_INVALID_STATE",jg=5e3;function Ya(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Xo=class{id;direction;timeline;protocol;metadata;source;status;readStatus;writeStatus;log;sinkController;sinkEnd;closed;endErr;streamSource;onEnd;onCloseRead;onCloseWrite;onReset;onAbort;sendCloseWriteTimeout;sendingData;constructor(e){this.sinkController=new AbortController,this.sinkEnd=pe(),this.closed=pe(),this.log=e.log,this.status="open",this.readStatus="ready",this.writeStatus="ready",this.id=e.id,this.metadata=e.metadata??{},this.direction=e.direction,this.timeline={open:Date.now()},this.sendCloseWriteTimeout=e.sendCloseWriteTimeout??jg,this.onEnd=e.onEnd,this.onCloseRead=e?.onCloseRead,this.onCloseWrite=e?.onCloseWrite,this.onReset=e?.onReset,this.onAbort=e?.onAbort,this.source=this.streamSource=Xt({onEnd:t=>{t!=null?this.log.trace("source ended with error",t):this.log.trace("source ended"),this.onSourceEnd(t)}}),this.sink=this.sink.bind(this)}async sink(e){if(this.writeStatus!=="ready")throw new L(`writable end state is "${this.writeStatus}" not "ready"`,Gg);try{this.writeStatus="writing";let t={signal:this.sinkController.signal};if(this.direction==="outbound"){let o=this.sendNewStream(t);Ya(o)&&await o}let n=()=>{mf(e,this.log)};try{this.sinkController.signal.addEventListener("abort",n),this.log.trace("sink reading from source");for await(let o of e){o=o instanceof Uint8Array?new ue(o):o;let s=this.sendData(o,t);Ya(s)&&(this.sendingData=pe(),await s,this.sendingData.resolve(),this.sendingData=void 0)}}finally{this.sinkController.signal.removeEventListener("abort",n)}this.log.trace('sink finished reading from source, write status is "%s"',this.writeStatus),this.writeStatus==="writing"&&(this.writeStatus="closing",this.log.trace("send close write to remote"),await this.sendCloseWrite({signal:AbortSignal.timeout(this.sendCloseWriteTimeout)}),this.writeStatus="closed"),this.onSinkEnd()}catch(t){throw this.log.trace("sink ended with error, calling abort with error",t),this.abort(t),t}finally{this.log.trace("resolve sink end"),this.sinkEnd.resolve()}}onSourceEnd(e){this.timeline.closeRead==null&&(this.timeline.closeRead=Date.now(),this.readStatus="closed",e!=null&&this.endErr==null&&(this.endErr=e),this.onCloseRead?.(),this.timeline.closeWrite!=null?(this.log.trace("source and sink ended"),this.timeline.close=Date.now(),this.status!=="aborted"&&this.status!=="reset"&&(this.status="closed"),this.onEnd!=null&&this.onEnd(this.endErr),this.closed.resolve()):this.log.trace("source ended, waiting for sink to end"))}onSinkEnd(e){this.timeline.closeWrite==null&&(this.timeline.closeWrite=Date.now(),this.writeStatus="closed",e!=null&&this.endErr==null&&(this.endErr=e),this.onCloseWrite?.(),this.timeline.closeRead!=null?(this.log.trace("sink and source ended"),this.timeline.close=Date.now(),this.status!=="aborted"&&this.status!=="reset"&&(this.status="closed"),this.onEnd!=null&&this.onEnd(this.endErr),this.closed.resolve()):this.log.trace("sink ended, waiting for source to end"))}async close(e){this.log.trace("closing gracefully"),this.status="closing",await _t(Promise.all([this.closeWrite(e),this.closeRead(e),this.closed.promise]),e?.signal),this.status="closed",this.log.trace("closed gracefully")}async closeRead(e={}){if(this.readStatus==="closing"||this.readStatus==="closed")return;this.log.trace('closing readable end of stream with starting read status "%s"',this.readStatus);let t=this.readStatus;this.readStatus="closing",this.status!=="reset"&&this.status!=="aborted"&&this.timeline.closeRead==null&&(this.log.trace("send close read to remote"),await this.sendCloseRead(e)),t==="ready"&&(this.log.trace("ending internal source queue with %d queued bytes",this.streamSource.readableLength),this.streamSource.end()),this.log.trace("closed readable end of stream")}async closeWrite(e={}){this.writeStatus==="closing"||this.writeStatus==="closed"||(this.log.trace('closing writable end of stream with starting write status "%s"',this.writeStatus),this.writeStatus==="ready"&&(this.log.trace("sink was never sunk, sink an empty array"),await _t(this.sink([]),e.signal)),this.writeStatus==="writing"&&(this.sendingData!=null&&await _t(this.sendingData.promise,e.signal),this.log.trace("aborting source passed to .sink"),this.sinkController.abort(),await _t(this.sinkEnd.promise,e.signal)),this.writeStatus="closed",this.log.trace("closed writable end of stream"))}abort(e){if(this.status==="closed"||this.status==="aborted"||this.status==="reset")return;this.log("abort with error",e),this.log("try to send reset to remote");let t=this.sendReset();Ya(t)&&t.catch(n=>{this.log.error("error sending reset message",n)}),this.status="aborted",this.timeline.abort=Date.now(),this._closeSinkAndSource(e),this.onAbort?.(e)}reset(){if(this.status==="closed"||this.status==="aborted"||this.status==="reset")return;let e=new L("stream reset",zg);this.status="reset",this.timeline.reset=Date.now(),this._closeSinkAndSource(e),this.onReset?.()}_closeSinkAndSource(e){this._closeSink(e),this._closeSource(e)}_closeSink(e){this.writeStatus==="writing"&&(this.log.trace("end sink source"),this.sinkController.abort()),this.onSinkEnd(e)}_closeSource(e){this.readStatus!=="closing"&&this.readStatus!=="closed"&&(this.log.trace("ending source with %d bytes to be read by consumer",this.streamSource.readableLength),this.readStatus="closing",this.streamSource.end(e))}remoteCloseWrite(){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("received remote close write but local source is already closed");return}this.log.trace("remote close write"),this._closeSource()}remoteCloseRead(){if(this.writeStatus==="closing"||this.writeStatus==="closed"){this.log("received remote close read but local sink is already closed");return}this.log.trace("remote close read"),this._closeSink()}destroy(){if(this.status==="closed"||this.status==="aborted"||this.status==="reset"){this.log("received destroy but we are already closed");return}this.log.trace("stream destroyed"),this._closeSinkAndSource()}sourcePush(e){this.streamSource.push(e)}sourceReadableLength(){return this.streamSource.readableLength}};function Jo(r){return r[Symbol.asyncIterator]!=null}var Qo=r=>{let e=we(r),t=Se(e);return wt(r,t),Qo.bytes=e,t};Qo.bytes=0;function qn(r,e){e=e??{};let t=e.lengthEncoder??Qo;function*n(o){let s=t(o.byteLength);s instanceof Uint8Array?yield s:yield*s,o instanceof Uint8Array?yield o:yield*o}return Jo(r)?async function*(){for await(let o of r)yield*n(o)}():function*(){for(let o of r)yield*n(o)}()}qn.single=(r,e)=>{e=e??{};let t=e.lengthEncoder??Qo;return new ue(t(r.byteLength),r)};var Qr=ko(yf(),1);var Zg=8,Xg=1024*1024*4,Er;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(Er||(Er={}));var Za=r=>{let e=nt(r);return Za.bytes=we(e),e};Za.bytes=0;function vr(r,e){let t=new ue,n=Er.LENGTH,o=-1,s=e?.lengthDecoder??Za,i=e?.maxLengthLength??Zg,a=e?.maxDataLength??Xg;function*c(){for(;t.byteLength>0;){if(n===Er.LENGTH)try{if(o=s(t),o<0)throw(0,Qr.default)(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(o>a)throw(0,Qr.default)(new Error("message length too long"),"ERR_MSG_DATA_TOO_LONG");let l=s.bytes;t.consume(l),e?.onLength!=null&&e.onLength(o),n=Er.DATA}catch(l){if(l instanceof RangeError){if(t.byteLength>i)throw(0,Qr.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw l}if(n===Er.DATA){if(t.byteLength<o)break;let l=t.sublist(0,o);t.consume(o),e?.onData!=null&&e.onData(l),yield l,n=Er.LENGTH}}}return Jo(r)?async function*(){for await(let l of r)t.append(l),yield*c();if(t.byteLength>0)throw(0,Qr.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}():function*(){for(let l of r)t.append(l),yield*c();if(t.byteLength>0)throw(0,Qr.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}()}vr.fromReader=(r,e)=>{let t=1,n=async function*(){for(;;)try{let{done:s,value:i}=await r.next(t);if(s===!0)return;i!=null&&(yield i)}catch(s){if(s.code==="ERR_UNDER_READ")return{done:!0,value:null};throw s}finally{t=1}}();return vr(n,{...e??{},onLength:s=>{t=s}})};var Qg=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 eb(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:u}=Qg(r),f=(...m)=>{let d=t.multiArgs?m:m[0];t.filter&&!t.filter(d)||(c.push(d),t.count===c.length&&(n(),s(c)))},g=m=>{n(),i(m)};n=()=>{for(let m of a)u(m,f);for(let m of t.rejectionEvents)u(m,g)};for(let m of a)l(m,f);for(let m of t.rejectionEvents)l(m,g);t.signal&&t.signal.addEventListener("abort",()=>{g(t.signal.reason)},{once:!0}),t.resolveImmediately&&s(c)});if(o.cancel=n,typeof t.timeout=="number"){let s=wr(o,{milliseconds:t.timeout});return s.cancel=n,s}return o}function Xa(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=eb(r,e,t),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}var Ja=new Float32Array([-0]),Jt=new Uint8Array(Ja.buffer);function wf(r,e,t){Ja[0]=r,e[t]=Jt[0],e[t+1]=Jt[1],e[t+2]=Jt[2],e[t+3]=Jt[3]}function xf(r,e){return Jt[0]=r[e],Jt[1]=r[e+1],Jt[2]=r[e+2],Jt[3]=r[e+3],Ja[0]}var Qa=new Float64Array([-0]),Me=new Uint8Array(Qa.buffer);function Ef(r,e,t){Qa[0]=r,e[t]=Me[0],e[t+1]=Me[1],e[t+2]=Me[2],e[t+3]=Me[3],e[t+4]=Me[4],e[t+5]=Me[5],e[t+6]=Me[6],e[t+7]=Me[7]}function vf(r,e){return Me[0]=r[e],Me[1]=r[e+1],Me[2]=r[e+2],Me[3]=r[e+3],Me[4]=r[e+4],Me[5]=r[e+5],Me[6]=r[e+6],Me[7]=r[e+7],Qa[0]}var tb=BigInt(Number.MAX_SAFE_INTEGER),rb=BigInt(Number.MIN_SAFE_INTEGER),je=class r{lo;hi;constructor(e,t){this.lo=e|0,this.hi=t|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(t+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(BigInt(t)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?t===0?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return Ar;if(e<tb&&e>rb)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let n=e>>32n,o=e-(n<<32n);return t&&(n=~n|0n,o=~o|0n,++o>Af&&(o=0n,++n>Af&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return Ar;let t=e<0;t&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return t&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(e){return typeof e=="number"?r.fromNumber(e):typeof e=="bigint"?r.fromBigInt(e):typeof e=="string"?r.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new r(e.low>>>0,e.high>>>0):Ar}},Ar=new je(0,0);Ar.toBigInt=function(){return 0n};Ar.zzEncode=Ar.zzDecode=function(){return this};Ar.length=function(){return 1};var Af=4294967296n;function Df(r){let e=0,t=0;for(let n=0;n<r.length;++n)t=r.charCodeAt(n),t<128?e+=1:t<2048?e+=2:(t&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function Sf(r,e,t){if(t-e<1)return"";let o,s=[],i=0,a;for(;e<t;)a=r[e++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|r[e++]&63:a>239&&a<365?(a=((a&7)<<18|(r[e++]&63)<<12|(r[e++]&63)<<6|r[e++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function ec(r,e,t){let n=t,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,e[t++]=o>>18|240,e[t++]=o>>12&63|128,e[t++]=o>>6&63|128,e[t++]=o&63|128):(e[t++]=o>>12|224,e[t++]=o>>6&63|128,e[t++]=o&63|128);return t-n}function st(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function es(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var tc=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,st(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw st(this,4);return es(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw st(this,4);return es(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw st(this,4);let e=xf(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw st(this,4);let e=vf(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),t=this.pos,n=this.pos+e;if(n>this.len)throw st(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return Sf(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw st(this,e);this.pos+=e}else do if(this.pos>=this.len)throw st(this);while(this.buf[this.pos++]&128);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new je(0,0),t=0;if(this.len-this.pos>4){for(;t<4;++t)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;t=0}else{for(;t<3;++t){if(this.pos>=this.len)throw st(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<t*7)>>>0,e}if(this.len-this.pos>4){for(;t<5;++t)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;t<5;++t){if(this.pos>=this.len)throw st(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw st(this,8);let e=es(this.buf,this.pos+=4),t=es(this.buf,this.pos+=4);return new je(e,t)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=ya(this.buf,this.pos);return this.pos+=we(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function rc(r){return new tc(r instanceof Uint8Array?r:r.subarray())}function it(r,e,t){let n=rc(r);return e.decode(n,void 0,t)}function nc(r){let e=r??8192,t=e>>>1,n,o=e;return function(i){if(i<1||i>t)return Se(i);o+i>e&&(n=Se(e),o=0);let a=n.subarray(o,o+=i);return o&7&&(o=(o|7)+1),a}}var Dr=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function oc(){}var ic=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},nb=nc();function ob(r){return globalThis.Buffer!=null?Se(r):nb(r)}var zn=class{len;head;tail;states;constructor(){this.len=0,this.head=new Dr(oc,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new Dr(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new ac((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(ts,10,je.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=je.fromBigInt(e);return this._push(ts,t.length(),t)}uint64Number(e){return this._push(ba,we(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let t=je.fromBigInt(e).zzEncode();return this._push(ts,t.length(),t)}sint64Number(e){let t=je.fromNumber(e).zzEncode();return this._push(ts,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(sc,1,e?1:0)}fixed32(e){return this._push(Wn,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=je.fromBigInt(e);return this._push(Wn,4,t.lo)._push(Wn,4,t.hi)}fixed64Number(e){let t=je.fromNumber(e);return this._push(Wn,4,t.lo)._push(Wn,4,t.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(wf,4,e)}double(e){return this._push(Ef,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(sc,1,0):this.uint32(t)._push(ib,t,e)}string(e){let t=Df(e);return t!==0?this.uint32(t)._push(ec,t,e):this._push(sc,1,0)}fork(){return this.states=new ic(this),this.head=this.tail=new Dr(oc,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new Dr(oc,0,0),this.len=0),this}ldelim(){let e=this.head,t=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=t,this.len+=n),this}finish(){let e=this.head.next,t=ob(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function sc(r,e,t){e[t]=r&255}function sb(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var ac=class extends Dr{next;constructor(e,t){super(sb,e,t),this.next=void 0}};function ts(r,e,t){for(;r.hi!==0;)e[t++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)e[t++]=r.lo&127|128,r.lo=r.lo>>>7;e[t++]=r.lo}function Wn(r,e,t){e[t]=r&255,e[t+1]=r>>>8&255,e[t+2]=r>>>16&255,e[t+3]=r>>>24}function ib(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(zn.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(ab,e,r),this},zn.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(cb,e,r),this});function ab(r,e,t){e.set(r,t)}function cb(r,e,t){r.length<40?ec(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(J(r),t)}function cc(){return new zn}function at(r,e){let t=cc();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var en;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(en||(en={}));function rs(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function Sr(r){function e(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let t=function(s,i){let a=e(s);i.int32(a)},n=function(s){let i=s.int32();return e(i)};return rs("enum",en.VARINT,t,n)}function ct(r,e){return rs("message",en.LENGTH_DELIMITED,r,e)}var $e;(function(r){let e;(function(o){o.FIN="FIN",o.STOP_SENDING="STOP_SENDING",o.RESET="RESET",o.FIN_ACK="FIN_ACK"})(e=r.Flag||(r.Flag={}));let t;(function(o){o[o.FIN=0]="FIN",o[o.STOP_SENDING=1]="STOP_SENDING",o[o.RESET=2]="RESET",o[o.FIN_ACK=3]="FIN_ACK"})(t||(t={})),function(o){o.codec=()=>Sr(t)}(e=r.Flag||(r.Flag={}));let n;r.codec=()=>(n==null&&(n=ct((o,s,i={})=>{i.lengthDelimited!==!1&&s.fork(),o.flag!=null&&(s.uint32(8),r.Flag.codec().encode(o.flag,s)),o.message!=null&&(s.uint32(18),s.bytes(o.message)),i.lengthDelimited!==!1&&s.ldelim()},(o,s)=>{let i={},a=s==null?o.len:o.pos+s;for(;o.pos<a;){let c=o.uint32();switch(c>>>3){case 1:i.flag=r.Flag.codec().decode(o);break;case 2:i.message=o.bytes();break;default:o.skipType(c&7);break}}return i})),n),r.encode=o=>at(o,r.codec()),r.decode=o=>it(o,r.codec())})($e||($e={}));var lb=16*1024*1024,ub=30*1e3,fb=5,hb=2,db=16*1024,pb=5e3,mb=5e3,lc=class extends Xo{channel;incomingData;maxBufferedAmount;bufferedAmountLowEventTimeout;maxMessageSize;receiveFinAck;finAckTimeout;openTimeout;constructor(e){let t=e.onEnd;switch(e.onEnd=o=>{this.log.trace("readable and writeable ends closed",this.status),Promise.resolve(async()=>{if(!(this.timeline.abort!=null||this.timeline.reset!==null))try{await wr(this.receiveFinAck.promise,{milliseconds:this.finAckTimeout})}catch(s){this.log.error("error receiving FIN_ACK",s)}}).then(()=>{this.incomingData.end(),t?.(o)}).catch(s=>{this.log.error("error ending stream",s)})},super(e),this.channel=e.channel,this.channel.binaryType="arraybuffer",this.incomingData=Xt(),this.bufferedAmountLowEventTimeout=e.bufferedAmountLowEventTimeout??ub,this.maxBufferedAmount=e.maxBufferedAmount??lb,this.maxMessageSize=(e.maxMessageSize??db)-fb-hb,this.receiveFinAck=pe(),this.finAckTimeout=e.closeTimeout??pb,this.openTimeout=e.openTimeout??mb,this.channel.readyState){case"open":this.timeline.open=new Date().getTime();break;case"closed":case"closing":(this.timeline.close===void 0||this.timeline.close===0)&&(this.timeline.close=Date.now());break;case"connecting":break;default:throw this.log.error("unknown datachannel state %s",this.channel.readyState),new L("Unknown datachannel state","ERR_INVALID_STATE")}this.channel.onopen=o=>{this.timeline.open=new Date().getTime()},this.channel.onclose=o=>{this.receiveFinAck.resolve(),this.close().catch(s=>{this.log.error("error closing stream after channel closed",s)})},this.channel.onerror=o=>{let s=o.error;this.abort(s)},this.channel.onmessage=async o=>{let{data:s}=o;s===null||s.byteLength===0||this.incomingData.push(new Uint8Array(s,0,s.byteLength))};let n=this;Promise.resolve().then(async()=>{for await(let o of vr(this.incomingData)){let s=n.processIncomingProtobuf(o);s!=null&&n.sourcePush(new ue(s))}}).catch(o=>{this.log.error("error processing incoming data channel messages",o)})}sendNewStream(){}async _sendMessage(e,t=!0){if(t&&this.channel.bufferedAmount>this.maxBufferedAmount)try{this.log('channel buffer is %d, wait for "bufferedamountlow" event',this.channel.bufferedAmount),await Xa(this.channel,"bufferedamountlow",{timeout:this.bufferedAmountLowEventTimeout})}catch(n){throw n instanceof Xr?new L(`Timed out waiting for DataChannel buffer to clear after ${this.bufferedAmountLowEventTimeout}ms`,"ERR_BUFFER_CLEAR_TIMEOUT"):n}if(this.channel.readyState==="closed"||this.channel.readyState==="closing")throw new L(`Invalid datachannel state - ${this.channel.readyState}`,"ERR_INVALID_STATE");this.channel.readyState!=="open"&&(this.log('channel state is "%s" and not "open", waiting for "open" event before sending data',this.channel.readyState),await Xa(this.channel,"open",{timeout:this.openTimeout}),this.log('channel state is now "%s", sending data',this.channel.readyState)),this.channel.send(e.subarray())}async sendData(e){for(e=e.sublist();e.byteLength>0;){let t=Math.min(e.byteLength,this.maxMessageSize),n=e.subarray(0,t),o=$e.encode({message:n}),s=qn.single(o);await this._sendMessage(s),e.consume(t)}}async sendReset(){await this._sendFlag($e.Flag.RESET)}async sendCloseWrite(e){if(await this._sendFlag($e.Flag.FIN)){this.log.trace("awaiting FIN_ACK");try{await _t(this.receiveFinAck.promise,e?.signal,{errorMessage:"sending close-write was aborted before FIN_ACK was received",errorCode:"ERR_FIN_ACK_NOT_RECEIVED"})}catch(n){this.log.error("failed to await FIN_ACK",n)}}else this.log.trace("sending FIN failed, not awaiting FIN_ACK");this.receiveFinAck.resolve()}async sendCloseRead(){await this._sendFlag($e.Flag.STOP_SENDING)}processIncomingProtobuf(e){let t=$e.decode(e);if(t.flag!==void 0&&(this.log.trace('incoming flag %s, write status "%s", read status "%s"',t.flag,this.writeStatus,this.readStatus),t.flag===$e.Flag.FIN&&(this.remoteCloseWrite(),this.log.trace("sending FIN_ACK"),this._sendFlag($e.Flag.FIN_ACK).catch(n=>{this.log.error("error sending FIN_ACK immediately",n)})),t.flag===$e.Flag.RESET&&this.reset(),t.flag===$e.Flag.STOP_SENDING&&this.remoteCloseRead(),t.flag===$e.Flag.FIN_ACK&&(this.log.trace("received FIN_ACK"),this.receiveFinAck.resolve())),this.readStatus==="ready")return t.message}async _sendFlag(e){if(this.channel.readyState!=="open")return this.log.trace('not sending flag %s because channel is "%s" and not "open"',this.channel.readyState,e.toString()),!1;this.log.trace("sending flag %s",e.toString());let t=$e.encode({flag:e}),n=qn.single(t);try{return await this._sendMessage(n,!1),!0}catch(o){this.log.error("could not send flag %s",e.toString(),o)}return!1}};function tn(r){let{channel:e,direction:t}=r;return new lc({id:t==="inbound"?`i${e.id}`:`r${e.id}`,log:r.logger.forComponent(`libp2p:webrtc:stream:${t}:${e.id}`),...r})}var kf="/webrtc",Qt=class{protocol;peerConnection;bufferedStreams=[];metrics;dataChannelOptions;components;log;constructor(e,t){this.components=e,this.peerConnection=t.peerConnection,this.metrics=t.metrics,this.protocol=t.protocol??kf,this.dataChannelOptions=t.dataChannelOptions??{},this.log=e.logger.forComponent("libp2p:webrtc:datachannelmuxerfactory"),this.peerConnection.ondatachannel=({channel:n})=>{if(this.log.trace('incoming early datachannel with channel id %d and label "%s"',n.id),n.label==="init"){this.log.trace("closing early init channel"),n.close();return}let o={},s=tn({channel:n,direction:"inbound",onEnd:i=>{o.onEnd(i)},logger:e.logger,...this.dataChannelOptions});o.stream=s,o.channel=n,o.onEnd=()=>{this.bufferedStreams=this.bufferedStreams.filter(i=>i.stream.id!==s.id)},this.bufferedStreams.push(o)}}createStreamMuxer(e){return new uc(this.components,{...e,peerConnection:this.peerConnection,dataChannelOptions:this.dataChannelOptions,metrics:this.metrics,streams:this.bufferedStreams,protocol:this.protocol})}},uc=class{init;streams;protocol;log;peerConnection;dataChannelOptions;metrics;logger;constructor(e,t){this.init=t,this.log=e.logger.forComponent("libp2p:webrtc:muxer"),this.logger=e.logger,this.streams=t.streams.map(n=>n.stream),this.peerConnection=t.peerConnection,this.protocol=t.protocol??kf,this.metrics=t.metrics,this.dataChannelOptions=t.dataChannelOptions??{},this.peerConnection.ondatachannel=({channel:n})=>{if(this.log.trace("incoming datachannel with channel id %d",n.id),n.label==="init"){this.log.trace("closing init channel"),n.close();return}let o=tn({channel:n,direction:"inbound",onEnd:()=>{this.log("incoming channel %s ended with state %s",n.id,n.readyState),this.#e(o,n)},logger:this.logger,...this.dataChannelOptions});this.streams.push(o),this.metrics?.increment({incoming_stream:!0}),t?.onIncomingStream?.(o)},this.init.streams.length>0&&queueMicrotask(()=>{this.init.streams.forEach(n=>{n.onEnd=()=>{this.log("incoming early channel %s ended with state %s",n.channel.id,n.channel.readyState),this.#e(n.stream,n.channel)},this.metrics?.increment({incoming_stream:!0}),this.init?.onIncomingStream?.(n.stream)})})}#e(e,t){this.log.trace("stream %s %s %s onEnd",e.direction,e.id,e.protocol),uf(t,`${e.direction} ${e.id} ${e.protocol}`,this.dataChannelOptions.drainTimeout,{log:this.log}),this.streams=this.streams.filter(n=>n.id!==e.id),this.metrics?.increment({stream_end:!0}),this.init?.onStreamEnd?.(e)}async close(e){try{await Promise.all(this.streams.map(async t=>t.close(e)))}catch(t){this.abort(t)}}abort(e){for(let t of this.streams)t.abort(e)}source=zo();sink=Go;newStream(){let e=this.peerConnection.createDataChannel("");this.log.trace("opened outgoing datachannel with channel id %s",e.id);let t=tn({channel:e,direction:"outbound",onEnd:()=>{this.log("outgoing channel %s ended with state %s",e.id,e.readyState),this.#e(t,e)},logger:this.logger,...this.dataChannelOptions});return this.streams.push(t),this.metrics?.increment({outgoing_stream:!0}),t}};var Br=globalThis.RTCPeerConnection,ns=globalThis.RTCSessionDescription,Cf=globalThis.RTCIceCandidate;var fc=class{readNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.readNext=pe(),this.haveNext=pe()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let e=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=pe(),e}async throw(e){return this.ended=!0,e!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(e)),{done:!0,value:void 0}}async return(){let e={done:!0,value:void 0};return await this._push(void 0),e}async push(e,t){await this._push(e,t)}async end(e,t){e!=null?await this.throw(e):await this._push(void 0,t)}async _push(e,t){if(e!=null&&this.ended)throw new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;e!=null?this.nextResult={done:!1,value:e}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=pe(),await _t(this.readNext.promise,t?.signal,t)}};function If(){return new fc}var os=class extends Error{code;constructor(e,t){super(e),this.code=t}},hc=class extends os{type;constructor(e){super(e,"ABORT_ERR"),this.type="aborted"}};function Tf(r,e){let t=If();r.sink(t).catch(async i=>{await t.end(i)}),r.sink=async i=>{for await(let a of i)await t.push(a);await t.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let o=new ue;return{read:async(i,a)=>{a?.signal?.throwIfAborted();let c,l=new Promise((u,f)=>{c=()=>{f(new hc("Read aborted"))},a?.signal?.addEventListener("abort",c)});try{if(i==null){let{done:f,value:g}=await Promise.race([n.next(),l]);return f===!0?new ue:g}for(;o.byteLength<i;){let{value:f,done:g}=await Promise.race([n.next(),l]);if(g===!0)throw new os("unexpected end of input","ERR_UNEXPECTED_EOF");o.append(f)}let u=o.sublist(0,i);return o.consume(i),u}finally{c!=null&&a?.signal?.removeEventListener("abort",c)}},write:async(i,a)=>{a?.signal?.throwIfAborted(),i instanceof Uint8Array?await t.push(i,a):await t.push(i.subarray(),a)},unwrap:()=>{if(o.byteLength>0){let i=r.source;r.source=async function*(){e?.yieldBytes===!1?yield o:yield*o,yield*i}()}return r}}}var ss=class extends Error{code;constructor(e,t){super(e),this.code=t}};function Gn(r,e={}){let t=Tf(r,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=we(e.maxDataLength));let n=e?.lengthDecoder??nt,o=e?.lengthEncoder??wt;return{read:async i=>{let a=-1,c=new ue;for(;;){c.append(await t.read(1,i));try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new ss("message length length too long","ERR_MSG_LENGTH_TOO_LONG");if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new ss("message length too long","ERR_MSG_DATA_TOO_LONG");return t.read(a,i)},write:async(i,a)=>{await t.write(new ue(o(i.byteLength),i),a)},writeV:async(i,a)=>{let c=new ue(...i.flatMap(l=>[o(l.byteLength),l]));await t.write(c,a)},unwrap:()=>t.unwrap()}}function is(r,e){let t=Gn(r,e),n={read:async(o,s)=>{let i=await t.read(s);return o.decode(i)},write:async(o,s,i)=>{await t.write(s.encode(o),i)},writeV:async(o,s,i)=>{await t.writeV(o.map(a=>s.encode(a)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>t.unwrap()};return n}var Ye=class extends Event{constructor(e,t){super(e),this.detail=t}};var qe;(function(r){let e;(function(o){o.SDP_OFFER="SDP_OFFER",o.SDP_ANSWER="SDP_ANSWER",o.ICE_CANDIDATE="ICE_CANDIDATE"})(e=r.Type||(r.Type={}));let t;(function(o){o[o.SDP_OFFER=0]="SDP_OFFER",o[o.SDP_ANSWER=1]="SDP_ANSWER",o[o.ICE_CANDIDATE=2]="ICE_CANDIDATE"})(t||(t={})),function(o){o.codec=()=>Sr(t)}(e=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=ct((o,s,i={})=>{i.lengthDelimited!==!1&&s.fork(),o.type!=null&&(s.uint32(8),r.Type.codec().encode(o.type,s)),o.data!=null&&(s.uint32(18),s.string(o.data)),i.lengthDelimited!==!1&&s.ldelim()},(o,s)=>{let i={},a=s==null?o.len:o.pos+s;for(;o.pos<a;){let c=o.uint32();switch(c>>>3){case 1:i.type=r.Type.codec().decode(o);break;case 2:i.data=o.string();break;default:o.skipType(c&7);break}}return i})),n),r.encode=o=>at(o,r.codec()),r.decode=o=>it(o,r.codec())})(qe||(qe={}));var as=async(r,e,t)=>{try{let n=pe();for(bb(r,n);;){let o=await Promise.race([n.promise,e.read({signal:t.signal}).catch(()=>{})]);if(o==null){t.signal?.throwIfAborted();break}if(o.type!==qe.Type.ICE_CANDIDATE)throw new L("ICE candidate message expected","ERR_NOT_ICE_CANDIDATE");let s=JSON.parse(o.data??"null");if(s===""||s===null){t.onProgress?.(new Ye("webrtc:end-of-ice-candidates")),t.log.trace("end-of-candidates received");continue}let i=new Cf(s);t.log.trace("%s received new ICE candidate %o",t.direction,s);try{t.onProgress?.(new Ye("webrtc:add-ice-candidate",i.candidate)),await r.addIceCandidate(i)}catch(a){t.log.error("%s bad candidate received",t.direction,s,a)}}}catch(n){if(t.log.error("%s error parsing ICE candidate",t.direction,n),t.signal?.aborted===!0)throw n}};function gb(r){return Kn?r.iceConnectionState:r.connectionState}function bb(r,e){r[Kn?"oniceconnectionstatechange":"onconnectionstatechange"]=t=>{switch(gb(r)){case"connected":e.resolve();break;case"failed":case"disconnected":case"closed":e.reject(new L("RTCPeerConnection was closed","ERR_CONNECTION_CLOSED_BEFORE_CONNECTED"));break;default:break}}}async function _f({rtcConfiguration:r,dataChannel:e,signal:t,metrics:n,multiaddr:o,connectionManager:s,transportManager:i,log:a,logger:c,onProgress:l}){let{baseAddr:u}=Rf(o);n?.dialerEvents.increment({open:!0}),a.trace("dialing base address: %a",u);let f=u.getPeerId();if(f==null)throw new L("Relay peer was missing","ERR_INVALID_ADDRESS");let g=s.getConnections(yr(f)),m,d=!1;g.length===0?(l?.(new Ye("webrtc:dial-relay")),m=await i.dial(u,{signal:t,onProgress:l}),d=!0):(l?.(new Ye("webrtc:reuse-relay-connection")),m=g[0]);try{l?.(new Ye("webrtc:open-signaling-stream"));let h=await m.newStream(cs,{signal:t,runOnTransientConnection:!0}),p=is(h).pb(qe),y=new Br(r),E=new Qt({logger:c},{peerConnection:y,dataChannelOptions:e});try{let b=y.createDataChannel("init");y.onicecandidate=({candidate:A})=>{let S=JSON.stringify(A?.toJSON()??null);a.trace("initiator sending ICE candidate %o",A),p.write({type:qe.Type.ICE_CANDIDATE,data:S},{signal:t}).catch(_=>{a.error("error sending ICE candidate",_)})},y.onicecandidateerror=A=>{a.error("initiator ICE candidate error",A)};let v=await y.createOffer().catch(A=>{throw a.error("could not execute createOffer",A),new L("Failed to set createOffer","ERR_SDP_HANDSHAKE_FAILED")});a.trace("initiator send SDP offer %s",v.sdp),l?.(new Ye("webrtc:send-sdp-offer")),await p.write({type:qe.Type.SDP_OFFER,data:v.sdp},{signal:t}),await y.setLocalDescription(v).catch(A=>{throw a.error("could not execute setLocalDescription",A),new L("Failed to set localDescription","ERR_SDP_HANDSHAKE_FAILED")}),l?.(new Ye("webrtc:read-sdp-answer"));let x=await p.read({signal:t});if(x.type!==qe.Type.SDP_ANSWER)throw new L("Remote should send an SDP answer","ERR_SDP_HANDSHAKE_FAILED");a.trace("initiator receive SDP answer %s",x.data);let D=new ns({type:"answer",sdp:x.data});return await y.setRemoteDescription(D).catch(A=>{throw a.error("could not execute setRemoteDescription",A),new L("Failed to set remoteDescription","ERR_SDP_HANDSHAKE_FAILED")}),a.trace("initiator read candidates until connected"),l?.(new Ye("webrtc:read-ice-candidates")),await as(y,p,{direction:"initiator",signal:t,log:a,onProgress:l}),a.trace("initiator connected, closing init channel"),b.close(),l?.(new Ye("webrtc:close-signaling-stream")),a.trace("closing signaling channel"),await h.close({signal:t}),a.trace("initiator connected to remote address %s",o),{remoteAddress:o,peerConnection:y,muxerFactory:E}}catch(b){throw a.error("outgoing signaling error",b),y.close(),h.abort(b),b}finally{y.onicecandidate=null,y.onicecandidateerror=null}}finally{if(d)try{await m.close({signal:t})}catch(h){m.abort(h)}}}var yb=U("dns4"),wb=U("dns6"),xb=U("dnsaddr"),kr=ye(U("dns"),xb,yb,wb),fs=ye(U("ip4"),U("ip6")),rn=ye(K(fs,U("tcp")),K(kr,U("tcp"))),hs=K(fs,U("udp")),Eb=K(hs,U("utp")),vb=K(hs,U("quic")),Ab=K(hs,U("quic-v1")),dc=ye(K(rn,U("ws")),K(kr,U("ws"))),ls=ye(K(dc,U("p2p")),dc),pc=ye(K(rn,U("wss")),K(kr,U("wss")),K(rn,U("tls"),U("ws")),K(kr,U("tls"),U("ws"))),us=ye(K(pc,U("p2p")),pc),mc=ye(K(rn,U("http")),K(fs,U("http")),K(kr,U("http"))),gc=ye(K(rn,U("https")),K(fs,U("https")),K(kr,U("https"))),Nf=K(hs,U("webrtc-direct"),U("certhash")),Of=ye(K(Nf,U("p2p")),Nf),Lf=K(Ab,U("webtransport"),U("certhash"),U("certhash")),Pf=ye(K(Lf,U("p2p")),Lf),Mf=ye(K(ls,U("p2p-webrtc-star"),U("p2p")),K(us,U("p2p-webrtc-star"),U("p2p")),K(ls,U("p2p-webrtc-star")),K(us,U("p2p-webrtc-star"))),e4=ye(K(ls,U("p2p-websocket-star"),U("p2p")),K(us,U("p2p-websocket-star"),U("p2p")),K(ls,U("p2p-websocket-star")),K(us,U("p2p-websocket-star"))),Ff=ye(K(mc,U("p2p-webrtc-direct"),U("p2p")),K(gc,U("p2p-webrtc-direct"),U("p2p")),K(mc,U("p2p-webrtc-direct")),K(gc,U("p2p-webrtc-direct"))),Cr=ye(dc,pc,mc,gc,Mf,Ff,rn,Eb,vb,kr,Of,Pf),t4=ye(K(Cr,U("p2p-stardust"),U("p2p")),K(Cr,U("p2p-stardust"))),er=ye(K(Cr,U("p2p")),Mf,Ff,Of,Pf,U("p2p")),Uf=ye(K(er,U("p2p-circuit"),er),K(er,U("p2p-circuit")),K(U("p2p-circuit"),er),K(Cr,U("p2p-circuit")),K(U("p2p-circuit"),Cr),U("p2p-circuit")),Vf=()=>ye(K(Uf,Vf),Uf),Rt=Vf(),r4=ye(K(Rt,er,Rt),K(er,Rt),K(Rt,er),Rt,er);var n4=ye(K(Rt,U("webrtc"),U("p2p")),K(Rt,U("webrtc")),K(Cr,U("webrtc"),U("p2p")),K(Cr,U("webrtc")),U("webrtc"));function Hf(r){function e(t){let n;try{n=ot(t)}catch{return!1}let o=r(n.protoNames());return o===null?!1:o===!0||o===!1?o:o.length===0}return e}function K(...r){function e(t){if(t.length<r.length)return null;let n=t;return r.some(o=>(n=typeof o=="function"?o().partialMatch(t):o.partialMatch(t),Array.isArray(n)&&(t=n),n===null)),n}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:Hf(e),partialMatch:e}}function ye(...r){function e(n){let o=null;return r.some(s=>{let i=typeof s=="function"?s().partialMatch(n):s.partialMatch(n);return i!=null?(o=i,!0):!1}),o}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:Hf(e),partialMatch:e}}function U(r){let e=r;function t(o){let s;try{s=ot(o)}catch{return!1}let i=s.protoNames();return i.length===1&&i[0]===e}function n(o){return o.length===0?null:o[0]===e?o.slice(1):null}return{toString:function(){return e},matches:t,partialMatch:n}}var ds=class extends _o{peerId;transportManager;shutdownController;constructor(e,t){super(),this.peerId=e.peerId,this.transportManager=e.transportManager,this.shutdownController=t.shutdownController}async listen(){this.safeDispatchEvent("listening",{})}getAddrs(){return this.transportManager.getListeners().filter(e=>e!==this).map(e=>e.getAddrs().filter(t=>Rt.matches(t)).map(t=>t.encapsulate(`/webrtc/p2p/${this.peerId}`))).flat()}async close(){this.shutdownController.abort(),this.safeDispatchEvent("close",{})}};async function Kf({peerConnection:r,stream:e,signal:t,connection:n,log:o}){o.trace("new inbound signaling stream");let s=is(e).pb(qe);try{r.onicecandidate=({candidate:u})=>{let f=JSON.stringify(u?.toJSON()??null);o.trace("recipient sending ICE candidate %s",f),s.write({type:qe.Type.ICE_CANDIDATE,data:f},{signal:t}).catch(g=>{o.error("error sending ICE candidate",g)})};let a=await s.read({signal:t});if(a.type!==qe.Type.SDP_OFFER)throw new L(`expected message type SDP_OFFER, received: ${a.type??"undefined"} `,"ERR_SDP_HANDSHAKE_FAILED");o.trace("recipient receive SDP offer %s",a.data);let c=new ns({type:"offer",sdp:a.data});await r.setRemoteDescription(c).catch(u=>{throw o.error("could not execute setRemoteDescription",u),new L("Failed to set remoteDescription","ERR_SDP_HANDSHAKE_FAILED")});let l=await r.createAnswer().catch(u=>{throw o.error("could not execute createAnswer",u),new L("Failed to create answer","ERR_SDP_HANDSHAKE_FAILED")});o.trace("recipient send SDP answer %s",l.sdp),await s.write({type:qe.Type.SDP_ANSWER,data:l.sdp},{signal:t}),await r.setLocalDescription(l).catch(u=>{throw o.error("could not execute setLocalDescription",u),new L("Failed to set localDescription","ERR_SDP_HANDSHAKE_FAILED")}),o.trace("recipient read candidates until connected"),await as(r,s,{direction:"recipient",signal:t,log:o})}catch(a){if(r.connectionState!=="connected")throw o.error("error while handling signaling stream from peer %a",n.remoteAddr,a),r.close(),a;o("error while handling signaling stream from peer %a, ignoring as the RTCPeerConnection is already connected",n.remoteAddr,a)}let i=ot(`/webrtc/p2p/${n.remoteAddr.getPeerId()}`);return o.trace("recipient connected to remote address %s",i),{remoteAddress:i}}var Db="/webrtc",Sb="/p2p-circuit",cs="/webrtc-signaling/0.0.1",Bb=30*1e3,ps=class{components;init;log;_started=!1;metrics;shutdownController;constructor(e,t={}){this.components=e,this.init=t,this.log=e.logger.forComponent("libp2p:webrtc"),this.shutdownController=new AbortController,To(1/0,this.shutdownController.signal),e.metrics!=null&&(this.metrics={dialerEvents:e.metrics.registerCounterGroup("libp2p_webrtc_dialer_events_total",{label:"event",help:"Total count of WebRTC dialer events by type"}),listenerEvents:e.metrics.registerCounterGroup("libp2p_webrtc_listener_events_total",{label:"event",help:"Total count of WebRTC listener events by type"})})}[Io]=!0;[Symbol.toStringTag]="@libp2p/webrtc";[Hr]=["@libp2p/transport"];[su]=["@libp2p/identify","@libp2p/circuit-relay-v2-transport"];isStarted(){return this._started}async start(){await this.components.registrar.handle(cs,e=>{this._onProtocol(e).catch(t=>{this.log.error("failed to handle incoming connect from %p",e.connection.remotePeer,t)})},{runOnTransientConnection:!0}),this._started=!0}async stop(){await this.components.registrar.unhandle(cs),this._started=!1}createListener(e){return new ds(this.components,{shutdownController:this.shutdownController})}listenFilter(e){return e.filter(Xu.exactMatch)}dialFilter(e){return this.listenFilter(e)}async dial(e,t){this.log.trace("dialing address: %a",e);let{remoteAddress:n,peerConnection:o,muxerFactory:s}=await _f({rtcConfiguration:await $n(this.init.rtcConfiguration),dataChannel:this.init.dataChannel,multiaddr:e,dataChannelOptions:this.init.dataChannel,signal:t.signal,connectionManager:this.components.connectionManager,transportManager:this.components.transportManager,log:this.log,logger:this.components.logger,onProgress:t.onProgress}),i=new xr(this.components,{peerConnection:o,timeline:{open:Date.now()},remoteAddr:n,metrics:this.metrics?.dialerEvents}),a=await t.upgrader.upgradeOutbound(i,{skipProtection:!0,skipEncryption:!0,muxerFactory:s,onProgress:t.onProgress});return this._closeOnShutdown(o,i),a}async _onProtocol({connection:e,stream:t}){let n=AbortSignal.timeout(this.init.inboundConnectionTimeout??Bb),o=new Br(await $n(this.init.rtcConfiguration)),s=new Qt(this.components,{peerConnection:o,dataChannelOptions:this.init.dataChannel});try{let{remoteAddress:i}=await Kf({peerConnection:o,connection:e,stream:t,signal:n,log:this.log});await t.close({signal:n});let a=new xr(this.components,{peerConnection:o,timeline:{open:new Date().getTime()},remoteAddr:i,metrics:this.metrics?.listenerEvents});await this.components.upgrader.upgradeInbound(a,{skipEncryption:!0,skipProtection:!0,muxerFactory:s}),this._closeOnShutdown(o,a)}catch(i){throw this.log.error("incoming signaling error",i),o.close(),t.abort(i),i}}_closeOnShutdown(e,t){let n=()=>{t.close().catch(o=>{this.log.error("could not close WebRTCMultiaddrConnection",o)})};this.shutdownController.signal.addEventListener("abort",n),e.addEventListener("close",()=>{this.shutdownController.signal.removeEventListener("abort",n)})}};function Rf(r){let e=r.toString().split(Db+"/");if(e.length!==2)throw new L("webrtc protocol was not present in multiaddr",Ge.ERR_INVALID_MULTIADDR);if(!e[0].includes(Sb))throw new L("p2p-circuit protocol was not present in multiaddr",Ge.ERR_INVALID_MULTIADDR);let t=ot(e[0]),o=ot("/"+e[1]).getPeerId();if(o==null)throw new L("destination peer id was missing",Ge.ERR_INVALID_MULTIADDR);let s=t.protos().pop();if(s===void 0)throw new L("invalid multiaddr",Ge.ERR_INVALID_MULTIADDR);return s.name!=="p2p"&&(t=t.encapsulate(`/p2p/${o}`)),{baseAddr:t,peerId:yr(o)}}var Rc={};Q(Rc,{Ed25519PrivateKey:()=>Nr,Ed25519PublicKey:()=>eo,generateKeyPair:()=>Uy,generateKeyPairFromSeed:()=>bh,unmarshalEd25519PrivateKey:()=>Ny,unmarshalEd25519PublicKey:()=>Ly});function Qe(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function tr(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`positive integer expected, not ${r}`)}function kb(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function nn(r,...e){if(!kb(r))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(r.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${r.length}`)}function Ir(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");tr(r.outputLen),tr(r.blockLen)}function on(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function $f(r,e){nn(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var ms=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var an=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),lt=(r,e)=>r<<32-e|r>>>e;var U4=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;var Cb=async()=>{};async function qf(r,e,t){let n=Date.now();for(let o=0;o<r;o++){t(o);let s=Date.now()-n;s>=0&&s<e||(await Cb(),n+=s)}}function Wf(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function ut(r){return typeof r=="string"&&(r=Wf(r)),nn(r),r}function bc(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];nn(o),e+=o.length}let t=new Uint8Array(e);for(let n=0,o=0;n<r.length;n++){let s=r[n];t.set(s,o),o+=s.length}return t}var sn=class{clone(){return this._cloneInto()}},Ib={}.toString;function zf(r,e){if(e!==void 0&&Ib.call(e)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(r,e)}function gs(r){let e=n=>r().update(ut(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function Tr(r=32){if(ms&&typeof ms.getRandomValues=="function")return ms.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function Tb(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(t>>o&s),a=Number(t&s),c=n?4:0,l=n?0:4;r.setUint32(e+c,i,n),r.setUint32(e+l,a,n)}var Gf=(r,e,t)=>r&e^~r&t,jf=(r,e,t)=>r&e^r&t^e&t,cn=class extends sn{constructor(e,t,n,o){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=an(this.buffer)}update(e){on(this);let{view:t,buffer:n,blockLen:o}=this;e=ut(e);let s=e.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=an(e);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(e.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){on(this),$f(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;t[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)t[f]=0;Tb(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=an(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let l=c/4,u=this.get();if(l>u.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<l;f++)a.setUint32(4*f,u[f],s)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return e.length=o,e.pos=a,e.finished=s,e.destroyed=i,o%t&&e.buffer.set(n),e}};var bs=BigInt(4294967295),yc=BigInt(32);function Yf(r,e=!1){return e?{h:Number(r&bs),l:Number(r>>yc&bs)}:{h:Number(r>>yc&bs)|0,l:Number(r&bs)|0}}function _b(r,e=!1){let t=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let o=0;o<r.length;o++){let{h:s,l:i}=Yf(r[o],e);[t[o],n[o]]=[s,i]}return[t,n]}var Rb=(r,e)=>BigInt(r>>>0)<<yc|BigInt(e>>>0),Nb=(r,e,t)=>r>>>t,Lb=(r,e,t)=>r<<32-t|e>>>t,Ub=(r,e,t)=>r>>>t|e<<32-t,Ob=(r,e,t)=>r<<32-t|e>>>t,Pb=(r,e,t)=>r<<64-t|e>>>t-32,Mb=(r,e,t)=>r>>>t-32|e<<64-t,Fb=(r,e)=>e,Vb=(r,e)=>r,Hb=(r,e,t)=>r<<t|e>>>32-t,Kb=(r,e,t)=>e<<t|r>>>32-t,$b=(r,e,t)=>e<<t-32|r>>>64-t,qb=(r,e,t)=>r<<t-32|e>>>64-t;function Wb(r,e,t,n){let o=(e>>>0)+(n>>>0);return{h:r+t+(o/2**32|0)|0,l:o|0}}var zb=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),Gb=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,jb=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),Yb=(r,e,t,n,o)=>e+t+n+o+(r/2**32|0)|0,Zb=(r,e,t,n,o)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(o>>>0),Xb=(r,e,t,n,o,s)=>e+t+n+o+s+(r/2**32|0)|0;var Jb={fromBig:Yf,split:_b,toBig:Rb,shrSH:Nb,shrSL:Lb,rotrSH:Ub,rotrSL:Ob,rotrBH:Pb,rotrBL:Mb,rotr32H:Fb,rotr32L:Vb,rotlSH:Hb,rotlSL:Kb,rotlBH:$b,rotlBL:qb,add:Wb,add3L:zb,add3H:Gb,add4L:jb,add4H:Yb,add5H:Xb,add5L:Zb},Z=Jb;var[Qb,ey]=Z.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),rr=new Uint32Array(80),nr=new Uint32Array(80),wc=class extends cn{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:e,Al:t,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:l,El:u,Fh:f,Fl:g,Gh:m,Gl:d,Hh:h,Hl:p}=this;return[e,t,n,o,s,i,a,c,l,u,f,g,m,d,h,p]}set(e,t,n,o,s,i,a,c,l,u,f,g,m,d,h,p){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=l|0,this.El=u|0,this.Fh=f|0,this.Fl=g|0,this.Gh=m|0,this.Gl=d|0,this.Hh=h|0,this.Hl=p|0}process(e,t){for(let b=0;b<16;b++,t+=4)rr[b]=e.getUint32(t),nr[b]=e.getUint32(t+=4);for(let b=16;b<80;b++){let v=rr[b-15]|0,x=nr[b-15]|0,D=Z.rotrSH(v,x,1)^Z.rotrSH(v,x,8)^Z.shrSH(v,x,7),A=Z.rotrSL(v,x,1)^Z.rotrSL(v,x,8)^Z.shrSL(v,x,7),S=rr[b-2]|0,_=nr[b-2]|0,O=Z.rotrSH(S,_,19)^Z.rotrBH(S,_,61)^Z.shrSH(S,_,6),R=Z.rotrSL(S,_,19)^Z.rotrBL(S,_,61)^Z.shrSL(S,_,6),H=Z.add4L(A,R,nr[b-7],nr[b-16]),V=Z.add4H(H,D,O,rr[b-7],rr[b-16]);rr[b]=V|0,nr[b]=H|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:l,Dl:u,Eh:f,El:g,Fh:m,Fl:d,Gh:h,Gl:p,Hh:y,Hl:E}=this;for(let b=0;b<80;b++){let v=Z.rotrSH(f,g,14)^Z.rotrSH(f,g,18)^Z.rotrBH(f,g,41),x=Z.rotrSL(f,g,14)^Z.rotrSL(f,g,18)^Z.rotrBL(f,g,41),D=f&m^~f&h,A=g&d^~g&p,S=Z.add5L(E,x,A,ey[b],nr[b]),_=Z.add5H(S,y,v,D,Qb[b],rr[b]),O=S|0,R=Z.rotrSH(n,o,28)^Z.rotrBH(n,o,34)^Z.rotrBH(n,o,39),H=Z.rotrSL(n,o,28)^Z.rotrBL(n,o,34)^Z.rotrBL(n,o,39),V=n&s^n&a^s&a,G=o&i^o&c^i&c;y=h|0,E=p|0,h=m|0,p=d|0,m=f|0,d=g|0,{h:f,l:g}=Z.add(l|0,u|0,_|0,O|0),l=a|0,u=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let B=Z.add3L(O,H,G);n=Z.add3H(B,_,R,V),o=B|0}({h:n,l:o}=Z.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Z.add(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Z.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:u}=Z.add(this.Dh|0,this.Dl|0,l|0,u|0),{h:f,l:g}=Z.add(this.Eh|0,this.El|0,f|0,g|0),{h:m,l:d}=Z.add(this.Fh|0,this.Fl|0,m|0,d|0),{h,l:p}=Z.add(this.Gh|0,this.Gl|0,h|0,p|0),{h:y,l:E}=Z.add(this.Hh|0,this.Hl|0,y|0,E|0),this.set(n,o,s,i,a,c,l,u,f,g,m,d,h,p,y,E)}roundClean(){rr.fill(0),nr.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var jn=gs(()=>new wc);var ws={};Q(ws,{abytes:()=>ln,bitGet:()=>ay,bitLen:()=>iy,bitMask:()=>Yn,bitSet:()=>cy,bytesToHex:()=>Lt,bytesToNumberBE:()=>Ut,bytesToNumberLE:()=>ft,concatBytes:()=>Pt,createHmacDrbg:()=>vc,ensureBytes:()=>ce,equalBytes:()=>oy,hexToBytes:()=>_r,hexToNumber:()=>Ec,isBytes:()=>or,numberToBytesBE:()=>sr,numberToBytesLE:()=>Ot,numberToHexUnpadded:()=>Qf,numberToVarBytesBE:()=>ny,utf8ToBytes:()=>sy,validateObject:()=>et});var Jf=BigInt(0),ys=BigInt(1),ty=BigInt(2);function or(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function ln(r){if(!or(r))throw new Error("Uint8Array expected")}var ry=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function Lt(r){ln(r);let e="";for(let t=0;t<r.length;t++)e+=ry[r[t]];return e}function Qf(r){let e=r.toString(16);return e.length&1?`0${e}`:e}function Ec(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var Nt={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function Zf(r){if(r>=Nt._0&&r<=Nt._9)return r-Nt._0;if(r>=Nt._A&&r<=Nt._F)return r-(Nt._A-10);if(r>=Nt._a&&r<=Nt._f)return r-(Nt._a-10)}function _r(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let e=r.length,t=e/2;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(t);for(let o=0,s=0;o<t;o++,s+=2){let i=Zf(r.charCodeAt(s)),a=Zf(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Ut(r){return Ec(Lt(r))}function ft(r){return ln(r),Ec(Lt(Uint8Array.from(r).reverse()))}function sr(r,e){return _r(r.toString(16).padStart(e*2,"0"))}function Ot(r,e){return sr(r,e).reverse()}function ny(r){return _r(Qf(r))}function ce(r,e,t){let n;if(typeof e=="string")try{n=_r(e)}catch(s){throw new Error(`${r} must be valid hex string, got "${e}". Cause: ${s}`)}else if(or(e))n=Uint8Array.from(e);else throw new Error(`${r} must be hex string or Uint8Array`);let o=n.length;if(typeof t=="number"&&o!==t)throw new Error(`${r} expected ${t} bytes, got ${o}`);return n}function Pt(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];ln(o),e+=o.length}let t=new Uint8Array(e);for(let n=0,o=0;n<r.length;n++){let s=r[n];t.set(s,o),o+=s.length}return t}function oy(r,e){if(r.length!==e.length)return!1;let t=0;for(let n=0;n<r.length;n++)t|=r[n]^e[n];return t===0}function sy(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function iy(r){let e;for(e=0;r>Jf;r>>=ys,e+=1);return e}function ay(r,e){return r>>BigInt(e)&ys}function cy(r,e,t){return r|(t?ys:Jf)<<BigInt(e)}var Yn=r=>(ty<<BigInt(r-1))-ys,xc=r=>new Uint8Array(r),Xf=r=>Uint8Array.from(r);function vc(r,e,t){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof t!="function")throw new Error("hmacFn must be a function");let n=xc(r),o=xc(r),s=0,i=()=>{n.fill(1),o.fill(0),s=0},a=(...f)=>t(o,n,...f),c=(f=xc())=>{o=a(Xf([0]),f),n=a(),f.length!==0&&(o=a(Xf([1]),f),n=a())},l=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,g=[];for(;f<e;){n=a();let m=n.slice();g.push(m),f+=n.length}return Pt(...g)};return(f,g)=>{i(),c(f);let m;for(;!(m=g(l()));)c();return i(),m}}var ly={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||or(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,e)=>e.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function et(r,e,t={}){let n=(o,s,i)=>{let a=ly[s];if(typeof a!="function")throw new Error(`Invalid validator "${s}", expected function`);let c=r[o];if(!(i&&c===void 0)&&!a(c,r))throw new Error(`Invalid param ${String(o)}=${c} (${typeof c}), expected ${s}`)};for(let[o,s]of Object.entries(e))n(o,s,!1);for(let[o,s]of Object.entries(t))n(o,s,!0);return r}var ke=BigInt(0),fe=BigInt(1),Rr=BigInt(2),uy=BigInt(3),Ac=BigInt(4),eh=BigInt(5),th=BigInt(8),fy=BigInt(9),hy=BigInt(16);function te(r,e){let t=r%e;return t>=ke?t:e+t}function Dc(r,e,t){if(t<=ke||e<ke)throw new Error("Expected power/modulo > 0");if(t===fe)return ke;let n=fe;for(;e>ke;)e&fe&&(n=n*r%t),r=r*r%t,e>>=fe;return n}function le(r,e,t){let n=r;for(;e-- >ke;)n*=n,n%=t;return n}function xs(r,e){if(r===ke||e<=ke)throw new Error(`invert: expected positive integers, got n=${r} mod=${e}`);let t=te(r,e),n=e,o=ke,s=fe,i=fe,a=ke;for(;t!==ke;){let l=n/t,u=n%t,f=o-i*l,g=s-a*l;n=t,t=u,o=i,s=a,i=f,a=g}if(n!==fe)throw new Error("invert: does not exist");return te(o,e)}function dy(r){let e=(r-fe)/Rr,t,n,o;for(t=r-fe,n=0;t%Rr===ke;t/=Rr,n++);for(o=Rr;o<r&&Dc(o,e,r)!==r-fe;o++);if(n===1){let i=(r+fe)/Ac;return function(c,l){let u=c.pow(l,i);if(!c.eql(c.sqr(u),l))throw new Error("Cannot find square root");return u}}let s=(t+fe)/Rr;return function(a,c){if(a.pow(c,e)===a.neg(a.ONE))throw new Error("Cannot find square root");let l=n,u=a.pow(a.mul(a.ONE,o),t),f=a.pow(c,s),g=a.pow(c,t);for(;!a.eql(g,a.ONE);){if(a.eql(g,a.ZERO))return a.ZERO;let m=1;for(let h=a.sqr(g);m<l&&!a.eql(h,a.ONE);m++)h=a.sqr(h);let d=a.pow(u,fe<<BigInt(l-m-1));u=a.sqr(d),f=a.mul(f,d),g=a.mul(g,u),l=m}return f}}function py(r){if(r%Ac===uy){let e=(r+fe)/Ac;return function(n,o){let s=n.pow(o,e);if(!n.eql(n.sqr(s),o))throw new Error("Cannot find square root");return s}}if(r%th===eh){let e=(r-eh)/th;return function(n,o){let s=n.mul(o,Rr),i=n.pow(s,e),a=n.mul(o,i),c=n.mul(n.mul(a,Rr),i),l=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(l),o))throw new Error("Cannot find square root");return l}}return r%hy,dy(r)}var rh=(r,e)=>(te(r,e)&fe)===fe,my=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Sc(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=my.reduce((n,o)=>(n[o]="function",n),e);return et(r,t)}function gy(r,e,t){if(t<ke)throw new Error("Expected power > 0");if(t===ke)return r.ONE;if(t===fe)return e;let n=r.ONE,o=e;for(;t>ke;)t&fe&&(n=r.mul(n,o)),o=r.sqr(o),t>>=fe;return n}function by(r,e){let t=new Array(e.length),n=e.reduce((s,i,a)=>r.is0(i)?s:(t[a]=s,r.mul(s,i)),r.ONE),o=r.inv(n);return e.reduceRight((s,i,a)=>r.is0(i)?s:(t[a]=r.mul(s,t[a]),r.mul(s,i)),o),t}function Bc(r,e){let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function Es(r,e,t=!1,n={}){if(r<=ke)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:o,nByteLength:s}=Bc(r,e);if(s>2048)throw new Error("Field lengths over 2048 bytes are not supported");let i=py(r),a=Object.freeze({ORDER:r,BITS:o,BYTES:s,MASK:Yn(o),ZERO:ke,ONE:fe,create:c=>te(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return ke<=c&&c<r},is0:c=>c===ke,isOdd:c=>(c&fe)===fe,neg:c=>te(-c,r),eql:(c,l)=>c===l,sqr:c=>te(c*c,r),add:(c,l)=>te(c+l,r),sub:(c,l)=>te(c-l,r),mul:(c,l)=>te(c*l,r),pow:(c,l)=>gy(a,c,l),div:(c,l)=>te(c*xs(l,r),r),sqrN:c=>c*c,addN:(c,l)=>c+l,subN:(c,l)=>c-l,mulN:(c,l)=>c*l,inv:c=>xs(c,r),sqrt:n.sqrt||(c=>i(a,c)),invertBatch:c=>by(a,c),cmov:(c,l,u)=>u?l:c,toBytes:c=>t?Ot(c,s):sr(c,s),fromBytes:c=>{if(c.length!==s)throw new Error(`Fp.fromBytes: expected ${s}, got ${c.length}`);return t?ft(c):Ut(c)}});return Object.freeze(a)}function nh(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let e=r.toString(2).length;return Math.ceil(e/8)}function kc(r){let e=nh(r);return e+Math.ceil(e/2)}function oh(r,e,t=!1){let n=r.length,o=nh(e),s=kc(e);if(n<16||n<s||n>1024)throw new Error(`expected ${s}-1024 bytes of input, got ${n}`);let i=t?Ut(r):ft(r),a=te(i,e-fe)+fe;return t?Ot(a,o):sr(a,o)}var wy=BigInt(0),Cc=BigInt(1);function vs(r,e){let t=(o,s)=>{let i=s.negate();return o?i:s},n=o=>{let s=Math.ceil(e/o)+1,i=2**(o-1);return{windows:s,windowSize:i}};return{constTimeNegate:t,unsafeLadder(o,s){let i=r.ZERO,a=o;for(;s>wy;)s&Cc&&(i=i.add(a)),a=a.double(),s>>=Cc;return i},precomputeWindow(o,s){let{windows:i,windowSize:a}=n(s),c=[],l=o,u=l;for(let f=0;f<i;f++){u=l,c.push(u);for(let g=1;g<a;g++)u=u.add(l),c.push(u);l=u.double()}return c},wNAF(o,s,i){let{windows:a,windowSize:c}=n(o),l=r.ZERO,u=r.BASE,f=BigInt(2**o-1),g=2**o,m=BigInt(o);for(let d=0;d<a;d++){let h=d*c,p=Number(i&f);i>>=m,p>c&&(p-=g,i+=Cc);let y=h,E=h+Math.abs(p)-1,b=d%2!==0,v=p<0;p===0?u=u.add(t(b,s[y])):l=l.add(t(v,s[E]))}return{p:l,f:u}},wNAFCached(o,s,i,a){let c=o._WINDOW_SIZE||1,l=s.get(o);return l||(l=this.precomputeWindow(o,c),c!==1&&s.set(o,a(l))),this.wNAF(c,l,i)}}}function Zn(r){return Sc(r.Fp),et(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Bc(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var ht=BigInt(0),Ze=BigInt(1),As=BigInt(2),xy=BigInt(8),Ey={zip215:!0};function vy(r){let e=Zn(r);return et(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function sh(r){let e=vy(r),{Fp:t,n,prehash:o,hash:s,randomBytes:i,nByteLength:a,h:c}=e,l=As<<BigInt(a*8)-Ze,u=t.create,f=e.uvRatio||((k,w)=>{try{return{isValid:!0,value:t.sqrt(k*t.inv(w))}}catch{return{isValid:!1,value:ht}}}),g=e.adjustScalarBytes||(k=>k),m=e.domain||((k,w,C)=>{if(w.length||C)throw new Error("Contexts/pre-hash are not supported");return k}),d=k=>typeof k=="bigint"&&ht<k,h=(k,w)=>d(k)&&d(w)&&k<w,p=k=>k===ht||h(k,l);function y(k,w){if(h(k,w))return k;throw new Error(`Expected valid scalar < ${w}, got ${typeof k} ${k}`)}function E(k){return k===ht?k:y(k,n)}let b=new Map;function v(k){if(!(k instanceof x))throw new Error("ExtendedPoint expected")}class x{constructor(w,C,T,N){if(this.ex=w,this.ey=C,this.ez=T,this.et=N,!p(w))throw new Error("x required");if(!p(C))throw new Error("y required");if(!p(T))throw new Error("z required");if(!p(N))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(w){if(w instanceof x)throw new Error("extended point not allowed");let{x:C,y:T}=w||{};if(!p(C)||!p(T))throw new Error("invalid affine point");return new x(C,T,Ze,u(C*T))}static normalizeZ(w){let C=t.invertBatch(w.map(T=>T.ez));return w.map((T,N)=>T.toAffine(C[N])).map(x.fromAffine)}_setWindowSize(w){this._WINDOW_SIZE=w,b.delete(this)}assertValidity(){let{a:w,d:C}=e;if(this.is0())throw new Error("bad point: ZERO");let{ex:T,ey:N,ez:$,et:q}=this,Y=u(T*T),z=u(N*N),j=u($*$),ae=u(j*j),se=u(Y*w),Ie=u(j*u(se+z)),Te=u(ae+u(C*u(Y*z)));if(Ie!==Te)throw new Error("bad point: equation left != right (1)");let ve=u(T*N),Oe=u($*q);if(ve!==Oe)throw new Error("bad point: equation left != right (2)")}equals(w){v(w);let{ex:C,ey:T,ez:N}=this,{ex:$,ey:q,ez:Y}=w,z=u(C*Y),j=u($*N),ae=u(T*Y),se=u(q*N);return z===j&&ae===se}is0(){return this.equals(x.ZERO)}negate(){return new x(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:w}=e,{ex:C,ey:T,ez:N}=this,$=u(C*C),q=u(T*T),Y=u(As*u(N*N)),z=u(w*$),j=C+T,ae=u(u(j*j)-$-q),se=z+q,Ie=se-Y,Te=z-q,ve=u(ae*Ie),Oe=u(se*Te),kt=u(ae*Te),mr=u(Ie*se);return new x(ve,Oe,mr,kt)}add(w){v(w);let{a:C,d:T}=e,{ex:N,ey:$,ez:q,et:Y}=this,{ex:z,ey:j,ez:ae,et:se}=w;if(C===BigInt(-1)){let Zl=u(($-N)*(j+z)),Xl=u(($+N)*(j-z)),Oi=u(Xl-Zl);if(Oi===ht)return this.double();let Jl=u(q*As*se),Ql=u(Y*As*ae),eu=Ql+Jl,tu=Xl+Zl,ru=Ql-Jl,P0=u(eu*Oi),M0=u(tu*ru),F0=u(eu*ru),V0=u(Oi*tu);return new x(P0,M0,V0,F0)}let Ie=u(N*z),Te=u($*j),ve=u(Y*T*se),Oe=u(q*ae),kt=u((N+$)*(z+j)-Ie-Te),mr=Oe-ve,Nn=Oe+ve,Yl=u(Te-C*Ie),N0=u(kt*mr),L0=u(Nn*Yl),U0=u(kt*Yl),O0=u(mr*Nn);return new x(N0,L0,O0,U0)}subtract(w){return this.add(w.negate())}wNAF(w){return S.wNAFCached(this,b,w,x.normalizeZ)}multiply(w){let{p:C,f:T}=this.wNAF(y(w,n));return x.normalizeZ([C,T])[0]}multiplyUnsafe(w){let C=E(w);return C===ht?A:this.equals(A)||C===Ze?this:this.equals(D)?this.wNAF(C).p:S.unsafeLadder(this,C)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return S.unsafeLadder(this,n).is0()}toAffine(w){let{ex:C,ey:T,ez:N}=this,$=this.is0();w==null&&(w=$?xy:t.inv(N));let q=u(C*w),Y=u(T*w),z=u(N*w);if($)return{x:ht,y:Ze};if(z!==Ze)throw new Error("invZ was invalid");return{x:q,y:Y}}clearCofactor(){let{h:w}=e;return w===Ze?this:this.multiplyUnsafe(w)}static fromHex(w,C=!1){let{d:T,a:N}=e,$=t.BYTES;w=ce("pointHex",w,$);let q=w.slice(),Y=w[$-1];q[$-1]=Y&-129;let z=ft(q);z===ht||(C?y(z,l):y(z,t.ORDER));let j=u(z*z),ae=u(j-Ze),se=u(T*j-N),{isValid:Ie,value:Te}=f(ae,se);if(!Ie)throw new Error("Point.fromHex: invalid y coordinate");let ve=(Te&Ze)===Ze,Oe=(Y&128)!==0;if(!C&&Te===ht&&Oe)throw new Error("Point.fromHex: x=0 and x_0=1");return Oe!==ve&&(Te=u(-Te)),x.fromAffine({x:Te,y:z})}static fromPrivateKey(w){return R(w).point}toRawBytes(){let{x:w,y:C}=this.toAffine(),T=Ot(C,t.BYTES);return T[T.length-1]|=w&Ze?128:0,T}toHex(){return Lt(this.toRawBytes())}}x.BASE=new x(e.Gx,e.Gy,Ze,u(e.Gx*e.Gy)),x.ZERO=new x(ht,Ze,Ze,ht);let{BASE:D,ZERO:A}=x,S=vs(x,a*8);function _(k){return te(k,n)}function O(k){return _(ft(k))}function R(k){let w=a;k=ce("private key",k,w);let C=ce("hashed private key",s(k),2*w),T=g(C.slice(0,w)),N=C.slice(w,2*w),$=O(T),q=D.multiply($),Y=q.toRawBytes();return{head:T,prefix:N,scalar:$,point:q,pointBytes:Y}}function H(k){return R(k).pointBytes}function V(k=new Uint8Array,...w){let C=Pt(...w);return O(s(m(C,ce("context",k),!!o)))}function G(k,w,C={}){k=ce("message",k),o&&(k=o(k));let{prefix:T,scalar:N,pointBytes:$}=R(w),q=V(C.context,T,k),Y=D.multiply(q).toRawBytes(),z=V(C.context,Y,$,k),j=_(q+z*N);E(j);let ae=Pt(Y,Ot(j,t.BYTES));return ce("result",ae,a*2)}let B=Ey;function I(k,w,C,T=B){let{context:N,zip215:$}=T,q=t.BYTES;k=ce("signature",k,2*q),w=ce("message",w),o&&(w=o(w));let Y=ft(k.slice(q,2*q)),z,j,ae;try{z=x.fromHex(C,$),j=x.fromHex(k.slice(0,q),$),ae=D.multiplyUnsafe(Y)}catch{return!1}if(!$&&z.isSmallOrder())return!1;let se=V(N,j.toRawBytes(),z.toRawBytes(),w);return j.add(z.multiplyUnsafe(se)).subtract(ae).clearCofactor().equals(x.ZERO)}return D._setWindowSize(8),{CURVE:e,getPublicKey:H,sign:G,verify:I,ExtendedPoint:x,utils:{getExtendedPublicKey:R,randomPrivateKey:()=>i(t.BYTES),precompute(k=8,w=x.BASE){return w._setWindowSize(k),w.multiply(BigInt(3)),w}}}}var Xn=BigInt(0),Ic=BigInt(1);function Ay(r){return et(r,{a:"bigint"},{montgomeryBits:"isSafeInteger",nByteLength:"isSafeInteger",adjustScalarBytes:"function",domain:"function",powPminus2:"function",Gu:"bigint"}),Object.freeze({...r})}function ih(r){let e=Ay(r),{P:t}=e,n=b=>te(b,t),o=e.montgomeryBits,s=Math.ceil(o/8),i=e.nByteLength,a=e.adjustScalarBytes||(b=>b),c=e.powPminus2||(b=>Dc(b,t-BigInt(2),t));function l(b,v,x){let D=n(b*(v-x));return v=n(v-D),x=n(x+D),[v,x]}function u(b){if(typeof b=="bigint"&&Xn<=b&&b<t)return b;throw new Error("Expected valid scalar 0 < scalar < CURVE.P")}let f=(e.a-BigInt(2))/BigInt(4);function g(b,v){let x=u(b),D=u(v),A=x,S=Ic,_=Xn,O=x,R=Ic,H=Xn,V;for(let B=BigInt(o-1);B>=Xn;B--){let I=D>>B&Ic;H^=I,V=l(H,S,O),S=V[0],O=V[1],V=l(H,_,R),_=V[0],R=V[1],H=I;let P=S+_,k=n(P*P),w=S-_,C=n(w*w),T=k-C,N=O+R,$=O-R,q=n($*P),Y=n(N*w),z=q+Y,j=q-Y;O=n(z*z),R=n(A*n(j*j)),S=n(k*C),_=n(T*(k+n(f*T)))}V=l(H,S,O),S=V[0],O=V[1],V=l(H,_,R),_=V[0],R=V[1];let G=c(_);return n(S*G)}function m(b){return Ot(n(b),s)}function d(b){let v=ce("u coordinate",b,s);return i===32&&(v[31]&=127),ft(v)}function h(b){let v=ce("scalar",b),x=v.length;if(x!==s&&x!==i)throw new Error(`Expected ${s} or ${i} bytes, got ${x}`);return ft(a(v))}function p(b,v){let x=d(v),D=h(b),A=g(x,D);if(A===Xn)throw new Error("Invalid private or public key received");return m(A)}let y=m(e.Gu);function E(b){return p(b,y)}return{scalarMult:p,scalarMultBase:E,getSharedSecret:(b,v)=>p(b,v),getPublicKey:b=>E(b),utils:{randomPrivateKey:()=>e.randomBytes(e.nByteLength)},GuBytes:y}}var Jn=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),ah=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),cD=BigInt(0),Dy=BigInt(1),ch=BigInt(2),Sy=BigInt(3),By=BigInt(5),ky=BigInt(8);function lh(r){let e=BigInt(10),t=BigInt(20),n=BigInt(40),o=BigInt(80),s=Jn,a=r*r%s*r%s,c=le(a,ch,s)*a%s,l=le(c,Dy,s)*r%s,u=le(l,By,s)*l%s,f=le(u,e,s)*u%s,g=le(f,t,s)*f%s,m=le(g,n,s)*g%s,d=le(m,o,s)*m%s,h=le(d,o,s)*m%s,p=le(h,e,s)*u%s;return{pow_p_5_8:le(p,ch,s)*r%s,b2:a}}function uh(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Cy(r,e){let t=Jn,n=te(e*e*e,t),o=te(n*n*e,t),s=lh(r*o).pow_p_5_8,i=te(r*n*s,t),a=te(e*i*i,t),c=i,l=te(i*ah,t),u=a===r,f=a===te(-r,t),g=a===te(-r*ah,t);return u&&(i=c),(f||g)&&(i=l),rh(i,t)&&(i=te(-i,t)),{isValid:u||f,value:i}}var Iy=Es(Jn,void 0,!0),Ty={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Iy,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:ky,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:jn,randomBytes:Tr,adjustScalarBytes:uh,uvRatio:Cy},un=sh(Ty);var Qn=ih({P:Jn,a:BigInt(486662),montgomeryBits:255,nByteLength:32,Gu:BigInt(9),powPminus2:r=>{let e=Jn,{pow_p_5_8:t,b2:n}=lh(r);return te(le(t,Sy,e)*n,e)},adjustScalarBytes:uh,randomBytes:Tr});var fn=32,Mt=64,Ds=32;function fh(){let r=un.utils.randomPrivateKey(),e=un.getPublicKey(r);return{privateKey:mh(r,e),publicKey:e}}function hh(r){if(r.length!==Ds)throw new TypeError('"seed" must be 32 bytes in length.');if(!(r instanceof Uint8Array))throw new TypeError('"seed" must be a node.js Buffer, or Uint8Array.');let e=r,t=un.getPublicKey(e);return{privateKey:mh(e,t),publicKey:t}}function dh(r,e){let t=r.subarray(0,Ds);return un.sign(e instanceof Uint8Array?e:e.subarray(),t)}function ph(r,e,t){return un.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}function mh(r,e){let t=new Uint8Array(Mt);for(let n=0;n<Ds;n++)t[n]=r[n],t[Ds+n]=e[n];return t}var Ve={get(r=globalThis){let e=r.crypto;if(e==null||e.subtle==null)throw Object.assign(new Error("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api"),{code:"ERR_MISSING_WEB_CRYPTO"});return e}};var Tc={alg:"A128GCM",ext:!0,k:"scm9jmO_4BJAgdwWGVulLg",key_ops:["encrypt","decrypt"],kty:"oct"};function gh(r){let e=r?.algorithm??"AES-GCM",t=r?.keyLength??16,n=r?.nonceLength??12,o=r?.digest??"SHA-256",s=r?.saltLength??16,i=r?.iterations??32767,a=Ve.get();t*=8;async function c(f,g){let m=a.getRandomValues(new Uint8Array(s)),d=a.getRandomValues(new Uint8Array(n)),h={name:e,iv:d};typeof g=="string"&&(g=J(g));let p;if(g.length===0){p=await a.subtle.importKey("jwk",Tc,{name:"AES-GCM"},!0,["encrypt"]);try{let E={name:"PBKDF2",salt:m,iterations:i,hash:{name:o}},b=await a.subtle.importKey("raw",g,{name:"PBKDF2"},!1,["deriveKey"]);p=await a.subtle.deriveKey(E,b,{name:e,length:t},!0,["encrypt"])}catch{p=await a.subtle.importKey("jwk",Tc,{name:"AES-GCM"},!0,["encrypt"])}}else{let E={name:"PBKDF2",salt:m,iterations:i,hash:{name:o}},b=await a.subtle.importKey("raw",g,{name:"PBKDF2"},!1,["deriveKey"]);p=await a.subtle.deriveKey(E,b,{name:e,length:t},!0,["encrypt"])}let y=await a.subtle.encrypt(h,p,f);return xe([m,h.iv,new Uint8Array(y)])}async function l(f,g){let m=f.subarray(0,s),d=f.subarray(s,s+n),h=f.subarray(s+n),p={name:e,iv:d};typeof g=="string"&&(g=J(g));let y;if(g.length===0)try{let b={name:"PBKDF2",salt:m,iterations:i,hash:{name:o}},v=await a.subtle.importKey("raw",g,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(b,v,{name:e,length:t},!0,["decrypt"])}catch{y=await a.subtle.importKey("jwk",Tc,{name:"AES-GCM"},!0,["decrypt"])}else{let b={name:"PBKDF2",salt:m,iterations:i,hash:{name:o}},v=await a.subtle.importKey("raw",g,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(b,v,{name:e,length:t},!0,["decrypt"])}let E=await a.subtle.decrypt(p,y,h);return new Uint8Array(E)}return{encrypt:c,decrypt:l}}async function hn(r,e){let n=await gh().encrypt(r,e);return Zi.encode(n)}var he;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.Secp256k1="Secp256k1"})(he||(he={}));var _c;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.Secp256k1=2]="Secp256k1"})(_c||(_c={}));(function(r){r.codec=()=>Sr(_c)})(he||(he={}));var Et;(function(r){let e;r.codec=()=>(e==null&&(e=ct((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),he.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let o={},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let i=t.uint32();switch(i>>>3){case 1:o.Type=he.codec().decode(t);break;case 2:o.Data=t.bytes();break;default:t.skipType(i&7);break}}return o})),e),r.encode=t=>at(t,r.codec()),r.decode=t=>it(t,r.codec())})(Et||(Et={}));var vt;(function(r){let e;r.codec=()=>(e==null&&(e=ct((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),he.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let o={},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let i=t.uint32();switch(i>>>3){case 1:o.Type=he.codec().decode(t);break;case 2:o.Data=t.bytes();break;default:t.skipType(i&7);break}}return o})),e),r.encode=t=>at(t,r.codec()),r.decode=t=>it(t,r.codec())})(vt||(vt={}));var eo=class{_key;constructor(e){this._key=dn(e,fn)}verify(e,t){return ph(this._key,t,e)}marshal(){return this._key}get bytes(){return Et.encode({Type:he.Ed25519,Data:this.marshal()}).subarray()}equals(e){return Ae(this.bytes,e.bytes)}hash(){let e=_e.digest(this.bytes);return Qe(e)?e.then(({bytes:t})=>t):e.bytes}},Nr=class{_key;_publicKey;constructor(e,t){this._key=dn(e,Mt),this._publicKey=dn(t,fn)}sign(e){return dh(this._key,e)}get public(){return new eo(this._publicKey)}marshal(){return this._key}get bytes(){return vt.encode({Type:he.Ed25519,Data:this.marshal()}).subarray()}equals(e){return Ae(this.bytes,e.bytes)}async hash(){let e=_e.digest(this.bytes),t;return Qe(e)?{bytes:t}=await e:t=e.bytes,t}async id(){let e=Tt.digest(this.public.bytes);return ge.encode(e.bytes).substring(1)}async export(e,t="libp2p-key"){if(t==="libp2p-key")return hn(this.bytes,e);throw new L(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function Ny(r){if(r.length>Mt){r=dn(r,Mt+fn);let n=r.subarray(0,Mt),o=r.subarray(Mt,r.length);return new Nr(n,o)}r=dn(r,Mt);let e=r.subarray(0,Mt),t=r.subarray(fn);return new Nr(e,t)}function Ly(r){return r=dn(r,fn),new eo(r)}async function Uy(){let{privateKey:r,publicKey:e}=fh();return new Nr(r,e)}async function bh(r){let{privateKey:e,publicKey:t}=hh(r);return new Nr(e,t)}function dn(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new L(`Key must be a Uint8Array of length ${e}, got ${r.length}`,"ERR_INVALID_KEY_TYPE");return r}var Kc={};Q(Kc,{MAX_RSA_KEY_SIZE:()=>fo,RsaPrivateKey:()=>yn,RsaPublicKey:()=>uo,fromJwk:()=>cw,generateKeyPair:()=>lw,unmarshalRsaPrivateKey:()=>Vc,unmarshalRsaPublicKey:()=>aw});function Lr(r){if(isNaN(r)||r<=0)throw new L("random bytes length must be a Number bigger than 0","ERR_INVALID_LENGTH");return Tr(r)}var ur={};Q(ur,{exportToPem:()=>rw,importFromPem:()=>nw,jwkToPkcs1:()=>Jy,jwkToPkix:()=>ew,pkcs1ToJwk:()=>Xy,pkixToJwk:()=>Qy});var Bs=class extends sn{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,Ir(e);let n=ut(t);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?e.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=e.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),s.fill(0)}update(e){return on(this),this.iHash.update(e),this}digestInto(e){on(this),nn(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:t,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=a,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},ir=(r,e,t)=>new Bs(r,e).update(t).digest();ir.create=(r,e)=>new Bs(r,e);function Oy(r,e,t,n){Ir(r);let o=zf({dkLen:32,asyncTick:10},n),{c:s,dkLen:i,asyncTick:a}=o;if(tr(s),tr(i),tr(a),s<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let c=ut(e),l=ut(t),u=new Uint8Array(i),f=ir.create(r,c),g=f._cloneInto().update(l);return{c:s,dkLen:i,asyncTick:a,DK:u,PRF:f,PRFSalt:g}}function Py(r,e,t,n,o){return r.destroy(),e.destroy(),n&&n.destroy(),o.fill(0),t}async function Nc(r,e,t,n){let{c:o,dkLen:s,asyncTick:i,DK:a,PRF:c,PRFSalt:l}=Oy(r,e,t,n),u,f=new Uint8Array(4),g=an(f),m=new Uint8Array(c.outputLen);for(let d=1,h=0;h<s;d++,h+=c.outputLen){let p=a.subarray(h,h+c.outputLen);g.setInt32(0,d,!1),(u=l._cloneInto(u)).update(f).digestInto(m),p.set(m.subarray(0,p.length)),await qf(o-1,i,()=>{c._cloneInto(u).update(m).digestInto(m);for(let y=0;y<p.length;y++)p[y]^=m[y]})}return Py(c,l,a,u,m)}var X=ko(yh());function Ur(r,e){let t=0;if(r.length===1)return r[0];for(let n=r.length-1;n>=0;n--)t+=r[r.length-1-n]*Math.pow(2,e*n);return t}function ar(r,e,t=-1){let n=t,o=r,s=0,i=Math.pow(2,e);for(let a=1;a<8;a++){if(r<i){let c;if(n<0)c=new ArrayBuffer(a),s=a;else{if(n<a)return new ArrayBuffer(0);c=new ArrayBuffer(n),s=n}let l=new Uint8Array(c);for(let u=a-1;u>=0;u--){let f=Math.pow(2,u*e);l[s-u-1]=Math.floor(o/f),o-=l[s-u-1]*f}return c}i*=Math.pow(2,e)}return new ArrayBuffer(0)}function Is(...r){let e=0,t=0;for(let s of r)e+=s.length;let n=new ArrayBuffer(e),o=new Uint8Array(n);for(let s of r)o.set(s,t),t+=s.length;return o}function Uc(){let r=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){let a=r[0]===255&&r[1]&128,c=r[0]===0&&(r[1]&128)===0;(a||c)&&this.warnings.push("Needlessly long format")}let e=new ArrayBuffer(this.valueHex.byteLength),t=new Uint8Array(e);for(let a=0;a<this.valueHex.byteLength;a++)t[a]=0;t[0]=r[0]&128;let n=Ur(t,8),o=new ArrayBuffer(this.valueHex.byteLength),s=new Uint8Array(o);for(let a=0;a<this.valueHex.byteLength;a++)s[a]=r[a];return s[0]&=127,Ur(s,8)-n}function wh(r){let e=r<0?r*-1:r,t=128;for(let n=1;n<8;n++){if(e<=t){if(r<0){let i=t-e,a=ar(i,8,n),c=new Uint8Array(a);return c[0]|=128,a}let o=ar(e,8,n),s=new Uint8Array(o);if(s[0]&128){let i=o.slice(0),a=new Uint8Array(i);o=new ArrayBuffer(o.byteLength+1),s=new Uint8Array(o);for(let c=0;c<i.byteLength;c++)s[c+1]=a[c];s[0]=0}return o}t*=Math.pow(2,8)}return new ArrayBuffer(0)}function xh(r,e){if(r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let o=0;o<t.length;o++)if(t[o]!==n[o])return!1;return!0}function We(r,e){let t=r.toString(10);if(e<t.length)return"";let n=e-t.length,o=new Array(n);for(let i=0;i<n;i++)o[i]="0";return o.join("").concat(t)}var OD=Math.log(2);function Ts(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function Oc(r){let e=0,t=0;for(let o=0;o<r.length;o++){let s=r[o];e+=s.byteLength}let n=new Uint8Array(e);for(let o=0;o<r.length;o++){let s=r[o];n.set(new Uint8Array(s),t),t+=s.byteLength}return n.buffer}function $t(r,e,t,n){return e instanceof Uint8Array?e.byteLength?t<0?(r.error="Wrong parameter: inputOffset less than zero",!1):n<0?(r.error="Wrong parameter: inputLength less than zero",!1):e.byteLength-t-n<0?(r.error="End of input reached before message was fully decoded (inconsistent offset and length values)",!1):!0:(r.error="Wrong parameter: inputBuffer has zero length",!1):(r.error="Wrong parameter: inputBuffer must be 'Uint8Array'",!1)}var ro=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return Oc(this.items)}},to=[new Uint8Array([1])],Eh="0123456789";var gn="",pt=new ArrayBuffer(0),Pc=new Uint8Array(0),no="EndOfContent",Ah="OCTET STRING",Dh="BIT STRING";function qt(r){var e;return e=class extends r{constructor(...n){var o;super(...n);let s=n[0]||{};this.isHexOnly=(o=s.isHexOnly)!==null&&o!==void 0?o:!1,this.valueHexView=s.valueHex?X.BufferSourceConverter.toUint8Array(s.valueHex):Pc}get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}fromBER(n,o,s){let i=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!$t(this,i,o,s))return-1;let a=o+s;return this.valueHexView=i.subarray(o,a),this.valueHexView.length?(this.blockLength=s,a):(this.warnings.push("Zero buffer length"),o)}toBER(n=!1){return this.isHexOnly?n?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.byteLength===this.valueHexView.buffer.byteLength?this.valueHexView.buffer:this.valueHexView.slice().buffer:(this.error="Flag 'isHexOnly' is not set, abort",pt)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:X.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var Vt=class{constructor({blockLength:e=0,error:t=gn,warnings:n=[],valueBeforeDecode:o=Pc}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=X.BufferSourceConverter.toUint8Array(o)}static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(e){this.valueBeforeDecodeView=new Uint8Array(e)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:X.Convert.ToHex(this.valueBeforeDecodeView)}}};Vt.NAME="baseBlock";var Fe=class extends Vt{fromBER(e,t,n){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}toBER(e,t){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}};Fe.NAME="valueBlock";var _s=class extends qt(Vt){constructor({idBlock:e={}}={}){var t,n,o,s;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?X.BufferSourceConverter.toUint8Array(e.valueHex):Pc,this.tagClass=(n=e.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(o=e.tagNumber)!==null&&o!==void 0?o:-1,this.isConstructed=(s=e.isConstructed)!==null&&s!==void 0?s:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(e=!1){let t=0;switch(this.tagClass){case 1:t|=0;break;case 2:t|=64;break;case 3:t|=128;break;case 4:t|=192;break;default:return this.error="Unknown tag class",pt}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){let o=new Uint8Array(1);if(!e){let s=this.tagNumber;s&=31,t|=s,o[0]=t}return o.buffer}if(!this.isHexOnly){let o=ar(this.tagNumber,7),s=new Uint8Array(o),i=o.byteLength,a=new Uint8Array(i+1);if(a[0]=t|31,!e){for(let c=0;c<i-1;c++)a[c+1]=s[c]|128;a[i]=s[i-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=t|31,!e){let o=this.valueHexView;for(let s=0;s<o.length-1;s++)n[s+1]=o[s]|128;n[this.valueHexView.byteLength]=o[o.length-1]}return n.buffer}fromBER(e,t,n){let o=X.BufferSourceConverter.toUint8Array(e);if(!$t(this,o,t,n))return-1;let s=o.subarray(t,t+n);if(s.length===0)return this.error="Zero buffer length",-1;switch(s[0]&192){case 0:this.tagClass=1;break;case 64:this.tagClass=2;break;case 128:this.tagClass=3;break;case 192:this.tagClass=4;break;default:return this.error="Unknown tag class",-1}this.isConstructed=(s[0]&32)===32,this.isHexOnly=!1;let a=s[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=1,l=this.valueHexView=new Uint8Array(255),u=255;for(;s[c]&128;){if(l[c-1]=s[c]&127,c++,c>=s.length)return this.error="End of input reached before message was fully decoded",-1;if(c===u){u+=255;let g=new Uint8Array(u);for(let m=0;m<l.length;m++)g[m]=l[m];l=this.valueHexView=new Uint8Array(u)}}this.blockLength=c+1,l[c-1]=s[c]&127;let f=new Uint8Array(c);for(let g=0;g<c;g++)f[g]=l[g];l=this.valueHexView=new Uint8Array(c),l.set(f),this.blockLength<=9?this.tagNumber=Ur(l,7):(this.isHexOnly=!0,this.warnings.push("Tag too long, represented as hex-coded"))}if(this.tagClass===1&&this.isConstructed)switch(this.tagNumber){case 1:case 2:case 5:case 6:case 9:case 13:case 14:case 23:case 24:case 31:case 32:case 33:case 34:return this.error="Constructed encoding used for primitive type",-1}return t+this.blockLength}toJSON(){return{...super.toJSON(),tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed}}};_s.NAME="identificationBlock";var Rs=class extends Vt{constructor({lenBlock:e={}}={}){var t,n,o;super(),this.isIndefiniteForm=(t=e.isIndefiniteForm)!==null&&t!==void 0?t:!1,this.longFormUsed=(n=e.longFormUsed)!==null&&n!==void 0?n:!1,this.length=(o=e.length)!==null&&o!==void 0?o:0}fromBER(e,t,n){let o=X.BufferSourceConverter.toUint8Array(e);if(!$t(this,o,t,n))return-1;let s=o.subarray(t,t+n);if(s.length===0)return this.error="Zero buffer length",-1;if(s[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=s[0]===128,this.isIndefiniteForm)return this.blockLength=1,t+this.blockLength;if(this.longFormUsed=!!(s[0]&128),this.longFormUsed===!1)return this.length=s[0],this.blockLength=1,t+this.blockLength;let i=s[0]&127;if(i>8)return this.error="Too big integer",-1;if(i+1>s.length)return this.error="End of input reached before message was fully decoded",-1;let a=t+1,c=o.subarray(a,a+i);return c[i-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=Ur(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=i+1,t+this.blockLength}toBER(e=!1){let t,n;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=128),t;if(this.longFormUsed){let o=ar(this.length,8);if(o.byteLength>127)return this.error="Too big length",pt;if(t=new ArrayBuffer(o.byteLength+1),e)return t;let s=new Uint8Array(o);n=new Uint8Array(t),n[0]=o.byteLength|128;for(let i=0;i<o.byteLength;i++)n[i+1]=s[i];return t}return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=this.length),t}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}};Rs.NAME="lengthBlock";var M={},Ne=class extends Vt{constructor({name:e=gn,optional:t=!1,primitiveSchema:n,...o}={},s){super(o),this.name=e,this.optional=t,n&&(this.primitiveSchema=n),this.idBlock=new _s(o),this.lenBlock=new Rs(o),this.valueBlock=s?new s(o):new Fe(o)}fromBER(e,t,n){let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),o)}toBER(e,t){let n=t||new ro;t||Sh(this);let o=this.idBlock.toBER(e);if(n.write(o),this.lenBlock.isIndefiniteForm)n.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,n),n.write(new ArrayBuffer(2));else{let s=this.valueBlock.toBER(e);this.lenBlock.length=s.byteLength;let i=this.lenBlock.toBER(e);n.write(i),n.write(s)}return t?pt:n.final()}toJSON(){let e={...super.toJSON(),idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional};return this.primitiveSchema&&(e.primitiveSchema=this.primitiveSchema.toJSON()),e}toString(e="ascii"){return e==="ascii"?this.onAsciiEncoding():X.Convert.ToHex(this.toBER())}onAsciiEncoding(){return`${this.constructor.NAME} : ${X.Convert.ToHex(this.valueBlock.valueBeforeDecodeView)}`}isEqual(e){if(this===e)return!0;if(!(e instanceof this.constructor))return!1;let t=this.toBER(),n=e.toBER();return xh(t,n)}};Ne.NAME="BaseBlock";function Sh(r){if(r instanceof M.Constructed)for(let e of r.valueBlock.value)Sh(e)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var Ns=class extends Ne{constructor({value:e=gn,...t}={},n){super(t,n),e&&this.fromString(e)}getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}fromBER(e,t,n){let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(this.fromBuffer(this.valueBlock.valueHexView),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),o)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}};Ns.NAME="BaseStringBlock";var Ls=class extends qt(Fe){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};Ls.NAME="PrimitiveValueBlock";var Bh,Us=class extends Ne{constructor(e={}){super(e,Ls),this.idBlock.isConstructed=!1}};Bh=Us;M.Primitive=Bh;Us.NAME="PRIMITIVE";function zy(r,e){if(r instanceof e)return r;let t=new e;return t.idBlock=r.idBlock,t.lenBlock=r.lenBlock,t.warnings=r.warnings,t.valueBeforeDecodeView=r.valueBeforeDecodeView,t}function pi(r,e=0,t=r.length){let n=e,o=new Ne({},Fe),s=new Vt;if(!$t(s,r,e,t))return o.error=s.error,{offset:-1,result:o};if(!r.subarray(e,e+t).length)return o.error="Zero buffer length",{offset:-1,result:o};let a=o.idBlock.fromBER(r,e,t);if(o.idBlock.warnings.length&&o.warnings.concat(o.idBlock.warnings),a===-1)return o.error=o.idBlock.error,{offset:-1,result:o};if(e=a,t-=o.idBlock.blockLength,a=o.lenBlock.fromBER(r,e,t),o.lenBlock.warnings.length&&o.warnings.concat(o.lenBlock.warnings),a===-1)return o.error=o.lenBlock.error,{offset:-1,result:o};if(e=a,t-=o.lenBlock.blockLength,!o.idBlock.isConstructed&&o.lenBlock.isIndefiniteForm)return o.error="Indefinite length form used for primitive encoding form",{offset:-1,result:o};let c=Ne;switch(o.idBlock.tagClass){case 1:if(o.idBlock.tagNumber>=37&&o.idBlock.isHexOnly===!1)return o.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:o};switch(o.idBlock.tagNumber){case 0:if(o.idBlock.isConstructed&&o.lenBlock.length>0)return o.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:o};c=M.EndOfContent;break;case 1:c=M.Boolean;break;case 2:c=M.Integer;break;case 3:c=M.BitString;break;case 4:c=M.OctetString;break;case 5:c=M.Null;break;case 6:c=M.ObjectIdentifier;break;case 10:c=M.Enumerated;break;case 12:c=M.Utf8String;break;case 13:c=M.RelativeObjectIdentifier;break;case 14:c=M.TIME;break;case 15:return o.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:o};case 16:c=M.Sequence;break;case 17:c=M.Set;break;case 18:c=M.NumericString;break;case 19:c=M.PrintableString;break;case 20:c=M.TeletexString;break;case 21:c=M.VideotexString;break;case 22:c=M.IA5String;break;case 23:c=M.UTCTime;break;case 24:c=M.GeneralizedTime;break;case 25:c=M.GraphicString;break;case 26:c=M.VisibleString;break;case 27:c=M.GeneralString;break;case 28:c=M.UniversalString;break;case 29:c=M.CharacterString;break;case 30:c=M.BmpString;break;case 31:c=M.DATE;break;case 32:c=M.TimeOfDay;break;case 33:c=M.DateTime;break;case 34:c=M.Duration;break;default:{let l=o.idBlock.isConstructed?new M.Constructed:new M.Primitive;l.idBlock=o.idBlock,l.lenBlock=o.lenBlock,l.warnings=o.warnings,o=l}}break;case 2:case 3:case 4:default:c=o.idBlock.isConstructed?M.Constructed:M.Primitive}return o=zy(o,c),a=o.fromBER(r,e,o.lenBlock.isIndefiniteForm?t:o.lenBlock.length),o.valueBeforeDecodeView=r.subarray(n,n+o.blockLength),{offset:a,result:o}}function bn(r){if(!r.byteLength){let e=new Ne({},Fe);return e.error="Input buffer has zero length",{offset:-1,result:e}}return pi(X.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function Gy(r,e){return r?1:e}var At=class extends Fe{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let o=X.BufferSourceConverter.toUint8Array(e);if(!$t(this,o,t,n))return-1;if(this.valueBeforeDecodeView=o.subarray(t,t+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),t;let s=t;for(;Gy(this.isIndefiniteForm,n)>0;){let i=pi(o,s,n);if(i.offset===-1)return this.error=i.result.error,this.warnings.concat(i.result.warnings),-1;if(s=i.offset,this.blockLength+=i.result.blockLength,n-=i.result.blockLength,this.value.push(i.result),this.isIndefiniteForm&&i.result.constructor.NAME===no)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===no?this.value.pop():this.warnings.push("No EndOfContent block encoded")),s}toBER(e,t){let n=t||new ro;for(let o=0;o<this.value.length;o++)this.value[o].toBER(e,n);return t?pt:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};At.NAME="ConstructedValueBlock";var kh,cr=class extends Ne{constructor(e={}){super(e,At),this.idBlock.isConstructed=!0}fromBER(e,t,n){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),o)}onAsciiEncoding(){let e=[];for(let n of this.valueBlock.value)e.push(n.toString("ascii").split(`
16
+ `});var l0=re(()=>{c0();Bi();dr();Pl();Ao()});var Vl,b6,u0=re(()=>{Pp();Mp();Fp();Vp();Hp();Cl();Kp();_l();$p();Wp();e0();n0();o0();s0();l0();Vl={...vl,...Al,...Dl,...Sl,...Bl,...kl,...Il,...Tl,...Rl,...Nl},b6={...Ml,...Fl}});function Tn(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}var Ti=re(()=>{});function _i(r=0){return globalThis.Buffer!=null&&globalThis.Buffer.allocUnsafe!=null?Tn(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}var Hl=re(()=>{Ti()});function h0(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var f0,Kl,P2,Ri,$l=re(()=>{u0();Hl();f0=h0("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Kl=h0("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=_i(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),P2={utf8:f0,"utf-8":f0,hex:Vl.base16,latin1:Kl,ascii:Kl,binary:Kl,...Vl},Ri=P2});var d0={};Q(d0,{toString:()=>M2});function M2(r,e="utf8"){let t=Ri[e];if(!t)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}var p0=re(()=>{$l()});var m0={};Q(m0,{fromString:()=>F2});function F2(r,e="utf8"){let t=Ri[e];if(!t)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?Tn(globalThis.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}var g0=re(()=>{$l();Ti()});var b0={};Q(b0,{concat:()=>V2});function V2(r,e){e||(e=r.reduce((o,s)=>o+s.length,0));let t=_i(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return Tn(t)}var y0=re(()=>{Hl();Ti()});var Wl=Ke((T6,D0)=>{"use strict";var w0=gp(),_n=kp(),{names:So}=Ip(),{toString:Ni}=(p0(),Co(d0)),{fromString:H2}=(g0(),Co(m0)),{concat:K2}=(y0(),Co(b0)),Rn={};for(let r in So){let e=r;Rn[So[e]]=e}Object.freeze(Rn);function $2(r){if(!(r instanceof Uint8Array))throw new Error("must be passed a Uint8Array");return Ni(r,"base16")}function q2(r){return H2(r,"base16")}function W2(r){if(!(r instanceof Uint8Array))throw new Error("must be passed a Uint8Array");return Ni(w0.encode("base58btc",r)).slice(1)}function z2(r){let e=r instanceof Uint8Array?Ni(r):r;return w0.decode("z"+e)}function x0(r){if(!(r instanceof Uint8Array))throw new Error("multihash must be a Uint8Array");if(r.length<2)throw new Error("multihash too short. must be > 2 bytes.");let e=_n.decode(r);if(!v0(e))throw new Error(`multihash unknown function code: 0x${e.toString(16)}`);r=r.slice(_n.decode.bytes);let t=_n.decode(r);if(t<0)throw new Error(`multihash invalid length: ${t}`);if(r=r.slice(_n.decode.bytes),r.length!==t)throw new Error(`multihash length inconsistent: 0x${Ni(r,"base16")}`);return{code:e,name:Rn[e],length:t,digest:r}}function G2(r,e,t){if(!r||e===void 0)throw new Error("multihash encode requires at least two args: digest, code");let n=E0(e);if(!(r instanceof Uint8Array))throw new Error("digest should be a Uint8Array");if(t==null&&(t=r.length),t&&r.length!==t)throw new Error("digest length should be equal to specified length.");let o=_n.encode(n),s=_n.encode(t);return K2([o,s,r],o.length+s.length+r.length)}function E0(r){let e=r;if(typeof r=="string"){if(So[r]===void 0)throw new Error(`Unrecognized hash function named: ${r}`);e=So[r]}if(typeof e!="number")throw new Error(`Hash function code should be a number. Got: ${e}`);if(Rn[e]===void 0&&!ql(e))throw new Error(`Unrecognized function code: ${e}`);return e}function ql(r){return r>0&&r<16}function v0(r){return!!(ql(r)||Rn[r])}function A0(r){x0(r)}function j2(r){return A0(r),r.subarray(0,2)}D0.exports={names:So,codes:Rn,toHexString:$2,fromHexString:q2,toB58String:W2,fromB58String:z2,decode:x0,encode:G2,coerceCode:E0,isAppCode:ql,validate:A0,prefix:j2,isValidCode:v0}});var o1={};Q(o1,{webRTC:()=>n1,webRTCDirect:()=>r1});var Pi=Symbol.for("@libp2p/peer-id");var Io=Symbol.for("@libp2p/transport");var ou;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(ou||(ou={}));var L=class extends Error{code;props;constructor(e,t,n){super(e),this.code=t,this.name=n?.name??"CodeError",this.props=n??{}}};var To=(r,...e)=>{try{[...e]}catch{}};var _o=class extends EventTarget{#e=new Map;constructor(){super(),To(1/0,this)}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 z0(e,t))}},Mi=class extends Event{detail;constructor(e,t){super(e,t),this.detail=t?.detail}},z0=globalThis.CustomEvent??Mi;var Hr=Symbol.for("@libp2p/service-capabilities"),su=Symbol.for("@libp2p/service-dependencies");var $i={};Q($i,{base58btc:()=>ge,base58flickr:()=>J0});var U1=new Uint8Array(0);function iu(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 Ct(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 au(r){return new TextEncoder().encode(r)}function cu(r){return new TextDecoder().decode(r)}function G0(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),u=Math.log(256)/Math.log(a);function f(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var h=0,p=0,y=0,E=d.length;y!==E&&d[y]===0;)y++,h++;for(var b=(E-y)*u+1>>>0,v=new Uint8Array(b);y!==E;){for(var x=d[y],D=0,A=b-1;(x!==0||D<p)&&A!==-1;A--,D++)x+=256*v[A]>>>0,v[A]=x%a>>>0,x=x/a>>>0;if(x!==0)throw new Error("Non-zero carry");p=D,y++}for(var S=b-p;S!==b&&v[S]===0;)S++;for(var _=c.repeat(h);S<b;++S)_+=r.charAt(v[S]);return _}function g(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var h=0;if(d[h]!==" "){for(var p=0,y=0;d[h]===c;)p++,h++;for(var E=(d.length-h)*l+1>>>0,b=new Uint8Array(E);d[h];){var v=t[d.charCodeAt(h)];if(v===255)return;for(var x=0,D=E-1;(v!==0||x<y)&&D!==-1;D--,x++)v+=a*b[D]>>>0,b[D]=v%256>>>0,v=v/256>>>0;if(v!==0)throw new Error("Non-zero carry");y=x,h++}if(d[h]!==" "){for(var A=E-y;A!==E&&b[A]===0;)A++;for(var S=new Uint8Array(p+(E-A)),_=p;A!==E;)S[_++]=b[A++];return S}}}function m(d){var h=g(d);if(h)return h;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:g,decode:m}}var j0=G0,Y0=j0,uu=Y0;var Fi=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")}},Vi=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),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 fu(this,e)}},Hi=class{decoders;constructor(e){this.decoders=e}or(e){return fu(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 fu(r,e){return new Hi({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Ki=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 Fi(e,t,n),this.decoder=new Vi(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Kr({name:r,prefix:e,encode:t,decode:n}){return new Ki(r,e,t,n)}function Yt({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=uu(t,r);return Kr({prefix:e,name:r,encode:n,decode:s=>Ct(o(s))})}function Z0(r,e,t,n){let o={};for(let u=0;u<e.length;++u)o[e[u]]=u;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*t/8|0),a=0,c=0,l=0;for(let u=0;u<s;++u){let f=o[r[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<t|f,a+=t,a>=8&&(a-=8,i[l++]=255&c>>a)}if(a>=t||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return i}function X0(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;)s+="=";return s}function de({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return Kr({prefix:e,name:r,encode(o){return X0(o,n,t)},decode(o){return Z0(o,n,t,r)}})}var ge=Yt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),J0=Yt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var qi={};Q(qi,{base10:()=>Q0});var Q0=Yt({prefix:"9",name:"base10",alphabet:"0123456789"});var Wi={};Q(Wi,{base16:()=>em,base16upper:()=>tm});var em=de({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),tm=de({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var zi={};Q(zi,{base2:()=>rm});var rm=de({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Gi={};Q(Gi,{base256emoji:()=>am});var hu=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}"),nm=hu.reduce((r,e,t)=>(r[t]=e,r),[]),om=hu.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function sm(r){return r.reduce((e,t)=>(e+=nm[t],e),"")}function im(r){let e=[];for(let t of r){let n=om[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var am=Kr({prefix:"\u{1F680}",name:"base256emoji",encode:sm,decode:im});var ji={};Q(ji,{base32:()=>It,base32hex:()=>fm,base32hexpad:()=>dm,base32hexpadupper:()=>pm,base32hexupper:()=>hm,base32pad:()=>lm,base32padupper:()=>um,base32upper:()=>cm,base32z:()=>mm});var It=de({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),cm=de({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),lm=de({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),um=de({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),fm=de({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),hm=de({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),dm=de({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),pm=de({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),mm=de({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Yi={};Q(Yi,{base36:()=>gm,base36upper:()=>bm});var gm=Yt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),bm=Yt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ji={};Q(Ji,{base64:()=>Zi,base64pad:()=>ym,base64url:()=>Xi,base64urlpad:()=>wm});var Zi=de({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ym=de({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Xi=de({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),wm=de({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Qi={};Q(Qi,{base8:()=>xm});var xm=de({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ea={};Q(ea,{identity:()=>Em});var Em=Kr({prefix:"\0",name:"identity",encode:r=>cu(r),decode:r=>au(r)});var X1=new TextEncoder,J1=new TextDecoder;var ra={};Q(ra,{identity:()=>Tt});var Dm=mu,du=128,Sm=127,Bm=~Sm,km=Math.pow(2,31);function mu(r,e,t){e=e||[],t=t||0;for(var n=t;r>=km;)e[t++]=r&255|du,r/=128;for(;r&Bm;)e[t++]=r&255|du,r>>>=7;return e[t]=r|0,mu.bytes=t-n+1,e}var Cm=ta,Im=128,pu=127;function ta(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw ta.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&pu)<<o:(i&pu)*Math.pow(2,o),o+=7}while(i>=Im);return ta.bytes=s-n,t}var Tm=Math.pow(2,7),_m=Math.pow(2,14),Rm=Math.pow(2,21),Nm=Math.pow(2,28),Lm=Math.pow(2,35),Um=Math.pow(2,42),Om=Math.pow(2,49),Pm=Math.pow(2,56),Mm=Math.pow(2,63),Fm=function(r){return r<Tm?1:r<_m?2:r<Rm?3:r<Nm?4:r<Lm?5:r<Um?6:r<Om?7:r<Pm?8:r<Mm?9:10},Vm={encode:Dm,decode:Cm,encodingLength:Fm},Hm=Vm,Ln=Hm;function Un(r,e=0){return[Ln.decode(r,e),Ln.decode.bytes]}function $r(r,e,t=0){return Ln.encode(r,e,t),e}function qr(r){return Ln.encodingLength(r)}function bt(r,e){let t=e.byteLength,n=qr(r),o=n+qr(t),s=new Uint8Array(o+t);return $r(r,s,0),$r(t,s,n),s.set(e,o),new Wr(r,t,e,s)}function gr(r){let e=Ct(r),[t,n]=Un(e),[o,s]=Un(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Wr(t,o,i,e)}function gu(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&iu(r.bytes,t.bytes)}}var Wr=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};var bu=0,Km="identity",yu=Ct;function $m(r){return bt(bu,yu(r))}var Tt={code:bu,name:Km,encode:yu,digest:$m};var sa={};Q(sa,{sha256:()=>_e,sha512:()=>qm});function oa({name:r,code:e,encode:t}){return new na(r,e,t)}var na=class{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?bt(this.code,t):t.then(n=>bt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function xu(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var _e=oa({name:"sha2-256",code:18,encode:xu("SHA-256")}),qm=oa({name:"sha2-512",code:19,encode:xu("SHA-512")});function Eu(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return zm(t,ia(r),e??ge.encoder);default:return Gm(t,ia(r),e??It.encoder)}}var vu=new WeakMap;function ia(r){let e=vu.get(r);if(e==null){let t=new Map;return vu.set(r,t),t}return e}var Xe=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!==On)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==jm)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=bt(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&&gu(e.multihash,n.multihash)}toString(e){return Eu(this,e)}toJSON(){return{"/":Eu(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??Au(n,o,s.bytes))}else if(t[Ym]===!0){let{version:n,multihash:o,code:s}=t,i=gr(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!==On)throw new Error(`Version 0 CID must use dag-pb (code: ${On}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=Au(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,On,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=Ct(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 Wr(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[f,g]=Un(e.subarray(t));return t+=g,f},o=n(),s=On;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,u=l-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:u,size:l}}static parse(e,t){let[n,o]=Wm(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 ia(s).set(n,e),s}};function Wm(r,e){switch(r[0]){case"Q":{let t=e??ge;return[ge.prefix,t.decode(`${ge.prefix}${r}`)]}case ge.prefix:{let t=e??ge;return[ge.prefix,t.decode(r)]}case It.prefix:{let t=e??It;return[It.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function zm(r,e,t){let{prefix:n}=t;if(n!==ge.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 Gm(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 On=112,jm=18;function Au(r,e,t){let n=qr(r),o=n+qr(e),s=new Uint8Array(o+t.byteLength);return $r(r,s,0),$r(e,s,n),s.set(t,o),s}var Ym=Symbol.for("@ipld/js-cid/CID");var yt={...ea,...zi,...Qi,...qi,...Wi,...ji,...Yi,...$i,...Ji,...Gi},wE={...sa,...ra};function Ae(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 De(r=0){return new Uint8Array(r)}function Se(r=0){return new Uint8Array(r)}function Su(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Du=Su("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),aa=Su("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=Se(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Zm={utf8:Du,"utf-8":Du,hex:yt.base16,latin1:aa,ascii:aa,binary:aa,...yt},No=Zm;function J(r,e="utf8"){let t=No[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function W(r,e="utf8"){let t=No[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var ku=Symbol.for("nodejs.util.inspect.custom"),Bu=Object.values(yt).map(r=>r.decoder).reduce((r,e)=>r.or(e),yt.identity.decoder),Cu=114,ua=36,fa=37,Pn=class{type;multihash;privateKey;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,this.privateKey=e.privateKey,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Pi]=!0;toString(){return this.string==null&&(this.string=ge.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return Xe.createV1(Cu,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return Ae(this.multihash.bytes,e);if(typeof e=="string")return yr(e).equals(this);if(e?.multihash?.bytes!=null)return Ae(this.multihash.bytes,e.multihash.bytes);throw new Error("not valid Id")}[ku](){return`PeerId(${this.toString()})`}},zr=class extends Pn{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Gr=class extends Pn{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.multihash.digest}},jr=class extends Pn{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.multihash.digest}},ca=2336,la=class{type="url";multihash;privateKey;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Tt.digest(J(this.url))}[ku](){return`PeerId(${this.url})`}[Pi]=!0;toString(){return this.toCID().toString()}toCID(){return Xe.createV1(ca,this.multihash)}toBytes(){return this.toCID().bytes}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=W(e)),e.toString()===this.toString())}};function yr(r,e){if(e=e??Bu,r.charAt(0)==="1"||r.charAt(0)==="Q"){let t=gr(ge.decode(`z${r}`));return r.startsWith("12D")?new Gr({multihash:t}):r.startsWith("16U")?new jr({multihash:t}):new zr({multihash:t})}return Xm(Bu.decode(r))}function Xm(r){try{let e=gr(r);if(e.code===Tt.code){if(e.digest.length===ua)return new Gr({multihash:e});if(e.digest.length===fa)return new jr({multihash:e})}if(e.code===_e.code)return new zr({multihash:e})}catch{return Jm(Xe.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function Jm(r){if(r==null||r.multihash==null||r.version==null||r.version===1&&r.code!==Cu&&r.code!==ca)throw new Error("Supplied PeerID CID is invalid");if(r.code===ca){let t=W(r.multihash.digest);return new la(new URL(t))}let e=r.multihash;if(e.code===_e.code)return new zr({multihash:r.multihash});if(e.code===Tt.code){if(e.digest.length===ua)return new Gr({multihash:r.multihash});if(e.digest.length===fa)return new jr({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function ha(r,e){return r.length===ua?new Gr({multihash:bt(Tt.code,r),privateKey:e}):r.length===fa?new jr({multihash:bt(Tt.code,r),privateKey:e}):new zr({multihash:await _e.digest(r),publicKey:r,privateKey:e})}var eg=Math.pow(2,7),tg=Math.pow(2,14),rg=Math.pow(2,21),da=Math.pow(2,28),pa=Math.pow(2,35),ma=Math.pow(2,42),ga=Math.pow(2,49),ne=128,Pe=127;function we(r){if(r<eg)return 1;if(r<tg)return 2;if(r<rg)return 3;if(r<da)return 4;if(r<pa)return 5;if(r<ma)return 6;if(r<ga)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ba(r,e,t=0){switch(we(r)){case 8:e[t++]=r&255|ne,r/=128;case 7:e[t++]=r&255|ne,r/=128;case 6:e[t++]=r&255|ne,r/=128;case 5:e[t++]=r&255|ne,r/=128;case 4:e[t++]=r&255|ne,r>>>=7;case 3:e[t++]=r&255|ne,r>>>=7;case 2:e[t++]=r&255|ne,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function ng(r,e,t=0){switch(we(r)){case 8:e.set(t++,r&255|ne),r/=128;case 7:e.set(t++,r&255|ne),r/=128;case 6:e.set(t++,r&255|ne),r/=128;case 5:e.set(t++,r&255|ne),r/=128;case 4:e.set(t++,r&255|ne),r>>>=7;case 3:e.set(t++,r&255|ne),r>>>=7;case 2:e.set(t++,r&255|ne),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function ya(r,e){let t=r[e],n=0;if(n+=t&Pe,t<ne||(t=r[e+1],n+=(t&Pe)<<7,t<ne)||(t=r[e+2],n+=(t&Pe)<<14,t<ne)||(t=r[e+3],n+=(t&Pe)<<21,t<ne)||(t=r[e+4],n+=(t&Pe)*da,t<ne)||(t=r[e+5],n+=(t&Pe)*pa,t<ne)||(t=r[e+6],n+=(t&Pe)*ma,t<ne)||(t=r[e+7],n+=(t&Pe)*ga,t<ne))return n;throw new RangeError("Could not decode varint")}function og(r,e){let t=r.get(e),n=0;if(n+=t&Pe,t<ne||(t=r.get(e+1),n+=(t&Pe)<<7,t<ne)||(t=r.get(e+2),n+=(t&Pe)<<14,t<ne)||(t=r.get(e+3),n+=(t&Pe)<<21,t<ne)||(t=r.get(e+4),n+=(t&Pe)*da,t<ne)||(t=r.get(e+5),n+=(t&Pe)*pa,t<ne)||(t=r.get(e+6),n+=(t&Pe)*ma,t<ne)||(t=r.get(e+7),n+=(t&Pe)*ga,t<ne))return n;throw new RangeError("Could not decode varint")}function wt(r,e,t=0){return e==null&&(e=Se(we(r))),e instanceof Uint8Array?ba(r,e,t):ng(r,e,t)}function nt(r,e=0){return r instanceof Uint8Array?ya(r,e):og(r,e)}function xe(r,e){e==null&&(e=r.reduce((o,s)=>o+s.length,0));let t=Se(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var Lo=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 u=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let g=Number.parseInt(f,e);if(!Number.isNaN(g))return g});if(u===void 0)break;if(s*=e,s+=u,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 Iu=45,ig=15,Yr=new Lo;function wa(r){if(!(r.length>ig))return Yr.new(r).parseWith(()=>Yr.readIPv4Addr())}function xa(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Iu))return Yr.new(r).parseWith(()=>Yr.readIPv6Addr())}function Uo(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Iu))return Yr.new(r).parseWith(()=>Yr.readIPAddr())}var QE=parseInt("0xFFFF",16),e8=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Oo(r){return!!wa(r)}function Po(r){return!!xa(r)}function Mo(r){return!!Uo(r)}var Ru=Oo,fg=Po,Ea=function(r){let e=0;if(r=r.toString().trim(),Ru(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(fg(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let s=Ru(t[n]),i;s&&(i=Ea(t[n]),t[n]=W(i.slice(0,2),"base16")),i!=null&&++n<8&&t.splice(n,0,W(i.slice(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++){let s=parseInt(t[n],16);o[e++]=s>>8&255,o[e++]=s&255}return o}throw new Error("invalid ip address")},Nu=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let o=[];for(let s=0;s<t;s++)o.push(r[e+s]);return o.join(".")}if(t===16){let o=[];for(let s=0;s<t;s+=2)o.push(n.getUint16(e+s).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var Zr={},va={},dg=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,-1,"http-path"],[777,-1,"memory"]];dg.forEach(r=>{let e=pg(...r);va[e.code]=e,Zr[e.name]=e});function pg(r,e,t,n,o){return{code:r,size:e,name:t,resolvable:!!n,path:!!o}}function oe(r){if(typeof r=="number"){if(va[r]!=null)return va[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(Zr[r]!=null)return Zr[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var P8=oe("ip4"),M8=oe("ip6"),F8=oe("ipcidr");function Ba(r,e){switch(oe(r).code){case 4:case 41:return gg(e);case 42:return Sa(e);case 6:case 273:case 33:case 132:return Ou(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Sa(e);case 421:return xg(e);case 444:return Uu(e);case 445:return Uu(e);case 466:return wg(e);case 481:return globalThis.encodeURIComponent(Sa(e));default:return W(e,"base16")}}function ka(r,e){switch(oe(r).code){case 4:return Lu(e);case 41:return Lu(e);case 42:return Da(e);case 6:case 273:case 33:case 132:return Ca(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Da(e);case 421:return bg(e);case 444:return Eg(e);case 445:return vg(e);case 466:return yg(e);case 481:return Da(globalThis.decodeURIComponent(e));default:return J(e,"base16")}}var Aa=Object.values(yt).map(r=>r.decoder),mg=function(){let r=Aa[0].or(Aa[1]);return Aa.slice(2).forEach(e=>r=r.or(e)),r}();function Lu(r){if(!Mo(r))throw new Error("invalid ip address");return Ea(r)}function gg(r){let e=Nu(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!Mo(e))throw new Error("invalid ip address");return e}function Ca(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function Ou(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Da(r){let e=J(r),t=Uint8Array.from(wt(e.length));return xe([t,e],t.length+e.length)}function Sa(r){let e=nt(r);if(r=r.slice(we(e)),r.length!==e)throw new Error("inconsistent lengths");return W(r)}function bg(r){let e;r[0]==="Q"||r[0]==="1"?e=gr(ge.decode(`z${r}`)).bytes:e=Xe.parse(r).multihash.bytes;let t=Uint8Array.from(wt(e.length));return xe([t,e],t.length+e.length)}function yg(r){let e=mg.decode(r),t=Uint8Array.from(wt(e.length));return xe([t,e],t.length+e.length)}function wg(r){let e=nt(r),t=r.slice(we(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+W(t,"base64url")}function xg(r){let e=nt(r),t=r.slice(we(e));if(t.length!==e)throw new Error("inconsistent lengths");return W(t,"base58btc")}function Eg(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=It.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=Ca(n);return xe([t,o],t.length+o.length)}function vg(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=It.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=Ca(n);return xe([t,o],t.length+o.length)}function Uu(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=W(e,"base32"),o=Ou(t);return`${n}:${o}`}function Pu(r){r=Ia(r);let e=[],t=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let s=0;s<o.length;s++){let i=o[s],a=oe(i);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(s++,s>=o.length)throw Fu("invalid address: "+r);if(a.path===!0){n=Ia(o.slice(s).join("/")),e.push([a.code,ka(a.code,n)]),t.push([a.code,n]);break}let c=ka(a.code,o[s]);e.push([a.code,c]),t.push([a.code,Ba(a.code,c)])}return{string:Mu(t),bytes:_a(e),tuples:e,stringTuples:t,path:n}}function Ta(r){let e=[],t=[],n=null,o=0;for(;o<r.length;){let s=nt(r,o),i=we(s),a=oe(s),c=Ag(a,r.slice(o+i));if(c===0){e.push([s]),t.push([s]),o+=i;continue}let l=r.slice(o+i,o+i+c);if(o+=c+i,o>r.length)throw Fu("Invalid address Uint8Array: "+W(r,"base16"));e.push([s,l]);let u=Ba(s,l);if(t.push([s,u]),a.path===!0){n=u;break}}return{bytes:Uint8Array.from(r),string:Mu(t),tuples:e,stringTuples:t,path:n}}function Mu(r){let e=[];return r.map(t=>{let n=oe(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),Ia(e.join("/"))}function _a(r){return xe(r.map(e=>{let t=oe(e[0]),n=Uint8Array.from(wt(t.code));return e.length>1&&e[1]!=null&&(n=xe([n,e[1]])),n}))}function Ag(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=nt(e instanceof Uint8Array?e:Uint8Array.from(e));return t+we(t)}}function Ia(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}function Fu(r){return new Error("Error parsing address: "+r)}var Dg=Symbol.for("nodejs.util.inspect.custom"),Ra=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Sg=[oe("dns").code,oe("dns4").code,oe("dns6").code,oe("dnsaddr").code],Fo=class r{bytes;#e;#t;#r;#n;[Ra]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=Ta(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=Pu(e)}else if(Hu(e))t=Ta(e.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=t.bytes,this.#e=t.string,this.#t=t.tuples,this.#r=t.stringTuples,this.#n=t.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let e,t,n,o,s="",i=oe("tcp"),a=oe("udp"),c=oe("ip4"),l=oe("ip6"),u=oe("dns6"),f=oe("ip6zone");for(let[m,d]of this.stringTuples())m===f.code&&(s=`%${d??""}`),Sg.includes(m)&&(t=i.name,o=443,n=`${d??""}${s}`,e=m===u.code?6:4),(m===i.code||m===a.code)&&(t=oe(m).name,o=parseInt(d??"")),(m===c.code||m===l.code)&&(t=oe(m).name,n=`${d??""}${s}`,e=m===l.code?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}}protos(){return this.#t.map(([e])=>Object.assign({},oe(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>oe(e).name)}tuples(){return this.#t}stringTuples(){return this.#r}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,o))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(_a(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,o])=>{n===Zr.p2p.code&&e.push([n,o]),n===Zr["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?W(ge.decode(`z${n}`),"base58btc"):W(Xe.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(e){return Ae(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(s=>s.resolvable);if(t==null)return[this];let n=Vu.get(t.name);if(n==null)throw new L(`no available resolver for ${t.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,e)).map(s=>ot(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(e){let t=(e??this).protos();return!(t.length!==2||t[0].code!==4&&t[0].code!==41||t[1].code!==6&&t[1].code!==273)}[Dg](){return`Multiaddr(${this.#e})`}};var Vu=new Map;function Hu(r){return!!r?.[Ra]}function ot(r){return new Fo(r)}var Bg=r=>r.toString().split("/").slice(1),Fn=r=>({match:e=>e.length<1?!1:r(e[0])?e.slice(1):!1,pattern:"fn"}),ee=r=>({match:e=>Fn(t=>t===r).match(e),pattern:r}),Ko=()=>({match:r=>Fn(e=>typeof e=="string").match(r),pattern:"{string}"}),$o=()=>({match:r=>Fn(e=>!isNaN(parseInt(e))).match(r),pattern:"{number}"}),Re=()=>({match:r=>{if(r.length<2||r[0]!=="p2p"&&r[0]!=="ipfs")return!1;if(r[1].startsWith("Q")||r[1].startsWith("1"))try{ge.decode(`z${r[1]}`)}catch{return!1}else return!1;return r.slice(2)},pattern:"/p2p/{peerid}"}),Vo=()=>({match:r=>{if(r.length<2||r[0]!=="certhash")return!1;try{Xi.decode(r[1])}catch{return!1}return r.slice(2)},pattern:"/certhash/{certhash}"}),Be=r=>({match:e=>{let t=r.match(e);return t===!1?e:t},pattern:`optional(${r.pattern})`}),Je=(...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},pattern:`or(${r.map(e=>e.pattern).join(", ")})`}),ie=(...r)=>({match:e=>{for(let t of r){let n=t.match(e);if(n===!1)return!1;e=n}return e},pattern:`and(${r.map(e=>e.pattern).join(", ")})`});function be(...r){function e(o){let s=Bg(o);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{matches:t,exactMatch:n}}var La=ie(ee("dns4"),Ko()),Ua=ie(ee("dns6"),Ko()),Oa=ie(ee("dnsaddr"),Ko()),Ku=ie(ee("dns"),Ko()),pv=be(La),mv=be(Ua),gv=be(Oa),bv=be(Je(Ku,Oa,La,Ua)),$u=ie(ee("ip4"),Fn(Oo)),qu=ie(ee("ip6"),Fn(Po)),Wu=Je($u,qu),xt=Je(Wu,Ku,La,Ua,Oa),yv=be(xt),wv=be($u),xv=be(qu),Ev=be(Wu),Pa=ie(xt,ee("tcp"),$o()),Vn=ie(xt,ee("udp"),$o()),vv=be(Pa),Av=be(Vn),Ma=ie(Vn,ee("quic")),qo=ie(Vn,ee("quic-v1")),kg=Je(Ma,qo),Dv=be(Ma),Sv=be(qo),Na=Je(xt,Pa,Vn,Ma,qo),zu=Je(ie(Na,ee("ws"),Be(Re()))),Bv=be(zu),Gu=Je(ie(Na,ee("wss"),Be(Re())),ie(Na,ee("tls"),ee("ws"),Be(Re()))),kv=be(Gu),ju=ie(Vn,ee("webrtc-direct"),Be(Vo()),Be(Vo()),Be(Re())),Yu=be(ju),Zu=ie(qo,ee("webtransport"),Be(Vo()),Be(Vo()),Be(Re())),Cv=be(Zu),Ho=Je(zu,Gu,ie(Pa,Be(Re())),ie(kg,Be(Re())),ie(xt,Be(Re())),ju,Zu,Re()),Iv=be(Ho),Cg=ie(Ho,ee("p2p-circuit"),Re()),Tv=be(Cg),Ig=Je(ie(Ho,ee("p2p-circuit"),ee("webrtc"),Be(Re())),ie(Ho,ee("webrtc"),Be(Re())),ee("webrtc")),Xu=be(Ig),Tg=Je(ie(xt,ee("tcp"),$o(),ee("http"),Be(Re())),ie(xt,ee("http"),Be(Re()))),_v=be(Tg),_g=Je(ie(xt,ee("tcp"),Je(ie(ee("443"),ee("http")),ie($o(),ee("https"))),Be(Re())),ie(xt,ee("tls"),ee("http"),Be(Re())),ie(xt,ee("https"),Be(Re()))),Rv=be(_g);var Ge;(function(r){r.ERR_ALREADY_ABORTED="ERR_ALREADY_ABORTED",r.ERR_DATA_CHANNEL="ERR_DATA_CHANNEL",r.ERR_CONNECTION_CLOSED="ERR_CONNECTION_CLOSED",r.ERR_HASH_NOT_SUPPORTED="ERR_HASH_NOT_SUPPORTED",r.ERR_INVALID_MULTIADDR="ERR_INVALID_MULTIADDR",r.ERR_INVALID_FINGERPRINT="ERR_INVALID_FINGERPRINT",r.ERR_INVALID_PARAMETERS="ERR_INVALID_PARAMETERS",r.ERR_NOT_IMPLEMENTED="ERR_NOT_IMPLEMENTED",r.ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS="ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS",r.ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS="ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS"})(Ge||(Ge={}));var Zt=class extends L{constructor(e,t){super(`WebRTC transport error: ${e}`,t??""),this.name="WebRTCTransportError"}};var Fa=class extends Zt{constructor(e,t){super(`[stream: ${e}] data channel error: ${t}`,Ge.ERR_DATA_CHANNEL),this.name="WebRTC/DataChannelError"}};function Wa(r,e){return new Fa(r,e)}var Va=class extends Zt{constructor(e){super(`There was a problem with the Multiaddr which was passed in: ${e}`,Ge.ERR_INVALID_MULTIADDR),this.name="WebRTC/InappropriateMultiaddrError"}};function Wo(r){return new Va(r)}var Ha=class extends Zt{constructor(e){super(`There was a problem with a provided argument: ${e}`,Ge.ERR_INVALID_PARAMETERS),this.name="WebRTC/InvalidArgumentError"}};function Hn(r){return new Ha(r)}var Ka=class extends Zt{constructor(e,t){super(`Invalid fingerprint "${e}" within ${t}`,Ge.ERR_INVALID_FINGERPRINT),this.name="WebRTC/InvalidFingerprintError"}};function za(r,e){return new Ka(r,e)}var $a=class extends Zt{constructor(e){super(`A method (${e}) was called though it has been intentionally left unimplemented.`,Ge.ERR_NOT_IMPLEMENTED),this.name="WebRTC/UnimplementedError"}};function Ju(r){return new $a(r)}var qa=class extends Zt{constructor(e){super(`unsupported hash algorithm: ${e}`,Ge.ERR_HASH_NOT_SUPPORTED),this.name="WebRTC/UnsupportedHashAlgorithmError"}};function Qu(r){return new qa(r)}var ef=function(r,e,t){if(t||arguments.length===2)for(var n=0,o=e.length,s;n<o;n++)(s||!(n in e))&&(s||(s=Array.prototype.slice.call(e,0,n)),s[n]=e[n]);return r.concat(s||Array.prototype.slice.call(e))},Rg=function(){function r(e,t,n){this.name=e,this.version=t,this.os=n,this.type="browser"}return r}();var Ng=function(){function r(e){this.version=e,this.type="node",this.name="node",this.os=process.platform}return r}();var Lg=function(){function r(e,t,n,o){this.name=e,this.version=t,this.os=n,this.bot=o,this.type="bot-device"}return r}();var Ug=function(){function r(){this.type="bot",this.bot=!0,this.name="bot",this.version=null,this.os=null}return r}();var Og=function(){function r(){this.type="react-native",this.name="react-native",this.version=null,this.os=null}return r}();var Pg=/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/,Mg=/(nuhk|curl|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask\ Jeeves\/Teoma|ia_archiver)/,tf=3,Fg=[["aol",/AOLShield\/([0-9\._]+)/],["edge",/Edge\/([0-9\._]+)/],["edge-ios",/EdgiOS\/([0-9\._]+)/],["yandexbrowser",/YaBrowser\/([0-9\._]+)/],["kakaotalk",/KAKAOTALK\s([0-9\.]+)/],["samsung",/SamsungBrowser\/([0-9\.]+)/],["silk",/\bSilk\/([0-9._-]+)\b/],["miui",/MiuiBrowser\/([0-9\.]+)$/],["beaker",/BeakerBrowser\/([0-9\.]+)/],["edge-chromium",/EdgA?\/([0-9\.]+)/],["chromium-webview",/(?!Chrom.*OPR)wv\).*Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["chrome",/(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["phantomjs",/PhantomJS\/([0-9\.]+)(:?\s|$)/],["crios",/CriOS\/([0-9\.]+)(:?\s|$)/],["firefox",/Firefox\/([0-9\.]+)(?:\s|$)/],["fxios",/FxiOS\/([0-9\.]+)/],["opera-mini",/Opera Mini.*Version\/([0-9\.]+)/],["opera",/Opera\/([0-9\.]+)(?:\s|$)/],["opera",/OPR\/([0-9\.]+)(:?\s|$)/],["pie",/^Microsoft Pocket Internet Explorer\/(\d+\.\d+)$/],["pie",/^Mozilla\/\d\.\d+\s\(compatible;\s(?:MSP?IE|MSInternet Explorer) (\d+\.\d+);.*Windows CE.*\)$/],["netfront",/^Mozilla\/\d\.\d+.*NetFront\/(\d.\d)/],["ie",/Trident\/7\.0.*rv\:([0-9\.]+).*\).*Gecko$/],["ie",/MSIE\s([0-9\.]+);.*Trident\/[4-7].0/],["ie",/MSIE\s(7\.0)/],["bb10",/BB10;\sTouch.*Version\/([0-9\.]+)/],["android",/Android\s([0-9\.]+)/],["ios",/Version\/([0-9\._]+).*Mobile.*Safari.*/],["safari",/Version\/([0-9\._]+).*Safari/],["facebook",/FB[AS]V\/([0-9\.]+)/],["instagram",/Instagram\s([0-9\.]+)/],["ios-webview",/AppleWebKit\/([0-9\.]+).*Mobile/],["ios-webview",/AppleWebKit\/([0-9\.]+).*Gecko\)$/],["curl",/^curl\/([0-9\.]+)$/],["searchbot",Pg]],rf=[["iOS",/iP(hone|od|ad)/],["Android OS",/Android/],["BlackBerry OS",/BlackBerry|BB10/],["Windows Mobile",/IEMobile/],["Amazon OS",/Kindle/],["Windows 3.11",/Win16/],["Windows 95",/(Windows 95)|(Win95)|(Windows_95)/],["Windows 98",/(Windows 98)|(Win98)/],["Windows 2000",/(Windows NT 5.0)|(Windows 2000)/],["Windows XP",/(Windows NT 5.1)|(Windows XP)/],["Windows Server 2003",/(Windows NT 5.2)/],["Windows Vista",/(Windows NT 6.0)/],["Windows 7",/(Windows NT 6.1)/],["Windows 8",/(Windows NT 6.2)/],["Windows 8.1",/(Windows NT 6.3)/],["Windows 10",/(Windows NT 10.0)/],["Windows ME",/Windows ME/],["Windows CE",/Windows CE|WinCE|Microsoft Pocket Internet Explorer/],["Open BSD",/OpenBSD/],["Sun OS",/SunOS/],["Chrome OS",/CrOS/],["Linux",/(Linux)|(X11)/],["Mac OS",/(Mac_PowerPC)|(Macintosh)/],["QNX",/QNX/],["BeOS",/BeOS/],["OS/2",/OS\/2/]];function of(r){return r?nf(r):typeof document>"u"&&typeof navigator<"u"&&navigator.product==="ReactNative"?new Og:typeof navigator<"u"?nf(navigator.userAgent):Kg()}function Vg(r){return r!==""&&Fg.reduce(function(e,t){var n=t[0],o=t[1];if(e)return e;var s=o.exec(r);return!!s&&[n,s]},!1)}function nf(r){var e=Vg(r);if(!e)return null;var t=e[0],n=e[1];if(t==="searchbot")return new Ug;var o=n[1]&&n[1].split(".").join("_").split("_").slice(0,3);o?o.length<tf&&(o=ef(ef([],o,!0),$g(tf-o.length),!0)):o=[];var s=o.join("."),i=Hg(r),a=Mg.exec(r);return a&&a[1]?new Lg(t,s,i,a[1]):new Rg(t,s,i)}function Hg(r){for(var e=0,t=rf.length;e<t;e++){var n=rf[e],o=n[0],s=n[1],i=s.exec(r);if(i)return o}return null}function Kg(){var r=typeof process<"u"&&process.version;return r?new Ng(process.version.slice(1)):null}function $g(r){for(var e=[],t=0;t<r;t++)e.push("0");return e}function pe(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var Xr=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Ga=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},sf=r=>globalThis.DOMException===void 0?new Ga(r):new DOMException(r),af=r=>{let e=r.reason===void 0?sf("This operation was aborted."):r.reason;return e instanceof Error?e:sf(e)};function wr(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=e,i,c=new Promise((l,u)=>{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:g}=e;g.aborted&&u(af(g)),g.addEventListener("abort",()=>{u(af(g))})}if(t===Number.POSITIVE_INFINITY){r.then(l,u);return}let f=new Xr;i=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(g){u(g)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?l():o instanceof Error?u(o):(f.message=o??`Promise timed out after ${t} milliseconds`,u(f))},t),(async()=>{try{l(await r)}catch(g){u(g)}})()}).finally(()=>{c.clear()});return c.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},c}var cf=["stun:stun.l.google.com:19302","stun:global.stun.twilio.com:3478","stun:stun.cloudflare.com:3478","stun:stun.services.mozilla.com:3478"];var lf=of(),Kn=lf!=null&&lf.name==="firefox",zo=async function*(){},Go=async r=>{},qg=30*1e3;function uf(r,e,t=qg,n){r.readyState==="open"&&Promise.resolve().then(async()=>{if(r.bufferedAmount>0){n.log("%s drain channel with %d buffered bytes",e,r.bufferedAmount);let o=pe(),s=!1;r.bufferedAmountLowThreshold=0;let i=()=>{s||(n.log("%s drain channel closed before drain",e),o.resolve())};r.addEventListener("close",i,{once:!0}),r.addEventListener("bufferedamountlow",()=>{s=!0,r.removeEventListener("close",i),o.resolve()}),await wr(o.promise,{milliseconds:t})}}).then(async()=>{r.readyState==="open"&&r.close()}).catch(o=>{n.log.error("error closing outbound stream",o)})}async function $n(r){return r=r??{},typeof r=="function"&&(r=await r()),r.iceServers=r.iceServers??cf.map(e=>({urls:[e]})),r}var xr=class{log;peerConnection;remoteAddr;timeline;metrics;source=zo();sink=Go;constructor(e,t){this.log=e.logger.forComponent("libp2p:webrtc:maconn"),this.remoteAddr=t.remoteAddr,this.timeline=t.timeline,this.peerConnection=t.peerConnection;let n=this.peerConnection.connectionState;this.peerConnection.onconnectionstatechange=()=>{this.log.trace("peer connection state change",this.peerConnection.connectionState,"initial state",n),(this.peerConnection.connectionState==="disconnected"||this.peerConnection.connectionState==="failed"||this.peerConnection.connectionState==="closed")&&(this.timeline.close=Date.now())}}async close(e){this.log.trace("closing connection"),this.peerConnection.close(),this.timeline.close=Date.now(),this.metrics?.increment({close:!0})}abort(e){this.log.error("closing connection due to error",e),this.peerConnection.close(),this.timeline.close=Date.now(),this.metrics?.increment({abort:!0})}};var jo=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||e-1&e)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}},Jr=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new jo(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 jo(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 ja=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function Xt(r={}){return Wg(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 Wg(r,e){e=e??{};let t=e.onEnd,n=new Jr,o,s,i,a=pe(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((p,y)=>{s=E=>{s=null,n.push(E);try{p(r(n))}catch(b){y(b)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=pe()})}},l=p=>s!=null?s(p):(n.push(p),o),u=p=>(n=new Jr,s!=null?s({error:p}):(n.push({error:p}),o)),f=p=>{if(i)return o;if(e?.objectMode!==!0&&p?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:p})},g=p=>i?o:(i=!0,p!=null?u(p):l({done:!0})),m=()=>(n=new Jr,g(),{done:!0}),d=p=>(g(p),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:m,throw:d,push:f,end:g,get readableLength(){return n.size},onEmpty:async p=>{let y=p?.signal;if(y?.throwIfAborted(),n.isEmpty())return;let E,b;y!=null&&(E=new Promise((v,x)=>{b=()=>{x(new ja)},y.addEventListener("abort",b)}));try{await Promise.race([a.promise,E])}finally{b!=null&&y!=null&&y?.removeEventListener("abort",b)}}},t==null)return o;let h=o;return o={[Symbol.asyncIterator](){return this},next(){return h.next()},throw(p){return h.throw(p),t!=null&&(t(p),t=void 0),{done:!0}},return(){return h.return(),t!=null&&(t(),t=void 0),{done:!0}},push:f,end(p){return h.end(p),t!=null&&(t(p),t=void 0),o},get readableLength(){return h.readableLength},onEmpty:p=>h.onEmpty(p)},o}var Yo=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=t??"ABORT_ERR"}};async function _t(r,e,t){if(e==null)return r;if(e.aborted)return Promise.reject(new Yo(t?.errorMessage,t?.errorCode));let n,o=new Yo(t?.errorMessage,t?.errorCode);try{return await Promise.race([r,new Promise((s,i)=>{n=()=>{i(o)},e.addEventListener("abort",n)})])}finally{n!=null&&e.removeEventListener("abort",n)}}var hf=Symbol.for("@achingbrain/uint8arraylist");function ff(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 Zo(r){return!!r?.[hf]}var ue=class r{bufs;length;[hf]=!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(Zo(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(Zo(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=ff(this.bufs,e);return t.buf[t.index]}set(e,t){let n=ff(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(Zo(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 xe(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:xe(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,u=t>a&&t<=c;if(l&&u){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(u){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(!Zo(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,u;for(let f=t;f<=c;f+=u){u=0;for(let g=l;g>=0;g--){let m=this.get(f+g);if(n[g]!==m){u=Math.max(1,g-a[m]);break}}if(u===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=Se(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=De(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=De(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=De(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=Se(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=De(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=De(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=De(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=De(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=De(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(!Ae(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((o,s)=>o+s.byteLength,0)),n.length=t,n}};function df(r){if(r!=null){if(typeof r[Symbol.iterator]=="function")return r[Symbol.iterator]();if(typeof r[Symbol.asyncIterator]=="function")return r[Symbol.asyncIterator]();if(typeof r.next=="function")return r}throw new Error("argument is not an iterator or iterable")}function pf(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function mf(r,e){let t=df(r).return?.();pf(t)&&t.catch(n=>{e.error("could not cause iterator to return",n)})}var zg="ERR_STREAM_RESET",Gg="ERR_SINK_INVALID_STATE",jg=5e3;function Ya(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Xo=class{id;direction;timeline;protocol;metadata;source;status;readStatus;writeStatus;log;sinkController;sinkEnd;closed;endErr;streamSource;onEnd;onCloseRead;onCloseWrite;onReset;onAbort;sendCloseWriteTimeout;sendingData;constructor(e){this.sinkController=new AbortController,this.sinkEnd=pe(),this.closed=pe(),this.log=e.log,this.status="open",this.readStatus="ready",this.writeStatus="ready",this.id=e.id,this.metadata=e.metadata??{},this.direction=e.direction,this.timeline={open:Date.now()},this.sendCloseWriteTimeout=e.sendCloseWriteTimeout??jg,this.onEnd=e.onEnd,this.onCloseRead=e?.onCloseRead,this.onCloseWrite=e?.onCloseWrite,this.onReset=e?.onReset,this.onAbort=e?.onAbort,this.source=this.streamSource=Xt({onEnd:t=>{t!=null?this.log.trace("source ended with error",t):this.log.trace("source ended"),this.onSourceEnd(t)}}),this.sink=this.sink.bind(this)}async sink(e){if(this.writeStatus!=="ready")throw new L(`writable end state is "${this.writeStatus}" not "ready"`,Gg);try{this.writeStatus="writing";let t={signal:this.sinkController.signal};if(this.direction==="outbound"){let o=this.sendNewStream(t);Ya(o)&&await o}let n=()=>{mf(e,this.log)};try{this.sinkController.signal.addEventListener("abort",n),this.log.trace("sink reading from source");for await(let o of e){o=o instanceof Uint8Array?new ue(o):o;let s=this.sendData(o,t);Ya(s)&&(this.sendingData=pe(),await s,this.sendingData.resolve(),this.sendingData=void 0)}}finally{this.sinkController.signal.removeEventListener("abort",n)}this.log.trace('sink finished reading from source, write status is "%s"',this.writeStatus),this.writeStatus==="writing"&&(this.writeStatus="closing",this.log.trace("send close write to remote"),await this.sendCloseWrite({signal:AbortSignal.timeout(this.sendCloseWriteTimeout)}),this.writeStatus="closed"),this.onSinkEnd()}catch(t){throw this.log.trace("sink ended with error, calling abort with error",t),this.abort(t),t}finally{this.log.trace("resolve sink end"),this.sinkEnd.resolve()}}onSourceEnd(e){this.timeline.closeRead==null&&(this.timeline.closeRead=Date.now(),this.readStatus="closed",e!=null&&this.endErr==null&&(this.endErr=e),this.onCloseRead?.(),this.timeline.closeWrite!=null?(this.log.trace("source and sink ended"),this.timeline.close=Date.now(),this.status!=="aborted"&&this.status!=="reset"&&(this.status="closed"),this.onEnd!=null&&this.onEnd(this.endErr),this.closed.resolve()):this.log.trace("source ended, waiting for sink to end"))}onSinkEnd(e){this.timeline.closeWrite==null&&(this.timeline.closeWrite=Date.now(),this.writeStatus="closed",e!=null&&this.endErr==null&&(this.endErr=e),this.onCloseWrite?.(),this.timeline.closeRead!=null?(this.log.trace("sink and source ended"),this.timeline.close=Date.now(),this.status!=="aborted"&&this.status!=="reset"&&(this.status="closed"),this.onEnd!=null&&this.onEnd(this.endErr),this.closed.resolve()):this.log.trace("sink ended, waiting for source to end"))}async close(e){this.log.trace("closing gracefully"),this.status="closing",await _t(Promise.all([this.closeWrite(e),this.closeRead(e),this.closed.promise]),e?.signal),this.status="closed",this.log.trace("closed gracefully")}async closeRead(e={}){if(this.readStatus==="closing"||this.readStatus==="closed")return;this.log.trace('closing readable end of stream with starting read status "%s"',this.readStatus);let t=this.readStatus;this.readStatus="closing",this.status!=="reset"&&this.status!=="aborted"&&this.timeline.closeRead==null&&(this.log.trace("send close read to remote"),await this.sendCloseRead(e)),t==="ready"&&(this.log.trace("ending internal source queue with %d queued bytes",this.streamSource.readableLength),this.streamSource.end()),this.log.trace("closed readable end of stream")}async closeWrite(e={}){this.writeStatus==="closing"||this.writeStatus==="closed"||(this.log.trace('closing writable end of stream with starting write status "%s"',this.writeStatus),this.writeStatus==="ready"&&(this.log.trace("sink was never sunk, sink an empty array"),await _t(this.sink([]),e.signal)),this.writeStatus==="writing"&&(this.sendingData!=null&&await _t(this.sendingData.promise,e.signal),this.log.trace("aborting source passed to .sink"),this.sinkController.abort(),await _t(this.sinkEnd.promise,e.signal)),this.writeStatus="closed",this.log.trace("closed writable end of stream"))}abort(e){if(this.status==="closed"||this.status==="aborted"||this.status==="reset")return;this.log("abort with error",e),this.log("try to send reset to remote");let t=this.sendReset();Ya(t)&&t.catch(n=>{this.log.error("error sending reset message",n)}),this.status="aborted",this.timeline.abort=Date.now(),this._closeSinkAndSource(e),this.onAbort?.(e)}reset(){if(this.status==="closed"||this.status==="aborted"||this.status==="reset")return;let e=new L("stream reset",zg);this.status="reset",this.timeline.reset=Date.now(),this._closeSinkAndSource(e),this.onReset?.()}_closeSinkAndSource(e){this._closeSink(e),this._closeSource(e)}_closeSink(e){this.writeStatus==="writing"&&(this.log.trace("end sink source"),this.sinkController.abort()),this.onSinkEnd(e)}_closeSource(e){this.readStatus!=="closing"&&this.readStatus!=="closed"&&(this.log.trace("ending source with %d bytes to be read by consumer",this.streamSource.readableLength),this.readStatus="closing",this.streamSource.end(e))}remoteCloseWrite(){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("received remote close write but local source is already closed");return}this.log.trace("remote close write"),this._closeSource()}remoteCloseRead(){if(this.writeStatus==="closing"||this.writeStatus==="closed"){this.log("received remote close read but local sink is already closed");return}this.log.trace("remote close read"),this._closeSink()}destroy(){if(this.status==="closed"||this.status==="aborted"||this.status==="reset"){this.log("received destroy but we are already closed");return}this.log.trace("stream destroyed"),this._closeSinkAndSource()}sourcePush(e){this.streamSource.push(e)}sourceReadableLength(){return this.streamSource.readableLength}};function Jo(r){return r[Symbol.asyncIterator]!=null}var Qo=r=>{let e=we(r),t=Se(e);return wt(r,t),Qo.bytes=e,t};Qo.bytes=0;function qn(r,e){e=e??{};let t=e.lengthEncoder??Qo;function*n(o){let s=t(o.byteLength);s instanceof Uint8Array?yield s:yield*s,o instanceof Uint8Array?yield o:yield*o}return Jo(r)?async function*(){for await(let o of r)yield*n(o)}():function*(){for(let o of r)yield*n(o)}()}qn.single=(r,e)=>{e=e??{};let t=e.lengthEncoder??Qo;return new ue(t(r.byteLength),r)};var Qr=ko(yf(),1);var Zg=8,Xg=1024*1024*4,Er;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(Er||(Er={}));var Za=r=>{let e=nt(r);return Za.bytes=we(e),e};Za.bytes=0;function vr(r,e){let t=new ue,n=Er.LENGTH,o=-1,s=e?.lengthDecoder??Za,i=e?.maxLengthLength??Zg,a=e?.maxDataLength??Xg;function*c(){for(;t.byteLength>0;){if(n===Er.LENGTH)try{if(o=s(t),o<0)throw(0,Qr.default)(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(o>a)throw(0,Qr.default)(new Error("message length too long"),"ERR_MSG_DATA_TOO_LONG");let l=s.bytes;t.consume(l),e?.onLength!=null&&e.onLength(o),n=Er.DATA}catch(l){if(l instanceof RangeError){if(t.byteLength>i)throw(0,Qr.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw l}if(n===Er.DATA){if(t.byteLength<o)break;let l=t.sublist(0,o);t.consume(o),e?.onData!=null&&e.onData(l),yield l,n=Er.LENGTH}}}return Jo(r)?async function*(){for await(let l of r)t.append(l),yield*c();if(t.byteLength>0)throw(0,Qr.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}():function*(){for(let l of r)t.append(l),yield*c();if(t.byteLength>0)throw(0,Qr.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}()}vr.fromReader=(r,e)=>{let t=1,n=async function*(){for(;;)try{let{done:s,value:i}=await r.next(t);if(s===!0)return;i!=null&&(yield i)}catch(s){if(s.code==="ERR_UNDER_READ")return{done:!0,value:null};throw s}finally{t=1}}();return vr(n,{...e??{},onLength:s=>{t=s}})};var Qg=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 eb(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:u}=Qg(r),f=(...m)=>{let d=t.multiArgs?m:m[0];t.filter&&!t.filter(d)||(c.push(d),t.count===c.length&&(n(),s(c)))},g=m=>{n(),i(m)};n=()=>{for(let m of a)u(m,f);for(let m of t.rejectionEvents)u(m,g)};for(let m of a)l(m,f);for(let m of t.rejectionEvents)l(m,g);t.signal&&t.signal.addEventListener("abort",()=>{g(t.signal.reason)},{once:!0}),t.resolveImmediately&&s(c)});if(o.cancel=n,typeof t.timeout=="number"){let s=wr(o,{milliseconds:t.timeout});return s.cancel=n,s}return o}function Xa(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=eb(r,e,t),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}var Ja=new Float32Array([-0]),Jt=new Uint8Array(Ja.buffer);function wf(r,e,t){Ja[0]=r,e[t]=Jt[0],e[t+1]=Jt[1],e[t+2]=Jt[2],e[t+3]=Jt[3]}function xf(r,e){return Jt[0]=r[e],Jt[1]=r[e+1],Jt[2]=r[e+2],Jt[3]=r[e+3],Ja[0]}var Qa=new Float64Array([-0]),Me=new Uint8Array(Qa.buffer);function Ef(r,e,t){Qa[0]=r,e[t]=Me[0],e[t+1]=Me[1],e[t+2]=Me[2],e[t+3]=Me[3],e[t+4]=Me[4],e[t+5]=Me[5],e[t+6]=Me[6],e[t+7]=Me[7]}function vf(r,e){return Me[0]=r[e],Me[1]=r[e+1],Me[2]=r[e+2],Me[3]=r[e+3],Me[4]=r[e+4],Me[5]=r[e+5],Me[6]=r[e+6],Me[7]=r[e+7],Qa[0]}var tb=BigInt(Number.MAX_SAFE_INTEGER),rb=BigInt(Number.MIN_SAFE_INTEGER),je=class r{lo;hi;constructor(e,t){this.lo=e|0,this.hi=t|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(t+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(BigInt(t)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?t===0?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return Ar;if(e<tb&&e>rb)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let n=e>>32n,o=e-(n<<32n);return t&&(n=~n|0n,o=~o|0n,++o>Af&&(o=0n,++n>Af&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return Ar;let t=e<0;t&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return t&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(e){return typeof e=="number"?r.fromNumber(e):typeof e=="bigint"?r.fromBigInt(e):typeof e=="string"?r.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new r(e.low>>>0,e.high>>>0):Ar}},Ar=new je(0,0);Ar.toBigInt=function(){return 0n};Ar.zzEncode=Ar.zzDecode=function(){return this};Ar.length=function(){return 1};var Af=4294967296n;function Df(r){let e=0,t=0;for(let n=0;n<r.length;++n)t=r.charCodeAt(n),t<128?e+=1:t<2048?e+=2:(t&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function Sf(r,e,t){if(t-e<1)return"";let o,s=[],i=0,a;for(;e<t;)a=r[e++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|r[e++]&63:a>239&&a<365?(a=((a&7)<<18|(r[e++]&63)<<12|(r[e++]&63)<<6|r[e++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function ec(r,e,t){let n=t,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,e[t++]=o>>18|240,e[t++]=o>>12&63|128,e[t++]=o>>6&63|128,e[t++]=o&63|128):(e[t++]=o>>12|224,e[t++]=o>>6&63|128,e[t++]=o&63|128);return t-n}function st(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function es(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var tc=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,st(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw st(this,4);return es(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw st(this,4);return es(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw st(this,4);let e=xf(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw st(this,4);let e=vf(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),t=this.pos,n=this.pos+e;if(n>this.len)throw st(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return Sf(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw st(this,e);this.pos+=e}else do if(this.pos>=this.len)throw st(this);while(this.buf[this.pos++]&128);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new je(0,0),t=0;if(this.len-this.pos>4){for(;t<4;++t)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;t=0}else{for(;t<3;++t){if(this.pos>=this.len)throw st(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<t*7)>>>0,e}if(this.len-this.pos>4){for(;t<5;++t)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;t<5;++t){if(this.pos>=this.len)throw st(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw st(this,8);let e=es(this.buf,this.pos+=4),t=es(this.buf,this.pos+=4);return new je(e,t)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=ya(this.buf,this.pos);return this.pos+=we(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function rc(r){return new tc(r instanceof Uint8Array?r:r.subarray())}function it(r,e,t){let n=rc(r);return e.decode(n,void 0,t)}function nc(r){let e=r??8192,t=e>>>1,n,o=e;return function(i){if(i<1||i>t)return Se(i);o+i>e&&(n=Se(e),o=0);let a=n.subarray(o,o+=i);return o&7&&(o=(o|7)+1),a}}var Dr=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function oc(){}var ic=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},nb=nc();function ob(r){return globalThis.Buffer!=null?Se(r):nb(r)}var zn=class{len;head;tail;states;constructor(){this.len=0,this.head=new Dr(oc,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new Dr(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new ac((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(ts,10,je.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=je.fromBigInt(e);return this._push(ts,t.length(),t)}uint64Number(e){return this._push(ba,we(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let t=je.fromBigInt(e).zzEncode();return this._push(ts,t.length(),t)}sint64Number(e){let t=je.fromNumber(e).zzEncode();return this._push(ts,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(sc,1,e?1:0)}fixed32(e){return this._push(Wn,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=je.fromBigInt(e);return this._push(Wn,4,t.lo)._push(Wn,4,t.hi)}fixed64Number(e){let t=je.fromNumber(e);return this._push(Wn,4,t.lo)._push(Wn,4,t.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(wf,4,e)}double(e){return this._push(Ef,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(sc,1,0):this.uint32(t)._push(ib,t,e)}string(e){let t=Df(e);return t!==0?this.uint32(t)._push(ec,t,e):this._push(sc,1,0)}fork(){return this.states=new ic(this),this.head=this.tail=new Dr(oc,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new Dr(oc,0,0),this.len=0),this}ldelim(){let e=this.head,t=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=t,this.len+=n),this}finish(){let e=this.head.next,t=ob(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function sc(r,e,t){e[t]=r&255}function sb(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var ac=class extends Dr{next;constructor(e,t){super(sb,e,t),this.next=void 0}};function ts(r,e,t){for(;r.hi!==0;)e[t++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)e[t++]=r.lo&127|128,r.lo=r.lo>>>7;e[t++]=r.lo}function Wn(r,e,t){e[t]=r&255,e[t+1]=r>>>8&255,e[t+2]=r>>>16&255,e[t+3]=r>>>24}function ib(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(zn.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(ab,e,r),this},zn.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(cb,e,r),this});function ab(r,e,t){e.set(r,t)}function cb(r,e,t){r.length<40?ec(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(J(r),t)}function cc(){return new zn}function at(r,e){let t=cc();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var en;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(en||(en={}));function rs(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function Sr(r){function e(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let t=function(s,i){let a=e(s);i.int32(a)},n=function(s){let i=s.int32();return e(i)};return rs("enum",en.VARINT,t,n)}function ct(r,e){return rs("message",en.LENGTH_DELIMITED,r,e)}var $e;(function(r){let e;(function(o){o.FIN="FIN",o.STOP_SENDING="STOP_SENDING",o.RESET="RESET",o.FIN_ACK="FIN_ACK"})(e=r.Flag||(r.Flag={}));let t;(function(o){o[o.FIN=0]="FIN",o[o.STOP_SENDING=1]="STOP_SENDING",o[o.RESET=2]="RESET",o[o.FIN_ACK=3]="FIN_ACK"})(t||(t={})),function(o){o.codec=()=>Sr(t)}(e=r.Flag||(r.Flag={}));let n;r.codec=()=>(n==null&&(n=ct((o,s,i={})=>{i.lengthDelimited!==!1&&s.fork(),o.flag!=null&&(s.uint32(8),r.Flag.codec().encode(o.flag,s)),o.message!=null&&(s.uint32(18),s.bytes(o.message)),i.lengthDelimited!==!1&&s.ldelim()},(o,s)=>{let i={},a=s==null?o.len:o.pos+s;for(;o.pos<a;){let c=o.uint32();switch(c>>>3){case 1:i.flag=r.Flag.codec().decode(o);break;case 2:i.message=o.bytes();break;default:o.skipType(c&7);break}}return i})),n),r.encode=o=>at(o,r.codec()),r.decode=o=>it(o,r.codec())})($e||($e={}));var lb=16*1024*1024,ub=30*1e3,fb=5,hb=2,db=16*1024,pb=5e3,mb=5e3,lc=class extends Xo{channel;incomingData;maxBufferedAmount;bufferedAmountLowEventTimeout;maxMessageSize;receiveFinAck;finAckTimeout;openTimeout;constructor(e){let t=e.onEnd;switch(e.onEnd=o=>{this.log.trace("readable and writeable ends closed",this.status),Promise.resolve(async()=>{if(!(this.timeline.abort!=null||this.timeline.reset!==null))try{await wr(this.receiveFinAck.promise,{milliseconds:this.finAckTimeout})}catch(s){this.log.error("error receiving FIN_ACK",s)}}).then(()=>{this.incomingData.end(),t?.(o)}).catch(s=>{this.log.error("error ending stream",s)})},super(e),this.channel=e.channel,this.channel.binaryType="arraybuffer",this.incomingData=Xt(),this.bufferedAmountLowEventTimeout=e.bufferedAmountLowEventTimeout??ub,this.maxBufferedAmount=e.maxBufferedAmount??lb,this.maxMessageSize=(e.maxMessageSize??db)-fb-hb,this.receiveFinAck=pe(),this.finAckTimeout=e.closeTimeout??pb,this.openTimeout=e.openTimeout??mb,this.channel.readyState){case"open":this.timeline.open=new Date().getTime();break;case"closed":case"closing":(this.timeline.close===void 0||this.timeline.close===0)&&(this.timeline.close=Date.now());break;case"connecting":break;default:throw this.log.error("unknown datachannel state %s",this.channel.readyState),new L("Unknown datachannel state","ERR_INVALID_STATE")}this.channel.onopen=o=>{this.timeline.open=new Date().getTime()},this.channel.onclose=o=>{this.receiveFinAck.resolve(),this.close().catch(s=>{this.log.error("error closing stream after channel closed",s)})},this.channel.onerror=o=>{let s=o.error;this.abort(s)},this.channel.onmessage=async o=>{let{data:s}=o;s===null||s.byteLength===0||this.incomingData.push(new Uint8Array(s,0,s.byteLength))};let n=this;Promise.resolve().then(async()=>{for await(let o of vr(this.incomingData)){let s=n.processIncomingProtobuf(o);s!=null&&n.sourcePush(new ue(s))}}).catch(o=>{this.log.error("error processing incoming data channel messages",o)})}sendNewStream(){}async _sendMessage(e,t=!0){if(t&&this.channel.bufferedAmount>this.maxBufferedAmount)try{this.log('channel buffer is %d, wait for "bufferedamountlow" event',this.channel.bufferedAmount),await Xa(this.channel,"bufferedamountlow",{timeout:this.bufferedAmountLowEventTimeout})}catch(n){throw n instanceof Xr?new L(`Timed out waiting for DataChannel buffer to clear after ${this.bufferedAmountLowEventTimeout}ms`,"ERR_BUFFER_CLEAR_TIMEOUT"):n}if(this.channel.readyState==="closed"||this.channel.readyState==="closing")throw new L(`Invalid datachannel state - ${this.channel.readyState}`,"ERR_INVALID_STATE");this.channel.readyState!=="open"&&(this.log('channel state is "%s" and not "open", waiting for "open" event before sending data',this.channel.readyState),await Xa(this.channel,"open",{timeout:this.openTimeout}),this.log('channel state is now "%s", sending data',this.channel.readyState)),this.channel.send(e.subarray())}async sendData(e){for(e=e.sublist();e.byteLength>0;){let t=Math.min(e.byteLength,this.maxMessageSize),n=e.subarray(0,t),o=$e.encode({message:n}),s=qn.single(o);await this._sendMessage(s),e.consume(t)}}async sendReset(){await this._sendFlag($e.Flag.RESET)}async sendCloseWrite(e){if(await this._sendFlag($e.Flag.FIN)){this.log.trace("awaiting FIN_ACK");try{await _t(this.receiveFinAck.promise,e?.signal,{errorMessage:"sending close-write was aborted before FIN_ACK was received",errorCode:"ERR_FIN_ACK_NOT_RECEIVED"})}catch(n){this.log.error("failed to await FIN_ACK",n)}}else this.log.trace("sending FIN failed, not awaiting FIN_ACK");this.receiveFinAck.resolve()}async sendCloseRead(){await this._sendFlag($e.Flag.STOP_SENDING)}processIncomingProtobuf(e){let t=$e.decode(e);if(t.flag!==void 0&&(this.log.trace('incoming flag %s, write status "%s", read status "%s"',t.flag,this.writeStatus,this.readStatus),t.flag===$e.Flag.FIN&&(this.remoteCloseWrite(),this.log.trace("sending FIN_ACK"),this._sendFlag($e.Flag.FIN_ACK).catch(n=>{this.log.error("error sending FIN_ACK immediately",n)})),t.flag===$e.Flag.RESET&&this.reset(),t.flag===$e.Flag.STOP_SENDING&&this.remoteCloseRead(),t.flag===$e.Flag.FIN_ACK&&(this.log.trace("received FIN_ACK"),this.receiveFinAck.resolve())),this.readStatus==="ready")return t.message}async _sendFlag(e){if(this.channel.readyState!=="open")return this.log.trace('not sending flag %s because channel is "%s" and not "open"',this.channel.readyState,e.toString()),!1;this.log.trace("sending flag %s",e.toString());let t=$e.encode({flag:e}),n=qn.single(t);try{return await this._sendMessage(n,!1),!0}catch(o){this.log.error("could not send flag %s",e.toString(),o)}return!1}};function tn(r){let{channel:e,direction:t}=r;return new lc({id:t==="inbound"?`i${e.id}`:`r${e.id}`,log:r.logger.forComponent(`libp2p:webrtc:stream:${t}:${e.id}`),...r})}var kf="/webrtc",Qt=class{protocol;peerConnection;bufferedStreams=[];metrics;dataChannelOptions;components;log;constructor(e,t){this.components=e,this.peerConnection=t.peerConnection,this.metrics=t.metrics,this.protocol=t.protocol??kf,this.dataChannelOptions=t.dataChannelOptions??{},this.log=e.logger.forComponent("libp2p:webrtc:datachannelmuxerfactory"),this.peerConnection.ondatachannel=({channel:n})=>{if(this.log.trace('incoming early datachannel with channel id %d and label "%s"',n.id),n.label==="init"){this.log.trace("closing early init channel"),n.close();return}let o={},s=tn({channel:n,direction:"inbound",onEnd:i=>{o.onEnd(i)},logger:e.logger,...this.dataChannelOptions});o.stream=s,o.channel=n,o.onEnd=()=>{this.bufferedStreams=this.bufferedStreams.filter(i=>i.stream.id!==s.id)},this.bufferedStreams.push(o)}}createStreamMuxer(e){return new uc(this.components,{...e,peerConnection:this.peerConnection,dataChannelOptions:this.dataChannelOptions,metrics:this.metrics,streams:this.bufferedStreams,protocol:this.protocol})}},uc=class{init;streams;protocol;log;peerConnection;dataChannelOptions;metrics;logger;constructor(e,t){this.init=t,this.log=e.logger.forComponent("libp2p:webrtc:muxer"),this.logger=e.logger,this.streams=t.streams.map(n=>n.stream),this.peerConnection=t.peerConnection,this.protocol=t.protocol??kf,this.metrics=t.metrics,this.dataChannelOptions=t.dataChannelOptions??{},this.peerConnection.ondatachannel=({channel:n})=>{if(this.log.trace("incoming datachannel with channel id %d",n.id),n.label==="init"){this.log.trace("closing init channel"),n.close();return}let o=tn({channel:n,direction:"inbound",onEnd:()=>{this.log("incoming channel %s ended with state %s",n.id,n.readyState),this.#e(o,n)},logger:this.logger,...this.dataChannelOptions});this.streams.push(o),this.metrics?.increment({incoming_stream:!0}),t?.onIncomingStream?.(o)},this.init.streams.length>0&&queueMicrotask(()=>{this.init.streams.forEach(n=>{n.onEnd=()=>{this.log("incoming early channel %s ended with state %s",n.channel.id,n.channel.readyState),this.#e(n.stream,n.channel)},this.metrics?.increment({incoming_stream:!0}),this.init?.onIncomingStream?.(n.stream)})})}#e(e,t){this.log.trace("stream %s %s %s onEnd",e.direction,e.id,e.protocol),uf(t,`${e.direction} ${e.id} ${e.protocol}`,this.dataChannelOptions.drainTimeout,{log:this.log}),this.streams=this.streams.filter(n=>n.id!==e.id),this.metrics?.increment({stream_end:!0}),this.init?.onStreamEnd?.(e)}async close(e){try{await Promise.all(this.streams.map(async t=>t.close(e)))}catch(t){this.abort(t)}}abort(e){for(let t of this.streams)t.abort(e)}source=zo();sink=Go;newStream(){let e=this.peerConnection.createDataChannel("");this.log.trace("opened outgoing datachannel with channel id %s",e.id);let t=tn({channel:e,direction:"outbound",onEnd:()=>{this.log("outgoing channel %s ended with state %s",e.id,e.readyState),this.#e(t,e)},logger:this.logger,...this.dataChannelOptions});return this.streams.push(t),this.metrics?.increment({outgoing_stream:!0}),t}};var Br=globalThis.RTCPeerConnection,ns=globalThis.RTCSessionDescription,Cf=globalThis.RTCIceCandidate;var fc=class{readNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.readNext=pe(),this.haveNext=pe()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let e=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=pe(),e}async throw(e){return this.ended=!0,e!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(e)),{done:!0,value:void 0}}async return(){let e={done:!0,value:void 0};return await this._push(void 0),e}async push(e,t){await this._push(e,t)}async end(e,t){e!=null?await this.throw(e):await this._push(void 0,t)}async _push(e,t){if(e!=null&&this.ended)throw new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;e!=null?this.nextResult={done:!1,value:e}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=pe(),await _t(this.readNext.promise,t?.signal,t)}};function If(){return new fc}var os=class extends Error{code;constructor(e,t){super(e),this.code=t}},hc=class extends os{type;constructor(e){super(e,"ABORT_ERR"),this.type="aborted"}};function Tf(r,e){let t=If();r.sink(t).catch(async i=>{await t.end(i)}),r.sink=async i=>{for await(let a of i)await t.push(a);await t.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let o=new ue;return{read:async(i,a)=>{a?.signal?.throwIfAborted();let c,l=new Promise((u,f)=>{c=()=>{f(new hc("Read aborted"))},a?.signal?.addEventListener("abort",c)});try{if(i==null){let{done:f,value:g}=await Promise.race([n.next(),l]);return f===!0?new ue:g}for(;o.byteLength<i;){let{value:f,done:g}=await Promise.race([n.next(),l]);if(g===!0)throw new os("unexpected end of input","ERR_UNEXPECTED_EOF");o.append(f)}let u=o.sublist(0,i);return o.consume(i),u}finally{c!=null&&a?.signal?.removeEventListener("abort",c)}},write:async(i,a)=>{a?.signal?.throwIfAborted(),i instanceof Uint8Array?await t.push(i,a):await t.push(i.subarray(),a)},unwrap:()=>{if(o.byteLength>0){let i=r.source;r.source=async function*(){e?.yieldBytes===!1?yield o:yield*o,yield*i}()}return r}}}var ss=class extends Error{code;constructor(e,t){super(e),this.code=t}};function Gn(r,e={}){let t=Tf(r,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=we(e.maxDataLength));let n=e?.lengthDecoder??nt,o=e?.lengthEncoder??wt;return{read:async i=>{let a=-1,c=new ue;for(;;){c.append(await t.read(1,i));try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new ss("message length length too long","ERR_MSG_LENGTH_TOO_LONG");if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new ss("message length too long","ERR_MSG_DATA_TOO_LONG");return t.read(a,i)},write:async(i,a)=>{await t.write(new ue(o(i.byteLength),i),a)},writeV:async(i,a)=>{let c=new ue(...i.flatMap(l=>[o(l.byteLength),l]));await t.write(c,a)},unwrap:()=>t.unwrap()}}function is(r,e){let t=Gn(r,e),n={read:async(o,s)=>{let i=await t.read(s);return o.decode(i)},write:async(o,s,i)=>{await t.write(s.encode(o),i)},writeV:async(o,s,i)=>{await t.writeV(o.map(a=>s.encode(a)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>t.unwrap()};return n}var Ye=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var qe;(function(r){let e;(function(o){o.SDP_OFFER="SDP_OFFER",o.SDP_ANSWER="SDP_ANSWER",o.ICE_CANDIDATE="ICE_CANDIDATE"})(e=r.Type||(r.Type={}));let t;(function(o){o[o.SDP_OFFER=0]="SDP_OFFER",o[o.SDP_ANSWER=1]="SDP_ANSWER",o[o.ICE_CANDIDATE=2]="ICE_CANDIDATE"})(t||(t={})),function(o){o.codec=()=>Sr(t)}(e=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=ct((o,s,i={})=>{i.lengthDelimited!==!1&&s.fork(),o.type!=null&&(s.uint32(8),r.Type.codec().encode(o.type,s)),o.data!=null&&(s.uint32(18),s.string(o.data)),i.lengthDelimited!==!1&&s.ldelim()},(o,s)=>{let i={},a=s==null?o.len:o.pos+s;for(;o.pos<a;){let c=o.uint32();switch(c>>>3){case 1:i.type=r.Type.codec().decode(o);break;case 2:i.data=o.string();break;default:o.skipType(c&7);break}}return i})),n),r.encode=o=>at(o,r.codec()),r.decode=o=>it(o,r.codec())})(qe||(qe={}));var as=async(r,e,t)=>{try{let n=pe();for(bb(r,n);;){let o=await Promise.race([n.promise,e.read({signal:t.signal}).catch(()=>{})]);if(o==null){t.signal?.throwIfAborted();break}if(o.type!==qe.Type.ICE_CANDIDATE)throw new L("ICE candidate message expected","ERR_NOT_ICE_CANDIDATE");let s=JSON.parse(o.data??"null");if(s===""||s===null){t.onProgress?.(new Ye("webrtc:end-of-ice-candidates")),t.log.trace("end-of-candidates received");continue}let i=new Cf(s);t.log.trace("%s received new ICE candidate %o",t.direction,s);try{t.onProgress?.(new Ye("webrtc:add-ice-candidate",i.candidate)),await r.addIceCandidate(i)}catch(a){t.log.error("%s bad candidate received",t.direction,s,a)}}}catch(n){if(t.log.error("%s error parsing ICE candidate",t.direction,n),t.signal?.aborted===!0)throw n}};function gb(r){return Kn?r.iceConnectionState:r.connectionState}function bb(r,e){r[Kn?"oniceconnectionstatechange":"onconnectionstatechange"]=t=>{switch(gb(r)){case"connected":e.resolve();break;case"failed":case"disconnected":case"closed":e.reject(new L("RTCPeerConnection was closed","ERR_CONNECTION_CLOSED_BEFORE_CONNECTED"));break;default:break}}}async function _f({rtcConfiguration:r,dataChannel:e,signal:t,metrics:n,multiaddr:o,connectionManager:s,transportManager:i,log:a,logger:c,onProgress:l}){let{baseAddr:u}=Rf(o);n?.dialerEvents.increment({open:!0}),a.trace("dialing base address: %a",u);let f=u.getPeerId();if(f==null)throw new L("Relay peer was missing","ERR_INVALID_ADDRESS");let g=s.getConnections(yr(f)),m,d=!1;g.length===0?(l?.(new Ye("webrtc:dial-relay")),m=await i.dial(u,{signal:t,onProgress:l}),d=!0):(l?.(new Ye("webrtc:reuse-relay-connection")),m=g[0]);try{l?.(new Ye("webrtc:open-signaling-stream"));let h=await m.newStream(cs,{signal:t,runOnTransientConnection:!0}),p=is(h).pb(qe),y=new Br(r),E=new Qt({logger:c},{peerConnection:y,dataChannelOptions:e});try{let b=y.createDataChannel("init");y.onicecandidate=({candidate:A})=>{let S=JSON.stringify(A?.toJSON()??null);a.trace("initiator sending ICE candidate %o",A),p.write({type:qe.Type.ICE_CANDIDATE,data:S},{signal:t}).catch(_=>{a.error("error sending ICE candidate",_)})},y.onicecandidateerror=A=>{a.error("initiator ICE candidate error",A)};let v=await y.createOffer().catch(A=>{throw a.error("could not execute createOffer",A),new L("Failed to set createOffer","ERR_SDP_HANDSHAKE_FAILED")});a.trace("initiator send SDP offer %s",v.sdp),l?.(new Ye("webrtc:send-sdp-offer")),await p.write({type:qe.Type.SDP_OFFER,data:v.sdp},{signal:t}),await y.setLocalDescription(v).catch(A=>{throw a.error("could not execute setLocalDescription",A),new L("Failed to set localDescription","ERR_SDP_HANDSHAKE_FAILED")}),l?.(new Ye("webrtc:read-sdp-answer"));let x=await p.read({signal:t});if(x.type!==qe.Type.SDP_ANSWER)throw new L("Remote should send an SDP answer","ERR_SDP_HANDSHAKE_FAILED");a.trace("initiator receive SDP answer %s",x.data);let D=new ns({type:"answer",sdp:x.data});return await y.setRemoteDescription(D).catch(A=>{throw a.error("could not execute setRemoteDescription",A),new L("Failed to set remoteDescription","ERR_SDP_HANDSHAKE_FAILED")}),a.trace("initiator read candidates until connected"),l?.(new Ye("webrtc:read-ice-candidates")),await as(y,p,{direction:"initiator",signal:t,log:a,onProgress:l}),a.trace("initiator connected, closing init channel"),b.close(),l?.(new Ye("webrtc:close-signaling-stream")),a.trace("closing signaling channel"),await h.close({signal:t}),a.trace("initiator connected to remote address %s",o),{remoteAddress:o,peerConnection:y,muxerFactory:E}}catch(b){throw a.error("outgoing signaling error",b),y.close(),h.abort(b),b}finally{y.onicecandidate=null,y.onicecandidateerror=null}}finally{if(d)try{await m.close({signal:t})}catch(h){m.abort(h)}}}var yb=U("dns4"),wb=U("dns6"),xb=U("dnsaddr"),kr=ye(U("dns"),xb,yb,wb),fs=ye(U("ip4"),U("ip6")),rn=ye(K(fs,U("tcp")),K(kr,U("tcp"))),hs=K(fs,U("udp")),Eb=K(hs,U("utp")),vb=K(hs,U("quic")),Ab=K(hs,U("quic-v1")),dc=ye(K(rn,U("ws")),K(kr,U("ws"))),ls=ye(K(dc,U("p2p")),dc),pc=ye(K(rn,U("wss")),K(kr,U("wss")),K(rn,U("tls"),U("ws")),K(kr,U("tls"),U("ws"))),us=ye(K(pc,U("p2p")),pc),mc=ye(K(rn,U("http")),K(fs,U("http")),K(kr,U("http"))),gc=ye(K(rn,U("https")),K(fs,U("https")),K(kr,U("https"))),Nf=K(hs,U("webrtc-direct"),U("certhash")),Of=ye(K(Nf,U("p2p")),Nf),Lf=K(Ab,U("webtransport"),U("certhash"),U("certhash")),Pf=ye(K(Lf,U("p2p")),Lf),Mf=ye(K(ls,U("p2p-webrtc-star"),U("p2p")),K(us,U("p2p-webrtc-star"),U("p2p")),K(ls,U("p2p-webrtc-star")),K(us,U("p2p-webrtc-star"))),eD=ye(K(ls,U("p2p-websocket-star"),U("p2p")),K(us,U("p2p-websocket-star"),U("p2p")),K(ls,U("p2p-websocket-star")),K(us,U("p2p-websocket-star"))),Ff=ye(K(mc,U("p2p-webrtc-direct"),U("p2p")),K(gc,U("p2p-webrtc-direct"),U("p2p")),K(mc,U("p2p-webrtc-direct")),K(gc,U("p2p-webrtc-direct"))),Cr=ye(dc,pc,mc,gc,Mf,Ff,rn,Eb,vb,kr,Of,Pf),tD=ye(K(Cr,U("p2p-stardust"),U("p2p")),K(Cr,U("p2p-stardust"))),er=ye(K(Cr,U("p2p")),Mf,Ff,Of,Pf,U("p2p")),Uf=ye(K(er,U("p2p-circuit"),er),K(er,U("p2p-circuit")),K(U("p2p-circuit"),er),K(Cr,U("p2p-circuit")),K(U("p2p-circuit"),Cr),U("p2p-circuit")),Vf=()=>ye(K(Uf,Vf),Uf),Rt=Vf(),rD=ye(K(Rt,er,Rt),K(er,Rt),K(Rt,er),Rt,er);var nD=ye(K(Rt,U("webrtc"),U("p2p")),K(Rt,U("webrtc")),K(Cr,U("webrtc"),U("p2p")),K(Cr,U("webrtc")),U("webrtc"));function Hf(r){function e(t){let n;try{n=ot(t)}catch{return!1}let o=r(n.protoNames());return o===null?!1:o===!0||o===!1?o:o.length===0}return e}function K(...r){function e(t){if(t.length<r.length)return null;let n=t;return r.some(o=>(n=typeof o=="function"?o().partialMatch(t):o.partialMatch(t),Array.isArray(n)&&(t=n),n===null)),n}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:Hf(e),partialMatch:e}}function ye(...r){function e(n){let o=null;return r.some(s=>{let i=typeof s=="function"?s().partialMatch(n):s.partialMatch(n);return i!=null?(o=i,!0):!1}),o}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:Hf(e),partialMatch:e}}function U(r){let e=r;function t(o){let s;try{s=ot(o)}catch{return!1}let i=s.protoNames();return i.length===1&&i[0]===e}function n(o){return o.length===0?null:o[0]===e?o.slice(1):null}return{toString:function(){return e},matches:t,partialMatch:n}}var ds=class extends _o{peerId;transportManager;shutdownController;constructor(e,t){super(),this.peerId=e.peerId,this.transportManager=e.transportManager,this.shutdownController=t.shutdownController}async listen(){this.safeDispatchEvent("listening",{})}getAddrs(){return this.transportManager.getListeners().filter(e=>e!==this).map(e=>e.getAddrs().filter(t=>Rt.matches(t)).map(t=>t.encapsulate(`/webrtc/p2p/${this.peerId}`))).flat()}async close(){this.shutdownController.abort(),this.safeDispatchEvent("close",{})}};async function Kf({peerConnection:r,stream:e,signal:t,connection:n,log:o}){o.trace("new inbound signaling stream");let s=is(e).pb(qe);try{r.onicecandidate=({candidate:u})=>{let f=JSON.stringify(u?.toJSON()??null);o.trace("recipient sending ICE candidate %s",f),s.write({type:qe.Type.ICE_CANDIDATE,data:f},{signal:t}).catch(g=>{o.error("error sending ICE candidate",g)})};let a=await s.read({signal:t});if(a.type!==qe.Type.SDP_OFFER)throw new L(`expected message type SDP_OFFER, received: ${a.type??"undefined"} `,"ERR_SDP_HANDSHAKE_FAILED");o.trace("recipient receive SDP offer %s",a.data);let c=new ns({type:"offer",sdp:a.data});await r.setRemoteDescription(c).catch(u=>{throw o.error("could not execute setRemoteDescription",u),new L("Failed to set remoteDescription","ERR_SDP_HANDSHAKE_FAILED")});let l=await r.createAnswer().catch(u=>{throw o.error("could not execute createAnswer",u),new L("Failed to create answer","ERR_SDP_HANDSHAKE_FAILED")});o.trace("recipient send SDP answer %s",l.sdp),await s.write({type:qe.Type.SDP_ANSWER,data:l.sdp},{signal:t}),await r.setLocalDescription(l).catch(u=>{throw o.error("could not execute setLocalDescription",u),new L("Failed to set localDescription","ERR_SDP_HANDSHAKE_FAILED")}),o.trace("recipient read candidates until connected"),await as(r,s,{direction:"recipient",signal:t,log:o})}catch(a){if(r.connectionState!=="connected")throw o.error("error while handling signaling stream from peer %a",n.remoteAddr,a),r.close(),a;o("error while handling signaling stream from peer %a, ignoring as the RTCPeerConnection is already connected",n.remoteAddr,a)}let i=ot(`/webrtc/p2p/${n.remoteAddr.getPeerId()}`);return o.trace("recipient connected to remote address %s",i),{remoteAddress:i}}var Db="/webrtc",Sb="/p2p-circuit",cs="/webrtc-signaling/0.0.1",Bb=30*1e3,ps=class{components;init;log;_started=!1;metrics;shutdownController;constructor(e,t={}){this.components=e,this.init=t,this.log=e.logger.forComponent("libp2p:webrtc"),this.shutdownController=new AbortController,To(1/0,this.shutdownController.signal),e.metrics!=null&&(this.metrics={dialerEvents:e.metrics.registerCounterGroup("libp2p_webrtc_dialer_events_total",{label:"event",help:"Total count of WebRTC dialer events by type"}),listenerEvents:e.metrics.registerCounterGroup("libp2p_webrtc_listener_events_total",{label:"event",help:"Total count of WebRTC listener events by type"})})}[Io]=!0;[Symbol.toStringTag]="@libp2p/webrtc";[Hr]=["@libp2p/transport"];[su]=["@libp2p/identify","@libp2p/circuit-relay-v2-transport"];isStarted(){return this._started}async start(){await this.components.registrar.handle(cs,e=>{this._onProtocol(e).catch(t=>{this.log.error("failed to handle incoming connect from %p",e.connection.remotePeer,t)})},{runOnTransientConnection:!0}),this._started=!0}async stop(){await this.components.registrar.unhandle(cs),this._started=!1}createListener(e){return new ds(this.components,{shutdownController:this.shutdownController})}listenFilter(e){return e.filter(Xu.exactMatch)}dialFilter(e){return this.listenFilter(e)}async dial(e,t){this.log.trace("dialing address: %a",e);let{remoteAddress:n,peerConnection:o,muxerFactory:s}=await _f({rtcConfiguration:await $n(this.init.rtcConfiguration),dataChannel:this.init.dataChannel,multiaddr:e,dataChannelOptions:this.init.dataChannel,signal:t.signal,connectionManager:this.components.connectionManager,transportManager:this.components.transportManager,log:this.log,logger:this.components.logger,onProgress:t.onProgress}),i=new xr(this.components,{peerConnection:o,timeline:{open:Date.now()},remoteAddr:n,metrics:this.metrics?.dialerEvents}),a=await t.upgrader.upgradeOutbound(i,{skipProtection:!0,skipEncryption:!0,muxerFactory:s,onProgress:t.onProgress});return this._closeOnShutdown(o,i),a}async _onProtocol({connection:e,stream:t}){let n=AbortSignal.timeout(this.init.inboundConnectionTimeout??Bb),o=new Br(await $n(this.init.rtcConfiguration)),s=new Qt(this.components,{peerConnection:o,dataChannelOptions:this.init.dataChannel});try{let{remoteAddress:i}=await Kf({peerConnection:o,connection:e,stream:t,signal:n,log:this.log});await t.close({signal:n});let a=new xr(this.components,{peerConnection:o,timeline:{open:new Date().getTime()},remoteAddr:i,metrics:this.metrics?.listenerEvents});await this.components.upgrader.upgradeInbound(a,{skipEncryption:!0,skipProtection:!0,muxerFactory:s}),this._closeOnShutdown(o,a)}catch(i){throw this.log.error("incoming signaling error",i),o.close(),t.abort(i),i}}_closeOnShutdown(e,t){let n=()=>{t.close().catch(o=>{this.log.error("could not close WebRTCMultiaddrConnection",o)})};this.shutdownController.signal.addEventListener("abort",n),e.addEventListener("close",()=>{this.shutdownController.signal.removeEventListener("abort",n)})}};function Rf(r){let e=r.toString().split(Db+"/");if(e.length!==2)throw new L("webrtc protocol was not present in multiaddr",Ge.ERR_INVALID_MULTIADDR);if(!e[0].includes(Sb))throw new L("p2p-circuit protocol was not present in multiaddr",Ge.ERR_INVALID_MULTIADDR);let t=ot(e[0]),o=ot("/"+e[1]).getPeerId();if(o==null)throw new L("destination peer id was missing",Ge.ERR_INVALID_MULTIADDR);let s=t.protos().pop();if(s===void 0)throw new L("invalid multiaddr",Ge.ERR_INVALID_MULTIADDR);return s.name!=="p2p"&&(t=t.encapsulate(`/p2p/${o}`)),{baseAddr:t,peerId:yr(o)}}var Rc={};Q(Rc,{Ed25519PrivateKey:()=>Nr,Ed25519PublicKey:()=>eo,generateKeyPair:()=>Uy,generateKeyPairFromSeed:()=>bh,unmarshalEd25519PrivateKey:()=>Ny,unmarshalEd25519PublicKey:()=>Ly});function Qe(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function tr(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`positive integer expected, not ${r}`)}function kb(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function nn(r,...e){if(!kb(r))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(r.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${r.length}`)}function Ir(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");tr(r.outputLen),tr(r.blockLen)}function on(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function $f(r,e){nn(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var ms=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var an=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),lt=(r,e)=>r<<32-e|r>>>e;var UD=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;var Cb=async()=>{};async function qf(r,e,t){let n=Date.now();for(let o=0;o<r;o++){t(o);let s=Date.now()-n;s>=0&&s<e||(await Cb(),n+=s)}}function Wf(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function ut(r){return typeof r=="string"&&(r=Wf(r)),nn(r),r}function bc(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];nn(o),e+=o.length}let t=new Uint8Array(e);for(let n=0,o=0;n<r.length;n++){let s=r[n];t.set(s,o),o+=s.length}return t}var sn=class{clone(){return this._cloneInto()}},Ib={}.toString;function zf(r,e){if(e!==void 0&&Ib.call(e)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(r,e)}function gs(r){let e=n=>r().update(ut(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function Tr(r=32){if(ms&&typeof ms.getRandomValues=="function")return ms.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function Tb(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(t>>o&s),a=Number(t&s),c=n?4:0,l=n?0:4;r.setUint32(e+c,i,n),r.setUint32(e+l,a,n)}var Gf=(r,e,t)=>r&e^~r&t,jf=(r,e,t)=>r&e^r&t^e&t,cn=class extends sn{constructor(e,t,n,o){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=an(this.buffer)}update(e){on(this);let{view:t,buffer:n,blockLen:o}=this;e=ut(e);let s=e.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=an(e);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(e.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){on(this),$f(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;t[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)t[f]=0;Tb(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=an(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let l=c/4,u=this.get();if(l>u.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<l;f++)a.setUint32(4*f,u[f],s)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return e.length=o,e.pos=a,e.finished=s,e.destroyed=i,o%t&&e.buffer.set(n),e}};var bs=BigInt(4294967295),yc=BigInt(32);function Yf(r,e=!1){return e?{h:Number(r&bs),l:Number(r>>yc&bs)}:{h:Number(r>>yc&bs)|0,l:Number(r&bs)|0}}function _b(r,e=!1){let t=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let o=0;o<r.length;o++){let{h:s,l:i}=Yf(r[o],e);[t[o],n[o]]=[s,i]}return[t,n]}var Rb=(r,e)=>BigInt(r>>>0)<<yc|BigInt(e>>>0),Nb=(r,e,t)=>r>>>t,Lb=(r,e,t)=>r<<32-t|e>>>t,Ub=(r,e,t)=>r>>>t|e<<32-t,Ob=(r,e,t)=>r<<32-t|e>>>t,Pb=(r,e,t)=>r<<64-t|e>>>t-32,Mb=(r,e,t)=>r>>>t-32|e<<64-t,Fb=(r,e)=>e,Vb=(r,e)=>r,Hb=(r,e,t)=>r<<t|e>>>32-t,Kb=(r,e,t)=>e<<t|r>>>32-t,$b=(r,e,t)=>e<<t-32|r>>>64-t,qb=(r,e,t)=>r<<t-32|e>>>64-t;function Wb(r,e,t,n){let o=(e>>>0)+(n>>>0);return{h:r+t+(o/2**32|0)|0,l:o|0}}var zb=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),Gb=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,jb=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),Yb=(r,e,t,n,o)=>e+t+n+o+(r/2**32|0)|0,Zb=(r,e,t,n,o)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(o>>>0),Xb=(r,e,t,n,o,s)=>e+t+n+o+s+(r/2**32|0)|0;var Jb={fromBig:Yf,split:_b,toBig:Rb,shrSH:Nb,shrSL:Lb,rotrSH:Ub,rotrSL:Ob,rotrBH:Pb,rotrBL:Mb,rotr32H:Fb,rotr32L:Vb,rotlSH:Hb,rotlSL:Kb,rotlBH:$b,rotlBL:qb,add:Wb,add3L:zb,add3H:Gb,add4L:jb,add4H:Yb,add5H:Xb,add5L:Zb},Z=Jb;var[Qb,ey]=Z.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),rr=new Uint32Array(80),nr=new Uint32Array(80),wc=class extends cn{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:e,Al:t,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:l,El:u,Fh:f,Fl:g,Gh:m,Gl:d,Hh:h,Hl:p}=this;return[e,t,n,o,s,i,a,c,l,u,f,g,m,d,h,p]}set(e,t,n,o,s,i,a,c,l,u,f,g,m,d,h,p){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=l|0,this.El=u|0,this.Fh=f|0,this.Fl=g|0,this.Gh=m|0,this.Gl=d|0,this.Hh=h|0,this.Hl=p|0}process(e,t){for(let b=0;b<16;b++,t+=4)rr[b]=e.getUint32(t),nr[b]=e.getUint32(t+=4);for(let b=16;b<80;b++){let v=rr[b-15]|0,x=nr[b-15]|0,D=Z.rotrSH(v,x,1)^Z.rotrSH(v,x,8)^Z.shrSH(v,x,7),A=Z.rotrSL(v,x,1)^Z.rotrSL(v,x,8)^Z.shrSL(v,x,7),S=rr[b-2]|0,_=nr[b-2]|0,O=Z.rotrSH(S,_,19)^Z.rotrBH(S,_,61)^Z.shrSH(S,_,6),R=Z.rotrSL(S,_,19)^Z.rotrBL(S,_,61)^Z.shrSL(S,_,6),H=Z.add4L(A,R,nr[b-7],nr[b-16]),V=Z.add4H(H,D,O,rr[b-7],rr[b-16]);rr[b]=V|0,nr[b]=H|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:l,Dl:u,Eh:f,El:g,Fh:m,Fl:d,Gh:h,Gl:p,Hh:y,Hl:E}=this;for(let b=0;b<80;b++){let v=Z.rotrSH(f,g,14)^Z.rotrSH(f,g,18)^Z.rotrBH(f,g,41),x=Z.rotrSL(f,g,14)^Z.rotrSL(f,g,18)^Z.rotrBL(f,g,41),D=f&m^~f&h,A=g&d^~g&p,S=Z.add5L(E,x,A,ey[b],nr[b]),_=Z.add5H(S,y,v,D,Qb[b],rr[b]),O=S|0,R=Z.rotrSH(n,o,28)^Z.rotrBH(n,o,34)^Z.rotrBH(n,o,39),H=Z.rotrSL(n,o,28)^Z.rotrBL(n,o,34)^Z.rotrBL(n,o,39),V=n&s^n&a^s&a,G=o&i^o&c^i&c;y=h|0,E=p|0,h=m|0,p=d|0,m=f|0,d=g|0,{h:f,l:g}=Z.add(l|0,u|0,_|0,O|0),l=a|0,u=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let B=Z.add3L(O,H,G);n=Z.add3H(B,_,R,V),o=B|0}({h:n,l:o}=Z.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Z.add(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Z.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:u}=Z.add(this.Dh|0,this.Dl|0,l|0,u|0),{h:f,l:g}=Z.add(this.Eh|0,this.El|0,f|0,g|0),{h:m,l:d}=Z.add(this.Fh|0,this.Fl|0,m|0,d|0),{h,l:p}=Z.add(this.Gh|0,this.Gl|0,h|0,p|0),{h:y,l:E}=Z.add(this.Hh|0,this.Hl|0,y|0,E|0),this.set(n,o,s,i,a,c,l,u,f,g,m,d,h,p,y,E)}roundClean(){rr.fill(0),nr.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var jn=gs(()=>new wc);var ws={};Q(ws,{abytes:()=>ln,bitGet:()=>ay,bitLen:()=>iy,bitMask:()=>Yn,bitSet:()=>cy,bytesToHex:()=>Lt,bytesToNumberBE:()=>Ut,bytesToNumberLE:()=>ft,concatBytes:()=>Pt,createHmacDrbg:()=>vc,ensureBytes:()=>ce,equalBytes:()=>oy,hexToBytes:()=>_r,hexToNumber:()=>Ec,isBytes:()=>or,numberToBytesBE:()=>sr,numberToBytesLE:()=>Ot,numberToHexUnpadded:()=>Qf,numberToVarBytesBE:()=>ny,utf8ToBytes:()=>sy,validateObject:()=>et});var Jf=BigInt(0),ys=BigInt(1),ty=BigInt(2);function or(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function ln(r){if(!or(r))throw new Error("Uint8Array expected")}var ry=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function Lt(r){ln(r);let e="";for(let t=0;t<r.length;t++)e+=ry[r[t]];return e}function Qf(r){let e=r.toString(16);return e.length&1?`0${e}`:e}function Ec(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var Nt={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function Zf(r){if(r>=Nt._0&&r<=Nt._9)return r-Nt._0;if(r>=Nt._A&&r<=Nt._F)return r-(Nt._A-10);if(r>=Nt._a&&r<=Nt._f)return r-(Nt._a-10)}function _r(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let e=r.length,t=e/2;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(t);for(let o=0,s=0;o<t;o++,s+=2){let i=Zf(r.charCodeAt(s)),a=Zf(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Ut(r){return Ec(Lt(r))}function ft(r){return ln(r),Ec(Lt(Uint8Array.from(r).reverse()))}function sr(r,e){return _r(r.toString(16).padStart(e*2,"0"))}function Ot(r,e){return sr(r,e).reverse()}function ny(r){return _r(Qf(r))}function ce(r,e,t){let n;if(typeof e=="string")try{n=_r(e)}catch(s){throw new Error(`${r} must be valid hex string, got "${e}". Cause: ${s}`)}else if(or(e))n=Uint8Array.from(e);else throw new Error(`${r} must be hex string or Uint8Array`);let o=n.length;if(typeof t=="number"&&o!==t)throw new Error(`${r} expected ${t} bytes, got ${o}`);return n}function Pt(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];ln(o),e+=o.length}let t=new Uint8Array(e);for(let n=0,o=0;n<r.length;n++){let s=r[n];t.set(s,o),o+=s.length}return t}function oy(r,e){if(r.length!==e.length)return!1;let t=0;for(let n=0;n<r.length;n++)t|=r[n]^e[n];return t===0}function sy(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function iy(r){let e;for(e=0;r>Jf;r>>=ys,e+=1);return e}function ay(r,e){return r>>BigInt(e)&ys}function cy(r,e,t){return r|(t?ys:Jf)<<BigInt(e)}var Yn=r=>(ty<<BigInt(r-1))-ys,xc=r=>new Uint8Array(r),Xf=r=>Uint8Array.from(r);function vc(r,e,t){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof t!="function")throw new Error("hmacFn must be a function");let n=xc(r),o=xc(r),s=0,i=()=>{n.fill(1),o.fill(0),s=0},a=(...f)=>t(o,n,...f),c=(f=xc())=>{o=a(Xf([0]),f),n=a(),f.length!==0&&(o=a(Xf([1]),f),n=a())},l=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,g=[];for(;f<e;){n=a();let m=n.slice();g.push(m),f+=n.length}return Pt(...g)};return(f,g)=>{i(),c(f);let m;for(;!(m=g(l()));)c();return i(),m}}var ly={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||or(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,e)=>e.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function et(r,e,t={}){let n=(o,s,i)=>{let a=ly[s];if(typeof a!="function")throw new Error(`Invalid validator "${s}", expected function`);let c=r[o];if(!(i&&c===void 0)&&!a(c,r))throw new Error(`Invalid param ${String(o)}=${c} (${typeof c}), expected ${s}`)};for(let[o,s]of Object.entries(e))n(o,s,!1);for(let[o,s]of Object.entries(t))n(o,s,!0);return r}var ke=BigInt(0),fe=BigInt(1),Rr=BigInt(2),uy=BigInt(3),Ac=BigInt(4),eh=BigInt(5),th=BigInt(8),fy=BigInt(9),hy=BigInt(16);function te(r,e){let t=r%e;return t>=ke?t:e+t}function Dc(r,e,t){if(t<=ke||e<ke)throw new Error("Expected power/modulo > 0");if(t===fe)return ke;let n=fe;for(;e>ke;)e&fe&&(n=n*r%t),r=r*r%t,e>>=fe;return n}function le(r,e,t){let n=r;for(;e-- >ke;)n*=n,n%=t;return n}function xs(r,e){if(r===ke||e<=ke)throw new Error(`invert: expected positive integers, got n=${r} mod=${e}`);let t=te(r,e),n=e,o=ke,s=fe,i=fe,a=ke;for(;t!==ke;){let l=n/t,u=n%t,f=o-i*l,g=s-a*l;n=t,t=u,o=i,s=a,i=f,a=g}if(n!==fe)throw new Error("invert: does not exist");return te(o,e)}function dy(r){let e=(r-fe)/Rr,t,n,o;for(t=r-fe,n=0;t%Rr===ke;t/=Rr,n++);for(o=Rr;o<r&&Dc(o,e,r)!==r-fe;o++);if(n===1){let i=(r+fe)/Ac;return function(c,l){let u=c.pow(l,i);if(!c.eql(c.sqr(u),l))throw new Error("Cannot find square root");return u}}let s=(t+fe)/Rr;return function(a,c){if(a.pow(c,e)===a.neg(a.ONE))throw new Error("Cannot find square root");let l=n,u=a.pow(a.mul(a.ONE,o),t),f=a.pow(c,s),g=a.pow(c,t);for(;!a.eql(g,a.ONE);){if(a.eql(g,a.ZERO))return a.ZERO;let m=1;for(let h=a.sqr(g);m<l&&!a.eql(h,a.ONE);m++)h=a.sqr(h);let d=a.pow(u,fe<<BigInt(l-m-1));u=a.sqr(d),f=a.mul(f,d),g=a.mul(g,u),l=m}return f}}function py(r){if(r%Ac===uy){let e=(r+fe)/Ac;return function(n,o){let s=n.pow(o,e);if(!n.eql(n.sqr(s),o))throw new Error("Cannot find square root");return s}}if(r%th===eh){let e=(r-eh)/th;return function(n,o){let s=n.mul(o,Rr),i=n.pow(s,e),a=n.mul(o,i),c=n.mul(n.mul(a,Rr),i),l=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(l),o))throw new Error("Cannot find square root");return l}}return r%hy,dy(r)}var rh=(r,e)=>(te(r,e)&fe)===fe,my=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Sc(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=my.reduce((n,o)=>(n[o]="function",n),e);return et(r,t)}function gy(r,e,t){if(t<ke)throw new Error("Expected power > 0");if(t===ke)return r.ONE;if(t===fe)return e;let n=r.ONE,o=e;for(;t>ke;)t&fe&&(n=r.mul(n,o)),o=r.sqr(o),t>>=fe;return n}function by(r,e){let t=new Array(e.length),n=e.reduce((s,i,a)=>r.is0(i)?s:(t[a]=s,r.mul(s,i)),r.ONE),o=r.inv(n);return e.reduceRight((s,i,a)=>r.is0(i)?s:(t[a]=r.mul(s,t[a]),r.mul(s,i)),o),t}function Bc(r,e){let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function Es(r,e,t=!1,n={}){if(r<=ke)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:o,nByteLength:s}=Bc(r,e);if(s>2048)throw new Error("Field lengths over 2048 bytes are not supported");let i=py(r),a=Object.freeze({ORDER:r,BITS:o,BYTES:s,MASK:Yn(o),ZERO:ke,ONE:fe,create:c=>te(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return ke<=c&&c<r},is0:c=>c===ke,isOdd:c=>(c&fe)===fe,neg:c=>te(-c,r),eql:(c,l)=>c===l,sqr:c=>te(c*c,r),add:(c,l)=>te(c+l,r),sub:(c,l)=>te(c-l,r),mul:(c,l)=>te(c*l,r),pow:(c,l)=>gy(a,c,l),div:(c,l)=>te(c*xs(l,r),r),sqrN:c=>c*c,addN:(c,l)=>c+l,subN:(c,l)=>c-l,mulN:(c,l)=>c*l,inv:c=>xs(c,r),sqrt:n.sqrt||(c=>i(a,c)),invertBatch:c=>by(a,c),cmov:(c,l,u)=>u?l:c,toBytes:c=>t?Ot(c,s):sr(c,s),fromBytes:c=>{if(c.length!==s)throw new Error(`Fp.fromBytes: expected ${s}, got ${c.length}`);return t?ft(c):Ut(c)}});return Object.freeze(a)}function nh(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let e=r.toString(2).length;return Math.ceil(e/8)}function kc(r){let e=nh(r);return e+Math.ceil(e/2)}function oh(r,e,t=!1){let n=r.length,o=nh(e),s=kc(e);if(n<16||n<s||n>1024)throw new Error(`expected ${s}-1024 bytes of input, got ${n}`);let i=t?Ut(r):ft(r),a=te(i,e-fe)+fe;return t?Ot(a,o):sr(a,o)}var wy=BigInt(0),Cc=BigInt(1);function vs(r,e){let t=(o,s)=>{let i=s.negate();return o?i:s},n=o=>{let s=Math.ceil(e/o)+1,i=2**(o-1);return{windows:s,windowSize:i}};return{constTimeNegate:t,unsafeLadder(o,s){let i=r.ZERO,a=o;for(;s>wy;)s&Cc&&(i=i.add(a)),a=a.double(),s>>=Cc;return i},precomputeWindow(o,s){let{windows:i,windowSize:a}=n(s),c=[],l=o,u=l;for(let f=0;f<i;f++){u=l,c.push(u);for(let g=1;g<a;g++)u=u.add(l),c.push(u);l=u.double()}return c},wNAF(o,s,i){let{windows:a,windowSize:c}=n(o),l=r.ZERO,u=r.BASE,f=BigInt(2**o-1),g=2**o,m=BigInt(o);for(let d=0;d<a;d++){let h=d*c,p=Number(i&f);i>>=m,p>c&&(p-=g,i+=Cc);let y=h,E=h+Math.abs(p)-1,b=d%2!==0,v=p<0;p===0?u=u.add(t(b,s[y])):l=l.add(t(v,s[E]))}return{p:l,f:u}},wNAFCached(o,s,i,a){let c=o._WINDOW_SIZE||1,l=s.get(o);return l||(l=this.precomputeWindow(o,c),c!==1&&s.set(o,a(l))),this.wNAF(c,l,i)}}}function Zn(r){return Sc(r.Fp),et(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Bc(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var ht=BigInt(0),Ze=BigInt(1),As=BigInt(2),xy=BigInt(8),Ey={zip215:!0};function vy(r){let e=Zn(r);return et(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function sh(r){let e=vy(r),{Fp:t,n,prehash:o,hash:s,randomBytes:i,nByteLength:a,h:c}=e,l=As<<BigInt(a*8)-Ze,u=t.create,f=e.uvRatio||((k,w)=>{try{return{isValid:!0,value:t.sqrt(k*t.inv(w))}}catch{return{isValid:!1,value:ht}}}),g=e.adjustScalarBytes||(k=>k),m=e.domain||((k,w,C)=>{if(w.length||C)throw new Error("Contexts/pre-hash are not supported");return k}),d=k=>typeof k=="bigint"&&ht<k,h=(k,w)=>d(k)&&d(w)&&k<w,p=k=>k===ht||h(k,l);function y(k,w){if(h(k,w))return k;throw new Error(`Expected valid scalar < ${w}, got ${typeof k} ${k}`)}function E(k){return k===ht?k:y(k,n)}let b=new Map;function v(k){if(!(k instanceof x))throw new Error("ExtendedPoint expected")}class x{constructor(w,C,T,N){if(this.ex=w,this.ey=C,this.ez=T,this.et=N,!p(w))throw new Error("x required");if(!p(C))throw new Error("y required");if(!p(T))throw new Error("z required");if(!p(N))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(w){if(w instanceof x)throw new Error("extended point not allowed");let{x:C,y:T}=w||{};if(!p(C)||!p(T))throw new Error("invalid affine point");return new x(C,T,Ze,u(C*T))}static normalizeZ(w){let C=t.invertBatch(w.map(T=>T.ez));return w.map((T,N)=>T.toAffine(C[N])).map(x.fromAffine)}_setWindowSize(w){this._WINDOW_SIZE=w,b.delete(this)}assertValidity(){let{a:w,d:C}=e;if(this.is0())throw new Error("bad point: ZERO");let{ex:T,ey:N,ez:$,et:q}=this,Y=u(T*T),z=u(N*N),j=u($*$),ae=u(j*j),se=u(Y*w),Ie=u(j*u(se+z)),Te=u(ae+u(C*u(Y*z)));if(Ie!==Te)throw new Error("bad point: equation left != right (1)");let ve=u(T*N),Oe=u($*q);if(ve!==Oe)throw new Error("bad point: equation left != right (2)")}equals(w){v(w);let{ex:C,ey:T,ez:N}=this,{ex:$,ey:q,ez:Y}=w,z=u(C*Y),j=u($*N),ae=u(T*Y),se=u(q*N);return z===j&&ae===se}is0(){return this.equals(x.ZERO)}negate(){return new x(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:w}=e,{ex:C,ey:T,ez:N}=this,$=u(C*C),q=u(T*T),Y=u(As*u(N*N)),z=u(w*$),j=C+T,ae=u(u(j*j)-$-q),se=z+q,Ie=se-Y,Te=z-q,ve=u(ae*Ie),Oe=u(se*Te),kt=u(ae*Te),mr=u(Ie*se);return new x(ve,Oe,mr,kt)}add(w){v(w);let{a:C,d:T}=e,{ex:N,ey:$,ez:q,et:Y}=this,{ex:z,ey:j,ez:ae,et:se}=w;if(C===BigInt(-1)){let Zl=u(($-N)*(j+z)),Xl=u(($+N)*(j-z)),Oi=u(Xl-Zl);if(Oi===ht)return this.double();let Jl=u(q*As*se),Ql=u(Y*As*ae),eu=Ql+Jl,tu=Xl+Zl,ru=Ql-Jl,P0=u(eu*Oi),M0=u(tu*ru),F0=u(eu*ru),V0=u(Oi*tu);return new x(P0,M0,V0,F0)}let Ie=u(N*z),Te=u($*j),ve=u(Y*T*se),Oe=u(q*ae),kt=u((N+$)*(z+j)-Ie-Te),mr=Oe-ve,Nn=Oe+ve,Yl=u(Te-C*Ie),N0=u(kt*mr),L0=u(Nn*Yl),U0=u(kt*Yl),O0=u(mr*Nn);return new x(N0,L0,O0,U0)}subtract(w){return this.add(w.negate())}wNAF(w){return S.wNAFCached(this,b,w,x.normalizeZ)}multiply(w){let{p:C,f:T}=this.wNAF(y(w,n));return x.normalizeZ([C,T])[0]}multiplyUnsafe(w){let C=E(w);return C===ht?A:this.equals(A)||C===Ze?this:this.equals(D)?this.wNAF(C).p:S.unsafeLadder(this,C)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return S.unsafeLadder(this,n).is0()}toAffine(w){let{ex:C,ey:T,ez:N}=this,$=this.is0();w==null&&(w=$?xy:t.inv(N));let q=u(C*w),Y=u(T*w),z=u(N*w);if($)return{x:ht,y:Ze};if(z!==Ze)throw new Error("invZ was invalid");return{x:q,y:Y}}clearCofactor(){let{h:w}=e;return w===Ze?this:this.multiplyUnsafe(w)}static fromHex(w,C=!1){let{d:T,a:N}=e,$=t.BYTES;w=ce("pointHex",w,$);let q=w.slice(),Y=w[$-1];q[$-1]=Y&-129;let z=ft(q);z===ht||(C?y(z,l):y(z,t.ORDER));let j=u(z*z),ae=u(j-Ze),se=u(T*j-N),{isValid:Ie,value:Te}=f(ae,se);if(!Ie)throw new Error("Point.fromHex: invalid y coordinate");let ve=(Te&Ze)===Ze,Oe=(Y&128)!==0;if(!C&&Te===ht&&Oe)throw new Error("Point.fromHex: x=0 and x_0=1");return Oe!==ve&&(Te=u(-Te)),x.fromAffine({x:Te,y:z})}static fromPrivateKey(w){return R(w).point}toRawBytes(){let{x:w,y:C}=this.toAffine(),T=Ot(C,t.BYTES);return T[T.length-1]|=w&Ze?128:0,T}toHex(){return Lt(this.toRawBytes())}}x.BASE=new x(e.Gx,e.Gy,Ze,u(e.Gx*e.Gy)),x.ZERO=new x(ht,Ze,Ze,ht);let{BASE:D,ZERO:A}=x,S=vs(x,a*8);function _(k){return te(k,n)}function O(k){return _(ft(k))}function R(k){let w=a;k=ce("private key",k,w);let C=ce("hashed private key",s(k),2*w),T=g(C.slice(0,w)),N=C.slice(w,2*w),$=O(T),q=D.multiply($),Y=q.toRawBytes();return{head:T,prefix:N,scalar:$,point:q,pointBytes:Y}}function H(k){return R(k).pointBytes}function V(k=new Uint8Array,...w){let C=Pt(...w);return O(s(m(C,ce("context",k),!!o)))}function G(k,w,C={}){k=ce("message",k),o&&(k=o(k));let{prefix:T,scalar:N,pointBytes:$}=R(w),q=V(C.context,T,k),Y=D.multiply(q).toRawBytes(),z=V(C.context,Y,$,k),j=_(q+z*N);E(j);let ae=Pt(Y,Ot(j,t.BYTES));return ce("result",ae,a*2)}let B=Ey;function I(k,w,C,T=B){let{context:N,zip215:$}=T,q=t.BYTES;k=ce("signature",k,2*q),w=ce("message",w),o&&(w=o(w));let Y=ft(k.slice(q,2*q)),z,j,ae;try{z=x.fromHex(C,$),j=x.fromHex(k.slice(0,q),$),ae=D.multiplyUnsafe(Y)}catch{return!1}if(!$&&z.isSmallOrder())return!1;let se=V(N,j.toRawBytes(),z.toRawBytes(),w);return j.add(z.multiplyUnsafe(se)).subtract(ae).clearCofactor().equals(x.ZERO)}return D._setWindowSize(8),{CURVE:e,getPublicKey:H,sign:G,verify:I,ExtendedPoint:x,utils:{getExtendedPublicKey:R,randomPrivateKey:()=>i(t.BYTES),precompute(k=8,w=x.BASE){return w._setWindowSize(k),w.multiply(BigInt(3)),w}}}}var Xn=BigInt(0),Ic=BigInt(1);function Ay(r){return et(r,{a:"bigint"},{montgomeryBits:"isSafeInteger",nByteLength:"isSafeInteger",adjustScalarBytes:"function",domain:"function",powPminus2:"function",Gu:"bigint"}),Object.freeze({...r})}function ih(r){let e=Ay(r),{P:t}=e,n=b=>te(b,t),o=e.montgomeryBits,s=Math.ceil(o/8),i=e.nByteLength,a=e.adjustScalarBytes||(b=>b),c=e.powPminus2||(b=>Dc(b,t-BigInt(2),t));function l(b,v,x){let D=n(b*(v-x));return v=n(v-D),x=n(x+D),[v,x]}function u(b){if(typeof b=="bigint"&&Xn<=b&&b<t)return b;throw new Error("Expected valid scalar 0 < scalar < CURVE.P")}let f=(e.a-BigInt(2))/BigInt(4);function g(b,v){let x=u(b),D=u(v),A=x,S=Ic,_=Xn,O=x,R=Ic,H=Xn,V;for(let B=BigInt(o-1);B>=Xn;B--){let I=D>>B&Ic;H^=I,V=l(H,S,O),S=V[0],O=V[1],V=l(H,_,R),_=V[0],R=V[1],H=I;let P=S+_,k=n(P*P),w=S-_,C=n(w*w),T=k-C,N=O+R,$=O-R,q=n($*P),Y=n(N*w),z=q+Y,j=q-Y;O=n(z*z),R=n(A*n(j*j)),S=n(k*C),_=n(T*(k+n(f*T)))}V=l(H,S,O),S=V[0],O=V[1],V=l(H,_,R),_=V[0],R=V[1];let G=c(_);return n(S*G)}function m(b){return Ot(n(b),s)}function d(b){let v=ce("u coordinate",b,s);return i===32&&(v[31]&=127),ft(v)}function h(b){let v=ce("scalar",b),x=v.length;if(x!==s&&x!==i)throw new Error(`Expected ${s} or ${i} bytes, got ${x}`);return ft(a(v))}function p(b,v){let x=d(v),D=h(b),A=g(x,D);if(A===Xn)throw new Error("Invalid private or public key received");return m(A)}let y=m(e.Gu);function E(b){return p(b,y)}return{scalarMult:p,scalarMultBase:E,getSharedSecret:(b,v)=>p(b,v),getPublicKey:b=>E(b),utils:{randomPrivateKey:()=>e.randomBytes(e.nByteLength)},GuBytes:y}}var Jn=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),ah=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),c4=BigInt(0),Dy=BigInt(1),ch=BigInt(2),Sy=BigInt(3),By=BigInt(5),ky=BigInt(8);function lh(r){let e=BigInt(10),t=BigInt(20),n=BigInt(40),o=BigInt(80),s=Jn,a=r*r%s*r%s,c=le(a,ch,s)*a%s,l=le(c,Dy,s)*r%s,u=le(l,By,s)*l%s,f=le(u,e,s)*u%s,g=le(f,t,s)*f%s,m=le(g,n,s)*g%s,d=le(m,o,s)*m%s,h=le(d,o,s)*m%s,p=le(h,e,s)*u%s;return{pow_p_5_8:le(p,ch,s)*r%s,b2:a}}function uh(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Cy(r,e){let t=Jn,n=te(e*e*e,t),o=te(n*n*e,t),s=lh(r*o).pow_p_5_8,i=te(r*n*s,t),a=te(e*i*i,t),c=i,l=te(i*ah,t),u=a===r,f=a===te(-r,t),g=a===te(-r*ah,t);return u&&(i=c),(f||g)&&(i=l),rh(i,t)&&(i=te(-i,t)),{isValid:u||f,value:i}}var Iy=Es(Jn,void 0,!0),Ty={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Iy,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:ky,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:jn,randomBytes:Tr,adjustScalarBytes:uh,uvRatio:Cy},un=sh(Ty);var Qn=ih({P:Jn,a:BigInt(486662),montgomeryBits:255,nByteLength:32,Gu:BigInt(9),powPminus2:r=>{let e=Jn,{pow_p_5_8:t,b2:n}=lh(r);return te(le(t,Sy,e)*n,e)},adjustScalarBytes:uh,randomBytes:Tr});var fn=32,Mt=64,Ds=32;function fh(){let r=un.utils.randomPrivateKey(),e=un.getPublicKey(r);return{privateKey:mh(r,e),publicKey:e}}function hh(r){if(r.length!==Ds)throw new TypeError('"seed" must be 32 bytes in length.');if(!(r instanceof Uint8Array))throw new TypeError('"seed" must be a node.js Buffer, or Uint8Array.');let e=r,t=un.getPublicKey(e);return{privateKey:mh(e,t),publicKey:t}}function dh(r,e){let t=r.subarray(0,Ds);return un.sign(e instanceof Uint8Array?e:e.subarray(),t)}function ph(r,e,t){return un.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}function mh(r,e){let t=new Uint8Array(Mt);for(let n=0;n<Ds;n++)t[n]=r[n],t[Ds+n]=e[n];return t}var Ve={get(r=globalThis){let e=r.crypto;if(e==null||e.subtle==null)throw Object.assign(new Error("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api"),{code:"ERR_MISSING_WEB_CRYPTO"});return e}};var Tc={alg:"A128GCM",ext:!0,k:"scm9jmO_4BJAgdwWGVulLg",key_ops:["encrypt","decrypt"],kty:"oct"};function gh(r){let e=r?.algorithm??"AES-GCM",t=r?.keyLength??16,n=r?.nonceLength??12,o=r?.digest??"SHA-256",s=r?.saltLength??16,i=r?.iterations??32767,a=Ve.get();t*=8;async function c(f,g){let m=a.getRandomValues(new Uint8Array(s)),d=a.getRandomValues(new Uint8Array(n)),h={name:e,iv:d};typeof g=="string"&&(g=J(g));let p;if(g.length===0){p=await a.subtle.importKey("jwk",Tc,{name:"AES-GCM"},!0,["encrypt"]);try{let E={name:"PBKDF2",salt:m,iterations:i,hash:{name:o}},b=await a.subtle.importKey("raw",g,{name:"PBKDF2"},!1,["deriveKey"]);p=await a.subtle.deriveKey(E,b,{name:e,length:t},!0,["encrypt"])}catch{p=await a.subtle.importKey("jwk",Tc,{name:"AES-GCM"},!0,["encrypt"])}}else{let E={name:"PBKDF2",salt:m,iterations:i,hash:{name:o}},b=await a.subtle.importKey("raw",g,{name:"PBKDF2"},!1,["deriveKey"]);p=await a.subtle.deriveKey(E,b,{name:e,length:t},!0,["encrypt"])}let y=await a.subtle.encrypt(h,p,f);return xe([m,h.iv,new Uint8Array(y)])}async function l(f,g){let m=f.subarray(0,s),d=f.subarray(s,s+n),h=f.subarray(s+n),p={name:e,iv:d};typeof g=="string"&&(g=J(g));let y;if(g.length===0)try{let b={name:"PBKDF2",salt:m,iterations:i,hash:{name:o}},v=await a.subtle.importKey("raw",g,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(b,v,{name:e,length:t},!0,["decrypt"])}catch{y=await a.subtle.importKey("jwk",Tc,{name:"AES-GCM"},!0,["decrypt"])}else{let b={name:"PBKDF2",salt:m,iterations:i,hash:{name:o}},v=await a.subtle.importKey("raw",g,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(b,v,{name:e,length:t},!0,["decrypt"])}let E=await a.subtle.decrypt(p,y,h);return new Uint8Array(E)}return{encrypt:c,decrypt:l}}async function hn(r,e){let n=await gh().encrypt(r,e);return Zi.encode(n)}var he;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.Secp256k1="Secp256k1"})(he||(he={}));var _c;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.Secp256k1=2]="Secp256k1"})(_c||(_c={}));(function(r){r.codec=()=>Sr(_c)})(he||(he={}));var Et;(function(r){let e;r.codec=()=>(e==null&&(e=ct((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),he.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let o={},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let i=t.uint32();switch(i>>>3){case 1:o.Type=he.codec().decode(t);break;case 2:o.Data=t.bytes();break;default:t.skipType(i&7);break}}return o})),e),r.encode=t=>at(t,r.codec()),r.decode=t=>it(t,r.codec())})(Et||(Et={}));var vt;(function(r){let e;r.codec=()=>(e==null&&(e=ct((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),he.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let o={},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let i=t.uint32();switch(i>>>3){case 1:o.Type=he.codec().decode(t);break;case 2:o.Data=t.bytes();break;default:t.skipType(i&7);break}}return o})),e),r.encode=t=>at(t,r.codec()),r.decode=t=>it(t,r.codec())})(vt||(vt={}));var eo=class{_key;constructor(e){this._key=dn(e,fn)}verify(e,t){return ph(this._key,t,e)}marshal(){return this._key}get bytes(){return Et.encode({Type:he.Ed25519,Data:this.marshal()}).subarray()}equals(e){return Ae(this.bytes,e.bytes)}hash(){let e=_e.digest(this.bytes);return Qe(e)?e.then(({bytes:t})=>t):e.bytes}},Nr=class{_key;_publicKey;constructor(e,t){this._key=dn(e,Mt),this._publicKey=dn(t,fn)}sign(e){return dh(this._key,e)}get public(){return new eo(this._publicKey)}marshal(){return this._key}get bytes(){return vt.encode({Type:he.Ed25519,Data:this.marshal()}).subarray()}equals(e){return Ae(this.bytes,e.bytes)}async hash(){let e=_e.digest(this.bytes),t;return Qe(e)?{bytes:t}=await e:t=e.bytes,t}async id(){let e=Tt.digest(this.public.bytes);return ge.encode(e.bytes).substring(1)}async export(e,t="libp2p-key"){if(t==="libp2p-key")return hn(this.bytes,e);throw new L(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function Ny(r){if(r.length>Mt){r=dn(r,Mt+fn);let n=r.subarray(0,Mt),o=r.subarray(Mt,r.length);return new Nr(n,o)}r=dn(r,Mt);let e=r.subarray(0,Mt),t=r.subarray(fn);return new Nr(e,t)}function Ly(r){return r=dn(r,fn),new eo(r)}async function Uy(){let{privateKey:r,publicKey:e}=fh();return new Nr(r,e)}async function bh(r){let{privateKey:e,publicKey:t}=hh(r);return new Nr(e,t)}function dn(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new L(`Key must be a Uint8Array of length ${e}, got ${r.length}`,"ERR_INVALID_KEY_TYPE");return r}var Kc={};Q(Kc,{MAX_RSA_KEY_SIZE:()=>fo,RsaPrivateKey:()=>yn,RsaPublicKey:()=>uo,fromJwk:()=>cw,generateKeyPair:()=>lw,unmarshalRsaPrivateKey:()=>Vc,unmarshalRsaPublicKey:()=>aw});function Lr(r){if(isNaN(r)||r<=0)throw new L("random bytes length must be a Number bigger than 0","ERR_INVALID_LENGTH");return Tr(r)}var ur={};Q(ur,{exportToPem:()=>rw,importFromPem:()=>nw,jwkToPkcs1:()=>Jy,jwkToPkix:()=>ew,pkcs1ToJwk:()=>Xy,pkixToJwk:()=>Qy});var Bs=class extends sn{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,Ir(e);let n=ut(t);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?e.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=e.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),s.fill(0)}update(e){return on(this),this.iHash.update(e),this}digestInto(e){on(this),nn(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:t,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=a,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},ir=(r,e,t)=>new Bs(r,e).update(t).digest();ir.create=(r,e)=>new Bs(r,e);function Oy(r,e,t,n){Ir(r);let o=zf({dkLen:32,asyncTick:10},n),{c:s,dkLen:i,asyncTick:a}=o;if(tr(s),tr(i),tr(a),s<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let c=ut(e),l=ut(t),u=new Uint8Array(i),f=ir.create(r,c),g=f._cloneInto().update(l);return{c:s,dkLen:i,asyncTick:a,DK:u,PRF:f,PRFSalt:g}}function Py(r,e,t,n,o){return r.destroy(),e.destroy(),n&&n.destroy(),o.fill(0),t}async function Nc(r,e,t,n){let{c:o,dkLen:s,asyncTick:i,DK:a,PRF:c,PRFSalt:l}=Oy(r,e,t,n),u,f=new Uint8Array(4),g=an(f),m=new Uint8Array(c.outputLen);for(let d=1,h=0;h<s;d++,h+=c.outputLen){let p=a.subarray(h,h+c.outputLen);g.setInt32(0,d,!1),(u=l._cloneInto(u)).update(f).digestInto(m),p.set(m.subarray(0,p.length)),await qf(o-1,i,()=>{c._cloneInto(u).update(m).digestInto(m);for(let y=0;y<p.length;y++)p[y]^=m[y]})}return Py(c,l,a,u,m)}var X=ko(yh());function Ur(r,e){let t=0;if(r.length===1)return r[0];for(let n=r.length-1;n>=0;n--)t+=r[r.length-1-n]*Math.pow(2,e*n);return t}function ar(r,e,t=-1){let n=t,o=r,s=0,i=Math.pow(2,e);for(let a=1;a<8;a++){if(r<i){let c;if(n<0)c=new ArrayBuffer(a),s=a;else{if(n<a)return new ArrayBuffer(0);c=new ArrayBuffer(n),s=n}let l=new Uint8Array(c);for(let u=a-1;u>=0;u--){let f=Math.pow(2,u*e);l[s-u-1]=Math.floor(o/f),o-=l[s-u-1]*f}return c}i*=Math.pow(2,e)}return new ArrayBuffer(0)}function Is(...r){let e=0,t=0;for(let s of r)e+=s.length;let n=new ArrayBuffer(e),o=new Uint8Array(n);for(let s of r)o.set(s,t),t+=s.length;return o}function Uc(){let r=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){let a=r[0]===255&&r[1]&128,c=r[0]===0&&(r[1]&128)===0;(a||c)&&this.warnings.push("Needlessly long format")}let e=new ArrayBuffer(this.valueHex.byteLength),t=new Uint8Array(e);for(let a=0;a<this.valueHex.byteLength;a++)t[a]=0;t[0]=r[0]&128;let n=Ur(t,8),o=new ArrayBuffer(this.valueHex.byteLength),s=new Uint8Array(o);for(let a=0;a<this.valueHex.byteLength;a++)s[a]=r[a];return s[0]&=127,Ur(s,8)-n}function wh(r){let e=r<0?r*-1:r,t=128;for(let n=1;n<8;n++){if(e<=t){if(r<0){let i=t-e,a=ar(i,8,n),c=new Uint8Array(a);return c[0]|=128,a}let o=ar(e,8,n),s=new Uint8Array(o);if(s[0]&128){let i=o.slice(0),a=new Uint8Array(i);o=new ArrayBuffer(o.byteLength+1),s=new Uint8Array(o);for(let c=0;c<i.byteLength;c++)s[c+1]=a[c];s[0]=0}return o}t*=Math.pow(2,8)}return new ArrayBuffer(0)}function xh(r,e){if(r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let o=0;o<t.length;o++)if(t[o]!==n[o])return!1;return!0}function We(r,e){let t=r.toString(10);if(e<t.length)return"";let n=e-t.length,o=new Array(n);for(let i=0;i<n;i++)o[i]="0";return o.join("").concat(t)}var O4=Math.log(2);function Ts(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function Oc(r){let e=0,t=0;for(let o=0;o<r.length;o++){let s=r[o];e+=s.byteLength}let n=new Uint8Array(e);for(let o=0;o<r.length;o++){let s=r[o];n.set(new Uint8Array(s),t),t+=s.byteLength}return n.buffer}function $t(r,e,t,n){return e instanceof Uint8Array?e.byteLength?t<0?(r.error="Wrong parameter: inputOffset less than zero",!1):n<0?(r.error="Wrong parameter: inputLength less than zero",!1):e.byteLength-t-n<0?(r.error="End of input reached before message was fully decoded (inconsistent offset and length values)",!1):!0:(r.error="Wrong parameter: inputBuffer has zero length",!1):(r.error="Wrong parameter: inputBuffer must be 'Uint8Array'",!1)}var ro=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return Oc(this.items)}},to=[new Uint8Array([1])],Eh="0123456789";var gn="",pt=new ArrayBuffer(0),Pc=new Uint8Array(0),no="EndOfContent",Ah="OCTET STRING",Dh="BIT STRING";function qt(r){var e;return e=class extends r{constructor(...n){var o;super(...n);let s=n[0]||{};this.isHexOnly=(o=s.isHexOnly)!==null&&o!==void 0?o:!1,this.valueHexView=s.valueHex?X.BufferSourceConverter.toUint8Array(s.valueHex):Pc}get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}fromBER(n,o,s){let i=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!$t(this,i,o,s))return-1;let a=o+s;return this.valueHexView=i.subarray(o,a),this.valueHexView.length?(this.blockLength=s,a):(this.warnings.push("Zero buffer length"),o)}toBER(n=!1){return this.isHexOnly?n?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.byteLength===this.valueHexView.buffer.byteLength?this.valueHexView.buffer:this.valueHexView.slice().buffer:(this.error="Flag 'isHexOnly' is not set, abort",pt)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:X.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var Vt=class{constructor({blockLength:e=0,error:t=gn,warnings:n=[],valueBeforeDecode:o=Pc}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=X.BufferSourceConverter.toUint8Array(o)}static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(e){this.valueBeforeDecodeView=new Uint8Array(e)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:X.Convert.ToHex(this.valueBeforeDecodeView)}}};Vt.NAME="baseBlock";var Fe=class extends Vt{fromBER(e,t,n){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}toBER(e,t){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}};Fe.NAME="valueBlock";var _s=class extends qt(Vt){constructor({idBlock:e={}}={}){var t,n,o,s;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?X.BufferSourceConverter.toUint8Array(e.valueHex):Pc,this.tagClass=(n=e.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(o=e.tagNumber)!==null&&o!==void 0?o:-1,this.isConstructed=(s=e.isConstructed)!==null&&s!==void 0?s:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(e=!1){let t=0;switch(this.tagClass){case 1:t|=0;break;case 2:t|=64;break;case 3:t|=128;break;case 4:t|=192;break;default:return this.error="Unknown tag class",pt}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){let o=new Uint8Array(1);if(!e){let s=this.tagNumber;s&=31,t|=s,o[0]=t}return o.buffer}if(!this.isHexOnly){let o=ar(this.tagNumber,7),s=new Uint8Array(o),i=o.byteLength,a=new Uint8Array(i+1);if(a[0]=t|31,!e){for(let c=0;c<i-1;c++)a[c+1]=s[c]|128;a[i]=s[i-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=t|31,!e){let o=this.valueHexView;for(let s=0;s<o.length-1;s++)n[s+1]=o[s]|128;n[this.valueHexView.byteLength]=o[o.length-1]}return n.buffer}fromBER(e,t,n){let o=X.BufferSourceConverter.toUint8Array(e);if(!$t(this,o,t,n))return-1;let s=o.subarray(t,t+n);if(s.length===0)return this.error="Zero buffer length",-1;switch(s[0]&192){case 0:this.tagClass=1;break;case 64:this.tagClass=2;break;case 128:this.tagClass=3;break;case 192:this.tagClass=4;break;default:return this.error="Unknown tag class",-1}this.isConstructed=(s[0]&32)===32,this.isHexOnly=!1;let a=s[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=1,l=this.valueHexView=new Uint8Array(255),u=255;for(;s[c]&128;){if(l[c-1]=s[c]&127,c++,c>=s.length)return this.error="End of input reached before message was fully decoded",-1;if(c===u){u+=255;let g=new Uint8Array(u);for(let m=0;m<l.length;m++)g[m]=l[m];l=this.valueHexView=new Uint8Array(u)}}this.blockLength=c+1,l[c-1]=s[c]&127;let f=new Uint8Array(c);for(let g=0;g<c;g++)f[g]=l[g];l=this.valueHexView=new Uint8Array(c),l.set(f),this.blockLength<=9?this.tagNumber=Ur(l,7):(this.isHexOnly=!0,this.warnings.push("Tag too long, represented as hex-coded"))}if(this.tagClass===1&&this.isConstructed)switch(this.tagNumber){case 1:case 2:case 5:case 6:case 9:case 13:case 14:case 23:case 24:case 31:case 32:case 33:case 34:return this.error="Constructed encoding used for primitive type",-1}return t+this.blockLength}toJSON(){return{...super.toJSON(),tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed}}};_s.NAME="identificationBlock";var Rs=class extends Vt{constructor({lenBlock:e={}}={}){var t,n,o;super(),this.isIndefiniteForm=(t=e.isIndefiniteForm)!==null&&t!==void 0?t:!1,this.longFormUsed=(n=e.longFormUsed)!==null&&n!==void 0?n:!1,this.length=(o=e.length)!==null&&o!==void 0?o:0}fromBER(e,t,n){let o=X.BufferSourceConverter.toUint8Array(e);if(!$t(this,o,t,n))return-1;let s=o.subarray(t,t+n);if(s.length===0)return this.error="Zero buffer length",-1;if(s[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=s[0]===128,this.isIndefiniteForm)return this.blockLength=1,t+this.blockLength;if(this.longFormUsed=!!(s[0]&128),this.longFormUsed===!1)return this.length=s[0],this.blockLength=1,t+this.blockLength;let i=s[0]&127;if(i>8)return this.error="Too big integer",-1;if(i+1>s.length)return this.error="End of input reached before message was fully decoded",-1;let a=t+1,c=o.subarray(a,a+i);return c[i-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=Ur(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=i+1,t+this.blockLength}toBER(e=!1){let t,n;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=128),t;if(this.longFormUsed){let o=ar(this.length,8);if(o.byteLength>127)return this.error="Too big length",pt;if(t=new ArrayBuffer(o.byteLength+1),e)return t;let s=new Uint8Array(o);n=new Uint8Array(t),n[0]=o.byteLength|128;for(let i=0;i<o.byteLength;i++)n[i+1]=s[i];return t}return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=this.length),t}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}};Rs.NAME="lengthBlock";var M={},Ne=class extends Vt{constructor({name:e=gn,optional:t=!1,primitiveSchema:n,...o}={},s){super(o),this.name=e,this.optional=t,n&&(this.primitiveSchema=n),this.idBlock=new _s(o),this.lenBlock=new Rs(o),this.valueBlock=s?new s(o):new Fe(o)}fromBER(e,t,n){let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),o)}toBER(e,t){let n=t||new ro;t||Sh(this);let o=this.idBlock.toBER(e);if(n.write(o),this.lenBlock.isIndefiniteForm)n.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,n),n.write(new ArrayBuffer(2));else{let s=this.valueBlock.toBER(e);this.lenBlock.length=s.byteLength;let i=this.lenBlock.toBER(e);n.write(i),n.write(s)}return t?pt:n.final()}toJSON(){let e={...super.toJSON(),idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional};return this.primitiveSchema&&(e.primitiveSchema=this.primitiveSchema.toJSON()),e}toString(e="ascii"){return e==="ascii"?this.onAsciiEncoding():X.Convert.ToHex(this.toBER())}onAsciiEncoding(){return`${this.constructor.NAME} : ${X.Convert.ToHex(this.valueBlock.valueBeforeDecodeView)}`}isEqual(e){if(this===e)return!0;if(!(e instanceof this.constructor))return!1;let t=this.toBER(),n=e.toBER();return xh(t,n)}};Ne.NAME="BaseBlock";function Sh(r){if(r instanceof M.Constructed)for(let e of r.valueBlock.value)Sh(e)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var Ns=class extends Ne{constructor({value:e=gn,...t}={},n){super(t,n),e&&this.fromString(e)}getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}fromBER(e,t,n){let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(this.fromBuffer(this.valueBlock.valueHexView),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),o)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}};Ns.NAME="BaseStringBlock";var Ls=class extends qt(Fe){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};Ls.NAME="PrimitiveValueBlock";var Bh,Us=class extends Ne{constructor(e={}){super(e,Ls),this.idBlock.isConstructed=!1}};Bh=Us;M.Primitive=Bh;Us.NAME="PRIMITIVE";function zy(r,e){if(r instanceof e)return r;let t=new e;return t.idBlock=r.idBlock,t.lenBlock=r.lenBlock,t.warnings=r.warnings,t.valueBeforeDecodeView=r.valueBeforeDecodeView,t}function pi(r,e=0,t=r.length){let n=e,o=new Ne({},Fe),s=new Vt;if(!$t(s,r,e,t))return o.error=s.error,{offset:-1,result:o};if(!r.subarray(e,e+t).length)return o.error="Zero buffer length",{offset:-1,result:o};let a=o.idBlock.fromBER(r,e,t);if(o.idBlock.warnings.length&&o.warnings.concat(o.idBlock.warnings),a===-1)return o.error=o.idBlock.error,{offset:-1,result:o};if(e=a,t-=o.idBlock.blockLength,a=o.lenBlock.fromBER(r,e,t),o.lenBlock.warnings.length&&o.warnings.concat(o.lenBlock.warnings),a===-1)return o.error=o.lenBlock.error,{offset:-1,result:o};if(e=a,t-=o.lenBlock.blockLength,!o.idBlock.isConstructed&&o.lenBlock.isIndefiniteForm)return o.error="Indefinite length form used for primitive encoding form",{offset:-1,result:o};let c=Ne;switch(o.idBlock.tagClass){case 1:if(o.idBlock.tagNumber>=37&&o.idBlock.isHexOnly===!1)return o.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:o};switch(o.idBlock.tagNumber){case 0:if(o.idBlock.isConstructed&&o.lenBlock.length>0)return o.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:o};c=M.EndOfContent;break;case 1:c=M.Boolean;break;case 2:c=M.Integer;break;case 3:c=M.BitString;break;case 4:c=M.OctetString;break;case 5:c=M.Null;break;case 6:c=M.ObjectIdentifier;break;case 10:c=M.Enumerated;break;case 12:c=M.Utf8String;break;case 13:c=M.RelativeObjectIdentifier;break;case 14:c=M.TIME;break;case 15:return o.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:o};case 16:c=M.Sequence;break;case 17:c=M.Set;break;case 18:c=M.NumericString;break;case 19:c=M.PrintableString;break;case 20:c=M.TeletexString;break;case 21:c=M.VideotexString;break;case 22:c=M.IA5String;break;case 23:c=M.UTCTime;break;case 24:c=M.GeneralizedTime;break;case 25:c=M.GraphicString;break;case 26:c=M.VisibleString;break;case 27:c=M.GeneralString;break;case 28:c=M.UniversalString;break;case 29:c=M.CharacterString;break;case 30:c=M.BmpString;break;case 31:c=M.DATE;break;case 32:c=M.TimeOfDay;break;case 33:c=M.DateTime;break;case 34:c=M.Duration;break;default:{let l=o.idBlock.isConstructed?new M.Constructed:new M.Primitive;l.idBlock=o.idBlock,l.lenBlock=o.lenBlock,l.warnings=o.warnings,o=l}}break;case 2:case 3:case 4:default:c=o.idBlock.isConstructed?M.Constructed:M.Primitive}return o=zy(o,c),a=o.fromBER(r,e,o.lenBlock.isIndefiniteForm?t:o.lenBlock.length),o.valueBeforeDecodeView=r.subarray(n,n+o.blockLength),{offset:a,result:o}}function bn(r){if(!r.byteLength){let e=new Ne({},Fe);return e.error="Input buffer has zero length",{offset:-1,result:e}}return pi(X.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function Gy(r,e){return r?1:e}var At=class extends Fe{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let o=X.BufferSourceConverter.toUint8Array(e);if(!$t(this,o,t,n))return-1;if(this.valueBeforeDecodeView=o.subarray(t,t+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),t;let s=t;for(;Gy(this.isIndefiniteForm,n)>0;){let i=pi(o,s,n);if(i.offset===-1)return this.error=i.result.error,this.warnings.concat(i.result.warnings),-1;if(s=i.offset,this.blockLength+=i.result.blockLength,n-=i.result.blockLength,this.value.push(i.result),this.isIndefiniteForm&&i.result.constructor.NAME===no)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===no?this.value.pop():this.warnings.push("No EndOfContent block encoded")),s}toBER(e,t){let n=t||new ro;for(let o=0;o<this.value.length;o++)this.value[o].toBER(e,n);return t?pt:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};At.NAME="ConstructedValueBlock";var kh,cr=class extends Ne{constructor(e={}){super(e,At),this.idBlock.isConstructed=!0}fromBER(e,t,n){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),o)}onAsciiEncoding(){let e=[];for(let n of this.valueBlock.value)e.push(n.toString("ascii").split(`
17
17
  `).map(o=>` ${o}`).join(`
18
18
  `));let t=this.idBlock.tagClass===3?`[${this.idBlock.tagNumber}]`:this.constructor.NAME;return e.length?`${t} :
19
19
  ${e.join(`
@@ -1,5 +1,8 @@
1
1
  /**
2
- * STUN servers help clients discover their own public IPs
2
+ * STUN servers help clients discover their own public IPs.
3
+ *
4
+ * Using five or more servers causes warnings to be printed so
5
+ * ensure we limit it to max x4
3
6
  *
4
7
  * @see https://gist.github.com/mondain/b0ec1cf5f60ae726202e
5
8
  */
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,UAU/B,CAAA"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,UAK/B,CAAA"}
@@ -1,17 +1,15 @@
1
1
  /**
2
- * STUN servers help clients discover their own public IPs
2
+ * STUN servers help clients discover their own public IPs.
3
+ *
4
+ * Using five or more servers causes warnings to be printed so
5
+ * ensure we limit it to max x4
3
6
  *
4
7
  * @see https://gist.github.com/mondain/b0ec1cf5f60ae726202e
5
8
  */
6
9
  export const DEFAULT_ICE_SERVERS = [
7
10
  'stun:stun.l.google.com:19302',
8
- 'stun:stun1.l.google.com:19302',
9
- 'stun:stun2.l.google.com:19302',
10
- 'stun:stun3.l.google.com:19302',
11
- 'stun:stun4.l.google.com:19302',
12
11
  'stun:global.stun.twilio.com:3478',
13
12
  'stun:stun.cloudflare.com:3478',
14
- 'stun:stun.services.mozilla.com:3478',
15
- 'stun:stun.1und1.de:3478'
13
+ 'stun:stun.services.mozilla.com:3478'
16
14
  ];
17
15
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,8BAA8B;IAC9B,+BAA+B;IAC/B,+BAA+B;IAC/B,+BAA+B;IAC/B,+BAA+B;IAC/B,kCAAkC;IAClC,+BAA+B;IAC/B,qCAAqC;IACrC,yBAAyB;CAC1B,CAAA"}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,8BAA8B;IAC9B,kCAAkC;IAClC,+BAA+B;IAC/B,qCAAqC;CACtC,CAAA"}
@@ -1,8 +1,8 @@
1
1
  import { serviceCapabilities, serviceDependencies, transportSymbol } from '@libp2p/interface';
2
2
  import { type Multiaddr } from '@multiformats/multiaddr';
3
3
  import type { DataChannelOptions } from '../index.js';
4
- import type { OutboundConnectionUpgradeEvents, CreateListenerOptions, DialOptions, Transport, Listener, Upgrader, ComponentLogger, Connection, PeerId, CounterGroup, Metrics, Startable } from '@libp2p/interface';
5
- import type { IncomingStreamData, Registrar, ConnectionManager, TransportManager, OpenConnectionProgressEvents } from '@libp2p/interface-internal';
4
+ import type { OutboundConnectionUpgradeEvents, CreateListenerOptions, DialTransportOptions, Transport, Listener, Upgrader, ComponentLogger, Connection, PeerId, CounterGroup, Metrics, Startable, OpenConnectionProgressEvents } from '@libp2p/interface';
5
+ import type { IncomingStreamData, Registrar, ConnectionManager, TransportManager } from '@libp2p/interface-internal';
6
6
  import type { ProgressEvent } from 'progress-events';
7
7
  export declare const SIGNALING_PROTO_ID = "/webrtc-signaling/0.0.1";
8
8
  export interface WebRTCTransportInit {
@@ -52,7 +52,7 @@ export declare class WebRTCTransport implements Transport<WebRTCDialEvents>, Sta
52
52
  * Filter check for all Multiaddrs that this transport can dial
53
53
  */
54
54
  dialFilter(multiaddrs: Multiaddr[]): Multiaddr[];
55
- dial(ma: Multiaddr, options: DialOptions<WebRTCDialEvents>): Promise<Connection>;
55
+ dial(ma: Multiaddr, options: DialTransportOptions<WebRTCDialEvents>): Promise<Connection>;
56
56
  _onProtocol({ connection, stream }: IncomingStreamData): Promise<void>;
57
57
  private _closeOnShutdown;
58
58
  }
@@ -1 +1 @@
1
- {"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../../src/private-to-private/transport.ts"],"names":[],"mappings":"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"}
1
+ {"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../../src/private-to-private/transport.ts"],"names":[],"mappings":"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"}
@@ -1 +1 @@
1
- {"version":3,"file":"transport.js","sourceRoot":"","sources":["../../../src/private-to-private/transport.ts"],"names":[],"mappings":"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"}
1
+ {"version":3,"file":"transport.js","sourceRoot":"","sources":["../../../src/private-to-private/transport.ts"],"names":[],"mappings":"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"}
@@ -1,6 +1,6 @@
1
- import type { CreateListenerOptions, DialOptions } from '@libp2p/interface';
1
+ import type { CreateListenerOptions, DialTransportOptions } from '@libp2p/interface';
2
2
  export interface WebRTCListenerOptions extends CreateListenerOptions {
3
3
  }
4
- export interface WebRTCDialOptions extends DialOptions {
4
+ export interface WebRTCDialOptions extends DialTransportOptions {
5
5
  }
6
6
  //# sourceMappingURL=options.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../../src/private-to-public/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAE3E,MAAM,WAAW,qBAAsB,SAAQ,qBAAqB;CAAG;AACvE,MAAM,WAAW,iBAAkB,SAAQ,WAAW;CAAG"}
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../../src/private-to-public/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA;AAEpF,MAAM,WAAW,qBAAsB,SAAQ,qBAAqB;CAAG;AACvE,MAAM,WAAW,iBAAkB,SAAQ,oBAAoB;CAAG"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/webrtc",
3
- "version": "4.1.1-151bc46fb",
3
+ "version": "4.1.1-3319ff41e",
4
4
  "description": "A libp2p transport using WebRTC connections",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/transport-webrtc#readme",
@@ -51,10 +51,10 @@
51
51
  },
52
52
  "dependencies": {
53
53
  "@chainsafe/libp2p-noise": "^15.0.0",
54
- "@libp2p/interface": "1.6.0-151bc46fb",
55
- "@libp2p/interface-internal": "1.3.0-151bc46fb",
56
- "@libp2p/peer-id": "4.2.0-151bc46fb",
57
- "@libp2p/utils": "5.4.5-151bc46fb",
54
+ "@libp2p/interface": "1.6.0-3319ff41e",
55
+ "@libp2p/interface-internal": "1.3.0-3319ff41e",
56
+ "@libp2p/peer-id": "4.2.0-3319ff41e",
57
+ "@libp2p/utils": "5.4.5-3319ff41e",
58
58
  "@multiformats/mafmt": "^12.1.6",
59
59
  "@multiformats/multiaddr": "^12.2.3",
60
60
  "@multiformats/multiaddr-matcher": "^1.2.1",
@@ -78,12 +78,12 @@
78
78
  },
79
79
  "devDependencies": {
80
80
  "@chainsafe/libp2p-yamux": "^6.0.2",
81
- "@libp2p/circuit-relay-v2": "1.1.1-151bc46fb",
82
- "@libp2p/identify": "2.1.1-151bc46fb",
83
- "@libp2p/interface-compliance-tests": "5.4.8-151bc46fb",
84
- "@libp2p/logger": "4.0.16-151bc46fb",
85
- "@libp2p/peer-id-factory": "4.2.0-151bc46fb",
86
- "@libp2p/websockets": "8.1.1-151bc46fb",
81
+ "@libp2p/circuit-relay-v2": "1.1.1-3319ff41e",
82
+ "@libp2p/identify": "2.1.1-3319ff41e",
83
+ "@libp2p/interface-compliance-tests": "5.4.8-3319ff41e",
84
+ "@libp2p/logger": "4.0.16-3319ff41e",
85
+ "@libp2p/peer-id-factory": "4.2.0-3319ff41e",
86
+ "@libp2p/websockets": "8.1.1-3319ff41e",
87
87
  "@types/sinon": "^17.0.3",
88
88
  "aegir": "^43.0.1",
89
89
  "delay": "^6.0.0",
@@ -93,7 +93,7 @@
93
93
  "it-pair": "^2.0.6",
94
94
  "it-pipe": "^3.0.1",
95
95
  "it-to-buffer": "^4.0.7",
96
- "libp2p": "1.8.0-151bc46fb",
96
+ "libp2p": "1.8.0-3319ff41e",
97
97
  "p-retry": "^6.2.0",
98
98
  "protons": "^7.5.0",
99
99
  "sinon": "^18.0.0",
package/src/constants.ts CHANGED
@@ -1,16 +1,14 @@
1
1
  /**
2
- * STUN servers help clients discover their own public IPs
2
+ * STUN servers help clients discover their own public IPs.
3
+ *
4
+ * Using five or more servers causes warnings to be printed so
5
+ * ensure we limit it to max x4
3
6
  *
4
7
  * @see https://gist.github.com/mondain/b0ec1cf5f60ae726202e
5
8
  */
6
9
  export const DEFAULT_ICE_SERVERS = [
7
10
  'stun:stun.l.google.com:19302',
8
- 'stun:stun1.l.google.com:19302',
9
- 'stun:stun2.l.google.com:19302',
10
- 'stun:stun3.l.google.com:19302',
11
- 'stun:stun4.l.google.com:19302',
12
11
  'stun:global.stun.twilio.com:3478',
13
12
  'stun:stun.cloudflare.com:3478',
14
- 'stun:stun.services.mozilla.com:3478',
15
- 'stun:stun.1und1.de:3478'
13
+ 'stun:stun.services.mozilla.com:3478'
16
14
  ]
@@ -11,8 +11,8 @@ import { initiateConnection } from './initiate-connection.js'
11
11
  import { WebRTCPeerListener } from './listener.js'
12
12
  import { handleIncomingStream } from './signaling-stream-handler.js'
13
13
  import type { DataChannelOptions } from '../index.js'
14
- import type { OutboundConnectionUpgradeEvents, CreateListenerOptions, DialOptions, Transport, Listener, Upgrader, ComponentLogger, Logger, Connection, PeerId, CounterGroup, Metrics, Startable } from '@libp2p/interface'
15
- import type { IncomingStreamData, Registrar, ConnectionManager, TransportManager, OpenConnectionProgressEvents } from '@libp2p/interface-internal'
14
+ import type { OutboundConnectionUpgradeEvents, CreateListenerOptions, DialTransportOptions, Transport, Listener, Upgrader, ComponentLogger, Logger, Connection, PeerId, CounterGroup, Metrics, Startable, OpenConnectionProgressEvents } from '@libp2p/interface'
15
+ import type { IncomingStreamData, Registrar, ConnectionManager, TransportManager } from '@libp2p/interface-internal'
16
16
  import type { ProgressEvent } from 'progress-events'
17
17
 
18
18
  const WEBRTC_TRANSPORT = '/webrtc'
@@ -145,7 +145,7 @@ export class WebRTCTransport implements Transport<WebRTCDialEvents>, Startable {
145
145
  * For a circuit relay, this will be of the form
146
146
  * <relay address>/p2p/<relay-peer>/p2p-circuit/webrtc/p2p/<destination-peer>
147
147
  */
148
- async dial (ma: Multiaddr, options: DialOptions<WebRTCDialEvents>): Promise<Connection> {
148
+ async dial (ma: Multiaddr, options: DialTransportOptions<WebRTCDialEvents>): Promise<Connection> {
149
149
  this.log.trace('dialing address: %a', ma)
150
150
 
151
151
  const { remoteAddress, peerConnection, muxerFactory } = await initiateConnection({
@@ -1,4 +1,4 @@
1
- import type { CreateListenerOptions, DialOptions } from '@libp2p/interface'
1
+ import type { CreateListenerOptions, DialTransportOptions } from '@libp2p/interface'
2
2
 
3
3
  export interface WebRTCListenerOptions extends CreateListenerOptions {}
4
- export interface WebRTCDialOptions extends DialOptions {}
4
+ export interface WebRTCDialOptions extends DialTransportOptions {}