@libp2p/webrtc 4.0.20-28e51652a → 4.0.20-83ef3717e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js
CHANGED
|
@@ -13,7 +13,7 @@ if (cid) {
|
|
|
13
13
|
// Make sure to use cid instead of value
|
|
14
14
|
doSomethingWithCID(cid)
|
|
15
15
|
}
|
|
16
|
-
`});var ip=te(()=>{op();ki();fr();Lu();xs()});var Pu,jk,ap=te(()=>{L0();U0();O0();P0();M0();Bu();F0();Cu();V0();K0();X0();ep();tp();rp();ip();Pu={...wu,...xu,...Eu,...vu,...Au,...Du,...Su,...ku,...Iu,...Tu},jk={...Uu,...Ou}});function In(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}var _i=te(()=>{});function Ri(r=0){return globalThis.Buffer!=null&&globalThis.Buffer.allocUnsafe!=null?In(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}var Mu=te(()=>{_i()});function up(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var cp,Fu,P2,Ni,Vu=te(()=>{ap();Mu();cp=up("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Fu=up("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=Ri(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),P2={utf8:cp,"utf-8":cp,hex:Pu.base16,latin1:Fu,ascii:Fu,binary:Fu,...Pu},Ni=P2});var lp={};J(lp,{toString:()=>M2});function M2(r,e="utf8"){let t=Ni[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 fp=te(()=>{Vu()});var hp={};J(hp,{fromString:()=>F2});function F2(r,e="utf8"){let t=Ni[e];if(!t)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?In(globalThis.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}var dp=te(()=>{Vu();_i()});var pp={};J(pp,{concat:()=>V2});function V2(r,e){e||(e=r.reduce((s,o)=>s+o.length,0));let t=Ri(e),n=0;for(let s of r)t.set(s,n),n+=s.length;return In(t)}var mp=te(()=>{Mu();_i()});var Ku=Ve((a6,Ep)=>{"use strict";var gp=d0(),Tn=D0(),{names:vs}=S0(),{toString:Li}=(fp(),Bs(lp)),{fromString:H2}=(dp(),Bs(hp)),{concat:K2}=(mp(),Bs(pp)),_n={};for(let r in vs){let e=r;_n[vs[e]]=e}Object.freeze(_n);function $2(r){if(!(r instanceof Uint8Array))throw new Error("must be passed a Uint8Array");return Li(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 Li(gp.encode("base58btc",r)).slice(1)}function z2(r){let e=r instanceof Uint8Array?Li(r):r;return gp.decode("z"+e)}function bp(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=Tn.decode(r);if(!wp(e))throw new Error(`multihash unknown function code: 0x${e.toString(16)}`);r=r.slice(Tn.decode.bytes);let t=Tn.decode(r);if(t<0)throw new Error(`multihash invalid length: ${t}`);if(r=r.slice(Tn.decode.bytes),r.length!==t)throw new Error(`multihash length inconsistent: 0x${Li(r,"base16")}`);return{code:e,name:_n[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=yp(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 s=Tn.encode(n),o=Tn.encode(t);return K2([s,o,r],s.length+o.length+r.length)}function yp(r){let e=r;if(typeof r=="string"){if(vs[r]===void 0)throw new Error(`Unrecognized hash function named: ${r}`);e=vs[r]}if(typeof e!="number")throw new Error(`Hash function code should be a number. Got: ${e}`);if(_n[e]===void 0&&!Hu(e))throw new Error(`Unrecognized function code: ${e}`);return e}function Hu(r){return r>0&&r<16}function wp(r){return!!(Hu(r)||_n[r])}function xp(r){bp(r)}function j2(r){return xp(r),r.subarray(0,2)}Ep.exports={names:vs,codes:_n,toHexString:$2,fromHexString:q2,toB58String:W2,fromB58String:z2,decode:bp,encode:G2,coerceCode:yp,isAppCode:Hu,validate:xp,prefix:j2,isValidCode:wp}});var s1={};J(s1,{webRTC:()=>n1,webRTCDirect:()=>r1});var tl=Symbol.for("@libp2p/peer-id");var Ss=Symbol.for("@libp2p/transport");var rl;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(rl||(rl={}));var N=class extends Error{code;props;constructor(e,t,n){super(e),this.code=t,this.name=n?.name??"CodeError",this.props=n??{}}};var ks=(r,...e)=>{try{[...e]}catch{}};var Cs=class extends EventTarget{#e=new Map;constructor(){super(),ks(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 s=this.#e.get(e);s==null&&(s=[],this.#e.set(e,s)),s.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let s=this.#e.get(e);s!=null&&(s=s.filter(({callback:o})=>o!==t),this.#e.set(e,s))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:s})=>!s),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new $p(e,t))}},Mi=class extends Event{detail;constructor(e,t){super(e,t),this.detail=t?.detail}},$p=globalThis.CustomEvent??Mi;var $i={};J($i,{base58btc:()=>pe,base58flickr:()=>Yp});var h1=new Uint8Array(0);function nl(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 Bt(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 sl(r){return new TextEncoder().encode(r)}function ol(r){return new TextDecoder().decode(r)}function qp(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 s=0;s<r.length;s++){var o=r.charAt(s),i=o.charCodeAt(0);if(t[i]!==255)throw new TypeError(o+" is ambiguous");t[i]=s}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),l=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,x=d.length;y!==x&&d[y]===0;)y++,h++;for(var b=(x-y)*l+1>>>0,v=new Uint8Array(b);y!==x;){for(var E=d[y],A=0,S=b-1;(E!==0||A<p)&&S!==-1;S--,A++)E+=256*v[S]>>>0,v[S]=E%a>>>0,E=E/a>>>0;if(E!==0)throw new Error("Non-zero carry");p=A,y++}for(var D=b-p;D!==b&&v[D]===0;)D++;for(var _=c.repeat(h);D<b;++D)_+=r.charAt(v[D]);return _}function m(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 x=(d.length-h)*u+1>>>0,b=new Uint8Array(x);d[h];){var v=t[d.charCodeAt(h)];if(v===255)return;for(var E=0,A=x-1;(v!==0||E<y)&&A!==-1;A--,E++)v+=a*b[A]>>>0,b[A]=v%256>>>0,v=v/256>>>0;if(v!==0)throw new Error("Non-zero carry");y=E,h++}if(d[h]!==" "){for(var S=x-y;S!==x&&b[S]===0;)S++;for(var D=new Uint8Array(p+(x-S)),_=p;S!==x;)D[_++]=b[S++];return D}}}function g(d){var h=m(d);if(h)return h;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:m,decode:g}}var Wp=qp,zp=Wp,al=zp;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 cl(this,e)}},Hi=class{decoders;constructor(e){this.decoders=e}or(e){return cl(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 cl(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,s){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=s,this.encoder=new Fi(e,t,n),this.decoder=new Vi(e,t,s)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Vr({name:r,prefix:e,encode:t,decode:n}){return new Ki(r,e,t,n)}function jt({name:r,prefix:e,alphabet:t}){let{encode:n,decode:s}=al(t,r);return Vr({prefix:e,name:r,encode:n,decode:o=>Bt(s(o))})}function Gp(r,e,t,n){let s={};for(let l=0;l<e.length;++l)s[e[l]]=l;let o=r.length;for(;r[o-1]==="=";)--o;let i=new Uint8Array(o*t/8|0),a=0,c=0,u=0;for(let l=0;l<o;++l){let f=s[r[l]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<t|f,a+=t,a>=8&&(a-=8,i[u++]=255&c>>a)}if(a>=t||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return i}function jp(r,e,t){let n=e[e.length-1]==="=",s=(1<<t)-1,o="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>t;)i-=t,o+=e[s&a>>i];if(i!==0&&(o+=e[s&a<<t-i]),n)for(;o.length*t&7;)o+="=";return o}function fe({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return Vr({prefix:e,name:r,encode(s){return jp(s,n,t)},decode(s){return Gp(s,n,t,r)}})}var pe=jt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Yp=jt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var qi={};J(qi,{base10:()=>Zp});var Zp=jt({prefix:"9",name:"base10",alphabet:"0123456789"});var Wi={};J(Wi,{base16:()=>Xp,base16upper:()=>Jp});var Xp=fe({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Jp=fe({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var zi={};J(zi,{base2:()=>Qp});var Qp=fe({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Gi={};J(Gi,{base256emoji:()=>sm});var ul=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}"),em=ul.reduce((r,e,t)=>(r[t]=e,r),[]),tm=ul.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function rm(r){return r.reduce((e,t)=>(e+=em[t],e),"")}function nm(r){let e=[];for(let t of r){let n=tm[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var sm=Vr({prefix:"\u{1F680}",name:"base256emoji",encode:rm,decode:nm});var ji={};J(ji,{base32:()=>St,base32hex:()=>cm,base32hexpad:()=>lm,base32hexpadupper:()=>fm,base32hexupper:()=>um,base32pad:()=>im,base32padupper:()=>am,base32upper:()=>om,base32z:()=>hm});var St=fe({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),om=fe({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),im=fe({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),am=fe({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),cm=fe({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),um=fe({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),lm=fe({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),fm=fe({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),hm=fe({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Yi={};J(Yi,{base36:()=>dm,base36upper:()=>pm});var dm=jt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),pm=jt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ji={};J(Ji,{base64:()=>Zi,base64pad:()=>mm,base64url:()=>Xi,base64urlpad:()=>gm});var Zi=fe({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),mm=fe({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Xi=fe({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),gm=fe({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Qi={};J(Qi,{base8:()=>bm});var bm=fe({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ea={};J(ea,{identity:()=>ym});var ym=Vr({prefix:"\0",name:"identity",encode:r=>ol(r),decode:r=>sl(r)});var C1=new TextEncoder,I1=new TextDecoder;var ra={};J(ra,{identity:()=>Yt});var Em=hl,ll=128,vm=127,Am=~vm,Dm=Math.pow(2,31);function hl(r,e,t){e=e||[],t=t||0;for(var n=t;r>=Dm;)e[t++]=r&255|ll,r/=128;for(;r&Am;)e[t++]=r&255|ll,r>>>=7;return e[t]=r|0,hl.bytes=t-n+1,e}var Bm=ta,Sm=128,fl=127;function ta(r,n){var t=0,n=n||0,s=0,o=n,i,a=r.length;do{if(o>=a)throw ta.bytes=0,new RangeError("Could not decode varint");i=r[o++],t+=s<28?(i&fl)<<s:(i&fl)*Math.pow(2,s),s+=7}while(i>=Sm);return ta.bytes=o-n,t}var km=Math.pow(2,7),Cm=Math.pow(2,14),Im=Math.pow(2,21),Tm=Math.pow(2,28),_m=Math.pow(2,35),Rm=Math.pow(2,42),Nm=Math.pow(2,49),Lm=Math.pow(2,56),Um=Math.pow(2,63),Om=function(r){return r<km?1:r<Cm?2:r<Im?3:r<Tm?4:r<_m?5:r<Rm?6:r<Nm?7:r<Lm?8:r<Um?9:10},Pm={encode:Em,decode:Bm,encodingLength:Om},Mm=Pm,Nn=Mm;function Ln(r,e=0){return[Nn.decode(r,e),Nn.decode.bytes]}function Hr(r,e,t=0){return Nn.encode(r,e,t),e}function Kr(r){return Nn.encodingLength(r)}function dt(r,e){let t=e.byteLength,n=Kr(r),s=n+Kr(t),o=new Uint8Array(s+t);return Hr(r,o,0),Hr(t,o,n),o.set(e,s),new $r(r,t,e,o)}function pr(r){let e=Bt(r),[t,n]=Ln(e),[s,o]=Ln(e.subarray(n)),i=e.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new $r(t,s,i,e)}function dl(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&nl(r.bytes,t.bytes)}}var $r=class{code;size;digest;bytes;constructor(e,t,n,s){this.code=e,this.size=t,this.digest=n,this.bytes=s}};var pl=0,Fm="identity",ml=Bt;function Vm(r){return dt(pl,ml(r))}var Yt={code:pl,name:Fm,encode:ml,digest:Vm};var oa={};J(oa,{sha256:()=>Te,sha512:()=>Hm});function sa({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?dt(this.code,t):t.then(n=>dt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function bl(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var Te=sa({name:"sha2-256",code:18,encode:bl("SHA-256")}),Hm=sa({name:"sha2-512",code:19,encode:bl("SHA-512")});function yl(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return $m(t,ia(r),e??pe.encoder);default:return qm(t,ia(r),e??St.encoder)}}var wl=new WeakMap;function ia(r){let e=wl.get(r);if(e==null){let t=new Map;return wl.set(r,t),t}return e}var Je=class r{code;version;multihash;bytes;"/";constructor(e,t,n,s){this.code=t,this.version=e,this.multihash=n,this.bytes=s,this["/"]=s}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!==Un)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Wm)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=dt(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&&dl(e.multihash,n.multihash)}toString(e){return yl(this,e)}toJSON(){return{"/":yl(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:s,multihash:o,bytes:i}=t;return new r(n,s,o,i??xl(n,s,o.bytes))}else if(t[zm]===!0){let{version:n,multihash:s,code:o}=t,i=pr(s);return r.create(n,o,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!==Un)throw new Error(`Version 0 CID must use dag-pb (code: ${Un}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let s=xl(e,t,n.bytes);return new r(e,t,n,s)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Un,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,s=Bt(e.subarray(n,n+t.multihashSize));if(s.byteLength!==t.multihashSize)throw new Error("Incorrect length");let o=s.subarray(t.multihashSize-t.digestSize),i=new $r(t.multihashCode,t.digestSize,o,s);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,m]=Ln(e.subarray(t));return t+=m,f},s=n(),o=Un;if(s===18?(s=0,t=0):o=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let i=t,a=n(),c=n(),u=t+c,l=u-i;return{version:s,codec:o,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(e,t){let[n,s]=Km(e,t),o=r.decode(s);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ia(o).set(n,e),o}};function Km(r,e){switch(r[0]){case"Q":{let t=e??pe;return[pe.prefix,t.decode(`${pe.prefix}${r}`)]}case pe.prefix:{let t=e??pe;return[pe.prefix,t.decode(r)]}case St.prefix:{let t=e??St;return[St.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 $m(r,e,t){let{prefix:n}=t;if(n!==pe.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let s=e.get(n);if(s==null){let o=t.encode(r).slice(1);return e.set(n,o),o}else return s}function qm(r,e,t){let{prefix:n}=t,s=e.get(n);if(s==null){let o=t.encode(r);return e.set(n,o),o}else return s}var Un=112,Wm=18;function xl(r,e,t){let n=Kr(r),s=n+Kr(e),o=new Uint8Array(s+t.byteLength);return Hr(r,o,0),Hr(e,o,n),o.set(t,s),o}var zm=Symbol.for("@ipld/js-cid/CID");var pt={...ea,...zi,...Qi,...qi,...Wi,...ji,...Yi,...$i,...Ji,...Gi},Z1={...oa,...ra};function ve(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}var Gm=Symbol.for("nodejs.util.inspect.custom"),El=Object.values(pt).map(r=>r.decoder).reduce((r,e)=>r.or(e),pt.identity.decoder),vl=114,aa=36,ca=37,On=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()})`}[tl]=!0;toString(){return this.string==null&&(this.string=pe.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return Je.createV1(vl,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return ve(this.multihash.bytes,e);if(typeof e=="string")return gr(e).equals(this);if(e?.multihash?.bytes!=null)return ve(this.multihash.bytes,e.multihash.bytes);throw new Error("not valid Id")}[Gm](){return`PeerId(${this.toString()})`}},qr=class extends On{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Wr=class extends On{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.multihash.digest}},zr=class extends On{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.multihash.digest}};function gr(r,e){if(e=e??El,r.charAt(0)==="1"||r.charAt(0)==="Q"){let t=pr(pe.decode(`z${r}`));return r.startsWith("12D")?new Wr({multihash:t}):r.startsWith("16U")?new zr({multihash:t}):new qr({multihash:t})}return jm(El.decode(r))}function jm(r){try{let e=pr(r);if(e.code===Yt.code){if(e.digest.length===aa)return new Wr({multihash:e});if(e.digest.length===ca)return new zr({multihash:e})}if(e.code===Te.code)return new qr({multihash:e})}catch{return Ym(Je.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function Ym(r){if(r==null||r.multihash==null||r.version==null||r.version===1&&r.code!==vl)throw new Error("Supplied PeerID CID is invalid");let e=r.multihash;if(e.code===Te.code)return new qr({multihash:r.multihash});if(e.code===Yt.code){if(e.digest.length===aa)return new Wr({multihash:r.multihash});if(e.digest.length===ca)return new zr({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function ua(r,e){return r.length===aa?new Wr({multihash:dt(Yt.code,r),privateKey:e}):r.length===ca?new zr({multihash:dt(Yt.code,r),privateKey:e}):new qr({multihash:await Te.digest(r),publicKey:r,privateKey:e})}function kt(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function Ae(r=0){return globalThis.Buffer?.alloc!=null?kt(globalThis.Buffer.alloc(r)):new Uint8Array(r)}function De(r=0){return globalThis.Buffer?.allocUnsafe!=null?kt(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function Dl(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Al=Dl("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),la=Dl("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=De(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Xm={utf8:Al,"utf-8":Al,hex:pt.base16,latin1:la,ascii:la,binary:la,...pt},Ts=Xm;function z(r,e="utf8"){let t=Ts[e];if(t==null)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 Jm=Math.pow(2,7),Qm=Math.pow(2,14),eg=Math.pow(2,21),fa=Math.pow(2,28),ha=Math.pow(2,35),da=Math.pow(2,42),pa=Math.pow(2,49),re=128,Ue=127;function ye(r){if(r<Jm)return 1;if(r<Qm)return 2;if(r<eg)return 3;if(r<fa)return 4;if(r<ha)return 5;if(r<da)return 6;if(r<pa)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ma(r,e,t=0){switch(ye(r)){case 8:e[t++]=r&255|re,r/=128;case 7:e[t++]=r&255|re,r/=128;case 6:e[t++]=r&255|re,r/=128;case 5:e[t++]=r&255|re,r/=128;case 4:e[t++]=r&255|re,r>>>=7;case 3:e[t++]=r&255|re,r>>>=7;case 2:e[t++]=r&255|re,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function tg(r,e,t=0){switch(ye(r)){case 8:e.set(t++,r&255|re),r/=128;case 7:e.set(t++,r&255|re),r/=128;case 6:e.set(t++,r&255|re),r/=128;case 5:e.set(t++,r&255|re),r/=128;case 4:e.set(t++,r&255|re),r>>>=7;case 3:e.set(t++,r&255|re),r>>>=7;case 2:e.set(t++,r&255|re),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function ga(r,e){let t=r[e],n=0;if(n+=t&Ue,t<re||(t=r[e+1],n+=(t&Ue)<<7,t<re)||(t=r[e+2],n+=(t&Ue)<<14,t<re)||(t=r[e+3],n+=(t&Ue)<<21,t<re)||(t=r[e+4],n+=(t&Ue)*fa,t<re)||(t=r[e+5],n+=(t&Ue)*ha,t<re)||(t=r[e+6],n+=(t&Ue)*da,t<re)||(t=r[e+7],n+=(t&Ue)*pa,t<re))return n;throw new RangeError("Could not decode varint")}function rg(r,e){let t=r.get(e),n=0;if(n+=t&Ue,t<re||(t=r.get(e+1),n+=(t&Ue)<<7,t<re)||(t=r.get(e+2),n+=(t&Ue)<<14,t<re)||(t=r.get(e+3),n+=(t&Ue)<<21,t<re)||(t=r.get(e+4),n+=(t&Ue)*fa,t<re)||(t=r.get(e+5),n+=(t&Ue)*ha,t<re)||(t=r.get(e+6),n+=(t&Ue)*da,t<re)||(t=r.get(e+7),n+=(t&Ue)*pa,t<re))return n;throw new RangeError("Could not decode varint")}function mt(r,e,t=0){return e==null&&(e=De(ye(r))),e instanceof Uint8Array?ma(r,e,t):tg(r,e,t)}function Qe(r,e=0){return r instanceof Uint8Array?ga(r,e):rg(r,e)}function we(r,e){if(globalThis.Buffer!=null)return kt(globalThis.Buffer.concat(r,e));e==null&&(e=r.reduce((s,o)=>s+o.length,0));let t=De(e),n=0;for(let s of r)t.set(s,n),n+=s.length;return kt(t)}var _s=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,s){return this.readAtomically(()=>{let o=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*s)-1;for(;;){let l=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let m=Number.parseInt(f,e);if(!Number.isNaN(m))return m});if(l===void 0)break;if(o*=e,o+=l,o>u||(i+=1,t!==void 0&&i>t))return}if(i!==0)return!n&&c&&i>1?void 0:o})}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 s=n*2;if(n<t.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return t[s]=i[0],t[s+1]=i[1],t[s+2]=i[2],t[s+3]=i[3],[s+4,!0]}let o=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(o===void 0)return[s,!1];t[s]=o>>8,t[s+1]=o&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,s]=e(t);if(n===16)return t;if(s||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let o=new Uint8Array(14),i=16-(n+2),[a]=e(o.subarray(0,i));return t.set(o.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Bl=45,ng=15,Gr=new _s;function ba(r){if(!(r.length>ng))return Gr.new(r).parseWith(()=>Gr.readIPv4Addr())}function ya(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Bl))return Gr.new(r).parseWith(()=>Gr.readIPv6Addr())}function Rs(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Bl))return Gr.new(r).parseWith(()=>Gr.readIPAddr())}var kE=parseInt("0xFFFF",16),CE=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Q(r,e="utf8"){let t=Ts[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?kt(globalThis.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}function Ns(r){return!!ba(r)}function Ls(r){return!!ya(r)}function Us(r){return!!Rs(r)}var Cl=Ns,cg=Ls,wa=function(r){let e=0;if(r=r.toString().trim(),Cl(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(cg(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let o=Cl(t[n]),i;o&&(i=wa(t[n]),t[n]=z(i.slice(0,2),"base16")),i!=null&&++n<8&&t.splice(n,0,z(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 o=[n,1];for(n=9-t.length;n>0;n--)o.push("0");t.splice.apply(t,o)}let s=new Uint8Array(e+16);for(n=0;n<t.length;n++){let o=parseInt(t[n],16);s[e++]=o>>8&255,s[e++]=o&255}return s}throw new Error("invalid ip address")},Il=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let s=[];for(let o=0;o<t;o++)s.push(r[e+o]);return s.join(".")}if(t===16){let s=[];for(let o=0;o<t;o+=2)s.push(n.getUint16(e+o).toString(16));return s.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var jr={},xa={},lg=[[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"],[777,-1,"memory"]];lg.forEach(r=>{let e=fg(...r);xa[e.code]=e,jr[e.name]=e});function fg(r,e,t,n,s){return{code:r,size:e,name:t,resolvable:!!n,path:!!s}}function ne(r){if(typeof r=="number"){if(xa[r]!=null)return xa[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(jr[r]!=null)return jr[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var p8=ne("ip4"),m8=ne("ip6"),g8=ne("ipcidr");function va(r,e){switch(ne(r).code){case 4:case 41:return dg(e);case 42:return Rl(e);case 6:case 273:case 33:case 132:return Ll(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Rl(e);case 421:return bg(e);case 444:return Nl(e);case 445:return Nl(e);case 466:return gg(e);default:return z(e,"base16")}}function Aa(r,e){switch(ne(r).code){case 4:return Tl(e);case 41:return Tl(e);case 42:return _l(e);case 6:case 273:case 33:case 132:return Da(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return _l(e);case 421:return pg(e);case 444:return yg(e);case 445:return wg(e);case 466:return mg(e);default:return Q(e,"base16")}}var Ea=Object.values(pt).map(r=>r.decoder),hg=function(){let r=Ea[0].or(Ea[1]);return Ea.slice(2).forEach(e=>r=r.or(e)),r}();function Tl(r){if(!Us(r))throw new Error("invalid ip address");return wa(r)}function dg(r){let e=Il(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!Us(e))throw new Error("invalid ip address");return e}function Da(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function Ll(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function _l(r){let e=Q(r),t=Uint8Array.from(mt(e.length));return we([t,e],t.length+e.length)}function Rl(r){let e=Qe(r);if(r=r.slice(ye(e)),r.length!==e)throw new Error("inconsistent lengths");return z(r)}function pg(r){let e;r[0]==="Q"||r[0]==="1"?e=pr(pe.decode(`z${r}`)).bytes:e=Je.parse(r).multihash.bytes;let t=Uint8Array.from(mt(e.length));return we([t,e],t.length+e.length)}function mg(r){let e=hg.decode(r),t=Uint8Array.from(mt(e.length));return we([t,e],t.length+e.length)}function gg(r){let e=Qe(r),t=r.slice(ye(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+z(t,"base64url")}function bg(r){let e=Qe(r),t=r.slice(ye(e));if(t.length!==e)throw new Error("inconsistent lengths");return z(t,"base58btc")}function yg(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=St.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 s=Da(n);return we([t,s],t.length+s.length)}function wg(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=St.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 s=Da(n);return we([t,s],t.length+s.length)}function Nl(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=z(e,"base32"),s=Ll(t);return`${n}:${s}`}function Ul(r){r=Ba(r);let e=[],t=[],n=null,s=r.split("/").slice(1);if(s.length===1&&s[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let o=0;o<s.length;o++){let i=s[o],a=ne(i);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(o++,o>=s.length)throw Pl("invalid address: "+r);if(a.path===!0){n=Ba(s.slice(o).join("/")),e.push([a.code,Aa(a.code,n)]),t.push([a.code,n]);break}let c=Aa(a.code,s[o]);e.push([a.code,c]),t.push([a.code,va(a.code,c)])}return{string:Ol(t),bytes:ka(e),tuples:e,stringTuples:t,path:n}}function Sa(r){let e=[],t=[],n=null,s=0;for(;s<r.length;){let o=Qe(r,s),i=ye(o),a=ne(o),c=xg(a,r.slice(s+i));if(c===0){e.push([o]),t.push([o]),s+=i;continue}let u=r.slice(s+i,s+i+c);if(s+=c+i,s>r.length)throw Pl("Invalid address Uint8Array: "+z(r,"base16"));e.push([o,u]);let l=va(o,u);if(t.push([o,l]),a.path===!0){n=l;break}}return{bytes:Uint8Array.from(r),string:Ol(t),tuples:e,stringTuples:t,path:n}}function Ol(r){let e=[];return r.map(t=>{let n=ne(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),Ba(e.join("/"))}function ka(r){return we(r.map(e=>{let t=ne(e[0]),n=Uint8Array.from(mt(t.code));return e.length>1&&e[1]!=null&&(n=we([n,e[1]])),n}))}function xg(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=Qe(e instanceof Uint8Array?e:Uint8Array.from(e));return t+ye(t)}}function Ba(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}function Pl(r){return new Error("Error parsing address: "+r)}var Eg=Symbol.for("nodejs.util.inspect.custom"),Ca=Symbol.for("@multiformats/js-multiaddr/multiaddr"),vg=[ne("dns").code,ne("dns4").code,ne("dns6").code,ne("dnsaddr").code],Os=class r{bytes;#e;#t;#r;#n;[Ca]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=Sa(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=Ul(e)}else if(Fl(e))t=Sa(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,s,o="",i=ne("tcp"),a=ne("udp"),c=ne("ip4"),u=ne("ip6"),l=ne("dns6"),f=ne("ip6zone");for(let[g,d]of this.stringTuples())g===f.code&&(o=`%${d??""}`),vg.includes(g)&&(t=i.name,s=443,n=`${d??""}${o}`,e=g===l.code?6:4),(g===i.code||g===a.code)&&(t=ne(g).name,s=parseInt(d??"")),(g===c.code||g===u.code)&&(t=ne(g).name,n=`${d??""}${o}`,e=g===u.code?6:4);if(e==null||t==null||n==null||s==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:s}}protos(){return this.#t.map(([e])=>Object.assign({},ne(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>ne(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(),s=n.lastIndexOf(t);if(s<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,s))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(ka(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,s])=>{n===jr.p2p.code&&e.push([n,s]),n===jr["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?z(pe.decode(`z${n}`),"base58btc"):z(Je.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(e){return ve(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(o=>o.resolvable);if(t==null)return[this];let n=Ml.get(t.name);if(n==null)throw new N(`no available resolver for ${t.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,e)).map(o=>new r(o))}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)}[Eg](){return`Multiaddr(${this.#e})`}};var Ml=new Map;function Fl(r){return!!r?.[Ca]}function Ct(r){return new Os(r)}var Ag=r=>r.toString().split("/").slice(1),Mn=r=>({match:e=>e.length<1?!1:r(e[0])?e.slice(1):!1,pattern:"fn"}),me=r=>({match:e=>Mn(t=>t===r).match(e),pattern:r}),Fs=()=>({match:r=>Mn(e=>typeof e=="string").match(r),pattern:"{string}"}),Vl=()=>({match:r=>Mn(e=>!isNaN(parseInt(e))).match(r),pattern:"{number}"}),Ge=()=>({match:r=>{if(r.length<2||r[0]!=="p2p"&&r[0]!=="ipfs")return!1;if(r[1].startsWith("Q")||r[1].startsWith("1"))try{pe.decode(`z${r[1]}`)}catch{return!1}else return!1;return r.slice(2)},pattern:"/p2p/{peerid}"}),Ps=()=>({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}"}),gt=r=>({match:e=>{let t=r.match(e);return t===!1?e:t},pattern:`optional(${r.pattern})`}),bt=(...r)=>({match:e=>{let t;for(let n of r){let s=n.match(e);s!==!1&&(t==null||s.length<t.length)&&(t=s)}return t??!1},pattern:`or(${r.map(e=>e.pattern).join(", ")})`}),ge=(...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(s){let o=Ag(s);for(let i of r){let a=i.match(o);if(a===!1)return!1;o=a}return o}function t(s){return e(s)!==!1}function n(s){let o=e(s);return o===!1?!1:o.length===0}return{matches:t,exactMatch:n}}var Ta=ge(me("dns4"),Fs()),_a=ge(me("dns6"),Fs()),Ra=ge(me("dnsaddr"),Fs()),Hl=ge(me("dns"),Fs()),W8=Be(Ta),z8=Be(_a),G8=Be(Ra),j8=Be(bt(Hl,Ra,Ta,_a)),Kl=ge(me("ip4"),Mn(Ns)),$l=ge(me("ip6"),Mn(Ls)),ql=bt(Kl,$l),Fn=bt(ql,Hl,Ta,_a,Ra),Y8=Be(Fn),Z8=Be(Kl),X8=Be($l),J8=Be(ql),Vs=ge(Fn,me("tcp"),Vl()),Vn=ge(Fn,me("udp"),Vl()),Dg=bt(Vs,Vn),Q8=Be(Vs),ev=Be(Vn),Na=ge(Vn,me("quic")),Hs=ge(Vn,me("quic-v1")),Bg=bt(Na,Hs),tv=Be(Na),rv=Be(Hs),Ia=bt(Fn,Vs,Vn,Na,Hs),Wl=bt(ge(Ia,me("ws"),gt(Ge()))),nv=Be(Wl),zl=bt(ge(Ia,me("wss"),gt(Ge())),ge(Ia,me("tls"),me("ws"),gt(Ge()))),sv=Be(zl),Gl=ge(Dg,me("webrtc-direct"),Ps(),gt(Ps()),gt(Ge())),jl=Be(Gl),Yl=ge(Hs,me("webtransport"),Ps(),Ps(),gt(Ge())),ov=Be(Yl),Ms=bt(Wl,zl,ge(Vs,gt(Ge())),ge(Bg,gt(Ge())),ge(Fn,gt(Ge())),Gl,Yl,Ge()),iv=Be(Ms),Sg=ge(Ms,me("p2p-circuit"),Ge()),av=Be(Sg),kg=bt(ge(Ms,me("p2p-circuit"),me("webrtc"),Ge()),ge(Ms,me("webrtc"),gt(Ge())),me("webrtc")),Zl=Be(kg);var qe;(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"})(qe||(qe={}));var Zt=class extends N{constructor(e,t){super(`WebRTC transport error: ${e}`,t??""),this.name="WebRTCTransportError"}};var La=class extends Zt{constructor(e,t){super(`[stream: ${e}] data channel error: ${t}`,qe.ERR_DATA_CHANNEL),this.name="WebRTC/DataChannelError"}};function Va(r,e){return new La(r,e)}var Ua=class extends Zt{constructor(e){super(`There was a problem with the Multiaddr which was passed in: ${e}`,qe.ERR_INVALID_MULTIADDR),this.name="WebRTC/InappropriateMultiaddrError"}};function Ks(r){return new Ua(r)}var Oa=class extends Zt{constructor(e){super(`There was a problem with a provided argument: ${e}`,qe.ERR_INVALID_PARAMETERS),this.name="WebRTC/InvalidArgumentError"}};function Hn(r){return new Oa(r)}var Pa=class extends Zt{constructor(e,t){super(`Invalid fingerprint "${e}" within ${t}`,qe.ERR_INVALID_FINGERPRINT),this.name="WebRTC/InvalidFingerprintError"}};function Ha(r,e){return new Pa(r,e)}var Ma=class extends Zt{constructor(e){super(`A method (${e}) was called though it has been intentionally left unimplemented.`,qe.ERR_NOT_IMPLEMENTED),this.name="WebRTC/UnimplementedError"}};function Xl(r){return new Ma(r)}var Fa=class extends Zt{constructor(e){super(`unsupported hash algorithm: ${e}`,qe.ERR_HASH_NOT_SUPPORTED),this.name="WebRTC/UnsupportedHashAlgorithmError"}};function Jl(r){return new Fa(r)}var Ql=function(r,e,t){if(t||arguments.length===2)for(var n=0,s=e.length,o;n<s;n++)(o||!(n in e))&&(o||(o=Array.prototype.slice.call(e,0,n)),o[n]=e[n]);return r.concat(o||Array.prototype.slice.call(e))},Cg=function(){function r(e,t,n){this.name=e,this.version=t,this.os=n,this.type="browser"}return r}();var Ig=function(){function r(e){this.version=e,this.type="node",this.name="node",this.os=process.platform}return r}();var Tg=function(){function r(e,t,n,s){this.name=e,this.version=t,this.os=n,this.bot=s,this.type="bot-device"}return r}();var _g=function(){function r(){this.type="bot",this.bot=!0,this.name="bot",this.version=null,this.os=null}return r}();var Rg=function(){function r(){this.type="react-native",this.name="react-native",this.version=null,this.os=null}return r}();var Ng=/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/,Lg=/(nuhk|curl|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask\ Jeeves\/Teoma|ia_archiver)/,ef=3,Ug=[["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",Ng]],tf=[["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 nf(r){return r?rf(r):typeof document>"u"&&typeof navigator<"u"&&navigator.product==="ReactNative"?new Rg:typeof navigator<"u"?rf(navigator.userAgent):Mg()}function Og(r){return r!==""&&Ug.reduce(function(e,t){var n=t[0],s=t[1];if(e)return e;var o=s.exec(r);return!!o&&[n,o]},!1)}function rf(r){var e=Og(r);if(!e)return null;var t=e[0],n=e[1];if(t==="searchbot")return new _g;var s=n[1]&&n[1].split(".").join("_").split("_").slice(0,3);s?s.length<ef&&(s=Ql(Ql([],s,!0),Fg(ef-s.length),!0)):s=[];var o=s.join("."),i=Pg(r),a=Lg.exec(r);return a&&a[1]?new Tg(t,o,i,a[1]):new Cg(t,o,i)}function Pg(r){for(var e=0,t=tf.length;e<t;e++){var n=tf[e],s=n[0],o=n[1],i=o.exec(r);if(i)return s}return null}function Mg(){var r=typeof process<"u"&&process.version;return r?new Ig(process.version.slice(1)):null}function Fg(r){for(var e=[],t=0;t<r;t++)e.push("0");return e}function he(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var Yr=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Ka=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},sf=r=>globalThis.DOMException===void 0?new Ka(r):new DOMException(r),of=r=>{let e=r.reason===void 0?sf("This operation was aborted."):r.reason;return e instanceof Error?e:sf(e)};function br(r,e){let{milliseconds:t,fallback:n,message:s,customTimers:o={setTimeout,clearTimeout}}=e,i,c=new Promise((u,l)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:m}=e;m.aborted&&l(of(m)),m.addEventListener("abort",()=>{l(of(m))})}if(t===Number.POSITIVE_INFINITY){r.then(u,l);return}let f=new Yr;i=o.setTimeout.call(void 0,()=>{if(n){try{u(n())}catch(m){l(m)}return}typeof r.cancel=="function"&&r.cancel(),s===!1?u():s instanceof Error?l(s):(f.message=s??`Promise timed out after ${t} milliseconds`,l(f))},t),(async()=>{try{u(await r)}catch(m){l(m)}})()}).finally(()=>{c.clear()});return c.clear=()=>{o.clearTimeout.call(void 0,i),i=void 0},c}var af=nf(),Kn=af!=null&&af.name==="firefox",$s=async function*(){},qs=async r=>{},Vg=30*1e3;function cf(r,e,t=Vg,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 s=he(),o=!1;r.bufferedAmountLowThreshold=0;let i=()=>{o||(n.log("%s drain channel closed before drain",e),s.resolve())};r.addEventListener("close",i,{once:!0}),r.addEventListener("bufferedamountlow",()=>{o=!0,r.removeEventListener("close",i),s.resolve()}),await br(s.promise,{milliseconds:t})}}).then(async()=>{r.readyState==="open"&&r.close()}).catch(s=>{n.log.error("error closing outbound stream",s)})}var yr=class{log;peerConnection;remoteAddr;timeline;metrics;source=$s();sink=qs;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 Ws=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}},Zr=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Ws(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 Ws(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 $a=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 Hg(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 Hg(r,e){e=e??{};let t=e.onEnd,n=new Zr,s,o,i,a=he(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((p,y)=>{o=x=>{o=null,n.push(x);try{p(r(n))}catch(b){y(b)}return s}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=he()})}},u=p=>o!=null?o(p):(n.push(p),s),l=p=>(n=new Zr,o!=null?o({error:p}):(n.push({error:p}),s)),f=p=>{if(i)return s;if(e?.objectMode!==!0&&p?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:p})},m=p=>i?s:(i=!0,p!=null?l(p):u({done:!0})),g=()=>(n=new Zr,m(),{done:!0}),d=p=>(m(p),{done:!0});if(s={[Symbol.asyncIterator](){return this},next:c,return:g,throw:d,push:f,end:m,get readableLength(){return n.size},onEmpty:async p=>{let y=p?.signal;if(y?.throwIfAborted(),n.isEmpty())return;let x,b;y!=null&&(x=new Promise((v,E)=>{b=()=>{E(new $a)},y.addEventListener("abort",b)}));try{await Promise.race([a.promise,x])}finally{b!=null&&y!=null&&y?.removeEventListener("abort",b)}}},t==null)return s;let h=s;return s={[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),s},get readableLength(){return h.readableLength},onEmpty:p=>h.onEmpty(p)},s}var zs=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 It(r,e,t){if(e==null)return r;if(e.aborted)return Promise.reject(new zs(t?.errorMessage,t?.errorCode));let n,s=new zs(t?.errorMessage,t?.errorCode);try{return await Promise.race([r,new Promise((o,i)=>{n=()=>{i(s)},e.addEventListener("abort",n)})])}finally{n!=null&&e.removeEventListener("abort",n)}}var lf=Symbol.for("@achingbrain/uint8arraylist");function uf(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let s=t+n.byteLength;if(e<s)return{buf:n,index:e-t};t=s}throw new RangeError("index is out of bounds")}function Gs(r){return!!r?.[lf]}var ce=class r{bufs;length;[lf]=!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(Gs(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(Gs(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=uf(this.bufs,e);return t.buf[t.index]}set(e,t){let n=uf(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(Gs(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:s}=this._subList(e,t);return we(n,s)}subarray(e,t){let{bufs:n,length:s}=this._subList(e,t);return n.length===1?n[0]:we(n,s)}sublist(e,t){let{bufs:n,length:s}=this._subList(e,t),o=new r;return o.length=s,o.bufs=[...n],o}_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=[],s=0;for(let o=0;o<this.bufs.length;o++){let i=this.bufs[o],a=s,c=a+i.byteLength;if(s=c,e>=c)continue;let u=e>=a&&e<c,l=t>a&&t<=c;if(u&&l){if(e===a&&t===c){n.push(i);break}let f=e-a;n.push(i.subarray(f,f+(t-e)));break}if(u){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(l){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(!Gs(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 s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let o=256,i=new Int32Array(o);for(let f=0;f<o;f++)i[f]=-1;for(let f=0;f<s;f++)i[n[f]]=f;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let f=t;f<=c;f+=l){l=0;for(let m=u;m>=0;m--){let g=this.get(f+m);if(n[m]!==g){l=Math.max(1,m-a[g]);break}}if(l===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=De(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 s=Ae(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,t,n),this.write(s,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 s=Ae(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,t,n),this.write(s,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 s=Ae(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,t,n),this.write(s,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=De(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 s=Ae(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,t,n),this.write(s,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 s=Ae(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,t,n),this.write(s,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 s=Ae(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,t,n),this.write(s,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 s=Ae(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,t,n),this.write(s,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 s=Ae(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,t,n),this.write(s,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(!ve(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((s,o)=>s+o.byteLength,0)),n.length=t,n}};function ff(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 hf(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function df(r,e){let t=ff(r).return?.();hf(t)&&t.catch(n=>{e.error("could not cause iterator to return",n)})}var Kg="ERR_STREAM_RESET",$g="ERR_SINK_INVALID_STATE",qg=5e3;function qa(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var js=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=he(),this.closed=he(),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??qg,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 N(`writable end state is "${this.writeStatus}" not "ready"`,$g);try{this.writeStatus="writing";let t={signal:this.sinkController.signal};if(this.direction==="outbound"){let s=this.sendNewStream(t);qa(s)&&await s}let n=()=>{df(e,this.log)};try{this.sinkController.signal.addEventListener("abort",n),this.log.trace("sink reading from source");for await(let s of e){s=s instanceof Uint8Array?new ce(s):s;let o=this.sendData(s,t);qa(o)&&(this.sendingData=he(),await o,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 It(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 It(this.sink([]),e.signal)),this.writeStatus==="writing"&&(this.sendingData!=null&&await It(this.sendingData.promise,e.signal),this.log.trace("aborting source passed to .sink"),this.sinkController.abort(),await It(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();qa(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 N("stream reset",Kg);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 Ys(r){return r[Symbol.asyncIterator]!=null}var Zs=r=>{let e=ye(r),t=De(e);return mt(r,t),Zs.bytes=e,t};Zs.bytes=0;function $n(r,e){e=e??{};let t=e.lengthEncoder??Zs;function*n(s){let o=t(s.byteLength);o instanceof Uint8Array?yield o:yield*o,s instanceof Uint8Array?yield s:yield*s}return Ys(r)?async function*(){for await(let s of r)yield*n(s)}():function*(){for(let s of r)yield*n(s)}()}$n.single=(r,e)=>{e=e??{};let t=e.lengthEncoder??Zs;return new ce(t(r.byteLength),r)};var Xr=Ds(gf(),1);var zg=8,Gg=1024*1024*4,wr;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(wr||(wr={}));var Wa=r=>{let e=Qe(r);return Wa.bytes=ye(e),e};Wa.bytes=0;function xr(r,e){let t=new ce,n=wr.LENGTH,s=-1,o=e?.lengthDecoder??Wa,i=e?.maxLengthLength??zg,a=e?.maxDataLength??Gg;function*c(){for(;t.byteLength>0;){if(n===wr.LENGTH)try{if(s=o(t),s<0)throw(0,Xr.default)(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(s>a)throw(0,Xr.default)(new Error("message length too long"),"ERR_MSG_DATA_TOO_LONG");let u=o.bytes;t.consume(u),e?.onLength!=null&&e.onLength(s),n=wr.DATA}catch(u){if(u instanceof RangeError){if(t.byteLength>i)throw(0,Xr.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw u}if(n===wr.DATA){if(t.byteLength<s)break;let u=t.sublist(0,s);t.consume(s),e?.onData!=null&&e.onData(u),yield u,n=wr.LENGTH}}}return Ys(r)?async function*(){for await(let u of r)t.append(u),yield*c();if(t.byteLength>0)throw(0,Xr.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}():function*(){for(let u of r)t.append(u),yield*c();if(t.byteLength>0)throw(0,Xr.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}()}xr.fromReader=(r,e)=>{let t=1,n=async function*(){for(;;)try{let{done:o,value:i}=await r.next(t);if(o===!0)return;i!=null&&(yield i)}catch(o){if(o.code==="ERR_UNDER_READ")return{done:!0,value:null};throw o}finally{t=1}}();return xr(n,{...e??{},onLength:o=>{t=o}})};var Yg=r=>{let e=r.on||r.addListener||r.addEventListener,t=r.off||r.removeListener||r.removeEventListener;if(!e||!t)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(r),removeListener:t.bind(r)}};function Zg(r,e,t){let n,s=new Promise((o,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:u,removeListener:l}=Yg(r),f=(...g)=>{let d=t.multiArgs?g:g[0];t.filter&&!t.filter(d)||(c.push(d),t.count===c.length&&(n(),o(c)))},m=g=>{n(),i(g)};n=()=>{for(let g of a)l(g,f);for(let g of t.rejectionEvents)l(g,m)};for(let g of a)u(g,f);for(let g of t.rejectionEvents)u(g,m);t.signal&&t.signal.addEventListener("abort",()=>{m(t.signal.reason)},{once:!0}),t.resolveImmediately&&o(c)});if(s.cancel=n,typeof t.timeout=="number"){let o=br(s,{milliseconds:t.timeout});return o.cancel=n,o}return s}function za(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=Zg(r,e,t),s=n.then(o=>o[0]);return s.cancel=n.cancel,s}var Ga=new Float32Array([-0]),Jt=new Uint8Array(Ga.buffer);function bf(r,e,t){Ga[0]=r,e[t]=Jt[0],e[t+1]=Jt[1],e[t+2]=Jt[2],e[t+3]=Jt[3]}function yf(r,e){return Jt[0]=r[e],Jt[1]=r[e+1],Jt[2]=r[e+2],Jt[3]=r[e+3],Ga[0]}var ja=new Float64Array([-0]),Oe=new Uint8Array(ja.buffer);function wf(r,e,t){ja[0]=r,e[t]=Oe[0],e[t+1]=Oe[1],e[t+2]=Oe[2],e[t+3]=Oe[3],e[t+4]=Oe[4],e[t+5]=Oe[5],e[t+6]=Oe[6],e[t+7]=Oe[7]}function xf(r,e){return Oe[0]=r[e],Oe[1]=r[e+1],Oe[2]=r[e+2],Oe[3]=r[e+3],Oe[4]=r[e+4],Oe[5]=r[e+5],Oe[6]=r[e+6],Oe[7]=r[e+7],ja[0]}var Xg=BigInt(Number.MAX_SAFE_INTEGER),Jg=BigInt(Number.MIN_SAFE_INTEGER),We=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 Er;if(e<Xg&&e>Jg)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let n=e>>32n,s=e-(n<<32n);return t&&(n=~n|0n,s=~s|0n,++s>Ef&&(s=0n,++n>Ef&&(n=0n))),new r(Number(s),Number(n))}static fromNumber(e){if(e===0)return Er;let t=e<0;t&&(e=-e);let n=e>>>0,s=(e-n)/4294967296>>>0;return t&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new r(n,s)}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):Er}},Er=new We(0,0);Er.toBigInt=function(){return 0n};Er.zzEncode=Er.zzDecode=function(){return this};Er.length=function(){return 1};var Ef=4294967296n;function vf(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 Af(r,e,t){if(t-e<1)return"";let s,o=[],i=0,a;for(;e<t;)a=r[e++],a<128?o[i++]=a:a>191&&a<224?o[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,o[i++]=55296+(a>>10),o[i++]=56320+(a&1023)):o[i++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&63,i>8191&&((s??(s=[])).push(String.fromCharCode.apply(String,o)),i=0);return s!=null?(i>0&&s.push(String.fromCharCode.apply(String,o.slice(0,i))),s.join("")):String.fromCharCode.apply(String,o.slice(0,i))}function Ya(r,e,t){let n=t,s,o;for(let i=0;i<r.length;++i)s=r.charCodeAt(i),s<128?e[t++]=s:s<2048?(e[t++]=s>>6|192,e[t++]=s&63|128):(s&64512)===55296&&((o=r.charCodeAt(i+1))&64512)===56320?(s=65536+((s&1023)<<10)+(o&1023),++i,e[t++]=s>>18|240,e[t++]=s>>12&63|128,e[t++]=s>>6&63|128,e[t++]=s&63|128):(e[t++]=s>>12|224,e[t++]=s>>6&63|128,e[t++]=s&63|128);return t-n}function et(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function Xs(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var Za=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,et(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 et(this,4);return Xs(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw et(this,4);return Xs(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw et(this,4);let e=yf(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw et(this,4);let e=xf(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 et(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return Af(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw et(this,e);this.pos+=e}else do if(this.pos>=this.len)throw et(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 We(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 et(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 et(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 et(this,8);let e=Xs(this.buf,this.pos+=4),t=Xs(this.buf,this.pos+=4);return new We(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=ga(this.buf,this.pos);return this.pos+=ye(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 Xa(r){return new Za(r instanceof Uint8Array?r:r.subarray())}function tt(r,e,t){let n=Xa(r);return e.decode(n,void 0,t)}function Ja(r){let e=r??8192,t=e>>>1,n,s=e;return function(i){if(i<1||i>t)return De(i);s+i>e&&(n=De(e),s=0);let a=n.subarray(s,s+=i);return s&7&&(s=(s|7)+1),a}}var vr=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function Qa(){}var tc=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Qg=Ja();function eb(r){return globalThis.Buffer!=null?De(r):Qg(r)}var Wn=class{len;head;tail;states;constructor(){this.len=0,this.head=new vr(Qa,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new vr(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new rc((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(Js,10,We.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=We.fromBigInt(e);return this._push(Js,t.length(),t)}uint64Number(e){return this._push(ma,ye(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=We.fromBigInt(e).zzEncode();return this._push(Js,t.length(),t)}sint64Number(e){let t=We.fromNumber(e).zzEncode();return this._push(Js,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(ec,1,e?1:0)}fixed32(e){return this._push(qn,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=We.fromBigInt(e);return this._push(qn,4,t.lo)._push(qn,4,t.hi)}fixed64Number(e){let t=We.fromNumber(e);return this._push(qn,4,t.lo)._push(qn,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(bf,4,e)}double(e){return this._push(wf,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(ec,1,0):this.uint32(t)._push(rb,t,e)}string(e){let t=vf(e);return t!==0?this.uint32(t)._push(Ya,t,e):this._push(ec,1,0)}fork(){return this.states=new tc(this),this.head=this.tail=new vr(Qa,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 vr(Qa,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=eb(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function ec(r,e,t){e[t]=r&255}function tb(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var rc=class extends vr{next;constructor(e,t){super(tb,e,t),this.next=void 0}};function Js(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 qn(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 rb(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(Wn.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(nb,e,r),this},Wn.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(sb,e,r),this});function nb(r,e,t){e.set(r,t)}function sb(r,e,t){r.length<40?Ya(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(Q(r),t)}function nc(){return new Wn}function rt(r,e){let t=nc();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var Jr;(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"})(Jr||(Jr={}));function Qs(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function Ar(r){function e(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let t=function(o,i){let a=e(o);i.int32(a)},n=function(o){let i=o.int32();return e(i)};return Qs("enum",Jr.VARINT,t,n)}function nt(r,e){return Qs("message",Jr.LENGTH_DELIMITED,r,e)}var He;(function(r){let e;(function(s){s.FIN="FIN",s.STOP_SENDING="STOP_SENDING",s.RESET="RESET",s.FIN_ACK="FIN_ACK"})(e=r.Flag||(r.Flag={}));let t;(function(s){s[s.FIN=0]="FIN",s[s.STOP_SENDING=1]="STOP_SENDING",s[s.RESET=2]="RESET",s[s.FIN_ACK=3]="FIN_ACK"})(t||(t={})),function(s){s.codec=()=>Ar(t)}(e=r.Flag||(r.Flag={}));let n;r.codec=()=>(n==null&&(n=nt((s,o,i={})=>{i.lengthDelimited!==!1&&o.fork(),s.flag!=null&&(o.uint32(8),r.Flag.codec().encode(s.flag,o)),s.message!=null&&(o.uint32(18),o.bytes(s.message)),i.lengthDelimited!==!1&&o.ldelim()},(s,o)=>{let i={},a=o==null?s.len:s.pos+o;for(;s.pos<a;){let c=s.uint32();switch(c>>>3){case 1:i.flag=r.Flag.codec().decode(s);break;case 2:i.message=s.bytes();break;default:s.skipType(c&7);break}}return i})),n),r.encode=s=>rt(s,r.codec()),r.decode=s=>tt(s,r.codec())})(He||(He={}));var ob=16*1024*1024,ib=30*1e3,ab=5,cb=2,ub=16*1024,lb=5e3,fb=5e3,sc=class extends js{channel;incomingData;maxBufferedAmount;bufferedAmountLowEventTimeout;maxMessageSize;receiveFinAck;finAckTimeout;openTimeout;constructor(e){let t=e.onEnd;switch(e.onEnd=s=>{this.log.trace("readable and writeable ends closed",this.status),Promise.resolve(async()=>{if(!(this.timeline.abort!=null||this.timeline.reset!==null))try{await br(this.receiveFinAck.promise,{milliseconds:this.finAckTimeout})}catch(o){this.log.error("error receiving FIN_ACK",o)}}).then(()=>{this.incomingData.end(),t?.(s)}).catch(o=>{this.log.error("error ending stream",o)})},super(e),this.channel=e.channel,this.channel.binaryType="arraybuffer",this.incomingData=Xt(),this.bufferedAmountLowEventTimeout=e.bufferedAmountLowEventTimeout??ib,this.maxBufferedAmount=e.maxBufferedAmount??ob,this.maxMessageSize=(e.maxMessageSize??ub)-ab-cb,this.receiveFinAck=he(),this.finAckTimeout=e.closeTimeout??lb,this.openTimeout=e.openTimeout??fb,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 N("Unknown datachannel state","ERR_INVALID_STATE")}this.channel.onopen=s=>{this.timeline.open=new Date().getTime()},this.channel.onclose=s=>{this.receiveFinAck.resolve(),this.close().catch(o=>{this.log.error("error closing stream after channel closed",o)})},this.channel.onerror=s=>{let o=s.error;this.abort(o)},this.channel.onmessage=async s=>{let{data:o}=s;o===null||o.byteLength===0||this.incomingData.push(new Uint8Array(o,0,o.byteLength))};let n=this;Promise.resolve().then(async()=>{for await(let s of xr(this.incomingData)){let o=n.processIncomingProtobuf(s);o!=null&&n.sourcePush(new ce(o))}}).catch(s=>{this.log.error("error processing incoming data channel messages",s)})}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 za(this.channel,"bufferedamountlow",{timeout:this.bufferedAmountLowEventTimeout})}catch(n){throw n instanceof Yr?new N(`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 N(`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 za(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),s=He.encode({message:n}),o=$n.single(s);await this._sendMessage(o),e.consume(t)}}async sendReset(){await this._sendFlag(He.Flag.RESET)}async sendCloseWrite(e){if(await this._sendFlag(He.Flag.FIN)){this.log.trace("awaiting FIN_ACK");try{await It(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(He.Flag.STOP_SENDING)}processIncomingProtobuf(e){let t=He.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===He.Flag.FIN&&(this.remoteCloseWrite(),this.log.trace("sending FIN_ACK"),this._sendFlag(He.Flag.FIN_ACK).catch(n=>{this.log.error("error sending FIN_ACK immediately",n)})),t.flag===He.Flag.RESET&&this.reset(),t.flag===He.Flag.STOP_SENDING&&this.remoteCloseRead(),t.flag===He.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=He.encode({flag:e}),n=$n.single(t);try{return await this._sendMessage(n,!1),!0}catch(s){this.log.error("could not send flag %s",e.toString(),s)}return!1}};function Qr(r){let{channel:e,direction:t}=r;return new sc({id:t==="inbound"?`i${e.id}`:`r${e.id}`,log:r.logger.forComponent(`libp2p:webrtc:stream:${t}:${e.id}`),...r})}var Bf="/webrtc",Dr=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??Bf,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 s={},o=Qr({channel:n,direction:"inbound",onEnd:i=>{s.onEnd(i)},logger:e.logger,...this.dataChannelOptions});s.stream=o,s.channel=n,s.onEnd=()=>{this.bufferedStreams=this.bufferedStreams.filter(i=>i.stream.id!==o.id)},this.bufferedStreams.push(s)}}createStreamMuxer(e){return new oc(this.components,{...e,peerConnection:this.peerConnection,dataChannelOptions:this.dataChannelOptions,metrics:this.metrics,streams:this.bufferedStreams,protocol:this.protocol})}},oc=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??Bf,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 s=Qr({channel:n,direction:"inbound",onEnd:()=>{this.log("incoming channel %s ended with state %s",n.id,n.readyState),this.#e(s,n)},logger:this.logger,...this.dataChannelOptions});this.streams.push(s),this.metrics?.increment({incoming_stream:!0}),t?.onIncomingStream?.(s)},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),cf(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=$s();sink=qs;newStream(){let e=this.peerConnection.createDataChannel("");this.log.trace("opened outgoing datachannel with channel id %s",e.id);let t=Qr({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 en=globalThis.RTCPeerConnection,eo=globalThis.RTCSessionDescription,Sf=globalThis.RTCIceCandidate;var ic=class{readNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.readNext=he(),this.haveNext=he()}[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=he(),e}async throw(e){return this.ended=!0,e!=null&&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");if(this.nextResult!=null&&(await this.readNext.promise,this.nextResult!=null))throw new Error("NeedNext promise resolved but nextResult was not consumed");e!=null?this.nextResult={done:!1,value:e}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=he(),await It(this.readNext.promise,t?.signal,t)}};function kf(){return new ic}var to=class extends Error{code;constructor(e,t){super(e),this.code=t}},ac=class extends to{type;constructor(e){super(e,"ABORT_ERR"),this.type="aborted"}};function Cf(r,e){let t=kf();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 s=new ce;return{read:async(i,a)=>{a?.signal?.throwIfAborted();let c,u=new Promise((l,f)=>{c=()=>{f(new ac("Read aborted"))},a?.signal?.addEventListener("abort",c)});try{if(i==null){let{done:f,value:m}=await Promise.race([n.next(),u]);return f===!0?new ce:m}for(;s.byteLength<i;){let{value:f,done:m}=await Promise.race([n.next(),u]);if(m===!0)throw new to("unexpected end of input","ERR_UNEXPECTED_EOF");s.append(f)}let l=s.sublist(0,i);return s.consume(i),l}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(s.byteLength>0){let i=r.source;r.source=async function*(){e?.yieldBytes===!1?yield s:yield*s,yield*i}()}return r}}}var ro=class extends Error{code;constructor(e,t){super(e),this.code=t}};function zn(r,e={}){let t=Cf(r,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=ye(e.maxDataLength));let n=e?.lengthDecoder??Qe,s=e?.lengthEncoder??mt;return{read:async i=>{let a=-1,c=new ce;for(;;){c.append(await t.read(1,i));try{a=n(c)}catch(u){if(u instanceof RangeError)continue;throw u}if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new ro("message length length too long","ERR_MSG_LENGTH_TOO_LONG");if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new ro("message length too long","ERR_MSG_DATA_TOO_LONG");return t.read(a,i)},write:async(i,a)=>{await t.write(new ce(s(i.byteLength),i),a)},writeV:async(i,a)=>{let c=new ce(...i.flatMap(u=>[s(u.byteLength),u]));await t.write(c,a)},unwrap:()=>t.unwrap()}}function no(r,e){let t=zn(r,e),n={read:async(s,o)=>{let i=await t.read(o);return s.decode(i)},write:async(s,o,i)=>{await t.write(o.encode(s),i)},writeV:async(s,o,i)=>{await t.writeV(s.map(a=>o.encode(a)),i)},pb:s=>({read:async o=>n.read(s,o),write:async(o,i)=>n.write(o,s,i),writeV:async(o,i)=>n.writeV(o,s,i),unwrap:()=>n}),unwrap:()=>t.unwrap()};return n}var Ke;(function(r){let e;(function(s){s.SDP_OFFER="SDP_OFFER",s.SDP_ANSWER="SDP_ANSWER",s.ICE_CANDIDATE="ICE_CANDIDATE"})(e=r.Type||(r.Type={}));let t;(function(s){s[s.SDP_OFFER=0]="SDP_OFFER",s[s.SDP_ANSWER=1]="SDP_ANSWER",s[s.ICE_CANDIDATE=2]="ICE_CANDIDATE"})(t||(t={})),function(s){s.codec=()=>Ar(t)}(e=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=nt((s,o,i={})=>{i.lengthDelimited!==!1&&o.fork(),s.type!=null&&(o.uint32(8),r.Type.codec().encode(s.type,o)),s.data!=null&&(o.uint32(18),o.string(s.data)),i.lengthDelimited!==!1&&o.ldelim()},(s,o)=>{let i={},a=o==null?s.len:s.pos+o;for(;s.pos<a;){let c=s.uint32();switch(c>>>3){case 1:i.type=r.Type.codec().decode(s);break;case 2:i.data=s.string();break;default:s.skipType(c&7);break}}return i})),n),r.encode=s=>rt(s,r.codec()),r.decode=s=>tt(s,r.codec())})(Ke||(Ke={}));var so=async(r,e,t)=>{try{let n=he();for(db(r,n);;){let s=await Promise.race([n.promise,e.read({signal:t.signal})]);if(s==null)break;if(s.type!==Ke.Type.ICE_CANDIDATE)throw new N("ICE candidate message expected","ERR_NOT_ICE_CANDIDATE");let o=JSON.parse(s.data??"null");if(o===""||o===null){t.log.trace("end-of-candidates received");continue}let i=new Sf(o);t.log.trace("%s received new ICE candidate",t.direction,i);try{await r.addIceCandidate(i)}catch(a){t.log.error("%s bad candidate received",t.direction,o,a)}}}catch(n){if(t.log.error("%s error parsing ICE candidate",t.direction,n),t.signal?.aborted===!0)throw n}};function hb(r){return Kn?r.iceConnectionState:r.connectionState}function db(r,e){r[Kn?"oniceconnectionstatechange":"onconnectionstatechange"]=t=>{switch(hb(r)){case"connected":e.resolve();break;case"failed":case"disconnected":case"closed":e.reject(new N("RTCPeerConnection was closed","ERR_CONNECTION_CLOSED_BEFORE_CONNECTED"));break;default:break}}}async function If({peerConnection:r,signal:e,metrics:t,multiaddr:n,connectionManager:s,transportManager:o,log:i}){let{baseAddr:a}=Tf(n);t?.dialerEvents.increment({open:!0}),i.trace("dialing base address: %a",a);let c=a.getPeerId();if(c==null)throw new N("Relay peer was missing","ERR_INVALID_ADDRESS");let u=s.getConnections(gr(c)),l,f=!1;u.length===0?(l=await o.dial(a,{signal:e}),f=!0):l=u[0];try{let m=await l.newStream(oo,{signal:e,runOnTransientConnection:!0}),g=no(m).pb(Ke);try{let d=r.createDataChannel("init");r.onicecandidate=({candidate:x})=>{let b=JSON.stringify(x?.toJSON()??null);i.trace("initiator sending ICE candidate %s",b),g.write({type:Ke.Type.ICE_CANDIDATE,data:b},{signal:e}).catch(v=>{i.error("error sending ICE candidate",v)})},r.onicecandidateerror=x=>{i.error("initiator ICE candidate error",x)};let h=await r.createOffer().catch(x=>{throw i.error("could not execute createOffer",x),new N("Failed to set createOffer","ERR_SDP_HANDSHAKE_FAILED")});i.trace("initiator send SDP offer %s",h.sdp),await g.write({type:Ke.Type.SDP_OFFER,data:h.sdp},{signal:e}),await r.setLocalDescription(h).catch(x=>{throw i.error("could not execute setLocalDescription",x),new N("Failed to set localDescription","ERR_SDP_HANDSHAKE_FAILED")});let p=await g.read({signal:e});if(p.type!==Ke.Type.SDP_ANSWER)throw new N("Remote should send an SDP answer","ERR_SDP_HANDSHAKE_FAILED");i.trace("initiator receive SDP answer %s",p.data);let y=new eo({type:"answer",sdp:p.data});return await r.setRemoteDescription(y).catch(x=>{throw i.error("could not execute setRemoteDescription",x),new N("Failed to set remoteDescription","ERR_SDP_HANDSHAKE_FAILED")}),i.trace("initiator read candidates until connected"),await so(r,g,{direction:"initiator",signal:e,log:i}),i.trace("initiator connected, closing init channel"),d.close(),i.trace("initiator closing signalling stream"),await g.unwrap().unwrap().close({signal:e}),i.trace("initiator connected to remote address %s",n),{remoteAddress:n}}catch(d){throw r.close(),m.abort(d),d}finally{r.onicecandidate=null,r.onicecandidateerror=null}}finally{if(f)try{await l.close({signal:e})}catch(m){l.abort(m)}}}var pb=L("dns4"),mb=L("dns6"),gb=L("dnsaddr"),Br=be(L("dns"),gb,pb,mb),co=be(L("ip4"),L("ip6")),tn=be(K(co,L("tcp")),K(Br,L("tcp"))),uo=K(co,L("udp")),bb=K(uo,L("utp")),yb=K(uo,L("quic")),wb=K(uo,L("quic-v1")),cc=be(K(tn,L("ws")),K(Br,L("ws"))),io=be(K(cc,L("p2p")),cc),uc=be(K(tn,L("wss")),K(Br,L("wss")),K(tn,L("tls"),L("ws")),K(Br,L("tls"),L("ws"))),ao=be(K(uc,L("p2p")),uc),lc=be(K(tn,L("http")),K(co,L("http")),K(Br,L("http"))),fc=be(K(tn,L("https")),K(co,L("https")),K(Br,L("https"))),_f=K(uo,L("webrtc-direct"),L("certhash")),Lf=be(K(_f,L("p2p")),_f),Rf=K(wb,L("webtransport"),L("certhash"),L("certhash")),Uf=be(K(Rf,L("p2p")),Rf),Of=be(K(io,L("p2p-webrtc-star"),L("p2p")),K(ao,L("p2p-webrtc-star"),L("p2p")),K(io,L("p2p-webrtc-star")),K(ao,L("p2p-webrtc-star"))),DA=be(K(io,L("p2p-websocket-star"),L("p2p")),K(ao,L("p2p-websocket-star"),L("p2p")),K(io,L("p2p-websocket-star")),K(ao,L("p2p-websocket-star"))),Pf=be(K(lc,L("p2p-webrtc-direct"),L("p2p")),K(fc,L("p2p-webrtc-direct"),L("p2p")),K(lc,L("p2p-webrtc-direct")),K(fc,L("p2p-webrtc-direct"))),Sr=be(cc,uc,lc,fc,Of,Pf,tn,bb,yb,Br,Lf,Uf),BA=be(K(Sr,L("p2p-stardust"),L("p2p")),K(Sr,L("p2p-stardust"))),Qt=be(K(Sr,L("p2p")),Of,Pf,Lf,Uf,L("p2p")),Nf=be(K(Qt,L("p2p-circuit"),Qt),K(Qt,L("p2p-circuit")),K(L("p2p-circuit"),Qt),K(Sr,L("p2p-circuit")),K(L("p2p-circuit"),Sr),L("p2p-circuit")),Mf=()=>be(K(Nf,Mf),Nf),Tt=Mf(),SA=be(K(Tt,Qt,Tt),K(Qt,Tt),K(Tt,Qt),Tt,Qt);var kA=be(K(Tt,L("webrtc"),L("p2p")),K(Tt,L("webrtc")),K(Sr,L("webrtc"),L("p2p")),K(Sr,L("webrtc")),L("webrtc"));function Ff(r){function e(t){let n;try{n=Ct(t)}catch{return!1}let s=r(n.protoNames());return s===null?!1:s===!0||s===!1?s:s.length===0}return e}function K(...r){function e(t){if(t.length<r.length)return null;let n=t;return r.some(s=>(n=typeof s=="function"?s().partialMatch(t):s.partialMatch(t),Array.isArray(n)&&(t=n),n===null)),n}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:Ff(e),partialMatch:e}}function be(...r){function e(n){let s=null;return r.some(o=>{let i=typeof o=="function"?o().partialMatch(n):o.partialMatch(n);return i!=null?(s=i,!0):!1}),s}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:Ff(e),partialMatch:e}}function L(r){let e=r;function t(s){let o;try{o=Ct(s)}catch{return!1}let i=o.protoNames();return i.length===1&&i[0]===e}function n(s){return s.length===0?null:s[0]===e?s.slice(1):null}return{toString:function(){return e},matches:t,partialMatch:n}}var lo=class extends Cs{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=>Tt.matches(t)).map(t=>t.encapsulate(`/webrtc/p2p/${this.peerId}`))).flat()}async close(){this.shutdownController.abort(),this.safeDispatchEvent("close",{})}};async function Vf({peerConnection:r,stream:e,signal:t,connection:n,log:s}){s.trace("new inbound signaling stream");let o=no(e).pb(Ke);try{r.onicecandidate=({candidate:l})=>{let f=JSON.stringify(l?.toJSON()??null);s.trace("recipient sending ICE candidate %s",f),o.write({type:Ke.Type.ICE_CANDIDATE,data:f},{signal:t}).catch(m=>{s.error("error sending ICE candidate",m)})};let a=await o.read({signal:t});if(a.type!==Ke.Type.SDP_OFFER)throw new N(`expected message type SDP_OFFER, received: ${a.type??"undefined"} `,"ERR_SDP_HANDSHAKE_FAILED");s.trace("recipient receive SDP offer %s",a.data);let c=new eo({type:"offer",sdp:a.data});await r.setRemoteDescription(c).catch(l=>{throw s.error("could not execute setRemoteDescription",l),new N("Failed to set remoteDescription","ERR_SDP_HANDSHAKE_FAILED")});let u=await r.createAnswer().catch(l=>{throw s.error("could not execute createAnswer",l),new N("Failed to create answer","ERR_SDP_HANDSHAKE_FAILED")});s.trace("recipient send SDP answer %s",u.sdp),await o.write({type:Ke.Type.SDP_ANSWER,data:u.sdp},{signal:t}),await r.setLocalDescription(u).catch(l=>{throw s.error("could not execute setLocalDescription",l),new N("Failed to set localDescription","ERR_SDP_HANDSHAKE_FAILED")}),s.trace("recipient read candidates until connected"),await so(r,o,{direction:"recipient",signal:t,log:s})}catch(a){if(r.connectionState!=="connected")throw s.error("error while handling signaling stream from peer %a",n.remoteAddr,a),r.close(),a;s("error while handling signaling stream from peer %a, ignoring as the RTCPeerConnection is already connected",n.remoteAddr,a)}let i=Ct(`/webrtc/p2p/${n.remoteAddr.getPeerId()}`);return s.trace("recipient connected to remote address %s",i),{remoteAddress:i}}var xb="/webrtc",Eb="/p2p-circuit",oo="/webrtc-signaling/0.0.1",vb=30*1e3,fo=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,ks(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"})})}isStarted(){return this._started}async start(){await this.components.registrar.handle(oo,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(oo),this._started=!1}createListener(e){return new lo(this.components,{shutdownController:this.shutdownController})}[Symbol.toStringTag]="@libp2p/webrtc";[Ss]=!0;filter(e){return e.filter(Zl.exactMatch)}async dial(e,t){this.log.trace("dialing address: %a",e);let n=new en(this.init.rtcConfiguration),s=new Dr(this.components,{peerConnection:n,dataChannelOptions:this.init.dataChannel}),{remoteAddress:o}=await If({peerConnection:n,multiaddr:e,dataChannelOptions:this.init.dataChannel,signal:t.signal,connectionManager:this.components.connectionManager,transportManager:this.components.transportManager,log:this.log}),i=new yr(this.components,{peerConnection:n,timeline:{open:Date.now()},remoteAddr:o,metrics:this.metrics?.dialerEvents}),a=await t.upgrader.upgradeOutbound(i,{skipProtection:!0,skipEncryption:!0,muxerFactory:s});return this._closeOnShutdown(n,i),a}async _onProtocol({connection:e,stream:t}){let n=AbortSignal.timeout(this.init.inboundConnectionTimeout??vb),s=new en(this.init.rtcConfiguration),o=new Dr(this.components,{peerConnection:s,dataChannelOptions:this.init.dataChannel});try{let{remoteAddress:i}=await Vf({peerConnection:s,connection:e,stream:t,signal:n,log:this.log}),a=new yr(this.components,{peerConnection:s,timeline:{open:new Date().getTime()},remoteAddr:i,metrics:this.metrics?.listenerEvents});this._closeOnShutdown(s,a),await this.components.upgrader.upgradeInbound(a,{skipEncryption:!0,skipProtection:!0,muxerFactory:o}),await t.close({signal:n})}catch(i){throw t.abort(i),i}}_closeOnShutdown(e,t){let n=()=>{t.close().catch(s=>{this.log.error("could not close WebRTCMultiaddrConnection",s)})};this.shutdownController.signal.addEventListener("abort",n),e.addEventListener("close",()=>{this.shutdownController.signal.removeEventListener("abort",n)})}};function Tf(r){let e=r.toString().split(xb+"/");if(e.length!==2)throw new N("webrtc protocol was not present in multiaddr",qe.ERR_INVALID_MULTIADDR);if(!e[0].includes(Eb))throw new N("p2p-circuit protocol was not present in multiaddr",qe.ERR_INVALID_MULTIADDR);let t=Ct(e[0]),s=Ct("/"+e[1]).getPeerId();if(s==null)throw new N("destination peer id was missing",qe.ERR_INVALID_MULTIADDR);let o=t.protos().pop();if(o===void 0)throw new N("invalid multiaddr",qe.ERR_INVALID_MULTIADDR);return o.name!=="p2p"&&(t=t.encapsulate(`/p2p/${s}`)),{baseAddr:t,peerId:gr(s)}}var Tc={};J(Tc,{Ed25519PrivateKey:()=>_r,Ed25519PublicKey:()=>Jn,generateKeyPair:()=>_y,generateKeyPairFromSeed:()=>mh,unmarshalEd25519PrivateKey:()=>Iy,unmarshalEd25519PublicKey:()=>Ty});function je(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function er(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`Wrong positive integer: ${r}`)}function Ab(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function hc(r,...e){if(!Ab(r))throw new Error("Expected Uint8Array");if(e.length>0&&!e.includes(r.length))throw new Error(`Expected Uint8Array of length ${e}, not of length=${r.length}`)}function kr(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");er(r.outputLen),er(r.blockLen)}function rn(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 Hf(r,e){hc(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var ho=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Kf(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var sn=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),st=(r,e)=>r<<32-e|r>>>e,Db=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Db)throw new Error("Non little-endian hardware is not supported");var Bb=async()=>{};async function $f(r,e,t){let n=Date.now();for(let s=0;s<r;s++){t(s);let o=Date.now()-n;o>=0&&o<e||(await Bb(),n+=o)}}function dc(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function ot(r){if(typeof r=="string"&&(r=dc(r)),!Kf(r))throw new Error(`expected Uint8Array, got ${typeof r}`);return r}function po(...r){let e=0;for(let n=0;n<r.length;n++){let s=r[n];if(!Kf(s))throw new Error("Uint8Array expected");e+=s.length}let t=new Uint8Array(e);for(let n=0,s=0;n<r.length;n++){let o=r[n];t.set(o,s),s+=o.length}return t}var nn=class{clone(){return this._cloneInto()}},Sb={}.toString;function qf(r,e){if(e!==void 0&&Sb.call(e)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(r,e)}function mo(r){let e=n=>r().update(ot(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function Cr(r=32){if(ho&&typeof ho.getRandomValues=="function")return ho.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function kb(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let s=BigInt(32),o=BigInt(4294967295),i=Number(t>>s&o),a=Number(t&o),c=n?4:0,u=n?0:4;r.setUint32(e+c,i,n),r.setUint32(e+u,a,n)}var on=class extends nn{constructor(e,t,n,s){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=s,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=sn(this.buffer)}update(e){rn(this);let{view:t,buffer:n,blockLen:s}=this;e=ot(e);let o=e.length;for(let i=0;i<o;){let a=Math.min(s-this.pos,o-i);if(a===s){let c=sn(e);for(;s<=o-i;i+=s)this.process(c,i);continue}n.set(e.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===s&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){rn(this),Hf(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:s,isLE:o}=this,{pos:i}=this;t[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>s-i&&(this.process(n,0),i=0);for(let f=i;f<s;f++)t[f]=0;kb(n,s-8,BigInt(this.length*8),o),this.process(n,0);let a=sn(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)a.setUint32(4*f,l[f],o)}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:s,finished:o,destroyed:i,pos:a}=this;return e.length=s,e.pos=a,e.finished=o,e.destroyed=i,s%t&&e.buffer.set(n),e}};var go=BigInt(4294967295),pc=BigInt(32);function Wf(r,e=!1){return e?{h:Number(r&go),l:Number(r>>pc&go)}:{h:Number(r>>pc&go)|0,l:Number(r&go)|0}}function Cb(r,e=!1){let t=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let s=0;s<r.length;s++){let{h:o,l:i}=Wf(r[s],e);[t[s],n[s]]=[o,i]}return[t,n]}var Ib=(r,e)=>BigInt(r>>>0)<<pc|BigInt(e>>>0),Tb=(r,e,t)=>r>>>t,_b=(r,e,t)=>r<<32-t|e>>>t,Rb=(r,e,t)=>r>>>t|e<<32-t,Nb=(r,e,t)=>r<<32-t|e>>>t,Lb=(r,e,t)=>r<<64-t|e>>>t-32,Ub=(r,e,t)=>r>>>t-32|e<<64-t,Ob=(r,e)=>e,Pb=(r,e)=>r,Mb=(r,e,t)=>r<<t|e>>>32-t,Fb=(r,e,t)=>e<<t|r>>>32-t,Vb=(r,e,t)=>e<<t-32|r>>>64-t,Hb=(r,e,t)=>r<<t-32|e>>>64-t;function Kb(r,e,t,n){let s=(e>>>0)+(n>>>0);return{h:r+t+(s/2**32|0)|0,l:s|0}}var $b=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),qb=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,Wb=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),zb=(r,e,t,n,s)=>e+t+n+s+(r/2**32|0)|0,Gb=(r,e,t,n,s)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(s>>>0),jb=(r,e,t,n,s,o)=>e+t+n+s+o+(r/2**32|0)|0;var Yb={fromBig:Wf,split:Cb,toBig:Ib,shrSH:Tb,shrSL:_b,rotrSH:Rb,rotrSL:Nb,rotrBH:Lb,rotrBL:Ub,rotr32H:Ob,rotr32L:Pb,rotlSH:Mb,rotlSL:Fb,rotlBH:Vb,rotlBL:Hb,add:Kb,add3L:$b,add3H:qb,add4L:Wb,add4H:zb,add5H:jb,add5L:Gb},Y=Yb;var[Zb,Xb]=Y.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))),tr=new Uint32Array(80),rr=new Uint32Array(80),mc=class extends on{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:s,Ch:o,Cl:i,Dh:a,Dl:c,Eh:u,El:l,Fh:f,Fl:m,Gh:g,Gl:d,Hh:h,Hl:p}=this;return[e,t,n,s,o,i,a,c,u,l,f,m,g,d,h,p]}set(e,t,n,s,o,i,a,c,u,l,f,m,g,d,h,p){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=s|0,this.Ch=o|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=l|0,this.Fh=f|0,this.Fl=m|0,this.Gh=g|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)tr[b]=e.getUint32(t),rr[b]=e.getUint32(t+=4);for(let b=16;b<80;b++){let v=tr[b-15]|0,E=rr[b-15]|0,A=Y.rotrSH(v,E,1)^Y.rotrSH(v,E,8)^Y.shrSH(v,E,7),S=Y.rotrSL(v,E,1)^Y.rotrSL(v,E,8)^Y.shrSL(v,E,7),D=tr[b-2]|0,_=rr[b-2]|0,U=Y.rotrSH(D,_,19)^Y.rotrBH(D,_,61)^Y.shrSH(D,_,6),R=Y.rotrSL(D,_,19)^Y.rotrBL(D,_,61)^Y.shrSL(D,_,6),H=Y.add4L(S,R,rr[b-7],rr[b-16]),V=Y.add4H(H,A,U,tr[b-7],tr[b-16]);tr[b]=V|0,rr[b]=H|0}let{Ah:n,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:u,Dl:l,Eh:f,El:m,Fh:g,Fl:d,Gh:h,Gl:p,Hh:y,Hl:x}=this;for(let b=0;b<80;b++){let v=Y.rotrSH(f,m,14)^Y.rotrSH(f,m,18)^Y.rotrBH(f,m,41),E=Y.rotrSL(f,m,14)^Y.rotrSL(f,m,18)^Y.rotrBL(f,m,41),A=f&g^~f&h,S=m&d^~m&p,D=Y.add5L(x,E,S,Xb[b],rr[b]),_=Y.add5H(D,y,v,A,Zb[b],tr[b]),U=D|0,R=Y.rotrSH(n,s,28)^Y.rotrBH(n,s,34)^Y.rotrBH(n,s,39),H=Y.rotrSL(n,s,28)^Y.rotrBL(n,s,34)^Y.rotrBL(n,s,39),V=n&o^n&a^o&a,G=s&i^s&c^i&c;y=h|0,x=p|0,h=g|0,p=d|0,g=f|0,d=m|0,{h:f,l:m}=Y.add(u|0,l|0,_|0,U|0),u=a|0,l=c|0,a=o|0,c=i|0,o=n|0,i=s|0;let B=Y.add3L(U,H,G);n=Y.add3H(B,_,R,V),s=B|0}({h:n,l:s}=Y.add(this.Ah|0,this.Al|0,n|0,s|0)),{h:o,l:i}=Y.add(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=Y.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=Y.add(this.Dh|0,this.Dl|0,u|0,l|0),{h:f,l:m}=Y.add(this.Eh|0,this.El|0,f|0,m|0),{h:g,l:d}=Y.add(this.Fh|0,this.Fl|0,g|0,d|0),{h,l:p}=Y.add(this.Gh|0,this.Gl|0,h|0,p|0),{h:y,l:x}=Y.add(this.Hh|0,this.Hl|0,y|0,x|0),this.set(n,s,o,i,a,c,u,l,f,m,g,d,h,p,y,x)}roundClean(){tr.fill(0),rr.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 an=mo(()=>new mc);var yo={};J(yo,{bitGet:()=>sy,bitLen:()=>ny,bitMask:()=>Gn,bitSet:()=>oy,bytesToHex:()=>Rt,bytesToNumberBE:()=>Nt,bytesToNumberLE:()=>at,concatBytes:()=>Ut,createHmacDrbg:()=>yc,ensureBytes:()=>ie,equalBytes:()=>ty,hexToBytes:()=>Ir,hexToNumber:()=>bc,isBytes:()=>it,numberToBytesBE:()=>nr,numberToBytesLE:()=>Lt,numberToHexUnpadded:()=>Yf,numberToVarBytesBE:()=>ey,utf8ToBytes:()=>ry,validateObject:()=>Ye});var jf=BigInt(0),bo=BigInt(1),Jb=BigInt(2);function it(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var Qb=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function Rt(r){if(!it(r))throw new Error("Uint8Array expected");let e="";for(let t=0;t<r.length;t++)e+=Qb[r[t]];return e}function Yf(r){let e=r.toString(16);return e.length&1?`0${e}`:e}function bc(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var _t={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function zf(r){if(r>=_t._0&&r<=_t._9)return r-_t._0;if(r>=_t._A&&r<=_t._F)return r-(_t._A-10);if(r>=_t._a&&r<=_t._f)return r-(_t._a-10)}function Ir(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 s=0,o=0;s<t;s++,o+=2){let i=zf(r.charCodeAt(o)),a=zf(r.charCodeAt(o+1));if(i===void 0||a===void 0){let c=r[o]+r[o+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+o)}n[s]=i*16+a}return n}function Nt(r){return bc(Rt(r))}function at(r){if(!it(r))throw new Error("Uint8Array expected");return bc(Rt(Uint8Array.from(r).reverse()))}function nr(r,e){return Ir(r.toString(16).padStart(e*2,"0"))}function Lt(r,e){return nr(r,e).reverse()}function ey(r){return Ir(Yf(r))}function ie(r,e,t){let n;if(typeof e=="string")try{n=Ir(e)}catch(o){throw new Error(`${r} must be valid hex string, got "${e}". Cause: ${o}`)}else if(it(e))n=Uint8Array.from(e);else throw new Error(`${r} must be hex string or Uint8Array`);let s=n.length;if(typeof t=="number"&&s!==t)throw new Error(`${r} expected ${t} bytes, got ${s}`);return n}function Ut(...r){let e=0;for(let s=0;s<r.length;s++){let o=r[s];if(!it(o))throw new Error("Uint8Array expected");e+=o.length}let t=new Uint8Array(e),n=0;for(let s=0;s<r.length;s++){let o=r[s];t.set(o,n),n+=o.length}return t}function ty(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 ry(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function ny(r){let e;for(e=0;r>jf;r>>=bo,e+=1);return e}function sy(r,e){return r>>BigInt(e)&bo}var oy=(r,e,t)=>r|(t?bo:jf)<<BigInt(e),Gn=r=>(Jb<<BigInt(r-1))-bo,gc=r=>new Uint8Array(r),Gf=r=>Uint8Array.from(r);function yc(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=gc(r),s=gc(r),o=0,i=()=>{n.fill(1),s.fill(0),o=0},a=(...f)=>t(s,n,...f),c=(f=gc())=>{s=a(Gf([0]),f),n=a(),f.length!==0&&(s=a(Gf([1]),f),n=a())},u=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,m=[];for(;f<e;){n=a();let g=n.slice();m.push(g),f+=n.length}return Ut(...m)};return(f,m)=>{i(),c(f);let g;for(;!(g=m(u()));)c();return i(),g}}var iy={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"||it(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 Ye(r,e,t={}){let n=(s,o,i)=>{let a=iy[o];if(typeof a!="function")throw new Error(`Invalid validator "${o}", expected function`);let c=r[s];if(!(i&&c===void 0)&&!a(c,r))throw new Error(`Invalid param ${String(s)}=${c} (${typeof c}), expected ${o}`)};for(let[s,o]of Object.entries(e))n(s,o,!1);for(let[s,o]of Object.entries(t))n(s,o,!0);return r}var Se=BigInt(0),ue=BigInt(1),Tr=BigInt(2),ay=BigInt(3),wc=BigInt(4),Zf=BigInt(5),Xf=BigInt(8),cy=BigInt(9),uy=BigInt(16);function ee(r,e){let t=r%e;return t>=Se?t:e+t}function xc(r,e,t){if(t<=Se||e<Se)throw new Error("Expected power/modulo > 0");if(t===ue)return Se;let n=ue;for(;e>Se;)e&ue&&(n=n*r%t),r=r*r%t,e>>=ue;return n}function ae(r,e,t){let n=r;for(;e-- >Se;)n*=n,n%=t;return n}function wo(r,e){if(r===Se||e<=Se)throw new Error(`invert: expected positive integers, got n=${r} mod=${e}`);let t=ee(r,e),n=e,s=Se,o=ue,i=ue,a=Se;for(;t!==Se;){let u=n/t,l=n%t,f=s-i*u,m=o-a*u;n=t,t=l,s=i,o=a,i=f,a=m}if(n!==ue)throw new Error("invert: does not exist");return ee(s,e)}function ly(r){let e=(r-ue)/Tr,t,n,s;for(t=r-ue,n=0;t%Tr===Se;t/=Tr,n++);for(s=Tr;s<r&&xc(s,e,r)!==r-ue;s++);if(n===1){let i=(r+ue)/wc;return function(c,u){let l=c.pow(u,i);if(!c.eql(c.sqr(l),u))throw new Error("Cannot find square root");return l}}let o=(t+ue)/Tr;return function(a,c){if(a.pow(c,e)===a.neg(a.ONE))throw new Error("Cannot find square root");let u=n,l=a.pow(a.mul(a.ONE,s),t),f=a.pow(c,o),m=a.pow(c,t);for(;!a.eql(m,a.ONE);){if(a.eql(m,a.ZERO))return a.ZERO;let g=1;for(let h=a.sqr(m);g<u&&!a.eql(h,a.ONE);g++)h=a.sqr(h);let d=a.pow(l,ue<<BigInt(u-g-1));l=a.sqr(d),f=a.mul(f,d),m=a.mul(m,l),u=g}return f}}function fy(r){if(r%wc===ay){let e=(r+ue)/wc;return function(n,s){let o=n.pow(s,e);if(!n.eql(n.sqr(o),s))throw new Error("Cannot find square root");return o}}if(r%Xf===Zf){let e=(r-Zf)/Xf;return function(n,s){let o=n.mul(s,Tr),i=n.pow(o,e),a=n.mul(s,i),c=n.mul(n.mul(a,Tr),i),u=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(u),s))throw new Error("Cannot find square root");return u}}return r%uy,ly(r)}var Jf=(r,e)=>(ee(r,e)&ue)===ue,hy=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ec(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=hy.reduce((n,s)=>(n[s]="function",n),e);return Ye(r,t)}function dy(r,e,t){if(t<Se)throw new Error("Expected power > 0");if(t===Se)return r.ONE;if(t===ue)return e;let n=r.ONE,s=e;for(;t>Se;)t&ue&&(n=r.mul(n,s)),s=r.sqr(s),t>>=ue;return n}function py(r,e){let t=new Array(e.length),n=e.reduce((o,i,a)=>r.is0(i)?o:(t[a]=o,r.mul(o,i)),r.ONE),s=r.inv(n);return e.reduceRight((o,i,a)=>r.is0(i)?o:(t[a]=r.mul(o,t[a]),r.mul(o,i)),s),t}function vc(r,e){let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function xo(r,e,t=!1,n={}){if(r<=Se)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:s,nByteLength:o}=vc(r,e);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");let i=fy(r),a=Object.freeze({ORDER:r,BITS:s,BYTES:o,MASK:Gn(s),ZERO:Se,ONE:ue,create:c=>ee(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return Se<=c&&c<r},is0:c=>c===Se,isOdd:c=>(c&ue)===ue,neg:c=>ee(-c,r),eql:(c,u)=>c===u,sqr:c=>ee(c*c,r),add:(c,u)=>ee(c+u,r),sub:(c,u)=>ee(c-u,r),mul:(c,u)=>ee(c*u,r),pow:(c,u)=>dy(a,c,u),div:(c,u)=>ee(c*wo(u,r),r),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>wo(c,r),sqrt:n.sqrt||(c=>i(a,c)),invertBatch:c=>py(a,c),cmov:(c,u,l)=>l?u:c,toBytes:c=>t?Lt(c,o):nr(c,o),fromBytes:c=>{if(c.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${c.length}`);return t?at(c):Nt(c)}});return Object.freeze(a)}function Qf(r,e){if(!r.isOdd)throw new Error("Field doesn't have isOdd");let t=r.sqrt(e);return r.isOdd(t)?r.neg(t):t}function eh(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 Ac(r){let e=eh(r);return e+Math.ceil(e/2)}function th(r,e,t=!1){let n=r.length,s=eh(e),o=Ac(e);if(n<16||n<o||n>1024)throw new Error(`expected ${o}-1024 bytes of input, got ${n}`);let i=t?Nt(r):at(r),a=ee(i,e-ue)+ue;return t?Lt(a,s):nr(a,s)}var gy=BigInt(0),Dc=BigInt(1);function Eo(r,e){let t=(s,o)=>{let i=o.negate();return s?i:o},n=s=>{let o=Math.ceil(e/s)+1,i=2**(s-1);return{windows:o,windowSize:i}};return{constTimeNegate:t,unsafeLadder(s,o){let i=r.ZERO,a=s;for(;o>gy;)o&Dc&&(i=i.add(a)),a=a.double(),o>>=Dc;return i},precomputeWindow(s,o){let{windows:i,windowSize:a}=n(o),c=[],u=s,l=u;for(let f=0;f<i;f++){l=u,c.push(l);for(let m=1;m<a;m++)l=l.add(u),c.push(l);u=l.double()}return c},wNAF(s,o,i){let{windows:a,windowSize:c}=n(s),u=r.ZERO,l=r.BASE,f=BigInt(2**s-1),m=2**s,g=BigInt(s);for(let d=0;d<a;d++){let h=d*c,p=Number(i&f);i>>=g,p>c&&(p-=m,i+=Dc);let y=h,x=h+Math.abs(p)-1,b=d%2!==0,v=p<0;p===0?l=l.add(t(b,o[y])):u=u.add(t(v,o[x]))}return{p:u,f:l}},wNAFCached(s,o,i,a){let c=s._WINDOW_SIZE||1,u=o.get(s);return u||(u=this.precomputeWindow(s,c),c!==1&&o.set(s,a(u))),this.wNAF(c,u,i)}}}function jn(r){return Ec(r.Fp),Ye(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...vc(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var ct=BigInt(0),ze=BigInt(1),vo=BigInt(2),by=BigInt(8),yy={zip215:!0};function wy(r){let e=jn(r);return Ye(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function Ao(r){let e=wy(r),{Fp:t,n,prehash:s,hash:o,randomBytes:i,nByteLength:a,h:c}=e,u=vo<<BigInt(a*8)-ze,l=t.create,f=e.uvRatio||((k,w)=>{try{return{isValid:!0,value:t.sqrt(k*t.inv(w))}}catch{return{isValid:!1,value:ct}}}),m=e.adjustScalarBytes||(k=>k),g=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"&&ct<k,h=(k,w)=>d(k)&&d(w)&&k<w,p=k=>k===ct||h(k,u);function y(k,w){if(h(k,w))return k;throw new Error(`Expected valid scalar < ${w}, got ${typeof k} ${k}`)}function x(k){return k===ct?k:y(k,n)}let b=new Map;function v(k){if(!(k instanceof E))throw new Error("ExtendedPoint expected")}class E{constructor(w,C,T,O){if(this.ex=w,this.ey=C,this.ez=T,this.et=O,!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(O))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(w){if(w instanceof E)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 E(C,T,ze,l(C*T))}static normalizeZ(w){let C=t.invertBatch(w.map(T=>T.ez));return w.map((T,O)=>T.toAffine(C[O])).map(E.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:O,ez:$,et:q}=this,Z=l(T*T),W=l(O*O),j=l($*$),oe=l(j*j),se=l(Z*w),Ce=l(j*l(se+W)),Ie=l(oe+l(C*l(Z*W)));if(Ce!==Ie)throw new Error("bad point: equation left != right (1)");let Ee=l(T*O),Le=l($*q);if(Ee!==Le)throw new Error("bad point: equation left != right (2)")}equals(w){v(w);let{ex:C,ey:T,ez:O}=this,{ex:$,ey:q,ez:Z}=w,W=l(C*Z),j=l($*O),oe=l(T*Z),se=l(q*O);return W===j&&oe===se}is0(){return this.equals(E.ZERO)}negate(){return new E(l(-this.ex),this.ey,this.ez,l(-this.et))}double(){let{a:w}=e,{ex:C,ey:T,ez:O}=this,$=l(C*C),q=l(T*T),Z=l(vo*l(O*O)),W=l(w*$),j=C+T,oe=l(l(j*j)-$-q),se=W+q,Ce=se-Z,Ie=W-q,Ee=l(oe*Ce),Le=l(se*Ie),Dt=l(oe*Ie),dr=l(Ce*se);return new E(Ee,Le,dr,Dt)}add(w){v(w);let{a:C,d:T}=e,{ex:O,ey:$,ez:q,et:Z}=this,{ex:W,ey:j,ez:oe,et:se}=w;if(C===BigInt(-1)){let Gu=l(($-O)*(j+W)),ju=l(($+O)*(j-W)),Pi=l(ju-Gu);if(Pi===ct)return this.double();let Yu=l(q*vo*se),Zu=l(Z*vo*oe),Xu=Zu+Yu,Ju=ju+Gu,Qu=Zu-Yu,Lp=l(Xu*Pi),Up=l(Ju*Qu),Op=l(Xu*Qu),Pp=l(Pi*Ju);return new E(Lp,Up,Pp,Op)}let Ce=l(O*W),Ie=l($*j),Ee=l(Z*T*se),Le=l(q*oe),Dt=l((O+$)*(W+j)-Ce-Ie),dr=Le-Ee,Rn=Le+Ee,zu=l(Ie-C*Ce),Tp=l(Dt*dr),_p=l(Rn*zu),Rp=l(Dt*zu),Np=l(dr*Rn);return new E(Tp,_p,Np,Rp)}subtract(w){return this.add(w.negate())}wNAF(w){return D.wNAFCached(this,b,w,E.normalizeZ)}multiply(w){let{p:C,f:T}=this.wNAF(y(w,n));return E.normalizeZ([C,T])[0]}multiplyUnsafe(w){let C=x(w);return C===ct?S:this.equals(S)||C===ze?this:this.equals(A)?this.wNAF(C).p:D.unsafeLadder(this,C)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return D.unsafeLadder(this,n).is0()}toAffine(w){let{ex:C,ey:T,ez:O}=this,$=this.is0();w==null&&(w=$?by:t.inv(O));let q=l(C*w),Z=l(T*w),W=l(O*w);if($)return{x:ct,y:ze};if(W!==ze)throw new Error("invZ was invalid");return{x:q,y:Z}}clearCofactor(){let{h:w}=e;return w===ze?this:this.multiplyUnsafe(w)}static fromHex(w,C=!1){let{d:T,a:O}=e,$=t.BYTES;w=ie("pointHex",w,$);let q=w.slice(),Z=w[$-1];q[$-1]=Z&-129;let W=at(q);W===ct||(C?y(W,u):y(W,t.ORDER));let j=l(W*W),oe=l(j-ze),se=l(T*j-O),{isValid:Ce,value:Ie}=f(oe,se);if(!Ce)throw new Error("Point.fromHex: invalid y coordinate");let Ee=(Ie&ze)===ze,Le=(Z&128)!==0;if(!C&&Ie===ct&&Le)throw new Error("Point.fromHex: x=0 and x_0=1");return Le!==Ee&&(Ie=l(-Ie)),E.fromAffine({x:Ie,y:W})}static fromPrivateKey(w){return R(w).point}toRawBytes(){let{x:w,y:C}=this.toAffine(),T=Lt(C,t.BYTES);return T[T.length-1]|=w&ze?128:0,T}toHex(){return Rt(this.toRawBytes())}}E.BASE=new E(e.Gx,e.Gy,ze,l(e.Gx*e.Gy)),E.ZERO=new E(ct,ze,ze,ct);let{BASE:A,ZERO:S}=E,D=Eo(E,a*8);function _(k){return ee(k,n)}function U(k){return _(at(k))}function R(k){let w=a;k=ie("private key",k,w);let C=ie("hashed private key",o(k),2*w),T=m(C.slice(0,w)),O=C.slice(w,2*w),$=U(T),q=A.multiply($),Z=q.toRawBytes();return{head:T,prefix:O,scalar:$,point:q,pointBytes:Z}}function H(k){return R(k).pointBytes}function V(k=new Uint8Array,...w){let C=Ut(...w);return U(o(g(C,ie("context",k),!!s)))}function G(k,w,C={}){k=ie("message",k),s&&(k=s(k));let{prefix:T,scalar:O,pointBytes:$}=R(w),q=V(C.context,T,k),Z=A.multiply(q).toRawBytes(),W=V(C.context,Z,$,k),j=_(q+W*O);x(j);let oe=Ut(Z,Lt(j,t.BYTES));return ie("result",oe,a*2)}let B=yy;function I(k,w,C,T=B){let{context:O,zip215:$}=T,q=t.BYTES;k=ie("signature",k,2*q),w=ie("message",w),s&&(w=s(w));let Z=at(k.slice(q,2*q)),W,j,oe;try{W=E.fromHex(C,$),j=E.fromHex(k.slice(0,q),$),oe=A.multiplyUnsafe(Z)}catch{return!1}if(!$&&W.isSmallOrder())return!1;let se=V(O,j.toRawBytes(),W.toRawBytes(),w);return j.add(W.multiplyUnsafe(se)).subtract(oe).clearCofactor().equals(E.ZERO)}return A._setWindowSize(8),{CURVE:e,getPublicKey:H,sign:G,verify:I,ExtendedPoint:E,utils:{getExtendedPublicKey:R,randomPrivateKey:()=>i(t.BYTES),precompute(k=8,w=E.BASE){return w._setWindowSize(k),w.multiply(BigInt(3)),w}}}}var Yn=BigInt(0),Bc=BigInt(1);function xy(r){return Ye(r,{a:"bigint"},{montgomeryBits:"isSafeInteger",nByteLength:"isSafeInteger",adjustScalarBytes:"function",domain:"function",powPminus2:"function",Gu:"bigint"}),Object.freeze({...r})}function rh(r){let e=xy(r),{P:t}=e,n=b=>ee(b,t),s=e.montgomeryBits,o=Math.ceil(s/8),i=e.nByteLength,a=e.adjustScalarBytes||(b=>b),c=e.powPminus2||(b=>xc(b,t-BigInt(2),t));function u(b,v,E){let A=n(b*(v-E));return v=n(v-A),E=n(E+A),[v,E]}function l(b){if(typeof b=="bigint"&&Yn<=b&&b<t)return b;throw new Error("Expected valid scalar 0 < scalar < CURVE.P")}let f=(e.a-BigInt(2))/BigInt(4);function m(b,v){let E=l(b),A=l(v),S=E,D=Bc,_=Yn,U=E,R=Bc,H=Yn,V;for(let B=BigInt(s-1);B>=Yn;B--){let I=A>>B&Bc;H^=I,V=u(H,D,U),D=V[0],U=V[1],V=u(H,_,R),_=V[0],R=V[1],H=I;let P=D+_,k=n(P*P),w=D-_,C=n(w*w),T=k-C,O=U+R,$=U-R,q=n($*P),Z=n(O*w),W=q+Z,j=q-Z;U=n(W*W),R=n(S*n(j*j)),D=n(k*C),_=n(T*(k+n(f*T)))}V=u(H,D,U),D=V[0],U=V[1],V=u(H,_,R),_=V[0],R=V[1];let G=c(_);return n(D*G)}function g(b){return Lt(n(b),o)}function d(b){let v=ie("u coordinate",b,o);return i===32&&(v[31]&=127),at(v)}function h(b){let v=ie("scalar",b),E=v.length;if(E!==o&&E!==i)throw new Error(`Expected ${o} or ${i} bytes, got ${E}`);return at(a(v))}function p(b,v){let E=d(v),A=h(b),S=m(E,A);if(S===Yn)throw new Error("Invalid private or public key received");return g(S)}let y=g(e.Gu);function x(b){return p(b,y)}return{scalarMult:p,scalarMultBase:x,getSharedSecret:(b,v)=>p(b,v),getPublicKey:b=>x(b),utils:{randomPrivateKey:()=>e.randomBytes(e.nByteLength)},GuBytes:y}}var Zn=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),nh=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),TD=BigInt(0),Ey=BigInt(1),Sc=BigInt(2),vy=BigInt(5),sh=BigInt(10),Ay=BigInt(20),Dy=BigInt(40),oh=BigInt(80);function ih(r){let e=Zn,n=r*r%e*r%e,s=ae(n,Sc,e)*n%e,o=ae(s,Ey,e)*r%e,i=ae(o,vy,e)*o%e,a=ae(i,sh,e)*i%e,c=ae(a,Ay,e)*a%e,u=ae(c,Dy,e)*c%e,l=ae(u,oh,e)*u%e,f=ae(l,oh,e)*u%e,m=ae(f,sh,e)*i%e;return{pow_p_5_8:ae(m,Sc,e)*r%e,b2:n}}function ah(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function By(r,e){let t=Zn,n=ee(e*e*e,t),s=ee(n*n*e,t),o=ih(r*s).pow_p_5_8,i=ee(r*n*o,t),a=ee(e*i*i,t),c=i,u=ee(i*nh,t),l=a===r,f=a===ee(-r,t),m=a===ee(-r*nh,t);return l&&(i=c),(f||m)&&(i=u),Jf(i,t)&&(i=ee(-i,t)),{isValid:l||f,value:i}}var Ot=xo(Zn,void 0,!0),kc={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Ot,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:an,randomBytes:Cr,adjustScalarBytes:ah,uvRatio:By},cn=Ao(kc);function ch(r,e,t){if(e.length>255)throw new Error("Context is too big");return po(dc("SigEd25519 no Ed25519 collisions"),new Uint8Array([t?1:0,e.length]),e,r)}var _D=Ao({...kc,domain:ch}),RD=Ao({...kc,domain:ch,prehash:an}),Xn=rh({P:Zn,a:BigInt(486662),montgomeryBits:255,nByteLength:32,Gu:BigInt(9),powPminus2:r=>{let e=Zn,{pow_p_5_8:t,b2:n}=ih(r);return ee(ae(t,BigInt(3),e)*n,e)},adjustScalarBytes:ah,randomBytes:Cr});var Sy=(Ot.ORDER+BigInt(3))/BigInt(8),ND=Ot.pow(Sc,Sy),LD=Ot.sqrt(Ot.neg(Ot.ONE)),UD=(Ot.ORDER-BigInt(5))/BigInt(8),OD=BigInt(486662);var PD=Qf(Ot,Ot.neg(BigInt(486664)));var MD=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),FD=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),VD=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),HD=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");var KD=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var un=32,Pt=64,Do=32;function uh(){let r=cn.utils.randomPrivateKey(),e=cn.getPublicKey(r);return{privateKey:dh(r,e),publicKey:e}}function lh(r){if(r.length!==Do)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=cn.getPublicKey(e);return{privateKey:dh(e,t),publicKey:t}}function fh(r,e){let t=r.subarray(0,Do);return cn.sign(e instanceof Uint8Array?e:e.subarray(),t)}function hh(r,e,t){return cn.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}function dh(r,e){let t=new Uint8Array(Pt);for(let n=0;n<Do;n++)t[n]=r[n],t[Do+n]=e[n];return t}var Me={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 Cc={alg:"A128GCM",ext:!0,k:"scm9jmO_4BJAgdwWGVulLg",key_ops:["encrypt","decrypt"],kty:"oct"};function ph(r){let e=r?.algorithm??"AES-GCM",t=r?.keyLength??16,n=r?.nonceLength??12,s=r?.digest??"SHA-256",o=r?.saltLength??16,i=r?.iterations??32767,a=Me.get();t*=8;async function c(f,m){let g=a.getRandomValues(new Uint8Array(o)),d=a.getRandomValues(new Uint8Array(n)),h={name:e,iv:d};typeof m=="string"&&(m=Q(m));let p;if(m.length===0){p=await a.subtle.importKey("jwk",Cc,{name:"AES-GCM"},!0,["encrypt"]);try{let x={name:"PBKDF2",salt:g,iterations:i,hash:{name:s}},b=await a.subtle.importKey("raw",m,{name:"PBKDF2"},!1,["deriveKey"]);p=await a.subtle.deriveKey(x,b,{name:e,length:t},!0,["encrypt"])}catch{p=await a.subtle.importKey("jwk",Cc,{name:"AES-GCM"},!0,["encrypt"])}}else{let x={name:"PBKDF2",salt:g,iterations:i,hash:{name:s}},b=await a.subtle.importKey("raw",m,{name:"PBKDF2"},!1,["deriveKey"]);p=await a.subtle.deriveKey(x,b,{name:e,length:t},!0,["encrypt"])}let y=await a.subtle.encrypt(h,p,f);return we([g,h.iv,new Uint8Array(y)])}async function u(f,m){let g=f.subarray(0,o),d=f.subarray(o,o+n),h=f.subarray(o+n),p={name:e,iv:d};typeof m=="string"&&(m=Q(m));let y;if(m.length===0)try{let b={name:"PBKDF2",salt:g,iterations:i,hash:{name:s}},v=await a.subtle.importKey("raw",m,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(b,v,{name:e,length:t},!0,["decrypt"])}catch{y=await a.subtle.importKey("jwk",Cc,{name:"AES-GCM"},!0,["decrypt"])}else{let b={name:"PBKDF2",salt:g,iterations:i,hash:{name:s}},v=await a.subtle.importKey("raw",m,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(b,v,{name:e,length:t},!0,["decrypt"])}let x=await a.subtle.decrypt(p,y,h);return new Uint8Array(x)}return{encrypt:c,decrypt:u}}async function ln(r,e){let n=await ph().encrypt(r,e);return Zi.encode(n)}var le;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.Secp256k1="Secp256k1"})(le||(le={}));var Ic;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.Secp256k1=2]="Secp256k1"})(Ic||(Ic={}));(function(r){r.codec=()=>Ar(Ic)})(le||(le={}));var yt;(function(r){let e;r.codec=()=>(e==null&&(e=nt((t,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),le.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),s.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let s={},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let i=t.uint32();switch(i>>>3){case 1:s.Type=le.codec().decode(t);break;case 2:s.Data=t.bytes();break;default:t.skipType(i&7);break}}return s})),e),r.encode=t=>rt(t,r.codec()),r.decode=t=>tt(t,r.codec())})(yt||(yt={}));var wt;(function(r){let e;r.codec=()=>(e==null&&(e=nt((t,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),le.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),s.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let s={},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let i=t.uint32();switch(i>>>3){case 1:s.Type=le.codec().decode(t);break;case 2:s.Data=t.bytes();break;default:t.skipType(i&7);break}}return s})),e),r.encode=t=>rt(t,r.codec()),r.decode=t=>tt(t,r.codec())})(wt||(wt={}));var Jn=class{_key;constructor(e){this._key=fn(e,un)}verify(e,t){return hh(this._key,t,e)}marshal(){return this._key}get bytes(){return yt.encode({Type:le.Ed25519,Data:this.marshal()}).subarray()}equals(e){return ve(this.bytes,e.bytes)}hash(){let e=Te.digest(this.bytes);return je(e)?e.then(({bytes:t})=>t):e.bytes}},_r=class{_key;_publicKey;constructor(e,t){this._key=fn(e,Pt),this._publicKey=fn(t,un)}sign(e){return fh(this._key,e)}get public(){return new Jn(this._publicKey)}marshal(){return this._key}get bytes(){return wt.encode({Type:le.Ed25519,Data:this.marshal()}).subarray()}equals(e){return ve(this.bytes,e.bytes)}async hash(){let e=Te.digest(this.bytes),t;return je(e)?{bytes:t}=await e:t=e.bytes,t}async id(){let e=Yt.digest(this.public.bytes);return pe.encode(e.bytes).substring(1)}async export(e,t="libp2p-key"){if(t==="libp2p-key")return ln(this.bytes,e);throw new N(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function Iy(r){if(r.length>Pt){r=fn(r,Pt+un);let n=r.subarray(0,Pt),s=r.subarray(Pt,r.length);return new _r(n,s)}r=fn(r,Pt);let e=r.subarray(0,Pt),t=r.subarray(un);return new _r(e,t)}function Ty(r){return r=fn(r,un),new Jn(r)}async function _y(){let{privateKey:r,publicKey:e}=uh();return new _r(r,e)}async function mh(r){let{privateKey:e,publicKey:t}=lh(r);return new _r(e,t)}function fn(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new N(`Key must be a Uint8Array of length ${e}, got ${r.length}`,"ERR_INVALID_KEY_TYPE");return r}var Vc={};J(Vc,{MAX_RSA_KEY_SIZE:()=>us,RsaPrivateKey:()=>gn,RsaPublicKey:()=>cs,fromJwk:()=>sw,generateKeyPair:()=>ow,unmarshalRsaPrivateKey:()=>Mc,unmarshalRsaPublicKey:()=>nw});function Rr(r){if(isNaN(r)||r<=0)throw new N("random bytes length must be a Number bigger than 0","ERR_INVALID_LENGTH");return Cr(r)}var cr={};J(cr,{exportToPem:()=>Jy,importFromPem:()=>Qy,jwkToPkcs1:()=>jy,jwkToPkix:()=>Zy,pkcs1ToJwk:()=>Gy,pkixToJwk:()=>Yy});var So=class extends nn{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,kr(e);let n=ot(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 s=this.blockLen,o=new Uint8Array(s);o.set(n.length>s?e.create().update(n).digest():n);for(let i=0;i<o.length;i++)o[i]^=54;this.iHash.update(o),this.oHash=e.create();for(let i=0;i<o.length;i++)o[i]^=106;this.oHash.update(o),o.fill(0)}update(e){return rn(this),this.iHash.update(e),this}digestInto(e){rn(this),hc(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:s,destroyed:o,blockLen:i,outputLen:a}=this;return e=e,e.finished=s,e.destroyed=o,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()}},sr=(r,e,t)=>new So(r,e).update(t).digest();sr.create=(r,e)=>new So(r,e);function Ry(r,e,t,n){kr(r);let s=qf({dkLen:32,asyncTick:10},n),{c:o,dkLen:i,asyncTick:a}=s;if(er(o),er(i),er(a),o<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let c=ot(e),u=ot(t),l=new Uint8Array(i),f=sr.create(r,c),m=f._cloneInto().update(u);return{c:o,dkLen:i,asyncTick:a,DK:l,PRF:f,PRFSalt:m}}function Ny(r,e,t,n,s){return r.destroy(),e.destroy(),n&&n.destroy(),s.fill(0),t}async function _c(r,e,t,n){let{c:s,dkLen:o,asyncTick:i,DK:a,PRF:c,PRFSalt:u}=Ry(r,e,t,n),l,f=new Uint8Array(4),m=sn(f),g=new Uint8Array(c.outputLen);for(let d=1,h=0;h<o;d++,h+=c.outputLen){let p=a.subarray(h,h+c.outputLen);m.setInt32(0,d,!1),(l=u._cloneInto(l)).update(f).digestInto(g),p.set(g.subarray(0,p.length)),await $f(s-1,i,()=>{c._cloneInto(l).update(g).digestInto(g);for(let y=0;y<p.length;y++)p[y]^=g[y]})}return Ny(c,u,a,l,g)}var X=Ds(gh());function Nr(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 or(r,e,t=-1){let n=t,s=r,o=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),o=a;else{if(n<a)return new ArrayBuffer(0);c=new ArrayBuffer(n),o=n}let u=new Uint8Array(c);for(let l=a-1;l>=0;l--){let f=Math.pow(2,l*e);u[o-l-1]=Math.floor(s/f),s-=u[o-l-1]*f}return c}i*=Math.pow(2,e)}return new ArrayBuffer(0)}function Io(...r){let e=0,t=0;for(let o of r)e+=o.length;let n=new ArrayBuffer(e),s=new Uint8Array(n);for(let o of r)s.set(o,t),t+=o.length;return s}function Nc(){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=Nr(t,8),s=new ArrayBuffer(this.valueHex.byteLength),o=new Uint8Array(s);for(let a=0;a<this.valueHex.byteLength;a++)o[a]=r[a];return o[0]&=127,Nr(o,8)-n}function bh(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=or(i,8,n),c=new Uint8Array(a);return c[0]|=128,a}let s=or(e,8,n),o=new Uint8Array(s);if(o[0]&128){let i=s.slice(0),a=new Uint8Array(i);s=new ArrayBuffer(s.byteLength+1),o=new Uint8Array(s);for(let c=0;c<i.byteLength;c++)o[c+1]=a[c];o[0]=0}return s}t*=Math.pow(2,8)}return new ArrayBuffer(0)}function yh(r,e){if(r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let s=0;s<t.length;s++)if(t[s]!==n[s])return!1;return!0}function $e(r,e){let t=r.toString(10);if(e<t.length)return"";let n=e-t.length,s=new Array(n);for(let i=0;i<n;i++)s[i]="0";return s.join("").concat(t)}var g4=Math.log(2);function To(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function Lc(r){let e=0,t=0;for(let s=0;s<r.length;s++){let o=r[s];e+=o.byteLength}let n=new Uint8Array(e);for(let s=0;s<r.length;s++){let o=r[s];n.set(new Uint8Array(o),t),t+=o.byteLength}return n.buffer}function Kt(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 es=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return Lc(this.items)}},Qn=[new Uint8Array([1])],wh="0123456789";var pn="",lt=new ArrayBuffer(0),Uc=new Uint8Array(0),ts="EndOfContent",Eh="OCTET STRING",vh="BIT STRING";function $t(r){var e;return e=class extends r{constructor(...n){var s;super(...n);let o=n[0]||{};this.isHexOnly=(s=o.isHexOnly)!==null&&s!==void 0?s:!1,this.valueHexView=o.valueHex?X.BufferSourceConverter.toUint8Array(o.valueHex):Uc}get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}fromBER(n,s,o){let i=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!Kt(this,i,s,o))return-1;let a=s+o;return this.valueHexView=i.subarray(s,a),this.valueHexView.length?(this.blockLength=o,a):(this.warnings.push("Zero buffer length"),s)}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",lt)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:X.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var Ft=class{constructor({blockLength:e=0,error:t=pn,warnings:n=[],valueBeforeDecode:s=Uc}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=X.BufferSourceConverter.toUint8Array(s)}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)}}};Ft.NAME="baseBlock";var Pe=class extends Ft{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'")}};Pe.NAME="valueBlock";var _o=class extends $t(Ft){constructor({idBlock:e={}}={}){var t,n,s,o;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?X.BufferSourceConverter.toUint8Array(e.valueHex):Uc,this.tagClass=(n=e.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(s=e.tagNumber)!==null&&s!==void 0?s:-1,this.isConstructed=(o=e.isConstructed)!==null&&o!==void 0?o:!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",lt}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){let s=new Uint8Array(1);if(!e){let o=this.tagNumber;o&=31,t|=o,s[0]=t}return s.buffer}if(!this.isHexOnly){let s=or(this.tagNumber,7),o=new Uint8Array(s),i=s.byteLength,a=new Uint8Array(i+1);if(a[0]=t|31,!e){for(let c=0;c<i-1;c++)a[c+1]=o[c]|128;a[i]=o[i-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=t|31,!e){let s=this.valueHexView;for(let o=0;o<s.length-1;o++)n[o+1]=s[o]|128;n[this.valueHexView.byteLength]=s[s.length-1]}return n.buffer}fromBER(e,t,n){let s=X.BufferSourceConverter.toUint8Array(e);if(!Kt(this,s,t,n))return-1;let o=s.subarray(t,t+n);if(o.length===0)return this.error="Zero buffer length",-1;switch(o[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=(o[0]&32)===32,this.isHexOnly=!1;let a=o[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=1,u=this.valueHexView=new Uint8Array(255),l=255;for(;o[c]&128;){if(u[c-1]=o[c]&127,c++,c>=o.length)return this.error="End of input reached before message was fully decoded",-1;if(c===l){l+=255;let m=new Uint8Array(l);for(let g=0;g<u.length;g++)m[g]=u[g];u=this.valueHexView=new Uint8Array(l)}}this.blockLength=c+1,u[c-1]=o[c]&127;let f=new Uint8Array(c);for(let m=0;m<c;m++)f[m]=u[m];u=this.valueHexView=new Uint8Array(c),u.set(f),this.blockLength<=9?this.tagNumber=Nr(u,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}}};_o.NAME="identificationBlock";var Ro=class extends Ft{constructor({lenBlock:e={}}={}){var t,n,s;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=(s=e.length)!==null&&s!==void 0?s:0}fromBER(e,t,n){let s=X.BufferSourceConverter.toUint8Array(e);if(!Kt(this,s,t,n))return-1;let o=s.subarray(t,t+n);if(o.length===0)return this.error="Zero buffer length",-1;if(o[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=o[0]===128,this.isIndefiniteForm)return this.blockLength=1,t+this.blockLength;if(this.longFormUsed=!!(o[0]&128),this.longFormUsed===!1)return this.length=o[0],this.blockLength=1,t+this.blockLength;let i=o[0]&127;if(i>8)return this.error="Too big integer",-1;if(i+1>o.length)return this.error="End of input reached before message was fully decoded",-1;let a=t+1,c=s.subarray(a,a+i);return c[i-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=Nr(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 s=or(this.length,8);if(s.byteLength>127)return this.error="Too big length",lt;if(t=new ArrayBuffer(s.byteLength+1),e)return t;let o=new Uint8Array(s);n=new Uint8Array(t),n[0]=s.byteLength|128;for(let i=0;i<s.byteLength;i++)n[i+1]=o[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}}};Ro.NAME="lengthBlock";var M={},_e=class extends Ft{constructor({name:e=pn,optional:t=!1,primitiveSchema:n,...s}={},o){super(s),this.name=e,this.optional=t,n&&(this.primitiveSchema=n),this.idBlock=new _o(s),this.lenBlock=new Ro(s),this.valueBlock=o?new o(s):new Pe(s)}fromBER(e,t,n){let s=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(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),s)}toBER(e,t){let n=t||new es;t||Ah(this);let s=this.idBlock.toBER(e);if(n.write(s),this.lenBlock.isIndefiniteForm)n.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,n),n.write(new ArrayBuffer(2));else{let o=this.valueBlock.toBER(e);this.lenBlock.length=o.byteLength;let i=this.lenBlock.toBER(e);n.write(i),n.write(o)}return t?lt: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 yh(t,n)}};_e.NAME="BaseBlock";function Ah(r){if(r instanceof M.Constructed)for(let e of r.valueBlock.value)Ah(e)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var No=class extends _e{constructor({value:e=pn,...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 s=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(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),s)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}};No.NAME="BaseStringBlock";var Lo=class extends $t(Pe){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};Lo.NAME="PrimitiveValueBlock";var Dh,Uo=class extends _e{constructor(e={}){super(e,Lo),this.idBlock.isConstructed=!1}};Dh=Uo;M.Primitive=Dh;Uo.NAME="PRIMITIVE";function Ky(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,s=new _e({},Pe),o=new Ft;if(!Kt(o,r,e,t))return s.error=o.error,{offset:-1,result:s};if(!r.subarray(e,e+t).length)return s.error="Zero buffer length",{offset:-1,result:s};let a=s.idBlock.fromBER(r,e,t);if(s.idBlock.warnings.length&&s.warnings.concat(s.idBlock.warnings),a===-1)return s.error=s.idBlock.error,{offset:-1,result:s};if(e=a,t-=s.idBlock.blockLength,a=s.lenBlock.fromBER(r,e,t),s.lenBlock.warnings.length&&s.warnings.concat(s.lenBlock.warnings),a===-1)return s.error=s.lenBlock.error,{offset:-1,result:s};if(e=a,t-=s.lenBlock.blockLength,!s.idBlock.isConstructed&&s.lenBlock.isIndefiniteForm)return s.error="Indefinite length form used for primitive encoding form",{offset:-1,result:s};let c=_e;switch(s.idBlock.tagClass){case 1:if(s.idBlock.tagNumber>=37&&s.idBlock.isHexOnly===!1)return s.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:s};switch(s.idBlock.tagNumber){case 0:if(s.idBlock.isConstructed&&s.lenBlock.length>0)return s.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:s};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 s.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:s};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 u=s.idBlock.isConstructed?new M.Constructed:new M.Primitive;u.idBlock=s.idBlock,u.lenBlock=s.lenBlock,u.warnings=s.warnings,s=u}}break;case 2:case 3:case 4:default:c=s.idBlock.isConstructed?M.Constructed:M.Primitive}return s=Ky(s,c),a=s.fromBER(r,e,s.lenBlock.isIndefiniteForm?t:s.lenBlock.length),s.valueBeforeDecodeView=r.subarray(n,n+s.blockLength),{offset:a,result:s}}function mn(r){if(!r.byteLength){let e=new _e({},Pe);return e.error="Input buffer has zero length",{offset:-1,result:e}}return pi(X.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function $y(r,e){return r?1:e}var xt=class extends Pe{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let s=X.BufferSourceConverter.toUint8Array(e);if(!Kt(this,s,t,n))return-1;if(this.valueBeforeDecodeView=s.subarray(t,t+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),t;let o=t;for(;$y(this.isIndefiniteForm,n)>0;){let i=pi(s,o,n);if(i.offset===-1)return this.error=i.result.error,this.warnings.concat(i.result.warnings),-1;if(o=i.offset,this.blockLength+=i.result.blockLength,n-=i.result.blockLength,this.value.push(i.result),this.isIndefiniteForm&&i.result.constructor.NAME===ts)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===ts?this.value.pop():this.warnings.push("No EndOfContent block encoded")),o}toBER(e,t){let n=t||new es;for(let s=0;s<this.value.length;s++)this.value[s].toBER(e,n);return t?lt:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};xt.NAME="ConstructedValueBlock";var Bh,ir=class extends _e{constructor(e={}){super(e,xt),this.idBlock.isConstructed=!0}fromBER(e,t,n){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let s=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(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),s)}onAsciiEncoding(){let e=[];for(let n of this.valueBlock.value)e.push(n.toString("ascii").split(`
|
|
16
|
+
`});var ip=te(()=>{op();ki();fr();Lu();xs()});var Pu,jk,ap=te(()=>{L0();U0();O0();P0();M0();Bu();F0();Cu();V0();K0();X0();ep();tp();rp();ip();Pu={...wu,...xu,...Eu,...vu,...Au,...Du,...Su,...ku,...Iu,...Tu},jk={...Uu,...Ou}});function In(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}var _i=te(()=>{});function Ri(r=0){return globalThis.Buffer!=null&&globalThis.Buffer.allocUnsafe!=null?In(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}var Mu=te(()=>{_i()});function up(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var cp,Fu,P2,Ni,Vu=te(()=>{ap();Mu();cp=up("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Fu=up("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=Ri(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),P2={utf8:cp,"utf-8":cp,hex:Pu.base16,latin1:Fu,ascii:Fu,binary:Fu,...Pu},Ni=P2});var lp={};J(lp,{toString:()=>M2});function M2(r,e="utf8"){let t=Ni[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 fp=te(()=>{Vu()});var hp={};J(hp,{fromString:()=>F2});function F2(r,e="utf8"){let t=Ni[e];if(!t)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?In(globalThis.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}var dp=te(()=>{Vu();_i()});var pp={};J(pp,{concat:()=>V2});function V2(r,e){e||(e=r.reduce((s,o)=>s+o.length,0));let t=Ri(e),n=0;for(let s of r)t.set(s,n),n+=s.length;return In(t)}var mp=te(()=>{Mu();_i()});var Ku=Ve((a6,Ep)=>{"use strict";var gp=d0(),Tn=D0(),{names:vs}=S0(),{toString:Li}=(fp(),Bs(lp)),{fromString:H2}=(dp(),Bs(hp)),{concat:K2}=(mp(),Bs(pp)),_n={};for(let r in vs){let e=r;_n[vs[e]]=e}Object.freeze(_n);function $2(r){if(!(r instanceof Uint8Array))throw new Error("must be passed a Uint8Array");return Li(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 Li(gp.encode("base58btc",r)).slice(1)}function z2(r){let e=r instanceof Uint8Array?Li(r):r;return gp.decode("z"+e)}function bp(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=Tn.decode(r);if(!wp(e))throw new Error(`multihash unknown function code: 0x${e.toString(16)}`);r=r.slice(Tn.decode.bytes);let t=Tn.decode(r);if(t<0)throw new Error(`multihash invalid length: ${t}`);if(r=r.slice(Tn.decode.bytes),r.length!==t)throw new Error(`multihash length inconsistent: 0x${Li(r,"base16")}`);return{code:e,name:_n[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=yp(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 s=Tn.encode(n),o=Tn.encode(t);return K2([s,o,r],s.length+o.length+r.length)}function yp(r){let e=r;if(typeof r=="string"){if(vs[r]===void 0)throw new Error(`Unrecognized hash function named: ${r}`);e=vs[r]}if(typeof e!="number")throw new Error(`Hash function code should be a number. Got: ${e}`);if(_n[e]===void 0&&!Hu(e))throw new Error(`Unrecognized function code: ${e}`);return e}function Hu(r){return r>0&&r<16}function wp(r){return!!(Hu(r)||_n[r])}function xp(r){bp(r)}function j2(r){return xp(r),r.subarray(0,2)}Ep.exports={names:vs,codes:_n,toHexString:$2,fromHexString:q2,toB58String:W2,fromB58String:z2,decode:bp,encode:G2,coerceCode:yp,isAppCode:Hu,validate:xp,prefix:j2,isValidCode:wp}});var s1={};J(s1,{webRTC:()=>n1,webRTCDirect:()=>r1});var tl=Symbol.for("@libp2p/peer-id");var Ss=Symbol.for("@libp2p/transport");var rl;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(rl||(rl={}));var N=class extends Error{code;props;constructor(e,t,n){super(e),this.code=t,this.name=n?.name??"CodeError",this.props=n??{}}};var ks=(r,...e)=>{try{[...e]}catch{}};var Cs=class extends EventTarget{#e=new Map;constructor(){super(),ks(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 s=this.#e.get(e);s==null&&(s=[],this.#e.set(e,s)),s.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let s=this.#e.get(e);s!=null&&(s=s.filter(({callback:o})=>o!==t),this.#e.set(e,s))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:s})=>!s),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new $p(e,t))}},Mi=class extends Event{detail;constructor(e,t){super(e,t),this.detail=t?.detail}},$p=globalThis.CustomEvent??Mi;var $i={};J($i,{base58btc:()=>pe,base58flickr:()=>Yp});var h1=new Uint8Array(0);function nl(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 Bt(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 sl(r){return new TextEncoder().encode(r)}function ol(r){return new TextDecoder().decode(r)}function qp(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 s=0;s<r.length;s++){var o=r.charAt(s),i=o.charCodeAt(0);if(t[i]!==255)throw new TypeError(o+" is ambiguous");t[i]=s}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),l=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,x=d.length;y!==x&&d[y]===0;)y++,h++;for(var b=(x-y)*l+1>>>0,v=new Uint8Array(b);y!==x;){for(var E=d[y],A=0,S=b-1;(E!==0||A<p)&&S!==-1;S--,A++)E+=256*v[S]>>>0,v[S]=E%a>>>0,E=E/a>>>0;if(E!==0)throw new Error("Non-zero carry");p=A,y++}for(var D=b-p;D!==b&&v[D]===0;)D++;for(var _=c.repeat(h);D<b;++D)_+=r.charAt(v[D]);return _}function m(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 x=(d.length-h)*u+1>>>0,b=new Uint8Array(x);d[h];){var v=t[d.charCodeAt(h)];if(v===255)return;for(var E=0,A=x-1;(v!==0||E<y)&&A!==-1;A--,E++)v+=a*b[A]>>>0,b[A]=v%256>>>0,v=v/256>>>0;if(v!==0)throw new Error("Non-zero carry");y=E,h++}if(d[h]!==" "){for(var S=x-y;S!==x&&b[S]===0;)S++;for(var D=new Uint8Array(p+(x-S)),_=p;S!==x;)D[_++]=b[S++];return D}}}function g(d){var h=m(d);if(h)return h;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:m,decode:g}}var Wp=qp,zp=Wp,al=zp;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 cl(this,e)}},Hi=class{decoders;constructor(e){this.decoders=e}or(e){return cl(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 cl(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,s){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=s,this.encoder=new Fi(e,t,n),this.decoder=new Vi(e,t,s)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Vr({name:r,prefix:e,encode:t,decode:n}){return new Ki(r,e,t,n)}function jt({name:r,prefix:e,alphabet:t}){let{encode:n,decode:s}=al(t,r);return Vr({prefix:e,name:r,encode:n,decode:o=>Bt(s(o))})}function Gp(r,e,t,n){let s={};for(let l=0;l<e.length;++l)s[e[l]]=l;let o=r.length;for(;r[o-1]==="=";)--o;let i=new Uint8Array(o*t/8|0),a=0,c=0,u=0;for(let l=0;l<o;++l){let f=s[r[l]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<t|f,a+=t,a>=8&&(a-=8,i[u++]=255&c>>a)}if(a>=t||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return i}function jp(r,e,t){let n=e[e.length-1]==="=",s=(1<<t)-1,o="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>t;)i-=t,o+=e[s&a>>i];if(i!==0&&(o+=e[s&a<<t-i]),n)for(;o.length*t&7;)o+="=";return o}function fe({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return Vr({prefix:e,name:r,encode(s){return jp(s,n,t)},decode(s){return Gp(s,n,t,r)}})}var pe=jt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Yp=jt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var qi={};J(qi,{base10:()=>Zp});var Zp=jt({prefix:"9",name:"base10",alphabet:"0123456789"});var Wi={};J(Wi,{base16:()=>Xp,base16upper:()=>Jp});var Xp=fe({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Jp=fe({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var zi={};J(zi,{base2:()=>Qp});var Qp=fe({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Gi={};J(Gi,{base256emoji:()=>sm});var ul=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}"),em=ul.reduce((r,e,t)=>(r[t]=e,r),[]),tm=ul.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function rm(r){return r.reduce((e,t)=>(e+=em[t],e),"")}function nm(r){let e=[];for(let t of r){let n=tm[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var sm=Vr({prefix:"\u{1F680}",name:"base256emoji",encode:rm,decode:nm});var ji={};J(ji,{base32:()=>St,base32hex:()=>cm,base32hexpad:()=>lm,base32hexpadupper:()=>fm,base32hexupper:()=>um,base32pad:()=>im,base32padupper:()=>am,base32upper:()=>om,base32z:()=>hm});var St=fe({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),om=fe({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),im=fe({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),am=fe({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),cm=fe({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),um=fe({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),lm=fe({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),fm=fe({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),hm=fe({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Yi={};J(Yi,{base36:()=>dm,base36upper:()=>pm});var dm=jt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),pm=jt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ji={};J(Ji,{base64:()=>Zi,base64pad:()=>mm,base64url:()=>Xi,base64urlpad:()=>gm});var Zi=fe({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),mm=fe({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Xi=fe({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),gm=fe({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Qi={};J(Qi,{base8:()=>bm});var bm=fe({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ea={};J(ea,{identity:()=>ym});var ym=Vr({prefix:"\0",name:"identity",encode:r=>ol(r),decode:r=>sl(r)});var C1=new TextEncoder,I1=new TextDecoder;var ra={};J(ra,{identity:()=>Yt});var Em=hl,ll=128,vm=127,Am=~vm,Dm=Math.pow(2,31);function hl(r,e,t){e=e||[],t=t||0;for(var n=t;r>=Dm;)e[t++]=r&255|ll,r/=128;for(;r&Am;)e[t++]=r&255|ll,r>>>=7;return e[t]=r|0,hl.bytes=t-n+1,e}var Bm=ta,Sm=128,fl=127;function ta(r,n){var t=0,n=n||0,s=0,o=n,i,a=r.length;do{if(o>=a)throw ta.bytes=0,new RangeError("Could not decode varint");i=r[o++],t+=s<28?(i&fl)<<s:(i&fl)*Math.pow(2,s),s+=7}while(i>=Sm);return ta.bytes=o-n,t}var km=Math.pow(2,7),Cm=Math.pow(2,14),Im=Math.pow(2,21),Tm=Math.pow(2,28),_m=Math.pow(2,35),Rm=Math.pow(2,42),Nm=Math.pow(2,49),Lm=Math.pow(2,56),Um=Math.pow(2,63),Om=function(r){return r<km?1:r<Cm?2:r<Im?3:r<Tm?4:r<_m?5:r<Rm?6:r<Nm?7:r<Lm?8:r<Um?9:10},Pm={encode:Em,decode:Bm,encodingLength:Om},Mm=Pm,Nn=Mm;function Ln(r,e=0){return[Nn.decode(r,e),Nn.decode.bytes]}function Hr(r,e,t=0){return Nn.encode(r,e,t),e}function Kr(r){return Nn.encodingLength(r)}function dt(r,e){let t=e.byteLength,n=Kr(r),s=n+Kr(t),o=new Uint8Array(s+t);return Hr(r,o,0),Hr(t,o,n),o.set(e,s),new $r(r,t,e,o)}function pr(r){let e=Bt(r),[t,n]=Ln(e),[s,o]=Ln(e.subarray(n)),i=e.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new $r(t,s,i,e)}function dl(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&nl(r.bytes,t.bytes)}}var $r=class{code;size;digest;bytes;constructor(e,t,n,s){this.code=e,this.size=t,this.digest=n,this.bytes=s}};var pl=0,Fm="identity",ml=Bt;function Vm(r){return dt(pl,ml(r))}var Yt={code:pl,name:Fm,encode:ml,digest:Vm};var oa={};J(oa,{sha256:()=>Te,sha512:()=>Hm});function sa({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?dt(this.code,t):t.then(n=>dt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function bl(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var Te=sa({name:"sha2-256",code:18,encode:bl("SHA-256")}),Hm=sa({name:"sha2-512",code:19,encode:bl("SHA-512")});function yl(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return $m(t,ia(r),e??pe.encoder);default:return qm(t,ia(r),e??St.encoder)}}var wl=new WeakMap;function ia(r){let e=wl.get(r);if(e==null){let t=new Map;return wl.set(r,t),t}return e}var Je=class r{code;version;multihash;bytes;"/";constructor(e,t,n,s){this.code=t,this.version=e,this.multihash=n,this.bytes=s,this["/"]=s}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!==Un)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Wm)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=dt(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&&dl(e.multihash,n.multihash)}toString(e){return yl(this,e)}toJSON(){return{"/":yl(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:s,multihash:o,bytes:i}=t;return new r(n,s,o,i??xl(n,s,o.bytes))}else if(t[zm]===!0){let{version:n,multihash:s,code:o}=t,i=pr(s);return r.create(n,o,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!==Un)throw new Error(`Version 0 CID must use dag-pb (code: ${Un}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let s=xl(e,t,n.bytes);return new r(e,t,n,s)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Un,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,s=Bt(e.subarray(n,n+t.multihashSize));if(s.byteLength!==t.multihashSize)throw new Error("Incorrect length");let o=s.subarray(t.multihashSize-t.digestSize),i=new $r(t.multihashCode,t.digestSize,o,s);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,m]=Ln(e.subarray(t));return t+=m,f},s=n(),o=Un;if(s===18?(s=0,t=0):o=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let i=t,a=n(),c=n(),u=t+c,l=u-i;return{version:s,codec:o,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(e,t){let[n,s]=Km(e,t),o=r.decode(s);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ia(o).set(n,e),o}};function Km(r,e){switch(r[0]){case"Q":{let t=e??pe;return[pe.prefix,t.decode(`${pe.prefix}${r}`)]}case pe.prefix:{let t=e??pe;return[pe.prefix,t.decode(r)]}case St.prefix:{let t=e??St;return[St.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 $m(r,e,t){let{prefix:n}=t;if(n!==pe.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let s=e.get(n);if(s==null){let o=t.encode(r).slice(1);return e.set(n,o),o}else return s}function qm(r,e,t){let{prefix:n}=t,s=e.get(n);if(s==null){let o=t.encode(r);return e.set(n,o),o}else return s}var Un=112,Wm=18;function xl(r,e,t){let n=Kr(r),s=n+Kr(e),o=new Uint8Array(s+t.byteLength);return Hr(r,o,0),Hr(e,o,n),o.set(t,s),o}var zm=Symbol.for("@ipld/js-cid/CID");var pt={...ea,...zi,...Qi,...qi,...Wi,...ji,...Yi,...$i,...Ji,...Gi},Z1={...oa,...ra};function ve(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}var Gm=Symbol.for("nodejs.util.inspect.custom"),El=Object.values(pt).map(r=>r.decoder).reduce((r,e)=>r.or(e),pt.identity.decoder),vl=114,aa=36,ca=37,On=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()})`}[tl]=!0;toString(){return this.string==null&&(this.string=pe.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return Je.createV1(vl,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return ve(this.multihash.bytes,e);if(typeof e=="string")return gr(e).equals(this);if(e?.multihash?.bytes!=null)return ve(this.multihash.bytes,e.multihash.bytes);throw new Error("not valid Id")}[Gm](){return`PeerId(${this.toString()})`}},qr=class extends On{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Wr=class extends On{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.multihash.digest}},zr=class extends On{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.multihash.digest}};function gr(r,e){if(e=e??El,r.charAt(0)==="1"||r.charAt(0)==="Q"){let t=pr(pe.decode(`z${r}`));return r.startsWith("12D")?new Wr({multihash:t}):r.startsWith("16U")?new zr({multihash:t}):new qr({multihash:t})}return jm(El.decode(r))}function jm(r){try{let e=pr(r);if(e.code===Yt.code){if(e.digest.length===aa)return new Wr({multihash:e});if(e.digest.length===ca)return new zr({multihash:e})}if(e.code===Te.code)return new qr({multihash:e})}catch{return Ym(Je.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function Ym(r){if(r==null||r.multihash==null||r.version==null||r.version===1&&r.code!==vl)throw new Error("Supplied PeerID CID is invalid");let e=r.multihash;if(e.code===Te.code)return new qr({multihash:r.multihash});if(e.code===Yt.code){if(e.digest.length===aa)return new Wr({multihash:r.multihash});if(e.digest.length===ca)return new zr({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function ua(r,e){return r.length===aa?new Wr({multihash:dt(Yt.code,r),privateKey:e}):r.length===ca?new zr({multihash:dt(Yt.code,r),privateKey:e}):new qr({multihash:await Te.digest(r),publicKey:r,privateKey:e})}function kt(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function Ae(r=0){return globalThis.Buffer?.alloc!=null?kt(globalThis.Buffer.alloc(r)):new Uint8Array(r)}function De(r=0){return globalThis.Buffer?.allocUnsafe!=null?kt(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function Dl(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Al=Dl("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),la=Dl("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=De(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Xm={utf8:Al,"utf-8":Al,hex:pt.base16,latin1:la,ascii:la,binary:la,...pt},Ts=Xm;function z(r,e="utf8"){let t=Ts[e];if(t==null)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 Jm=Math.pow(2,7),Qm=Math.pow(2,14),eg=Math.pow(2,21),fa=Math.pow(2,28),ha=Math.pow(2,35),da=Math.pow(2,42),pa=Math.pow(2,49),re=128,Ue=127;function ye(r){if(r<Jm)return 1;if(r<Qm)return 2;if(r<eg)return 3;if(r<fa)return 4;if(r<ha)return 5;if(r<da)return 6;if(r<pa)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ma(r,e,t=0){switch(ye(r)){case 8:e[t++]=r&255|re,r/=128;case 7:e[t++]=r&255|re,r/=128;case 6:e[t++]=r&255|re,r/=128;case 5:e[t++]=r&255|re,r/=128;case 4:e[t++]=r&255|re,r>>>=7;case 3:e[t++]=r&255|re,r>>>=7;case 2:e[t++]=r&255|re,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function tg(r,e,t=0){switch(ye(r)){case 8:e.set(t++,r&255|re),r/=128;case 7:e.set(t++,r&255|re),r/=128;case 6:e.set(t++,r&255|re),r/=128;case 5:e.set(t++,r&255|re),r/=128;case 4:e.set(t++,r&255|re),r>>>=7;case 3:e.set(t++,r&255|re),r>>>=7;case 2:e.set(t++,r&255|re),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function ga(r,e){let t=r[e],n=0;if(n+=t&Ue,t<re||(t=r[e+1],n+=(t&Ue)<<7,t<re)||(t=r[e+2],n+=(t&Ue)<<14,t<re)||(t=r[e+3],n+=(t&Ue)<<21,t<re)||(t=r[e+4],n+=(t&Ue)*fa,t<re)||(t=r[e+5],n+=(t&Ue)*ha,t<re)||(t=r[e+6],n+=(t&Ue)*da,t<re)||(t=r[e+7],n+=(t&Ue)*pa,t<re))return n;throw new RangeError("Could not decode varint")}function rg(r,e){let t=r.get(e),n=0;if(n+=t&Ue,t<re||(t=r.get(e+1),n+=(t&Ue)<<7,t<re)||(t=r.get(e+2),n+=(t&Ue)<<14,t<re)||(t=r.get(e+3),n+=(t&Ue)<<21,t<re)||(t=r.get(e+4),n+=(t&Ue)*fa,t<re)||(t=r.get(e+5),n+=(t&Ue)*ha,t<re)||(t=r.get(e+6),n+=(t&Ue)*da,t<re)||(t=r.get(e+7),n+=(t&Ue)*pa,t<re))return n;throw new RangeError("Could not decode varint")}function mt(r,e,t=0){return e==null&&(e=De(ye(r))),e instanceof Uint8Array?ma(r,e,t):tg(r,e,t)}function Qe(r,e=0){return r instanceof Uint8Array?ga(r,e):rg(r,e)}function we(r,e){if(globalThis.Buffer!=null)return kt(globalThis.Buffer.concat(r,e));e==null&&(e=r.reduce((s,o)=>s+o.length,0));let t=De(e),n=0;for(let s of r)t.set(s,n),n+=s.length;return kt(t)}var _s=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,s){return this.readAtomically(()=>{let o=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*s)-1;for(;;){let l=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let m=Number.parseInt(f,e);if(!Number.isNaN(m))return m});if(l===void 0)break;if(o*=e,o+=l,o>u||(i+=1,t!==void 0&&i>t))return}if(i!==0)return!n&&c&&i>1?void 0:o})}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 s=n*2;if(n<t.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return t[s]=i[0],t[s+1]=i[1],t[s+2]=i[2],t[s+3]=i[3],[s+4,!0]}let o=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(o===void 0)return[s,!1];t[s]=o>>8,t[s+1]=o&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,s]=e(t);if(n===16)return t;if(s||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let o=new Uint8Array(14),i=16-(n+2),[a]=e(o.subarray(0,i));return t.set(o.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Bl=45,ng=15,Gr=new _s;function ba(r){if(!(r.length>ng))return Gr.new(r).parseWith(()=>Gr.readIPv4Addr())}function ya(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Bl))return Gr.new(r).parseWith(()=>Gr.readIPv6Addr())}function Rs(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Bl))return Gr.new(r).parseWith(()=>Gr.readIPAddr())}var kE=parseInt("0xFFFF",16),CE=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Q(r,e="utf8"){let t=Ts[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?kt(globalThis.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}function Ns(r){return!!ba(r)}function Ls(r){return!!ya(r)}function Us(r){return!!Rs(r)}var Cl=Ns,cg=Ls,wa=function(r){let e=0;if(r=r.toString().trim(),Cl(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(cg(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let o=Cl(t[n]),i;o&&(i=wa(t[n]),t[n]=z(i.slice(0,2),"base16")),i!=null&&++n<8&&t.splice(n,0,z(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 o=[n,1];for(n=9-t.length;n>0;n--)o.push("0");t.splice.apply(t,o)}let s=new Uint8Array(e+16);for(n=0;n<t.length;n++){let o=parseInt(t[n],16);s[e++]=o>>8&255,s[e++]=o&255}return s}throw new Error("invalid ip address")},Il=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let s=[];for(let o=0;o<t;o++)s.push(r[e+o]);return s.join(".")}if(t===16){let s=[];for(let o=0;o<t;o+=2)s.push(n.getUint16(e+o).toString(16));return s.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var jr={},xa={},lg=[[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"],[777,-1,"memory"]];lg.forEach(r=>{let e=fg(...r);xa[e.code]=e,jr[e.name]=e});function fg(r,e,t,n,s){return{code:r,size:e,name:t,resolvable:!!n,path:!!s}}function ne(r){if(typeof r=="number"){if(xa[r]!=null)return xa[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(jr[r]!=null)return jr[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var p8=ne("ip4"),m8=ne("ip6"),g8=ne("ipcidr");function va(r,e){switch(ne(r).code){case 4:case 41:return dg(e);case 42:return Rl(e);case 6:case 273:case 33:case 132:return Ll(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Rl(e);case 421:return bg(e);case 444:return Nl(e);case 445:return Nl(e);case 466:return gg(e);default:return z(e,"base16")}}function Aa(r,e){switch(ne(r).code){case 4:return Tl(e);case 41:return Tl(e);case 42:return _l(e);case 6:case 273:case 33:case 132:return Da(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return _l(e);case 421:return pg(e);case 444:return yg(e);case 445:return wg(e);case 466:return mg(e);default:return Q(e,"base16")}}var Ea=Object.values(pt).map(r=>r.decoder),hg=function(){let r=Ea[0].or(Ea[1]);return Ea.slice(2).forEach(e=>r=r.or(e)),r}();function Tl(r){if(!Us(r))throw new Error("invalid ip address");return wa(r)}function dg(r){let e=Il(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!Us(e))throw new Error("invalid ip address");return e}function Da(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function Ll(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function _l(r){let e=Q(r),t=Uint8Array.from(mt(e.length));return we([t,e],t.length+e.length)}function Rl(r){let e=Qe(r);if(r=r.slice(ye(e)),r.length!==e)throw new Error("inconsistent lengths");return z(r)}function pg(r){let e;r[0]==="Q"||r[0]==="1"?e=pr(pe.decode(`z${r}`)).bytes:e=Je.parse(r).multihash.bytes;let t=Uint8Array.from(mt(e.length));return we([t,e],t.length+e.length)}function mg(r){let e=hg.decode(r),t=Uint8Array.from(mt(e.length));return we([t,e],t.length+e.length)}function gg(r){let e=Qe(r),t=r.slice(ye(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+z(t,"base64url")}function bg(r){let e=Qe(r),t=r.slice(ye(e));if(t.length!==e)throw new Error("inconsistent lengths");return z(t,"base58btc")}function yg(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=St.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 s=Da(n);return we([t,s],t.length+s.length)}function wg(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=St.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 s=Da(n);return we([t,s],t.length+s.length)}function Nl(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=z(e,"base32"),s=Ll(t);return`${n}:${s}`}function Ul(r){r=Ba(r);let e=[],t=[],n=null,s=r.split("/").slice(1);if(s.length===1&&s[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let o=0;o<s.length;o++){let i=s[o],a=ne(i);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(o++,o>=s.length)throw Pl("invalid address: "+r);if(a.path===!0){n=Ba(s.slice(o).join("/")),e.push([a.code,Aa(a.code,n)]),t.push([a.code,n]);break}let c=Aa(a.code,s[o]);e.push([a.code,c]),t.push([a.code,va(a.code,c)])}return{string:Ol(t),bytes:ka(e),tuples:e,stringTuples:t,path:n}}function Sa(r){let e=[],t=[],n=null,s=0;for(;s<r.length;){let o=Qe(r,s),i=ye(o),a=ne(o),c=xg(a,r.slice(s+i));if(c===0){e.push([o]),t.push([o]),s+=i;continue}let u=r.slice(s+i,s+i+c);if(s+=c+i,s>r.length)throw Pl("Invalid address Uint8Array: "+z(r,"base16"));e.push([o,u]);let l=va(o,u);if(t.push([o,l]),a.path===!0){n=l;break}}return{bytes:Uint8Array.from(r),string:Ol(t),tuples:e,stringTuples:t,path:n}}function Ol(r){let e=[];return r.map(t=>{let n=ne(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),Ba(e.join("/"))}function ka(r){return we(r.map(e=>{let t=ne(e[0]),n=Uint8Array.from(mt(t.code));return e.length>1&&e[1]!=null&&(n=we([n,e[1]])),n}))}function xg(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=Qe(e instanceof Uint8Array?e:Uint8Array.from(e));return t+ye(t)}}function Ba(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}function Pl(r){return new Error("Error parsing address: "+r)}var Eg=Symbol.for("nodejs.util.inspect.custom"),Ca=Symbol.for("@multiformats/js-multiaddr/multiaddr"),vg=[ne("dns").code,ne("dns4").code,ne("dns6").code,ne("dnsaddr").code],Os=class r{bytes;#e;#t;#r;#n;[Ca]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=Sa(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=Ul(e)}else if(Fl(e))t=Sa(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,s,o="",i=ne("tcp"),a=ne("udp"),c=ne("ip4"),u=ne("ip6"),l=ne("dns6"),f=ne("ip6zone");for(let[g,d]of this.stringTuples())g===f.code&&(o=`%${d??""}`),vg.includes(g)&&(t=i.name,s=443,n=`${d??""}${o}`,e=g===l.code?6:4),(g===i.code||g===a.code)&&(t=ne(g).name,s=parseInt(d??"")),(g===c.code||g===u.code)&&(t=ne(g).name,n=`${d??""}${o}`,e=g===u.code?6:4);if(e==null||t==null||n==null||s==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:s}}protos(){return this.#t.map(([e])=>Object.assign({},ne(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>ne(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(),s=n.lastIndexOf(t);if(s<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,s))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(ka(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,s])=>{n===jr.p2p.code&&e.push([n,s]),n===jr["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?z(pe.decode(`z${n}`),"base58btc"):z(Je.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(e){return ve(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(o=>o.resolvable);if(t==null)return[this];let n=Ml.get(t.name);if(n==null)throw new N(`no available resolver for ${t.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,e)).map(o=>new r(o))}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)}[Eg](){return`Multiaddr(${this.#e})`}};var Ml=new Map;function Fl(r){return!!r?.[Ca]}function Ct(r){return new Os(r)}var Ag=r=>r.toString().split("/").slice(1),Mn=r=>({match:e=>e.length<1?!1:r(e[0])?e.slice(1):!1,pattern:"fn"}),me=r=>({match:e=>Mn(t=>t===r).match(e),pattern:r}),Fs=()=>({match:r=>Mn(e=>typeof e=="string").match(r),pattern:"{string}"}),Vl=()=>({match:r=>Mn(e=>!isNaN(parseInt(e))).match(r),pattern:"{number}"}),Ge=()=>({match:r=>{if(r.length<2||r[0]!=="p2p"&&r[0]!=="ipfs")return!1;if(r[1].startsWith("Q")||r[1].startsWith("1"))try{pe.decode(`z${r[1]}`)}catch{return!1}else return!1;return r.slice(2)},pattern:"/p2p/{peerid}"}),Ps=()=>({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}"}),gt=r=>({match:e=>{let t=r.match(e);return t===!1?e:t},pattern:`optional(${r.pattern})`}),bt=(...r)=>({match:e=>{let t;for(let n of r){let s=n.match(e);s!==!1&&(t==null||s.length<t.length)&&(t=s)}return t??!1},pattern:`or(${r.map(e=>e.pattern).join(", ")})`}),ge=(...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(s){let o=Ag(s);for(let i of r){let a=i.match(o);if(a===!1)return!1;o=a}return o}function t(s){return e(s)!==!1}function n(s){let o=e(s);return o===!1?!1:o.length===0}return{matches:t,exactMatch:n}}var Ta=ge(me("dns4"),Fs()),_a=ge(me("dns6"),Fs()),Ra=ge(me("dnsaddr"),Fs()),Hl=ge(me("dns"),Fs()),W8=Be(Ta),z8=Be(_a),G8=Be(Ra),j8=Be(bt(Hl,Ra,Ta,_a)),Kl=ge(me("ip4"),Mn(Ns)),$l=ge(me("ip6"),Mn(Ls)),ql=bt(Kl,$l),Fn=bt(ql,Hl,Ta,_a,Ra),Y8=Be(Fn),Z8=Be(Kl),X8=Be($l),J8=Be(ql),Vs=ge(Fn,me("tcp"),Vl()),Vn=ge(Fn,me("udp"),Vl()),Dg=bt(Vs,Vn),Q8=Be(Vs),ev=Be(Vn),Na=ge(Vn,me("quic")),Hs=ge(Vn,me("quic-v1")),Bg=bt(Na,Hs),tv=Be(Na),rv=Be(Hs),Ia=bt(Fn,Vs,Vn,Na,Hs),Wl=bt(ge(Ia,me("ws"),gt(Ge()))),nv=Be(Wl),zl=bt(ge(Ia,me("wss"),gt(Ge())),ge(Ia,me("tls"),me("ws"),gt(Ge()))),sv=Be(zl),Gl=ge(Dg,me("webrtc-direct"),Ps(),gt(Ps()),gt(Ge())),jl=Be(Gl),Yl=ge(Hs,me("webtransport"),Ps(),Ps(),gt(Ge())),ov=Be(Yl),Ms=bt(Wl,zl,ge(Vs,gt(Ge())),ge(Bg,gt(Ge())),ge(Fn,gt(Ge())),Gl,Yl,Ge()),iv=Be(Ms),Sg=ge(Ms,me("p2p-circuit"),Ge()),av=Be(Sg),kg=bt(ge(Ms,me("p2p-circuit"),me("webrtc"),Ge()),ge(Ms,me("webrtc"),gt(Ge())),me("webrtc")),Zl=Be(kg);var qe;(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"})(qe||(qe={}));var Zt=class extends N{constructor(e,t){super(`WebRTC transport error: ${e}`,t??""),this.name="WebRTCTransportError"}};var La=class extends Zt{constructor(e,t){super(`[stream: ${e}] data channel error: ${t}`,qe.ERR_DATA_CHANNEL),this.name="WebRTC/DataChannelError"}};function Va(r,e){return new La(r,e)}var Ua=class extends Zt{constructor(e){super(`There was a problem with the Multiaddr which was passed in: ${e}`,qe.ERR_INVALID_MULTIADDR),this.name="WebRTC/InappropriateMultiaddrError"}};function Ks(r){return new Ua(r)}var Oa=class extends Zt{constructor(e){super(`There was a problem with a provided argument: ${e}`,qe.ERR_INVALID_PARAMETERS),this.name="WebRTC/InvalidArgumentError"}};function Hn(r){return new Oa(r)}var Pa=class extends Zt{constructor(e,t){super(`Invalid fingerprint "${e}" within ${t}`,qe.ERR_INVALID_FINGERPRINT),this.name="WebRTC/InvalidFingerprintError"}};function Ha(r,e){return new Pa(r,e)}var Ma=class extends Zt{constructor(e){super(`A method (${e}) was called though it has been intentionally left unimplemented.`,qe.ERR_NOT_IMPLEMENTED),this.name="WebRTC/UnimplementedError"}};function Xl(r){return new Ma(r)}var Fa=class extends Zt{constructor(e){super(`unsupported hash algorithm: ${e}`,qe.ERR_HASH_NOT_SUPPORTED),this.name="WebRTC/UnsupportedHashAlgorithmError"}};function Jl(r){return new Fa(r)}var Ql=function(r,e,t){if(t||arguments.length===2)for(var n=0,s=e.length,o;n<s;n++)(o||!(n in e))&&(o||(o=Array.prototype.slice.call(e,0,n)),o[n]=e[n]);return r.concat(o||Array.prototype.slice.call(e))},Cg=function(){function r(e,t,n){this.name=e,this.version=t,this.os=n,this.type="browser"}return r}();var Ig=function(){function r(e){this.version=e,this.type="node",this.name="node",this.os=process.platform}return r}();var Tg=function(){function r(e,t,n,s){this.name=e,this.version=t,this.os=n,this.bot=s,this.type="bot-device"}return r}();var _g=function(){function r(){this.type="bot",this.bot=!0,this.name="bot",this.version=null,this.os=null}return r}();var Rg=function(){function r(){this.type="react-native",this.name="react-native",this.version=null,this.os=null}return r}();var Ng=/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/,Lg=/(nuhk|curl|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask\ Jeeves\/Teoma|ia_archiver)/,ef=3,Ug=[["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",Ng]],tf=[["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 nf(r){return r?rf(r):typeof document>"u"&&typeof navigator<"u"&&navigator.product==="ReactNative"?new Rg:typeof navigator<"u"?rf(navigator.userAgent):Mg()}function Og(r){return r!==""&&Ug.reduce(function(e,t){var n=t[0],s=t[1];if(e)return e;var o=s.exec(r);return!!o&&[n,o]},!1)}function rf(r){var e=Og(r);if(!e)return null;var t=e[0],n=e[1];if(t==="searchbot")return new _g;var s=n[1]&&n[1].split(".").join("_").split("_").slice(0,3);s?s.length<ef&&(s=Ql(Ql([],s,!0),Fg(ef-s.length),!0)):s=[];var o=s.join("."),i=Pg(r),a=Lg.exec(r);return a&&a[1]?new Tg(t,o,i,a[1]):new Cg(t,o,i)}function Pg(r){for(var e=0,t=tf.length;e<t;e++){var n=tf[e],s=n[0],o=n[1],i=o.exec(r);if(i)return s}return null}function Mg(){var r=typeof process<"u"&&process.version;return r?new Ig(process.version.slice(1)):null}function Fg(r){for(var e=[],t=0;t<r;t++)e.push("0");return e}function he(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var Yr=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Ka=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},sf=r=>globalThis.DOMException===void 0?new Ka(r):new DOMException(r),of=r=>{let e=r.reason===void 0?sf("This operation was aborted."):r.reason;return e instanceof Error?e:sf(e)};function br(r,e){let{milliseconds:t,fallback:n,message:s,customTimers:o={setTimeout,clearTimeout}}=e,i,c=new Promise((u,l)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:m}=e;m.aborted&&l(of(m)),m.addEventListener("abort",()=>{l(of(m))})}if(t===Number.POSITIVE_INFINITY){r.then(u,l);return}let f=new Yr;i=o.setTimeout.call(void 0,()=>{if(n){try{u(n())}catch(m){l(m)}return}typeof r.cancel=="function"&&r.cancel(),s===!1?u():s instanceof Error?l(s):(f.message=s??`Promise timed out after ${t} milliseconds`,l(f))},t),(async()=>{try{u(await r)}catch(m){l(m)}})()}).finally(()=>{c.clear()});return c.clear=()=>{o.clearTimeout.call(void 0,i),i=void 0},c}var af=nf(),Kn=af!=null&&af.name==="firefox",$s=async function*(){},qs=async r=>{},Vg=30*1e3;function cf(r,e,t=Vg,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 s=he(),o=!1;r.bufferedAmountLowThreshold=0;let i=()=>{o||(n.log("%s drain channel closed before drain",e),s.resolve())};r.addEventListener("close",i,{once:!0}),r.addEventListener("bufferedamountlow",()=>{o=!0,r.removeEventListener("close",i),s.resolve()}),await br(s.promise,{milliseconds:t})}}).then(async()=>{r.readyState==="open"&&r.close()}).catch(s=>{n.log.error("error closing outbound stream",s)})}var yr=class{log;peerConnection;remoteAddr;timeline;metrics;source=$s();sink=qs;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 Ws=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}},Zr=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Ws(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 Ws(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 $a=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 Hg(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 Hg(r,e){e=e??{};let t=e.onEnd,n=new Zr,s,o,i,a=he(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((p,y)=>{o=x=>{o=null,n.push(x);try{p(r(n))}catch(b){y(b)}return s}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=he()})}},u=p=>o!=null?o(p):(n.push(p),s),l=p=>(n=new Zr,o!=null?o({error:p}):(n.push({error:p}),s)),f=p=>{if(i)return s;if(e?.objectMode!==!0&&p?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:p})},m=p=>i?s:(i=!0,p!=null?l(p):u({done:!0})),g=()=>(n=new Zr,m(),{done:!0}),d=p=>(m(p),{done:!0});if(s={[Symbol.asyncIterator](){return this},next:c,return:g,throw:d,push:f,end:m,get readableLength(){return n.size},onEmpty:async p=>{let y=p?.signal;if(y?.throwIfAborted(),n.isEmpty())return;let x,b;y!=null&&(x=new Promise((v,E)=>{b=()=>{E(new $a)},y.addEventListener("abort",b)}));try{await Promise.race([a.promise,x])}finally{b!=null&&y!=null&&y?.removeEventListener("abort",b)}}},t==null)return s;let h=s;return s={[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),s},get readableLength(){return h.readableLength},onEmpty:p=>h.onEmpty(p)},s}var zs=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 It(r,e,t){if(e==null)return r;if(e.aborted)return Promise.reject(new zs(t?.errorMessage,t?.errorCode));let n,s=new zs(t?.errorMessage,t?.errorCode);try{return await Promise.race([r,new Promise((o,i)=>{n=()=>{i(s)},e.addEventListener("abort",n)})])}finally{n!=null&&e.removeEventListener("abort",n)}}var lf=Symbol.for("@achingbrain/uint8arraylist");function uf(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let s=t+n.byteLength;if(e<s)return{buf:n,index:e-t};t=s}throw new RangeError("index is out of bounds")}function Gs(r){return!!r?.[lf]}var ce=class r{bufs;length;[lf]=!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(Gs(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(Gs(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=uf(this.bufs,e);return t.buf[t.index]}set(e,t){let n=uf(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(Gs(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:s}=this._subList(e,t);return we(n,s)}subarray(e,t){let{bufs:n,length:s}=this._subList(e,t);return n.length===1?n[0]:we(n,s)}sublist(e,t){let{bufs:n,length:s}=this._subList(e,t),o=new r;return o.length=s,o.bufs=[...n],o}_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=[],s=0;for(let o=0;o<this.bufs.length;o++){let i=this.bufs[o],a=s,c=a+i.byteLength;if(s=c,e>=c)continue;let u=e>=a&&e<c,l=t>a&&t<=c;if(u&&l){if(e===a&&t===c){n.push(i);break}let f=e-a;n.push(i.subarray(f,f+(t-e)));break}if(u){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(l){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(!Gs(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 s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let o=256,i=new Int32Array(o);for(let f=0;f<o;f++)i[f]=-1;for(let f=0;f<s;f++)i[n[f]]=f;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let f=t;f<=c;f+=l){l=0;for(let m=u;m>=0;m--){let g=this.get(f+m);if(n[m]!==g){l=Math.max(1,m-a[g]);break}}if(l===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=De(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 s=Ae(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,t,n),this.write(s,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 s=Ae(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,t,n),this.write(s,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 s=Ae(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,t,n),this.write(s,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=De(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 s=Ae(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,t,n),this.write(s,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 s=Ae(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,t,n),this.write(s,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 s=Ae(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,t,n),this.write(s,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 s=Ae(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,t,n),this.write(s,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 s=Ae(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,t,n),this.write(s,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(!ve(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((s,o)=>s+o.byteLength,0)),n.length=t,n}};function ff(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 hf(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function df(r,e){let t=ff(r).return?.();hf(t)&&t.catch(n=>{e.error("could not cause iterator to return",n)})}var Kg="ERR_STREAM_RESET",$g="ERR_SINK_INVALID_STATE",qg=5e3;function qa(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var js=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=he(),this.closed=he(),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??qg,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 N(`writable end state is "${this.writeStatus}" not "ready"`,$g);try{this.writeStatus="writing";let t={signal:this.sinkController.signal};if(this.direction==="outbound"){let s=this.sendNewStream(t);qa(s)&&await s}let n=()=>{df(e,this.log)};try{this.sinkController.signal.addEventListener("abort",n),this.log.trace("sink reading from source");for await(let s of e){s=s instanceof Uint8Array?new ce(s):s;let o=this.sendData(s,t);qa(o)&&(this.sendingData=he(),await o,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 It(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 It(this.sink([]),e.signal)),this.writeStatus==="writing"&&(this.sendingData!=null&&await It(this.sendingData.promise,e.signal),this.log.trace("aborting source passed to .sink"),this.sinkController.abort(),await It(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();qa(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 N("stream reset",Kg);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 Ys(r){return r[Symbol.asyncIterator]!=null}var Zs=r=>{let e=ye(r),t=De(e);return mt(r,t),Zs.bytes=e,t};Zs.bytes=0;function $n(r,e){e=e??{};let t=e.lengthEncoder??Zs;function*n(s){let o=t(s.byteLength);o instanceof Uint8Array?yield o:yield*o,s instanceof Uint8Array?yield s:yield*s}return Ys(r)?async function*(){for await(let s of r)yield*n(s)}():function*(){for(let s of r)yield*n(s)}()}$n.single=(r,e)=>{e=e??{};let t=e.lengthEncoder??Zs;return new ce(t(r.byteLength),r)};var Xr=Ds(gf(),1);var zg=8,Gg=1024*1024*4,wr;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(wr||(wr={}));var Wa=r=>{let e=Qe(r);return Wa.bytes=ye(e),e};Wa.bytes=0;function xr(r,e){let t=new ce,n=wr.LENGTH,s=-1,o=e?.lengthDecoder??Wa,i=e?.maxLengthLength??zg,a=e?.maxDataLength??Gg;function*c(){for(;t.byteLength>0;){if(n===wr.LENGTH)try{if(s=o(t),s<0)throw(0,Xr.default)(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(s>a)throw(0,Xr.default)(new Error("message length too long"),"ERR_MSG_DATA_TOO_LONG");let u=o.bytes;t.consume(u),e?.onLength!=null&&e.onLength(s),n=wr.DATA}catch(u){if(u instanceof RangeError){if(t.byteLength>i)throw(0,Xr.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw u}if(n===wr.DATA){if(t.byteLength<s)break;let u=t.sublist(0,s);t.consume(s),e?.onData!=null&&e.onData(u),yield u,n=wr.LENGTH}}}return Ys(r)?async function*(){for await(let u of r)t.append(u),yield*c();if(t.byteLength>0)throw(0,Xr.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}():function*(){for(let u of r)t.append(u),yield*c();if(t.byteLength>0)throw(0,Xr.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}()}xr.fromReader=(r,e)=>{let t=1,n=async function*(){for(;;)try{let{done:o,value:i}=await r.next(t);if(o===!0)return;i!=null&&(yield i)}catch(o){if(o.code==="ERR_UNDER_READ")return{done:!0,value:null};throw o}finally{t=1}}();return xr(n,{...e??{},onLength:o=>{t=o}})};var Yg=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 Zg(r,e,t){let n,s=new Promise((o,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:u,removeListener:l}=Yg(r),f=(...g)=>{let d=t.multiArgs?g:g[0];t.filter&&!t.filter(d)||(c.push(d),t.count===c.length&&(n(),o(c)))},m=g=>{n(),i(g)};n=()=>{for(let g of a)l(g,f);for(let g of t.rejectionEvents)l(g,m)};for(let g of a)u(g,f);for(let g of t.rejectionEvents)u(g,m);t.signal&&t.signal.addEventListener("abort",()=>{m(t.signal.reason)},{once:!0}),t.resolveImmediately&&o(c)});if(s.cancel=n,typeof t.timeout=="number"){let o=br(s,{milliseconds:t.timeout});return o.cancel=n,o}return s}function za(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=Zg(r,e,t),s=n.then(o=>o[0]);return s.cancel=n.cancel,s}var Ga=new Float32Array([-0]),Jt=new Uint8Array(Ga.buffer);function bf(r,e,t){Ga[0]=r,e[t]=Jt[0],e[t+1]=Jt[1],e[t+2]=Jt[2],e[t+3]=Jt[3]}function yf(r,e){return Jt[0]=r[e],Jt[1]=r[e+1],Jt[2]=r[e+2],Jt[3]=r[e+3],Ga[0]}var ja=new Float64Array([-0]),Oe=new Uint8Array(ja.buffer);function wf(r,e,t){ja[0]=r,e[t]=Oe[0],e[t+1]=Oe[1],e[t+2]=Oe[2],e[t+3]=Oe[3],e[t+4]=Oe[4],e[t+5]=Oe[5],e[t+6]=Oe[6],e[t+7]=Oe[7]}function xf(r,e){return Oe[0]=r[e],Oe[1]=r[e+1],Oe[2]=r[e+2],Oe[3]=r[e+3],Oe[4]=r[e+4],Oe[5]=r[e+5],Oe[6]=r[e+6],Oe[7]=r[e+7],ja[0]}var Xg=BigInt(Number.MAX_SAFE_INTEGER),Jg=BigInt(Number.MIN_SAFE_INTEGER),We=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 Er;if(e<Xg&&e>Jg)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let n=e>>32n,s=e-(n<<32n);return t&&(n=~n|0n,s=~s|0n,++s>Ef&&(s=0n,++n>Ef&&(n=0n))),new r(Number(s),Number(n))}static fromNumber(e){if(e===0)return Er;let t=e<0;t&&(e=-e);let n=e>>>0,s=(e-n)/4294967296>>>0;return t&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new r(n,s)}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):Er}},Er=new We(0,0);Er.toBigInt=function(){return 0n};Er.zzEncode=Er.zzDecode=function(){return this};Er.length=function(){return 1};var Ef=4294967296n;function vf(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 Af(r,e,t){if(t-e<1)return"";let s,o=[],i=0,a;for(;e<t;)a=r[e++],a<128?o[i++]=a:a>191&&a<224?o[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,o[i++]=55296+(a>>10),o[i++]=56320+(a&1023)):o[i++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&63,i>8191&&((s??(s=[])).push(String.fromCharCode.apply(String,o)),i=0);return s!=null?(i>0&&s.push(String.fromCharCode.apply(String,o.slice(0,i))),s.join("")):String.fromCharCode.apply(String,o.slice(0,i))}function Ya(r,e,t){let n=t,s,o;for(let i=0;i<r.length;++i)s=r.charCodeAt(i),s<128?e[t++]=s:s<2048?(e[t++]=s>>6|192,e[t++]=s&63|128):(s&64512)===55296&&((o=r.charCodeAt(i+1))&64512)===56320?(s=65536+((s&1023)<<10)+(o&1023),++i,e[t++]=s>>18|240,e[t++]=s>>12&63|128,e[t++]=s>>6&63|128,e[t++]=s&63|128):(e[t++]=s>>12|224,e[t++]=s>>6&63|128,e[t++]=s&63|128);return t-n}function et(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function Xs(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var Za=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,et(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 et(this,4);return Xs(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw et(this,4);return Xs(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw et(this,4);let e=yf(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw et(this,4);let e=xf(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 et(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return Af(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw et(this,e);this.pos+=e}else do if(this.pos>=this.len)throw et(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 We(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 et(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 et(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 et(this,8);let e=Xs(this.buf,this.pos+=4),t=Xs(this.buf,this.pos+=4);return new We(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=ga(this.buf,this.pos);return this.pos+=ye(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 Xa(r){return new Za(r instanceof Uint8Array?r:r.subarray())}function tt(r,e,t){let n=Xa(r);return e.decode(n,void 0,t)}function Ja(r){let e=r??8192,t=e>>>1,n,s=e;return function(i){if(i<1||i>t)return De(i);s+i>e&&(n=De(e),s=0);let a=n.subarray(s,s+=i);return s&7&&(s=(s|7)+1),a}}var vr=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function Qa(){}var tc=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Qg=Ja();function eb(r){return globalThis.Buffer!=null?De(r):Qg(r)}var Wn=class{len;head;tail;states;constructor(){this.len=0,this.head=new vr(Qa,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new vr(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new rc((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(Js,10,We.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=We.fromBigInt(e);return this._push(Js,t.length(),t)}uint64Number(e){return this._push(ma,ye(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=We.fromBigInt(e).zzEncode();return this._push(Js,t.length(),t)}sint64Number(e){let t=We.fromNumber(e).zzEncode();return this._push(Js,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(ec,1,e?1:0)}fixed32(e){return this._push(qn,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=We.fromBigInt(e);return this._push(qn,4,t.lo)._push(qn,4,t.hi)}fixed64Number(e){let t=We.fromNumber(e);return this._push(qn,4,t.lo)._push(qn,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(bf,4,e)}double(e){return this._push(wf,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(ec,1,0):this.uint32(t)._push(rb,t,e)}string(e){let t=vf(e);return t!==0?this.uint32(t)._push(Ya,t,e):this._push(ec,1,0)}fork(){return this.states=new tc(this),this.head=this.tail=new vr(Qa,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 vr(Qa,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=eb(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function ec(r,e,t){e[t]=r&255}function tb(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var rc=class extends vr{next;constructor(e,t){super(tb,e,t),this.next=void 0}};function Js(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 qn(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 rb(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(Wn.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(nb,e,r),this},Wn.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(sb,e,r),this});function nb(r,e,t){e.set(r,t)}function sb(r,e,t){r.length<40?Ya(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(Q(r),t)}function nc(){return new Wn}function rt(r,e){let t=nc();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var Jr;(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"})(Jr||(Jr={}));function Qs(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function Ar(r){function e(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let t=function(o,i){let a=e(o);i.int32(a)},n=function(o){let i=o.int32();return e(i)};return Qs("enum",Jr.VARINT,t,n)}function nt(r,e){return Qs("message",Jr.LENGTH_DELIMITED,r,e)}var He;(function(r){let e;(function(s){s.FIN="FIN",s.STOP_SENDING="STOP_SENDING",s.RESET="RESET",s.FIN_ACK="FIN_ACK"})(e=r.Flag||(r.Flag={}));let t;(function(s){s[s.FIN=0]="FIN",s[s.STOP_SENDING=1]="STOP_SENDING",s[s.RESET=2]="RESET",s[s.FIN_ACK=3]="FIN_ACK"})(t||(t={})),function(s){s.codec=()=>Ar(t)}(e=r.Flag||(r.Flag={}));let n;r.codec=()=>(n==null&&(n=nt((s,o,i={})=>{i.lengthDelimited!==!1&&o.fork(),s.flag!=null&&(o.uint32(8),r.Flag.codec().encode(s.flag,o)),s.message!=null&&(o.uint32(18),o.bytes(s.message)),i.lengthDelimited!==!1&&o.ldelim()},(s,o)=>{let i={},a=o==null?s.len:s.pos+o;for(;s.pos<a;){let c=s.uint32();switch(c>>>3){case 1:i.flag=r.Flag.codec().decode(s);break;case 2:i.message=s.bytes();break;default:s.skipType(c&7);break}}return i})),n),r.encode=s=>rt(s,r.codec()),r.decode=s=>tt(s,r.codec())})(He||(He={}));var ob=16*1024*1024,ib=30*1e3,ab=5,cb=2,ub=16*1024,lb=5e3,fb=5e3,sc=class extends js{channel;incomingData;maxBufferedAmount;bufferedAmountLowEventTimeout;maxMessageSize;receiveFinAck;finAckTimeout;openTimeout;constructor(e){let t=e.onEnd;switch(e.onEnd=s=>{this.log.trace("readable and writeable ends closed",this.status),Promise.resolve(async()=>{if(!(this.timeline.abort!=null||this.timeline.reset!==null))try{await br(this.receiveFinAck.promise,{milliseconds:this.finAckTimeout})}catch(o){this.log.error("error receiving FIN_ACK",o)}}).then(()=>{this.incomingData.end(),t?.(s)}).catch(o=>{this.log.error("error ending stream",o)})},super(e),this.channel=e.channel,this.channel.binaryType="arraybuffer",this.incomingData=Xt(),this.bufferedAmountLowEventTimeout=e.bufferedAmountLowEventTimeout??ib,this.maxBufferedAmount=e.maxBufferedAmount??ob,this.maxMessageSize=(e.maxMessageSize??ub)-ab-cb,this.receiveFinAck=he(),this.finAckTimeout=e.closeTimeout??lb,this.openTimeout=e.openTimeout??fb,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 N("Unknown datachannel state","ERR_INVALID_STATE")}this.channel.onopen=s=>{this.timeline.open=new Date().getTime()},this.channel.onclose=s=>{this.receiveFinAck.resolve(),this.close().catch(o=>{this.log.error("error closing stream after channel closed",o)})},this.channel.onerror=s=>{let o=s.error;this.abort(o)},this.channel.onmessage=async s=>{let{data:o}=s;o===null||o.byteLength===0||this.incomingData.push(new Uint8Array(o,0,o.byteLength))};let n=this;Promise.resolve().then(async()=>{for await(let s of xr(this.incomingData)){let o=n.processIncomingProtobuf(s);o!=null&&n.sourcePush(new ce(o))}}).catch(s=>{this.log.error("error processing incoming data channel messages",s)})}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 za(this.channel,"bufferedamountlow",{timeout:this.bufferedAmountLowEventTimeout})}catch(n){throw n instanceof Yr?new N(`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 N(`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 za(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),s=He.encode({message:n}),o=$n.single(s);await this._sendMessage(o),e.consume(t)}}async sendReset(){await this._sendFlag(He.Flag.RESET)}async sendCloseWrite(e){if(await this._sendFlag(He.Flag.FIN)){this.log.trace("awaiting FIN_ACK");try{await It(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(He.Flag.STOP_SENDING)}processIncomingProtobuf(e){let t=He.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===He.Flag.FIN&&(this.remoteCloseWrite(),this.log.trace("sending FIN_ACK"),this._sendFlag(He.Flag.FIN_ACK).catch(n=>{this.log.error("error sending FIN_ACK immediately",n)})),t.flag===He.Flag.RESET&&this.reset(),t.flag===He.Flag.STOP_SENDING&&this.remoteCloseRead(),t.flag===He.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=He.encode({flag:e}),n=$n.single(t);try{return await this._sendMessage(n,!1),!0}catch(s){this.log.error("could not send flag %s",e.toString(),s)}return!1}};function Qr(r){let{channel:e,direction:t}=r;return new sc({id:t==="inbound"?`i${e.id}`:`r${e.id}`,log:r.logger.forComponent(`libp2p:webrtc:stream:${t}:${e.id}`),...r})}var Bf="/webrtc",Dr=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??Bf,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 s={},o=Qr({channel:n,direction:"inbound",onEnd:i=>{s.onEnd(i)},logger:e.logger,...this.dataChannelOptions});s.stream=o,s.channel=n,s.onEnd=()=>{this.bufferedStreams=this.bufferedStreams.filter(i=>i.stream.id!==o.id)},this.bufferedStreams.push(s)}}createStreamMuxer(e){return new oc(this.components,{...e,peerConnection:this.peerConnection,dataChannelOptions:this.dataChannelOptions,metrics:this.metrics,streams:this.bufferedStreams,protocol:this.protocol})}},oc=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??Bf,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 s=Qr({channel:n,direction:"inbound",onEnd:()=>{this.log("incoming channel %s ended with state %s",n.id,n.readyState),this.#e(s,n)},logger:this.logger,...this.dataChannelOptions});this.streams.push(s),this.metrics?.increment({incoming_stream:!0}),t?.onIncomingStream?.(s)},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),cf(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=$s();sink=qs;newStream(){let e=this.peerConnection.createDataChannel("");this.log.trace("opened outgoing datachannel with channel id %s",e.id);let t=Qr({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 en=globalThis.RTCPeerConnection,eo=globalThis.RTCSessionDescription,Sf=globalThis.RTCIceCandidate;var ic=class{readNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.readNext=he(),this.haveNext=he()}[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=he(),e}async throw(e){return this.ended=!0,e!=null&&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");if(this.nextResult!=null&&(await this.readNext.promise,this.nextResult!=null))throw new Error("NeedNext promise resolved but nextResult was not consumed");e!=null?this.nextResult={done:!1,value:e}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=he(),await It(this.readNext.promise,t?.signal,t)}};function kf(){return new ic}var to=class extends Error{code;constructor(e,t){super(e),this.code=t}},ac=class extends to{type;constructor(e){super(e,"ABORT_ERR"),this.type="aborted"}};function Cf(r,e){let t=kf();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 s=new ce;return{read:async(i,a)=>{a?.signal?.throwIfAborted();let c,u=new Promise((l,f)=>{c=()=>{f(new ac("Read aborted"))},a?.signal?.addEventListener("abort",c)});try{if(i==null){let{done:f,value:m}=await Promise.race([n.next(),u]);return f===!0?new ce:m}for(;s.byteLength<i;){let{value:f,done:m}=await Promise.race([n.next(),u]);if(m===!0)throw new to("unexpected end of input","ERR_UNEXPECTED_EOF");s.append(f)}let l=s.sublist(0,i);return s.consume(i),l}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(s.byteLength>0){let i=r.source;r.source=async function*(){e?.yieldBytes===!1?yield s:yield*s,yield*i}()}return r}}}var ro=class extends Error{code;constructor(e,t){super(e),this.code=t}};function zn(r,e={}){let t=Cf(r,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=ye(e.maxDataLength));let n=e?.lengthDecoder??Qe,s=e?.lengthEncoder??mt;return{read:async i=>{let a=-1,c=new ce;for(;;){c.append(await t.read(1,i));try{a=n(c)}catch(u){if(u instanceof RangeError)continue;throw u}if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new ro("message length length too long","ERR_MSG_LENGTH_TOO_LONG");if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new ro("message length too long","ERR_MSG_DATA_TOO_LONG");return t.read(a,i)},write:async(i,a)=>{await t.write(new ce(s(i.byteLength),i),a)},writeV:async(i,a)=>{let c=new ce(...i.flatMap(u=>[s(u.byteLength),u]));await t.write(c,a)},unwrap:()=>t.unwrap()}}function no(r,e){let t=zn(r,e),n={read:async(s,o)=>{let i=await t.read(o);return s.decode(i)},write:async(s,o,i)=>{await t.write(o.encode(s),i)},writeV:async(s,o,i)=>{await t.writeV(s.map(a=>o.encode(a)),i)},pb:s=>({read:async o=>n.read(s,o),write:async(o,i)=>n.write(o,s,i),writeV:async(o,i)=>n.writeV(o,s,i),unwrap:()=>n}),unwrap:()=>t.unwrap()};return n}var Ke;(function(r){let e;(function(s){s.SDP_OFFER="SDP_OFFER",s.SDP_ANSWER="SDP_ANSWER",s.ICE_CANDIDATE="ICE_CANDIDATE"})(e=r.Type||(r.Type={}));let t;(function(s){s[s.SDP_OFFER=0]="SDP_OFFER",s[s.SDP_ANSWER=1]="SDP_ANSWER",s[s.ICE_CANDIDATE=2]="ICE_CANDIDATE"})(t||(t={})),function(s){s.codec=()=>Ar(t)}(e=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=nt((s,o,i={})=>{i.lengthDelimited!==!1&&o.fork(),s.type!=null&&(o.uint32(8),r.Type.codec().encode(s.type,o)),s.data!=null&&(o.uint32(18),o.string(s.data)),i.lengthDelimited!==!1&&o.ldelim()},(s,o)=>{let i={},a=o==null?s.len:s.pos+o;for(;s.pos<a;){let c=s.uint32();switch(c>>>3){case 1:i.type=r.Type.codec().decode(s);break;case 2:i.data=s.string();break;default:s.skipType(c&7);break}}return i})),n),r.encode=s=>rt(s,r.codec()),r.decode=s=>tt(s,r.codec())})(Ke||(Ke={}));var so=async(r,e,t)=>{try{let n=he();for(db(r,n);;){let s=await Promise.race([n.promise,e.read({signal:t.signal})]);if(s==null)break;if(s.type!==Ke.Type.ICE_CANDIDATE)throw new N("ICE candidate message expected","ERR_NOT_ICE_CANDIDATE");let o=JSON.parse(s.data??"null");if(o===""||o===null){t.log.trace("end-of-candidates received");continue}let i=new Sf(o);t.log.trace("%s received new ICE candidate",t.direction,i);try{await r.addIceCandidate(i)}catch(a){t.log.error("%s bad candidate received",t.direction,o,a)}}}catch(n){if(t.log.error("%s error parsing ICE candidate",t.direction,n),t.signal?.aborted===!0)throw n}};function hb(r){return Kn?r.iceConnectionState:r.connectionState}function db(r,e){r[Kn?"oniceconnectionstatechange":"onconnectionstatechange"]=t=>{switch(hb(r)){case"connected":e.resolve();break;case"failed":case"disconnected":case"closed":e.reject(new N("RTCPeerConnection was closed","ERR_CONNECTION_CLOSED_BEFORE_CONNECTED"));break;default:break}}}async function If({peerConnection:r,signal:e,metrics:t,multiaddr:n,connectionManager:s,transportManager:o,log:i}){let{baseAddr:a}=Tf(n);t?.dialerEvents.increment({open:!0}),i.trace("dialing base address: %a",a);let c=a.getPeerId();if(c==null)throw new N("Relay peer was missing","ERR_INVALID_ADDRESS");let u=s.getConnections(gr(c)),l,f=!1;u.length===0?(l=await o.dial(a,{signal:e}),f=!0):l=u[0];try{let m=await l.newStream(oo,{signal:e,runOnTransientConnection:!0}),g=no(m).pb(Ke);try{let d=r.createDataChannel("init");r.onicecandidate=({candidate:x})=>{let b=JSON.stringify(x?.toJSON()??null);i.trace("initiator sending ICE candidate %s",b),g.write({type:Ke.Type.ICE_CANDIDATE,data:b},{signal:e}).catch(v=>{i.error("error sending ICE candidate",v)})},r.onicecandidateerror=x=>{i.error("initiator ICE candidate error",x)};let h=await r.createOffer().catch(x=>{throw i.error("could not execute createOffer",x),new N("Failed to set createOffer","ERR_SDP_HANDSHAKE_FAILED")});i.trace("initiator send SDP offer %s",h.sdp),await g.write({type:Ke.Type.SDP_OFFER,data:h.sdp},{signal:e}),await r.setLocalDescription(h).catch(x=>{throw i.error("could not execute setLocalDescription",x),new N("Failed to set localDescription","ERR_SDP_HANDSHAKE_FAILED")});let p=await g.read({signal:e});if(p.type!==Ke.Type.SDP_ANSWER)throw new N("Remote should send an SDP answer","ERR_SDP_HANDSHAKE_FAILED");i.trace("initiator receive SDP answer %s",p.data);let y=new eo({type:"answer",sdp:p.data});return await r.setRemoteDescription(y).catch(x=>{throw i.error("could not execute setRemoteDescription",x),new N("Failed to set remoteDescription","ERR_SDP_HANDSHAKE_FAILED")}),i.trace("initiator read candidates until connected"),await so(r,g,{direction:"initiator",signal:e,log:i}),i.trace("initiator connected, closing init channel"),d.close(),i.trace("initiator closing signalling stream"),await g.unwrap().unwrap().close({signal:e}),i.trace("initiator connected to remote address %s",n),{remoteAddress:n}}catch(d){throw r.close(),m.abort(d),d}finally{r.onicecandidate=null,r.onicecandidateerror=null}}finally{if(f)try{await l.close({signal:e})}catch(m){l.abort(m)}}}var pb=L("dns4"),mb=L("dns6"),gb=L("dnsaddr"),Br=be(L("dns"),gb,pb,mb),co=be(L("ip4"),L("ip6")),tn=be(K(co,L("tcp")),K(Br,L("tcp"))),uo=K(co,L("udp")),bb=K(uo,L("utp")),yb=K(uo,L("quic")),wb=K(uo,L("quic-v1")),cc=be(K(tn,L("ws")),K(Br,L("ws"))),io=be(K(cc,L("p2p")),cc),uc=be(K(tn,L("wss")),K(Br,L("wss")),K(tn,L("tls"),L("ws")),K(Br,L("tls"),L("ws"))),ao=be(K(uc,L("p2p")),uc),lc=be(K(tn,L("http")),K(co,L("http")),K(Br,L("http"))),fc=be(K(tn,L("https")),K(co,L("https")),K(Br,L("https"))),_f=K(uo,L("webrtc-direct"),L("certhash")),Lf=be(K(_f,L("p2p")),_f),Rf=K(wb,L("webtransport"),L("certhash"),L("certhash")),Uf=be(K(Rf,L("p2p")),Rf),Of=be(K(io,L("p2p-webrtc-star"),L("p2p")),K(ao,L("p2p-webrtc-star"),L("p2p")),K(io,L("p2p-webrtc-star")),K(ao,L("p2p-webrtc-star"))),DA=be(K(io,L("p2p-websocket-star"),L("p2p")),K(ao,L("p2p-websocket-star"),L("p2p")),K(io,L("p2p-websocket-star")),K(ao,L("p2p-websocket-star"))),Pf=be(K(lc,L("p2p-webrtc-direct"),L("p2p")),K(fc,L("p2p-webrtc-direct"),L("p2p")),K(lc,L("p2p-webrtc-direct")),K(fc,L("p2p-webrtc-direct"))),Sr=be(cc,uc,lc,fc,Of,Pf,tn,bb,yb,Br,Lf,Uf),BA=be(K(Sr,L("p2p-stardust"),L("p2p")),K(Sr,L("p2p-stardust"))),Qt=be(K(Sr,L("p2p")),Of,Pf,Lf,Uf,L("p2p")),Nf=be(K(Qt,L("p2p-circuit"),Qt),K(Qt,L("p2p-circuit")),K(L("p2p-circuit"),Qt),K(Sr,L("p2p-circuit")),K(L("p2p-circuit"),Sr),L("p2p-circuit")),Mf=()=>be(K(Nf,Mf),Nf),Tt=Mf(),SA=be(K(Tt,Qt,Tt),K(Qt,Tt),K(Tt,Qt),Tt,Qt);var kA=be(K(Tt,L("webrtc"),L("p2p")),K(Tt,L("webrtc")),K(Sr,L("webrtc"),L("p2p")),K(Sr,L("webrtc")),L("webrtc"));function Ff(r){function e(t){let n;try{n=Ct(t)}catch{return!1}let s=r(n.protoNames());return s===null?!1:s===!0||s===!1?s:s.length===0}return e}function K(...r){function e(t){if(t.length<r.length)return null;let n=t;return r.some(s=>(n=typeof s=="function"?s().partialMatch(t):s.partialMatch(t),Array.isArray(n)&&(t=n),n===null)),n}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:Ff(e),partialMatch:e}}function be(...r){function e(n){let s=null;return r.some(o=>{let i=typeof o=="function"?o().partialMatch(n):o.partialMatch(n);return i!=null?(s=i,!0):!1}),s}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:Ff(e),partialMatch:e}}function L(r){let e=r;function t(s){let o;try{o=Ct(s)}catch{return!1}let i=o.protoNames();return i.length===1&&i[0]===e}function n(s){return s.length===0?null:s[0]===e?s.slice(1):null}return{toString:function(){return e},matches:t,partialMatch:n}}var lo=class extends Cs{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=>Tt.matches(t)).map(t=>t.encapsulate(`/webrtc/p2p/${this.peerId}`))).flat()}async close(){this.shutdownController.abort(),this.safeDispatchEvent("close",{})}};async function Vf({peerConnection:r,stream:e,signal:t,connection:n,log:s}){s.trace("new inbound signaling stream");let o=no(e).pb(Ke);try{r.onicecandidate=({candidate:l})=>{let f=JSON.stringify(l?.toJSON()??null);s.trace("recipient sending ICE candidate %s",f),o.write({type:Ke.Type.ICE_CANDIDATE,data:f},{signal:t}).catch(m=>{s.error("error sending ICE candidate",m)})};let a=await o.read({signal:t});if(a.type!==Ke.Type.SDP_OFFER)throw new N(`expected message type SDP_OFFER, received: ${a.type??"undefined"} `,"ERR_SDP_HANDSHAKE_FAILED");s.trace("recipient receive SDP offer %s",a.data);let c=new eo({type:"offer",sdp:a.data});await r.setRemoteDescription(c).catch(l=>{throw s.error("could not execute setRemoteDescription",l),new N("Failed to set remoteDescription","ERR_SDP_HANDSHAKE_FAILED")});let u=await r.createAnswer().catch(l=>{throw s.error("could not execute createAnswer",l),new N("Failed to create answer","ERR_SDP_HANDSHAKE_FAILED")});s.trace("recipient send SDP answer %s",u.sdp),await o.write({type:Ke.Type.SDP_ANSWER,data:u.sdp},{signal:t}),await r.setLocalDescription(u).catch(l=>{throw s.error("could not execute setLocalDescription",l),new N("Failed to set localDescription","ERR_SDP_HANDSHAKE_FAILED")}),s.trace("recipient read candidates until connected"),await so(r,o,{direction:"recipient",signal:t,log:s})}catch(a){if(r.connectionState!=="connected")throw s.error("error while handling signaling stream from peer %a",n.remoteAddr,a),r.close(),a;s("error while handling signaling stream from peer %a, ignoring as the RTCPeerConnection is already connected",n.remoteAddr,a)}let i=Ct(`/webrtc/p2p/${n.remoteAddr.getPeerId()}`);return s.trace("recipient connected to remote address %s",i),{remoteAddress:i}}var xb="/webrtc",Eb="/p2p-circuit",oo="/webrtc-signaling/0.0.1",vb=30*1e3,fo=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,ks(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"})})}isStarted(){return this._started}async start(){await this.components.registrar.handle(oo,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(oo),this._started=!1}createListener(e){return new lo(this.components,{shutdownController:this.shutdownController})}[Symbol.toStringTag]="@libp2p/webrtc";[Ss]=!0;filter(e){return e.filter(Zl.exactMatch)}async dial(e,t){this.log.trace("dialing address: %a",e);let n=new en(this.init.rtcConfiguration),s=new Dr(this.components,{peerConnection:n,dataChannelOptions:this.init.dataChannel}),{remoteAddress:o}=await If({peerConnection:n,multiaddr:e,dataChannelOptions:this.init.dataChannel,signal:t.signal,connectionManager:this.components.connectionManager,transportManager:this.components.transportManager,log:this.log}),i=new yr(this.components,{peerConnection:n,timeline:{open:Date.now()},remoteAddr:o,metrics:this.metrics?.dialerEvents}),a=await t.upgrader.upgradeOutbound(i,{skipProtection:!0,skipEncryption:!0,muxerFactory:s});return this._closeOnShutdown(n,i),a}async _onProtocol({connection:e,stream:t}){let n=AbortSignal.timeout(this.init.inboundConnectionTimeout??vb),s=new en(this.init.rtcConfiguration),o=new Dr(this.components,{peerConnection:s,dataChannelOptions:this.init.dataChannel});try{let{remoteAddress:i}=await Vf({peerConnection:s,connection:e,stream:t,signal:n,log:this.log}),a=new yr(this.components,{peerConnection:s,timeline:{open:new Date().getTime()},remoteAddr:i,metrics:this.metrics?.listenerEvents});this._closeOnShutdown(s,a),await this.components.upgrader.upgradeInbound(a,{skipEncryption:!0,skipProtection:!0,muxerFactory:o}),await t.close({signal:n})}catch(i){throw t.abort(i),i}}_closeOnShutdown(e,t){let n=()=>{t.close().catch(s=>{this.log.error("could not close WebRTCMultiaddrConnection",s)})};this.shutdownController.signal.addEventListener("abort",n),e.addEventListener("close",()=>{this.shutdownController.signal.removeEventListener("abort",n)})}};function Tf(r){let e=r.toString().split(xb+"/");if(e.length!==2)throw new N("webrtc protocol was not present in multiaddr",qe.ERR_INVALID_MULTIADDR);if(!e[0].includes(Eb))throw new N("p2p-circuit protocol was not present in multiaddr",qe.ERR_INVALID_MULTIADDR);let t=Ct(e[0]),s=Ct("/"+e[1]).getPeerId();if(s==null)throw new N("destination peer id was missing",qe.ERR_INVALID_MULTIADDR);let o=t.protos().pop();if(o===void 0)throw new N("invalid multiaddr",qe.ERR_INVALID_MULTIADDR);return o.name!=="p2p"&&(t=t.encapsulate(`/p2p/${s}`)),{baseAddr:t,peerId:gr(s)}}var Tc={};J(Tc,{Ed25519PrivateKey:()=>_r,Ed25519PublicKey:()=>Jn,generateKeyPair:()=>_y,generateKeyPairFromSeed:()=>mh,unmarshalEd25519PrivateKey:()=>Iy,unmarshalEd25519PublicKey:()=>Ty});function je(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function er(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`Wrong positive integer: ${r}`)}function Ab(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function hc(r,...e){if(!Ab(r))throw new Error("Expected Uint8Array");if(e.length>0&&!e.includes(r.length))throw new Error(`Expected Uint8Array of length ${e}, not of length=${r.length}`)}function kr(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");er(r.outputLen),er(r.blockLen)}function rn(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 Hf(r,e){hc(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var ho=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Kf(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var sn=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),st=(r,e)=>r<<32-e|r>>>e,Db=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Db)throw new Error("Non little-endian hardware is not supported");var Bb=async()=>{};async function $f(r,e,t){let n=Date.now();for(let s=0;s<r;s++){t(s);let o=Date.now()-n;o>=0&&o<e||(await Bb(),n+=o)}}function dc(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function ot(r){if(typeof r=="string"&&(r=dc(r)),!Kf(r))throw new Error(`expected Uint8Array, got ${typeof r}`);return r}function po(...r){let e=0;for(let n=0;n<r.length;n++){let s=r[n];if(!Kf(s))throw new Error("Uint8Array expected");e+=s.length}let t=new Uint8Array(e);for(let n=0,s=0;n<r.length;n++){let o=r[n];t.set(o,s),s+=o.length}return t}var nn=class{clone(){return this._cloneInto()}},Sb={}.toString;function qf(r,e){if(e!==void 0&&Sb.call(e)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(r,e)}function mo(r){let e=n=>r().update(ot(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function Cr(r=32){if(ho&&typeof ho.getRandomValues=="function")return ho.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function kb(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let s=BigInt(32),o=BigInt(4294967295),i=Number(t>>s&o),a=Number(t&o),c=n?4:0,u=n?0:4;r.setUint32(e+c,i,n),r.setUint32(e+u,a,n)}var on=class extends nn{constructor(e,t,n,s){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=s,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=sn(this.buffer)}update(e){rn(this);let{view:t,buffer:n,blockLen:s}=this;e=ot(e);let o=e.length;for(let i=0;i<o;){let a=Math.min(s-this.pos,o-i);if(a===s){let c=sn(e);for(;s<=o-i;i+=s)this.process(c,i);continue}n.set(e.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===s&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){rn(this),Hf(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:s,isLE:o}=this,{pos:i}=this;t[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>s-i&&(this.process(n,0),i=0);for(let f=i;f<s;f++)t[f]=0;kb(n,s-8,BigInt(this.length*8),o),this.process(n,0);let a=sn(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)a.setUint32(4*f,l[f],o)}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:s,finished:o,destroyed:i,pos:a}=this;return e.length=s,e.pos=a,e.finished=o,e.destroyed=i,s%t&&e.buffer.set(n),e}};var go=BigInt(4294967295),pc=BigInt(32);function Wf(r,e=!1){return e?{h:Number(r&go),l:Number(r>>pc&go)}:{h:Number(r>>pc&go)|0,l:Number(r&go)|0}}function Cb(r,e=!1){let t=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let s=0;s<r.length;s++){let{h:o,l:i}=Wf(r[s],e);[t[s],n[s]]=[o,i]}return[t,n]}var Ib=(r,e)=>BigInt(r>>>0)<<pc|BigInt(e>>>0),Tb=(r,e,t)=>r>>>t,_b=(r,e,t)=>r<<32-t|e>>>t,Rb=(r,e,t)=>r>>>t|e<<32-t,Nb=(r,e,t)=>r<<32-t|e>>>t,Lb=(r,e,t)=>r<<64-t|e>>>t-32,Ub=(r,e,t)=>r>>>t-32|e<<64-t,Ob=(r,e)=>e,Pb=(r,e)=>r,Mb=(r,e,t)=>r<<t|e>>>32-t,Fb=(r,e,t)=>e<<t|r>>>32-t,Vb=(r,e,t)=>e<<t-32|r>>>64-t,Hb=(r,e,t)=>r<<t-32|e>>>64-t;function Kb(r,e,t,n){let s=(e>>>0)+(n>>>0);return{h:r+t+(s/2**32|0)|0,l:s|0}}var $b=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),qb=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,Wb=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),zb=(r,e,t,n,s)=>e+t+n+s+(r/2**32|0)|0,Gb=(r,e,t,n,s)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(s>>>0),jb=(r,e,t,n,s,o)=>e+t+n+s+o+(r/2**32|0)|0;var Yb={fromBig:Wf,split:Cb,toBig:Ib,shrSH:Tb,shrSL:_b,rotrSH:Rb,rotrSL:Nb,rotrBH:Lb,rotrBL:Ub,rotr32H:Ob,rotr32L:Pb,rotlSH:Mb,rotlSL:Fb,rotlBH:Vb,rotlBL:Hb,add:Kb,add3L:$b,add3H:qb,add4L:Wb,add4H:zb,add5H:jb,add5L:Gb},Y=Yb;var[Zb,Xb]=Y.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))),tr=new Uint32Array(80),rr=new Uint32Array(80),mc=class extends on{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:s,Ch:o,Cl:i,Dh:a,Dl:c,Eh:u,El:l,Fh:f,Fl:m,Gh:g,Gl:d,Hh:h,Hl:p}=this;return[e,t,n,s,o,i,a,c,u,l,f,m,g,d,h,p]}set(e,t,n,s,o,i,a,c,u,l,f,m,g,d,h,p){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=s|0,this.Ch=o|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=l|0,this.Fh=f|0,this.Fl=m|0,this.Gh=g|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)tr[b]=e.getUint32(t),rr[b]=e.getUint32(t+=4);for(let b=16;b<80;b++){let v=tr[b-15]|0,E=rr[b-15]|0,A=Y.rotrSH(v,E,1)^Y.rotrSH(v,E,8)^Y.shrSH(v,E,7),S=Y.rotrSL(v,E,1)^Y.rotrSL(v,E,8)^Y.shrSL(v,E,7),D=tr[b-2]|0,_=rr[b-2]|0,U=Y.rotrSH(D,_,19)^Y.rotrBH(D,_,61)^Y.shrSH(D,_,6),R=Y.rotrSL(D,_,19)^Y.rotrBL(D,_,61)^Y.shrSL(D,_,6),H=Y.add4L(S,R,rr[b-7],rr[b-16]),V=Y.add4H(H,A,U,tr[b-7],tr[b-16]);tr[b]=V|0,rr[b]=H|0}let{Ah:n,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:u,Dl:l,Eh:f,El:m,Fh:g,Fl:d,Gh:h,Gl:p,Hh:y,Hl:x}=this;for(let b=0;b<80;b++){let v=Y.rotrSH(f,m,14)^Y.rotrSH(f,m,18)^Y.rotrBH(f,m,41),E=Y.rotrSL(f,m,14)^Y.rotrSL(f,m,18)^Y.rotrBL(f,m,41),A=f&g^~f&h,S=m&d^~m&p,D=Y.add5L(x,E,S,Xb[b],rr[b]),_=Y.add5H(D,y,v,A,Zb[b],tr[b]),U=D|0,R=Y.rotrSH(n,s,28)^Y.rotrBH(n,s,34)^Y.rotrBH(n,s,39),H=Y.rotrSL(n,s,28)^Y.rotrBL(n,s,34)^Y.rotrBL(n,s,39),V=n&o^n&a^o&a,G=s&i^s&c^i&c;y=h|0,x=p|0,h=g|0,p=d|0,g=f|0,d=m|0,{h:f,l:m}=Y.add(u|0,l|0,_|0,U|0),u=a|0,l=c|0,a=o|0,c=i|0,o=n|0,i=s|0;let B=Y.add3L(U,H,G);n=Y.add3H(B,_,R,V),s=B|0}({h:n,l:s}=Y.add(this.Ah|0,this.Al|0,n|0,s|0)),{h:o,l:i}=Y.add(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=Y.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=Y.add(this.Dh|0,this.Dl|0,u|0,l|0),{h:f,l:m}=Y.add(this.Eh|0,this.El|0,f|0,m|0),{h:g,l:d}=Y.add(this.Fh|0,this.Fl|0,g|0,d|0),{h,l:p}=Y.add(this.Gh|0,this.Gl|0,h|0,p|0),{h:y,l:x}=Y.add(this.Hh|0,this.Hl|0,y|0,x|0),this.set(n,s,o,i,a,c,u,l,f,m,g,d,h,p,y,x)}roundClean(){tr.fill(0),rr.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 an=mo(()=>new mc);var yo={};J(yo,{bitGet:()=>sy,bitLen:()=>ny,bitMask:()=>Gn,bitSet:()=>oy,bytesToHex:()=>Rt,bytesToNumberBE:()=>Nt,bytesToNumberLE:()=>at,concatBytes:()=>Ut,createHmacDrbg:()=>yc,ensureBytes:()=>ie,equalBytes:()=>ty,hexToBytes:()=>Ir,hexToNumber:()=>bc,isBytes:()=>it,numberToBytesBE:()=>nr,numberToBytesLE:()=>Lt,numberToHexUnpadded:()=>Yf,numberToVarBytesBE:()=>ey,utf8ToBytes:()=>ry,validateObject:()=>Ye});var jf=BigInt(0),bo=BigInt(1),Jb=BigInt(2);function it(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var Qb=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function Rt(r){if(!it(r))throw new Error("Uint8Array expected");let e="";for(let t=0;t<r.length;t++)e+=Qb[r[t]];return e}function Yf(r){let e=r.toString(16);return e.length&1?`0${e}`:e}function bc(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var _t={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function zf(r){if(r>=_t._0&&r<=_t._9)return r-_t._0;if(r>=_t._A&&r<=_t._F)return r-(_t._A-10);if(r>=_t._a&&r<=_t._f)return r-(_t._a-10)}function Ir(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 s=0,o=0;s<t;s++,o+=2){let i=zf(r.charCodeAt(o)),a=zf(r.charCodeAt(o+1));if(i===void 0||a===void 0){let c=r[o]+r[o+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+o)}n[s]=i*16+a}return n}function Nt(r){return bc(Rt(r))}function at(r){if(!it(r))throw new Error("Uint8Array expected");return bc(Rt(Uint8Array.from(r).reverse()))}function nr(r,e){return Ir(r.toString(16).padStart(e*2,"0"))}function Lt(r,e){return nr(r,e).reverse()}function ey(r){return Ir(Yf(r))}function ie(r,e,t){let n;if(typeof e=="string")try{n=Ir(e)}catch(o){throw new Error(`${r} must be valid hex string, got "${e}". Cause: ${o}`)}else if(it(e))n=Uint8Array.from(e);else throw new Error(`${r} must be hex string or Uint8Array`);let s=n.length;if(typeof t=="number"&&s!==t)throw new Error(`${r} expected ${t} bytes, got ${s}`);return n}function Ut(...r){let e=0;for(let s=0;s<r.length;s++){let o=r[s];if(!it(o))throw new Error("Uint8Array expected");e+=o.length}let t=new Uint8Array(e),n=0;for(let s=0;s<r.length;s++){let o=r[s];t.set(o,n),n+=o.length}return t}function ty(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 ry(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function ny(r){let e;for(e=0;r>jf;r>>=bo,e+=1);return e}function sy(r,e){return r>>BigInt(e)&bo}var oy=(r,e,t)=>r|(t?bo:jf)<<BigInt(e),Gn=r=>(Jb<<BigInt(r-1))-bo,gc=r=>new Uint8Array(r),Gf=r=>Uint8Array.from(r);function yc(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=gc(r),s=gc(r),o=0,i=()=>{n.fill(1),s.fill(0),o=0},a=(...f)=>t(s,n,...f),c=(f=gc())=>{s=a(Gf([0]),f),n=a(),f.length!==0&&(s=a(Gf([1]),f),n=a())},u=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,m=[];for(;f<e;){n=a();let g=n.slice();m.push(g),f+=n.length}return Ut(...m)};return(f,m)=>{i(),c(f);let g;for(;!(g=m(u()));)c();return i(),g}}var iy={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"||it(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 Ye(r,e,t={}){let n=(s,o,i)=>{let a=iy[o];if(typeof a!="function")throw new Error(`Invalid validator "${o}", expected function`);let c=r[s];if(!(i&&c===void 0)&&!a(c,r))throw new Error(`Invalid param ${String(s)}=${c} (${typeof c}), expected ${o}`)};for(let[s,o]of Object.entries(e))n(s,o,!1);for(let[s,o]of Object.entries(t))n(s,o,!0);return r}var Se=BigInt(0),ue=BigInt(1),Tr=BigInt(2),ay=BigInt(3),wc=BigInt(4),Zf=BigInt(5),Xf=BigInt(8),cy=BigInt(9),uy=BigInt(16);function ee(r,e){let t=r%e;return t>=Se?t:e+t}function xc(r,e,t){if(t<=Se||e<Se)throw new Error("Expected power/modulo > 0");if(t===ue)return Se;let n=ue;for(;e>Se;)e&ue&&(n=n*r%t),r=r*r%t,e>>=ue;return n}function ae(r,e,t){let n=r;for(;e-- >Se;)n*=n,n%=t;return n}function wo(r,e){if(r===Se||e<=Se)throw new Error(`invert: expected positive integers, got n=${r} mod=${e}`);let t=ee(r,e),n=e,s=Se,o=ue,i=ue,a=Se;for(;t!==Se;){let u=n/t,l=n%t,f=s-i*u,m=o-a*u;n=t,t=l,s=i,o=a,i=f,a=m}if(n!==ue)throw new Error("invert: does not exist");return ee(s,e)}function ly(r){let e=(r-ue)/Tr,t,n,s;for(t=r-ue,n=0;t%Tr===Se;t/=Tr,n++);for(s=Tr;s<r&&xc(s,e,r)!==r-ue;s++);if(n===1){let i=(r+ue)/wc;return function(c,u){let l=c.pow(u,i);if(!c.eql(c.sqr(l),u))throw new Error("Cannot find square root");return l}}let o=(t+ue)/Tr;return function(a,c){if(a.pow(c,e)===a.neg(a.ONE))throw new Error("Cannot find square root");let u=n,l=a.pow(a.mul(a.ONE,s),t),f=a.pow(c,o),m=a.pow(c,t);for(;!a.eql(m,a.ONE);){if(a.eql(m,a.ZERO))return a.ZERO;let g=1;for(let h=a.sqr(m);g<u&&!a.eql(h,a.ONE);g++)h=a.sqr(h);let d=a.pow(l,ue<<BigInt(u-g-1));l=a.sqr(d),f=a.mul(f,d),m=a.mul(m,l),u=g}return f}}function fy(r){if(r%wc===ay){let e=(r+ue)/wc;return function(n,s){let o=n.pow(s,e);if(!n.eql(n.sqr(o),s))throw new Error("Cannot find square root");return o}}if(r%Xf===Zf){let e=(r-Zf)/Xf;return function(n,s){let o=n.mul(s,Tr),i=n.pow(o,e),a=n.mul(s,i),c=n.mul(n.mul(a,Tr),i),u=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(u),s))throw new Error("Cannot find square root");return u}}return r%uy,ly(r)}var Jf=(r,e)=>(ee(r,e)&ue)===ue,hy=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ec(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=hy.reduce((n,s)=>(n[s]="function",n),e);return Ye(r,t)}function dy(r,e,t){if(t<Se)throw new Error("Expected power > 0");if(t===Se)return r.ONE;if(t===ue)return e;let n=r.ONE,s=e;for(;t>Se;)t&ue&&(n=r.mul(n,s)),s=r.sqr(s),t>>=ue;return n}function py(r,e){let t=new Array(e.length),n=e.reduce((o,i,a)=>r.is0(i)?o:(t[a]=o,r.mul(o,i)),r.ONE),s=r.inv(n);return e.reduceRight((o,i,a)=>r.is0(i)?o:(t[a]=r.mul(o,t[a]),r.mul(o,i)),s),t}function vc(r,e){let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function xo(r,e,t=!1,n={}){if(r<=Se)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:s,nByteLength:o}=vc(r,e);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");let i=fy(r),a=Object.freeze({ORDER:r,BITS:s,BYTES:o,MASK:Gn(s),ZERO:Se,ONE:ue,create:c=>ee(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return Se<=c&&c<r},is0:c=>c===Se,isOdd:c=>(c&ue)===ue,neg:c=>ee(-c,r),eql:(c,u)=>c===u,sqr:c=>ee(c*c,r),add:(c,u)=>ee(c+u,r),sub:(c,u)=>ee(c-u,r),mul:(c,u)=>ee(c*u,r),pow:(c,u)=>dy(a,c,u),div:(c,u)=>ee(c*wo(u,r),r),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>wo(c,r),sqrt:n.sqrt||(c=>i(a,c)),invertBatch:c=>py(a,c),cmov:(c,u,l)=>l?u:c,toBytes:c=>t?Lt(c,o):nr(c,o),fromBytes:c=>{if(c.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${c.length}`);return t?at(c):Nt(c)}});return Object.freeze(a)}function Qf(r,e){if(!r.isOdd)throw new Error("Field doesn't have isOdd");let t=r.sqrt(e);return r.isOdd(t)?r.neg(t):t}function eh(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 Ac(r){let e=eh(r);return e+Math.ceil(e/2)}function th(r,e,t=!1){let n=r.length,s=eh(e),o=Ac(e);if(n<16||n<o||n>1024)throw new Error(`expected ${o}-1024 bytes of input, got ${n}`);let i=t?Nt(r):at(r),a=ee(i,e-ue)+ue;return t?Lt(a,s):nr(a,s)}var gy=BigInt(0),Dc=BigInt(1);function Eo(r,e){let t=(s,o)=>{let i=o.negate();return s?i:o},n=s=>{let o=Math.ceil(e/s)+1,i=2**(s-1);return{windows:o,windowSize:i}};return{constTimeNegate:t,unsafeLadder(s,o){let i=r.ZERO,a=s;for(;o>gy;)o&Dc&&(i=i.add(a)),a=a.double(),o>>=Dc;return i},precomputeWindow(s,o){let{windows:i,windowSize:a}=n(o),c=[],u=s,l=u;for(let f=0;f<i;f++){l=u,c.push(l);for(let m=1;m<a;m++)l=l.add(u),c.push(l);u=l.double()}return c},wNAF(s,o,i){let{windows:a,windowSize:c}=n(s),u=r.ZERO,l=r.BASE,f=BigInt(2**s-1),m=2**s,g=BigInt(s);for(let d=0;d<a;d++){let h=d*c,p=Number(i&f);i>>=g,p>c&&(p-=m,i+=Dc);let y=h,x=h+Math.abs(p)-1,b=d%2!==0,v=p<0;p===0?l=l.add(t(b,o[y])):u=u.add(t(v,o[x]))}return{p:u,f:l}},wNAFCached(s,o,i,a){let c=s._WINDOW_SIZE||1,u=o.get(s);return u||(u=this.precomputeWindow(s,c),c!==1&&o.set(s,a(u))),this.wNAF(c,u,i)}}}function jn(r){return Ec(r.Fp),Ye(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...vc(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var ct=BigInt(0),ze=BigInt(1),vo=BigInt(2),by=BigInt(8),yy={zip215:!0};function wy(r){let e=jn(r);return Ye(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function Ao(r){let e=wy(r),{Fp:t,n,prehash:s,hash:o,randomBytes:i,nByteLength:a,h:c}=e,u=vo<<BigInt(a*8)-ze,l=t.create,f=e.uvRatio||((k,w)=>{try{return{isValid:!0,value:t.sqrt(k*t.inv(w))}}catch{return{isValid:!1,value:ct}}}),m=e.adjustScalarBytes||(k=>k),g=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"&&ct<k,h=(k,w)=>d(k)&&d(w)&&k<w,p=k=>k===ct||h(k,u);function y(k,w){if(h(k,w))return k;throw new Error(`Expected valid scalar < ${w}, got ${typeof k} ${k}`)}function x(k){return k===ct?k:y(k,n)}let b=new Map;function v(k){if(!(k instanceof E))throw new Error("ExtendedPoint expected")}class E{constructor(w,C,T,O){if(this.ex=w,this.ey=C,this.ez=T,this.et=O,!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(O))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(w){if(w instanceof E)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 E(C,T,ze,l(C*T))}static normalizeZ(w){let C=t.invertBatch(w.map(T=>T.ez));return w.map((T,O)=>T.toAffine(C[O])).map(E.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:O,ez:$,et:q}=this,Z=l(T*T),W=l(O*O),j=l($*$),oe=l(j*j),se=l(Z*w),Ce=l(j*l(se+W)),Ie=l(oe+l(C*l(Z*W)));if(Ce!==Ie)throw new Error("bad point: equation left != right (1)");let Ee=l(T*O),Le=l($*q);if(Ee!==Le)throw new Error("bad point: equation left != right (2)")}equals(w){v(w);let{ex:C,ey:T,ez:O}=this,{ex:$,ey:q,ez:Z}=w,W=l(C*Z),j=l($*O),oe=l(T*Z),se=l(q*O);return W===j&&oe===se}is0(){return this.equals(E.ZERO)}negate(){return new E(l(-this.ex),this.ey,this.ez,l(-this.et))}double(){let{a:w}=e,{ex:C,ey:T,ez:O}=this,$=l(C*C),q=l(T*T),Z=l(vo*l(O*O)),W=l(w*$),j=C+T,oe=l(l(j*j)-$-q),se=W+q,Ce=se-Z,Ie=W-q,Ee=l(oe*Ce),Le=l(se*Ie),Dt=l(oe*Ie),dr=l(Ce*se);return new E(Ee,Le,dr,Dt)}add(w){v(w);let{a:C,d:T}=e,{ex:O,ey:$,ez:q,et:Z}=this,{ex:W,ey:j,ez:oe,et:se}=w;if(C===BigInt(-1)){let Gu=l(($-O)*(j+W)),ju=l(($+O)*(j-W)),Pi=l(ju-Gu);if(Pi===ct)return this.double();let Yu=l(q*vo*se),Zu=l(Z*vo*oe),Xu=Zu+Yu,Ju=ju+Gu,Qu=Zu-Yu,Lp=l(Xu*Pi),Up=l(Ju*Qu),Op=l(Xu*Qu),Pp=l(Pi*Ju);return new E(Lp,Up,Pp,Op)}let Ce=l(O*W),Ie=l($*j),Ee=l(Z*T*se),Le=l(q*oe),Dt=l((O+$)*(W+j)-Ce-Ie),dr=Le-Ee,Rn=Le+Ee,zu=l(Ie-C*Ce),Tp=l(Dt*dr),_p=l(Rn*zu),Rp=l(Dt*zu),Np=l(dr*Rn);return new E(Tp,_p,Np,Rp)}subtract(w){return this.add(w.negate())}wNAF(w){return D.wNAFCached(this,b,w,E.normalizeZ)}multiply(w){let{p:C,f:T}=this.wNAF(y(w,n));return E.normalizeZ([C,T])[0]}multiplyUnsafe(w){let C=x(w);return C===ct?S:this.equals(S)||C===ze?this:this.equals(A)?this.wNAF(C).p:D.unsafeLadder(this,C)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return D.unsafeLadder(this,n).is0()}toAffine(w){let{ex:C,ey:T,ez:O}=this,$=this.is0();w==null&&(w=$?by:t.inv(O));let q=l(C*w),Z=l(T*w),W=l(O*w);if($)return{x:ct,y:ze};if(W!==ze)throw new Error("invZ was invalid");return{x:q,y:Z}}clearCofactor(){let{h:w}=e;return w===ze?this:this.multiplyUnsafe(w)}static fromHex(w,C=!1){let{d:T,a:O}=e,$=t.BYTES;w=ie("pointHex",w,$);let q=w.slice(),Z=w[$-1];q[$-1]=Z&-129;let W=at(q);W===ct||(C?y(W,u):y(W,t.ORDER));let j=l(W*W),oe=l(j-ze),se=l(T*j-O),{isValid:Ce,value:Ie}=f(oe,se);if(!Ce)throw new Error("Point.fromHex: invalid y coordinate");let Ee=(Ie&ze)===ze,Le=(Z&128)!==0;if(!C&&Ie===ct&&Le)throw new Error("Point.fromHex: x=0 and x_0=1");return Le!==Ee&&(Ie=l(-Ie)),E.fromAffine({x:Ie,y:W})}static fromPrivateKey(w){return R(w).point}toRawBytes(){let{x:w,y:C}=this.toAffine(),T=Lt(C,t.BYTES);return T[T.length-1]|=w&ze?128:0,T}toHex(){return Rt(this.toRawBytes())}}E.BASE=new E(e.Gx,e.Gy,ze,l(e.Gx*e.Gy)),E.ZERO=new E(ct,ze,ze,ct);let{BASE:A,ZERO:S}=E,D=Eo(E,a*8);function _(k){return ee(k,n)}function U(k){return _(at(k))}function R(k){let w=a;k=ie("private key",k,w);let C=ie("hashed private key",o(k),2*w),T=m(C.slice(0,w)),O=C.slice(w,2*w),$=U(T),q=A.multiply($),Z=q.toRawBytes();return{head:T,prefix:O,scalar:$,point:q,pointBytes:Z}}function H(k){return R(k).pointBytes}function V(k=new Uint8Array,...w){let C=Ut(...w);return U(o(g(C,ie("context",k),!!s)))}function G(k,w,C={}){k=ie("message",k),s&&(k=s(k));let{prefix:T,scalar:O,pointBytes:$}=R(w),q=V(C.context,T,k),Z=A.multiply(q).toRawBytes(),W=V(C.context,Z,$,k),j=_(q+W*O);x(j);let oe=Ut(Z,Lt(j,t.BYTES));return ie("result",oe,a*2)}let B=yy;function I(k,w,C,T=B){let{context:O,zip215:$}=T,q=t.BYTES;k=ie("signature",k,2*q),w=ie("message",w),s&&(w=s(w));let Z=at(k.slice(q,2*q)),W,j,oe;try{W=E.fromHex(C,$),j=E.fromHex(k.slice(0,q),$),oe=A.multiplyUnsafe(Z)}catch{return!1}if(!$&&W.isSmallOrder())return!1;let se=V(O,j.toRawBytes(),W.toRawBytes(),w);return j.add(W.multiplyUnsafe(se)).subtract(oe).clearCofactor().equals(E.ZERO)}return A._setWindowSize(8),{CURVE:e,getPublicKey:H,sign:G,verify:I,ExtendedPoint:E,utils:{getExtendedPublicKey:R,randomPrivateKey:()=>i(t.BYTES),precompute(k=8,w=E.BASE){return w._setWindowSize(k),w.multiply(BigInt(3)),w}}}}var Yn=BigInt(0),Bc=BigInt(1);function xy(r){return Ye(r,{a:"bigint"},{montgomeryBits:"isSafeInteger",nByteLength:"isSafeInteger",adjustScalarBytes:"function",domain:"function",powPminus2:"function",Gu:"bigint"}),Object.freeze({...r})}function rh(r){let e=xy(r),{P:t}=e,n=b=>ee(b,t),s=e.montgomeryBits,o=Math.ceil(s/8),i=e.nByteLength,a=e.adjustScalarBytes||(b=>b),c=e.powPminus2||(b=>xc(b,t-BigInt(2),t));function u(b,v,E){let A=n(b*(v-E));return v=n(v-A),E=n(E+A),[v,E]}function l(b){if(typeof b=="bigint"&&Yn<=b&&b<t)return b;throw new Error("Expected valid scalar 0 < scalar < CURVE.P")}let f=(e.a-BigInt(2))/BigInt(4);function m(b,v){let E=l(b),A=l(v),S=E,D=Bc,_=Yn,U=E,R=Bc,H=Yn,V;for(let B=BigInt(s-1);B>=Yn;B--){let I=A>>B&Bc;H^=I,V=u(H,D,U),D=V[0],U=V[1],V=u(H,_,R),_=V[0],R=V[1],H=I;let P=D+_,k=n(P*P),w=D-_,C=n(w*w),T=k-C,O=U+R,$=U-R,q=n($*P),Z=n(O*w),W=q+Z,j=q-Z;U=n(W*W),R=n(S*n(j*j)),D=n(k*C),_=n(T*(k+n(f*T)))}V=u(H,D,U),D=V[0],U=V[1],V=u(H,_,R),_=V[0],R=V[1];let G=c(_);return n(D*G)}function g(b){return Lt(n(b),o)}function d(b){let v=ie("u coordinate",b,o);return i===32&&(v[31]&=127),at(v)}function h(b){let v=ie("scalar",b),E=v.length;if(E!==o&&E!==i)throw new Error(`Expected ${o} or ${i} bytes, got ${E}`);return at(a(v))}function p(b,v){let E=d(v),A=h(b),S=m(E,A);if(S===Yn)throw new Error("Invalid private or public key received");return g(S)}let y=g(e.Gu);function x(b){return p(b,y)}return{scalarMult:p,scalarMultBase:x,getSharedSecret:(b,v)=>p(b,v),getPublicKey:b=>x(b),utils:{randomPrivateKey:()=>e.randomBytes(e.nByteLength)},GuBytes:y}}var Zn=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),nh=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),TD=BigInt(0),Ey=BigInt(1),Sc=BigInt(2),vy=BigInt(5),sh=BigInt(10),Ay=BigInt(20),Dy=BigInt(40),oh=BigInt(80);function ih(r){let e=Zn,n=r*r%e*r%e,s=ae(n,Sc,e)*n%e,o=ae(s,Ey,e)*r%e,i=ae(o,vy,e)*o%e,a=ae(i,sh,e)*i%e,c=ae(a,Ay,e)*a%e,u=ae(c,Dy,e)*c%e,l=ae(u,oh,e)*u%e,f=ae(l,oh,e)*u%e,m=ae(f,sh,e)*i%e;return{pow_p_5_8:ae(m,Sc,e)*r%e,b2:n}}function ah(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function By(r,e){let t=Zn,n=ee(e*e*e,t),s=ee(n*n*e,t),o=ih(r*s).pow_p_5_8,i=ee(r*n*o,t),a=ee(e*i*i,t),c=i,u=ee(i*nh,t),l=a===r,f=a===ee(-r,t),m=a===ee(-r*nh,t);return l&&(i=c),(f||m)&&(i=u),Jf(i,t)&&(i=ee(-i,t)),{isValid:l||f,value:i}}var Ot=xo(Zn,void 0,!0),kc={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Ot,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:an,randomBytes:Cr,adjustScalarBytes:ah,uvRatio:By},cn=Ao(kc);function ch(r,e,t){if(e.length>255)throw new Error("Context is too big");return po(dc("SigEd25519 no Ed25519 collisions"),new Uint8Array([t?1:0,e.length]),e,r)}var _D=Ao({...kc,domain:ch}),RD=Ao({...kc,domain:ch,prehash:an}),Xn=rh({P:Zn,a:BigInt(486662),montgomeryBits:255,nByteLength:32,Gu:BigInt(9),powPminus2:r=>{let e=Zn,{pow_p_5_8:t,b2:n}=ih(r);return ee(ae(t,BigInt(3),e)*n,e)},adjustScalarBytes:ah,randomBytes:Cr});var Sy=(Ot.ORDER+BigInt(3))/BigInt(8),ND=Ot.pow(Sc,Sy),LD=Ot.sqrt(Ot.neg(Ot.ONE)),UD=(Ot.ORDER-BigInt(5))/BigInt(8),OD=BigInt(486662);var PD=Qf(Ot,Ot.neg(BigInt(486664)));var MD=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),FD=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),VD=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),HD=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");var KD=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var un=32,Pt=64,Do=32;function uh(){let r=cn.utils.randomPrivateKey(),e=cn.getPublicKey(r);return{privateKey:dh(r,e),publicKey:e}}function lh(r){if(r.length!==Do)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=cn.getPublicKey(e);return{privateKey:dh(e,t),publicKey:t}}function fh(r,e){let t=r.subarray(0,Do);return cn.sign(e instanceof Uint8Array?e:e.subarray(),t)}function hh(r,e,t){return cn.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}function dh(r,e){let t=new Uint8Array(Pt);for(let n=0;n<Do;n++)t[n]=r[n],t[Do+n]=e[n];return t}var Me={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 Cc={alg:"A128GCM",ext:!0,k:"scm9jmO_4BJAgdwWGVulLg",key_ops:["encrypt","decrypt"],kty:"oct"};function ph(r){let e=r?.algorithm??"AES-GCM",t=r?.keyLength??16,n=r?.nonceLength??12,s=r?.digest??"SHA-256",o=r?.saltLength??16,i=r?.iterations??32767,a=Me.get();t*=8;async function c(f,m){let g=a.getRandomValues(new Uint8Array(o)),d=a.getRandomValues(new Uint8Array(n)),h={name:e,iv:d};typeof m=="string"&&(m=Q(m));let p;if(m.length===0){p=await a.subtle.importKey("jwk",Cc,{name:"AES-GCM"},!0,["encrypt"]);try{let x={name:"PBKDF2",salt:g,iterations:i,hash:{name:s}},b=await a.subtle.importKey("raw",m,{name:"PBKDF2"},!1,["deriveKey"]);p=await a.subtle.deriveKey(x,b,{name:e,length:t},!0,["encrypt"])}catch{p=await a.subtle.importKey("jwk",Cc,{name:"AES-GCM"},!0,["encrypt"])}}else{let x={name:"PBKDF2",salt:g,iterations:i,hash:{name:s}},b=await a.subtle.importKey("raw",m,{name:"PBKDF2"},!1,["deriveKey"]);p=await a.subtle.deriveKey(x,b,{name:e,length:t},!0,["encrypt"])}let y=await a.subtle.encrypt(h,p,f);return we([g,h.iv,new Uint8Array(y)])}async function u(f,m){let g=f.subarray(0,o),d=f.subarray(o,o+n),h=f.subarray(o+n),p={name:e,iv:d};typeof m=="string"&&(m=Q(m));let y;if(m.length===0)try{let b={name:"PBKDF2",salt:g,iterations:i,hash:{name:s}},v=await a.subtle.importKey("raw",m,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(b,v,{name:e,length:t},!0,["decrypt"])}catch{y=await a.subtle.importKey("jwk",Cc,{name:"AES-GCM"},!0,["decrypt"])}else{let b={name:"PBKDF2",salt:g,iterations:i,hash:{name:s}},v=await a.subtle.importKey("raw",m,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(b,v,{name:e,length:t},!0,["decrypt"])}let x=await a.subtle.decrypt(p,y,h);return new Uint8Array(x)}return{encrypt:c,decrypt:u}}async function ln(r,e){let n=await ph().encrypt(r,e);return Zi.encode(n)}var le;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.Secp256k1="Secp256k1"})(le||(le={}));var Ic;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.Secp256k1=2]="Secp256k1"})(Ic||(Ic={}));(function(r){r.codec=()=>Ar(Ic)})(le||(le={}));var yt;(function(r){let e;r.codec=()=>(e==null&&(e=nt((t,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),le.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),s.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let s={},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let i=t.uint32();switch(i>>>3){case 1:s.Type=le.codec().decode(t);break;case 2:s.Data=t.bytes();break;default:t.skipType(i&7);break}}return s})),e),r.encode=t=>rt(t,r.codec()),r.decode=t=>tt(t,r.codec())})(yt||(yt={}));var wt;(function(r){let e;r.codec=()=>(e==null&&(e=nt((t,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),le.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),s.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let s={},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let i=t.uint32();switch(i>>>3){case 1:s.Type=le.codec().decode(t);break;case 2:s.Data=t.bytes();break;default:t.skipType(i&7);break}}return s})),e),r.encode=t=>rt(t,r.codec()),r.decode=t=>tt(t,r.codec())})(wt||(wt={}));var Jn=class{_key;constructor(e){this._key=fn(e,un)}verify(e,t){return hh(this._key,t,e)}marshal(){return this._key}get bytes(){return yt.encode({Type:le.Ed25519,Data:this.marshal()}).subarray()}equals(e){return ve(this.bytes,e.bytes)}hash(){let e=Te.digest(this.bytes);return je(e)?e.then(({bytes:t})=>t):e.bytes}},_r=class{_key;_publicKey;constructor(e,t){this._key=fn(e,Pt),this._publicKey=fn(t,un)}sign(e){return fh(this._key,e)}get public(){return new Jn(this._publicKey)}marshal(){return this._key}get bytes(){return wt.encode({Type:le.Ed25519,Data:this.marshal()}).subarray()}equals(e){return ve(this.bytes,e.bytes)}async hash(){let e=Te.digest(this.bytes),t;return je(e)?{bytes:t}=await e:t=e.bytes,t}async id(){let e=Yt.digest(this.public.bytes);return pe.encode(e.bytes).substring(1)}async export(e,t="libp2p-key"){if(t==="libp2p-key")return ln(this.bytes,e);throw new N(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function Iy(r){if(r.length>Pt){r=fn(r,Pt+un);let n=r.subarray(0,Pt),s=r.subarray(Pt,r.length);return new _r(n,s)}r=fn(r,Pt);let e=r.subarray(0,Pt),t=r.subarray(un);return new _r(e,t)}function Ty(r){return r=fn(r,un),new Jn(r)}async function _y(){let{privateKey:r,publicKey:e}=uh();return new _r(r,e)}async function mh(r){let{privateKey:e,publicKey:t}=lh(r);return new _r(e,t)}function fn(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new N(`Key must be a Uint8Array of length ${e}, got ${r.length}`,"ERR_INVALID_KEY_TYPE");return r}var Vc={};J(Vc,{MAX_RSA_KEY_SIZE:()=>us,RsaPrivateKey:()=>gn,RsaPublicKey:()=>cs,fromJwk:()=>sw,generateKeyPair:()=>ow,unmarshalRsaPrivateKey:()=>Mc,unmarshalRsaPublicKey:()=>nw});function Rr(r){if(isNaN(r)||r<=0)throw new N("random bytes length must be a Number bigger than 0","ERR_INVALID_LENGTH");return Cr(r)}var cr={};J(cr,{exportToPem:()=>Jy,importFromPem:()=>Qy,jwkToPkcs1:()=>jy,jwkToPkix:()=>Zy,pkcs1ToJwk:()=>Gy,pkixToJwk:()=>Yy});var So=class extends nn{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,kr(e);let n=ot(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 s=this.blockLen,o=new Uint8Array(s);o.set(n.length>s?e.create().update(n).digest():n);for(let i=0;i<o.length;i++)o[i]^=54;this.iHash.update(o),this.oHash=e.create();for(let i=0;i<o.length;i++)o[i]^=106;this.oHash.update(o),o.fill(0)}update(e){return rn(this),this.iHash.update(e),this}digestInto(e){rn(this),hc(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:s,destroyed:o,blockLen:i,outputLen:a}=this;return e=e,e.finished=s,e.destroyed=o,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()}},sr=(r,e,t)=>new So(r,e).update(t).digest();sr.create=(r,e)=>new So(r,e);function Ry(r,e,t,n){kr(r);let s=qf({dkLen:32,asyncTick:10},n),{c:o,dkLen:i,asyncTick:a}=s;if(er(o),er(i),er(a),o<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let c=ot(e),u=ot(t),l=new Uint8Array(i),f=sr.create(r,c),m=f._cloneInto().update(u);return{c:o,dkLen:i,asyncTick:a,DK:l,PRF:f,PRFSalt:m}}function Ny(r,e,t,n,s){return r.destroy(),e.destroy(),n&&n.destroy(),s.fill(0),t}async function _c(r,e,t,n){let{c:s,dkLen:o,asyncTick:i,DK:a,PRF:c,PRFSalt:u}=Ry(r,e,t,n),l,f=new Uint8Array(4),m=sn(f),g=new Uint8Array(c.outputLen);for(let d=1,h=0;h<o;d++,h+=c.outputLen){let p=a.subarray(h,h+c.outputLen);m.setInt32(0,d,!1),(l=u._cloneInto(l)).update(f).digestInto(g),p.set(g.subarray(0,p.length)),await $f(s-1,i,()=>{c._cloneInto(l).update(g).digestInto(g);for(let y=0;y<p.length;y++)p[y]^=g[y]})}return Ny(c,u,a,l,g)}var X=Ds(gh());function Nr(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 or(r,e,t=-1){let n=t,s=r,o=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),o=a;else{if(n<a)return new ArrayBuffer(0);c=new ArrayBuffer(n),o=n}let u=new Uint8Array(c);for(let l=a-1;l>=0;l--){let f=Math.pow(2,l*e);u[o-l-1]=Math.floor(s/f),s-=u[o-l-1]*f}return c}i*=Math.pow(2,e)}return new ArrayBuffer(0)}function Io(...r){let e=0,t=0;for(let o of r)e+=o.length;let n=new ArrayBuffer(e),s=new Uint8Array(n);for(let o of r)s.set(o,t),t+=o.length;return s}function Nc(){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=Nr(t,8),s=new ArrayBuffer(this.valueHex.byteLength),o=new Uint8Array(s);for(let a=0;a<this.valueHex.byteLength;a++)o[a]=r[a];return o[0]&=127,Nr(o,8)-n}function bh(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=or(i,8,n),c=new Uint8Array(a);return c[0]|=128,a}let s=or(e,8,n),o=new Uint8Array(s);if(o[0]&128){let i=s.slice(0),a=new Uint8Array(i);s=new ArrayBuffer(s.byteLength+1),o=new Uint8Array(s);for(let c=0;c<i.byteLength;c++)o[c+1]=a[c];o[0]=0}return s}t*=Math.pow(2,8)}return new ArrayBuffer(0)}function yh(r,e){if(r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let s=0;s<t.length;s++)if(t[s]!==n[s])return!1;return!0}function $e(r,e){let t=r.toString(10);if(e<t.length)return"";let n=e-t.length,s=new Array(n);for(let i=0;i<n;i++)s[i]="0";return s.join("").concat(t)}var g4=Math.log(2);function To(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function Lc(r){let e=0,t=0;for(let s=0;s<r.length;s++){let o=r[s];e+=o.byteLength}let n=new Uint8Array(e);for(let s=0;s<r.length;s++){let o=r[s];n.set(new Uint8Array(o),t),t+=o.byteLength}return n.buffer}function Kt(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 es=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return Lc(this.items)}},Qn=[new Uint8Array([1])],wh="0123456789";var pn="",lt=new ArrayBuffer(0),Uc=new Uint8Array(0),ts="EndOfContent",Eh="OCTET STRING",vh="BIT STRING";function $t(r){var e;return e=class extends r{constructor(...n){var s;super(...n);let o=n[0]||{};this.isHexOnly=(s=o.isHexOnly)!==null&&s!==void 0?s:!1,this.valueHexView=o.valueHex?X.BufferSourceConverter.toUint8Array(o.valueHex):Uc}get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}fromBER(n,s,o){let i=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!Kt(this,i,s,o))return-1;let a=s+o;return this.valueHexView=i.subarray(s,a),this.valueHexView.length?(this.blockLength=o,a):(this.warnings.push("Zero buffer length"),s)}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",lt)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:X.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var Ft=class{constructor({blockLength:e=0,error:t=pn,warnings:n=[],valueBeforeDecode:s=Uc}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=X.BufferSourceConverter.toUint8Array(s)}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)}}};Ft.NAME="baseBlock";var Pe=class extends Ft{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'")}};Pe.NAME="valueBlock";var _o=class extends $t(Ft){constructor({idBlock:e={}}={}){var t,n,s,o;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?X.BufferSourceConverter.toUint8Array(e.valueHex):Uc,this.tagClass=(n=e.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(s=e.tagNumber)!==null&&s!==void 0?s:-1,this.isConstructed=(o=e.isConstructed)!==null&&o!==void 0?o:!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",lt}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){let s=new Uint8Array(1);if(!e){let o=this.tagNumber;o&=31,t|=o,s[0]=t}return s.buffer}if(!this.isHexOnly){let s=or(this.tagNumber,7),o=new Uint8Array(s),i=s.byteLength,a=new Uint8Array(i+1);if(a[0]=t|31,!e){for(let c=0;c<i-1;c++)a[c+1]=o[c]|128;a[i]=o[i-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=t|31,!e){let s=this.valueHexView;for(let o=0;o<s.length-1;o++)n[o+1]=s[o]|128;n[this.valueHexView.byteLength]=s[s.length-1]}return n.buffer}fromBER(e,t,n){let s=X.BufferSourceConverter.toUint8Array(e);if(!Kt(this,s,t,n))return-1;let o=s.subarray(t,t+n);if(o.length===0)return this.error="Zero buffer length",-1;switch(o[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=(o[0]&32)===32,this.isHexOnly=!1;let a=o[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=1,u=this.valueHexView=new Uint8Array(255),l=255;for(;o[c]&128;){if(u[c-1]=o[c]&127,c++,c>=o.length)return this.error="End of input reached before message was fully decoded",-1;if(c===l){l+=255;let m=new Uint8Array(l);for(let g=0;g<u.length;g++)m[g]=u[g];u=this.valueHexView=new Uint8Array(l)}}this.blockLength=c+1,u[c-1]=o[c]&127;let f=new Uint8Array(c);for(let m=0;m<c;m++)f[m]=u[m];u=this.valueHexView=new Uint8Array(c),u.set(f),this.blockLength<=9?this.tagNumber=Nr(u,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}}};_o.NAME="identificationBlock";var Ro=class extends Ft{constructor({lenBlock:e={}}={}){var t,n,s;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=(s=e.length)!==null&&s!==void 0?s:0}fromBER(e,t,n){let s=X.BufferSourceConverter.toUint8Array(e);if(!Kt(this,s,t,n))return-1;let o=s.subarray(t,t+n);if(o.length===0)return this.error="Zero buffer length",-1;if(o[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=o[0]===128,this.isIndefiniteForm)return this.blockLength=1,t+this.blockLength;if(this.longFormUsed=!!(o[0]&128),this.longFormUsed===!1)return this.length=o[0],this.blockLength=1,t+this.blockLength;let i=o[0]&127;if(i>8)return this.error="Too big integer",-1;if(i+1>o.length)return this.error="End of input reached before message was fully decoded",-1;let a=t+1,c=s.subarray(a,a+i);return c[i-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=Nr(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 s=or(this.length,8);if(s.byteLength>127)return this.error="Too big length",lt;if(t=new ArrayBuffer(s.byteLength+1),e)return t;let o=new Uint8Array(s);n=new Uint8Array(t),n[0]=s.byteLength|128;for(let i=0;i<s.byteLength;i++)n[i+1]=o[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}}};Ro.NAME="lengthBlock";var M={},_e=class extends Ft{constructor({name:e=pn,optional:t=!1,primitiveSchema:n,...s}={},o){super(s),this.name=e,this.optional=t,n&&(this.primitiveSchema=n),this.idBlock=new _o(s),this.lenBlock=new Ro(s),this.valueBlock=o?new o(s):new Pe(s)}fromBER(e,t,n){let s=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(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),s)}toBER(e,t){let n=t||new es;t||Ah(this);let s=this.idBlock.toBER(e);if(n.write(s),this.lenBlock.isIndefiniteForm)n.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,n),n.write(new ArrayBuffer(2));else{let o=this.valueBlock.toBER(e);this.lenBlock.length=o.byteLength;let i=this.lenBlock.toBER(e);n.write(i),n.write(o)}return t?lt: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 yh(t,n)}};_e.NAME="BaseBlock";function Ah(r){if(r instanceof M.Constructed)for(let e of r.valueBlock.value)Ah(e)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var No=class extends _e{constructor({value:e=pn,...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 s=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(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),s)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}};No.NAME="BaseStringBlock";var Lo=class extends $t(Pe){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};Lo.NAME="PrimitiveValueBlock";var Dh,Uo=class extends _e{constructor(e={}){super(e,Lo),this.idBlock.isConstructed=!1}};Dh=Uo;M.Primitive=Dh;Uo.NAME="PRIMITIVE";function Ky(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,s=new _e({},Pe),o=new Ft;if(!Kt(o,r,e,t))return s.error=o.error,{offset:-1,result:s};if(!r.subarray(e,e+t).length)return s.error="Zero buffer length",{offset:-1,result:s};let a=s.idBlock.fromBER(r,e,t);if(s.idBlock.warnings.length&&s.warnings.concat(s.idBlock.warnings),a===-1)return s.error=s.idBlock.error,{offset:-1,result:s};if(e=a,t-=s.idBlock.blockLength,a=s.lenBlock.fromBER(r,e,t),s.lenBlock.warnings.length&&s.warnings.concat(s.lenBlock.warnings),a===-1)return s.error=s.lenBlock.error,{offset:-1,result:s};if(e=a,t-=s.lenBlock.blockLength,!s.idBlock.isConstructed&&s.lenBlock.isIndefiniteForm)return s.error="Indefinite length form used for primitive encoding form",{offset:-1,result:s};let c=_e;switch(s.idBlock.tagClass){case 1:if(s.idBlock.tagNumber>=37&&s.idBlock.isHexOnly===!1)return s.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:s};switch(s.idBlock.tagNumber){case 0:if(s.idBlock.isConstructed&&s.lenBlock.length>0)return s.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:s};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 s.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:s};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 u=s.idBlock.isConstructed?new M.Constructed:new M.Primitive;u.idBlock=s.idBlock,u.lenBlock=s.lenBlock,u.warnings=s.warnings,s=u}}break;case 2:case 3:case 4:default:c=s.idBlock.isConstructed?M.Constructed:M.Primitive}return s=Ky(s,c),a=s.fromBER(r,e,s.lenBlock.isIndefiniteForm?t:s.lenBlock.length),s.valueBeforeDecodeView=r.subarray(n,n+s.blockLength),{offset:a,result:s}}function mn(r){if(!r.byteLength){let e=new _e({},Pe);return e.error="Input buffer has zero length",{offset:-1,result:e}}return pi(X.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function $y(r,e){return r?1:e}var xt=class extends Pe{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let s=X.BufferSourceConverter.toUint8Array(e);if(!Kt(this,s,t,n))return-1;if(this.valueBeforeDecodeView=s.subarray(t,t+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),t;let o=t;for(;$y(this.isIndefiniteForm,n)>0;){let i=pi(s,o,n);if(i.offset===-1)return this.error=i.result.error,this.warnings.concat(i.result.warnings),-1;if(o=i.offset,this.blockLength+=i.result.blockLength,n-=i.result.blockLength,this.value.push(i.result),this.isIndefiniteForm&&i.result.constructor.NAME===ts)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===ts?this.value.pop():this.warnings.push("No EndOfContent block encoded")),o}toBER(e,t){let n=t||new es;for(let s=0;s<this.value.length;s++)this.value[s].toBER(e,n);return t?lt:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};xt.NAME="ConstructedValueBlock";var Bh,ir=class extends _e{constructor(e={}){super(e,xt),this.idBlock.isConstructed=!0}fromBER(e,t,n){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let s=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(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),s)}onAsciiEncoding(){let e=[];for(let n of this.valueBlock.value)e.push(n.toString("ascii").split(`
|
|
17
17
|
`).map(s=>` ${s}`).join(`
|
|
18
18
|
`));let t=this.idBlock.tagClass===3?`[${this.idBlock.tagNumber}]`:this.constructor.NAME;return e.length?`${t} :
|
|
19
19
|
${e.join(`
|
|
@@ -17,7 +17,7 @@ import { genUfrag } from './util.js';
|
|
|
17
17
|
/**
|
|
18
18
|
* The time to wait, in milliseconds, for the data channel handshake to complete
|
|
19
19
|
*/
|
|
20
|
-
const HANDSHAKE_TIMEOUT_MS =
|
|
20
|
+
const HANDSHAKE_TIMEOUT_MS = 10_000;
|
|
21
21
|
/**
|
|
22
22
|
* Created by converting the hexadecimal protocol code to an integer.
|
|
23
23
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../../../src/private-to-public/transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAC/C,OAAO,EAA8B,eAAe,EAAmI,MAAM,mBAAmB,CAAA;AAChN,OAAO,KAAK,CAAC,MAAM,iBAAiB,CAAA;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAA;AAC9D,OAAO,KAAK,WAAW,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAC3C,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AACtG,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,KAAK,GAAG,MAAM,UAAU,CAAA;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAKpC;;GAEG;AACH,MAAM,oBAAoB,GAAG,
|
|
1
|
+
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../../../src/private-to-public/transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAC/C,OAAO,EAA8B,eAAe,EAAmI,MAAM,mBAAmB,CAAA;AAChN,OAAO,KAAK,CAAC,MAAM,iBAAiB,CAAA;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAA;AAC9D,OAAO,KAAK,WAAW,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAC3C,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AACtG,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,KAAK,GAAG,MAAM,UAAU,CAAA;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAKpC;;GAEG;AACH,MAAM,oBAAoB,GAAG,MAAM,CAAA;AAEnC;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAW,SAAS,CAAC,eAAe,CAAC,CAAC,IAAI,CAAA;AAElE;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAW,SAAS,CAAC,UAAU,CAAC,CAAC,IAAI,CAAA;AAmB/D,MAAM,OAAO,qBAAqB;IACf,GAAG,CAAQ;IACX,OAAO,CAAgB;IACvB,UAAU,CAAiC;IAC3C,IAAI,CAA2B;IAChD,YAAa,UAA2C,EAAE,OAAkC,EAAE;QAC5F,IAAI,CAAC,GAAG,GAAG,UAAU,CAAC,MAAM,CAAC,YAAY,CAAC,sBAAsB,CAAC,CAAA;QACjE,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,UAAU,CAAC,OAAO,IAAI,IAAI,EAAE,CAAC;YAC/B,IAAI,CAAC,OAAO,GAAG;gBACb,YAAY,EAAE,UAAU,CAAC,OAAO,CAAC,oBAAoB,CAAC,0CAA0C,EAAE;oBAChG,KAAK,EAAE,OAAO;oBACd,IAAI,EAAE,kDAAkD;iBACzD,CAAC;aACH,CAAA;QACH,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,IAAI,CAAE,EAAa,EAAE,OAA0B;QACnD,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC,CAAA;QAChD,IAAI,CAAC,GAAG,CAAC,qBAAqB,EAAE,EAAE,CAAC,CAAA;QACnC,OAAO,OAAO,CAAA;IAChB,CAAC;IAED;;OAEG;IACH,cAAc,CAAE,OAA8B;QAC5C,MAAM,aAAa,CAAC,gCAAgC,CAAC,CAAA;IACvD,CAAC;IAED;;OAEG;IACH,MAAM,CAAE,UAAuB;QAC7B,OAAO,UAAU,CAAC,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC,CAAA;IACnD,CAAC;IAED;;OAEG;IACM,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG,uBAAuB,CAAA;IAEvD;;OAEG;IACM,CAAC,eAAe,CAAC,GAAG,IAAI,CAAA;IAEjC;;OAEG;IACH,KAAK,CAAC,QAAQ,CAAE,EAAa,EAAE,OAA0B;QACvD,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAA;QACxC,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAA;QAEhC,MAAM,gBAAgB,GAAG,EAAE,CAAC,SAAS,EAAE,CAAA;QACvC,IAAI,gBAAgB,KAAK,IAAI,EAAE,CAAC;YAC9B,MAAM,sBAAsB,CAAC,qCAAqC,CAAC,CAAA;QACrE,CAAC;QACD,MAAM,WAAW,GAAG,CAAC,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,CAAA;QAExD,MAAM,cAAc,GAAG,GAAG,CAAC,cAAc,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAA;QAE3D,iFAAiF;QACjF,8EAA8E;QAC9E,gFAAgF;QAChF,gCAAgC;QAChC,MAAM,WAAW,GAAG,MAAM,iBAAiB,CAAC,mBAAmB,CAAC;YAC9D,IAAI,EAAE,OAAO;YACb,UAAU,EAAE,OAAO;YACnB,IAAI,EAAE,GAAG,CAAC,uBAAuB,CAAC,cAAc,CAAC,IAAI,CAAC;SAChD,CAAC,CAAA;QAET,MAAM,cAAc,GAAG,IAAI,iBAAiB,CAAC,EAAE,YAAY,EAAE,CAAC,WAAW,CAAC,EAAE,CAAC,CAAA;QAE7E,IAAI,CAAC;YACH,wFAAwF;YACxF,wFAAwF;YACxF,YAAY;YACZ,MAAM,sBAAsB,GAAG,IAAI,OAAO,CAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;gBAC7E,MAAM,oBAAoB,GAAG,cAAc,CAAC,iBAAiB,CAAC,EAAE,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,CAAA;gBAC9F,MAAM,gBAAgB,GAAG,UAAU,CAAC,GAAG,EAAE;oBACvC,MAAM,KAAK,GAAG,yCAAyC,oBAAoB,CAAC,UAAU,EAAE,CAAA;oBACxF,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;oBACrB,IAAI,CAAC,OAAO,EAAE,YAAY,CAAC,SAAS,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAA;oBAC1D,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAA;gBACzC,CAAC,EAAE,oBAAoB,CAAC,CAAA;gBAExB,oBAAoB,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,EAAE;oBAClC,YAAY,CAAC,gBAAgB,CAAC,CAAA;oBAC9B,OAAO,CAAC,oBAAoB,CAAC,CAAA;gBAC/B,CAAC,CAAA;gBAED,mFAAmF;gBACnF,oBAAoB,CAAC,OAAO,GAAG,CAAC,KAAY,EAAE,EAAE;oBAC9C,YAAY,CAAC,gBAAgB,CAAC,CAAA;oBAC9B,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,eAAe,CAAA;oBAC/D,MAAM,KAAK,GAAG,iDAAiD,WAAW,EAAE,CAAA;oBAC5E,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;oBACrB,sGAAsG;oBACtG,IAAI,CAAC,OAAO,EAAE,YAAY,CAAC,SAAS,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAA;oBAC7D,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAA;gBACzC,CAAC,CAAA;YACH,CAAC,CAAC,CAAA;YAEF,MAAM,KAAK,GAAG,mBAAmB,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAA;YAEhD,0EAA0E;YAC1E,sEAAsE;YACtE,wEAAwE;YACxE,iCAAiC;YACjC,MAAM,QAAQ,GAAG,MAAM,cAAc,CAAC,WAAW,EAAE,CAAA;YACnD,MAAM,cAAc,GAAG,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAA;YACjD,MAAM,cAAc,CAAC,mBAAmB,CAAC,cAAc,CAAC,CAAA;YAExD,gDAAgD;YAChD,MAAM,SAAS,GAAG,GAAG,CAAC,aAAa,CAAC,EAAE,EAAE,KAAK,CAAC,CAAA;YAC9C,MAAM,cAAc,CAAC,oBAAoB,CAAC,SAAS,CAAC,CAAA;YAEpD,yEAAyE;YACzE,MAAM,oBAAoB,GAAG,MAAM,sBAAsB,CAAA;YAEzD,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAA;YAEvC,sBAAsB;YACtB,2GAA2G;YAC3G,uJAAuJ;YACvJ,MAAM,oBAAoB,GAAG,IAAI,CAAC,qBAAqB,CAAC,cAAc,EAAE,cAAc,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;YAEhG,uFAAuF;YACvF,6CAA6C;YAC7C,MAAM,mBAAmB,GAAG,KAAK,CAAC,EAAE,aAAa,EAAE,oBAAoB,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;YAE3F,MAAM,cAAc,GAAG,YAAY,CAAC;gBAClC,OAAO,EAAE,oBAAoB;gBAC7B,SAAS,EAAE,SAAS;gBACpB,MAAM,EAAE,IAAI,CAAC,UAAU,CAAC,MAAM;gBAC9B,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,IAAI,EAAE,CAAC;aACjC,CAAC,CAAA;YACF,MAAM,aAAa,GAAG;gBACpB,GAAG,cAAc;gBACjB,IAAI,EAAE,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC;gBAC9C,MAAM,EAAE,CAAC,KAAK,SAAU,CAAC;oBACvB,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,cAAc,CAAC,MAAM,EAAE,CAAC;wBAC/C,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;4BACvB,MAAM,GAAG,CAAA;wBACX,CAAC;oBACH,CAAC;gBACH,CAAC,EAAE,CAAC;aACL,CAAA;YAED,yDAAyD;YACzD,+DAA+D;YAC/D,MAAM,MAAM,GAAG,IAAI,yBAAyB,CAAC,IAAI,CAAC,UAAU,EAAE;gBAC5D,cAAc;gBACd,UAAU,EAAE,EAAE;gBACd,QAAQ,EAAE;oBACR,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE;iBACjB;gBACD,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,YAAY;aACpC,CAAC,CAAA;YAEF,MAAM,kBAAkB,GAAG,SAAS,CAAC,CAAC,CAAC,0BAA0B,CAAC,CAAC,CAAC,uBAAuB,CAAA;YAE3F,cAAc,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,GAAG,EAAE;gBACvD,QAAQ,cAAc,CAAC,eAAe,EAAE,CAAC;oBACvC,KAAK,QAAQ,CAAC;oBACd,KAAK,cAAc,CAAC;oBACpB,KAAK,QAAQ;wBACX,MAAM,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;4BAC3B,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,0BAA0B,EAAE,GAAG,CAAC,CAAA;wBACjD,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE;4BACd,0DAA0D;4BAC1D,UAAU,CAAC,KAAK,EAAE,CAAA;wBACpB,CAAC,CAAC,CAAA;wBACF,MAAK;oBACP;wBACE,MAAK;gBACT,CAAC;YACH,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,CAAA;YAEd,+BAA+B;YAC/B,IAAI,CAAC,OAAO,EAAE,YAAY,CAAC,SAAS,CAAC,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC,CAAA;YAE/D,MAAM,YAAY,GAAG,IAAI,uBAAuB,CAAC,IAAI,CAAC,UAAU,EAAE;gBAChE,cAAc;gBACd,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,YAAY;gBACnC,kBAAkB,EAAE,IAAI,CAAC,IAAI,CAAC,WAAW;aAC1C,CAAC,CAAA;YAEF,iFAAiF;YACjF,4EAA4E;YAC5E,MAAM,mBAAmB,CAAC,aAAa,CAAC,QAAQ,EAAE,aAAa,EAAE,WAAW,CAAC,CAAA;YAE7E,OAAO,MAAM,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC,MAAM,EAAE,EAAE,cAAc,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAA;QACrH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,cAAc,CAAC,KAAK,EAAE,CAAA;YACtB,MAAM,GAAG,CAAA;QACX,CAAC;IACH,CAAC;IAED;;;OAGG;IACK,qBAAqB,CAAE,EAAqB,EAAE,QAA8B,EAAE,EAAa;QACjG,IAAI,EAAE,CAAC,gBAAgB,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,CAAC,EAAE,CAAC;YACrD,MAAM,eAAe,CAAC,sBAAsB,CAAC,CAAA;QAC/C,CAAC;QAED,MAAM,gBAAgB,GAAG,GAAG,CAAC,mBAAmB,CAAC,EAAE,EAAE;YACnD,GAAG,EAAE,IAAI,CAAC,GAAG;SACd,CAAC,CAAA;QACF,IAAI,gBAAgB,IAAI,IAAI,EAAE,CAAC;YAC7B,MAAM,eAAe,CAAC,4BAA4B,CAAC,CAAA;QACrD,CAAC;QAED,MAAM,aAAa,GAAG,gBAAgB,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;QAC/E,MAAM,YAAY,GAAG,oBAAoB,CAAC,aAAa,EAAE,KAAK,CAAC,CAAA;QAC/D,MAAM,KAAK,GAAG,WAAW,CAAC,MAAM,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAA;QACxD,MAAM,MAAM,GAAe,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAA;QACjE,MAAM,MAAM,GAAG,oBAAoB,CAAC,sBAAsB,CAAC,CAAA;QAE3D,OAAO,MAAM,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAA;IACxC,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/webrtc",
|
|
3
|
-
"version": "4.0.20-
|
|
3
|
+
"version": "4.0.20-83ef3717e",
|
|
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.1.4-
|
|
55
|
-
"@libp2p/interface-internal": "1.0.9-
|
|
56
|
-
"@libp2p/peer-id": "4.0.7-
|
|
57
|
-
"@libp2p/utils": "5.2.6-
|
|
54
|
+
"@libp2p/interface": "1.1.4-83ef3717e",
|
|
55
|
+
"@libp2p/interface-internal": "1.0.9-83ef3717e",
|
|
56
|
+
"@libp2p/peer-id": "4.0.7-83ef3717e",
|
|
57
|
+
"@libp2p/utils": "5.2.6-83ef3717e",
|
|
58
58
|
"@multiformats/mafmt": "^12.1.6",
|
|
59
59
|
"@multiformats/multiaddr": "^12.1.14",
|
|
60
60
|
"@multiformats/multiaddr-matcher": "^1.1.2",
|
|
@@ -77,11 +77,11 @@
|
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
79
|
"@chainsafe/libp2p-yamux": "^6.0.2",
|
|
80
|
-
"@libp2p/circuit-relay-v2": "1.0.16-
|
|
81
|
-
"@libp2p/interface-compliance-tests": "5.3.2-
|
|
82
|
-
"@libp2p/logger": "4.0.7-
|
|
83
|
-
"@libp2p/peer-id-factory": "4.0.7-
|
|
84
|
-
"@libp2p/websockets": "8.0.16-
|
|
80
|
+
"@libp2p/circuit-relay-v2": "1.0.16-83ef3717e",
|
|
81
|
+
"@libp2p/interface-compliance-tests": "5.3.2-83ef3717e",
|
|
82
|
+
"@libp2p/logger": "4.0.7-83ef3717e",
|
|
83
|
+
"@libp2p/peer-id-factory": "4.0.7-83ef3717e",
|
|
84
|
+
"@libp2p/websockets": "8.0.16-83ef3717e",
|
|
85
85
|
"@types/sinon": "^17.0.3",
|
|
86
86
|
"aegir": "^42.2.4",
|
|
87
87
|
"delay": "^6.0.0",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"it-pair": "^2.0.6",
|
|
92
92
|
"it-pipe": "^3.0.1",
|
|
93
93
|
"it-to-buffer": "^4.0.5",
|
|
94
|
-
"libp2p": "1.2.4-
|
|
94
|
+
"libp2p": "1.2.4-83ef3717e",
|
|
95
95
|
"p-retry": "^6.2.0",
|
|
96
96
|
"protons": "^7.5.0",
|
|
97
97
|
"sinon": "^17.0.1",
|