@libp2p/webrtc 4.1.0-6573cb8b0 → 4.1.0-af85a7cad

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.min.js CHANGED
@@ -1,5 +1,5 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PWebrtc = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PWebrtc=(()=>{var U0=Object.create;var Do=Object.defineProperty;var O0=Object.getOwnPropertyDescriptor;var P0=Object.getOwnPropertyNames;var M0=Object.getPrototypeOf,F0=Object.prototype.hasOwnProperty;var re=(r,e)=>()=>(r&&(e=r(r=0)),e);var Ke=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),J=(r,e)=>{for(var t in e)Do(r,t,{get:e[t],enumerable:!0})},Jl=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of P0(e))!F0.call(r,o)&&o!==t&&Do(r,o,{get:()=>e[o],enumerable:!(n=O0(e,o))||n.enumerable});return r};var So=(r,e,t)=>(t=r!=null?U0(M0(r)):{},Jl(e||!r||!r.__esModule?Do(t,"default",{value:r,enumerable:!0}):t,r)),Bo=r=>Jl(Do({},"__esModule",{value:!0}),r);var hf=Ke((f3,ff)=>{"use strict";function uf(r,e){for(let t in e)Object.defineProperty(r,t,{value:e[t],enumerable:!0,configurable:!0});return r}function qg(r,e,t){if(!r||typeof r=="string")throw new TypeError("Please pass an Error to err-code");t||(t={}),typeof e=="object"&&(t=e,e=""),e&&(t.code=e);try{return uf(r,t)}catch{t.message=r.message,t.stack=r.stack;let o=function(){};return o.prototype=Object.create(Object.getPrototypeOf(r)),uf(new o,t)}}ff.exports=qg});var hh=Ke(dn=>{"use strict";var Ny="[object ArrayBuffer]",Pt=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===Ny}static toArrayBuffer(e){return this.isArrayBuffer(e)?e:e.byteLength===e.buffer.byteLength||e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:this.toUint8Array(e.buffer).slice(e.byteOffset,e.byteOffset+e.byteLength).buffer}static toUint8Array(e){return this.toView(e,Uint8Array)}static toView(e,t){if(e.constructor===t)return e;if(this.isArrayBuffer(e))return new t(e);if(this.isArrayBufferView(e))return new t(e.buffer,e.byteOffset,e.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(e){return this.isArrayBufferView(e)||this.isArrayBuffer(e)}static isArrayBufferView(e){return ArrayBuffer.isView(e)||e&&this.isArrayBuffer(e.buffer)}static isEqual(e,t){let n=r.toUint8Array(e),o=r.toUint8Array(t);if(n.length!==o.byteLength)return!1;for(let s=0;s<n.length;s++)if(n[s]!==o[s])return!1;return!0}static concat(...e){let t;Array.isArray(e[0])&&!(e[1]instanceof Function)||Array.isArray(e[0])&&e[1]instanceof Function?t=e[0]:e[e.length-1]instanceof Function?t=e.slice(0,e.length-1):t=e;let n=0;for(let i of t)n+=i.byteLength;let o=new Uint8Array(n),s=0;for(let i of t){let a=this.toUint8Array(i);o.set(a,s),s+=a.length}return e[e.length-1]instanceof Function?this.toView(o,e[e.length-1]):o.buffer}},Ic="string",Ly=/^[0-9a-f]+$/i,Uy=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,Oy=/^[a-zA-Z0-9-_]+$/,Ss=class{static fromString(e){let t=unescape(encodeURIComponent(e)),n=new Uint8Array(t.length);for(let o=0;o<t.length;o++)n[o]=t.charCodeAt(o);return n.buffer}static toString(e){let t=Pt.toUint8Array(e),n="";for(let s=0;s<t.length;s++)n+=String.fromCharCode(t[s]);return decodeURIComponent(escape(n))}},Qe=class{static toString(e,t=!1){let n=Pt.toArrayBuffer(e),o=new DataView(n),s="";for(let i=0;i<n.byteLength;i+=2){let a=o.getUint16(i,t);s+=String.fromCharCode(a)}return s}static fromString(e,t=!1){let n=new ArrayBuffer(e.length*2),o=new DataView(n);for(let s=0;s<e.length;s++)o.setUint16(s*2,e.charCodeAt(s),t);return n}},Bs=class r{static isHex(e){return typeof e===Ic&&Ly.test(e)}static isBase64(e){return typeof e===Ic&&Uy.test(e)}static isBase64Url(e){return typeof e===Ic&&Oy.test(e)}static ToString(e,t="utf8"){let n=Pt.toUint8Array(e);switch(t.toLowerCase()){case"utf8":return this.ToUtf8String(n);case"binary":return this.ToBinary(n);case"hex":return this.ToHex(n);case"base64":return this.ToBase64(n);case"base64url":return this.ToBase64Url(n);case"utf16le":return Qe.toString(n,!0);case"utf16":case"utf16be":return Qe.toString(n);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromString(e,t="utf8"){if(!e)return new ArrayBuffer(0);switch(t.toLowerCase()){case"utf8":return this.FromUtf8String(e);case"binary":return this.FromBinary(e);case"hex":return this.FromHex(e);case"base64":return this.FromBase64(e);case"base64url":return this.FromBase64Url(e);case"utf16le":return Qe.fromString(e,!0);case"utf16":case"utf16be":return Qe.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=Pt.toUint8Array(e);if(typeof btoa<"u"){let n=this.ToString(t,"binary");return btoa(n)}else return Buffer.from(t).toString("base64")}static FromBase64(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64(t))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return typeof atob<"u"?this.FromBinary(atob(t)):new Uint8Array(Buffer.from(t,"base64")).buffer}static FromBase64Url(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64Url(t))throw new TypeError("Argument 'base64url' is not Base64Url encoded");return this.FromBase64(this.Base64Padding(t.replace(/\-/g,"+").replace(/\_/g,"/")))}static ToBase64Url(e){return this.ToBase64(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}static FromUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.FromBinary(e);case"utf8":return Ss.fromString(e);case"utf16":case"utf16be":return Qe.fromString(e);case"utf16le":case"usc2":return Qe.fromString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.ToBinary(e);case"utf8":return Ss.toString(e);case"utf16":case"utf16be":return Qe.toString(e);case"utf16le":case"usc2":return Qe.toString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromBinary(e){let t=e.length,n=new Uint8Array(t);for(let o=0;o<t;o++)n[o]=e.charCodeAt(o);return n.buffer}static ToBinary(e){let t=Pt.toUint8Array(e),n="";for(let o=0;o<t.length;o++)n+=String.fromCharCode(t[o]);return n}static ToHex(e){let t=Pt.toUint8Array(e),n="",o=t.length;for(let s=0;s<o;s++){let i=t[s];i<16&&(n+="0"),n+=i.toString(16)}return n}static FromHex(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isHex(t))throw new TypeError("Argument 'hexString' is not HEX encoded");t.length%2&&(t=`0${t}`);let n=new Uint8Array(t.length/2);for(let o=0;o<t.length;o=o+2){let s=t.slice(o,o+2);n[o/2]=parseInt(s,16)}return n.buffer}static ToUtf16String(e,t=!1){return Qe.toString(e,t)}static FromUtf16String(e,t=!1){return Qe.fromString(e,t)}static Base64Padding(e){let t=4-e.length%4;if(t<4)for(let n=0;n<t;n++)e+="=";return e}static formatString(e){return e?.replace(/[\n\r\t ]/g,"")||""}};Bs.DEFAULT_UTF8_ENCODING="utf8";function Py(r,...e){let t=arguments[0];for(let n=1;n<arguments.length;n++){let o=arguments[n];for(let s in o)t[s]=o[s]}return t}function My(...r){let e=r.map(o=>o.byteLength).reduce((o,s)=>o+s),t=new Uint8Array(e),n=0;return r.map(o=>new Uint8Array(o)).forEach(o=>{for(let s of o)t[n++]=s}),t.buffer}function Fy(r,e){if(!(r&&e)||r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let o=0;o<r.byteLength;o++)if(t[o]!==n[o])return!1;return!0}dn.BufferSourceConverter=Pt;dn.Convert=Bs;dn.assign=Py;dn.combine=My;dn.isEqual=Fy});var Jd=Ke((yk,Xd)=>{"use strict";function Fw(r){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),t=0;t<e.length;t++)e[t]=255;for(var n=0;n<r.length;n++){var o=r.charAt(n),s=o.charCodeAt(0);if(e[s]!==255)throw new TypeError(o+" is ambiguous");e[s]=n}var i=r.length,a=r.charAt(0),c=Math.log(i)/Math.log(256),l=Math.log(256)/Math.log(i);function u(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var p=0,h=0,d=0,y=g.length;d!==y&&g[d]===0;)d++,p++;for(var x=(y-d)*l+1>>>0,b=new Uint8Array(x);d!==y;){for(var A=g[d],E=0,v=x-1;(A!==0||E<h)&&v!==-1;v--,E++)A+=256*b[v]>>>0,b[v]=A%i>>>0,A=A/i>>>0;if(A!==0)throw new Error("Non-zero carry");h=E,d++}for(var S=x-h;S!==x&&b[S]===0;)S++;for(var D=a.repeat(p);S<x;++S)D+=r.charAt(b[S]);return D}function f(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var p=0;if(g[p]!==" "){for(var h=0,d=0;g[p]===a;)h++,p++;for(var y=(g.length-p)*c+1>>>0,x=new Uint8Array(y);g[p];){var b=e[g.charCodeAt(p)];if(b===255)return;for(var A=0,E=y-1;(b!==0||A<d)&&E!==-1;E--,A++)b+=i*x[E]>>>0,x[E]=b%256>>>0,b=b/256>>>0;if(b!==0)throw new Error("Non-zero carry");d=A,p++}if(g[p]!==" "){for(var v=y-d;v!==y&&x[v]===0;)v++;for(var S=new Uint8Array(h+(y-v)),D=h;v!==y;)S[D++]=x[v++];return S}}}function m(g){var p=f(g);if(p)return p;throw new Error("Non-base"+i+" character")}return{encode:u,decodeUnsafe:f,decode:m}}Xd.exports=Fw});var Ei=Ke((wk,Qd)=>{"use strict";var Vw=new TextDecoder,Hw=r=>Vw.decode(r),Kw=new TextEncoder,$w=r=>Kw.encode(r);function qw(r,e){let t=new Uint8Array(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}Qd.exports={decodeText:Hw,encodeText:$w,concat:qw}});var tp=Ke((xk,ep)=>{"use strict";var{encodeText:Ww}=Ei(),fl=class{constructor(e,t,n,o){this.name=e,this.code=t,this.codeBuf=Ww(this.code),this.alphabet=o,this.codec=n(o)}encode(e){return this.codec.encode(e)}decode(e){for(let t of e)if(this.alphabet&&this.alphabet.indexOf(t)<0)throw new Error(`invalid character '${t}' in '${e}'`);return this.codec.decode(e)}};ep.exports=fl});var np=Ke((Ek,rp)=>{"use strict";var zw=(r,e,t)=>{let n={};for(let l=0;l<e.length;++l)n[e[l]]=l;let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*t/8|0),i=0,a=0,c=0;for(let l=0;l<o;++l){let u=n[r[l]];if(u===void 0)throw new SyntaxError("Invalid character "+r[l]);a=a<<t|u,i+=t,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=t||255&a<<8-i)throw new SyntaxError("Unexpected end of data");return s},Gw=(r,e,t)=>{let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>t;)i-=t,s+=e[o&a>>i];if(i&&(s+=e[o&a<<t-i]),n)for(;s.length*t&7;)s+="=";return s},jw=r=>e=>({encode(t){return Gw(t,e,r)},decode(t){return zw(t,e,r)}});rp.exports={rfc4648:jw}});var ap=Ke((vk,ip)=>{"use strict";var bo=Jd(),Yw=tp(),{rfc4648:Ue}=np(),{decodeText:Zw,encodeText:Xw}=Ei(),Jw=()=>({encode:Zw,decode:Xw}),op=[["identity","\0",Jw,""],["base2","0",Ue(1),"01"],["base8","7",Ue(3),"01234567"],["base10","9",bo,"0123456789"],["base16","f",Ue(4),"0123456789abcdef"],["base16upper","F",Ue(4),"0123456789ABCDEF"],["base32hex","v",Ue(5),"0123456789abcdefghijklmnopqrstuv"],["base32hexupper","V",Ue(5),"0123456789ABCDEFGHIJKLMNOPQRSTUV"],["base32hexpad","t",Ue(5),"0123456789abcdefghijklmnopqrstuv="],["base32hexpadupper","T",Ue(5),"0123456789ABCDEFGHIJKLMNOPQRSTUV="],["base32","b",Ue(5),"abcdefghijklmnopqrstuvwxyz234567"],["base32upper","B",Ue(5),"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"],["base32pad","c",Ue(5),"abcdefghijklmnopqrstuvwxyz234567="],["base32padupper","C",Ue(5),"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567="],["base32z","h",Ue(5),"ybndrfg8ejkmcpqxot1uwisza345h769"],["base36","k",bo,"0123456789abcdefghijklmnopqrstuvwxyz"],["base36upper","K",bo,"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"],["base58btc","z",bo,"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"],["base58flickr","Z",bo,"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"],["base64","m",Ue(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"],["base64pad","M",Ue(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="],["base64url","u",Ue(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"],["base64urlpad","U",Ue(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_="]],sp=op.reduce((r,e)=>(r[e[0]]=new Yw(e[0],e[1],e[2],e[3]),r),{}),Qw=op.reduce((r,e)=>(r[e[1]]=sp[e[0]],r),{});ip.exports={names:sp,codes:Qw}});var up=Ke((Wt,lp)=>{"use strict";var An=ap(),{encodeText:ex,decodeText:vi,concat:cp}=Ei();function tx(r,e){if(!e)throw new Error("requires an encoded Uint8Array");let{name:t,codeBuf:n}=Mr(r);return sx(t,e),cp([n,e],n.length+e.length)}function rx(r,e){let t=Mr(r),n=ex(t.encode(e));return cp([t.codeBuf,n],t.codeBuf.length+n.length)}function nx(r){r instanceof Uint8Array&&(r=vi(r));let e=r[0];return["f","F","v","V","t","T","b","B","c","C","h","k","K"].includes(e)&&(r=r.toLowerCase()),Mr(r[0]).decode(r.substring(1))}function ox(r){if(r instanceof Uint8Array&&(r=vi(r)),Object.prototype.toString.call(r)!=="[object String]")return!1;try{return Mr(r[0]).name}catch{return!1}}function sx(r,e){Mr(r).decode(vi(e))}function Mr(r){if(Object.prototype.hasOwnProperty.call(An.names,r))return An.names[r];if(Object.prototype.hasOwnProperty.call(An.codes,r))return An.codes[r];throw new Error(`Unsupported encoding: ${r}`)}function ix(r){return r instanceof Uint8Array&&(r=vi(r)),Mr(r[0])}Wt=lp.exports=tx;Wt.encode=rx;Wt.decode=nx;Wt.isEncoded=ox;Wt.encoding=Mr;Wt.encodingFromData=ix;var ax=Object.freeze(An.names),cx=Object.freeze(An.codes);Wt.names=ax;Wt.codes=cx});var pp=Ke((Ak,dp)=>{dp.exports=hp;var fp=128,lx=127,ux=~lx,fx=Math.pow(2,31);function hp(r,e,t){e=e||[],t=t||0;for(var n=t;r>=fx;)e[t++]=r&255|fp,r/=128;for(;r&ux;)e[t++]=r&255|fp,r>>>=7;return e[t]=r|0,hp.bytes=t-n+1,e}});var bp=Ke((Dk,gp)=>{gp.exports=hl;var hx=128,mp=127;function hl(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw hl.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&mp)<<o:(i&mp)*Math.pow(2,o),o+=7}while(i>=hx);return hl.bytes=s-n,t}});var wp=Ke((Sk,yp)=>{var dx=Math.pow(2,7),px=Math.pow(2,14),mx=Math.pow(2,21),gx=Math.pow(2,28),bx=Math.pow(2,35),yx=Math.pow(2,42),wx=Math.pow(2,49),xx=Math.pow(2,56),Ex=Math.pow(2,63);yp.exports=function(r){return r<dx?1:r<px?2:r<mx?3:r<gx?4:r<bx?5:r<yx?6:r<wx?7:r<xx?8:r<Ex?9:10}});var Ep=Ke((Bk,xp)=>{xp.exports={encode:pp(),decode:bp(),encodingLength:wp()}});var Ap=Ke((kk,vp)=>{"use strict";var vx=Object.freeze({identity:0,sha1:17,"sha2-256":18,"sha2-512":19,"sha3-512":20,"sha3-384":21,"sha3-256":22,"sha3-224":23,"shake-128":24,"shake-256":25,"keccak-224":26,"keccak-256":27,"keccak-384":28,"keccak-512":29,blake3:30,"murmur3-128":34,"murmur3-32":35,"dbl-sha2-256":86,md4:212,md5:213,bmt:214,"sha2-256-trunc254-padded":4114,"ripemd-128":4178,"ripemd-160":4179,"ripemd-256":4180,"ripemd-320":4181,x11:4352,kangarootwelve:7425,"sm3-256":21325,"blake2b-8":45569,"blake2b-16":45570,"blake2b-24":45571,"blake2b-32":45572,"blake2b-40":45573,"blake2b-48":45574,"blake2b-56":45575,"blake2b-64":45576,"blake2b-72":45577,"blake2b-80":45578,"blake2b-88":45579,"blake2b-96":45580,"blake2b-104":45581,"blake2b-112":45582,"blake2b-120":45583,"blake2b-128":45584,"blake2b-136":45585,"blake2b-144":45586,"blake2b-152":45587,"blake2b-160":45588,"blake2b-168":45589,"blake2b-176":45590,"blake2b-184":45591,"blake2b-192":45592,"blake2b-200":45593,"blake2b-208":45594,"blake2b-216":45595,"blake2b-224":45596,"blake2b-232":45597,"blake2b-240":45598,"blake2b-248":45599,"blake2b-256":45600,"blake2b-264":45601,"blake2b-272":45602,"blake2b-280":45603,"blake2b-288":45604,"blake2b-296":45605,"blake2b-304":45606,"blake2b-312":45607,"blake2b-320":45608,"blake2b-328":45609,"blake2b-336":45610,"blake2b-344":45611,"blake2b-352":45612,"blake2b-360":45613,"blake2b-368":45614,"blake2b-376":45615,"blake2b-384":45616,"blake2b-392":45617,"blake2b-400":45618,"blake2b-408":45619,"blake2b-416":45620,"blake2b-424":45621,"blake2b-432":45622,"blake2b-440":45623,"blake2b-448":45624,"blake2b-456":45625,"blake2b-464":45626,"blake2b-472":45627,"blake2b-480":45628,"blake2b-488":45629,"blake2b-496":45630,"blake2b-504":45631,"blake2b-512":45632,"blake2s-8":45633,"blake2s-16":45634,"blake2s-24":45635,"blake2s-32":45636,"blake2s-40":45637,"blake2s-48":45638,"blake2s-56":45639,"blake2s-64":45640,"blake2s-72":45641,"blake2s-80":45642,"blake2s-88":45643,"blake2s-96":45644,"blake2s-104":45645,"blake2s-112":45646,"blake2s-120":45647,"blake2s-128":45648,"blake2s-136":45649,"blake2s-144":45650,"blake2s-152":45651,"blake2s-160":45652,"blake2s-168":45653,"blake2s-176":45654,"blake2s-184":45655,"blake2s-192":45656,"blake2s-200":45657,"blake2s-208":45658,"blake2s-216":45659,"blake2s-224":45660,"blake2s-232":45661,"blake2s-240":45662,"blake2s-248":45663,"blake2s-256":45664,"skein256-8":45825,"skein256-16":45826,"skein256-24":45827,"skein256-32":45828,"skein256-40":45829,"skein256-48":45830,"skein256-56":45831,"skein256-64":45832,"skein256-72":45833,"skein256-80":45834,"skein256-88":45835,"skein256-96":45836,"skein256-104":45837,"skein256-112":45838,"skein256-120":45839,"skein256-128":45840,"skein256-136":45841,"skein256-144":45842,"skein256-152":45843,"skein256-160":45844,"skein256-168":45845,"skein256-176":45846,"skein256-184":45847,"skein256-192":45848,"skein256-200":45849,"skein256-208":45850,"skein256-216":45851,"skein256-224":45852,"skein256-232":45853,"skein256-240":45854,"skein256-248":45855,"skein256-256":45856,"skein512-8":45857,"skein512-16":45858,"skein512-24":45859,"skein512-32":45860,"skein512-40":45861,"skein512-48":45862,"skein512-56":45863,"skein512-64":45864,"skein512-72":45865,"skein512-80":45866,"skein512-88":45867,"skein512-96":45868,"skein512-104":45869,"skein512-112":45870,"skein512-120":45871,"skein512-128":45872,"skein512-136":45873,"skein512-144":45874,"skein512-152":45875,"skein512-160":45876,"skein512-168":45877,"skein512-176":45878,"skein512-184":45879,"skein512-192":45880,"skein512-200":45881,"skein512-208":45882,"skein512-216":45883,"skein512-224":45884,"skein512-232":45885,"skein512-240":45886,"skein512-248":45887,"skein512-256":45888,"skein512-264":45889,"skein512-272":45890,"skein512-280":45891,"skein512-288":45892,"skein512-296":45893,"skein512-304":45894,"skein512-312":45895,"skein512-320":45896,"skein512-328":45897,"skein512-336":45898,"skein512-344":45899,"skein512-352":45900,"skein512-360":45901,"skein512-368":45902,"skein512-376":45903,"skein512-384":45904,"skein512-392":45905,"skein512-400":45906,"skein512-408":45907,"skein512-416":45908,"skein512-424":45909,"skein512-432":45910,"skein512-440":45911,"skein512-448":45912,"skein512-456":45913,"skein512-464":45914,"skein512-472":45915,"skein512-480":45916,"skein512-488":45917,"skein512-496":45918,"skein512-504":45919,"skein512-512":45920,"skein1024-8":45921,"skein1024-16":45922,"skein1024-24":45923,"skein1024-32":45924,"skein1024-40":45925,"skein1024-48":45926,"skein1024-56":45927,"skein1024-64":45928,"skein1024-72":45929,"skein1024-80":45930,"skein1024-88":45931,"skein1024-96":45932,"skein1024-104":45933,"skein1024-112":45934,"skein1024-120":45935,"skein1024-128":45936,"skein1024-136":45937,"skein1024-144":45938,"skein1024-152":45939,"skein1024-160":45940,"skein1024-168":45941,"skein1024-176":45942,"skein1024-184":45943,"skein1024-192":45944,"skein1024-200":45945,"skein1024-208":45946,"skein1024-216":45947,"skein1024-224":45948,"skein1024-232":45949,"skein1024-240":45950,"skein1024-248":45951,"skein1024-256":45952,"skein1024-264":45953,"skein1024-272":45954,"skein1024-280":45955,"skein1024-288":45956,"skein1024-296":45957,"skein1024-304":45958,"skein1024-312":45959,"skein1024-320":45960,"skein1024-328":45961,"skein1024-336":45962,"skein1024-344":45963,"skein1024-352":45964,"skein1024-360":45965,"skein1024-368":45966,"skein1024-376":45967,"skein1024-384":45968,"skein1024-392":45969,"skein1024-400":45970,"skein1024-408":45971,"skein1024-416":45972,"skein1024-424":45973,"skein1024-432":45974,"skein1024-440":45975,"skein1024-448":45976,"skein1024-456":45977,"skein1024-464":45978,"skein1024-472":45979,"skein1024-480":45980,"skein1024-488":45981,"skein1024-496":45982,"skein1024-504":45983,"skein1024-512":45984,"skein1024-520":45985,"skein1024-528":45986,"skein1024-536":45987,"skein1024-544":45988,"skein1024-552":45989,"skein1024-560":45990,"skein1024-568":45991,"skein1024-576":45992,"skein1024-584":45993,"skein1024-592":45994,"skein1024-600":45995,"skein1024-608":45996,"skein1024-616":45997,"skein1024-624":45998,"skein1024-632":45999,"skein1024-640":46e3,"skein1024-648":46001,"skein1024-656":46002,"skein1024-664":46003,"skein1024-672":46004,"skein1024-680":46005,"skein1024-688":46006,"skein1024-696":46007,"skein1024-704":46008,"skein1024-712":46009,"skein1024-720":46010,"skein1024-728":46011,"skein1024-736":46012,"skein1024-744":46013,"skein1024-752":46014,"skein1024-760":46015,"skein1024-768":46016,"skein1024-776":46017,"skein1024-784":46018,"skein1024-792":46019,"skein1024-800":46020,"skein1024-808":46021,"skein1024-816":46022,"skein1024-824":46023,"skein1024-832":46024,"skein1024-840":46025,"skein1024-848":46026,"skein1024-856":46027,"skein1024-864":46028,"skein1024-872":46029,"skein1024-880":46030,"skein1024-888":46031,"skein1024-896":46032,"skein1024-904":46033,"skein1024-912":46034,"skein1024-920":46035,"skein1024-928":46036,"skein1024-936":46037,"skein1024-944":46038,"skein1024-952":46039,"skein1024-960":46040,"skein1024-968":46041,"skein1024-976":46042,"skein1024-984":46043,"skein1024-992":46044,"skein1024-1000":46045,"skein1024-1008":46046,"skein1024-1016":46047,"skein1024-1024":46048,"poseidon-bls12_381-a2-fc1":46081,"poseidon-bls12_381-a2-fc1-sc":46082});vp.exports={names:vx}});function Ax(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(t[i]!==255)throw new TypeError(s+" is ambiguous");t[i]=o}var a=r.length,c=r.charAt(0),l=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function f(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var h=0,d=0,y=0,x=p.length;y!==x&&p[y]===0;)y++,h++;for(var b=(x-y)*u+1>>>0,A=new Uint8Array(b);y!==x;){for(var E=p[y],v=0,S=b-1;(E!==0||v<d)&&S!==-1;S--,v++)E+=256*A[S]>>>0,A[S]=E%a>>>0,E=E/a>>>0;if(E!==0)throw new Error("Non-zero carry");d=v,y++}for(var D=b-d;D!==b&&A[D]===0;)D++;for(var _=c.repeat(h);D<b;++D)_+=r.charAt(A[D]);return _}function m(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var h=0;if(p[h]!==" "){for(var d=0,y=0;p[h]===c;)d++,h++;for(var x=(p.length-h)*l+1>>>0,b=new Uint8Array(x);p[h];){var A=t[p.charCodeAt(h)];if(A===255)return;for(var E=0,v=x-1;(A!==0||E<y)&&v!==-1;v--,E++)A+=a*b[v]>>>0,b[v]=A%256>>>0,A=A/256>>>0;if(A!==0)throw new Error("Non-zero carry");y=E,h++}if(p[h]!==" "){for(var S=x-y;S!==x&&b[S]===0;)S++;for(var D=new Uint8Array(d+(x-S)),_=d;S!==x;)D[_++]=b[S++];return D}}}function g(p){var h=m(p);if(h)return h;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:m,decode:g}}var Dx,Sx,Dp,Sp=re(()=>{Dx=Ax,Sx=Dx,Dp=Sx});var Ik,Bp,zt,kp,Cp,hr=re(()=>{Ik=new Uint8Array(0),Bp=(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},zt=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")},kp=r=>new TextEncoder().encode(r),Cp=r=>new TextDecoder().decode(r)});var dl,pl,ml,Tp,gl,Dn,dr,Bx,kx,me,mt=re(()=>{Sp();hr();dl=class{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")}},pl=class{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 Tp(this,e)}},ml=class{constructor(e){this.decoders=e}or(e){return Tp(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},Tp=(r,e)=>new ml({...r.decoders||{[r.prefix]:r},...e.decoders||{[e.prefix]:e}}),gl=class{constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new dl(e,t,n),this.decoder=new pl(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}},Dn=({name:r,prefix:e,encode:t,decode:n})=>new gl(r,e,t,n),dr=({prefix:r,name:e,alphabet:t})=>{let{encode:n,decode:o}=Dp(t,e);return Dn({prefix:r,name:e,encode:n,decode:s=>zt(o(s))})},Bx=(r,e,t,n)=>{let o={};for(let u=0;u<e.length;++u)o[e[u]]=u;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*t/8|0),a=0,c=0,l=0;for(let u=0;u<s;++u){let f=o[r[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<t|f,a+=t,a>=8&&(a-=8,i[l++]=255&c>>a)}if(a>=t||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return i},kx=(r,e,t)=>{let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>t;)i-=t,s+=e[o&a>>i];if(i&&(s+=e[o&a<<t-i]),n)for(;s.length*t&7;)s+="=";return s},me=({name:r,prefix:e,bitsPerChar:t,alphabet:n})=>Dn({prefix:e,name:r,encode(o){return kx(o,n,t)},decode(o){return Bx(o,n,t,r)}})});var bl={};J(bl,{identity:()=>Cx});var Cx,_p=re(()=>{mt();hr();Cx=Dn({prefix:"\0",name:"identity",encode:r=>Cp(r),decode:r=>kp(r)})});var yl={};J(yl,{base2:()=>Ix});var Ix,Rp=re(()=>{mt();Ix=me({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1})});var wl={};J(wl,{base8:()=>Tx});var Tx,Np=re(()=>{mt();Tx=me({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3})});var xl={};J(xl,{base10:()=>_x});var _x,Lp=re(()=>{mt();_x=dr({prefix:"9",name:"base10",alphabet:"0123456789"})});var El={};J(El,{base16:()=>Rx,base16upper:()=>Nx});var Rx,Nx,Up=re(()=>{mt();Rx=me({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Nx=me({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4})});var vl={};J(vl,{base32:()=>Sn,base32hex:()=>Px,base32hexpad:()=>Fx,base32hexpadupper:()=>Vx,base32hexupper:()=>Mx,base32pad:()=>Ux,base32padupper:()=>Ox,base32upper:()=>Lx,base32z:()=>Hx});var Sn,Lx,Ux,Ox,Px,Mx,Fx,Vx,Hx,Al=re(()=>{mt();Sn=me({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Lx=me({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ux=me({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ox=me({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Px=me({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Mx=me({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Fx=me({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Vx=me({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Hx=me({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5})});var Dl={};J(Dl,{base36:()=>Kx,base36upper:()=>$x});var Kx,$x,Op=re(()=>{mt();Kx=dr({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),$x=dr({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"})});var Sl={};J(Sl,{base58btc:()=>St,base58flickr:()=>qx});var St,qx,Bl=re(()=>{mt();St=dr({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),qx=dr({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"})});var kl={};J(kl,{base64:()=>Wx,base64pad:()=>zx,base64url:()=>Gx,base64urlpad:()=>jx});var Wx,zx,Gx,jx,Pp=re(()=>{mt();Wx=me({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),zx=me({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Gx=me({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),jx=me({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6})});var Cl={};J(Cl,{base256emoji:()=>Qx});function Xx(r){return r.reduce((e,t)=>(e+=Yx[t],e),"")}function Jx(r){let e=[];for(let t of r){let n=Zx[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var Mp,Yx,Zx,Qx,Fp=re(()=>{mt();Mp=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}"),Yx=Mp.reduce((r,e,t)=>(r[t]=e,r),[]),Zx=Mp.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);Qx=Dn({prefix:"\u{1F680}",name:"base256emoji",encode:Xx,decode:Jx})});function Kp(r,e,t){e=e||[],t=t||0;for(var n=t;r>=n2;)e[t++]=r&255|Vp,r/=128;for(;r&r2;)e[t++]=r&255|Vp,r>>>=7;return e[t]=r|0,Kp.bytes=t-n+1,e}function Il(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Il.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&Hp)<<o:(i&Hp)*Math.pow(2,o),o+=7}while(i>=s2);return Il.bytes=s-n,t}var e2,Vp,t2,r2,n2,o2,s2,Hp,i2,a2,c2,l2,u2,f2,h2,d2,p2,m2,g2,b2,yo,$p=re(()=>{e2=Kp,Vp=128,t2=127,r2=~t2,n2=Math.pow(2,31);o2=Il,s2=128,Hp=127;i2=Math.pow(2,7),a2=Math.pow(2,14),c2=Math.pow(2,21),l2=Math.pow(2,28),u2=Math.pow(2,35),f2=Math.pow(2,42),h2=Math.pow(2,49),d2=Math.pow(2,56),p2=Math.pow(2,63),m2=function(r){return r<i2?1:r<a2?2:r<c2?3:r<l2?4:r<u2?5:r<f2?6:r<h2?7:r<d2?8:r<p2?9:10},g2={encode:e2,decode:o2,encodingLength:m2},b2=g2,yo=b2});var wo,Bn,kn,Di=re(()=>{$p();wo=(r,e=0)=>[yo.decode(r,e),yo.decode.bytes],Bn=(r,e,t=0)=>(yo.encode(r,e,t),e),kn=r=>yo.encodingLength(r)});var Fr,qp,Wp,Cn,Eo=re(()=>{hr();Di();Fr=(r,e)=>{let t=e.byteLength,n=kn(r),o=n+kn(t),s=new Uint8Array(o+t);return Bn(r,s,0),Bn(t,s,n),s.set(e,o),new Cn(r,t,e,s)},qp=r=>{let e=zt(r),[t,n]=wo(e),[o,s]=wo(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Cn(t,o,i,e)},Wp=(r,e)=>r===e?!0:r.code===e.code&&r.size===e.size&&Bp(r.bytes,e.bytes),Cn=class{constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}}});var _l,Tl,Rl=re(()=>{Eo();_l=({name:r,code:e,encode:t})=>new Tl(r,e,t),Tl=class{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?Fr(this.code,t):t.then(n=>Fr(this.code,n))}else throw Error("Unknown type, must be binary type")}}});var Nl={};J(Nl,{sha256:()=>y2,sha512:()=>w2});var Gp,y2,w2,jp=re(()=>{Rl();Gp=r=>async e=>new Uint8Array(await crypto.subtle.digest(r,e)),y2=_l({name:"sha2-256",code:18,encode:Gp("SHA-256")}),w2=_l({name:"sha2-512",code:19,encode:Gp("SHA-512")})});var Ll={};J(Ll,{identity:()=>v2});var Yp,x2,Zp,E2,v2,Xp=re(()=>{hr();Eo();Yp=0,x2="identity",Zp=zt,E2=r=>Fr(Yp,Zp(r)),v2={code:Yp,name:x2,encode:Zp,digest:E2}});var Jp=re(()=>{hr()});var Zk,Xk,Qp=re(()=>{Zk=new TextEncoder,Xk=new TextDecoder});var ki,S2,B2,k2,vo,C2,e0,t0,Si,Bi,I2,T2,_2,r0=re(()=>{Di();Eo();Bl();Al();hr();ki=class r{constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this.byteOffset=o.byteOffset,this.byteLength=o.byteLength,this.asCID=this,this._baseCache=new Map,Object.defineProperties(this,{byteOffset:Bi,byteLength:Bi,code:Si,version:Si,multihash:Si,bytes:Si,_baseCache:Bi,asCID:Bi})}toV0(){switch(this.version){case 0:return this;default:{let{code:e,multihash:t}=this;if(e!==vo)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==C2)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=Fr(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}equals(e){return e&&this.code===e.code&&this.version===e.version&&Wp(this.multihash,e.multihash)}toString(e){let{bytes:t,version:n,_baseCache:o}=this;switch(n){case 0:return B2(t,o,e||St.encoder);default:return k2(t,o,e||Sn.encoder)}}toJSON(){return{code:this.code,version:this.version,hash:this.multihash.bytes}}get[Symbol.toStringTag](){return"CID"}[Symbol.for("nodejs.util.inspect.custom")](){return"CID("+this.toString()+")"}static isCID(e){return T2(/^0\.0/,_2),!!(e&&(e[t0]||e.asCID===e))}get toBaseEncodedString(){throw new Error("Deprecated, use .toString()")}get codec(){throw new Error('"codec" property is deprecated, use integer "code" property instead')}get buffer(){throw new Error("Deprecated .buffer property, use .bytes to get Uint8Array instead")}get multibaseName(){throw new Error('"multibaseName" property is deprecated')}get prefix(){throw new Error('"prefix" property is deprecated')}static asCID(e){if(e instanceof r)return e;if(e!=null&&e.asCID===e){let{version:t,code:n,multihash:o,bytes:s}=e;return new r(t,n,o,s||e0(t,n,o.bytes))}else if(e!=null&&e[t0]===!0){let{version:t,multihash:n,code:o}=e,s=qp(n);return r.create(t,o,s)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");switch(e){case 0:{if(t!==vo)throw new Error(`Version 0 CID must use dag-pb (code: ${vo}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=e0(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,vo,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=zt(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let s=o.subarray(t.multihashSize-t.digestSize),i=new Cn(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[f,m]=wo(e.subarray(t));return t+=m,f},o=n(),s=vo;if(o===18?(o=0,t=0):o===1&&(s=n()),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=t,a=n(),c=n(),l=t+c,u=l-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:u,size:l}}static parse(e,t){let[n,o]=S2(e,t),s=r.decode(o);return s._baseCache.set(n,e),s}},S2=(r,e)=>{switch(r[0]){case"Q":{let t=e||St;return[St.prefix,t.decode(`${St.prefix}${r}`)]}case St.prefix:{let t=e||St;return[St.prefix,t.decode(r)]}case Sn.prefix:{let t=e||Sn;return[Sn.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)]}}},B2=(r,e,t)=>{let{prefix:n}=t;if(n!==St.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let s=t.encode(r).slice(1);return e.set(n,s),s}else return o},k2=(r,e,t)=>{let{prefix:n}=t,o=e.get(n);if(o==null){let s=t.encode(r);return e.set(n,s),s}else return o},vo=112,C2=18,e0=(r,e,t)=>{let n=kn(r),o=n+kn(e),s=new Uint8Array(o+t.byteLength);return Bn(r,s,0),Bn(e,s,n),s.set(t,o),s},t0=Symbol.for("@ipld/js-cid/CID"),Si={writable:!1,configurable:!1,enumerable:!0},Bi={writable:!1,enumerable:!1,configurable:!1},I2="0.0.0-dev",T2=(r,e)=>{if(r.test(I2))console.warn(e);else throw new Error(e)},_2=`CID.isCID(v) is deprecated and will be removed in the next major release.
2
+ "use strict";var Libp2PWebrtc=(()=>{var V0=Object.create;var So=Object.defineProperty;var H0=Object.getOwnPropertyDescriptor;var K0=Object.getOwnPropertyNames;var $0=Object.getPrototypeOf,q0=Object.prototype.hasOwnProperty;var re=(r,e)=>()=>(r&&(e=r(r=0)),e);var Ke=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),Q=(r,e)=>{for(var t in e)So(r,t,{get:e[t],enumerable:!0})},rl=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of K0(e))!q0.call(r,o)&&o!==t&&So(r,o,{get:()=>e[o],enumerable:!(n=H0(e,o))||n.enumerable});return r};var Bo=(r,e,t)=>(t=r!=null?V0($0(r)):{},rl(e||!r||!r.__esModule?So(t,"default",{value:r,enumerable:!0}):t,r)),ko=r=>rl(So({},"__esModule",{value:!0}),r);var bf=Ke((w3,gf)=>{"use strict";function mf(r,e){for(let t in e)Object.defineProperty(r,t,{value:e[t],enumerable:!0,configurable:!0});return r}function jg(r,e,t){if(!r||typeof r=="string")throw new TypeError("Please pass an Error to err-code");t||(t={}),typeof e=="object"&&(t=e,e=""),e&&(t.code=e);try{return mf(r,t)}catch{t.message=r.message,t.stack=r.stack;let o=function(){};return o.prototype=Object.create(Object.getPrototypeOf(r)),mf(new o,t)}}gf.exports=jg});var bh=Ke(dn=>{"use strict";var Py="[object ArrayBuffer]",Mt=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===Py}static toArrayBuffer(e){return this.isArrayBuffer(e)?e:e.byteLength===e.buffer.byteLength||e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:this.toUint8Array(e.buffer).slice(e.byteOffset,e.byteOffset+e.byteLength).buffer}static toUint8Array(e){return this.toView(e,Uint8Array)}static toView(e,t){if(e.constructor===t)return e;if(this.isArrayBuffer(e))return new t(e);if(this.isArrayBufferView(e))return new t(e.buffer,e.byteOffset,e.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(e){return this.isArrayBufferView(e)||this.isArrayBuffer(e)}static isArrayBufferView(e){return ArrayBuffer.isView(e)||e&&this.isArrayBuffer(e.buffer)}static isEqual(e,t){let n=r.toUint8Array(e),o=r.toUint8Array(t);if(n.length!==o.byteLength)return!1;for(let s=0;s<n.length;s++)if(n[s]!==o[s])return!1;return!0}static concat(...e){let t;Array.isArray(e[0])&&!(e[1]instanceof Function)||Array.isArray(e[0])&&e[1]instanceof Function?t=e[0]:e[e.length-1]instanceof Function?t=e.slice(0,e.length-1):t=e;let n=0;for(let i of t)n+=i.byteLength;let o=new Uint8Array(n),s=0;for(let i of t){let a=this.toUint8Array(i);o.set(a,s),s+=a.length}return e[e.length-1]instanceof Function?this.toView(o,e[e.length-1]):o.buffer}},Nc="string",My=/^[0-9a-f]+$/i,Fy=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,Vy=/^[a-zA-Z0-9-_]+$/,Bs=class{static fromString(e){let t=unescape(encodeURIComponent(e)),n=new Uint8Array(t.length);for(let o=0;o<t.length;o++)n[o]=t.charCodeAt(o);return n.buffer}static toString(e){let t=Mt.toUint8Array(e),n="";for(let s=0;s<t.length;s++)n+=String.fromCharCode(t[s]);return decodeURIComponent(escape(n))}},et=class{static toString(e,t=!1){let n=Mt.toArrayBuffer(e),o=new DataView(n),s="";for(let i=0;i<n.byteLength;i+=2){let a=o.getUint16(i,t);s+=String.fromCharCode(a)}return s}static fromString(e,t=!1){let n=new ArrayBuffer(e.length*2),o=new DataView(n);for(let s=0;s<e.length;s++)o.setUint16(s*2,e.charCodeAt(s),t);return n}},ks=class r{static isHex(e){return typeof e===Nc&&My.test(e)}static isBase64(e){return typeof e===Nc&&Fy.test(e)}static isBase64Url(e){return typeof e===Nc&&Vy.test(e)}static ToString(e,t="utf8"){let n=Mt.toUint8Array(e);switch(t.toLowerCase()){case"utf8":return this.ToUtf8String(n);case"binary":return this.ToBinary(n);case"hex":return this.ToHex(n);case"base64":return this.ToBase64(n);case"base64url":return this.ToBase64Url(n);case"utf16le":return et.toString(n,!0);case"utf16":case"utf16be":return et.toString(n);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromString(e,t="utf8"){if(!e)return new ArrayBuffer(0);switch(t.toLowerCase()){case"utf8":return this.FromUtf8String(e);case"binary":return this.FromBinary(e);case"hex":return this.FromHex(e);case"base64":return this.FromBase64(e);case"base64url":return this.FromBase64Url(e);case"utf16le":return et.fromString(e,!0);case"utf16":case"utf16be":return et.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=Mt.toUint8Array(e);if(typeof btoa<"u"){let n=this.ToString(t,"binary");return btoa(n)}else return Buffer.from(t).toString("base64")}static FromBase64(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64(t))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return typeof atob<"u"?this.FromBinary(atob(t)):new Uint8Array(Buffer.from(t,"base64")).buffer}static FromBase64Url(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64Url(t))throw new TypeError("Argument 'base64url' is not Base64Url encoded");return this.FromBase64(this.Base64Padding(t.replace(/\-/g,"+").replace(/\_/g,"/")))}static ToBase64Url(e){return this.ToBase64(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}static FromUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.FromBinary(e);case"utf8":return Bs.fromString(e);case"utf16":case"utf16be":return et.fromString(e);case"utf16le":case"usc2":return et.fromString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.ToBinary(e);case"utf8":return Bs.toString(e);case"utf16":case"utf16be":return et.toString(e);case"utf16le":case"usc2":return et.toString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromBinary(e){let t=e.length,n=new Uint8Array(t);for(let o=0;o<t;o++)n[o]=e.charCodeAt(o);return n.buffer}static ToBinary(e){let t=Mt.toUint8Array(e),n="";for(let o=0;o<t.length;o++)n+=String.fromCharCode(t[o]);return n}static ToHex(e){let t=Mt.toUint8Array(e),n="",o=t.length;for(let s=0;s<o;s++){let i=t[s];i<16&&(n+="0"),n+=i.toString(16)}return n}static FromHex(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isHex(t))throw new TypeError("Argument 'hexString' is not HEX encoded");t.length%2&&(t=`0${t}`);let n=new Uint8Array(t.length/2);for(let o=0;o<t.length;o=o+2){let s=t.slice(o,o+2);n[o/2]=parseInt(s,16)}return n.buffer}static ToUtf16String(e,t=!1){return et.toString(e,t)}static FromUtf16String(e,t=!1){return et.fromString(e,t)}static Base64Padding(e){let t=4-e.length%4;if(t<4)for(let n=0;n<t;n++)e+="=";return e}static formatString(e){return e?.replace(/[\n\r\t ]/g,"")||""}};ks.DEFAULT_UTF8_ENCODING="utf8";function Hy(r,...e){let t=arguments[0];for(let n=1;n<arguments.length;n++){let o=arguments[n];for(let s in o)t[s]=o[s]}return t}function Ky(...r){let e=r.map(o=>o.byteLength).reduce((o,s)=>o+s),t=new Uint8Array(e),n=0;return r.map(o=>new Uint8Array(o)).forEach(o=>{for(let s of o)t[n++]=s}),t.buffer}function $y(r,e){if(!(r&&e)||r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let o=0;o<r.byteLength;o++)if(t[o]!==n[o])return!1;return!0}dn.BufferSourceConverter=Mt;dn.Convert=ks;dn.assign=Hy;dn.combine=Ky;dn.isEqual=$y});var np=Ke((kk,rp)=>{"use strict";function $w(r){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),t=0;t<e.length;t++)e[t]=255;for(var n=0;n<r.length;n++){var o=r.charAt(n),s=o.charCodeAt(0);if(e[s]!==255)throw new TypeError(o+" is ambiguous");e[s]=n}var i=r.length,a=r.charAt(0),c=Math.log(i)/Math.log(256),u=Math.log(256)/Math.log(i);function l(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var p=0,h=0,d=0,y=g.length;d!==y&&g[d]===0;)d++,p++;for(var x=(y-d)*u+1>>>0,b=new Uint8Array(x);d!==y;){for(var A=g[d],E=0,v=x-1;(A!==0||E<h)&&v!==-1;v--,E++)A+=256*b[v]>>>0,b[v]=A%i>>>0,A=A/i>>>0;if(A!==0)throw new Error("Non-zero carry");h=E,d++}for(var S=x-h;S!==x&&b[S]===0;)S++;for(var D=a.repeat(p);S<x;++S)D+=r.charAt(b[S]);return D}function f(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var p=0;if(g[p]!==" "){for(var h=0,d=0;g[p]===a;)h++,p++;for(var y=(g.length-p)*c+1>>>0,x=new Uint8Array(y);g[p];){var b=e[g.charCodeAt(p)];if(b===255)return;for(var A=0,E=y-1;(b!==0||A<d)&&E!==-1;E--,A++)b+=i*x[E]>>>0,x[E]=b%256>>>0,b=b/256>>>0;if(b!==0)throw new Error("Non-zero carry");d=A,p++}if(g[p]!==" "){for(var v=y-d;v!==y&&x[v]===0;)v++;for(var S=new Uint8Array(h+(y-v)),D=h;v!==y;)S[D++]=x[v++];return S}}}function m(g){var p=f(g);if(p)return p;throw new Error("Non-base"+i+" character")}return{encode:l,decodeUnsafe:f,decode:m}}rp.exports=$w});var vi=Ke((Ck,op)=>{"use strict";var qw=new TextDecoder,Ww=r=>qw.decode(r),zw=new TextEncoder,Gw=r=>zw.encode(r);function jw(r,e){let t=new Uint8Array(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}op.exports={decodeText:Ww,encodeText:Gw,concat:jw}});var ip=Ke((Ik,sp)=>{"use strict";var{encodeText:Yw}=vi(),mu=class{constructor(e,t,n,o){this.name=e,this.code=t,this.codeBuf=Yw(this.code),this.alphabet=o,this.codec=n(o)}encode(e){return this.codec.encode(e)}decode(e){for(let t of e)if(this.alphabet&&this.alphabet.indexOf(t)<0)throw new Error(`invalid character '${t}' in '${e}'`);return this.codec.decode(e)}};sp.exports=mu});var cp=Ke((Tk,ap)=>{"use strict";var Zw=(r,e,t)=>{let n={};for(let u=0;u<e.length;++u)n[e[u]]=u;let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*t/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let l=n[r[u]];if(l===void 0)throw new SyntaxError("Invalid character "+r[u]);a=a<<t|l,i+=t,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=t||255&a<<8-i)throw new SyntaxError("Unexpected end of data");return s},Xw=(r,e,t)=>{let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>t;)i-=t,s+=e[o&a>>i];if(i&&(s+=e[o&a<<t-i]),n)for(;s.length*t&7;)s+="=";return s},Jw=r=>e=>({encode(t){return Xw(t,e,r)},decode(t){return Zw(t,e,r)}});ap.exports={rfc4648:Jw}});var hp=Ke((_k,fp)=>{"use strict";var yo=np(),Qw=ip(),{rfc4648:Ue}=cp(),{decodeText:ex,encodeText:tx}=vi(),rx=()=>({encode:ex,decode:tx}),up=[["identity","\0",rx,""],["base2","0",Ue(1),"01"],["base8","7",Ue(3),"01234567"],["base10","9",yo,"0123456789"],["base16","f",Ue(4),"0123456789abcdef"],["base16upper","F",Ue(4),"0123456789ABCDEF"],["base32hex","v",Ue(5),"0123456789abcdefghijklmnopqrstuv"],["base32hexupper","V",Ue(5),"0123456789ABCDEFGHIJKLMNOPQRSTUV"],["base32hexpad","t",Ue(5),"0123456789abcdefghijklmnopqrstuv="],["base32hexpadupper","T",Ue(5),"0123456789ABCDEFGHIJKLMNOPQRSTUV="],["base32","b",Ue(5),"abcdefghijklmnopqrstuvwxyz234567"],["base32upper","B",Ue(5),"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"],["base32pad","c",Ue(5),"abcdefghijklmnopqrstuvwxyz234567="],["base32padupper","C",Ue(5),"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567="],["base32z","h",Ue(5),"ybndrfg8ejkmcpqxot1uwisza345h769"],["base36","k",yo,"0123456789abcdefghijklmnopqrstuvwxyz"],["base36upper","K",yo,"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"],["base58btc","z",yo,"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"],["base58flickr","Z",yo,"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"],["base64","m",Ue(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"],["base64pad","M",Ue(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="],["base64url","u",Ue(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"],["base64urlpad","U",Ue(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_="]],lp=up.reduce((r,e)=>(r[e[0]]=new Qw(e[0],e[1],e[2],e[3]),r),{}),nx=up.reduce((r,e)=>(r[e[1]]=lp[e[0]],r),{});fp.exports={names:lp,codes:nx}});var mp=Ke((zt,pp)=>{"use strict";var An=hp(),{encodeText:ox,decodeText:Ai,concat:dp}=vi();function sx(r,e){if(!e)throw new Error("requires an encoded Uint8Array");let{name:t,codeBuf:n}=Mr(r);return ux(t,e),dp([n,e],n.length+e.length)}function ix(r,e){let t=Mr(r),n=ox(t.encode(e));return dp([t.codeBuf,n],t.codeBuf.length+n.length)}function ax(r){r instanceof Uint8Array&&(r=Ai(r));let e=r[0];return["f","F","v","V","t","T","b","B","c","C","h","k","K"].includes(e)&&(r=r.toLowerCase()),Mr(r[0]).decode(r.substring(1))}function cx(r){if(r instanceof Uint8Array&&(r=Ai(r)),Object.prototype.toString.call(r)!=="[object String]")return!1;try{return Mr(r[0]).name}catch{return!1}}function ux(r,e){Mr(r).decode(Ai(e))}function Mr(r){if(Object.prototype.hasOwnProperty.call(An.names,r))return An.names[r];if(Object.prototype.hasOwnProperty.call(An.codes,r))return An.codes[r];throw new Error(`Unsupported encoding: ${r}`)}function lx(r){return r instanceof Uint8Array&&(r=Ai(r)),Mr(r[0])}zt=pp.exports=sx;zt.encode=ix;zt.decode=ax;zt.isEncoded=cx;zt.encoding=Mr;zt.encodingFromData=lx;var fx=Object.freeze(An.names),hx=Object.freeze(An.codes);zt.names=fx;zt.codes=hx});var wp=Ke((Rk,yp)=>{yp.exports=bp;var gp=128,dx=127,px=~dx,mx=Math.pow(2,31);function bp(r,e,t){e=e||[],t=t||0;for(var n=t;r>=mx;)e[t++]=r&255|gp,r/=128;for(;r&px;)e[t++]=r&255|gp,r>>>=7;return e[t]=r|0,bp.bytes=t-n+1,e}});var vp=Ke((Nk,Ep)=>{Ep.exports=gu;var gx=128,xp=127;function gu(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw gu.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&xp)<<o:(i&xp)*Math.pow(2,o),o+=7}while(i>=gx);return gu.bytes=s-n,t}});var Dp=Ke((Lk,Ap)=>{var bx=Math.pow(2,7),yx=Math.pow(2,14),wx=Math.pow(2,21),xx=Math.pow(2,28),Ex=Math.pow(2,35),vx=Math.pow(2,42),Ax=Math.pow(2,49),Dx=Math.pow(2,56),Sx=Math.pow(2,63);Ap.exports=function(r){return r<bx?1:r<yx?2:r<wx?3:r<xx?4:r<Ex?5:r<vx?6:r<Ax?7:r<Dx?8:r<Sx?9:10}});var Bp=Ke((Uk,Sp)=>{Sp.exports={encode:wp(),decode:vp(),encodingLength:Dp()}});var Cp=Ke((Ok,kp)=>{"use strict";var Bx=Object.freeze({identity:0,sha1:17,"sha2-256":18,"sha2-512":19,"sha3-512":20,"sha3-384":21,"sha3-256":22,"sha3-224":23,"shake-128":24,"shake-256":25,"keccak-224":26,"keccak-256":27,"keccak-384":28,"keccak-512":29,blake3:30,"murmur3-128":34,"murmur3-32":35,"dbl-sha2-256":86,md4:212,md5:213,bmt:214,"sha2-256-trunc254-padded":4114,"ripemd-128":4178,"ripemd-160":4179,"ripemd-256":4180,"ripemd-320":4181,x11:4352,kangarootwelve:7425,"sm3-256":21325,"blake2b-8":45569,"blake2b-16":45570,"blake2b-24":45571,"blake2b-32":45572,"blake2b-40":45573,"blake2b-48":45574,"blake2b-56":45575,"blake2b-64":45576,"blake2b-72":45577,"blake2b-80":45578,"blake2b-88":45579,"blake2b-96":45580,"blake2b-104":45581,"blake2b-112":45582,"blake2b-120":45583,"blake2b-128":45584,"blake2b-136":45585,"blake2b-144":45586,"blake2b-152":45587,"blake2b-160":45588,"blake2b-168":45589,"blake2b-176":45590,"blake2b-184":45591,"blake2b-192":45592,"blake2b-200":45593,"blake2b-208":45594,"blake2b-216":45595,"blake2b-224":45596,"blake2b-232":45597,"blake2b-240":45598,"blake2b-248":45599,"blake2b-256":45600,"blake2b-264":45601,"blake2b-272":45602,"blake2b-280":45603,"blake2b-288":45604,"blake2b-296":45605,"blake2b-304":45606,"blake2b-312":45607,"blake2b-320":45608,"blake2b-328":45609,"blake2b-336":45610,"blake2b-344":45611,"blake2b-352":45612,"blake2b-360":45613,"blake2b-368":45614,"blake2b-376":45615,"blake2b-384":45616,"blake2b-392":45617,"blake2b-400":45618,"blake2b-408":45619,"blake2b-416":45620,"blake2b-424":45621,"blake2b-432":45622,"blake2b-440":45623,"blake2b-448":45624,"blake2b-456":45625,"blake2b-464":45626,"blake2b-472":45627,"blake2b-480":45628,"blake2b-488":45629,"blake2b-496":45630,"blake2b-504":45631,"blake2b-512":45632,"blake2s-8":45633,"blake2s-16":45634,"blake2s-24":45635,"blake2s-32":45636,"blake2s-40":45637,"blake2s-48":45638,"blake2s-56":45639,"blake2s-64":45640,"blake2s-72":45641,"blake2s-80":45642,"blake2s-88":45643,"blake2s-96":45644,"blake2s-104":45645,"blake2s-112":45646,"blake2s-120":45647,"blake2s-128":45648,"blake2s-136":45649,"blake2s-144":45650,"blake2s-152":45651,"blake2s-160":45652,"blake2s-168":45653,"blake2s-176":45654,"blake2s-184":45655,"blake2s-192":45656,"blake2s-200":45657,"blake2s-208":45658,"blake2s-216":45659,"blake2s-224":45660,"blake2s-232":45661,"blake2s-240":45662,"blake2s-248":45663,"blake2s-256":45664,"skein256-8":45825,"skein256-16":45826,"skein256-24":45827,"skein256-32":45828,"skein256-40":45829,"skein256-48":45830,"skein256-56":45831,"skein256-64":45832,"skein256-72":45833,"skein256-80":45834,"skein256-88":45835,"skein256-96":45836,"skein256-104":45837,"skein256-112":45838,"skein256-120":45839,"skein256-128":45840,"skein256-136":45841,"skein256-144":45842,"skein256-152":45843,"skein256-160":45844,"skein256-168":45845,"skein256-176":45846,"skein256-184":45847,"skein256-192":45848,"skein256-200":45849,"skein256-208":45850,"skein256-216":45851,"skein256-224":45852,"skein256-232":45853,"skein256-240":45854,"skein256-248":45855,"skein256-256":45856,"skein512-8":45857,"skein512-16":45858,"skein512-24":45859,"skein512-32":45860,"skein512-40":45861,"skein512-48":45862,"skein512-56":45863,"skein512-64":45864,"skein512-72":45865,"skein512-80":45866,"skein512-88":45867,"skein512-96":45868,"skein512-104":45869,"skein512-112":45870,"skein512-120":45871,"skein512-128":45872,"skein512-136":45873,"skein512-144":45874,"skein512-152":45875,"skein512-160":45876,"skein512-168":45877,"skein512-176":45878,"skein512-184":45879,"skein512-192":45880,"skein512-200":45881,"skein512-208":45882,"skein512-216":45883,"skein512-224":45884,"skein512-232":45885,"skein512-240":45886,"skein512-248":45887,"skein512-256":45888,"skein512-264":45889,"skein512-272":45890,"skein512-280":45891,"skein512-288":45892,"skein512-296":45893,"skein512-304":45894,"skein512-312":45895,"skein512-320":45896,"skein512-328":45897,"skein512-336":45898,"skein512-344":45899,"skein512-352":45900,"skein512-360":45901,"skein512-368":45902,"skein512-376":45903,"skein512-384":45904,"skein512-392":45905,"skein512-400":45906,"skein512-408":45907,"skein512-416":45908,"skein512-424":45909,"skein512-432":45910,"skein512-440":45911,"skein512-448":45912,"skein512-456":45913,"skein512-464":45914,"skein512-472":45915,"skein512-480":45916,"skein512-488":45917,"skein512-496":45918,"skein512-504":45919,"skein512-512":45920,"skein1024-8":45921,"skein1024-16":45922,"skein1024-24":45923,"skein1024-32":45924,"skein1024-40":45925,"skein1024-48":45926,"skein1024-56":45927,"skein1024-64":45928,"skein1024-72":45929,"skein1024-80":45930,"skein1024-88":45931,"skein1024-96":45932,"skein1024-104":45933,"skein1024-112":45934,"skein1024-120":45935,"skein1024-128":45936,"skein1024-136":45937,"skein1024-144":45938,"skein1024-152":45939,"skein1024-160":45940,"skein1024-168":45941,"skein1024-176":45942,"skein1024-184":45943,"skein1024-192":45944,"skein1024-200":45945,"skein1024-208":45946,"skein1024-216":45947,"skein1024-224":45948,"skein1024-232":45949,"skein1024-240":45950,"skein1024-248":45951,"skein1024-256":45952,"skein1024-264":45953,"skein1024-272":45954,"skein1024-280":45955,"skein1024-288":45956,"skein1024-296":45957,"skein1024-304":45958,"skein1024-312":45959,"skein1024-320":45960,"skein1024-328":45961,"skein1024-336":45962,"skein1024-344":45963,"skein1024-352":45964,"skein1024-360":45965,"skein1024-368":45966,"skein1024-376":45967,"skein1024-384":45968,"skein1024-392":45969,"skein1024-400":45970,"skein1024-408":45971,"skein1024-416":45972,"skein1024-424":45973,"skein1024-432":45974,"skein1024-440":45975,"skein1024-448":45976,"skein1024-456":45977,"skein1024-464":45978,"skein1024-472":45979,"skein1024-480":45980,"skein1024-488":45981,"skein1024-496":45982,"skein1024-504":45983,"skein1024-512":45984,"skein1024-520":45985,"skein1024-528":45986,"skein1024-536":45987,"skein1024-544":45988,"skein1024-552":45989,"skein1024-560":45990,"skein1024-568":45991,"skein1024-576":45992,"skein1024-584":45993,"skein1024-592":45994,"skein1024-600":45995,"skein1024-608":45996,"skein1024-616":45997,"skein1024-624":45998,"skein1024-632":45999,"skein1024-640":46e3,"skein1024-648":46001,"skein1024-656":46002,"skein1024-664":46003,"skein1024-672":46004,"skein1024-680":46005,"skein1024-688":46006,"skein1024-696":46007,"skein1024-704":46008,"skein1024-712":46009,"skein1024-720":46010,"skein1024-728":46011,"skein1024-736":46012,"skein1024-744":46013,"skein1024-752":46014,"skein1024-760":46015,"skein1024-768":46016,"skein1024-776":46017,"skein1024-784":46018,"skein1024-792":46019,"skein1024-800":46020,"skein1024-808":46021,"skein1024-816":46022,"skein1024-824":46023,"skein1024-832":46024,"skein1024-840":46025,"skein1024-848":46026,"skein1024-856":46027,"skein1024-864":46028,"skein1024-872":46029,"skein1024-880":46030,"skein1024-888":46031,"skein1024-896":46032,"skein1024-904":46033,"skein1024-912":46034,"skein1024-920":46035,"skein1024-928":46036,"skein1024-936":46037,"skein1024-944":46038,"skein1024-952":46039,"skein1024-960":46040,"skein1024-968":46041,"skein1024-976":46042,"skein1024-984":46043,"skein1024-992":46044,"skein1024-1000":46045,"skein1024-1008":46046,"skein1024-1016":46047,"skein1024-1024":46048,"poseidon-bls12_381-a2-fc1":46081,"poseidon-bls12_381-a2-fc1-sc":46082});kp.exports={names:Bx}});function kx(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(t[i]!==255)throw new TypeError(s+" is ambiguous");t[i]=o}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function f(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var h=0,d=0,y=0,x=p.length;y!==x&&p[y]===0;)y++,h++;for(var b=(x-y)*l+1>>>0,A=new Uint8Array(b);y!==x;){for(var E=p[y],v=0,S=b-1;(E!==0||v<d)&&S!==-1;S--,v++)E+=256*A[S]>>>0,A[S]=E%a>>>0,E=E/a>>>0;if(E!==0)throw new Error("Non-zero carry");d=v,y++}for(var D=b-d;D!==b&&A[D]===0;)D++;for(var _=c.repeat(h);D<b;++D)_+=r.charAt(A[D]);return _}function m(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var h=0;if(p[h]!==" "){for(var d=0,y=0;p[h]===c;)d++,h++;for(var x=(p.length-h)*u+1>>>0,b=new Uint8Array(x);p[h];){var A=t[p.charCodeAt(h)];if(A===255)return;for(var E=0,v=x-1;(A!==0||E<y)&&v!==-1;v--,E++)A+=a*b[v]>>>0,b[v]=A%256>>>0,A=A/256>>>0;if(A!==0)throw new Error("Non-zero carry");y=E,h++}if(p[h]!==" "){for(var S=x-y;S!==x&&b[S]===0;)S++;for(var D=new Uint8Array(d+(x-S)),_=d;S!==x;)D[_++]=b[S++];return D}}}function g(p){var h=m(p);if(h)return h;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:m,decode:g}}var Cx,Ix,Ip,Tp=re(()=>{Cx=kx,Ix=Cx,Ip=Ix});var Mk,_p,Gt,Rp,Np,hr=re(()=>{Mk=new Uint8Array(0),_p=(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},Gt=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")},Rp=r=>new TextEncoder().encode(r),Np=r=>new TextDecoder().decode(r)});var bu,yu,wu,Up,xu,Dn,dr,Tx,_x,me,mt=re(()=>{Tp();hr();bu=class{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")}},yu=class{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 Up(this,e)}},wu=class{constructor(e){this.decoders=e}or(e){return Up(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},Up=(r,e)=>new wu({...r.decoders||{[r.prefix]:r},...e.decoders||{[e.prefix]:e}}),xu=class{constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new bu(e,t,n),this.decoder=new yu(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}},Dn=({name:r,prefix:e,encode:t,decode:n})=>new xu(r,e,t,n),dr=({prefix:r,name:e,alphabet:t})=>{let{encode:n,decode:o}=Ip(t,e);return Dn({prefix:r,name:e,encode:n,decode:s=>Gt(o(s))})},Tx=(r,e,t,n)=>{let o={};for(let l=0;l<e.length;++l)o[e[l]]=l;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*t/8|0),a=0,c=0,u=0;for(let l=0;l<s;++l){let f=o[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},_x=(r,e,t)=>{let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>t;)i-=t,s+=e[o&a>>i];if(i&&(s+=e[o&a<<t-i]),n)for(;s.length*t&7;)s+="=";return s},me=({name:r,prefix:e,bitsPerChar:t,alphabet:n})=>Dn({prefix:e,name:r,encode(o){return _x(o,n,t)},decode(o){return Tx(o,n,t,r)}})});var Eu={};Q(Eu,{identity:()=>Rx});var Rx,Op=re(()=>{mt();hr();Rx=Dn({prefix:"\0",name:"identity",encode:r=>Np(r),decode:r=>Rp(r)})});var vu={};Q(vu,{base2:()=>Nx});var Nx,Pp=re(()=>{mt();Nx=me({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1})});var Au={};Q(Au,{base8:()=>Lx});var Lx,Mp=re(()=>{mt();Lx=me({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3})});var Du={};Q(Du,{base10:()=>Ux});var Ux,Fp=re(()=>{mt();Ux=dr({prefix:"9",name:"base10",alphabet:"0123456789"})});var Su={};Q(Su,{base16:()=>Ox,base16upper:()=>Px});var Ox,Px,Vp=re(()=>{mt();Ox=me({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Px=me({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4})});var Bu={};Q(Bu,{base32:()=>Sn,base32hex:()=>Hx,base32hexpad:()=>$x,base32hexpadupper:()=>qx,base32hexupper:()=>Kx,base32pad:()=>Fx,base32padupper:()=>Vx,base32upper:()=>Mx,base32z:()=>Wx});var Sn,Mx,Fx,Vx,Hx,Kx,$x,qx,Wx,ku=re(()=>{mt();Sn=me({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Mx=me({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Fx=me({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Vx=me({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Hx=me({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Kx=me({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),$x=me({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),qx=me({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Wx=me({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5})});var Cu={};Q(Cu,{base36:()=>zx,base36upper:()=>Gx});var zx,Gx,Hp=re(()=>{mt();zx=dr({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Gx=dr({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"})});var Iu={};Q(Iu,{base58btc:()=>St,base58flickr:()=>jx});var St,jx,Tu=re(()=>{mt();St=dr({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),jx=dr({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"})});var _u={};Q(_u,{base64:()=>Yx,base64pad:()=>Zx,base64url:()=>Xx,base64urlpad:()=>Jx});var Yx,Zx,Xx,Jx,Kp=re(()=>{mt();Yx=me({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Zx=me({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Xx=me({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Jx=me({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6})});var Ru={};Q(Ru,{base256emoji:()=>n2});function t2(r){return r.reduce((e,t)=>(e+=Qx[t],e),"")}function r2(r){let e=[];for(let t of r){let n=e2[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var $p,Qx,e2,n2,qp=re(()=>{mt();$p=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}"),Qx=$p.reduce((r,e,t)=>(r[t]=e,r),[]),e2=$p.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);n2=Dn({prefix:"\u{1F680}",name:"base256emoji",encode:t2,decode:r2})});function Gp(r,e,t){e=e||[],t=t||0;for(var n=t;r>=a2;)e[t++]=r&255|Wp,r/=128;for(;r&i2;)e[t++]=r&255|Wp,r>>>=7;return e[t]=r|0,Gp.bytes=t-n+1,e}function Nu(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Nu.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&zp)<<o:(i&zp)*Math.pow(2,o),o+=7}while(i>=u2);return Nu.bytes=s-n,t}var o2,Wp,s2,i2,a2,c2,u2,zp,l2,f2,h2,d2,p2,m2,g2,b2,y2,w2,x2,E2,wo,jp=re(()=>{o2=Gp,Wp=128,s2=127,i2=~s2,a2=Math.pow(2,31);c2=Nu,u2=128,zp=127;l2=Math.pow(2,7),f2=Math.pow(2,14),h2=Math.pow(2,21),d2=Math.pow(2,28),p2=Math.pow(2,35),m2=Math.pow(2,42),g2=Math.pow(2,49),b2=Math.pow(2,56),y2=Math.pow(2,63),w2=function(r){return r<l2?1:r<f2?2:r<h2?3:r<d2?4:r<p2?5:r<m2?6:r<g2?7:r<b2?8:r<y2?9:10},x2={encode:o2,decode:c2,encodingLength:w2},E2=x2,wo=E2});var xo,Bn,kn,Si=re(()=>{jp();xo=(r,e=0)=>[wo.decode(r,e),wo.decode.bytes],Bn=(r,e,t=0)=>(wo.encode(r,e,t),e),kn=r=>wo.encodingLength(r)});var Fr,Yp,Zp,Cn,vo=re(()=>{hr();Si();Fr=(r,e)=>{let t=e.byteLength,n=kn(r),o=n+kn(t),s=new Uint8Array(o+t);return Bn(r,s,0),Bn(t,s,n),s.set(e,o),new Cn(r,t,e,s)},Yp=r=>{let e=Gt(r),[t,n]=xo(e),[o,s]=xo(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Cn(t,o,i,e)},Zp=(r,e)=>r===e?!0:r.code===e.code&&r.size===e.size&&_p(r.bytes,e.bytes),Cn=class{constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}}});var Uu,Lu,Ou=re(()=>{vo();Uu=({name:r,code:e,encode:t})=>new Lu(r,e,t),Lu=class{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?Fr(this.code,t):t.then(n=>Fr(this.code,n))}else throw Error("Unknown type, must be binary type")}}});var Pu={};Q(Pu,{sha256:()=>v2,sha512:()=>A2});var Jp,v2,A2,Qp=re(()=>{Ou();Jp=r=>async e=>new Uint8Array(await crypto.subtle.digest(r,e)),v2=Uu({name:"sha2-256",code:18,encode:Jp("SHA-256")}),A2=Uu({name:"sha2-512",code:19,encode:Jp("SHA-512")})});var Mu={};Q(Mu,{identity:()=>B2});var e0,D2,t0,S2,B2,r0=re(()=>{hr();vo();e0=0,D2="identity",t0=Gt,S2=r=>Fr(e0,t0(r)),B2={code:e0,name:D2,encode:t0,digest:S2}});var n0=re(()=>{hr()});var s6,i6,o0=re(()=>{s6=new TextEncoder,i6=new TextDecoder});var Ci,I2,T2,_2,Ao,R2,s0,i0,Bi,ki,N2,L2,U2,a0=re(()=>{Si();vo();Tu();ku();hr();Ci=class r{constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this.byteOffset=o.byteOffset,this.byteLength=o.byteLength,this.asCID=this,this._baseCache=new Map,Object.defineProperties(this,{byteOffset:ki,byteLength:ki,code:Bi,version:Bi,multihash:Bi,bytes:Bi,_baseCache:ki,asCID:ki})}toV0(){switch(this.version){case 0:return this;default:{let{code:e,multihash:t}=this;if(e!==Ao)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==R2)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=Fr(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}equals(e){return e&&this.code===e.code&&this.version===e.version&&Zp(this.multihash,e.multihash)}toString(e){let{bytes:t,version:n,_baseCache:o}=this;switch(n){case 0:return T2(t,o,e||St.encoder);default:return _2(t,o,e||Sn.encoder)}}toJSON(){return{code:this.code,version:this.version,hash:this.multihash.bytes}}get[Symbol.toStringTag](){return"CID"}[Symbol.for("nodejs.util.inspect.custom")](){return"CID("+this.toString()+")"}static isCID(e){return L2(/^0\.0/,U2),!!(e&&(e[i0]||e.asCID===e))}get toBaseEncodedString(){throw new Error("Deprecated, use .toString()")}get codec(){throw new Error('"codec" property is deprecated, use integer "code" property instead')}get buffer(){throw new Error("Deprecated .buffer property, use .bytes to get Uint8Array instead")}get multibaseName(){throw new Error('"multibaseName" property is deprecated')}get prefix(){throw new Error('"prefix" property is deprecated')}static asCID(e){if(e instanceof r)return e;if(e!=null&&e.asCID===e){let{version:t,code:n,multihash:o,bytes:s}=e;return new r(t,n,o,s||s0(t,n,o.bytes))}else if(e!=null&&e[i0]===!0){let{version:t,multihash:n,code:o}=e,s=Yp(n);return r.create(t,o,s)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");switch(e){case 0:{if(t!==Ao)throw new Error(`Version 0 CID must use dag-pb (code: ${Ao}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=s0(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Ao,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=Gt(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let s=o.subarray(t.multihashSize-t.digestSize),i=new Cn(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[f,m]=xo(e.subarray(t));return t+=m,f},o=n(),s=Ao;if(o===18?(o=0,t=0):o===1&&(s=n()),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=t,a=n(),c=n(),u=t+c,l=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(e,t){let[n,o]=I2(e,t),s=r.decode(o);return s._baseCache.set(n,e),s}},I2=(r,e)=>{switch(r[0]){case"Q":{let t=e||St;return[St.prefix,t.decode(`${St.prefix}${r}`)]}case St.prefix:{let t=e||St;return[St.prefix,t.decode(r)]}case Sn.prefix:{let t=e||Sn;return[Sn.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)]}}},T2=(r,e,t)=>{let{prefix:n}=t;if(n!==St.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let s=t.encode(r).slice(1);return e.set(n,s),s}else return o},_2=(r,e,t)=>{let{prefix:n}=t,o=e.get(n);if(o==null){let s=t.encode(r);return e.set(n,s),s}else return o},Ao=112,R2=18,s0=(r,e,t)=>{let n=kn(r),o=n+kn(e),s=new Uint8Array(o+t.byteLength);return Bn(r,s,0),Bn(e,s,n),s.set(t,o),s},i0=Symbol.for("@ipld/js-cid/CID"),Bi={writable:!1,configurable:!1,enumerable:!0},ki={writable:!1,enumerable:!1,configurable:!1},N2="0.0.0-dev",L2=(r,e)=>{if(r.test(N2))console.warn(e);else throw new Error(e)},U2=`CID.isCID(v) is deprecated and will be removed in the next major release.
3
3
  Following code pattern:
4
4
 
5
5
  if (CID.isCID(value)) {
@@ -13,12 +13,12 @@ if (cid) {
13
13
  // Make sure to use cid instead of value
14
14
  doSomethingWithCID(cid)
15
15
  }
16
- `});var n0=re(()=>{r0();Di();hr();Rl();Eo()});var Ul,s6,o0=re(()=>{_p();Rp();Np();Lp();Up();Al();Op();Bl();Pp();Fp();jp();Xp();Jp();Qp();n0();Ul={...bl,...yl,...wl,...xl,...El,...vl,...Dl,...Sl,...kl,...Cl},s6={...Nl,...Ll}});function In(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}var Ci=re(()=>{});function Ii(r=0){return globalThis.Buffer!=null&&globalThis.Buffer.allocUnsafe!=null?In(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}var Ol=re(()=>{Ci()});function i0(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var s0,Pl,R2,Ti,Ml=re(()=>{o0();Ol();s0=i0("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Pl=i0("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=Ii(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),R2={utf8:s0,"utf-8":s0,hex:Ul.base16,latin1:Pl,ascii:Pl,binary:Pl,...Ul},Ti=R2});var a0={};J(a0,{toString:()=>N2});function N2(r,e="utf8"){let t=Ti[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 c0=re(()=>{Ml()});var l0={};J(l0,{fromString:()=>L2});function L2(r,e="utf8"){let t=Ti[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 u0=re(()=>{Ml();Ci()});var f0={};J(f0,{concat:()=>U2});function U2(r,e){e||(e=r.reduce((o,s)=>o+s.length,0));let t=Ii(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return In(t)}var h0=re(()=>{Ol();Ci()});var Vl=Ke((y6,y0)=>{"use strict";var d0=up(),Tn=Ep(),{names:Ao}=Ap(),{toString:_i}=(c0(),Bo(a0)),{fromString:O2}=(u0(),Bo(l0)),{concat:P2}=(h0(),Bo(f0)),_n={};for(let r in Ao){let e=r;_n[Ao[e]]=e}Object.freeze(_n);function M2(r){if(!(r instanceof Uint8Array))throw new Error("must be passed a Uint8Array");return _i(r,"base16")}function F2(r){return O2(r,"base16")}function V2(r){if(!(r instanceof Uint8Array))throw new Error("must be passed a Uint8Array");return _i(d0.encode("base58btc",r)).slice(1)}function H2(r){let e=r instanceof Uint8Array?_i(r):r;return d0.decode("z"+e)}function p0(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(!g0(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${_i(r,"base16")}`);return{code:e,name:_n[e],length:t,digest:r}}function K2(r,e,t){if(!r||e===void 0)throw new Error("multihash encode requires at least two args: digest, code");let n=m0(e);if(!(r instanceof Uint8Array))throw new Error("digest should be a Uint8Array");if(t==null&&(t=r.length),t&&r.length!==t)throw new Error("digest length should be equal to specified length.");let o=Tn.encode(n),s=Tn.encode(t);return P2([o,s,r],o.length+s.length+r.length)}function m0(r){let e=r;if(typeof r=="string"){if(Ao[r]===void 0)throw new Error(`Unrecognized hash function named: ${r}`);e=Ao[r]}if(typeof e!="number")throw new Error(`Hash function code should be a number. Got: ${e}`);if(_n[e]===void 0&&!Fl(e))throw new Error(`Unrecognized function code: ${e}`);return e}function Fl(r){return r>0&&r<16}function g0(r){return!!(Fl(r)||_n[r])}function b0(r){p0(r)}function $2(r){return b0(r),r.subarray(0,2)}y0.exports={names:Ao,codes:_n,toHexString:M2,fromHexString:F2,toB58String:V2,fromB58String:H2,decode:p0,encode:K2,coerceCode:m0,isAppCode:Fl,validate:b0,prefix:$2,isValidCode:g0}});var Q2={};J(Q2,{webRTC:()=>J2,webRTCDirect:()=>X2});var Ql=Symbol.for("@libp2p/peer-id");var ko=Symbol.for("@libp2p/transport");var eu;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(eu||(eu={}));var L=class extends Error{code;props;constructor(e,t,n){super(e),this.code=t,this.name=n?.name??"CodeError",this.props=n??{}}};var Co=(r,...e)=>{try{[...e]}catch{}};var Io=class extends EventTarget{#e=new Map;constructor(){super(),Co(1/0,this)}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:s})=>s!==t),this.#e.set(e,o))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new V0(e,t))}},Ui=class extends Event{detail;constructor(e,t){super(e,t),this.detail=t?.detail}},V0=globalThis.CustomEvent??Ui;var Vr=Symbol.for("@libp2p/service-capabilities"),tu=Symbol.for("@libp2p/service-dependencies");var Vi={};J(Vi,{base58btc:()=>ge,base58flickr:()=>z0});var T1=new Uint8Array(0);function ru(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 kt(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 nu(r){return new TextEncoder().encode(r)}function ou(r){return new TextDecoder().decode(r)}function H0(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(t[i]!==255)throw new TypeError(s+" is ambiguous");t[i]=o}var a=r.length,c=r.charAt(0),l=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function f(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var h=0,d=0,y=0,x=p.length;y!==x&&p[y]===0;)y++,h++;for(var b=(x-y)*u+1>>>0,A=new Uint8Array(b);y!==x;){for(var E=p[y],v=0,S=b-1;(E!==0||v<d)&&S!==-1;S--,v++)E+=256*A[S]>>>0,A[S]=E%a>>>0,E=E/a>>>0;if(E!==0)throw new Error("Non-zero carry");d=v,y++}for(var D=b-d;D!==b&&A[D]===0;)D++;for(var _=c.repeat(h);D<b;++D)_+=r.charAt(A[D]);return _}function m(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var h=0;if(p[h]!==" "){for(var d=0,y=0;p[h]===c;)d++,h++;for(var x=(p.length-h)*l+1>>>0,b=new Uint8Array(x);p[h];){var A=t[p.charCodeAt(h)];if(A===255)return;for(var E=0,v=x-1;(A!==0||E<y)&&v!==-1;v--,E++)A+=a*b[v]>>>0,b[v]=A%256>>>0,A=A/256>>>0;if(A!==0)throw new Error("Non-zero carry");y=E,h++}if(p[h]!==" "){for(var S=x-y;S!==x&&b[S]===0;)S++;for(var D=new Uint8Array(d+(x-S)),_=d;S!==x;)D[_++]=b[S++];return D}}}function g(p){var h=m(p);if(h)return h;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:m,decode:g}}var K0=H0,$0=K0,iu=$0;var Oi=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")}},Pi=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 au(this,e)}},Mi=class{decoders;constructor(e){this.decoders=e}or(e){return au(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 au(r,e){return new Mi({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Fi=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new Oi(e,t,n),this.decoder=new Pi(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Hr({name:r,prefix:e,encode:t,decode:n}){return new Fi(r,e,t,n)}function Gt({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=iu(t,r);return Hr({prefix:e,name:r,encode:n,decode:s=>kt(o(s))})}function q0(r,e,t,n){let o={};for(let u=0;u<e.length;++u)o[e[u]]=u;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*t/8|0),a=0,c=0,l=0;for(let u=0;u<s;++u){let f=o[r[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<t|f,a+=t,a>=8&&(a-=8,i[l++]=255&c>>a)}if(a>=t||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return i}function W0(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>t;)i-=t,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<t-i]),n)for(;s.length*t&7;)s+="=";return s}function de({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return Hr({prefix:e,name:r,encode(o){return W0(o,n,t)},decode(o){return q0(o,n,t,r)}})}var ge=Gt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),z0=Gt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Hi={};J(Hi,{base10:()=>G0});var G0=Gt({prefix:"9",name:"base10",alphabet:"0123456789"});var Ki={};J(Ki,{base16:()=>j0,base16upper:()=>Y0});var j0=de({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Y0=de({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var $i={};J($i,{base2:()=>Z0});var Z0=de({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var qi={};J(qi,{base256emoji:()=>tm});var cu=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}"),X0=cu.reduce((r,e,t)=>(r[t]=e,r),[]),J0=cu.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function Q0(r){return r.reduce((e,t)=>(e+=X0[t],e),"")}function em(r){let e=[];for(let t of r){let n=J0[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var tm=Hr({prefix:"\u{1F680}",name:"base256emoji",encode:Q0,decode:em});var Wi={};J(Wi,{base32:()=>Ct,base32hex:()=>sm,base32hexpad:()=>am,base32hexpadupper:()=>cm,base32hexupper:()=>im,base32pad:()=>nm,base32padupper:()=>om,base32upper:()=>rm,base32z:()=>lm});var Ct=de({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),rm=de({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),nm=de({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),om=de({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),sm=de({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),im=de({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),am=de({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),cm=de({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),lm=de({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var zi={};J(zi,{base36:()=>um,base36upper:()=>fm});var um=Gt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),fm=Gt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Yi={};J(Yi,{base64:()=>Gi,base64pad:()=>hm,base64url:()=>ji,base64urlpad:()=>dm});var Gi=de({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),hm=de({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),ji=de({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),dm=de({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Zi={};J(Zi,{base8:()=>pm});var pm=de({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Xi={};J(Xi,{identity:()=>mm});var mm=Hr({prefix:"\0",name:"identity",encode:r=>ou(r),decode:r=>nu(r)});var z1=new TextEncoder,G1=new TextDecoder;var Qi={};J(Qi,{identity:()=>jt});var ym=fu,lu=128,wm=127,xm=~wm,Em=Math.pow(2,31);function fu(r,e,t){e=e||[],t=t||0;for(var n=t;r>=Em;)e[t++]=r&255|lu,r/=128;for(;r&xm;)e[t++]=r&255|lu,r>>>=7;return e[t]=r|0,fu.bytes=t-n+1,e}var vm=Ji,Am=128,uu=127;function Ji(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Ji.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&uu)<<o:(i&uu)*Math.pow(2,o),o+=7}while(i>=Am);return Ji.bytes=s-n,t}var Dm=Math.pow(2,7),Sm=Math.pow(2,14),Bm=Math.pow(2,21),km=Math.pow(2,28),Cm=Math.pow(2,35),Im=Math.pow(2,42),Tm=Math.pow(2,49),_m=Math.pow(2,56),Rm=Math.pow(2,63),Nm=function(r){return r<Dm?1:r<Sm?2:r<Bm?3:r<km?4:r<Cm?5:r<Im?6:r<Tm?7:r<_m?8:r<Rm?9:10},Lm={encode:ym,decode:vm,encodingLength:Nm},Um=Lm,Nn=Um;function Ln(r,e=0){return[Nn.decode(r,e),Nn.decode.bytes]}function Kr(r,e,t=0){return Nn.encode(r,e,t),e}function $r(r){return Nn.encodingLength(r)}function gt(r,e){let t=e.byteLength,n=$r(r),o=n+$r(t),s=new Uint8Array(o+t);return Kr(r,s,0),Kr(t,s,n),s.set(e,o),new qr(r,t,e,s)}function mr(r){let e=kt(r),[t,n]=Ln(e),[o,s]=Ln(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new qr(t,o,i,e)}function hu(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&ru(r.bytes,t.bytes)}}var qr=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};var du=0,Om="identity",pu=kt;function Pm(r){return gt(du,pu(r))}var jt={code:du,name:Om,encode:pu,digest:Pm};var ra={};J(ra,{sha256:()=>_e,sha512:()=>Mm});function ta({name:r,code:e,encode:t}){return new ea(r,e,t)}var ea=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?gt(this.code,t):t.then(n=>gt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function gu(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var _e=ta({name:"sha2-256",code:18,encode:gu("SHA-256")}),Mm=ta({name:"sha2-512",code:19,encode:gu("SHA-512")});function bu(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return Vm(t,na(r),e??ge.encoder);default:return Hm(t,na(r),e??Ct.encoder)}}var yu=new WeakMap;function na(r){let e=yu.get(r);if(e==null){let t=new Map;return yu.set(r,t),t}return e}var tt=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==Un)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Km)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=gt(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&&hu(e.multihash,n.multihash)}toString(e){return bu(this,e)}toJSON(){return{"/":bu(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:s,bytes:i}=t;return new r(n,o,s,i??wu(n,o,s.bytes))}else if(t[$m]===!0){let{version:n,multihash:o,code:s}=t,i=mr(o);return r.create(n,s,i)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==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 o=wu(e,t,n.bytes);return new r(e,t,n,o)}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,o=kt(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let s=o.subarray(t.multihashSize-t.digestSize),i=new qr(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[f,m]=Ln(e.subarray(t));return t+=m,f},o=n(),s=Un;if(o===18?(o=0,t=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=t,a=n(),c=n(),l=t+c,u=l-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:u,size:l}}static parse(e,t){let[n,o]=Fm(e,t),s=r.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return na(s).set(n,e),s}};function Fm(r,e){switch(r[0]){case"Q":{let t=e??ge;return[ge.prefix,t.decode(`${ge.prefix}${r}`)]}case ge.prefix:{let t=e??ge;return[ge.prefix,t.decode(r)]}case Ct.prefix:{let t=e??Ct;return[Ct.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 Vm(r,e,t){let{prefix:n}=t;if(n!==ge.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let s=t.encode(r).slice(1);return e.set(n,s),s}else return o}function Hm(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let s=t.encode(r);return e.set(n,s),s}else return o}var Un=112,Km=18;function wu(r,e,t){let n=$r(r),o=n+$r(e),s=new Uint8Array(o+t.byteLength);return Kr(r,s,0),Kr(e,s,n),s.set(t,o),s}var $m=Symbol.for("@ipld/js-cid/CID");var bt={...Xi,...$i,...Zi,...Hi,...Ki,...Wi,...zi,...Vi,...Yi,...qi},pE={...ra,...Qi};function Ae(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}var qm=Symbol.for("nodejs.util.inspect.custom"),xu=Object.values(bt).map(r=>r.decoder).reduce((r,e)=>r.or(e),bt.identity.decoder),Eu=114,oa=36,sa=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()})`}[Ql]=!0;toString(){return this.string==null&&(this.string=ge.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return tt.createV1(Eu,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return Ae(this.multihash.bytes,e);if(typeof e=="string")return br(e).equals(this);if(e?.multihash?.bytes!=null)return Ae(this.multihash.bytes,e.multihash.bytes);throw new Error("not valid Id")}[qm](){return`PeerId(${this.toString()})`}},Wr=class extends On{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},zr=class extends On{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.multihash.digest}},Gr=class extends On{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.multihash.digest}};function br(r,e){if(e=e??xu,r.charAt(0)==="1"||r.charAt(0)==="Q"){let t=mr(ge.decode(`z${r}`));return r.startsWith("12D")?new zr({multihash:t}):r.startsWith("16U")?new Gr({multihash:t}):new Wr({multihash:t})}return Wm(xu.decode(r))}function Wm(r){try{let e=mr(r);if(e.code===jt.code){if(e.digest.length===oa)return new zr({multihash:e});if(e.digest.length===sa)return new Gr({multihash:e})}if(e.code===_e.code)return new Wr({multihash:e})}catch{return zm(tt.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function zm(r){if(r==null||r.multihash==null||r.version==null||r.version===1&&r.code!==Eu)throw new Error("Supplied PeerID CID is invalid");let e=r.multihash;if(e.code===_e.code)return new Wr({multihash:r.multihash});if(e.code===jt.code){if(e.digest.length===oa)return new zr({multihash:r.multihash});if(e.digest.length===sa)return new Gr({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function ia(r,e){return r.length===oa?new zr({multihash:gt(jt.code,r),privateKey:e}):r.length===sa?new Gr({multihash:gt(jt.code,r),privateKey:e}):new Wr({multihash:await _e.digest(r),publicKey:r,privateKey:e})}function De(r=0){return new Uint8Array(r)}function Se(r=0){return new Uint8Array(r)}function Au(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var vu=Au("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),aa=Au("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=Se(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),jm={utf8:vu,"utf-8":vu,hex:bt.base16,latin1:aa,ascii:aa,binary:aa,...bt},_o=jm;function z(r,e="utf8"){let t=_o[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var Ym=Math.pow(2,7),Zm=Math.pow(2,14),Xm=Math.pow(2,21),ca=Math.pow(2,28),la=Math.pow(2,35),ua=Math.pow(2,42),fa=Math.pow(2,49),ne=128,Pe=127;function we(r){if(r<Ym)return 1;if(r<Zm)return 2;if(r<Xm)return 3;if(r<ca)return 4;if(r<la)return 5;if(r<ua)return 6;if(r<fa)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ha(r,e,t=0){switch(we(r)){case 8:e[t++]=r&255|ne,r/=128;case 7:e[t++]=r&255|ne,r/=128;case 6:e[t++]=r&255|ne,r/=128;case 5:e[t++]=r&255|ne,r/=128;case 4:e[t++]=r&255|ne,r>>>=7;case 3:e[t++]=r&255|ne,r>>>=7;case 2:e[t++]=r&255|ne,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function Jm(r,e,t=0){switch(we(r)){case 8:e.set(t++,r&255|ne),r/=128;case 7:e.set(t++,r&255|ne),r/=128;case 6:e.set(t++,r&255|ne),r/=128;case 5:e.set(t++,r&255|ne),r/=128;case 4:e.set(t++,r&255|ne),r>>>=7;case 3:e.set(t++,r&255|ne),r>>>=7;case 2:e.set(t++,r&255|ne),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function da(r,e){let t=r[e],n=0;if(n+=t&Pe,t<ne||(t=r[e+1],n+=(t&Pe)<<7,t<ne)||(t=r[e+2],n+=(t&Pe)<<14,t<ne)||(t=r[e+3],n+=(t&Pe)<<21,t<ne)||(t=r[e+4],n+=(t&Pe)*ca,t<ne)||(t=r[e+5],n+=(t&Pe)*la,t<ne)||(t=r[e+6],n+=(t&Pe)*ua,t<ne)||(t=r[e+7],n+=(t&Pe)*fa,t<ne))return n;throw new RangeError("Could not decode varint")}function Qm(r,e){let t=r.get(e),n=0;if(n+=t&Pe,t<ne||(t=r.get(e+1),n+=(t&Pe)<<7,t<ne)||(t=r.get(e+2),n+=(t&Pe)<<14,t<ne)||(t=r.get(e+3),n+=(t&Pe)<<21,t<ne)||(t=r.get(e+4),n+=(t&Pe)*ca,t<ne)||(t=r.get(e+5),n+=(t&Pe)*la,t<ne)||(t=r.get(e+6),n+=(t&Pe)*ua,t<ne)||(t=r.get(e+7),n+=(t&Pe)*fa,t<ne))return n;throw new RangeError("Could not decode varint")}function yt(r,e,t=0){return e==null&&(e=Se(we(r))),e instanceof Uint8Array?ha(r,e,t):Jm(r,e,t)}function rt(r,e=0){return r instanceof Uint8Array?da(r,e):Qm(r,e)}function xe(r,e){e==null&&(e=r.reduce((o,s)=>o+s.length,0));let t=Se(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var Ro=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",l=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let m=Number.parseInt(f,e);if(!Number.isNaN(m))return m});if(u===void 0)break;if(s*=e,s+=u,s>l||(i+=1,t!==void 0&&i>t))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let o=n*2;if(n<t.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return t[o]=i[0],t[o+1]=i[1],t[o+2]=i[2],t[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];t[o]=s>>8,t[o+1]=s&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,o]=e(t);if(n===16)return t;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=e(s.subarray(0,i));return t.set(s.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Du=45,tg=15,jr=new Ro;function pa(r){if(!(r.length>tg))return jr.new(r).parseWith(()=>jr.readIPv4Addr())}function ma(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Du))return jr.new(r).parseWith(()=>jr.readIPv6Addr())}function No(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Du))return jr.new(r).parseWith(()=>jr.readIPAddr())}var qE=parseInt("0xFFFF",16),WE=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Q(r,e="utf8"){let t=_o[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function Lo(r){return!!pa(r)}function Uo(r){return!!ma(r)}function Oo(r){return!!No(r)}var ku=Lo,ig=Uo,ga=function(r){let e=0;if(r=r.toString().trim(),ku(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(ig(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let s=ku(t[n]),i;s&&(i=ga(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 s=[n,1];for(n=9-t.length;n>0;n--)s.push("0");t.splice.apply(t,s)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){let s=parseInt(t[n],16);o[e++]=s>>8&255,o[e++]=s&255}return o}throw new Error("invalid ip address")},Cu=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let o=[];for(let s=0;s<t;s++)o.push(r[e+s]);return o.join(".")}if(t===16){let o=[];for(let s=0;s<t;s+=2)o.push(n.getUint16(e+s).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var Yr={},ba={},cg=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,-1,"http-path"],[777,-1,"memory"]];cg.forEach(r=>{let e=lg(...r);ba[e.code]=e,Yr[e.name]=e});function lg(r,e,t,n,o){return{code:r,size:e,name:t,resolvable:!!n,path:!!o}}function oe(r){if(typeof r=="number"){if(ba[r]!=null)return ba[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(Yr[r]!=null)return Yr[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var T8=oe("ip4"),_8=oe("ip6"),R8=oe("ipcidr");function Ea(r,e){switch(oe(r).code){case 4:case 41:return fg(e);case 42:return xa(e);case 6:case 273:case 33:case 132:return _u(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return xa(e);case 421:return mg(e);case 444:return Tu(e);case 445:return Tu(e);case 466:return pg(e);case 481:return globalThis.encodeURIComponent(xa(e));default:return z(e,"base16")}}function va(r,e){switch(oe(r).code){case 4:return Iu(e);case 41:return Iu(e);case 42:return wa(e);case 6:case 273:case 33:case 132:return Aa(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return wa(e);case 421:return hg(e);case 444:return gg(e);case 445:return bg(e);case 466:return dg(e);case 481:return wa(globalThis.decodeURIComponent(e));default:return Q(e,"base16")}}var ya=Object.values(bt).map(r=>r.decoder),ug=function(){let r=ya[0].or(ya[1]);return ya.slice(2).forEach(e=>r=r.or(e)),r}();function Iu(r){if(!Oo(r))throw new Error("invalid ip address");return ga(r)}function fg(r){let e=Cu(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!Oo(e))throw new Error("invalid ip address");return e}function Aa(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function _u(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function wa(r){let e=Q(r),t=Uint8Array.from(yt(e.length));return xe([t,e],t.length+e.length)}function xa(r){let e=rt(r);if(r=r.slice(we(e)),r.length!==e)throw new Error("inconsistent lengths");return z(r)}function hg(r){let e;r[0]==="Q"||r[0]==="1"?e=mr(ge.decode(`z${r}`)).bytes:e=tt.parse(r).multihash.bytes;let t=Uint8Array.from(yt(e.length));return xe([t,e],t.length+e.length)}function dg(r){let e=ug.decode(r),t=Uint8Array.from(yt(e.length));return xe([t,e],t.length+e.length)}function pg(r){let e=rt(r),t=r.slice(we(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+z(t,"base64url")}function mg(r){let e=rt(r),t=r.slice(we(e));if(t.length!==e)throw new Error("inconsistent lengths");return z(t,"base58btc")}function gg(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=Ct.decode("b"+e[0]),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Aa(n);return xe([t,o],t.length+o.length)}function bg(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=Ct.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Aa(n);return xe([t,o],t.length+o.length)}function Tu(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=z(e,"base32"),o=_u(t);return`${n}:${o}`}function Ru(r){r=Da(r);let e=[],t=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let s=0;s<o.length;s++){let i=o[s],a=oe(i);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(s++,s>=o.length)throw Lu("invalid address: "+r);if(a.path===!0){n=Da(o.slice(s).join("/")),e.push([a.code,va(a.code,n)]),t.push([a.code,n]);break}let c=va(a.code,o[s]);e.push([a.code,c]),t.push([a.code,Ea(a.code,c)])}return{string:Nu(t),bytes:Ba(e),tuples:e,stringTuples:t,path:n}}function Sa(r){let e=[],t=[],n=null,o=0;for(;o<r.length;){let s=rt(r,o),i=we(s),a=oe(s),c=yg(a,r.slice(o+i));if(c===0){e.push([s]),t.push([s]),o+=i;continue}let l=r.slice(o+i,o+i+c);if(o+=c+i,o>r.length)throw Lu("Invalid address Uint8Array: "+z(r,"base16"));e.push([s,l]);let u=Ea(s,l);if(t.push([s,u]),a.path===!0){n=u;break}}return{bytes:Uint8Array.from(r),string:Nu(t),tuples:e,stringTuples:t,path:n}}function Nu(r){let e=[];return r.map(t=>{let n=oe(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),Da(e.join("/"))}function Ba(r){return xe(r.map(e=>{let t=oe(e[0]),n=Uint8Array.from(yt(t.code));return e.length>1&&e[1]!=null&&(n=xe([n,e[1]])),n}))}function yg(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=rt(e instanceof Uint8Array?e:Uint8Array.from(e));return t+we(t)}}function Da(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}function Lu(r){return new Error("Error parsing address: "+r)}var wg=Symbol.for("nodejs.util.inspect.custom"),ka=Symbol.for("@multiformats/js-multiaddr/multiaddr"),xg=[oe("dns").code,oe("dns4").code,oe("dns6").code,oe("dnsaddr").code],Po=class r{bytes;#e;#t;#r;#n;[ka]=!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=Ru(e)}else if(Ou(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,o,s="",i=oe("tcp"),a=oe("udp"),c=oe("ip4"),l=oe("ip6"),u=oe("dns6"),f=oe("ip6zone");for(let[g,p]of this.stringTuples())g===f.code&&(s=`%${p??""}`),xg.includes(g)&&(t=i.name,o=443,n=`${p??""}${s}`,e=g===u.code?6:4),(g===i.code||g===a.code)&&(t=oe(g).name,o=parseInt(p??"")),(g===c.code||g===l.code)&&(t=oe(g).name,n=`${p??""}${s}`,e=g===l.code?6:4);if(e==null||t==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:e,host:n,transport:t,port:o}}protos(){return this.#t.map(([e])=>Object.assign({},oe(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>oe(e).name)}tuples(){return this.#t}stringTuples(){return this.#r}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,o))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(Ba(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,o])=>{n===Yr.p2p.code&&e.push([n,o]),n===Yr["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?z(ge.decode(`z${n}`),"base58btc"):z(tt.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(e){return Ae(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(s=>s.resolvable);if(t==null)return[this];let n=Uu.get(t.name);if(n==null)throw new L(`no available resolver for ${t.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,e)).map(s=>nt(s))}nodeAddress(){let e=this.toOptions();if(e.transport!=="tcp"&&e.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(e){let t=(e??this).protos();return!(t.length!==2||t[0].code!==4&&t[0].code!==41||t[1].code!==6&&t[1].code!==273)}[wg](){return`Multiaddr(${this.#e})`}};var Uu=new Map;function Ou(r){return!!r?.[ka]}function nt(r){return new Po(r)}var Eg=r=>r.toString().split("/").slice(1),Mn=r=>({match:e=>e.length<1?!1:r(e[0])?e.slice(1):!1,pattern:"fn"}),ee=r=>({match:e=>Mn(t=>t===r).match(e),pattern:r}),Vo=()=>({match:r=>Mn(e=>typeof e=="string").match(r),pattern:"{string}"}),Ho=()=>({match:r=>Mn(e=>!isNaN(parseInt(e))).match(r),pattern:"{number}"}),Re=()=>({match:r=>{if(r.length<2||r[0]!=="p2p"&&r[0]!=="ipfs")return!1;if(r[1].startsWith("Q")||r[1].startsWith("1"))try{ge.decode(`z${r[1]}`)}catch{return!1}else return!1;return r.slice(2)},pattern:"/p2p/{peerid}"}),Mo=()=>({match:r=>{if(r.length<2||r[0]!=="certhash")return!1;try{ji.decode(r[1])}catch{return!1}return r.slice(2)},pattern:"/certhash/{certhash}"}),Be=r=>({match:e=>{let t=r.match(e);return t===!1?e:t},pattern:`optional(${r.pattern})`}),Ze=(...r)=>({match:e=>{let t;for(let n of r){let o=n.match(e);o!==!1&&(t==null||o.length<t.length)&&(t=o)}return t??!1},pattern:`or(${r.map(e=>e.pattern).join(", ")})`}),ie=(...r)=>({match:e=>{for(let t of r){let n=t.match(e);if(n===!1)return!1;e=n}return e},pattern:`and(${r.map(e=>e.pattern).join(", ")})`});function be(...r){function e(o){let s=Eg(o);for(let i of r){let a=i.match(s);if(a===!1)return!1;s=a}return s}function t(o){return e(o)!==!1}function n(o){let s=e(o);return s===!1?!1:s.length===0}return{matches:t,exactMatch:n}}var Ia=ie(ee("dns4"),Vo()),Ta=ie(ee("dns6"),Vo()),_a=ie(ee("dnsaddr"),Vo()),Pu=ie(ee("dns"),Vo()),av=be(Ia),cv=be(Ta),lv=be(_a),uv=be(Ze(Pu,_a,Ia,Ta)),Mu=ie(ee("ip4"),Mn(Lo)),Fu=ie(ee("ip6"),Mn(Uo)),Vu=Ze(Mu,Fu),wt=Ze(Vu,Pu,Ia,Ta,_a),fv=be(wt),hv=be(Mu),dv=be(Fu),pv=be(Vu),Ra=ie(wt,ee("tcp"),Ho()),Fn=ie(wt,ee("udp"),Ho()),mv=be(Ra),gv=be(Fn),Na=ie(Fn,ee("quic")),Ko=ie(Fn,ee("quic-v1")),vg=Ze(Na,Ko),bv=be(Na),yv=be(Ko),Ca=Ze(wt,Ra,Fn,Na,Ko),Hu=Ze(ie(Ca,ee("ws"),Be(Re()))),wv=be(Hu),Ku=Ze(ie(Ca,ee("wss"),Be(Re())),ie(Ca,ee("tls"),ee("ws"),Be(Re()))),xv=be(Ku),$u=ie(Fn,ee("webrtc-direct"),Be(Mo()),Be(Mo()),Be(Re())),qu=be($u),Wu=ie(Ko,ee("webtransport"),Be(Mo()),Be(Mo()),Be(Re())),Ev=be(Wu),Fo=Ze(Hu,Ku,ie(Ra,Be(Re())),ie(vg,Be(Re())),ie(wt,Be(Re())),$u,Wu,Re()),vv=be(Fo),Ag=ie(Fo,ee("p2p-circuit"),Re()),Av=be(Ag),Dg=Ze(ie(Fo,ee("p2p-circuit"),ee("webrtc"),Be(Re())),ie(Fo,ee("webrtc"),Be(Re())),ee("webrtc")),zu=be(Dg),Sg=Ze(ie(wt,ee("tcp"),Ho(),ee("http"),Be(Re())),ie(wt,ee("http"),Be(Re()))),Dv=be(Sg),Bg=Ze(ie(wt,ee("tcp"),Ze(ie(ee("443"),ee("http")),ie(Ho(),ee("https"))),Be(Re())),ie(wt,ee("tls"),ee("http"),Be(Re())),ie(wt,ee("https"),Be(Re()))),Sv=be(Bg);var Ge;(function(r){r.ERR_ALREADY_ABORTED="ERR_ALREADY_ABORTED",r.ERR_DATA_CHANNEL="ERR_DATA_CHANNEL",r.ERR_CONNECTION_CLOSED="ERR_CONNECTION_CLOSED",r.ERR_HASH_NOT_SUPPORTED="ERR_HASH_NOT_SUPPORTED",r.ERR_INVALID_MULTIADDR="ERR_INVALID_MULTIADDR",r.ERR_INVALID_FINGERPRINT="ERR_INVALID_FINGERPRINT",r.ERR_INVALID_PARAMETERS="ERR_INVALID_PARAMETERS",r.ERR_NOT_IMPLEMENTED="ERR_NOT_IMPLEMENTED",r.ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS="ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS",r.ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS="ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS"})(Ge||(Ge={}));var Yt=class extends L{constructor(e,t){super(`WebRTC transport error: ${e}`,t??""),this.name="WebRTCTransportError"}};var La=class extends Yt{constructor(e,t){super(`[stream: ${e}] data channel error: ${t}`,Ge.ERR_DATA_CHANNEL),this.name="WebRTC/DataChannelError"}};function Va(r,e){return new La(r,e)}var Ua=class extends Yt{constructor(e){super(`There was a problem with the Multiaddr which was passed in: ${e}`,Ge.ERR_INVALID_MULTIADDR),this.name="WebRTC/InappropriateMultiaddrError"}};function $o(r){return new Ua(r)}var Oa=class extends Yt{constructor(e){super(`There was a problem with a provided argument: ${e}`,Ge.ERR_INVALID_PARAMETERS),this.name="WebRTC/InvalidArgumentError"}};function Vn(r){return new Oa(r)}var Pa=class extends Yt{constructor(e,t){super(`Invalid fingerprint "${e}" within ${t}`,Ge.ERR_INVALID_FINGERPRINT),this.name="WebRTC/InvalidFingerprintError"}};function Ha(r,e){return new Pa(r,e)}var Ma=class extends Yt{constructor(e){super(`A method (${e}) was called though it has been intentionally left unimplemented.`,Ge.ERR_NOT_IMPLEMENTED),this.name="WebRTC/UnimplementedError"}};function Gu(r){return new Ma(r)}var Fa=class extends Yt{constructor(e){super(`unsupported hash algorithm: ${e}`,Ge.ERR_HASH_NOT_SUPPORTED),this.name="WebRTC/UnsupportedHashAlgorithmError"}};function ju(r){return new Fa(r)}var Yu=function(r,e,t){if(t||arguments.length===2)for(var n=0,o=e.length,s;n<o;n++)(s||!(n in e))&&(s||(s=Array.prototype.slice.call(e,0,n)),s[n]=e[n]);return r.concat(s||Array.prototype.slice.call(e))},kg=function(){function r(e,t,n){this.name=e,this.version=t,this.os=n,this.type="browser"}return r}();var Cg=function(){function r(e){this.version=e,this.type="node",this.name="node",this.os=process.platform}return r}();var Ig=function(){function r(e,t,n,o){this.name=e,this.version=t,this.os=n,this.bot=o,this.type="bot-device"}return r}();var Tg=function(){function r(){this.type="bot",this.bot=!0,this.name="bot",this.version=null,this.os=null}return r}();var _g=function(){function r(){this.type="react-native",this.name="react-native",this.version=null,this.os=null}return r}();var Rg=/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/,Ng=/(nuhk|curl|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask\ Jeeves\/Teoma|ia_archiver)/,Zu=3,Lg=[["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",Rg]],Xu=[["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 Qu(r){return r?Ju(r):typeof document>"u"&&typeof navigator<"u"&&navigator.product==="ReactNative"?new _g:typeof navigator<"u"?Ju(navigator.userAgent):Pg()}function Ug(r){return r!==""&&Lg.reduce(function(e,t){var n=t[0],o=t[1];if(e)return e;var s=o.exec(r);return!!s&&[n,s]},!1)}function Ju(r){var e=Ug(r);if(!e)return null;var t=e[0],n=e[1];if(t==="searchbot")return new Tg;var o=n[1]&&n[1].split(".").join("_").split("_").slice(0,3);o?o.length<Zu&&(o=Yu(Yu([],o,!0),Mg(Zu-o.length),!0)):o=[];var s=o.join("."),i=Og(r),a=Ng.exec(r);return a&&a[1]?new Ig(t,s,i,a[1]):new kg(t,s,i)}function Og(r){for(var e=0,t=Xu.length;e<t;e++){var n=Xu[e],o=n[0],s=n[1],i=s.exec(r);if(i)return o}return null}function Pg(){var r=typeof process<"u"&&process.version;return r?new Cg(process.version.slice(1)):null}function Mg(r){for(var e=[],t=0;t<r;t++)e.push("0");return e}function pe(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var Zr=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Ka=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},ef=r=>globalThis.DOMException===void 0?new Ka(r):new DOMException(r),tf=r=>{let e=r.reason===void 0?ef("This operation was aborted."):r.reason;return e instanceof Error?e:ef(e)};function yr(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=e,i,c=new Promise((l,u)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:m}=e;m.aborted&&u(tf(m)),m.addEventListener("abort",()=>{u(tf(m))})}if(t===Number.POSITIVE_INFINITY){r.then(l,u);return}let f=new Zr;i=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(m){u(m)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?l():o instanceof Error?u(o):(f.message=o??`Promise timed out after ${t} milliseconds`,u(f))},t),(async()=>{try{l(await r)}catch(m){u(m)}})()}).finally(()=>{c.clear()});return c.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},c}var rf=Qu(),Hn=rf!=null&&rf.name==="firefox",qo=async function*(){},Wo=async r=>{},Fg=30*1e3;function nf(r,e,t=Fg,n){r.readyState==="open"&&Promise.resolve().then(async()=>{if(r.bufferedAmount>0){n.log("%s drain channel with %d buffered bytes",e,r.bufferedAmount);let o=pe(),s=!1;r.bufferedAmountLowThreshold=0;let i=()=>{s||(n.log("%s drain channel closed before drain",e),o.resolve())};r.addEventListener("close",i,{once:!0}),r.addEventListener("bufferedamountlow",()=>{s=!0,r.removeEventListener("close",i),o.resolve()}),await yr(o.promise,{milliseconds:t})}}).then(async()=>{r.readyState==="open"&&r.close()}).catch(o=>{n.log.error("error closing outbound stream",o)})}var wr=class{log;peerConnection;remoteAddr;timeline;metrics;source=qo();sink=Wo;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 zo=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}},Xr=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new zo(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 zo(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 Zt(r={}){return Vg(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 Vg(r,e){e=e??{};let t=e.onEnd,n=new Xr,o,s,i,a=pe(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((d,y)=>{s=x=>{s=null,n.push(x);try{d(r(n))}catch(b){y(b)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=pe()})}},l=d=>s!=null?s(d):(n.push(d),o),u=d=>(n=new Xr,s!=null?s({error:d}):(n.push({error:d}),o)),f=d=>{if(i)return o;if(e?.objectMode!==!0&&d?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:d})},m=d=>i?o:(i=!0,d!=null?u(d):l({done:!0})),g=()=>(n=new Xr,m(),{done:!0}),p=d=>(m(d),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:g,throw:p,push:f,end:m,get readableLength(){return n.size},onEmpty:async d=>{let y=d?.signal;if(y?.throwIfAborted(),n.isEmpty())return;let x,b;y!=null&&(x=new Promise((A,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 o;let h=o;return o={[Symbol.asyncIterator](){return this},next(){return h.next()},throw(d){return h.throw(d),t!=null&&(t(d),t=void 0),{done:!0}},return(){return h.return(),t!=null&&(t(),t=void 0),{done:!0}},push:f,end(d){return h.end(d),t!=null&&(t(d),t=void 0),o},get readableLength(){return h.readableLength},onEmpty:d=>h.onEmpty(d)},o}var Go=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 Go(t?.errorMessage,t?.errorCode));let n,o=new Go(t?.errorMessage,t?.errorCode);try{return await Promise.race([r,new Promise((s,i)=>{n=()=>{i(o)},e.addEventListener("abort",n)})])}finally{n!=null&&e.removeEventListener("abort",n)}}var sf=Symbol.for("@achingbrain/uint8arraylist");function of(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let o=t+n.byteLength;if(e<o)return{buf:n,index:e-t};t=o}throw new RangeError("index is out of bounds")}function jo(r){return!!r?.[sf]}var ue=class r{bufs;length;[sf]=!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(jo(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(jo(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=of(this.bufs,e);return t.buf[t.index]}set(e,t){let n=of(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(jo(e))for(let n=0;n<e.length;n++)this.set(t+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:n,length:o}=this._subList(e,t);return xe(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:xe(n,o)}sublist(e,t){let{bufs:n,length:o}=this._subList(e,t),s=new r;return s.length=o,s.bufs=[...n],s}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,e>=c)continue;let l=e>=a&&e<c,u=t>a&&t<=c;if(l&&u){if(e===a&&t===c){n.push(i);break}let f=e-a;n.push(i.subarray(f,f+(t-e)));break}if(l){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(u){if(t===c){n.push(i);break}n.push(i.subarray(0,t-a));break}n.push(i)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!jo(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let f=0;f<s;f++)i[f]=-1;for(let f=0;f<o;f++)i[n[f]]=f;let a=i,c=this.byteLength-n.byteLength,l=n.byteLength-1,u;for(let f=t;f<=c;f+=u){u=0;for(let m=l;m>=0;m--){let g=this.get(f+m);if(n[m]!==g){u=Math.max(1,m-a[g]);break}}if(u===0)return f}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let n=Se(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){let o=De(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,t,n),this.write(o,e)}getInt32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){let o=De(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,t,n),this.write(o,e)}getBigInt64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){let o=De(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,t,n),this.write(o,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let n=Se(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){let o=De(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,t,n),this.write(o,e)}getUint32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){let o=De(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,t,n),this.write(o,e)}getBigUint64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){let o=De(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,t,n),this.write(o,e)}getFloat32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){let o=De(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,t,n),this.write(o,e)}getFloat64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){let o=De(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,t,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof r)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!Ae(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((o,s)=>o+s.byteLength,0)),n.length=t,n}};function af(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 cf(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function lf(r,e){let t=af(r).return?.();cf(t)&&t.catch(n=>{e.error("could not cause iterator to return",n)})}var Hg="ERR_STREAM_RESET",Kg="ERR_SINK_INVALID_STATE",$g=5e3;function qa(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Yo=class{id;direction;timeline;protocol;metadata;source;status;readStatus;writeStatus;log;sinkController;sinkEnd;closed;endErr;streamSource;onEnd;onCloseRead;onCloseWrite;onReset;onAbort;sendCloseWriteTimeout;sendingData;constructor(e){this.sinkController=new AbortController,this.sinkEnd=pe(),this.closed=pe(),this.log=e.log,this.status="open",this.readStatus="ready",this.writeStatus="ready",this.id=e.id,this.metadata=e.metadata??{},this.direction=e.direction,this.timeline={open:Date.now()},this.sendCloseWriteTimeout=e.sendCloseWriteTimeout??$g,this.onEnd=e.onEnd,this.onCloseRead=e?.onCloseRead,this.onCloseWrite=e?.onCloseWrite,this.onReset=e?.onReset,this.onAbort=e?.onAbort,this.source=this.streamSource=Zt({onEnd:t=>{t!=null?this.log.trace("source ended with error",t):this.log.trace("source ended"),this.onSourceEnd(t)}}),this.sink=this.sink.bind(this)}async sink(e){if(this.writeStatus!=="ready")throw new L(`writable end state is "${this.writeStatus}" not "ready"`,Kg);try{this.writeStatus="writing";let t={signal:this.sinkController.signal};if(this.direction==="outbound"){let o=this.sendNewStream(t);qa(o)&&await o}let n=()=>{lf(e,this.log)};try{this.sinkController.signal.addEventListener("abort",n),this.log.trace("sink reading from source");for await(let o of e){o=o instanceof Uint8Array?new ue(o):o;let s=this.sendData(o,t);qa(s)&&(this.sendingData=pe(),await s,this.sendingData.resolve(),this.sendingData=void 0)}}finally{this.sinkController.signal.removeEventListener("abort",n)}this.log.trace('sink finished reading from source, write status is "%s"',this.writeStatus),this.writeStatus==="writing"&&(this.writeStatus="closing",this.log.trace("send close write to remote"),await this.sendCloseWrite({signal:AbortSignal.timeout(this.sendCloseWriteTimeout)}),this.writeStatus="closed"),this.onSinkEnd()}catch(t){throw this.log.trace("sink ended with error, calling abort with error",t),this.abort(t),t}finally{this.log.trace("resolve sink end"),this.sinkEnd.resolve()}}onSourceEnd(e){this.timeline.closeRead==null&&(this.timeline.closeRead=Date.now(),this.readStatus="closed",e!=null&&this.endErr==null&&(this.endErr=e),this.onCloseRead?.(),this.timeline.closeWrite!=null?(this.log.trace("source and sink ended"),this.timeline.close=Date.now(),this.status!=="aborted"&&this.status!=="reset"&&(this.status="closed"),this.onEnd!=null&&this.onEnd(this.endErr),this.closed.resolve()):this.log.trace("source ended, waiting for sink to end"))}onSinkEnd(e){this.timeline.closeWrite==null&&(this.timeline.closeWrite=Date.now(),this.writeStatus="closed",e!=null&&this.endErr==null&&(this.endErr=e),this.onCloseWrite?.(),this.timeline.closeRead!=null?(this.log.trace("sink and source ended"),this.timeline.close=Date.now(),this.status!=="aborted"&&this.status!=="reset"&&(this.status="closed"),this.onEnd!=null&&this.onEnd(this.endErr),this.closed.resolve()):this.log.trace("sink ended, waiting for source to end"))}async close(e){this.log.trace("closing gracefully"),this.status="closing",await 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 L("stream reset",Hg);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 Zo(r){return r[Symbol.asyncIterator]!=null}var Xo=r=>{let e=we(r),t=Se(e);return yt(r,t),Xo.bytes=e,t};Xo.bytes=0;function Kn(r,e){e=e??{};let t=e.lengthEncoder??Xo;function*n(o){let s=t(o.byteLength);s instanceof Uint8Array?yield s:yield*s,o instanceof Uint8Array?yield o:yield*o}return Zo(r)?async function*(){for await(let o of r)yield*n(o)}():function*(){for(let o of r)yield*n(o)}()}Kn.single=(r,e)=>{e=e??{};let t=e.lengthEncoder??Xo;return new ue(t(r.byteLength),r)};var Jr=So(hf(),1);var Wg=8,zg=1024*1024*4,xr;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(xr||(xr={}));var Wa=r=>{let e=rt(r);return Wa.bytes=we(e),e};Wa.bytes=0;function Er(r,e){let t=new ue,n=xr.LENGTH,o=-1,s=e?.lengthDecoder??Wa,i=e?.maxLengthLength??Wg,a=e?.maxDataLength??zg;function*c(){for(;t.byteLength>0;){if(n===xr.LENGTH)try{if(o=s(t),o<0)throw(0,Jr.default)(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(o>a)throw(0,Jr.default)(new Error("message length too long"),"ERR_MSG_DATA_TOO_LONG");let l=s.bytes;t.consume(l),e?.onLength!=null&&e.onLength(o),n=xr.DATA}catch(l){if(l instanceof RangeError){if(t.byteLength>i)throw(0,Jr.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw l}if(n===xr.DATA){if(t.byteLength<o)break;let l=t.sublist(0,o);t.consume(o),e?.onData!=null&&e.onData(l),yield l,n=xr.LENGTH}}}return Zo(r)?async function*(){for await(let l of r)t.append(l),yield*c();if(t.byteLength>0)throw(0,Jr.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}():function*(){for(let l of r)t.append(l),yield*c();if(t.byteLength>0)throw(0,Jr.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}()}Er.fromReader=(r,e)=>{let t=1,n=async function*(){for(;;)try{let{done:s,value:i}=await r.next(t);if(s===!0)return;i!=null&&(yield i)}catch(s){if(s.code==="ERR_UNDER_READ")return{done:!0,value:null};throw s}finally{t=1}}();return Er(n,{...e??{},onLength:s=>{t=s}})};var jg=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 Yg(r,e,t){let n,o=new Promise((s,i)=>{if(t={rejectionEvents:["error"],multiArgs:!1,resolveImmediately:!1,...t},!(t.count>=0&&(t.count===Number.POSITIVE_INFINITY||Number.isInteger(t.count))))throw new TypeError("The `count` option should be at least 0 or more");t.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:l,removeListener:u}=jg(r),f=(...g)=>{let p=t.multiArgs?g:g[0];t.filter&&!t.filter(p)||(c.push(p),t.count===c.length&&(n(),s(c)))},m=g=>{n(),i(g)};n=()=>{for(let g of a)u(g,f);for(let g of t.rejectionEvents)u(g,m)};for(let g of a)l(g,f);for(let g of t.rejectionEvents)l(g,m);t.signal&&t.signal.addEventListener("abort",()=>{m(t.signal.reason)},{once:!0}),t.resolveImmediately&&s(c)});if(o.cancel=n,typeof t.timeout=="number"){let s=yr(o,{milliseconds:t.timeout});return s.cancel=n,s}return o}function za(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=Yg(r,e,t),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}var Ga=new Float32Array([-0]),Xt=new Uint8Array(Ga.buffer);function df(r,e,t){Ga[0]=r,e[t]=Xt[0],e[t+1]=Xt[1],e[t+2]=Xt[2],e[t+3]=Xt[3]}function pf(r,e){return Xt[0]=r[e],Xt[1]=r[e+1],Xt[2]=r[e+2],Xt[3]=r[e+3],Ga[0]}var ja=new Float64Array([-0]),Me=new Uint8Array(ja.buffer);function mf(r,e,t){ja[0]=r,e[t]=Me[0],e[t+1]=Me[1],e[t+2]=Me[2],e[t+3]=Me[3],e[t+4]=Me[4],e[t+5]=Me[5],e[t+6]=Me[6],e[t+7]=Me[7]}function gf(r,e){return Me[0]=r[e],Me[1]=r[e+1],Me[2]=r[e+2],Me[3]=r[e+3],Me[4]=r[e+4],Me[5]=r[e+5],Me[6]=r[e+6],Me[7]=r[e+7],ja[0]}var Zg=BigInt(Number.MAX_SAFE_INTEGER),Xg=BigInt(Number.MIN_SAFE_INTEGER),je=class r{lo;hi;constructor(e,t){this.lo=e|0,this.hi=t|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(t+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(BigInt(t)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?t===0?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return vr;if(e<Zg&&e>Xg)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let n=e>>32n,o=e-(n<<32n);return t&&(n=~n|0n,o=~o|0n,++o>bf&&(o=0n,++n>bf&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return vr;let t=e<0;t&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return t&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(e){return typeof e=="number"?r.fromNumber(e):typeof e=="bigint"?r.fromBigInt(e):typeof e=="string"?r.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new r(e.low>>>0,e.high>>>0):vr}},vr=new je(0,0);vr.toBigInt=function(){return 0n};vr.zzEncode=vr.zzDecode=function(){return this};vr.length=function(){return 1};var bf=4294967296n;function yf(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 wf(r,e,t){if(t-e<1)return"";let o,s=[],i=0,a;for(;e<t;)a=r[e++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|r[e++]&63:a>239&&a<365?(a=((a&7)<<18|(r[e++]&63)<<12|(r[e++]&63)<<6|r[e++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Ya(r,e,t){let n=t,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,e[t++]=o>>18|240,e[t++]=o>>12&63|128,e[t++]=o>>6&63|128,e[t++]=o&63|128):(e[t++]=o>>12|224,e[t++]=o>>6&63|128,e[t++]=o&63|128);return t-n}function ot(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function Jo(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,ot(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 ot(this,4);return Jo(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw ot(this,4);return Jo(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw ot(this,4);let e=pf(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw ot(this,4);let e=gf(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 ot(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return wf(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw ot(this,e);this.pos+=e}else do if(this.pos>=this.len)throw ot(this);while(this.buf[this.pos++]&128);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new je(0,0),t=0;if(this.len-this.pos>4){for(;t<4;++t)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;t=0}else{for(;t<3;++t){if(this.pos>=this.len)throw ot(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 ot(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 ot(this,8);let e=Jo(this.buf,this.pos+=4),t=Jo(this.buf,this.pos+=4);return new je(e,t)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=da(this.buf,this.pos);return this.pos+=we(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Xa(r){return new Za(r instanceof Uint8Array?r:r.subarray())}function st(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,o=e;return function(i){if(i<1||i>t)return Se(i);o+i>e&&(n=Se(e),o=0);let a=n.subarray(o,o+=i);return o&7&&(o=(o|7)+1),a}}var Ar=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}},Jg=Ja();function Qg(r){return globalThis.Buffer!=null?Se(r):Jg(r)}var qn=class{len;head;tail;states;constructor(){this.len=0,this.head=new Ar(Qa,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new Ar(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(Qo,10,je.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=je.fromBigInt(e);return this._push(Qo,t.length(),t)}uint64Number(e){return this._push(ha,we(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let t=je.fromBigInt(e).zzEncode();return this._push(Qo,t.length(),t)}sint64Number(e){let t=je.fromNumber(e).zzEncode();return this._push(Qo,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($n,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=je.fromBigInt(e);return this._push($n,4,t.lo)._push($n,4,t.hi)}fixed64Number(e){let t=je.fromNumber(e);return this._push($n,4,t.lo)._push($n,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(df,4,e)}double(e){return this._push(mf,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(ec,1,0):this.uint32(t)._push(tb,t,e)}string(e){let t=yf(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 Ar(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 Ar(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=Qg(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 eb(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var rc=class extends Ar{next;constructor(e,t){super(eb,e,t),this.next=void 0}};function Qo(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 $n(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 tb(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(qn.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(rb,e,r),this},qn.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(nb,e,r),this});function rb(r,e,t){e.set(r,t)}function nb(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 qn}function it(r,e){let t=nc();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var Qr;(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"})(Qr||(Qr={}));function es(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function Dr(r){function e(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let t=function(s,i){let a=e(s);i.int32(a)},n=function(s){let i=s.int32();return e(i)};return es("enum",Qr.VARINT,t,n)}function at(r,e){return es("message",Qr.LENGTH_DELIMITED,r,e)}var $e;(function(r){let e;(function(o){o.FIN="FIN",o.STOP_SENDING="STOP_SENDING",o.RESET="RESET",o.FIN_ACK="FIN_ACK"})(e=r.Flag||(r.Flag={}));let t;(function(o){o[o.FIN=0]="FIN",o[o.STOP_SENDING=1]="STOP_SENDING",o[o.RESET=2]="RESET",o[o.FIN_ACK=3]="FIN_ACK"})(t||(t={})),function(o){o.codec=()=>Dr(t)}(e=r.Flag||(r.Flag={}));let n;r.codec=()=>(n==null&&(n=at((o,s,i={})=>{i.lengthDelimited!==!1&&s.fork(),o.flag!=null&&(s.uint32(8),r.Flag.codec().encode(o.flag,s)),o.message!=null&&(s.uint32(18),s.bytes(o.message)),i.lengthDelimited!==!1&&s.ldelim()},(o,s)=>{let i={},a=s==null?o.len:o.pos+s;for(;o.pos<a;){let c=o.uint32();switch(c>>>3){case 1:i.flag=r.Flag.codec().decode(o);break;case 2:i.message=o.bytes();break;default:o.skipType(c&7);break}}return i})),n),r.encode=o=>it(o,r.codec()),r.decode=o=>st(o,r.codec())})($e||($e={}));var ob=16*1024*1024,sb=30*1e3,ib=5,ab=2,cb=16*1024,lb=5e3,ub=5e3,oc=class extends Yo{channel;incomingData;maxBufferedAmount;bufferedAmountLowEventTimeout;maxMessageSize;receiveFinAck;finAckTimeout;openTimeout;constructor(e){let t=e.onEnd;switch(e.onEnd=o=>{this.log.trace("readable and writeable ends closed",this.status),Promise.resolve(async()=>{if(!(this.timeline.abort!=null||this.timeline.reset!==null))try{await yr(this.receiveFinAck.promise,{milliseconds:this.finAckTimeout})}catch(s){this.log.error("error receiving FIN_ACK",s)}}).then(()=>{this.incomingData.end(),t?.(o)}).catch(s=>{this.log.error("error ending stream",s)})},super(e),this.channel=e.channel,this.channel.binaryType="arraybuffer",this.incomingData=Zt(),this.bufferedAmountLowEventTimeout=e.bufferedAmountLowEventTimeout??sb,this.maxBufferedAmount=e.maxBufferedAmount??ob,this.maxMessageSize=(e.maxMessageSize??cb)-ib-ab,this.receiveFinAck=pe(),this.finAckTimeout=e.closeTimeout??lb,this.openTimeout=e.openTimeout??ub,this.channel.readyState){case"open":this.timeline.open=new Date().getTime();break;case"closed":case"closing":(this.timeline.close===void 0||this.timeline.close===0)&&(this.timeline.close=Date.now());break;case"connecting":break;default:throw this.log.error("unknown datachannel state %s",this.channel.readyState),new L("Unknown datachannel state","ERR_INVALID_STATE")}this.channel.onopen=o=>{this.timeline.open=new Date().getTime()},this.channel.onclose=o=>{this.receiveFinAck.resolve(),this.close().catch(s=>{this.log.error("error closing stream after channel closed",s)})},this.channel.onerror=o=>{let s=o.error;this.abort(s)},this.channel.onmessage=async o=>{let{data:s}=o;s===null||s.byteLength===0||this.incomingData.push(new Uint8Array(s,0,s.byteLength))};let n=this;Promise.resolve().then(async()=>{for await(let o of Er(this.incomingData)){let s=n.processIncomingProtobuf(o);s!=null&&n.sourcePush(new ue(s))}}).catch(o=>{this.log.error("error processing incoming data channel messages",o)})}sendNewStream(){}async _sendMessage(e,t=!0){if(t&&this.channel.bufferedAmount>this.maxBufferedAmount)try{this.log('channel buffer is %d, wait for "bufferedamountlow" event',this.channel.bufferedAmount),await za(this.channel,"bufferedamountlow",{timeout:this.bufferedAmountLowEventTimeout})}catch(n){throw n instanceof Zr?new L(`Timed out waiting for DataChannel buffer to clear after ${this.bufferedAmountLowEventTimeout}ms`,"ERR_BUFFER_CLEAR_TIMEOUT"):n}if(this.channel.readyState==="closed"||this.channel.readyState==="closing")throw new L(`Invalid datachannel state - ${this.channel.readyState}`,"ERR_INVALID_STATE");this.channel.readyState!=="open"&&(this.log('channel state is "%s" and not "open", waiting for "open" event before sending data',this.channel.readyState),await 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),o=$e.encode({message:n}),s=Kn.single(o);await this._sendMessage(s),e.consume(t)}}async sendReset(){await this._sendFlag($e.Flag.RESET)}async sendCloseWrite(e){if(await this._sendFlag($e.Flag.FIN)){this.log.trace("awaiting FIN_ACK");try{await 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($e.Flag.STOP_SENDING)}processIncomingProtobuf(e){let t=$e.decode(e);if(t.flag!==void 0&&(this.log.trace('incoming flag %s, write status "%s", read status "%s"',t.flag,this.writeStatus,this.readStatus),t.flag===$e.Flag.FIN&&(this.remoteCloseWrite(),this.log.trace("sending FIN_ACK"),this._sendFlag($e.Flag.FIN_ACK).catch(n=>{this.log.error("error sending FIN_ACK immediately",n)})),t.flag===$e.Flag.RESET&&this.reset(),t.flag===$e.Flag.STOP_SENDING&&this.remoteCloseRead(),t.flag===$e.Flag.FIN_ACK&&(this.log.trace("received FIN_ACK"),this.receiveFinAck.resolve())),this.readStatus==="ready")return t.message}async _sendFlag(e){if(this.channel.readyState!=="open")return this.log.trace('not sending flag %s because channel is "%s" and not "open"',this.channel.readyState,e.toString()),!1;this.log.trace("sending flag %s",e.toString());let t=$e.encode({flag:e}),n=Kn.single(t);try{return await this._sendMessage(n,!1),!0}catch(o){this.log.error("could not send flag %s",e.toString(),o)}return!1}};function en(r){let{channel:e,direction:t}=r;return new oc({id:t==="inbound"?`i${e.id}`:`r${e.id}`,log:r.logger.forComponent(`libp2p:webrtc:stream:${t}:${e.id}`),...r})}var Ef="/webrtc",Jt=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??Ef,this.dataChannelOptions=t.dataChannelOptions??{},this.log=e.logger.forComponent("libp2p:webrtc:datachannelmuxerfactory"),this.peerConnection.ondatachannel=({channel:n})=>{if(this.log.trace('incoming early datachannel with channel id %d and label "%s"',n.id),n.label==="init"){this.log.trace("closing early init channel"),n.close();return}let o={},s=en({channel:n,direction:"inbound",onEnd:i=>{o.onEnd(i)},logger:e.logger,...this.dataChannelOptions});o.stream=s,o.channel=n,o.onEnd=()=>{this.bufferedStreams=this.bufferedStreams.filter(i=>i.stream.id!==s.id)},this.bufferedStreams.push(o)}}createStreamMuxer(e){return new sc(this.components,{...e,peerConnection:this.peerConnection,dataChannelOptions:this.dataChannelOptions,metrics:this.metrics,streams:this.bufferedStreams,protocol:this.protocol})}},sc=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??Ef,this.metrics=t.metrics,this.dataChannelOptions=t.dataChannelOptions??{},this.peerConnection.ondatachannel=({channel:n})=>{if(this.log.trace("incoming datachannel with channel id %d",n.id),n.label==="init"){this.log.trace("closing init channel"),n.close();return}let o=en({channel:n,direction:"inbound",onEnd:()=>{this.log("incoming channel %s ended with state %s",n.id,n.readyState),this.#e(o,n)},logger:this.logger,...this.dataChannelOptions});this.streams.push(o),this.metrics?.increment({incoming_stream:!0}),t?.onIncomingStream?.(o)},this.init.streams.length>0&&queueMicrotask(()=>{this.init.streams.forEach(n=>{n.onEnd=()=>{this.log("incoming early channel %s ended with state %s",n.channel.id,n.channel.readyState),this.#e(n.stream,n.channel)},this.metrics?.increment({incoming_stream:!0}),this.init?.onIncomingStream?.(n.stream)})})}#e(e,t){this.log.trace("stream %s %s %s onEnd",e.direction,e.id,e.protocol),nf(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=qo();sink=Wo;newStream(){let e=this.peerConnection.createDataChannel("");this.log.trace("opened outgoing datachannel with channel id %s",e.id);let t=en({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 Sr=globalThis.RTCPeerConnection,ts=globalThis.RTCSessionDescription,vf=globalThis.RTCIceCandidate;var ic=class{readNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.readNext=pe(),this.haveNext=pe()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let e=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=pe(),e}async throw(e){return this.ended=!0,e!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(e)),{done:!0,value:void 0}}async return(){let e={done:!0,value:void 0};return await this._push(void 0),e}async push(e,t){await this._push(e,t)}async end(e,t){e!=null?await this.throw(e):await this._push(void 0,t)}async _push(e,t){if(e!=null&&this.ended)throw new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;e!=null?this.nextResult={done:!1,value:e}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=pe(),await It(this.readNext.promise,t?.signal,t)}};function Af(){return new ic}var rs=class extends Error{code;constructor(e,t){super(e),this.code=t}},ac=class extends rs{type;constructor(e){super(e,"ABORT_ERR"),this.type="aborted"}};function Df(r,e){let t=Af();r.sink(t).catch(async i=>{await t.end(i)}),r.sink=async i=>{for await(let a of i)await t.push(a);await t.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let o=new ue;return{read:async(i,a)=>{a?.signal?.throwIfAborted();let c,l=new Promise((u,f)=>{c=()=>{f(new ac("Read aborted"))},a?.signal?.addEventListener("abort",c)});try{if(i==null){let{done:f,value:m}=await Promise.race([n.next(),l]);return f===!0?new ue:m}for(;o.byteLength<i;){let{value:f,done:m}=await Promise.race([n.next(),l]);if(m===!0)throw new rs("unexpected end of input","ERR_UNEXPECTED_EOF");o.append(f)}let u=o.sublist(0,i);return o.consume(i),u}finally{c!=null&&a?.signal?.removeEventListener("abort",c)}},write:async(i,a)=>{a?.signal?.throwIfAborted(),i instanceof Uint8Array?await t.push(i,a):await t.push(i.subarray(),a)},unwrap:()=>{if(o.byteLength>0){let i=r.source;r.source=async function*(){e?.yieldBytes===!1?yield o:yield*o,yield*i}()}return r}}}var ns=class extends Error{code;constructor(e,t){super(e),this.code=t}};function Wn(r,e={}){let t=Df(r,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=we(e.maxDataLength));let n=e?.lengthDecoder??rt,o=e?.lengthEncoder??yt;return{read:async i=>{let a=-1,c=new ue;for(;;){c.append(await t.read(1,i));try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new ns("message length length too long","ERR_MSG_LENGTH_TOO_LONG");if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new ns("message length too long","ERR_MSG_DATA_TOO_LONG");return t.read(a,i)},write:async(i,a)=>{await t.write(new ue(o(i.byteLength),i),a)},writeV:async(i,a)=>{let c=new ue(...i.flatMap(l=>[o(l.byteLength),l]));await t.write(c,a)},unwrap:()=>t.unwrap()}}function os(r,e){let t=Wn(r,e),n={read:async(o,s)=>{let i=await t.read(s);return o.decode(i)},write:async(o,s,i)=>{await t.write(s.encode(o),i)},writeV:async(o,s,i)=>{await t.writeV(o.map(a=>s.encode(a)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>t.unwrap()};return n}var qe;(function(r){let e;(function(o){o.SDP_OFFER="SDP_OFFER",o.SDP_ANSWER="SDP_ANSWER",o.ICE_CANDIDATE="ICE_CANDIDATE"})(e=r.Type||(r.Type={}));let t;(function(o){o[o.SDP_OFFER=0]="SDP_OFFER",o[o.SDP_ANSWER=1]="SDP_ANSWER",o[o.ICE_CANDIDATE=2]="ICE_CANDIDATE"})(t||(t={})),function(o){o.codec=()=>Dr(t)}(e=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=at((o,s,i={})=>{i.lengthDelimited!==!1&&s.fork(),o.type!=null&&(s.uint32(8),r.Type.codec().encode(o.type,s)),o.data!=null&&(s.uint32(18),s.string(o.data)),i.lengthDelimited!==!1&&s.ldelim()},(o,s)=>{let i={},a=s==null?o.len:o.pos+s;for(;o.pos<a;){let c=o.uint32();switch(c>>>3){case 1:i.type=r.Type.codec().decode(o);break;case 2:i.data=o.string();break;default:o.skipType(c&7);break}}return i})),n),r.encode=o=>it(o,r.codec()),r.decode=o=>st(o,r.codec())})(qe||(qe={}));var ss=async(r,e,t)=>{try{let n=pe();for(hb(r,n);;){let o=await Promise.race([n.promise,e.read({signal:t.signal}).catch(()=>{})]);if(o==null){t.signal?.throwIfAborted();break}if(o.type!==qe.Type.ICE_CANDIDATE)throw new L("ICE candidate message expected","ERR_NOT_ICE_CANDIDATE");let s=JSON.parse(o.data??"null");if(s===""||s===null){t.log.trace("end-of-candidates received");continue}let i=new vf(s);t.log.trace("%s received new ICE candidate %o",t.direction,s);try{await r.addIceCandidate(i)}catch(a){t.log.error("%s bad candidate received",t.direction,s,a)}}}catch(n){if(t.log.error("%s error parsing ICE candidate",t.direction,n),t.signal?.aborted===!0)throw n}};function fb(r){return Hn?r.iceConnectionState:r.connectionState}function hb(r,e){r[Hn?"oniceconnectionstatechange":"onconnectionstatechange"]=t=>{switch(fb(r)){case"connected":e.resolve();break;case"failed":case"disconnected":case"closed":e.reject(new L("RTCPeerConnection was closed","ERR_CONNECTION_CLOSED_BEFORE_CONNECTED"));break;default:break}}}async function Sf({rtcConfiguration:r,dataChannel:e,signal:t,metrics:n,multiaddr:o,connectionManager:s,transportManager:i,log:a,logger:c}){let{baseAddr:l}=Bf(o);n?.dialerEvents.increment({open:!0}),a.trace("dialing base address: %a",l);let u=l.getPeerId();if(u==null)throw new L("Relay peer was missing","ERR_INVALID_ADDRESS");let f=s.getConnections(br(u)),m,g=!1;f.length===0?(m=await i.dial(l,{signal:t}),g=!0):m=f[0];try{let p=await m.newStream(is,{signal:t,runOnTransientConnection:!0}),h=os(p).pb(qe),d=new Sr(r),y=new Jt({logger:c},{peerConnection:d,dataChannelOptions:e});try{let x=d.createDataChannel("init");d.onicecandidate=({candidate:v})=>{let S=JSON.stringify(v?.toJSON()??null);a.trace("initiator sending ICE candidate %o",v),h.write({type:qe.Type.ICE_CANDIDATE,data:S},{signal:t}).catch(D=>{a.error("error sending ICE candidate",D)})},d.onicecandidateerror=v=>{a.error("initiator ICE candidate error",v)};let b=await d.createOffer().catch(v=>{throw a.error("could not execute createOffer",v),new L("Failed to set createOffer","ERR_SDP_HANDSHAKE_FAILED")});a.trace("initiator send SDP offer %s",b.sdp),await h.write({type:qe.Type.SDP_OFFER,data:b.sdp},{signal:t}),await d.setLocalDescription(b).catch(v=>{throw a.error("could not execute setLocalDescription",v),new L("Failed to set localDescription","ERR_SDP_HANDSHAKE_FAILED")});let A=await h.read({signal:t});if(A.type!==qe.Type.SDP_ANSWER)throw new L("Remote should send an SDP answer","ERR_SDP_HANDSHAKE_FAILED");a.trace("initiator receive SDP answer %s",A.data);let E=new ts({type:"answer",sdp:A.data});return await d.setRemoteDescription(E).catch(v=>{throw a.error("could not execute setRemoteDescription",v),new L("Failed to set remoteDescription","ERR_SDP_HANDSHAKE_FAILED")}),a.trace("initiator read candidates until connected"),await ss(d,h,{direction:"initiator",signal:t,log:a}),a.trace("initiator connected, closing init channel"),x.close(),a.trace("closing signalling channel"),await p.close({signal:t}),a.trace("initiator connected to remote address %s",o),{remoteAddress:o,peerConnection:d,muxerFactory:y}}catch(x){throw a.error("outgoing signalling error",x),d.close(),p.abort(x),x}finally{d.onicecandidate=null,d.onicecandidateerror=null}}finally{if(g)try{await m.close({signal:t})}catch(p){m.abort(p)}}}var db=U("dns4"),pb=U("dns6"),mb=U("dnsaddr"),Br=ye(U("dns"),mb,db,pb),ls=ye(U("ip4"),U("ip6")),tn=ye(K(ls,U("tcp")),K(Br,U("tcp"))),us=K(ls,U("udp")),gb=K(us,U("utp")),bb=K(us,U("quic")),yb=K(us,U("quic-v1")),cc=ye(K(tn,U("ws")),K(Br,U("ws"))),as=ye(K(cc,U("p2p")),cc),lc=ye(K(tn,U("wss")),K(Br,U("wss")),K(tn,U("tls"),U("ws")),K(Br,U("tls"),U("ws"))),cs=ye(K(lc,U("p2p")),lc),uc=ye(K(tn,U("http")),K(ls,U("http")),K(Br,U("http"))),fc=ye(K(tn,U("https")),K(ls,U("https")),K(Br,U("https"))),kf=K(us,U("webrtc-direct"),U("certhash")),Tf=ye(K(kf,U("p2p")),kf),Cf=K(yb,U("webtransport"),U("certhash"),U("certhash")),_f=ye(K(Cf,U("p2p")),Cf),Rf=ye(K(as,U("p2p-webrtc-star"),U("p2p")),K(cs,U("p2p-webrtc-star"),U("p2p")),K(as,U("p2p-webrtc-star")),K(cs,U("p2p-webrtc-star"))),KA=ye(K(as,U("p2p-websocket-star"),U("p2p")),K(cs,U("p2p-websocket-star"),U("p2p")),K(as,U("p2p-websocket-star")),K(cs,U("p2p-websocket-star"))),Nf=ye(K(uc,U("p2p-webrtc-direct"),U("p2p")),K(fc,U("p2p-webrtc-direct"),U("p2p")),K(uc,U("p2p-webrtc-direct")),K(fc,U("p2p-webrtc-direct"))),kr=ye(cc,lc,uc,fc,Rf,Nf,tn,gb,bb,Br,Tf,_f),$A=ye(K(kr,U("p2p-stardust"),U("p2p")),K(kr,U("p2p-stardust"))),Qt=ye(K(kr,U("p2p")),Rf,Nf,Tf,_f,U("p2p")),If=ye(K(Qt,U("p2p-circuit"),Qt),K(Qt,U("p2p-circuit")),K(U("p2p-circuit"),Qt),K(kr,U("p2p-circuit")),K(U("p2p-circuit"),kr),U("p2p-circuit")),Lf=()=>ye(K(If,Lf),If),Tt=Lf(),qA=ye(K(Tt,Qt,Tt),K(Qt,Tt),K(Tt,Qt),Tt,Qt);var WA=ye(K(Tt,U("webrtc"),U("p2p")),K(Tt,U("webrtc")),K(kr,U("webrtc"),U("p2p")),K(kr,U("webrtc")),U("webrtc"));function Uf(r){function e(t){let n;try{n=nt(t)}catch{return!1}let o=r(n.protoNames());return o===null?!1:o===!0||o===!1?o:o.length===0}return e}function K(...r){function e(t){if(t.length<r.length)return null;let n=t;return r.some(o=>(n=typeof o=="function"?o().partialMatch(t):o.partialMatch(t),Array.isArray(n)&&(t=n),n===null)),n}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:Uf(e),partialMatch:e}}function ye(...r){function e(n){let o=null;return r.some(s=>{let i=typeof s=="function"?s().partialMatch(n):s.partialMatch(n);return i!=null?(o=i,!0):!1}),o}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:Uf(e),partialMatch:e}}function U(r){let e=r;function t(o){let s;try{s=nt(o)}catch{return!1}let i=s.protoNames();return i.length===1&&i[0]===e}function n(o){return o.length===0?null:o[0]===e?o.slice(1):null}return{toString:function(){return e},matches:t,partialMatch:n}}var fs=class extends Io{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 Of({peerConnection:r,stream:e,signal:t,connection:n,log:o}){o.trace("new inbound signaling stream");let s=os(e).pb(qe);try{r.onicecandidate=({candidate:u})=>{let f=JSON.stringify(u?.toJSON()??null);o.trace("recipient sending ICE candidate %s",f),s.write({type:qe.Type.ICE_CANDIDATE,data:f},{signal:t}).catch(m=>{o.error("error sending ICE candidate",m)})};let a=await s.read({signal:t});if(a.type!==qe.Type.SDP_OFFER)throw new L(`expected message type SDP_OFFER, received: ${a.type??"undefined"} `,"ERR_SDP_HANDSHAKE_FAILED");o.trace("recipient receive SDP offer %s",a.data);let c=new ts({type:"offer",sdp:a.data});await r.setRemoteDescription(c).catch(u=>{throw o.error("could not execute setRemoteDescription",u),new L("Failed to set remoteDescription","ERR_SDP_HANDSHAKE_FAILED")});let l=await r.createAnswer().catch(u=>{throw o.error("could not execute createAnswer",u),new L("Failed to create answer","ERR_SDP_HANDSHAKE_FAILED")});o.trace("recipient send SDP answer %s",l.sdp),await s.write({type:qe.Type.SDP_ANSWER,data:l.sdp},{signal:t}),await r.setLocalDescription(l).catch(u=>{throw o.error("could not execute setLocalDescription",u),new L("Failed to set localDescription","ERR_SDP_HANDSHAKE_FAILED")}),o.trace("recipient read candidates until connected"),await ss(r,s,{direction:"recipient",signal:t,log:o})}catch(a){if(r.connectionState!=="connected")throw o.error("error while handling signaling stream from peer %a",n.remoteAddr,a),r.close(),a;o("error while handling signaling stream from peer %a, ignoring as the RTCPeerConnection is already connected",n.remoteAddr,a)}let i=nt(`/webrtc/p2p/${n.remoteAddr.getPeerId()}`);return o.trace("recipient connected to remote address %s",i),{remoteAddress:i}}var wb="/webrtc",xb="/p2p-circuit",is="/webrtc-signaling/0.0.1",Eb=30*1e3,hs=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,Co(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"})})}[ko]=!0;[Symbol.toStringTag]="@libp2p/webrtc";[Vr]=["@libp2p/transport"];[tu]=["@libp2p/identify","@libp2p/circuit-relay-v2-transport"];isStarted(){return this._started}async start(){await this.components.registrar.handle(is,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(is),this._started=!1}createListener(e){return new fs(this.components,{shutdownController:this.shutdownController})}listenFilter(e){return e.filter(zu.exactMatch)}dialFilter(e){return this.listenFilter(e)}async dial(e,t){this.log.trace("dialing address: %a",e);let{remoteAddress:n,peerConnection:o,muxerFactory:s}=await Sf({rtcConfiguration:typeof this.init.rtcConfiguration=="function"?await this.init.rtcConfiguration():this.init.rtcConfiguration,dataChannel:this.init.dataChannel,multiaddr:e,dataChannelOptions:this.init.dataChannel,signal:t.signal,connectionManager:this.components.connectionManager,transportManager:this.components.transportManager,log:this.log,logger:this.components.logger}),i=new wr(this.components,{peerConnection:o,timeline:{open:Date.now()},remoteAddr:n,metrics:this.metrics?.dialerEvents}),a=await t.upgrader.upgradeOutbound(i,{skipProtection:!0,skipEncryption:!0,muxerFactory:s});return this._closeOnShutdown(o,i),a}async _onProtocol({connection:e,stream:t}){let n=AbortSignal.timeout(this.init.inboundConnectionTimeout??Eb),o=new Sr(typeof this.init.rtcConfiguration=="function"?await this.init.rtcConfiguration():this.init.rtcConfiguration),s=new Jt(this.components,{peerConnection:o,dataChannelOptions:this.init.dataChannel});try{let{remoteAddress:i}=await Of({peerConnection:o,connection:e,stream:t,signal:n,log:this.log});await t.close({signal:n});let a=new wr(this.components,{peerConnection:o,timeline:{open:new Date().getTime()},remoteAddr:i,metrics:this.metrics?.listenerEvents});await this.components.upgrader.upgradeInbound(a,{skipEncryption:!0,skipProtection:!0,muxerFactory:s}),this._closeOnShutdown(o,a)}catch(i){throw this.log.error("incoming signalling error",i),o.close(),t.abort(i),i}}_closeOnShutdown(e,t){let n=()=>{t.close().catch(o=>{this.log.error("could not close WebRTCMultiaddrConnection",o)})};this.shutdownController.signal.addEventListener("abort",n),e.addEventListener("close",()=>{this.shutdownController.signal.removeEventListener("abort",n)})}};function Bf(r){let e=r.toString().split(wb+"/");if(e.length!==2)throw new L("webrtc protocol was not present in multiaddr",Ge.ERR_INVALID_MULTIADDR);if(!e[0].includes(xb))throw new L("p2p-circuit protocol was not present in multiaddr",Ge.ERR_INVALID_MULTIADDR);let t=nt(e[0]),o=nt("/"+e[1]).getPeerId();if(o==null)throw new L("destination peer id was missing",Ge.ERR_INVALID_MULTIADDR);let s=t.protos().pop();if(s===void 0)throw new L("invalid multiaddr",Ge.ERR_INVALID_MULTIADDR);return s.name!=="p2p"&&(t=t.encapsulate(`/p2p/${o}`)),{baseAddr:t,peerId:br(o)}}var kc={};J(kc,{Ed25519PrivateKey:()=>Rr,Ed25519PublicKey:()=>Jn,generateKeyPair:()=>Ty,generateKeyPairFromSeed:()=>fh,unmarshalEd25519PrivateKey:()=>Cy,unmarshalEd25519PublicKey:()=>Iy});function Xe(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(`positive integer expected, not ${r}`)}function vb(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function rn(r,...e){if(!vb(r))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(r.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${r.length}`)}function Cr(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 nn(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 Pf(r,e){rn(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var ds=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var sn=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),ct=(r,e)=>r<<32-e|r>>>e;var A4=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;var Ab=async()=>{};async function Mf(r,e,t){let n=Date.now();for(let o=0;o<r;o++){t(o);let s=Date.now()-n;s>=0&&s<e||(await Ab(),n+=s)}}function Ff(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function lt(r){return typeof r=="string"&&(r=Ff(r)),rn(r),r}function hc(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];rn(o),e+=o.length}let t=new Uint8Array(e);for(let n=0,o=0;n<r.length;n++){let s=r[n];t.set(s,o),o+=s.length}return t}var on=class{clone(){return this._cloneInto()}},Db={}.toString;function Vf(r,e){if(e!==void 0&&Db.call(e)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(r,e)}function ps(r){let e=n=>r().update(lt(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function Ir(r=32){if(ds&&typeof ds.getRandomValues=="function")return ds.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function Sb(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(t>>o&s),a=Number(t&s),c=n?4:0,l=n?0:4;r.setUint32(e+c,i,n),r.setUint32(e+l,a,n)}var Hf=(r,e,t)=>r&e^~r&t,Kf=(r,e,t)=>r&e^r&t^e&t,an=class extends on{constructor(e,t,n,o){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=sn(this.buffer)}update(e){nn(this);let{view:t,buffer:n,blockLen:o}=this;e=lt(e);let s=e.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=sn(e);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(e.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){nn(this),Pf(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;t[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)t[f]=0;Sb(n,o-8,BigInt(this.length*8),s),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 l=c/4,u=this.get();if(l>u.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<l;f++)a.setUint32(4*f,u[f],s)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return e.length=o,e.pos=a,e.finished=s,e.destroyed=i,o%t&&e.buffer.set(n),e}};var ms=BigInt(4294967295),dc=BigInt(32);function $f(r,e=!1){return e?{h:Number(r&ms),l:Number(r>>dc&ms)}:{h:Number(r>>dc&ms)|0,l:Number(r&ms)|0}}function Bb(r,e=!1){let t=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let o=0;o<r.length;o++){let{h:s,l:i}=$f(r[o],e);[t[o],n[o]]=[s,i]}return[t,n]}var kb=(r,e)=>BigInt(r>>>0)<<dc|BigInt(e>>>0),Cb=(r,e,t)=>r>>>t,Ib=(r,e,t)=>r<<32-t|e>>>t,Tb=(r,e,t)=>r>>>t|e<<32-t,_b=(r,e,t)=>r<<32-t|e>>>t,Rb=(r,e,t)=>r<<64-t|e>>>t-32,Nb=(r,e,t)=>r>>>t-32|e<<64-t,Lb=(r,e)=>e,Ub=(r,e)=>r,Ob=(r,e,t)=>r<<t|e>>>32-t,Pb=(r,e,t)=>e<<t|r>>>32-t,Mb=(r,e,t)=>e<<t-32|r>>>64-t,Fb=(r,e,t)=>r<<t-32|e>>>64-t;function Vb(r,e,t,n){let o=(e>>>0)+(n>>>0);return{h:r+t+(o/2**32|0)|0,l:o|0}}var Hb=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),Kb=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,$b=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),qb=(r,e,t,n,o)=>e+t+n+o+(r/2**32|0)|0,Wb=(r,e,t,n,o)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(o>>>0),zb=(r,e,t,n,o,s)=>e+t+n+o+s+(r/2**32|0)|0;var Gb={fromBig:$f,split:Bb,toBig:kb,shrSH:Cb,shrSL:Ib,rotrSH:Tb,rotrSL:_b,rotrBH:Rb,rotrBL:Nb,rotr32H:Lb,rotr32L:Ub,rotlSH:Ob,rotlSL:Pb,rotlBH:Mb,rotlBL:Fb,add:Vb,add3L:Hb,add3H:Kb,add4L:$b,add4H:qb,add5H:zb,add5L:Wb},Z=Gb;var[jb,Yb]=Z.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),tr=new Uint32Array(80),rr=new Uint32Array(80),pc=class extends an{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:e,Al:t,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:l,El:u,Fh:f,Fl:m,Gh:g,Gl:p,Hh:h,Hl:d}=this;return[e,t,n,o,s,i,a,c,l,u,f,m,g,p,h,d]}set(e,t,n,o,s,i,a,c,l,u,f,m,g,p,h,d){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=l|0,this.El=u|0,this.Fh=f|0,this.Fl=m|0,this.Gh=g|0,this.Gl=p|0,this.Hh=h|0,this.Hl=d|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 A=tr[b-15]|0,E=rr[b-15]|0,v=Z.rotrSH(A,E,1)^Z.rotrSH(A,E,8)^Z.shrSH(A,E,7),S=Z.rotrSL(A,E,1)^Z.rotrSL(A,E,8)^Z.shrSL(A,E,7),D=tr[b-2]|0,_=rr[b-2]|0,O=Z.rotrSH(D,_,19)^Z.rotrBH(D,_,61)^Z.shrSH(D,_,6),R=Z.rotrSL(D,_,19)^Z.rotrBL(D,_,61)^Z.shrSL(D,_,6),H=Z.add4L(S,R,rr[b-7],rr[b-16]),V=Z.add4H(H,v,O,tr[b-7],tr[b-16]);tr[b]=V|0,rr[b]=H|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:l,Dl:u,Eh:f,El:m,Fh:g,Fl:p,Gh:h,Gl:d,Hh:y,Hl:x}=this;for(let b=0;b<80;b++){let A=Z.rotrSH(f,m,14)^Z.rotrSH(f,m,18)^Z.rotrBH(f,m,41),E=Z.rotrSL(f,m,14)^Z.rotrSL(f,m,18)^Z.rotrBL(f,m,41),v=f&g^~f&h,S=m&p^~m&d,D=Z.add5L(x,E,S,Yb[b],rr[b]),_=Z.add5H(D,y,A,v,jb[b],tr[b]),O=D|0,R=Z.rotrSH(n,o,28)^Z.rotrBH(n,o,34)^Z.rotrBH(n,o,39),H=Z.rotrSL(n,o,28)^Z.rotrBL(n,o,34)^Z.rotrBL(n,o,39),V=n&s^n&a^s&a,G=o&i^o&c^i&c;y=h|0,x=d|0,h=g|0,d=p|0,g=f|0,p=m|0,{h:f,l:m}=Z.add(l|0,u|0,_|0,O|0),l=a|0,u=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let B=Z.add3L(O,H,G);n=Z.add3H(B,_,R,V),o=B|0}({h:n,l:o}=Z.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Z.add(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Z.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:u}=Z.add(this.Dh|0,this.Dl|0,l|0,u|0),{h:f,l:m}=Z.add(this.Eh|0,this.El|0,f|0,m|0),{h:g,l:p}=Z.add(this.Fh|0,this.Fl|0,g|0,p|0),{h,l:d}=Z.add(this.Gh|0,this.Gl|0,h|0,d|0),{h:y,l:x}=Z.add(this.Hh|0,this.Hl|0,y|0,x|0),this.set(n,o,s,i,a,c,l,u,f,m,g,p,h,d,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 zn=ps(()=>new pc);var bs={};J(bs,{abytes:()=>cn,bitGet:()=>ry,bitLen:()=>ty,bitMask:()=>Gn,bitSet:()=>ny,bytesToHex:()=>Rt,bytesToNumberBE:()=>Nt,bytesToNumberLE:()=>ut,concatBytes:()=>Ut,createHmacDrbg:()=>bc,ensureBytes:()=>ce,equalBytes:()=>Qb,hexToBytes:()=>Tr,hexToNumber:()=>gc,isBytes:()=>nr,numberToBytesBE:()=>or,numberToBytesLE:()=>Lt,numberToHexUnpadded:()=>Gf,numberToVarBytesBE:()=>Jb,utf8ToBytes:()=>ey,validateObject:()=>Je});var zf=BigInt(0),gs=BigInt(1),Zb=BigInt(2);function nr(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function cn(r){if(!nr(r))throw new Error("Uint8Array expected")}var Xb=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function Rt(r){cn(r);let e="";for(let t=0;t<r.length;t++)e+=Xb[r[t]];return e}function Gf(r){let e=r.toString(16);return e.length&1?`0${e}`:e}function gc(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 qf(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 Tr(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let e=r.length,t=e/2;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(t);for(let o=0,s=0;o<t;o++,s+=2){let i=qf(r.charCodeAt(s)),a=qf(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Nt(r){return gc(Rt(r))}function ut(r){return cn(r),gc(Rt(Uint8Array.from(r).reverse()))}function or(r,e){return Tr(r.toString(16).padStart(e*2,"0"))}function Lt(r,e){return or(r,e).reverse()}function Jb(r){return Tr(Gf(r))}function ce(r,e,t){let n;if(typeof e=="string")try{n=Tr(e)}catch(s){throw new Error(`${r} must be valid hex string, got "${e}". Cause: ${s}`)}else if(nr(e))n=Uint8Array.from(e);else throw new Error(`${r} must be hex string or Uint8Array`);let o=n.length;if(typeof t=="number"&&o!==t)throw new Error(`${r} expected ${t} bytes, got ${o}`);return n}function Ut(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];cn(o),e+=o.length}let t=new Uint8Array(e);for(let n=0,o=0;n<r.length;n++){let s=r[n];t.set(s,o),o+=s.length}return t}function Qb(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 ey(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function ty(r){let e;for(e=0;r>zf;r>>=gs,e+=1);return e}function ry(r,e){return r>>BigInt(e)&gs}function ny(r,e,t){return r|(t?gs:zf)<<BigInt(e)}var Gn=r=>(Zb<<BigInt(r-1))-gs,mc=r=>new Uint8Array(r),Wf=r=>Uint8Array.from(r);function bc(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=mc(r),o=mc(r),s=0,i=()=>{n.fill(1),o.fill(0),s=0},a=(...f)=>t(o,n,...f),c=(f=mc())=>{o=a(Wf([0]),f),n=a(),f.length!==0&&(o=a(Wf([1]),f),n=a())},l=()=>{if(s++>=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(l()));)c();return i(),g}}var oy={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"||nr(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 Je(r,e,t={}){let n=(o,s,i)=>{let a=oy[s];if(typeof a!="function")throw new Error(`Invalid validator "${s}", expected function`);let c=r[o];if(!(i&&c===void 0)&&!a(c,r))throw new Error(`Invalid param ${String(o)}=${c} (${typeof c}), expected ${s}`)};for(let[o,s]of Object.entries(e))n(o,s,!1);for(let[o,s]of Object.entries(t))n(o,s,!0);return r}var ke=BigInt(0),fe=BigInt(1),_r=BigInt(2),sy=BigInt(3),yc=BigInt(4),jf=BigInt(5),Yf=BigInt(8),iy=BigInt(9),ay=BigInt(16);function te(r,e){let t=r%e;return t>=ke?t:e+t}function wc(r,e,t){if(t<=ke||e<ke)throw new Error("Expected power/modulo > 0");if(t===fe)return ke;let n=fe;for(;e>ke;)e&fe&&(n=n*r%t),r=r*r%t,e>>=fe;return n}function le(r,e,t){let n=r;for(;e-- >ke;)n*=n,n%=t;return n}function ys(r,e){if(r===ke||e<=ke)throw new Error(`invert: expected positive integers, got n=${r} mod=${e}`);let t=te(r,e),n=e,o=ke,s=fe,i=fe,a=ke;for(;t!==ke;){let l=n/t,u=n%t,f=o-i*l,m=s-a*l;n=t,t=u,o=i,s=a,i=f,a=m}if(n!==fe)throw new Error("invert: does not exist");return te(o,e)}function cy(r){let e=(r-fe)/_r,t,n,o;for(t=r-fe,n=0;t%_r===ke;t/=_r,n++);for(o=_r;o<r&&wc(o,e,r)!==r-fe;o++);if(n===1){let i=(r+fe)/yc;return function(c,l){let u=c.pow(l,i);if(!c.eql(c.sqr(u),l))throw new Error("Cannot find square root");return u}}let s=(t+fe)/_r;return function(a,c){if(a.pow(c,e)===a.neg(a.ONE))throw new Error("Cannot find square root");let l=n,u=a.pow(a.mul(a.ONE,o),t),f=a.pow(c,s),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<l&&!a.eql(h,a.ONE);g++)h=a.sqr(h);let p=a.pow(u,fe<<BigInt(l-g-1));u=a.sqr(p),f=a.mul(f,p),m=a.mul(m,u),l=g}return f}}function ly(r){if(r%yc===sy){let e=(r+fe)/yc;return function(n,o){let s=n.pow(o,e);if(!n.eql(n.sqr(s),o))throw new Error("Cannot find square root");return s}}if(r%Yf===jf){let e=(r-jf)/Yf;return function(n,o){let s=n.mul(o,_r),i=n.pow(s,e),a=n.mul(o,i),c=n.mul(n.mul(a,_r),i),l=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(l),o))throw new Error("Cannot find square root");return l}}return r%ay,cy(r)}var Zf=(r,e)=>(te(r,e)&fe)===fe,uy=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function xc(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=uy.reduce((n,o)=>(n[o]="function",n),e);return Je(r,t)}function fy(r,e,t){if(t<ke)throw new Error("Expected power > 0");if(t===ke)return r.ONE;if(t===fe)return e;let n=r.ONE,o=e;for(;t>ke;)t&fe&&(n=r.mul(n,o)),o=r.sqr(o),t>>=fe;return n}function hy(r,e){let t=new Array(e.length),n=e.reduce((s,i,a)=>r.is0(i)?s:(t[a]=s,r.mul(s,i)),r.ONE),o=r.inv(n);return e.reduceRight((s,i,a)=>r.is0(i)?s:(t[a]=r.mul(s,t[a]),r.mul(s,i)),o),t}function Ec(r,e){let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function ws(r,e,t=!1,n={}){if(r<=ke)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:o,nByteLength:s}=Ec(r,e);if(s>2048)throw new Error("Field lengths over 2048 bytes are not supported");let i=ly(r),a=Object.freeze({ORDER:r,BITS:o,BYTES:s,MASK:Gn(o),ZERO:ke,ONE:fe,create:c=>te(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return ke<=c&&c<r},is0:c=>c===ke,isOdd:c=>(c&fe)===fe,neg:c=>te(-c,r),eql:(c,l)=>c===l,sqr:c=>te(c*c,r),add:(c,l)=>te(c+l,r),sub:(c,l)=>te(c-l,r),mul:(c,l)=>te(c*l,r),pow:(c,l)=>fy(a,c,l),div:(c,l)=>te(c*ys(l,r),r),sqrN:c=>c*c,addN:(c,l)=>c+l,subN:(c,l)=>c-l,mulN:(c,l)=>c*l,inv:c=>ys(c,r),sqrt:n.sqrt||(c=>i(a,c)),invertBatch:c=>hy(a,c),cmov:(c,l,u)=>u?l:c,toBytes:c=>t?Lt(c,s):or(c,s),fromBytes:c=>{if(c.length!==s)throw new Error(`Fp.fromBytes: expected ${s}, got ${c.length}`);return t?ut(c):Nt(c)}});return Object.freeze(a)}function Xf(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 vc(r){let e=Xf(r);return e+Math.ceil(e/2)}function Jf(r,e,t=!1){let n=r.length,o=Xf(e),s=vc(e);if(n<16||n<s||n>1024)throw new Error(`expected ${s}-1024 bytes of input, got ${n}`);let i=t?Nt(r):ut(r),a=te(i,e-fe)+fe;return t?Lt(a,o):or(a,o)}var py=BigInt(0),Ac=BigInt(1);function xs(r,e){let t=(o,s)=>{let i=s.negate();return o?i:s},n=o=>{let s=Math.ceil(e/o)+1,i=2**(o-1);return{windows:s,windowSize:i}};return{constTimeNegate:t,unsafeLadder(o,s){let i=r.ZERO,a=o;for(;s>py;)s&Ac&&(i=i.add(a)),a=a.double(),s>>=Ac;return i},precomputeWindow(o,s){let{windows:i,windowSize:a}=n(s),c=[],l=o,u=l;for(let f=0;f<i;f++){u=l,c.push(u);for(let m=1;m<a;m++)u=u.add(l),c.push(u);l=u.double()}return c},wNAF(o,s,i){let{windows:a,windowSize:c}=n(o),l=r.ZERO,u=r.BASE,f=BigInt(2**o-1),m=2**o,g=BigInt(o);for(let p=0;p<a;p++){let h=p*c,d=Number(i&f);i>>=g,d>c&&(d-=m,i+=Ac);let y=h,x=h+Math.abs(d)-1,b=p%2!==0,A=d<0;d===0?u=u.add(t(b,s[y])):l=l.add(t(A,s[x]))}return{p:l,f:u}},wNAFCached(o,s,i,a){let c=o._WINDOW_SIZE||1,l=s.get(o);return l||(l=this.precomputeWindow(o,c),c!==1&&s.set(o,a(l))),this.wNAF(c,l,i)}}}function jn(r){return xc(r.Fp),Je(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Ec(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var ft=BigInt(0),Ye=BigInt(1),Es=BigInt(2),my=BigInt(8),gy={zip215:!0};function by(r){let e=jn(r);return Je(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function Qf(r){let e=by(r),{Fp:t,n,prehash:o,hash:s,randomBytes:i,nByteLength:a,h:c}=e,l=Es<<BigInt(a*8)-Ye,u=t.create,f=e.uvRatio||((k,w)=>{try{return{isValid:!0,value:t.sqrt(k*t.inv(w))}}catch{return{isValid:!1,value:ft}}}),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}),p=k=>typeof k=="bigint"&&ft<k,h=(k,w)=>p(k)&&p(w)&&k<w,d=k=>k===ft||h(k,l);function y(k,w){if(h(k,w))return k;throw new Error(`Expected valid scalar < ${w}, got ${typeof k} ${k}`)}function x(k){return k===ft?k:y(k,n)}let b=new Map;function A(k){if(!(k instanceof E))throw new Error("ExtendedPoint expected")}class E{constructor(w,C,T,N){if(this.ex=w,this.ey=C,this.ez=T,this.et=N,!d(w))throw new Error("x required");if(!d(C))throw new Error("y required");if(!d(T))throw new Error("z required");if(!d(N))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(!d(C)||!d(T))throw new Error("invalid affine point");return new E(C,T,Ye,u(C*T))}static normalizeZ(w){let C=t.invertBatch(w.map(T=>T.ez));return w.map((T,N)=>T.toAffine(C[N])).map(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:N,ez:$,et:q}=this,Y=u(T*T),W=u(N*N),j=u($*$),ae=u(j*j),se=u(Y*w),Ie=u(j*u(se+W)),Te=u(ae+u(C*u(Y*W)));if(Ie!==Te)throw new Error("bad point: equation left != right (1)");let ve=u(T*N),Oe=u($*q);if(ve!==Oe)throw new Error("bad point: equation left != right (2)")}equals(w){A(w);let{ex:C,ey:T,ez:N}=this,{ex:$,ey:q,ez:Y}=w,W=u(C*Y),j=u($*N),ae=u(T*Y),se=u(q*N);return W===j&&ae===se}is0(){return this.equals(E.ZERO)}negate(){return new E(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:w}=e,{ex:C,ey:T,ez:N}=this,$=u(C*C),q=u(T*T),Y=u(Es*u(N*N)),W=u(w*$),j=C+T,ae=u(u(j*j)-$-q),se=W+q,Ie=se-Y,Te=W-q,ve=u(ae*Ie),Oe=u(se*Te),Bt=u(ae*Te),pr=u(Ie*se);return new E(ve,Oe,pr,Bt)}add(w){A(w);let{a:C,d:T}=e,{ex:N,ey:$,ez:q,et:Y}=this,{ex:W,ey:j,ez:ae,et:se}=w;if(C===BigInt(-1)){let Wl=u(($-N)*(j+W)),zl=u(($+N)*(j-W)),Li=u(zl-Wl);if(Li===ft)return this.double();let Gl=u(q*Es*se),jl=u(Y*Es*ae),Yl=jl+Gl,Zl=zl+Wl,Xl=jl-Gl,_0=u(Yl*Li),R0=u(Zl*Xl),N0=u(Yl*Xl),L0=u(Li*Zl);return new E(_0,R0,L0,N0)}let Ie=u(N*W),Te=u($*j),ve=u(Y*T*se),Oe=u(q*ae),Bt=u((N+$)*(W+j)-Ie-Te),pr=Oe-ve,Rn=Oe+ve,ql=u(Te-C*Ie),k0=u(Bt*pr),C0=u(Rn*ql),I0=u(Bt*ql),T0=u(pr*Rn);return new E(k0,C0,T0,I0)}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===ft?S:this.equals(S)||C===Ye?this:this.equals(v)?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:N}=this,$=this.is0();w==null&&(w=$?my:t.inv(N));let q=u(C*w),Y=u(T*w),W=u(N*w);if($)return{x:ft,y:Ye};if(W!==Ye)throw new Error("invZ was invalid");return{x:q,y:Y}}clearCofactor(){let{h:w}=e;return w===Ye?this:this.multiplyUnsafe(w)}static fromHex(w,C=!1){let{d:T,a:N}=e,$=t.BYTES;w=ce("pointHex",w,$);let q=w.slice(),Y=w[$-1];q[$-1]=Y&-129;let W=ut(q);W===ft||(C?y(W,l):y(W,t.ORDER));let j=u(W*W),ae=u(j-Ye),se=u(T*j-N),{isValid:Ie,value:Te}=f(ae,se);if(!Ie)throw new Error("Point.fromHex: invalid y coordinate");let ve=(Te&Ye)===Ye,Oe=(Y&128)!==0;if(!C&&Te===ft&&Oe)throw new Error("Point.fromHex: x=0 and x_0=1");return Oe!==ve&&(Te=u(-Te)),E.fromAffine({x:Te,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&Ye?128:0,T}toHex(){return Rt(this.toRawBytes())}}E.BASE=new E(e.Gx,e.Gy,Ye,u(e.Gx*e.Gy)),E.ZERO=new E(ft,Ye,Ye,ft);let{BASE:v,ZERO:S}=E,D=xs(E,a*8);function _(k){return te(k,n)}function O(k){return _(ut(k))}function R(k){let w=a;k=ce("private key",k,w);let C=ce("hashed private key",s(k),2*w),T=m(C.slice(0,w)),N=C.slice(w,2*w),$=O(T),q=v.multiply($),Y=q.toRawBytes();return{head:T,prefix:N,scalar:$,point:q,pointBytes:Y}}function H(k){return R(k).pointBytes}function V(k=new Uint8Array,...w){let C=Ut(...w);return O(s(g(C,ce("context",k),!!o)))}function G(k,w,C={}){k=ce("message",k),o&&(k=o(k));let{prefix:T,scalar:N,pointBytes:$}=R(w),q=V(C.context,T,k),Y=v.multiply(q).toRawBytes(),W=V(C.context,Y,$,k),j=_(q+W*N);x(j);let ae=Ut(Y,Lt(j,t.BYTES));return ce("result",ae,a*2)}let B=gy;function I(k,w,C,T=B){let{context:N,zip215:$}=T,q=t.BYTES;k=ce("signature",k,2*q),w=ce("message",w),o&&(w=o(w));let Y=ut(k.slice(q,2*q)),W,j,ae;try{W=E.fromHex(C,$),j=E.fromHex(k.slice(0,q),$),ae=v.multiplyUnsafe(Y)}catch{return!1}if(!$&&W.isSmallOrder())return!1;let se=V(N,j.toRawBytes(),W.toRawBytes(),w);return j.add(W.multiplyUnsafe(se)).subtract(ae).clearCofactor().equals(E.ZERO)}return v._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),Dc=BigInt(1);function yy(r){return Je(r,{a:"bigint"},{montgomeryBits:"isSafeInteger",nByteLength:"isSafeInteger",adjustScalarBytes:"function",domain:"function",powPminus2:"function",Gu:"bigint"}),Object.freeze({...r})}function eh(r){let e=yy(r),{P:t}=e,n=b=>te(b,t),o=e.montgomeryBits,s=Math.ceil(o/8),i=e.nByteLength,a=e.adjustScalarBytes||(b=>b),c=e.powPminus2||(b=>wc(b,t-BigInt(2),t));function l(b,A,E){let v=n(b*(A-E));return A=n(A-v),E=n(E+v),[A,E]}function u(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,A){let E=u(b),v=u(A),S=E,D=Dc,_=Yn,O=E,R=Dc,H=Yn,V;for(let B=BigInt(o-1);B>=Yn;B--){let I=v>>B&Dc;H^=I,V=l(H,D,O),D=V[0],O=V[1],V=l(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,N=O+R,$=O-R,q=n($*P),Y=n(N*w),W=q+Y,j=q-Y;O=n(W*W),R=n(S*n(j*j)),D=n(k*C),_=n(T*(k+n(f*T)))}V=l(H,D,O),D=V[0],O=V[1],V=l(H,_,R),_=V[0],R=V[1];let G=c(_);return n(D*G)}function g(b){return Lt(n(b),s)}function p(b){let A=ce("u coordinate",b,s);return i===32&&(A[31]&=127),ut(A)}function h(b){let A=ce("scalar",b),E=A.length;if(E!==s&&E!==i)throw new Error(`Expected ${s} or ${i} bytes, got ${E}`);return ut(a(A))}function d(b,A){let E=p(A),v=h(b),S=m(E,v);if(S===Yn)throw new Error("Invalid private or public key received");return g(S)}let y=g(e.Gu);function x(b){return d(b,y)}return{scalarMult:d,scalarMultBase:x,getSharedSecret:(b,A)=>d(b,A),getPublicKey:b=>x(b),utils:{randomPrivateKey:()=>e.randomBytes(e.nByteLength)},GuBytes:y}}var Zn=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),th=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Z4=BigInt(0),wy=BigInt(1),rh=BigInt(2),xy=BigInt(3),Ey=BigInt(5),vy=BigInt(8);function nh(r){let e=BigInt(10),t=BigInt(20),n=BigInt(40),o=BigInt(80),s=Zn,a=r*r%s*r%s,c=le(a,rh,s)*a%s,l=le(c,wy,s)*r%s,u=le(l,Ey,s)*l%s,f=le(u,e,s)*u%s,m=le(f,t,s)*f%s,g=le(m,n,s)*m%s,p=le(g,o,s)*g%s,h=le(p,o,s)*g%s,d=le(h,e,s)*u%s;return{pow_p_5_8:le(d,rh,s)*r%s,b2:a}}function oh(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Ay(r,e){let t=Zn,n=te(e*e*e,t),o=te(n*n*e,t),s=nh(r*o).pow_p_5_8,i=te(r*n*s,t),a=te(e*i*i,t),c=i,l=te(i*th,t),u=a===r,f=a===te(-r,t),m=a===te(-r*th,t);return u&&(i=c),(f||m)&&(i=l),Zf(i,t)&&(i=te(-i,t)),{isValid:u||f,value:i}}var Dy=ws(Zn,void 0,!0),Sy={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Dy,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:vy,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:zn,randomBytes:Ir,adjustScalarBytes:oh,uvRatio:Ay},ln=Qf(Sy);var Xn=eh({P:Zn,a:BigInt(486662),montgomeryBits:255,nByteLength:32,Gu:BigInt(9),powPminus2:r=>{let e=Zn,{pow_p_5_8:t,b2:n}=nh(r);return te(le(t,xy,e)*n,e)},adjustScalarBytes:oh,randomBytes:Ir});var un=32,Ot=64,vs=32;function sh(){let r=ln.utils.randomPrivateKey(),e=ln.getPublicKey(r);return{privateKey:lh(r,e),publicKey:e}}function ih(r){if(r.length!==vs)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=ln.getPublicKey(e);return{privateKey:lh(e,t),publicKey:t}}function ah(r,e){let t=r.subarray(0,vs);return ln.sign(e instanceof Uint8Array?e:e.subarray(),t)}function ch(r,e,t){return ln.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}function lh(r,e){let t=new Uint8Array(Ot);for(let n=0;n<vs;n++)t[n]=r[n],t[vs+n]=e[n];return t}var Ve={get(r=globalThis){let e=r.crypto;if(e==null||e.subtle==null)throw Object.assign(new Error("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api"),{code:"ERR_MISSING_WEB_CRYPTO"});return e}};var Sc={alg:"A128GCM",ext:!0,k:"scm9jmO_4BJAgdwWGVulLg",key_ops:["encrypt","decrypt"],kty:"oct"};function uh(r){let e=r?.algorithm??"AES-GCM",t=r?.keyLength??16,n=r?.nonceLength??12,o=r?.digest??"SHA-256",s=r?.saltLength??16,i=r?.iterations??32767,a=Ve.get();t*=8;async function c(f,m){let g=a.getRandomValues(new Uint8Array(s)),p=a.getRandomValues(new Uint8Array(n)),h={name:e,iv:p};typeof m=="string"&&(m=Q(m));let d;if(m.length===0){d=await a.subtle.importKey("jwk",Sc,{name:"AES-GCM"},!0,["encrypt"]);try{let x={name:"PBKDF2",salt:g,iterations:i,hash:{name:o}},b=await a.subtle.importKey("raw",m,{name:"PBKDF2"},!1,["deriveKey"]);d=await a.subtle.deriveKey(x,b,{name:e,length:t},!0,["encrypt"])}catch{d=await a.subtle.importKey("jwk",Sc,{name:"AES-GCM"},!0,["encrypt"])}}else{let x={name:"PBKDF2",salt:g,iterations:i,hash:{name:o}},b=await a.subtle.importKey("raw",m,{name:"PBKDF2"},!1,["deriveKey"]);d=await a.subtle.deriveKey(x,b,{name:e,length:t},!0,["encrypt"])}let y=await a.subtle.encrypt(h,d,f);return xe([g,h.iv,new Uint8Array(y)])}async function l(f,m){let g=f.subarray(0,s),p=f.subarray(s,s+n),h=f.subarray(s+n),d={name:e,iv:p};typeof m=="string"&&(m=Q(m));let y;if(m.length===0)try{let b={name:"PBKDF2",salt:g,iterations:i,hash:{name:o}},A=await a.subtle.importKey("raw",m,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(b,A,{name:e,length:t},!0,["decrypt"])}catch{y=await a.subtle.importKey("jwk",Sc,{name:"AES-GCM"},!0,["decrypt"])}else{let b={name:"PBKDF2",salt:g,iterations:i,hash:{name:o}},A=await a.subtle.importKey("raw",m,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(b,A,{name:e,length:t},!0,["decrypt"])}let x=await a.subtle.decrypt(d,y,h);return new Uint8Array(x)}return{encrypt:c,decrypt:l}}async function fn(r,e){let n=await uh().encrypt(r,e);return Gi.encode(n)}var he;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.Secp256k1="Secp256k1"})(he||(he={}));var Bc;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.Secp256k1=2]="Secp256k1"})(Bc||(Bc={}));(function(r){r.codec=()=>Dr(Bc)})(he||(he={}));var xt;(function(r){let e;r.codec=()=>(e==null&&(e=at((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),he.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let o={},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let i=t.uint32();switch(i>>>3){case 1:o.Type=he.codec().decode(t);break;case 2:o.Data=t.bytes();break;default:t.skipType(i&7);break}}return o})),e),r.encode=t=>it(t,r.codec()),r.decode=t=>st(t,r.codec())})(xt||(xt={}));var Et;(function(r){let e;r.codec=()=>(e==null&&(e=at((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),he.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let o={},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let i=t.uint32();switch(i>>>3){case 1:o.Type=he.codec().decode(t);break;case 2:o.Data=t.bytes();break;default:t.skipType(i&7);break}}return o})),e),r.encode=t=>it(t,r.codec()),r.decode=t=>st(t,r.codec())})(Et||(Et={}));var Jn=class{_key;constructor(e){this._key=hn(e,un)}verify(e,t){return ch(this._key,t,e)}marshal(){return this._key}get bytes(){return xt.encode({Type:he.Ed25519,Data:this.marshal()}).subarray()}equals(e){return Ae(this.bytes,e.bytes)}hash(){let e=_e.digest(this.bytes);return Xe(e)?e.then(({bytes:t})=>t):e.bytes}},Rr=class{_key;_publicKey;constructor(e,t){this._key=hn(e,Ot),this._publicKey=hn(t,un)}sign(e){return ah(this._key,e)}get public(){return new Jn(this._publicKey)}marshal(){return this._key}get bytes(){return Et.encode({Type:he.Ed25519,Data:this.marshal()}).subarray()}equals(e){return Ae(this.bytes,e.bytes)}async hash(){let e=_e.digest(this.bytes),t;return Xe(e)?{bytes:t}=await e:t=e.bytes,t}async id(){let e=jt.digest(this.public.bytes);return ge.encode(e.bytes).substring(1)}async export(e,t="libp2p-key"){if(t==="libp2p-key")return fn(this.bytes,e);throw new L(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function Cy(r){if(r.length>Ot){r=hn(r,Ot+un);let n=r.subarray(0,Ot),o=r.subarray(Ot,r.length);return new Rr(n,o)}r=hn(r,Ot);let e=r.subarray(0,Ot),t=r.subarray(un);return new Rr(e,t)}function Iy(r){return r=hn(r,un),new Jn(r)}async function Ty(){let{privateKey:r,publicKey:e}=sh();return new Rr(r,e)}async function fh(r){let{privateKey:e,publicKey:t}=ih(r);return new Rr(e,t)}function hn(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new L(`Key must be a Uint8Array of length ${e}, got ${r.length}`,"ERR_INVALID_KEY_TYPE");return r}var Pc={};J(Pc,{MAX_RSA_KEY_SIZE:()=>lo,RsaPrivateKey:()=>bn,RsaPublicKey:()=>co,fromJwk:()=>nw,generateKeyPair:()=>ow,unmarshalRsaPrivateKey:()=>Uc,unmarshalRsaPublicKey:()=>rw});function Nr(r){if(isNaN(r)||r<=0)throw new L("random bytes length must be a Number bigger than 0","ERR_INVALID_LENGTH");return Ir(r)}var lr={};J(lr,{exportToPem:()=>Xy,importFromPem:()=>Jy,jwkToPkcs1:()=>Gy,jwkToPkix:()=>Yy,pkcs1ToJwk:()=>zy,pkixToJwk:()=>jy});var Ds=class extends on{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,Cr(e);let n=lt(t);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?e.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=e.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),s.fill(0)}update(e){return nn(this),this.iHash.update(e),this}digestInto(e){nn(this),rn(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:t,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=a,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},sr=(r,e,t)=>new Ds(r,e).update(t).digest();sr.create=(r,e)=>new Ds(r,e);function _y(r,e,t,n){Cr(r);let o=Vf({dkLen:32,asyncTick:10},n),{c:s,dkLen:i,asyncTick:a}=o;if(er(s),er(i),er(a),s<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let c=lt(e),l=lt(t),u=new Uint8Array(i),f=sr.create(r,c),m=f._cloneInto().update(l);return{c:s,dkLen:i,asyncTick:a,DK:u,PRF:f,PRFSalt:m}}function Ry(r,e,t,n,o){return r.destroy(),e.destroy(),n&&n.destroy(),o.fill(0),t}async function Cc(r,e,t,n){let{c:o,dkLen:s,asyncTick:i,DK:a,PRF:c,PRFSalt:l}=_y(r,e,t,n),u,f=new Uint8Array(4),m=sn(f),g=new Uint8Array(c.outputLen);for(let p=1,h=0;h<s;p++,h+=c.outputLen){let d=a.subarray(h,h+c.outputLen);m.setInt32(0,p,!1),(u=l._cloneInto(u)).update(f).digestInto(g),d.set(g.subarray(0,d.length)),await Mf(o-1,i,()=>{c._cloneInto(u).update(g).digestInto(g);for(let y=0;y<d.length;y++)d[y]^=g[y]})}return Ry(c,l,a,u,g)}var X=So(hh());function Lr(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 ir(r,e,t=-1){let n=t,o=r,s=0,i=Math.pow(2,e);for(let a=1;a<8;a++){if(r<i){let c;if(n<0)c=new ArrayBuffer(a),s=a;else{if(n<a)return new ArrayBuffer(0);c=new ArrayBuffer(n),s=n}let l=new Uint8Array(c);for(let u=a-1;u>=0;u--){let f=Math.pow(2,u*e);l[s-u-1]=Math.floor(o/f),o-=l[s-u-1]*f}return c}i*=Math.pow(2,e)}return new ArrayBuffer(0)}function ks(...r){let e=0,t=0;for(let s of r)e+=s.length;let n=new ArrayBuffer(e),o=new Uint8Array(n);for(let s of r)o.set(s,t),t+=s.length;return o}function Tc(){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=Lr(t,8),o=new ArrayBuffer(this.valueHex.byteLength),s=new Uint8Array(o);for(let a=0;a<this.valueHex.byteLength;a++)s[a]=r[a];return s[0]&=127,Lr(s,8)-n}function dh(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=ir(i,8,n),c=new Uint8Array(a);return c[0]|=128,a}let o=ir(e,8,n),s=new Uint8Array(o);if(s[0]&128){let i=o.slice(0),a=new Uint8Array(i);o=new ArrayBuffer(o.byteLength+1),s=new Uint8Array(o);for(let c=0;c<i.byteLength;c++)s[c+1]=a[c];s[0]=0}return o}t*=Math.pow(2,8)}return new ArrayBuffer(0)}function ph(r,e){if(r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let o=0;o<t.length;o++)if(t[o]!==n[o])return!1;return!0}function We(r,e){let t=r.toString(10);if(e<t.length)return"";let n=e-t.length,o=new Array(n);for(let i=0;i<n;i++)o[i]="0";return o.join("").concat(t)}var DD=Math.log(2);function Cs(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function _c(r){let e=0,t=0;for(let o=0;o<r.length;o++){let s=r[o];e+=s.byteLength}let n=new Uint8Array(e);for(let o=0;o<r.length;o++){let s=r[o];n.set(new Uint8Array(s),t),t+=s.byteLength}return n.buffer}function Ht(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 eo=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return _c(this.items)}},Qn=[new Uint8Array([1])],mh="0123456789";var mn="",dt=new ArrayBuffer(0),Rc=new Uint8Array(0),to="EndOfContent",bh="OCTET STRING",yh="BIT STRING";function Kt(r){var e;return e=class extends r{constructor(...n){var o;super(...n);let s=n[0]||{};this.isHexOnly=(o=s.isHexOnly)!==null&&o!==void 0?o:!1,this.valueHexView=s.valueHex?X.BufferSourceConverter.toUint8Array(s.valueHex):Rc}get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}fromBER(n,o,s){let i=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!Ht(this,i,o,s))return-1;let a=o+s;return this.valueHexView=i.subarray(o,a),this.valueHexView.length?(this.blockLength=s,a):(this.warnings.push("Zero buffer length"),o)}toBER(n=!1){return this.isHexOnly?n?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.byteLength===this.valueHexView.buffer.byteLength?this.valueHexView.buffer:this.valueHexView.slice().buffer:(this.error="Flag 'isHexOnly' is not set, abort",dt)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:X.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var Mt=class{constructor({blockLength:e=0,error:t=mn,warnings:n=[],valueBeforeDecode:o=Rc}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=X.BufferSourceConverter.toUint8Array(o)}static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(e){this.valueBeforeDecodeView=new Uint8Array(e)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:X.Convert.ToHex(this.valueBeforeDecodeView)}}};Mt.NAME="baseBlock";var Fe=class extends Mt{fromBER(e,t,n){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}toBER(e,t){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}};Fe.NAME="valueBlock";var Is=class extends Kt(Mt){constructor({idBlock:e={}}={}){var t,n,o,s;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?X.BufferSourceConverter.toUint8Array(e.valueHex):Rc,this.tagClass=(n=e.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(o=e.tagNumber)!==null&&o!==void 0?o:-1,this.isConstructed=(s=e.isConstructed)!==null&&s!==void 0?s:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(e=!1){let t=0;switch(this.tagClass){case 1:t|=0;break;case 2:t|=64;break;case 3:t|=128;break;case 4:t|=192;break;default:return this.error="Unknown tag class",dt}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){let o=new Uint8Array(1);if(!e){let s=this.tagNumber;s&=31,t|=s,o[0]=t}return o.buffer}if(!this.isHexOnly){let o=ir(this.tagNumber,7),s=new Uint8Array(o),i=o.byteLength,a=new Uint8Array(i+1);if(a[0]=t|31,!e){for(let c=0;c<i-1;c++)a[c+1]=s[c]|128;a[i]=s[i-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=t|31,!e){let o=this.valueHexView;for(let s=0;s<o.length-1;s++)n[s+1]=o[s]|128;n[this.valueHexView.byteLength]=o[o.length-1]}return n.buffer}fromBER(e,t,n){let o=X.BufferSourceConverter.toUint8Array(e);if(!Ht(this,o,t,n))return-1;let s=o.subarray(t,t+n);if(s.length===0)return this.error="Zero buffer length",-1;switch(s[0]&192){case 0:this.tagClass=1;break;case 64:this.tagClass=2;break;case 128:this.tagClass=3;break;case 192:this.tagClass=4;break;default:return this.error="Unknown tag class",-1}this.isConstructed=(s[0]&32)===32,this.isHexOnly=!1;let a=s[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=1,l=this.valueHexView=new Uint8Array(255),u=255;for(;s[c]&128;){if(l[c-1]=s[c]&127,c++,c>=s.length)return this.error="End of input reached before message was fully decoded",-1;if(c===u){u+=255;let m=new Uint8Array(u);for(let g=0;g<l.length;g++)m[g]=l[g];l=this.valueHexView=new Uint8Array(u)}}this.blockLength=c+1,l[c-1]=s[c]&127;let f=new Uint8Array(c);for(let m=0;m<c;m++)f[m]=l[m];l=this.valueHexView=new Uint8Array(c),l.set(f),this.blockLength<=9?this.tagNumber=Lr(l,7):(this.isHexOnly=!0,this.warnings.push("Tag too long, represented as hex-coded"))}if(this.tagClass===1&&this.isConstructed)switch(this.tagNumber){case 1:case 2:case 5:case 6:case 9:case 13:case 14:case 23:case 24:case 31:case 32:case 33:case 34:return this.error="Constructed encoding used for primitive type",-1}return t+this.blockLength}toJSON(){return{...super.toJSON(),tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed}}};Is.NAME="identificationBlock";var Ts=class extends Mt{constructor({lenBlock:e={}}={}){var t,n,o;super(),this.isIndefiniteForm=(t=e.isIndefiniteForm)!==null&&t!==void 0?t:!1,this.longFormUsed=(n=e.longFormUsed)!==null&&n!==void 0?n:!1,this.length=(o=e.length)!==null&&o!==void 0?o:0}fromBER(e,t,n){let o=X.BufferSourceConverter.toUint8Array(e);if(!Ht(this,o,t,n))return-1;let s=o.subarray(t,t+n);if(s.length===0)return this.error="Zero buffer length",-1;if(s[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=s[0]===128,this.isIndefiniteForm)return this.blockLength=1,t+this.blockLength;if(this.longFormUsed=!!(s[0]&128),this.longFormUsed===!1)return this.length=s[0],this.blockLength=1,t+this.blockLength;let i=s[0]&127;if(i>8)return this.error="Too big integer",-1;if(i+1>s.length)return this.error="End of input reached before message was fully decoded",-1;let a=t+1,c=o.subarray(a,a+i);return c[i-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=Lr(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=i+1,t+this.blockLength}toBER(e=!1){let t,n;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=128),t;if(this.longFormUsed){let o=ir(this.length,8);if(o.byteLength>127)return this.error="Too big length",dt;if(t=new ArrayBuffer(o.byteLength+1),e)return t;let s=new Uint8Array(o);n=new Uint8Array(t),n[0]=o.byteLength|128;for(let i=0;i<o.byteLength;i++)n[i+1]=s[i];return t}return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=this.length),t}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}};Ts.NAME="lengthBlock";var M={},Ne=class extends Mt{constructor({name:e=mn,optional:t=!1,primitiveSchema:n,...o}={},s){super(o),this.name=e,this.optional=t,n&&(this.primitiveSchema=n),this.idBlock=new Is(o),this.lenBlock=new Ts(o),this.valueBlock=s?new s(o):new Fe(o)}fromBER(e,t,n){let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),o)}toBER(e,t){let n=t||new eo;t||wh(this);let o=this.idBlock.toBER(e);if(n.write(o),this.lenBlock.isIndefiniteForm)n.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,n),n.write(new ArrayBuffer(2));else{let s=this.valueBlock.toBER(e);this.lenBlock.length=s.byteLength;let i=this.lenBlock.toBER(e);n.write(i),n.write(s)}return t?dt: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 ph(t,n)}};Ne.NAME="BaseBlock";function wh(r){if(r instanceof M.Constructed)for(let e of r.valueBlock.value)wh(e)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var _s=class extends Ne{constructor({value:e=mn,...t}={},n){super(t,n),e&&this.fromString(e)}getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}fromBER(e,t,n){let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(this.fromBuffer(this.valueBlock.valueHexView),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),o)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}};_s.NAME="BaseStringBlock";var Rs=class extends Kt(Fe){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};Rs.NAME="PrimitiveValueBlock";var xh,Ns=class extends Ne{constructor(e={}){super(e,Rs),this.idBlock.isConstructed=!1}};xh=Ns;M.Primitive=xh;Ns.NAME="PRIMITIVE";function Hy(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 hi(r,e=0,t=r.length){let n=e,o=new Ne({},Fe),s=new Mt;if(!Ht(s,r,e,t))return o.error=s.error,{offset:-1,result:o};if(!r.subarray(e,e+t).length)return o.error="Zero buffer length",{offset:-1,result:o};let a=o.idBlock.fromBER(r,e,t);if(o.idBlock.warnings.length&&o.warnings.concat(o.idBlock.warnings),a===-1)return o.error=o.idBlock.error,{offset:-1,result:o};if(e=a,t-=o.idBlock.blockLength,a=o.lenBlock.fromBER(r,e,t),o.lenBlock.warnings.length&&o.warnings.concat(o.lenBlock.warnings),a===-1)return o.error=o.lenBlock.error,{offset:-1,result:o};if(e=a,t-=o.lenBlock.blockLength,!o.idBlock.isConstructed&&o.lenBlock.isIndefiniteForm)return o.error="Indefinite length form used for primitive encoding form",{offset:-1,result:o};let c=Ne;switch(o.idBlock.tagClass){case 1:if(o.idBlock.tagNumber>=37&&o.idBlock.isHexOnly===!1)return o.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:o};switch(o.idBlock.tagNumber){case 0:if(o.idBlock.isConstructed&&o.lenBlock.length>0)return o.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:o};c=M.EndOfContent;break;case 1:c=M.Boolean;break;case 2:c=M.Integer;break;case 3:c=M.BitString;break;case 4:c=M.OctetString;break;case 5:c=M.Null;break;case 6:c=M.ObjectIdentifier;break;case 10:c=M.Enumerated;break;case 12:c=M.Utf8String;break;case 13:c=M.RelativeObjectIdentifier;break;case 14:c=M.TIME;break;case 15:return o.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:o};case 16:c=M.Sequence;break;case 17:c=M.Set;break;case 18:c=M.NumericString;break;case 19:c=M.PrintableString;break;case 20:c=M.TeletexString;break;case 21:c=M.VideotexString;break;case 22:c=M.IA5String;break;case 23:c=M.UTCTime;break;case 24:c=M.GeneralizedTime;break;case 25:c=M.GraphicString;break;case 26:c=M.VisibleString;break;case 27:c=M.GeneralString;break;case 28:c=M.UniversalString;break;case 29:c=M.CharacterString;break;case 30:c=M.BmpString;break;case 31:c=M.DATE;break;case 32:c=M.TimeOfDay;break;case 33:c=M.DateTime;break;case 34:c=M.Duration;break;default:{let l=o.idBlock.isConstructed?new M.Constructed:new M.Primitive;l.idBlock=o.idBlock,l.lenBlock=o.lenBlock,l.warnings=o.warnings,o=l}}break;case 2:case 3:case 4:default:c=o.idBlock.isConstructed?M.Constructed:M.Primitive}return o=Hy(o,c),a=o.fromBER(r,e,o.lenBlock.isIndefiniteForm?t:o.lenBlock.length),o.valueBeforeDecodeView=r.subarray(n,n+o.blockLength),{offset:a,result:o}}function gn(r){if(!r.byteLength){let e=new Ne({},Fe);return e.error="Input buffer has zero length",{offset:-1,result:e}}return hi(X.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function Ky(r,e){return r?1:e}var vt=class extends Fe{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let o=X.BufferSourceConverter.toUint8Array(e);if(!Ht(this,o,t,n))return-1;if(this.valueBeforeDecodeView=o.subarray(t,t+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),t;let s=t;for(;Ky(this.isIndefiniteForm,n)>0;){let i=hi(o,s,n);if(i.offset===-1)return this.error=i.result.error,this.warnings.concat(i.result.warnings),-1;if(s=i.offset,this.blockLength+=i.result.blockLength,n-=i.result.blockLength,this.value.push(i.result),this.isIndefiniteForm&&i.result.constructor.NAME===to)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===to?this.value.pop():this.warnings.push("No EndOfContent block encoded")),s}toBER(e,t){let n=t||new eo;for(let o=0;o<this.value.length;o++)this.value[o].toBER(e,n);return t?dt:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};vt.NAME="ConstructedValueBlock";var Eh,ar=class extends Ne{constructor(e={}){super(e,vt),this.idBlock.isConstructed=!0}fromBER(e,t,n){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),o)}onAsciiEncoding(){let e=[];for(let n of this.valueBlock.value)e.push(n.toString("ascii").split(`
16
+ `});var c0=re(()=>{a0();Si();hr();Ou();vo()});var Fu,p6,u0=re(()=>{Op();Pp();Mp();Fp();Vp();ku();Hp();Tu();Kp();qp();Qp();r0();n0();o0();c0();Fu={...Eu,...vu,...Au,...Du,...Su,...Bu,...Cu,...Iu,..._u,...Ru},p6={...Pu,...Mu}});function In(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}var Ii=re(()=>{});function Ti(r=0){return globalThis.Buffer!=null&&globalThis.Buffer.allocUnsafe!=null?In(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}var Vu=re(()=>{Ii()});function f0(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var l0,Hu,O2,_i,Ku=re(()=>{u0();Vu();l0=f0("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Hu=f0("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=Ti(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),O2={utf8:l0,"utf-8":l0,hex:Fu.base16,latin1:Hu,ascii:Hu,binary:Hu,...Fu},_i=O2});var h0={};Q(h0,{toString:()=>P2});function P2(r,e="utf8"){let t=_i[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 d0=re(()=>{Ku()});var p0={};Q(p0,{fromString:()=>M2});function M2(r,e="utf8"){let t=_i[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 m0=re(()=>{Ku();Ii()});var g0={};Q(g0,{concat:()=>F2});function F2(r,e){e||(e=r.reduce((o,s)=>o+s.length,0));let t=Ti(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return In(t)}var b0=re(()=>{Vu();Ii()});var qu=Ke((k6,A0)=>{"use strict";var y0=mp(),Tn=Bp(),{names:Do}=Cp(),{toString:Ri}=(d0(),ko(h0)),{fromString:V2}=(m0(),ko(p0)),{concat:H2}=(b0(),ko(g0)),_n={};for(let r in Do){let e=r;_n[Do[e]]=e}Object.freeze(_n);function K2(r){if(!(r instanceof Uint8Array))throw new Error("must be passed a Uint8Array");return Ri(r,"base16")}function $2(r){return V2(r,"base16")}function q2(r){if(!(r instanceof Uint8Array))throw new Error("must be passed a Uint8Array");return Ri(y0.encode("base58btc",r)).slice(1)}function W2(r){let e=r instanceof Uint8Array?Ri(r):r;return y0.decode("z"+e)}function w0(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(!E0(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${Ri(r,"base16")}`);return{code:e,name:_n[e],length:t,digest:r}}function z2(r,e,t){if(!r||e===void 0)throw new Error("multihash encode requires at least two args: digest, code");let n=x0(e);if(!(r instanceof Uint8Array))throw new Error("digest should be a Uint8Array");if(t==null&&(t=r.length),t&&r.length!==t)throw new Error("digest length should be equal to specified length.");let o=Tn.encode(n),s=Tn.encode(t);return H2([o,s,r],o.length+s.length+r.length)}function x0(r){let e=r;if(typeof r=="string"){if(Do[r]===void 0)throw new Error(`Unrecognized hash function named: ${r}`);e=Do[r]}if(typeof e!="number")throw new Error(`Hash function code should be a number. Got: ${e}`);if(_n[e]===void 0&&!$u(e))throw new Error(`Unrecognized function code: ${e}`);return e}function $u(r){return r>0&&r<16}function E0(r){return!!($u(r)||_n[r])}function v0(r){w0(r)}function G2(r){return v0(r),r.subarray(0,2)}A0.exports={names:Do,codes:_n,toHexString:K2,fromHexString:$2,toB58String:q2,fromB58String:W2,decode:w0,encode:z2,coerceCode:x0,isAppCode:$u,validate:v0,prefix:G2,isValidCode:E0}});var n1={};Q(n1,{webRTC:()=>r1,webRTCDirect:()=>t1});var Oi=Symbol.for("@libp2p/peer-id");var Co=Symbol.for("@libp2p/transport");var nl;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(nl||(nl={}));var L=class extends Error{code;props;constructor(e,t,n){super(e),this.code=t,this.name=n?.name??"CodeError",this.props=n??{}}};var Io=(r,...e)=>{try{[...e]}catch{}};var To=class extends EventTarget{#e=new Map;constructor(){super(),Io(1/0,this)}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:s})=>s!==t),this.#e.set(e,o))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new W0(e,t))}},Pi=class extends Event{detail;constructor(e,t){super(e,t),this.detail=t?.detail}},W0=globalThis.CustomEvent??Pi;var Vr=Symbol.for("@libp2p/service-capabilities"),ol=Symbol.for("@libp2p/service-dependencies");var Ki={};Q(Ki,{base58btc:()=>ge,base58flickr:()=>X0});var L1=new Uint8Array(0);function sl(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 kt(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 il(r){return new TextEncoder().encode(r)}function al(r){return new TextDecoder().decode(r)}function z0(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(t[i]!==255)throw new TypeError(s+" is ambiguous");t[i]=o}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function f(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var h=0,d=0,y=0,x=p.length;y!==x&&p[y]===0;)y++,h++;for(var b=(x-y)*l+1>>>0,A=new Uint8Array(b);y!==x;){for(var E=p[y],v=0,S=b-1;(E!==0||v<d)&&S!==-1;S--,v++)E+=256*A[S]>>>0,A[S]=E%a>>>0,E=E/a>>>0;if(E!==0)throw new Error("Non-zero carry");d=v,y++}for(var D=b-d;D!==b&&A[D]===0;)D++;for(var _=c.repeat(h);D<b;++D)_+=r.charAt(A[D]);return _}function m(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var h=0;if(p[h]!==" "){for(var d=0,y=0;p[h]===c;)d++,h++;for(var x=(p.length-h)*u+1>>>0,b=new Uint8Array(x);p[h];){var A=t[p.charCodeAt(h)];if(A===255)return;for(var E=0,v=x-1;(A!==0||E<y)&&v!==-1;v--,E++)A+=a*b[v]>>>0,b[v]=A%256>>>0,A=A/256>>>0;if(A!==0)throw new Error("Non-zero carry");y=E,h++}if(p[h]!==" "){for(var S=x-y;S!==x&&b[S]===0;)S++;for(var D=new Uint8Array(d+(x-S)),_=d;S!==x;)D[_++]=b[S++];return D}}}function g(p){var h=m(p);if(h)return h;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:m,decode:g}}var G0=z0,j0=G0,ul=j0;var Mi=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")}},Fi=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 ll(this,e)}},Vi=class{decoders;constructor(e){this.decoders=e}or(e){return ll(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 ll(r,e){return new Vi({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Hi=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new Mi(e,t,n),this.decoder=new Fi(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Hr({name:r,prefix:e,encode:t,decode:n}){return new Hi(r,e,t,n)}function jt({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=ul(t,r);return Hr({prefix:e,name:r,encode:n,decode:s=>kt(o(s))})}function Y0(r,e,t,n){let o={};for(let l=0;l<e.length;++l)o[e[l]]=l;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*t/8|0),a=0,c=0,u=0;for(let l=0;l<s;++l){let f=o[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 Z0(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>t;)i-=t,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<t-i]),n)for(;s.length*t&7;)s+="=";return s}function de({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return Hr({prefix:e,name:r,encode(o){return Z0(o,n,t)},decode(o){return Y0(o,n,t,r)}})}var ge=jt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),X0=jt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var $i={};Q($i,{base10:()=>J0});var J0=jt({prefix:"9",name:"base10",alphabet:"0123456789"});var qi={};Q(qi,{base16:()=>Q0,base16upper:()=>em});var Q0=de({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),em=de({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Wi={};Q(Wi,{base2:()=>tm});var tm=de({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var zi={};Q(zi,{base256emoji:()=>im});var fl=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}"),rm=fl.reduce((r,e,t)=>(r[t]=e,r),[]),nm=fl.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function om(r){return r.reduce((e,t)=>(e+=rm[t],e),"")}function sm(r){let e=[];for(let t of r){let n=nm[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var im=Hr({prefix:"\u{1F680}",name:"base256emoji",encode:om,decode:sm});var Gi={};Q(Gi,{base32:()=>Ct,base32hex:()=>lm,base32hexpad:()=>hm,base32hexpadupper:()=>dm,base32hexupper:()=>fm,base32pad:()=>cm,base32padupper:()=>um,base32upper:()=>am,base32z:()=>pm});var Ct=de({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),am=de({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),cm=de({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),um=de({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),lm=de({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),fm=de({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),hm=de({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),dm=de({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),pm=de({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ji={};Q(ji,{base36:()=>mm,base36upper:()=>gm});var mm=jt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),gm=jt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Xi={};Q(Xi,{base64:()=>Yi,base64pad:()=>bm,base64url:()=>Zi,base64urlpad:()=>ym});var Yi=de({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),bm=de({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Zi=de({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),ym=de({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ji={};Q(Ji,{base8:()=>wm});var wm=de({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Qi={};Q(Qi,{identity:()=>xm});var xm=Hr({prefix:"\0",name:"identity",encode:r=>al(r),decode:r=>il(r)});var Z1=new TextEncoder,X1=new TextDecoder;var ta={};Q(ta,{identity:()=>It});var Am=pl,hl=128,Dm=127,Sm=~Dm,Bm=Math.pow(2,31);function pl(r,e,t){e=e||[],t=t||0;for(var n=t;r>=Bm;)e[t++]=r&255|hl,r/=128;for(;r&Sm;)e[t++]=r&255|hl,r>>>=7;return e[t]=r|0,pl.bytes=t-n+1,e}var km=ea,Cm=128,dl=127;function ea(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw ea.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&dl)<<o:(i&dl)*Math.pow(2,o),o+=7}while(i>=Cm);return ea.bytes=s-n,t}var Im=Math.pow(2,7),Tm=Math.pow(2,14),_m=Math.pow(2,21),Rm=Math.pow(2,28),Nm=Math.pow(2,35),Lm=Math.pow(2,42),Um=Math.pow(2,49),Om=Math.pow(2,56),Pm=Math.pow(2,63),Mm=function(r){return r<Im?1:r<Tm?2:r<_m?3:r<Rm?4:r<Nm?5:r<Lm?6:r<Um?7:r<Om?8:r<Pm?9:10},Fm={encode:Am,decode:km,encodingLength:Mm},Vm=Fm,Nn=Vm;function Ln(r,e=0){return[Nn.decode(r,e),Nn.decode.bytes]}function Kr(r,e,t=0){return Nn.encode(r,e,t),e}function $r(r){return Nn.encodingLength(r)}function gt(r,e){let t=e.byteLength,n=$r(r),o=n+$r(t),s=new Uint8Array(o+t);return Kr(r,s,0),Kr(t,s,n),s.set(e,o),new qr(r,t,e,s)}function mr(r){let e=kt(r),[t,n]=Ln(e),[o,s]=Ln(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new qr(t,o,i,e)}function ml(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&sl(r.bytes,t.bytes)}}var qr=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};var gl=0,Hm="identity",bl=kt;function Km(r){return gt(gl,bl(r))}var It={code:gl,name:Hm,encode:bl,digest:Km};var oa={};Q(oa,{sha256:()=>_e,sha512:()=>$m});function na({name:r,code:e,encode:t}){return new ra(r,e,t)}var ra=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?gt(this.code,t):t.then(n=>gt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function wl(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var _e=na({name:"sha2-256",code:18,encode:wl("SHA-256")}),$m=na({name:"sha2-512",code:19,encode:wl("SHA-512")});function xl(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return Wm(t,sa(r),e??ge.encoder);default:return zm(t,sa(r),e??Ct.encoder)}}var El=new WeakMap;function sa(r){let e=El.get(r);if(e==null){let t=new Map;return El.set(r,t),t}return e}var Ze=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==Un)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Gm)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=gt(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&&ml(e.multihash,n.multihash)}toString(e){return xl(this,e)}toJSON(){return{"/":xl(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:s,bytes:i}=t;return new r(n,o,s,i??vl(n,o,s.bytes))}else if(t[jm]===!0){let{version:n,multihash:o,code:s}=t,i=mr(o);return r.create(n,s,i)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==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 o=vl(e,t,n.bytes);return new r(e,t,n,o)}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,o=kt(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let s=o.subarray(t.multihashSize-t.digestSize),i=new qr(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[f,m]=Ln(e.subarray(t));return t+=m,f},o=n(),s=Un;if(o===18?(o=0,t=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=t,a=n(),c=n(),u=t+c,l=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(e,t){let[n,o]=qm(e,t),s=r.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return sa(s).set(n,e),s}};function qm(r,e){switch(r[0]){case"Q":{let t=e??ge;return[ge.prefix,t.decode(`${ge.prefix}${r}`)]}case ge.prefix:{let t=e??ge;return[ge.prefix,t.decode(r)]}case Ct.prefix:{let t=e??Ct;return[Ct.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 Wm(r,e,t){let{prefix:n}=t;if(n!==ge.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let s=t.encode(r).slice(1);return e.set(n,s),s}else return o}function zm(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let s=t.encode(r);return e.set(n,s),s}else return o}var Un=112,Gm=18;function vl(r,e,t){let n=$r(r),o=n+$r(e),s=new Uint8Array(o+t.byteLength);return Kr(r,s,0),Kr(e,s,n),s.set(t,o),s}var jm=Symbol.for("@ipld/js-cid/CID");var bt={...Qi,...Wi,...Ji,...$i,...qi,...Gi,...ji,...Ki,...Xi,...zi},yE={...oa,...ta};function Ae(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function De(r=0){return new Uint8Array(r)}function Se(r=0){return new Uint8Array(r)}function 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))),ia=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=Se(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Ym={utf8:Al,"utf-8":Al,hex:bt.base16,latin1:ia,ascii:ia,binary:ia,...bt},Ro=Ym;function J(r,e="utf8"){let t=Ro[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function W(r,e="utf8"){let t=Ro[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var Bl=Symbol.for("nodejs.util.inspect.custom"),Sl=Object.values(bt).map(r=>r.decoder).reduce((r,e)=>r.or(e),bt.identity.decoder),kl=114,ua=36,la=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()})`}[Oi]=!0;toString(){return this.string==null&&(this.string=ge.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return Ze.createV1(kl,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return Ae(this.multihash.bytes,e);if(typeof e=="string")return br(e).equals(this);if(e?.multihash?.bytes!=null)return Ae(this.multihash.bytes,e.multihash.bytes);throw new Error("not valid Id")}[Bl](){return`PeerId(${this.toString()})`}},Wr=class extends On{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},zr=class extends On{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.multihash.digest}},Gr=class extends On{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.multihash.digest}},aa=2336,ca=class{type="url";multihash;privateKey;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=It.digest(J(this.url))}[Bl](){return`PeerId(${this.url})`}[Oi]=!0;toString(){return this.toCID().toString()}toCID(){return Ze.createV1(aa,this.multihash)}toBytes(){return this.toCID().bytes}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=W(e)),e.toString()===this.toString())}};function br(r,e){if(e=e??Sl,r.charAt(0)==="1"||r.charAt(0)==="Q"){let t=mr(ge.decode(`z${r}`));return r.startsWith("12D")?new zr({multihash:t}):r.startsWith("16U")?new Gr({multihash:t}):new Wr({multihash:t})}return Zm(Sl.decode(r))}function Zm(r){try{let e=mr(r);if(e.code===It.code){if(e.digest.length===ua)return new zr({multihash:e});if(e.digest.length===la)return new Gr({multihash:e})}if(e.code===_e.code)return new Wr({multihash:e})}catch{return Xm(Ze.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function Xm(r){if(r==null||r.multihash==null||r.version==null||r.version===1&&r.code!==kl&&r.code!==aa)throw new Error("Supplied PeerID CID is invalid");if(r.code===aa){let t=W(r.multihash.digest);return new ca(new URL(t))}let e=r.multihash;if(e.code===_e.code)return new Wr({multihash:r.multihash});if(e.code===It.code){if(e.digest.length===ua)return new zr({multihash:r.multihash});if(e.digest.length===la)return new Gr({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function fa(r,e){return r.length===ua?new zr({multihash:gt(It.code,r),privateKey:e}):r.length===la?new Gr({multihash:gt(It.code,r),privateKey:e}):new Wr({multihash:await _e.digest(r),publicKey:r,privateKey:e})}var Qm=Math.pow(2,7),eg=Math.pow(2,14),tg=Math.pow(2,21),ha=Math.pow(2,28),da=Math.pow(2,35),pa=Math.pow(2,42),ma=Math.pow(2,49),ne=128,Pe=127;function we(r){if(r<Qm)return 1;if(r<eg)return 2;if(r<tg)return 3;if(r<ha)return 4;if(r<da)return 5;if(r<pa)return 6;if(r<ma)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ga(r,e,t=0){switch(we(r)){case 8:e[t++]=r&255|ne,r/=128;case 7:e[t++]=r&255|ne,r/=128;case 6:e[t++]=r&255|ne,r/=128;case 5:e[t++]=r&255|ne,r/=128;case 4:e[t++]=r&255|ne,r>>>=7;case 3:e[t++]=r&255|ne,r>>>=7;case 2:e[t++]=r&255|ne,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function rg(r,e,t=0){switch(we(r)){case 8:e.set(t++,r&255|ne),r/=128;case 7:e.set(t++,r&255|ne),r/=128;case 6:e.set(t++,r&255|ne),r/=128;case 5:e.set(t++,r&255|ne),r/=128;case 4:e.set(t++,r&255|ne),r>>>=7;case 3:e.set(t++,r&255|ne),r>>>=7;case 2:e.set(t++,r&255|ne),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function ba(r,e){let t=r[e],n=0;if(n+=t&Pe,t<ne||(t=r[e+1],n+=(t&Pe)<<7,t<ne)||(t=r[e+2],n+=(t&Pe)<<14,t<ne)||(t=r[e+3],n+=(t&Pe)<<21,t<ne)||(t=r[e+4],n+=(t&Pe)*ha,t<ne)||(t=r[e+5],n+=(t&Pe)*da,t<ne)||(t=r[e+6],n+=(t&Pe)*pa,t<ne)||(t=r[e+7],n+=(t&Pe)*ma,t<ne))return n;throw new RangeError("Could not decode varint")}function ng(r,e){let t=r.get(e),n=0;if(n+=t&Pe,t<ne||(t=r.get(e+1),n+=(t&Pe)<<7,t<ne)||(t=r.get(e+2),n+=(t&Pe)<<14,t<ne)||(t=r.get(e+3),n+=(t&Pe)<<21,t<ne)||(t=r.get(e+4),n+=(t&Pe)*ha,t<ne)||(t=r.get(e+5),n+=(t&Pe)*da,t<ne)||(t=r.get(e+6),n+=(t&Pe)*pa,t<ne)||(t=r.get(e+7),n+=(t&Pe)*ma,t<ne))return n;throw new RangeError("Could not decode varint")}function yt(r,e,t=0){return e==null&&(e=Se(we(r))),e instanceof Uint8Array?ga(r,e,t):rg(r,e,t)}function rt(r,e=0){return r instanceof Uint8Array?ba(r,e):ng(r,e)}function xe(r,e){e==null&&(e=r.reduce((o,s)=>o+s.length,0));let t=Se(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var No=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-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(s*=e,s+=l,s>u||(i+=1,t!==void 0&&i>t))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let o=n*2;if(n<t.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return t[o]=i[0],t[o+1]=i[1],t[o+2]=i[2],t[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];t[o]=s>>8,t[o+1]=s&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,o]=e(t);if(n===16)return t;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=e(s.subarray(0,i));return t.set(s.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Cl=45,sg=15,jr=new No;function ya(r){if(!(r.length>sg))return jr.new(r).parseWith(()=>jr.readIPv4Addr())}function wa(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Cl))return jr.new(r).parseWith(()=>jr.readIPv6Addr())}function Lo(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Cl))return jr.new(r).parseWith(()=>jr.readIPAddr())}var JE=parseInt("0xFFFF",16),QE=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Uo(r){return!!ya(r)}function Oo(r){return!!wa(r)}function Po(r){return!!Lo(r)}var _l=Uo,lg=Oo,xa=function(r){let e=0;if(r=r.toString().trim(),_l(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(lg(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let s=_l(t[n]),i;s&&(i=xa(t[n]),t[n]=W(i.slice(0,2),"base16")),i!=null&&++n<8&&t.splice(n,0,W(i.slice(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let s=[n,1];for(n=9-t.length;n>0;n--)s.push("0");t.splice.apply(t,s)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){let s=parseInt(t[n],16);o[e++]=s>>8&255,o[e++]=s&255}return o}throw new Error("invalid ip address")},Rl=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let o=[];for(let s=0;s<t;s++)o.push(r[e+s]);return o.join(".")}if(t===16){let o=[];for(let s=0;s<t;s+=2)o.push(n.getUint16(e+s).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var Yr={},Ea={},hg=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,-1,"http-path"],[777,-1,"memory"]];hg.forEach(r=>{let e=dg(...r);Ea[e.code]=e,Yr[e.name]=e});function dg(r,e,t,n,o){return{code:r,size:e,name:t,resolvable:!!n,path:!!o}}function oe(r){if(typeof r=="number"){if(Ea[r]!=null)return Ea[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(Yr[r]!=null)return Yr[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var O8=oe("ip4"),P8=oe("ip6"),M8=oe("ipcidr");function Sa(r,e){switch(oe(r).code){case 4:case 41:return mg(e);case 42:return Da(e);case 6:case 273:case 33:case 132:return Ul(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Da(e);case 421:return wg(e);case 444:return Ll(e);case 445:return Ll(e);case 466:return yg(e);case 481:return globalThis.encodeURIComponent(Da(e));default:return W(e,"base16")}}function Ba(r,e){switch(oe(r).code){case 4:return Nl(e);case 41:return Nl(e);case 42:return Aa(e);case 6:case 273:case 33:case 132:return ka(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Aa(e);case 421:return gg(e);case 444:return xg(e);case 445:return Eg(e);case 466:return bg(e);case 481:return Aa(globalThis.decodeURIComponent(e));default:return J(e,"base16")}}var va=Object.values(bt).map(r=>r.decoder),pg=function(){let r=va[0].or(va[1]);return va.slice(2).forEach(e=>r=r.or(e)),r}();function Nl(r){if(!Po(r))throw new Error("invalid ip address");return xa(r)}function mg(r){let e=Rl(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!Po(e))throw new Error("invalid ip address");return e}function ka(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function Ul(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Aa(r){let e=J(r),t=Uint8Array.from(yt(e.length));return xe([t,e],t.length+e.length)}function Da(r){let e=rt(r);if(r=r.slice(we(e)),r.length!==e)throw new Error("inconsistent lengths");return W(r)}function gg(r){let e;r[0]==="Q"||r[0]==="1"?e=mr(ge.decode(`z${r}`)).bytes:e=Ze.parse(r).multihash.bytes;let t=Uint8Array.from(yt(e.length));return xe([t,e],t.length+e.length)}function bg(r){let e=pg.decode(r),t=Uint8Array.from(yt(e.length));return xe([t,e],t.length+e.length)}function yg(r){let e=rt(r),t=r.slice(we(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+W(t,"base64url")}function wg(r){let e=rt(r),t=r.slice(we(e));if(t.length!==e)throw new Error("inconsistent lengths");return W(t,"base58btc")}function xg(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=Ct.decode("b"+e[0]),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ka(n);return xe([t,o],t.length+o.length)}function Eg(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let t=Ct.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ka(n);return xe([t,o],t.length+o.length)}function Ll(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=W(e,"base32"),o=Ul(t);return`${n}:${o}`}function Ol(r){r=Ca(r);let e=[],t=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let s=0;s<o.length;s++){let i=o[s],a=oe(i);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(s++,s>=o.length)throw Ml("invalid address: "+r);if(a.path===!0){n=Ca(o.slice(s).join("/")),e.push([a.code,Ba(a.code,n)]),t.push([a.code,n]);break}let c=Ba(a.code,o[s]);e.push([a.code,c]),t.push([a.code,Sa(a.code,c)])}return{string:Pl(t),bytes:Ta(e),tuples:e,stringTuples:t,path:n}}function Ia(r){let e=[],t=[],n=null,o=0;for(;o<r.length;){let s=rt(r,o),i=we(s),a=oe(s),c=vg(a,r.slice(o+i));if(c===0){e.push([s]),t.push([s]),o+=i;continue}let u=r.slice(o+i,o+i+c);if(o+=c+i,o>r.length)throw Ml("Invalid address Uint8Array: "+W(r,"base16"));e.push([s,u]);let l=Sa(s,u);if(t.push([s,l]),a.path===!0){n=l;break}}return{bytes:Uint8Array.from(r),string:Pl(t),tuples:e,stringTuples:t,path:n}}function Pl(r){let e=[];return r.map(t=>{let n=oe(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),Ca(e.join("/"))}function Ta(r){return xe(r.map(e=>{let t=oe(e[0]),n=Uint8Array.from(yt(t.code));return e.length>1&&e[1]!=null&&(n=xe([n,e[1]])),n}))}function vg(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=rt(e instanceof Uint8Array?e:Uint8Array.from(e));return t+we(t)}}function Ca(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}function Ml(r){return new Error("Error parsing address: "+r)}var Ag=Symbol.for("nodejs.util.inspect.custom"),_a=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Dg=[oe("dns").code,oe("dns4").code,oe("dns6").code,oe("dnsaddr").code],Mo=class r{bytes;#e;#t;#r;#n;[_a]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=Ia(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=Ol(e)}else if(Vl(e))t=Ia(e.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=t.bytes,this.#e=t.string,this.#t=t.tuples,this.#r=t.stringTuples,this.#n=t.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let e,t,n,o,s="",i=oe("tcp"),a=oe("udp"),c=oe("ip4"),u=oe("ip6"),l=oe("dns6"),f=oe("ip6zone");for(let[g,p]of this.stringTuples())g===f.code&&(s=`%${p??""}`),Dg.includes(g)&&(t=i.name,o=443,n=`${p??""}${s}`,e=g===l.code?6:4),(g===i.code||g===a.code)&&(t=oe(g).name,o=parseInt(p??"")),(g===c.code||g===u.code)&&(t=oe(g).name,n=`${p??""}${s}`,e=g===u.code?6:4);if(e==null||t==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:e,host:n,transport:t,port:o}}protos(){return this.#t.map(([e])=>Object.assign({},oe(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>oe(e).name)}tuples(){return this.#t}stringTuples(){return this.#r}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,o))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(Ta(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,o])=>{n===Yr.p2p.code&&e.push([n,o]),n===Yr["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?W(ge.decode(`z${n}`),"base58btc"):W(Ze.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(e){return Ae(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(s=>s.resolvable);if(t==null)return[this];let n=Fl.get(t.name);if(n==null)throw new L(`no available resolver for ${t.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,e)).map(s=>nt(s))}nodeAddress(){let e=this.toOptions();if(e.transport!=="tcp"&&e.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(e){let t=(e??this).protos();return!(t.length!==2||t[0].code!==4&&t[0].code!==41||t[1].code!==6&&t[1].code!==273)}[Ag](){return`Multiaddr(${this.#e})`}};var Fl=new Map;function Vl(r){return!!r?.[_a]}function nt(r){return new Mo(r)}var Sg=r=>r.toString().split("/").slice(1),Mn=r=>({match:e=>e.length<1?!1:r(e[0])?e.slice(1):!1,pattern:"fn"}),ee=r=>({match:e=>Mn(t=>t===r).match(e),pattern:r}),Ho=()=>({match:r=>Mn(e=>typeof e=="string").match(r),pattern:"{string}"}),Ko=()=>({match:r=>Mn(e=>!isNaN(parseInt(e))).match(r),pattern:"{number}"}),Re=()=>({match:r=>{if(r.length<2||r[0]!=="p2p"&&r[0]!=="ipfs")return!1;if(r[1].startsWith("Q")||r[1].startsWith("1"))try{ge.decode(`z${r[1]}`)}catch{return!1}else return!1;return r.slice(2)},pattern:"/p2p/{peerid}"}),Fo=()=>({match:r=>{if(r.length<2||r[0]!=="certhash")return!1;try{Zi.decode(r[1])}catch{return!1}return r.slice(2)},pattern:"/certhash/{certhash}"}),Be=r=>({match:e=>{let t=r.match(e);return t===!1?e:t},pattern:`optional(${r.pattern})`}),Xe=(...r)=>({match:e=>{let t;for(let n of r){let o=n.match(e);o!==!1&&(t==null||o.length<t.length)&&(t=o)}return t??!1},pattern:`or(${r.map(e=>e.pattern).join(", ")})`}),ie=(...r)=>({match:e=>{for(let t of r){let n=t.match(e);if(n===!1)return!1;e=n}return e},pattern:`and(${r.map(e=>e.pattern).join(", ")})`});function be(...r){function e(o){let s=Sg(o);for(let i of r){let a=i.match(s);if(a===!1)return!1;s=a}return s}function t(o){return e(o)!==!1}function n(o){let s=e(o);return s===!1?!1:s.length===0}return{matches:t,exactMatch:n}}var Na=ie(ee("dns4"),Ho()),La=ie(ee("dns6"),Ho()),Ua=ie(ee("dnsaddr"),Ho()),Hl=ie(ee("dns"),Ho()),dv=be(Na),pv=be(La),mv=be(Ua),gv=be(Xe(Hl,Ua,Na,La)),Kl=ie(ee("ip4"),Mn(Uo)),$l=ie(ee("ip6"),Mn(Oo)),ql=Xe(Kl,$l),wt=Xe(ql,Hl,Na,La,Ua),bv=be(wt),yv=be(Kl),wv=be($l),xv=be(ql),Oa=ie(wt,ee("tcp"),Ko()),Fn=ie(wt,ee("udp"),Ko()),Ev=be(Oa),vv=be(Fn),Pa=ie(Fn,ee("quic")),$o=ie(Fn,ee("quic-v1")),Bg=Xe(Pa,$o),Av=be(Pa),Dv=be($o),Ra=Xe(wt,Oa,Fn,Pa,$o),Wl=Xe(ie(Ra,ee("ws"),Be(Re()))),Sv=be(Wl),zl=Xe(ie(Ra,ee("wss"),Be(Re())),ie(Ra,ee("tls"),ee("ws"),Be(Re()))),Bv=be(zl),Gl=ie(Fn,ee("webrtc-direct"),Be(Fo()),Be(Fo()),Be(Re())),jl=be(Gl),Yl=ie($o,ee("webtransport"),Be(Fo()),Be(Fo()),Be(Re())),kv=be(Yl),Vo=Xe(Wl,zl,ie(Oa,Be(Re())),ie(Bg,Be(Re())),ie(wt,Be(Re())),Gl,Yl,Re()),Cv=be(Vo),kg=ie(Vo,ee("p2p-circuit"),Re()),Iv=be(kg),Cg=Xe(ie(Vo,ee("p2p-circuit"),ee("webrtc"),Be(Re())),ie(Vo,ee("webrtc"),Be(Re())),ee("webrtc")),Zl=be(Cg),Ig=Xe(ie(wt,ee("tcp"),Ko(),ee("http"),Be(Re())),ie(wt,ee("http"),Be(Re()))),Tv=be(Ig),Tg=Xe(ie(wt,ee("tcp"),Xe(ie(ee("443"),ee("http")),ie(Ko(),ee("https"))),Be(Re())),ie(wt,ee("tls"),ee("http"),Be(Re())),ie(wt,ee("https"),Be(Re()))),_v=be(Tg);var Ge;(function(r){r.ERR_ALREADY_ABORTED="ERR_ALREADY_ABORTED",r.ERR_DATA_CHANNEL="ERR_DATA_CHANNEL",r.ERR_CONNECTION_CLOSED="ERR_CONNECTION_CLOSED",r.ERR_HASH_NOT_SUPPORTED="ERR_HASH_NOT_SUPPORTED",r.ERR_INVALID_MULTIADDR="ERR_INVALID_MULTIADDR",r.ERR_INVALID_FINGERPRINT="ERR_INVALID_FINGERPRINT",r.ERR_INVALID_PARAMETERS="ERR_INVALID_PARAMETERS",r.ERR_NOT_IMPLEMENTED="ERR_NOT_IMPLEMENTED",r.ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS="ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS",r.ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS="ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS"})(Ge||(Ge={}));var Yt=class extends L{constructor(e,t){super(`WebRTC transport error: ${e}`,t??""),this.name="WebRTCTransportError"}};var Ma=class extends Yt{constructor(e,t){super(`[stream: ${e}] data channel error: ${t}`,Ge.ERR_DATA_CHANNEL),this.name="WebRTC/DataChannelError"}};function qa(r,e){return new Ma(r,e)}var Fa=class extends Yt{constructor(e){super(`There was a problem with the Multiaddr which was passed in: ${e}`,Ge.ERR_INVALID_MULTIADDR),this.name="WebRTC/InappropriateMultiaddrError"}};function qo(r){return new Fa(r)}var Va=class extends Yt{constructor(e){super(`There was a problem with a provided argument: ${e}`,Ge.ERR_INVALID_PARAMETERS),this.name="WebRTC/InvalidArgumentError"}};function Vn(r){return new Va(r)}var Ha=class extends Yt{constructor(e,t){super(`Invalid fingerprint "${e}" within ${t}`,Ge.ERR_INVALID_FINGERPRINT),this.name="WebRTC/InvalidFingerprintError"}};function Wa(r,e){return new Ha(r,e)}var Ka=class extends Yt{constructor(e){super(`A method (${e}) was called though it has been intentionally left unimplemented.`,Ge.ERR_NOT_IMPLEMENTED),this.name="WebRTC/UnimplementedError"}};function Xl(r){return new Ka(r)}var $a=class extends Yt{constructor(e){super(`unsupported hash algorithm: ${e}`,Ge.ERR_HASH_NOT_SUPPORTED),this.name="WebRTC/UnsupportedHashAlgorithmError"}};function Jl(r){return new $a(r)}var Ql=function(r,e,t){if(t||arguments.length===2)for(var n=0,o=e.length,s;n<o;n++)(s||!(n in e))&&(s||(s=Array.prototype.slice.call(e,0,n)),s[n]=e[n]);return r.concat(s||Array.prototype.slice.call(e))},_g=function(){function r(e,t,n){this.name=e,this.version=t,this.os=n,this.type="browser"}return r}();var Rg=function(){function r(e){this.version=e,this.type="node",this.name="node",this.os=process.platform}return r}();var Ng=function(){function r(e,t,n,o){this.name=e,this.version=t,this.os=n,this.bot=o,this.type="bot-device"}return r}();var Lg=function(){function r(){this.type="bot",this.bot=!0,this.name="bot",this.version=null,this.os=null}return r}();var Ug=function(){function r(){this.type="react-native",this.name="react-native",this.version=null,this.os=null}return r}();var Og=/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/,Pg=/(nuhk|curl|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask\ Jeeves\/Teoma|ia_archiver)/,ef=3,Mg=[["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",Og]],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 Ug:typeof navigator<"u"?rf(navigator.userAgent):Hg()}function Fg(r){return r!==""&&Mg.reduce(function(e,t){var n=t[0],o=t[1];if(e)return e;var s=o.exec(r);return!!s&&[n,s]},!1)}function rf(r){var e=Fg(r);if(!e)return null;var t=e[0],n=e[1];if(t==="searchbot")return new Lg;var o=n[1]&&n[1].split(".").join("_").split("_").slice(0,3);o?o.length<ef&&(o=Ql(Ql([],o,!0),Kg(ef-o.length),!0)):o=[];var s=o.join("."),i=Vg(r),a=Pg.exec(r);return a&&a[1]?new Ng(t,s,i,a[1]):new _g(t,s,i)}function Vg(r){for(var e=0,t=tf.length;e<t;e++){var n=tf[e],o=n[0],s=n[1],i=s.exec(r);if(i)return o}return null}function Hg(){var r=typeof process<"u"&&process.version;return r?new Rg(process.version.slice(1)):null}function Kg(r){for(var e=[],t=0;t<r;t++)e.push("0");return e}function pe(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var Zr=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},za=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},of=r=>globalThis.DOMException===void 0?new za(r):new DOMException(r),sf=r=>{let e=r.reason===void 0?of("This operation was aborted."):r.reason;return e instanceof Error?e:of(e)};function yr(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:s={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(sf(m)),m.addEventListener("abort",()=>{l(sf(m))})}if(t===Number.POSITIVE_INFINITY){r.then(u,l);return}let f=new Zr;i=s.setTimeout.call(void 0,()=>{if(n){try{u(n())}catch(m){l(m)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?u():o instanceof Error?l(o):(f.message=o??`Promise timed out after ${t} milliseconds`,l(f))},t),(async()=>{try{u(await r)}catch(m){l(m)}})()}).finally(()=>{c.clear()});return c.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},c}var af=["stun:stun.l.google.com:19302","stun:stun1.l.google.com:19302","stun:stun2.l.google.com:19302","stun:stun3.l.google.com:19302","stun:stun4.l.google.com:19302","stun:global.stun.twilio.com:3478","stun:stun.cloudflare.com:3478","stun:stun.services.mozilla.com:3478","stun:stun.1und1.de:3478"];var cf=nf(),Hn=cf!=null&&cf.name==="firefox",Wo=async function*(){},zo=async r=>{},$g=30*1e3;function uf(r,e,t=$g,n){r.readyState==="open"&&Promise.resolve().then(async()=>{if(r.bufferedAmount>0){n.log("%s drain channel with %d buffered bytes",e,r.bufferedAmount);let o=pe(),s=!1;r.bufferedAmountLowThreshold=0;let i=()=>{s||(n.log("%s drain channel closed before drain",e),o.resolve())};r.addEventListener("close",i,{once:!0}),r.addEventListener("bufferedamountlow",()=>{s=!0,r.removeEventListener("close",i),o.resolve()}),await yr(o.promise,{milliseconds:t})}}).then(async()=>{r.readyState==="open"&&r.close()}).catch(o=>{n.log.error("error closing outbound stream",o)})}async function Kn(r){return r=r??{},typeof r=="function"&&(r=await r()),r.iceServers=r.iceServers??af.map(e=>({urls:[e]})),r}var wr=class{log;peerConnection;remoteAddr;timeline;metrics;source=Wo();sink=zo;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 Go=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}},Xr=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Go(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 Go(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 Ga=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function Zt(r={}){return qg(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 qg(r,e){e=e??{};let t=e.onEnd,n=new Xr,o,s,i,a=pe(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((d,y)=>{s=x=>{s=null,n.push(x);try{d(r(n))}catch(b){y(b)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=pe()})}},u=d=>s!=null?s(d):(n.push(d),o),l=d=>(n=new Xr,s!=null?s({error:d}):(n.push({error:d}),o)),f=d=>{if(i)return o;if(e?.objectMode!==!0&&d?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:d})},m=d=>i?o:(i=!0,d!=null?l(d):u({done:!0})),g=()=>(n=new Xr,m(),{done:!0}),p=d=>(m(d),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:g,throw:p,push:f,end:m,get readableLength(){return n.size},onEmpty:async d=>{let y=d?.signal;if(y?.throwIfAborted(),n.isEmpty())return;let x,b;y!=null&&(x=new Promise((A,E)=>{b=()=>{E(new Ga)},y.addEventListener("abort",b)}));try{await Promise.race([a.promise,x])}finally{b!=null&&y!=null&&y?.removeEventListener("abort",b)}}},t==null)return o;let h=o;return o={[Symbol.asyncIterator](){return this},next(){return h.next()},throw(d){return h.throw(d),t!=null&&(t(d),t=void 0),{done:!0}},return(){return h.return(),t!=null&&(t(),t=void 0),{done:!0}},push:f,end(d){return h.end(d),t!=null&&(t(d),t=void 0),o},get readableLength(){return h.readableLength},onEmpty:d=>h.onEmpty(d)},o}var jo=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 Tt(r,e,t){if(e==null)return r;if(e.aborted)return Promise.reject(new jo(t?.errorMessage,t?.errorCode));let n,o=new jo(t?.errorMessage,t?.errorCode);try{return await Promise.race([r,new Promise((s,i)=>{n=()=>{i(o)},e.addEventListener("abort",n)})])}finally{n!=null&&e.removeEventListener("abort",n)}}var ff=Symbol.for("@achingbrain/uint8arraylist");function lf(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let o=t+n.byteLength;if(e<o)return{buf:n,index:e-t};t=o}throw new RangeError("index is out of bounds")}function Yo(r){return!!r?.[ff]}var le=class r{bufs;length;[ff]=!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(Yo(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(Yo(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=lf(this.bufs,e);return t.buf[t.index]}set(e,t){let n=lf(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(Yo(e))for(let n=0;n<e.length;n++)this.set(t+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:n,length:o}=this._subList(e,t);return xe(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:xe(n,o)}sublist(e,t){let{bufs:n,length:o}=this._subList(e,t),s=new r;return s.length=o,s.bufs=[...n],s}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,e>=c)continue;let 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(!Yo(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let f=0;f<s;f++)i[f]=-1;for(let f=0;f<o;f++)i[n[f]]=f;let a=i,c=this.byteLength-n.byteLength,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=Se(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){let o=De(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,t,n),this.write(o,e)}getInt32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){let o=De(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,t,n),this.write(o,e)}getBigInt64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){let o=De(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,t,n),this.write(o,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let n=Se(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){let o=De(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,t,n),this.write(o,e)}getUint32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){let o=De(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,t,n),this.write(o,e)}getBigUint64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){let o=De(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,t,n),this.write(o,e)}getFloat32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){let o=De(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,t,n),this.write(o,e)}getFloat64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){let o=De(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,t,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof r)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!Ae(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((o,s)=>o+s.byteLength,0)),n.length=t,n}};function hf(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 df(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function pf(r,e){let t=hf(r).return?.();df(t)&&t.catch(n=>{e.error("could not cause iterator to return",n)})}var Wg="ERR_STREAM_RESET",zg="ERR_SINK_INVALID_STATE",Gg=5e3;function ja(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Zo=class{id;direction;timeline;protocol;metadata;source;status;readStatus;writeStatus;log;sinkController;sinkEnd;closed;endErr;streamSource;onEnd;onCloseRead;onCloseWrite;onReset;onAbort;sendCloseWriteTimeout;sendingData;constructor(e){this.sinkController=new AbortController,this.sinkEnd=pe(),this.closed=pe(),this.log=e.log,this.status="open",this.readStatus="ready",this.writeStatus="ready",this.id=e.id,this.metadata=e.metadata??{},this.direction=e.direction,this.timeline={open:Date.now()},this.sendCloseWriteTimeout=e.sendCloseWriteTimeout??Gg,this.onEnd=e.onEnd,this.onCloseRead=e?.onCloseRead,this.onCloseWrite=e?.onCloseWrite,this.onReset=e?.onReset,this.onAbort=e?.onAbort,this.source=this.streamSource=Zt({onEnd:t=>{t!=null?this.log.trace("source ended with error",t):this.log.trace("source ended"),this.onSourceEnd(t)}}),this.sink=this.sink.bind(this)}async sink(e){if(this.writeStatus!=="ready")throw new L(`writable end state is "${this.writeStatus}" not "ready"`,zg);try{this.writeStatus="writing";let t={signal:this.sinkController.signal};if(this.direction==="outbound"){let o=this.sendNewStream(t);ja(o)&&await o}let n=()=>{pf(e,this.log)};try{this.sinkController.signal.addEventListener("abort",n),this.log.trace("sink reading from source");for await(let o of e){o=o instanceof Uint8Array?new le(o):o;let s=this.sendData(o,t);ja(s)&&(this.sendingData=pe(),await s,this.sendingData.resolve(),this.sendingData=void 0)}}finally{this.sinkController.signal.removeEventListener("abort",n)}this.log.trace('sink finished reading from source, write status is "%s"',this.writeStatus),this.writeStatus==="writing"&&(this.writeStatus="closing",this.log.trace("send close write to remote"),await this.sendCloseWrite({signal:AbortSignal.timeout(this.sendCloseWriteTimeout)}),this.writeStatus="closed"),this.onSinkEnd()}catch(t){throw this.log.trace("sink ended with error, calling abort with error",t),this.abort(t),t}finally{this.log.trace("resolve sink end"),this.sinkEnd.resolve()}}onSourceEnd(e){this.timeline.closeRead==null&&(this.timeline.closeRead=Date.now(),this.readStatus="closed",e!=null&&this.endErr==null&&(this.endErr=e),this.onCloseRead?.(),this.timeline.closeWrite!=null?(this.log.trace("source and sink ended"),this.timeline.close=Date.now(),this.status!=="aborted"&&this.status!=="reset"&&(this.status="closed"),this.onEnd!=null&&this.onEnd(this.endErr),this.closed.resolve()):this.log.trace("source ended, waiting for sink to end"))}onSinkEnd(e){this.timeline.closeWrite==null&&(this.timeline.closeWrite=Date.now(),this.writeStatus="closed",e!=null&&this.endErr==null&&(this.endErr=e),this.onCloseWrite?.(),this.timeline.closeRead!=null?(this.log.trace("sink and source ended"),this.timeline.close=Date.now(),this.status!=="aborted"&&this.status!=="reset"&&(this.status="closed"),this.onEnd!=null&&this.onEnd(this.endErr),this.closed.resolve()):this.log.trace("sink ended, waiting for source to end"))}async close(e){this.log.trace("closing gracefully"),this.status="closing",await Tt(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 Tt(this.sink([]),e.signal)),this.writeStatus==="writing"&&(this.sendingData!=null&&await Tt(this.sendingData.promise,e.signal),this.log.trace("aborting source passed to .sink"),this.sinkController.abort(),await Tt(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();ja(t)&&t.catch(n=>{this.log.error("error sending reset message",n)}),this.status="aborted",this.timeline.abort=Date.now(),this._closeSinkAndSource(e),this.onAbort?.(e)}reset(){if(this.status==="closed"||this.status==="aborted"||this.status==="reset")return;let e=new L("stream reset",Wg);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 Xo(r){return r[Symbol.asyncIterator]!=null}var Jo=r=>{let e=we(r),t=Se(e);return yt(r,t),Jo.bytes=e,t};Jo.bytes=0;function $n(r,e){e=e??{};let t=e.lengthEncoder??Jo;function*n(o){let s=t(o.byteLength);s instanceof Uint8Array?yield s:yield*s,o instanceof Uint8Array?yield o:yield*o}return Xo(r)?async function*(){for await(let o of r)yield*n(o)}():function*(){for(let o of r)yield*n(o)}()}$n.single=(r,e)=>{e=e??{};let t=e.lengthEncoder??Jo;return new le(t(r.byteLength),r)};var Jr=Bo(bf(),1);var Yg=8,Zg=1024*1024*4,xr;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(xr||(xr={}));var Ya=r=>{let e=rt(r);return Ya.bytes=we(e),e};Ya.bytes=0;function Er(r,e){let t=new le,n=xr.LENGTH,o=-1,s=e?.lengthDecoder??Ya,i=e?.maxLengthLength??Yg,a=e?.maxDataLength??Zg;function*c(){for(;t.byteLength>0;){if(n===xr.LENGTH)try{if(o=s(t),o<0)throw(0,Jr.default)(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(o>a)throw(0,Jr.default)(new Error("message length too long"),"ERR_MSG_DATA_TOO_LONG");let u=s.bytes;t.consume(u),e?.onLength!=null&&e.onLength(o),n=xr.DATA}catch(u){if(u instanceof RangeError){if(t.byteLength>i)throw(0,Jr.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw u}if(n===xr.DATA){if(t.byteLength<o)break;let u=t.sublist(0,o);t.consume(o),e?.onData!=null&&e.onData(u),yield u,n=xr.LENGTH}}}return Xo(r)?async function*(){for await(let u of r)t.append(u),yield*c();if(t.byteLength>0)throw(0,Jr.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,Jr.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}()}Er.fromReader=(r,e)=>{let t=1,n=async function*(){for(;;)try{let{done:s,value:i}=await r.next(t);if(s===!0)return;i!=null&&(yield i)}catch(s){if(s.code==="ERR_UNDER_READ")return{done:!0,value:null};throw s}finally{t=1}}();return Er(n,{...e??{},onLength:s=>{t=s}})};var Jg=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 Qg(r,e,t){let n,o=new Promise((s,i)=>{if(t={rejectionEvents:["error"],multiArgs:!1,resolveImmediately:!1,...t},!(t.count>=0&&(t.count===Number.POSITIVE_INFINITY||Number.isInteger(t.count))))throw new TypeError("The `count` option should be at least 0 or more");t.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:u,removeListener:l}=Jg(r),f=(...g)=>{let p=t.multiArgs?g:g[0];t.filter&&!t.filter(p)||(c.push(p),t.count===c.length&&(n(),s(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&&s(c)});if(o.cancel=n,typeof t.timeout=="number"){let s=yr(o,{milliseconds:t.timeout});return s.cancel=n,s}return o}function Za(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=Qg(r,e,t),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}var Xa=new Float32Array([-0]),Xt=new Uint8Array(Xa.buffer);function yf(r,e,t){Xa[0]=r,e[t]=Xt[0],e[t+1]=Xt[1],e[t+2]=Xt[2],e[t+3]=Xt[3]}function wf(r,e){return Xt[0]=r[e],Xt[1]=r[e+1],Xt[2]=r[e+2],Xt[3]=r[e+3],Xa[0]}var Ja=new Float64Array([-0]),Me=new Uint8Array(Ja.buffer);function xf(r,e,t){Ja[0]=r,e[t]=Me[0],e[t+1]=Me[1],e[t+2]=Me[2],e[t+3]=Me[3],e[t+4]=Me[4],e[t+5]=Me[5],e[t+6]=Me[6],e[t+7]=Me[7]}function Ef(r,e){return Me[0]=r[e],Me[1]=r[e+1],Me[2]=r[e+2],Me[3]=r[e+3],Me[4]=r[e+4],Me[5]=r[e+5],Me[6]=r[e+6],Me[7]=r[e+7],Ja[0]}var eb=BigInt(Number.MAX_SAFE_INTEGER),tb=BigInt(Number.MIN_SAFE_INTEGER),je=class r{lo;hi;constructor(e,t){this.lo=e|0,this.hi=t|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(t+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(BigInt(t)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?t===0?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return vr;if(e<eb&&e>tb)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let n=e>>32n,o=e-(n<<32n);return t&&(n=~n|0n,o=~o|0n,++o>vf&&(o=0n,++n>vf&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return vr;let t=e<0;t&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return t&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(e){return typeof e=="number"?r.fromNumber(e):typeof e=="bigint"?r.fromBigInt(e):typeof e=="string"?r.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new r(e.low>>>0,e.high>>>0):vr}},vr=new je(0,0);vr.toBigInt=function(){return 0n};vr.zzEncode=vr.zzDecode=function(){return this};vr.length=function(){return 1};var vf=4294967296n;function Af(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 Df(r,e,t){if(t-e<1)return"";let o,s=[],i=0,a;for(;e<t;)a=r[e++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|r[e++]&63:a>239&&a<365?(a=((a&7)<<18|(r[e++]&63)<<12|(r[e++]&63)<<6|r[e++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Qa(r,e,t){let n=t,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,e[t++]=o>>18|240,e[t++]=o>>12&63|128,e[t++]=o>>6&63|128,e[t++]=o&63|128):(e[t++]=o>>12|224,e[t++]=o>>6&63|128,e[t++]=o&63|128);return t-n}function ot(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function Qo(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var ec=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,ot(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 ot(this,4);return Qo(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw ot(this,4);return Qo(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw ot(this,4);let e=wf(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw ot(this,4);let e=Ef(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 ot(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return Df(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw ot(this,e);this.pos+=e}else do if(this.pos>=this.len)throw ot(this);while(this.buf[this.pos++]&128);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new je(0,0),t=0;if(this.len-this.pos>4){for(;t<4;++t)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;t=0}else{for(;t<3;++t){if(this.pos>=this.len)throw ot(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 ot(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 ot(this,8);let e=Qo(this.buf,this.pos+=4),t=Qo(this.buf,this.pos+=4);return new je(e,t)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=ba(this.buf,this.pos);return this.pos+=we(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function tc(r){return new ec(r instanceof Uint8Array?r:r.subarray())}function st(r,e,t){let n=tc(r);return e.decode(n,void 0,t)}function rc(r){let e=r??8192,t=e>>>1,n,o=e;return function(i){if(i<1||i>t)return Se(i);o+i>e&&(n=Se(e),o=0);let a=n.subarray(o,o+=i);return o&7&&(o=(o|7)+1),a}}var Ar=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function nc(){}var sc=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},rb=rc();function nb(r){return globalThis.Buffer!=null?Se(r):rb(r)}var Wn=class{len;head;tail;states;constructor(){this.len=0,this.head=new Ar(nc,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new Ar(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new ic((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(es,10,je.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=je.fromBigInt(e);return this._push(es,t.length(),t)}uint64Number(e){return this._push(ga,we(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let t=je.fromBigInt(e).zzEncode();return this._push(es,t.length(),t)}sint64Number(e){let t=je.fromNumber(e).zzEncode();return this._push(es,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(oc,1,e?1:0)}fixed32(e){return this._push(qn,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=je.fromBigInt(e);return this._push(qn,4,t.lo)._push(qn,4,t.hi)}fixed64Number(e){let t=je.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(yf,4,e)}double(e){return this._push(xf,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(oc,1,0):this.uint32(t)._push(sb,t,e)}string(e){let t=Af(e);return t!==0?this.uint32(t)._push(Qa,t,e):this._push(oc,1,0)}fork(){return this.states=new sc(this),this.head=this.tail=new Ar(nc,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 Ar(nc,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=nb(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function oc(r,e,t){e[t]=r&255}function ob(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var ic=class extends Ar{next;constructor(e,t){super(ob,e,t),this.next=void 0}};function es(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 sb(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(ib,e,r),this},Wn.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(ab,e,r),this});function ib(r,e,t){e.set(r,t)}function ab(r,e,t){r.length<40?Qa(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(J(r),t)}function ac(){return new Wn}function it(r,e){let t=ac();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var Qr;(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"})(Qr||(Qr={}));function ts(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function Dr(r){function e(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let t=function(s,i){let a=e(s);i.int32(a)},n=function(s){let i=s.int32();return e(i)};return ts("enum",Qr.VARINT,t,n)}function at(r,e){return ts("message",Qr.LENGTH_DELIMITED,r,e)}var $e;(function(r){let e;(function(o){o.FIN="FIN",o.STOP_SENDING="STOP_SENDING",o.RESET="RESET",o.FIN_ACK="FIN_ACK"})(e=r.Flag||(r.Flag={}));let t;(function(o){o[o.FIN=0]="FIN",o[o.STOP_SENDING=1]="STOP_SENDING",o[o.RESET=2]="RESET",o[o.FIN_ACK=3]="FIN_ACK"})(t||(t={})),function(o){o.codec=()=>Dr(t)}(e=r.Flag||(r.Flag={}));let n;r.codec=()=>(n==null&&(n=at((o,s,i={})=>{i.lengthDelimited!==!1&&s.fork(),o.flag!=null&&(s.uint32(8),r.Flag.codec().encode(o.flag,s)),o.message!=null&&(s.uint32(18),s.bytes(o.message)),i.lengthDelimited!==!1&&s.ldelim()},(o,s)=>{let i={},a=s==null?o.len:o.pos+s;for(;o.pos<a;){let c=o.uint32();switch(c>>>3){case 1:i.flag=r.Flag.codec().decode(o);break;case 2:i.message=o.bytes();break;default:o.skipType(c&7);break}}return i})),n),r.encode=o=>it(o,r.codec()),r.decode=o=>st(o,r.codec())})($e||($e={}));var cb=16*1024*1024,ub=30*1e3,lb=5,fb=2,hb=16*1024,db=5e3,pb=5e3,cc=class extends Zo{channel;incomingData;maxBufferedAmount;bufferedAmountLowEventTimeout;maxMessageSize;receiveFinAck;finAckTimeout;openTimeout;constructor(e){let t=e.onEnd;switch(e.onEnd=o=>{this.log.trace("readable and writeable ends closed",this.status),Promise.resolve(async()=>{if(!(this.timeline.abort!=null||this.timeline.reset!==null))try{await yr(this.receiveFinAck.promise,{milliseconds:this.finAckTimeout})}catch(s){this.log.error("error receiving FIN_ACK",s)}}).then(()=>{this.incomingData.end(),t?.(o)}).catch(s=>{this.log.error("error ending stream",s)})},super(e),this.channel=e.channel,this.channel.binaryType="arraybuffer",this.incomingData=Zt(),this.bufferedAmountLowEventTimeout=e.bufferedAmountLowEventTimeout??ub,this.maxBufferedAmount=e.maxBufferedAmount??cb,this.maxMessageSize=(e.maxMessageSize??hb)-lb-fb,this.receiveFinAck=pe(),this.finAckTimeout=e.closeTimeout??db,this.openTimeout=e.openTimeout??pb,this.channel.readyState){case"open":this.timeline.open=new Date().getTime();break;case"closed":case"closing":(this.timeline.close===void 0||this.timeline.close===0)&&(this.timeline.close=Date.now());break;case"connecting":break;default:throw this.log.error("unknown datachannel state %s",this.channel.readyState),new L("Unknown datachannel state","ERR_INVALID_STATE")}this.channel.onopen=o=>{this.timeline.open=new Date().getTime()},this.channel.onclose=o=>{this.receiveFinAck.resolve(),this.close().catch(s=>{this.log.error("error closing stream after channel closed",s)})},this.channel.onerror=o=>{let s=o.error;this.abort(s)},this.channel.onmessage=async o=>{let{data:s}=o;s===null||s.byteLength===0||this.incomingData.push(new Uint8Array(s,0,s.byteLength))};let n=this;Promise.resolve().then(async()=>{for await(let o of Er(this.incomingData)){let s=n.processIncomingProtobuf(o);s!=null&&n.sourcePush(new le(s))}}).catch(o=>{this.log.error("error processing incoming data channel messages",o)})}sendNewStream(){}async _sendMessage(e,t=!0){if(t&&this.channel.bufferedAmount>this.maxBufferedAmount)try{this.log('channel buffer is %d, wait for "bufferedamountlow" event',this.channel.bufferedAmount),await Za(this.channel,"bufferedamountlow",{timeout:this.bufferedAmountLowEventTimeout})}catch(n){throw n instanceof Zr?new L(`Timed out waiting for DataChannel buffer to clear after ${this.bufferedAmountLowEventTimeout}ms`,"ERR_BUFFER_CLEAR_TIMEOUT"):n}if(this.channel.readyState==="closed"||this.channel.readyState==="closing")throw new L(`Invalid datachannel state - ${this.channel.readyState}`,"ERR_INVALID_STATE");this.channel.readyState!=="open"&&(this.log('channel state is "%s" and not "open", waiting for "open" event before sending data',this.channel.readyState),await 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),o=$e.encode({message:n}),s=$n.single(o);await this._sendMessage(s),e.consume(t)}}async sendReset(){await this._sendFlag($e.Flag.RESET)}async sendCloseWrite(e){if(await this._sendFlag($e.Flag.FIN)){this.log.trace("awaiting FIN_ACK");try{await Tt(this.receiveFinAck.promise,e?.signal,{errorMessage:"sending close-write was aborted before FIN_ACK was received",errorCode:"ERR_FIN_ACK_NOT_RECEIVED"})}catch(n){this.log.error("failed to await FIN_ACK",n)}}else this.log.trace("sending FIN failed, not awaiting FIN_ACK");this.receiveFinAck.resolve()}async sendCloseRead(){await this._sendFlag($e.Flag.STOP_SENDING)}processIncomingProtobuf(e){let t=$e.decode(e);if(t.flag!==void 0&&(this.log.trace('incoming flag %s, write status "%s", read status "%s"',t.flag,this.writeStatus,this.readStatus),t.flag===$e.Flag.FIN&&(this.remoteCloseWrite(),this.log.trace("sending FIN_ACK"),this._sendFlag($e.Flag.FIN_ACK).catch(n=>{this.log.error("error sending FIN_ACK immediately",n)})),t.flag===$e.Flag.RESET&&this.reset(),t.flag===$e.Flag.STOP_SENDING&&this.remoteCloseRead(),t.flag===$e.Flag.FIN_ACK&&(this.log.trace("received FIN_ACK"),this.receiveFinAck.resolve())),this.readStatus==="ready")return t.message}async _sendFlag(e){if(this.channel.readyState!=="open")return this.log.trace('not sending flag %s because channel is "%s" and not "open"',this.channel.readyState,e.toString()),!1;this.log.trace("sending flag %s",e.toString());let t=$e.encode({flag:e}),n=$n.single(t);try{return await this._sendMessage(n,!1),!0}catch(o){this.log.error("could not send flag %s",e.toString(),o)}return!1}};function en(r){let{channel:e,direction:t}=r;return new cc({id:t==="inbound"?`i${e.id}`:`r${e.id}`,log:r.logger.forComponent(`libp2p:webrtc:stream:${t}:${e.id}`),...r})}var Bf="/webrtc",Jt=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 o={},s=en({channel:n,direction:"inbound",onEnd:i=>{o.onEnd(i)},logger:e.logger,...this.dataChannelOptions});o.stream=s,o.channel=n,o.onEnd=()=>{this.bufferedStreams=this.bufferedStreams.filter(i=>i.stream.id!==s.id)},this.bufferedStreams.push(o)}}createStreamMuxer(e){return new uc(this.components,{...e,peerConnection:this.peerConnection,dataChannelOptions:this.dataChannelOptions,metrics:this.metrics,streams:this.bufferedStreams,protocol:this.protocol})}},uc=class{init;streams;protocol;log;peerConnection;dataChannelOptions;metrics;logger;constructor(e,t){this.init=t,this.log=e.logger.forComponent("libp2p:webrtc:muxer"),this.logger=e.logger,this.streams=t.streams.map(n=>n.stream),this.peerConnection=t.peerConnection,this.protocol=t.protocol??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 o=en({channel:n,direction:"inbound",onEnd:()=>{this.log("incoming channel %s ended with state %s",n.id,n.readyState),this.#e(o,n)},logger:this.logger,...this.dataChannelOptions});this.streams.push(o),this.metrics?.increment({incoming_stream:!0}),t?.onIncomingStream?.(o)},this.init.streams.length>0&&queueMicrotask(()=>{this.init.streams.forEach(n=>{n.onEnd=()=>{this.log("incoming early channel %s ended with state %s",n.channel.id,n.channel.readyState),this.#e(n.stream,n.channel)},this.metrics?.increment({incoming_stream:!0}),this.init?.onIncomingStream?.(n.stream)})})}#e(e,t){this.log.trace("stream %s %s %s onEnd",e.direction,e.id,e.protocol),uf(t,`${e.direction} ${e.id} ${e.protocol}`,this.dataChannelOptions.drainTimeout,{log:this.log}),this.streams=this.streams.filter(n=>n.id!==e.id),this.metrics?.increment({stream_end:!0}),this.init?.onStreamEnd?.(e)}async close(e){try{await Promise.all(this.streams.map(async t=>t.close(e)))}catch(t){this.abort(t)}}abort(e){for(let t of this.streams)t.abort(e)}source=Wo();sink=zo;newStream(){let e=this.peerConnection.createDataChannel("");this.log.trace("opened outgoing datachannel with channel id %s",e.id);let t=en({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 Sr=globalThis.RTCPeerConnection,rs=globalThis.RTCSessionDescription,kf=globalThis.RTCIceCandidate;var lc=class{readNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.readNext=pe(),this.haveNext=pe()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let e=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=pe(),e}async throw(e){return this.ended=!0,e!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(e)),{done:!0,value:void 0}}async return(){let e={done:!0,value:void 0};return await this._push(void 0),e}async push(e,t){await this._push(e,t)}async end(e,t){e!=null?await this.throw(e):await this._push(void 0,t)}async _push(e,t){if(e!=null&&this.ended)throw new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;e!=null?this.nextResult={done:!1,value:e}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=pe(),await Tt(this.readNext.promise,t?.signal,t)}};function Cf(){return new lc}var ns=class extends Error{code;constructor(e,t){super(e),this.code=t}},fc=class extends ns{type;constructor(e){super(e,"ABORT_ERR"),this.type="aborted"}};function If(r,e){let t=Cf();r.sink(t).catch(async i=>{await t.end(i)}),r.sink=async i=>{for await(let a of i)await t.push(a);await t.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let o=new le;return{read:async(i,a)=>{a?.signal?.throwIfAborted();let c,u=new Promise((l,f)=>{c=()=>{f(new fc("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 le:m}for(;o.byteLength<i;){let{value:f,done:m}=await Promise.race([n.next(),u]);if(m===!0)throw new ns("unexpected end of input","ERR_UNEXPECTED_EOF");o.append(f)}let l=o.sublist(0,i);return o.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(o.byteLength>0){let i=r.source;r.source=async function*(){e?.yieldBytes===!1?yield o:yield*o,yield*i}()}return r}}}var os=class extends Error{code;constructor(e,t){super(e),this.code=t}};function zn(r,e={}){let t=If(r,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=we(e.maxDataLength));let n=e?.lengthDecoder??rt,o=e?.lengthEncoder??yt;return{read:async i=>{let a=-1,c=new le;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 os("message length length too long","ERR_MSG_LENGTH_TOO_LONG");if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new os("message length too long","ERR_MSG_DATA_TOO_LONG");return t.read(a,i)},write:async(i,a)=>{await t.write(new le(o(i.byteLength),i),a)},writeV:async(i,a)=>{let c=new le(...i.flatMap(u=>[o(u.byteLength),u]));await t.write(c,a)},unwrap:()=>t.unwrap()}}function ss(r,e){let t=zn(r,e),n={read:async(o,s)=>{let i=await t.read(s);return o.decode(i)},write:async(o,s,i)=>{await t.write(s.encode(o),i)},writeV:async(o,s,i)=>{await t.writeV(o.map(a=>s.encode(a)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>t.unwrap()};return n}var qe;(function(r){let e;(function(o){o.SDP_OFFER="SDP_OFFER",o.SDP_ANSWER="SDP_ANSWER",o.ICE_CANDIDATE="ICE_CANDIDATE"})(e=r.Type||(r.Type={}));let t;(function(o){o[o.SDP_OFFER=0]="SDP_OFFER",o[o.SDP_ANSWER=1]="SDP_ANSWER",o[o.ICE_CANDIDATE=2]="ICE_CANDIDATE"})(t||(t={})),function(o){o.codec=()=>Dr(t)}(e=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=at((o,s,i={})=>{i.lengthDelimited!==!1&&s.fork(),o.type!=null&&(s.uint32(8),r.Type.codec().encode(o.type,s)),o.data!=null&&(s.uint32(18),s.string(o.data)),i.lengthDelimited!==!1&&s.ldelim()},(o,s)=>{let i={},a=s==null?o.len:o.pos+s;for(;o.pos<a;){let c=o.uint32();switch(c>>>3){case 1:i.type=r.Type.codec().decode(o);break;case 2:i.data=o.string();break;default:o.skipType(c&7);break}}return i})),n),r.encode=o=>it(o,r.codec()),r.decode=o=>st(o,r.codec())})(qe||(qe={}));var is=async(r,e,t)=>{try{let n=pe();for(gb(r,n);;){let o=await Promise.race([n.promise,e.read({signal:t.signal}).catch(()=>{})]);if(o==null){t.signal?.throwIfAborted();break}if(o.type!==qe.Type.ICE_CANDIDATE)throw new L("ICE candidate message expected","ERR_NOT_ICE_CANDIDATE");let s=JSON.parse(o.data??"null");if(s===""||s===null){t.log.trace("end-of-candidates received");continue}let i=new kf(s);t.log.trace("%s received new ICE candidate %o",t.direction,s);try{await r.addIceCandidate(i)}catch(a){t.log.error("%s bad candidate received",t.direction,s,a)}}}catch(n){if(t.log.error("%s error parsing ICE candidate",t.direction,n),t.signal?.aborted===!0)throw n}};function mb(r){return Hn?r.iceConnectionState:r.connectionState}function gb(r,e){r[Hn?"oniceconnectionstatechange":"onconnectionstatechange"]=t=>{switch(mb(r)){case"connected":e.resolve();break;case"failed":case"disconnected":case"closed":e.reject(new L("RTCPeerConnection was closed","ERR_CONNECTION_CLOSED_BEFORE_CONNECTED"));break;default:break}}}async function Tf({rtcConfiguration:r,dataChannel:e,signal:t,metrics:n,multiaddr:o,connectionManager:s,transportManager:i,log:a,logger:c}){let{baseAddr:u}=_f(o);n?.dialerEvents.increment({open:!0}),a.trace("dialing base address: %a",u);let l=u.getPeerId();if(l==null)throw new L("Relay peer was missing","ERR_INVALID_ADDRESS");let f=s.getConnections(br(l)),m,g=!1;f.length===0?(m=await i.dial(u,{signal:t}),g=!0):m=f[0];try{let p=await m.newStream(as,{signal:t,runOnTransientConnection:!0}),h=ss(p).pb(qe),d=new Sr(r),y=new Jt({logger:c},{peerConnection:d,dataChannelOptions:e});try{let x=d.createDataChannel("init");d.onicecandidate=({candidate:v})=>{let S=JSON.stringify(v?.toJSON()??null);a.trace("initiator sending ICE candidate %o",v),h.write({type:qe.Type.ICE_CANDIDATE,data:S},{signal:t}).catch(D=>{a.error("error sending ICE candidate",D)})},d.onicecandidateerror=v=>{a.error("initiator ICE candidate error",v)};let b=await d.createOffer().catch(v=>{throw a.error("could not execute createOffer",v),new L("Failed to set createOffer","ERR_SDP_HANDSHAKE_FAILED")});a.trace("initiator send SDP offer %s",b.sdp),await h.write({type:qe.Type.SDP_OFFER,data:b.sdp},{signal:t}),await d.setLocalDescription(b).catch(v=>{throw a.error("could not execute setLocalDescription",v),new L("Failed to set localDescription","ERR_SDP_HANDSHAKE_FAILED")});let A=await h.read({signal:t});if(A.type!==qe.Type.SDP_ANSWER)throw new L("Remote should send an SDP answer","ERR_SDP_HANDSHAKE_FAILED");a.trace("initiator receive SDP answer %s",A.data);let E=new rs({type:"answer",sdp:A.data});return await d.setRemoteDescription(E).catch(v=>{throw a.error("could not execute setRemoteDescription",v),new L("Failed to set remoteDescription","ERR_SDP_HANDSHAKE_FAILED")}),a.trace("initiator read candidates until connected"),await is(d,h,{direction:"initiator",signal:t,log:a}),a.trace("initiator connected, closing init channel"),x.close(),a.trace("closing signalling channel"),await p.close({signal:t}),a.trace("initiator connected to remote address %s",o),{remoteAddress:o,peerConnection:d,muxerFactory:y}}catch(x){throw a.error("outgoing signalling error",x),d.close(),p.abort(x),x}finally{d.onicecandidate=null,d.onicecandidateerror=null}}finally{if(g)try{await m.close({signal:t})}catch(p){m.abort(p)}}}var bb=U("dns4"),yb=U("dns6"),wb=U("dnsaddr"),Br=ye(U("dns"),wb,bb,yb),ls=ye(U("ip4"),U("ip6")),tn=ye(K(ls,U("tcp")),K(Br,U("tcp"))),fs=K(ls,U("udp")),xb=K(fs,U("utp")),Eb=K(fs,U("quic")),vb=K(fs,U("quic-v1")),hc=ye(K(tn,U("ws")),K(Br,U("ws"))),cs=ye(K(hc,U("p2p")),hc),dc=ye(K(tn,U("wss")),K(Br,U("wss")),K(tn,U("tls"),U("ws")),K(Br,U("tls"),U("ws"))),us=ye(K(dc,U("p2p")),dc),pc=ye(K(tn,U("http")),K(ls,U("http")),K(Br,U("http"))),mc=ye(K(tn,U("https")),K(ls,U("https")),K(Br,U("https"))),Rf=K(fs,U("webrtc-direct"),U("certhash")),Uf=ye(K(Rf,U("p2p")),Rf),Nf=K(vb,U("webtransport"),U("certhash"),U("certhash")),Of=ye(K(Nf,U("p2p")),Nf),Pf=ye(K(cs,U("p2p-webrtc-star"),U("p2p")),K(us,U("p2p-webrtc-star"),U("p2p")),K(cs,U("p2p-webrtc-star")),K(us,U("p2p-webrtc-star"))),ZA=ye(K(cs,U("p2p-websocket-star"),U("p2p")),K(us,U("p2p-websocket-star"),U("p2p")),K(cs,U("p2p-websocket-star")),K(us,U("p2p-websocket-star"))),Mf=ye(K(pc,U("p2p-webrtc-direct"),U("p2p")),K(mc,U("p2p-webrtc-direct"),U("p2p")),K(pc,U("p2p-webrtc-direct")),K(mc,U("p2p-webrtc-direct"))),kr=ye(hc,dc,pc,mc,Pf,Mf,tn,xb,Eb,Br,Uf,Of),XA=ye(K(kr,U("p2p-stardust"),U("p2p")),K(kr,U("p2p-stardust"))),Qt=ye(K(kr,U("p2p")),Pf,Mf,Uf,Of,U("p2p")),Lf=ye(K(Qt,U("p2p-circuit"),Qt),K(Qt,U("p2p-circuit")),K(U("p2p-circuit"),Qt),K(kr,U("p2p-circuit")),K(U("p2p-circuit"),kr),U("p2p-circuit")),Ff=()=>ye(K(Lf,Ff),Lf),_t=Ff(),JA=ye(K(_t,Qt,_t),K(Qt,_t),K(_t,Qt),_t,Qt);var QA=ye(K(_t,U("webrtc"),U("p2p")),K(_t,U("webrtc")),K(kr,U("webrtc"),U("p2p")),K(kr,U("webrtc")),U("webrtc"));function Vf(r){function e(t){let n;try{n=nt(t)}catch{return!1}let o=r(n.protoNames());return o===null?!1:o===!0||o===!1?o:o.length===0}return e}function K(...r){function e(t){if(t.length<r.length)return null;let n=t;return r.some(o=>(n=typeof o=="function"?o().partialMatch(t):o.partialMatch(t),Array.isArray(n)&&(t=n),n===null)),n}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:Vf(e),partialMatch:e}}function ye(...r){function e(n){let o=null;return r.some(s=>{let i=typeof s=="function"?s().partialMatch(n):s.partialMatch(n);return i!=null?(o=i,!0):!1}),o}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:Vf(e),partialMatch:e}}function U(r){let e=r;function t(o){let s;try{s=nt(o)}catch{return!1}let i=s.protoNames();return i.length===1&&i[0]===e}function n(o){return o.length===0?null:o[0]===e?o.slice(1):null}return{toString:function(){return e},matches:t,partialMatch:n}}var hs=class extends To{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=>_t.matches(t)).map(t=>t.encapsulate(`/webrtc/p2p/${this.peerId}`))).flat()}async close(){this.shutdownController.abort(),this.safeDispatchEvent("close",{})}};async function Hf({peerConnection:r,stream:e,signal:t,connection:n,log:o}){o.trace("new inbound signaling stream");let s=ss(e).pb(qe);try{r.onicecandidate=({candidate:l})=>{let f=JSON.stringify(l?.toJSON()??null);o.trace("recipient sending ICE candidate %s",f),s.write({type:qe.Type.ICE_CANDIDATE,data:f},{signal:t}).catch(m=>{o.error("error sending ICE candidate",m)})};let a=await s.read({signal:t});if(a.type!==qe.Type.SDP_OFFER)throw new L(`expected message type SDP_OFFER, received: ${a.type??"undefined"} `,"ERR_SDP_HANDSHAKE_FAILED");o.trace("recipient receive SDP offer %s",a.data);let c=new rs({type:"offer",sdp:a.data});await r.setRemoteDescription(c).catch(l=>{throw o.error("could not execute setRemoteDescription",l),new L("Failed to set remoteDescription","ERR_SDP_HANDSHAKE_FAILED")});let u=await r.createAnswer().catch(l=>{throw o.error("could not execute createAnswer",l),new L("Failed to create answer","ERR_SDP_HANDSHAKE_FAILED")});o.trace("recipient send SDP answer %s",u.sdp),await s.write({type:qe.Type.SDP_ANSWER,data:u.sdp},{signal:t}),await r.setLocalDescription(u).catch(l=>{throw o.error("could not execute setLocalDescription",l),new L("Failed to set localDescription","ERR_SDP_HANDSHAKE_FAILED")}),o.trace("recipient read candidates until connected"),await is(r,s,{direction:"recipient",signal:t,log:o})}catch(a){if(r.connectionState!=="connected")throw o.error("error while handling signaling stream from peer %a",n.remoteAddr,a),r.close(),a;o("error while handling signaling stream from peer %a, ignoring as the RTCPeerConnection is already connected",n.remoteAddr,a)}let i=nt(`/webrtc/p2p/${n.remoteAddr.getPeerId()}`);return o.trace("recipient connected to remote address %s",i),{remoteAddress:i}}var Ab="/webrtc",Db="/p2p-circuit",as="/webrtc-signaling/0.0.1",Sb=30*1e3,ds=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,Io(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"})})}[Co]=!0;[Symbol.toStringTag]="@libp2p/webrtc";[Vr]=["@libp2p/transport"];[ol]=["@libp2p/identify","@libp2p/circuit-relay-v2-transport"];isStarted(){return this._started}async start(){await this.components.registrar.handle(as,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(as),this._started=!1}createListener(e){return new hs(this.components,{shutdownController:this.shutdownController})}listenFilter(e){return e.filter(Zl.exactMatch)}dialFilter(e){return this.listenFilter(e)}async dial(e,t){this.log.trace("dialing address: %a",e);let{remoteAddress:n,peerConnection:o,muxerFactory:s}=await Tf({rtcConfiguration:await Kn(this.init.rtcConfiguration),dataChannel:this.init.dataChannel,multiaddr:e,dataChannelOptions:this.init.dataChannel,signal:t.signal,connectionManager:this.components.connectionManager,transportManager:this.components.transportManager,log:this.log,logger:this.components.logger}),i=new wr(this.components,{peerConnection:o,timeline:{open:Date.now()},remoteAddr:n,metrics:this.metrics?.dialerEvents}),a=await t.upgrader.upgradeOutbound(i,{skipProtection:!0,skipEncryption:!0,muxerFactory:s});return this._closeOnShutdown(o,i),a}async _onProtocol({connection:e,stream:t}){let n=AbortSignal.timeout(this.init.inboundConnectionTimeout??Sb),o=new Sr(await Kn(this.init.rtcConfiguration)),s=new Jt(this.components,{peerConnection:o,dataChannelOptions:this.init.dataChannel});try{let{remoteAddress:i}=await Hf({peerConnection:o,connection:e,stream:t,signal:n,log:this.log});await t.close({signal:n});let a=new wr(this.components,{peerConnection:o,timeline:{open:new Date().getTime()},remoteAddr:i,metrics:this.metrics?.listenerEvents});await this.components.upgrader.upgradeInbound(a,{skipEncryption:!0,skipProtection:!0,muxerFactory:s}),this._closeOnShutdown(o,a)}catch(i){throw this.log.error("incoming signalling error",i),o.close(),t.abort(i),i}}_closeOnShutdown(e,t){let n=()=>{t.close().catch(o=>{this.log.error("could not close WebRTCMultiaddrConnection",o)})};this.shutdownController.signal.addEventListener("abort",n),e.addEventListener("close",()=>{this.shutdownController.signal.removeEventListener("abort",n)})}};function _f(r){let e=r.toString().split(Ab+"/");if(e.length!==2)throw new L("webrtc protocol was not present in multiaddr",Ge.ERR_INVALID_MULTIADDR);if(!e[0].includes(Db))throw new L("p2p-circuit protocol was not present in multiaddr",Ge.ERR_INVALID_MULTIADDR);let t=nt(e[0]),o=nt("/"+e[1]).getPeerId();if(o==null)throw new L("destination peer id was missing",Ge.ERR_INVALID_MULTIADDR);let s=t.protos().pop();if(s===void 0)throw new L("invalid multiaddr",Ge.ERR_INVALID_MULTIADDR);return s.name!=="p2p"&&(t=t.encapsulate(`/p2p/${o}`)),{baseAddr:t,peerId:br(o)}}var _c={};Q(_c,{Ed25519PrivateKey:()=>Rr,Ed25519PublicKey:()=>Qn,generateKeyPair:()=>Ly,generateKeyPairFromSeed:()=>gh,unmarshalEd25519PrivateKey:()=>Ry,unmarshalEd25519PublicKey:()=>Ny});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(`positive integer expected, not ${r}`)}function Bb(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function rn(r,...e){if(!Bb(r))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(r.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${r.length}`)}function Cr(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 nn(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 Kf(r,e){rn(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var ps=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var sn=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),ct=(r,e)=>r<<32-e|r>>>e;var R4=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;var kb=async()=>{};async function $f(r,e,t){let n=Date.now();for(let o=0;o<r;o++){t(o);let s=Date.now()-n;s>=0&&s<e||(await kb(),n+=s)}}function qf(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function ut(r){return typeof r=="string"&&(r=qf(r)),rn(r),r}function gc(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];rn(o),e+=o.length}let t=new Uint8Array(e);for(let n=0,o=0;n<r.length;n++){let s=r[n];t.set(s,o),o+=s.length}return t}var on=class{clone(){return this._cloneInto()}},Cb={}.toString;function Wf(r,e){if(e!==void 0&&Cb.call(e)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(r,e)}function ms(r){let e=n=>r().update(ut(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function Ir(r=32){if(ps&&typeof ps.getRandomValues=="function")return ps.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function Ib(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(t>>o&s),a=Number(t&s),c=n?4:0,u=n?0:4;r.setUint32(e+c,i,n),r.setUint32(e+u,a,n)}var zf=(r,e,t)=>r&e^~r&t,Gf=(r,e,t)=>r&e^r&t^e&t,an=class extends on{constructor(e,t,n,o){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=sn(this.buffer)}update(e){nn(this);let{view:t,buffer:n,blockLen:o}=this;e=ut(e);let s=e.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=sn(e);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(e.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){nn(this),Kf(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;t[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)t[f]=0;Ib(n,o-8,BigInt(this.length*8),s),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],s)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return e.length=o,e.pos=a,e.finished=s,e.destroyed=i,o%t&&e.buffer.set(n),e}};var gs=BigInt(4294967295),bc=BigInt(32);function jf(r,e=!1){return e?{h:Number(r&gs),l:Number(r>>bc&gs)}:{h:Number(r>>bc&gs)|0,l:Number(r&gs)|0}}function Tb(r,e=!1){let t=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let o=0;o<r.length;o++){let{h:s,l:i}=jf(r[o],e);[t[o],n[o]]=[s,i]}return[t,n]}var _b=(r,e)=>BigInt(r>>>0)<<bc|BigInt(e>>>0),Rb=(r,e,t)=>r>>>t,Nb=(r,e,t)=>r<<32-t|e>>>t,Lb=(r,e,t)=>r>>>t|e<<32-t,Ub=(r,e,t)=>r<<32-t|e>>>t,Ob=(r,e,t)=>r<<64-t|e>>>t-32,Pb=(r,e,t)=>r>>>t-32|e<<64-t,Mb=(r,e)=>e,Fb=(r,e)=>r,Vb=(r,e,t)=>r<<t|e>>>32-t,Hb=(r,e,t)=>e<<t|r>>>32-t,Kb=(r,e,t)=>e<<t-32|r>>>64-t,$b=(r,e,t)=>r<<t-32|e>>>64-t;function qb(r,e,t,n){let o=(e>>>0)+(n>>>0);return{h:r+t+(o/2**32|0)|0,l:o|0}}var Wb=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),zb=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,Gb=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),jb=(r,e,t,n,o)=>e+t+n+o+(r/2**32|0)|0,Yb=(r,e,t,n,o)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(o>>>0),Zb=(r,e,t,n,o,s)=>e+t+n+o+s+(r/2**32|0)|0;var Xb={fromBig:jf,split:Tb,toBig:_b,shrSH:Rb,shrSL:Nb,rotrSH:Lb,rotrSL:Ub,rotrBH:Ob,rotrBL:Pb,rotr32H:Mb,rotr32L:Fb,rotlSH:Vb,rotlSL:Hb,rotlBH:Kb,rotlBL:$b,add:qb,add3L:Wb,add3H:zb,add4L:Gb,add4H:jb,add5H:Zb,add5L:Yb},Z=Xb;var[Jb,Qb]=Z.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),tr=new Uint32Array(80),rr=new Uint32Array(80),yc=class extends an{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:e,Al:t,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:l,Fh:f,Fl:m,Gh:g,Gl:p,Hh:h,Hl:d}=this;return[e,t,n,o,s,i,a,c,u,l,f,m,g,p,h,d]}set(e,t,n,o,s,i,a,c,u,l,f,m,g,p,h,d){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=l|0,this.Fh=f|0,this.Fl=m|0,this.Gh=g|0,this.Gl=p|0,this.Hh=h|0,this.Hl=d|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 A=tr[b-15]|0,E=rr[b-15]|0,v=Z.rotrSH(A,E,1)^Z.rotrSH(A,E,8)^Z.shrSH(A,E,7),S=Z.rotrSL(A,E,1)^Z.rotrSL(A,E,8)^Z.shrSL(A,E,7),D=tr[b-2]|0,_=rr[b-2]|0,O=Z.rotrSH(D,_,19)^Z.rotrBH(D,_,61)^Z.shrSH(D,_,6),R=Z.rotrSL(D,_,19)^Z.rotrBL(D,_,61)^Z.shrSL(D,_,6),H=Z.add4L(S,R,rr[b-7],rr[b-16]),V=Z.add4H(H,v,O,tr[b-7],tr[b-16]);tr[b]=V|0,rr[b]=H|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:l,Eh:f,El:m,Fh:g,Fl:p,Gh:h,Gl:d,Hh:y,Hl:x}=this;for(let b=0;b<80;b++){let A=Z.rotrSH(f,m,14)^Z.rotrSH(f,m,18)^Z.rotrBH(f,m,41),E=Z.rotrSL(f,m,14)^Z.rotrSL(f,m,18)^Z.rotrBL(f,m,41),v=f&g^~f&h,S=m&p^~m&d,D=Z.add5L(x,E,S,Qb[b],rr[b]),_=Z.add5H(D,y,A,v,Jb[b],tr[b]),O=D|0,R=Z.rotrSH(n,o,28)^Z.rotrBH(n,o,34)^Z.rotrBH(n,o,39),H=Z.rotrSL(n,o,28)^Z.rotrBL(n,o,34)^Z.rotrBL(n,o,39),V=n&s^n&a^s&a,G=o&i^o&c^i&c;y=h|0,x=d|0,h=g|0,d=p|0,g=f|0,p=m|0,{h:f,l:m}=Z.add(u|0,l|0,_|0,O|0),u=a|0,l=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let B=Z.add3L(O,H,G);n=Z.add3H(B,_,R,V),o=B|0}({h:n,l:o}=Z.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Z.add(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Z.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=Z.add(this.Dh|0,this.Dl|0,u|0,l|0),{h:f,l:m}=Z.add(this.Eh|0,this.El|0,f|0,m|0),{h:g,l:p}=Z.add(this.Fh|0,this.Fl|0,g|0,p|0),{h,l:d}=Z.add(this.Gh|0,this.Gl|0,h|0,d|0),{h:y,l:x}=Z.add(this.Hh|0,this.Hl|0,y|0,x|0),this.set(n,o,s,i,a,c,u,l,f,m,g,p,h,d,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 Gn=ms(()=>new yc);var ys={};Q(ys,{abytes:()=>cn,bitGet:()=>iy,bitLen:()=>sy,bitMask:()=>jn,bitSet:()=>ay,bytesToHex:()=>Nt,bytesToNumberBE:()=>Lt,bytesToNumberLE:()=>lt,concatBytes:()=>Ot,createHmacDrbg:()=>Ec,ensureBytes:()=>ce,equalBytes:()=>ny,hexToBytes:()=>Tr,hexToNumber:()=>xc,isBytes:()=>nr,numberToBytesBE:()=>or,numberToBytesLE:()=>Ut,numberToHexUnpadded:()=>Jf,numberToVarBytesBE:()=>ry,utf8ToBytes:()=>oy,validateObject:()=>Qe});var Xf=BigInt(0),bs=BigInt(1),ey=BigInt(2);function nr(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function cn(r){if(!nr(r))throw new Error("Uint8Array expected")}var ty=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function Nt(r){cn(r);let e="";for(let t=0;t<r.length;t++)e+=ty[r[t]];return e}function Jf(r){let e=r.toString(16);return e.length&1?`0${e}`:e}function xc(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var Rt={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function Yf(r){if(r>=Rt._0&&r<=Rt._9)return r-Rt._0;if(r>=Rt._A&&r<=Rt._F)return r-(Rt._A-10);if(r>=Rt._a&&r<=Rt._f)return r-(Rt._a-10)}function Tr(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let e=r.length,t=e/2;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(t);for(let o=0,s=0;o<t;o++,s+=2){let i=Yf(r.charCodeAt(s)),a=Yf(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Lt(r){return xc(Nt(r))}function lt(r){return cn(r),xc(Nt(Uint8Array.from(r).reverse()))}function or(r,e){return Tr(r.toString(16).padStart(e*2,"0"))}function Ut(r,e){return or(r,e).reverse()}function ry(r){return Tr(Jf(r))}function ce(r,e,t){let n;if(typeof e=="string")try{n=Tr(e)}catch(s){throw new Error(`${r} must be valid hex string, got "${e}". Cause: ${s}`)}else if(nr(e))n=Uint8Array.from(e);else throw new Error(`${r} must be hex string or Uint8Array`);let o=n.length;if(typeof t=="number"&&o!==t)throw new Error(`${r} expected ${t} bytes, got ${o}`);return n}function Ot(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];cn(o),e+=o.length}let t=new Uint8Array(e);for(let n=0,o=0;n<r.length;n++){let s=r[n];t.set(s,o),o+=s.length}return t}function ny(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 oy(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function sy(r){let e;for(e=0;r>Xf;r>>=bs,e+=1);return e}function iy(r,e){return r>>BigInt(e)&bs}function ay(r,e,t){return r|(t?bs:Xf)<<BigInt(e)}var jn=r=>(ey<<BigInt(r-1))-bs,wc=r=>new Uint8Array(r),Zf=r=>Uint8Array.from(r);function Ec(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=wc(r),o=wc(r),s=0,i=()=>{n.fill(1),o.fill(0),s=0},a=(...f)=>t(o,n,...f),c=(f=wc())=>{o=a(Zf([0]),f),n=a(),f.length!==0&&(o=a(Zf([1]),f),n=a())},u=()=>{if(s++>=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 Ot(...m)};return(f,m)=>{i(),c(f);let g;for(;!(g=m(u()));)c();return i(),g}}var cy={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"||nr(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 Qe(r,e,t={}){let n=(o,s,i)=>{let a=cy[s];if(typeof a!="function")throw new Error(`Invalid validator "${s}", expected function`);let c=r[o];if(!(i&&c===void 0)&&!a(c,r))throw new Error(`Invalid param ${String(o)}=${c} (${typeof c}), expected ${s}`)};for(let[o,s]of Object.entries(e))n(o,s,!1);for(let[o,s]of Object.entries(t))n(o,s,!0);return r}var ke=BigInt(0),fe=BigInt(1),_r=BigInt(2),uy=BigInt(3),vc=BigInt(4),Qf=BigInt(5),eh=BigInt(8),ly=BigInt(9),fy=BigInt(16);function te(r,e){let t=r%e;return t>=ke?t:e+t}function Ac(r,e,t){if(t<=ke||e<ke)throw new Error("Expected power/modulo > 0");if(t===fe)return ke;let n=fe;for(;e>ke;)e&fe&&(n=n*r%t),r=r*r%t,e>>=fe;return n}function ue(r,e,t){let n=r;for(;e-- >ke;)n*=n,n%=t;return n}function ws(r,e){if(r===ke||e<=ke)throw new Error(`invert: expected positive integers, got n=${r} mod=${e}`);let t=te(r,e),n=e,o=ke,s=fe,i=fe,a=ke;for(;t!==ke;){let u=n/t,l=n%t,f=o-i*u,m=s-a*u;n=t,t=l,o=i,s=a,i=f,a=m}if(n!==fe)throw new Error("invert: does not exist");return te(o,e)}function hy(r){let e=(r-fe)/_r,t,n,o;for(t=r-fe,n=0;t%_r===ke;t/=_r,n++);for(o=_r;o<r&&Ac(o,e,r)!==r-fe;o++);if(n===1){let i=(r+fe)/vc;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 s=(t+fe)/_r;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,o),t),f=a.pow(c,s),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 p=a.pow(l,fe<<BigInt(u-g-1));l=a.sqr(p),f=a.mul(f,p),m=a.mul(m,l),u=g}return f}}function dy(r){if(r%vc===uy){let e=(r+fe)/vc;return function(n,o){let s=n.pow(o,e);if(!n.eql(n.sqr(s),o))throw new Error("Cannot find square root");return s}}if(r%eh===Qf){let e=(r-Qf)/eh;return function(n,o){let s=n.mul(o,_r),i=n.pow(s,e),a=n.mul(o,i),c=n.mul(n.mul(a,_r),i),u=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(u),o))throw new Error("Cannot find square root");return u}}return r%fy,hy(r)}var th=(r,e)=>(te(r,e)&fe)===fe,py=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Dc(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=py.reduce((n,o)=>(n[o]="function",n),e);return Qe(r,t)}function my(r,e,t){if(t<ke)throw new Error("Expected power > 0");if(t===ke)return r.ONE;if(t===fe)return e;let n=r.ONE,o=e;for(;t>ke;)t&fe&&(n=r.mul(n,o)),o=r.sqr(o),t>>=fe;return n}function gy(r,e){let t=new Array(e.length),n=e.reduce((s,i,a)=>r.is0(i)?s:(t[a]=s,r.mul(s,i)),r.ONE),o=r.inv(n);return e.reduceRight((s,i,a)=>r.is0(i)?s:(t[a]=r.mul(s,t[a]),r.mul(s,i)),o),t}function Sc(r,e){let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function xs(r,e,t=!1,n={}){if(r<=ke)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:o,nByteLength:s}=Sc(r,e);if(s>2048)throw new Error("Field lengths over 2048 bytes are not supported");let i=dy(r),a=Object.freeze({ORDER:r,BITS:o,BYTES:s,MASK:jn(o),ZERO:ke,ONE:fe,create:c=>te(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return ke<=c&&c<r},is0:c=>c===ke,isOdd:c=>(c&fe)===fe,neg:c=>te(-c,r),eql:(c,u)=>c===u,sqr:c=>te(c*c,r),add:(c,u)=>te(c+u,r),sub:(c,u)=>te(c-u,r),mul:(c,u)=>te(c*u,r),pow:(c,u)=>my(a,c,u),div:(c,u)=>te(c*ws(u,r),r),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>ws(c,r),sqrt:n.sqrt||(c=>i(a,c)),invertBatch:c=>gy(a,c),cmov:(c,u,l)=>l?u:c,toBytes:c=>t?Ut(c,s):or(c,s),fromBytes:c=>{if(c.length!==s)throw new Error(`Fp.fromBytes: expected ${s}, got ${c.length}`);return t?lt(c):Lt(c)}});return Object.freeze(a)}function rh(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 Bc(r){let e=rh(r);return e+Math.ceil(e/2)}function nh(r,e,t=!1){let n=r.length,o=rh(e),s=Bc(e);if(n<16||n<s||n>1024)throw new Error(`expected ${s}-1024 bytes of input, got ${n}`);let i=t?Lt(r):lt(r),a=te(i,e-fe)+fe;return t?Ut(a,o):or(a,o)}var yy=BigInt(0),kc=BigInt(1);function Es(r,e){let t=(o,s)=>{let i=s.negate();return o?i:s},n=o=>{let s=Math.ceil(e/o)+1,i=2**(o-1);return{windows:s,windowSize:i}};return{constTimeNegate:t,unsafeLadder(o,s){let i=r.ZERO,a=o;for(;s>yy;)s&kc&&(i=i.add(a)),a=a.double(),s>>=kc;return i},precomputeWindow(o,s){let{windows:i,windowSize:a}=n(s),c=[],u=o,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(o,s,i){let{windows:a,windowSize:c}=n(o),u=r.ZERO,l=r.BASE,f=BigInt(2**o-1),m=2**o,g=BigInt(o);for(let p=0;p<a;p++){let h=p*c,d=Number(i&f);i>>=g,d>c&&(d-=m,i+=kc);let y=h,x=h+Math.abs(d)-1,b=p%2!==0,A=d<0;d===0?l=l.add(t(b,s[y])):u=u.add(t(A,s[x]))}return{p:u,f:l}},wNAFCached(o,s,i,a){let c=o._WINDOW_SIZE||1,u=s.get(o);return u||(u=this.precomputeWindow(o,c),c!==1&&s.set(o,a(u))),this.wNAF(c,u,i)}}}function Yn(r){return Dc(r.Fp),Qe(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Sc(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var ft=BigInt(0),Ye=BigInt(1),vs=BigInt(2),wy=BigInt(8),xy={zip215:!0};function Ey(r){let e=Yn(r);return Qe(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function oh(r){let e=Ey(r),{Fp:t,n,prehash:o,hash:s,randomBytes:i,nByteLength:a,h:c}=e,u=vs<<BigInt(a*8)-Ye,l=t.create,f=e.uvRatio||((k,w)=>{try{return{isValid:!0,value:t.sqrt(k*t.inv(w))}}catch{return{isValid:!1,value:ft}}}),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}),p=k=>typeof k=="bigint"&&ft<k,h=(k,w)=>p(k)&&p(w)&&k<w,d=k=>k===ft||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===ft?k:y(k,n)}let b=new Map;function A(k){if(!(k instanceof E))throw new Error("ExtendedPoint expected")}class E{constructor(w,C,T,N){if(this.ex=w,this.ey=C,this.ez=T,this.et=N,!d(w))throw new Error("x required");if(!d(C))throw new Error("y required");if(!d(T))throw new Error("z required");if(!d(N))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(!d(C)||!d(T))throw new Error("invalid affine point");return new E(C,T,Ye,l(C*T))}static normalizeZ(w){let C=t.invertBatch(w.map(T=>T.ez));return w.map((T,N)=>T.toAffine(C[N])).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:N,ez:$,et:q}=this,Y=l(T*T),z=l(N*N),j=l($*$),ae=l(j*j),se=l(Y*w),Ie=l(j*l(se+z)),Te=l(ae+l(C*l(Y*z)));if(Ie!==Te)throw new Error("bad point: equation left != right (1)");let ve=l(T*N),Oe=l($*q);if(ve!==Oe)throw new Error("bad point: equation left != right (2)")}equals(w){A(w);let{ex:C,ey:T,ez:N}=this,{ex:$,ey:q,ez:Y}=w,z=l(C*Y),j=l($*N),ae=l(T*Y),se=l(q*N);return z===j&&ae===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:N}=this,$=l(C*C),q=l(T*T),Y=l(vs*l(N*N)),z=l(w*$),j=C+T,ae=l(l(j*j)-$-q),se=z+q,Ie=se-Y,Te=z-q,ve=l(ae*Ie),Oe=l(se*Te),Bt=l(ae*Te),pr=l(Ie*se);return new E(ve,Oe,pr,Bt)}add(w){A(w);let{a:C,d:T}=e,{ex:N,ey:$,ez:q,et:Y}=this,{ex:z,ey:j,ez:ae,et:se}=w;if(C===BigInt(-1)){let Yu=l(($-N)*(j+z)),Zu=l(($+N)*(j-z)),Ui=l(Zu-Yu);if(Ui===ft)return this.double();let Xu=l(q*vs*se),Ju=l(Y*vs*ae),Qu=Ju+Xu,el=Zu+Yu,tl=Ju-Xu,O0=l(Qu*Ui),P0=l(el*tl),M0=l(Qu*tl),F0=l(Ui*el);return new E(O0,P0,F0,M0)}let Ie=l(N*z),Te=l($*j),ve=l(Y*T*se),Oe=l(q*ae),Bt=l((N+$)*(z+j)-Ie-Te),pr=Oe-ve,Rn=Oe+ve,ju=l(Te-C*Ie),R0=l(Bt*pr),N0=l(Rn*ju),L0=l(Bt*ju),U0=l(pr*Rn);return new E(R0,N0,U0,L0)}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===ft?S:this.equals(S)||C===Ye?this:this.equals(v)?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:N}=this,$=this.is0();w==null&&(w=$?wy:t.inv(N));let q=l(C*w),Y=l(T*w),z=l(N*w);if($)return{x:ft,y:Ye};if(z!==Ye)throw new Error("invZ was invalid");return{x:q,y:Y}}clearCofactor(){let{h:w}=e;return w===Ye?this:this.multiplyUnsafe(w)}static fromHex(w,C=!1){let{d:T,a:N}=e,$=t.BYTES;w=ce("pointHex",w,$);let q=w.slice(),Y=w[$-1];q[$-1]=Y&-129;let z=lt(q);z===ft||(C?y(z,u):y(z,t.ORDER));let j=l(z*z),ae=l(j-Ye),se=l(T*j-N),{isValid:Ie,value:Te}=f(ae,se);if(!Ie)throw new Error("Point.fromHex: invalid y coordinate");let ve=(Te&Ye)===Ye,Oe=(Y&128)!==0;if(!C&&Te===ft&&Oe)throw new Error("Point.fromHex: x=0 and x_0=1");return Oe!==ve&&(Te=l(-Te)),E.fromAffine({x:Te,y:z})}static fromPrivateKey(w){return R(w).point}toRawBytes(){let{x:w,y:C}=this.toAffine(),T=Ut(C,t.BYTES);return T[T.length-1]|=w&Ye?128:0,T}toHex(){return Nt(this.toRawBytes())}}E.BASE=new E(e.Gx,e.Gy,Ye,l(e.Gx*e.Gy)),E.ZERO=new E(ft,Ye,Ye,ft);let{BASE:v,ZERO:S}=E,D=Es(E,a*8);function _(k){return te(k,n)}function O(k){return _(lt(k))}function R(k){let w=a;k=ce("private key",k,w);let C=ce("hashed private key",s(k),2*w),T=m(C.slice(0,w)),N=C.slice(w,2*w),$=O(T),q=v.multiply($),Y=q.toRawBytes();return{head:T,prefix:N,scalar:$,point:q,pointBytes:Y}}function H(k){return R(k).pointBytes}function V(k=new Uint8Array,...w){let C=Ot(...w);return O(s(g(C,ce("context",k),!!o)))}function G(k,w,C={}){k=ce("message",k),o&&(k=o(k));let{prefix:T,scalar:N,pointBytes:$}=R(w),q=V(C.context,T,k),Y=v.multiply(q).toRawBytes(),z=V(C.context,Y,$,k),j=_(q+z*N);x(j);let ae=Ot(Y,Ut(j,t.BYTES));return ce("result",ae,a*2)}let B=xy;function I(k,w,C,T=B){let{context:N,zip215:$}=T,q=t.BYTES;k=ce("signature",k,2*q),w=ce("message",w),o&&(w=o(w));let Y=lt(k.slice(q,2*q)),z,j,ae;try{z=E.fromHex(C,$),j=E.fromHex(k.slice(0,q),$),ae=v.multiplyUnsafe(Y)}catch{return!1}if(!$&&z.isSmallOrder())return!1;let se=V(N,j.toRawBytes(),z.toRawBytes(),w);return j.add(z.multiplyUnsafe(se)).subtract(ae).clearCofactor().equals(E.ZERO)}return v._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 Zn=BigInt(0),Cc=BigInt(1);function vy(r){return Qe(r,{a:"bigint"},{montgomeryBits:"isSafeInteger",nByteLength:"isSafeInteger",adjustScalarBytes:"function",domain:"function",powPminus2:"function",Gu:"bigint"}),Object.freeze({...r})}function sh(r){let e=vy(r),{P:t}=e,n=b=>te(b,t),o=e.montgomeryBits,s=Math.ceil(o/8),i=e.nByteLength,a=e.adjustScalarBytes||(b=>b),c=e.powPminus2||(b=>Ac(b,t-BigInt(2),t));function u(b,A,E){let v=n(b*(A-E));return A=n(A-v),E=n(E+v),[A,E]}function l(b){if(typeof b=="bigint"&&Zn<=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,A){let E=l(b),v=l(A),S=E,D=Cc,_=Zn,O=E,R=Cc,H=Zn,V;for(let B=BigInt(o-1);B>=Zn;B--){let I=v>>B&Cc;H^=I,V=u(H,D,O),D=V[0],O=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,N=O+R,$=O-R,q=n($*P),Y=n(N*w),z=q+Y,j=q-Y;O=n(z*z),R=n(S*n(j*j)),D=n(k*C),_=n(T*(k+n(f*T)))}V=u(H,D,O),D=V[0],O=V[1],V=u(H,_,R),_=V[0],R=V[1];let G=c(_);return n(D*G)}function g(b){return Ut(n(b),s)}function p(b){let A=ce("u coordinate",b,s);return i===32&&(A[31]&=127),lt(A)}function h(b){let A=ce("scalar",b),E=A.length;if(E!==s&&E!==i)throw new Error(`Expected ${s} or ${i} bytes, got ${E}`);return lt(a(A))}function d(b,A){let E=p(A),v=h(b),S=m(E,v);if(S===Zn)throw new Error("Invalid private or public key received");return g(S)}let y=g(e.Gu);function x(b){return d(b,y)}return{scalarMult:d,scalarMultBase:x,getSharedSecret:(b,A)=>d(b,A),getPublicKey:b=>x(b),utils:{randomPrivateKey:()=>e.randomBytes(e.nByteLength)},GuBytes:y}}var Xn=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),ih=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),sD=BigInt(0),Ay=BigInt(1),ah=BigInt(2),Dy=BigInt(3),Sy=BigInt(5),By=BigInt(8);function ch(r){let e=BigInt(10),t=BigInt(20),n=BigInt(40),o=BigInt(80),s=Xn,a=r*r%s*r%s,c=ue(a,ah,s)*a%s,u=ue(c,Ay,s)*r%s,l=ue(u,Sy,s)*u%s,f=ue(l,e,s)*l%s,m=ue(f,t,s)*f%s,g=ue(m,n,s)*m%s,p=ue(g,o,s)*g%s,h=ue(p,o,s)*g%s,d=ue(h,e,s)*l%s;return{pow_p_5_8:ue(d,ah,s)*r%s,b2:a}}function uh(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function ky(r,e){let t=Xn,n=te(e*e*e,t),o=te(n*n*e,t),s=ch(r*o).pow_p_5_8,i=te(r*n*s,t),a=te(e*i*i,t),c=i,u=te(i*ih,t),l=a===r,f=a===te(-r,t),m=a===te(-r*ih,t);return l&&(i=c),(f||m)&&(i=u),th(i,t)&&(i=te(-i,t)),{isValid:l||f,value:i}}var Cy=xs(Xn,void 0,!0),Iy={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Cy,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:By,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Gn,randomBytes:Ir,adjustScalarBytes:uh,uvRatio:ky},un=oh(Iy);var Jn=sh({P:Xn,a:BigInt(486662),montgomeryBits:255,nByteLength:32,Gu:BigInt(9),powPminus2:r=>{let e=Xn,{pow_p_5_8:t,b2:n}=ch(r);return te(ue(t,Dy,e)*n,e)},adjustScalarBytes:uh,randomBytes:Ir});var ln=32,Pt=64,As=32;function lh(){let r=un.utils.randomPrivateKey(),e=un.getPublicKey(r);return{privateKey:ph(r,e),publicKey:e}}function fh(r){if(r.length!==As)throw new TypeError('"seed" must be 32 bytes in length.');if(!(r instanceof Uint8Array))throw new TypeError('"seed" must be a node.js Buffer, or Uint8Array.');let e=r,t=un.getPublicKey(e);return{privateKey:ph(e,t),publicKey:t}}function hh(r,e){let t=r.subarray(0,As);return un.sign(e instanceof Uint8Array?e:e.subarray(),t)}function dh(r,e,t){return un.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}function ph(r,e){let t=new Uint8Array(Pt);for(let n=0;n<As;n++)t[n]=r[n],t[As+n]=e[n];return t}var Ve={get(r=globalThis){let e=r.crypto;if(e==null||e.subtle==null)throw Object.assign(new Error("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api"),{code:"ERR_MISSING_WEB_CRYPTO"});return e}};var Ic={alg:"A128GCM",ext:!0,k:"scm9jmO_4BJAgdwWGVulLg",key_ops:["encrypt","decrypt"],kty:"oct"};function mh(r){let e=r?.algorithm??"AES-GCM",t=r?.keyLength??16,n=r?.nonceLength??12,o=r?.digest??"SHA-256",s=r?.saltLength??16,i=r?.iterations??32767,a=Ve.get();t*=8;async function c(f,m){let g=a.getRandomValues(new Uint8Array(s)),p=a.getRandomValues(new Uint8Array(n)),h={name:e,iv:p};typeof m=="string"&&(m=J(m));let d;if(m.length===0){d=await a.subtle.importKey("jwk",Ic,{name:"AES-GCM"},!0,["encrypt"]);try{let x={name:"PBKDF2",salt:g,iterations:i,hash:{name:o}},b=await a.subtle.importKey("raw",m,{name:"PBKDF2"},!1,["deriveKey"]);d=await a.subtle.deriveKey(x,b,{name:e,length:t},!0,["encrypt"])}catch{d=await a.subtle.importKey("jwk",Ic,{name:"AES-GCM"},!0,["encrypt"])}}else{let x={name:"PBKDF2",salt:g,iterations:i,hash:{name:o}},b=await a.subtle.importKey("raw",m,{name:"PBKDF2"},!1,["deriveKey"]);d=await a.subtle.deriveKey(x,b,{name:e,length:t},!0,["encrypt"])}let y=await a.subtle.encrypt(h,d,f);return xe([g,h.iv,new Uint8Array(y)])}async function u(f,m){let g=f.subarray(0,s),p=f.subarray(s,s+n),h=f.subarray(s+n),d={name:e,iv:p};typeof m=="string"&&(m=J(m));let y;if(m.length===0)try{let b={name:"PBKDF2",salt:g,iterations:i,hash:{name:o}},A=await a.subtle.importKey("raw",m,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(b,A,{name:e,length:t},!0,["decrypt"])}catch{y=await a.subtle.importKey("jwk",Ic,{name:"AES-GCM"},!0,["decrypt"])}else{let b={name:"PBKDF2",salt:g,iterations:i,hash:{name:o}},A=await a.subtle.importKey("raw",m,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(b,A,{name:e,length:t},!0,["decrypt"])}let x=await a.subtle.decrypt(d,y,h);return new Uint8Array(x)}return{encrypt:c,decrypt:u}}async function fn(r,e){let n=await mh().encrypt(r,e);return Yi.encode(n)}var he;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.Secp256k1="Secp256k1"})(he||(he={}));var Tc;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.Secp256k1=2]="Secp256k1"})(Tc||(Tc={}));(function(r){r.codec=()=>Dr(Tc)})(he||(he={}));var xt;(function(r){let e;r.codec=()=>(e==null&&(e=at((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),he.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let o={},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let i=t.uint32();switch(i>>>3){case 1:o.Type=he.codec().decode(t);break;case 2:o.Data=t.bytes();break;default:t.skipType(i&7);break}}return o})),e),r.encode=t=>it(t,r.codec()),r.decode=t=>st(t,r.codec())})(xt||(xt={}));var Et;(function(r){let e;r.codec=()=>(e==null&&(e=at((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),he.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let o={},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let i=t.uint32();switch(i>>>3){case 1:o.Type=he.codec().decode(t);break;case 2:o.Data=t.bytes();break;default:t.skipType(i&7);break}}return o})),e),r.encode=t=>it(t,r.codec()),r.decode=t=>st(t,r.codec())})(Et||(Et={}));var Qn=class{_key;constructor(e){this._key=hn(e,ln)}verify(e,t){return dh(this._key,t,e)}marshal(){return this._key}get bytes(){return xt.encode({Type:he.Ed25519,Data:this.marshal()}).subarray()}equals(e){return Ae(this.bytes,e.bytes)}hash(){let e=_e.digest(this.bytes);return Je(e)?e.then(({bytes:t})=>t):e.bytes}},Rr=class{_key;_publicKey;constructor(e,t){this._key=hn(e,Pt),this._publicKey=hn(t,ln)}sign(e){return hh(this._key,e)}get public(){return new Qn(this._publicKey)}marshal(){return this._key}get bytes(){return Et.encode({Type:he.Ed25519,Data:this.marshal()}).subarray()}equals(e){return Ae(this.bytes,e.bytes)}async hash(){let e=_e.digest(this.bytes),t;return Je(e)?{bytes:t}=await e:t=e.bytes,t}async id(){let e=It.digest(this.public.bytes);return ge.encode(e.bytes).substring(1)}async export(e,t="libp2p-key"){if(t==="libp2p-key")return fn(this.bytes,e);throw new L(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function Ry(r){if(r.length>Pt){r=hn(r,Pt+ln);let n=r.subarray(0,Pt),o=r.subarray(Pt,r.length);return new Rr(n,o)}r=hn(r,Pt);let e=r.subarray(0,Pt),t=r.subarray(ln);return new Rr(e,t)}function Ny(r){return r=hn(r,ln),new Qn(r)}async function Ly(){let{privateKey:r,publicKey:e}=lh();return new Rr(r,e)}async function gh(r){let{privateKey:e,publicKey:t}=fh(r);return new Rr(e,t)}function hn(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new L(`Key must be a Uint8Array of length ${e}, got ${r.length}`,"ERR_INVALID_KEY_TYPE");return r}var Hc={};Q(Hc,{MAX_RSA_KEY_SIZE:()=>lo,RsaPrivateKey:()=>bn,RsaPublicKey:()=>uo,fromJwk:()=>aw,generateKeyPair:()=>cw,unmarshalRsaPrivateKey:()=>Fc,unmarshalRsaPublicKey:()=>iw});function Nr(r){if(isNaN(r)||r<=0)throw new L("random bytes length must be a Number bigger than 0","ERR_INVALID_LENGTH");return Ir(r)}var ur={};Q(ur,{exportToPem:()=>tw,importFromPem:()=>rw,jwkToPkcs1:()=>Xy,jwkToPkix:()=>Qy,pkcs1ToJwk:()=>Zy,pkixToJwk:()=>Jy});var Ss=class extends on{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,Cr(e);let n=ut(t);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?e.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=e.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),s.fill(0)}update(e){return nn(this),this.iHash.update(e),this}digestInto(e){nn(this),rn(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:t,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=a,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},sr=(r,e,t)=>new Ss(r,e).update(t).digest();sr.create=(r,e)=>new Ss(r,e);function Uy(r,e,t,n){Cr(r);let o=Wf({dkLen:32,asyncTick:10},n),{c:s,dkLen:i,asyncTick:a}=o;if(er(s),er(i),er(a),s<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let c=ut(e),u=ut(t),l=new Uint8Array(i),f=sr.create(r,c),m=f._cloneInto().update(u);return{c:s,dkLen:i,asyncTick:a,DK:l,PRF:f,PRFSalt:m}}function Oy(r,e,t,n,o){return r.destroy(),e.destroy(),n&&n.destroy(),o.fill(0),t}async function Rc(r,e,t,n){let{c:o,dkLen:s,asyncTick:i,DK:a,PRF:c,PRFSalt:u}=Uy(r,e,t,n),l,f=new Uint8Array(4),m=sn(f),g=new Uint8Array(c.outputLen);for(let p=1,h=0;h<s;p++,h+=c.outputLen){let d=a.subarray(h,h+c.outputLen);m.setInt32(0,p,!1),(l=u._cloneInto(l)).update(f).digestInto(g),d.set(g.subarray(0,d.length)),await $f(o-1,i,()=>{c._cloneInto(l).update(g).digestInto(g);for(let y=0;y<d.length;y++)d[y]^=g[y]})}return Oy(c,u,a,l,g)}var X=Bo(bh());function Lr(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 ir(r,e,t=-1){let n=t,o=r,s=0,i=Math.pow(2,e);for(let a=1;a<8;a++){if(r<i){let c;if(n<0)c=new ArrayBuffer(a),s=a;else{if(n<a)return new ArrayBuffer(0);c=new ArrayBuffer(n),s=n}let u=new Uint8Array(c);for(let l=a-1;l>=0;l--){let f=Math.pow(2,l*e);u[s-l-1]=Math.floor(o/f),o-=u[s-l-1]*f}return c}i*=Math.pow(2,e)}return new ArrayBuffer(0)}function Cs(...r){let e=0,t=0;for(let s of r)e+=s.length;let n=new ArrayBuffer(e),o=new Uint8Array(n);for(let s of r)o.set(s,t),t+=s.length;return o}function Lc(){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=Lr(t,8),o=new ArrayBuffer(this.valueHex.byteLength),s=new Uint8Array(o);for(let a=0;a<this.valueHex.byteLength;a++)s[a]=r[a];return s[0]&=127,Lr(s,8)-n}function yh(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=ir(i,8,n),c=new Uint8Array(a);return c[0]|=128,a}let o=ir(e,8,n),s=new Uint8Array(o);if(s[0]&128){let i=o.slice(0),a=new Uint8Array(i);o=new ArrayBuffer(o.byteLength+1),s=new Uint8Array(o);for(let c=0;c<i.byteLength;c++)s[c+1]=a[c];s[0]=0}return o}t*=Math.pow(2,8)}return new ArrayBuffer(0)}function wh(r,e){if(r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let o=0;o<t.length;o++)if(t[o]!==n[o])return!1;return!0}function We(r,e){let t=r.toString(10);if(e<t.length)return"";let n=e-t.length,o=new Array(n);for(let i=0;i<n;i++)o[i]="0";return o.join("").concat(t)}var ND=Math.log(2);function Is(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function Uc(r){let e=0,t=0;for(let o=0;o<r.length;o++){let s=r[o];e+=s.byteLength}let n=new Uint8Array(e);for(let o=0;o<r.length;o++){let s=r[o];n.set(new Uint8Array(s),t),t+=s.byteLength}return n.buffer}function 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 to=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return Uc(this.items)}},eo=[new Uint8Array([1])],xh="0123456789";var mn="",dt=new ArrayBuffer(0),Oc=new Uint8Array(0),ro="EndOfContent",vh="OCTET STRING",Ah="BIT STRING";function $t(r){var e;return e=class extends r{constructor(...n){var o;super(...n);let s=n[0]||{};this.isHexOnly=(o=s.isHexOnly)!==null&&o!==void 0?o:!1,this.valueHexView=s.valueHex?X.BufferSourceConverter.toUint8Array(s.valueHex):Oc}get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}fromBER(n,o,s){let i=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!Kt(this,i,o,s))return-1;let a=o+s;return this.valueHexView=i.subarray(o,a),this.valueHexView.length?(this.blockLength=s,a):(this.warnings.push("Zero buffer length"),o)}toBER(n=!1){return this.isHexOnly?n?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.byteLength===this.valueHexView.buffer.byteLength?this.valueHexView.buffer:this.valueHexView.slice().buffer:(this.error="Flag 'isHexOnly' is not set, abort",dt)}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=mn,warnings:n=[],valueBeforeDecode:o=Oc}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=X.BufferSourceConverter.toUint8Array(o)}static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(e){this.valueBeforeDecodeView=new Uint8Array(e)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:X.Convert.ToHex(this.valueBeforeDecodeView)}}};Ft.NAME="baseBlock";var Fe=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'")}};Fe.NAME="valueBlock";var Ts=class extends $t(Ft){constructor({idBlock:e={}}={}){var t,n,o,s;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?X.BufferSourceConverter.toUint8Array(e.valueHex):Oc,this.tagClass=(n=e.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(o=e.tagNumber)!==null&&o!==void 0?o:-1,this.isConstructed=(s=e.isConstructed)!==null&&s!==void 0?s:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(e=!1){let t=0;switch(this.tagClass){case 1:t|=0;break;case 2:t|=64;break;case 3:t|=128;break;case 4:t|=192;break;default:return this.error="Unknown tag class",dt}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){let o=new Uint8Array(1);if(!e){let s=this.tagNumber;s&=31,t|=s,o[0]=t}return o.buffer}if(!this.isHexOnly){let o=ir(this.tagNumber,7),s=new Uint8Array(o),i=o.byteLength,a=new Uint8Array(i+1);if(a[0]=t|31,!e){for(let c=0;c<i-1;c++)a[c+1]=s[c]|128;a[i]=s[i-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=t|31,!e){let o=this.valueHexView;for(let s=0;s<o.length-1;s++)n[s+1]=o[s]|128;n[this.valueHexView.byteLength]=o[o.length-1]}return n.buffer}fromBER(e,t,n){let o=X.BufferSourceConverter.toUint8Array(e);if(!Kt(this,o,t,n))return-1;let s=o.subarray(t,t+n);if(s.length===0)return this.error="Zero buffer length",-1;switch(s[0]&192){case 0:this.tagClass=1;break;case 64:this.tagClass=2;break;case 128:this.tagClass=3;break;case 192:this.tagClass=4;break;default:return this.error="Unknown tag class",-1}this.isConstructed=(s[0]&32)===32,this.isHexOnly=!1;let a=s[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=1,u=this.valueHexView=new Uint8Array(255),l=255;for(;s[c]&128;){if(u[c-1]=s[c]&127,c++,c>=s.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]=s[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=Lr(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}}};Ts.NAME="identificationBlock";var _s=class extends Ft{constructor({lenBlock:e={}}={}){var t,n,o;super(),this.isIndefiniteForm=(t=e.isIndefiniteForm)!==null&&t!==void 0?t:!1,this.longFormUsed=(n=e.longFormUsed)!==null&&n!==void 0?n:!1,this.length=(o=e.length)!==null&&o!==void 0?o:0}fromBER(e,t,n){let o=X.BufferSourceConverter.toUint8Array(e);if(!Kt(this,o,t,n))return-1;let s=o.subarray(t,t+n);if(s.length===0)return this.error="Zero buffer length",-1;if(s[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=s[0]===128,this.isIndefiniteForm)return this.blockLength=1,t+this.blockLength;if(this.longFormUsed=!!(s[0]&128),this.longFormUsed===!1)return this.length=s[0],this.blockLength=1,t+this.blockLength;let i=s[0]&127;if(i>8)return this.error="Too big integer",-1;if(i+1>s.length)return this.error="End of input reached before message was fully decoded",-1;let a=t+1,c=o.subarray(a,a+i);return c[i-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=Lr(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=i+1,t+this.blockLength}toBER(e=!1){let t,n;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=128),t;if(this.longFormUsed){let o=ir(this.length,8);if(o.byteLength>127)return this.error="Too big length",dt;if(t=new ArrayBuffer(o.byteLength+1),e)return t;let s=new Uint8Array(o);n=new Uint8Array(t),n[0]=o.byteLength|128;for(let i=0;i<o.byteLength;i++)n[i+1]=s[i];return t}return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=this.length),t}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}};_s.NAME="lengthBlock";var M={},Ne=class extends Ft{constructor({name:e=mn,optional:t=!1,primitiveSchema:n,...o}={},s){super(o),this.name=e,this.optional=t,n&&(this.primitiveSchema=n),this.idBlock=new Ts(o),this.lenBlock=new _s(o),this.valueBlock=s?new s(o):new Fe(o)}fromBER(e,t,n){let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),o)}toBER(e,t){let n=t||new to;t||Dh(this);let o=this.idBlock.toBER(e);if(n.write(o),this.lenBlock.isIndefiniteForm)n.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,n),n.write(new ArrayBuffer(2));else{let s=this.valueBlock.toBER(e);this.lenBlock.length=s.byteLength;let i=this.lenBlock.toBER(e);n.write(i),n.write(s)}return t?dt: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 wh(t,n)}};Ne.NAME="BaseBlock";function Dh(r){if(r instanceof M.Constructed)for(let e of r.valueBlock.value)Dh(e)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var Rs=class extends Ne{constructor({value:e=mn,...t}={},n){super(t,n),e&&this.fromString(e)}getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}fromBER(e,t,n){let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(this.fromBuffer(this.valueBlock.valueHexView),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),o)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}};Rs.NAME="BaseStringBlock";var Ns=class extends $t(Fe){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};Ns.NAME="PrimitiveValueBlock";var Sh,Ls=class extends Ne{constructor(e={}){super(e,Ns),this.idBlock.isConstructed=!1}};Sh=Ls;M.Primitive=Sh;Ls.NAME="PRIMITIVE";function Wy(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 di(r,e=0,t=r.length){let n=e,o=new Ne({},Fe),s=new Ft;if(!Kt(s,r,e,t))return o.error=s.error,{offset:-1,result:o};if(!r.subarray(e,e+t).length)return o.error="Zero buffer length",{offset:-1,result:o};let a=o.idBlock.fromBER(r,e,t);if(o.idBlock.warnings.length&&o.warnings.concat(o.idBlock.warnings),a===-1)return o.error=o.idBlock.error,{offset:-1,result:o};if(e=a,t-=o.idBlock.blockLength,a=o.lenBlock.fromBER(r,e,t),o.lenBlock.warnings.length&&o.warnings.concat(o.lenBlock.warnings),a===-1)return o.error=o.lenBlock.error,{offset:-1,result:o};if(e=a,t-=o.lenBlock.blockLength,!o.idBlock.isConstructed&&o.lenBlock.isIndefiniteForm)return o.error="Indefinite length form used for primitive encoding form",{offset:-1,result:o};let c=Ne;switch(o.idBlock.tagClass){case 1:if(o.idBlock.tagNumber>=37&&o.idBlock.isHexOnly===!1)return o.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:o};switch(o.idBlock.tagNumber){case 0:if(o.idBlock.isConstructed&&o.lenBlock.length>0)return o.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:o};c=M.EndOfContent;break;case 1:c=M.Boolean;break;case 2:c=M.Integer;break;case 3:c=M.BitString;break;case 4:c=M.OctetString;break;case 5:c=M.Null;break;case 6:c=M.ObjectIdentifier;break;case 10:c=M.Enumerated;break;case 12:c=M.Utf8String;break;case 13:c=M.RelativeObjectIdentifier;break;case 14:c=M.TIME;break;case 15:return o.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:o};case 16:c=M.Sequence;break;case 17:c=M.Set;break;case 18:c=M.NumericString;break;case 19:c=M.PrintableString;break;case 20:c=M.TeletexString;break;case 21:c=M.VideotexString;break;case 22:c=M.IA5String;break;case 23:c=M.UTCTime;break;case 24:c=M.GeneralizedTime;break;case 25:c=M.GraphicString;break;case 26:c=M.VisibleString;break;case 27:c=M.GeneralString;break;case 28:c=M.UniversalString;break;case 29:c=M.CharacterString;break;case 30:c=M.BmpString;break;case 31:c=M.DATE;break;case 32:c=M.TimeOfDay;break;case 33:c=M.DateTime;break;case 34:c=M.Duration;break;default:{let u=o.idBlock.isConstructed?new M.Constructed:new M.Primitive;u.idBlock=o.idBlock,u.lenBlock=o.lenBlock,u.warnings=o.warnings,o=u}}break;case 2:case 3:case 4:default:c=o.idBlock.isConstructed?M.Constructed:M.Primitive}return o=Wy(o,c),a=o.fromBER(r,e,o.lenBlock.isIndefiniteForm?t:o.lenBlock.length),o.valueBeforeDecodeView=r.subarray(n,n+o.blockLength),{offset:a,result:o}}function gn(r){if(!r.byteLength){let e=new Ne({},Fe);return e.error="Input buffer has zero length",{offset:-1,result:e}}return di(X.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function zy(r,e){return r?1:e}var vt=class extends Fe{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let o=X.BufferSourceConverter.toUint8Array(e);if(!Kt(this,o,t,n))return-1;if(this.valueBeforeDecodeView=o.subarray(t,t+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),t;let s=t;for(;zy(this.isIndefiniteForm,n)>0;){let i=di(o,s,n);if(i.offset===-1)return this.error=i.result.error,this.warnings.concat(i.result.warnings),-1;if(s=i.offset,this.blockLength+=i.result.blockLength,n-=i.result.blockLength,this.value.push(i.result),this.isIndefiniteForm&&i.result.constructor.NAME===ro)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===ro?this.value.pop():this.warnings.push("No EndOfContent block encoded")),s}toBER(e,t){let n=t||new to;for(let o=0;o<this.value.length;o++)this.value[o].toBER(e,n);return t?dt:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};vt.NAME="ConstructedValueBlock";var Bh,ar=class extends Ne{constructor(e={}){super(e,vt),this.idBlock.isConstructed=!0}fromBER(e,t,n){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),o)}onAsciiEncoding(){let e=[];for(let n of this.valueBlock.value)e.push(n.toString("ascii").split(`
17
17
  `).map(o=>` ${o}`).join(`
18
18
  `));let t=this.idBlock.tagClass===3?`[${this.idBlock.tagNumber}]`:this.constructor.NAME;return e.length?`${t} :
19
19
  ${e.join(`
20
- `)}`:`${t} :`}};Eh=ar;M.Constructed=Eh;ar.NAME="CONSTRUCTED";var Ls=class extends Fe{fromBER(e,t,n){return t}toBER(e){return dt}};Ls.override="EndOfContentValueBlock";var vh,Us=class extends Ne{constructor(e={}){super(e,Ls),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};vh=Us;M.EndOfContent=vh;Us.NAME=to;var Ah,cr=class extends Ne{constructor(e={}){super(e,Fe),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(e,t,n){return this.lenBlock.length>0&&this.warnings.push("Non-zero length of value block for Null type"),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.blockLength+=n,t+n>e.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):t+n}toBER(e,t){let n=new ArrayBuffer(2);if(!e){let o=new Uint8Array(n);o[0]=5,o[1]=0}return t&&t.write(n),n}onAsciiEncoding(){return`${this.constructor.NAME}`}};Ah=cr;M.Null=Ah;cr.NAME="NULL";var Os=class extends Kt(Fe){constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=X.BufferSourceConverter.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}get value(){for(let e of this.valueHexView)if(e>0)return!0;return!1}set value(e){this.valueHexView[0]=e?255:0}fromBER(e,t,n){let o=X.BufferSourceConverter.toUint8Array(e);return Ht(this,o,t,n)?(this.valueHexView=o.subarray(t,t+n),n>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,Tc.call(this),this.blockLength=n,t+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};Os.NAME="BooleanValueBlock";var Dh,Ps=class extends Ne{constructor(e={}){super(e,Os),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};Dh=Ps;M.Boolean=Dh;Ps.NAME="BOOLEAN";var Ms=class extends Kt(vt){constructor({isConstructed:e=!1,...t}={}){super(t),this.isConstructed=e}fromBER(e,t,n){let o=0;if(this.isConstructed){if(this.isHexOnly=!1,o=vt.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let s=0;s<this.value.length;s++){let i=this.value[s].constructor.NAME;if(i===to){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(i!==bh)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,o=super.fromBER(e,t,n),this.blockLength=n;return o}toBER(e,t){return this.isConstructed?vt.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};Ms.NAME="OctetStringValueBlock";var Sh,Ft=class r extends Ne{constructor({idBlock:e={},lenBlock:t={},...n}={}){var o,s;(o=n.isConstructed)!==null&&o!==void 0||(n.isConstructed=!!(!((s=n.value)===null||s===void 0)&&s.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},Ms),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(e,t,n){if(this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,n===0)return this.idBlock.error.length===0&&(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length===0&&(this.blockLength+=this.lenBlock.blockLength),t;if(!this.valueBlock.isConstructed){let s=(e instanceof ArrayBuffer?new Uint8Array(e):e).subarray(t,t+n);try{if(s.byteLength){let i=hi(s,0,s.byteLength);i.offset!==-1&&i.offset===n&&(this.valueBlock.value=[i.result])}}catch{}}return super.fromBER(e,t,n)}onAsciiEncoding(){return this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length?ar.prototype.onAsciiEncoding.call(this):`${this.constructor.NAME} : ${X.Convert.ToHex(this.valueBlock.valueHexView)}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;let e=[];for(let t of this.valueBlock.value)t instanceof r&&e.push(t.valueBlock.valueHexView);return X.BufferSourceConverter.concat(e)}};Sh=Ft;M.OctetString=Sh;Ft.NAME=bh;var Fs=class extends Kt(vt){constructor({unusedBits:e=0,isConstructed:t=!1,...n}={}){super(n),this.unusedBits=e,this.isConstructed=t,this.blockLength=this.valueHexView.byteLength}fromBER(e,t,n){if(!n)return t;let o=-1;if(this.isConstructed){if(o=vt.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let a of this.value){let c=a.constructor.NAME;if(c===to){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==yh)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let l=a.valueBlock;if(this.unusedBits>0&&l.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=l.unusedBits}return o}let s=X.BufferSourceConverter.toUint8Array(e);if(!Ht(this,s,t,n))return-1;let i=s.subarray(t,t+n);if(this.unusedBits=i[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){let a=i.subarray(1);try{if(a.byteLength){let c=hi(a,0,a.byteLength);c.offset!==-1&&c.offset===n-1&&(this.value=[c.result])}}catch{}}return this.valueHexView=i.subarray(1),this.blockLength=i.length,t+n}toBER(e,t){if(this.isConstructed)return vt.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return dt;let n=new Uint8Array(this.valueHexView.length+1);return n[0]=this.unusedBits,n.set(this.valueHexView,1),n.buffer}toJSON(){return{...super.toJSON(),unusedBits:this.unusedBits,isConstructed:this.isConstructed}}};Fs.NAME="BitStringValueBlock";var Bh,pn=class extends Ne{constructor({idBlock:e={},lenBlock:t={},...n}={}){var o,s;(o=n.isConstructed)!==null&&o!==void 0||(n.isConstructed=!!(!((s=n.value)===null||s===void 0)&&s.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},Fs),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(e,t,n){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(e,t,n)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return ar.prototype.onAsciiEncoding.call(this);{let e=[],t=this.valueBlock.valueHexView;for(let o of t)e.push(o.toString(2).padStart(8,"0"));let n=e.join("");return`${this.constructor.NAME} : ${n.substring(0,n.length-this.valueBlock.unusedBits)}`}}};Bh=pn;M.BitString=Bh;pn.NAME=yh;var kh;function $y(r,e){let t=new Uint8Array([0]),n=new Uint8Array(r),o=new Uint8Array(e),s=n.slice(0),i=s.length-1,a=o.slice(0),c=a.length-1,l=0,u=c<i?i:c,f=0;for(let m=u;m>=0;m--,f++){switch(!0){case f<a.length:l=s[i-f]+a[c-f]+t[0];break;default:l=s[i-f]+t[0]}switch(t[0]=l/10,!0){case f>=s.length:s=ks(new Uint8Array([l%10]),s);break;default:s[i-f]=l%10}}return t[0]>0&&(s=ks(t,s)),s}function gh(r){if(r>=Qn.length)for(let e=Qn.length;e<=r;e++){let t=new Uint8Array([0]),n=Qn[e-1].slice(0);for(let o=n.length-1;o>=0;o--){let s=new Uint8Array([(n[o]<<1)+t[0]]);t[0]=s[0]/10,n[o]=s[0]%10}t[0]>0&&(n=ks(t,n)),Qn.push(n)}return Qn[r]}function qy(r,e){let t=0,n=new Uint8Array(r),o=new Uint8Array(e),s=n.slice(0),i=s.length-1,a=o.slice(0),c=a.length-1,l,u=0;for(let f=c;f>=0;f--,u++)switch(l=s[i-u]-a[c-u]-t,!0){case l<0:t=1,s[i-u]=l+10;break;default:t=0,s[i-u]=l}if(t>0)for(let f=i-c+1;f>=0;f--,u++)if(l=s[i-u]-t,l<0)t=1,s[i-u]=l+10;else{t=0,s[i-u]=l;break}return s.slice()}var ro=class extends Kt(Fe){constructor({value:e,...t}={}){super(t),this._valueDec=0,t.valueHex&&this.setValueHex(),e!==void 0&&(this.valueDec=e)}setValueHex(){this.valueHexView.length>=4?(this.warnings.push("Too big Integer for decoding, hex only"),this.isHexOnly=!0,this._valueDec=0):(this.isHexOnly=!1,this.valueHexView.length>0&&(this._valueDec=Tc.call(this)))}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(dh(e))}get valueDec(){return this._valueDec}fromDER(e,t,n,o=0){let s=this.fromBER(e,t,n);if(s===-1)return s;let i=this.valueHexView;return i[0]===0&&i[1]&128?this.valueHexView=i.subarray(1):o!==0&&i.length<o&&(o-i.length>1&&(o=i.length+1),this.valueHexView=i.subarray(o-i.length)),s}toDER(e=!1){let t=this.valueHexView;switch(!0){case(t[0]&128)!==0:{let n=new Uint8Array(this.valueHexView.length+1);n[0]=0,n.set(t,1),this.valueHexView=n}break;case(t[0]===0&&(t[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(e)}fromBER(e,t,n){let o=super.fromBER(e,t,n);return o===-1||this.setValueHex(),o}toBER(e){return e?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){let e=this.valueHexView.length*8-1,t=new Uint8Array(this.valueHexView.length*8/3),n=0,o,s=this.valueHexView,i="",a=!1;for(let c=s.byteLength-1;c>=0;c--){o=s[c];for(let l=0;l<8;l++){if((o&1)===1)switch(n){case e:t=qy(gh(n),t),i="-";break;default:t=$y(t,gh(n))}n++,o>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(i+=mh.charAt(t[c]));return a===!1&&(i+=mh.charAt(0)),i}};kh=ro;ro.NAME="IntegerValueBlock";Object.defineProperty(kh.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var Ch,Ee=class r extends Ne{constructor(e={}){super(e,ro),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return Cs(),BigInt(this.valueBlock.toString())}static fromBigInt(e){Cs();let t=BigInt(e),n=new eo,o=t.toString(16).replace(/^-/,""),s=new Uint8Array(X.Convert.FromHex(o));if(t<0){let a=new Uint8Array(s.length+(s[0]&128?1:0));a[0]|=128;let l=BigInt(`0x${X.Convert.ToHex(a)}`)+t,u=X.BufferSourceConverter.toUint8Array(X.Convert.FromHex(l.toString(16)));u[0]|=128,n.write(u)}else s[0]&128&&n.write(new Uint8Array([0])),n.write(s);return new r({valueHex:n.final()})}convertToDER(){let e=new r({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new r({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}};Ch=Ee;M.Integer=Ch;Ee.NAME="INTEGER";var Ih,Vs=class extends Ee{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};Ih=Vs;M.Enumerated=Ih;Vs.NAME="ENUMERATED";var no=class extends Kt(Fe){constructor({valueDec:e=-1,isFirstSid:t=!1,...n}={}){super(n),this.valueDec=e,this.isFirstSid=t}fromBER(e,t,n){if(!n)return t;let o=X.BufferSourceConverter.toUint8Array(e);if(!Ht(this,o,t,n))return-1;let s=o.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=s[a]&127,this.blockLength++,!!(s[a]&128));a++);let i=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)i[a]=this.valueHexView[a];return this.valueHexView=i,s[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=Lr(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){Cs();let t=BigInt(e).toString(2);for(;t.length%7;)t="0"+t;let n=new Uint8Array(t.length/7);for(let o=0;o<n.length;o++)n[o]=parseInt(t.slice(o*7,o*7+7),2)+(o+1<n.length?128:0);this.fromBER(n.buffer,0,n.length)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let o=this.valueHexView,s=new Uint8Array(this.blockLength);for(let i=0;i<this.blockLength-1;i++)s[i]=o[i]|128;return s[this.blockLength-1]=o[this.blockLength-1],s.buffer}let t=ir(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",dt;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),s=t.byteLength-1;for(let i=0;i<s;i++)n[i]=o[i]|128;n[s]=o[s]}return n}toString(){let e="";if(this.isHexOnly)e=X.Convert.ToHex(this.valueHexView);else if(this.isFirstSid){let t=this.valueDec;this.valueDec<=39?e="0.":this.valueDec<=79?(e="1.",t-=40):(e="2.",t-=80),e+=t.toString()}else e=this.valueDec.toString();return e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}};no.NAME="sidBlock";var Hs=class extends Fe{constructor({value:e=mn,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let s=new no;if(o=s.fromBER(e,o,n),o===-1)return this.blockLength=0,this.error=s.error,o;this.value.length===0&&(s.isFirstSid=!0),this.blockLength+=s.blockLength,n-=s.blockLength,this.value.push(s)}return o}toBER(e){let t=[];for(let n=0;n<this.value.length;n++){let o=this.value[n].toBER(e);if(o.byteLength===0)return this.error=this.value[n].error,dt;t.push(o)}return _c(t)}fromString(e){this.value=[];let t=0,n=0,o="",s=!1;do if(n=e.indexOf(".",t),n===-1?o=e.substring(t):o=e.substring(t,n),t=n+1,s){let i=this.value[0],a=0;switch(i.valueDec){case 0:break;case 1:a=40;break;case 2:a=80;break;default:this.value=[];return}let c=parseInt(o,10);if(isNaN(c))return;i.valueDec=c+a,s=!1}else{let i=new no;if(o>Number.MAX_SAFE_INTEGER){Cs();let a=BigInt(o);i.valueBigInt=a}else if(i.valueDec=parseInt(o,10),isNaN(i.valueDec))return;this.value.length||(i.isFirstSid=!0,s=!0),this.value.push(i)}while(n!==-1)}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let o=this.value[n].toString();n!==0&&(e=`${e}.`),t?(o=`{${o}}`,this.value[n].isFirstSid?e=`2.{${o} - 80}`:e+=o):e+=o}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};Hs.NAME="ObjectIdentifierValueBlock";var Th,ht=class extends Ne{constructor(e={}){super(e,Hs),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};Th=ht;M.ObjectIdentifier=Th;ht.NAME="OBJECT IDENTIFIER";var oo=class extends Kt(Mt){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,n){if(n===0)return t;let o=X.BufferSourceConverter.toUint8Array(e);if(!Ht(this,o,t,n))return-1;let s=o.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=s[a]&127,this.blockLength++,!!(s[a]&128));a++);let i=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)i[a]=this.valueHexView[a];return this.valueHexView=i,s[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=Lr(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let o=this.valueHexView,s=new Uint8Array(this.blockLength);for(let i=0;i<this.blockLength-1;i++)s[i]=o[i]|128;return s[this.blockLength-1]=o[this.blockLength-1],s.buffer}let t=ir(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",dt;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),s=t.byteLength-1;for(let i=0;i<s;i++)n[i]=o[i]|128;n[s]=o[s]}return n.buffer}toString(){let e="";return this.isHexOnly?e=X.Convert.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};oo.NAME="relativeSidBlock";var Ks=class extends Fe{constructor({value:e=mn,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let s=new oo;if(o=s.fromBER(e,o,n),o===-1)return this.blockLength=0,this.error=s.error,o;this.blockLength+=s.blockLength,n-=s.blockLength,this.value.push(s)}return o}toBER(e,t){let n=[];for(let o=0;o<this.value.length;o++){let s=this.value[o].toBER(e);if(s.byteLength===0)return this.error=this.value[o].error,dt;n.push(s)}return _c(n)}fromString(e){this.value=[];let t=0,n=0,o="";do{n=e.indexOf(".",t),n===-1?o=e.substring(t):o=e.substring(t,n),t=n+1;let s=new oo;if(s.valueDec=parseInt(o,10),isNaN(s.valueDec))return!0;this.value.push(s)}while(n!==-1);return!0}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let o=this.value[n].toString();n!==0&&(e=`${e}.`),t&&(o=`{${o}}`),e+=o}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};Ks.NAME="RelativeObjectIdentifierValueBlock";var _h,$s=class extends Ne{constructor(e={}){super(e,Ks),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};_h=$s;M.RelativeObjectIdentifier=_h;$s.NAME="RelativeObjectIdentifier";var Rh,Ce=class extends ar{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};Rh=Ce;M.Sequence=Rh;Ce.NAME="SEQUENCE";var Nh,qs=class extends ar{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};Nh=qs;M.Set=Nh;qs.NAME="SET";var Ws=class extends Kt(Fe){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=mn}toJSON(){return{...super.toJSON(),value:this.value}}};Ws.NAME="StringValueBlock";var zs=class extends Ws{};zs.NAME="SimpleStringValueBlock";var He=class extends _s{constructor({...e}={}){super(e,zs)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,X.BufferSourceConverter.toUint8Array(e))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t);for(let o=0;o<t;o++)n[o]=e.charCodeAt(o);this.valueBlock.value=e}};He.NAME="SIMPLE STRING";var Gs=class extends He{fromBuffer(e){this.valueBlock.valueHexView=X.BufferSourceConverter.toUint8Array(e);try{this.valueBlock.value=X.Convert.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=X.Convert.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(X.Convert.FromUtf8String(e)),this.valueBlock.value=e}};Gs.NAME="Utf8StringValueBlock";var Lh,Vt=class extends Gs{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};Lh=Vt;M.Utf8String=Lh;Vt.NAME="UTF8String";var js=class extends He{fromBuffer(e){this.valueBlock.value=X.Convert.ToUtf16String(e),this.valueBlock.valueHexView=X.BufferSourceConverter.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(X.Convert.FromUtf16String(e))}};js.NAME="BmpStringValueBlock";var Uh,Ys=class extends js{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};Uh=Ys;M.BmpString=Uh;Ys.NAME="BMPString";var Zs=class extends He{fromBuffer(e){let t=ArrayBuffer.isView(e)?e.slice().buffer:e.slice(0),n=new Uint8Array(t);for(let o=0;o<n.length;o+=4)n[o]=n[o+3],n[o+1]=n[o+2],n[o+2]=0,n[o+3]=0;this.valueBlock.value=String.fromCharCode.apply(null,new Uint32Array(t))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t*4);for(let o=0;o<t;o++){let s=ir(e.charCodeAt(o),8),i=new Uint8Array(s);if(i.length>4)continue;let a=4-i.length;for(let c=i.length-1;c>=0;c--)n[o*4+c+a]=i[c]}this.valueBlock.value=e}};Zs.NAME="UniversalStringValueBlock";var Oh,Xs=class extends Zs{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};Oh=Xs;M.UniversalString=Oh;Xs.NAME="UniversalString";var Ph,Js=class extends He{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};Ph=Js;M.NumericString=Ph;Js.NAME="NumericString";var Mh,Qs=class extends He{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};Mh=Qs;M.PrintableString=Mh;Qs.NAME="PrintableString";var Fh,ei=class extends He{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};Fh=ei;M.TeletexString=Fh;ei.NAME="TeletexString";var Vh,ti=class extends He{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};Vh=ti;M.VideotexString=Vh;ti.NAME="VideotexString";var Hh,ri=class extends He{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};Hh=ri;M.IA5String=Hh;ri.NAME="IA5String";var Kh,ni=class extends He{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};Kh=ni;M.GraphicString=Kh;ni.NAME="GraphicString";var $h,so=class extends He{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};$h=so;M.VisibleString=$h;so.NAME="VisibleString";var qh,oi=class extends He{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};qh=oi;M.GeneralString=qh;oi.NAME="GeneralString";var Wh,si=class extends He{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};Wh=si;M.CharacterString=Wh;si.NAME="CharacterString";var zh,io=class extends so{constructor({value:e,valueDate:t,...n}={}){if(super(n),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,e){this.fromString(e),this.valueBlock.valueHexView=new Uint8Array(e.length);for(let o=0;o<e.length;o++)this.valueBlock.valueHexView[o]=e.charCodeAt(o)}t&&(this.fromDate(t),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(e){this.fromString(String.fromCharCode.apply(null,X.BufferSourceConverter.toUint8Array(e)))}toBuffer(){let e=this.toString(),t=new ArrayBuffer(e.length),n=new Uint8Array(t);for(let o=0;o<e.length;o++)n[o]=e.charCodeAt(o);return t}fromDate(e){this.year=e.getUTCFullYear(),this.month=e.getUTCMonth()+1,this.day=e.getUTCDate(),this.hour=e.getUTCHours(),this.minute=e.getUTCMinutes(),this.second=e.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(e){let n=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig.exec(e);if(n===null){this.error="Wrong input string for conversion";return}let o=parseInt(n[1],10);o>=50?this.year=1900+o:this.year=2e3+o,this.month=parseInt(n[2],10),this.day=parseInt(n[3],10),this.hour=parseInt(n[4],10),this.minute=parseInt(n[5],10),this.second=parseInt(n[6],10)}toString(e="iso"){if(e==="iso"){let t=new Array(7);return t[0]=We(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=We(this.month,2),t[2]=We(this.day,2),t[3]=We(this.hour,2),t[4]=We(this.minute,2),t[5]=We(this.second,2),t[6]="Z",t.join("")}return super.toString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.toDate().toISOString()}`}toJSON(){return{...super.toJSON(),year:this.year,month:this.month,day:this.day,hour:this.hour,minute:this.minute,second:this.second}}};zh=io;M.UTCTime=zh;io.NAME="UTCTime";var Gh,ii=class extends io{constructor(e={}){var t;super(e),(t=this.millisecond)!==null&&t!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(e){super.fromDate(e),this.millisecond=e.getUTCMilliseconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond))}fromString(e){let t=!1,n="",o="",s=0,i,a=0,c=0;if(e[e.length-1]==="Z")n=e.substring(0,e.length-1),t=!0;else{let f=new Number(e[e.length-1]);if(isNaN(f.valueOf()))throw new Error("Wrong input string for conversion");n=e}if(t){if(n.indexOf("+")!==-1)throw new Error("Wrong input string for conversion");if(n.indexOf("-")!==-1)throw new Error("Wrong input string for conversion")}else{let f=1,m=n.indexOf("+"),g="";if(m===-1&&(m=n.indexOf("-"),f=-1),m!==-1){if(g=n.substring(m+1),n=n.substring(0,m),g.length!==2&&g.length!==4)throw new Error("Wrong input string for conversion");let p=parseInt(g.substring(0,2),10);if(isNaN(p.valueOf()))throw new Error("Wrong input string for conversion");if(a=f*p,g.length===4){if(p=parseInt(g.substring(2,4),10),isNaN(p.valueOf()))throw new Error("Wrong input string for conversion");c=f*p}}}let l=n.indexOf(".");if(l===-1&&(l=n.indexOf(",")),l!==-1){let f=new Number(`0${n.substring(l)}`);if(isNaN(f.valueOf()))throw new Error("Wrong input string for conversion");s=f.valueOf(),o=n.substring(0,l)}else o=n;switch(!0){case o.length===8:if(i=/(\d{4})(\d{2})(\d{2})/ig,l!==-1)throw new Error("Wrong input string for conversion");break;case o.length===10:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,l!==-1){let f=60*s;this.minute=Math.floor(f),f=60*(f-this.minute),this.second=Math.floor(f),f=1e3*(f-this.second),this.millisecond=Math.floor(f)}break;case o.length===12:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,l!==-1){let f=60*s;this.second=Math.floor(f),f=1e3*(f-this.second),this.millisecond=Math.floor(f)}break;case o.length===14:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,l!==-1){let f=1e3*s;this.millisecond=Math.floor(f)}break;default:throw new Error("Wrong input string for conversion")}let u=i.exec(o);if(u===null)throw new Error("Wrong input string for conversion");for(let f=1;f<u.length;f++)switch(f){case 1:this.year=parseInt(u[f],10);break;case 2:this.month=parseInt(u[f],10);break;case 3:this.day=parseInt(u[f],10);break;case 4:this.hour=parseInt(u[f],10)+a;break;case 5:this.minute=parseInt(u[f],10)+c;break;case 6:this.second=parseInt(u[f],10);break;default:throw new Error("Wrong input string for conversion")}if(t===!1){let f=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=f.getUTCFullYear(),this.month=f.getUTCMonth(),this.day=f.getUTCDay(),this.hour=f.getUTCHours(),this.minute=f.getUTCMinutes(),this.second=f.getUTCSeconds(),this.millisecond=f.getUTCMilliseconds()}}toString(e="iso"){if(e==="iso"){let t=[];return t.push(We(this.year,4)),t.push(We(this.month,2)),t.push(We(this.day,2)),t.push(We(this.hour,2)),t.push(We(this.minute,2)),t.push(We(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(We(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};Gh=ii;M.GeneralizedTime=Gh;ii.NAME="GeneralizedTime";var jh,ai=class extends Vt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};jh=ai;M.DATE=jh;ai.NAME="DATE";var Yh,ci=class extends Vt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};Yh=ci;M.TimeOfDay=Yh;ci.NAME="TimeOfDay";var Zh,li=class extends Vt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};Zh=li;M.DateTime=Zh;li.NAME="DateTime";var Xh,ui=class extends Vt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};Xh=ui;M.Duration=Xh;ui.NAME="Duration";var Jh,fi=class extends Vt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};Jh=fi;M.TIME=Jh;fi.NAME="TIME";function zy(r){let{result:e}=gn(r),t=e.valueBlock.value;return{n:z(At(t[1].toBigInt()),"base64url"),e:z(At(t[2].toBigInt()),"base64url"),d:z(At(t[3].toBigInt()),"base64url"),p:z(At(t[4].toBigInt()),"base64url"),q:z(At(t[5].toBigInt()),"base64url"),dp:z(At(t[6].toBigInt()),"base64url"),dq:z(At(t[7].toBigInt()),"base64url"),qi:z(At(t[8].toBigInt()),"base64url"),kty:"RSA",alg:"RS256"}}function Gy(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new L("JWK was missing components","ERR_INVALID_PARAMETERS");let t=new Ce({value:[new Ee({value:0}),Ee.fromBigInt(Dt(Q(r.n,"base64url"))),Ee.fromBigInt(Dt(Q(r.e,"base64url"))),Ee.fromBigInt(Dt(Q(r.d,"base64url"))),Ee.fromBigInt(Dt(Q(r.p,"base64url"))),Ee.fromBigInt(Dt(Q(r.q,"base64url"))),Ee.fromBigInt(Dt(Q(r.dp,"base64url"))),Ee.fromBigInt(Dt(Q(r.dq,"base64url"))),Ee.fromBigInt(Dt(Q(r.qi,"base64url")))]}).toBER();return new Uint8Array(t,0,t.byteLength)}function jy(r){let{result:e}=gn(r),t=e.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:z(At(t[0].toBigInt()),"base64url"),e:z(At(t[1].toBigInt()),"base64url")}}function Yy(r){if(r.n==null||r.e==null)throw new L("JWK was missing components","ERR_INVALID_PARAMETERS");let t=new Ce({value:[new Ce({value:[new ht({value:"1.2.840.113549.1.1.1"}),new cr]}),new pn({valueHex:new Ce({value:[Ee.fromBigInt(Dt(Q(r.n,"base64url"))),Ee.fromBigInt(Dt(Q(r.e,"base64url")))]}).toBER()})]}).toBER();return new Uint8Array(t,0,t.byteLength)}function At(r){let e=r.toString(16);e.length%2>0&&(e=`0${e}`);let t=e.length/2,n=new Uint8Array(t),o=0,s=0;for(;o<t;)n[o]=parseInt(e.slice(s,s+2),16),o+=1,s+=2;return n}function Dt(r){let e=[];return r.forEach(function(t){let n=t.toString(16);n.length%2>0&&(n=`0${n}`),e.push(n)}),BigInt("0x"+e.join(""))}var Zy=16,Nc=32,Lc=1e4;async function Xy(r,e){let t=Ve.get(),o=new Ce({value:[new Ee({value:0}),new Ce({value:[new ht({value:"1.2.840.113549.1.1.1"}),new cr]}),new Ft({valueHex:r.marshal()})]}).toBER(),s=new Uint8Array(o,0,o.byteLength),i=Nr(Zy),a=await Cc(zn,e,i,{c:Lc,dkLen:Nc}),c=Nr(16),l=await t.subtle.importKey("raw",a,"AES-CBC",!1,["encrypt"]),u=await t.subtle.encrypt({name:"AES-CBC",iv:c},l,s),f=new Ce({value:[new Ft({valueHex:i}),new Ee({value:Lc}),new Ee({value:Nc}),new Ce({value:[new ht({value:"1.2.840.113549.2.11"}),new cr]})]}),m=new Ce({value:[new ht({value:"1.2.840.113549.1.5.13"}),new Ce({value:[new Ce({value:[new ht({value:"1.2.840.113549.1.5.12"}),f]}),new Ce({value:[new ht({value:"2.16.840.1.101.3.4.1.42"}),new Ft({valueHex:c})]})]})]}),p=new Ce({value:[m,new Ft({valueHex:u})]}).toBER(),h=new Uint8Array(p,0,p.byteLength);return["-----BEGIN ENCRYPTED PRIVATE KEY-----",...z(h,"base64pad").split(/(.{64})/).filter(Boolean),"-----END ENCRYPTED PRIVATE KEY-----"].join(`
21
- `)}async function Jy(r,e){let t=Ve.get(),n;if(r.includes("-----BEGIN ENCRYPTED PRIVATE KEY-----")){let o=Q(r.replace("-----BEGIN ENCRYPTED PRIVATE KEY-----","").replace("-----END ENCRYPTED PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:s}=gn(o),{iv:i,salt:a,iterations:c,keySize:l,cipherText:u}=Qy(s),f=await Cc(zn,e,a,{c,dkLen:l}),m=await t.subtle.importKey("raw",f,"AES-CBC",!1,["decrypt"]),g=ao(await t.subtle.decrypt({name:"AES-CBC",iv:i},m,u)),{result:p}=gn(g);n=Qh(p)}else if(r.includes("-----BEGIN PRIVATE KEY-----")){let o=Q(r.replace("-----BEGIN PRIVATE KEY-----","").replace("-----END PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:s}=gn(o);n=Qh(s)}else throw new L("Could not parse private key from PEM data","ERR_INVALID_PARAMETERS");return Uc(n)}function Qy(r){let e=r.valueBlock.value[0];if(e.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.13")throw new L("Only pkcs5PBES2 encrypted private keys are supported","ERR_INVALID_PARAMS");let n=e.valueBlock.value[1].valueBlock.value[0];if(n.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.12")throw new L("Only pkcs5PBKDF2 key derivation functions are supported","ERR_INVALID_PARAMS");let s=n.valueBlock.value[1],i=ao(s.valueBlock.value[0].getValue()),a=Lc,c=Nc;if(s.valueBlock.value.length===3)a=Number(s.valueBlock.value[1].toBigInt()),c=Number(s.valueBlock.value[2].toBigInt());else if(s.valueBlock.value.length===2)throw new L("Could not derive key size and iterations from PEM file - please use @libp2p/rsa to re-import your key","ERR_INVALID_PARAMS");let l=e.valueBlock.value[1].valueBlock.value[1],u=l.valueBlock.value[0].toString();if(u!=="OBJECT IDENTIFIER : 1.2.840.113549.3.7"){if(u!=="OBJECT IDENTIFIER : 1.3.14.3.2.7"){if(u!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.2"){if(u!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.22"){if(u!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.42")throw new L("Only AES-CBC encryption schemes are supported","ERR_INVALID_PARAMS")}}}}let f=ao(l.valueBlock.value[1].getValue());return{cipherText:ao(r.valueBlock.value[1].getValue()),salt:i,iterations:a,keySize:c,iv:f}}function Qh(r){return ao(r.valueBlock.value[2].getValue())}function ao(r){return new Uint8Array(r,0,r.byteLength)}async function ed(r){let e=await Ve.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),t=await nd(e);return{privateKey:t[0],publicKey:t[1]}}async function Oc(r){let t=[await Ve.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),await ew(r)],n=await nd({privateKey:t[0],publicKey:t[1]});return{privateKey:n[0],publicKey:n[1]}}async function td(r,e){let t=await Ve.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await Ve.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},t,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(n,0,n.byteLength)}async function rd(r,e,t){let n=await Ve.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return Ve.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,e,t instanceof Uint8Array?t:t.subarray())}async function nd(r){if(r.privateKey==null||r.publicKey==null)throw new L("Private and public key are required","ERR_INVALID_PARAMETERS");return Promise.all([Ve.get().subtle.exportKey("jwk",r.privateKey),Ve.get().subtle.exportKey("jwk",r.publicKey)])}async function ew(r){return Ve.get().subtle.importKey("jwk",{kty:r.kty,n:r.n,e:r.e},{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])}function di(r){if(r.kty!=="RSA")throw new L("invalid key type","ERR_INVALID_KEY_TYPE");if(r.n==null)throw new L("invalid key modulus","ERR_INVALID_KEY_MODULUS");return Q(r.n,"base64url").length*8}var lo=8192,co=class{_key;constructor(e){this._key=e}verify(e,t){return rd(this._key,t,e)}marshal(){return lr.jwkToPkix(this._key)}get bytes(){return xt.encode({Type:he.RSA,Data:this.marshal()}).subarray()}equals(e){return Ae(this.bytes,e.bytes)}hash(){let e=_e.digest(this.bytes);return Xe(e)?e.then(({bytes:t})=>t):e.bytes}},bn=class{_key;_publicKey;constructor(e,t){this._key=e,this._publicKey=t}genSecret(){return Nr(16)}sign(e){return td(this._key,e)}get public(){if(this._publicKey==null)throw new L("public key not provided","ERR_PUBKEY_NOT_PROVIDED");return new co(this._publicKey)}marshal(){return lr.jwkToPkcs1(this._key)}get bytes(){return Et.encode({Type:he.RSA,Data:this.marshal()}).subarray()}equals(e){return Ae(this.bytes,e.bytes)}hash(){let e=_e.digest(this.bytes);return Xe(e)?e.then(({bytes:t})=>t):e.bytes}async id(){let e=await this.public.hash();return z(e,"base58btc")}async export(e,t="pkcs-8"){if(t==="pkcs-8")return lr.exportToPem(this,e);if(t==="libp2p-key")return fn(this.bytes,e);throw new L(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};async function Uc(r){let e=lr.pkcs1ToJwk(r);if(di(e)>lo)throw new L("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let t=await Oc(e);return new bn(t.privateKey,t.publicKey)}function rw(r){let e=lr.pkixToJwk(r);if(di(e)>lo)throw new L("key size is too large","ERR_KEY_SIZE_TOO_LARGE");return new co(e)}async function nw(r){if(di(r)>lo)throw new L("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await Oc(r);return new bn(e.privateKey,e.publicKey)}async function ow(r){if(r>lo)throw new L("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await ed(r);return new bn(e.privateKey,e.publicKey)}var Kc={};J(Kc,{Secp256k1PrivateKey:()=>fo,Secp256k1PublicKey:()=>uo,generateKeyPair:()=>bw,unmarshalSecp256k1PrivateKey:()=>mw,unmarshalSecp256k1PublicKey:()=>gw});var sw=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),ur=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),fr=new Uint32Array(64),Mc=class extends an{constructor(){super(64,32,8,!1),this.A=ur[0]|0,this.B=ur[1]|0,this.C=ur[2]|0,this.D=ur[3]|0,this.E=ur[4]|0,this.F=ur[5]|0,this.G=ur[6]|0,this.H=ur[7]|0}get(){let{A:e,B:t,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[e,t,n,o,s,i,a,c]}set(e,t,n,o,s,i,a,c){this.A=e|0,this.B=t|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(e,t){for(let f=0;f<16;f++,t+=4)fr[f]=e.getUint32(t,!1);for(let f=16;f<64;f++){let m=fr[f-15],g=fr[f-2],p=ct(m,7)^ct(m,18)^m>>>3,h=ct(g,17)^ct(g,19)^g>>>10;fr[f]=h+fr[f-7]+p+fr[f-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:l,H:u}=this;for(let f=0;f<64;f++){let m=ct(a,6)^ct(a,11)^ct(a,25),g=u+m+Hf(a,c,l)+sw[f]+fr[f]|0,h=(ct(n,2)^ct(n,13)^ct(n,22))+Kf(n,o,s)|0;u=l,l=c,c=a,a=i+g|0,i=s,s=o,o=n,n=g+h|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,l=l+this.G|0,u=u+this.H|0,this.set(n,o,s,i,a,c,l,u)}roundClean(){fr.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var yn=ps(()=>new Mc);function iw(r){let e=jn(r);Je(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:t,Fp:n,a:o}=e;if(t){if(!n.eql(o,n.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof t!="object"||typeof t.beta!="bigint"||typeof t.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...e})}var{bytesToNumberBE:aw,hexToBytes:cw}=bs,Ur={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(r){let{Err:e}=Ur;if(r.length<2||r[0]!==2)throw new e("Invalid signature integer tag");let t=r[1],n=r.subarray(2,t+2);if(!t||n.length!==t)throw new e("Invalid signature integer: wrong length");if(n[0]&128)throw new e("Invalid signature integer: negative");if(n[0]===0&&!(n[1]&128))throw new e("Invalid signature integer: unnecessary leading zero");return{d:aw(n),l:r.subarray(t+2)}},toSig(r){let{Err:e}=Ur,t=typeof r=="string"?cw(r):r;cn(t);let n=t.length;if(n<2||t[0]!=48)throw new e("Invalid signature tag");if(t[1]!==n-2)throw new e("Invalid signature: incorrect length");let{d:o,l:s}=Ur._parseInt(t.subarray(2)),{d:i,l:a}=Ur._parseInt(s);if(a.length)throw new e("Invalid signature: left bytes after parsing");return{r:o,s:i}},hexFromSig(r){let e=l=>Number.parseInt(l[0],16)&8?"00"+l:l,t=l=>{let u=l.toString(16);return u.length&1?`0${u}`:u},n=e(t(r.s)),o=e(t(r.r)),s=n.length/2,i=o.length/2,a=t(s),c=t(i);return`30${t(i+s+4)}02${c}${o}02${a}${n}`}},$t=BigInt(0),et=BigInt(1),ZD=BigInt(2),od=BigInt(3),XD=BigInt(4);function lw(r){let e=iw(r),{Fp:t}=e,n=e.toBytes||((p,h,d)=>{let y=h.toAffine();return Ut(Uint8Array.from([4]),t.toBytes(y.x),t.toBytes(y.y))}),o=e.fromBytes||(p=>{let h=p.subarray(1),d=t.fromBytes(h.subarray(0,t.BYTES)),y=t.fromBytes(h.subarray(t.BYTES,2*t.BYTES));return{x:d,y}});function s(p){let{a:h,b:d}=e,y=t.sqr(p),x=t.mul(y,p);return t.add(t.add(x,t.mul(p,h)),d)}if(!t.eql(t.sqr(e.Gy),s(e.Gx)))throw new Error("bad generator point: equation left != right");function i(p){return typeof p=="bigint"&&$t<p&&p<e.n}function a(p){if(!i(p))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function c(p){let{allowedPrivateKeyLengths:h,nByteLength:d,wrapPrivateKey:y,n:x}=e;if(h&&typeof p!="bigint"){if(nr(p)&&(p=Rt(p)),typeof p!="string"||!h.includes(p.length))throw new Error("Invalid key");p=p.padStart(d*2,"0")}let b;try{b=typeof p=="bigint"?p:Nt(ce("private key",p,d))}catch{throw new Error(`private key must be ${d} bytes, hex or bigint, not ${typeof p}`)}return y&&(b=te(b,x)),a(b),b}let l=new Map;function u(p){if(!(p instanceof f))throw new Error("ProjectivePoint expected")}class f{constructor(h,d,y){if(this.px=h,this.py=d,this.pz=y,h==null||!t.isValid(h))throw new Error("x required");if(d==null||!t.isValid(d))throw new Error("y required");if(y==null||!t.isValid(y))throw new Error("z required")}static fromAffine(h){let{x:d,y}=h||{};if(!h||!t.isValid(d)||!t.isValid(y))throw new Error("invalid affine point");if(h instanceof f)throw new Error("projective point not allowed");let x=b=>t.eql(b,t.ZERO);return x(d)&&x(y)?f.ZERO:new f(d,y,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let d=t.invertBatch(h.map(y=>y.pz));return h.map((y,x)=>y.toAffine(d[x])).map(f.fromAffine)}static fromHex(h){let d=f.fromAffine(o(ce("pointHex",h)));return d.assertValidity(),d}static fromPrivateKey(h){return f.BASE.multiply(c(h))}_setWindowSize(h){this._WINDOW_SIZE=h,l.delete(this)}assertValidity(){if(this.is0()){if(e.allowInfinityPoint&&!t.is0(this.py))return;throw new Error("bad point: ZERO")}let{x:h,y:d}=this.toAffine();if(!t.isValid(h)||!t.isValid(d))throw new Error("bad point: x or y not FE");let y=t.sqr(d),x=s(h);if(!t.eql(y,x))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:h}=this.toAffine();if(t.isOdd)return!t.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){u(h);let{px:d,py:y,pz:x}=this,{px:b,py:A,pz:E}=h,v=t.eql(t.mul(d,E),t.mul(b,x)),S=t.eql(t.mul(y,E),t.mul(A,x));return v&&S}negate(){return new f(this.px,t.neg(this.py),this.pz)}double(){let{a:h,b:d}=e,y=t.mul(d,od),{px:x,py:b,pz:A}=this,E=t.ZERO,v=t.ZERO,S=t.ZERO,D=t.mul(x,x),_=t.mul(b,b),O=t.mul(A,A),R=t.mul(x,b);return R=t.add(R,R),S=t.mul(x,A),S=t.add(S,S),E=t.mul(h,S),v=t.mul(y,O),v=t.add(E,v),E=t.sub(_,v),v=t.add(_,v),v=t.mul(E,v),E=t.mul(R,E),S=t.mul(y,S),O=t.mul(h,O),R=t.sub(D,O),R=t.mul(h,R),R=t.add(R,S),S=t.add(D,D),D=t.add(S,D),D=t.add(D,O),D=t.mul(D,R),v=t.add(v,D),O=t.mul(b,A),O=t.add(O,O),D=t.mul(O,R),E=t.sub(E,D),S=t.mul(O,_),S=t.add(S,S),S=t.add(S,S),new f(E,v,S)}add(h){u(h);let{px:d,py:y,pz:x}=this,{px:b,py:A,pz:E}=h,v=t.ZERO,S=t.ZERO,D=t.ZERO,_=e.a,O=t.mul(e.b,od),R=t.mul(d,b),H=t.mul(y,A),V=t.mul(x,E),G=t.add(d,y),B=t.add(b,A);G=t.mul(G,B),B=t.add(R,H),G=t.sub(G,B),B=t.add(d,x);let I=t.add(b,E);return B=t.mul(B,I),I=t.add(R,V),B=t.sub(B,I),I=t.add(y,x),v=t.add(A,E),I=t.mul(I,v),v=t.add(H,V),I=t.sub(I,v),D=t.mul(_,B),v=t.mul(O,V),D=t.add(v,D),v=t.sub(H,D),D=t.add(H,D),S=t.mul(v,D),H=t.add(R,R),H=t.add(H,R),V=t.mul(_,V),B=t.mul(O,B),H=t.add(H,V),V=t.sub(R,V),V=t.mul(_,V),B=t.add(B,V),R=t.mul(H,B),S=t.add(S,R),R=t.mul(I,B),v=t.mul(G,v),v=t.sub(v,R),R=t.mul(G,H),D=t.mul(I,D),D=t.add(D,R),new f(v,S,D)}subtract(h){return this.add(h.negate())}is0(){return this.equals(f.ZERO)}wNAF(h){return g.wNAFCached(this,l,h,d=>{let y=t.invertBatch(d.map(x=>x.pz));return d.map((x,b)=>x.toAffine(y[b])).map(f.fromAffine)})}multiplyUnsafe(h){let d=f.ZERO;if(h===$t)return d;if(a(h),h===et)return this;let{endo:y}=e;if(!y)return g.unsafeLadder(this,h);let{k1neg:x,k1:b,k2neg:A,k2:E}=y.splitScalar(h),v=d,S=d,D=this;for(;b>$t||E>$t;)b&et&&(v=v.add(D)),E&et&&(S=S.add(D)),D=D.double(),b>>=et,E>>=et;return x&&(v=v.negate()),A&&(S=S.negate()),S=new f(t.mul(S.px,y.beta),S.py,S.pz),v.add(S)}multiply(h){a(h);let d=h,y,x,{endo:b}=e;if(b){let{k1neg:A,k1:E,k2neg:v,k2:S}=b.splitScalar(d),{p:D,f:_}=this.wNAF(E),{p:O,f:R}=this.wNAF(S);D=g.constTimeNegate(A,D),O=g.constTimeNegate(v,O),O=new f(t.mul(O.px,b.beta),O.py,O.pz),y=D.add(O),x=_.add(R)}else{let{p:A,f:E}=this.wNAF(d);y=A,x=E}return f.normalizeZ([y,x])[0]}multiplyAndAddUnsafe(h,d,y){let x=f.BASE,b=(E,v)=>v===$t||v===et||!E.equals(x)?E.multiplyUnsafe(v):E.multiply(v),A=b(this,d).add(b(h,y));return A.is0()?void 0:A}toAffine(h){let{px:d,py:y,pz:x}=this,b=this.is0();h==null&&(h=b?t.ONE:t.inv(x));let A=t.mul(d,h),E=t.mul(y,h),v=t.mul(x,h);if(b)return{x:t.ZERO,y:t.ZERO};if(!t.eql(v,t.ONE))throw new Error("invZ was invalid");return{x:A,y:E}}isTorsionFree(){let{h,isTorsionFree:d}=e;if(h===et)return!0;if(d)return d(f,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:d}=e;return h===et?this:d?d(f,this):this.multiplyUnsafe(e.h)}toRawBytes(h=!0){return this.assertValidity(),n(f,this,h)}toHex(h=!0){return Rt(this.toRawBytes(h))}}f.BASE=new f(e.Gx,e.Gy,t.ONE),f.ZERO=new f(t.ZERO,t.ONE,t.ZERO);let m=e.nBitLength,g=xs(f,e.endo?Math.ceil(m/2):m);return{CURVE:e,ProjectivePoint:f,normPrivateKeyToScalar:c,weierstrassEquation:s,isWithinCurveOrder:i}}function uw(r){let e=jn(r);return Je(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function sd(r){let e=uw(r),{Fp:t,n}=e,o=t.BYTES+1,s=2*t.BYTES+1;function i(B){return $t<B&&B<t.ORDER}function a(B){return te(B,n)}function c(B){return ys(B,n)}let{ProjectivePoint:l,normPrivateKeyToScalar:u,weierstrassEquation:f,isWithinCurveOrder:m}=lw({...e,toBytes(B,I,P){let k=I.toAffine(),w=t.toBytes(k.x),C=Ut;return P?C(Uint8Array.from([I.hasEvenY()?2:3]),w):C(Uint8Array.from([4]),w,t.toBytes(k.y))},fromBytes(B){let I=B.length,P=B[0],k=B.subarray(1);if(I===o&&(P===2||P===3)){let w=Nt(k);if(!i(w))throw new Error("Point is not on curve");let C=f(w),T;try{T=t.sqrt(C)}catch(q){let Y=q instanceof Error?": "+q.message:"";throw new Error("Point is not on curve"+Y)}let N=(T&et)===et;return(P&1)===1!==N&&(T=t.neg(T)),{x:w,y:T}}else if(I===s&&P===4){let w=t.fromBytes(k.subarray(0,t.BYTES)),C=t.fromBytes(k.subarray(t.BYTES,2*t.BYTES));return{x:w,y:C}}else throw new Error(`Point of length ${I} was invalid. Expected ${o} compressed bytes or ${s} uncompressed bytes`)}}),g=B=>Rt(or(B,e.nByteLength));function p(B){let I=n>>et;return B>I}function h(B){return p(B)?a(-B):B}let d=(B,I,P)=>Nt(B.slice(I,P));class y{constructor(I,P,k){this.r=I,this.s=P,this.recovery=k,this.assertValidity()}static fromCompact(I){let P=e.nByteLength;return I=ce("compactSignature",I,P*2),new y(d(I,0,P),d(I,P,2*P))}static fromDER(I){let{r:P,s:k}=Ur.toSig(ce("DER",I));return new y(P,k)}assertValidity(){if(!m(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!m(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(I){return new y(this.r,this.s,I)}recoverPublicKey(I){let{r:P,s:k,recovery:w}=this,C=S(ce("msgHash",I));if(w==null||![0,1,2,3].includes(w))throw new Error("recovery id invalid");let T=w===2||w===3?P+e.n:P;if(T>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");let N=w&1?"03":"02",$=l.fromHex(N+g(T)),q=c(T),Y=a(-C*q),W=a(k*q),j=l.BASE.multiplyAndAddUnsafe($,Y,W);if(!j)throw new Error("point at infinify");return j.assertValidity(),j}hasHighS(){return p(this.s)}normalizeS(){return this.hasHighS()?new y(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return Tr(this.toDERHex())}toDERHex(){return Ur.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Tr(this.toCompactHex())}toCompactHex(){return g(this.r)+g(this.s)}}let x={isValidPrivateKey(B){try{return u(B),!0}catch{return!1}},normPrivateKeyToScalar:u,randomPrivateKey:()=>{let B=vc(e.n);return Jf(e.randomBytes(B),e.n)},precompute(B=8,I=l.BASE){return I._setWindowSize(B),I.multiply(BigInt(3)),I}};function b(B,I=!0){return l.fromPrivateKey(B).toRawBytes(I)}function A(B){let I=nr(B),P=typeof B=="string",k=(I||P)&&B.length;return I?k===o||k===s:P?k===2*o||k===2*s:B instanceof l}function E(B,I,P=!0){if(A(B))throw new Error("first arg must be private key");if(!A(I))throw new Error("second arg must be public key");return l.fromHex(I).multiply(u(B)).toRawBytes(P)}let v=e.bits2int||function(B){let I=Nt(B),P=B.length*8-e.nBitLength;return P>0?I>>BigInt(P):I},S=e.bits2int_modN||function(B){return a(v(B))},D=Gn(e.nBitLength);function _(B){if(typeof B!="bigint")throw new Error("bigint expected");if(!($t<=B&&B<D))throw new Error(`bigint expected < 2^${e.nBitLength}`);return or(B,e.nByteLength)}function O(B,I,P=R){if(["recovered","canonical"].some(se=>se in P))throw new Error("sign() legacy options not supported");let{hash:k,randomBytes:w}=e,{lowS:C,prehash:T,extraEntropy:N}=P;C==null&&(C=!0),B=ce("msgHash",B),T&&(B=ce("prehashed msgHash",k(B)));let $=S(B),q=u(I),Y=[_(q),_($)];if(N!=null&&N!==!1){let se=N===!0?w(t.BYTES):N;Y.push(ce("extraEntropy",se))}let W=Ut(...Y),j=$;function ae(se){let Ie=v(se);if(!m(Ie))return;let Te=c(Ie),ve=l.BASE.multiply(Ie).toAffine(),Oe=a(ve.x);if(Oe===$t)return;let Bt=a(Te*a(j+Oe*q));if(Bt===$t)return;let pr=(ve.x===Oe?0:2)|Number(ve.y&et),Rn=Bt;return C&&p(Bt)&&(Rn=h(Bt),pr^=1),new y(Oe,Rn,pr)}return{seed:W,k2sig:ae}}let R={lowS:e.lowS,prehash:!1},H={lowS:e.lowS,prehash:!1};function V(B,I,P=R){let{seed:k,k2sig:w}=O(B,I,P),C=e;return bc(C.hash.outputLen,C.nByteLength,C.hmac)(k,w)}l.BASE._setWindowSize(8);function G(B,I,P,k=H){let w=B;if(I=ce("msgHash",I),P=ce("publicKey",P),"strict"in k)throw new Error("options.strict was renamed to lowS");let{lowS:C,prehash:T}=k,N,$;try{if(typeof w=="string"||nr(w))try{N=y.fromDER(w)}catch(ve){if(!(ve instanceof Ur.Err))throw ve;N=y.fromCompact(w)}else if(typeof w=="object"&&typeof w.r=="bigint"&&typeof w.s=="bigint"){let{r:ve,s:Oe}=w;N=new y(ve,Oe)}else throw new Error("PARSE");$=l.fromHex(P)}catch(ve){if(ve.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(C&&N.hasHighS())return!1;T&&(I=e.hash(I));let{r:q,s:Y}=N,W=S(I),j=c(Y),ae=a(W*j),se=a(q*j),Ie=l.BASE.multiplyAndAddUnsafe($,ae,se)?.toAffine();return Ie?a(Ie.x)===q:!1}return{CURVE:e,getPublicKey:b,getSharedSecret:E,sign:V,verify:G,ProjectivePoint:l,Signature:y,utils:x}}function fw(r){return{hash:r,hmac:(e,...t)=>sr(r,e,hc(...t)),randomBytes:Ir}}function id(r,e){let t=n=>sd({...r,...fw(n)});return Object.freeze({...t(e),create:t})}var ld=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),ad=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),hw=BigInt(1),Fc=BigInt(2),cd=(r,e)=>(r+e/Fc)/e;function dw(r){let e=ld,t=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),l=r*r*r%e,u=l*l*r%e,f=le(u,t,e)*u%e,m=le(f,t,e)*u%e,g=le(m,Fc,e)*l%e,p=le(g,o,e)*g%e,h=le(p,s,e)*p%e,d=le(h,a,e)*h%e,y=le(d,c,e)*d%e,x=le(y,a,e)*h%e,b=le(x,t,e)*u%e,A=le(b,i,e)*p%e,E=le(A,n,e)*l%e,v=le(E,Fc,e);if(!Vc.eql(Vc.sqr(v),r))throw new Error("Cannot find square root");return v}var Vc=ws(ld,void 0,void 0,{sqrt:dw}),pt=id({a:BigInt(0),b:BigInt(7),Fp:Vc,n:ad,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let e=ad,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-hw*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=t,i=BigInt("0x100000000000000000000000000000000"),a=cd(s*r,e),c=cd(-n*r,e),l=te(r-a*t-c*o,e),u=te(-a*n-c*s,e),f=l>i,m=u>i;if(f&&(l=e-l),m&&(u=e-u),l>i||u>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:l,k2neg:m,k2:u}}}},yn),iS=BigInt(0);var aS=pt.ProjectivePoint;function ud(){return pt.utils.randomPrivateKey()}function fd(r,e){let t=_e.digest(e instanceof Uint8Array?e:e.subarray());if(Xe(t))return t.then(({digest:n})=>pt.sign(n,r).toDERRawBytes()).catch(n=>{throw new L(String(n),"ERR_INVALID_INPUT")});try{return pt.sign(t.digest,r).toDERRawBytes()}catch(n){throw new L(String(n),"ERR_INVALID_INPUT")}}function hd(r,e,t){let n=_e.digest(t instanceof Uint8Array?t:t.subarray());if(Xe(n))return n.then(({digest:o})=>pt.verify(e,o,r)).catch(o=>{throw new L(String(o),"ERR_INVALID_INPUT")});try{return pt.verify(e,n.digest,r)}catch(o){throw new L(String(o),"ERR_INVALID_INPUT")}}function dd(r){return pt.ProjectivePoint.fromHex(r).toRawBytes(!0)}function pd(r){try{pt.getPublicKey(r,!0)}catch(e){throw new L(String(e),"ERR_INVALID_PRIVATE_KEY")}}function Hc(r){try{pt.ProjectivePoint.fromHex(r)}catch(e){throw new L(String(e),"ERR_INVALID_PUBLIC_KEY")}}function md(r){try{return pt.getPublicKey(r,!0)}catch(e){throw new L(String(e),"ERR_INVALID_PRIVATE_KEY")}}var uo=class{_key;constructor(e){Hc(e),this._key=e}verify(e,t){return hd(this._key,t,e)}marshal(){return dd(this._key)}get bytes(){return xt.encode({Type:he.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return Ae(this.bytes,e.bytes)}async hash(){let e=_e.digest(this.bytes),t;return Xe(e)?{bytes:t}=await e:t=e.bytes,t}},fo=class{_key;_publicKey;constructor(e,t){this._key=e,this._publicKey=t??md(e),pd(this._key),Hc(this._publicKey)}sign(e){return fd(this._key,e)}get public(){return new uo(this._publicKey)}marshal(){return this._key}get bytes(){return Et.encode({Type:he.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return Ae(this.bytes,e.bytes)}hash(){let e=_e.digest(this.bytes);return Xe(e)?e.then(({bytes:t})=>t):e.bytes}async id(){let e=await this.public.hash();return z(e,"base58btc")}async export(e,t="libp2p-key"){if(t==="libp2p-key")return fn(this.bytes,e);throw new L(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function mw(r){return new fo(r)}function gw(r){return new uo(r)}async function bw(){let r=ud();return new fo(r)}var Or={rsa:Pc,ed25519:kc,secp256k1:Kc};function gd(r){let e=Object.keys(Or).join(" / ");return new L(`invalid or unsupported key type ${r}. Must be ${e}`,"ERR_UNSUPPORTED_KEY_TYPE")}function bd(r){let e=xt.decode(r),t=e.Data??new Uint8Array;switch(e.Type){case he.RSA:return Or.rsa.unmarshalRsaPublicKey(t);case he.Ed25519:return Or.ed25519.unmarshalEd25519PublicKey(t);case he.Secp256k1:return Or.secp256k1.unmarshalSecp256k1PublicKey(t);default:throw gd(e.Type??"unknown")}}async function $c(r){let e=Et.decode(r),t=e.Data??new Uint8Array;switch(e.Type){case he.RSA:return Or.rsa.unmarshalRsaPrivateKey(t);case he.Ed25519:return Or.ed25519.unmarshalEd25519PrivateKey(t);case he.Secp256k1:return Or.secp256k1.unmarshalSecp256k1PrivateKey(t);default:throw gd(e.Type??"RSA")}}function qc(){let r=pe(),e=!1;return{sink:async t=>{if(e)throw new Error("already piped");e=!0,r.resolve(t)},source:async function*(){yield*await r.promise}()}}function yd(){let r=qc(),e=qc();return[{source:r.source,sink:e.sink},{source:e.source,sink:r.sink}]}function yw(r){return r[Symbol.asyncIterator]!=null}function ww(...r){let e=[];for(let t of r)yw(t)||e.push(t);return e.length===r.length?function*(){for(let t of e)yield*t}():async function*(){let t=Zt({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(r.map(async n=>{for await(let o of n)t.push(o)})),t.end()}catch(n){t.end(n)}}),yield*t}()}var wd=ww;function xd(r,...e){if(r==null)throw new Error("Empty pipeline");if(Wc(r)){let n=r;r=()=>n.source}else if(vd(r)||Ed(r)){let n=r;r=()=>n}let t=[r,...e];if(t.length>1&&Wc(t[t.length-1])&&(t[t.length-1]=t[t.length-1].sink),t.length>2)for(let n=1;n<t.length-1;n++)Wc(t[n])&&(t[n]=Ew(t[n]));return xw(...t)}var xw=(...r)=>{let e;for(;r.length>0;)e=r.shift()(e);return e},Ed=r=>r?.[Symbol.asyncIterator]!=null,vd=r=>r?.[Symbol.iterator]!=null,Wc=r=>r==null?!1:r.sink!=null&&r.source!=null,Ew=r=>e=>{let t=r.sink(e);if(t?.then!=null){let n=Zt({objectMode:!0});t.then(()=>{n.end()},i=>{n.end(i)});let o,s=r.source;if(Ed(s))o=async function*(){yield*s,n.end()};else if(vd(s))o=function*(){yield*s,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return wd(n,o())}return r.source};var wn=!!globalThis.process?.env?.DUMP_SESSION_KEYS;function pi(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`positive integer expected, not ${r}`)}function zc(r){if(typeof r!="boolean")throw new Error(`boolean expected, not ${r}`)}function Gc(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function ze(r,...e){if(!Gc(r))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(r.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${r.length}`)}function jc(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 Ad(r,e){ze(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var qt=r=>new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4)),Dd=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),vw=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!vw)throw new Error("Non little-endian hardware is not supported");function Aw(r){if(typeof r!="string")throw new Error(`string expected, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function mi(r){if(typeof r=="string")r=Aw(r);else if(Gc(r))r=r.slice();else throw new Error(`Uint8Array expected, got ${typeof r}`);return r}function Sd(r,e){if(e==null||typeof e!="object")throw new Error("options must be defined");return Object.assign(r,e)}function Bd(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}var Yc=(r,e)=>(Object.assign(e,r),e);function Zc(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(t>>o&s),a=Number(t&s),c=n?4:0,l=n?0:4;r.setUint32(e+c,i,n),r.setUint32(e+l,a,n)}var Le=(r,e)=>r[e++]&255|(r[e++]&255)<<8,Xc=class{constructor(e){this.blockLen=16,this.outputLen=16,this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.pos=0,this.finished=!1,e=mi(e),ze(e,32);let t=Le(e,0),n=Le(e,2),o=Le(e,4),s=Le(e,6),i=Le(e,8),a=Le(e,10),c=Le(e,12),l=Le(e,14);this.r[0]=t&8191,this.r[1]=(t>>>13|n<<3)&8191,this.r[2]=(n>>>10|o<<6)&7939,this.r[3]=(o>>>7|s<<9)&8191,this.r[4]=(s>>>4|i<<12)&255,this.r[5]=i>>>1&8190,this.r[6]=(i>>>14|a<<2)&8191,this.r[7]=(a>>>11|c<<5)&8065,this.r[8]=(c>>>8|l<<8)&8191,this.r[9]=l>>>5&127;for(let u=0;u<8;u++)this.pad[u]=Le(e,16+2*u)}process(e,t,n=!1){let o=n?0:2048,{h:s,r:i}=this,a=i[0],c=i[1],l=i[2],u=i[3],f=i[4],m=i[5],g=i[6],p=i[7],h=i[8],d=i[9],y=Le(e,t+0),x=Le(e,t+2),b=Le(e,t+4),A=Le(e,t+6),E=Le(e,t+8),v=Le(e,t+10),S=Le(e,t+12),D=Le(e,t+14),_=s[0]+(y&8191),O=s[1]+((y>>>13|x<<3)&8191),R=s[2]+((x>>>10|b<<6)&8191),H=s[3]+((b>>>7|A<<9)&8191),V=s[4]+((A>>>4|E<<12)&8191),G=s[5]+(E>>>1&8191),B=s[6]+((E>>>14|v<<2)&8191),I=s[7]+((v>>>11|S<<5)&8191),P=s[8]+((S>>>8|D<<8)&8191),k=s[9]+(D>>>5|o),w=0,C=w+_*a+O*(5*d)+R*(5*h)+H*(5*p)+V*(5*g);w=C>>>13,C&=8191,C+=G*(5*m)+B*(5*f)+I*(5*u)+P*(5*l)+k*(5*c),w+=C>>>13,C&=8191;let T=w+_*c+O*a+R*(5*d)+H*(5*h)+V*(5*p);w=T>>>13,T&=8191,T+=G*(5*g)+B*(5*m)+I*(5*f)+P*(5*u)+k*(5*l),w+=T>>>13,T&=8191;let N=w+_*l+O*c+R*a+H*(5*d)+V*(5*h);w=N>>>13,N&=8191,N+=G*(5*p)+B*(5*g)+I*(5*m)+P*(5*f)+k*(5*u),w+=N>>>13,N&=8191;let $=w+_*u+O*l+R*c+H*a+V*(5*d);w=$>>>13,$&=8191,$+=G*(5*h)+B*(5*p)+I*(5*g)+P*(5*m)+k*(5*f),w+=$>>>13,$&=8191;let q=w+_*f+O*u+R*l+H*c+V*a;w=q>>>13,q&=8191,q+=G*(5*d)+B*(5*h)+I*(5*p)+P*(5*g)+k*(5*m),w+=q>>>13,q&=8191;let Y=w+_*m+O*f+R*u+H*l+V*c;w=Y>>>13,Y&=8191,Y+=G*a+B*(5*d)+I*(5*h)+P*(5*p)+k*(5*g),w+=Y>>>13,Y&=8191;let W=w+_*g+O*m+R*f+H*u+V*l;w=W>>>13,W&=8191,W+=G*c+B*a+I*(5*d)+P*(5*h)+k*(5*p),w+=W>>>13,W&=8191;let j=w+_*p+O*g+R*m+H*f+V*u;w=j>>>13,j&=8191,j+=G*l+B*c+I*a+P*(5*d)+k*(5*h),w+=j>>>13,j&=8191;let ae=w+_*h+O*p+R*g+H*m+V*f;w=ae>>>13,ae&=8191,ae+=G*u+B*l+I*c+P*a+k*(5*d),w+=ae>>>13,ae&=8191;let se=w+_*d+O*h+R*p+H*g+V*m;w=se>>>13,se&=8191,se+=G*f+B*u+I*l+P*c+k*a,w+=se>>>13,se&=8191,w=(w<<2)+w|0,w=w+C|0,C=w&8191,w=w>>>13,T+=w,s[0]=C,s[1]=T,s[2]=N,s[3]=$,s[4]=q,s[5]=Y,s[6]=W,s[7]=j,s[8]=ae,s[9]=se}finalize(){let{h:e,pad:t}=this,n=new Uint16Array(10),o=e[1]>>>13;e[1]&=8191;for(let a=2;a<10;a++)e[a]+=o,o=e[a]>>>13,e[a]&=8191;e[0]+=o*5,o=e[0]>>>13,e[0]&=8191,e[1]+=o,o=e[1]>>>13,e[1]&=8191,e[2]+=o,n[0]=e[0]+5,o=n[0]>>>13,n[0]&=8191;for(let a=1;a<10;a++)n[a]=e[a]+o,o=n[a]>>>13,n[a]&=8191;n[9]-=8192;let s=(o^1)-1;for(let a=0;a<10;a++)n[a]&=s;s=~s;for(let a=0;a<10;a++)e[a]=e[a]&s|n[a];e[0]=(e[0]|e[1]<<13)&65535,e[1]=(e[1]>>>3|e[2]<<10)&65535,e[2]=(e[2]>>>6|e[3]<<7)&65535,e[3]=(e[3]>>>9|e[4]<<4)&65535,e[4]=(e[4]>>>12|e[5]<<1|e[6]<<14)&65535,e[5]=(e[6]>>>2|e[7]<<11)&65535,e[6]=(e[7]>>>5|e[8]<<8)&65535,e[7]=(e[8]>>>8|e[9]<<5)&65535;let i=e[0]+t[0];e[0]=i&65535;for(let a=1;a<8;a++)i=(e[a]+t[a]|0)+(i>>>16)|0,e[a]=i&65535}update(e){jc(this);let{buffer:t,blockLen:n}=this;e=mi(e);let o=e.length;for(let s=0;s<o;){let i=Math.min(n-this.pos,o-s);if(i===n){for(;n<=o-s;s+=n)this.process(e,s);continue}t.set(e.subarray(s,s+i),this.pos),this.pos+=i,s+=i,this.pos===n&&(this.process(t,0,!1),this.pos=0)}return this}destroy(){this.h.fill(0),this.r.fill(0),this.buffer.fill(0),this.pad.fill(0)}digestInto(e){jc(this),Ad(e,this),this.finished=!0;let{buffer:t,h:n}=this,{pos:o}=this;if(o){for(t[o++]=1;o<16;o++)t[o]=0;this.process(t,0,!0)}this.finalize();let s=0;for(let i=0;i<8;i++)e[s++]=n[i]>>>0,e[s++]=n[i]>>>8;return e}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}};function Dw(r){let e=(n,o)=>r(o).update(mi(n)).digest(),t=r(new Uint8Array(32));return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=n=>r(n),e}var kd=Dw(r=>new Xc(r));var Id=r=>Uint8Array.from(r.split("").map(e=>e.charCodeAt(0))),Sw=Id("expand 16-byte k"),Bw=Id("expand 32-byte k"),kw=qt(Sw),Td=qt(Bw),FS=Td.slice();function F(r,e){return r<<e|r>>>32-e}function Jc(r){return r.byteOffset%4===0}var gi=64,Cw=16,_d=2**32-1,Cd=new Uint32Array;function Iw(r,e,t,n,o,s,i,a){let c=o.length,l=new Uint8Array(gi),u=qt(l),f=Jc(o)&&Jc(s),m=f?qt(o):Cd,g=f?qt(s):Cd;for(let p=0;p<c;i++){if(r(e,t,n,u,i,a),i>=_d)throw new Error("arx: counter overflow");let h=Math.min(gi,c-p);if(f&&h===gi){let d=p/4;if(p%4!==0)throw new Error("arx: invalid block position");for(let y=0,x;y<Cw;y++)x=d+y,g[x]=m[x]^u[y];p+=gi;continue}for(let d=0,y;d<h;d++)y=p+d,s[y]=o[y]^l[d];p+=h}}function Qc(r,e){let{allowShortKeys:t,extendNonceFn:n,counterLength:o,counterRight:s,rounds:i}=Sd({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof r!="function")throw new Error("core must be a function");return pi(o),pi(i),zc(s),zc(t),(a,c,l,u,f=0)=>{ze(a),ze(c),ze(l);let m=l.length;if(u||(u=new Uint8Array(m)),ze(u),pi(f),f<0||f>=_d)throw new Error("arx: counter overflow");if(u.length<m)throw new Error(`arx: output (${u.length}) is shorter than data (${m})`);let g=[],p=a.length,h,d;if(p===32)h=a.slice(),g.push(h),d=Td;else if(p===16&&t)h=new Uint8Array(32),h.set(a),h.set(a,16),d=kw,g.push(h);else throw new Error(`arx: invalid 32-byte key, got length=${p}`);Jc(c)||(c=c.slice(),g.push(c));let y=qt(h);if(n){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");n(d,y,qt(c.subarray(0,16)),y),c=c.subarray(16)}let x=16-o;if(x!==c.length)throw new Error(`arx: nonce must be ${x} or 16 bytes`);if(x!==12){let A=new Uint8Array(12);A.set(c,s?0:12-c.length),c=A,g.push(c)}let b=qt(c);for(Iw(r,d,y,b,l,u,f,i);g.length>0;)g.pop().fill(0);return u}}function Ld(r,e,t,n,o,s=20){let i=r[0],a=r[1],c=r[2],l=r[3],u=e[0],f=e[1],m=e[2],g=e[3],p=e[4],h=e[5],d=e[6],y=e[7],x=o,b=t[0],A=t[1],E=t[2],v=i,S=a,D=c,_=l,O=u,R=f,H=m,V=g,G=p,B=h,I=d,P=y,k=x,w=b,C=A,T=E;for(let $=0;$<s;$+=2)v=v+O|0,k=F(k^v,16),G=G+k|0,O=F(O^G,12),v=v+O|0,k=F(k^v,8),G=G+k|0,O=F(O^G,7),S=S+R|0,w=F(w^S,16),B=B+w|0,R=F(R^B,12),S=S+R|0,w=F(w^S,8),B=B+w|0,R=F(R^B,7),D=D+H|0,C=F(C^D,16),I=I+C|0,H=F(H^I,12),D=D+H|0,C=F(C^D,8),I=I+C|0,H=F(H^I,7),_=_+V|0,T=F(T^_,16),P=P+T|0,V=F(V^P,12),_=_+V|0,T=F(T^_,8),P=P+T|0,V=F(V^P,7),v=v+R|0,T=F(T^v,16),I=I+T|0,R=F(R^I,12),v=v+R|0,T=F(T^v,8),I=I+T|0,R=F(R^I,7),S=S+H|0,k=F(k^S,16),P=P+k|0,H=F(H^P,12),S=S+H|0,k=F(k^S,8),P=P+k|0,H=F(H^P,7),D=D+V|0,w=F(w^D,16),G=G+w|0,V=F(V^G,12),D=D+V|0,w=F(w^D,8),G=G+w|0,V=F(V^G,7),_=_+O|0,C=F(C^_,16),B=B+C|0,O=F(O^B,12),_=_+O|0,C=F(C^_,8),B=B+C|0,O=F(O^B,7);let N=0;n[N++]=i+v|0,n[N++]=a+S|0,n[N++]=c+D|0,n[N++]=l+_|0,n[N++]=u+O|0,n[N++]=f+R|0,n[N++]=m+H|0,n[N++]=g+V|0,n[N++]=p+G|0,n[N++]=h+B|0,n[N++]=d+I|0,n[N++]=y+P|0,n[N++]=x+k|0,n[N++]=b+w|0,n[N++]=A+C|0,n[N++]=E+T|0}function Tw(r,e,t,n){let o=r[0],s=r[1],i=r[2],a=r[3],c=e[0],l=e[1],u=e[2],f=e[3],m=e[4],g=e[5],p=e[6],h=e[7],d=t[0],y=t[1],x=t[2],b=t[3];for(let E=0;E<20;E+=2)o=o+c|0,d=F(d^o,16),m=m+d|0,c=F(c^m,12),o=o+c|0,d=F(d^o,8),m=m+d|0,c=F(c^m,7),s=s+l|0,y=F(y^s,16),g=g+y|0,l=F(l^g,12),s=s+l|0,y=F(y^s,8),g=g+y|0,l=F(l^g,7),i=i+u|0,x=F(x^i,16),p=p+x|0,u=F(u^p,12),i=i+u|0,x=F(x^i,8),p=p+x|0,u=F(u^p,7),a=a+f|0,b=F(b^a,16),h=h+b|0,f=F(f^h,12),a=a+f|0,b=F(b^a,8),h=h+b|0,f=F(f^h,7),o=o+l|0,b=F(b^o,16),p=p+b|0,l=F(l^p,12),o=o+l|0,b=F(b^o,8),p=p+b|0,l=F(l^p,7),s=s+u|0,d=F(d^s,16),h=h+d|0,u=F(u^h,12),s=s+u|0,d=F(d^s,8),h=h+d|0,u=F(u^h,7),i=i+f|0,y=F(y^i,16),m=m+y|0,f=F(f^m,12),i=i+f|0,y=F(y^i,8),m=m+y|0,f=F(f^m,7),a=a+c|0,x=F(x^a,16),g=g+x|0,c=F(c^g,12),a=a+c|0,x=F(x^a,8),g=g+x|0,c=F(c^g,7);let A=0;n[A++]=o,n[A++]=s,n[A++]=i,n[A++]=a,n[A++]=d,n[A++]=y,n[A++]=x,n[A++]=b}var _w=Qc(Ld,{counterRight:!1,counterLength:4,allowShortKeys:!1}),Rw=Qc(Ld,{counterRight:!1,counterLength:8,extendNonceFn:Tw,allowShortKeys:!1});var Nw=new Uint8Array(16),Rd=(r,e)=>{r.update(e);let t=e.length%16;t&&r.update(Nw.subarray(t))},Lw=new Uint8Array(32);function Nd(r,e,t,n,o){let s=r(e,t,Lw),i=kd.create(s);o&&Rd(i,o),Rd(i,n);let a=new Uint8Array(16),c=Dd(a);Zc(c,0,BigInt(o?o.length:0),!0),Zc(c,8,BigInt(n.length),!0),i.update(a);let l=i.digest();return s.fill(0),l}var Ud=r=>(e,t,n)=>(ze(e,32),ze(t),{encrypt:(s,i)=>{let a=s.length,c=a+16;i?ze(i,c):i=new Uint8Array(c),r(e,t,s,i,1);let l=Nd(r,e,t,i.subarray(0,-16),n);return i.set(l,a),i},decrypt:(s,i)=>{let a=s.length,c=a-16;if(a<16)throw new Error("encrypted data must be at least 16 bytes");i?ze(i,c):i=new Uint8Array(c);let l=s.subarray(0,-16),u=s.subarray(-16),f=Nd(r,e,t,l,n);if(!Bd(u,f))throw new Error("invalid tag");return r(e,t,l,i,1),i}}),el=Yc({blockSize:64,nonceLength:12,tagLength:16},Ud(_w)),WS=Yc({blockSize:64,nonceLength:24,tagLength:16},Ud(Rw));function Pd(r,e,t){return Cr(r),t===void 0&&(t=new Uint8Array(r.outputLen)),sr(r,lt(t),lt(e))}var tl=new Uint8Array([0]),Od=new Uint8Array;function Md(r,e,t,n=32){if(Cr(r),er(n),n>255*r.outputLen)throw new Error("Length should be <= 255*HashLen");let o=Math.ceil(n/r.outputLen);t===void 0&&(t=Od);let s=new Uint8Array(o*r.outputLen),i=sr.create(r,e),a=i._cloneInto(),c=new Uint8Array(i.outputLen);for(let l=0;l<o;l++)tl[0]=l+1,a.update(l===0?Od:c).update(t).update(tl).digestInto(c),s.set(c,r.outputLen*l),i._cloneInto(a);return i.destroy(),a.destroy(),c.fill(0),tl.fill(0),s.slice(0,n)}var rl={hashSHA256(r){return yn(r.subarray())},getHKDF(r,e){let t=Pd(yn,e,r),o=Md(yn,t,void 0,96),s=o.subarray(0,32),i=o.subarray(32,64),a=o.subarray(64,96);return[s,i,a]},generateX25519KeyPair(){let r=Xn.utils.randomPrivateKey();return{publicKey:Xn.getPublicKey(r),privateKey:r}},generateX25519KeyPairFromSeed(r){return{publicKey:Xn.getPublicKey(r),privateKey:r}},generateX25519SharedKey(r,e){return Xn.getSharedSecret(r.subarray(),e.subarray())},chaCha20Poly1305Encrypt(r,e,t,n){return el(n,e,t).encrypt(r.subarray())},chaCha20Poly1305Decrypt(r,e,t,n,o){return el(n,e,t).decrypt(r.subarray(),o)}};var Fd=rl;function Vd(r){return{generateKeypair:r.generateX25519KeyPair,dh:(e,t)=>r.generateX25519SharedKey(e.privateKey,t).subarray(0,32),encrypt:r.chaCha20Poly1305Encrypt,decrypt:r.chaCha20Poly1305Decrypt,hash:r.hashSHA256,hkdf:r.getHKDF}}var xn=r=>{let e=Se(2);return e[0]=r>>8,e[1]=r,e};xn.bytes=2;var ho=r=>{if(r.length<2)throw RangeError("Could not decode int16BE");if(r instanceof Uint8Array){let e=0;return e+=r[0]<<8,e+=r[1],e}return r.getUint16(0)};ho.bytes=2;function Hd(r){return{xxHandshakeSuccesses:r.registerCounter("libp2p_noise_xxhandshake_successes_total",{help:"Total count of noise xxHandshakes successes_"}),xxHandshakeErrors:r.registerCounter("libp2p_noise_xxhandshake_error_total",{help:"Total count of noise xxHandshakes errors"}),encryptedPackets:r.registerCounter("libp2p_noise_encrypted_packets_total",{help:"Total count of noise encrypted packets successfully"}),decryptedPackets:r.registerCounter("libp2p_noise_decrypted_packets_total",{help:"Total count of noise decrypted packets"}),decryptErrors:r.registerCounter("libp2p_noise_decrypt_errors_total",{help:"Total count of noise decrypt errors"})}}function nl(r,e){!e.enabled||!wn||(r?(e(`LOCAL_STATIC_PUBLIC_KEY ${z(r.publicKey,"hex")}`),e(`LOCAL_STATIC_PRIVATE_KEY ${z(r.privateKey,"hex")}`)):e("Missing local static keys."))}function ol(r,e){!e.enabled||!wn||(r?(e(`LOCAL_PUBLIC_EPHEMERAL_KEY ${z(r.publicKey,"hex")}`),e(`LOCAL_PRIVATE_EPHEMERAL_KEY ${z(r.privateKey,"hex")}`)):e("Missing local ephemeral keys."))}function Kd(r,e){!e.enabled||!wn||e(r?`REMOTE_STATIC_PUBLIC_KEY ${z(r.subarray(),"hex")}`:"Missing remote static public key.")}function sl(r,e){!e.enabled||!wn||e(r?`REMOTE_EPHEMERAL_PUBLIC_KEY ${z(r.subarray(),"hex")}`:"Missing remote ephemeral keys.")}function il(r,e,t){!t.enabled||!wn||(t(`CIPHER_STATE_1 ${r.n.getUint64()} ${r.k&&z(r.k,"hex")}`),t(`CIPHER_STATE_2 ${e.n.getUint64()} ${e.k&&z(e.k,"hex")}`))}var bi=class r extends Error{code;constructor(e="Unexpected Peer"){super(e),this.code=r.code}static code="ERR_UNEXPECTED_PEER"},En=class r extends Error{code;constructor(e="Invalid crypto exchange"){super(e),this.code=r.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var Uw=0,Ow=4294967295,Pw="Cipherstate has reached maximum n, a new handshake must be performed",yi=class{n;bytes;view;constructor(e=Uw){this.n=e,this.bytes=De(12),this.view=new DataView(this.bytes.buffer,this.bytes.byteOffset,this.bytes.byteLength),this.view.setUint32(4,e,!0)}increment(){this.n++,this.view.setUint32(4,this.n,!0)}getBytes(){return this.bytes}getUint64(){return this.n}assertValue(){if(this.n>Ow)throw new Error(Pw)}};var Pr=De(0),vn=class{k;n;crypto;constructor(e,t=void 0,n=0){this.crypto=e,this.k=t,this.n=new yi(n)}hasKey(){return!!this.k}encryptWithAd(e,t){if(!this.hasKey())return t;this.n.assertValue();let n=this.crypto.encrypt(t,this.n.getBytes(),e,this.k);return this.n.increment(),n}decryptWithAd(e,t,n){if(!this.hasKey())return t;this.n.assertValue();let o=this.crypto.decrypt(t,this.n.getBytes(),e,this.k,n);return this.n.increment(),o}},al=class{cs;ck;h;crypto;constructor(e,t){this.crypto=e;let n=Q(t,"utf-8");this.h=Mw(e,n),this.ck=this.h,this.cs=new vn(e)}mixKey(e){let[t,n]=this.crypto.hkdf(this.ck,e);this.ck=t,this.cs=new vn(this.crypto,n)}mixHash(e){this.h=this.crypto.hash(new ue(this.h,e))}encryptAndHash(e){let t=this.cs.encryptWithAd(this.h,e);return this.mixHash(t),t}decryptAndHash(e){let t=this.cs.decryptWithAd(this.h,e);return this.mixHash(e),t}split(){let[e,t]=this.crypto.hkdf(this.ck,Pr);return[new vn(this.crypto,e),new vn(this.crypto,t)]}},cl=class{ss;s;e;rs;re;initiator;crypto;constructor(e){let{crypto:t,protocolName:n,prologue:o,initiator:s,s:i,e:a,rs:c,re:l}=e;this.crypto=t,this.ss=new al(t,n),this.ss.mixHash(o),this.initiator=s,this.s=i,this.e=a,this.rs=c,this.re=l}writeE(){if(this.e)throw new Error("ephemeral keypair is already set");let e=this.crypto.generateKeypair();return this.ss.mixHash(e.publicKey),this.e=e,e.publicKey}writeS(){if(!this.s)throw new Error("static keypair is not set");return this.ss.encryptAndHash(this.s.publicKey)}writeEE(){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.re))}writeES(){if(this.initiator){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}else{if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}}writeSE(){if(this.initiator){if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}else{if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}}readE(e,t=0){if(this.re)throw new Error("remote ephemeral public key is already set");if(e.byteLength<t+32)throw new Error("message is not long enough");this.re=e.sublist(t,t+32),this.ss.mixHash(this.re)}readS(e,t=0){if(this.rs)throw new Error("remote static public key is already set");let n=32+(this.ss.cs.hasKey()?16:0);if(e.byteLength<t+n)throw new Error("message is not long enough");let o=e.sublist(t,t+n);return this.rs=this.ss.decryptAndHash(o),n}readEE(){this.writeEE()}readES(){this.writeES()}readSE(){this.writeSE()}},po=class extends cl{writeMessageA(e){return new ue(this.writeE(),this.ss.encryptAndHash(e))}writeMessageB(e){let t=this.writeE();this.writeEE();let n=this.writeS();return this.writeES(),new ue(t,n,this.ss.encryptAndHash(e))}writeMessageC(e){let t=this.writeS();return this.writeSE(),new ue(t,this.ss.encryptAndHash(e))}readMessageA(e){try{return this.readE(e),this.ss.decryptAndHash(e.sublist(32))}catch(t){throw new En(`handshake stage 0 validation fail: ${t.message}`)}}readMessageB(e){try{this.readE(e),this.readEE();let t=this.readS(e,32);return this.readES(),this.ss.decryptAndHash(e.sublist(32+t))}catch(t){throw new En(`handshake stage 1 validation fail: ${t.message}`)}}readMessageC(e){try{let t=this.readS(e);return this.readSE(),this.ss.decryptAndHash(e.sublist(t))}catch(t){throw new En(`handshake stage 2 validation fail: ${t.message}`)}}};function Mw(r,e){if(e.length<=32){let t=De(32);return t.set(e),t}else return r.hash(e)}var wi;(function(r){let e;r.codec=()=>(e==null&&(e=at((t,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),t.webtransportCerthashes!=null)for(let s of t.webtransportCerthashes)n.uint32(10),n.bytes(s);o.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let o={webtransportCerthashes:[]},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let i=t.uint32();switch(i>>>3){case 1:{o.webtransportCerthashes.push(t.bytes());break}default:{t.skipType(i&7);break}}}return o})),e),r.encode=t=>it(t,r.codec()),r.decode=t=>st(t,r.codec())})(wi||(wi={}));var mo;(function(r){let e;r.codec=()=>(e==null&&(e=at((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.identityKey!=null&&t.identityKey.byteLength>0&&(n.uint32(10),n.bytes(t.identityKey)),t.identitySig!=null&&t.identitySig.byteLength>0&&(n.uint32(18),n.bytes(t.identitySig)),t.extensions!=null&&(n.uint32(34),wi.codec().encode(t.extensions,n)),o.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let o={identityKey:De(0),identitySig:De(0)},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let i=t.uint32();switch(i>>>3){case 1:{o.identityKey=t.bytes();break}case 2:{o.identitySig=t.bytes();break}case 4:{o.extensions=wi.codec().decode(t,t.uint32());break}default:{t.skipType(i&7);break}}}return o})),e),r.encode=t=>it(t,r.codec()),r.decode=t=>st(t,r.codec())})(mo||(mo={}));async function ll(r,e,t){let n=await r.sign($d(e));return mo.encode({identityKey:r.public.bytes,identitySig:n,extensions:t})}async function ul(r,e,t){try{let n=mo.decode(r);if(t){let i=t.subarray();if(!Ae(i,n.identityKey))throw new Error(`Payload identity key ${z(n.identityKey,"hex")} does not match expected remote identity key ${z(i,"hex")}`)}if(!e)throw new Error("Remote static does not exist");let o=$d(e);if(!await bd(n.identityKey).verify(o,n.identitySig))throw new Error("Invalid payload signature");return n}catch(n){throw new bi(n.message)}}function $d(r){let e=Q("noise-libp2p-static-key:");return r instanceof Uint8Array?xe([e,r],e.length+r.length):(r.prepend(e),r)}async function qd(r){let{log:e,connection:t,crypto:n,privateKey:o,prologue:s,s:i,remoteIdentityKey:a,extensions:c}=r,l=await ll(o,i.publicKey,c),u=new po({crypto:n,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!0,prologue:s,s:i});nl(u.s,e),e.trace("Stage 0 - Initiator starting to send first message."),await t.write(u.writeMessageA(Pr)),e.trace("Stage 0 - Initiator finished sending first message."),ol(u.e,e),e.trace("Stage 1 - Initiator waiting to receive first message from responder...");let f=u.readMessageB(await t.read());e.trace("Stage 1 - Initiator received the message."),sl(u.re,e),Kd(u.rs,e),e.trace("Initiator going to check remote's signature...");let m=await ul(f,u.rs,a);e.trace("All good with the signature!"),e.trace("Stage 2 - Initiator sending third handshake message."),await t.write(u.writeMessageC(l)),e.trace("Stage 2 - Initiator sent message with signed payload.");let[g,p]=u.ss.split();return il(g,p,e),{payload:m,encrypt:h=>g.encryptWithAd(Pr,h),decrypt:(h,d)=>p.decryptWithAd(Pr,h,d)}}async function Wd(r){let{log:e,connection:t,crypto:n,privateKey:o,prologue:s,s:i,remoteIdentityKey:a,extensions:c}=r,l=await ll(o,i.publicKey,c),u=new po({crypto:n,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!1,prologue:s,s:i});nl(u.s,e),e.trace("Stage 0 - Responder waiting to receive first message."),u.readMessageA(await t.read()),e.trace("Stage 0 - Responder received first message."),sl(u.re,e),e.trace("Stage 1 - Responder sending out first message with signed payload and static key."),await t.write(u.writeMessageB(l)),e.trace("Stage 1 - Responder sent the second handshake message with signed payload."),ol(u.e,e),e.trace("Stage 2 - Responder waiting for third handshake message...");let f=u.readMessageC(await t.read());e.trace("Stage 2 - Responder received the message, finished handshake.");let m=await ul(f,u.rs,a),[g,p]=u.ss.split();return il(g,p,e),{payload:m,encrypt:h=>p.encryptWithAd(Pr,h),decrypt:(h,d)=>g.decryptWithAd(Pr,h,d)}}var Gd=16;function jd(r,e){return async function*(t){for await(let n of t)for(let o=0;o<n.length;o+=65519){let s=o+65519;s>n.length&&(s=n.length);let i;n instanceof Uint8Array?i=r.encrypt(n.subarray(o,s)):i=r.encrypt(n.sublist(o,s)),e?.encryptedPackets.increment(),yield new ue(xn(i.byteLength),i)}}}function Yd(r,e){return async function*(t){for await(let n of t)for(let o=0;o<n.length;o+=65535){let s=o+65535;if(s>n.length&&(s=n.length),s-Gd<o)throw new Error("Invalid chunk");let i=n.sublist(o,s),a=n.subarray(o,s-Gd);try{let c=r.decrypt(i,a);e?.decryptedPackets.increment(),yield c}catch(c){throw e?.decryptErrors.increment(),c}}}}var xi=class{protocol="/noise";crypto;prologue;staticKey;extensions;metrics;components;constructor(e,t={}){let{staticNoiseKey:n,extensions:o,crypto:s,prologueBytes:i}=t,{metrics:a}=e;this.components=e;let c=s??Fd;this.crypto=Vd(c),this.extensions=o,this.metrics=a?Hd(a):void 0,n?this.staticKey=c.generateX25519KeyPairFromSeed(n):this.staticKey=c.generateX25519KeyPair(),this.prologue=i??De(0)}[Symbol.toStringTag]="@chainsafe/libp2p-noise";[Vr]=["@libp2p/connection-encryption","@chainsafe/libp2p-noise"];async secureOutbound(e,t,n){let o=Wn(t,{lengthEncoder:xn,lengthDecoder:ho,maxDataLength:65535});if(!e.privateKey)throw new L("local peerId does not contain private key","ERR_NO_PRIVATE_KEY");let s=await $c(e.privateKey),i=n?.publicKey,a=await this.performHandshakeInitiator(o,s,i),c=await this.createSecureConnection(o,a);return t.source=c.source,t.sink=c.sink,{conn:t,remoteExtensions:a.payload.extensions,remotePeer:await ia(a.payload.identityKey)}}async secureInbound(e,t,n){let o=Wn(t,{lengthEncoder:xn,lengthDecoder:ho,maxDataLength:65535});if(!e.privateKey)throw new L("local peerId does not contain private key","ERR_NO_PRIVATE_KEY");let s=await $c(e.privateKey),i=n?.publicKey,a=await this.performHandshakeResponder(o,s,i),c=await this.createSecureConnection(o,a);return t.source=c.source,t.sink=c.sink,{conn:t,remoteExtensions:a.payload.extensions,remotePeer:await ia(a.payload.identityKey)}}async performHandshakeInitiator(e,t,n){let o;try{o=await qd({connection:e,privateKey:t,remoteIdentityKey:n,log:this.components.logger.forComponent("libp2p:noise:xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:this.extensions}),this.metrics?.xxHandshakeSuccesses.increment()}catch(s){throw this.metrics?.xxHandshakeErrors.increment(),s}return o}async performHandshakeResponder(e,t,n){let o;try{o=await Wd({connection:e,privateKey:t,remoteIdentityKey:n,log:this.components.logger.forComponent("libp2p:noise:xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:this.extensions}),this.metrics?.xxHandshakeSuccesses.increment()}catch(s){throw this.metrics?.xxHandshakeErrors.increment(),s}return o}async createSecureConnection(e,t){let[n,o]=yd(),s=e.unwrap();return await xd(n,jd(t,this.metrics),s,i=>Er(i,{lengthDecoder:ho}),Yd(t,this.metrics),n),o}};function Zd(r={}){return e=>new xi(e,r)}var B0=So(Vl(),1);var w0=So(Vl(),1);var Hl=Object.values(bt).map(r=>r.decoder).reduce((r,e)=>r.or(e));function x0(r,e){let t=r.getConfiguration().certificates?.at(0);if(t==null||t.getFingerprints==null){e.log.trace("fetching fingerprint from local SDP");let o=r.localDescription;return o==null?void 0:W2(o.sdp)}if(e.log.trace("fetching fingerprint from local certificate"),t.getFingerprints().length===0)return;let n=t.getFingerprints()[0].value;if(n==null)throw Ha("","no fingerprint on local certificate");return n}var q2=/^a=fingerprint:(?:\w+-[0-9]+)\s(?<fingerprint>(:?[0-9a-fA-F]{2})+)$/m;function W2(r){return r.match(q2)?.groups?.fingerprint}function z2(r){for(let e of r.protoNames())if(e.startsWith("ip"))return e.toUpperCase();return"IP6"}function Ri(r){let t=r.stringTuples().filter(n=>n[0]===A0).map(n=>n[1])[0];if(t===void 0||t==="")throw $o(`Couldn't find a certhash component of multiaddr: ${r.toString()}`);return t}function Kl(r){let e=Hl.decode(r);return w0.decode(e)}function G2(r){let e=Kl(Ri(r)),t=$l(e.name),n=e.digest.reduce((s,i)=>s+i.toString(16).padStart(2,"0"),""),o=n.match(/.{1,2}/g);if(o==null)throw Ha(n,r.toString());return[`${t.toUpperCase()} ${o.join(":").toUpperCase()}`,n]}function $l(r){switch(r){case"sha1":return"sha-1";case"sha2-256":return"sha-256";case"sha2-512":return"sha-512";default:throw ju(r)}}function j2(r,e){let{host:t,port:n}=r.toOptions(),o=z2(r),[s]=G2(r);return`v=0
20
+ `)}`:`${t} :`}};Bh=ar;M.Constructed=Bh;ar.NAME="CONSTRUCTED";var Us=class extends Fe{fromBER(e,t,n){return t}toBER(e){return dt}};Us.override="EndOfContentValueBlock";var kh,Os=class extends Ne{constructor(e={}){super(e,Us),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};kh=Os;M.EndOfContent=kh;Os.NAME=ro;var Ch,cr=class extends Ne{constructor(e={}){super(e,Fe),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(e,t,n){return this.lenBlock.length>0&&this.warnings.push("Non-zero length of value block for Null type"),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.blockLength+=n,t+n>e.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):t+n}toBER(e,t){let n=new ArrayBuffer(2);if(!e){let o=new Uint8Array(n);o[0]=5,o[1]=0}return t&&t.write(n),n}onAsciiEncoding(){return`${this.constructor.NAME}`}};Ch=cr;M.Null=Ch;cr.NAME="NULL";var Ps=class extends $t(Fe){constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=X.BufferSourceConverter.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}get value(){for(let e of this.valueHexView)if(e>0)return!0;return!1}set value(e){this.valueHexView[0]=e?255:0}fromBER(e,t,n){let o=X.BufferSourceConverter.toUint8Array(e);return Kt(this,o,t,n)?(this.valueHexView=o.subarray(t,t+n),n>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,Lc.call(this),this.blockLength=n,t+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};Ps.NAME="BooleanValueBlock";var Ih,Ms=class extends Ne{constructor(e={}){super(e,Ps),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};Ih=Ms;M.Boolean=Ih;Ms.NAME="BOOLEAN";var Fs=class extends $t(vt){constructor({isConstructed:e=!1,...t}={}){super(t),this.isConstructed=e}fromBER(e,t,n){let o=0;if(this.isConstructed){if(this.isHexOnly=!1,o=vt.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let s=0;s<this.value.length;s++){let i=this.value[s].constructor.NAME;if(i===ro){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(i!==vh)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,o=super.fromBER(e,t,n),this.blockLength=n;return o}toBER(e,t){return this.isConstructed?vt.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};Fs.NAME="OctetStringValueBlock";var Th,Vt=class r extends Ne{constructor({idBlock:e={},lenBlock:t={},...n}={}){var o,s;(o=n.isConstructed)!==null&&o!==void 0||(n.isConstructed=!!(!((s=n.value)===null||s===void 0)&&s.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},Fs),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(e,t,n){if(this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,n===0)return this.idBlock.error.length===0&&(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length===0&&(this.blockLength+=this.lenBlock.blockLength),t;if(!this.valueBlock.isConstructed){let s=(e instanceof ArrayBuffer?new Uint8Array(e):e).subarray(t,t+n);try{if(s.byteLength){let i=di(s,0,s.byteLength);i.offset!==-1&&i.offset===n&&(this.valueBlock.value=[i.result])}}catch{}}return super.fromBER(e,t,n)}onAsciiEncoding(){return this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length?ar.prototype.onAsciiEncoding.call(this):`${this.constructor.NAME} : ${X.Convert.ToHex(this.valueBlock.valueHexView)}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;let e=[];for(let t of this.valueBlock.value)t instanceof r&&e.push(t.valueBlock.valueHexView);return X.BufferSourceConverter.concat(e)}};Th=Vt;M.OctetString=Th;Vt.NAME=vh;var Vs=class extends $t(vt){constructor({unusedBits:e=0,isConstructed:t=!1,...n}={}){super(n),this.unusedBits=e,this.isConstructed=t,this.blockLength=this.valueHexView.byteLength}fromBER(e,t,n){if(!n)return t;let o=-1;if(this.isConstructed){if(o=vt.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let a of this.value){let c=a.constructor.NAME;if(c===ro){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==Ah)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let u=a.valueBlock;if(this.unusedBits>0&&u.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=u.unusedBits}return o}let s=X.BufferSourceConverter.toUint8Array(e);if(!Kt(this,s,t,n))return-1;let i=s.subarray(t,t+n);if(this.unusedBits=i[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){let a=i.subarray(1);try{if(a.byteLength){let c=di(a,0,a.byteLength);c.offset!==-1&&c.offset===n-1&&(this.value=[c.result])}}catch{}}return this.valueHexView=i.subarray(1),this.blockLength=i.length,t+n}toBER(e,t){if(this.isConstructed)return vt.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return dt;let n=new Uint8Array(this.valueHexView.length+1);return n[0]=this.unusedBits,n.set(this.valueHexView,1),n.buffer}toJSON(){return{...super.toJSON(),unusedBits:this.unusedBits,isConstructed:this.isConstructed}}};Vs.NAME="BitStringValueBlock";var _h,pn=class extends Ne{constructor({idBlock:e={},lenBlock:t={},...n}={}){var o,s;(o=n.isConstructed)!==null&&o!==void 0||(n.isConstructed=!!(!((s=n.value)===null||s===void 0)&&s.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},Vs),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(e,t,n){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(e,t,n)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return ar.prototype.onAsciiEncoding.call(this);{let e=[],t=this.valueBlock.valueHexView;for(let o of t)e.push(o.toString(2).padStart(8,"0"));let n=e.join("");return`${this.constructor.NAME} : ${n.substring(0,n.length-this.valueBlock.unusedBits)}`}}};_h=pn;M.BitString=_h;pn.NAME=Ah;var Rh;function Gy(r,e){let t=new Uint8Array([0]),n=new Uint8Array(r),o=new Uint8Array(e),s=n.slice(0),i=s.length-1,a=o.slice(0),c=a.length-1,u=0,l=c<i?i:c,f=0;for(let m=l;m>=0;m--,f++){switch(!0){case f<a.length:u=s[i-f]+a[c-f]+t[0];break;default:u=s[i-f]+t[0]}switch(t[0]=u/10,!0){case f>=s.length:s=Cs(new Uint8Array([u%10]),s);break;default:s[i-f]=u%10}}return t[0]>0&&(s=Cs(t,s)),s}function Eh(r){if(r>=eo.length)for(let e=eo.length;e<=r;e++){let t=new Uint8Array([0]),n=eo[e-1].slice(0);for(let o=n.length-1;o>=0;o--){let s=new Uint8Array([(n[o]<<1)+t[0]]);t[0]=s[0]/10,n[o]=s[0]%10}t[0]>0&&(n=Cs(t,n)),eo.push(n)}return eo[r]}function jy(r,e){let t=0,n=new Uint8Array(r),o=new Uint8Array(e),s=n.slice(0),i=s.length-1,a=o.slice(0),c=a.length-1,u,l=0;for(let f=c;f>=0;f--,l++)switch(u=s[i-l]-a[c-l]-t,!0){case u<0:t=1,s[i-l]=u+10;break;default:t=0,s[i-l]=u}if(t>0)for(let f=i-c+1;f>=0;f--,l++)if(u=s[i-l]-t,u<0)t=1,s[i-l]=u+10;else{t=0,s[i-l]=u;break}return s.slice()}var no=class extends $t(Fe){constructor({value:e,...t}={}){super(t),this._valueDec=0,t.valueHex&&this.setValueHex(),e!==void 0&&(this.valueDec=e)}setValueHex(){this.valueHexView.length>=4?(this.warnings.push("Too big Integer for decoding, hex only"),this.isHexOnly=!0,this._valueDec=0):(this.isHexOnly=!1,this.valueHexView.length>0&&(this._valueDec=Lc.call(this)))}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(yh(e))}get valueDec(){return this._valueDec}fromDER(e,t,n,o=0){let s=this.fromBER(e,t,n);if(s===-1)return s;let i=this.valueHexView;return i[0]===0&&i[1]&128?this.valueHexView=i.subarray(1):o!==0&&i.length<o&&(o-i.length>1&&(o=i.length+1),this.valueHexView=i.subarray(o-i.length)),s}toDER(e=!1){let t=this.valueHexView;switch(!0){case(t[0]&128)!==0:{let n=new Uint8Array(this.valueHexView.length+1);n[0]=0,n.set(t,1),this.valueHexView=n}break;case(t[0]===0&&(t[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(e)}fromBER(e,t,n){let o=super.fromBER(e,t,n);return o===-1||this.setValueHex(),o}toBER(e){return e?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){let e=this.valueHexView.length*8-1,t=new Uint8Array(this.valueHexView.length*8/3),n=0,o,s=this.valueHexView,i="",a=!1;for(let c=s.byteLength-1;c>=0;c--){o=s[c];for(let u=0;u<8;u++){if((o&1)===1)switch(n){case e:t=jy(Eh(n),t),i="-";break;default:t=Gy(t,Eh(n))}n++,o>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(i+=xh.charAt(t[c]));return a===!1&&(i+=xh.charAt(0)),i}};Rh=no;no.NAME="IntegerValueBlock";Object.defineProperty(Rh.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var Nh,Ee=class r extends Ne{constructor(e={}){super(e,no),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return Is(),BigInt(this.valueBlock.toString())}static fromBigInt(e){Is();let t=BigInt(e),n=new to,o=t.toString(16).replace(/^-/,""),s=new Uint8Array(X.Convert.FromHex(o));if(t<0){let a=new Uint8Array(s.length+(s[0]&128?1:0));a[0]|=128;let u=BigInt(`0x${X.Convert.ToHex(a)}`)+t,l=X.BufferSourceConverter.toUint8Array(X.Convert.FromHex(u.toString(16)));l[0]|=128,n.write(l)}else s[0]&128&&n.write(new Uint8Array([0])),n.write(s);return new r({valueHex:n.final()})}convertToDER(){let e=new r({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new r({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}};Nh=Ee;M.Integer=Nh;Ee.NAME="INTEGER";var Lh,Hs=class extends Ee{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};Lh=Hs;M.Enumerated=Lh;Hs.NAME="ENUMERATED";var oo=class extends $t(Fe){constructor({valueDec:e=-1,isFirstSid:t=!1,...n}={}){super(n),this.valueDec=e,this.isFirstSid=t}fromBER(e,t,n){if(!n)return t;let o=X.BufferSourceConverter.toUint8Array(e);if(!Kt(this,o,t,n))return-1;let s=o.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=s[a]&127,this.blockLength++,!!(s[a]&128));a++);let i=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)i[a]=this.valueHexView[a];return this.valueHexView=i,s[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=Lr(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){Is();let t=BigInt(e).toString(2);for(;t.length%7;)t="0"+t;let n=new Uint8Array(t.length/7);for(let o=0;o<n.length;o++)n[o]=parseInt(t.slice(o*7,o*7+7),2)+(o+1<n.length?128:0);this.fromBER(n.buffer,0,n.length)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let o=this.valueHexView,s=new Uint8Array(this.blockLength);for(let i=0;i<this.blockLength-1;i++)s[i]=o[i]|128;return s[this.blockLength-1]=o[this.blockLength-1],s.buffer}let t=ir(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",dt;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),s=t.byteLength-1;for(let i=0;i<s;i++)n[i]=o[i]|128;n[s]=o[s]}return n}toString(){let e="";if(this.isHexOnly)e=X.Convert.ToHex(this.valueHexView);else if(this.isFirstSid){let t=this.valueDec;this.valueDec<=39?e="0.":this.valueDec<=79?(e="1.",t-=40):(e="2.",t-=80),e+=t.toString()}else e=this.valueDec.toString();return e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}};oo.NAME="sidBlock";var Ks=class extends Fe{constructor({value:e=mn,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let s=new oo;if(o=s.fromBER(e,o,n),o===-1)return this.blockLength=0,this.error=s.error,o;this.value.length===0&&(s.isFirstSid=!0),this.blockLength+=s.blockLength,n-=s.blockLength,this.value.push(s)}return o}toBER(e){let t=[];for(let n=0;n<this.value.length;n++){let o=this.value[n].toBER(e);if(o.byteLength===0)return this.error=this.value[n].error,dt;t.push(o)}return Uc(t)}fromString(e){this.value=[];let t=0,n=0,o="",s=!1;do if(n=e.indexOf(".",t),n===-1?o=e.substring(t):o=e.substring(t,n),t=n+1,s){let i=this.value[0],a=0;switch(i.valueDec){case 0:break;case 1:a=40;break;case 2:a=80;break;default:this.value=[];return}let c=parseInt(o,10);if(isNaN(c))return;i.valueDec=c+a,s=!1}else{let i=new oo;if(o>Number.MAX_SAFE_INTEGER){Is();let a=BigInt(o);i.valueBigInt=a}else if(i.valueDec=parseInt(o,10),isNaN(i.valueDec))return;this.value.length||(i.isFirstSid=!0,s=!0),this.value.push(i)}while(n!==-1)}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let o=this.value[n].toString();n!==0&&(e=`${e}.`),t?(o=`{${o}}`,this.value[n].isFirstSid?e=`2.{${o} - 80}`:e+=o):e+=o}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};Ks.NAME="ObjectIdentifierValueBlock";var Uh,ht=class extends Ne{constructor(e={}){super(e,Ks),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};Uh=ht;M.ObjectIdentifier=Uh;ht.NAME="OBJECT IDENTIFIER";var so=class extends $t(Ft){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,n){if(n===0)return t;let o=X.BufferSourceConverter.toUint8Array(e);if(!Kt(this,o,t,n))return-1;let s=o.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=s[a]&127,this.blockLength++,!!(s[a]&128));a++);let i=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)i[a]=this.valueHexView[a];return this.valueHexView=i,s[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=Lr(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let o=this.valueHexView,s=new Uint8Array(this.blockLength);for(let i=0;i<this.blockLength-1;i++)s[i]=o[i]|128;return s[this.blockLength-1]=o[this.blockLength-1],s.buffer}let t=ir(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",dt;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),s=t.byteLength-1;for(let i=0;i<s;i++)n[i]=o[i]|128;n[s]=o[s]}return n.buffer}toString(){let e="";return this.isHexOnly?e=X.Convert.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};so.NAME="relativeSidBlock";var $s=class extends Fe{constructor({value:e=mn,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let s=new so;if(o=s.fromBER(e,o,n),o===-1)return this.blockLength=0,this.error=s.error,o;this.blockLength+=s.blockLength,n-=s.blockLength,this.value.push(s)}return o}toBER(e,t){let n=[];for(let o=0;o<this.value.length;o++){let s=this.value[o].toBER(e);if(s.byteLength===0)return this.error=this.value[o].error,dt;n.push(s)}return Uc(n)}fromString(e){this.value=[];let t=0,n=0,o="";do{n=e.indexOf(".",t),n===-1?o=e.substring(t):o=e.substring(t,n),t=n+1;let s=new so;if(s.valueDec=parseInt(o,10),isNaN(s.valueDec))return!0;this.value.push(s)}while(n!==-1);return!0}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let o=this.value[n].toString();n!==0&&(e=`${e}.`),t&&(o=`{${o}}`),e+=o}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};$s.NAME="RelativeObjectIdentifierValueBlock";var Oh,qs=class extends Ne{constructor(e={}){super(e,$s),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};Oh=qs;M.RelativeObjectIdentifier=Oh;qs.NAME="RelativeObjectIdentifier";var Ph,Ce=class extends ar{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};Ph=Ce;M.Sequence=Ph;Ce.NAME="SEQUENCE";var Mh,Ws=class extends ar{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};Mh=Ws;M.Set=Mh;Ws.NAME="SET";var zs=class extends $t(Fe){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=mn}toJSON(){return{...super.toJSON(),value:this.value}}};zs.NAME="StringValueBlock";var Gs=class extends zs{};Gs.NAME="SimpleStringValueBlock";var He=class extends Rs{constructor({...e}={}){super(e,Gs)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,X.BufferSourceConverter.toUint8Array(e))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t);for(let o=0;o<t;o++)n[o]=e.charCodeAt(o);this.valueBlock.value=e}};He.NAME="SIMPLE STRING";var js=class extends He{fromBuffer(e){this.valueBlock.valueHexView=X.BufferSourceConverter.toUint8Array(e);try{this.valueBlock.value=X.Convert.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=X.Convert.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(X.Convert.FromUtf8String(e)),this.valueBlock.value=e}};js.NAME="Utf8StringValueBlock";var Fh,Ht=class extends js{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};Fh=Ht;M.Utf8String=Fh;Ht.NAME="UTF8String";var Ys=class extends He{fromBuffer(e){this.valueBlock.value=X.Convert.ToUtf16String(e),this.valueBlock.valueHexView=X.BufferSourceConverter.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(X.Convert.FromUtf16String(e))}};Ys.NAME="BmpStringValueBlock";var Vh,Zs=class extends Ys{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};Vh=Zs;M.BmpString=Vh;Zs.NAME="BMPString";var Xs=class extends He{fromBuffer(e){let t=ArrayBuffer.isView(e)?e.slice().buffer:e.slice(0),n=new Uint8Array(t);for(let o=0;o<n.length;o+=4)n[o]=n[o+3],n[o+1]=n[o+2],n[o+2]=0,n[o+3]=0;this.valueBlock.value=String.fromCharCode.apply(null,new Uint32Array(t))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t*4);for(let o=0;o<t;o++){let s=ir(e.charCodeAt(o),8),i=new Uint8Array(s);if(i.length>4)continue;let a=4-i.length;for(let c=i.length-1;c>=0;c--)n[o*4+c+a]=i[c]}this.valueBlock.value=e}};Xs.NAME="UniversalStringValueBlock";var Hh,Js=class extends Xs{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};Hh=Js;M.UniversalString=Hh;Js.NAME="UniversalString";var Kh,Qs=class extends He{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};Kh=Qs;M.NumericString=Kh;Qs.NAME="NumericString";var $h,ei=class extends He{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};$h=ei;M.PrintableString=$h;ei.NAME="PrintableString";var qh,ti=class extends He{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};qh=ti;M.TeletexString=qh;ti.NAME="TeletexString";var Wh,ri=class extends He{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};Wh=ri;M.VideotexString=Wh;ri.NAME="VideotexString";var zh,ni=class extends He{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};zh=ni;M.IA5String=zh;ni.NAME="IA5String";var Gh,oi=class extends He{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};Gh=oi;M.GraphicString=Gh;oi.NAME="GraphicString";var jh,io=class extends He{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};jh=io;M.VisibleString=jh;io.NAME="VisibleString";var Yh,si=class extends He{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};Yh=si;M.GeneralString=Yh;si.NAME="GeneralString";var Zh,ii=class extends He{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};Zh=ii;M.CharacterString=Zh;ii.NAME="CharacterString";var Xh,ao=class extends io{constructor({value:e,valueDate:t,...n}={}){if(super(n),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,e){this.fromString(e),this.valueBlock.valueHexView=new Uint8Array(e.length);for(let o=0;o<e.length;o++)this.valueBlock.valueHexView[o]=e.charCodeAt(o)}t&&(this.fromDate(t),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(e){this.fromString(String.fromCharCode.apply(null,X.BufferSourceConverter.toUint8Array(e)))}toBuffer(){let e=this.toString(),t=new ArrayBuffer(e.length),n=new Uint8Array(t);for(let o=0;o<e.length;o++)n[o]=e.charCodeAt(o);return t}fromDate(e){this.year=e.getUTCFullYear(),this.month=e.getUTCMonth()+1,this.day=e.getUTCDate(),this.hour=e.getUTCHours(),this.minute=e.getUTCMinutes(),this.second=e.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(e){let n=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig.exec(e);if(n===null){this.error="Wrong input string for conversion";return}let o=parseInt(n[1],10);o>=50?this.year=1900+o:this.year=2e3+o,this.month=parseInt(n[2],10),this.day=parseInt(n[3],10),this.hour=parseInt(n[4],10),this.minute=parseInt(n[5],10),this.second=parseInt(n[6],10)}toString(e="iso"){if(e==="iso"){let t=new Array(7);return t[0]=We(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=We(this.month,2),t[2]=We(this.day,2),t[3]=We(this.hour,2),t[4]=We(this.minute,2),t[5]=We(this.second,2),t[6]="Z",t.join("")}return super.toString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.toDate().toISOString()}`}toJSON(){return{...super.toJSON(),year:this.year,month:this.month,day:this.day,hour:this.hour,minute:this.minute,second:this.second}}};Xh=ao;M.UTCTime=Xh;ao.NAME="UTCTime";var Jh,ai=class extends ao{constructor(e={}){var t;super(e),(t=this.millisecond)!==null&&t!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(e){super.fromDate(e),this.millisecond=e.getUTCMilliseconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond))}fromString(e){let t=!1,n="",o="",s=0,i,a=0,c=0;if(e[e.length-1]==="Z")n=e.substring(0,e.length-1),t=!0;else{let f=new Number(e[e.length-1]);if(isNaN(f.valueOf()))throw new Error("Wrong input string for conversion");n=e}if(t){if(n.indexOf("+")!==-1)throw new Error("Wrong input string for conversion");if(n.indexOf("-")!==-1)throw new Error("Wrong input string for conversion")}else{let f=1,m=n.indexOf("+"),g="";if(m===-1&&(m=n.indexOf("-"),f=-1),m!==-1){if(g=n.substring(m+1),n=n.substring(0,m),g.length!==2&&g.length!==4)throw new Error("Wrong input string for conversion");let p=parseInt(g.substring(0,2),10);if(isNaN(p.valueOf()))throw new Error("Wrong input string for conversion");if(a=f*p,g.length===4){if(p=parseInt(g.substring(2,4),10),isNaN(p.valueOf()))throw new Error("Wrong input string for conversion");c=f*p}}}let u=n.indexOf(".");if(u===-1&&(u=n.indexOf(",")),u!==-1){let f=new Number(`0${n.substring(u)}`);if(isNaN(f.valueOf()))throw new Error("Wrong input string for conversion");s=f.valueOf(),o=n.substring(0,u)}else o=n;switch(!0){case o.length===8:if(i=/(\d{4})(\d{2})(\d{2})/ig,u!==-1)throw new Error("Wrong input string for conversion");break;case o.length===10:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let f=60*s;this.minute=Math.floor(f),f=60*(f-this.minute),this.second=Math.floor(f),f=1e3*(f-this.second),this.millisecond=Math.floor(f)}break;case o.length===12:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let f=60*s;this.second=Math.floor(f),f=1e3*(f-this.second),this.millisecond=Math.floor(f)}break;case o.length===14:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let f=1e3*s;this.millisecond=Math.floor(f)}break;default:throw new Error("Wrong input string for conversion")}let l=i.exec(o);if(l===null)throw new Error("Wrong input string for conversion");for(let f=1;f<l.length;f++)switch(f){case 1:this.year=parseInt(l[f],10);break;case 2:this.month=parseInt(l[f],10);break;case 3:this.day=parseInt(l[f],10);break;case 4:this.hour=parseInt(l[f],10)+a;break;case 5:this.minute=parseInt(l[f],10)+c;break;case 6:this.second=parseInt(l[f],10);break;default:throw new Error("Wrong input string for conversion")}if(t===!1){let f=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=f.getUTCFullYear(),this.month=f.getUTCMonth(),this.day=f.getUTCDay(),this.hour=f.getUTCHours(),this.minute=f.getUTCMinutes(),this.second=f.getUTCSeconds(),this.millisecond=f.getUTCMilliseconds()}}toString(e="iso"){if(e==="iso"){let t=[];return t.push(We(this.year,4)),t.push(We(this.month,2)),t.push(We(this.day,2)),t.push(We(this.hour,2)),t.push(We(this.minute,2)),t.push(We(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(We(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};Jh=ai;M.GeneralizedTime=Jh;ai.NAME="GeneralizedTime";var Qh,ci=class extends Ht{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};Qh=ci;M.DATE=Qh;ci.NAME="DATE";var ed,ui=class extends Ht{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};ed=ui;M.TimeOfDay=ed;ui.NAME="TimeOfDay";var td,li=class extends Ht{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};td=li;M.DateTime=td;li.NAME="DateTime";var rd,fi=class extends Ht{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};rd=fi;M.Duration=rd;fi.NAME="Duration";var nd,hi=class extends Ht{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};nd=hi;M.TIME=nd;hi.NAME="TIME";function Zy(r){let{result:e}=gn(r),t=e.valueBlock.value;return{n:W(At(t[1].toBigInt()),"base64url"),e:W(At(t[2].toBigInt()),"base64url"),d:W(At(t[3].toBigInt()),"base64url"),p:W(At(t[4].toBigInt()),"base64url"),q:W(At(t[5].toBigInt()),"base64url"),dp:W(At(t[6].toBigInt()),"base64url"),dq:W(At(t[7].toBigInt()),"base64url"),qi:W(At(t[8].toBigInt()),"base64url"),kty:"RSA",alg:"RS256"}}function Xy(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new L("JWK was missing components","ERR_INVALID_PARAMETERS");let t=new Ce({value:[new Ee({value:0}),Ee.fromBigInt(Dt(J(r.n,"base64url"))),Ee.fromBigInt(Dt(J(r.e,"base64url"))),Ee.fromBigInt(Dt(J(r.d,"base64url"))),Ee.fromBigInt(Dt(J(r.p,"base64url"))),Ee.fromBigInt(Dt(J(r.q,"base64url"))),Ee.fromBigInt(Dt(J(r.dp,"base64url"))),Ee.fromBigInt(Dt(J(r.dq,"base64url"))),Ee.fromBigInt(Dt(J(r.qi,"base64url")))]}).toBER();return new Uint8Array(t,0,t.byteLength)}function Jy(r){let{result:e}=gn(r),t=e.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:W(At(t[0].toBigInt()),"base64url"),e:W(At(t[1].toBigInt()),"base64url")}}function Qy(r){if(r.n==null||r.e==null)throw new L("JWK was missing components","ERR_INVALID_PARAMETERS");let t=new Ce({value:[new Ce({value:[new ht({value:"1.2.840.113549.1.1.1"}),new cr]}),new pn({valueHex:new Ce({value:[Ee.fromBigInt(Dt(J(r.n,"base64url"))),Ee.fromBigInt(Dt(J(r.e,"base64url")))]}).toBER()})]}).toBER();return new Uint8Array(t,0,t.byteLength)}function At(r){let e=r.toString(16);e.length%2>0&&(e=`0${e}`);let t=e.length/2,n=new Uint8Array(t),o=0,s=0;for(;o<t;)n[o]=parseInt(e.slice(s,s+2),16),o+=1,s+=2;return n}function Dt(r){let e=[];return r.forEach(function(t){let n=t.toString(16);n.length%2>0&&(n=`0${n}`),e.push(n)}),BigInt("0x"+e.join(""))}var ew=16,Pc=32,Mc=1e4;async function tw(r,e){let t=Ve.get(),o=new Ce({value:[new Ee({value:0}),new Ce({value:[new ht({value:"1.2.840.113549.1.1.1"}),new cr]}),new Vt({valueHex:r.marshal()})]}).toBER(),s=new Uint8Array(o,0,o.byteLength),i=Nr(ew),a=await Rc(Gn,e,i,{c:Mc,dkLen:Pc}),c=Nr(16),u=await t.subtle.importKey("raw",a,"AES-CBC",!1,["encrypt"]),l=await t.subtle.encrypt({name:"AES-CBC",iv:c},u,s),f=new Ce({value:[new Vt({valueHex:i}),new Ee({value:Mc}),new Ee({value:Pc}),new Ce({value:[new ht({value:"1.2.840.113549.2.11"}),new cr]})]}),m=new Ce({value:[new ht({value:"1.2.840.113549.1.5.13"}),new Ce({value:[new Ce({value:[new ht({value:"1.2.840.113549.1.5.12"}),f]}),new Ce({value:[new ht({value:"2.16.840.1.101.3.4.1.42"}),new Vt({valueHex:c})]})]})]}),p=new Ce({value:[m,new Vt({valueHex:l})]}).toBER(),h=new Uint8Array(p,0,p.byteLength);return["-----BEGIN ENCRYPTED PRIVATE KEY-----",...W(h,"base64pad").split(/(.{64})/).filter(Boolean),"-----END ENCRYPTED PRIVATE KEY-----"].join(`
21
+ `)}async function rw(r,e){let t=Ve.get(),n;if(r.includes("-----BEGIN ENCRYPTED PRIVATE KEY-----")){let o=J(r.replace("-----BEGIN ENCRYPTED PRIVATE KEY-----","").replace("-----END ENCRYPTED PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:s}=gn(o),{iv:i,salt:a,iterations:c,keySize:u,cipherText:l}=nw(s),f=await Rc(Gn,e,a,{c,dkLen:u}),m=await t.subtle.importKey("raw",f,"AES-CBC",!1,["decrypt"]),g=co(await t.subtle.decrypt({name:"AES-CBC",iv:i},m,l)),{result:p}=gn(g);n=od(p)}else if(r.includes("-----BEGIN PRIVATE KEY-----")){let o=J(r.replace("-----BEGIN PRIVATE KEY-----","").replace("-----END PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:s}=gn(o);n=od(s)}else throw new L("Could not parse private key from PEM data","ERR_INVALID_PARAMETERS");return Fc(n)}function nw(r){let e=r.valueBlock.value[0];if(e.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.13")throw new L("Only pkcs5PBES2 encrypted private keys are supported","ERR_INVALID_PARAMS");let n=e.valueBlock.value[1].valueBlock.value[0];if(n.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.12")throw new L("Only pkcs5PBKDF2 key derivation functions are supported","ERR_INVALID_PARAMS");let s=n.valueBlock.value[1],i=co(s.valueBlock.value[0].getValue()),a=Mc,c=Pc;if(s.valueBlock.value.length===3)a=Number(s.valueBlock.value[1].toBigInt()),c=Number(s.valueBlock.value[2].toBigInt());else if(s.valueBlock.value.length===2)throw new L("Could not derive key size and iterations from PEM file - please use @libp2p/rsa to re-import your key","ERR_INVALID_PARAMS");let u=e.valueBlock.value[1].valueBlock.value[1],l=u.valueBlock.value[0].toString();if(l!=="OBJECT IDENTIFIER : 1.2.840.113549.3.7"){if(l!=="OBJECT IDENTIFIER : 1.3.14.3.2.7"){if(l!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.2"){if(l!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.22"){if(l!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.42")throw new L("Only AES-CBC encryption schemes are supported","ERR_INVALID_PARAMS")}}}}let f=co(u.valueBlock.value[1].getValue());return{cipherText:co(r.valueBlock.value[1].getValue()),salt:i,iterations:a,keySize:c,iv:f}}function od(r){return co(r.valueBlock.value[2].getValue())}function co(r){return new Uint8Array(r,0,r.byteLength)}async function sd(r){let e=await Ve.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),t=await cd(e);return{privateKey:t[0],publicKey:t[1]}}async function Vc(r){let t=[await Ve.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),await ow(r)],n=await cd({privateKey:t[0],publicKey:t[1]});return{privateKey:n[0],publicKey:n[1]}}async function id(r,e){let t=await Ve.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await Ve.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},t,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(n,0,n.byteLength)}async function ad(r,e,t){let n=await Ve.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return Ve.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,e,t instanceof Uint8Array?t:t.subarray())}async function cd(r){if(r.privateKey==null||r.publicKey==null)throw new L("Private and public key are required","ERR_INVALID_PARAMETERS");return Promise.all([Ve.get().subtle.exportKey("jwk",r.privateKey),Ve.get().subtle.exportKey("jwk",r.publicKey)])}async function ow(r){return Ve.get().subtle.importKey("jwk",{kty:r.kty,n:r.n,e:r.e},{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])}function pi(r){if(r.kty!=="RSA")throw new L("invalid key type","ERR_INVALID_KEY_TYPE");if(r.n==null)throw new L("invalid key modulus","ERR_INVALID_KEY_MODULUS");return J(r.n,"base64url").length*8}var lo=8192,uo=class{_key;constructor(e){this._key=e}verify(e,t){return ad(this._key,t,e)}marshal(){return ur.jwkToPkix(this._key)}get bytes(){return xt.encode({Type:he.RSA,Data:this.marshal()}).subarray()}equals(e){return Ae(this.bytes,e.bytes)}hash(){let e=_e.digest(this.bytes);return Je(e)?e.then(({bytes:t})=>t):e.bytes}},bn=class{_key;_publicKey;constructor(e,t){this._key=e,this._publicKey=t}genSecret(){return Nr(16)}sign(e){return id(this._key,e)}get public(){if(this._publicKey==null)throw new L("public key not provided","ERR_PUBKEY_NOT_PROVIDED");return new uo(this._publicKey)}marshal(){return ur.jwkToPkcs1(this._key)}get bytes(){return Et.encode({Type:he.RSA,Data:this.marshal()}).subarray()}equals(e){return Ae(this.bytes,e.bytes)}hash(){let e=_e.digest(this.bytes);return Je(e)?e.then(({bytes:t})=>t):e.bytes}async id(){let e=await this.public.hash();return W(e,"base58btc")}async export(e,t="pkcs-8"){if(t==="pkcs-8")return ur.exportToPem(this,e);if(t==="libp2p-key")return fn(this.bytes,e);throw new L(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};async function Fc(r){let e=ur.pkcs1ToJwk(r);if(pi(e)>lo)throw new L("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let t=await Vc(e);return new bn(t.privateKey,t.publicKey)}function iw(r){let e=ur.pkixToJwk(r);if(pi(e)>lo)throw new L("key size is too large","ERR_KEY_SIZE_TOO_LARGE");return new uo(e)}async function aw(r){if(pi(r)>lo)throw new L("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await Vc(r);return new bn(e.privateKey,e.publicKey)}async function cw(r){if(r>lo)throw new L("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await sd(r);return new bn(e.privateKey,e.publicKey)}var zc={};Q(zc,{Secp256k1PrivateKey:()=>ho,Secp256k1PublicKey:()=>fo,generateKeyPair:()=>Ew,unmarshalSecp256k1PrivateKey:()=>ww,unmarshalSecp256k1PublicKey:()=>xw});var uw=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),lr=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),fr=new Uint32Array(64),Kc=class extends an{constructor(){super(64,32,8,!1),this.A=lr[0]|0,this.B=lr[1]|0,this.C=lr[2]|0,this.D=lr[3]|0,this.E=lr[4]|0,this.F=lr[5]|0,this.G=lr[6]|0,this.H=lr[7]|0}get(){let{A:e,B:t,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[e,t,n,o,s,i,a,c]}set(e,t,n,o,s,i,a,c){this.A=e|0,this.B=t|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(e,t){for(let f=0;f<16;f++,t+=4)fr[f]=e.getUint32(t,!1);for(let f=16;f<64;f++){let m=fr[f-15],g=fr[f-2],p=ct(m,7)^ct(m,18)^m>>>3,h=ct(g,17)^ct(g,19)^g>>>10;fr[f]=h+fr[f-7]+p+fr[f-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:l}=this;for(let f=0;f<64;f++){let m=ct(a,6)^ct(a,11)^ct(a,25),g=l+m+zf(a,c,u)+uw[f]+fr[f]|0,h=(ct(n,2)^ct(n,13)^ct(n,22))+Gf(n,o,s)|0;l=u,u=c,c=a,a=i+g|0,i=s,s=o,o=n,n=g+h|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,o,s,i,a,c,u,l)}roundClean(){fr.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var yn=ms(()=>new Kc);function lw(r){let e=Yn(r);Qe(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:t,Fp:n,a:o}=e;if(t){if(!n.eql(o,n.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof t!="object"||typeof t.beta!="bigint"||typeof t.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...e})}var{bytesToNumberBE:fw,hexToBytes:hw}=ys,Ur={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(r){let{Err:e}=Ur;if(r.length<2||r[0]!==2)throw new e("Invalid signature integer tag");let t=r[1],n=r.subarray(2,t+2);if(!t||n.length!==t)throw new e("Invalid signature integer: wrong length");if(n[0]&128)throw new e("Invalid signature integer: negative");if(n[0]===0&&!(n[1]&128))throw new e("Invalid signature integer: unnecessary leading zero");return{d:fw(n),l:r.subarray(t+2)}},toSig(r){let{Err:e}=Ur,t=typeof r=="string"?hw(r):r;cn(t);let n=t.length;if(n<2||t[0]!=48)throw new e("Invalid signature tag");if(t[1]!==n-2)throw new e("Invalid signature: incorrect length");let{d:o,l:s}=Ur._parseInt(t.subarray(2)),{d:i,l:a}=Ur._parseInt(s);if(a.length)throw new e("Invalid signature: left bytes after parsing");return{r:o,s:i}},hexFromSig(r){let e=u=>Number.parseInt(u[0],16)&8?"00"+u:u,t=u=>{let l=u.toString(16);return l.length&1?`0${l}`:l},n=e(t(r.s)),o=e(t(r.r)),s=n.length/2,i=o.length/2,a=t(s),c=t(i);return`30${t(i+s+4)}02${c}${o}02${a}${n}`}},qt=BigInt(0),tt=BigInt(1),sS=BigInt(2),ud=BigInt(3),iS=BigInt(4);function dw(r){let e=lw(r),{Fp:t}=e,n=e.toBytes||((p,h,d)=>{let y=h.toAffine();return Ot(Uint8Array.from([4]),t.toBytes(y.x),t.toBytes(y.y))}),o=e.fromBytes||(p=>{let h=p.subarray(1),d=t.fromBytes(h.subarray(0,t.BYTES)),y=t.fromBytes(h.subarray(t.BYTES,2*t.BYTES));return{x:d,y}});function s(p){let{a:h,b:d}=e,y=t.sqr(p),x=t.mul(y,p);return t.add(t.add(x,t.mul(p,h)),d)}if(!t.eql(t.sqr(e.Gy),s(e.Gx)))throw new Error("bad generator point: equation left != right");function i(p){return typeof p=="bigint"&&qt<p&&p<e.n}function a(p){if(!i(p))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function c(p){let{allowedPrivateKeyLengths:h,nByteLength:d,wrapPrivateKey:y,n:x}=e;if(h&&typeof p!="bigint"){if(nr(p)&&(p=Nt(p)),typeof p!="string"||!h.includes(p.length))throw new Error("Invalid key");p=p.padStart(d*2,"0")}let b;try{b=typeof p=="bigint"?p:Lt(ce("private key",p,d))}catch{throw new Error(`private key must be ${d} bytes, hex or bigint, not ${typeof p}`)}return y&&(b=te(b,x)),a(b),b}let u=new Map;function l(p){if(!(p instanceof f))throw new Error("ProjectivePoint expected")}class f{constructor(h,d,y){if(this.px=h,this.py=d,this.pz=y,h==null||!t.isValid(h))throw new Error("x required");if(d==null||!t.isValid(d))throw new Error("y required");if(y==null||!t.isValid(y))throw new Error("z required")}static fromAffine(h){let{x:d,y}=h||{};if(!h||!t.isValid(d)||!t.isValid(y))throw new Error("invalid affine point");if(h instanceof f)throw new Error("projective point not allowed");let x=b=>t.eql(b,t.ZERO);return x(d)&&x(y)?f.ZERO:new f(d,y,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let d=t.invertBatch(h.map(y=>y.pz));return h.map((y,x)=>y.toAffine(d[x])).map(f.fromAffine)}static fromHex(h){let d=f.fromAffine(o(ce("pointHex",h)));return d.assertValidity(),d}static fromPrivateKey(h){return f.BASE.multiply(c(h))}_setWindowSize(h){this._WINDOW_SIZE=h,u.delete(this)}assertValidity(){if(this.is0()){if(e.allowInfinityPoint&&!t.is0(this.py))return;throw new Error("bad point: ZERO")}let{x:h,y:d}=this.toAffine();if(!t.isValid(h)||!t.isValid(d))throw new Error("bad point: x or y not FE");let y=t.sqr(d),x=s(h);if(!t.eql(y,x))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:h}=this.toAffine();if(t.isOdd)return!t.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){l(h);let{px:d,py:y,pz:x}=this,{px:b,py:A,pz:E}=h,v=t.eql(t.mul(d,E),t.mul(b,x)),S=t.eql(t.mul(y,E),t.mul(A,x));return v&&S}negate(){return new f(this.px,t.neg(this.py),this.pz)}double(){let{a:h,b:d}=e,y=t.mul(d,ud),{px:x,py:b,pz:A}=this,E=t.ZERO,v=t.ZERO,S=t.ZERO,D=t.mul(x,x),_=t.mul(b,b),O=t.mul(A,A),R=t.mul(x,b);return R=t.add(R,R),S=t.mul(x,A),S=t.add(S,S),E=t.mul(h,S),v=t.mul(y,O),v=t.add(E,v),E=t.sub(_,v),v=t.add(_,v),v=t.mul(E,v),E=t.mul(R,E),S=t.mul(y,S),O=t.mul(h,O),R=t.sub(D,O),R=t.mul(h,R),R=t.add(R,S),S=t.add(D,D),D=t.add(S,D),D=t.add(D,O),D=t.mul(D,R),v=t.add(v,D),O=t.mul(b,A),O=t.add(O,O),D=t.mul(O,R),E=t.sub(E,D),S=t.mul(O,_),S=t.add(S,S),S=t.add(S,S),new f(E,v,S)}add(h){l(h);let{px:d,py:y,pz:x}=this,{px:b,py:A,pz:E}=h,v=t.ZERO,S=t.ZERO,D=t.ZERO,_=e.a,O=t.mul(e.b,ud),R=t.mul(d,b),H=t.mul(y,A),V=t.mul(x,E),G=t.add(d,y),B=t.add(b,A);G=t.mul(G,B),B=t.add(R,H),G=t.sub(G,B),B=t.add(d,x);let I=t.add(b,E);return B=t.mul(B,I),I=t.add(R,V),B=t.sub(B,I),I=t.add(y,x),v=t.add(A,E),I=t.mul(I,v),v=t.add(H,V),I=t.sub(I,v),D=t.mul(_,B),v=t.mul(O,V),D=t.add(v,D),v=t.sub(H,D),D=t.add(H,D),S=t.mul(v,D),H=t.add(R,R),H=t.add(H,R),V=t.mul(_,V),B=t.mul(O,B),H=t.add(H,V),V=t.sub(R,V),V=t.mul(_,V),B=t.add(B,V),R=t.mul(H,B),S=t.add(S,R),R=t.mul(I,B),v=t.mul(G,v),v=t.sub(v,R),R=t.mul(G,H),D=t.mul(I,D),D=t.add(D,R),new f(v,S,D)}subtract(h){return this.add(h.negate())}is0(){return this.equals(f.ZERO)}wNAF(h){return g.wNAFCached(this,u,h,d=>{let y=t.invertBatch(d.map(x=>x.pz));return d.map((x,b)=>x.toAffine(y[b])).map(f.fromAffine)})}multiplyUnsafe(h){let d=f.ZERO;if(h===qt)return d;if(a(h),h===tt)return this;let{endo:y}=e;if(!y)return g.unsafeLadder(this,h);let{k1neg:x,k1:b,k2neg:A,k2:E}=y.splitScalar(h),v=d,S=d,D=this;for(;b>qt||E>qt;)b&tt&&(v=v.add(D)),E&tt&&(S=S.add(D)),D=D.double(),b>>=tt,E>>=tt;return x&&(v=v.negate()),A&&(S=S.negate()),S=new f(t.mul(S.px,y.beta),S.py,S.pz),v.add(S)}multiply(h){a(h);let d=h,y,x,{endo:b}=e;if(b){let{k1neg:A,k1:E,k2neg:v,k2:S}=b.splitScalar(d),{p:D,f:_}=this.wNAF(E),{p:O,f:R}=this.wNAF(S);D=g.constTimeNegate(A,D),O=g.constTimeNegate(v,O),O=new f(t.mul(O.px,b.beta),O.py,O.pz),y=D.add(O),x=_.add(R)}else{let{p:A,f:E}=this.wNAF(d);y=A,x=E}return f.normalizeZ([y,x])[0]}multiplyAndAddUnsafe(h,d,y){let x=f.BASE,b=(E,v)=>v===qt||v===tt||!E.equals(x)?E.multiplyUnsafe(v):E.multiply(v),A=b(this,d).add(b(h,y));return A.is0()?void 0:A}toAffine(h){let{px:d,py:y,pz:x}=this,b=this.is0();h==null&&(h=b?t.ONE:t.inv(x));let A=t.mul(d,h),E=t.mul(y,h),v=t.mul(x,h);if(b)return{x:t.ZERO,y:t.ZERO};if(!t.eql(v,t.ONE))throw new Error("invZ was invalid");return{x:A,y:E}}isTorsionFree(){let{h,isTorsionFree:d}=e;if(h===tt)return!0;if(d)return d(f,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:d}=e;return h===tt?this:d?d(f,this):this.multiplyUnsafe(e.h)}toRawBytes(h=!0){return this.assertValidity(),n(f,this,h)}toHex(h=!0){return Nt(this.toRawBytes(h))}}f.BASE=new f(e.Gx,e.Gy,t.ONE),f.ZERO=new f(t.ZERO,t.ONE,t.ZERO);let m=e.nBitLength,g=Es(f,e.endo?Math.ceil(m/2):m);return{CURVE:e,ProjectivePoint:f,normPrivateKeyToScalar:c,weierstrassEquation:s,isWithinCurveOrder:i}}function pw(r){let e=Yn(r);return Qe(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function ld(r){let e=pw(r),{Fp:t,n}=e,o=t.BYTES+1,s=2*t.BYTES+1;function i(B){return qt<B&&B<t.ORDER}function a(B){return te(B,n)}function c(B){return ws(B,n)}let{ProjectivePoint:u,normPrivateKeyToScalar:l,weierstrassEquation:f,isWithinCurveOrder:m}=dw({...e,toBytes(B,I,P){let k=I.toAffine(),w=t.toBytes(k.x),C=Ot;return P?C(Uint8Array.from([I.hasEvenY()?2:3]),w):C(Uint8Array.from([4]),w,t.toBytes(k.y))},fromBytes(B){let I=B.length,P=B[0],k=B.subarray(1);if(I===o&&(P===2||P===3)){let w=Lt(k);if(!i(w))throw new Error("Point is not on curve");let C=f(w),T;try{T=t.sqrt(C)}catch(q){let Y=q instanceof Error?": "+q.message:"";throw new Error("Point is not on curve"+Y)}let N=(T&tt)===tt;return(P&1)===1!==N&&(T=t.neg(T)),{x:w,y:T}}else if(I===s&&P===4){let w=t.fromBytes(k.subarray(0,t.BYTES)),C=t.fromBytes(k.subarray(t.BYTES,2*t.BYTES));return{x:w,y:C}}else throw new Error(`Point of length ${I} was invalid. Expected ${o} compressed bytes or ${s} uncompressed bytes`)}}),g=B=>Nt(or(B,e.nByteLength));function p(B){let I=n>>tt;return B>I}function h(B){return p(B)?a(-B):B}let d=(B,I,P)=>Lt(B.slice(I,P));class y{constructor(I,P,k){this.r=I,this.s=P,this.recovery=k,this.assertValidity()}static fromCompact(I){let P=e.nByteLength;return I=ce("compactSignature",I,P*2),new y(d(I,0,P),d(I,P,2*P))}static fromDER(I){let{r:P,s:k}=Ur.toSig(ce("DER",I));return new y(P,k)}assertValidity(){if(!m(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!m(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(I){return new y(this.r,this.s,I)}recoverPublicKey(I){let{r:P,s:k,recovery:w}=this,C=S(ce("msgHash",I));if(w==null||![0,1,2,3].includes(w))throw new Error("recovery id invalid");let T=w===2||w===3?P+e.n:P;if(T>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");let N=w&1?"03":"02",$=u.fromHex(N+g(T)),q=c(T),Y=a(-C*q),z=a(k*q),j=u.BASE.multiplyAndAddUnsafe($,Y,z);if(!j)throw new Error("point at infinify");return j.assertValidity(),j}hasHighS(){return p(this.s)}normalizeS(){return this.hasHighS()?new y(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return Tr(this.toDERHex())}toDERHex(){return Ur.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Tr(this.toCompactHex())}toCompactHex(){return g(this.r)+g(this.s)}}let x={isValidPrivateKey(B){try{return l(B),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{let B=Bc(e.n);return nh(e.randomBytes(B),e.n)},precompute(B=8,I=u.BASE){return I._setWindowSize(B),I.multiply(BigInt(3)),I}};function b(B,I=!0){return u.fromPrivateKey(B).toRawBytes(I)}function A(B){let I=nr(B),P=typeof B=="string",k=(I||P)&&B.length;return I?k===o||k===s:P?k===2*o||k===2*s:B instanceof u}function E(B,I,P=!0){if(A(B))throw new Error("first arg must be private key");if(!A(I))throw new Error("second arg must be public key");return u.fromHex(I).multiply(l(B)).toRawBytes(P)}let v=e.bits2int||function(B){let I=Lt(B),P=B.length*8-e.nBitLength;return P>0?I>>BigInt(P):I},S=e.bits2int_modN||function(B){return a(v(B))},D=jn(e.nBitLength);function _(B){if(typeof B!="bigint")throw new Error("bigint expected");if(!(qt<=B&&B<D))throw new Error(`bigint expected < 2^${e.nBitLength}`);return or(B,e.nByteLength)}function O(B,I,P=R){if(["recovered","canonical"].some(se=>se in P))throw new Error("sign() legacy options not supported");let{hash:k,randomBytes:w}=e,{lowS:C,prehash:T,extraEntropy:N}=P;C==null&&(C=!0),B=ce("msgHash",B),T&&(B=ce("prehashed msgHash",k(B)));let $=S(B),q=l(I),Y=[_(q),_($)];if(N!=null&&N!==!1){let se=N===!0?w(t.BYTES):N;Y.push(ce("extraEntropy",se))}let z=Ot(...Y),j=$;function ae(se){let Ie=v(se);if(!m(Ie))return;let Te=c(Ie),ve=u.BASE.multiply(Ie).toAffine(),Oe=a(ve.x);if(Oe===qt)return;let Bt=a(Te*a(j+Oe*q));if(Bt===qt)return;let pr=(ve.x===Oe?0:2)|Number(ve.y&tt),Rn=Bt;return C&&p(Bt)&&(Rn=h(Bt),pr^=1),new y(Oe,Rn,pr)}return{seed:z,k2sig:ae}}let R={lowS:e.lowS,prehash:!1},H={lowS:e.lowS,prehash:!1};function V(B,I,P=R){let{seed:k,k2sig:w}=O(B,I,P),C=e;return Ec(C.hash.outputLen,C.nByteLength,C.hmac)(k,w)}u.BASE._setWindowSize(8);function G(B,I,P,k=H){let w=B;if(I=ce("msgHash",I),P=ce("publicKey",P),"strict"in k)throw new Error("options.strict was renamed to lowS");let{lowS:C,prehash:T}=k,N,$;try{if(typeof w=="string"||nr(w))try{N=y.fromDER(w)}catch(ve){if(!(ve instanceof Ur.Err))throw ve;N=y.fromCompact(w)}else if(typeof w=="object"&&typeof w.r=="bigint"&&typeof w.s=="bigint"){let{r:ve,s:Oe}=w;N=new y(ve,Oe)}else throw new Error("PARSE");$=u.fromHex(P)}catch(ve){if(ve.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(C&&N.hasHighS())return!1;T&&(I=e.hash(I));let{r:q,s:Y}=N,z=S(I),j=c(Y),ae=a(z*j),se=a(q*j),Ie=u.BASE.multiplyAndAddUnsafe($,ae,se)?.toAffine();return Ie?a(Ie.x)===q:!1}return{CURVE:e,getPublicKey:b,getSharedSecret:E,sign:V,verify:G,ProjectivePoint:u,Signature:y,utils:x}}function mw(r){return{hash:r,hmac:(e,...t)=>sr(r,e,gc(...t)),randomBytes:Ir}}function fd(r,e){let t=n=>ld({...r,...mw(n)});return Object.freeze({...t(e),create:t})}var pd=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),hd=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),gw=BigInt(1),$c=BigInt(2),dd=(r,e)=>(r+e/$c)/e;function bw(r){let e=pd,t=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=r*r*r%e,l=u*u*r%e,f=ue(l,t,e)*l%e,m=ue(f,t,e)*l%e,g=ue(m,$c,e)*u%e,p=ue(g,o,e)*g%e,h=ue(p,s,e)*p%e,d=ue(h,a,e)*h%e,y=ue(d,c,e)*d%e,x=ue(y,a,e)*h%e,b=ue(x,t,e)*l%e,A=ue(b,i,e)*p%e,E=ue(A,n,e)*u%e,v=ue(E,$c,e);if(!qc.eql(qc.sqr(v),r))throw new Error("Cannot find square root");return v}var qc=xs(pd,void 0,void 0,{sqrt:bw}),pt=fd({a:BigInt(0),b:BigInt(7),Fp:qc,n:hd,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let e=hd,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-gw*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=t,i=BigInt("0x100000000000000000000000000000000"),a=dd(s*r,e),c=dd(-n*r,e),u=te(r-a*t-c*o,e),l=te(-a*n-c*s,e),f=u>i,m=l>i;if(f&&(u=e-u),m&&(l=e-l),u>i||l>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:u,k2neg:m,k2:l}}}},yn),mS=BigInt(0);var gS=pt.ProjectivePoint;function md(){return pt.utils.randomPrivateKey()}function gd(r,e){let t=_e.digest(e instanceof Uint8Array?e:e.subarray());if(Je(t))return t.then(({digest:n})=>pt.sign(n,r).toDERRawBytes()).catch(n=>{throw new L(String(n),"ERR_INVALID_INPUT")});try{return pt.sign(t.digest,r).toDERRawBytes()}catch(n){throw new L(String(n),"ERR_INVALID_INPUT")}}function bd(r,e,t){let n=_e.digest(t instanceof Uint8Array?t:t.subarray());if(Je(n))return n.then(({digest:o})=>pt.verify(e,o,r)).catch(o=>{throw new L(String(o),"ERR_INVALID_INPUT")});try{return pt.verify(e,n.digest,r)}catch(o){throw new L(String(o),"ERR_INVALID_INPUT")}}function yd(r){return pt.ProjectivePoint.fromHex(r).toRawBytes(!0)}function wd(r){try{pt.getPublicKey(r,!0)}catch(e){throw new L(String(e),"ERR_INVALID_PRIVATE_KEY")}}function Wc(r){try{pt.ProjectivePoint.fromHex(r)}catch(e){throw new L(String(e),"ERR_INVALID_PUBLIC_KEY")}}function xd(r){try{return pt.getPublicKey(r,!0)}catch(e){throw new L(String(e),"ERR_INVALID_PRIVATE_KEY")}}var fo=class{_key;constructor(e){Wc(e),this._key=e}verify(e,t){return bd(this._key,t,e)}marshal(){return yd(this._key)}get bytes(){return xt.encode({Type:he.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return Ae(this.bytes,e.bytes)}async hash(){let e=_e.digest(this.bytes),t;return Je(e)?{bytes:t}=await e:t=e.bytes,t}},ho=class{_key;_publicKey;constructor(e,t){this._key=e,this._publicKey=t??xd(e),wd(this._key),Wc(this._publicKey)}sign(e){return gd(this._key,e)}get public(){return new fo(this._publicKey)}marshal(){return this._key}get bytes(){return Et.encode({Type:he.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return Ae(this.bytes,e.bytes)}hash(){let e=_e.digest(this.bytes);return Je(e)?e.then(({bytes:t})=>t):e.bytes}async id(){let e=await this.public.hash();return W(e,"base58btc")}async export(e,t="libp2p-key"){if(t==="libp2p-key")return fn(this.bytes,e);throw new L(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function ww(r){return new ho(r)}function xw(r){return new fo(r)}async function Ew(){let r=md();return new ho(r)}var Or={rsa:Hc,ed25519:_c,secp256k1:zc};function Ed(r){let e=Object.keys(Or).join(" / ");return new L(`invalid or unsupported key type ${r}. Must be ${e}`,"ERR_UNSUPPORTED_KEY_TYPE")}function vd(r){let e=xt.decode(r),t=e.Data??new Uint8Array;switch(e.Type){case he.RSA:return Or.rsa.unmarshalRsaPublicKey(t);case he.Ed25519:return Or.ed25519.unmarshalEd25519PublicKey(t);case he.Secp256k1:return Or.secp256k1.unmarshalSecp256k1PublicKey(t);default:throw Ed(e.Type??"unknown")}}async function Gc(r){let e=Et.decode(r),t=e.Data??new Uint8Array;switch(e.Type){case he.RSA:return Or.rsa.unmarshalRsaPrivateKey(t);case he.Ed25519:return Or.ed25519.unmarshalEd25519PrivateKey(t);case he.Secp256k1:return Or.secp256k1.unmarshalSecp256k1PrivateKey(t);default:throw Ed(e.Type??"RSA")}}function jc(){let r=pe(),e=!1;return{sink:async t=>{if(e)throw new Error("already piped");e=!0,r.resolve(t)},source:async function*(){yield*await r.promise}()}}function Ad(){let r=jc(),e=jc();return[{source:r.source,sink:e.sink},{source:e.source,sink:r.sink}]}function vw(r){return r[Symbol.asyncIterator]!=null}function Aw(...r){let e=[];for(let t of r)vw(t)||e.push(t);return e.length===r.length?function*(){for(let t of e)yield*t}():async function*(){let t=Zt({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(r.map(async n=>{for await(let o of n)t.push(o)})),t.end()}catch(n){t.end(n)}}),yield*t}()}var Dd=Aw;function Sd(r,...e){if(r==null)throw new Error("Empty pipeline");if(Yc(r)){let n=r;r=()=>n.source}else if(kd(r)||Bd(r)){let n=r;r=()=>n}let t=[r,...e];if(t.length>1&&Yc(t[t.length-1])&&(t[t.length-1]=t[t.length-1].sink),t.length>2)for(let n=1;n<t.length-1;n++)Yc(t[n])&&(t[n]=Sw(t[n]));return Dw(...t)}var Dw=(...r)=>{let e;for(;r.length>0;)e=r.shift()(e);return e},Bd=r=>r?.[Symbol.asyncIterator]!=null,kd=r=>r?.[Symbol.iterator]!=null,Yc=r=>r==null?!1:r.sink!=null&&r.source!=null,Sw=r=>e=>{let t=r.sink(e);if(t?.then!=null){let n=Zt({objectMode:!0});t.then(()=>{n.end()},i=>{n.end(i)});let o,s=r.source;if(Bd(s))o=async function*(){yield*s,n.end()};else if(kd(s))o=function*(){yield*s,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return Dd(n,o())}return r.source};var wn=!!globalThis.process?.env?.DUMP_SESSION_KEYS;function mi(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`positive integer expected, not ${r}`)}function Zc(r){if(typeof r!="boolean")throw new Error(`boolean expected, not ${r}`)}function Xc(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function ze(r,...e){if(!Xc(r))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(r.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${r.length}`)}function Jc(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 Cd(r,e){ze(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var Wt=r=>new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4)),Id=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Bw=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Bw)throw new Error("Non little-endian hardware is not supported");function kw(r){if(typeof r!="string")throw new Error(`string expected, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function gi(r){if(typeof r=="string")r=kw(r);else if(Xc(r))r=r.slice();else throw new Error(`Uint8Array expected, got ${typeof r}`);return r}function Td(r,e){if(e==null||typeof e!="object")throw new Error("options must be defined");return Object.assign(r,e)}function _d(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}var Qc=(r,e)=>(Object.assign(e,r),e);function eu(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(t>>o&s),a=Number(t&s),c=n?4:0,u=n?0:4;r.setUint32(e+c,i,n),r.setUint32(e+u,a,n)}var Le=(r,e)=>r[e++]&255|(r[e++]&255)<<8,tu=class{constructor(e){this.blockLen=16,this.outputLen=16,this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.pos=0,this.finished=!1,e=gi(e),ze(e,32);let t=Le(e,0),n=Le(e,2),o=Le(e,4),s=Le(e,6),i=Le(e,8),a=Le(e,10),c=Le(e,12),u=Le(e,14);this.r[0]=t&8191,this.r[1]=(t>>>13|n<<3)&8191,this.r[2]=(n>>>10|o<<6)&7939,this.r[3]=(o>>>7|s<<9)&8191,this.r[4]=(s>>>4|i<<12)&255,this.r[5]=i>>>1&8190,this.r[6]=(i>>>14|a<<2)&8191,this.r[7]=(a>>>11|c<<5)&8065,this.r[8]=(c>>>8|u<<8)&8191,this.r[9]=u>>>5&127;for(let l=0;l<8;l++)this.pad[l]=Le(e,16+2*l)}process(e,t,n=!1){let o=n?0:2048,{h:s,r:i}=this,a=i[0],c=i[1],u=i[2],l=i[3],f=i[4],m=i[5],g=i[6],p=i[7],h=i[8],d=i[9],y=Le(e,t+0),x=Le(e,t+2),b=Le(e,t+4),A=Le(e,t+6),E=Le(e,t+8),v=Le(e,t+10),S=Le(e,t+12),D=Le(e,t+14),_=s[0]+(y&8191),O=s[1]+((y>>>13|x<<3)&8191),R=s[2]+((x>>>10|b<<6)&8191),H=s[3]+((b>>>7|A<<9)&8191),V=s[4]+((A>>>4|E<<12)&8191),G=s[5]+(E>>>1&8191),B=s[6]+((E>>>14|v<<2)&8191),I=s[7]+((v>>>11|S<<5)&8191),P=s[8]+((S>>>8|D<<8)&8191),k=s[9]+(D>>>5|o),w=0,C=w+_*a+O*(5*d)+R*(5*h)+H*(5*p)+V*(5*g);w=C>>>13,C&=8191,C+=G*(5*m)+B*(5*f)+I*(5*l)+P*(5*u)+k*(5*c),w+=C>>>13,C&=8191;let T=w+_*c+O*a+R*(5*d)+H*(5*h)+V*(5*p);w=T>>>13,T&=8191,T+=G*(5*g)+B*(5*m)+I*(5*f)+P*(5*l)+k*(5*u),w+=T>>>13,T&=8191;let N=w+_*u+O*c+R*a+H*(5*d)+V*(5*h);w=N>>>13,N&=8191,N+=G*(5*p)+B*(5*g)+I*(5*m)+P*(5*f)+k*(5*l),w+=N>>>13,N&=8191;let $=w+_*l+O*u+R*c+H*a+V*(5*d);w=$>>>13,$&=8191,$+=G*(5*h)+B*(5*p)+I*(5*g)+P*(5*m)+k*(5*f),w+=$>>>13,$&=8191;let q=w+_*f+O*l+R*u+H*c+V*a;w=q>>>13,q&=8191,q+=G*(5*d)+B*(5*h)+I*(5*p)+P*(5*g)+k*(5*m),w+=q>>>13,q&=8191;let Y=w+_*m+O*f+R*l+H*u+V*c;w=Y>>>13,Y&=8191,Y+=G*a+B*(5*d)+I*(5*h)+P*(5*p)+k*(5*g),w+=Y>>>13,Y&=8191;let z=w+_*g+O*m+R*f+H*l+V*u;w=z>>>13,z&=8191,z+=G*c+B*a+I*(5*d)+P*(5*h)+k*(5*p),w+=z>>>13,z&=8191;let j=w+_*p+O*g+R*m+H*f+V*l;w=j>>>13,j&=8191,j+=G*u+B*c+I*a+P*(5*d)+k*(5*h),w+=j>>>13,j&=8191;let ae=w+_*h+O*p+R*g+H*m+V*f;w=ae>>>13,ae&=8191,ae+=G*l+B*u+I*c+P*a+k*(5*d),w+=ae>>>13,ae&=8191;let se=w+_*d+O*h+R*p+H*g+V*m;w=se>>>13,se&=8191,se+=G*f+B*l+I*u+P*c+k*a,w+=se>>>13,se&=8191,w=(w<<2)+w|0,w=w+C|0,C=w&8191,w=w>>>13,T+=w,s[0]=C,s[1]=T,s[2]=N,s[3]=$,s[4]=q,s[5]=Y,s[6]=z,s[7]=j,s[8]=ae,s[9]=se}finalize(){let{h:e,pad:t}=this,n=new Uint16Array(10),o=e[1]>>>13;e[1]&=8191;for(let a=2;a<10;a++)e[a]+=o,o=e[a]>>>13,e[a]&=8191;e[0]+=o*5,o=e[0]>>>13,e[0]&=8191,e[1]+=o,o=e[1]>>>13,e[1]&=8191,e[2]+=o,n[0]=e[0]+5,o=n[0]>>>13,n[0]&=8191;for(let a=1;a<10;a++)n[a]=e[a]+o,o=n[a]>>>13,n[a]&=8191;n[9]-=8192;let s=(o^1)-1;for(let a=0;a<10;a++)n[a]&=s;s=~s;for(let a=0;a<10;a++)e[a]=e[a]&s|n[a];e[0]=(e[0]|e[1]<<13)&65535,e[1]=(e[1]>>>3|e[2]<<10)&65535,e[2]=(e[2]>>>6|e[3]<<7)&65535,e[3]=(e[3]>>>9|e[4]<<4)&65535,e[4]=(e[4]>>>12|e[5]<<1|e[6]<<14)&65535,e[5]=(e[6]>>>2|e[7]<<11)&65535,e[6]=(e[7]>>>5|e[8]<<8)&65535,e[7]=(e[8]>>>8|e[9]<<5)&65535;let i=e[0]+t[0];e[0]=i&65535;for(let a=1;a<8;a++)i=(e[a]+t[a]|0)+(i>>>16)|0,e[a]=i&65535}update(e){Jc(this);let{buffer:t,blockLen:n}=this;e=gi(e);let o=e.length;for(let s=0;s<o;){let i=Math.min(n-this.pos,o-s);if(i===n){for(;n<=o-s;s+=n)this.process(e,s);continue}t.set(e.subarray(s,s+i),this.pos),this.pos+=i,s+=i,this.pos===n&&(this.process(t,0,!1),this.pos=0)}return this}destroy(){this.h.fill(0),this.r.fill(0),this.buffer.fill(0),this.pad.fill(0)}digestInto(e){Jc(this),Cd(e,this),this.finished=!0;let{buffer:t,h:n}=this,{pos:o}=this;if(o){for(t[o++]=1;o<16;o++)t[o]=0;this.process(t,0,!0)}this.finalize();let s=0;for(let i=0;i<8;i++)e[s++]=n[i]>>>0,e[s++]=n[i]>>>8;return e}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}};function Cw(r){let e=(n,o)=>r(o).update(gi(n)).digest(),t=r(new Uint8Array(32));return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=n=>r(n),e}var Rd=Cw(r=>new tu(r));var Ld=r=>Uint8Array.from(r.split("").map(e=>e.charCodeAt(0))),Iw=Ld("expand 16-byte k"),Tw=Ld("expand 32-byte k"),_w=Wt(Iw),Ud=Wt(Tw),jS=Ud.slice();function F(r,e){return r<<e|r>>>32-e}function ru(r){return r.byteOffset%4===0}var bi=64,Rw=16,Od=2**32-1,Nd=new Uint32Array;function Nw(r,e,t,n,o,s,i,a){let c=o.length,u=new Uint8Array(bi),l=Wt(u),f=ru(o)&&ru(s),m=f?Wt(o):Nd,g=f?Wt(s):Nd;for(let p=0;p<c;i++){if(r(e,t,n,l,i,a),i>=Od)throw new Error("arx: counter overflow");let h=Math.min(bi,c-p);if(f&&h===bi){let d=p/4;if(p%4!==0)throw new Error("arx: invalid block position");for(let y=0,x;y<Rw;y++)x=d+y,g[x]=m[x]^l[y];p+=bi;continue}for(let d=0,y;d<h;d++)y=p+d,s[y]=o[y]^u[d];p+=h}}function nu(r,e){let{allowShortKeys:t,extendNonceFn:n,counterLength:o,counterRight:s,rounds:i}=Td({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof r!="function")throw new Error("core must be a function");return mi(o),mi(i),Zc(s),Zc(t),(a,c,u,l,f=0)=>{ze(a),ze(c),ze(u);let m=u.length;if(l||(l=new Uint8Array(m)),ze(l),mi(f),f<0||f>=Od)throw new Error("arx: counter overflow");if(l.length<m)throw new Error(`arx: output (${l.length}) is shorter than data (${m})`);let g=[],p=a.length,h,d;if(p===32)h=a.slice(),g.push(h),d=Ud;else if(p===16&&t)h=new Uint8Array(32),h.set(a),h.set(a,16),d=_w,g.push(h);else throw new Error(`arx: invalid 32-byte key, got length=${p}`);ru(c)||(c=c.slice(),g.push(c));let y=Wt(h);if(n){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");n(d,y,Wt(c.subarray(0,16)),y),c=c.subarray(16)}let x=16-o;if(x!==c.length)throw new Error(`arx: nonce must be ${x} or 16 bytes`);if(x!==12){let A=new Uint8Array(12);A.set(c,s?0:12-c.length),c=A,g.push(c)}let b=Wt(c);for(Nw(r,d,y,b,u,l,f,i);g.length>0;)g.pop().fill(0);return l}}function Fd(r,e,t,n,o,s=20){let i=r[0],a=r[1],c=r[2],u=r[3],l=e[0],f=e[1],m=e[2],g=e[3],p=e[4],h=e[5],d=e[6],y=e[7],x=o,b=t[0],A=t[1],E=t[2],v=i,S=a,D=c,_=u,O=l,R=f,H=m,V=g,G=p,B=h,I=d,P=y,k=x,w=b,C=A,T=E;for(let $=0;$<s;$+=2)v=v+O|0,k=F(k^v,16),G=G+k|0,O=F(O^G,12),v=v+O|0,k=F(k^v,8),G=G+k|0,O=F(O^G,7),S=S+R|0,w=F(w^S,16),B=B+w|0,R=F(R^B,12),S=S+R|0,w=F(w^S,8),B=B+w|0,R=F(R^B,7),D=D+H|0,C=F(C^D,16),I=I+C|0,H=F(H^I,12),D=D+H|0,C=F(C^D,8),I=I+C|0,H=F(H^I,7),_=_+V|0,T=F(T^_,16),P=P+T|0,V=F(V^P,12),_=_+V|0,T=F(T^_,8),P=P+T|0,V=F(V^P,7),v=v+R|0,T=F(T^v,16),I=I+T|0,R=F(R^I,12),v=v+R|0,T=F(T^v,8),I=I+T|0,R=F(R^I,7),S=S+H|0,k=F(k^S,16),P=P+k|0,H=F(H^P,12),S=S+H|0,k=F(k^S,8),P=P+k|0,H=F(H^P,7),D=D+V|0,w=F(w^D,16),G=G+w|0,V=F(V^G,12),D=D+V|0,w=F(w^D,8),G=G+w|0,V=F(V^G,7),_=_+O|0,C=F(C^_,16),B=B+C|0,O=F(O^B,12),_=_+O|0,C=F(C^_,8),B=B+C|0,O=F(O^B,7);let N=0;n[N++]=i+v|0,n[N++]=a+S|0,n[N++]=c+D|0,n[N++]=u+_|0,n[N++]=l+O|0,n[N++]=f+R|0,n[N++]=m+H|0,n[N++]=g+V|0,n[N++]=p+G|0,n[N++]=h+B|0,n[N++]=d+I|0,n[N++]=y+P|0,n[N++]=x+k|0,n[N++]=b+w|0,n[N++]=A+C|0,n[N++]=E+T|0}function Lw(r,e,t,n){let o=r[0],s=r[1],i=r[2],a=r[3],c=e[0],u=e[1],l=e[2],f=e[3],m=e[4],g=e[5],p=e[6],h=e[7],d=t[0],y=t[1],x=t[2],b=t[3];for(let E=0;E<20;E+=2)o=o+c|0,d=F(d^o,16),m=m+d|0,c=F(c^m,12),o=o+c|0,d=F(d^o,8),m=m+d|0,c=F(c^m,7),s=s+u|0,y=F(y^s,16),g=g+y|0,u=F(u^g,12),s=s+u|0,y=F(y^s,8),g=g+y|0,u=F(u^g,7),i=i+l|0,x=F(x^i,16),p=p+x|0,l=F(l^p,12),i=i+l|0,x=F(x^i,8),p=p+x|0,l=F(l^p,7),a=a+f|0,b=F(b^a,16),h=h+b|0,f=F(f^h,12),a=a+f|0,b=F(b^a,8),h=h+b|0,f=F(f^h,7),o=o+u|0,b=F(b^o,16),p=p+b|0,u=F(u^p,12),o=o+u|0,b=F(b^o,8),p=p+b|0,u=F(u^p,7),s=s+l|0,d=F(d^s,16),h=h+d|0,l=F(l^h,12),s=s+l|0,d=F(d^s,8),h=h+d|0,l=F(l^h,7),i=i+f|0,y=F(y^i,16),m=m+y|0,f=F(f^m,12),i=i+f|0,y=F(y^i,8),m=m+y|0,f=F(f^m,7),a=a+c|0,x=F(x^a,16),g=g+x|0,c=F(c^g,12),a=a+c|0,x=F(x^a,8),g=g+x|0,c=F(c^g,7);let A=0;n[A++]=o,n[A++]=s,n[A++]=i,n[A++]=a,n[A++]=d,n[A++]=y,n[A++]=x,n[A++]=b}var Uw=nu(Fd,{counterRight:!1,counterLength:4,allowShortKeys:!1}),Ow=nu(Fd,{counterRight:!1,counterLength:8,extendNonceFn:Lw,allowShortKeys:!1});var Pw=new Uint8Array(16),Pd=(r,e)=>{r.update(e);let t=e.length%16;t&&r.update(Pw.subarray(t))},Mw=new Uint8Array(32);function Md(r,e,t,n,o){let s=r(e,t,Mw),i=Rd.create(s);o&&Pd(i,o),Pd(i,n);let a=new Uint8Array(16),c=Id(a);eu(c,0,BigInt(o?o.length:0),!0),eu(c,8,BigInt(n.length),!0),i.update(a);let u=i.digest();return s.fill(0),u}var Vd=r=>(e,t,n)=>(ze(e,32),ze(t),{encrypt:(s,i)=>{let a=s.length,c=a+16;i?ze(i,c):i=new Uint8Array(c),r(e,t,s,i,1);let u=Md(r,e,t,i.subarray(0,-16),n);return i.set(u,a),i},decrypt:(s,i)=>{let a=s.length,c=a-16;if(a<16)throw new Error("encrypted data must be at least 16 bytes");i?ze(i,c):i=new Uint8Array(c);let u=s.subarray(0,-16),l=s.subarray(-16),f=Md(r,e,t,u,n);if(!_d(l,f))throw new Error("invalid tag");return r(e,t,u,i,1),i}}),ou=Qc({blockSize:64,nonceLength:12,tagLength:16},Vd(Uw)),eB=Qc({blockSize:64,nonceLength:24,tagLength:16},Vd(Ow));function Kd(r,e,t){return Cr(r),t===void 0&&(t=new Uint8Array(r.outputLen)),sr(r,ut(t),ut(e))}var su=new Uint8Array([0]),Hd=new Uint8Array;function $d(r,e,t,n=32){if(Cr(r),er(n),n>255*r.outputLen)throw new Error("Length should be <= 255*HashLen");let o=Math.ceil(n/r.outputLen);t===void 0&&(t=Hd);let s=new Uint8Array(o*r.outputLen),i=sr.create(r,e),a=i._cloneInto(),c=new Uint8Array(i.outputLen);for(let u=0;u<o;u++)su[0]=u+1,a.update(u===0?Hd:c).update(t).update(su).digestInto(c),s.set(c,r.outputLen*u),i._cloneInto(a);return i.destroy(),a.destroy(),c.fill(0),su.fill(0),s.slice(0,n)}var iu={hashSHA256(r){return yn(r.subarray())},getHKDF(r,e){let t=Kd(yn,e,r),o=$d(yn,t,void 0,96),s=o.subarray(0,32),i=o.subarray(32,64),a=o.subarray(64,96);return[s,i,a]},generateX25519KeyPair(){let r=Jn.utils.randomPrivateKey();return{publicKey:Jn.getPublicKey(r),privateKey:r}},generateX25519KeyPairFromSeed(r){return{publicKey:Jn.getPublicKey(r),privateKey:r}},generateX25519SharedKey(r,e){return Jn.getSharedSecret(r.subarray(),e.subarray())},chaCha20Poly1305Encrypt(r,e,t,n){return ou(n,e,t).encrypt(r.subarray())},chaCha20Poly1305Decrypt(r,e,t,n,o){return ou(n,e,t).decrypt(r.subarray(),o)}};var qd=iu;function Wd(r){return{generateKeypair:r.generateX25519KeyPair,dh:(e,t)=>r.generateX25519SharedKey(e.privateKey,t).subarray(0,32),encrypt:r.chaCha20Poly1305Encrypt,decrypt:r.chaCha20Poly1305Decrypt,hash:r.hashSHA256,hkdf:r.getHKDF}}var xn=r=>{let e=Se(2);return e[0]=r>>8,e[1]=r,e};xn.bytes=2;var po=r=>{if(r.length<2)throw RangeError("Could not decode int16BE");if(r instanceof Uint8Array){let e=0;return e+=r[0]<<8,e+=r[1],e}return r.getUint16(0)};po.bytes=2;function zd(r){return{xxHandshakeSuccesses:r.registerCounter("libp2p_noise_xxhandshake_successes_total",{help:"Total count of noise xxHandshakes successes_"}),xxHandshakeErrors:r.registerCounter("libp2p_noise_xxhandshake_error_total",{help:"Total count of noise xxHandshakes errors"}),encryptedPackets:r.registerCounter("libp2p_noise_encrypted_packets_total",{help:"Total count of noise encrypted packets successfully"}),decryptedPackets:r.registerCounter("libp2p_noise_decrypted_packets_total",{help:"Total count of noise decrypted packets"}),decryptErrors:r.registerCounter("libp2p_noise_decrypt_errors_total",{help:"Total count of noise decrypt errors"})}}function au(r,e){!e.enabled||!wn||(r?(e(`LOCAL_STATIC_PUBLIC_KEY ${W(r.publicKey,"hex")}`),e(`LOCAL_STATIC_PRIVATE_KEY ${W(r.privateKey,"hex")}`)):e("Missing local static keys."))}function cu(r,e){!e.enabled||!wn||(r?(e(`LOCAL_PUBLIC_EPHEMERAL_KEY ${W(r.publicKey,"hex")}`),e(`LOCAL_PRIVATE_EPHEMERAL_KEY ${W(r.privateKey,"hex")}`)):e("Missing local ephemeral keys."))}function Gd(r,e){!e.enabled||!wn||e(r?`REMOTE_STATIC_PUBLIC_KEY ${W(r.subarray(),"hex")}`:"Missing remote static public key.")}function uu(r,e){!e.enabled||!wn||e(r?`REMOTE_EPHEMERAL_PUBLIC_KEY ${W(r.subarray(),"hex")}`:"Missing remote ephemeral keys.")}function lu(r,e,t){!t.enabled||!wn||(t(`CIPHER_STATE_1 ${r.n.getUint64()} ${r.k&&W(r.k,"hex")}`),t(`CIPHER_STATE_2 ${e.n.getUint64()} ${e.k&&W(e.k,"hex")}`))}var yi=class r extends Error{code;constructor(e="Unexpected Peer"){super(e),this.code=r.code}static code="ERR_UNEXPECTED_PEER"},En=class r extends Error{code;constructor(e="Invalid crypto exchange"){super(e),this.code=r.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var Fw=0,Vw=4294967295,Hw="Cipherstate has reached maximum n, a new handshake must be performed",wi=class{n;bytes;view;constructor(e=Fw){this.n=e,this.bytes=De(12),this.view=new DataView(this.bytes.buffer,this.bytes.byteOffset,this.bytes.byteLength),this.view.setUint32(4,e,!0)}increment(){this.n++,this.view.setUint32(4,this.n,!0)}getBytes(){return this.bytes}getUint64(){return this.n}assertValue(){if(this.n>Vw)throw new Error(Hw)}};var Pr=De(0),vn=class{k;n;crypto;constructor(e,t=void 0,n=0){this.crypto=e,this.k=t,this.n=new wi(n)}hasKey(){return!!this.k}encryptWithAd(e,t){if(!this.hasKey())return t;this.n.assertValue();let n=this.crypto.encrypt(t,this.n.getBytes(),e,this.k);return this.n.increment(),n}decryptWithAd(e,t,n){if(!this.hasKey())return t;this.n.assertValue();let o=this.crypto.decrypt(t,this.n.getBytes(),e,this.k,n);return this.n.increment(),o}},fu=class{cs;ck;h;crypto;constructor(e,t){this.crypto=e;let n=J(t,"utf-8");this.h=Kw(e,n),this.ck=this.h,this.cs=new vn(e)}mixKey(e){let[t,n]=this.crypto.hkdf(this.ck,e);this.ck=t,this.cs=new vn(this.crypto,n)}mixHash(e){this.h=this.crypto.hash(new le(this.h,e))}encryptAndHash(e){let t=this.cs.encryptWithAd(this.h,e);return this.mixHash(t),t}decryptAndHash(e){let t=this.cs.decryptWithAd(this.h,e);return this.mixHash(e),t}split(){let[e,t]=this.crypto.hkdf(this.ck,Pr);return[new vn(this.crypto,e),new vn(this.crypto,t)]}},hu=class{ss;s;e;rs;re;initiator;crypto;constructor(e){let{crypto:t,protocolName:n,prologue:o,initiator:s,s:i,e:a,rs:c,re:u}=e;this.crypto=t,this.ss=new fu(t,n),this.ss.mixHash(o),this.initiator=s,this.s=i,this.e=a,this.rs=c,this.re=u}writeE(){if(this.e)throw new Error("ephemeral keypair is already set");let e=this.crypto.generateKeypair();return this.ss.mixHash(e.publicKey),this.e=e,e.publicKey}writeS(){if(!this.s)throw new Error("static keypair is not set");return this.ss.encryptAndHash(this.s.publicKey)}writeEE(){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.re))}writeES(){if(this.initiator){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}else{if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}}writeSE(){if(this.initiator){if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}else{if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}}readE(e,t=0){if(this.re)throw new Error("remote ephemeral public key is already set");if(e.byteLength<t+32)throw new Error("message is not long enough");this.re=e.sublist(t,t+32),this.ss.mixHash(this.re)}readS(e,t=0){if(this.rs)throw new Error("remote static public key is already set");let n=32+(this.ss.cs.hasKey()?16:0);if(e.byteLength<t+n)throw new Error("message is not long enough");let o=e.sublist(t,t+n);return this.rs=this.ss.decryptAndHash(o),n}readEE(){this.writeEE()}readES(){this.writeES()}readSE(){this.writeSE()}},mo=class extends hu{writeMessageA(e){return new le(this.writeE(),this.ss.encryptAndHash(e))}writeMessageB(e){let t=this.writeE();this.writeEE();let n=this.writeS();return this.writeES(),new le(t,n,this.ss.encryptAndHash(e))}writeMessageC(e){let t=this.writeS();return this.writeSE(),new le(t,this.ss.encryptAndHash(e))}readMessageA(e){try{return this.readE(e),this.ss.decryptAndHash(e.sublist(32))}catch(t){throw new En(`handshake stage 0 validation fail: ${t.message}`)}}readMessageB(e){try{this.readE(e),this.readEE();let t=this.readS(e,32);return this.readES(),this.ss.decryptAndHash(e.sublist(32+t))}catch(t){throw new En(`handshake stage 1 validation fail: ${t.message}`)}}readMessageC(e){try{let t=this.readS(e);return this.readSE(),this.ss.decryptAndHash(e.sublist(t))}catch(t){throw new En(`handshake stage 2 validation fail: ${t.message}`)}}};function Kw(r,e){if(e.length<=32){let t=De(32);return t.set(e),t}else return r.hash(e)}var xi;(function(r){let e;r.codec=()=>(e==null&&(e=at((t,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),t.webtransportCerthashes!=null)for(let s of t.webtransportCerthashes)n.uint32(10),n.bytes(s);o.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let o={webtransportCerthashes:[]},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let i=t.uint32();switch(i>>>3){case 1:{o.webtransportCerthashes.push(t.bytes());break}default:{t.skipType(i&7);break}}}return o})),e),r.encode=t=>it(t,r.codec()),r.decode=t=>st(t,r.codec())})(xi||(xi={}));var go;(function(r){let e;r.codec=()=>(e==null&&(e=at((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.identityKey!=null&&t.identityKey.byteLength>0&&(n.uint32(10),n.bytes(t.identityKey)),t.identitySig!=null&&t.identitySig.byteLength>0&&(n.uint32(18),n.bytes(t.identitySig)),t.extensions!=null&&(n.uint32(34),xi.codec().encode(t.extensions,n)),o.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let o={identityKey:De(0),identitySig:De(0)},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let i=t.uint32();switch(i>>>3){case 1:{o.identityKey=t.bytes();break}case 2:{o.identitySig=t.bytes();break}case 4:{o.extensions=xi.codec().decode(t,t.uint32());break}default:{t.skipType(i&7);break}}}return o})),e),r.encode=t=>it(t,r.codec()),r.decode=t=>st(t,r.codec())})(go||(go={}));async function du(r,e,t){let n=await r.sign(jd(e));return go.encode({identityKey:r.public.bytes,identitySig:n,extensions:t})}async function pu(r,e,t){try{let n=go.decode(r);if(t){let i=t.subarray();if(!Ae(i,n.identityKey))throw new Error(`Payload identity key ${W(n.identityKey,"hex")} does not match expected remote identity key ${W(i,"hex")}`)}if(!e)throw new Error("Remote static does not exist");let o=jd(e);if(!await vd(n.identityKey).verify(o,n.identitySig))throw new Error("Invalid payload signature");return n}catch(n){throw new yi(n.message)}}function jd(r){let e=J("noise-libp2p-static-key:");return r instanceof Uint8Array?xe([e,r],e.length+r.length):(r.prepend(e),r)}async function Yd(r){let{log:e,connection:t,crypto:n,privateKey:o,prologue:s,s:i,remoteIdentityKey:a,extensions:c}=r,u=await du(o,i.publicKey,c),l=new mo({crypto:n,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!0,prologue:s,s:i});au(l.s,e),e.trace("Stage 0 - Initiator starting to send first message."),await t.write(l.writeMessageA(Pr)),e.trace("Stage 0 - Initiator finished sending first message."),cu(l.e,e),e.trace("Stage 1 - Initiator waiting to receive first message from responder...");let f=l.readMessageB(await t.read());e.trace("Stage 1 - Initiator received the message."),uu(l.re,e),Gd(l.rs,e),e.trace("Initiator going to check remote's signature...");let m=await pu(f,l.rs,a);e.trace("All good with the signature!"),e.trace("Stage 2 - Initiator sending third handshake message."),await t.write(l.writeMessageC(u)),e.trace("Stage 2 - Initiator sent message with signed payload.");let[g,p]=l.ss.split();return lu(g,p,e),{payload:m,encrypt:h=>g.encryptWithAd(Pr,h),decrypt:(h,d)=>p.decryptWithAd(Pr,h,d)}}async function Zd(r){let{log:e,connection:t,crypto:n,privateKey:o,prologue:s,s:i,remoteIdentityKey:a,extensions:c}=r,u=await du(o,i.publicKey,c),l=new mo({crypto:n,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!1,prologue:s,s:i});au(l.s,e),e.trace("Stage 0 - Responder waiting to receive first message."),l.readMessageA(await t.read()),e.trace("Stage 0 - Responder received first message."),uu(l.re,e),e.trace("Stage 1 - Responder sending out first message with signed payload and static key."),await t.write(l.writeMessageB(u)),e.trace("Stage 1 - Responder sent the second handshake message with signed payload."),cu(l.e,e),e.trace("Stage 2 - Responder waiting for third handshake message...");let f=l.readMessageC(await t.read());e.trace("Stage 2 - Responder received the message, finished handshake.");let m=await pu(f,l.rs,a),[g,p]=l.ss.split();return lu(g,p,e),{payload:m,encrypt:h=>p.encryptWithAd(Pr,h),decrypt:(h,d)=>g.decryptWithAd(Pr,h,d)}}var Jd=16;function Qd(r,e){return async function*(t){for await(let n of t)for(let o=0;o<n.length;o+=65519){let s=o+65519;s>n.length&&(s=n.length);let i;n instanceof Uint8Array?i=r.encrypt(n.subarray(o,s)):i=r.encrypt(n.sublist(o,s)),e?.encryptedPackets.increment(),yield new le(xn(i.byteLength),i)}}}function ep(r,e){return async function*(t){for await(let n of t)for(let o=0;o<n.length;o+=65535){let s=o+65535;if(s>n.length&&(s=n.length),s-Jd<o)throw new Error("Invalid chunk");let i=n.sublist(o,s),a=n.subarray(o,s-Jd);try{let c=r.decrypt(i,a);e?.decryptedPackets.increment(),yield c}catch(c){throw e?.decryptErrors.increment(),c}}}}var Ei=class{protocol="/noise";crypto;prologue;staticKey;extensions;metrics;components;constructor(e,t={}){let{staticNoiseKey:n,extensions:o,crypto:s,prologueBytes:i}=t,{metrics:a}=e;this.components=e;let c=s??qd;this.crypto=Wd(c),this.extensions=o,this.metrics=a?zd(a):void 0,n?this.staticKey=c.generateX25519KeyPairFromSeed(n):this.staticKey=c.generateX25519KeyPair(),this.prologue=i??De(0)}[Symbol.toStringTag]="@chainsafe/libp2p-noise";[Vr]=["@libp2p/connection-encryption","@chainsafe/libp2p-noise"];async secureOutbound(e,t,n){let o=zn(t,{lengthEncoder:xn,lengthDecoder:po,maxDataLength:65535});if(!e.privateKey)throw new L("local peerId does not contain private key","ERR_NO_PRIVATE_KEY");let s=await Gc(e.privateKey),i=n?.publicKey,a=await this.performHandshakeInitiator(o,s,i),c=await this.createSecureConnection(o,a);return t.source=c.source,t.sink=c.sink,{conn:t,remoteExtensions:a.payload.extensions,remotePeer:await fa(a.payload.identityKey)}}async secureInbound(e,t,n){let o=zn(t,{lengthEncoder:xn,lengthDecoder:po,maxDataLength:65535});if(!e.privateKey)throw new L("local peerId does not contain private key","ERR_NO_PRIVATE_KEY");let s=await Gc(e.privateKey),i=n?.publicKey,a=await this.performHandshakeResponder(o,s,i),c=await this.createSecureConnection(o,a);return t.source=c.source,t.sink=c.sink,{conn:t,remoteExtensions:a.payload.extensions,remotePeer:await fa(a.payload.identityKey)}}async performHandshakeInitiator(e,t,n){let o;try{o=await Yd({connection:e,privateKey:t,remoteIdentityKey:n,log:this.components.logger.forComponent("libp2p:noise:xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:this.extensions}),this.metrics?.xxHandshakeSuccesses.increment()}catch(s){throw this.metrics?.xxHandshakeErrors.increment(),s}return o}async performHandshakeResponder(e,t,n){let o;try{o=await Zd({connection:e,privateKey:t,remoteIdentityKey:n,log:this.components.logger.forComponent("libp2p:noise:xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:this.extensions}),this.metrics?.xxHandshakeSuccesses.increment()}catch(s){throw this.metrics?.xxHandshakeErrors.increment(),s}return o}async createSecureConnection(e,t){let[n,o]=Ad(),s=e.unwrap();return await Sd(n,Qd(t,this.metrics),s,i=>Er(i,{lengthDecoder:po}),ep(t,this.metrics),n),o}};function tp(r={}){return e=>new Ei(e,r)}var _0=Bo(qu(),1);var D0=Bo(qu(),1);var Wu=Object.values(bt).map(r=>r.decoder).reduce((r,e)=>r.or(e));function S0(r,e){let t=r.getConfiguration().certificates?.at(0);if(t==null||t.getFingerprints==null){e.log.trace("fetching fingerprint from local SDP");let o=r.localDescription;return o==null?void 0:Y2(o.sdp)}if(e.log.trace("fetching fingerprint from local certificate"),t.getFingerprints().length===0)return;let n=t.getFingerprints()[0].value;if(n==null)throw Wa("","no fingerprint on local certificate");return n}var j2=/^a=fingerprint:(?:\w+-[0-9]+)\s(?<fingerprint>(:?[0-9a-fA-F]{2})+)$/m;function Y2(r){return r.match(j2)?.groups?.fingerprint}function Z2(r){for(let e of r.protoNames())if(e.startsWith("ip"))return e.toUpperCase();return"IP6"}function Ni(r){let t=r.stringTuples().filter(n=>n[0]===C0).map(n=>n[1])[0];if(t===void 0||t==="")throw qo(`Couldn't find a certhash component of multiaddr: ${r.toString()}`);return t}function zu(r){let e=Wu.decode(r);return D0.decode(e)}function X2(r){let e=zu(Ni(r)),t=Gu(e.name),n=e.digest.reduce((s,i)=>s+i.toString(16).padStart(2,"0"),""),o=n.match(/.{1,2}/g);if(o==null)throw Wa(n,r.toString());return[`${t.toUpperCase()} ${o.join(":").toUpperCase()}`,n]}function Gu(r){switch(r){case"sha1":return"sha-1";case"sha2-256":return"sha-256";case"sha2-512":return"sha-512";default:throw Jl(r)}}function J2(r,e){let{host:t,port:n}=r.toOptions(),o=Z2(r),[s]=X2(r);return`v=0
22
22
  o=- 0 0 IN ${o} ${t}
23
23
  s=-
24
24
  c=IN ${o} ${t}
@@ -33,11 +33,11 @@ a=fingerprint:${s}
33
33
  a=sctp-port:5000
34
34
  a=max-message-size:16384
35
35
  a=candidate:1467250027 1 UDP 1467250027 ${t} ${n} typ host\r
36
- `}function E0(r,e){return{type:"answer",sdp:j2(r,e)}}function v0(r,e){if(r.sdp===void 0)throw Vn("Can't munge a missing SDP");return r.sdp=r.sdp.replace(/\na=ice-ufrag:[^\n]*\n/,`
36
+ `}function B0(r,e){return{type:"answer",sdp:J2(r,e)}}function k0(r,e){if(r.sdp===void 0)throw Vn("Can't munge a missing SDP");return r.sdp=r.sdp.replace(/\na=ice-ufrag:[^\n]*\n/,`
37
37
  a=ice-ufrag:`+e+`
38
38
  `).replace(/\na=ice-pwd:[^\n]*\n/,`
39
39
  a=ice-pwd:`+e+`
40
- `),r}var D0=Array.from("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),S0=r=>[...Array(r)].map(()=>D0.at(Math.floor(Math.random()*D0.length))).join("");var Z2=1e4,O6=oe("webrtc-direct").code,A0=oe("certhash").code,Ni=class{log;metrics;components;init;constructor(e,t={}){this.log=e.logger.forComponent("libp2p:webrtc-direct"),this.components=e,this.init=t,e.metrics!=null&&(this.metrics={dialerEvents:e.metrics.registerCounterGroup("libp2p_webrtc-direct_dialer_events_total",{label:"event",help:"Total count of WebRTC-direct dial events by type"})})}[ko]=!0;[Symbol.toStringTag]="@libp2p/webrtc-direct";[Vr]=["@libp2p/transport"];async dial(e,t){let n=await this._connect(e,t);return this.log("dialing address: %a",e),n}createListener(e){throw Gu("WebRTCTransport.createListener")}listenFilter(e){return e.filter(qu.exactMatch)}dialFilter(e){return this.listenFilter(e)}async _connect(e,t){let n=new AbortController,o=n.signal,s=e.getPeerId();if(s===null)throw $o("we need to have the remote's PeerId");let i=br(s),a=Kl(Ri(e)),c=await Sr.generateCertificate({name:"ECDSA",namedCurve:"P-256",hash:$l(a.name)}),l=new Sr({...typeof this.init.rtcConfiguration=="function"?await this.init.rtcConfiguration():this.init.rtcConfiguration??{},certificates:[c]});try{let u=new Promise((D,_)=>{let O=l.createDataChannel("",{negotiated:!0,id:0}),R=setTimeout(()=>{let H=`Data channel was never opened: state: ${O.readyState}`;this.log.error(H),this.metrics?.dialerEvents.increment({open_error:!0}),_(Va("data",H))},Z2);O.onopen=H=>{clearTimeout(R),D(O)},O.onerror=H=>{clearTimeout(R);let G=`Error opening a data channel for handshaking: ${H.target?.toString()??"not specified"}`;this.log.error(G),this.metrics?.dialerEvents.increment({unknown_error:!0}),_(Va("data",G))}}),f="libp2p+webrtc+v1/"+S0(32),m=await l.createOffer(),g=v0(m,f);await l.setLocalDescription(g);let p=E0(e,f);await l.setRemoteDescription(p);let h=await u,d=this.components.peerId,y=this.generateNoisePrologue(l,a.code,e),x=Zd({prologueBytes:y})(this.components),b=en({channel:h,direction:"inbound",logger:this.components.logger,...this.init.dataChannel??{}}),A={...b,sink:b.sink.bind(b),source:async function*(){for await(let D of b.source)for(let _ of D)yield _}()},E=new wr(this.components,{peerConnection:l,remoteAddr:e,timeline:{open:Date.now()},metrics:this.metrics?.dialerEvents}),v=Hn?"iceconnectionstatechange":"connectionstatechange";l.addEventListener(v,()=>{switch(l.connectionState){case"failed":case"disconnected":case"closed":E.close().catch(D=>{this.log.error("error closing connection",D)}).finally(()=>{n.abort()});break;default:break}},{signal:o}),this.metrics?.dialerEvents.increment({peer_connection:!0});let S=new Jt(this.components,{peerConnection:l,metrics:this.metrics?.dialerEvents,dataChannelOptions:this.init.dataChannel});return await x.secureInbound(d,A,i),await t.upgrader.upgradeOutbound(E,{skipProtection:!0,skipEncryption:!0,muxerFactory:S})}catch(u){throw l.close(),u}}generateNoisePrologue(e,t,n){if(e.getConfiguration().certificates?.length===0)throw Vn("no local certificate");let o=x0(e,{log:this.log});if(o==null)throw Vn("no local fingerprint found");let s=o.trim().toLowerCase().replaceAll(":",""),i=Q(s,"hex"),a=B0.encode(i,t),c=Hl.decode(Ri(n)),l=Q("libp2p-webrtc-noise:");return xe([l,a,c])}};function X2(r){return e=>new Ni(e,r)}function J2(r){return e=>new hs(e,r)}return Bo(Q2);})();
40
+ `),r}var I0=Array.from("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),T0=r=>[...Array(r)].map(()=>I0.at(Math.floor(Math.random()*I0.length))).join("");var e1=1e4,W6=oe("webrtc-direct").code,C0=oe("certhash").code,Li=class{log;metrics;components;init;constructor(e,t={}){this.log=e.logger.forComponent("libp2p:webrtc-direct"),this.components=e,this.init=t,e.metrics!=null&&(this.metrics={dialerEvents:e.metrics.registerCounterGroup("libp2p_webrtc-direct_dialer_events_total",{label:"event",help:"Total count of WebRTC-direct dial events by type"})})}[Co]=!0;[Symbol.toStringTag]="@libp2p/webrtc-direct";[Vr]=["@libp2p/transport"];async dial(e,t){let n=await this._connect(e,t);return this.log("dialing address: %a",e),n}createListener(e){throw Xl("WebRTCTransport.createListener")}listenFilter(e){return e.filter(jl.exactMatch)}dialFilter(e){return this.listenFilter(e)}async _connect(e,t){let n=new AbortController,o=n.signal,s=e.getPeerId();if(s===null)throw qo("we need to have the remote's PeerId");let i=br(s),a=zu(Ni(e)),c=await Sr.generateCertificate({name:"ECDSA",namedCurve:"P-256",hash:Gu(a.name)}),u=new Sr({...await Kn(this.init.rtcConfiguration),certificates:[c]});try{let l=new Promise((D,_)=>{let O=u.createDataChannel("",{negotiated:!0,id:0}),R=setTimeout(()=>{let H=`Data channel was never opened: state: ${O.readyState}`;this.log.error(H),this.metrics?.dialerEvents.increment({open_error:!0}),_(qa("data",H))},e1);O.onopen=H=>{clearTimeout(R),D(O)},O.onerror=H=>{clearTimeout(R);let G=`Error opening a data channel for handshaking: ${H.target?.toString()??"not specified"}`;this.log.error(G),this.metrics?.dialerEvents.increment({unknown_error:!0}),_(qa("data",G))}}),f="libp2p+webrtc+v1/"+T0(32),m=await u.createOffer(),g=k0(m,f);await u.setLocalDescription(g);let p=B0(e,f);await u.setRemoteDescription(p);let h=await l,d=this.components.peerId,y=this.generateNoisePrologue(u,a.code,e),x=tp({prologueBytes:y})(this.components),b=en({channel:h,direction:"inbound",logger:this.components.logger,...this.init.dataChannel??{}}),A={...b,sink:b.sink.bind(b),source:async function*(){for await(let D of b.source)for(let _ of D)yield _}()},E=new wr(this.components,{peerConnection:u,remoteAddr:e,timeline:{open:Date.now()},metrics:this.metrics?.dialerEvents}),v=Hn?"iceconnectionstatechange":"connectionstatechange";u.addEventListener(v,()=>{switch(u.connectionState){case"failed":case"disconnected":case"closed":E.close().catch(D=>{this.log.error("error closing connection",D)}).finally(()=>{n.abort()});break;default:break}},{signal:o}),this.metrics?.dialerEvents.increment({peer_connection:!0});let S=new Jt(this.components,{peerConnection:u,metrics:this.metrics?.dialerEvents,dataChannelOptions:this.init.dataChannel});return await x.secureInbound(d,A,i),await t.upgrader.upgradeOutbound(E,{skipProtection:!0,skipEncryption:!0,muxerFactory:S})}catch(l){throw u.close(),l}}generateNoisePrologue(e,t,n){if(e.getConfiguration().certificates?.length===0)throw Vn("no local certificate");let o=S0(e,{log:this.log});if(o==null)throw Vn("no local fingerprint found");let s=o.trim().toLowerCase().replaceAll(":",""),i=J(s,"hex"),a=_0.encode(i,t),c=Wu.decode(Ni(n)),u=J("libp2p-webrtc-noise:");return xe([u,a,c])}};function t1(r){return e=>new Li(e,r)}function r1(r){return e=>new ds(e,r)}return ko(n1);})();
41
41
  /*! Bundled license information:
42
42
 
43
43
  pvtsutils/build/index.js: