UNPKG

@liascript/exporter

Version:
1 lines โ€ข 954 kB
!function(){var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{};function t(e,t,n,r){Object.defineProperty(e,t,{get:n,set:r,enumerable:!0,configurable:!0})}var n=e.parcelRequire55a5;n.register("eB8Zt",(function(r,i){t(r.exports,"selfId",(function(){return xx}),(function(e){return xx=e})),t(r.exports,"joinRoom",(function(){return sC}),(function(e){return sC=e}));var a,o,u,s,l,c,f,d,h,v,p,g,y,m,b,w,k,_,E,S,A,I,x,C,T,P,R,L,D,M,N,O,U,F,B,q=n("f1evb"),z=n("1PH9R"),j=n("3u2tY"),K=n("hnmIs"),V=n("9yQwa"),H=n("9Klpk"),W=n("8qpTe"),G=n("gwSkA"),X=n("7ukXT"),Y=n("8TzS1"),Z=n("aFAb1"),Q=n("kw2NY"),J=n("fWXUu"),$=n("3bWnf"),ee=n("W5eu1"),te=n("eT7f3"),ne=n("9WzNc"),re=n("div3d"),ie=n("kb0qF"),ae=n("bgoEC"),oe=n("7j4mF"),ue=n("1Qswt"),se=n("5ENmm"),le=n("iPOEm"),ce=n("6Wo7Q"),fe=n("rJmE6"),de=n("hXL9f"),he=n("fSF4h"),ve=n("bWNdT"),pe=n("32Euv"),ge=(pe=n("32Euv"),n("84cK9"));function ye(){return new Uint8Array(arguments.length>0&&void 0!==arguments[0]?arguments[0]:0)}function me(){return new Uint8Array(arguments.length>0&&void 0!==arguments[0]?arguments[0]:0)}var be=268435456,we=34359738368,ke=4398046511104,_e=Math.pow(2,49),Ee=128,Se=127;function Ae(e){if(e<128)return 1;if(e<16384)return 2;if(e<2097152)return 3;if(e<be)return 4;if(e<we)return 5;if(e<ke)return 6;if(e<_e)return 7;if(null!=Number.MAX_SAFE_INTEGER&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ie(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;switch(Ae(e)){case 8:t[n++]=255&e|Ee,e/=128;case 7:t[n++]=255&e|Ee,e/=128;case 6:t[n++]=255&e|Ee,e/=128;case 5:t[n++]=255&e|Ee,e/=128;case 4:t[n++]=255&e|Ee,e>>>=7;case 3:t[n++]=255&e|Ee,e>>>=7;case 2:t[n++]=255&e|Ee,e>>>=7;case 1:t[n++]=255&e,e>>>=7;break;default:throw Error("unreachable")}return t}function xe(e,t){var n=e[t],r=0;if(r+=n&Se,n<Ee)return r;if(r+=((n=e[t+1])&Se)<<7,n<Ee)return r;if(r+=((n=e[t+2])&Se)<<14,n<Ee)return r;if(r+=((n=e[t+3])&Se)<<21,n<Ee)return r;if(r+=((n=e[t+4])&Se)*be,n<Ee)return r;if(r+=((n=e[t+5])&Se)*we,n<Ee)return r;if(r+=((n=e[t+6])&Se)*ke,n<Ee)return r;if(r+=((n=e[t+7])&Se)*_e,n<Ee)return r;throw new RangeError("Could not decode varint")}function Ce(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;return null==t&&(t=me(Ae(e))),t instanceof Uint8Array?Ie(e,t,n):function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;switch(Ae(e)){case 8:t.set(n++,255&e|Ee),e/=128;case 7:t.set(n++,255&e|Ee),e/=128;case 6:t.set(n++,255&e|Ee),e/=128;case 5:t.set(n++,255&e|Ee),e/=128;case 4:t.set(n++,255&e|Ee),e>>>=7;case 3:t.set(n++,255&e|Ee),e>>>=7;case 2:t.set(n++,255&e|Ee),e>>>=7;case 1:t.set(n++,255&e),e>>>=7;break;default:throw Error("unreachable")}return t}(e,t,n)}function Te(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return e instanceof Uint8Array?xe(e,t):function(e,t){var n=e.get(t),r=0;if(r+=n&Se,n<Ee)return r;if(r+=((n=e.get(t+1))&Se)<<7,n<Ee)return r;if(r+=((n=e.get(t+2))&Se)<<14,n<Ee)return r;if(r+=((n=e.get(t+3))&Se)<<21,n<Ee)return r;if(r+=((n=e.get(t+4))&Se)*be,n<Ee)return r;if(r+=((n=e.get(t+5))&Se)*we,n<Ee)return r;if(r+=((n=e.get(t+6))&Se)*ke,n<Ee)return r;if(r+=((n=e.get(t+7))&Se)*_e,n<Ee)return r;throw new RangeError("Could not decode varint")}(e,t)}var Pe=new Float32Array([-0]),Re=new Uint8Array(Pe.buffer);function Le(e,t,n){Pe[0]=e,t[n]=Re[0],t[n+1]=Re[1],t[n+2]=Re[2],t[n+3]=Re[3]}var De=new Float64Array([-0]),Me=new Uint8Array(De.buffer);function Ne(e,t,n){De[0]=e,t[n]=Me[0],t[n+1]=Me[1],t[n+2]=Me[2],t[n+3]=Me[3],t[n+4]=Me[4],t[n+5]=Me[5],t[n+6]=Me[6],t[n+7]=Me[7]}var Oe=BigInt(Number.MAX_SAFE_INTEGER),Ue=BigInt(Number.MIN_SAFE_INTEGER),Fe=function(){"use strict";function e(t,n){(0,H.default)(this,e),(0,te.default)(this,"lo",void 0),(0,te.default)(this,"hi",void 0),this.lo=0|t,this.hi=0|n}return(0,$.default)(e,[{key:"toNumber",value:function(){if(!(arguments.length>0&&void 0!==arguments[0]&&arguments[0])&&this.hi>>>31>0){var e=1+~this.lo>>>0,t=~this.hi>>>0;return 0===e&&(t=t+1>>>0),-(e+4294967296*t)}return this.lo+4294967296*this.hi}},{key:"toBigInt",value:function(){if(arguments.length>0&&void 0!==arguments[0]&&arguments[0])return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31!=0){var e=1+~this.lo>>>0,t=~this.hi>>>0;return 0===e&&(t=t+1>>>0),-(BigInt(e)+(BigInt(t)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}},{key:"toString",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return this.toBigInt(e).toString()}},{key:"zzEncode",value:function(){var e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}},{key:"zzDecode",value:function(){var e=-(1&this.lo);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}},{key:"length",value:function(){var e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return 0===n?0===t?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:n<128?9:10}}],[{key:"fromBigInt",value:function(t){if(0n===t)return Be;if(t<Oe&&t>Ue)return this.fromNumber(Number(t));var n=t<0n;n&&(t=-t);var r=t>>32n,i=t-(r<<32n);return n&&(r=0n|~r,i=0n|~i,++i>qe&&(i=0n,++r>qe&&(r=0n))),new e(Number(i),Number(r))}},{key:"fromNumber",value:function(t){if(0===t)return Be;var n=t<0;n&&(t=-t);var r=t>>>0,i=(t-r)/4294967296>>>0;return n&&(i=~i>>>0,r=~r>>>0,++r>4294967295&&(r=0,++i>4294967295&&(i=0))),new e(r,i)}},{key:"from",value:function(t){return"number"==typeof t?e.fromNumber(t):"bigint"==(void 0===t?"undefined":(0,fe.default)(t))?e.fromBigInt(t):"string"==typeof t?e.fromBigInt(BigInt(t)):null!=t.low||null!=t.high?new e(t.low>>>0,t.high>>>0):Be}}]),e}(),Be=new Fe(0,0);Be.toBigInt=function(){return 0n},Be.zzEncode=Be.zzDecode=function(){return this},Be.length=function(){return 1};var qe=4294967296n;function ze(e,t,n){for(var r,i,a=n,o=0;o<e.length;++o)(r=e.charCodeAt(o))<128?t[n++]=r:r<2048?(t[n++]=r>>6|192,t[n++]=63&r|128):55296==(64512&r)&&56320==(64512&(i=e.charCodeAt(o+1)))?(r=65536+((1023&r)<<10)+(1023&i),++o,t[n++]=r>>18|240,t[n++]=r>>12&63|128,t[n++]=r>>6&63|128,t[n++]=63&r|128):(t[n++]=r>>12|224,t[n++]=r>>6&63|128,t[n++]=63&r|128);return n-a}function je(e,t){return RangeError("index out of range: ".concat(e.pos," + ").concat(null!=t?t:1," > ").concat(e.len))}function Ke(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var Ve=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"buf",void 0),(0,te.default)(this,"pos",void 0),(0,te.default)(this,"len",void 0),(0,te.default)(this,"_slice",Uint8Array.prototype.subarray),this.buf=t,this.pos=0,this.len=t.length}return(0,$.default)(e,[{key:"uint32",value:function(){var e=4294967295;if(e=(127&this.buf[this.pos])>>>0,this.buf[this.pos++]<128)return e;if(e=(e|(127&this.buf[this.pos])<<7)>>>0,this.buf[this.pos++]<128)return e;if(e=(e|(127&this.buf[this.pos])<<14)>>>0,this.buf[this.pos++]<128)return e;if(e=(e|(127&this.buf[this.pos])<<21)>>>0,this.buf[this.pos++]<128)return e;if(e=(e|(15&this.buf[this.pos])<<28)>>>0,this.buf[this.pos++]<128)return e;if((this.pos+=5)>this.len)throw this.pos=this.len,je(this,10);return e}},{key:"int32",value:function(){return 0|this.uint32()}},{key:"sint32",value:function(){var e=this.uint32();return e>>>1^-(1&e)}},{key:"bool",value:function(){return 0!==this.uint32()}},{key:"fixed32",value:function(){if(this.pos+4>this.len)throw je(this,4);return Ke(this.buf,this.pos+=4)}},{key:"sfixed32",value:function(){if(this.pos+4>this.len)throw je(this,4);return 0|Ke(this.buf,this.pos+=4)}},{key:"float",value:function(){if(this.pos+4>this.len)throw je(this,4);var e,t,n=(e=this.buf,t=this.pos,Re[0]=e[t],Re[1]=e[t+1],Re[2]=e[t+2],Re[3]=e[t+3],Pe[0]);return this.pos+=4,n}},{key:"double",value:function(){if(this.pos+8>this.len)throw je(this,4);var e,t,n=(e=this.buf,t=this.pos,Me[0]=e[t],Me[1]=e[t+1],Me[2]=e[t+2],Me[3]=e[t+3],Me[4]=e[t+4],Me[5]=e[t+5],Me[6]=e[t+6],Me[7]=e[t+7],De[0]);return this.pos+=8,n}},{key:"bytes",value:function(){var e=this.uint32(),t=this.pos,n=this.pos+e;if(n>this.len)throw je(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}},{key:"string",value:function(){var e=this.bytes();return function(e,t,n){if(n-t<1)return"";for(var r,i,a=[],o=0;t<n;)(i=e[t++])<128?a[o++]=i:i>191&&i<224?a[o++]=(31&i)<<6|63&e[t++]:i>239&&i<365?(i=((7&i)<<18|(63&e[t++])<<12|(63&e[t++])<<6|63&e[t++])-65536,a[o++]=55296+(i>>10),a[o++]=56320+(1023&i)):a[o++]=(15&i)<<12|(63&e[t++])<<6|63&e[t++],o>8191&&((null!=r?r:r=[]).push(String.fromCharCode.apply(String,a)),o=0);return null!=r?(o>0&&r.push(String.fromCharCode.apply(String,a.slice(0,o))),r.join("")):String.fromCharCode.apply(String,a.slice(0,o))}(e,0,e.length)}},{key:"skip",value:function(e){if("number"==typeof e){if(this.pos+e>this.len)throw je(this,e);this.pos+=e}else do{if(this.pos>=this.len)throw je(this)}while(128&this.buf[this.pos++]);return this}},{key:"skipType",value:function(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;4!=(e=7&this.uint32());)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error("invalid wire type ".concat(e," at offset ").concat(this.pos))}return this}},{key:"readLongVarint",value:function(){var e=new Fe(0,0),t=0;if(!(this.len-this.pos>4)){for(;t<3;++t){if(this.pos>=this.len)throw je(this);if(e.lo=(e.lo|(127&this.buf[this.pos])<<7*t)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(127&this.buf[this.pos++])<<7*t)>>>0,e}for(;t<4;++t)if(e.lo=(e.lo|(127&this.buf[this.pos])<<7*t)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(127&this.buf[this.pos])<<28)>>>0,e.hi=(e.hi|(127&this.buf[this.pos])>>4)>>>0,this.buf[this.pos++]<128)return e;if(t=0,this.len-this.pos>4){for(;t<5;++t)if(e.hi=(e.hi|(127&this.buf[this.pos])<<7*t+3)>>>0,this.buf[this.pos++]<128)return e}else for(;t<5;++t){if(this.pos>=this.len)throw je(this);if(e.hi=(e.hi|(127&this.buf[this.pos])<<7*t+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}},{key:"readFixed64",value:function(){if(this.pos+8>this.len)throw je(this,8);var e=Ke(this.buf,this.pos+=4),t=Ke(this.buf,this.pos+=4);return new Fe(e,t)}},{key:"int64",value:function(){return this.readLongVarint().toBigInt()}},{key:"int64Number",value:function(){return this.readLongVarint().toNumber()}},{key:"int64String",value:function(){return this.readLongVarint().toString()}},{key:"uint64",value:function(){return this.readLongVarint().toBigInt(!0)}},{key:"uint64Number",value:function(){var e=xe(this.buf,this.pos);return this.pos+=Ae(e),e}},{key:"uint64String",value:function(){return this.readLongVarint().toString(!0)}},{key:"sint64",value:function(){return this.readLongVarint().zzDecode().toBigInt()}},{key:"sint64Number",value:function(){return this.readLongVarint().zzDecode().toNumber()}},{key:"sint64String",value:function(){return this.readLongVarint().zzDecode().toString()}},{key:"fixed64",value:function(){return this.readFixed64().toBigInt()}},{key:"fixed64Number",value:function(){return this.readFixed64().toNumber()}},{key:"fixed64String",value:function(){return this.readFixed64().toString()}},{key:"sfixed64",value:function(){return this.readFixed64().toBigInt()}},{key:"sfixed64Number",value:function(){return this.readFixed64().toNumber()}},{key:"sfixed64String",value:function(){return this.readFixed64().toString()}}]),e}();function He(e,t,n){var r=function(e){return new Ve(e instanceof Uint8Array?e:e.subarray())}(e);return t.decode(r,void 0,n)}function We(e){if(e instanceof Uint8Array&&"Uint8Array"===e.constructor.name)return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw Error("Unknown type, must be binary type")}var Ge=function(e,t){var n=function(e){if("string"!=typeof e)throw new TypeError("Expected String");if(0===e.length)return new Uint8Array;var t=0;if(" "!==e[t]){for(var n=0,i=0;e[t]===l;)n++,t++;for(var a=(e.length-t)*c+1>>>0,o=new Uint8Array(a);e[t];){var u=r[e.charCodeAt(t)];if(255===u)return;for(var f=0,d=a-1;(0!==u||f<i)&&-1!==d;d--,f++)u+=s*o[d]>>>0,o[d]=u%256>>>0,u=u/256>>>0;if(0!==u)throw Error("Non-zero carry");i=f,t++}if(" "!==e[t]){for(var h=a-i;h!==a&&0===o[h];)h++;for(var v=new Uint8Array(n+(a-h)),p=n;h!==a;)v[p++]=o[h++];return v}}};if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),i=0;i<r.length;i++)r[i]=255;for(var a=0;a<e.length;a++){var o=e.charAt(a),u=o.charCodeAt(0);if(255!==r[u])throw new TypeError(o+" is ambiguous");r[u]=a}var s=e.length,l=e.charAt(0),c=Math.log(s)/Math.log(256),f=Math.log(256)/Math.log(s);return{encode:function(t){if(t instanceof Uint8Array||(ArrayBuffer.isView(t)?t=new Uint8Array(t.buffer,t.byteOffset,t.byteLength):Array.isArray(t)&&(t=Uint8Array.from(t))),!(t instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===t.length)return"";for(var n=0,r=0,i=0,a=t.length;i!==a&&0===t[i];)i++,n++;for(var o=(a-i)*f+1>>>0,u=new Uint8Array(o);i!==a;){for(var c=t[i],d=0,h=o-1;(0!==c||d<r)&&-1!==h;h--,d++)c+=256*u[h]>>>0,u[h]=c%s>>>0,c=c/s>>>0;if(0!==c)throw Error("Non-zero carry");r=d,i++}for(var v=o-r;v!==o&&0===u[v];)v++;for(var p=l.repeat(n);v<o;++v)p+=e.charAt(u[v]);return p},decodeUnsafe:n,decode:function(e){var r=n(e);if(r)return r;throw Error("Non-".concat(t," character"))}}},Xe=function(){"use strict";function e(t,n,r){(0,H.default)(this,e),(0,te.default)(this,"name",void 0),(0,te.default)(this,"prefix",void 0),(0,te.default)(this,"baseEncode",void 0),this.name=t,this.prefix=n,this.baseEncode=r}return(0,$.default)(e,[{key:"encode",value:function(e){if(e instanceof Uint8Array)return"".concat(this.prefix).concat(this.baseEncode(e));throw Error("Unknown type, must be binary type")}}]),e}(),Ye=function(){"use strict";function e(t,n,r){(0,H.default)(this,e),(0,te.default)(this,"name",void 0),(0,te.default)(this,"prefix",void 0),(0,te.default)(this,"baseDecode",void 0),(0,te.default)(this,"prefixCodePoint",void 0),this.name=t,this.prefix=n;var i=n.codePointAt(0);if(void 0===i)throw Error("Invalid prefix character");this.prefixCodePoint=i,this.baseDecode=r}return(0,$.default)(e,[{key:"decode",value:function(e){if("string"==typeof e){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error("Unable to decode multibase string ".concat(JSON.stringify(e),", ").concat(this.name," decoder only supports inputs prefixed with ").concat(this.prefix));return this.baseDecode(e.slice(this.prefix.length))}throw Error("Can only multibase decode strings")}},{key:"or",value:function(e){return Qe(this,e)}}]),e}(),Ze=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"decoders",void 0),this.decoders=t}return(0,$.default)(e,[{key:"or",value:function(e){return Qe(this,e)}},{key:"decode",value:function(e){var t=e[0],n=this.decoders[t];if(null!=n)return n.decode(e);throw RangeError("Unable to decode multibase string ".concat(JSON.stringify(e),", only inputs prefixed with ").concat(Object.keys(this.decoders)," are supported"))}}]),e}();function Qe(e,t){var n,r;return new Ze((0,ae.default)({},null!==(n=e.decoders)&&void 0!==n?n:(0,te.default)({},e.prefix,e),null!==(r=t.decoders)&&void 0!==r?r:(0,te.default)({},t.prefix,t)))}var Je=function(){"use strict";function e(t,n,r,i){(0,H.default)(this,e),(0,te.default)(this,"name",void 0),(0,te.default)(this,"prefix",void 0),(0,te.default)(this,"baseEncode",void 0),(0,te.default)(this,"baseDecode",void 0),(0,te.default)(this,"encoder",void 0),(0,te.default)(this,"decoder",void 0),this.name=t,this.prefix=n,this.baseEncode=r,this.baseDecode=i,this.encoder=new Xe(t,n,r),this.decoder=new Ye(t,n,i)}return(0,$.default)(e,[{key:"encode",value:function(e){return this.encoder.encode(e)}},{key:"decode",value:function(e){return this.decoder.decode(e)}}]),e}();function $e(e){var t=e.name,n=e.prefix,r=e.encode,i=e.decode;return new Je(t,n,r,i)}function et(e){var t=e.name,n=e.prefix,r=e.alphabet,i=Ge(r,t),a=i.encode,o=i.decode;return $e({prefix:n,name:t,encode:a,decode:function(e){return We(o(e))}})}function tt(e){var t=e.name,n=e.prefix,r=e.bitsPerChar,i=e.alphabet,a=function(e){for(var t={},n=0;n<e.length;++n)t[e[n]]=n;return t}(i);return $e({prefix:n,name:t,encode:function(e){return function(e,t,n){for(var r="="===t[t.length-1],i=(1<<n)-1,a="",o=0,u=0,s=0;s<e.length;++s)for(u=u<<8|e[s],o+=8;o>n;)a+=t[i&u>>(o-=n)];if(0!==o&&(a+=t[i&u<<n-o]),r)for(;a.length*n&7;)a+="=";return a}(e,i,r)},decode:function(e){return function(e,t,n,r){for(var i=e.length;"="===e[i-1];)--i;for(var a=new Uint8Array(i*n/8|0),o=0,u=0,s=0,l=0;l<i;++l){var c=t[e[l]];if(void 0===c)throw new SyntaxError("Non-".concat(r," character"));u=u<<n|c,(o+=n)>=8&&(o-=8,a[s++]=255&u>>o)}if(o>=n||255&u<<8-o)throw new SyntaxError("Unexpected end of data");return a}(e,a,r,t)}})}var nt=et({prefix:"9",name:"base10",alphabet:"0123456789"}),rt=Object.freeze({__proto__:null,base10:nt}),it=tt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),at=tt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4}),ot=Object.freeze({__proto__:null,base16:it,base16upper:at}),ut=tt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1}),st=Object.freeze({__proto__:null,base2:ut}),lt=Array.from("๐Ÿš€๐Ÿชโ˜„๐Ÿ›ฐ๐ŸŒŒ๐ŸŒ‘๐ŸŒ’๐ŸŒ“๐ŸŒ”๐ŸŒ•๐ŸŒ–๐ŸŒ—๐ŸŒ˜๐ŸŒ๐ŸŒ๐ŸŒŽ๐Ÿ‰โ˜€๐Ÿ’ป๐Ÿ–ฅ๐Ÿ’พ๐Ÿ’ฟ๐Ÿ˜‚โค๐Ÿ˜๐Ÿคฃ๐Ÿ˜Š๐Ÿ™๐Ÿ’•๐Ÿ˜ญ๐Ÿ˜˜๐Ÿ‘๐Ÿ˜…๐Ÿ‘๐Ÿ˜๐Ÿ”ฅ๐Ÿฅฐ๐Ÿ’”๐Ÿ’–๐Ÿ’™๐Ÿ˜ข๐Ÿค”๐Ÿ˜†๐Ÿ™„๐Ÿ’ช๐Ÿ˜‰โ˜บ๐Ÿ‘Œ๐Ÿค—๐Ÿ’œ๐Ÿ˜”๐Ÿ˜Ž๐Ÿ˜‡๐ŸŒน๐Ÿคฆ๐ŸŽ‰๐Ÿ’žโœŒโœจ๐Ÿคท๐Ÿ˜ฑ๐Ÿ˜Œ๐ŸŒธ๐Ÿ™Œ๐Ÿ˜‹๐Ÿ’—๐Ÿ’š๐Ÿ˜๐Ÿ’›๐Ÿ™‚๐Ÿ’“๐Ÿคฉ๐Ÿ˜„๐Ÿ˜€๐Ÿ–ค๐Ÿ˜ƒ๐Ÿ’ฏ๐Ÿ™ˆ๐Ÿ‘‡๐ŸŽถ๐Ÿ˜’๐Ÿคญโฃ๐Ÿ˜œ๐Ÿ’‹๐Ÿ‘€๐Ÿ˜ช๐Ÿ˜‘๐Ÿ’ฅ๐Ÿ™‹๐Ÿ˜ž๐Ÿ˜ฉ๐Ÿ˜ก๐Ÿคช๐Ÿ‘Š๐Ÿฅณ๐Ÿ˜ฅ๐Ÿคค๐Ÿ‘‰๐Ÿ’ƒ๐Ÿ˜ณโœ‹๐Ÿ˜š๐Ÿ˜๐Ÿ˜ด๐ŸŒŸ๐Ÿ˜ฌ๐Ÿ™ƒ๐Ÿ€๐ŸŒท๐Ÿ˜ป๐Ÿ˜“โญโœ…๐Ÿฅบ๐ŸŒˆ๐Ÿ˜ˆ๐Ÿค˜๐Ÿ’ฆโœ”๐Ÿ˜ฃ๐Ÿƒ๐Ÿ’โ˜น๐ŸŽŠ๐Ÿ’˜๐Ÿ˜ โ˜๐Ÿ˜•๐ŸŒบ๐ŸŽ‚๐ŸŒป๐Ÿ˜๐Ÿ–•๐Ÿ’๐Ÿ™Š๐Ÿ˜น๐Ÿ—ฃ๐Ÿ’ซ๐Ÿ’€๐Ÿ‘‘๐ŸŽต๐Ÿคž๐Ÿ˜›๐Ÿ”ด๐Ÿ˜ค๐ŸŒผ๐Ÿ˜ซโšฝ๐Ÿค™โ˜•๐Ÿ†๐Ÿคซ๐Ÿ‘ˆ๐Ÿ˜ฎ๐Ÿ™†๐Ÿป๐Ÿƒ๐Ÿถ๐Ÿ’๐Ÿ˜ฒ๐ŸŒฟ๐Ÿงก๐ŸŽโšก๐ŸŒž๐ŸŽˆโŒโœŠ๐Ÿ‘‹๐Ÿ˜ฐ๐Ÿคจ๐Ÿ˜ถ๐Ÿค๐Ÿšถ๐Ÿ’ฐ๐Ÿ“๐Ÿ’ข๐ŸคŸ๐Ÿ™๐Ÿšจ๐Ÿ’จ๐Ÿคฌโœˆ๐ŸŽ€๐Ÿบ๐Ÿค“๐Ÿ˜™๐Ÿ’Ÿ๐ŸŒฑ๐Ÿ˜–๐Ÿ‘ถ๐Ÿฅดโ–ถโžกโ“๐Ÿ’Ž๐Ÿ’ธโฌ‡๐Ÿ˜จ๐ŸŒš๐Ÿฆ‹๐Ÿ˜ท๐Ÿ•บโš ๐Ÿ™…๐Ÿ˜Ÿ๐Ÿ˜ต๐Ÿ‘Ž๐Ÿคฒ๐Ÿค ๐Ÿคง๐Ÿ“Œ๐Ÿ”ต๐Ÿ’…๐Ÿง๐Ÿพ๐Ÿ’๐Ÿ˜—๐Ÿค‘๐ŸŒŠ๐Ÿคฏ๐Ÿทโ˜Ž๐Ÿ’ง๐Ÿ˜ฏ๐Ÿ’†๐Ÿ‘†๐ŸŽค๐Ÿ™‡๐Ÿ‘โ„๐ŸŒด๐Ÿ’ฃ๐Ÿธ๐Ÿ’Œ๐Ÿ“๐Ÿฅ€๐Ÿคข๐Ÿ‘…๐Ÿ’ก๐Ÿ’ฉ๐Ÿ‘๐Ÿ“ธ๐Ÿ‘ป๐Ÿค๐Ÿคฎ๐ŸŽผ๐Ÿฅต๐Ÿšฉ๐ŸŽ๐ŸŠ๐Ÿ‘ผ๐Ÿ’๐Ÿ“ฃ๐Ÿฅ‚"),ct=lt.reduce((function(e,t,n){return e[n]=t,e}),[]),ft=lt.reduce((function(e,t,n){var r=t.codePointAt(0);if(null==r)throw Error("Invalid character: "+t);return e[r]=n,e}),[]),dt=$e({prefix:"๐Ÿš€",name:"base256emoji",encode:function(e){return e.reduce((function(e,t){return e+ct[t]}),"")},decode:function(e){var t=[],n=!0,r=!1,i=void 0;try{for(var a,o=e[Symbol.iterator]();!(n=(a=o.next()).done);n=!0){var u=a.value,s=u.codePointAt(0);if(null==s)throw Error("Invalid character: "+u);var l=ft[s];if(null==l)throw Error("Non-base256emoji character: "+u);t.push(l)}}catch(e){r=!0,i=e}finally{try{n||null==o.return||o.return()}finally{if(r)throw i}}return new Uint8Array(t)}}),ht=Object.freeze({__proto__:null,base256emoji:dt}),vt=tt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),pt=tt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),gt=tt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),yt=tt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),mt=tt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),bt=tt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),wt=tt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),kt=tt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),_t=tt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5}),Et=Object.freeze({__proto__:null,base32:vt,base32hex:mt,base32hexpad:wt,base32hexpadupper:kt,base32hexupper:bt,base32pad:gt,base32padupper:yt,base32upper:pt,base32z:_t}),St=et({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),At=et({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"}),It=Object.freeze({__proto__:null,base36:St,base36upper:At}),xt=et({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ct=et({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"}),Tt=Object.freeze({__proto__:null,base58btc:xt,base58flickr:Ct}),Pt=tt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Rt=tt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Lt=tt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Dt=tt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6}),Mt=Object.freeze({__proto__:null,base64:Pt,base64pad:Rt,base64url:Lt,base64urlpad:Dt}),Nt=tt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3}),Ot=Object.freeze({__proto__:null,base8:Nt}),Ut=$e({prefix:"\0",name:"identity",encode:function(e){var t;return t=e,(new TextDecoder).decode(t)},decode:function(e){return function(e){return(new TextEncoder).encode(e)}(e)}}),Ft=Object.freeze({__proto__:null,identity:Ut});new TextEncoder,new TextDecoder;var Bt=128,qt=-128,zt=2147483648,jt=128,Kt=127,Vt=Math.pow(2,63),Ht={encode:function e(t,n,r){n=n||[];for(var i=r=r||0;t>=zt;)n[r++]=255&t|Bt,t/=128;for(;t&qt;)n[r++]=255&t|Bt,t>>>=7;return n[r]=0|t,e.bytes=r-i+1,n},decode:function e(t,n){var r,i=0,a=0,o=n=n||0,u=t.length;do{if(o>=u)throw e.bytes=0,new RangeError("Could not decode varint");r=t[o++],i+=a<28?(r&Kt)<<a:(r&Kt)*Math.pow(2,a),a+=7}while(r>=jt);return e.bytes=o-n,i},encodingLength:function(e){return e<128?1:e<16384?2:e<2097152?3:e<268435456?4:e<34359738368?5:e<4398046511104?6:e<562949953421312?7:e<72057594037927940?8:e<Vt?9:10}};function Wt(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return[Ht.decode(e,t),Ht.decode.bytes]}function Gt(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;return Ht.encode(e,t,n),t}function Xt(e){return Ht.encodingLength(e)}function Yt(e,t){var n=t.byteLength,r=Xt(e),i=r+Xt(n),a=new Uint8Array(i+n);return Gt(e,a,0),Gt(n,a,r),a.set(t,i),new $t(e,n,t,a)}function Zt(e){var t=We(e),n=(0,se.default)(Wt(t),2),r=n[0],i=n[1],a=(0,se.default)(Wt(t.subarray(i)),2),o=a[0],u=a[1],s=t.subarray(i+u);if(s.byteLength!==o)throw Error("Incorrect length");return new $t(r,o,s,t)}var Qt,Jt,$t=function e(t,n,r,i){"use strict";(0,H.default)(this,e),(0,te.default)(this,"code",void 0),(0,te.default)(this,"size",void 0),(0,te.default)(this,"digest",void 0),(0,te.default)(this,"bytes",void 0),this.code=t,this.size=n,this.digest=r,this.bytes=i},en=We,tn={code:0,name:"identity",encode:en,digest:function(e){return Yt(0,en(e))}},nn=function(){"use strict";function e(t,n,r){(0,H.default)(this,e),(0,te.default)(this,"name",void 0),(0,te.default)(this,"code",void 0),(0,te.default)(this,"encode",void 0),this.name=t,this.code=n,this.encode=r}return(0,$.default)(e,[{key:"digest",value:function(e){var t=this;if(e instanceof Uint8Array){var n=this.encode(e);return n instanceof Uint8Array?Yt(this.code,n):n.then((function(e){return Yt(t.code,e)}))}throw Error("Unknown type, must be binary type")}}]),e}(),rn=(Qt={name:"sha2-256",code:18,encode:(Jt=(0,K.default)((function(e){var t;return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:return t=Uint8Array.bind,[4,crypto.subtle.digest("SHA-256",e)];case 1:return[2,new(t.apply(Uint8Array,[void 0,n.sent()]))]}}))})),function(e){return Jt.apply(this,arguments)})},new nn(Qt.name,Qt.code,Qt.encode));function an(e,t){var n=e.bytes;return 0===e.version?function(e,t,n){var r=n.prefix;if(r!==xt.prefix)throw Error("Cannot string encode V0 in ".concat(n.name," encoding"));var i=t.get(r);if(null==i){var a=n.encode(e).slice(1);return t.set(r,a),a}return i}(n,un(e),null!=t?t:xt.encoder):function(e,t,n){var r=n.prefix,i=t.get(r);if(null==i){var a=n.encode(e);return t.set(r,a),a}return i}(n,un(e),null!=t?t:vt.encoder)}var on=new WeakMap;function un(e){var t=on.get(e);if(null==t){var n=new Map;return on.set(e,n),n}return t}var sn=Symbol.toStringTag,ln=Symbol.for("nodejs.util.inspect.custom"),cn=function(){"use strict";function e(t,n,r,i){(0,H.default)(this,e),(0,te.default)(this,"code",void 0),(0,te.default)(this,"version",void 0),(0,te.default)(this,"multihash",void 0),(0,te.default)(this,"bytes",void 0),(0,te.default)(this,"/",void 0),(0,te.default)(this,sn,"CID"),this.code=n,this.version=t,this.multihash=r,this.bytes=i,this["/"]=i}return(0,$.default)(e,[{key:"asCID",get:function(){return this}},{key:"byteOffset",get:function(){return this.bytes.byteOffset}},{key:"byteLength",get:function(){return this.bytes.byteLength}},{key:"toV0",value:function(){switch(this.version){case 0:return this;case 1:var t=this.code,n=this.multihash;if(t!==fn)throw Error("Cannot convert a non dag-pb CID to CIDv0");if(n.code!==dn)throw Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(n);default:throw Error("Can not convert CID version ".concat(this.version," to version 0. This is a bug please report"))}}},{key:"toV1",value:function(){switch(this.version){case 0:var t=this.multihash,n=Yt(t.code,t.digest);return e.createV1(this.code,n);case 1:return this;default:throw Error("Can not convert CID version ".concat(this.version," to version 1. This is a bug please report"))}}},{key:"equals",value:function(t){return e.equals(this,t)}},{key:"toString",value:function(e){return an(this,e)}},{key:"toJSON",value:function(){return{"/":an(this)}}},{key:"link",value:function(){return this}},{key:ln,value:function(){return"CID(".concat(this.toString(),")")}}],[{key:"equals",value:function(e,t){var n=t;return null!=n&&e.code===n.code&&e.version===n.version&&function(e,t){if(e===t)return!0;var n=t;return e.code===n.code&&e.size===n.size&&n.bytes instanceof Uint8Array&&function(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(var n=0;n<e.byteLength;n++)if(e[n]!==t[n])return!1;return!0}(e.bytes,n.bytes)}(e.multihash,n.multihash)}},{key:"asCID",value:function(t){if(null==t)return null;var n=t;if(n instanceof e)return n;if(null!=n["/"]&&n["/"]===n.bytes||n.asCID===n){var r=n.version,i=n.code,a=n.multihash,o=n.bytes;return new e(r,i,a,null!=o?o:hn(r,i,a.bytes))}if(!0===n[vn]){var u=n.version,s=n.multihash,l=n.code,c=Zt(s);return e.create(u,l,c)}return null}},{key:"create",value:function(t,n,r){if("number"!=typeof n)throw Error("String codecs are no longer supported");if(!(r.bytes instanceof Uint8Array))throw Error("Invalid digest");switch(t){case 0:if(n!==fn)throw Error("Version 0 CID must use dag-pb (code: ".concat(fn,") block encoding"));return new e(t,n,r,r.bytes);case 1:return new e(t,n,r,hn(t,n,r.bytes));default:throw Error("Invalid version")}}},{key:"createV0",value:function(t){return e.create(0,fn,t)}},{key:"createV1",value:function(t,n){return e.create(1,t,n)}},{key:"decode",value:function(t){var n=(0,se.default)(e.decodeFirst(t),2),r=n[0];if(0!==n[1].length)throw Error("Incorrect length");return r}},{key:"decodeFirst",value:function(t){var n=e.inspectBytes(t),r=n.size-n.multihashSize,i=We(t.subarray(r,r+n.multihashSize));if(i.byteLength!==n.multihashSize)throw Error("Incorrect length");var a=i.subarray(n.multihashSize-n.digestSize),o=new $t(n.multihashCode,n.digestSize,a,i);return[0===n.version?e.createV0(o):e.createV1(n.codec,o),t.subarray(n.size)]}},{key:"inspectBytes",value:function(e){var t=0,n=function(){var n=(0,se.default)(Wt(e.subarray(t)),2),r=n[0],i=n[1];return t+=i,r},r=n(),i=fn;if(18===r?(r=0,t=0):i=n(),0!==r&&1!==r)throw new RangeError("Invalid CID version "+r);var a=t,o=n(),u=n(),s=t+u;return{version:r,codec:i,multihashCode:o,digestSize:u,multihashSize:s-a,size:s}}},{key:"parse",value:function(t,n){var r=(0,se.default)(function(e,t){switch(e[0]){case"Q":var n=null!=t?t:xt;return[xt.prefix,n.decode("".concat(xt.prefix).concat(e))];case xt.prefix:var r=null!=t?t:xt;return[xt.prefix,r.decode(e)];case vt.prefix:var i=null!=t?t:vt;return[vt.prefix,i.decode(e)];case St.prefix:var a=null!=t?t:St;return[St.prefix,a.decode(e)];default:if(null==t)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}(t,n),2),i=r[0],a=r[1],o=e.decode(a);if(0===o.version&&"Q"!==t[0])throw Error("Version 0 CID string must not include multibase prefix");return un(o).set(i,t),o}}]),e}(),fn=112,dn=18;function hn(e,t,n){var r=Xt(e),i=r+Xt(t),a=new Uint8Array(i+n.byteLength);return Gt(e,a,0),Gt(t,a,r),a.set(n,i),a}var vn=Symbol.for("@ipld/js-cid/CID"),pn=(0,ae.default)({},Ft,st,Ot,rt,ot,Et,It,Tt,Mt,ht);function gn(e,t,n,r){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:n},decoder:{decode:r}}}var yn=gn("utf8","u",(function(e){return"u"+new TextDecoder("utf8").decode(e)}),(function(e){return(new TextEncoder).encode(e.substring(1))})),mn=gn("ascii","a",(function(e){for(var t="a",n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);return t}),(function(e){for(var t=me((e=e.substring(1)).length),n=0;n<e.length;n++)t[n]=e.charCodeAt(n);return t})),bn=(0,ae.default)({utf8:yn,"utf-8":yn,hex:pn.base16,latin1:mn,ascii:mn,binary:mn},pn);function wn(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"utf8",n=bn[t];if(null==n)throw Error('Unsupported encoding "'.concat(t,'"'));return n.decoder.decode("".concat(n.prefix).concat(e))}var kn=function e(t,n,r){"use strict";(0,H.default)(this,e),(0,te.default)(this,"fn",void 0),(0,te.default)(this,"len",void 0),(0,te.default)(this,"next",void 0),(0,te.default)(this,"val",void 0),this.fn=t,this.len=n,this.next=void 0,this.val=r};function _n(){}var En,Sn,An,In=function e(t){"use strict";(0,H.default)(this,e),(0,te.default)(this,"head",void 0),(0,te.default)(this,"tail",void 0),(0,te.default)(this,"len",void 0),(0,te.default)(this,"next",void 0),this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states},xn=(An=Sn=8192,function(e){if(e<1||e>4096)return me(e);An+e>Sn&&(En=me(Sn),An=0);var t=En.subarray(An,An+=e);return 7&An&&(An=1+(7|An)),t}),Cn=function(){"use strict";function e(){(0,H.default)(this,e),(0,te.default)(this,"len",void 0),(0,te.default)(this,"head",void 0),(0,te.default)(this,"tail",void 0),(0,te.default)(this,"states",void 0),this.len=0,this.head=new kn(_n,0,0),this.tail=this.head,this.states=null}return(0,$.default)(e,[{key:"_push",value:function(e,t,n){return this.tail=this.tail.next=new kn(e,t,n),this.len+=t,this}},{key:"uint32",value:function(e){return this.len+=(this.tail=this.tail.next=new dr((e>>>=0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}},{key:"int32",value:function(e){return e<0?this._push(hr,10,Fe.fromNumber(e)):this.uint32(e)}},{key:"sint32",value:function(e){return this.uint32((e<<1^e>>31)>>>0)}},{key:"uint64",value:function(e){var t=Fe.fromBigInt(e);return this._push(hr,t.length(),t)}},{key:"uint64Number",value:function(e){return this._push(Ie,Ae(e),e)}},{key:"uint64String",value:function(e){return this.uint64(BigInt(e))}},{key:"int64",value:function(e){return this.uint64(e)}},{key:"int64Number",value:function(e){return this.uint64Number(e)}},{key:"int64String",value:function(e){return this.uint64String(e)}},{key:"sint64",value:function(e){var t=Fe.fromBigInt(e).zzEncode();return this._push(hr,t.length(),t)}},{key:"sint64Number",value:function(e){var t=Fe.fromNumber(e).zzEncode();return this._push(hr,t.length(),t)}},{key:"sint64String",value:function(e){return this.sint64(BigInt(e))}},{key:"bool",value:function(e){return this._push(Tn,1,e?1:0)}},{key:"fixed32",value:function(e){return this._push(vr,4,e>>>0)}},{key:"sfixed32",value:function(e){return this.fixed32(e)}},{key:"fixed64",value:function(e){var t=Fe.fromBigInt(e);return this._push(vr,4,t.lo)._push(vr,4,t.hi)}},{key:"fixed64Number",value:function(e){var t=Fe.fromNumber(e);return this._push(vr,4,t.lo)._push(vr,4,t.hi)}},{key:"fixed64String",value:function(e){return this.fixed64(BigInt(e))}},{key:"sfixed64",value:function(e){return this.fixed64(e)}},{key:"sfixed64Number",value:function(e){return this.fixed64Number(e)}},{key:"sfixed64String",value:function(e){return this.fixed64String(e)}},{key:"float",value:function(e){return this._push(Le,4,e)}},{key:"double",value:function(e){return this._push(Ne,8,e)}},{key:"bytes",value:function(e){var t=e.length>>>0;return 0===t?this._push(Tn,1,0):this.uint32(t)._push(pr,t,e)}},{key:"string",value:function(e){var t=function(e){for(var t=0,n=0,r=0;r<e.length;++r)(n=e.charCodeAt(r))<128?t+=1:n<2048?t+=2:55296==(64512&n)&&56320==(64512&e.charCodeAt(r+1))?(++r,t+=4):t+=3;return t}(e);return 0!==t?this.uint32(t)._push(ze,t,e):this._push(Tn,1,0)}},{key:"fork",value:function(){return this.states=new In(this),this.head=this.tail=new kn(_n,0,0),this.len=0,this}},{key:"reset",value:function(){return null!=this.states?(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 kn(_n,0,0),this.len=0),this}},{key:"ldelim",value:function(){var e=this.head,t=this.tail,n=this.len;return this.reset().uint32(n),0!==n&&(this.tail.next=e.next,this.tail=t,this.len+=n),this}},{key:"finish",value:function(){for(var e,t=this.head.next,n=(e=this.len,null!=globalThis.Buffer?me(e):xn(e)),r=0;null!=t;)t.fn(t.val,n,r),r+=t.len,t=t.next;return n}}]),e}();function Tn(e,t,n){t[n]=255&e}function Pn(e,t,n){for(;e>127;)t[n++]=127&e|128,e>>>=7;t[n]=e}var Rn,Ln,Dn,Mn,Nn,On,Un,Fn,Bn,qn,zn,jn,Kn,Vn,Hn,Wn,Gn,Xn,Yn,Zn,Qn,Jn,$n,er,tr,nr,rr,ir,ar,or,ur,sr,lr,cr,fr,dr=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(e,r){var i;return(0,H.default)(this,n),i=t.call(this,Pn,e,r),(0,te.default)((0,q.default)(i),"next",void 0),i.next=void 0,(0,ue.default)(i)}return n}(kn);function hr(e,t,n){for(;0!==e.hi;)t[n++]=127&e.lo|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[n++]=127&e.lo|128,e.lo=e.lo>>>7;t[n++]=e.lo}function vr(e,t,n){t[n]=255&e,t[n+1]=e>>>8&255,t[n+2]=e>>>16&255,t[n+3]=e>>>24}function pr(e,t,n){t.set(e,n)}function gr(e,t,n){t.set(e,n)}function yr(e,t,n){e.length<40?ze(e,t,n):null!=t.utf8Write?t.utf8Write(e,n):t.set(wn(e),n)}function mr(e,t){var n=new Cn;return t.encode(e,n,{lengthDelimited:!1}),n.finish()}function br(e,t,n,r){return{name:e,type:t,encode:n,decode:r}}function wr(e){var t=function(t){if(null==e[t.toString()])throw Error("Invalid enum value");return e[t]};return br("enum",Rn.VARINT,(function(e,n){var r=t(e);n.int32(r)}),(function(e){return t(e.int32())}))}function kr(e,t){return br("message",Rn.LENGTH_DELIMITED,e,t)}null!=globalThis.Buffer&&(Cn.prototype.bytes=function(e){var t=e.length>>>0;return this.uint32(t),t>0&&this._push(gr,t,e),this},Cn.prototype.string=function(e){var t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(yr,t,e),this}),(fr=Rn||(Rn={}))[fr.VARINT=0]="VARINT",fr[fr.BIT64=1]="BIT64",fr[fr.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",fr[fr.START_GROUP=3]="START_GROUP",fr[fr.END_GROUP=4]="END_GROUP",fr[fr.BIT32=5]="BIT32";var _r=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e;return(0,H.default)(this,n),e=t.apply(this,arguments),(0,te.default)((0,q.default)(e),"code","ERR_MAX_LENGTH"),(0,te.default)((0,q.default)(e),"name","MaxLengthError"),e}return n}((0,he.default)(Error)),Er=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e;return(0,H.default)(this,n),e=t.apply(this,arguments),(0,te.default)((0,q.default)(e),"code","ERR_MAX_SIZE"),(0,te.default)((0,q.default)(e),"name","MaxSizeError"),e}return n}((0,he.default)(Error));function Sr(e){return!!e}(function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};!1!==n.lengthDelimited&&t.fork(),null!=e.proof&&e.proof.byteLength>0&&(t.uint32(10),t.bytes(e.proof)),null!=e.merkleRoot&&e.merkleRoot.byteLength>0&&(t.uint32(18),t.bytes(e.merkleRoot)),null!=e.epoch&&e.epoch.byteLength>0&&(t.uint32(26),t.bytes(e.epoch)),null!=e.shareX&&e.shareX.byteLength>0&&(t.uint32(34),t.bytes(e.shareX)),null!=e.shareY&&e.shareY.byteLength>0&&(t.uint32(42),t.bytes(e.shareY)),null!=e.nullifier&&e.nullifier.byteLength>0&&(t.uint32(50),t.bytes(e.nullifier)),null!=e.rlnIdentifier&&e.rlnIdentifier.byteLength>0&&(t.uint32(58),t.bytes(e.rlnIdentifier)),!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n={proof:ye(0),merkleRoot:ye(0),epoch:ye(0),shareX:ye(0),shareY:ye(0),nullifier:ye(0),rlnIdentifier:ye(0)},r=null==t?e.len:e.pos+t;e.pos<r;){var i=e.uint32();switch(i>>>3){case 1:n.proof=e.bytes();break;case 2:n.merkleRoot=e.bytes();break;case 3:n.epoch=e.bytes();break;case 4:n.shareX=e.bytes();break;case 5:n.shareY=e.bytes();break;case 6:n.nullifier=e.bytes();break;case 7:n.rlnIdentifier=e.bytes();break;default:e.skipType(7&i)}}return n}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}})(Ln||(Ln={})),function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};!1!==n.lengthDelimited&&t.fork(),null!=e.payload&&e.payload.byteLength>0&&(t.uint32(10),t.bytes(e.payload)),null!=e.contentTopic&&""!==e.contentTopic&&(t.uint32(18),t.string(e.contentTopic)),null!=e.version&&(t.uint32(24),t.uint32(e.version)),null!=e.timestamp&&(t.uint32(80),t.sint64(e.timestamp)),null!=e.meta&&(t.uint32(90),t.bytes(e.meta)),null!=e.rateLimitProof&&(t.uint32(170),Ln.codec().encode(e.rateLimitProof,t)),null!=e.ephemeral&&(t.uint32(248),t.bool(e.ephemeral)),!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r={payload:ye(0),contentTopic:""},i=null==t?e.len:e.pos+t;e.pos<i;){var a=e.uint32();switch(a>>>3){case 1:r.payload=e.bytes();break;case 2:r.contentTopic=e.string();break;case 3:r.version=e.uint32();break;case 10:r.timestamp=e.sint64();break;case 11:r.meta=e.bytes();break;case 21:var o;r.rateLimitProof=Ln.codec().decode(e,e.uint32(),{limits:null===(o=n.limits)||void 0===o?void 0:o.rateLimitProof});break;case 31:r.ephemeral=e.bool();break;default:e.skipType(7&a)}}return r}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(Dn||(Dn={})),function(e){var t;(function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};!1!==n.lengthDelimited&&t.fork(),null!=e.contentTopic&&""!==e.contentTopic&&(t.uint32(10),t.string(e.contentTopic)),!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n={contentTopic:""},r=null==t?e.len:e.pos+t;e.pos<r;){var i=e.uint32();i>>>3==1?n.contentTopic=e.string():e.skipType(7&i)}return n}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}})(e.ContentFilter||(e.ContentFilter={})),e.codec=function(){return null==t&&(t=kr((function(t,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=!0,a=!1,o=void 0;if(!1!==r.lengthDelimited&&n.fork(),null!=t.subscribe&&!1!==t.subscribe&&(n.uint32(8),n.bool(t.subscribe)),null!=t.topic&&""!==t.topic&&(n.uint32(18),n.string(t.topic)),null!=t.contentFilters)try{for(var u,s=t.contentFilters[Symbol.iterator]();!(i=(u=s.next()).done);i=!0){var l=u.value;n.uint32(26),e.ContentFilter.codec().encode(l,n)}}catch(e){a=!0,o=e}finally{try{i||null==s.return||s.return()}finally{if(a)throw o}}!1!==r.lengthDelimited&&n.ldelim()}),(function(t,n){for(var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i={subscribe:!1,topic:"",contentFilters:[]},a=null==n?t.len:t.pos+n;t.pos<a;){var o=t.uint32();switch(o>>>3){case 1:i.subscribe=t.bool();break;case 2:i.topic=t.string();break;case 3:var u,s;if(null!=(null===(u=r.limits)||void 0===u?void 0:u.contentFilters)&&i.contentFilters.length===r.limits.contentFilters)throw new _r('Decode error - map field "contentFilters" had too many elements');i.contentFilters.push(e.ContentFilter.codec().decode(t,t.uint32(),{limits:null===(s=r.limits)||void 0===s?void 0:s.contentFilters$}));break;default:t.skipType(7&o)}}return i}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(Mn||(Mn={})),function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=!0,i=!1,a=void 0;if(!1!==n.lengthDelimited&&t.fork(),null!=e.messages)try{for(var o,u=e.messages[Symbol.iterator]();!(r=(o=u.next()).done);r=!0){var s=o.value;t.uint32(10),Fn.codec().encode(s,t)}}catch(e){i=!0,a=e}finally{try{r||null==u.return||u.return()}finally{if(i)throw a}}!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r={messages:[]},i=null==t?e.len:e.pos+t;e.pos<i;){var a=e.uint32();if(a>>>3==1){var o,u;if(null!=(null===(o=n.limits)||void 0===o?void 0:o.messages)&&r.messages.length===n.limits.messages)throw new _r('Decode error - map field "messages" had too many elements');r.messages.push(Fn.codec().decode(e,e.uint32(),{limits:null===(u=n.limits)||void 0===u?void 0:u.messages$}))}else e.skipType(7&a)}return r}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(Nn||(Nn={})),function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};!1!==n.lengthDelimited&&t.fork(),null!=e.requestId&&""!==e.requestId&&(t.uint32(10),t.string(e.requestId)),null!=e.request&&(t.uint32(18),Mn.codec().encode(e.request,t)),null!=e.push&&(t.uint32(26),Nn.codec().encode(e.push,t)),!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r={requestId:""},i=null==t?e.len:e.pos+t;e.pos<i;){var a=e.uint32();switch(a>>>3){case 1:r.requestId=e.string();break;case 2:var o;r.request=Mn.codec().decode(e,e.uint32(),{limits:null===(o=n.limits)||void 0===o?void 0:o.request});break;case 3:var u;r.push=Nn.codec().decode(e,e.uint32(),{limits:null===(u=n.limits)||void 0===u?void 0:u.push});break;default:e.skipType(7&a)}}return r}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(On||(On={})),function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};!1!==n.lengthDelimited&&t.fork(),null!=e.proof&&e.proof.byteLength>0&&(t.uint32(10),t.bytes(e.proof)),null!=e.merkleRoot&&e.merkleRoot.byteLength>0&&(t.uint32(18),t.bytes(e.merkleRoot)),null!=e.epoch&&e.epoch.byteLength>0&&(t.uint32(26),t.bytes(e.epoch)),null!=e.shareX&&e.shareX.byteLength>0&&(t.uint32(34),t.bytes(e.shareX)),null!=e.shareY&&e.shareY.byteLength>0&&(t.uint32(42),t.bytes(e.shareY)),null!=e.nullifier&&e.nullifier.byteLength>0&&(t.uint32(50),t.bytes(e.nullifier)),null!=e.rlnIdentifier&&e.rlnIdentifier.byteLength>0&&(t.uint32(58),t.bytes(e.rlnIdentifier)),!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n={proof:ye(0),merkleRoot:ye(0),epoch:ye(0),shareX:ye(0),shareY:ye(0),nullifier:ye(0),rlnIdentifier:ye(0)},r=null==t?e.len:e.pos+t;e.pos<r;){var i=e.uint32();switch(i>>>3){case 1:n.proof=e.bytes();break;case 2:n.merkleRoot=e.bytes();break;case 3:n.epoch=e.bytes();break;case 4:n.shareX=e.bytes();break;case 5:n.shareY=e.bytes();break;case 6:n.nullifier=e.bytes();break;case 7:n.rlnIdentifier=e.bytes();break;default:e.skipType(7&i)}}return n}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(Un||(Un={})),function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};!1!==n.lengthDelimited&&t.fork(),null!=e.payload&&e.payload.byteLength>0&&(t.uint32(10),t.bytes(e.payload)),null!=e.contentTopic&&""!==e.contentTopic&&(t.uint32(18),t.string(e.contentTopic)),null!=e.version&&(t.uint32(24),t.uint32(e.version)),null!=e.timestamp&&(t.uint32(80),t.sint64(e.timestamp)),null!=e.meta&&(t.uint32(90),t.bytes(e.meta)),null!=e.rateLimitProof&&(t.uint32(170),Un.codec().encode(e.rateLimitProof,t)),null!=e.ephemeral&&(t.uint32(248),t.bool(e.ephemeral)),!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r={payload:ye(0),contentTopic:""},i=null==t?e.len:e.pos+t;e.pos<i;){var a=e.uint32();switch(a>>>3){case 1:r.payload=e.bytes();break;case 2:r.contentTopic=e.string();break;case 3:r.version=e.uint32();break;case 10:r.timestamp=e.sint64();break;case 11:r.meta=e.bytes();break;case 21:var o;r.rateLimitProof=Un.codec().decode(e,e.uint32(),{limits:null===(o=n.limits)||void 0===o?void 0:o.rateLimitProof});break;case 31:r.ephemeral=e.bool();break;default:e.skipType(7&a)}}return r}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(Fn||(Fn={})),function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};!1!==n.lengthDelimited&&t.fork(),null!=e.contentTopic&&""!==e.contentTopic&&(t.uint32(18),t.string(e.contentTopic)),!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n={contentTopic:""},r=null==t?e.len:e.pos+t;e.pos<r;){var i=e.uint32();i>>>3==2?n.contentTopic=e.string():e.skipType(7&i)}return n}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(Bn||(Bn={})),function(e){var t,n,r;(function(e){e.SUBSCRIBER_PING="SUBSCRIBER_PING",e.SUBSCRIBE="SUBSCRIBE",e.UNSUBSCRIBE="UNSUBSCRIBE",e.UNSUBSCRIBE_ALL="UNSUBSCRIBE_ALL"})(e.FilterSubscribeType||(e.FilterSubscribeType={})),function(e){e[e.SUBSCRIBER_PING=0]="SUBSCRIBER_PING",e[e.SUBSCRIBE=1]="SUBSCRIBE",e[e.UNSUBSCRIBE=2]="UNSUBSCRIBE",e[e.UNSUBSCRIBE_ALL=3]="UNSUBSCRIBE_ALL"}(n||(n={})),function(e){e.codec=function(){return wr(n)}}(t=e.FilterSubscribeType||(e.FilterSubscribeType={})),e.codec=function(){return null==r&&(r=kr((function(t,r){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=!0,o=!1,u=void 0;if(!1!==i.lengthDelimited&&r.fork(),null!=t.requestId&&""!==t.requestId&&(r.uint32(10),r.string(t.requestId)),null!=t.filterSubscribeType&&0!==n[t.filterSubscribeType]&&(r.uint32(16),e.FilterSubscribeType.codec().encode(t.filterSubscribeType,r)),null!=t.pubsubTopic&&(r.uint32(82),r.string(t.pubsubTopic)),null!=t.contentTopics)try{for(var s,l=t.contentTopics[Symbol.iterator]();!(a=(s=l.next()).done);a=!0){var c=s.value;r.uint32(90),r.string(c)}}catch(e){o=!0,u=e}finally{try{a||null==l.return||l.return()}finally{if(o)throw u}}!1!==i.lengthDelimited&&r.ldelim()}),(function(n,r){for(var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a={requestId:"",filterSubscribeType:t.SUBSCRIBER_PING,contentTopics:[]},o=null==r?n.len:n.pos+r;n.pos<o;){var u=n.uint32();switch(u>>>3){case 1:a.requestId=n.string();break;case 2:a.filterSubscribeType=e.FilterSubscribeType.codec().decode(n);break;case 10:a.pubsubTopic=n.string();break;case 11:var s;if(null!=(null===(s=i.limits)||void 0===s?void 0:s.contentTopics)&&a.contentTopics.length===i.limits.contentTopics)throw new _r('Decode error - map field "contentTopics" had too many elements');a.contentTopics.push(n.string());break;default:n.skipType(7&u)}}return a}))),r},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(qn||(qn={})),function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};!1!==n.lengthDelimited&&t.fork(),null!=e.requestId&&""!==e.requestId&&(t.uint32(10),t.string(e.requestId)),null!=e.statusCode&&0!==e.statusCode&&(t.uint32(80),t.uint32(e.statusCode)),null!=e.statusDesc&&(t.uint32(90),t.string(e.statusDesc)),!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n={requestId:"",statusCode:0},r=null==t?e.len:e.pos+t;e.pos<r;){var i=e.uint32();switch(i>>>3){case 1:n.requestId=e.string();break;case 10:n.statusCode=e.uint32();break;case 11:n.statusDesc=e.string();break;default:e.skipType(7&i)}}return n}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(zn||(zn={})),function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};!1!==n.lengthDelimited&&t.fork(),null!=e.wakuMessage&&(t.uint32(10),Vn.codec().encode(e.wakuMessage,t)),null!=e.pubsubTopic&&(t.uint32(18),t.string(e.pubsubTopic)),!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r={},i=null==t?e.len:e.pos+t;e.pos<i;){var a=e.uint32();switch(a>>>3){case 1:var o;r.wakuMessage=Vn.codec().decode(e,e.uint32(),{limits:null===(o=n.limits)||void 0===o?void 0:o.wakuMessage});break;case 2:r.pubsubTopic=e.string();break;default:e.skipType(7&a)}}return r}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(jn||(jn={})),function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};!1!==n.lengthDelimited&&t.fork(),null!=e.proof&&e.proof.byteLength>0&&(t.uint32(10),t.bytes(e.proof)),null!=e.merkleRoot&&e.merkleRoot.byteLength>0&&(t.uint32(18),t.bytes(e.merkleRoot)),null!=e.epoch&&e.epoch.byteLength>0&&(t.uint32(26),t.bytes(e.epoch)),null!=e.shareX&&e.shareX.byteLength>0&&(t.uint32(34),t.bytes(e.shareX)),null!=e.shareY&&e.shareY.byteLength>0&&(t.uint32(42),t.bytes(e.shareY)),null!=e.nullifier&&e.nullifier.byteLength>0&&(t.uint32(50),t.bytes(e.nullifier)),null!=e.rlnIdentifier&&e.rlnIdentifier.byteLength>0&&(t.uint32(58),t.bytes(e.rlnIdentifier)),!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n={proof:ye(0),merkleRoot:ye(0),epoch:ye(0),shareX:ye(0),shareY:ye(0),nullifier:ye(0),rlnIdentifier:ye(0)},r=null==t?e.len:e.pos+t;e.pos<r;){var i=e.uint32();switch(i>>>3){case 1:n.proof=e.bytes();break;case 2:n.merkleRoot=e.bytes();break;case 3:n.epoch=e.bytes();break;case 4:n.shareX=e.bytes();break;case 5:n.shareY=e.bytes();break;case 6:n.nullifier=e.bytes();break;case 7:n.rlnIdentifier=e.bytes();break;default:e.skipType(7&i)}}return n}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(Kn||(Kn={})),function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};!1!==n.lengthDelimited&&t.fork(),null!=e.payload&&e.payload.byteLength>0&&(t.uint32(10),t.bytes(e.payload)),null!=e.contentTopic&&""!==e.contentTopic&&(t.uint32(18),t.string(e.contentTopic)),null!=e.version&&(t.uint32(24),t.uint32(e.version)),null!=e.timestamp&&(t.uint32(80),t.sint64(e.timestamp)),null!=e.meta&&(t.uint32(90),t.bytes(e.meta)),null!=e.rateLimitProof&&(t.uint32(170),Kn.codec().encode(e.rateLimitProof,t)),null!=e.ephemeral&&(t.uint32(248),t.bool(e.ephemeral)),!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r={payload:ye(0),contentTopic:""},i=null==t?e.len:e.pos+t;e.pos<i;){var a=e.uint32();switch(a>>>3){case 1:r.payload=e.bytes();break;case 2:r.contentTopic=e.string();break;case 3:r.version=e.uint32();break;case 10:r.timestamp=e.sint64();break;case 11:r.meta=e.bytes();break;case 21:var o;r.rateLimitProof=Kn.codec().decode(e,e.uint32(),{limits:null===(o=n.limits)||void 0===o?void 0:o.rateLimitProof});break;case 31:r.ephemeral=e.bool();break;default:e.skipType(7&a)}}return r}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(Vn||(Vn={})),function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};!1!==n.lengthDelimited&&t.fork(),null!=e.pubsubTopic&&""!==e.pubsubTopic&&(t.uint32(10),t.string(e.pubsubTopic)),null!=e.message&&(t.uint32(18),Qn.codec().encode(e.message,t)),!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r={pubsubTopic:""},i=null==t?e.len:e.pos+t;e.pos<i;){var a=e.uint32();switch(a>>>3){case 1:r.pubsubTopic=e.string();break;case 2:var o;r.message=Qn.codec().decode(e,e.uint32(),{limits:null===(o=n.limits)||void 0===o?void 0:o.message});break;default:e.skipType(7&a)}}return r}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(Hn||(Hn={})),function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};!1!==n.lengthDelimited&&t.fork(),null!=e.isSuccess&&!1!==e.isSuccess&&(t.uint32(8),t.bool(e.isSuccess)),null!=e.info&&(t.uint32(18),t.string(e.info)),null!=e.statusCode&&(t.uint32(80),t.uint32(e.statusCode)),null!=e.statusDesc&&(t.uint32(90),t.string(e.statusDesc)),null!=e.relayPeerCount&&(t.uint32(96),t.uint32(e.relayPeerCount)),!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n={isSuccess:!1},r=null==t?e.len:e.pos+t;e.pos<r;){var i=e.uint32();switch(i>>>3){case 1:n.isSuccess=e.bool();break;case 2:n.info=e.string();break;case 10:n.statusCode=e.uint32();break;case 11:n.statusDesc=e.string();break;case 12:n.relayPeerCount=e.uint32();break;default:e.skipType(7&i)}}return n}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(Wn||(Wn={})),function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};!1!==n.lengthDelimited&&t.fork(),null!=e.requestId&&""!==e.requestId&&(t.uint32(10),t.string(e.requestId)),null!=e.request&&(t.uint32(18),Hn.codec().encode(e.request,t)),null!=e.response&&(t.uint32(26),Wn.codec().encode(e.response,t)),!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r={requestId:""},i=null==t?e.len:e.pos+t;e.pos<i;){var a=e.uint32();switch(a>>>3){case 1:r.requestId=e.string();break;case 2:var o;r.request=Hn.codec().decode(e,e.uint32(),{limits:null===(o=n.limits)||void 0===o?void 0:o.request});break;case 3:var u;r.response=Wn.codec().decode(e,e.uint32(),{limits:null===(u=n.limits)||void 0===u?void 0:u.response});break;default:e.skipType(7&a)}}return r}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(Gn||(Gn={})),function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};!1!==n.lengthDelimited&&t.fork(),null!=e.requestId&&""!==e.requestId&&(t.uint32(10),t.string(e.requestId)),null!=e.pubsubTopic&&(t.uint32(162),t.string(e.pubsubTopic)),null!=e.message&&(t.uint32(170),Qn.codec().encode(e.message,t)),!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r={requestId:""},i=null==t?e.len:e.pos+t;e.pos<i;){var a=e.uint32();switch(a>>>3){case 1:r.requestId=e.string();break;case 20:r.pubsubTopic=e.string();break;case 21:var o;r.message=Qn.codec().decode(e,e.uint32(),{limits:null===(o=n.limits)||void 0===o?void 0:o.message});break;default:e.skipType(7&a)}}return r}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(Xn||(Xn={})),function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};!1!==n.lengthDelimited&&t.fork(),null!=e.requestId&&""!==e.requestId&&(t.uint32(10),t.string(e.requestId)),null!=e.statusCode&&0!==e.statusCode&&(t.uint32(80),t.uint32(e.statusCode)),null!=e.statusDesc&&(t.uint32(90),t.string(e.statusDesc)),null!=e.relayPeerCount&&(t.uint32(96),t.uint32(e.relayPeerCount)),!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n={requestId:"",statusCode:0},r=null==t?e.len:e.pos+t;e.pos<r;){var i=e.uint32();switch(i>>>3){case 1:n.requestId=e.string();break;case 10:n.statusCode=e.uint32();break;case 11:n.statusDesc=e.string();break;case 12:n.relayPeerCount=e.uint32();break;default:e.skipType(7&i)}}return n}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(Yn||(Yn={})),function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};!1!==n.lengthDelimited&&t.fork(),null!=e.proof&&e.proof.byteLength>0&&(t.uint32(10),t.bytes(e.proof)),null!=e.merkleRoot&&e.merkleRoot.byteLength>0&&(t.uint32(18),t.bytes(e.merkleRoot)),null!=e.epoch&&e.epoch.byteLength>0&&(t.uint32(26),t.bytes(e.epoch)),null!=e.shareX&&e.shareX.byteLength>0&&(t.uint32(34),t.bytes(e.shareX)),null!=e.shareY&&e.shareY.byteLength>0&&(t.uint32(42),t.bytes(e.shareY)),null!=e.nullifier&&e.nullifier.byteLength>0&&(t.uint32(50),t.bytes(e.nullifier)),null!=e.rlnIdentifier&&e.rlnIdentifier.byteLength>0&&(t.uint32(58),t.bytes(e.rlnIdentifier)),!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n={proof:ye(0),merkleRoot:ye(0),epoch:ye(0),shareX:ye(0),shareY:ye(0),nullifier:ye(0),rlnIdentifier:ye(0)},r=null==t?e.len:e.pos+t;e.pos<r;){var i=e.uint32();switch(i>>>3){case 1:n.proof=e.bytes();break;case 2:n.merkleRoot=e.bytes();break;case 3:n.epoch=e.bytes();break;case 4:n.shareX=e.bytes();break;case 5:n.shareY=e.bytes();break;case 6:n.nullifier=e.bytes();break;case 7:n.rlnIdentifier=e.bytes();break;default:e.skipType(7&i)}}return n}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(Zn||(Zn={})),function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};!1!==n.lengthDelimited&&t.fork(),null!=e.payload&&e.payload.byteLength>0&&(t.uint32(10),t.bytes(e.payload)),null!=e.contentTopic&&""!==e.contentTopic&&(t.uint32(18),t.string(e.contentTopic)),null!=e.version&&(t.uint32(24),t.uint32(e.version)),null!=e.timestamp&&(t.uint32(80),t.sint64(e.timestamp)),null!=e.meta&&(t.uint32(90),t.bytes(e.meta)),null!=e.rateLimitProof&&(t.uint32(170),Zn.codec().encode(e.rateLimitProof,t)),null!=e.ephemeral&&(t.uint32(248),t.bool(e.ephemeral)),!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r={payload:ye(0),contentTopic:""},i=null==t?e.len:e.pos+t;e.pos<i;){var a=e.uint32();switch(a>>>3){case 1:r.payload=e.bytes();break;case 2:r.contentTopic=e.string();break;case 3:r.version=e.uint32();break;case 10:r.timestamp=e.sint64();break;case 11:r.meta=e.bytes();break;case 21:var o;r.rateLimitProof=Zn.codec().decode(e,e.uint32(),{limits:null===(o=n.limits)||void 0===o?void 0:o.rateLimitProof});break;case 31:r.ephemeral=e.bool();break;default:e.skipType(7&a)}}return r}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(Qn||(Qn={})),function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};!1!==n.lengthDelimited&&t.fork(),null!=e.messageHash&&(t.uint32(10),t.bytes(e.messageHash)),null!=e.message&&(t.uint32(18),nr.codec().encode(e.message,t)),null!=e.pubsubTopic&&(t.uint32(26),t.string(e.pubsubTopic)),!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r={},i=null==t?e.len:e.pos+t;e.pos<i;){var a=e.uint32();switch(a>>>3){case 1:r.messageHash=e.bytes();break;case 2:var o;r.message=nr.codec().decode(e,e.uint32(),{limits:null===(o=n.limits)||void 0===o?void 0:o.message});break;case 3:r.pubsubTopic=e.string();break;default:e.skipType(7&a)}}return r}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(Jn||(Jn={})),function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=!0,i=!1,a=void 0;if(!1!==n.lengthDelimited&&t.fork(),null!=e.requestId&&""!==e.requestId&&(t.uint32(10),t.string(e.requestId)),null!=e.includeData&&!1!==e.includeData&&(t.uint32(16),t.bool(e.includeData)),null!=e.pubsubTopic&&(t.uint32(82),t.string(e.pubsubTopic)),null!=e.contentTopics)try{for(var o,u=e.contentTopics[Symbol.iterator]();!(r=(o=u.next()).done);r=!0){var s=o.value;t.uint32(90),t.string(s)}}catch(e){i=!0,a=e}finally{try{r||null==u.return||u.return()}finally{if(i)throw a}}var l=!0,c=!1,f=void 0;if(null!=e.timeStart&&(t.uint32(96),t.sint64(e.timeStart)),null!=e.timeEnd&&(t.uint32(104),t.sint64(e.timeEnd)),null!=e.messageHashes)try{for(var d,h=e.messageHashes[Symbol.iterator]();!(l=(d=h.next()).done);l=!0){var v=d.value;t.uint32(162),t.bytes(v)}}catch(e){c=!0,f=e}finally{try{l||null==h.return||h.return()}finally{if(c)throw f}}null!=e.paginationCursor&&(t.uint32(410),t.bytes(e.paginationCursor)),null!=e.paginationForward&&!1!==e.paginationForward&&(t.uint32(416),t.bool(e.paginationForward)),null!=e.paginationLimit&&(t.uint32(424),t.uint64(e.paginationLimit)),!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r={requestId:"",includeData:!1,contentTopics:[],messageHashes:[],paginationForward:!1},i=null==t?e.len:e.pos+t;e.pos<i;){var a=e.uint32();switch(a>>>3){case 1:r.requestId=e.string();break;case 2:r.includeData=e.bool();break;case 10:r.pubsubTopic=e.string();break;case 11:var o;if(null!=(null===(o=n.limits)||void 0===o?void 0:o.contentTopics)&&r.contentTopics.length===n.limits.contentTopics)throw new _r('Decode error - map field "contentTopics" had too many elements');r.contentTopics.push(e.string());break;case 12:r.timeStart=e.sint64();break;case 13:r.timeEnd=e.sint64();break;case 20:var u;if(null!=(null===(u=n.limits)||void 0===u?void 0:u.messageHashes)&&r.messageHashes.length===n.limits.messageHashes)throw new _r('Decode error - map field "messageHashes" had too many elements');r.messageHashes.push(e.bytes());break;case 51:r.paginationCursor=e.bytes();break;case 52:r.paginationForward=e.bool();break;case 53:r.paginationLimit=e.uint64();break;default:e.skipType(7&a)}}return r}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}($n||($n={})),function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=!0,i=!1,a=void 0;if(!1!==n.lengthDelimited&&t.fork(),null!=e.requestId&&""!==e.requestId&&(t.uint32(10),t.string(e.requestId)),null!=e.statusCode&&(t.uint32(80),t.uint32(e.statusCode)),null!=e.statusDesc&&(t.uint32(90),t.string(e.statusDesc)),null!=e.messages)try{for(var o,u=e.messages[Symbol.iterator]();!(r=(o=u.next()).done);r=!0){var s=o.value;t.uint32(162),Jn.codec().encode(s,t)}}catch(e){i=!0,a=e}finally{try{r||null==u.return||u.return()}finally{if(i)throw a}}null!=e.paginationCursor&&(t.uint32(410),t.bytes(e.paginationCursor)),!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r={requestId:"",messages:[]},i=null==t?e.len:e.pos+t;e.pos<i;){var a=e.uint32();switch(a>>>3){case 1:r.requestId=e.string();break;case 10:r.statusCode=e.uint32();break;case 11:r.statusDesc=e.string();break;case 20:var o,u;if(null!=(null===(o=n.limits)||void 0===o?void 0:o.messages)&&r.messages.length===n.limits.messages)throw new _r('Decode error - map field "messages" had too many elements');r.messages.push(Jn.codec().decode(e,e.uint32(),{limits:null===(u=n.limits)||void 0===u?void 0:u.messages$}));break;case 51:r.paginationCursor=e.bytes();break;default:e.skipType(7&a)}}return r}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(er||(er={})),function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};!1!==n.lengthDelimited&&t.fork(),null!=e.proof&&e.proof.byteLength>0&&(t.uint32(10),t.bytes(e.proof)),null!=e.merkleRoot&&e.merkleRoot.byteLength>0&&(t.uint32(18),t.bytes(e.merkleRoot)),null!=e.epoch&&e.epoch.byteLength>0&&(t.uint32(26),t.bytes(e.epoch)),null!=e.shareX&&e.shareX.byteLength>0&&(t.uint32(34),t.bytes(e.shareX)),null!=e.shareY&&e.shareY.byteLength>0&&(t.uint32(42),t.bytes(e.shareY)),null!=e.nullifier&&e.nullifier.byteLength>0&&(t.uint32(50),t.bytes(e.nullifier)),null!=e.rlnIdentifier&&e.rlnIdentifier.byteLength>0&&(t.uint32(58),t.bytes(e.rlnIdentifier)),!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n={proof:ye(0),merkleRoot:ye(0),epoch:ye(0),shareX:ye(0),shareY:ye(0),nullifier:ye(0),rlnIdentifier:ye(0)},r=null==t?e.len:e.pos+t;e.pos<r;){var i=e.uint32();switch(i>>>3){case 1:n.proof=e.bytes();break;case 2:n.merkleRoot=e.bytes();break;case 3:n.epoch=e.bytes();break;case 4:n.shareX=e.bytes();break;case 5:n.shareY=e.bytes();break;case 6:n.nullifier=e.bytes();break;case 7:n.rlnIdentifier=e.bytes();break;default:e.skipType(7&i)}}return n}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(tr||(tr={})),function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};!1!==n.lengthDelimited&&t.fork(),null!=e.payload&&e.payload.byteLength>0&&(t.uint32(10),t.bytes(e.payload)),null!=e.contentTopic&&""!==e.contentTopic&&(t.uint32(18),t.string(e.contentTopic)),null!=e.version&&(t.uint32(24),t.uint32(e.version)),null!=e.timestamp&&(t.uint32(80),t.sint64(e.timestamp)),null!=e.meta&&(t.uint32(90),t.bytes(e.meta)),null!=e.rateLimitProof&&(t.uint32(170),tr.codec().encode(e.rateLimitProof,t)),null!=e.ephemeral&&(t.uint32(248),t.bool(e.ephemeral)),!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r={payload:ye(0),contentTopic:""},i=null==t?e.len:e.pos+t;e.pos<i;){var a=e.uint32();switch(a>>>3){case 1:r.payload=e.bytes();break;case 2:r.contentTopic=e.string();break;case 3:r.version=e.uint32();break;case 10:r.timestamp=e.sint64();break;case 11:r.meta=e.bytes();break;case 21:var o;r.rateLimitProof=tr.codec().decode(e,e.uint32(),{limits:null===(o=n.limits)||void 0===o?void 0:o.rateLimitProof});break;case 31:r.ephemeral=e.bool();break;default:e.skipType(7&a)}}return r}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(nr||(nr={})),function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};!1!==n.lengthDelimited&&t.fork(),null!=e.enr&&(t.uint32(10),t.bytes(e.enr)),!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n={},r=null==t?e.len:e.pos+t;e.pos<r;){var i=e.uint32();i>>>3==1?n.enr=e.bytes():e.skipType(7&i)}return n}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(rr||(rr={})),function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};!1!==n.lengthDelimited&&t.fork(),null!=e.numPeers&&(t.uint32(8),t.uint64(e.numPeers)),!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n={},r=null==t?e.len:e.pos+t;e.pos<r;){var i=e.uint32();i>>>3==1?n.numPeers=e.uint64():e.skipType(7&i)}return n}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(ir||(ir={})),function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=!0,i=!1,a=void 0;if(!1!==n.lengthDelimited&&t.fork(),null!=e.peerInfos)try{for(var o,u=e.peerInfos[Symbol.iterator]();!(r=(o=u.next()).done);r=!0){var s=o.value;t.uint32(10),rr.codec().encode(s,t)}}catch(e){i=!0,a=e}finally{try{r||null==u.return||u.return()}finally{if(i)throw a}}!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r={peerInfos:[]},i=null==t?e.len:e.pos+t;e.pos<i;){var a=e.uint32();if(a>>>3==1){var o,u;if(null!=(null===(o=n.limits)||void 0===o?void 0:o.peerInfos)&&r.peerInfos.length===n.limits.peerInfos)throw new _r('Decode error - map field "peerInfos" had too many elements');r.peerInfos.push(rr.codec().decode(e,e.uint32(),{limits:null===(u=n.limits)||void 0===u?void 0:u.peerInfos$}))}else e.skipType(7&a)}return r}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(ar||(ar={})),function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};!1!==n.lengthDelimited&&t.fork(),null!=e.query&&(t.uint32(10),ir.codec().encode(e.query,t)),null!=e.response&&(t.uint32(18),ar.codec().encode(e.response,t)),!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r={},i=null==t?e.len:e.pos+t;e.pos<i;){var a=e.uint32();switch(a>>>3){case 1:var o;r.query=ir.codec().decode(e,e.uint32(),{limits:null===(o=n.limits)||void 0===o?void 0:o.query});break;case 2:var u;r.response=ar.codec().decode(e,e.uint32(),{limits:null===(u=n.limits)||void 0===u?void 0:u.response});break;default:e.skipType(7&a)}}return r}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(or||(or={})),function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=!0,i=!1,a=void 0;if(!1!==n.lengthDelimited&&t.fork(),null!=e.clusterId&&(t.uint32(8),t.uint32(e.clusterId)),null!=e.shards)try{for(var o,u=e.shards[Symbol.iterator]();!(r=(o=u.next()).done);r=!0){var s=o.value;t.uint32(16),t.uint32(s)}}catch(e){i=!0,a=e}finally{try{r||null==u.return||u.return()}finally{if(i)throw a}}!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r={shards:[]},i=null==t?e.len:e.pos+t;e.pos<i;){var a=e.uint32();switch(a>>>3){case 1:r.clusterId=e.uint32();break;case 2:var o;if(null!=(null===(o=n.limits)||void 0===o?void 0:o.shards)&&r.shards.length===n.limits.shards)throw new _r('Decode error - map field "shards" had too many elements');r.shards.push(e.uint32());break;default:e.skipType(7&a)}}return r}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(ur||(ur={})),function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=!0,i=!1,a=void 0;if(!1!==n.lengthDelimited&&t.fork(),null!=e.clusterId&&(t.uint32(8),t.uint32(e.clusterId)),null!=e.shards)try{for(var o,u=e.shards[Symbol.iterator]();!(r=(o=u.next()).done);r=!0){var s=o.value;t.uint32(16),t.uint32(s)}}catch(e){i=!0,a=e}finally{try{r||null==u.return||u.return()}finally{if(i)throw a}}!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r={shards:[]},i=null==t?e.len:e.pos+t;e.pos<i;){var a=e.uint32();switch(a>>>3){case 1:r.clusterId=e.uint32();break;case 2:var o;if(null!=(null===(o=n.limits)||void 0===o?void 0:o.shards)&&r.shards.length===n.limits.shards)throw new _r('Decode error - map field "shards" had too many elements');r.shards.push(e.uint32());break;default:e.skipType(7&a)}}return r}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(sr||(sr={})),function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};!1!==n.lengthDelimited&&t.fork(),null!=e.messageId&&""!==e.messageId&&(t.uint32(10),t.string(e.messageId)),null!=e.retrievalHint&&(t.uint32(18),t.bytes(e.retrievalHint)),!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n={messageId:""},r=null==t?e.len:e.pos+t;e.pos<r;){var i=e.uint32();switch(i>>>3){case 1:n.messageId=e.string();break;case 2:n.retrievalHint=e.bytes();break;default:e.skipType(7&i)}}return n}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(lr||(lr={})),function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=!0,i=!1,a=void 0;if(!1!==n.lengthDelimited&&t.fork(),null!=e.senderId&&""!==e.senderId&&(t.uint32(10),t.string(e.senderId)),null!=e.messageId&&""!==e.messageId&&(t.uint32(18),t.string(e.messageId)),null!=e.channelId&&""!==e.channelId&&(t.uint32(26),t.string(e.channelId)),null!=e.lamportTimestamp&&(t.uint32(80),t.int32(e.lamportTimestamp)),null!=e.causalHistory)try{for(var o,u=e.causalHistory[Symbol.iterator]();!(r=(o=u.next()).done);r=!0){var s=o.value;t.uint32(90),lr.codec().encode(s,t)}}catch(e){i=!0,a=e}finally{try{r||null==u.return||u.return()}finally{if(i)throw a}}null!=e.bloomFilter&&(t.uint32(98),t.bytes(e.bloomFilter)),null!=e.content&&(t.uint32(162),t.bytes(e.content)),!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r={senderId:"",messageId:"",channelId:"",causalHistory:[]},i=null==t?e.len:e.pos+t;e.pos<i;){var a=e.uint32();switch(a>>>3){case 1:r.senderId=e.string();break;case 2:r.messageId=e.string();break;case 3:r.channelId=e.string();break;case 10:r.lamportTimestamp=e.int32();break;case 11:var o,u;if(null!=(null===(o=n.limits)||void 0===o?void 0:o.causalHistory)&&r.causalHistory.length===n.limits.causalHistory)throw new _r('Decode error - map field "causalHistory" had too many elements');r.causalHistory.push(lr.codec().decode(e,e.uint32(),{limits:null===(u=n.limits)||void 0===u?void 0:u.causalHistory$}));break;case 12:r.bloomFilter=e.bytes();break;case 20:r.content=e.bytes();break;default:e.skipType(7&a)}}return r}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(cr||(cr={}));var Ar=function(e){return e.length/1048576<=1},Ir="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0;function xr(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function Cr(e){if(!Number.isSafeInteger(e)||e<0)throw Error("positive integer expected, got "+e)}function Tr(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];if(!xr(e))throw Error("Uint8Array expected");if(n.length>0&&!n.includes(e.length))throw Error("Uint8Array expected of length "+n+", got length="+e.length)}function Pr(e){if("function"!=typeof e||"function"!=typeof e.create)throw Error("Hash should be wrapped by utils.createHasher");Cr(e.outputLen),Cr(e.blockLen)}function Rr(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(e.destroyed)throw Error("Hash instance has been destroyed");if(t&&e.finished)throw Error("Hash#digest() has already been called")}function Lr(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];for(var r=0;r<t.length;r++)t[r].fill(0)}function Dr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Mr(e,t){return e<<32-t|e>>>t}var Nr="function"==typeof Uint8Array.from([]).toHex&&"function"==typeof Uint8Array.fromHex,Or=Array.from({length:256},(function(e,t){return t.toString(16).padStart(2,"0")}));function Ur(e){if(Tr(e),Nr)return e.toHex();for(var t="",n=0;n<e.length;n++)t+=Or[e[n]];return t}var Fr=48,Br=57,qr=65,zr=70,jr=97,Kr=102;function Vr(e){return e>=Fr&&e<=Br?e-Fr:e>=qr&&e<=zr?e-(qr-10):e>=jr&&e<=Kr?e-(jr-10):void 0}function Hr(e){if("string"!=typeof e)throw Error("hex string expected, got "+(void 0===e?"undefined":(0,fe.default)(e)));if(Nr)return Uint8Array.fromHex(e);var t=e.length,n=t/2;if(t%2)throw Error("hex string expected, got unpadded hex of length "+t);for(var r=new Uint8Array(n),i=0,a=0;i<n;i++,a+=2){var o=Vr(e.charCodeAt(a)),u=Vr(e.charCodeAt(a+1));if(void 0===o||void 0===u){var s=e[a]+e[a+1];throw Error('hex string expected, got non-hex character "'+s+'" at index '+a)}r[i]=16*o+u}return r}function Wr(e){return"string"==typeof e&&(e=function(e){if("string"!=typeof e)throw Error("string expected");return new Uint8Array((new TextEncoder).encode(e))}(e)),Tr(e),e}function Gr(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];for(var r=0,i=0;i<t.length;i++){var a=t[i];Tr(a),r+=a.length}for(var o=new Uint8Array(r),u=0,s=0;u<t.length;u++){var l=t[u];o.set(l,s),s+=l.length}return o}var Xr=function e(){"use strict";(0,H.default)(this,e)};function Yr(e){var t=function(t){return e().update(Wr(t)).digest()},n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=function(){return e()},t}function Zr(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:32;if(Ir&&"function"==typeof Ir.getRandomValues)return Ir.getRandomValues(new Uint8Array(e));if(Ir&&"function"==typeof Ir.randomBytes)return Uint8Array.from(Ir.randomBytes(e));throw Error("crypto.getRandomValues must be defined")}function Qr(e,t,n){return e&t^e&n^t&n}var Jr=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(e,r,i,a){var o;return(0,H.default)(this,n),(o=t.call(this)).finished=!1,o.length=0,o.pos=0,o.destroyed=!1,o.blockLen=e,o.outputLen=r,o.padOffset=i,o.isLE=a,o.buffer=new Uint8Array(e),o.view=Dr(o.buffer),(0,ue.default)(o)}return(0,$.default)(n,[{key:"update",value:function(e){Rr(this),Tr(e=Wr(e));for(var t=this,n=t.view,r=t.buffer,i=t.blockLen,a=e.length,o=0;o<a;){var u=Math.min(i-this.pos,a-o);if(u!==i)r.set(e.subarray(o,o+u),this.pos),this.pos+=u,o+=u,this.pos===i&&(this.process(n,0),this.pos=0);else for(var s=Dr(e);i<=a-o;o+=i)this.process(s,o)}return this.length+=e.length,this.roundClean(),this}},{key:"digestInto",value:function(e){Rr(this),function(e,t){Tr(e);var n=t.outputLen;if(e.length<n)throw Error("digestInto() expects output buffer of length at least "+n)}(e,this),this.finished=!0;var t=this,n=t.buffer,r=t.view,i=t.blockLen,a=t.isLE,o=this.pos;n[o++]=128,Lr(this.buffer.subarray(o)),this.padOffset>i-o&&(this.process(r,0),o=0);for(var u=o;u<i;u++)n[u]=0;!function(e,t,n,r){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,n,r);var i=BigInt(32),a=BigInt(4294967295),o=Number(n>>i&a),u=Number(n&a),s=r?4:0,l=r?0:4;e.setUint32(t+s,o,r),e.setUint32(t+l,u,r)}(r,i-8,BigInt(8*this.length),a),this.process(r,0);var s=Dr(e),l=this.outputLen;if(l%4)throw Error("_sha2: outputLen should be aligned to 32bit");var c=l/4,f=this.get();if(c>f.length)throw Error("_sha2: outputLen bigger than state");for(var d=0;d<c;d++)s.setUint32(4*d,f[d],a)}},{key:"digest",value:function(){var e=this.buffer,t=this.outputLen;this.digestInto(e);var n=e.slice(0,t);return this.destroy(),n}},{key:"_cloneInto",value:function(e){var t;e||(e=new this.constructor),(t=e).set.apply(t,(0,ce.default)(this.get()));var n=this,r=n.blockLen,i=n.buffer,a=n.length,o=n.finished,u=n.destroyed,s=n.pos;return e.destroyed=u,e.finished=o,e.length=a,e.pos=s,a%r&&e.buffer.set(i),e}},{key:"clone",value:function(){return this._cloneInto()}}]),n}(Xr),$r=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),ei=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),ti=BigInt(Math.pow(2,32)-1),ni=BigInt(32);function ri(e){return arguments.length>1&&void 0!==arguments[1]&&arguments[1]?{h:Number(e&ti),l:Number(e>>ni&ti)}:{h:0|Number(e>>ni&ti),l:0|Number(e&ti)}}var ii=function(e,t,n){return e>>>n},ai=function(e,t,n){return e<<32-n|t>>>n},oi=function(e,t,n){return e>>>n|t<<32-n},ui=function(e,t,n){return e<<32-n|t>>>n},si=function(e,t,n){return e<<64-n|t>>>n-32},li=function(e,t,n){return e>>>n-32|t<<64-n};function ci(e,t,n,r){var i=(t>>>0)+(r>>>0);return{h:e+n+(i/Math.pow(2,32)|0)|0,l:0|i}}var fi=function(e,t,n){return(e>>>0)+(t>>>0)+(n>>>0)},di=function(e,t,n,r){return t+n+r+(e/Math.pow(2,32)|0)|0},hi=function(e,t,n,r){return(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0)},vi=function(e,t,n,r,i){return t+n+r+i+(e/Math.pow(2,32)|0)|0},pi=function(e,t,n,r,i){return(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0)+(i>>>0)},gi=function(e,t,n,r,i,a){return t+n+r+i+a+(e/Math.pow(2,32)|0)|0},yi=Uint32Array.from([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]),mi=new Uint32Array(64),bi=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:32;return(0,H.default)(this,n),(e=t.call(this,64,r,8,!1)).A=0|$r[0],e.B=0|$r[1],e.C=0|$r[2],e.D=0|$r[3],e.E=0|$r[4],e.F=0|$r[5],e.G=0|$r[6],e.H=0|$r[7],(0,ue.default)(e)}return(0,$.default)(n,[{key:"get",value:function(){var e=this;return[e.A,e.B,e.C,e.D,e.E,e.F,e.G,e.H]}},{key:"set",value:function(e,t,n,r,i,a,o,u){this.A=0|e,this.B=0|t,this.C=0|n,this.D=0|r,this.E=0|i,this.F=0|a,this.G=0|o,this.H=0|u}},{key:"process",value:function(e,t){for(var n=0;n<16;n++,t+=4)mi[n]=e.getUint32(t,!1);for(var r=16;r<64;r++){var i=mi[r-15],a=mi[r-2],o=Mr(i,7)^Mr(i,18)^i>>>3,u=Mr(a,17)^Mr(a,19)^a>>>10;mi[r]=u+mi[r-7]+o+mi[r-16]|0}for(var s,l=this,c=l.A,f=l.B,d=l.C,h=l.D,v=l.E,p=l.F,g=l.G,y=l.H,m=0;m<64;m++){var b=y+(Mr(v,6)^Mr(v,11)^Mr(v,25))+((s=v)&p^~s&g)+yi[m]+mi[m]|0,w=(Mr(c,2)^Mr(c,13)^Mr(c,22))+Qr(c,f,d)|0;y=g,g=p,p=v,v=h+b|0,h=d,d=f,f=c,c=b+w|0}c=c+this.A|0,f=f+this.B|0,d=d+this.C|0,h=h+this.D|0,v=v+this.E|0,p=p+this.F|0,g=g+this.G|0,y=y+this.H|0,this.set(c,f,d,h,v,p,g,y)}},{key:"roundClean",value:function(){Lr(mi)}},{key:"destroy",value:function(){this.set(0,0,0,0,0,0,0,0),Lr(this.buffer)}}]),n}(Jr),wi=function(e){for(var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=e.length,r=new Uint32Array(n),i=new Uint32Array(n),a=0;a<n;a++){var o,u=ri(e[a],t);o=[u.h,u.l],r[a]=o[0],i[a]=o[1]}return[r,i]}(["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((function(e){return BigInt(e)}))),ki=wi[0],_i=wi[1],Ei=new Uint32Array(80),Si=new Uint32Array(80),Ai=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:64;return(0,H.default)(this,n),(e=t.call(this,128,r,16,!1)).Ah=0|ei[0],e.Al=0|ei[1],e.Bh=0|ei[2],e.Bl=0|ei[3],e.Ch=0|ei[4],e.Cl=0|ei[5],e.Dh=0|ei[6],e.Dl=0|ei[7],e.Eh=0|ei[8],e.El=0|ei[9],e.Fh=0|ei[10],e.Fl=0|ei[11],e.Gh=0|ei[12],e.Gl=0|ei[13],e.Hh=0|ei[14],e.Hl=0|ei[15],(0,ue.default)(e)}return(0,$.default)(n,[{key:"get",value:function(){var e=this;return[e.Ah,e.Al,e.Bh,e.Bl,e.Ch,e.Cl,e.Dh,e.Dl,e.Eh,e.El,e.Fh,e.Fl,e.Gh,e.Gl,e.Hh,e.Hl]}},{key:"set",value:function(e,t,n,r,i,a,o,u,s,l,c,f,d,h,v,p){this.Ah=0|e,this.Al=0|t,this.Bh=0|n,this.Bl=0|r,this.Ch=0|i,this.Cl=0|a,this.Dh=0|o,this.Dl=0|u,this.Eh=0|s,this.El=0|l,this.Fh=0|c,this.Fl=0|f,this.Gh=0|d,this.Gl=0|h,this.Hh=0|v,this.Hl=0|p}},{key:"process",value:function(e,t){for(var n=0;n<16;n++,t+=4)Ei[n]=e.getUint32(t),Si[n]=e.getUint32(t+=4);for(var r=16;r<80;r++){var i=0|Ei[r-15],a=0|Si[r-15],o=oi(i,a,1)^oi(i,a,8)^ii(i,0,7),u=ui(i,a,1)^ui(i,a,8)^ai(i,a,7),s=0|Ei[r-2],l=0|Si[r-2],c=oi(s,l,19)^si(s,l,61)^ii(s,0,6),f=ui(s,l,19)^li(s,l,61)^ai(s,l,6),d=hi(u,f,Si[r-7],Si[r-16]),h=vi(d,o,c,Ei[r-7],Ei[r-16]);Ei[r]=0|h,Si[r]=0|d}for(var v,p,g,y,m,b,w,k,_=this,E=_.Ah,S=_.Al,A=_.Bh,I=_.Bl,x=_.Ch,C=_.Cl,T=_.Dh,P=_.Dl,R=_.Eh,L=_.El,D=_.Fh,M=_.Fl,N=_.Gh,O=_.Gl,U=_.Hh,F=_.Hl,B=0;B<80;B++){var q,z=oi(R,L,14)^oi(R,L,18)^si(R,L,41),j=ui(R,L,14)^ui(R,L,18)^li(R,L,41),K=R&D^~R&N,V=pi(F,j,L&M^~L&O,_i[B],Si[B]),H=gi(V,U,z,K,ki[B],Ei[B]),W=0|V,G=oi(E,S,28)^si(E,S,34)^si(E,S,39),X=ui(E,S,28)^li(E,S,34)^li(E,S,39),Y=E&A^E&x^A&x,Z=S&I^S&C^I&C;U=0|N,F=0|O,N=0|D,O=0|M,D=0|R,M=0|L,R=(q=ci(0|T,0|P,0|H,0|W)).h,L=q.l,T=0|x,P=0|C,x=0|A,C=0|I,A=0|E,I=0|S;var Q=fi(W,X,Z);E=di(Q,H,G,Y),S=0|Q}E=(v=ci(0|this.Ah,0|this.Al,0|E,0|S)).h,S=v.l,A=(p=ci(0|this.Bh,0|this.Bl,0|A,0|I)).h,I=p.l,x=(g=ci(0|this.Ch,0|this.Cl,0|x,0|C)).h,C=g.l,T=(y=ci(0|this.Dh,0|this.Dl,0|T,0|P)).h,P=y.l,R=(m=ci(0|this.Eh,0|this.El,0|R,0|L)).h,L=m.l,D=(b=ci(0|this.Fh,0|this.Fl,0|D,0|M)).h,M=b.l,N=(w=ci(0|this.Gh,0|this.Gl,0|N,0|O)).h,O=w.l,U=(k=ci(0|this.Hh,0|this.Hl,0|U,0|F)).h,F=k.l,this.set(E,S,A,I,x,C,T,P,R,L,D,M,N,O,U,F)}},{key:"roundClean",value:function(){Lr(Ei,Si)}},{key:"destroy",value:function(){Lr(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}]),n}(Jr),Ii=Yr((function(){return new bi})),xi=Yr((function(){return new Ai})),Ci=Ii;function Ti(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"utf8",n=bn[t];if(null==n)throw Error('Unsupported encoding "'.concat(t,'"'));return n.encoder.encode(e).substring(1)}function Pi(e){return"string"==typeof e?wn(e.replace(/^0x/i,"").toLowerCase(),"base16"):e}function Ri(e){var t=new ArrayBuffer(8),n=new DataView(t);return"number"==typeof e?n.setFloat64(0,e,!1):n.setBigInt64(0,e,!1),new Uint8Array(t)}var Li=function(e){return Ti(e,"base16")},Di=function(e){return Ti(e,"utf8")},Mi=function(e){return wn(e,"utf8")};function Ni(e){var t=e.reduce((function(e,t){return e+t.length}),0),n=new Uint8Array(t),r=0,i=!0,a=!1,o=void 0;try{for(var u,s=e[Symbol.iterator]();!(i=(u=s.next()).done);i=!0){var l=u.value;n.set(l,r),r+=l.length}}catch(e){a=!0,o=e}finally{try{i||null==s.return||s.return()}finally{if(a)throw o}}return n}var Oi=function(e,t){return"/waku/2/rs/".concat(e,"/").concat(t)},Ui=function(e){var t=e.split("/");if(6!=t.length||"waku"!==t[1]||"2"!==t[2]||"rs"!==t[3])throw Error("Invalid pubsub topic");var n=parseInt(t[4]),r=parseInt(t[5]);if(isNaN(n)||isNaN(r))throw Error("Invalid clusterId or shard");return{clusterId:n,shard:r}};function Fi(e){var t=e.split("/");if(t.length<5||t.length>6)throw Error("Content topic format is invalid: "+e);var n=0;if(6==t.length){if(n=parseInt(t[1]),isNaN(n))throw Error("Invalid generation field in content topic: "+e);if(n>0)throw Error("Generation greater than 0 is not supported: "+e)}var r=t.splice(-4);if(0==r[0].length)throw Error("Application field cannot be empty: "+e);if(0==r[1].length)throw Error("Version field cannot be empty: "+e);if(0==r[2].length)throw Error("Topic name field cannot be empty: "+e);if(0==r[3].length)throw Error("Encoding field cannot be empty: "+e);return{generation:n,application:r[0],version:r[1],topicName:r[2],encoding:r[3]}}var Bi=function e(t,n,r){"use strict";(0,H.default)(this,e),(0,te.default)(this,"networkConfig",void 0),(0,te.default)(this,"pubsubTopic",void 0),(0,te.default)(this,"shardId",void 0),this.networkConfig=t,this.pubsubTopic=n,this.shardId=r},qi=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(e,r,i,a){var o;return(0,H.default)(this,n),o=t.call(this,e,r,i),(0,te.default)((0,q.default)(o),"networkConfig",void 0),(0,te.default)((0,q.default)(o),"pubsubTopic",void 0),(0,te.default)((0,q.default)(o),"shardId",void 0),(0,te.default)((0,q.default)(o),"contentTopic",void 0),o.networkConfig=e,o.pubsubTopic=r,o.shardId=i,o.contentTopic=a,(0,ue.default)(o)}return(0,$.default)(n,[{key:"clusterId",get:function(){return this.networkConfig.clusterId}},{key:"isAutoSharding",get:function(){return!0}},{key:"isStaticSharding",get:function(){return!1}}],[{key:"fromContentTopic",value:function(e,t){Fi(e);var r=function(e,t){var n=Fi(e),r=n.application,i=n.version,a=Ci(Ni([Mi(r),Mi(i)])),o=new DataView(a.buffer.slice(-8));return Number(o.getBigUint64(0,!1)%BigInt(t))}(e,t.numShardsInCluster);return new n(t,Oi(t.clusterId,r),r,e)}}]),n}(Bi),zi=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(e,r,i){var a;return(0,H.default)(this,n),a=t.call(this,e,r,i),(0,te.default)((0,q.default)(a),"networkConfig",void 0),(0,te.default)((0,q.default)(a),"pubsubTopic",void 0),(0,te.default)((0,q.default)(a),"shardId",void 0),a.networkConfig=e,a.pubsubTopic=r,a.shardId=i,(0,ue.default)(a)}return(0,$.default)(n,[{key:"clusterId",get:function(){return this.networkConfig.clusterId}},{key:"isAutoSharding",get:function(){return!1}},{key:"isStaticSharding",get:function(){return!0}}],[{key:"fromShard",value:function(e,t){return new n(t,Oi(t.clusterId,e),e)}},{key:"fromPubsubTopic",value:function(e,t){var r=Ui(e),i=r.clusterId,a=r.shard;if(i!=t.clusterId)throw"Pubsub topic does not match network config's cluster id";return new n(t,e,a)}}]),n}(Bi);function ji(e,t){if("clusterId"in(n=e)&&"numShardsInCluster"in n){if(t.contentTopic)return qi.fromContentTopic(t.contentTopic,e);throw Error("AutoSharding requires contentTopic")}if(void 0!==t.shardId)return zi.fromShard(t.shardId,e);if(t.pubsubTopic)return zi.fromPubsubTopic(t.pubsubTopic,e);var n;throw Error("StaticSharding requires shardId or pubsubTopic")}var Ki=function(e){if((e=new Uint8Array(e)).length<3)throw Error("Insufficient data");var t=new DataView(e.buffer),n=t.getUint16(0),r=[];if(130===e.length)for(var i=0;i<1024;i++){var a=Math.floor(i/8)+2,o=7-i%8;t.getUint8(a)&1<<o&&r.push(i)}else for(var u=t.getUint8(2),s=0,l=3;s<u;s++,l+=2){if(l+1>=e.length)throw Error("Unexpected end of data");r.push(t.getUint16(l))}return{clusterId:n,shards:r}},Vi=function(e){var t=e.clusterId,n=e.shards,r=n.length>=64?130:3+2*n.length,i=new ArrayBuffer(r),a=new DataView(i),o=!0,u=!1,s=void 0;if(a.setUint16(0,t),n.length>=64)try{for(var l,c=n[Symbol.iterator]();!(o=(l=c.next()).done);o=!0){var f=l.value,d=Math.floor(f/8)+2,h=7-f%8;a.setUint8(d,a.getUint8(d)|1<<h)}}catch(e){u=!0,s=e}finally{try{o||null==c.return||c.return()}finally{if(u)throw s}}else{a.setUint8(2,n.length);for(var v=0,p=3;v<n.length;v++,p+=2)a.setUint16(p,n[v])}return new Uint8Array(i)},Hi=Symbol.for("@libp2p/connection"),Wi=Symbol.for("@libp2p/content-routing"),Gi=Symbol.for("@libp2p/peer-discovery"),Xi=Symbol.for("@libp2p/peer-id");function Yi(e){return!!(null==e?void 0:e[Xi])}var Zi,Qi=Symbol.for("@libp2p/peer-routing"),Ji="keep-alive",$i=Symbol.for("@libp2p/transport");!function(e){e[e.FATAL_ALL=0]="FATAL_ALL",e[e.NO_FATAL=1]="NO_FATAL"}(Zi||(Zi={}));var ea=(P=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"The operation was aborted";return(0,H.default)(this,n),(e=t.call(this,r)).name="AbortError",(0,ue.default)(e)}return n}((0,he.default)(Error)),(0,te.default)(P,"name","AbortError"),P),ta=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Unexpected Peer";return(0,H.default)(this,n),(e=t.call(this,r)).name="UnexpectedPeerError",(0,ue.default)(e)}return n}((0,he.default)(Error));(0,te.default)(ta,"name","UnexpectedPeerError");var na=(R=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Invalid crypto exchange";return(0,H.default)(this,n),(e=t.call(this,r)).name="InvalidCryptoExchangeError",(0,ue.default)(e)}return n}((0,he.default)(Error)),(0,te.default)(R,"name","InvalidCryptoExchangeError"),R),ra=(L=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Invalid parameters";return(0,H.default)(this,n),(e=t.call(this,r)).name="InvalidParametersError",(0,ue.default)(e)}return n}((0,he.default)(Error)),(0,te.default)(L,"name","InvalidParametersError"),L),ia=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Invalid public key";return(0,H.default)(this,n),(e=t.call(this,r)).name="InvalidPublicKeyError",(0,ue.default)(e)}return n}((0,he.default)(Error));(0,te.default)(ia,"name","InvalidPublicKeyError");var aa=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"The connection is closing";return(0,H.default)(this,n),(e=t.call(this,r)).name="ConnectionClosingError",(0,ue.default)(e)}return n}((0,he.default)(Error));(0,te.default)(aa,"name","ConnectionClosingError");var oa=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"The connection is closed";return(0,H.default)(this,n),(e=t.call(this,r)).name="ConnectionClosedError",(0,ue.default)(e)}return n}((0,he.default)(Error));(0,te.default)(oa,"name","ConnectionClosedError");var ua=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Connection failed";return(0,H.default)(this,n),(e=t.call(this,r)).name="ConnectionFailedError",(0,ue.default)(e)}return n}((0,he.default)(Error));(0,te.default)(ua,"name","ConnectionFailedError");var sa=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"The muxer is closed";return(0,H.default)(this,n),(e=t.call(this,r)).name="MuxerClosedError",(0,ue.default)(e)}return n}((0,he.default)(Error));(0,te.default)(sa,"name","MuxerClosedError");var la=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"The stream has been reset";return(0,H.default)(this,n),(e=t.call(this,r)).name="StreamResetError",(0,ue.default)(e)}return n}((0,he.default)(Error));(0,te.default)(la,"name","StreamResetError");var ca=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"The stream is in an invalid state";return(0,H.default)(this,n),(e=t.call(this,r)).name="StreamStateError",(0,ue.default)(e)}return n}((0,he.default)(Error));(0,te.default)(ca,"name","StreamStateError");var fa=(D=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Not found";return(0,H.default)(this,n),(e=t.call(this,r)).name="NotFoundError",(0,ue.default)(e)}return n}((0,he.default)(Error)),(0,te.default)(D,"name","NotFoundError"),D),da=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Invalid PeerID";return(0,H.default)(this,n),(e=t.call(this,r)).name="InvalidPeerIdError",(0,ue.default)(e)}return n}((0,he.default)(Error));(0,te.default)(da,"name","InvalidPeerIdError");var ha=(M=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Invalid multiaddr";return(0,H.default)(this,n),(e=t.call(this,r)).name="InvalidMultiaddrError",(0,ue.default)(e)}return n}((0,he.default)(Error)),(0,te.default)(M,"name","InvalidMultiaddrError"),M),va=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Invalid CID";return(0,H.default)(this,n),(e=t.call(this,r)).name="InvalidCIDError",(0,ue.default)(e)}return n}((0,he.default)(Error));(0,te.default)(va,"name","InvalidCIDError");var pa=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Invalid Multihash";return(0,H.default)(this,n),(e=t.call(this,r)).name="InvalidMultihashError",(0,ue.default)(e)}return n}((0,he.default)(Error));(0,te.default)(pa,"name","InvalidMultihashError");var ga=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Unsupported protocol error";return(0,H.default)(this,n),(e=t.call(this,r)).name="UnsupportedProtocolError",(0,ue.default)(e)}return n}((0,he.default)(Error));(0,te.default)(ga,"name","UnsupportedProtocolError");var ya=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Invalid message";return(0,H.default)(this,n),(e=t.call(this,r)).name="InvalidMessageError",(0,ue.default)(e)}return n}((0,he.default)(Error));(0,te.default)(ya,"name","InvalidMessageError");var ma=(N=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Protocol error";return(0,H.default)(this,n),(e=t.call(this,r)).name="ProtocolError",(0,ue.default)(e)}return n}((0,he.default)(Error)),(0,te.default)(N,"name","ProtocolError"),N),ba=(O=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Timed out";return(0,H.default)(this,n),(e=t.call(this,r)).name="TimeoutError",(0,ue.default)(e)}return n}((0,he.default)(Error)),(0,te.default)(O,"name","TimeoutError"),O),wa=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Not started";return(0,H.default)(this,n),(e=t.call(this,r)).name="NotStartedError",(0,ue.default)(e)}return n}((0,he.default)(Error));(0,te.default)(wa,"name","NotStartedError");var ka=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Dial error";return(0,H.default)(this,n),(e=t.call(this,r)).name="DialError",(0,ue.default)(e)}return n}((0,he.default)(Error));(0,te.default)(ka,"name","DialError");var _a=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Limited connection";return(0,H.default)(this,n),(e=t.call(this,r)).name="LimitedConnectionError",(0,ue.default)(e)}return n}((0,he.default)(Error));(0,te.default)(_a,"name","LimitedConnectionError");var Ea=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Too many inbound protocol streams";return(0,H.default)(this,n),(e=t.call(this,r)).name="TooManyInboundProtocolStreamsError",(0,ue.default)(e)}return n}((0,he.default)(Error));(0,te.default)(Ea,"name","TooManyInboundProtocolStreamsError");var Sa=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Too many outbound protocol streams";return(0,H.default)(this,n),(e=t.call(this,r)).name="TooManyOutboundProtocolStreamsError",(0,ue.default)(e)}return n}((0,he.default)(Error));(0,te.default)(Sa,"name","TooManyOutboundProtocolStreamsError");var Aa=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Unsupported key type";return(0,H.default)(this,n),(e=t.call(this,r)).name="UnsupportedKeyTypeError",(0,ue.default)(e)}return n}((0,he.default)(Error));(0,te.default)(Aa,"name","UnsupportedKeyTypeError");var Ia=new WeakMap,xa=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e;return(0,H.default)(this,n),e=t.call(this),(0,G.default)((0,q.default)(e),Ia,{writable:!0,value:new Map}),e}return(0,$.default)(n,[{key:"listenerCount",value:function(e){var t=(0,W.default)(this,Ia).get(e);return null==t?0:t.length}},{key:"addEventListener",value:function(e,t,r){(0,ne.default)((0,re.default)(n.prototype),"addEventListener",this).call(this,e,t,r);var i,a=(0,W.default)(this,Ia).get(e);null==a&&(a=[],(0,W.default)(this,Ia).set(e,a)),a.push({callback:t,once:null!==(i=!0!==r&&!1!==r&&(null==r?void 0:r.once))&&void 0!==i&&i})}},{key:"removeEventListener",value:function(e,t,r){(0,ne.default)((0,re.default)(n.prototype),"removeEventListener",this).call(this,e.toString(),null!=t?t:null,r);var i=(0,W.default)(this,Ia).get(e);null!=i&&(i=i.filter((function(e){return e.callback!==t})),(0,W.default)(this,Ia).set(e,i))}},{key:"dispatchEvent",value:function(e){var t=(0,ne.default)((0,re.default)(n.prototype),"dispatchEvent",this).call(this,e),r=(0,W.default)(this,Ia).get(e.type);return null==r||(r=r.filter((function(e){return!e.once})),(0,W.default)(this,Ia).set(e.type,r)),t}},{key:"safeDispatchEvent",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.dispatchEvent(new CustomEvent(e,t))}}]),n}((0,he.default)(EventTarget));function Ca(e){return null!=e&&"function"==typeof e.start&&"function"==typeof e.stop}var Ta=Symbol.for("@libp2p/service-capabilities"),Pa=Symbol.for("@libp2p/service-dependencies"),Ra="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:void 0!==e?e:"undefined"!=typeof self?self:{};function La(e){return e&&e.__esModule&&{}.hasOwnProperty.call(e,"default")?e.default:e}var Da,Ma,Na,Oa,Ua,Fa={exports:{}};var Ba=(Ua||(Ua=1,function(e,t){t.formatArgs=function(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),this.useColors){var n="color: "+this.color;t.splice(1,0,n,"color: inherit");var r=0,i=0;t[0].replace(/%[a-zA-Z%]/g,(function(e){"%%"!==e&&(r++,"%c"===e&&(i=r))})),t.splice(i,0,n)}},t.save=function(e){try{e?t.storage.setItem("debug",e):t.storage.removeItem("debug")}catch(e){}},t.load=function(){var e;try{e=t.storage.getItem("debug")||t.storage.getItem("DEBUG")}catch(e){}return!e&&void 0!==ge&&"env"in ge&&(e=void 0),e},t.useColors=function(){return!("undefined"==typeof window||!window.process||"renderer"!==window.process.type&&!window.process.__nwjs)||("undefined"==typeof navigator||!navigator.userAgent||!navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))&&("undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&(e=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(e[1],10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));var e},t.storage=function(){try{return localStorage}catch(e){}}(),t.destroy=function(){var e=!1;return function(){e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}}(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],t.log=console.debug||console.log||function(){},e.exports=(Oa||(Oa=1,Na=function(e){var t=function(e,t){var n=r(this.namespace+(void 0===t?":":t)+e);return n.log=this.log,n},n=function(e,t){for(var n=0,r=0,i=-1,a=0;n<e.length;)if(r<t.length&&(t[r]===e[n]||"*"===t[r]))"*"===t[r]?(i=r,a=n,r++):(n++,r++);else{if(-1===i)return!1;r=i+1,n=++a}for(;r<t.length&&"*"===t[r];)r++;return r===t.length};function r(e){var n,i,a,o=null;function u(){for(var e=arguments.length,t=new Array(e),i=0;i<e;i++)t[i]=arguments[i];if(u.enabled){var a=u,o=Number(new Date),s=o-(n||o);a.diff=s,a.prev=n,a.curr=o,n=o,t[0]=r.coerce(t[0]),"string"!=typeof t[0]&&t.unshift("%O");var l=0;t[0]=t[0].replace(/%([a-zA-Z%])/g,(function(e,n){if("%%"===e)return"%";l++;var i=r.formatters[n];if("function"==typeof i){var o=t[l];e=i.call(a,o),t.splice(l,1),l--}return e})),r.formatArgs.call(a,t),(a.log||r.log).apply(a,t)}}return u.namespace=e,u.useColors=r.useColors(),u.color=r.selectColor(e),u.extend=t,u.destroy=r.destroy,Object.defineProperty(u,"enabled",{enumerable:!0,configurable:!1,get:function(){return null!==o?o:(i!==r.namespaces&&(i=r.namespaces,a=r.enabled(e)),a)},set:function(e){o=e}}),"function"==typeof r.init&&r.init(u),u}return r.debug=r,r.default=r,r.coerce=function(e){return e instanceof Error?e.stack||e.message:e},r.disable=function(){var e=(0,ce.default)(r.names).concat((0,ce.default)(r.skips.map((function(e){return"-"+e})))).join(",");return r.enable(""),e},r.enable=function(e){r.save(e),r.namespaces=e,r.names=[],r.skips=[];var t=("string"==typeof e?e:"").trim().replace(/\s+/g,",").split(",").filter(Boolean),n=!0,i=!1,a=void 0;try{for(var o,u=t[Symbol.iterator]();!(n=(o=u.next()).done);n=!0){var s=o.value;"-"===s[0]?r.skips.push(s.slice(1)):r.names.push(s)}}catch(e){i=!0,a=e}finally{try{n||null==u.return||u.return()}finally{if(i)throw a}}},r.enabled=function(e){var t=!0,i=!1,a=void 0;try{for(var o,u=r.skips[Symbol.iterator]();!(t=(o=u.next()).done);t=!0){var s=o.value;if(n(e,s))return!1}}catch(e){i=!0,a=e}finally{try{t||null==u.return||u.return()}finally{if(i)throw a}}var l=!0,c=!1,f=void 0;try{for(var d,h=r.names[Symbol.iterator]();!(l=(d=h.next()).done);l=!0){var v=d.value;if(n(e,v))return!0}}catch(e){c=!0,f=e}finally{try{l||null==h.return||h.return()}finally{if(c)throw f}}return!1},r.humanize=function(){var e=function(e,t,n,r){var i=t>=1.5*n;return Math.round(e/n)+" "+r+(i?"s":"")};if(Ma)return Da;Ma=1;var t=1e3,n=6e4,r=60*n,i=24*r,a=7*i;return Da=function(o,u){u=u||{};var s=void 0===o?"undefined":(0,fe.default)(o);if("string"===s&&o.length>0)return function(e){if(!((e+="").length>100)){var o=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(o){var u=parseFloat(o[1]);switch((o[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return 315576e5*u;case"weeks":case"week":case"w":return u*a;case"days":case"day":case"d":return u*i;case"hours":case"hour":case"hrs":case"hr":case"h":return u*r;case"minutes":case"minute":case"mins":case"min":case"m":return u*n;case"seconds":case"second":case"secs":case"sec":case"s":return u*t;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return u;default:return}}}}(o);if("number"===s&&isFinite(o))return u.long?function(a){var o=Math.abs(a);return o>=i?e(a,o,i,"day"):o>=r?e(a,o,r,"hour"):o>=n?e(a,o,n,"minute"):o>=t?e(a,o,t,"second"):a+" ms"}(o):function(e){var a=Math.abs(e);return a>=i?Math.round(e/i)+"d":a>=r?Math.round(e/r)+"h":a>=n?Math.round(e/n)+"m":a>=t?Math.round(e/t)+"s":e+"ms"}(o);throw Error("val is not a non-empty string or a valid number. val="+JSON.stringify(o))},Da}(),r.destroy=function(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")},Object.keys(e).forEach((function(t){r[t]=e[t]})),r.names=[],r.skips=[],r.formatters={},r.selectColor=function(e){for(var t=0,n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n),t|=0;return r.colors[Math.abs(t)%r.colors.length]},r.enable(r.load()),r}),Na)(t),e.exports.formatters.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}(Fa,Fa.exports)),Fa.exports),qa=La(Ba),za="waku",ja=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"_info",void 0),(0,te.default)(this,"_warn",void 0),(0,te.default)(this,"_error",void 0),this._info=qa(e.createDebugNamespace("info",t)),this._warn=qa(e.createDebugNamespace("warn",t)),this._error=qa(e.createDebugNamespace("error",t))}return(0,$.default)(e,[{key:"info",get:function(){return this._info}},{key:"warn",get:function(){return this._warn}},{key:"error",get:function(){return this._error}},{key:"log",value:function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];(this[e]||this.log).apply(this,(0,ce.default)(n))}}],[{key:"createDebugNamespace",value:function(e,t){return t?"".concat(za,":").concat(t,":").concat(e):"".concat(za,":").concat(e)}}]),e}();function Ka(e,t){var n=Mi(e),r=Mi(t.contentTopic),i=function(e){if(e)return Ri("bigint"==(void 0===e?"undefined":(0,fe.default)(e))?e:1000000n*BigInt(e.valueOf()))}(t.timestamp),a=Ni([n,t.payload,r,t.meta,i].filter(Sr));return Ci(a)}var Va=new ja("message:version-0"),Ha=BigInt(1e6),Wa=function(){"use strict";function e(t,n){(0,H.default)(this,e),(0,te.default)(this,"pubsubTopic",void 0),(0,te.default)(this,"proto",void 0),(0,te.default)(this,"_hash",void 0),(0,te.default)(this,"_hashStr",void 0),this.pubsubTopic=t,this.proto=n}return(0,$.default)(e,[{key:"ephemeral",get:function(){return!!this.proto.ephemeral}},{key:"payload",get:function(){return this.proto.payload}},{key:"contentTopic",get:function(){return this.proto.contentTopic}},{key:"hash",get:function(){return void 0===this._hash&&(this._hash=Ka(this.pubsubTopic,this.proto)),this._hash}},{key:"hashStr",get:function(){return void 0===this._hashStr&&(this._hashStr=Li(this.hash)),this._hashStr}},{key:"timestamp",get:function(){try{if(this.proto.timestamp){var e=this.proto.timestamp/Ha;return new Date(Number(e))}return}catch(e){return}}},{key:"meta",get:function(){return this.proto.meta}},{key:"version",get:function(){var e;return null!==(e=this.proto.version)&&void 0!==e?e:0}},{key:"rateLimitProof",get:function(){return this.proto.rateLimitProof}}]),e}(),Ga=function(){"use strict";function e(t){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=arguments.length>2?arguments[2]:void 0,i=arguments.length>3?arguments[3]:void 0;if((0,H.default)(this,e),(0,te.default)(this,"contentTopic",void 0),(0,te.default)(this,"ephemeral",void 0),(0,te.default)(this,"routingInfo",void 0),(0,te.default)(this,"metaSetter",void 0),this.contentTopic=t,this.ephemeral=n,this.routingInfo=r,this.metaSetter=i,!t||""===t)throw Error("Content topic must be specified")}return(0,$.default)(e,[{key:"pubsubTopic",get:function(){return this.routingInfo.pubsubTopic}},{key:"toWire",value:function(e){var t=this;return(0,K.default)((function(){var n;return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return n=Dn.encode,[4,t.toProtoObj(e)];case 1:return[2,n.apply(Dn,[r.sent()])]}}))}))()}},{key:"toProtoObj",value:function(e){var t=this;return(0,K.default)((function(){var n,r,i,a;return(0,pe.__generator)(this,(function(o){return r=null!==(n=e.timestamp)&&void 0!==n?n:new Date,i={payload:e.payload,version:0,contentTopic:t.contentTopic,timestamp:BigInt(r.valueOf())*Ha,meta:void 0,rateLimitProof:e.rateLimitProof,ephemeral:t.ephemeral},t.metaSetter?(a=t.metaSetter(i),[2,(0,oe.default)((0,ae.default)({},i),{meta:a})]):[2,i]}))}))()}}]),e}();function Xa(e){var t=e.contentTopic,n=e.routingInfo,r=e.ephemeral,i=e.metaSetter;return new Ga(t,r,n,i)}var Ya,Za,Qa,Ja,$a,eo,to,no=function(){"use strict";function e(t,n){if((0,H.default)(this,e),(0,te.default)(this,"contentTopic",void 0),(0,te.default)(this,"routingInfo",void 0),this.contentTopic=t,this.routingInfo=n,!t||""===t)throw Error("Content topic must be specified")}return(0,$.default)(e,[{key:"pubsubTopic",get:function(){return this.routingInfo.pubsubTopic}},{key:"fromWireToProtoObj",value:function(e){var t,n,r,i,a,o=Dn.decode(e);return Promise.resolve({payload:o.payload,contentTopic:o.contentTopic,version:null!==(t=o.version)&&void 0!==t?t:void 0,timestamp:null!==(n=o.timestamp)&&void 0!==n?n:void 0,meta:null!==(r=o.meta)&&void 0!==r?r:void 0,rateLimitProof:null!==(i=o.rateLimitProof)&&void 0!==i?i:void 0,ephemeral:null!==(a=o.ephemeral)&&void 0!==a&&a})}},{key:"fromProtoObj",value:function(e,t){return(0,K.default)((function(){return(0,pe.__generator)(this,(function(n){return[2,t.version?(Va.error("Failed to decode due to incorrect version, expected:",0,", actual:",t.version),Promise.resolve(void 0)):new Wa(e,t)]}))}))()}}]),e}();(function(e){e[e.SUCCESS=200]="SUCCESS",e[e.BAD_REQUEST=400]="BAD_REQUEST",e[e.PAYLOAD_TOO_LARGE=413]="PAYLOAD_TOO_LARGE",e[e.INVALID_MESSAGE=420]="INVALID_MESSAGE",e[e.UNSUPPORTED_TOPIC=421]="UNSUPPORTED_TOPIC",e[e.TOO_MANY_REQUESTS=429]="TOO_MANY_REQUESTS",e[e.INTERNAL_ERROR=500]="INTERNAL_ERROR",e[e.UNAVAILABLE=503]="UNAVAILABLE",e[e.NO_RLN_PROOF=504]="NO_RLN_PROOF",e[e.NO_PEERS=505]="NO_PEERS"})(Ya||(Ya={})),Ya.SUCCESS,Ya.BAD_REQUEST,Ya.PAYLOAD_TOO_LARGE,Ya.INVALID_MESSAGE,Ya.UNSUPPORTED_TOPIC,Ya.TOO_MANY_REQUESTS,Ya.INTERNAL_ERROR,Ya.UNAVAILABLE,Ya.NO_RLN_PROOF,Ya.NO_PEERS,function(e){e.Relay="relay",e.Store="store",e.LightPush="lightpush",e.Filter="filter"}(Za||(Za={})),function(e){e.GENERIC_FAIL="Generic error",e.DECODE_FAILED="Failed to decode",e.NO_PEER_AVAILABLE="No peer available",e.NO_STREAM_AVAILABLE="No stream available",e.NO_RESPONSE="No response received",e.STREAM_ABORTED="Stream aborted",e.ENCODE_FAILED="Failed to encode",e.EMPTY_PAYLOAD="Payload is empty",e.SIZE_TOO_BIG="Size is too big",e.TOPIC_NOT_CONFIGURED="Topic not configured",e.RLN_PROOF_GENERATION="Proof generation failed",e.REMOTE_PEER_REJECTED="Remote peer rejected",e.BAD_REQUEST="Bad request format",e.PAYLOAD_TOO_LARGE="Message payload exceeds maximum size",e.INVALID_MESSAGE="Message validation failed",e.UNSUPPORTED_TOPIC="Unsupported pubsub topic",e.TOO_MANY_REQUESTS="Rate limit exceeded",e.INTERNAL_ERROR="Internal server error",e.UNAVAILABLE="Service temporarily unavailable",e.NO_RLN_PROOF="RLN proof generation failed",e.NO_PEERS="No relay peers available"}(Qa||(Qa={})),function(e){e.GENERIC_FAIL="Generic error",e.DECODE_FAILED="Failed to decode",e.NO_PEER_AVAILABLE="No peer available",e.NO_STREAM_AVAILABLE="No stream available",e.NO_RESPONSE="No response received",e.STREAM_ABORTED="Stream aborted",e.REMOTE_PEER_REJECTED="Remote peer rejected",e.TOPIC_NOT_CONFIGURED="Topic not configured",e.SUBSCRIPTION_FAILED="Subscription failed",e.UNSUBSCRIBE_FAILED="Unsubscribe failed",e.PING_FAILED="Ping failed",e.TOPIC_DECODER_MISMATCH="Topic decoder mismatch",e.INVALID_DECODER_TOPICS="Invalid decoder topics",e.SUBSCRIPTION_LIMIT_EXCEEDED="Subscription limit exceeded",e.INVALID_CONTENT_TOPIC="Invalid content topic",e.PUSH_MESSAGE_FAILED="Push message failed",e.EMPTY_MESSAGE="Empty message received",e.MISSING_PUBSUB_TOPIC="Pubsub topic missing from push message"}(Ja||(Ja={})),function(e){e.GENERIC_FAIL="Generic error",e.REMOTE_PEER_REJECTED="Remote peer rejected",e.DECODE_FAILED="Failed to decode",e.NO_PEER_AVAILABLE="No peer available",e.NO_STREAM_AVAILABLE="No stream available",e.NO_RESPONSE="No response received",e.ENCODE_FAILED="Failed to encode",e.EMPTY_PAYLOAD="Payload is empty",e.SIZE_TOO_BIG="Size is too big",e.TOPIC_NOT_CONFIGURED="Topic not configured",e.STREAM_ABORTED="Stream aborted",e.RLN_PROOF_GENERATION="Proof generation failed",e.TOPIC_DECODER_MISMATCH="Topic decoder mismatch",e.INVALID_DECODER_TOPICS="Invalid decoder topics"}($a||($a={})),function(e){e.Connection="waku:connection",e.Health="waku:health"}(eo||(eo={})),function(e){e.BOOTSTRAP="bootstrap",e.PEER_EXCHANGE="peer-exchange",e.PEER_CACHE="peer-cache"}(to||(to={}));var ro,io="locked",ao={clusterId:1,numShardsInCluster:8};function oo(e){if(null!=e[Symbol.asyncIterator])return(0,K.default)((function(){var t,n,r,i,a,o,u,s,l;return(0,pe.__generator)(this,(function(c){switch(c.label){case 0:t=[],n=!1,r=!1,c.label=1;case 1:c.trys.push([1,6,7,12]),a=(0,j.default)(e),c.label=2;case 2:return[4,a.next()];case 3:if(!(n=!(o=c.sent()).done))return[3,5];u=o.value,s=u,t.push(s),c.label=4;case 4:return n=!1,[3,2];case 5:return[3,12];case 6:return l=c.sent(),r=!0,i=l,[3,12];case 7:return c.trys.push([7,,10,11]),n&&null!=a.return?[4,a.return()]:[3,9];case 8:c.sent(),c.label=9;case 9:return[3,11];case 10:if(r)throw i;return[7];case 11:return[7];case 12:return[2,t]}}))}))();var t=[],n=!0,r=!1,i=void 0;try{for(var a,o=e[Symbol.iterator]();!(n=(a=o.next()).done);n=!0){var u=a.value;t.push(u)}}catch(e){r=!0,i=e}finally{try{n||null==o.return||o.return()}finally{if(r)throw i}}return t}function uo(e,t){null==t&&(t=e.reduce((function(e,t){return e+t.length}),0));var n=me(t),r=0,i=!0,a=!1,o=void 0;try{for(var u,s=e[Symbol.iterator]();!(i=(u=s.next()).done);i=!0){var l=u.value;n.set(l,r),r+=l.length}}catch(e){a=!0,o=e}finally{try{i||null==s.return||s.return()}finally{if(a)throw o}}return n}function so(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(var n=0;n<e.byteLength;n++)if(e[n]!==t[n])return!1;return!0}!function(e){e.Unhealthy="Unhealthy",e.MinimallyHealthy="MinimallyHealthy",e.SufficientlyHealthy="SufficientlyHealthy"}(ro||(ro={}));var lo=Symbol.for("@achingbrain/uint8arraylist");function co(e,t){if(null==t||t<0)throw new RangeError("index is out of bounds");var n=0,r=!0,i=!1,a=void 0;try{for(var o,u=e[Symbol.iterator]();!(r=(o=u.next()).done);r=!0){var s=o.value,l=n+s.byteLength;if(t<l)return{buf:s,index:t-n};n=l}}catch(e){i=!0,a=e}finally{try{r||null==u.return||u.return()}finally{if(i)throw a}}throw new RangeError("index is out of bounds")}function fo(e){return!!(null==e?void 0:e[lo])}var ho=lo,vo=Symbol.iterator,po=function(){"use strict";function e(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];(0,H.default)(this,e),(0,te.default)(this,"bufs",void 0),(0,te.default)(this,"length",void 0),(0,te.default)(this,ho,!0),this.bufs=[],this.length=0,n.length>0&&this.appendAll(n)}return(0,$.default)(e,[{key:vo,value:function(){return(0,pe.__generator)(this,(function(e){switch(e.label){case 0:return[5,(0,pe.__values)(this.bufs)];case 1:return e.sent(),[2]}}))}},{key:"byteLength",get:function(){return this.length}},{key:"append",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];this.appendAll(t)}},{key:"appendAll",value:function(e){var t=0,n=!0,r=!1,i=void 0;try{for(var a,o=e[Symbol.iterator]();!(n=(a=o.next()).done);n=!0){var u=a.value;if(u instanceof Uint8Array)t+=u.byteLength,this.bufs.push(u);else{var s;if(!fo(u))throw Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");t+=u.byteLength,(s=this.bufs).push.apply(s,(0,ce.default)(u.bufs))}}}catch(e){r=!0,i=e}finally{try{n||null==o.return||o.return()}finally{if(r)throw i}}this.length+=t}},{key:"prepend",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];this.prependAll(t)}},{key:"prependAll",value:function(e){var t=0,n=!0,r=!1,i=void 0;try{for(var a,o=e.reverse()[Symbol.iterator]();!(n=(a=o.next()).done);n=!0){var u=a.value;if(u instanceof Uint8Array)t+=u.byteLength,this.bufs.unshift(u);else{var s;if(!fo(u))throw Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");t+=u.byteLength,(s=this.bufs).unshift.apply(s,(0,ce.default)(u.bufs))}}}catch(e){r=!0,i=e}finally{try{n||null==o.return||o.return()}finally{if(r)throw i}}this.length+=t}},{key:"get",value:function(e){var t=co(this.bufs,e);return t.buf[t.index]}},{key:"set",value:function(e,t){var n=co(this.bufs,e);n.buf[n.index]=t}},{key:"write",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(e instanceof Uint8Array)for(var n=0;n<e.length;n++)this.set(t+n,e[n]);else{if(!fo(e))throw Error("Could not write value, must be an Uint8Array or a Uint8ArrayList");for(var r=0;r<e.length;r++)this.set(t+r,e.get(r))}}},{key:"consume",value:function(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength)return this.bufs=[],void(this.length=0);for(;this.bufs.length>0;){if(!(e>=this.bufs[0].byteLength)){this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift()}}}},{key:"slice",value:function(e,t){var n=this._subList(e,t);return uo(n.bufs,n.length)}},{key:"subarray",value:function(e,t){var n=this._subList(e,t),r=n.bufs,i=n.length;return 1===r.length?r[0]:uo(r,i)}},{key:"sublist",value:function(t,n){var r=this._subList(t,n),i=r.bufs,a=r.length,o=new e;return o.length=a,o.bufs=(0,ce.default)(i),o}},{key:"_subList",value:function(e,t){if(e=null!=e?e:0,t=null!=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(0===e&&t===this.length)return{bufs:this.bufs,length:this.length};for(var n=[],r=0,i=0;i<this.bufs.length;i++){var a=this.bufs[i],o=r,u=o+a.byteLength;if(r=u,!(e>=u)){var s=e>=o&&e<u,l=t>o&&t<=u;if(s&&l){if(e===o&&t===u){n.push(a);break}var c=e-o;n.push(a.subarray(c,c+(t-e)));break}if(s){if(0===e){n.push(a);continue}n.push(a.subarray(e-o))}else{if(l){if(t===u){n.push(a);break}n.push(a.subarray(0,t-o));break}n.push(a)}}}return{bufs:n,length:t-e}}},{key:"indexOf",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(!(fo(e)||e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');var n=e instanceof Uint8Array?e:e.subarray();if(isNaN(t=Number(null!=t?t:0))&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),0===e.length)return t>this.length?this.length:t;var r=n.byteLength;if(0===r)throw new TypeError("search must be at least 1 byte long");for(var i=new Int32Array(256),a=0;a<256;a++)i[a]=-1;for(var o=0;o<r;o++)i[n[o]]=o;for(var u,s=i,l=this.byteLength-n.byteLength,c=n.byteLength-1,f=t;f<=l;f+=u){u=0;for(var d=c;d>=0;d--){var h=this.get(f+d);if(n[d]!==h){u=Math.max(1,d-s[h]);break}}if(0===u)return f}return-1}},{key:"getInt8",value:function(e){var t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}},{key:"setInt8",value:function(e,t){var n=me(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}},{key:"getInt16",value:function(e,t){var n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}},{key:"setInt16",value:function(e,t,n){var r=ye(2);new DataView(r.buffer,r.byteOffset,r.byteLength).setInt16(0,t,n),this.write(r,e)}},{key:"getInt32",value:function(e,t){var n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}},{key:"setInt32",value:function(e,t,n){var r=ye(4);new DataView(r.buffer,r.byteOffset,r.byteLength).setInt32(0,t,n),this.write(r,e)}},{key:"getBigInt64",value:function(e,t){var n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}},{key:"setBigInt64",value:function(e,t,n){var r=ye(8);new DataView(r.buffer,r.byteOffset,r.byteLength).setBigInt64(0,t,n),this.write(r,e)}},{key:"getUint8",value:function(e){var t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}},{key:"setUint8",value:function(e,t){var n=me(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}},{key:"getUint16",value:function(e,t){var n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}},{key:"setUint16",value:function(e,t,n){var r=ye(2);new DataView(r.buffer,r.byteOffset,r.byteLength).setUint16(0,t,n),this.write(r,e)}},{key:"getUint32",value:function(e,t){var n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}},{key:"setUint32",value:function(e,t,n){var r=ye(4);new DataView(r.buffer,r.byteOffset,r.byteLength).setUint32(0,t,n),this.write(r,e)}},{key:"getBigUint64",value:function(e,t){var n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}},{key:"setBigUint64",value:function(e,t,n){var r=ye(8);new DataView(r.buffer,r.byteOffset,r.byteLength).setBigUint64(0,t,n),this.write(r,e)}},{key:"getFloat32",value:function(e,t){var n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}},{key:"setFloat32",value:function(e,t,n){var r=ye(4);new DataView(r.buffer,r.byteOffset,r.byteLength).setFloat32(0,t,n),this.write(r,e)}},{key:"getFloat64",value:function(e,t){var n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}},{key:"setFloat64",value:function(e,t,n){var r=ye(8);new DataView(r.buffer,r.byteOffset,r.byteLength).setFloat64(0,t,n),this.write(r,e)}},{key:"equals",value:function(t){if(null==t)return!1;if(!(t instanceof e))return!1;if(t.bufs.length!==this.bufs.length)return!1;for(var n=0;n<this.bufs.length;n++)if(!so(this.bufs[n],t.bufs[n]))return!1;return!0}}],[{key:"fromUint8Arrays",value:function(t,n){var r=new e;return r.bufs=t,null==n&&(n=t.reduce((function(e,t){return e+t.byteLength}),0)),r.length=n,r}}]),e}();function go(e){return null!=e[Symbol.asyncIterator]}var yo=function(e){var t=Ae(e),n=me(t);return Ce(e,n),yo.bytes=t,n};function mo(e,t){var n,r=function(e){var t;return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:return(t=i(e.byteLength))instanceof Uint8Array?[4,t]:[3,2];case 1:return n.sent(),[3,4];case 2:return[5,(0,pe.__values)(t)];case 3:n.sent(),n.label=4;case 4:return e instanceof Uint8Array?[4,e]:[3,6];case 5:return n.sent(),[3,8];case 6:return[5,(0,pe.__values)(e)];case 7:n.sent(),n.label=8;case 8:return[2]}}))},i=null!==(n=(t=null!=t?t:{}).lengthEncoder)&&void 0!==n?n:yo;return go(e)?(0,de.default)((function(){var t,n,i,a,o,u,s,l;return(0,pe.__generator)(this,(function(c){switch(c.label){case 0:t=!1,n=!1,c.label=1;case 1:c.trys.push([1,7,8,13]),a=(0,j.default)(e),c.label=2;case 2:return[4,(0,V.default)(a.next())];case 3:return(t=!(o=c.sent()).done)?(u=o.value,s=u,[5,(0,pe.__values)((0,z.default)((0,j.default)(r(s)),V.default))]):[3,6];case 4:c.sent(),c.label=5;case 5:return t=!1,[3,2];case 6:return[3,13];case 7:return l=c.sent(),n=!0,i=l,[3,13];case 8:return c.trys.push([8,,11,12]),t&&null!=a.return?[4,a.return()]:[3,10];case 9:c.sent(),c.label=10;case 10:return[3,12];case 11:if(n)throw i;return[7];case 12:return[7];case 13:return[2]}}))}))():function(){var t,n,i,a,o,u,s;return(0,pe.__generator)(this,(function(l){switch(l.label){case 0:t=!0,n=!1,i=void 0,l.label=1;case 1:l.trys.push([1,6,7,8]),a=e[Symbol.iterator](),l.label=2;case 2:return(t=(o=a.next()).done)?[3,5]:(u=o.value,[5,(0,pe.__values)(r(u))]);case 3:l.sent(),l.label=4;case 4:return t=!0,[3,2];case 5:return[3,8];case 6:return s=l.sent(),n=!0,i=s,[3,8];case 7:try{t||null==a.return||a.return()}finally{if(n)throw i}return[7];case 8:return[2]}}))}()}yo.bytes=0,mo.single=function(e,t){var n,r=null!==(n=(t=null!=t?t:{}).lengthEncoder)&&void 0!==n?n:yo;return new po(r(e.byteLength),e)};var bo,wo=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e;return(0,H.default)(this,n),e=t.apply(this,arguments),(0,te.default)((0,q.default)(e),"name","InvalidMessageLengthError"),(0,te.default)((0,q.default)(e),"code","ERR_INVALID_MSG_LENGTH"),e}return n}((0,he.default)(Error)),ko=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e;return(0,H.default)(this,n),e=t.apply(this,arguments),(0,te.default)((0,q.default)(e),"name","InvalidDataLengthError"),(0,te.default)((0,q.default)(e),"code","ERR_MSG_DATA_TOO_LONG"),e}return n}((0,he.default)(Error)),_o=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e;return(0,H.default)(this,n),e=t.apply(this,arguments),(0,te.default)((0,q.default)(e),"name","InvalidDataLengthLengthError"),(0,te.default)((0,q.default)(e),"code","ERR_MSG_LENGTH_TOO_LONG"),e}return n}((0,he.default)(Error)),Eo=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e;return(0,H.default)(this,n),e=t.apply(this,arguments),(0,te.default)((0,q.default)(e),"name","UnexpectedEOFError"),(0,te.default)((0,q.default)(e),"code","ERR_UNEXPECTED_EOF"),e}return n}((0,he.default)(Error));!function(e){e[e.LENGTH=0]="LENGTH",e[e.DATA=1]="DATA"}(bo||(bo={}));var So=function(e){var t=Te(e);return So.bytes=Ae(t),t};function Ao(e,t){var n,r,i,a=function(){var e,n;return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:if(!(o.byteLength>0))return[3,3];if(u===bo.LENGTH)try{if((s=l(o))<0)throw new wo("Invalid message length");if(s>f)throw new ko("Message length too long");e=l.bytes,o.consume(e),null!=(null==t?void 0:t.onLength)&&t.onLength(s),u=bo.DATA}catch(e){if(e instanceof RangeError){if(o.byteLength>c)throw new _o("Message length length too long");return[3,3]}throw e}return u!==bo.DATA?[3,2]:o.byteLength<s?[3,3]:(n=o.sublist(0,s),o.consume(s),null!=(null==t?void 0:t.onData)&&t.onData(n),[4,n]);case 1:r.sent(),u=bo.LENGTH,r.label=2;case 2:return[3,0];case 3:return[2]}}))},o=new po,u=bo.LENGTH,s=-1,l=null!==(n=null==t?void 0:t.lengthDecoder)&&void 0!==n?n:So,c=null!==(r=null==t?void 0:t.maxLengthLength)&&void 0!==r?r:8,f=null!==(i=null==t?void 0:t.maxDataLength)&&void 0!==i?i:4194304;return go(e)?(0,de.default)((function(){var t,n,r,i,u,s,l,c;return(0,pe.__generator)(this,(function(f){switch(f.label){case 0:t=!1,n=!1,f.label=1;case 1:f.trys.push([1,7,8,13]),i=(0,j.default)(e),f.label=2;case 2:return[4,(0,V.default)(i.next())];case 3:return(t=!(u=f.sent()).done)?(s=u.value,l=s,o.append(l),[5,(0,pe.__values)((0,z.default)((0,j.default)(a()),V.default))]):[3,6];case 4:f.sent(),f.label=5;case 5:return t=!1,[3,2];case 6:return[3,13];case 7:return c=f.sent(),n=!0,r=c,[3,13];case 8:return f.trys.push([8,,11,12]),t&&null!=i.return?[4,i.return()]:[3,10];case 9:f.sent(),f.label=10;case 10:return[3,12];case 11:if(n)throw r;return[7];case 12:return[7];case 13:if(o.byteLength>0)throw new Eo("Unexpected end of input");return[2]}}))}))():function(){var t,n,r,i,u,s,l;return(0,pe.__generator)(this,(function(c){switch(c.label){case 0:t=!0,n=!1,r=void 0,c.label=1;case 1:c.trys.push([1,6,7,8]),i=e[Symbol.iterator](),c.label=2;case 2:return(t=(u=i.next()).done)?[3,5]:(s=u.value,o.append(s),[5,(0,pe.__values)(a())]);case 3:c.sent(),c.label=4;case 4:return t=!0,[3,2];case 5:return[3,8];case 6:return l=c.sent(),n=!0,r=l,[3,8];case 7:try{t||null==i.return||i.return()}finally{if(n)throw r}return[7];case 8:if(o.byteLength>0)throw new Eo("Unexpected end of input");return[2]}}))}()}function Io(){var e={};return e.promise=new Promise((function(t,n){e.resolve=t,e.reject=n})),e}So.bytes=0,Ao.fromReader=function(e,t){var n=1;return Ao((0,de.default)((function(){var t,r,i,a;return(0,pe.__generator)(this,(function(o){switch(o.label){case 0:return o.trys.push([0,4,5,6]),[4,(0,V.default)(e.next(n))];case 1:return t=o.sent(),r=t.done,i=t.value,!0===r?[2]:null!=i?[4,i]:[3,3];case 2:o.sent(),o.label=3;case 3:return[3,6];case 4:if("ERR_UNDER_READ"===(a=o.sent()).code)return[2,{done:!0,value:null}];throw a;case 5:return n=1,[7];case 6:return[3,0];case 7:return[2]}}))}))(),(0,oe.default)((0,ae.default)({},null!=t?t:{}),{onLength:function(e){n=e}}))};var xo=function(){"use strict";function e(t){if((0,H.default)(this,e),(0,te.default)(this,"buffer",void 0),(0,te.default)(this,"mask",void 0),(0,te.default)(this,"top",void 0),(0,te.default)(this,"btm",void 0),(0,te.default)(this,"next",void 0),!(t>0)||t-1&t)throw Error("Max size for a FixedFIFO should be a power of two");this.buffer=Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}return(0,$.default)(e,[{key:"push",value:function(e){return void 0===this.buffer[this.top]&&(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}},{key:"shift",value:function(){var e=this.buffer[this.btm];if(void 0!==e)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}},{key:"isEmpty",value:function(){return void 0===this.buffer[this.btm]}}]),e}(),Co=function(){"use strict";function e(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};(0,H.default)(this,e),(0,te.default)(this,"size",void 0),(0,te.default)(this,"hwm",void 0),(0,te.default)(this,"head",void 0),(0,te.default)(this,"tail",void 0),this.hwm=null!==(t=n.splitLimit)&&void 0!==t?t:16,this.head=new xo(this.hwm),this.tail=this.head,this.size=0}return(0,$.default)(e,[{key:"calculateSize",value:function(e){return null!=(null==e?void 0:e.byteLength)?e.byteLength:1}},{key:"push",value:function(e){if(null!=(null==e?void 0:e.value)&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){var t=this.head;this.head=t.next=new xo(2*this.head.buffer.length),this.head.push(e)}}},{key:"shift",value:function(){var e=this.tail.shift();if(void 0===e&&null!=this.tail.next){var t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return null!=(null==e?void 0:e.value)&&(this.size-=this.calculateSize(e.value)),e}},{key:"isEmpty",value:function(){return this.head.isEmpty()}}]),e}(),To=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(e,r){var i;return(0,H.default)(this,n),i=t.call(this,null!=e?e:"The operation was aborted"),(0,te.default)((0,q.default)(i),"type",void 0),(0,te.default)((0,q.default)(i),"code",void 0),i.type="aborted",i.code=null!=r?r:"ABORT_ERR",(0,ue.default)(i)}return n}((0,he.default)(Error));function Po(){return function(e,t){var n,r,i,a,o=(t=null!=t?t:{}).onEnd,u=new Co,s=Io(),l=function(){var t=(0,K.default)((function(){var t,a;return(0,pe.__generator)(this,(function(o){switch(o.label){case 0:return o.trys.push([0,,6,7]),u.isEmpty()?i?(a={done:!0},[3,3]):[3,1]:[3,4];case 1:return[4,new Promise((function(t,i){r=function(a){r=null,u.push(a);try{t(e(u))}catch(e){i(e)}return n}}))];case 2:a=o.sent(),o.label=3;case 3:return t=a,[3,5];case 4:t=e(u),o.label=5;case 5:return[2,t];case 6:return u.isEmpty()&&queueMicrotask((function(){s.resolve(),s=Io()})),[7];case 7:return[2]}}))}));return function(){return t.apply(this,arguments)}}(),c=function(e){return null!=r?r(e):(u.push(e),n)},f=function(e){if(i)return n;if(!0!==(null==t?void 0:t.objectMode)&&null==(null==e?void 0:e.byteLength))throw Error("objectMode was not true but tried to push non-Uint8Array value");return c({done:!1,value:e})},d=function(e){return i?n:(i=!0,null!=e?function(e){return u=new Co,null!=r?r({error:e}):(u.push({error:e}),n)}(e):c({done:!0}))},h={};if(a={},(0,te.default)(a,Symbol.asyncIterator,(function(){return this})),(0,te.default)(a,"next",l),(0,te.default)(a,"return",(function(){return u=new Co,d(),{done:!0}})),(0,te.default)(a,"throw",(function(e){return d(e),{done:!0}})),(0,te.default)(a,"push",f),(0,te.default)(a,"end",d),h.readableLength=h.readableLength||{},h.readableLength.get=function(){return u.size},(0,te.default)(a,"onEmpty",(function(e){return(0,K.default)((function(){var t,n,r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:if(null==(t=null==e?void 0:e.signal)||t.throwIfAborted(),u.isEmpty())return[2];null!=t&&(n=new Promise((function(e,n){r=function(){n(new To)},t.addEventListener("abort",r)}))),i.label=1;case 1:return i.trys.push([1,,3,4]),[4,Promise.race([s.promise,n])];case 2:return i.sent(),[3,4];case 3:return null!=r&&null!=t&&(null==t||t.removeEventListener("abort",r)),[7];case 4:return[2]}}))}))()})),(0,ee.default)(a,h),n=a,null==o)return n;var v,p=n,g={};return v={},(0,te.default)(v,Symbol.asyncIterator,(function(){return this})),(0,te.default)(v,"next",(function(){return p.next()})),(0,te.default)(v,"throw",(function(e){return p.throw(e),null!=o&&(o(e),o=void 0),{done:!0}})),(0,te.default)(v,"return",(function(){return p.return(),null!=o&&(o(),o=void 0),{done:!0}})),(0,te.default)(v,"push",f),(0,te.default)(v,"end",(function(e){return p.end(e),null!=o&&(o(e),o=void 0),n})),g.readableLength=g.readableLength||{},g.readableLength.get=function(){return p.readableLength},(0,te.default)(v,"onEmpty",(function(e){return p.onEmpty(e)})),(0,ee.default)(v,g),n=v}((function(e){var t=e.shift();if(null==t)return{done:!0};if(null!=t.error)throw t.error;return{done:!0===t.done,value:t.value}}),arguments.length>0&&void 0!==arguments[0]?arguments[0]:{})}var Ro=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(e,r,i){var a;return(0,H.default)(this,n),a=t.call(this,null!=e?e:"The operation was aborted"),(0,te.default)((0,q.default)(a),"type",void 0),(0,te.default)((0,q.default)(a),"code",void 0),a.type="aborted",a.name=null!=i?i:"AbortError",a.code=null!=r?r:"ABORT_ERR",(0,ue.default)(a)}return n}((0,he.default)(Error));function Lo(e,t,n){return Do.apply(this,arguments)}function Do(){return Do=(0,K.default)((function(e,t,n){var r,i;return(0,pe.__generator)(this,(function(a){switch(a.label){case 0:if(null==t)return[2,e];if(t.aborted)return[2,(e.catch((function(){})),Promise.reject(new Ro(null==n?void 0:n.errorMessage,null==n?void 0:n.errorCode,null==n?void 0:n.errorName)))];i=new Ro(null==n?void 0:n.errorMessage,null==n?void 0:n.errorCode,null==n?void 0:n.errorName),a.label=1;case 1:return a.trys.push([1,,3,4]),[4,Promise.race([e,new Promise((function(e,n){r=function(){n(i)},t.addEventListener("abort",r)}))])];case 2:return[2,a.sent()];case 3:return null!=r&&t.removeEventListener("abort",r),[7];case 4:return[2]}}))})),Do.apply(this,arguments)}var Mo=Symbol.asyncIterator,No=function(){"use strict";function e(){(0,H.default)(this,e),(0,te.default)(this,"readNext",void 0),(0,te.default)(this,"haveNext",void 0),(0,te.default)(this,"ended",void 0),(0,te.default)(this,"nextResult",void 0),(0,te.default)(this,"error",void 0),this.ended=!1,this.readNext=Io(),this.haveNext=Io()}return(0,$.default)(e,[{key:Mo,value:function(){return this}},{key:"next",value:function(){var e=this;return(0,K.default)((function(){var t;return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:return null==e.nextResult?[4,e.haveNext.promise]:[3,2];case 1:n.sent(),n.label=2;case 2:if(null==e.nextResult)throw Error("HaveNext promise resolved but nextResult was undefined");return t=e.nextResult,[2,(e.nextResult=void 0,e.readNext.resolve(),e.readNext=Io(),t)]}}))}))()}},{key:"throw",value:function(e){var t=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(n){return t.ended=!0,t.error=e,null!=e&&(t.haveNext.promise.catch((function(){})),t.haveNext.reject(e)),[2,{done:!0,value:void 0}]}))}))()}},{key:"return",value:function(){var e=this;return(0,K.default)((function(){var t;return(0,pe.__generator)(this,(function(n){return t={done:!0,value:void 0},[2,(e.ended=!0,e.nextResult=t,e.haveNext.resolve(),t)]}))}))()}},{key:"push",value:function(e,t){var n=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return[4,n._push(e,t)];case 1:return r.sent(),[2]}}))}))()}},{key:"end",value:function(e,t){var n=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return null==e?[3,2]:[4,n.throw(e)];case 1:return r.sent(),[3,4];case 2:return[4,n._push(void 0,t)];case 3:r.sent(),r.label=4;case 4:return[2]}}))}))()}},{key:"_push",value:function(e,t){var n=this;return(0,K.default)((function(){var r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:if(null!=e&&n.ended)throw null!==(r=n.error)&&void 0!==r?r:Error("Cannot push value onto an ended pushable");i.label=1;case 1:return null==n.nextResult?[3,4]:[4,n.readNext.promise];case 2:i.sent(),i.label=3;case 3:return[3,1];case 4:return null!=e?n.nextResult={done:!1,value:e}:(n.ended=!0,n.nextResult={done:!0,value:void 0}),n.haveNext.resolve(),n.haveNext=Io(),[4,Lo(n.readNext.promise,null==t?void 0:t.signal,t)];case 5:return i.sent(),[2]}}))}))()}}]),e}();function Oo(){return new No}function Uo(){return Uo=(0,de.default)((function(e){var t,n;return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:t=new AbortController,n=Oo(),function(){var e=(0,K.default)((function(e,t,n){var r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:return i.trys.push([0,3,,5]),[4,Promise.all(e.map(function(){var e=(0,K.default)((function(e){var r,i,a,o,u,s,l,c;return(0,pe.__generator)(this,(function(f){switch(f.label){case 0:r=!1,i=!1,f.label=1;case 1:f.trys.push([1,7,8,13]),o=(0,j.default)(e),f.label=2;case 2:return[4,o.next()];case 3:return(r=!(u=f.sent()).done)?(s=u.value,l=s,[4,t.push(l,{signal:n})]):[3,6];case 4:f.sent(),n.throwIfAborted(),f.label=5;case 5:return r=!1,[3,2];case 6:return[3,13];case 7:return c=f.sent(),i=!0,a=c,[3,13];case 8:return f.trys.push([8,,11,12]),r&&null!=o.return?[4,o.return()]:[3,10];case 9:f.sent(),f.label=10;case 10:return[3,12];case 11:if(i)throw a;return[7];case 12:return[7];case 13:return[2]}}))}));return function(t){return e.apply(this,arguments)}}()))];case 1:return i.sent(),[4,t.end(void 0,{signal:n})];case 2:case 4:return i.sent(),[3,5];case 3:return r=i.sent(),[4,t.end(r,{signal:n}).catch((function(){}))];case 5:return[2]}}))}));return function(t,n,r){return e.apply(this,arguments)}}()(e,n,t.signal).catch((function(){})),r.label=1;case 1:return r.trys.push([1,,3,4]),[5,(0,pe.__values)((0,z.default)((0,j.default)(n),V.default))];case 2:return r.sent(),[3,4];case 3:return t.abort(),[7];case 4:return[2]}}))})),Uo.apply(this,arguments)}function Fo(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];var r=[],i=!0,a=!1,o=void 0;try{for(var u,s=t[Symbol.iterator]();!(i=(u=s.next()).done);i=!0){var l=u.value;null==l[Symbol.asyncIterator]&&r.push(l)}}catch(e){a=!0,o=e}finally{try{i||null==s.return||s.return()}finally{if(a)throw o}}return r.length===t.length?function(e){var t,n,r,i,a,o,u;return(0,pe.__generator)(this,(function(s){switch(s.label){case 0:t=!0,n=!1,r=void 0,s.label=1;case 1:s.trys.push([1,6,7,8]),i=e[Symbol.iterator](),s.label=2;case 2:return(t=(a=i.next()).done)?[3,5]:(o=a.value,[5,(0,pe.__values)(o)]);case 3:s.sent(),s.label=4;case 4:return t=!0,[3,2];case 5:return[3,8];case 6:return u=s.sent(),n=!0,r=u,[3,8];case 7:try{t||null==i.return||i.return()}finally{if(n)throw r}return[7];case 8:return[2]}}))}(r):function(e){return Uo.apply(this,arguments)}(t)}function Bo(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];if(null==e)throw Error("Empty pipeline");if(Ko(e)){var i=e;e=function(){return i.source}}else if(jo(e)||zo(e)){var a=e;e=function(){return a}}var o=[e].concat((0,ce.default)(n));if(o.length>1&&Ko(o[o.length-1])&&(o[o.length-1]=o[o.length-1].sink),o.length>2)for(var u=1;u<o.length-1;u++)Ko(o[u])&&(o[u]=Vo(o[u]));return qo.apply(void 0,(0,ce.default)(o))}var qo=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];for(var r;t.length>0;)r=t.shift()(r);return r},zo=function(e){return null!=(null==e?void 0:e[Symbol.asyncIterator])},jo=function(e){return null!=(null==e?void 0:e[Symbol.iterator])},Ko=function(e){return null!=e&&null!=e.sink&&null!=e.source},Vo=function(e){return function(t){var n=e.sink(t);if(null!=(null==n?void 0:n.then)){var r,i=Po({objectMode:!0});n.then((function(){i.end()}),(function(e){i.end(e)}));var a=e.source;if(zo(a))r=(0,de.default)((function(){return(0,pe.__generator)(this,(function(e){switch(e.label){case 0:return[5,(0,pe.__values)((0,z.default)((0,j.default)(a),V.default))];case 1:return e.sent(),i.end(),[2]}}))}));else{if(!jo(a))throw Error("Unknown duplex source type - must be Iterable or AsyncIterable");r=function(){return(0,pe.__generator)(this,(function(e){switch(e.label){case 0:return[5,(0,pe.__values)(a)];case 1:return e.sent(),i.end(),[2]}}))}}return Fo(i,r())}return e.source}};function Ho(e){return e.filter((function(e){return"open"===e.status})).sort((function(e,t){return t.timeline.open-e.timeline.open})).at(0)}var Wo,Go="consumed",Xo=function(){"use strict";function e(t,n){var r=this;(0,H.default)(this,e),(0,te.default)(this,"multicodec",void 0),(0,te.default)(this,"libp2p",void 0),(0,te.default)(this,"log",void 0),(0,te.default)(this,"ongoingCreation",new Set),(0,te.default)(this,"streamPool",new Map),(0,te.default)(this,"handlePeerUpdateStreamPool",(function(e){var t=e.detail.peer;t.protocols.includes(r.multicodec)&&(r.getOpenStreamForCodec(t.id)||r.scheduleNewStream(t))})),this.multicodec=t,this.libp2p=n,this.log=new ja("stream-manager:"+t),this.libp2p.events.addEventListener("peer:update",this.handlePeerUpdateStreamPool)}return(0,$.default)(e,[{key:"getStream",value:function(e){var t=this;return(0,K.default)((function(){var n,r,i,a,o;return(0,pe.__generator)(this,(function(u){switch(u.label){case 0:return u.trys.push([0,5,,6]),n=e.toString(),r=t.streamPool.get(n),r?(t.streamPool.delete(n),[4,r]):[3,2];case 1:u.sent(),u.label=2;case 2:return(a=t.getOpenStreamForCodec(e))?[3,4]:[4,t.createStream(e)];case 3:a=u.sent(),u.label=4;case 4:return(i=a)?[2,(t.log.info("Using stream for peerId=".concat(n," multicodec=").concat(t.multicodec)),t.lockStream(n,i),i)]:[2];case 5:return o=u.sent(),[2,void t.log.error("Failed to getStream:",o)];case 6:return[2]}}))}))()}},{key:"createStream",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=this;return(0,K.default)((function(){var r,i,a,o,u;return(0,pe.__generator)(this,(function(s){switch(s.label){case 0:if(!(r=Ho(n.libp2p.connectionManager.getConnections(e))))return[2,void n.log.error("Failed to get a connection to the peer peerId=".concat(e.toString()," multicodec=").concat(n.multicodec))];o=0,s.label=1;case 1:if(!(o<t+1))return[3,6];s.label=2;case 2:return s.trys.push([2,4,,5]),n.log.info("Attempting to create a stream for peerId=".concat(e.toString()," multicodec=").concat(n.multicodec)),[4,r.newStream(n.multicodec)];case 3:return a=s.sent(),n.log.info("Created stream for peerId=".concat(e.toString()," multicodec=").concat(n.multicodec)),[3,6];case 4:return u=s.sent(),i=u,[3,5];case 5:return o++,[3,1];case 6:return a?[2,a]:(n.log.error("Failed to create a new stream for ".concat(e.toString()," -- ")+i),[2])}}))}))()}},{key:"createStreamWithLock",value:function(e){var t=this;return(0,K.default)((function(){var n,r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:return n=e.id.toString(),t.ongoingCreation.has(n)?(t.log.info("Skipping creation of a stream due to lock for peerId=".concat(n," multicodec=").concat(t.multicodec)),[3,5]):[3,1];case 1:return i.trys.push([1,3,4,5]),t.ongoingCreation.add(n),[4,t.createStream(e.id)];case 2:return i.sent(),[3,5];case 3:return r=i.sent(),t.log.error("Failed to createStreamWithLock:",r),[3,5];case 4:return t.ongoingCreation.delete(n),[7];case 5:return[2]}}))}))()}},{key:"scheduleNewStream",value:function(e){this.log.info("Scheduling creation of a stream for peerId=".concat(e.id.toString()," multicodec=").concat(this.multicodec)),this.streamPool.has(e.id.toString())&&this.streamPool.delete(e.id.toString()),this.streamPool.set(e.id.toString(),this.createStreamWithLock(e))}},{key:"getOpenStreamForCodec",value:function(e){var t=this,n=Ho(this.libp2p.connectionManager.getConnections(e));if(n){var r=n.streams.find((function(e){return e.protocol===t.multicodec}));if(r)return["done","closed","closing"].includes(r.writeStatus||"")||this.isStreamLocked(r)?void this.log.info("Stream for peerId=".concat(e.toString()," multicodec=").concat(this.multicodec," is unusable")):(this.log.info("Found open stream for peerId=".concat(e.toString()," multicodec=").concat(this.multicodec)),r);this.log.info("No open stream found for peerId=".concat(e.toString()," multicodec=").concat(this.multicodec))}else this.log.info("No open connection found for peerId=".concat(e.toString()," multicodec=").concat(this.multicodec))}},{key:"lockStream",value:function(e,t){this.log.info("Locking stream for peerId:".concat(e,"\tstreamId:").concat(t.id)),t.metadata[Go]=!0}},{key:"isStreamLocked",value:function(e){return!!e.metadata[Go]}}]),e}(),Yo=new Uint8Array(16);function Zo(){if(!Wo&&!(Wo="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)))throw Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Wo(Yo)}for(var Qo=[],Jo=0;Jo<256;++Jo)Qo.push((Jo+256).toString(16).slice(1));var $o={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function eu(e){if($o.randomUUID&&!e)return $o.randomUUID();var t=(e=e||{}).random||(e.rng||Zo)();return t[6]=15&t[6]|64,t[8]=63&t[8]|128,function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return Qo[e[t+0]]+Qo[e[t+1]]+Qo[e[t+2]]+Qo[e[t+3]]+"-"+Qo[e[t+4]]+Qo[e[t+5]]+"-"+Qo[e[t+6]]+Qo[e[t+7]]+"-"+Qo[e[t+8]]+Qo[e[t+9]]+"-"+Qo[e[t+10]]+Qo[e[t+11]]+Qo[e[t+12]]+Qo[e[t+13]]+Qo[e[t+14]]+Qo[e[t+15]]}(t)}var tu=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"proto",void 0),this.proto=t}return(0,$.default)(e,[{key:"encode",value:function(){return jn.encode(this.proto)}},{key:"wakuMessage",get:function(){return this.proto.wakuMessage}},{key:"pubsubTopic",get:function(){return this.proto.pubsubTopic}}],[{key:"decode",value:function(t){return new e(jn.decode(t))}}]),e}(),nu=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"proto",void 0),this.proto=t}return(0,$.default)(e,[{key:"encode",value:function(){return qn.encode(this.proto)}},{key:"filterSubscribeType",get:function(){return this.proto.filterSubscribeType}},{key:"requestId",get:function(){return this.proto.requestId}},{key:"pubsubTopic",get:function(){return this.proto.pubsubTopic}},{key:"contentTopics",get:function(){return this.proto.contentTopics}}],[{key:"createSubscribeRequest",value:function(t,n){return new e({requestId:eu(),filterSubscribeType:qn.FilterSubscribeType.SUBSCRIBE,pubsubTopic:t,contentTopics:n})}},{key:"createUnsubscribeRequest",value:function(t,n){return new e({requestId:eu(),filterSubscribeType:qn.FilterSubscribeType.UNSUBSCRIBE,pubsubTopic:t,contentTopics:n})}},{key:"createUnsubscribeAllRequest",value:function(t){return new e({requestId:eu(),filterSubscribeType:qn.FilterSubscribeType.UNSUBSCRIBE_ALL,pubsubTopic:t,contentTopics:[]})}},{key:"createSubscriberPingRequest",value:function(){return new e({requestId:eu(),filterSubscribeType:qn.FilterSubscribeType.SUBSCRIBER_PING,pubsubTopic:"",contentTopics:[]})}},{key:"decode",value:function(t){return new e(qn.decode(t))}}]),e}(),ru=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"proto",void 0),this.proto=t}return(0,$.default)(e,[{key:"encode",value:function(){return zn.encode(this.proto)}},{key:"statusCode",get:function(){return this.proto.statusCode}},{key:"statusDesc",get:function(){return this.proto.statusDesc}},{key:"requestId",get:function(){return this.proto.requestId}}],[{key:"decode",value:function(t){return new e(zn.decode(t))}}]),e}(),iu=new ja("filter-core"),au="/vac/waku/filter-subscribe/2.0.0-beta1",ou="/vac/waku/filter-push/2.0.0-beta1",uu=function(){"use strict";function e(t,n){(0,H.default)(this,e),(0,te.default)(this,"handleIncomingMessage",void 0),(0,te.default)(this,"libp2p",void 0),(0,te.default)(this,"streamManager",void 0),(0,te.default)(this,"multicodec",au),this.handleIncomingMessage=t,this.libp2p=n,this.streamManager=new Xo(au,n.components)}return(0,$.default)(e,[{key:"start",value:function(){var e=this;return(0,K.default)((function(){var t;return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,e.libp2p.handle(ou,e.onRequest.bind(e),{maxInboundStreams:100})];case 1:return n.sent(),[3,3];case 2:return t=n.sent(),iu.error("Failed to register ",ou,t),[3,3];case 3:return[2]}}))}))()}},{key:"stop",value:function(){var e=this;return(0,K.default)((function(){var t;return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,e.libp2p.unhandle(ou)];case 1:return n.sent(),[3,3];case 2:return t=n.sent(),iu.error("Failed to unregister ",ou,t),[3,3];case 3:return[2]}}))}))()}},{key:"subscribe",value:function(e,t,n){var r=this;return(0,K.default)((function(){var i,a,o,u,s,l,c,f;return(0,pe.__generator)(this,(function(d){switch(d.label){case 0:return[4,r.streamManager.getStream(t)];case 1:if(!(i=d.sent()))return[2,{success:null,failure:{error:Ja.NO_STREAM_AVAILABLE,peerId:t}}];a=nu.createSubscribeRequest(e,n),d.label=2;case 2:return d.trys.push([2,4,,5]),[4,Bo([a.encode()],mo,i,Ao,function(){var e=(0,K.default)((function(e){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return[4,oo(e)];case 1:return[2,t.sent()]}}))}));return function(t){return e.apply(this,arguments)}}())];case 3:if(!(null==(o=d.sent())?void 0:o.length))throw Error("Received no response from subscription request.");return[3,5];case 4:return u=d.sent(),[2,(iu.error("Failed to send subscribe request",u),{success:null,failure:{error:Ja.GENERIC_FAIL,peerId:t}})];case 5:return s=ru.decode(o[0].slice()),l=s.statusCode,c=s.requestId,f=s.statusDesc,[2,l<200||l>=300?(iu.error("Filter subscribe request ".concat(c," failed with status code ").concat(l,": ").concat(f)),{failure:{error:Ja.REMOTE_PEER_REJECTED,peerId:t},success:null}):{failure:null,success:t}]}}))}))()}},{key:"unsubscribe",value:function(e,t,n){var r=this;return(0,K.default)((function(){var i,a,o;return(0,pe.__generator)(this,(function(u){switch(u.label){case 0:return[4,r.streamManager.getStream(t)];case 1:if(!(i=u.sent()))return[2,(iu.error("Failed to get a stream for remote peer:"+t.toString()),{success:null,failure:{error:Ja.NO_STREAM_AVAILABLE,peerId:t}})];a=nu.createUnsubscribeRequest(e,n),u.label=2;case 2:return u.trys.push([2,4,,5]),[4,Bo([a.encode()],mo,i.sink)];case 3:return u.sent(),[3,5];case 4:return o=u.sent(),[2,(iu.error("Failed to send unsubscribe request",o),{success:null,failure:{error:Ja.GENERIC_FAIL,peerId:t}})];case 5:return[2,{success:t,failure:null}]}}))}))()}},{key:"unsubscribeAll",value:function(e,t){var n=this;return(0,K.default)((function(){var r,i,a,o,u,s;return(0,pe.__generator)(this,(function(l){switch(l.label){case 0:return[4,n.streamManager.getStream(t)];case 1:return(r=l.sent())?[4,Bo([nu.createUnsubscribeAllRequest(e).encode()],mo,r,Ao,function(){var e=(0,K.default)((function(e){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return[4,oo(e)];case 1:return[2,t.sent()]}}))}));return function(t){return e.apply(this,arguments)}}())]:[2,(iu.error("Failed to get a stream for remote peer:"+t.toString()),{success:null,failure:{error:Ja.NO_STREAM_AVAILABLE,peerId:t}})];case 2:return(i=l.sent())&&i.length?(a=ru.decode(i[0].slice()),o=a.statusCode,u=a.requestId,s=a.statusDesc,[2,o<200||o>=300?(iu.error("Filter unsubscribe all request ".concat(u," failed with status code ").concat(o,": ").concat(s)),{failure:{error:Ja.REMOTE_PEER_REJECTED,peerId:t},success:null}):{failure:null,success:t}]):[2,{failure:{error:Ja.NO_RESPONSE,peerId:t},success:null}]}}))}))()}},{key:"ping",value:function(e){var t=this;return(0,K.default)((function(){var n,r,i,a,o,u,s,l;return(0,pe.__generator)(this,(function(c){switch(c.label){case 0:return[4,t.streamManager.getStream(e)];case 1:if(!(n=c.sent()))return[2,(iu.error("Failed to get a stream for remote peer:"+e.toString()),{success:null,failure:{error:Ja.NO_STREAM_AVAILABLE,peerId:e}})];r=nu.createSubscriberPingRequest(),c.label=2;case 2:return c.trys.push([2,4,,5]),[4,Bo([r.encode()],mo,n,Ao,function(){var e=(0,K.default)((function(e){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return[4,oo(e)];case 1:return[2,t.sent()]}}))}));return function(t){return e.apply(this,arguments)}}())];case 3:return i=c.sent(),[3,5];case 4:return a=c.sent(),[2,(iu.error("Failed to send ping request",a),{success:null,failure:{error:Ja.GENERIC_FAIL,peerId:e}})];case 5:return i&&i.length?(o=ru.decode(i[0].slice()),u=o.statusCode,s=o.requestId,l=o.statusDesc,[2,u<200||u>=300?(iu.error("Filter ping request ".concat(s," failed with status code ").concat(u,": ").concat(l)),{success:null,failure:{error:Ja.REMOTE_PEER_REJECTED,peerId:e}}):{success:e,failure:null}]):[2,{success:null,failure:{error:Ja.NO_RESPONSE,peerId:e}}]}}))}))()}},{key:"onRequest",value:function(e){var t=e.connection,n=e.stream,r=t.remotePeer;iu.info("Received message from "+r.toString());try{var i=this;Bo(n,Ao,function(){var e=(0,K.default)((function(e){var n,r,a,o,u,s,l,c,f,d,h;return(0,pe.__generator)(this,(function(v){switch(v.label){case 0:n=!1,r=!1,v.label=1;case 1:v.trys.push([1,7,8,13]),o=(0,j.default)(e),v.label=2;case 2:return[4,o.next()];case 3:return(n=!(u=v.sent()).done)?(s=u.value,l=s,c=tu.decode(l.slice()),f=c.pubsubTopic,(d=c.wakuMessage)?f?[4,i.handleIncomingMessage(f,d,t.remotePeer.toString())]:[2,void iu.error("Pubsub topic missing from push message")]:[2,void iu.error("Received empty message")]):[3,6];case 4:v.sent(),v.label=5;case 5:return n=!1,[3,2];case 6:return[3,13];case 7:return h=v.sent(),r=!0,a=h,[3,13];case 8:return v.trys.push([8,,11,12]),n&&null!=o.return?[4,o.return()]:[3,10];case 9:v.sent(),v.label=10;case 10:return[3,12];case 11:if(r)throw a;return[7];case 12:return[7];case 13:return[2]}}))}));return function(t){return e.apply(this,arguments)}}()).then((function(){iu.info("Receiving pipe closed.")}),function(){var e=(0,K.default)((function(e){return(0,pe.__generator)(this,(function(r){return iu.error("Error with receiving pipe on peer:".concat(t.remotePeer.toString()," -- stream:").concat(n.id," -- protocol:").concat(n.protocol,": "),e),[2]}))}));return function(t){return e.apply(this,arguments)}}())}catch(e){iu.error("Error decoding message",e)}}}]),e}(),su="/vac/waku/lightpush/2.0.0-beta1",lu="/vac/waku/lightpush/3.0.0",cu=su,fu=lu,du=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"proto",void 0),this.proto=t}return(0,$.default)(e,[{key:"encode",value:function(){return Gn.encode(this.proto)}},{key:"query",get:function(){return this.proto.request}},{key:"response",get:function(){return this.proto.response}}],[{key:"createRequest",value:function(t,n){return new e({requestId:eu(),request:{message:t,pubsubTopic:n},response:void 0})}},{key:"decode",value:function(t){return new e(Gn.decode(t))}}]),e}(),hu=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"proto",void 0),this.proto=t}return(0,$.default)(e,[{key:"encode",value:function(){return this.isRequest()?Xn.encode(this.proto):Yn.encode(this.proto)}},{key:"request",get:function(){return this.isRequest()?this.proto:void 0}},{key:"response",get:function(){return this.isResponse()?this.proto:void 0}},{key:"requestId",get:function(){return this.proto.requestId}},{key:"pubsubTopic",get:function(){return this.isRequest()?this.proto.pubsubTopic:void 0}},{key:"message",get:function(){return this.isRequest()?this.proto.message:void 0}},{key:"statusCode",get:function(){return this.isResponse()?this.proto.statusCode:void 0}},{key:"statusDesc",get:function(){return this.isResponse()?this.proto.statusDesc:void 0}},{key:"relayPeerCount",get:function(){return this.isResponse()?this.proto.relayPeerCount:void 0}},{key:"isRequest",value:function(){return"pubsubTopic"in this.proto&&"message"in this.proto}},{key:"isResponse",value:function(){return"statusCode"in this.proto}}],[{key:"createRequest",value:function(t,n){return new e({requestId:eu(),pubsubTopic:n,message:t})}},{key:"createResponse",value:function(t,n,r,i){return new e({requestId:t,statusCode:n,statusDesc:r,relayPeerCount:i})}},{key:"decodeRequest",value:function(t){return new e(Xn.decode(t))}},{key:"decodeResponse",value:function(t){return new e(Yn.decode(t))}}]),e}(),vu=new ja("light-push:protocol-handler"),pu=function(){"use strict";function e(){(0,H.default)(this,e)}return(0,$.default)(e,null,[{key:"preparePushMessage",value:function(t,n,r){return(0,K.default)((function(){var i,a;return(0,pe.__generator)(this,(function(o){switch(o.label){case 0:return o.trys.push([0,3,,4]),n.payload&&0!==n.payload.length?[4,function(){var e=(0,K.default)((function(e,t){var n;return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return[4,e.toWire(t)];case 1:return[2,!!(n=r.sent())&&Ar(n)]}}))}));return function(t,n){return e.apply(this,arguments)}}()(t,n)]:[2,(vu.error("Failed to send waku light push: payload is empty"),{rpc:null,error:Qa.EMPTY_PAYLOAD})];case 1:return o.sent()?[4,t.toProtoObj(n)]:[2,(vu.error("Failed to send waku light push: message is bigger than 1MB"),{rpc:null,error:Qa.SIZE_TOO_BIG})];case 2:return[2,(i=o.sent())?r===lu?(vu.info("Creating v3 RPC message"),{rpc:e.createV3Rpc(i,t.pubsubTopic),error:null}):(vu.info("Creating v2 RPC message"),{rpc:e.createV2Rpc(i,t.pubsubTopic),error:null}):(vu.error("Failed to encode to protoMessage, aborting push"),{rpc:null,error:Qa.ENCODE_FAILED})];case 3:return a=o.sent(),[2,(vu.error("Failed to prepare push message",a),{rpc:null,error:Qa.GENERIC_FAIL})];case 4:return[2]}}))}))()}},{key:"handleResponse",value:function(t,n,r){return n===lu?e.handleV3Response(t,r):e.handleV2Response(t,r)}},{key:"handleV3Response",value:function(e,t){try{var n=hu.decodeResponse(e),r=n.statusCode,i=n.statusDesc;if(r!==Ya.SUCCESS){var a=Qa.REMOTE_PEER_REJECTED;return vu.error("Remote peer rejected with v3 status code ".concat(r,": ").concat(i)),{success:null,failure:{error:a,peerId:t}}}return void 0!==n.relayPeerCount&&vu.info("Message relayed to ".concat(n.relayPeerCount," peers")),{success:t,failure:null}}catch(e){return{success:null,failure:{error:Qa.DECODE_FAILED,peerId:t}}}}},{key:"handleV2Response",value:function(e,t){var n,r;try{n=du.decode(e).response}catch(e){return{success:null,failure:{error:Qa.DECODE_FAILED,peerId:t}}}return n?(r=n.info)&&(r.includes("could not generate rln proof")||r.includes("could not get new message id to generate an rln proof")||r.includes("RLN validation failed"))?(vu.error("Remote peer fault: RLN generation"),{success:null,failure:{error:Qa.RLN_PROOF_GENERATION,peerId:t}}):n.isSuccess?{success:t,failure:null}:(vu.error("Remote peer rejected the message: ",n.info),{success:null,failure:{error:Qa.REMOTE_PEER_REJECTED,peerId:t}}):{success:null,failure:{error:Qa.NO_RESPONSE,peerId:t}}}},{key:"createV2Rpc",value:function(e,t){var n=du.createRequest(e,t);return Object.assign(n,{version:"v2"})}},{key:"createV3Rpc",value:function(e,t){e.timestamp||(e.timestamp=BigInt(Date.now())*BigInt(1e6));var n=hu.createRequest(e,t);return Object.assign(n,{version:"v3"})}}]),e}(),gu=new ja("light-push"),yu=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"libp2p",void 0),(0,te.default)(this,"streamManager",void 0),(0,te.default)(this,"streamManagerV2",void 0),(0,te.default)(this,"multicodec",[lu,su]),this.libp2p=t,this.streamManagerV2=new Xo(su,t.components),this.streamManager=new Xo(lu,t.components)}return(0,$.default)(e,[{key:"send",value:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]&&arguments[3],i=this;return(0,K.default)((function(){var a,o,u,s,l,c,f,d;return(0,pe.__generator)(this,(function(h){switch(h.label){case 0:return[4,i.getProtocol(n,r)];case 1:return a=h.sent(),gu.info("Sending light push request to peer:".concat(n.toString(),", protocol:").concat(a)),a?[4,pu.preparePushMessage(e,t,a)]:[2,{success:null,failure:{error:Qa.GENERIC_FAIL,peerId:n}}];case 2:return o=h.sent(),u=o.rpc,(s=o.error)?[2,{success:null,failure:{error:s,peerId:n}}]:[4,i.getStream(n,a)];case 3:if(!(l=h.sent()))return[2,(gu.error("Failed to get a stream for remote peer:"+n.toString()),{success:null,failure:{error:Qa.NO_STREAM_AVAILABLE,peerId:n}})];h.label=4;case 4:return h.trys.push([4,6,,7]),[4,Bo([u.encode()],mo,l,Ao,function(){var e=(0,K.default)((function(e){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return[4,oo(e)];case 1:return[2,t.sent()]}}))}));return function(t){return e.apply(this,arguments)}}())];case 5:return c=h.sent(),[3,7];case 6:return f=h.sent(),[2,(gu.error("Failed to send waku light push request",f),{success:null,failure:{error:Qa.STREAM_ABORTED,peerId:n}})];case 7:return d=new po,[2,(c.forEach((function(e){return d.append(e)})),0===d.length?{success:null,failure:{error:Qa.NO_RESPONSE,peerId:n}}:pu.handleResponse(d,a,n))]}}))}))()}},{key:"getProtocol",value:function(e,t){var n=this;return(0,K.default)((function(){var r,i;return(0,pe.__generator)(this,(function(a){switch(a.label){case 0:return a.trys.push([0,2,,3]),[4,n.libp2p.peerStore.get(e)];case 1:if(r=a.sent(),t||!r.protocols.includes(lu)&&r.protocols.includes(su))return[2,su];if(r.protocols.includes(lu))return[2,lu];throw Error("No supported protocol found");case 2:return i=a.sent(),[2,void gu.error("Failed to get protocol",i)];case 3:return[2]}}))}))()}},{key:"getStream",value:function(e,t){var n=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(r){switch(t){case su:return[2,n.streamManagerV2.getStream(e)];case lu:return[2,n.streamManager.getStream(e)];default:return[2]}return[2]}))}))()}}]),e}(),mu={payload:new Uint8Array,contentTopic:"",version:void 0,timestamp:void 0,meta:void 0,rateLimitProof:void 0,ephemeral:void 0},bu=864e5,wu=1e6,ku=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"proto",void 0),this.proto=t}return(0,$.default)(e,[{key:"encode",value:function(){return $n.encode(this.proto)}}],[{key:"create",value:function(t){var n=new e((0,oe.default)((0,ae.default)({},t),{contentTopics:t.contentTopics||[],requestId:eu(),timeStart:t.timeStart?BigInt(t.timeStart.getTime()*wu):void 0,timeEnd:t.timeEnd?BigInt(t.timeEnd.getTime()*wu):void 0,messageHashes:t.messageHashes||[],paginationLimit:t.paginationLimit?BigInt(t.paginationLimit):void 0})),r=t.messageHashes&&t.messageHashes.length>0,i=t.contentTopics&&t.contentTopics.length>0,a=t.timeStart||t.timeEnd;if(r){if(i||a)throw Error("Message hash lookup queries cannot include content filter criteria (contentTopics, timeStart, or timeEnd)")}else if(t.pubsubTopic&&(!t.contentTopics||0===t.contentTopics.length)||!t.pubsubTopic&&t.contentTopics&&t.contentTopics.length>0)throw Error("Both pubsubTopic and contentTopics must be set together for content-filtered queries");return n}},{key:"decode",value:function(t){return new e($n.decode(t))}}]),e}(),_u=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"proto",void 0),this.proto=t}return(0,$.default)(e,[{key:"encode",value:function(){return er.encode(this.proto)}},{key:"statusCode",get:function(){return this.proto.statusCode}},{key:"statusDesc",get:function(){return this.proto.statusDesc}},{key:"messages",get:function(){return this.proto.messages}},{key:"paginationCursor",get:function(){return this.proto.paginationCursor}}],[{key:"decode",value:function(t){return new e(er.decode(t))}}]),e}(),Eu=new ja("store"),Su="/vac/waku/store-query/3.0.0",Au=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"streamManager",void 0),(0,te.default)(this,"multicodec",Su),this.streamManager=new Xo(Su,t.components)}return(0,$.default)(e,[{key:"maxTimeLimit",get:function(){return bu}},{key:"queryPerPage",value:function(e,t,n){var r=this;return(0,de.default)((function(){var i,a,o,u,s,l,c,f,d,h;return(0,pe.__generator)(this,(function(v){switch(v.label){case 0:if(e.timeStart&&e.timeEnd&&e.timeEnd.getTime()-e.timeStart.getTime()>bu)throw Error("Time range bigger than 24h");if(!(e.messageHashes&&e.messageHashes.length>0)&&e.contentTopics&&e.contentTopics.toString()!==Array.from(t.keys()).toString())throw Error("Internal error, the decoders should match the query's content topics");i=e.paginationCursor,v.label=1;case 1:return u=ku.create((0,oe.default)((0,ae.default)({},e),{paginationCursor:i})),Eu.info("Sending store query request:",{hasMessageHashes:!!(null===(a=e.messageHashes)||void 0===a?void 0:a.length),messageHashCount:null===(o=e.messageHashes)||void 0===o?void 0:o.length,pubsubTopic:e.pubsubTopic,contentTopics:e.contentTopics}),[4,(0,V.default)(r.streamManager.getStream(n))];case 2:return(s=v.sent())?[4,(0,V.default)(Bo([u.encode()],mo,s,Ao,function(){var e=(0,K.default)((function(e){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return[4,oo(e)];case 1:return[2,t.sent()]}}))}));return function(t){return e.apply(this,arguments)}}()))]:(Eu.error("Failed to get a stream for remote peer:"+n.toString()),[3,6]);case 3:if(l=v.sent(),c=new po,l.forEach((function(e){c.append(e)})),!(f=_u.decode(c)).statusCode||f.statusCode>=300)throw d="Store query failed with status code: ".concat(f.statusCode,", description: ").concat(f.statusDesc),Eu.error(d),Error(d);return f.messages&&f.messages.length?(Eu.info(f.messages.length+" messages retrieved from store"),h=f.messages.map((function(e){if(!e.message)return Promise.resolve(void 0);var n,r=e.message.contentTopic;if(r){var i=t.get(r);if(i)return i.fromProtoObj(e.pubsubTopic||"",(n=e.message,(0,ae.default)({},mu,n)))}return Promise.resolve(void 0)})),[4,h]):(Eu.warn("Stopping pagination due to empty messages in response"),[3,6]);case 4:if(v.sent(),i=e.paginationForward?f.messages[f.messages.length-1].messageHash:f.messages[0].messageHash,f.messages.length>100&&f.messages.length<(e.paginationLimit||20))return[3,6];v.label=5;case 5:return[3,1];case 6:return[2]}}))}))()}}]),e}(),Iu=parseInt("11111",2),xu=parseInt("10000000",2),Cu=parseInt("01111111",2),Tu={0:Lu,1:Lu,2:function(e,t){for(var n=Ru(e,t),r=t.offset,i=t.offset+n,a=[],o=r;o<i;o++)o===r&&0===e[o]||a.push(e[o]);return t.offset+=n,Uint8Array.from(a)},3:function(e,t){var n=Ru(e,t),r=e[t.offset];t.offset++;var i=e.subarray(t.offset,t.offset+n-1);if(t.offset+=n,0!==r)throw Error("Unused bits in bit string is unimplemented");return i},4:function(e,t){var n=Ru(e,t),r=e.subarray(t.offset,t.offset+n);return t.offset+=n,r},5:function(e,t){return t.offset++,null},6:function(e,t){var n=Ru(e,t),r=t.offset+n,i=e[t.offset];t.offset++;var a=0,o=0;i<40?(a=0,o=i):i<80?(a=1,o=i-40):(a=2,o=i-80);for(var u="".concat(a,".").concat(o),s=[];t.offset<r;){var l=e[t.offset];if(t.offset++,s.push(127&l),l<128){s.reverse();for(var c=0,f=0;f<s.length;f++)c+=s[f]<<7*f;u+="."+c,s=[]}}return u},16:Lu,22:Lu,48:Lu};function Pu(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{offset:0},n=e[t.offset]&Iu;if(t.offset++,null!=Tu[n])return Tu[n](e,t);throw Error("No decoder for tag "+n)}function Ru(e,t){var n=0;if((e[t.offset]&xu)===xu){var r=e[t.offset]&Cu,i="0x";t.offset++;for(var a=0;a<r;a++,t.offset++)i+=e[t.offset].toString(16).padStart(2,"0");n=parseInt(i,16)}else n=e[t.offset],t.offset++;return n}function Lu(e,t){Ru(e,t);for(var n=[];!(t.offset>=e.byteLength);){var r=Pu(e,t);if(null===r)break;n.push(r)}return n}function Du(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);var t=function(e){var t=e.toString(16);t.length%2==1&&(t="0"+t);for(var n=new po,r=0;r<t.length;r+=2)n.append(Uint8Array.from([parseInt("".concat(t[r]).concat(t[r+1]),16)]));return n}(e.byteLength);return new po(Uint8Array.from([t.byteLength|xu]),t)}function Mu(e){var t=new po;return!(128&~e.subarray()[0])&&t.append(Uint8Array.from([0])),t.append(e),new po(Uint8Array.from([2]),Du(t),t)}function Nu(e){var t=Uint8Array.from([0]),n=new po(t,e);return new po(Uint8Array.from([3]),Du(n),n)}function Ou(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:48,n=new po,r=!0,i=!1,a=void 0;try{for(var o,u=e[Symbol.iterator]();!(r=(o=u.next()).done);r=!0){var s=o.value;n.append(s)}}catch(e){i=!0,a=e}finally{try{r||null==u.return||u.return()}finally{if(i)throw a}}return new po(Uint8Array.from([t]),Du(n),n)}var Uu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Fu=Uint8Array.from([6,5,43,129,4,0,34]),Bu=Uint8Array.from([6,5,43,129,4,0,35]),qu={ext:!0,kty:"EC",crv:"P-256"},zu={ext:!0,kty:"EC",crv:"P-384"},ju={ext:!0,kty:"EC",crv:"P-521"},Ku=32,Vu=48,Hu=66;function Wu(e){return function(e){var t,n,r=e[1][1][0];if(65===r.byteLength)return t=Ti(r.subarray(1,1+Ku),"base64url"),n=Ti(r.subarray(1+Ku),"base64url"),new Xu((0,oe.default)((0,ae.default)({},qu),{key_ops:["verify"],x:t,y:n}));if(97===r.byteLength)return t=Ti(r.subarray(1,1+Vu),"base64url"),n=Ti(r.subarray(1+Vu),"base64url"),new Xu((0,oe.default)((0,ae.default)({},zu),{key_ops:["verify"],x:t,y:n}));if(133===r.byteLength)return t=Ti(r.subarray(1,1+Hu),"base64url"),n=Ti(r.subarray(1+Hu),"base64url"),new Xu((0,oe.default)((0,ae.default)({},ju),{key_ops:["verify"],x:t,y:n}));throw new ra("coordinates were wrong length, got ".concat(r.byteLength,", expected 65, 97 or 133"))}(Pu(e))}function Gu(e){if("P-256"===e)return Uu;if("P-384"===e)return Fu;if("P-521"===e)return Bu;throw new ra("Invalid curve "+e)}var Xu=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"type","ECDSA"),(0,te.default)(this,"jwk",void 0),(0,te.default)(this,"_raw",void 0),this.jwk=t}return(0,$.default)(e,[{key:"raw",get:function(){var e,t,n;return null==this._raw&&(this._raw=(e=this.jwk,Ou([Mu(Uint8Array.from([1])),Ou([Gu(e.crv)],160),Ou([Nu(new po(Uint8Array.from([4]),wn(null!==(t=e.x)&&void 0!==t?t:"","base64url"),wn(null!==(n=e.y)&&void 0!==n?n:"","base64url")))],161)]).subarray())),this._raw}},{key:"toMultihash",value:function(){return tn.digest(dc(this))}},{key:"toCID",value:function(){return cn.createV1(114,this.toMultihash())}},{key:"toString",value:function(){return xt.encode(this.toMultihash().bytes).substring(1)}},{key:"equals",value:function(e){return null!=e&&e.raw instanceof Uint8Array&&so(this.raw,e.raw)}},{key:"verify",value:function(e,t,n){var r=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(i){return[2,function(){var e=(0,K.default)((function(e,t,n,r){var i,a,o,u,s;return(0,pe.__generator)(this,(function(l){switch(l.label){case 0:return[4,crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:null!==(o=e.crv)&&void 0!==o?o:"P-256"},!1,["verify"])];case 1:return u=l.sent(),null==r||null===(i=r.signal)||void 0===i||i.throwIfAborted(),[4,crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},u,t,n.subarray())];case 2:return s=l.sent(),[2,(null==r||null===(a=r.signal)||void 0===a||a.throwIfAborted(),s)]}}))}));return function(t,n,r,i){return e.apply(this,arguments)}}()(r.jwk,t,e,n)]}))}))()}}]),e}(),Yu=BigInt(0),Zu=BigInt(1);function Qu(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";if("boolean"!=typeof e)throw Error((t&&'"'.concat(t,'"'))+"expected boolean, got type="+(void 0===e?"undefined":(0,fe.default)(e)));return e}function Ju(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",r=xr(e),i=null==e?void 0:e.length,a=void 0!==t;if(!r||a&&i!==t)throw Error((n&&'"'.concat(n,'" '))+"expected Uint8Array"+(a?" of length "+t:"")+", got "+(r?"length="+i:"type="+(void 0===e?"undefined":(0,fe.default)(e))));return e}function $u(e){var t=e.toString(16);return 1&t.length?"0"+t:t}function es(e){if("string"!=typeof e)throw Error("hex string expected, got "+(void 0===e?"undefined":(0,fe.default)(e)));return""===e?Yu:BigInt("0x"+e)}function ts(e){return es(Ur(e))}function ns(e){return Tr(e),es(Ur(Uint8Array.from(e).reverse()))}function rs(e,t){return Hr(e.toString(16).padStart(2*t,"0"))}function is(e,t){return rs(e,t).reverse()}function as(e,t,n){var r;if("string"==typeof t)try{r=Hr(t)}catch(t){throw Error(e+" must be hex string or Uint8Array, cause: "+t)}else{if(!xr(t))throw Error(e+" must be hex string or Uint8Array");r=Uint8Array.from(t)}var i=r.length;if("number"==typeof n&&i!==n)throw Error(e+" of length "+n+" expected, got "+i);return r}function os(e){return Uint8Array.from(e)}var us=function(e){return"bigint"==(void 0===e?"undefined":(0,fe.default)(e))&&Yu<=e};function ss(e,t,n,r){if(!function(e,t,n){return us(e)&&us(t)&&us(n)&&t<=e&&e<n}(t,n,r))throw Error("expected valid "+e+": "+n+" <= n < "+r+", got "+t)}function ls(e){var t;for(t=0;e>Yu;e>>=Zu,t+=1);return t}var cs=function(e){return(Zu<<BigInt(e))-Zu};function fs(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=function(t,n,r){var i=e[t];if(!r||void 0!==i){var a=void 0===i?"undefined":(0,fe.default)(i);if(a!==n||null===i)throw Error('param "'.concat(t,'" is invalid: expected ').concat(n,", got ").concat(a))}};if(!e||"object"!=typeof e)throw Error("expected valid options object");Object.entries(t).forEach((function(e){var t=(0,se.default)(e,2),n=t[0],i=t[1];return r(n,i,!1)})),Object.entries(n).forEach((function(e){var t=(0,se.default)(e,2),n=t[0],i=t[1];return r(n,i,!0)}))}function ds(e){var t=new WeakMap;return function(n){for(var r=arguments.length,i=new Array(r>1?r-1:0),a=1;a<r;a++)i[a-1]=arguments[a];var o=t.get(n);if(void 0!==o)return o;var u=e.apply(void 0,[n].concat((0,ce.default)(i)));return t.set(n,u),u}}var hs=BigInt(0),vs=BigInt(1),ps=BigInt(2),gs=BigInt(3),ys=BigInt(4),ms=BigInt(5),bs=BigInt(7),ws=BigInt(8),ks=BigInt(9),_s=BigInt(16);function Es(e,t){var n=e%t;return n>=hs?n:t+n}function Ss(e,t,n){for(var r=e;t-- >hs;)r*=r,r%=n;return r}function As(e,t){if(e===hs)throw Error("invert: expected non-zero number");if(t<=hs)throw Error("invert: expected positive modulus, got "+t);for(var n=Es(e,t),r=t,i=hs,a=vs;n!==hs;){var o=r%n,u=i-a*(r/n);r=n,n=o,i=a,a=u}if(r!==vs)throw Error("invert: does not exist");return Es(i,t)}function Is(e,t,n){if(!e.eql(e.sqr(t),n))throw Error("Cannot find square root")}function xs(e,t){var n=(e.ORDER+vs)/ys,r=e.pow(t,n);return Is(e,r,t),r}function Cs(e,t){var n=(e.ORDER-ms)/ws,r=e.mul(t,ps),i=e.pow(r,n),a=e.mul(t,i),o=e.mul(e.mul(a,ps),i),u=e.mul(a,e.sub(o,e.ONE));return Is(e,u,t),u}function Ts(e){if(e<gs)throw Error("sqrt is not defined for small field");for(var t=e-vs,n=0;t%ps===hs;)t/=ps,n++;for(var r=ps,i=Ms(e);1===Ls(i,r);)if(r++>1e3)throw Error("Cannot find square root: probably non-prime P");if(1===n)return xs;var a=i.pow(r,t),o=(t+vs)/ps;return function(e,r){if(e.is0(r))return r;if(1!==Ls(e,r))throw Error("Cannot find square root");for(var i=n,u=e.mul(e.ONE,a),s=e.pow(r,t),l=e.pow(r,o);!e.eql(s,e.ONE);){if(e.is0(s))return e.ZERO;for(var c=1,f=e.sqr(s);!e.eql(f,e.ONE);)if(c++,f=e.sqr(f),c===i)throw Error("Cannot find square root");var d=vs<<BigInt(i-c-1),h=e.pow(u,d);i=c,u=e.sqr(h),s=e.mul(s,u),l=e.mul(l,h)}return l}}var Ps=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Rs(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=Array(t.length).fill(n?e.ZERO:void 0),i=t.reduce((function(t,n,i){return e.is0(n)?t:(r[i]=t,e.mul(t,n))}),e.ONE),a=e.inv(i);return t.reduceRight((function(t,n,i){return e.is0(n)?t:(r[i]=e.mul(t,r[i]),e.mul(t,n))}),a),r}function Ls(e,t){var n=(e.ORDER-vs)/ps,r=e.pow(t,n),i=e.eql(r,e.ONE),a=e.eql(r,e.ZERO),o=e.eql(r,e.neg(e.ONE));if(!i&&!a&&!o)throw Error("invalid Legendre symbol result");return i?1:a?0:-1}function Ds(e,t){void 0!==t&&Cr(t);var n=void 0!==t?t:e.toString(2).length;return{nBitLength:n,nByteLength:Math.ceil(n/8)}}function Ms(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};if(e<=hs)throw Error("invalid field: expected ORDER > 0, got "+e);var i,a,o,u=!1;if("object"==typeof t&&null!=t){if(r.sqrt||n)throw Error("cannot specify opts in two arguments");var s=t;s.BITS&&(i=s.BITS),s.sqrt&&(a=s.sqrt),"boolean"==typeof s.isLE&&(n=s.isLE),"boolean"==typeof s.modFromBytes&&(u=s.modFromBytes),o=s.allowedLengths}else"number"==typeof t&&(i=t),r.sqrt&&(a=r.sqrt);var l,c=Ds(e,i),f=c.nBitLength,d=c.nByteLength;if(d>2048)throw Error("invalid field: expected ORDER of <= 2048 bytes");var h=Object.freeze({ORDER:e,isLE:n,BITS:f,BYTES:d,MASK:cs(f),ZERO:hs,ONE:vs,allowedLengths:o,create:function(t){return Es(t,e)},isValid:function(t){if("bigint"!=(void 0===t?"undefined":(0,fe.default)(t)))throw Error("invalid field element: expected bigint, got "+(void 0===t?"undefined":(0,fe.default)(t)));return hs<=t&&t<e},is0:function(e){return e===hs},isValidNot0:function(e){return!h.is0(e)&&h.isValid(e)},isOdd:function(e){return(e&vs)===vs},neg:function(t){return Es(-t,e)},eql:function(e,t){return e===t},sqr:function(t){return Es(t*t,e)},add:function(t,n){return Es(t+n,e)},sub:function(t,n){return Es(t-n,e)},mul:function(t,n){return Es(t*n,e)},pow:function(e,t){return function(e,t,n){if(n<hs)throw Error("invalid exponent, negatives unsupported");if(n===hs)return e.ONE;if(n===vs)return t;for(var r=e.ONE,i=t;n>hs;)n&vs&&(r=e.mul(r,i)),i=e.sqr(i),n>>=vs;return r}(h,e,t)},div:function(t,n){return Es(t*As(n,e),e)},sqrN:function(e){return e*e},addN:function(e,t){return e+t},subN:function(e,t){return e-t},mulN:function(e,t){return e*t},inv:function(t){return As(t,e)},sqrt:a||function(t){return l||(l=function(e){return e%ys===gs?xs:e%ws===ms?Cs:e%_s===ks?function(e){var t=Ms(e),n=Ts(e),r=n(t,t.neg(t.ONE)),i=n(t,r),a=n(t,t.neg(r)),o=(e+bs)/_s;return function(e,t){var n=e.pow(t,o),u=e.mul(n,r),s=e.mul(n,i),l=e.mul(n,a),c=e.eql(e.sqr(u),t),f=e.eql(e.sqr(s),t);n=e.cmov(n,u,c),u=e.cmov(l,s,f);var d=e.eql(e.sqr(u),t),h=e.cmov(n,u,d);return Is(e,h,t),h}}(e):Ts(e)}(e)),l(h,t)},toBytes:function(e){return n?is(e,d):rs(e,d)},fromBytes:function(t){var r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(o){if(!o.includes(t.length)||t.length>d)throw Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);var i=new Uint8Array(d);i.set(t,n?0:i.length-t.length),t=i}if(t.length!==d)throw Error("Field.fromBytes: expected "+d+" bytes, got "+t.length);var a=n?ns(t):ts(t);if(u&&(a=Es(a,e)),!r&&!h.isValid(a))throw Error("invalid field element: outside of range 0..ORDER");return a},invertBatch:function(e){return Rs(h,e)},cmov:function(e,t,n){return n?t:e}});return Object.freeze(h)}function Ns(e){if("bigint"!=(void 0===e?"undefined":(0,fe.default)(e)))throw Error("field order must be bigint");var t=e.toString(2).length;return Math.ceil(t/8)}function Os(e){var t=Ns(e);return t+Math.ceil(t/2)}var Us=BigInt(0),Fs=BigInt(1);function Bs(e,t){var n=t.negate();return e?n:t}function qs(e,t){var n=Rs(e.Fp,t.map((function(e){return e.Z})));return t.map((function(t,r){return e.fromAffine(t.toAffine(n[r]))}))}function zs(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw Error("invalid window size, expected [1.."+t+"], got W="+e)}function js(e,t){zs(e,t);var n=Math.pow(2,e);return{windows:Math.ceil(t/e)+1,windowSize:Math.pow(2,e-1),mask:cs(e),maxNumber:n,shiftBy:BigInt(e)}}function Ks(e,t,n){var r=n.windowSize,i=n.mask,a=n.maxNumber,o=n.shiftBy,u=Number(e&i),s=e>>o;u>r&&(u-=a,s+=Fs);var l=t*r;return{nextN:s,offset:l+Math.abs(u)-1,isZero:0===u,isNeg:u<0,isNegF:t%2!=0,offsetF:l}}var Vs=new WeakMap,Hs=new WeakMap;function Ws(e){return Hs.get(e)||1}function Gs(e){if(e!==Us)throw Error("invalid wNAF")}var Xs=function(){"use strict";function e(t,n){(0,H.default)(this,e),this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=n}return(0,$.default)(e,[{key:"_unsafeLadder",value:function(e,t){for(var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.ZERO,r=e;t>Us;)t&Fs&&(n=n.add(r)),r=r.double(),t>>=Fs;return n}},{key:"precomputeWindow",value:function(e,t){for(var n=js(t,this.bits),r=n.windows,i=n.windowSize,a=[],o=e,u=o,s=0;s<r;s++){u=o,a.push(u);for(var l=1;l<i;l++)u=u.add(o),a.push(u);o=u.double()}return a}},{key:"wNAF",value:function(e,t,n){if(!this.Fn.isValid(n))throw Error("invalid scalar");for(var r=this.ZERO,i=this.BASE,a=js(e,this.bits),o=0;o<a.windows;o++){var u=Ks(n,o,a),s=u.nextN,l=u.offset,c=u.isZero,f=u.isNeg,d=u.isNegF,h=u.offsetF;n=s,c?i=i.add(Bs(d,t[h])):r=r.add(Bs(f,t[l]))}return Gs(n),{p:r,f:i}}},{key:"wNAFUnsafe",value:function(e,t,n){for(var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:this.ZERO,i=js(e,this.bits),a=0;a<i.windows&&n!==Us;a++){var o=Ks(n,a,i),u=o.nextN,s=o.offset,l=o.isZero,c=o.isNeg;if(n=u,!l){var f=t[s];r=r.add(c?f.negate():f)}}return Gs(n),r}},{key:"getPrecomputes",value:function(e,t,n){var r=Vs.get(t);return r||(r=this.precomputeWindow(t,e),1!==e&&("function"==typeof n&&(r=n(r)),Vs.set(t,r))),r}},{key:"cached",value:function(e,t,n){var r=Ws(e);return this.wNAF(r,this.getPrecomputes(r,e,n),t)}},{key:"unsafe",value:function(e,t,n,r){var i=Ws(e);return 1===i?this._unsafeLadder(e,t,r):this.wNAFUnsafe(i,this.getPrecomputes(i,e,n),t,r)}},{key:"createCache",value:function(e,t){zs(t,this.bits),Hs.set(e,t),Vs.delete(e)}},{key:"hasCache",value:function(e){return 1!==Ws(e)}}]),e}();function Ys(e,t,n,r){!function(e,t){if(!Array.isArray(e))throw Error("array expected");e.forEach((function(e,n){if(!(e instanceof t))throw Error("invalid point at index "+n)}))}(n,e),function(e,t){if(!Array.isArray(e))throw Error("array of scalars expected");e.forEach((function(e,n){if(!t.isValid(e))throw Error("invalid scalar at index "+n)}))}(r,t);var i=n.length,a=r.length;if(i!==a)throw Error("arrays of points and scalars must have equal length");var o=e.ZERO,u=ls(BigInt(i)),s=1;u>12?s=u-3:u>4?s=u-2:u>0&&(s=2);for(var l=cs(s),c=Array(Number(l)+1).fill(o),f=o,d=Math.floor((t.BITS-1)/s)*s;d>=0;d-=s){c.fill(o);for(var h=0;h<a;h++){var v=r[h],p=Number(v>>BigInt(d)&l);c[p]=c[p].add(n[h])}for(var g=o,y=c.length-1,m=o;y>0;y--)m=m.add(c[y]),g=g.add(m);if(f=f.add(g),0!==d)for(var b=0;b<s;b++)f=f.double()}return f}function Zs(e,t,n){if(t){if(t.ORDER!==e)throw Error("Field.ORDER must match order: Fp == p, Fn == n");return function(e){var t=Ps.reduce((function(e,t){return e[t]="function",e}),{ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"});fs(e,t)}(t),t}return Ms(e,{isLE:n})}function Qs(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=arguments.length>3?arguments[3]:void 0;if(void 0===r&&(r="edwards"===e),!t||"object"!=typeof t)throw Error("expected valid ".concat(e," CURVE object"));for(var i=0,a=["p","n","h"];i<a.length;i++){var o=a[i],u=t[o];if(!("bigint"==(void 0===u?"undefined":(0,fe.default)(u))&&u>Us))throw Error("CURVE.".concat(o," must be positive bigint"))}var s=Zs(t.p,n.Fp,r),l=Zs(t.n,n.Fn,r),c=["Gx","Gy","a","weierstrass"===e?"b":"d"],f=!0,d=!1,h=void 0;try{for(var v,p=c[Symbol.iterator]();!(f=(v=p.next()).done);f=!0){var g=v.value;if(!s.isValid(t[g]))throw Error("CURVE.".concat(g," must be valid field element of CURVE.Fp"))}}catch(e){d=!0,h=e}finally{try{f||null==p.return||p.return()}finally{if(d)throw h}}return{CURVE:t=Object.freeze(Object.assign({},t)),Fp:s,Fn:l}}var Js=BigInt(0),$s=BigInt(1),el=BigInt(2),tl=BigInt(8);function nl(e){var t=function(e){var t={a:e.a,d:e.d,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},n={Fp:e.Fp,Fn:Ms(t.n,e.nBitLength,!0),uvRatio:e.uvRatio},r={randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve};return{CURVE:t,curveOpts:n,hash:e.hash,eddsaOpts:r}}(e),n=t.CURVE,r=t.curveOpts,i=t.hash,a=t.eddsaOpts,o=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=function(e,t){return ss("coordinate "+e,t,arguments.length>2&&void 0!==arguments[2]&&arguments[2]?$s:Js,l),t},r=function(e){if(!(e instanceof v))throw Error("ExtendedPoint expected")},i=Qs("edwards",e,t,t.FpFnLE),a=i.Fp,o=i.Fn,u=i.CURVE,s=u.h;fs(t,{},{uvRatio:"function"});var l=el<<BigInt(8*o.BYTES)-$s,c=function(e){return a.create(e)},f=t.uvRatio||function(e,t){try{return{isValid:!0,value:a.sqrt(a.div(e,t))}}catch(e){return{isValid:!1,value:Js}}};if(!function(e,t,n,r){var i=e.sqr(n),a=e.sqr(r),o=e.add(e.mul(t.a,i),a),u=e.add(e.ONE,e.mul(t.d,e.mul(i,a)));return e.eql(o,u)}(a,u,u.Gx,u.Gy))throw Error("bad curve params: generator point");var d=ds((function(e,t){var n=e.X,r=e.Y,i=e.Z,o=e.is0();null==t&&(t=o?tl:a.inv(i));var u=c(n*t),s=c(r*t),l=a.mul(i,t);if(o)return{x:Js,y:$s};if(l!==$s)throw Error("invZ was invalid");return{x:u,y:s}})),h=ds((function(e){var t=u.a,n=u.d;if(e.is0())throw Error("bad point: ZERO");var r=e.X,i=e.Y,a=e.Z,o=e.T,s=c(r*r),l=c(i*i),f=c(a*a),d=c(f*f),h=c(s*t);if(c(f*c(h+l))!==c(d+c(n*c(s*l))))throw Error("bad point: equation left != right (1)");if(c(r*i)!==c(a*o))throw Error("bad point: equation left != right (2)");return!0})),v=function(){"use strict";function e(t,r,i,a){(0,H.default)(this,e),this.X=n("x",t),this.Y=n("y",r),this.Z=n("z",i,!0),this.T=n("t",a),Object.freeze(this)}return(0,$.default)(e,[{key:"x",get:function(){return this.toAffine().x}},{key:"y",get:function(){return this.toAffine().y}},{key:"precompute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:8,t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return p.createCache(this,e),t||this.multiply(el),this}},{key:"assertValidity",value:function(){h(this)}},{key:"equals",value:function(e){r(e);var t=this,n=t.X,i=t.Y,a=t.Z,o=e.X,u=e.Y,s=e.Z,l=c(n*s),f=c(o*a),d=c(i*s),h=c(u*a);return l===f&&d===h}},{key:"is0",value:function(){return this.equals(e.ZERO)}},{key:"negate",value:function(){return new e(c(-this.X),this.Y,this.Z,c(-this.T))}},{key:"double",value:function(){var t=u.a,n=this,r=n.X,i=n.Y,a=n.Z,o=c(r*r),s=c(i*i),l=c(el*c(a*a)),f=c(t*o),d=r+i,h=c(c(d*d)-o-s),v=f+s,p=v-l,g=f-s,y=c(h*p),m=c(v*g),b=c(h*g);return new e(y,m,c(p*v),b)}},{key:"add",value:function(t){r(t);var n=u.a,i=u.d,a=this,o=a.X,s=a.Y,l=a.Z,f=a.T,d=t.X,h=t.Y,v=t.Z,p=t.T,g=c(o*d),y=c(s*h),m=c(f*i*p),b=c(l*v),w=c((o+s)*(d+h)-g-y),k=b-m,_=b+m,E=c(y-n*g),S=c(w*k),A=c(_*E),I=c(w*E);return new e(S,A,c(k*_),I)}},{key:"subtract",value:function(e){return this.add(e.negate())}},{key:"multiply",value:function(t){if(!o.isValidNot0(t))throw Error("invalid scalar: expected 1 <= sc < curve.n");var n=p.cached(this,t,(function(t){return qs(e,t)}));return qs(e,[n.p,n.f])[0]}},{key:"multiplyUnsafe",value:function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e.ZERO;if(!o.isValid(t))throw Error("invalid scalar: expected 0 <= sc < curve.n");return t===Js?e.ZERO:this.is0()||t===$s?this:p.unsafe(this,t,(function(t){return qs(e,t)}),n)}},{key:"isSmallOrder",value:function(){return this.multiplyUnsafe(s).is0()}},{key:"isTorsionFree",value:function(){return p.unsafe(this,u.n).is0()}},{key:"toAffine",value:function(e){return d(this,e)}},{key:"clearCofactor",value:function(){return s===$s?this:this.multiplyUnsafe(s)}},{key:"toBytes",value:function(){var e=this.toAffine(),t=e.x,n=e.y,r=a.toBytes(n);return r[r.length-1]|=t&$s?128:0,r}},{key:"toHex",value:function(){return Ur(this.toBytes())}},{key:"toString",value:function(){return"<Point ".concat(this.is0()?"ZERO":this.toHex(),">")}},{key:"ex",get:function(){return this.X}},{key:"ey",get:function(){return this.Y}},{key:"ez",get:function(){return this.Z}},{key:"et",get:function(){return this.T}},{key:"_setWindowSize",value:function(e){this.precompute(e)}},{key:"toRawBytes",value:function(){return this.toBytes()}}],[{key:"CURVE",value:function(){return u}},{key:"fromAffine",value:function(t){if(t instanceof e)throw Error("extended point not allowed");var r=t||{},i=r.x,a=r.y;return n("x",i),n("y",a),new e(i,a,$s,c(i*a))}},{key:"fromBytes",value:function(t){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=a.BYTES,i=u.a,o=u.d;t=os(Ju(t,r,"point")),Qu(n,"zip215");var s=os(t),d=t[r-1];s[r-1]=-129&d;var h=ns(s),v=n?l:a.ORDER;ss("point.y",h,Js,v);var p=c(h*h),g=c(p-$s),y=c(o*p-i),m=f(g,y),b=m.isValid,w=m.value;if(!b)throw Error("bad point: invalid y coordinate");var k=(w&$s)===$s,_=!!(128&d);if(!n&&w===Js&&_)throw Error("bad point: x=0 and x_0=1");return _!==k&&(w=c(-w)),e.fromAffine({x:w,y:h})}},{key:"fromHex",value:function(t){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return e.fromBytes(as("point",t),n)}},{key:"normalizeZ",value:function(t){return qs(e,t)}},{key:"msm",value:function(t,n){return Ys(e,o,t,n)}}]),e}();v.BASE=new v(u.Gx,u.Gy,$s,c(u.Gx*u.Gy)),v.ZERO=new v(Js,$s,$s,Js),v.Fp=a,v.Fn=o;var p=new Xs(v,o.BITS);return v.BASE.precompute(8),v}(n,r);return function(e,t){var n=t.Point;return Object.assign({},t,{ExtendedPoint:n,CURVE:e,nBitLength:n.Fn.BITS,nByteLength:n.Fn.BYTES})}(e,function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=function(e){return f.create(ns(e))},i=function(e){var n=function(e){var n=y.secretKey;e=as("private key",e,n);var i=as("hashed private key",t(e),2*n),a=h(i.slice(0,n));return{head:a,prefix:i.slice(n,2*n),scalar:r(a)}}(e),i=n.head,a=n.prefix,o=n.scalar,u=l.multiply(o),s=u.toBytes();return{head:i,prefix:a,scalar:o,point:u,pointBytes:s}},a=function(e){return i(e).pointBytes},o=function(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Uint8Array.of(),n=arguments.length,i=new Array(n>1?n-1:0),a=1;a<n;a++)i[a-1]=arguments[a];var o=Gr.apply(void 0,(0,ce.default)(i));return r(t(v(o,as("context",e),!!s)))},u=function(){return Ju(arguments.length>0&&void 0!==arguments[0]?arguments[0]:d(y.seed),y.seed,"seed")};if("function"!=typeof t)throw Error('"hash" function param is required');fs(n,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});var s=n.prehash,l=e.BASE,c=e.Fp,f=e.Fn,d=n.randomBytes||Zr,h=n.adjustScalarBytes||function(e){return e},v=n.domain||function(e,t,n){if(Qu(n,"phflag"),t.length||n)throw Error("Contexts/pre-hash are not supported");return e},p={zip215:!0},g=c.BYTES,y={secretKey:g,publicKey:g,signature:2*g,seed:g},m={getExtendedPublicKey:i,randomSecretKey:u,isValidSecretKey:function(e){return xr(e)&&e.length===f.BYTES},isValidPublicKey:function(t,n){try{return!!e.fromBytes(t,n)}catch(e){return!1}},toMontgomery:function(t){var n=e.fromBytes(t).y,r=y.publicKey,i=32===r;if(!i&&57!==r)throw Error("only defined for 25519 and 448");var a=i?c.div($s+n,$s-n):c.div(n-$s,n+$s);return c.toBytes(a)},toMontgomerySecret:function(e){var n=y.secretKey;Ju(e,n);var r=t(e.subarray(0,n));return h(r).subarray(0,n)},randomPrivateKey:u,precompute:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:8;return(arguments.length>1&&void 0!==arguments[1]?arguments[1]:e.BASE).precompute(t,!1)}};return Object.freeze({keygen:function(e){var t=m.randomSecretKey(e);return{secretKey:t,publicKey:a(t)}},getPublicKey:a,sign:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};e=as("message",e),s&&(e=s(e));var r=i(t),a=r.prefix,u=r.scalar,c=r.pointBytes,d=o(n.context,a,e),h=l.multiply(d).toBytes(),v=o(n.context,h,c,e),p=f.create(d+v*u);if(!f.isValid(p))throw Error("sign failed: invalid s");return Ju(Gr(h,f.toBytes(p)),y.signature,"result")},verify:function(t,n,r){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:p,a=i.context,u=i.zip215,c=y.signature;t=as("signature",t,c),n=as("message",n),r=as("publicKey",r,y.publicKey),void 0!==u&&Qu(u,"zip215"),s&&(n=s(n));var f,d,h,v=c/2,g=t.subarray(0,v),m=ns(t.subarray(v,c));try{f=e.fromBytes(r,u),d=e.fromBytes(g,u),h=l.multiplyUnsafe(m)}catch(e){return!1}if(!u&&f.isSmallOrder())return!1;var b=o(a,d.toBytes(),f.toBytes(),n);return d.add(f.multiplyUnsafe(b)).subtract(h).clearCofactor().is0()},utils:m,Point:e,lengths:y})}(o,i,a))}var rl=BigInt(0),il=BigInt(1),al=BigInt(2);var ol=BigInt(1),ul=BigInt(2),sl=BigInt(3),ll=BigInt(5),cl=BigInt(8),fl=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),dl={p:fl,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:cl,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function hl(e){var t=BigInt(10),n=BigInt(20),r=BigInt(40),i=BigInt(80),a=fl,o=e*e%a*e%a,u=Ss(o,ul,a)*o%a,s=Ss(u,ol,a)*e%a,l=Ss(s,ll,a)*s%a,c=Ss(l,t,a)*l%a,f=Ss(c,n,a)*c%a,d=Ss(f,r,a)*f%a,h=Ss(d,i,a)*d%a,v=Ss(h,i,a)*d%a,p=Ss(v,t,a)*l%a;return{pow_p_5_8:Ss(p,ul,a)*e%a,b2:o}}function vl(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var pl=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function gl(e,t){var n=fl,r=Es(t*t*t,n),i=Es(r*r*t,n),a=Es(e*r*hl(e*i).pow_p_5_8,n),o=Es(t*a*a,n),u=a,s=Es(a*pl,n),l=o===e,c=o===Es(-e,n),f=o===Es(-e*pl,n);return l&&(a=u),(c||f)&&(a=s),(Es(a,n)&vs)===vs&&(a=Es(-a,n)),{isValid:l||c,value:a}}var yl,ml=Ms(dl.p,{isLE:!0}),bl=nl((0,oe.default)((0,ae.default)({},dl),{Fp:ml,hash:xi,adjustScalarBytes:vl,uvRatio:gl})),wl=function(){var e=ml.ORDER;return function(e){var t,n=function(e){return is(k(e),p)},r=function(e,t){var r=function(e,t){ss("u",e,rl,u),ss("scalar",t,m,w);for(var n,r,i=t,o=e,s=il,l=rl,f=e,d=il,h=rl,p=BigInt(v-1);p>=rl;p--){var g,b,_=i>>p&il;s=(g=a(h^=_,s,f)).x_2,f=g.x_3,l=(b=a(h,l,d)).x_2,d=b.x_3,h=_;var E=s+l,S=k(E*E),A=s-l,I=k(A*A),x=S-I,C=f+d,T=k((f-d)*E),P=k(C*A),R=T+P,L=T-P;f=k(R*R),d=k(o*k(L*L)),s=k(S*I),l=k(x*(S+k(y*x)))}s=(n=a(h,s,f)).x_2,f=n.x_3,l=(r=a(h,l,d)).x_2,d=r.x_3;var D=c(l);return k(s*D)}(function(e){var t=as("u coordinate",e,p);return d&&(t[31]&=127),k(ns(t))}(t),function(e){return ns(l(as("scalar",e,p)))}(e));if(r===rl)throw Error("invalid private or public key received");return n(r)},i=function(e){return r(e,_)},a=function(e,t,n){var r=k(e*(t-n));return{x_2:t=k(t-r),x_3:n=k(n+r)}},o=(fs(t=e,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze((0,ae.default)({},t))),u=o.P,s=o.type,l=o.adjustScalarBytes,c=o.powPminus2,f=o.randomBytes,d="x25519"===s;if(!d&&"x448"!==s)throw Error("invalid type");var h=f||Zr,v=d?255:448,p=d?32:56,g=d?BigInt(9):BigInt(5),y=d?BigInt(121665):BigInt(39081),m=d?Math.pow(al,BigInt(254)):Math.pow(al,BigInt(447)),b=d?BigInt(8)*Math.pow(al,BigInt(251))-il:BigInt(4)*Math.pow(al,BigInt(445))-il,w=m+b+il,k=function(e){return Es(e,u)},_=n(g),E={secretKey:p,publicKey:p,seed:p},S=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:h(p);return Tr(e,E.seed),e};return{keygen:function(e){var t=S(e);return{secretKey:t,publicKey:i(t)}},getSharedSecret:function(e,t){return r(e,t)},getPublicKey:function(e){return i(e)},scalarMult:r,scalarMultBase:i,utils:{randomSecretKey:S,randomPrivateKey:S},GuBytes:_.slice(),lengths:E}}({P:e,type:"x25519",powPminus2:function(t){var n=hl(t),r=n.pow_p_5_8,i=n.b2;return Es(Ss(r,sl,e)*i,e)},adjustScalarBytes:vl})}(),kl=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"An error occurred while verifying a message";return(0,H.default)(this,n),(e=t.call(this,r)).name="VerificationError",(0,ue.default)(e)}return n}((0,he.default)(Error)),_l=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Missing Web Crypto API";return(0,H.default)(this,n),(e=t.call(this,r)).name="WebCryptoMissingError",(0,ue.default)(e)}return n}((0,he.default)(Error)),El={get:function(){var e=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:globalThis).crypto;if(null==(null==e?void 0:e.subtle))throw new _l("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");return e}},Sl=(0,K.default)((function(){return(0,pe.__generator)(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,El.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"])];case 1:return[2,(e.sent(),!0)];case 2:return e.sent(),[2,!1];case 3:return[2]}}))}))();function Al(){return Al=(0,K.default)((function(e,t){return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:return null==yl?[4,Sl]:[3,2];case 1:yl=n.sent(),n.label=2;case 2:return[2,yl?function(){var e=(0,K.default)((function(e,t){var n,r,i,a;return(0,pe.__generator)(this,(function(o){switch(o.label){case 0:return n=64===e.length?e.subarray(0,32):e,r={crv:"Ed25519",kty:"OKP",x:Ti(e.subarray(32),"base64url"),d:Ti(n,"base64url"),ext:!0,key_ops:["sign"]},[4,El.get().subtle.importKey("jwk",r,{name:"Ed25519"},!0,["sign"])];case 1:return i=o.sent(),[4,El.get().subtle.sign({name:"Ed25519"},i,t instanceof Uint8Array?t:t.subarray())];case 2:return a=o.sent(),[2,new Uint8Array(a,0,a.byteLength)]}}))}));return function(t,n){return e.apply(this,arguments)}}()(e,t):function(e,t){var n=e.subarray(0,32);return bl.sign(t instanceof Uint8Array?t:t.subarray(),n)}(e,t)]}}))})),Al.apply(this,arguments)}function Il(){return Il=(0,K.default)((function(e,t,n){return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return null==yl?[4,Sl]:[3,2];case 1:yl=r.sent(),r.label=2;case 2:return[2,yl?function(){var e=(0,K.default)((function(e,t,n){var r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:return e.buffer instanceof ArrayBuffer?[4,El.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"])]:[3,3];case 1:return r=i.sent(),[4,El.get().subtle.verify({name:"Ed25519"},r,t,n instanceof Uint8Array?n:n.subarray())];case 2:return[2,i.sent()];case 3:throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}}))}));return function(t,n,r){return e.apply(this,arguments)}}()(e,t,n):function(e,t,n){return bl.verify(t,n instanceof Uint8Array?n:n.subarray(),e)}(e,t,n)]}}))})),Il.apply(this,arguments)}function xl(e){return null!=e&&"function"==typeof e.then&&"function"==typeof e.catch&&"function"==typeof e.finally}var Cl,Tl,Pl,Rl,Ll=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"type","Ed25519"),(0,te.default)(this,"raw",void 0),this.raw=Nl(t,32)}return(0,$.default)(e,[{key:"toMultihash",value:function(){return tn.digest(dc(this))}},{key:"toCID",value:function(){return cn.createV1(114,this.toMultihash())}},{key:"toString",value:function(){return xt.encode(this.toMultihash().bytes).substring(1)}},{key:"equals",value:function(e){return null!=e&&e.raw instanceof Uint8Array&&so(this.raw,e.raw)}},{key:"verify",value:function(e,t,n){var r;null==n||null===(r=n.signal)||void 0===r||r.throwIfAborted();var i=function(e,t,n){return Il.apply(this,arguments)}(this.raw,t,e);return xl(i)?i.then((function(e){var t;return null==n||null===(t=n.signal)||void 0===t||t.throwIfAborted(),e})):i}}]),e}(),Dl=function(){"use strict";function e(t,n){(0,H.default)(this,e),(0,te.default)(this,"type","Ed25519"),(0,te.default)(this,"raw",void 0),(0,te.default)(this,"publicKey",void 0),this.raw=Nl(t,64),this.publicKey=new Ll(n)}return(0,$.default)(e,[{key:"equals",value:function(e){return null!=e&&e.raw instanceof Uint8Array&&so(this.raw,e.raw)}},{key:"sign",value:function(e,t){var n,r;null==t||null===(n=t.signal)||void 0===n||n.throwIfAborted();var i=function(e,t){return Al.apply(this,arguments)}(this.raw,e);return xl(i)?i.then((function(e){var n;return null==t||null===(n=t.signal)||void 0===n||n.throwIfAborted(),e})):(null==t||null===(r=t.signal)||void 0===r||r.throwIfAborted(),i)}}]),e}();function Ml(e){return e=Nl(e,32),new Ll(e)}function Nl(e,t){if((e=Uint8Array.from(null!=e?e:[])).length!==t)throw new ra("Key must be a Uint8Array of length ".concat(t,", got ").concat(e.length));return e}function Ol(e){if(isNaN(e)||e<=0)throw new ra("random bytes length must be a Number bigger than 0");return Zr(e)}(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(Cl||(Cl={})),function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"}(Tl||(Tl={})),(Cl||(Cl={})).codec=function(){return wr(Tl)},function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};!1!==n.lengthDelimited&&t.fork(),null!=e.Type&&(t.uint32(8),Cl.codec().encode(e.Type,t)),null!=e.Data&&(t.uint32(18),t.bytes(e.Data)),!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n={},r=null==t?e.len:e.pos+t;e.pos<r;){var i=e.uint32();switch(i>>>3){case 1:n.Type=Cl.codec().decode(e);break;case 2:n.Data=e.bytes();break;default:e.skipType(7&i)}}return n}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(Pl||(Pl={})),function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};!1!==n.lengthDelimited&&t.fork(),null!=e.Type&&(t.uint32(8),Cl.codec().encode(e.Type,t)),null!=e.Data&&(t.uint32(18),t.bytes(e.Data)),!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n={},r=null==t?e.len:e.pos+t;e.pos<r;){var i=e.uint32();switch(i>>>3){case 1:n.Type=Cl.codec().decode(e);break;case 2:n.Data=e.bytes();break;default:e.skipType(7&i)}}return n}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(Rl||(Rl={}));var Ul=function(){"use strict";function e(t,n){(0,H.default)(this,e),(0,te.default)(this,"type","RSA"),(0,te.default)(this,"jwk",void 0),(0,te.default)(this,"_raw",void 0),(0,te.default)(this,"_multihash",void 0),this.jwk=t,this._multihash=n}return(0,$.default)(e,[{key:"raw",get:function(){return null==this._raw&&(this._raw=function(e){if(null==e.n||null==e.e)throw new ra("JWK was missing components");return Ou([Fl,Nu(Ou([Mu(wn(e.n,"base64url")),Mu(wn(e.e,"base64url"))]))]).subarray()}(this.jwk)),this._raw}},{key:"toMultihash",value:function(){return this._multihash}},{key:"toCID",value:function(){return cn.createV1(114,this._multihash)}},{key:"toString",value:function(){return xt.encode(this.toMultihash().bytes).substring(1)}},{key:"equals",value:function(e){return null!=e&&e.raw instanceof Uint8Array&&so(this.raw,e.raw)}},{key:"verify",value:function(e,t,n){return function(){var e=(0,K.default)((function(e,t,n,r){var i,a,o,u;return(0,pe.__generator)(this,(function(s){switch(s.label){case 0:return[4,El.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"])];case 1:return o=s.sent(),null==r||null===(i=r.signal)||void 0===i||i.throwIfAborted(),[4,El.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,n instanceof Uint8Array?n:n.subarray())];case 2:return u=s.sent(),[2,(null==r||null===(a=r.signal)||void 0===a||a.throwIfAborted(),u)]}}))}));return function(t,n,r,i){return e.apply(this,arguments)}}()(this.jwk,t,e,n)}}]),e}(),Fl=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);var Bl=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(e,r){var i;(0,H.default)(this,n),(i=t.call(this)).finished=!1,i.destroyed=!1,Pr(e);var a=Wr(r);if(i.iHash=e.create(),"function"!=typeof i.iHash.update)throw Error("Expected instance of class which extends utils.Hash");i.blockLen=i.iHash.blockLen,i.outputLen=i.iHash.outputLen;var o=i.blockLen,u=new Uint8Array(o);u.set(a.length>o?e.create().update(a).digest():a);for(var s=0;s<u.length;s++)u[s]^=54;i.iHash.update(u),i.oHash=e.create();for(var l=0;l<u.length;l++)u[l]^=106;return i.oHash.update(u),Lr(u),(0,ue.default)(i)}return(0,$.default)(n,[{key:"update",value:function(e){return Rr(this),this.iHash.update(e),this}},{key:"digestInto",value:function(e){Rr(this),Tr(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}},{key:"digest",value:function(){var e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}},{key:"_cloneInto",value:function(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));var t=this,n=t.oHash,r=t.iHash,i=t.finished,a=t.destroyed,o=t.blockLen,u=t.outputLen;return e.finished=i,e.destroyed=a,e.blockLen=o,e.outputLen=u,e.oHash=n._cloneInto(e.oHash),e.iHash=r._cloneInto(e.iHash),e}},{key:"clone",value:function(){return this._cloneInto()}},{key:"destroy",value:function(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}]),n}(Xr),ql=function(e,t,n){return new Bl(e,t).update(n).digest()};ql.create=function(e,t){return new Bl(e,t)};var zl,jl=function(e,t){return(e+(e>=0?t:-t)/Xl)/t};function Kl(e){if(!["compact","recovered","der"].includes(e))throw Error('Signature format must be "compact", "recovered", or "der"');return e}function Vl(e,t){var n={},r=!0,i=!1,a=void 0;try{for(var o,u=Object.keys(t)[Symbol.iterator]();!(r=(o=u.next()).done);r=!0){var s=o.value;n[s]=void 0===e[s]?t[s]:e[s]}}catch(e){i=!0,a=e}finally{try{r||null==u.return||u.return()}finally{if(i)throw a}}return Qu(n.lowS,"lowS"),Qu(n.prehash,"prehash"),void 0!==n.format&&Kl(n.format),n}var Hl=(zl={Err:function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return(0,H.default)(this,n),t.call(this,e)}return n}((0,he.default)(Error))},(0,te.default)(zl,"_tlv",(0,te.default)({encode:function(e,t){var n=Hl.Err;if(e<0||e>256)throw new n("tlv.encode: wrong tag");if(1&t.length)throw new n("tlv.encode: unpadded data");var r=t.length/2,i=$u(r);if(i.length/2&128)throw new n("tlv.encode: long form length too big");var a=r>127?$u(i.length/2|128):"";return $u(e)+a+i+t}},"decode",(function(e,t){var n=Hl.Err,r=0;if(e<0||e>256)throw new n("tlv.encode: wrong tag");if(t.length<2||t[r++]!==e)throw new n("tlv.decode: wrong tlv");var i=t[r++],a=0;if(128&i){var o=127&i;if(!o)throw new n("tlv.decode(long): indefinite length not supported");if(o>4)throw new n("tlv.decode(long): byte length is too big");var u=t.subarray(r,r+o);if(u.length!==o)throw new n("tlv.decode: length bytes not complete");if(0===u[0])throw new n("tlv.decode(long): zero leftmost byte");var s=!0,l=!1,c=void 0;try{for(var f,d=u[Symbol.iterator]();!(s=(f=d.next()).done);s=!0){a=a<<8|f.value}}catch(e){l=!0,c=e}finally{try{s||null==d.return||d.return()}finally{if(l)throw c}}if(r+=o,a<128)throw new n("tlv.decode(long): not minimal encoding")}else a=i;var h=t.subarray(r,r+a);if(h.length!==a)throw new n("tlv.decode: wrong value length");return{v:h,l:t.subarray(r+a)}}))),(0,te.default)(zl,"_int",(0,te.default)({encode:function(e){var t=Hl.Err;if(e<Wl)throw new t("integer: negative integers are not allowed");var n=$u(e);if(8&Number.parseInt(n[0],16)&&(n="00"+n),1&n.length)throw new t("unexpected DER parsing assertion: unpadded hex");return n}},"decode",(function(e){var t=Hl.Err;if(128&e[0])throw new t("invalid signature integer: negative");if(0===e[0]&&!(128&e[1]))throw new t("invalid signature integer: unnecessary leading zero");return ts(e)}))),(0,te.default)(zl,"toSig",(function(e){var t=Hl.Err,n=Hl._int,r=Hl._tlv,i=as("signature",e),a=r.decode(48,i),o=a.v;if(a.l.length)throw new t("invalid signature: left bytes after parsing");var u=r.decode(2,o),s=u.v,l=u.l,c=r.decode(2,l),f=c.v;if(c.l.length)throw new t("invalid signature: left bytes after parsing");return{r:n.decode(s),s:n.decode(f)}})),(0,te.default)(zl,"hexFromSig",(function(e){var t=Hl._tlv,n=Hl._int,r=t.encode(2,n.encode(e.r))+t.encode(2,n.encode(e.s));return t.encode(48,r)})),zl),Wl=BigInt(0),Gl=BigInt(1),Xl=BigInt(2),Yl=BigInt(3),Zl=BigInt(4);function Ql(e,t){var n,r=e.BYTES;if("bigint"==(void 0===t?"undefined":(0,fe.default)(t)))n=t;else{var i=as("private key",t);try{n=e.fromBytes(i)}catch(e){throw Error("invalid private key: expected ui8a of size ".concat(r,", got ").concat(void 0===t?"undefined":(0,fe.default)(t)))}}if(!e.isValidNot0(n))throw Error("invalid private key: out of range [1..N-1]");return n}function Jl(e){return Uint8Array.of(e?2:3)}function $l(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function ec(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=function(e){return e>d>>Gl},i=function(e,t){if(!f.isValidNot0(t))throw Error("invalid signature ".concat(e,": out of range 1..Point.Fn.ORDER"));return t},a=function(e){return ss("num < 2^"+h,e,Wl,A),f.toBytes(e)},o=function(e,n){return Ju(e,void 0,"message"),n?Ju(t(e),void 0,"prehashed message"):e};Pr(t),fs(n,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});var u,s=n.randomBytes||Zr,l=n.hmac||function(e){for(var n=arguments.length,r=new Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];return ql(t,e,Gr.apply(void 0,(0,ce.default)(r)))},c=e.Fp,f=e.Fn,d=f.ORDER,h=f.BITS,v=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=function(e){try{return!!Ql(o,e)}catch(e){return!1}},r=function(){return function(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=e.length,i=Ns(t),a=Os(t);if(r<16||r<a||r>1024)throw Error("expected "+a+"-1024 bytes of input, got "+r);var o=Es(n?ns(e):ts(e),t-vs)+vs;return n?is(o,i):rs(o,i)}(Ju(arguments.length>0&&void 0!==arguments[0]?arguments[0]:u(s.seed),s.seed,"seed"),o.ORDER)},i=function(t){var n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return e.BASE.multiply(Ql(o,t)).toBytes(n)},a=function(t){if("bigint"==(void 0===t?"undefined":(0,fe.default)(t)))return!1;if(t instanceof e)return!0;var n=s.secretKey,r=s.publicKey,i=s.publicKeyUncompressed;if(!o.allowedLengths&&n!==r){var a=as("key",t).length;return a===r||a===i}},o=e.Fn,u=t.randomBytes||Zr,s=Object.assign($l(e.Fp,o),{seed:Os(o.ORDER)}),l={isValidSecretKey:n,isValidPublicKey:function(t,n){var r=s.publicKey,i=s.publicKeyUncompressed;try{var a=t.length;return!(!0===n&&a!==r||!1===n&&a!==i||!e.fromBytes(t))}catch(e){return!1}},randomSecretKey:r,isValidPrivateKey:n,randomPrivateKey:r,normPrivateKeyToScalar:function(e){return Ql(o,e)},precompute:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:8;return(arguments.length>1&&void 0!==arguments[1]?arguments[1]:e.BASE).precompute(t,!1)}};return Object.freeze({getPublicKey:i,getSharedSecret:function(t,n){var r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];if(!0===a(t))throw Error("first arg must be private key");if(!1===a(n))throw Error("second arg must be public key");var i=Ql(o,t);return e.fromHex(n).multiply(i).toBytes(r)},keygen:function(e){var t=r(e);return{secretKey:t,publicKey:i(t)}},Point:e,utils:l,lengths:s})}(e,n),p=v.keygen,g=v.getPublicKey,y=v.getSharedSecret,m=v.utils,b=v.lengths,w={prehash:!1,lowS:"boolean"==typeof n.lowS&&n.lowS,format:void 0,extraEntropy:!1},k="compact",_=function(){"use strict";function t(e,n,r){(0,H.default)(this,t),this.r=i("r",e),this.s=i("s",n),null!=r&&(this.recovery=r),Object.freeze(this)}return(0,$.default)(t,[{key:"addRecoveryBit",value:function(e){return new t(this.r,this.s,e)}},{key:"recoverPublicKey",value:function(t){var n=c.ORDER,r=this,i=r.r,a=r.s,o=r.recovery;if(null==o||![0,1,2,3].includes(o))throw Error("recovery id invalid");if(d*Xl<n&&o>1)throw Error("recovery id is ambiguous for h>1 curve");var u=2===o||3===o?i+d:i;if(!c.isValid(u))throw Error("recovery id 2 or 3 invalid");var s=c.toBytes(u),l=e.fromBytes(Gr(Jl(!(1&o)),s)),h=f.inv(u),v=S(as("msgHash",t)),p=f.create(-v*h),g=f.create(a*h),y=e.BASE.multiplyUnsafe(p).add(l.multiplyUnsafe(g));if(y.is0())throw Error("point at infinify");return y.assertValidity(),y}},{key:"hasHighS",value:function(){return r(this.s)}},{key:"toBytes",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:k;if(Kl(e),"der"===e)return Hr(Hl.hexFromSig(this));var t=f.toBytes(this.r),n=f.toBytes(this.s);if("recovered"===e){if(null==this.recovery)throw Error("recovery bit must be present");return Gr(Uint8Array.of(this.recovery),t,n)}return Gr(t,n)}},{key:"toHex",value:function(e){return Ur(this.toBytes(e))}},{key:"assertValidity",value:function(){}},{key:"normalizeS",value:function(){return this.hasHighS()?new t(this.r,f.neg(this.s),this.recovery):this}},{key:"toDERRawBytes",value:function(){return this.toBytes("der")}},{key:"toDERHex",value:function(){return Ur(this.toBytes("der"))}},{key:"toCompactRawBytes",value:function(){return this.toBytes("compact")}},{key:"toCompactHex",value:function(){return Ur(this.toBytes("compact"))}}],[{key:"fromBytes",value:function(e){var n,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:k;if(function(e,t){Kl(t);var n=b.signature;Ju(e,"compact"===t?n:"recovered"===t?n+1:void 0,t+" signature")}(e,r),"der"===r){var i=Hl.toSig(Ju(e));return new t(i.r,i.s)}"recovered"===r&&(n=e[0],r="compact",e=e.subarray(1));var a=f.BYTES,o=e.subarray(0,a),u=e.subarray(a,2*a);return new t(f.fromBytes(o),f.fromBytes(u),n)}},{key:"fromHex",value:function(e,t){return this.fromBytes(Hr(e),t)}},{key:"fromCompact",value:function(e){return t.fromBytes(as("sig",e),"compact")}},{key:"fromDER",value:function(e){return t.fromBytes(as("sig",e),"der")}}]),t}(),E=n.bits2int||function(e){if(e.length>8192)throw Error("input is too large");var t=ts(e),n=8*e.length-h;return n>0?t>>BigInt(n):t},S=n.bits2int_modN||function(e){return f.create(E(e))},A=cs(h);return Object.freeze((u={keygen:p,getPublicKey:g,getSharedSecret:y,utils:m,lengths:b,Point:e,sign:function(n,i){var u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},c=function(t,n,i){if(["recovered","canonical"].some((function(e){return e in i})))throw Error("sign() legacy options not supported");var u=Vl(i,w),l=u.lowS,c=u.prehash,d=u.extraEntropy;t=o(t,c);var h=S(t),v=Ql(f,n),p=[a(v),a(h)];if(null!=d&&!1!==d){var g=!0===d?s(b.secretKey):d;p.push(as("extraEntropy",g))}var y=Gr.apply(void 0,(0,ce.default)(p)),m=h;return{seed:y,k2sig:function(t){var n=E(t);if(f.isValidNot0(n)){var i=f.inv(n),a=e.BASE.multiply(n).toAffine(),o=f.create(a.x);if(o!==Wl){var u=f.create(i*f.create(m+o*v));if(u!==Wl){var s=(a.x===o?0:2)|Number(a.y&Gl),c=u;return l&&r(u)&&(c=f.neg(u),s^=1),new _(o,c,s)}}}}}}(n=as("message",n),i,u),d=c.seed,h=c.k2sig,v=function(e,t,n){if("number"!=typeof e||e<2)throw Error("hashLen must be a number");if("number"!=typeof t||t<2)throw Error("qByteLen must be a number");if("function"!=typeof n)throw Error("hmacFn must be a function");var r=function(e){return new Uint8Array(e)},i=function(e){return Uint8Array.of(e)},a=r(e),o=r(e),u=0,s=function(){a.fill(1),o.fill(0),u=0},l=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return n.apply(void 0,[o,a].concat((0,ce.default)(t)))},c=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:r(0);o=l(i(0),e),a=l(),0!==e.length&&(o=l(i(1),e),a=l())},f=function(){if(u++>=1e3)throw Error("drbg: tried 1000 values");for(var e=0,n=[];e<t;){var r=(a=l()).slice();n.push(r),e+=a.length}return Gr.apply(void 0,(0,ce.default)(n))};return function(e,t){var n;for(s(),c(e);!(n=t(f()));)c();return s(),n}}(t.outputLen,f.BYTES,l);return v(d,h)},verify:function(t,n,r){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},a=Vl(i,w),u=a.lowS,s=a.prehash,l=a.format;if(r=as("publicKey",r),n=o(as("message",n),s),"strict"in i)throw Error("options.strict was renamed to lowS");var c=void 0===l?function(e){var t,n="string"==typeof e||xr(e),r=!n&&null!==e&&"object"==typeof e&&"bigint"==(0,fe.default)(e.r)&&"bigint"==(0,fe.default)(e.s);if(!n&&!r)throw Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(r)t=new _(e.r,e.s);else if(n){try{t=_.fromBytes(as("sig",e),"der")}catch(e){if(!(e instanceof Hl.Err))throw e}if(!t)try{t=_.fromBytes(as("sig",e),"compact")}catch(e){return!1}}return t||!1}(t):_.fromBytes(as("sig",t),l);if(!1===c)return!1;try{var d=e.fromBytes(r);if(u&&c.hasHighS())return!1;var h=c.r,v=c.s,p=S(n),g=f.inv(v),y=f.create(p*g),m=f.create(h*g),b=e.BASE.multiplyUnsafe(y).add(d.multiplyUnsafe(m));return!b.is0()&&f.create(b.x)===h}catch(e){return!1}}},(0,te.default)(u,"recoverPublicKey",(function(e,t){var n=Vl(arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},w).prehash;return t=o(t,n),_.fromBytes(e,"recovered").recoverPublicKey(t).toBytes()})),(0,te.default)(u,"Signature",_),(0,te.default)(u,"hash",t),u))}function tc(e){var t=function(e){var t=function(e){var t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},n=e.Fp,r=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map((function(e){return Math.ceil(e/2)})))):void 0;return{CURVE:t,curveOpts:{Fp:n,Fn:Ms(t.n,{BITS:e.nBitLength,allowedLengths:r,modFromBytes:e.wrapPrivateKey}),allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes}}}(e),n=t.CURVE,r=t.curveOpts,i={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:n,curveOpts:r,hash:e.hash,ecdsaOpts:i}}(e),n=t.CURVE,r=t.curveOpts,i=t.hash,a=t.ecdsaOpts;return function(e,t){var n=t.Point;return Object.assign({},t,{ProjectivePoint:n,CURVE:Object.assign({},e,Ds(n.Fn.ORDER,n.Fn.BITS))})}(e,ec(function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=function(){if(!c.isOdd)throw Error("compression is not supported: Field does not have .isOdd()")},r=function(e){var t=c.sqr(e),n=c.mul(t,e);return c.add(c.add(n,c.mul(e,d.a)),d.b)},i=function(e,t){var n=c.sqr(t),i=r(e);return c.eql(n,i)},a=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];if(!c.isValid(t)||n&&c.is0(t))throw Error("bad point coordinate "+e);return t},o=function(e){if(!(e instanceof E))throw Error("ProjectivePoint expected")},u=function(e){if(!p||!p.basises)throw Error("no endo");return function(e,t,n){var r=(0,se.default)(t,2),i=(0,se.default)(r[0],2),a=i[0],o=i[1],u=(0,se.default)(r[1],2),s=u[0],l=u[1],c=jl(l*e,n),f=jl(-o*e,n),d=e-c*a-f*s,h=-c*o-f*l,v=d<Wl,p=h<Wl;v&&(d=-d),p&&(h=-h);var g=cs(Math.ceil(ls(n)/2))+Gl;if(d<Wl||d>=g||h<Wl||h>=g)throw Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:v,k1:d,k2neg:p,k2:h}}(e,p.basises,f.ORDER)},s=function(e,t,n,r,i){return n=new E(c.mul(n.X,e),n.Y,n.Z),t=Bs(r,t),n=Bs(i,n),t.add(n)},l=Qs("weierstrass",e,t),c=l.Fp,f=l.Fn,d=l.CURVE,h=d.h,v=d.n;fs(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});var p=t.endo;if(p&&(!c.is0(d.a)||"bigint"!=(0,fe.default)(p.beta)||!Array.isArray(p.basises)))throw Error('invalid endo: expected "beta": bigint and "basises": array');var g=$l(c,f),y=t.toBytes||function(e,t,r){var i=t.toAffine(),a=i.x,o=i.y,u=c.toBytes(a);return Qu(r,"isCompressed"),r?(n(),Gr(Jl(!c.isOdd(o)),u)):Gr(Uint8Array.of(4),u,c.toBytes(o))},m=t.fromBytes||function(e){Ju(e,void 0,"Point");var t=g.publicKey,a=g.publicKeyUncompressed,o=e.length,u=e[0],s=e.subarray(1);if(o!==t||2!==u&&3!==u){if(o===a&&4===u){var l=c.BYTES,f=c.fromBytes(s.subarray(0,l)),d=c.fromBytes(s.subarray(l,2*l));if(!i(f,d))throw Error("bad point: is not on curve");return{x:f,y:d}}throw Error("bad point: got length ".concat(o,", expected compressed=").concat(t," or uncompressed=").concat(a))}var h=c.fromBytes(s);if(!c.isValid(h))throw Error("bad point: is not on curve, wrong x");var v,p=r(h);try{v=c.sqrt(p)}catch(e){var y=e instanceof Error?": "+e.message:"";throw Error("bad point: is not on curve, sqrt error"+y)}return n(),!(1&~u)!==c.isOdd(v)&&(v=c.neg(v)),{x:h,y:v}};if(!i(d.Gx,d.Gy))throw Error("bad curve params: generator point");var b=c.mul(c.pow(d.a,Yl),Zl),w=c.mul(c.sqr(d.b),BigInt(27));if(c.is0(c.add(b,w)))throw Error("bad curve params: a or b");var k=ds((function(e,t){var n=e.X,r=e.Y,i=e.Z;if(c.eql(i,c.ONE))return{x:n,y:r};var a=e.is0();null==t&&(t=a?c.ONE:c.inv(i));var o=c.mul(n,t),u=c.mul(r,t),s=c.mul(i,t);if(a)return{x:c.ZERO,y:c.ZERO};if(!c.eql(s,c.ONE))throw Error("invZ was invalid");return{x:o,y:u}})),_=ds((function(e){if(e.is0()){if(t.allowInfinityPoint&&!c.is0(e.Y))return;throw Error("bad point: ZERO")}var n=e.toAffine(),r=n.x,a=n.y;if(!c.isValid(r)||!c.isValid(a))throw Error("bad point: x or y not field elements");if(!i(r,a))throw Error("bad point: equation left != right");if(!e.isTorsionFree())throw Error("bad point: not in prime-order subgroup");return!0})),E=function(){"use strict";function e(t,n,r){(0,H.default)(this,e),this.X=a("x",t),this.Y=a("y",n,!0),this.Z=a("z",r),Object.freeze(this)}return(0,$.default)(e,[{key:"x",get:function(){return this.toAffine().x}},{key:"y",get:function(){return this.toAffine().y}},{key:"precompute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:8,t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return A.createCache(this,e),t||this.multiply(Yl),this}},{key:"assertValidity",value:function(){_(this)}},{key:"hasEvenY",value:function(){var e=this.toAffine().y;if(!c.isOdd)throw Error("Field doesn't support isOdd");return!c.isOdd(e)}},{key:"equals",value:function(e){o(e);var t=this,n=t.X,r=t.Y,i=t.Z,a=e.X,u=e.Y,s=e.Z,l=c.eql(c.mul(n,s),c.mul(a,i)),f=c.eql(c.mul(r,s),c.mul(u,i));return l&&f}},{key:"negate",value:function(){return new e(this.X,c.neg(this.Y),this.Z)}},{key:"double",value:function(){var t=d.a,n=d.b,r=c.mul(n,Yl),i=this,a=i.X,o=i.Y,u=i.Z,s=c.ZERO,l=c.ZERO,f=c.ZERO,h=c.mul(a,a),v=c.mul(o,o),p=c.mul(u,u),g=c.mul(a,o);return g=c.add(g,g),f=c.mul(a,u),f=c.add(f,f),s=c.mul(t,f),l=c.mul(r,p),l=c.add(s,l),s=c.sub(v,l),l=c.add(v,l),l=c.mul(s,l),s=c.mul(g,s),f=c.mul(r,f),p=c.mul(t,p),g=c.sub(h,p),g=c.mul(t,g),g=c.add(g,f),f=c.add(h,h),h=c.add(f,h),h=c.add(h,p),h=c.mul(h,g),l=c.add(l,h),p=c.mul(o,u),p=c.add(p,p),h=c.mul(p,g),s=c.sub(s,h),f=c.mul(p,v),f=c.add(f,f),new e(s,l,f=c.add(f,f))}},{key:"add",value:function(t){o(t);var n=this,r=n.X,i=n.Y,a=n.Z,u=t.X,s=t.Y,l=t.Z,f=c.ZERO,h=c.ZERO,v=c.ZERO,p=d.a,g=c.mul(d.b,Yl),y=c.mul(r,u),m=c.mul(i,s),b=c.mul(a,l),w=c.add(r,i),k=c.add(u,s);w=c.mul(w,k),k=c.add(y,m),w=c.sub(w,k),k=c.add(r,a);var _=c.add(u,l);return k=c.mul(k,_),_=c.add(y,b),k=c.sub(k,_),_=c.add(i,a),f=c.add(s,l),_=c.mul(_,f),f=c.add(m,b),_=c.sub(_,f),v=c.mul(p,k),f=c.mul(g,b),v=c.add(f,v),f=c.sub(m,v),v=c.add(m,v),h=c.mul(f,v),m=c.add(y,y),m=c.add(m,y),b=c.mul(p,b),k=c.mul(g,k),m=c.add(m,b),b=c.sub(y,b),b=c.mul(p,b),k=c.add(k,b),y=c.mul(m,k),h=c.add(h,y),y=c.mul(_,k),f=c.mul(w,f),f=c.sub(f,y),y=c.mul(w,m),v=c.mul(_,v),new e(f,h,v=c.add(v,y))}},{key:"subtract",value:function(e){return this.add(e.negate())}},{key:"is0",value:function(){return this.equals(e.ZERO)}},{key:"multiply",value:function(n){var r,i,a=this,o=t.endo;if(!f.isValidNot0(n))throw Error("invalid scalar: out of range");var l=function(t){return A.cached(a,t,(function(t){return qs(e,t)}))};if(o){var c=u(n),d=c.k1neg,h=c.k1,v=c.k2neg,p=c.k2,g=l(h),y=g.p,m=g.f,b=l(p),w=b.p,k=b.f;i=m.add(k),r=s(o.beta,y,w,d,v)}else{var _=l(n);r=_.p,i=_.f}return qs(e,[r,i])[0]}},{key:"multiplyUnsafe",value:function(n){var r=t.endo,i=this;if(!f.isValid(n))throw Error("invalid scalar: out of range");if(n===Wl||i.is0())return e.ZERO;if(n===Gl)return i;if(A.hasCache(this))return this.multiply(n);if(r){var a=u(n),o=a.k1neg,l=a.k1,c=a.k2neg,d=function(e,t,n,r){for(var i=t,a=e.ZERO,o=e.ZERO;n>Us||r>Us;)n&Fs&&(a=a.add(i)),r&Fs&&(o=o.add(i)),i=i.double(),n>>=Fs,r>>=Fs;return{p1:a,p2:o}}(e,i,l,a.k2),h=d.p1,v=d.p2;return s(r.beta,h,v,o,c)}return A.unsafe(i,n)}},{key:"multiplyAndAddUnsafe",value:function(e,t,n){var r=this.multiplyUnsafe(t).add(e.multiplyUnsafe(n));return r.is0()?void 0:r}},{key:"toAffine",value:function(e){return k(this,e)}},{key:"isTorsionFree",value:function(){var n=t.isTorsionFree;return h===Gl||(n?n(e,this):A.unsafe(this,v).is0())}},{key:"clearCofactor",value:function(){var n=t.clearCofactor;return h===Gl?this:n?n(e,this):this.multiplyUnsafe(h)}},{key:"isSmallOrder",value:function(){return this.multiplyUnsafe(h).is0()}},{key:"toBytes",value:function(){var t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];return Qu(t,"isCompressed"),this.assertValidity(),y(e,this,t)}},{key:"toHex",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];return Ur(this.toBytes(e))}},{key:"toString",value:function(){return"<Point ".concat(this.is0()?"ZERO":this.toHex(),">")}},{key:"px",get:function(){return this.X}},{key:"py",get:function(){return this.X}},{key:"pz",get:function(){return this.Z}},{key:"toRawBytes",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];return this.toBytes(e)}},{key:"_setWindowSize",value:function(e){this.precompute(e)}}],[{key:"CURVE",value:function(){return d}},{key:"fromAffine",value:function(t){var n=t||{},r=n.x,i=n.y;if(!t||!c.isValid(r)||!c.isValid(i))throw Error("invalid affine point");if(t instanceof e)throw Error("projective point not allowed");return c.is0(r)&&c.is0(i)?e.ZERO:new e(r,i,c.ONE)}},{key:"fromBytes",value:function(t){var n=e.fromAffine(m(Ju(t,void 0,"point")));return n.assertValidity(),n}},{key:"fromHex",value:function(t){return e.fromBytes(as("pointHex",t))}},{key:"normalizeZ",value:function(t){return qs(e,t)}},{key:"msm",value:function(t,n){return Ys(e,f,t,n)}},{key:"fromPrivateKey",value:function(t){return e.BASE.multiply(Ql(f,t))}}]),e}();E.BASE=new E(d.Gx,d.Gy,c.ONE),E.ZERO=new E(c.ZERO,c.ONE,c.ZERO),E.Fp=c,E.Fn=f;var S=f.BITS,A=new Xs(E,t.endo?Math.ceil(S/2):S);return E.BASE.precompute(8),E}(n,r),i,a))}var nc={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},rc={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},ic=BigInt(2),ac=Ms(nc.p,{sqrt:function(e){var t=nc.p,n=BigInt(3),r=BigInt(6),i=BigInt(11),a=BigInt(22),o=BigInt(23),u=BigInt(44),s=BigInt(88),l=e*e*e%t,c=l*l*e%t,f=Ss(c,n,t)*c%t,d=Ss(f,n,t)*c%t,h=Ss(d,ic,t)*l%t,v=Ss(h,i,t)*h%t,p=Ss(v,a,t)*v%t,g=Ss(p,u,t)*p%t,y=Ss(g,s,t)*g%t,m=Ss(y,u,t)*p%t,b=Ss(m,n,t)*c%t,w=Ss(b,o,t)*v%t,k=Ss(w,r,t)*l%t,_=Ss(k,ic,t);if(!ac.eql(ac.sqr(_),e))throw Error("Cannot find square root");return _}}),oc=function(e,t){var n=function(t){return tc((0,oe.default)((0,ae.default)({},e),{hash:t}))};return(0,oe.default)((0,ae.default)({},n(t)),{create:n})}((0,oe.default)((0,ae.default)({},nc),{Fp:ac,lowS:!0,endo:rc}),Ii),uc=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"type","secp256k1"),(0,te.default)(this,"raw",void 0),(0,te.default)(this,"_key",void 0),this._key=function(e){try{return oc.ProjectivePoint.fromHex(e),e}catch(e){throw new ia(e+"")}}(t),this.raw=function(e){return oc.ProjectivePoint.fromHex(e).toRawBytes(!0)}(this._key)}return(0,$.default)(e,[{key:"toMultihash",value:function(){return tn.digest(dc(this))}},{key:"toCID",value:function(){return cn.createV1(114,this.toMultihash())}},{key:"toString",value:function(){return xt.encode(this.toMultihash().bytes).substring(1)}},{key:"equals",value:function(e){return null!=e&&e.raw instanceof Uint8Array&&so(this.raw,e.raw)}},{key:"verify",value:function(e,t,n){return function(e,t,n,r){var i=rn.digest(n instanceof Uint8Array?n:n.subarray());if(xl(i))return i.then((function(n){var i,a=n.digest;return null==r||null===(i=r.signal)||void 0===i||i.throwIfAborted(),oc.verify(t,a,e)})).catch((function(e){if("AbortError"===e.name)throw e;throw new kl(e+"")}));try{var a;return null==r||null===(a=r.signal)||void 0===a||a.throwIfAborted(),oc.verify(t,i.digest,e)}catch(e){throw new kl(e+"")}}(this._key,t,e,n)}}]),e}();function sc(e){return new uc(e)}function lc(){return cc.apply(this,arguments)}function cc(){return cc=(0,K.default)((function(){return(0,pe.__generator)(this,(function(e){return[2,(0,K.default)((function(){var e,t,n;return(0,pe.__generator)(this,(function(r){return e=function(){var e=bl.utils.randomPrivateKey(),t=bl.getPublicKey(e),n=function(e,t){for(var n=new Uint8Array(64),r=0;r<32;r++)n[r]=e[r],n[32+r]=t[r];return n}(e,t);return{privateKey:n,publicKey:t}}(),t=e.privateKey,n=e.publicKey,[2,new Dl(t,n)]}))}))()]}))})),cc.apply(this,arguments)}function fc(e,t){var n=Pl.decode(e),r=n.Type,i=n.Data,a=null!=i?i:new Uint8Array;switch(r){case Cl.RSA:return function(e,t){if(e.byteLength>=1062)throw new ia("Key size is too large");return function(e,t,n){var r=function(e){var t=Pu(e[1],{offset:0});return{kty:"RSA",n:Ti(t[0],"base64url"),e:Ti(t[1],"base64url")}}(e);return null==n&&(n=Yt(18,Ci(Pl.encode({Type:Cl.RSA,Data:t})))),new Ul(r,n)}(Pu(e,{offset:0}),e,t)}(a,t);case Cl.Ed25519:return Ml(a);case Cl.secp256k1:return sc(a);case Cl.ECDSA:return Wu(a);default:throw new Aa}}function dc(e){return Pl.encode({Type:Cl[e.type],Data:e.raw})}var hc=Symbol.for("nodejs.util.inspect.custom"),vc=(I=Symbol.toStringTag,x=Xi,C=hc,function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"type",void 0),(0,te.default)(this,"multihash",void 0),(0,te.default)(this,"publicKey",void 0),(0,te.default)(this,"string",void 0),(0,te.default)(this,x,!0),this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}return(0,$.default)(e,[{key:I,get:function(){return"PeerId(".concat(this.toString(),")")}},{key:"toString",value:function(){return null==this.string&&(this.string=xt.encode(this.multihash.bytes).slice(1)),this.string}},{key:"toMultihash",value:function(){return this.multihash}},{key:"toCID",value:function(){return cn.createV1(114,this.multihash)}},{key:"toJSON",value:function(){return this.toString()}},{key:"equals",value:function(e){var t;if(null==e)return!1;if(e instanceof Uint8Array)return so(this.multihash.bytes,e);if("string"==typeof e)return this.toString()===e;if(null!=(null===(t=null==e?void 0:e.toMultihash())||void 0===t?void 0:t.bytes))return so(this.multihash.bytes,e.toMultihash().bytes);throw Error("not valid Id")}},{key:C,value:function(){return"PeerId(".concat(this.toString(),")")}}]),e}()),pc=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(e){var r;return(0,H.default)(this,n),r=t.call(this,(0,oe.default)((0,ae.default)({},e),{type:"RSA"})),(0,te.default)((0,q.default)(r),"type","RSA"),(0,te.default)((0,q.default)(r),"publicKey",void 0),r.publicKey=e.publicKey,(0,ue.default)(r)}return n}(vc),gc=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(e){var r;return(0,H.default)(this,n),r=t.call(this,(0,oe.default)((0,ae.default)({},e),{type:"Ed25519"})),(0,te.default)((0,q.default)(r),"type","Ed25519"),(0,te.default)((0,q.default)(r),"publicKey",void 0),r.publicKey=e.publicKey,(0,ue.default)(r)}return n}(vc),yc=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(e){var r;return(0,H.default)(this,n),r=t.call(this,(0,oe.default)((0,ae.default)({},e),{type:"secp256k1"})),(0,te.default)((0,q.default)(r),"type","secp256k1"),(0,te.default)((0,q.default)(r),"publicKey",void 0),r.publicKey=e.publicKey,(0,ue.default)(r)}return n}(vc),mc=hc,bc=Xi,wc=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"type","url"),(0,te.default)(this,"multihash",void 0),(0,te.default)(this,"publicKey",void 0),(0,te.default)(this,"url",void 0),(0,te.default)(this,bc,!0),this.url=t.toString(),this.multihash=tn.digest(wn(this.url))}return(0,$.default)(e,[{key:mc,value:function(){return"PeerId(".concat(this.url,")")}},{key:"toString",value:function(){return this.toCID().toString()}},{key:"toMultihash",value:function(){return this.multihash}},{key:"toCID",value:function(){return cn.createV1(2336,this.toMultihash())}},{key:"toJSON",value:function(){return this.toString()}},{key:"equals",value:function(e){return null!=e&&(e instanceof Uint8Array&&(e=Ti(e)),e.toString()===this.toString())}}]),e}();function kc(e){if("1"!==e.charAt(0)&&"Q"!==e.charAt(0)){if(e.startsWith("k51qzi5uqu5")||e.startsWith("kzwfwjn5ji4")||e.startsWith("k2k4r8")||e.startsWith("bafz"))return Sc(cn.parse(e));throw new ra('Please pass a multibase decoder for strings that do not start with "1" or "Q"')}return Ec(Zt(xt.decode("z"+e)))}function _c(e){if("Ed25519"===e.type)return new gc({multihash:e.toCID().multihash,publicKey:e});if("secp256k1"===e.type)return new yc({multihash:e.toCID().multihash,publicKey:e});if("RSA"===e.type)return new pc({multihash:e.toCID().multihash,publicKey:e});throw new Aa}function Ec(e){if(function(e){return e.code===rn.code}(e))return new pc({multihash:e});if(function(e){return e.code===tn.code}(e))try{var t=function(e){var t=Pl.decode(e.digest),n=t.Type,r=t.Data,i=null!=r?r:new Uint8Array;switch(n){case Cl.Ed25519:return Ml(i);case Cl.secp256k1:return sc(i);case Cl.ECDSA:return Wu(i);default:throw new Aa}}(e);if("Ed25519"===t.type)return new gc({multihash:e,publicKey:t});if("secp256k1"===t.type)return new yc({multihash:e,publicKey:t})}catch(t){var n=Ti(e.digest);return new wc(new URL(n))}throw new pa("Supplied PeerID Multihash is invalid")}function Sc(e){if(null==(null==e?void 0:e.multihash)||null==e.version||1===e.version&&114!==e.code&&2336!==e.code)throw new va("Supplied PeerID CID is invalid");if(2336===e.code){var t=Ti(e.multihash.digest);return new wc(new URL(t))}return Ec(e.multihash)}var Ac=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e;return(0,H.default)(this,n),e=t.apply(this,arguments),(0,te.default)((0,q.default)(e),"name","InvalidMultiaddrError"),e}return n}((0,he.default)(Error));(0,te.default)(Ac,"name","InvalidMultiaddrError");var Ic=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e;return(0,H.default)(this,n),e=t.apply(this,arguments),(0,te.default)((0,q.default)(e),"name","ValidationError"),e}return n}((0,he.default)(Error));(0,te.default)(Ic,"name","ValidationError");var xc=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e;return(0,H.default)(this,n),e=t.apply(this,arguments),(0,te.default)((0,q.default)(e),"name","InvalidParametersError"),e}return n}((0,he.default)(Error));(0,te.default)(xc,"name","InvalidParametersError");var Cc=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e;return(0,H.default)(this,n),e=t.apply(this,arguments),(0,te.default)((0,q.default)(e),"name","UnknownProtocolError"),e}return n}((0,he.default)(Error));(0,te.default)(Cc,"name","UnknownProtocolError");var Tc=new(function(){"use strict";function e(){(0,H.default)(this,e),(0,te.default)(this,"index",0),(0,te.default)(this,"input","")}return(0,$.default)(e,[{key:"new",value:function(e){return this.index=0,this.input=e,this}},{key:"readAtomically",value:function(e){var t=this.index,n=e();return void 0===n&&(this.index=t),n}},{key:"parseWith",value:function(e){var t=e();if(this.index===this.input.length)return t}},{key:"peekChar",value:function(){if(!(this.index>=this.input.length))return this.input[this.index]}},{key:"readChar",value:function(){if(!(this.index>=this.input.length))return this.input[this.index++]}},{key:"readGivenChar",value:function(e){var t=this;return this.readAtomically((function(){var n=t.readChar();if(n===e)return n}))}},{key:"readSeparator",value:function(e,t,n){var r=this;return this.readAtomically((function(){if(!(t>0&&void 0===r.readGivenChar(e)))return n()}))}},{key:"readNumber",value:function(e,t,n,r){var i=this;return this.readAtomically((function(){var a=0,o=0,u=i.peekChar();if(void 0!==u){for(var s="0"===u,l=Math.pow(2,8*r)-1;;){var c=i.readAtomically((function(){var t=i.readChar();if(void 0!==t){var n=Number.parseInt(t,e);return Number.isNaN(n)?void 0:n}}));if(void 0===c)break;if(a*=e,(a+=c)>l)return;if(o+=1,void 0!==t&&o>t)return}return 0===o||!n&&s&&o>1?void 0:a}}))}},{key:"readIPv4Addr",value:function(){var e=this;return this.readAtomically((function(){for(var t=new Uint8Array(4),n=0;n<t.length;n++){var r=e.readSeparator(".",n,(function(){return e.readNumber(10,3,!1,1)}));if(void 0===r)return;t[n]=r}return t}))}},{key:"readIPv6Addr",value:function(){var e=this,t=function(t){for(var n=0;n<t.length/2;n++){var r=2*n;if(n<t.length-3){var i=e.readSeparator(":",n,(function(){return e.readIPv4Addr()}));if(void 0!==i)return t[r]=i[0],t[r+1]=i[1],t[r+2]=i[2],t[r+3]=i[3],[r+4,!0]}var a=e.readSeparator(":",n,(function(){return e.readNumber(16,4,!0,2)}));if(void 0===a)return[r,!1];t[r]=a>>8,t[r+1]=255&a}return[t.length,!1]};return this.readAtomically((function(){var n=new Uint8Array(16),r=(0,se.default)(t(n),2),i=r[0],a=r[1];if(16===i)return n;if(!a&&void 0!==e.readGivenChar(":")&&void 0!==e.readGivenChar(":")){var o=new Uint8Array(14),u=16-(i+2),s=(0,se.default)(t(o.subarray(0,u)),1)[0];return n.set(o.subarray(0,s),16-s),n}}))}},{key:"readIPAddr",value:function(){var e;return null!==(e=this.readIPv4Addr())&&void 0!==e?e:this.readIPv6Addr()}}]),e}());function Pc(e){if(!(e.length>15))return Tc.new(e).parseWith((function(){return Tc.readIPv4Addr()}))}function Rc(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>45))return Tc.new(e).parseWith((function(){return Tc.readIPv6Addr()}))}function Lc(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>45)){var n=Tc.new(e).parseWith((function(){return Tc.readIPAddr()}));return n?t&&4===n.length?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,n[0],n[1],n[2],n[3]]):n:void 0}}function Dc(e){return!!Pc(e)}function Mc(e){return!!Rc(e)}var Nc=41,Oc=42;function Uc(e){return function(t){return Ti(t,e)}}function Fc(e){return function(t){return wn(t,e)}}function Bc(e){return new DataView(e.buffer).getUint16(e.byteOffset).toString()}function qc(e){var t=new ArrayBuffer(2);return new DataView(t).setUint16(0,"string"==typeof e?parseInt(e):e),new Uint8Array(t)}function zc(e){var t=e.subarray(0,e.length-2),n=e.subarray(e.length-2);return"".concat(Ti(t,"base32"),":").concat(Bc(n))}var jc=function(e){e=e.toString().trim();var t=new Uint8Array(4);return e.split(/\./g).forEach((function(e,n){var r=parseInt(e,10);if(isNaN(r)||r<0||r>255)throw new Ac("Invalid byte value in IP address");t[n]=r})),t},Kc=Object.values(pn).map((function(e){return e.decoder})),Vc=function(){var e=Kc[0].or(Kc[1]);return Kc.slice(2).forEach((function(t){return e=e.or(t)})),e}(),Hc=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return function(e){var n=!0,r=!1,i=void 0;try{for(var a,o=t[Symbol.iterator]();!(n=(a=o.next()).done);n=!0){(0,a.value)(e)}}catch(e){r=!0,i=e}finally{try{n||null==o.return||o.return()}finally{if(r)throw i}}}}((function(e){if(parseInt(e).toString()!==e)throw new Ic("Value must be an integer")}),(function(e){if(e<0)throw new Ic("Value must be a positive integer, or zero")}),(65535,function(e){if(e>65535)throw new Ic("Value must be smaller than or equal to 65535")})),Wc=-1,Gc=new(function(){"use strict";function e(){(0,H.default)(this,e),(0,te.default)(this,"protocolsByCode",new Map),(0,te.default)(this,"protocolsByName",new Map)}return(0,$.default)(e,[{key:"getProtocol",value:function(e){var t;if(null==(t="string"==typeof e?this.protocolsByName.get(e):this.protocolsByCode.get(e)))throw new Cc("Protocol ".concat(e," was unknown"));return t}},{key:"addProtocol",value:function(e){var t,n=this;this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),null===(t=e.aliases)||void 0===t||t.forEach((function(t){n.protocolsByName.set(t,e)}))}},{key:"removeProtocol",value:function(e){var t,n=this,r=this.protocolsByCode.get(e);null!=r&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),null===(t=r.aliases)||void 0===t||t.forEach((function(e){n.protocolsByName.delete(e)})))}}]),e}()),Xc=[{code:4,name:"ip4",size:32,valueToBytes:jc,bytesToValue:function(e){if(4!==e.byteLength)throw new Ac("IPv4 address was incorrect length");for(var t=[],n=0;n<e.byteLength;n++)t.push(e[n]);return t.join(".")},validate:function(e){if(!Dc(e))throw new Ic('Invalid IPv4 address "'.concat(e,'"'))}},{code:6,name:"tcp",size:16,valueToBytes:qc,bytesToValue:Bc,validate:Hc},{code:273,name:"udp",size:16,valueToBytes:qc,bytesToValue:Bc,validate:Hc},{code:33,name:"dccp",size:16,valueToBytes:qc,bytesToValue:Bc,validate:Hc},{code:Nc,name:"ip6",size:128,valueToBytes:function(e){var t,n=0,r=(e=e.toString().trim()).split(":",8);for(t=0;t<r.length;t++){var i=void 0;Dc(r[t])&&(i=jc(r[t]),r[t]=Ti(i.subarray(0,2),"base16")),null!=i&&++t<8&&r.splice(t,0,Ti(i.subarray(2,4),"base16"))}if(""===r[0])for(;r.length<8;)r.unshift("0");else if(""===r[r.length-1])for(;r.length<8;)r.push("0");else if(r.length<8){for(t=0;t<r.length&&""!==r[t];t++);var a=[t,1];for(t=9-r.length;t>0;t--)a.push("0");r.splice.apply(r,a)}var o=new Uint8Array(n+16);for(t=0;t<r.length;t++){""===r[t]&&(r[t]="0");var u=parseInt(r[t],16);if(isNaN(u)||u<0||u>65535)throw new Ac("Invalid byte value in IP address");o[n++]=u>>8&255,o[n++]=255&u}return o},bytesToValue:function(e){if(16!==e.byteLength)throw new Ac("IPv6 address was incorrect length");for(var t=[],n=0;n<e.byteLength;n+=2){var r=e[n],i=e[n+1],a="".concat(r.toString(16).padStart(2,"0")).concat(i.toString(16).padStart(2,"0"));t.push(a)}var o=t.join(":");try{var u=new URL("http://[".concat(o,"]"));return u.hostname.substring(1,u.hostname.length-1)}catch(e){throw new Ac('Invalid IPv6 address "'.concat(o,'"'))}},stringToValue:function(e){try{var t=new URL("http://[".concat(e,"]"));return t.hostname.substring(1,t.hostname.length-1)}catch(t){throw new Ac('Invalid IPv6 address "'.concat(e,'"'))}},validate:function(e){if(!Mc(e))throw new Ic('Invalid IPv6 address "'.concat(e,'"'))}},{code:Oc,name:"ip6zone",size:Wc},{code:43,name:"ipcidr",size:8,bytesToValue:Uc("base10"),valueToBytes:Fc("base10")},{code:53,name:"dns",size:Wc,resolvable:!0},{code:54,name:"dns4",size:Wc,resolvable:!0},{code:55,name:"dns6",size:Wc,resolvable:!0},{code:56,name:"dnsaddr",size:Wc,resolvable:!0},{code:132,name:"sctp",size:16,valueToBytes:qc,bytesToValue:Bc,validate:Hc},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:Wc,path:!0,stringToValue:function(e){return decodeURIComponent(e)},valueToString:function(e){return encodeURIComponent(e)}},{code:421,name:"p2p",aliases:["ipfs"],size:Wc,bytesToValue:Uc("base58btc"),valueToBytes:function(e){return e.startsWith("Q")||e.startsWith("1")?Fc("base58btc")(e):cn.parse(e).multihash.bytes}},{code:444,name:"onion",size:96,bytesToValue:zc,valueToBytes:function(e){var t=e.split(":");if(2!==t.length)throw Error("failed to parse onion addr: [\"'".concat(t.join('", "'),"'\"]' does not contain a port number"));if(16!==t[0].length)throw Error("failed to parse onion addr: ".concat(t[0]," not a Tor onion address."));var n=wn(t[0],"base32"),r=parseInt(t[1],10);if(r<1||r>65536)throw Error("Port number is not in range(1, 65536)");var i=qc(r);return uo([n,i],n.length+i.length)}},{code:445,name:"onion3",size:296,bytesToValue:zc,valueToBytes:function(e){var t=e.split(":");if(2!==t.length)throw Error("failed to parse onion addr: [\"'".concat(t.join('", "'),"'\"]' does not contain a port number"));if(56!==t[0].length)throw Error("failed to parse onion addr: ".concat(t[0]," not a Tor onion3 address."));var n=vt.decode("b"+t[0]),r=parseInt(t[1],10);if(r<1||r>65536)throw Error("Port number is not in range(1, 65536)");var i=qc(r);return uo([n,i],n.length+i.length)}},{code:446,name:"garlic64",size:Wc},{code:447,name:"garlic32",size:Wc},{code:448,name:"tls"},{code:449,name:"sni",size:Wc},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:Wc,bytesToValue:function(e){return function(t){return e.encoder.encode(t)}}(Lt),valueToBytes:function(e){return Vc.decode(e)}},{code:480,name:"http"},{code:481,name:"http-path",size:Wc,stringToValue:function(e){return"/"+decodeURIComponent(e)},valueToString:function(e){return encodeURIComponent(e.substring(1))}},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:Wc}];function Yc(e,t,n){return null==e.size||0===e.size?0:e.size>0?e.size/8:Te(t,n)}Xc.forEach((function(e){Gc.addProtocol(e)}));var Zc=Symbol.for("nodejs.util.inspect.custom"),Qc=Symbol.for("@multiformats/multiaddr"),Jc=[53,54,55,56],$c=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"No available resolver";return(0,H.default)(this,n),(e=t.call(this,r)).name="NoAvailableResolverError",(0,ue.default)(e)}return n}((0,he.default)(Error));var ef=new WeakMap,tf=new WeakMap,nf=new WeakMap,rf=Qc,af=Zc,of=function(){"use strict";function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"/",n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};(0,H.default)(this,e),(0,te.default)(this,rf,!0),(0,G.default)(this,ef,{writable:!0,value:void 0}),(0,G.default)(this,tf,{writable:!0,value:void 0}),(0,G.default)(this,nf,{writable:!0,value:void 0}),(0,X.default)(this,ef,function(e){if(null==e&&(e="/"),vf(e))return e.getComponents();if(e instanceof Uint8Array)return function(e){for(var t=[],n=0;n<e.length;){var r=Te(e,n),i=Gc.getProtocol(r),a=Ae(r),o=Yc(i,e,n+a),u=0;o>0&&i.size===Wc&&(u=Ae(o));var s=a+u+o,l={code:r,name:i.name,bytes:e.subarray(n,n+s)};if(o>0){var c,f,d=n+a+u,h=e.subarray(d,d+o);l.value=null!==(f=null===(c=i.bytesToValue)||void 0===c?void 0:c.call(i,h))&&void 0!==f?f:Ti(h)}t.push(l),n+=s}return t}(e);if("string"==typeof e)return""===(e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""))&&(e="/"),function(e){if("/"!==e.charAt(0))throw new Ac('String multiaddr must start with "/"');for(var t=[],n="protocol",r="",i="",a=1;a<e.length;a++){var o=e.charAt(a);"/"!==o&&("protocol"===n?i+=e.charAt(a):r+=e.charAt(a));var u=a===e.length-1;if("/"===o||u){var s=Gc.getProtocol(i);if("protocol"===n){if(null==s.size||0===s.size){t.push({code:s.code,name:s.name}),r="",i="",n="protocol";continue}if(u)throw new Ac("Component ".concat(i," was missing value"));n="value"}else if("value"===n){var l={code:s.code,name:s.name};if(null!=s.size&&0!==s.size){var c,f;if(""===r)throw new Ac("Component ".concat(i," was missing value"));l.value=null!==(f=null===(c=s.stringToValue)||void 0===c?void 0:c.call(s,r))&&void 0!==f?f:r}t.push(l),r="",i="",n="protocol"}}}if(""!==i&&""!==r)throw new Ac("Incomplete multiaddr");return t}(e);if(Array.isArray(e))return e;throw new Ac("Must be a string, Uint8Array, Component[], or another Multiaddr")}(t)),!1!==n.validate&&function(e){e.getComponents().forEach((function(e){var t,n=Gc.getProtocol(e.code);null!=e.value&&(null===(t=n.validate)||void 0===t||t.call(n,e.value))}))}(this)}return(0,$.default)(e,[{key:"bytes",get:function(){return null==(0,W.default)(this,nf)&&(0,X.default)(this,nf,function(e){var t=0,n=[],r=!0,i=!1,a=void 0;try{for(var o,u=e[Symbol.iterator]();!(r=(o=u.next()).done);r=!0){var s=o.value;if(null==s.bytes){var l,c,f=Gc.getProtocol(s.code),d=Ae(s.code),h=void 0,v=0,p=0;null!=s.value&&(v=(h=null!==(c=null===(l=f.valueToBytes)||void 0===l?void 0:l.call(f,s.value))&&void 0!==c?c:wn(s.value)).byteLength,f.size===Wc&&(p=Ae(v)));var g=new Uint8Array(d+p+v),y=0;Ie(s.code,g,y),y+=d,null!=h&&(f.size===Wc&&(Ie(v,g,y),y+=p),g.set(h,y)),s.bytes=g}n.push(s.bytes),t+=s.bytes.byteLength}}catch(e){i=!0,a=e}finally{try{r||null==u.return||u.return()}finally{if(i)throw a}}return uo(n,t)}((0,W.default)(this,ef))),(0,W.default)(this,nf)}},{key:"toString",value:function(){return null==(0,W.default)(this,tf)&&(0,X.default)(this,tf,"/"+(0,W.default)(this,ef).flatMap((function(e){var t;if(null==e.value)return e.name;var n,r=Gc.getProtocol(e.code);if(null==r)throw new Ac("Unknown protocol code "+e.code);return[e.name,null!==(n=null===(t=r.valueToString)||void 0===t?void 0:t.call(r,e.value))&&void 0!==n?n:e.value]})).join("/")),(0,W.default)(this,tf)}},{key:"toJSON",value:function(){return this.toString()}},{key:"toOptions",value:function(){var e,t,n,r,i="",a=!0,o=!1,u=void 0;try{for(var s,l=(0,W.default)(this,ef)[Symbol.iterator]();!(a=(s=l.next()).done);a=!0){var c=s.value,f=c.code,d=c.name,h=c.value;f===Oc&&(i="%"+(null!=h?h:"")),Jc.includes(f)&&(t="tcp",r=443,n="".concat(null!=h?h:"").concat(i),e=55===f?6:4),6!==f&&273!==f||(t="tcp"===d?"tcp":"udp",r=parseInt(null!=h?h:"")),4!==f&&f!==Nc||(t="tcp",n="".concat(null!=h?h:"").concat(i),e=f===Nc?6:4)}}catch(e){o=!0,u=e}finally{try{a||null==l.return||l.return()}finally{if(o)throw u}}if(null==e||null==t||null==n||null==r)throw Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:e,host:n,transport:t,port:r}}},{key:"getComponents",value:function(){return(0,ce.default)((0,W.default)(this,ef))}},{key:"protos",value:function(){return(0,W.default)(this,ef).map((function(e){var t,n=e.code,r=(e.value,Gc.getProtocol(n));return{code:n,size:null!==(t=r.size)&&void 0!==t?t:0,name:r.name,resolvable:!!r.resolvable,path:!!r.path}}))}},{key:"protoCodes",value:function(){return(0,W.default)(this,ef).map((function(e){return e.code}))}},{key:"protoNames",value:function(){return(0,W.default)(this,ef).map((function(e){return e.name}))}},{key:"tuples",value:function(){return(0,W.default)(this,ef).map((function(e){var t,n=e.code,r=e.value;if(null==r)return[n];var i,a=Gc.getProtocol(n),o=[n];return null!=r&&o.push(null!==(i=null===(t=a.valueToBytes)||void 0===t?void 0:t.call(a,r))&&void 0!==i?i:wn(r)),o}))}},{key:"stringTuples",value:function(){return(0,W.default)(this,ef).map((function(e){var t=e.code,n=e.value;return null==n?[t]:[t,n]}))}},{key:"encapsulate",value:function(t){var n=new e(t);return new e((0,ce.default)((0,W.default)(this,ef)).concat((0,ce.default)(n.getComponents())),{validate:!1})}},{key:"decapsulate",value:function(t){var n=t.toString(),r=this.toString(),i=r.lastIndexOf(n);if(i<0)throw new xc("Address ".concat(this.toString()," does not contain subaddress: ").concat(t.toString()));return new e(r.slice(0,i),{validate:!1})}},{key:"decapsulateCode",value:function(t){for(var n,r=(0,W.default)(this,ef).length-1;r>-1;r--)if((0,W.default)(this,ef)[r].code===t){n=r;break}return new e((0,W.default)(this,ef).slice(0,n),{validate:!1})}},{key:"getPeerId",value:function(){try{var e=[];(0,W.default)(this,ef).forEach((function(t){var n=t.code,r=t.value;421===n&&e.push([n,r]),290===n&&(e=[])}));var t=e.pop();if(null!=(null==t?void 0:t[1])){var n=t[1];return"Q"===n[0]||"1"===n[0]?Ti(xt.decode("z"+n),"base58btc"):Ti(cn.parse(n).multihash.bytes,"base58btc")}return null}catch(e){return null}}},{key:"getPath",value:function(){var e=!0,t=!1,n=void 0;try{for(var r,i=(0,W.default)(this,ef)[Symbol.iterator]();!(e=(r=i.next()).done);e=!0){var a,o=r.value;if(Gc.getProtocol(o.code).path)return null!==(a=o.value)&&void 0!==a?a:null}}catch(e){t=!0,n=e}finally{try{e||null==i.return||i.return()}finally{if(t)throw n}}return null}},{key:"equals",value:function(e){return so(this.bytes,e.bytes)}},{key:"resolve",value:function(e){var t=this;return(0,K.default)((function(){var n,r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:if(n=t.protos().find((function(e){return e.resolvable})),null==n)return[2,[t]];if(null==(r=hf.get(n.name)))throw new $c("no available resolver for "+n.name);return[4,r(t,e)];case 1:return[2,i.sent().map((function(e){return pf(e)}))]}}))}))()}},{key:"nodeAddress",value:function(){var e=this.toOptions();if("tcp"!==e.transport&&"udp"!==e.transport)throw Error('multiaddr must have a valid format - no protocol with name: "'.concat(e.transport,'". Must have a valid transport protocol: "{tcp, udp}"'));return{family:e.family,address:e.host,port:e.port}}},{key:"isThinWaistAddress",value:function(){return!(2!==(0,W.default)(this,ef).length||4!==(0,W.default)(this,ef)[0].code&&(0,W.default)(this,ef)[0].code!==Nc||6!==(0,W.default)(this,ef)[1].code&&273!==(0,W.default)(this,ef)[1].code)}},{key:af,value:function(){return"Multiaddr(".concat(this.toString(),")")}}]),e}(),uf=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function sf(e,t){16===t.length&&4===e.length&&function(e,t,n){var r=0,i=!0,a=!1,o=void 0;try{for(var u,s=e[Symbol.iterator]();!(i=(u=s.next()).done);i=!0){var l=u.value;if(!(r<0)){if(r>11)break;if(255!==l)return!1;r++}}}catch(e){a=!0,o=e}finally{try{i||null==s.return||s.return()}finally{if(a)throw o}}return!0}(t)&&(t=t.slice(12)),4===t.length&&16===e.length&&function(e,t,n,r){var i=0,a=!0,o=!1,u=void 0;try{for(var s,l=e[Symbol.iterator]();!(a=(s=l.next()).done);a=!0){var c=s.value;if(!(i<0)){if(i>11)break;if(c!==t[i])return!1;i++}}}catch(e){o=!0,u=e}finally{try{a||null==l.return||l.return()}finally{if(o)throw u}}return!0}(e,uf)&&(e=e.slice(12));var n=e.length;if(n!=t.length)throw Error("Failed to mask ip");for(var r=new Uint8Array(n),i=0;i<n;i++)r[i]=e[i]&t[i];return r}function lf(e,t){if(32!==t&&128!==t)throw Error("Invalid CIDR mask");if(e<0||e>t)throw Error("Invalid CIDR mask");for(var n=t/8,r=new Uint8Array(n),i=0;i<n;i++)e>=8?(r[i]=255,e-=8):(r[i]=255-(255>>e),e=0);return r}var cf=function(){"use strict";function e(t,n){var r;if((0,H.default)(this,e),null==n)r=function(e){var t=(0,se.default)(e.split("/"),2),n=t[0],r=t[1];if(!n||!r)throw Error("Failed to parse given CIDR: "+e);var i=4,a=Pc(n);if(null==a&&(i=16,null==(a=Rc(n))))throw Error("Failed to parse given CIDR: "+e);var o=parseInt(r,10);if(Number.isNaN(o)||(o+"").length!==r.length||o<0||o>8*i)throw Error("Failed to parse given CIDR: "+e);var u=lf(o,8*i);return{network:sf(a,u),mask:u}}(t),this.network=r.network,this.mask=r.mask;else{var i=Lc(t);if(null==i)throw Error("Failed to parse network");var a=parseInt(n+="",10);if(Number.isNaN(a)||(a+"").length!==n.length||a<0||a>8*i.length){var o=Lc(n);if(null==o)throw Error("Failed to parse mask");this.mask=o}else this.mask=lf(a,8*i.length);this.network=sf(i,this.mask)}}return(0,$.default)(e,[{key:"contains",value:function(e){return function(e,t){if("string"==typeof t&&(t=Lc(t)),null==t)throw Error("Invalid ip");if(t.length!==e.network.length)return!1;for(var n=0;n<t.length;n++)if((e.network[n]&e.mask[n])!=(t[n]&e.mask[n]))return!1;return!0}({network:this.network,mask:this.mask},e)}},{key:"toString",value:function(){var e=function(e){var t=0,n=!0,r=!1,i=void 0;try{for(var a,o=e.entries()[Symbol.iterator]();!(n=(a=o.next()).done);n=!0){var u=(0,se.default)(a.value,2),s=u[0],l=u[1];if(255!==l){for(;128&l;)t++,l<<=1;if(128&l)return-1;for(var c=s+1;c<e.length;c++)if(0!=e[c])return-1;break}t+=8}}catch(e){r=!0,i=e}finally{try{n||null==o.return||o.return()}finally{if(r)throw i}}return t}(this.mask),t=-1!==e?e+"":function(e){var t="0x",n=!0,r=!1,i=void 0;try{for(var a,o=e[Symbol.iterator]();!(n=(a=o.next()).done);n=!0){var u=a.value;t+=(u>>4).toString(16)+(15&u).toString(16)}}catch(e){r=!0,i=e}finally{try{n||null==o.return||o.return()}finally{if(r)throw i}}return t}(this.mask);return function(e){switch(e.length){case 4:return e.join(".");case 16:for(var t=[],n=0;n<e.length;n++)n%2==0&&t.push(e[n].toString(16).padStart(2,"0")+e[n+1].toString(16).padStart(2,"0"));return t.join(":");default:throw Error("Invalid ip length")}}(this.network)+"/"+t}}]),e}();function ff(e,t){var n,r,i=Gc.getProtocol(e);return null!==(r=null===(n=i.bytesToValue)||void 0===n?void 0:n.call(i,t))&&void 0!==r?r:Ti(t,"base16")}function df(e,t){var n,r,i=Gc.getProtocol(e);return null!==(r=null===(n=i.valueToBytes)||void 0===n?void 0:n.call(i,t))&&void 0!==r?r:wn(t,"base16")}var hf=new Map;function vf(e){return!!(null==e?void 0:e[Qc])}function pf(e){return new of(e)}function gf(e){var t,n=Gc.getProtocol(e);return{code:n.code,size:null!==(t=n.size)&&void 0!==t?t:0,name:n.name,resolvable:!!n.resolvable,path:!!n.path}}var yf=function(e){if(!e)return-1;try{var t=e.metadata.get("ping");return t?Number(Di(t)):-1}catch(e){return-1}},mf=new ja("connection-limiter"),bf=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"libp2p",void 0),(0,te.default)(this,"events",void 0),(0,te.default)(this,"networkMonitor",void 0),(0,te.default)(this,"dialer",void 0),(0,te.default)(this,"connectionMonitorInterval",null),(0,te.default)(this,"options",void 0),this.libp2p=t.libp2p,this.events=t.events,this.networkMonitor=t.networkMonitor,this.dialer=t.dialer,this.options=t.options,this.onWakuConnectionEvent=this.onWakuConnectionEvent.bind(this),this.onDisconnectedEvent=this.onDisconnectedEvent.bind(this)}return(0,$.default)(e,[{key:"start",value:function(){var e=this;this.dialPeersFromStore(),this.options.enableAutoRecovery&&null===this.connectionMonitorInterval&&(this.connectionMonitorInterval=setInterval((function(){e.maintainConnections()}),5e3)),this.events.addEventListener(eo.Connection,this.onWakuConnectionEvent),this.libp2p.addEventListener("peer:disconnect",this.onDisconnectedEvent)}},{key:"stop",value:function(){this.events.removeEventListener(eo.Connection,this.onWakuConnectionEvent),this.libp2p.removeEventListener("peer:disconnect",this.onDisconnectedEvent),this.connectionMonitorInterval&&(clearInterval(this.connectionMonitorInterval),this.connectionMonitorInterval=null)}},{key:"onWakuConnectionEvent",value:function(){this.options.enableAutoRecovery?this.networkMonitor.isBrowserConnected()&&this.dialPeersFromStore():mf.info("Auto recovery is disabled, skipping")}},{key:"maintainConnections",value:function(){var e=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return[4,e.maintainConnectionsCount()];case 1:return t.sent(),[4,e.maintainBootstrapConnections()];case 2:return t.sent(),[4,e.maintainTTLConnectedPeers()];case 3:return t.sent(),[2]}}))}))()}},{key:"onDisconnectedEvent",value:function(){var e=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return 0===e.libp2p.getConnections().length?(mf.info("No connections, dialing peers from store"),[4,e.dialPeersFromStore()]):[3,2];case 1:t.sent(),t.label=2;case 2:return[2]}}))}))()}},{key:"maintainConnectionsCount",value:function(){var e=this;return(0,K.default)((function(){var t,n,r,i,a,o;return(0,pe.__generator)(this,(function(u){switch(u.label){case 0:return mf.info("Maintaining connections count"),(t=e.libp2p.getConnections()).length<=e.options.maxConnections?(mf.info("Node has less than max connections ".concat(e.options.maxConnections,", trying to dial more peers")),[4,e.getPrioritizedPeers()]):[3,5];case 1:return 0!==(n=u.sent()).length?[3,3]:(mf.info("No peers to dial, skipping"),[4,e.triggerBootstrap()]);case 2:return[2,void u.sent()];case 3:return r=n.slice(0,e.options.maxConnections-t.length).map((function(t){return e.dialer.dial(t.id)})),[4,Promise.all(r)];case 4:return u.sent(),[3,9];case 5:mf.info("Node has more than max connections ".concat(e.options.maxConnections,", dropping connections")),u.label=6;case 6:return u.trys.push([6,8,,9]),i=t.filter((function(e){return!e.tags.includes(io)})).slice(e.options.maxConnections),0===i.length?[2,void mf.info("No connections to drop, skipping")]:(a=i.map((function(t){return e.libp2p.hangUp(t.remotePeer)})),[4,Promise.all(a)]);case 7:return u.sent(),mf.info("Dropped ".concat(i.length," connections")),[3,9];case 8:return o=u.sent(),mf.error("Unexpected error while maintaining connections",o),[3,9];case 9:return[2]}}))}))()}},{key:"maintainBootstrapConnections",value:function(){var e=this;return(0,K.default)((function(){var t,n,r,i;return(0,pe.__generator)(this,(function(a){switch(a.label){case 0:return mf.info("Maintaining bootstrap connections"),[4,e.getBootstrapPeers()];case 1:if((t=a.sent()).length<=e.options.maxBootstrapPeers)return[3,5];a.label=2;case 2:return a.trys.push([2,4,,5]),n=t.slice(e.options.maxBootstrapPeers),mf.info("Dropping ".concat(n.length," bootstrap connections because node has more than max bootstrap connections ").concat(e.options.maxBootstrapPeers)),r=n.map((function(t){return e.libp2p.hangUp(t.id)})),[4,Promise.all(r)];case 3:return a.sent(),mf.info("Dropped ".concat(n.length," bootstrap connections")),[3,5];case 4:return i=a.sent(),mf.error("Unexpected error while maintaining bootstrap connections",i),[3,5];case 5:return[2]}}))}))()}},{key:"maintainTTLConnectedPeers",value:function(){var e=this;return(0,K.default)((function(){var t;return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:return mf.info("Maintaining TTL connected peers"),t=e.libp2p.getConnections().map(function(){var t=(0,K.default)((function(t){var n;return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,e.libp2p.peerStore.merge(t.remotePeer,{metadata:{ttl:Ri(Date.now())}})];case 1:return r.sent(),mf.info("TTL updated for connected peer "+t.remotePeer.toString()),[3,3];case 2:return n=r.sent(),mf.error("Unexpected error while maintaining TTL connected peer",n),[3,3];case 3:return[2]}}))}));return function(e){return t.apply(this,arguments)}}()),[4,Promise.all(t)];case 1:return n.sent(),[2]}}))}))()}},{key:"dialPeersFromStore",value:function(){var e=this;return(0,K.default)((function(){var t,n,r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:mf.info("Dialing peers from store"),i.label=1;case 1:return i.trys.push([1,6,,7]),[4,e.getPrioritizedPeers()];case 2:return 0!==(t=i.sent()).length?[3,4]:(mf.info("No peers to dial, skipping"),[4,e.triggerBootstrap()]);case 3:return[2,void i.sent()];case 4:return n=t.map((function(t){return e.dialer.dial(t.id)})),mf.info("Dialing ".concat(t.length," peers from store")),[4,Promise.all(n)];case 5:return i.sent(),mf.info("Dialed ".concat(n.length," peers from store")),[3,7];case 6:return r=i.sent(),mf.error("Unexpected error while dialing peer store peers",r),[3,7];case 7:return[2]}}))}))()}},{key:"getPrioritizedPeers",value:function(){var e=this;return(0,K.default)((function(){var t,n,r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:return[4,e.libp2p.peerStore.all()];case 1:return t=i.sent(),n=e.libp2p.getConnections(),mf.info("Found ".concat(t.length," peers in store, and found ").concat(n.length," connections")),r=t.filter((function(t){return!n.some((function(e){return e.remotePeer.equals(t.id)}))&&function(e,t){var n,r,i=(null==e||null===(n=e.components)||void 0===n||null===(r=n.transportManager)||void 0===r?void 0:r.getTransports())||[];return 0!==i.length&&i.map((function(e){return e.dialFilter(t)})).some((function(e){return e.length>0}))}(e.libp2p,t.addresses.map((function(e){return e.multiaddr})))})),[2,(0,ce.default)(r.filter((function(e){return e.tags.has(to.BOOTSTRAP)}))).concat((0,ce.default)(r.filter((function(e){return e.tags.has(to.PEER_EXCHANGE)}))),(0,ce.default)(r.filter((function(e){return e.tags.has(to.PEER_CACHE)}))),(0,ce.default)(r.filter((function(e){return!e.tags.has(to.BOOTSTRAP)&&!e.tags.has(to.PEER_EXCHANGE)&&!e.tags.has(to.PEER_CACHE)}))))]}}))}))()}},{key:"getBootstrapPeers",value:function(){var e=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return[4,Promise.all(e.libp2p.getConnections().map((function(e){return e.remotePeer})).map((function(t){return e.getPeer(t)})))];case 1:return[2,t.sent().filter((function(e){return e&&e.tags.has(to.BOOTSTRAP)}))]}}))}))()}},{key:"getPeer",value:function(e){var t=this;return(0,K.default)((function(){var n;return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,t.libp2p.peerStore.get(e)];case 1:return[2,r.sent()];case 2:return n=r.sent(),[2,(mf.error("Failed to get peer ".concat(e,", error: ").concat(n)),null)];case 3:return[2]}}))}))()}},{key:"triggerBootstrap",value:function(){var e=this;return(0,K.default)((function(){var t,n;return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return mf.info("Triggering bootstrap discovery"),t=Object.values(e.libp2p.components.components).filter((function(e){return!!e})).filter((function(e){return["@waku/"+to.BOOTSTRAP,"@waku/"+to.PEER_CACHE].includes(null==e?void 0:e[Symbol.toStringTag])})),0===t.length?[2,void mf.warn("No bootstrap components found to trigger")]:(mf.info("Found ".concat(t.length," bootstrap components, starting them")),n=t.map(function(){var e=(0,K.default)((function(e){var t,n,r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:return i.trys.push([0,3,,4]),[4,null==e||null===(t=e.stop)||void 0===t?void 0:t.call(e)];case 1:return i.sent(),[4,null==e||null===(n=e.start)||void 0===n?void 0:n.call(e)];case 2:return i.sent(),mf.info("Successfully started bootstrap component"),[3,4];case 3:return r=i.sent(),mf.error("Failed to start bootstrap component",r),[3,4];case 4:return[2]}}))}));return function(t){return e.apply(this,arguments)}}()),[4,Promise.all(n)]);case 1:return r.sent(),[2]}}))}))()}}]),e}(),wf=new ja("dialer"),kf=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"libp2p",void 0),(0,te.default)(this,"shardReader",void 0),(0,te.default)(this,"options",void 0),(0,te.default)(this,"dialingQueue",[]),(0,te.default)(this,"dialHistory",new Map),(0,te.default)(this,"failedDials",new Map),(0,te.default)(this,"dialingInterval",null),(0,te.default)(this,"isProcessing",!1),(0,te.default)(this,"isImmediateDialing",!1),this.libp2p=t.libp2p,this.shardReader=t.shardReader,this.options=t.options}return(0,$.default)(e,[{key:"start",value:function(){var e=this;wf.info("Starting dialer"),this.dialingInterval||(this.dialingInterval=setInterval((function(){e.processQueue()}),500)),this.dialHistory.clear(),this.failedDials.clear()}},{key:"stop",value:function(){wf.info("Stopping dialer"),this.dialingInterval&&(clearInterval(this.dialingInterval),this.dialingInterval=null),this.dialHistory.clear(),this.failedDials.clear()}},{key:"dial",value:function(e){var t=this;return(0,K.default)((function(){var n,r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:return[4,t.shouldSkipPeer(e)];case 1:return i.sent()?[2,void wf.info("Skipping peer: "+e)]:(n=0===t.dialingQueue.length,r=!t.isProcessing&&!t.isImmediateDialing,n&&r?(t.isImmediateDialing=!0,wf.info("Dialed peer immediately"),[4,t.dialPeer(e)]):[3,3]);case 2:return i.sent(),t.isImmediateDialing=!1,wf.info("Released immediate dial lock"),[3,4];case 3:t.dialingQueue.push(e),wf.info("Added peer to dialing queue, queue size: "+t.dialingQueue.length),i.label=4;case 4:return[2]}}))}))()}},{key:"processQueue",value:function(){var e=this;return(0,K.default)((function(){var t;return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:if(0===e.dialingQueue.length||e.isProcessing)return[3,4];e.isProcessing=!0,n.label=1;case 1:return n.trys.push([1,,3,4]),t=e.dialingQueue.slice(0,e.options.maxDialingPeers),e.dialingQueue=e.dialingQueue.slice(t.length),wf.info("Processing dial queue: dialing ".concat(t.length," peers, ").concat(e.dialingQueue.length," remaining in queue")),[4,Promise.all(t.map((function(t){return e.dialPeer(t)})))];case 2:return n.sent(),[3,4];case 3:return e.isProcessing=!1,[7];case 4:return[2]}}))}))()}},{key:"dialPeer",value:function(e){var t=this;return(0,K.default)((function(){var n;return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),wf.info("Dialing peer from queue: "+e),[4,t.libp2p.dial(e)];case 1:return r.sent(),t.dialHistory.set(e.toString(),Date.now()),t.failedDials.delete(e.toString()),wf.info("Successfully dialed peer from queue: "+e),[3,3];case 2:return n=r.sent(),wf.error("Error dialing peer "+e,n),t.failedDials.set(e.toString(),Date.now()),[3,3];case 3:return[2]}}))}))()}},{key:"shouldSkipPeer",value:function(e){var t=this;return(0,K.default)((function(){var n;return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:if(t.libp2p.getPeers().some((function(t){return t.equals(e)})))return[2,(wf.info("Skipping peer ".concat(e," - already connected")),!0)];if(t.isRecentlyDialed(e))return[2,(wf.info("Skipping peer ".concat(e," - already dialed in the last 10 seconds")),!0)];if(t.isRecentlyFailed(e))return[2,(wf.info("Skipping peer ".concat(e," - recently failed to dial")),!0)];r.label=1;case 1:return r.trys.push([1,4,,5]),[4,t.shardReader.hasShardInfo(e)];case 2:return r.sent()?[4,t.shardReader.isPeerOnCluster(e)]:[2,(wf.info("Skipping peer ".concat(e," - no shard info")),!1)];case 3:return[2,!r.sent()&&(wf.info("Skipping peer ".concat(e," - not on same cluster")),!0)];case 4:return n=r.sent(),[2,(wf.error("Error checking shard info for peer "+e,n),!0)];case 5:return[2]}}))}))()}},{key:"isRecentlyDialed",value:function(e){var t=this.dialHistory.get(e.toString());return!!(t&&Date.now()-t<1e3*this.options.dialCooldown)}},{key:"isRecentlyFailed",value:function(e){var t=this.failedDials.get(e.toString());return!!(t&&Date.now()-t<1e3*this.options.failedDialCooldown)}}]),e}(),_f=new ja("discovery-dialer"),Ef=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"libp2p",void 0),(0,te.default)(this,"dialer",void 0),this.libp2p=t.libp2p,this.dialer=t.dialer,this.onPeerDiscovery=this.onPeerDiscovery.bind(this)}return(0,$.default)(e,[{key:"start",value:function(){this.libp2p.addEventListener("peer:discovery",this.onPeerDiscovery)}},{key:"stop",value:function(){this.libp2p.removeEventListener("peer:discovery",this.onPeerDiscovery)}},{key:"onPeerDiscovery",value:function(e){var t=this;return(0,K.default)((function(){var n,r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:n=e.detail.id,_f.info("Discovered new peer: "+n),i.label=1;case 1:return i.trys.push([1,4,,5]),[4,t.updatePeerStore(n,e.detail.multiaddrs)];case 2:return i.sent(),[4,t.dialer.dial(n)];case 3:return i.sent(),[3,5];case 4:return r=i.sent(),_f.error("Error dialing peer "+n,r),[3,5];case 5:return[2]}}))}))()}},{key:"updatePeerStore",value:function(e,t){var n=this;return(0,K.default)((function(){var r,i;return(0,pe.__generator)(this,(function(a){switch(a.label){case 0:return a.trys.push([0,5,,6]),_f.info("Updating peer store for "+e),[4,n.getPeer(e)];case 1:return(r=a.sent())?[3,3]:(_f.info("Peer ".concat(e," not found in store, saving")),[4,n.libp2p.peerStore.save(e,{multiaddrs:t})]);case 2:return[2,void a.sent()];case 3:return t.every((function(e){return r.addresses.some((function(t){return t.multiaddr.equals(e)}))}))?[2,void _f.info("Peer ".concat(e," has same addresses in peer store, skipping"))]:(_f.info("Merging peer ".concat(e," addresses in peer store")),[4,n.libp2p.peerStore.merge(e,{multiaddrs:t})]);case 4:return a.sent(),[3,6];case 5:return i=a.sent(),_f.error("Error updating peer store for "+e,i),[3,6];case 6:return[2]}}))}))()}},{key:"getPeer",value:function(e){var t=this;return(0,K.default)((function(){var n;return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,t.libp2p.peerStore.get(e)];case 1:return[2,r.sent()];case 2:return n=r.sent(),[2,void _f.error("Error getting peer info for "+e,n)];case 3:return[2]}}))}))()}}]),e}(),Sf="/relay-ping/1/ping/null",Af=new ja("keep-alive"),If=function(){"use strict";function e(t){var n=t.options,r=t.relay,i=t.networkConfig,a=t.libp2p;(0,H.default)(this,e),(0,te.default)(this,"relay",void 0),(0,te.default)(this,"networkConfig",void 0),(0,te.default)(this,"libp2p",void 0),(0,te.default)(this,"options",void 0),(0,te.default)(this,"pingKeepAliveTimers",new Map),(0,te.default)(this,"relayKeepAliveTimers",new Map),this.options=n,this.relay=r,this.networkConfig=i,this.libp2p=a,this.onPeerConnect=this.onPeerConnect.bind(this),this.onPeerDisconnect=this.onPeerDisconnect.bind(this)}return(0,$.default)(e,[{key:"start",value:function(){this.libp2p.addEventListener("peer:connect",this.onPeerConnect),this.libp2p.addEventListener("peer:disconnect",this.onPeerDisconnect)}},{key:"stop",value:function(){this.libp2p.removeEventListener("peer:connect",this.onPeerConnect),this.libp2p.removeEventListener("peer:disconnect",this.onPeerDisconnect);var e=!0,t=!1,n=void 0;try{for(var r,i=this.pingKeepAliveTimers.values()[Symbol.iterator]();!(e=(r=i.next()).done);e=!0){var a=r.value;clearInterval(a)}}catch(e){t=!0,n=e}finally{try{e||null==i.return||i.return()}finally{if(t)throw n}}var o=!0,u=!1,s=void 0,l=!0,c=!1,f=void 0;try{for(var d,h=this.relayKeepAliveTimers.values()[Symbol.iterator]();!(l=(d=h.next()).done);l=!0){var v=d.value;try{for(var p,g=v[Symbol.iterator]();!(o=(p=g.next()).done);o=!0){var y=p.value;clearInterval(y)}}catch(e){u=!0,s=e}finally{try{o||null==g.return||g.return()}finally{if(u)throw s}}}}catch(e){c=!0,f=e}finally{try{l||null==h.return||h.return()}finally{if(c)throw f}}this.pingKeepAliveTimers.clear(),this.relayKeepAliveTimers.clear()}},{key:"onPeerConnect",value:function(e){var t=e.detail;this.startPingForPeer(t)}},{key:"onPeerDisconnect",value:function(e){var t=e.detail;this.stopPingForPeer(t)}},{key:"startPingForPeer",value:function(e){this.stopPingForPeer(e),this.startLibp2pPing(e),this.startRelayPing(e)}},{key:"stopPingForPeer",value:function(e){this.stopLibp2pPing(e),this.stopRelayPing(e)}},{key:"startLibp2pPing",value:function(e){var t=this;if(0!==this.options.pingKeepAlive){var n=e.toString();if(this.pingKeepAliveTimers.has(n))Af.warn("Ping already started for peer: ".concat(n,", skipping start for libp2p ping"));else{var r=setInterval((function(){t.pingLibp2p(e)}),1e3*this.options.pingKeepAlive);this.pingKeepAliveTimers.set(n,r)}}else Af.warn("Ping keep alive is disabled pingKeepAlive:".concat(this.options.pingKeepAlive,", skipping start for libp2p ping"))}},{key:"stopLibp2pPing",value:function(e){var t=e.toString();this.pingKeepAliveTimers.has(t)?(clearInterval(this.pingKeepAliveTimers.get(t)),this.pingKeepAliveTimers.delete(t)):Af.warn("Ping not started for peer: ".concat(t,", skipping stop for ping"))}},{key:"startRelayPing",value:function(e){var t=this;if(this.relay)if(0!==this.options.relayKeepAlive)if(this.relayKeepAliveTimers.has(e.toString()))Af.warn("Relay ping already started for peer: ".concat(e.toString(),", skipping start for relay ping"));else{var n=[],r=!0,i=!1,a=void 0;try{for(var o,u=this,s=function(){var r=o.value;if(!u.relay.getMeshPeers(r).includes(e.toString()))return Af.warn("Peer: ".concat(e.toString()," is not in the mesh for topic: ").concat(r,", skipping start for relay ping")),"continue";var i=Xa({routingInfo:ji(u.networkConfig,{contentTopic:Sf,pubsubTopic:r}),contentTopic:Sf,ephemeral:!0}),a=setInterval((function(){t.pingRelay(i)}),1e3*u.options.relayKeepAlive);n.push(a)},l=this.relay.pubsubTopics[Symbol.iterator]();!(r=(o=l.next()).done);r=!0)s()}catch(e){i=!0,a=e}finally{try{r||null==l.return||l.return()}finally{if(i)throw a}}this.relayKeepAliveTimers.set(e.toString(),n)}else Af.warn("Relay keep alive is disabled relayKeepAlive:".concat(this.options.relayKeepAlive,", skipping start for relay ping"))}},{key:"stopRelayPing",value:function(e){var t;if(this.relay){var n=e.toString();this.relayKeepAliveTimers.has(n)?(null===(t=this.relayKeepAliveTimers.get(n))||void 0===t||t.map(clearInterval),this.relayKeepAliveTimers.delete(n)):Af.warn("Relay ping not started for peer: ".concat(n,", skipping stop for relay ping"))}}},{key:"pingRelay",value:function(e){var t=this;return(0,K.default)((function(){var n;return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),Af.info("Sending Waku Relay ping message"),[4,t.relay.send(e,{payload:new Uint8Array([1])})];case 1:return r.sent(),[3,3];case 2:return n=r.sent(),Af.error("Failed to send relay ping",n),[3,3];case 3:return[2]}}))}))()}},{key:"pingLibp2p",value:function(e){var t=this;return(0,K.default)((function(){var n,r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:return i.trys.push([0,3,,4]),Af.info("Pinging libp2p peer (".concat(e.toString(),")")),[4,t.libp2p.services.ping.ping(e)];case 1:return n=i.sent(),Af.info("Ping succeeded (".concat(e.toString(),")"),n),[4,t.libp2p.peerStore.merge(e,{metadata:{ping:Mi(n.toString())}})];case 2:return i.sent(),Af.info("Ping updated for peer (".concat(e.toString(),")")),[3,4];case 3:return r=i.sent(),Af.error("Ping failed for peer (".concat(e.toString(),")"),r),[3,4];case 4:return[2]}}))}))()}}]),e}(),xf=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"libp2p",void 0),(0,te.default)(this,"events",void 0),(0,te.default)(this,"isNetworkConnected",!1),this.libp2p=t.libp2p,this.events=t.events,this.onConnectedEvent=this.onConnectedEvent.bind(this),this.onDisconnectedEvent=this.onDisconnectedEvent.bind(this),this.dispatchNetworkEvent=this.dispatchNetworkEvent.bind(this)}return(0,$.default)(e,[{key:"start",value:function(){this.libp2p.addEventListener("peer:connect",this.onConnectedEvent),this.libp2p.addEventListener("peer:disconnect",this.onDisconnectedEvent);try{globalThis.addEventListener("online",this.dispatchNetworkEvent),globalThis.addEventListener("offline",this.dispatchNetworkEvent)}catch(e){}}},{key:"stop",value:function(){this.libp2p.removeEventListener("peer:connect",this.onConnectedEvent),this.libp2p.removeEventListener("peer:disconnect",this.onDisconnectedEvent);try{globalThis.removeEventListener("online",this.dispatchNetworkEvent),globalThis.removeEventListener("offline",this.dispatchNetworkEvent)}catch(e){}}},{key:"isConnected",value:function(){return!!this.isBrowserConnected()&&this.isP2PConnected()}},{key:"isP2PConnected",value:function(){return this.isNetworkConnected}},{key:"isBrowserConnected",value:function(){try{var e;if((null===globalThis||void 0===globalThis?void 0:globalThis.navigator)&&!(null===globalThis||void 0===globalThis||null===(e=globalThis.navigator)||void 0===e?void 0:e.onLine))return!1}catch(e){}return!0}},{key:"onConnectedEvent",value:function(){this.isNetworkConnected||(this.isNetworkConnected=!0,this.dispatchNetworkEvent())}},{key:"onDisconnectedEvent",value:function(){this.isNetworkConnected&&0===this.libp2p.getConnections().length&&(this.isNetworkConnected=!1,this.dispatchNetworkEvent())}},{key:"dispatchNetworkEvent",value:function(){this.events.dispatchEvent(new CustomEvent(eo.Connection,{detail:this.isConnected()}))}}]),e}(),Cf=new ja("shard-reader"),Tf=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"libp2p",void 0),(0,te.default)(this,"clusterId",void 0),this.libp2p=t.libp2p,this.clusterId=t.networkConfig.clusterId}return(0,$.default)(e,[{key:"isPeerOnCluster",value:function(e){var t=this;return(0,K.default)((function(){var n;return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return[4,t.getRelayShards(e)];case 1:return[2,!!(n=r.sent())&&n.clusterId===t.clusterId]}}))}))()}},{key:"hasShardInfo",value:function(e){var t=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:return[4,t.getRelayShards(e)];case 1:return[2,!!n.sent()]}}))}))()}},{key:"isPeerOnTopic",value:function(e,t){var n=this;return(0,K.default)((function(){var r,i,a,o,u;return(0,pe.__generator)(this,(function(s){switch(s.label){case 0:return s.trys.push([0,3,,4]),r=Ui(t),i=r.clusterId,a=r.shard,(o=i===n.clusterId)?[4,n.isPeerOnShard(e,a)]:[3,2];case 1:o=s.sent(),s.label=2;case 2:return[2,o];case 3:return u=s.sent(),[2,(Cf.error("Error comparing pubsub topic ".concat(t," with shard info for ").concat(e),u),!1)];case 4:return[2]}}))}))()}},{key:"isPeerOnShard",value:function(e,t){var n=this;return(0,K.default)((function(){var r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:return[4,n.getRelayShards(e)];case 1:return r=i.sent(),[2,(Cf.info("Checking if peer on same shard: this { clusterId: ".concat(n.clusterId,", shardId: ").concat(t," },").concat(e," { clusterId: ").concat(null==r?void 0:r.clusterId,", shards: ").concat(null==r?void 0:r.shards," }")),!!r&&r.clusterId===n.clusterId&&r.shards.includes(t))]}}))}))()}},{key:"getRelayShards",value:function(e){var t=this;return(0,K.default)((function(){var n,r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,t.libp2p.peerStore.get(e)];case 1:return(n=i.sent().metadata.get("shardInfo"))?[2,Ki(n)]:[2];case 2:return r=i.sent(),[2,void Cf.error("Error getting shard info for "+e,r)];case 3:return[2]}}))}))()}}]),e}(),Pf=new ja("connection-manager"),Rf=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"keepAliveManager",void 0),(0,te.default)(this,"discoveryDialer",void 0),(0,te.default)(this,"dialer",void 0),(0,te.default)(this,"shardReader",void 0),(0,te.default)(this,"networkMonitor",void 0),(0,te.default)(this,"connectionLimiter",void 0),(0,te.default)(this,"options",void 0),(0,te.default)(this,"libp2p",void 0),this.libp2p=t.libp2p,this.options=(0,ae.default)({maxBootstrapPeers:3,maxConnections:10,pingKeepAlive:300,relayKeepAlive:300,enableAutoRecovery:!0,maxDialingPeers:3,failedDialCooldown:60,dialCooldown:10},t.config),this.keepAliveManager=new If({relay:t.relay,libp2p:t.libp2p,networkConfig:t.networkConfig,options:{pingKeepAlive:this.options.pingKeepAlive,relayKeepAlive:this.options.relayKeepAlive}}),this.shardReader=new Tf({libp2p:t.libp2p,networkConfig:t.networkConfig}),this.dialer=new kf({libp2p:t.libp2p,shardReader:this.shardReader,options:this.options}),this.discoveryDialer=new Ef({libp2p:t.libp2p,dialer:this.dialer}),this.networkMonitor=new xf({libp2p:t.libp2p,events:t.events}),this.connectionLimiter=new bf({libp2p:t.libp2p,events:t.events,networkMonitor:this.networkMonitor,dialer:this.dialer,options:this.options})}return(0,$.default)(e,[{key:"start",value:function(){this.dialer.start(),this.networkMonitor.start(),this.discoveryDialer.start(),this.keepAliveManager.start(),this.connectionLimiter.start()}},{key:"stop",value:function(){this.dialer.stop(),this.networkMonitor.stop(),this.discoveryDialer.stop(),this.keepAliveManager.stop(),this.connectionLimiter.stop()}},{key:"isConnected",value:function(){return this.networkMonitor.isConnected()}},{key:"dial",value:function(e,t){var n=this;return(0,K.default)((function(){var r,i,a;return(0,pe.__generator)(this,(function(o){switch(o.label){case 0:return r=Yi(i=e)?i:pf(i),Pf.info("Dialing peer ".concat(r.toString()," with protocols ").concat(t)),[4,n.libp2p.dialProtocol(r,t)];case 1:return a=o.sent(),[2,(Pf.info("Dialed peer ".concat(r.toString()," with protocols ").concat(t)),a)]}}))}))()}},{key:"hangUp",value:function(e){var t=this;return(0,K.default)((function(){var n,r,i;return(0,pe.__generator)(this,(function(a){switch(a.label){case 0:n=Yi(r=e)?r:kc(pf(r).getPeerId()),a.label=1;case 1:return a.trys.push([1,3,,4]),Pf.info("Dropping connection with peer "+n.toString()),[4,t.libp2p.hangUp(n)];case 2:return[2,(a.sent(),Pf.info("Dropped connection with peer "+n.toString()),!0)];case 3:return i=a.sent(),[2,(Pf.error("Error dropping connection with peer ".concat(n.toString()," - ").concat(i)),!1)];case 4:return[2]}}))}))()}},{key:"getConnectedPeers",value:function(e){var t=this;return(0,K.default)((function(){var n,r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:return n=t.libp2p.getPeers(),Pf.info("Getting connected peers for codec "+e),0===n.length?[2,(Pf.info("No connected peers"),[])]:[4,Promise.all(n.map(function(){var e=(0,K.default)((function(e){return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,t.libp2p.peerStore.get(e)];case 1:return[2,n.sent()];case 2:return n.sent(),[2,null];case 3:return[2]}}))}));return function(t){return e.apply(this,arguments)}}()))];case 1:return r=i.sent().filter((function(e){return!!e})).filter((function(t){return!e||t.protocols.includes(e)})).sort((function(e,t){return yf(e)-yf(t)})),[2,(Pf.info("Found ".concat(r.length," connected peers for codec ").concat(e)),r)]}}))}))()}},{key:"hasShardInfo",value:function(e){var t=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(n){return[2,t.shardReader.hasShardInfo(e)]}))}))()}},{key:"isPeerOnTopic",value:function(e,t){var n=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(r){return[2,n.shardReader.isPeerOnTopic(e,t)]}))}))()}},{key:"isPeerOnShard",value:function(e,t){var n=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(r){return[2,n.shardReader.isPeerOnShard(e,t)]}))}))()}}]),e}(),Lf=new ja("metadata"),Df="/vac/waku/metadata/1.0.0",Mf=function(){"use strict";function e(t,n){var r=this;(0,H.default)(this,e),(0,te.default)(this,"clusterId",void 0),(0,te.default)(this,"streamManager",void 0),(0,te.default)(this,"libp2pComponents",void 0),(0,te.default)(this,"handshakesConfirmed",new Map),(0,te.default)(this,"multicodec",Df),this.clusterId=t,this.streamManager=new Xo(Df,n),this.libp2pComponents=n,n.registrar.handle(Df,(function(e){r.onRequest(e)}))}return(0,$.default)(e,[{key:"query",value:function(e){var t=this;return(0,K.default)((function(){var n,r,i,a,o,u,s;return(0,pe.__generator)(this,(function(l){switch(l.label){case 0:return n=ur.encode({clusterId:t.clusterId,shards:[]}),[4,t.libp2pComponents.peerStore.get(e)];case 1:return l.sent()?[4,t.streamManager.getStream(e)]:[2,{shardInfo:null,error:$a.NO_PEER_AVAILABLE}];case 2:return(r=l.sent())?[4,Bo([n],mo,r,Ao,function(){var e=(0,K.default)((function(e){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return[4,oo(e)];case 1:return[2,t.sent()]}}))}));return function(t){return e.apply(this,arguments)}}())]:[2,(Lf.error("Failed to get a stream for remote peer:"+e.toString()),{shardInfo:null,error:$a.NO_STREAM_AVAILABLE})];case 3:return i=l.sent(),a=t.decodeMetadataResponse(i),o=a.error,u=a.shardInfo,o?(s={shardInfo:null,error:o},[3,6]):[3,4];case 4:return[4,t.savePeerShardInfo(e,u)];case 5:l.sent(),s={shardInfo:u,error:null},l.label=6;case 6:return[2,s]}}))}))()}},{key:"confirmOrAttemptHandshake",value:function(e){var t=this;return(0,K.default)((function(){var n,r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:return(n=t.handshakesConfirmed.get(e.toString()))?(r={shardInfo:n,error:null},[3,3]):[3,1];case 1:return[4,t.query(e)];case 2:r=i.sent(),i.label=3;case 3:return[2,r]}}))}))()}},{key:"onRequest",value:function(e){var t=this;return(0,K.default)((function(){var n,r,i,a,o,u,s;return(0,pe.__generator)(this,(function(l){switch(l.label){case 0:return l.trys.push([0,3,,4]),n=e.stream,r=e.connection,[4,Bo([sr.encode({clusterId:t.clusterId,shards:[]})],mo,n,Ao,function(){var e=(0,K.default)((function(e){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return[4,oo(e)];case 1:return[2,t.sent()]}}))}));return function(t){return e.apply(this,arguments)}}())];case 1:return i=l.sent(),a=t.decodeMetadataResponse(i),o=a.error,u=a.shardInfo,o?[2]:[4,t.savePeerShardInfo(r.remotePeer,u)];case 2:return l.sent(),[3,4];case 3:return s=l.sent(),Lf.error("Error handling metadata request",s),[3,4];case 4:return[2]}}))}))()}},{key:"decodeMetadataResponse",value:function(e){var t=new po;e.forEach((function(e){t.append(e)}));var n=sr.decode(t);return n?{shardInfo:n,error:null}:(Lf.error("Error decoding metadata response"),{shardInfo:null,error:$a.DECODE_FAILED})}},{key:"savePeerShardInfo",value:function(e,t){var n=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return[4,n.libp2pComponents.peerStore.merge(e,{metadata:{shardInfo:Vi(t)}})];case 1:return r.sent(),n.handshakesConfirmed.set(e.toString(),t),[2]}}))}))()}}]),e}();function Nf(e){return function(t){return new Mf(e,t)}}var Of,Uf=new ja("peer-manager");!function(e){e.FilterConnect="filter:connect",e.FilterDisconnect="filter:disconnect",e.StoreConnect="store:connect"}(Of||(Of={}));var Ff,Bf,qf=function(){"use strict";function e(t){var n;(0,H.default)(this,e),(0,te.default)(this,"events",new xa),(0,te.default)(this,"numPeersToUse",void 0),(0,te.default)(this,"libp2p",void 0),(0,te.default)(this,"connectionManager",void 0),(0,te.default)(this,"lockedPeers",new Set),(0,te.default)(this,"unlockedPeers",new Map),this.onConnected=this.onConnected.bind(this),this.onDisconnected=this.onDisconnected.bind(this),this.numPeersToUse=(null==t||null===(n=t.config)||void 0===n?void 0:n.numPeersToUse)||2,this.libp2p=t.libp2p,this.connectionManager=t.connectionManager}return(0,$.default)(e,[{key:"start",value:function(){this.libp2p.addEventListener("peer:identify",this.onConnected),this.libp2p.addEventListener("peer:disconnect",this.onDisconnected)}},{key:"stop",value:function(){this.libp2p.removeEventListener("peer:identify",this.onConnected),this.libp2p.removeEventListener("peer:disconnect",this.onDisconnected)}},{key:"getPeers",value:function(e){var t=this;return(0,K.default)((function(){var n,r,i,a,o,u,s,l,c,f,d,h,v,p,g,y;return(0,pe.__generator)(this,(function(m){switch(m.label){case 0:return Uf.info("Getting peers for protocol: ".concat(e.protocol,", pubsubTopic: ").concat(e.pubsubTopic)),[4,t.connectionManager.getConnectedPeers()];case 1:n=m.sent(),Uf.info("Found ".concat(n.length," connected peers")),r=[],i=!0,a=!1,o=void 0,m.label=2;case 2:m.trys.push([2,7,8,9]),u=n[Symbol.iterator](),m.label=3;case 3:return(i=(s=u.next()).done)?[3,6]:(l=s.value,c=t.hasPeerProtocol(l,e.protocol),[4,t.isPeerOnPubsub(l.id,e.pubsubTopic)]);case 4:f=m.sent(),d=t.isPeerAvailableForUse(l.id),c&&f&&d&&(r.push(l),Uf.info("Peer ".concat(l.id," qualifies for protocol ").concat(e.protocol))),m.label=5;case 5:return i=!0,[3,3];case 6:return[3,9];case 7:return h=m.sent(),a=!0,o=h,[3,9];case 8:try{i||null==u.return||u.return()}finally{if(a)throw o}return[7];case 9:return v=r.filter((function(e){return t.isPeerLocked(e.id)})),Uf.info("Found ".concat(v.length," locked peers out of ").concat(r.length," qualifying peers")),v.length>=t.numPeersToUse?(p=v.slice(0,t.numPeersToUse).map((function(e){return e.id})),[2,(Uf.info("Using ".concat(p.length," locked peers: ").concat(p.map((function(e){return e.toString()})))),p)]):(g=r.filter((function(e){return!t.isPeerLocked(e.id)})),Uf.info("Found ".concat(g.length," unlocked peers, need ").concat(t.numPeersToUse-v.length," more")),r=(0,ce.default)(v).concat((0,ce.default)(g)).slice(0,t.numPeersToUse).map((function(e){return t.lockPeer(e.id),e})),y=r.map((function(e){return e.id})),[2,(Uf.info("Selected ".concat(y.length," peers: ").concat(y.map((function(e){return e.toString()})))),y)])}}))}))()}},{key:"renewPeer",value:function(e,t){var n=this;return(0,K.default)((function(){var r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:return Uf.info("Renewing peer ".concat(e," for protocol: ").concat(t.protocol,", pubsubTopic: ").concat(t.pubsubTopic)),[4,n.connectionManager.getConnectedPeers()];case 1:return r=i.sent().find((function(t){return t.id.equals(e)})),r?(Uf.info("Found peer ".concat(e," in connected peers, unlocking and getting new peers")),n.unlockPeer(r.id),[4,n.getPeers(t)]):[3,3];case 2:return i.sent(),[3,4];case 3:Uf.warn("Cannot renew peer:".concat(e,", no connection to the peer.")),i.label=4;case 4:return[2]}}))}))()}},{key:"isPeerOnPubsub",value:function(e,t){var n=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return[4,n.connectionManager.hasShardInfo(e)];case 1:return[2,!r.sent()||n.connectionManager.isPeerOnTopic(e,t)]}}))}))()}},{key:"onConnected",value:function(e){var t=this;return(0,K.default)((function(){var n,r,i;return(0,pe.__generator)(this,(function(a){return n=e.detail,r=n.protocols.includes(t.getProtocolCodecs(Za.Filter)),i=n.protocols.includes(t.getProtocolCodecs(Za.Store)),r&&t.dispatchFilterPeerConnect(n.peerId),i&&t.dispatchStorePeerConnect(n.peerId),[2]}))}))()}},{key:"onDisconnected",value:function(e){var t=this;return(0,K.default)((function(){var n,r,i;return(0,pe.__generator)(this,(function(a){switch(a.label){case 0:n=e.detail,a.label=1;case 1:return a.trys.push([1,3,,4]),[4,t.libp2p.peerStore.get(n)];case 2:return r=a.sent(),t.hasPeerProtocol(r,Za.Filter)&&t.dispatchFilterPeerDisconnect(r.id),[3,4];case 3:return i=a.sent(),Uf.error("Failed to dispatch Filter disconnect event:"+i),[3,4];case 4:return[2]}}))}))()}},{key:"hasPeerProtocol",value:function(e,t){return e.protocols.includes(this.getProtocolCodecs(t))}},{key:"lockPeer",value:function(e){Uf.info("Locking peer "+e),this.lockedPeers.add(e.toString()),this.libp2p.getConnections().filter((function(t){return t.remotePeer.equals(e)})).forEach((function(e){return e.tags.push(io)})),this.unlockedPeers.delete(e.toString())}},{key:"isPeerLocked",value:function(e){return this.lockedPeers.has(e.toString())}},{key:"unlockPeer",value:function(e){Uf.info("Unlocking peer "+e),this.lockedPeers.delete(e.toString()),this.libp2p.getConnections().filter((function(t){return t.remotePeer.equals(e)})).forEach((function(e){e.tags=e.tags.filter((function(e){return e!==io}))})),this.unlockedPeers.set(e.toString(),Date.now())}},{key:"isPeerAvailableForUse",value:function(e){var t=this.unlockedPeers.get(e.toString());if(!t)return!0;var n=new Date(t).getTime();return Date.now()-n>=1e4}},{key:"dispatchFilterPeerConnect",value:function(e){this.events.dispatchEvent(new CustomEvent(Of.FilterConnect,{detail:e}))}},{key:"dispatchStorePeerConnect",value:function(e){this.events.dispatchEvent(new CustomEvent(Of.StoreConnect,{detail:e}))}},{key:"dispatchFilterPeerDisconnect",value:function(e){this.events.dispatchEvent(new CustomEvent(Of.FilterDisconnect,{detail:e}))}},{key:"getProtocolCodecs",value:function(e){if(e===Za.Relay)throw Error("Relay protocol is not supported");var t;return(t={},(0,te.default)(t,Za.Filter,au),(0,te.default)(t,Za.LightPush,fu),(0,te.default)(t,Za.Store,Su),(0,te.default)(t,"light-push-v2",cu),t)[e]}}]),e}(),zf=function(){"use strict";function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:5e3;(0,H.default)(this,e),(0,te.default)(this,"ttlMs",void 0),(0,te.default)(this,"cleanupIntervalId",null),(0,te.default)(this,"entryTimestamps",new Map),this.ttlMs=t,this.startCleanupInterval(n)}return(0,$.default)(e,[{key:"dispose",value:function(){null!==this.cleanupIntervalId&&(clearInterval(this.cleanupIntervalId),this.cleanupIntervalId=null),this.entryTimestamps.clear()}},{key:"add",value:function(e){return this.entryTimestamps.set(e,Date.now()),this}},{key:"has",value:function(e){return this.entryTimestamps.has(e)}},{key:"startCleanupInterval",value:function(e){var t=this;this.cleanupIntervalId=setInterval((function(){t.removeExpiredEntries()}),e)}},{key:"removeExpiredEntries",value:function(){var e=Date.now(),t=!0,n=!1,r=void 0;try{for(var i,a=this.entryTimestamps.entries()[Symbol.iterator]();!(t=(i=a.next()).done);t=!0){var o=(0,se.default)(i.value,2),u=o[0];e-o[1]>this.ttlMs&&this.entryTimestamps.delete(u)}}catch(e){n=!0,r=e}finally{try{t||null==a.return||a.return()}finally{if(n)throw r}}}}]),e}(),jf=new ja("sdk:filter-subscription"),Kf=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"pubsubTopic",void 0),(0,te.default)(this,"protocol",void 0),(0,te.default)(this,"peerManager",void 0),(0,te.default)(this,"config",void 0),(0,te.default)(this,"isStarted",!1),(0,te.default)(this,"inProgress",!1),(0,te.default)(this,"peers",new Map),(0,te.default)(this,"peerFailures",new Map),(0,te.default)(this,"receivedMessages",new zf(6e4)),(0,te.default)(this,"callbacks",new Map),(0,te.default)(this,"messageEmitter",new xa),(0,te.default)(this,"toSubscribeContentTopics",new Set),(0,te.default)(this,"toUnsubscribeContentTopics",new Set),(0,te.default)(this,"subscribeIntervalId",null),(0,te.default)(this,"keepAliveIntervalId",null),this.config=t.config,this.pubsubTopic=t.pubsubTopic,this.protocol=t.protocol,this.peerManager=t.peerManager,this.onPeerConnected=this.onPeerConnected.bind(this),this.onPeerDisconnected=this.onPeerDisconnected.bind(this)}return(0,$.default)(e,[{key:"contentTopics",get:function(){var e=Array.from(this.callbacks.keys()).map((function(e){return e.contentTopic})),t=new Set(e).values();return Array.from(t)}},{key:"start",value:function(){jf.info("Starting subscription for pubsubTopic: "+this.pubsubTopic),this.isStarted||this.inProgress?jf.info("Subscription already started or in progress, skipping start"):(this.inProgress=!0,this.attemptSubscribe({useNewContentTopics:!1}),this.setupSubscriptionInterval(),this.setupKeepAliveInterval(),this.setupEventListeners(),this.isStarted=!0,this.inProgress=!1,jf.info("Subscription started for pubsubTopic: "+this.pubsubTopic))}},{key:"stop",value:function(){jf.info("Stopping subscription for pubsubTopic: "+this.pubsubTopic),this.isStarted&&!this.inProgress?(this.inProgress=!0,this.disposeEventListeners(),this.disposeIntervals(),this.disposePeers(),this.disposeHandlers(),this.receivedMessages.dispose(),this.inProgress=!1,this.isStarted=!1,jf.info("Subscription stopped for pubsubTopic: "+this.pubsubTopic)):jf.info("Subscription not started or stop in progress, skipping stop")}},{key:"isEmpty",value:function(){return 0===this.callbacks.size}},{key:"add",value:function(e,t){var n=this;return(0,K.default)((function(){var r,i,a,o,u,s,l,c;return(0,pe.__generator)(this,(function(f){switch(f.label){case 0:r=Array.isArray(e)?e:[e],i=!0,a=!1,o=void 0;try{for(u=r[Symbol.iterator]();!(i=(s=u.next()).done);i=!0)l=s.value,n.addSingle(l,t)}catch(e){a=!0,o=e}finally{try{i||null==u.return||u.return()}finally{if(a)throw o}}return(c=!(n.toSubscribeContentTopics.size>0))?[3,2]:[4,n.attemptSubscribe({useNewContentTopics:!0})];case 1:c=f.sent(),f.label=2;case 2:return[2,c]}}))}))()}},{key:"remove",value:function(e){var t=this;return(0,K.default)((function(){var n,r,i,a,o,u,s,l;return(0,pe.__generator)(this,(function(c){switch(c.label){case 0:n=Array.isArray(e)?e:[e],r=!0,i=!1,a=void 0;try{for(o=n[Symbol.iterator]();!(r=(u=o.next()).done);r=!0)s=u.value,t.removeSingle(s)}catch(e){i=!0,a=e}finally{try{r||null==o.return||o.return()}finally{if(i)throw a}}return(l=!(t.toUnsubscribeContentTopics.size>0))?[3,2]:[4,t.attemptUnsubscribe({useNewContentTopics:!0})];case 1:l=c.sent(),c.label=2;case 2:return[2,l]}}))}))()}},{key:"invoke",value:function(e,t){this.isMessageReceived(e)?jf.info("Skipping invoking callbacks for already received message: pubsubTopic:".concat(this.pubsubTopic,", peerId:").concat(t.toString(),", contentTopic:").concat(e.contentTopic)):(jf.info("Invoking message for contentTopic: "+e.contentTopic),this.messageEmitter.dispatchEvent(new CustomEvent(e.contentTopic,{detail:e})))}},{key:"addSingle",value:function(e,t){jf.info("Adding subscription for contentTopic: "+e.contentTopic);var n=!this.contentTopics.includes(e.contentTopic);if(n&&this.toSubscribeContentTopics.add(e.contentTopic),this.callbacks.has(e)){jf.warn("Replacing callback associated associated with decoder with pubsubTopic:".concat(e.pubsubTopic," and contentTopic:").concat(e.contentTopic));var r=this.callbacks.get(e);this.callbacks.delete(e),this.messageEmitter.removeEventListener(e.contentTopic,r)}var i=function(n){(0,K.default)((function(){var r,i;return(0,pe.__generator)(this,(function(a){switch(a.label){case 0:return a.trys.push([0,2,,3]),[4,e.fromProtoObj(e.pubsubTopic,n.detail)];case 1:return r=a.sent(),t(r),[3,3];case 2:return i=a.sent(),jf.error("Error decoding message",i),[3,3];case 3:return[2]}}))}))()};this.callbacks.set(e,i),this.messageEmitter.addEventListener(e.contentTopic,i),jf.info("Subscription added for contentTopic: ".concat(e.contentTopic,", isNewContentTopic: ").concat(n))}},{key:"removeSingle",value:function(e){jf.info("Removing subscription for contentTopic: "+e.contentTopic);var t=this.callbacks.get(e);t||jf.warn("No callback associated with decoder with pubsubTopic:".concat(e.pubsubTopic," and contentTopic:").concat(e.contentTopic)),this.callbacks.delete(e),this.messageEmitter.removeEventListener(e.contentTopic,t);var n=!this.contentTopics.includes(e.contentTopic);n&&this.toUnsubscribeContentTopics.add(e.contentTopic),jf.info("Subscription removed for contentTopic: ".concat(e.contentTopic,", isCompletelyRemoved: ").concat(n))}},{key:"isMessageReceived",value:function(e){try{var t=function(e,t){var n=Ka(e,t);return Li(n)}(this.pubsubTopic,e);if(this.receivedMessages.has(t))return!0;this.receivedMessages.add(t)}catch(e){}return!1}},{key:"setupSubscriptionInterval",value:function(){var e=this;jf.info("Setting up subscription interval with period 1000ms"),this.subscribeIntervalId=setInterval((function(){var t=e;(0,K.default)((function(){return(0,pe.__generator)(this,(function(e){switch(e.label){case 0:return t.toSubscribeContentTopics.size>0?(jf.info("Subscription interval: ".concat(t.toSubscribeContentTopics.size," topics to subscribe")),[4,t.attemptSubscribe({useNewContentTopics:!0})]):[3,2];case 1:e.sent(),e.label=2;case 2:return t.toUnsubscribeContentTopics.size>0?(jf.info("Subscription interval: ".concat(t.toUnsubscribeContentTopics.size," topics to unsubscribe")),[4,t.attemptUnsubscribe({useNewContentTopics:!0})]):[3,4];case 3:e.sent(),e.label=4;case 4:return[2]}}))}))()}),1e3)}},{key:"setupKeepAliveInterval",value:function(){var e=this;jf.info("Setting up keep-alive interval with period ".concat(this.config.keepAliveIntervalMs,"ms")),this.keepAliveIntervalId=setInterval((function(){var t=e;(0,K.default)((function(){var e;return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:return jf.info("Keep-alive interval running for ".concat(t.peers.size," peers")),[4,Promise.all(Array.from(t.peers.values()).map(function(){var e=(0,K.default)((function(e){var n;return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return[4,t.protocol.ping(e)];case 1:return r.sent().success?[2,(jf.info("Ping successful for peer: "+e.toString()),void t.peerFailures.set(e.toString(),0))]:(n=t.peerFailures.get(e.toString())||0,[2,(n+=1,t.peerFailures.set(e.toString(),n),jf.warn("Ping failed for peer: ".concat(e.toString(),", failures: ").concat(n,"/").concat(t.config.pingsBeforePeerRenewed)),n<t.config.pingsBeforePeerRenewed?void 0:(jf.info("Peer ".concat(e.toString()," exceeded max failures (").concat(t.config.pingsBeforePeerRenewed,"), will be replaced")),e))])}}))}));return function(t){return e.apply(this,arguments)}}()))];case 1:return e=(e=n.sent()).filter((function(e){return!!e})),[4,Promise.all(e.map((function(e){return t.peers.delete(null==e?void 0:e.toString()),t.peerFailures.delete(null==e?void 0:e.toString()),t.requestUnsubscribe(e,t.contentTopics)})))];case 2:return n.sent(),e.length>0?(jf.info("Replacing ".concat(e.length," failed peers")),[4,t.attemptSubscribe({useNewContentTopics:!1,useOnlyNewPeers:!0})]):[3,4];case 3:n.sent(),n.label=4;case 4:return[2]}}))}))()}),this.config.keepAliveIntervalMs)}},{key:"setupEventListeners",value:function(){this.peerManager.events.addEventListener(Of.FilterConnect,this.onPeerConnected),this.peerManager.events.addEventListener(Of.FilterDisconnect,this.onPeerDisconnected)}},{key:"disposeIntervals",value:function(){this.subscribeIntervalId&&clearInterval(this.subscribeIntervalId),this.keepAliveIntervalId&&clearInterval(this.keepAliveIntervalId)}},{key:"disposeHandlers",value:function(){var e=!0,t=!1,n=void 0;try{for(var r,i=this.callbacks.entries()[Symbol.iterator]();!(e=(r=i.next()).done);e=!0){var a=(0,se.default)(r.value,2),o=a[0],u=a[1];this.messageEmitter.removeEventListener(o.contentTopic,u)}}catch(e){t=!0,n=e}finally{try{e||null==i.return||i.return()}finally{if(t)throw n}}this.callbacks.clear()}},{key:"disposePeers",value:function(){var e=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return[4,e.attemptUnsubscribe({useNewContentTopics:!1})];case 1:return t.sent(),e.peers.clear(),e.peerFailures=new Map,[2]}}))}))()}},{key:"disposeEventListeners",value:function(){this.peerManager.events.removeEventListener(Of.FilterConnect,this.onPeerConnected),this.peerManager.events.removeEventListener(Of.FilterDisconnect,this.onPeerDisconnected)}},{key:"onPeerConnected",value:function(e){var t=this;return(0,K.default)((function(){var n,r,i;return(0,pe.__generator)(this,(function(a){switch(a.label){case 0:return r=null===(n=e.detail)||void 0===n?void 0:n.toString(),jf.info("Peer connected: "+r),[4,t.peerManager.isPeerOnPubsub(e.detail,t.pubsubTopic)];case 1:return a.sent()?t.peers.has(r)?(i=jf.info("Peer ".concat(r," already subscribed, skipping")),[3,4]):[3,2]:[3,5];case 2:return[4,t.attemptSubscribe({useNewContentTopics:!1,useOnlyNewPeers:!0})];case 3:i=a.sent(),a.label=4;case 4:return i,[3,6];case 5:jf.info("Peer ".concat(r," doesn't support pubsubTopic:").concat(t.pubsubTopic)),a.label=6;case 6:return[2]}}))}))()}},{key:"onPeerDisconnected",value:function(e){var t=this;return(0,K.default)((function(){var n,r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:return r=null===(n=e.detail)||void 0===n?void 0:n.toString(),jf.info("Peer disconnected: "+r),[4,t.peerManager.isPeerOnPubsub(e.detail,t.pubsubTopic)];case 1:return i.sent()?t.peers.has(r)?(jf.info("Active peer ".concat(r," disconnected, removing from peers list")),t.peers.delete(r),t.attemptSubscribe({useNewContentTopics:!1,useOnlyNewPeers:!0})):jf.info("Disconnected peer ".concat(r," not in use, ignoring")):jf.info("Peer ".concat(r," doesn't support pubsubTopic:").concat(t.pubsubTopic)),[2]}}))}))()}},{key:"attemptSubscribe",value:function(e){var t=this;return(0,K.default)((function(){var n,r,i,a,o,u,s,l,c,f,d,h,v,p,g;return(0,pe.__generator)(this,(function(y){switch(y.label){case 0:return n=e.useNewContentTopics,r=e.useOnlyNewPeers,i=void 0!==r&&r,a=n?Array.from(t.toSubscribeContentTopics):t.contentTopics,jf.info("Attempting to subscribe: useNewContentTopics=".concat(n,", useOnlyNewPeers=").concat(i,", contentTopics=").concat(a.length)),a.length?(o=new Set(t.peers.keys()),[4,t.peerManager.getPeers({protocol:Za.Filter,pubsubTopic:t.pubsubTopic})]):[2,(jf.warn("Requested content topics is an empty array, skipping"),!1)];case 1:u=y.sent(),s=!0,l=!1,c=void 0;try{for(f=u[Symbol.iterator]();!(s=(d=f.next()).done)&&(h=d.value,!(t.peers.size>=t.config.numPeersToUse));s=!0)t.peers.set(h.toString(),h)}catch(e){l=!0,c=e}finally{try{s||null==f.return||f.return()}finally{if(l)throw c}}return v=i?Array.from(t.peers.values()).filter((function(e){return!o.has(e.toString())})):Array.from(t.peers.values()),jf.info("Subscribing with ".concat(v.length," peers for ").concat(a.length," content topics")),i&&0===v.length?[2,(jf.warn("Requested to use only new peers, but no peers found, skipping"),!1)]:[4,Promise.all(v.map((function(e){return t.requestSubscribe(e,a)})))];case 2:return p=y.sent(),g=p.filter((function(e){return e})).length,[2,(jf.info("Subscribe attempts completed: ".concat(g,"/").concat(p.length," successful")),n&&(t.toSubscribeContentTopics=new Set),p.some((function(e){return e})))]}}))}))()}},{key:"requestSubscribe",value:function(e,t){var n=this;return(0,K.default)((function(){var r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:return jf.info("requestSubscribe: pubsubTopic:".concat(n.pubsubTopic,"\tcontentTopics:").concat(t.join(","))),t.length&&n.pubsubTopic?[4,n.protocol.subscribe(n.pubsubTopic,e,t)]:[2,(jf.warn("requestSubscribe: no contentTopics or pubsubTopic provided, not sending subscribe request"),!1)];case 1:return[2,(r=i.sent()).failure?(jf.warn("requestSubscribe: Failed to subscribe ".concat(n.pubsubTopic," to ").concat(e.toString()," with error:").concat(r.failure.error," for contentTopics:").concat(t)),!1):(jf.info("requestSubscribe: Subscribed ".concat(n.pubsubTopic," to ").concat(e.toString()," for contentTopics:").concat(t)),!0)]}}))}))()}},{key:"attemptUnsubscribe",value:function(e){var t=this;return(0,K.default)((function(){var n,r,i,a,o;return(0,pe.__generator)(this,(function(u){switch(u.label){case 0:return n=e.useNewContentTopics,r=n?Array.from(t.toUnsubscribeContentTopics):t.contentTopics,jf.info("Attempting to unsubscribe: useNewContentTopics=".concat(n,", contentTopics=").concat(r.length)),r.length?(i=Array.from(t.peers.values()),[4,Promise.all(i.map((function(e){return t.requestUnsubscribe(e,n?r:void 0)})))]):[2,(jf.warn("Requested content topics is an empty array, skipping"),!1)];case 1:return a=u.sent(),o=a.filter((function(e){return e})).length,[2,(jf.info("Unsubscribe attempts completed: ".concat(o,"/").concat(a.length," successful")),n&&(t.toUnsubscribeContentTopics=new Set),a.some((function(e){return e})))]}}))}))()}},{key:"requestUnsubscribe",value:function(e,t){var n=this;return(0,K.default)((function(){var r,i,a;return(0,pe.__generator)(this,(function(o){switch(o.label){case 0:return t?[4,n.protocol.unsubscribe(n.pubsubTopic,e,t)]:[3,2];case 1:return a=o.sent(),[3,4];case 2:return[4,n.protocol.unsubscribeAll(n.pubsubTopic,e)];case 3:a=o.sent(),o.label=4;case 4:return[2,(i=a).failure?(jf.warn("requestUnsubscribe: Failed to unsubscribe for pubsubTopic:".concat(n.pubsubTopic," from peerId:").concat(e.toString()," with error:").concat(null===(r=i.failure)||void 0===r?void 0:r.error," for contentTopics:").concat(t)),!1):(jf.info("requestUnsubscribe: Unsubscribed pubsubTopic:".concat(n.pubsubTopic," from peerId:").concat(e.toString()," for contentTopics:").concat(t)),!0)]}}))}))()}}]),e}(),Vf=new ja("sdk:filter"),Hf=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"protocol",void 0),(0,te.default)(this,"peerManager",void 0),(0,te.default)(this,"config",void 0),(0,te.default)(this,"subscriptions",new Map),this.config=(0,ae.default)({numPeersToUse:2,pingsBeforePeerRenewed:3,keepAliveIntervalMs:6e4},t.options),this.peerManager=t.peerManager,this.protocol=new uu(this.onIncomingMessage.bind(this),t.libp2p)}return(0,$.default)(e,[{key:"multicodec",get:function(){return this.protocol.multicodec}},{key:"start",value:function(){var e=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return[4,e.protocol.start()];case 1:return t.sent(),[2]}}))}))()}},{key:"stop",value:function(){var e=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return[4,e.protocol.stop()];case 1:return t.sent(),[2]}}))}))()}},{key:"unsubscribeAll",value:function(){var e=!0,t=!1,n=void 0;try{for(var r,i=this.subscriptions.values()[Symbol.iterator]();!(e=(r=i.next()).done);e=!0){r.value.stop()}}catch(e){t=!0,n=e}finally{try{e||null==i.return||i.return()}finally{if(t)throw n}}this.subscriptions.clear()}},{key:"subscribe",value:function(e,t){var n=this;return(0,K.default)((function(){var r,i,a,o,u,s;return(0,pe.__generator)(this,(function(l){switch(l.label){case 0:if(0===(r=Array.isArray(e)?e:[e]).length)throw Error("Cannot subscribe with 0 decoders.");return i=r.map((function(e){return e.pubsubTopic})),a=i[0],o=r.map((function(e){return e.contentTopic})),Vf.info("Subscribing to contentTopics: ".concat(o,", pubsubTopic: ").concat(a)),n.throwIfTopicNotSame(i),(u=n.subscriptions.get(a))||(u=new Kf({pubsubTopic:a,protocol:n.protocol,config:n.config,peerManager:n.peerManager})).start(),[4,u.add(r,t)];case 1:return s=l.sent(),[2,(n.subscriptions.set(a,u),Vf.info("Subscription ".concat(s?"successful":"failed"," for content topic: ").concat(o)),s)]}}))}))()}},{key:"unsubscribe",value:function(e){var t=this;return(0,K.default)((function(){var n,r,i,a,o,u;return(0,pe.__generator)(this,(function(s){switch(s.label){case 0:if(0===(n=Array.isArray(e)?e:[e]).length)throw Error("Cannot unsubscribe with 0 decoders.");return r=n.map((function(e){return e.pubsubTopic})),i=r[0],a=n.map((function(e){return e.contentTopic})),Vf.info("Unsubscribing from contentTopics: ".concat(a,", pubsubTopic: ").concat(i)),t.throwIfTopicNotSame(r),(o=t.subscriptions.get(i))?[4,o.remove(n)]:[2,(Vf.warn("No subscriptions associated with the decoder."),!1)];case 1:return u=s.sent(),[2,(o.isEmpty()&&(Vf.warn("Subscription has no decoders anymore, terminating it."),o.stop(),t.subscriptions.delete(i)),Vf.info("Unsubscribing ".concat(u?"successful":"failed"," for content topic: ").concat(a)),u)]}}))}))()}},{key:"onIncomingMessage",value:function(e,t,n){var r=this;return(0,K.default)((function(){var i;return(0,pe.__generator)(this,(function(a){return Vf.info("Received message for pubsubTopic:".concat(e,", contentTopic:").concat(t.contentTopic,", peerId:").concat(n.toString())),(i=r.subscriptions.get(e))?i.invoke(t,n):Vf.error("No subscription locally registered for topic "+e),[2]}))}))()}},{key:"throwIfTopicNotSame",value:function(e){var t=e[0];if(!e.every((function(e){return e===t})))throw Error("Cannot subscribe to more than one pubsub topic at the same time, got pubsubTopics:"+e)}}]),e}(),Wf=function(){var e=function(e){var t=void 0===e?"undefined":(0,fe.default)(e);return!!e&&("object"==t||"function"==t)},t=function(t){if("number"==typeof t)return t;if(function(e){return"symbol"==(void 0===e?"undefined":(0,fe.default)(e))||function(e){return!!e&&"object"==typeof e}(e)&&"[object Symbol]"==c.call(e)}(t))return NaN;if(e(t)){var u="function"==typeof t.valueOf?t.valueOf():t;t=e(u)?u+"":u}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(n,"");var s=i.test(t);return s||a.test(t)?o(t.slice(2),s?2:8):r.test(t)?NaN:+t};if(Bf)return Ff;Bf=1;var n=/^\s+|\s+$/g,r=/^[-+]0x[0-9a-f]+$/i,i=/^0b[01]+$/i,a=/^0o[0-7]+$/i,o=parseInt,u="object"==typeof Ra&&Ra&&Ra.Object===Object&&Ra,s="object"==typeof self&&self&&self.Object===Object&&self,l=u||s||Function("return this")(),c=Object.prototype.toString,f=Math.max,d=Math.min,h=function(){return l.Date.now()};return Ff=function(n,r,i){var a,o,u,s,l,c,v=function(e){var t=a,r=o;return a=o=void 0,m=e,s=n.apply(r,t)},p=function(e){var t=e-c;return void 0===c||t>=r||t<0||w&&e-m>=u},g=function(e){return l=void 0,k&&a?v(e):(a=o=void 0,s)},y=function(){var e=h(),t=p(e);if(a=arguments,o=this,c=e,t){if(void 0===l)return function(e){return m=e,l=setTimeout(_,r),b?v(e):s}(c);if(w)return l=setTimeout(_,r),v(c)}return void 0===l&&(l=setTimeout(_,r)),s},m=0,b=!1,w=!1,k=!0;if("function"!=typeof n)throw new TypeError("Expected a function");function _(){var e=h();if(p(e))return g(e);l=setTimeout(_,function(e){var t=r-(e-c);return w?d(t,u-(e-m)):t}(e))}return r=t(r)||0,e(i)&&(b=!!i.leading,u=(w="maxWait"in i)?f(t(i.maxWait)||0,r):u,k="trailing"in i?!!i.trailing:k),y.cancel=function(){void 0!==l&&clearTimeout(l),m=0,a=c=o=l=void 0},y.flush=function(){return void 0===l?s:g(h())},y},Ff}(),Gf=La(Wf),Xf=new ja("health-indicator"),Yf=function(){"use strict";function e(t){var n=this;(0,H.default)(this,e),(0,te.default)(this,"isStarted",!1),(0,te.default)(this,"libp2p",void 0),(0,te.default)(this,"events",void 0),(0,te.default)(this,"value",ro.Unhealthy),(0,te.default)(this,"debouncedAssessHealth",void 0),this.libp2p=t.libp2p,this.events=t.events,this.onPeerIdentify=this.onPeerIdentify.bind(this),this.onPeerDisconnected=this.onPeerDisconnected.bind(this),this.debouncedAssessHealth=Gf((function(){n.assessHealth()}),100)}return(0,$.default)(e,[{key:"start",value:function(){this.isStarted||(this.isStarted=!0,Xf.info("start: adding listeners to libp2p"),this.libp2p.addEventListener("peer:identify",this.onPeerIdentify),this.libp2p.addEventListener("peer:disconnect",this.onPeerDisconnected),this.debouncedAssessHealth())}},{key:"stop",value:function(){this.isStarted&&(this.isStarted=!1,Xf.info("stop: removing listeners to libp2p"),this.libp2p.removeEventListener("peer:identify",this.onPeerIdentify),this.libp2p.removeEventListener("peer:disconnect",this.onPeerDisconnected),this.debouncedAssessHealth.cancel())}},{key:"toValue",value:function(){return this.value}},{key:"onPeerDisconnected",value:function(e){Xf.info("onPeerDisconnected: received libp2p event"),this.debouncedAssessHealth()}},{key:"onPeerIdentify",value:function(e){Xf.info("onPeerIdentify: received libp2p event"),this.debouncedAssessHealth()}},{key:"assessHealth",value:function(){var e=this;return(0,K.default)((function(){var t,n,r,i,a;return(0,pe.__generator)(this,(function(o){switch(o.label){case 0:return 0===(t=e.libp2p.getConnections()).length?[2,(Xf.info("assessHealth: no connections, setting to Unhealthy"),void e.updateAndDispatchHealthEvent(ro.Unhealthy))]:[4,Promise.all(t.map(function(){var t=(0,K.default)((function(t){return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,e.libp2p.peerStore.get(t.remotePeer)];case 1:return[2,n.sent()];case 2:return n.sent(),[2,(Xf.warn("assessHealth: failed to get peer ".concat(t.remotePeer,", skipping")),null)];case 3:return[2]}}))}));return function(e){return t.apply(this,arguments)}}()))];case 1:return n=o.sent(),r=n.filter((function(e){return null==e?void 0:e.protocols.includes(au)})).length,i=n.filter((function(e){return null==e?void 0:e.protocols.includes(fu)})).length,0===r||0===i?a=ro.Unhealthy:r>=2&&i>=2?a=ro.SufficientlyHealthy:1===r&&1===i?a=ro.MinimallyHealthy:(Xf.error("assessHealth: unexpected state, cannot identify health status of the node: Filter:".concat(r,"; LightPush:").concat(i)),a=e.value),Xf.info("assessHealth: node identified as ".concat(a," Filter:").concat(r,"; LightPush:").concat(i)),e.updateAndDispatchHealthEvent(a),[2]}}))}))()}},{key:"updateAndDispatchHealthEvent",value:function(e){this.value!==e&&(this.value=e,this.events.dispatchEvent(new CustomEvent(eo.Health,{detail:this.value})))}}]),e}(),Zf=function(e){return new Promise((function(t,n){return setTimeout((function(){return n(Error("Task timeout"))}),e)}))},Qf=new ja("sdk:retry-manager"),Jf=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"intervalID",null),(0,te.default)(this,"retryIntervalMs",void 0),(0,te.default)(this,"inProgress",0),(0,te.default)(this,"queue",[]),(0,te.default)(this,"peerManager",void 0),this.peerManager=t.peerManager,this.retryIntervalMs=t.retryIntervalMs||1e3}return(0,$.default)(e,[{key:"start",value:function(){var e=this;this.intervalID=setInterval((function(){e.processQueue()}),this.retryIntervalMs)}},{key:"stop",value:function(){this.intervalID&&(clearInterval(this.intervalID),this.intervalID=null)}},{key:"push",value:function(e,t,n){this.queue.push({maxAttempts:t,callback:e,routingInfo:n})}},{key:"processQueue",value:function(){if(0!==this.queue.length)for(;this.queue.length&&this.inProgress<5;){var e=this.queue.shift();e&&this.scheduleTask(e)}}},{key:"scheduleTask",value:function(e){var t=this;setTimeout((0,K.default)((function(){return(0,pe.__generator)(this,(function(n){return[2,t.taskExecutor(e)]}))})),100)}},{key:"taskExecutor",value:function(e){var t=this;return(0,K.default)((function(){var n,r,i,a,o;return(0,pe.__generator)(this,(function(u){switch(u.label){case 0:return e.maxAttempts<=0?[2,void Qf.warn("scheduleTask: max attempts has reached, removing from queue")]:[4,t.peerManager.getPeers({protocol:Za.LightPush,pubsubTopic:e.routingInfo.pubsubTopic})];case 1:if(!(n=u.sent()[0]))return[2,(Qf.warn("scheduleTask: no peers, putting back to queue"),void t.queue.push((0,oe.default)((0,ae.default)({},e),{maxAttempts:e.maxAttempts-1})))];u.label=2;case 2:return u.trys.push([2,4,7,8]),t.inProgress+=1,[4,Promise.race([Zf(1e4),e.callback(n)])];case 3:if(void 0===(r=u.sent()))throw Error("Task timeout");if(r.failure)throw Error(r.failure.error);return Qf.info("scheduleTask: executed successfully"),0===e.maxAttempts?[2,void Qf.warn("scheduleTask: discarded a task due to limit of max attempts")]:(t.queue.push((0,oe.default)((0,ae.default)({},e),{maxAttempts:e.maxAttempts-1})),[3,8]);case 4:return i=u.sent(),a=i,Qf.error("scheduleTask: task execution failed with error:",a),(o=a.message)===Qa.REMOTE_PEER_REJECTED||o===Qa.NO_RESPONSE||o===Qa.RLN_PROOF_GENERATION||o===Qa.NO_PEER_AVAILABLE?[4,t.peerManager.renewPeer(n,{protocol:Za.LightPush,pubsubTopic:e.routingInfo.pubsubTopic})]:[3,6];case 5:u.sent(),u.label=6;case 6:return 0===e.maxAttempts?[2,void Qf.warn("scheduleTask: discarded a task due to limit of max attempts")]:(t.queue.push((0,oe.default)((0,ae.default)({},e),{maxAttempts:e.maxAttempts-1})),[3,8]);case 7:return t.inProgress-=1,[7];case 8:return[2]}}))}))()}}]),e}(),$f=new ja("sdk:light-push"),ed={autoRetry:!0,retryIntervalMs:1e3,maxAttempts:3,numPeersToUse:1},td=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"config",void 0),(0,te.default)(this,"retryManager",void 0),(0,te.default)(this,"peerManager",void 0),(0,te.default)(this,"protocol",void 0),this.config=(0,ae.default)({},ed,t.options||{}),this.peerManager=t.peerManager,this.protocol=new yu(t.libp2p),this.retryManager=new Jf({peerManager:t.peerManager,retryIntervalMs:this.config.retryIntervalMs})}return(0,$.default)(e,[{key:"multicodec",get:function(){return this.protocol.multicodec}},{key:"start",value:function(){this.retryManager.start()}},{key:"stop",value:function(){this.retryManager.stop()}},{key:"send",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=this;return(0,K.default)((function(){var i,a,o,u,s,l;return(0,pe.__generator)(this,(function(c){switch(c.label){case 0:return n=(0,ae.default)({useLegacy:!1},r.config,n),i=e.pubsubTopic,$f.info("send: attempting to send a message to pubsubTopic:",i),[4,r.peerManager.getPeers({protocol:n.useLegacy?"light-push-v2":Za.LightPush,pubsubTopic:e.pubsubTopic})];case 1:return(null==(a=c.sent())?void 0:a.length)>0?[4,Promise.all(a.map((function(i){return r.protocol.send(e,t,i,n.useLegacy).catch((function(){return{success:null,failure:{error:Qa.GENERIC_FAIL}}}))})))]:[3,3];case 2:return s=c.sent(),[3,4];case 3:s=[],c.label=4;case 4:return u=(o=s).length?{successes:o.filter((function(e){return e.success})).map((function(e){return e.success})),failures:o.filter((function(e){return e.failure})).map((function(e){return e.failure}))}:{successes:[],failures:[{error:Qa.NO_PEER_AVAILABLE}]},n.autoRetry&&0===u.successes.length&&(l=function(i){return r.protocol.send(e,t,i,n.useLegacy)},r.retryManager.push(l.bind(r),n.maxAttempts||3,e.routingInfo)),[2,u]}}))}))()}}]),e}(),nd=new ja("store-sdk"),rd=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"options",void 0),(0,te.default)(this,"libp2p",void 0),(0,te.default)(this,"peerManager",void 0),(0,te.default)(this,"protocol",void 0),this.options=t.options||{},this.peerManager=t.peerManager,this.libp2p=t.libp2p,this.protocol=new Au(t.libp2p)}return(0,$.default)(e,[{key:"multicodec",get:function(){return this.protocol.multicodec}},{key:"queryGenerator",value:function(e,t){var n=this;return(0,de.default)((function(){var r,i,a,o,u,s,l,c,f,d,h,v,p,g,y,m,b,w,k,_,E;return(0,pe.__generator)(this,(function(S){switch(S.label){case 0:r=n.buildQueryParams(e,t),i=r.decodersAsMap,a=r.queryOptions,o=!0,u=!1,s=void 0,S.label=1;case 1:S.trys.push([1,20,21,22]),l=a[Symbol.iterator](),S.label=2;case 2:return(o=(c=l.next()).done)?[3,19]:(f=c.value,null===(d=null==t?void 0:t.peerId)||void 0===d?[3,3]:(v=d,[3,5]));case 3:return[4,(0,V.default)(n.getPeerToUse(f.pubsubTopic))];case 4:v=S.sent(),S.label=5;case 5:if(!(h=v))throw nd.error("No peers available to query"),Error("No peers available to query");nd.info("Querying store with options: "+JSON.stringify(f)),p=n.protocol.queryPerPage(f,i,h),g=!1,y=!1,S.label=6;case 6:S.trys.push([6,12,13,18]),b=(0,j.default)(p),S.label=7;case 7:return[4,(0,V.default)(b.next())];case 8:return(g=!(w=S.sent()).done)?(k=w.value,[4,k]):[3,11];case 9:S.sent(),S.label=10;case 10:return g=!1,[3,7];case 11:return[3,18];case 12:return _=S.sent(),y=!0,m=_,[3,18];case 13:return S.trys.push([13,,16,17]),g&&null!=b.return?[4,b.return()]:[3,15];case 14:S.sent(),S.label=15;case 15:return[3,17];case 16:if(y)throw m;return[7];case 17:return[7];case 18:return o=!0,[3,2];case 19:return[3,22];case 20:return E=S.sent(),u=!0,s=E,[3,22];case 21:try{o||null==l.return||l.return()}finally{if(u)throw s}return[7];case 22:return[2]}}))}))()}},{key:"queryWithOrderedCallback",value:function(e,t,n){var r=this;return(0,K.default)((function(){var i,a,o,u,s,l,c,f;return(0,pe.__generator)(this,(function(d){switch(d.label){case 0:nd.info("Querying store with ordered callback"),i=!1,a=!1,d.label=1;case 1:d.trys.push([1,7,8,13]),u=(0,j.default)(r.queryGenerator(e,n)),d.label=2;case 2:return[4,u.next()];case 3:return(i=!(s=d.sent()).done)?(l=s.value,c=l,[4,r.processMessages(c,t)]):[3,6];case 4:if(d.sent())return[3,6];d.label=5;case 5:return i=!1,[3,2];case 6:return[3,13];case 7:return f=d.sent(),a=!0,o=f,[3,13];case 8:return d.trys.push([8,,11,12]),i&&null!=u.return?[4,u.return()]:[3,10];case 9:d.sent(),d.label=10;case 10:return[3,12];case 11:if(a)throw o;return[7];case 12:return[7];case 13:return[2]}}))}))()}},{key:"queryWithPromiseCallback",value:function(e,t,n){var r=this;return(0,K.default)((function(){var i,a,o,u,s,l,c,f,d;return(0,pe.__generator)(this,(function(h){switch(h.label){case 0:nd.info("Querying store with promise callback"),i=!1,a=!1,o=!1,h.label=1;case 1:h.trys.push([1,7,8,13]),s=(0,j.default)(r.queryGenerator(e,n)),h.label=2;case 2:return[4,s.next()];case 3:return(a=!(l=h.sent()).done)?(c=l.value,f=c.map(function(){var e=(0,K.default)((function(e){return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:return i?[3,2]:[4,t(e)];case 1:i=!!n.sent(),n.label=2;case 2:return[2]}}))}));return function(t){return e.apply(this,arguments)}}()),[4,Promise.all(f)]):[3,6];case 4:if(h.sent(),i)return[3,6];h.label=5;case 5:return a=!1,[3,2];case 6:return[3,13];case 7:return d=h.sent(),o=!0,u=d,[3,13];case 8:return h.trys.push([8,,11,12]),a&&null!=s.return?[4,s.return()]:[3,10];case 9:h.sent(),h.label=10;case 10:return[3,12];case 11:if(o)throw u;return[7];case 12:return[7];case 13:return[2]}}))}))()}},{key:"processMessages",value:function(e,t){return(0,K.default)((function(){var n,r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:return n=!1,[4,Promise.all(e)];case 1:return r=i.sent().filter(Sr),[4,Promise.all(r.map(function(){var e=(0,K.default)((function(e){return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return e&&!n?[4,t(e)]:[3,2];case 1:n=!!r.sent(),r.label=2;case 2:return[2]}}))}));return function(t){return e.apply(this,arguments)}}()))];case 2:return[2,(i.sent(),n)]}}))}))()}},{key:"createCursor",value:function(e){return Ka(e.pubsubTopic,e)}},{key:"validateDecodersAndPubsubTopic",value:function(e){if(0===e.length)throw nd.error("No decoders provided"),Error("No decoders provided");var t=Array.from(new Set(e.map((function(e){return e.pubsubTopic}))));if(t.length>1)throw nd.error("API does not support querying multiple pubsub topics at once"),Error("API does not support querying multiple pubsub topics at once");var n=t[0],r=new Map;e.forEach((function(e){if(r.has(e.contentTopic))throw nd.error("API does not support different decoder per content topic"),Error("API does not support different decoder per content topic");r.set(e.contentTopic,e)}));var i=e.filter((function(e){return e.pubsubTopic===n})).map((function(e){return e.contentTopic}));if(0===i.length)throw nd.error("No decoders found for topic "+n),Error("No decoders found for topic "+n);return{pubsubTopic:n,contentTopics:i,decodersAsMap:r}}},{key:"getPeerToUse",value:function(e){var t=this;return(0,K.default)((function(){var n,r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:return[4,t.peerManager.getPeers({protocol:Za.Store,pubsubTopic:e})];case 1:return n=i.sent(),t.options.peers?[4,t.getPeerFromConfigurationOrFirst(n,t.options.peers)]:[3,3];case 2:return r=i.sent(),[3,4];case 3:r=n[0],i.label=4;case 4:return[2,r]}}))}))()}},{key:"getPeerFromConfigurationOrFirst",value:function(e,t){var n=this;return(0,K.default)((function(){var r,i,a,o,u,s,l,c,f,d,h;return(0,pe.__generator)(this,(function(v){switch(v.label){case 0:r=t.map(pf),i=[],a=!0,o=!1,u=void 0;try{for(s=r[Symbol.iterator]();!(a=(l=s.next()).done);a=!0){if(c=l.value,f=e.find((function(e){var t;return e.toString()===(null===(t=c.getPeerId())||void 0===t?void 0:t.toString())})),f)return[2,f];i.push(c)}}catch(e){o=!0,u=e}finally{try{a||null==s.return||s.return()}finally{if(o)throw u}}v.label=1;case 1:if(!i.length)return[3,6];if(!(d=i.pop()))return[2];v.label=2;case 2:return v.trys.push([2,4,,5]),[4,n.libp2p.dial(d)];case 3:return v.sent()?[2,kc(d.getPeerId())]:[3,5];case 4:return h=v.sent(),nd.warn("Failed to dial peer from options.peers list for Store protocol. Peer:".concat(d.getPeerId(),", error:").concat(h)),[3,5];case 5:return[3,1];case 6:return[2,(nd.warn("Passed node to use for Store not found: ".concat(t.toString(),". Attempting to use first available peers.")),e[0])]}}))}))()}},{key:"buildQueryParams",value:function(e,t){var n,r,i,a;if((null==t?void 0:t.messageHashes)&&t.messageHashes.length>0)r=t.pubsubTopic||(null===(n=e[0])||void 0===n?void 0:n.pubsubTopic)||"",i=[],a=new Map,e.forEach((function(e){a.set(e.contentTopic,e)}));else{var o=this.validateDecodersAndPubsubTopic(e);r=o.pubsubTopic,i=o.contentTopics,a=o.decodersAsMap}var u=[];if((null==t?void 0:t.timeStart)&&(null==t?void 0:t.timeEnd)){for(var s=t.timeStart,l=t.timeEnd;l.getTime()-s.getTime()>this.protocol.maxTimeLimit;){var c=new Date(s.getTime()+this.protocol.maxTimeLimit);u.push([s,c]),s=c}0===u.length&&(nd.info("Using single time range"),u.push([s,l]))}return 0===u.length?(nd.info("No sub time ranges"),{decodersAsMap:a,queryOptions:[(0,ae.default)({pubsubTopic:r,contentTopics:i,includeData:!0,paginationForward:!0},t)]}):(nd.info("Building ".concat(u.length," sub time ranges")),{decodersAsMap:a,queryOptions:u.map((function(e){var n=(0,se.default)(e,2),a=n[0],o=n[1];return(0,oe.default)((0,ae.default)({pubsubTopic:r,contentTopics:i,includeData:!0,paginationForward:!0},t),{timeStart:a,timeEnd:o})}))})}}]),e}(),id=new ja("wait-for-remote-peer");function ad(e,t,n){return od.apply(this,arguments)}function od(){return od=(0,K.default)((function(e,t,n){var r,i,a,o,u,s,l;return(0,pe.__generator)(this,(function(c){switch(c.label){case 0:if(t=(null==t?void 0:t.length)?t:function(e){var t=[];return e.relay&&t.push(Za.Relay),e.filter&&t.push(Za.Filter),e.store&&t.push(Za.Store),e.lightPush&&t.push(Za.LightPush),t}(e),r=e.libp2p.getConnections(),!e.isStarted())throw Error("Waku node is not started");i=!0,a=!1,o=void 0;try{for(u=t[Symbol.iterator]();!(i=(s=u.next()).done);i=!0)switch(s.value){case Za.Relay:if(!e.relay)throw Error("Cannot wait for Relay peer: protocol not mounted");break;case Za.LightPush:if(!e.lightPush)throw Error("Cannot wait for LightPush peer: protocol not mounted");break;case Za.Store:if(!e.store)throw Error("Cannot wait for Store peer: protocol not mounted");break;case Za.Filter:if(!e.filter)throw Error("Cannot wait for Filter peer: protocol not mounted")}}catch(e){a=!0,o=e}finally{try{i||null==u.return||u.return()}finally{if(a)throw o}}return l=[sd(e,t)],r.length>0&&!t.includes(Za.Relay)&&l.push(function(){var e=(0,K.default)((function(e,t){var n,r,i,a,o,u,s,l,c,f,d,h;return(0,pe.__generator)(this,(function(v){switch(v.label){case 0:if(n=e.libp2p.getPeers(),r=e.libp2p.services.metadata,i=function(e){var t,n=new Map,r=(t={},(0,te.default)(t,Za.Filter,[au]),(0,te.default)(t,Za.LightPush,[fu,cu]),(0,te.default)(t,Za.Store,[Su]),t),i=!0,a=!1,o=void 0;try{for(var u,s=e[Symbol.iterator]();!(i=(u=s.next()).done);i=!0){var l=u.value;r[l]&&r[l].forEach((function(e){n.set(e,!1)}))}}catch(e){a=!0,o=e}finally{try{i||null==s.return||s.return()}finally{if(a)throw o}}return n}(t),!n.length||!r)return[2,void id.info("Skipping waitForMetadata due to missing connections:".concat(n.length," or metadataService:").concat(!!r))];a=!0,o=!1,u=void 0,v.label=1;case 1:v.trys.push([1,10,11,12]),s=n[Symbol.iterator](),v.label=2;case 2:if(a=(l=s.next()).done)return[3,9];c=l.value,v.label=3;case 3:return v.trys.push([3,7,,8]),[4,e.libp2p.peerStore.get(c)];case 4:return(f=v.sent()).protocols.some((function(e){return i.has(e)}))?[4,r.confirmOrAttemptHandshake(c)]:[3,6];case 5:if(!v.sent().error&&(f.protocols.forEach((function(e){i.has(e)&&i.set(e,!0)})),Array.from(i.values()).every((function(e){return e}))))return[2];v.label=6;case 6:return[3,8];case 7:return"ERR_CONNECTION_BEING_CLOSED"===(d=v.sent()).code&&id.error("Connection closed. Some peers can be on different shard."),id.error("Error while iterating through peers: "+d),[3,8];case 8:return a=!0,[3,2];case 9:return[3,12];case 10:return h=v.sent(),o=!0,u=h,[3,12];case 11:try{a||null==s.return||s.return()}finally{if(o)throw u}return[7];case 12:return[2]}}))}));return function(t,n){return e.apply(this,arguments)}}()(e,t)),n?[4,function(){var e=(0,K.default)((function(e,t,n){return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return[4,Promise.race([e,cd(t,n)])];case 1:return r.sent(),[2]}}))}));return function(t,n,r){return e.apply(this,arguments)}}()(Promise.any(l),n,"Timed out waiting for a remote peer.")]:[3,2];case 1:return c.sent(),[3,4];case 2:return[4,Promise.any(l)];case 3:c.sent(),c.label=4;case 4:return[2]}}))})),od.apply(this,arguments)}function ud(e,t){return e.map((function(e){return function(){var e=(0,K.default)((function(e,t){return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:return id.info("Waiting for ".concat(e," peer.")),[4,new Promise((function(n){var r=function(){var i=(0,K.default)((function(i){var a,o,u,s;return(0,pe.__generator)(this,(function(l){switch(l.label){case 0:if(!(null===(a=i.detail)||void 0===a||null===(o=a.protocols)||void 0===o?void 0:o.includes(e)))return[3,4];if(!(u=t.services.metadata))return[2,(t.removeEventListener("peer:identify",r),void n())];l.label=1;case 1:return l.trys.push([1,3,,4]),[4,u.confirmOrAttemptHandshake(i.detail.peerId)];case 2:return l.sent(),t.removeEventListener("peer:identify",r),n(),[3,4];case 3:return"ERR_CONNECTION_BEING_CLOSED"===(s=l.sent()).code&&id.error("Connection closed. Some peers can be on different shard."),id.error("Error waiting for metadata: "+s),[3,4];case 4:return[2]}}))}));return function(e){return i.apply(this,arguments)}}();t.addEventListener("peer:identify",r)}))];case 1:return n.sent(),[2]}}))}));return function(t,n){return e.apply(this,arguments)}}()(e,t)}))}function sd(e,t){return ld.apply(this,arguments)}function ld(){return ld=(0,K.default)((function(e,t){var n,r,i,a;return(0,pe.__generator)(this,(function(o){return i=[],e.relay&&t.includes(Za.Relay)&&i.push(e.relay.waitForPeers()),e.store&&t.includes(Za.Store)&&(n=i).push.apply(n,(0,ce.default)(ud([Su],e.libp2p))),e.lightPush&&t.includes(Za.LightPush)&&(a=ud([fu,cu],e.libp2p),i.push(Promise.any(a))),[2,(e.filter&&t.includes(Za.Filter)&&(r=i).push.apply(r,(0,ce.default)(ud([au],e.libp2p))),Promise.all(i))]}))})),ld.apply(this,arguments)}var cd=function(e,t){return new Promise((function(n,r){return setTimeout((function(){return r(Error(t))}),e)}))},fd=new ja("sdk:waku"),dd=function(){"use strict";function e(t,n,r,i){(0,H.default)(this,e),(0,te.default)(this,"libp2p",void 0),(0,te.default)(this,"relay",void 0),(0,te.default)(this,"store",void 0),(0,te.default)(this,"filter",void 0),(0,te.default)(this,"lightPush",void 0),(0,te.default)(this,"events",new xa),(0,te.default)(this,"networkConfig",void 0),(0,te.default)(this,"_nodeStateLock",!1),(0,te.default)(this,"_nodeStarted",!1),(0,te.default)(this,"connectionManager",void 0),(0,te.default)(this,"peerManager",void 0),(0,te.default)(this,"healthIndicator",void 0),this.relay=i,this.libp2p=n,this.networkConfig=t.networkConfig||ao,r=(0,ae.default)({filter:!1,lightpush:!1,store:!1},r);var a=this.libp2p.peerId.toString();this.connectionManager=new Rf({libp2p:n,relay:this.relay,events:this.events,networkConfig:this.networkConfig,config:null==t?void 0:t.connectionManager}),this.peerManager=new qf({libp2p:n,config:{numPeersToUse:t.numPeersToUse},connectionManager:this.connectionManager}),this.healthIndicator=new Yf({libp2p:n,events:this.events}),r.store&&(this.store=new rd({libp2p:n,peerManager:this.peerManager,options:null==t?void 0:t.store})),r.lightpush&&(this.lightPush=new td({libp2p:n,peerManager:this.peerManager,options:null==t?void 0:t.lightPush})),r.filter&&(this.filter=new Hf({libp2p:n,peerManager:this.peerManager,options:t.filter})),fd.info("Waku node created",a,"relay: ".concat(!!this.relay,", store: ").concat(!!this.store,", light push: ").concat(!!this.lightPush,", filter: ").concat(!!this.filter))}return(0,$.default)(e,[{key:"peerId",get:function(){return this.libp2p.peerId}},{key:"protocols",get:function(){return this.libp2p.getProtocols()}},{key:"health",get:function(){return this.healthIndicator.toValue()}},{key:"dial",value:function(e,t){var n=this;return(0,K.default)((function(){var r,i,a;return(0,pe.__generator)(this,(function(o){switch(o.label){case 0:return i=null!=t?t:[],void 0===t&&(n.relay&&i.push(Za.Relay),n.store&&i.push(Za.Store),n.filter&&i.push(Za.Filter),n.lightPush&&i.push(Za.LightPush)),a=[],i.includes(Za.Relay)&&(n.relay?n.relay.gossipSub.multicodecs.forEach((function(e){return a.push(e)})):fd.error("Relay codec not included in dial codec: protocol not mounted locally")),i.includes(Za.Store)&&(n.store?a.push(n.store.multicodec):fd.error("Store codec not included in dial codec: protocol not mounted locally")),i.includes(Za.LightPush)&&(n.lightPush?(r=a).push.apply(r,(0,ce.default)(n.lightPush.multicodec)):fd.error("Light Push codec not included in dial codec: protocol not mounted locally")),i.includes(Za.Filter)&&(n.filter?a.push(n.filter.multicodec):fd.error("Filter codec not included in dial codec: protocol not mounted locally")),fd.info("Dialing to ".concat(null==e?void 0:e.toString()," with protocols ").concat(i)),[4,n.connectionManager.dial(e,a)];case 1:return[2,o.sent()]}}))}))()}},{key:"hangUp",value:function(e){var t=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(n){return[2,(fd.info("Hanging up peer:".concat(null==e?void 0:e.toString(),".")),t.connectionManager.hangUp(e))]}))}))()}},{key:"start",value:function(){var e=this;return(0,K.default)((function(){var t,n;return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return e._nodeStateLock||e.isStarted()?[3,3]:(e._nodeStateLock=!0,[4,e.libp2p.start()]);case 1:return r.sent(),[4,null===(t=e.filter)||void 0===t?void 0:t.start()];case 2:r.sent(),e.connectionManager.start(),e.peerManager.start(),e.healthIndicator.start(),null===(n=e.lightPush)||void 0===n||n.start(),e._nodeStateLock=!1,e._nodeStarted=!0,r.label=3;case 3:return[2]}}))}))()}},{key:"stop",value:function(){var e=this;return(0,K.default)((function(){var t,n;return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return!e._nodeStateLock&&e.isStarted()?(e._nodeStateLock=!0,null===(t=e.lightPush)||void 0===t||t.stop(),[4,null===(n=e.filter)||void 0===n?void 0:n.stop()]):[3,3];case 1:return r.sent(),e.healthIndicator.stop(),e.peerManager.stop(),e.connectionManager.stop(),[4,e.libp2p.stop()];case 2:r.sent(),e._nodeStateLock=!1,e._nodeStarted=!1,r.label=3;case 3:return[2]}}))}))()}},{key:"getConnectedPeers",value:function(){var e=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(t){return[2,e.connectionManager.getConnectedPeers()]}))}))()}},{key:"waitForPeers",value:function(e,t){var n=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(r){return[2,ad(n,e,t)]}))}))()}},{key:"isStarted",value:function(){return this._nodeStarted&&"started"===this.libp2p.status}},{key:"isConnected",value:function(){return this.connectionManager.isConnected()}},{key:"createDecoder",value:function(e){var t=this.createRoutingInfo(e.contentTopic,e.shardId);return function(e,t){return new no(e,t)}(e.contentTopic,t)}},{key:"createEncoder",value:function(e){var t=this.createRoutingInfo(e.contentTopic,e.shardId);return Xa({contentTopic:e.contentTopic,ephemeral:e.ephemeral,routingInfo:t})}},{key:"createRoutingInfo",value:function(e,t){return ji(this.networkConfig,{contentTopic:e,shardId:t})}}]),e}(),hd=4194304,vd=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e;return(0,H.default)(this,n),e=t.apply(this,arguments),(0,te.default)((0,q.default)(e),"name","InvalidMessageLengthError"),(0,te.default)((0,q.default)(e),"code","ERR_INVALID_MSG_LENGTH"),e}return n}((0,he.default)(Error)),pd=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e;return(0,H.default)(this,n),e=t.apply(this,arguments),(0,te.default)((0,q.default)(e),"name","InvalidDataLengthError"),(0,te.default)((0,q.default)(e),"code","ERR_MSG_DATA_TOO_LONG"),e}return n}((0,he.default)(Error)),gd=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e;return(0,H.default)(this,n),e=t.apply(this,arguments),(0,te.default)((0,q.default)(e),"name","InvalidDataLengthLengthError"),(0,te.default)((0,q.default)(e),"code","ERR_MSG_LENGTH_TOO_LONG"),e}return n}((0,he.default)(Error)),yd=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e;return(0,H.default)(this,n),e=t.apply(this,arguments),(0,te.default)((0,q.default)(e),"name","UnexpectedEOFError"),(0,te.default)((0,q.default)(e),"code","ERR_UNEXPECTED_EOF"),e}return n}((0,he.default)(Error));function md(e){return null!=e[Symbol.asyncIterator]}function bd(e,t){if(e.byteLength>t)throw new pd("Message length too long")}var wd,kd=function(e){var t=Ae(e),n=me(t);return Ce(e,n),kd.bytes=t,n};function _d(e,t){var n,r,i=function(e){var t;return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:return bd(e,o),(t=a(e.byteLength))instanceof Uint8Array?[4,t]:[3,2];case 1:return n.sent(),[3,4];case 2:return[5,(0,pe.__values)(t)];case 3:n.sent(),n.label=4;case 4:return e instanceof Uint8Array?[4,e]:[3,6];case 5:return n.sent(),[3,8];case 6:return[5,(0,pe.__values)(e)];case 7:n.sent(),n.label=8;case 8:return[2]}}))},a=null!==(n=(t=null!=t?t:{}).lengthEncoder)&&void 0!==n?n:kd,o=null!==(r=null==t?void 0:t.maxDataLength)&&void 0!==r?r:hd;return md(e)?(0,de.default)((function(){var t,n,r,a,o,u,s,l;return(0,pe.__generator)(this,(function(c){switch(c.label){case 0:t=!1,n=!1,c.label=1;case 1:c.trys.push([1,7,8,13]),a=(0,j.default)(e),c.label=2;case 2:return[4,(0,V.default)(a.next())];case 3:return(t=!(o=c.sent()).done)?(u=o.value,s=u,[5,(0,pe.__values)((0,z.default)((0,j.default)(i(s)),V.default))]):[3,6];case 4:c.sent(),c.label=5;case 5:return t=!1,[3,2];case 6:return[3,13];case 7:return l=c.sent(),n=!0,r=l,[3,13];case 8:return c.trys.push([8,,11,12]),t&&null!=a.return?[4,a.return()]:[3,10];case 9:c.sent(),c.label=10;case 10:return[3,12];case 11:if(n)throw r;return[7];case 12:return[7];case 13:return[2]}}))}))():function(){var t,n,r,a,o,u,s;return(0,pe.__generator)(this,(function(l){switch(l.label){case 0:t=!0,n=!1,r=void 0,l.label=1;case 1:l.trys.push([1,6,7,8]),a=e[Symbol.iterator](),l.label=2;case 2:return(t=(o=a.next()).done)?[3,5]:(u=o.value,[5,(0,pe.__values)(i(u))]);case 3:l.sent(),l.label=4;case 4:return t=!0,[3,2];case 5:return[3,8];case 6:return s=l.sent(),n=!0,r=s,[3,8];case 7:try{t||null==a.return||a.return()}finally{if(n)throw r}return[7];case 8:return[2]}}))}()}kd.bytes=0,_d.single=function(e,t){var n,r,i=null!==(n=(t=null!=t?t:{}).lengthEncoder)&&void 0!==n?n:kd;return bd(e,null!==(r=null==t?void 0:t.maxDataLength)&&void 0!==r?r:hd),new po(i(e.byteLength),e)},function(e){e[e.LENGTH=0]="LENGTH",e[e.DATA=1]="DATA"}(wd||(wd={}));var Ed=function(e){var t=Te(e);return Ed.bytes=Ae(t),t};function Sd(e,t){var n,r,i,a=function(){var e,n;return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:if(!(o.byteLength>0))return[3,3];if(u===wd.LENGTH)try{if((s=l(o))<0)throw new vd("Invalid message length");if(s>f)throw new pd("Message length too long");e=l.bytes,o.consume(e),null!=(null==t?void 0:t.onLength)&&t.onLength(s),u=wd.DATA}catch(e){if(e instanceof RangeError){if(o.byteLength>c)throw new gd("Message length length too long");return[3,3]}throw e}return u!==wd.DATA?[3,2]:o.byteLength<s?[3,3]:(n=o.sublist(0,s),o.consume(s),null!=(null==t?void 0:t.onData)&&t.onData(n),[4,n]);case 1:r.sent(),u=wd.LENGTH,r.label=2;case 2:return[3,0];case 3:return[2]}}))},o=new po,u=wd.LENGTH,s=-1,l=null!==(n=null==t?void 0:t.lengthDecoder)&&void 0!==n?n:Ed,c=null!==(r=null==t?void 0:t.maxLengthLength)&&void 0!==r?r:8,f=null!==(i=null==t?void 0:t.maxDataLength)&&void 0!==i?i:hd;return md(e)?(0,de.default)((function(){var t,n,r,i,u,s,l,c;return(0,pe.__generator)(this,(function(f){switch(f.label){case 0:t=!1,n=!1,f.label=1;case 1:f.trys.push([1,7,8,13]),i=(0,j.default)(e),f.label=2;case 2:return[4,(0,V.default)(i.next())];case 3:return(t=!(u=f.sent()).done)?(s=u.value,l=s,o.append(l),[5,(0,pe.__values)((0,z.default)((0,j.default)(a()),V.default))]):[3,6];case 4:f.sent(),f.label=5;case 5:return t=!1,[3,2];case 6:return[3,13];case 7:return c=f.sent(),n=!0,r=c,[3,13];case 8:return f.trys.push([8,,11,12]),t&&null!=i.return?[4,i.return()]:[3,10];case 9:f.sent(),f.label=10;case 10:return[3,12];case 11:if(n)throw r;return[7];case 12:return[7];case 13:if(o.byteLength>0)throw new yd("Unexpected end of input");return[2]}}))}))():function(){var t,n,r,i,u,s,l;return(0,pe.__generator)(this,(function(c){switch(c.label){case 0:t=!0,n=!1,r=void 0,c.label=1;case 1:c.trys.push([1,6,7,8]),i=e[Symbol.iterator](),c.label=2;case 2:return(t=(u=i.next()).done)?[3,5]:(s=u.value,o.append(s),[5,(0,pe.__values)(a())]);case 3:c.sent(),c.label=4;case 4:return t=!0,[3,2];case 5:return[3,8];case 6:return l=c.sent(),n=!0,r=l,[3,8];case 7:try{t||null==i.return||i.return()}finally{if(n)throw r}return[7];case 8:if(o.byteLength>0)throw new yd("Unexpected end of input");return[2]}}))}()}Ed.bytes=0,Sd.fromReader=function(e,t){var n=1;return Sd((0,de.default)((function(){var t,r,i,a;return(0,pe.__generator)(this,(function(o){switch(o.label){case 0:return o.trys.push([0,4,5,6]),[4,(0,V.default)(e.next(n))];case 1:return t=o.sent(),r=t.done,i=t.value,!0===r?[2]:null!=i?[4,i]:[3,3];case 2:o.sent(),o.label=3;case 3:return[3,6];case 4:if("ERR_UNDER_READ"===(a=o.sent()).code)return[2,{done:!0,value:null}];throw a;case 5:return n=1,[7];case 6:return[3,0];case 7:return[2]}}))}))(),(0,oe.default)((0,ae.default)({},null!=t?t:{}),{onLength:function(e){n=e}}))};var Ad=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e;return(0,H.default)(this,n),e=t.apply(this,arguments),(0,te.default)((0,q.default)(e),"name","UnexpectedEOFError"),(0,te.default)((0,q.default)(e),"code","ERR_UNEXPECTED_EOF"),e}return n}((0,he.default)(Error));function Id(e,t){var n=Oo();e.sink(n).catch(function(){var e=(0,K.default)((function(e){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return[4,n.end(e)];case 1:return t.sent(),[2]}}))}));return function(t){return e.apply(this,arguments)}}()),e.sink=function(){var e=(0,K.default)((function(e){var t,r,i,a,o,u,s,l;return(0,pe.__generator)(this,(function(c){switch(c.label){case 0:t=!1,r=!1,c.label=1;case 1:c.trys.push([1,7,8,13]),a=(0,j.default)(e),c.label=2;case 2:return[4,a.next()];case 3:return(t=!(o=c.sent()).done)?(u=o.value,s=u,[4,n.push(s)]):[3,6];case 4:c.sent(),c.label=5;case 5:return t=!1,[3,2];case 6:return[3,13];case 7:return l=c.sent(),r=!0,i=l,[3,13];case 8:return c.trys.push([8,,11,12]),t&&null!=a.return?[4,a.return()]:[3,10];case 9:c.sent(),c.label=10;case 10:return[3,12];case 11:if(r)throw i;return[7];case 12:return[7];case 13:return[4,n.end()];case 14:return c.sent(),[2]}}))}));return function(t){return e.apply(this,arguments)}}();var r=e.source;null!=e.source[Symbol.iterator]?r=e.source[Symbol.iterator]():null!=e.source[Symbol.asyncIterator]&&(r=e.source[Symbol.asyncIterator]());var i=new po;return{read:function(e){return(0,K.default)((function(){var t,n,a,o,u,s,l;return(0,pe.__generator)(this,(function(c){switch(c.label){case 0:return null==e||null===(t=e.signal)||void 0===t||t.throwIfAborted(),null!=(null==e?void 0:e.bytes)?[3,2]:[4,Lo(r.next(),null==e?void 0:e.signal)];case 1:return n=c.sent(),a=n.done,o=n.value,[2,!0===a?null:o];case 2:return i.byteLength<e.bytes?[4,Lo(r.next(),null==e?void 0:e.signal)]:[3,5];case 3:if(u=c.sent(),s=u.value,!0===u.done)throw new Ad("unexpected end of input");i.append(s),c.label=4;case 4:return[3,2];case 5:return l=i.sublist(0,e.bytes),[2,(i.consume(e.bytes),l)]}}))}))()},write:function(e,t){return(0,K.default)((function(){var r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:return null==t||null===(r=t.signal)||void 0===r||r.throwIfAborted(),e instanceof Uint8Array?[4,n.push(e,t)]:[3,2];case 1:return i.sent(),[3,4];case 2:return[4,n.push(e.subarray(),t)];case 3:i.sent(),i.label=4;case 4:return[2]}}))}))()},unwrap:function(){if(i.byteLength>0){var n=e.source;e.source=(0,de.default)((function(){return(0,pe.__generator)(this,(function(e){switch(e.label){case 0:return!1!==(null==t?void 0:t.yieldBytes)?[3,2]:[4,i];case 1:return e.sent(),[3,4];case 2:return[5,(0,pe.__values)((0,z.default)((0,j.default)(i),V.default))];case 3:e.sent(),e.label=4;case 4:return[5,(0,pe.__values)((0,z.default)((0,j.default)(n),V.default))];case 5:return e.sent(),[2]}}))}))()}return e}}}var xd=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e;return(0,H.default)(this,n),e=t.apply(this,arguments),(0,te.default)((0,q.default)(e),"name","InvalidMessageLengthError"),(0,te.default)((0,q.default)(e),"code","ERR_INVALID_MSG_LENGTH"),e}return n}((0,he.default)(Error)),Cd=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e;return(0,H.default)(this,n),e=t.apply(this,arguments),(0,te.default)((0,q.default)(e),"name","InvalidDataLengthError"),(0,te.default)((0,q.default)(e),"code","ERR_MSG_DATA_TOO_LONG"),e}return n}((0,he.default)(Error)),Td=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e;return(0,H.default)(this,n),e=t.apply(this,arguments),(0,te.default)((0,q.default)(e),"name","InvalidDataLengthLengthError"),(0,te.default)((0,q.default)(e),"code","ERR_MSG_LENGTH_TOO_LONG"),e}return n}((0,he.default)(Error));function Pd(e){var t,n,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=Id(e,r);null!=r.maxDataLength&&null==r.maxLengthLength&&(r.maxLengthLength=Ae(r.maxDataLength));var a=null!==(t=null==r?void 0:r.lengthDecoder)&&void 0!==t?t:Te,o=null!==(n=null==r?void 0:r.lengthEncoder)&&void 0!==n?n:Ce;return{read:function(e){return(0,K.default)((function(){var t,n,o;return(0,pe.__generator)(this,(function(u){switch(u.label){case 0:t=-1,n=new po,u.label=1;case 1:return o=n.append,[4,i.read((0,oe.default)((0,ae.default)({},e),{bytes:1}))];case 2:o.apply(n,[u.sent()]);try{t=a(n)}catch(e){if(e instanceof RangeError)return[3,3];throw e}if(t<0)throw new xd("Invalid message length");if(null!=(null==r?void 0:r.maxLengthLength)&&n.byteLength>r.maxLengthLength)throw new Td("message length length too long");if(t>-1)return[3,4];u.label=3;case 3:return[3,1];case 4:if(null!=(null==r?void 0:r.maxDataLength)&&t>r.maxDataLength)throw new Cd("message length too long");return[2,i.read((0,oe.default)((0,ae.default)({},e),{bytes:t}))]}}))}))()},write:function(e,t){return(0,K.default)((function(){return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:return[4,i.write(new po(o(e.byteLength),e),t)];case 1:return n.sent(),[2]}}))}))()},writeV:function(e,t){return(0,K.default)((function(){var n;return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return n=(0,J.default)(po,(0,ce.default)(e.flatMap((function(e){return[o(e.byteLength),e]})))),[4,i.write(n,t)];case 1:return r.sent(),[2]}}))}))()},unwrap:function(){return i.unwrap()}}}function Rd(){var e=Io(),t=!1;return{sink:function(n){return(0,K.default)((function(){return(0,pe.__generator)(this,(function(r){if(t)throw Error("already piped");return t=!0,e.resolve(n),[2]}))}))()},source:(0,de.default)((function(){var t;return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:return[4,(0,V.default)(e.promise)];case 1:return t=n.sent(),[5,(0,pe.__values)((0,z.default)((0,j.default)(t),V.default))];case 2:return n.sent(),[2]}}))}))()}}var Ld=65535,Dd=!!(null===(a=globalThis.process)||void 0===a||null===(o=a.env)||void 0===o?void 0:o.DUMP_SESSION_KEYS);function Md(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function Nd(e){if("boolean"!=typeof e)throw Error("boolean expected, not "+e)}function Od(e){if(!Number.isSafeInteger(e)||e<0)throw Error("positive integer expected, got "+e)}function Ud(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];if(!Md(e))throw Error("Uint8Array expected");if(n.length>0&&!n.includes(e.length))throw Error("Uint8Array expected of length "+n+", got length="+e.length)}function Fd(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(e.destroyed)throw Error("Hash instance has been destroyed");if(t&&e.finished)throw Error("Hash#digest() has already been called")}function Bd(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function qd(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];for(var r=0;r<t.length;r++)t[r].fill(0)}var zd=68===new Uint8Array(new Uint32Array([287454020]).buffer)[0];function jd(e){if("string"==typeof e)e=function(e){if("string"!=typeof e)throw Error("string expected");return new Uint8Array((new TextEncoder).encode(e))}(e);else{if(!Md(e))throw Error("Uint8Array expected, got "+(void 0===e?"undefined":(0,fe.default)(e)));e=Hd(e)}return e}function Kd(e,t){var n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];if(void 0===t)return new Uint8Array(e);if(t.length!==e)throw Error("invalid output length, expected "+e+", got: "+t.length);if(n&&t.byteOffset%4!=0)throw Error("invalid output, must be aligned");return t}function Vd(e,t,n,r){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,n,r);var i=BigInt(32),a=BigInt(4294967295),o=Number(n>>i&a),u=Number(n&a);e.setUint32(t+4,o,r),e.setUint32(t+0,u,r)}function Hd(e){return Uint8Array.from(e)}var Wd=function(e){return Uint8Array.from(e.split("").map((function(e){return e.charCodeAt(0)})))},Gd=Wd("expand 16-byte k"),Xd=Wd("expand 32-byte k"),Yd=Bd(Gd),Zd=Bd(Xd);function Qd(e,t){return e<<t|e>>>32-t}function Jd(e){return e.byteOffset%4==0}var $d=Math.pow(2,32)-1,eh=new Uint32Array;var th=function(e,t){return 255&e[t++]|(255&e[t++])<<8},nh=function(){"use strict";function e(t){(0,H.default)(this,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,Ud(t=jd(t),32);var n=th(t,0),r=th(t,2),i=th(t,4),a=th(t,6),o=th(t,8),u=th(t,10),s=th(t,12),l=th(t,14);this.r[0]=8191&n,this.r[1]=8191&(n>>>13|r<<3),this.r[2]=7939&(r>>>10|i<<6),this.r[3]=8191&(i>>>7|a<<9),this.r[4]=255&(a>>>4|o<<12),this.r[5]=o>>>1&8190,this.r[6]=8191&(o>>>14|u<<2),this.r[7]=8065&(u>>>11|s<<5),this.r[8]=8191&(s>>>8|l<<8),this.r[9]=l>>>5&127;for(var c=0;c<8;c++)this.pad[c]=th(t,16+2*c)}return(0,$.default)(e,[{key:"process",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2]?0:2048,r=this.h,i=this.r,a=i[0],o=i[1],u=i[2],s=i[3],l=i[4],c=i[5],f=i[6],d=i[7],h=i[8],v=i[9],p=th(e,t+0),g=th(e,t+2),y=th(e,t+4),m=th(e,t+6),b=th(e,t+8),w=th(e,t+10),k=th(e,t+12),_=th(e,t+14),E=r[0]+(8191&p),S=r[1]+(8191&(p>>>13|g<<3)),A=r[2]+(8191&(g>>>10|y<<6)),I=r[3]+(8191&(y>>>7|m<<9)),x=r[4]+(8191&(m>>>4|b<<12)),C=r[5]+(b>>>1&8191),T=r[6]+(8191&(b>>>14|w<<2)),P=r[7]+(8191&(w>>>11|k<<5)),R=r[8]+(8191&(k>>>8|_<<8)),L=r[9]+(_>>>5|n),D=0,M=D+E*a+S*(5*v)+A*(5*h)+I*(5*d)+x*(5*f);D=M>>>13,M&=8191;var N=(D+=(M+=C*(5*c)+T*(5*l)+P*(5*s)+R*(5*u)+L*(5*o))>>>13)+E*o+S*a+A*(5*v)+I*(5*h)+x*(5*d);D=N>>>13,N&=8191,D+=(N+=C*(5*f)+T*(5*c)+P*(5*l)+R*(5*s)+L*(5*u))>>>13,N&=8191;var O=D+E*u+S*o+A*a+I*(5*v)+x*(5*h);D=O>>>13,O&=8191,D+=(O+=C*(5*d)+T*(5*f)+P*(5*c)+R*(5*l)+L*(5*s))>>>13,O&=8191;var U=D+E*s+S*u+A*o+I*a+x*(5*v);D=U>>>13,U&=8191,D+=(U+=C*(5*h)+T*(5*d)+P*(5*f)+R*(5*c)+L*(5*l))>>>13,U&=8191;var F=D+E*l+S*s+A*u+I*o+x*a;D=F>>>13,F&=8191,D+=(F+=C*(5*v)+T*(5*h)+P*(5*d)+R*(5*f)+L*(5*c))>>>13,F&=8191;var B=D+E*c+S*l+A*s+I*u+x*o;D=B>>>13,B&=8191,D+=(B+=C*a+T*(5*v)+P*(5*h)+R*(5*d)+L*(5*f))>>>13,B&=8191;var q=D+E*f+S*c+A*l+I*s+x*u;D=q>>>13,q&=8191,D+=(q+=C*o+T*a+P*(5*v)+R*(5*h)+L*(5*d))>>>13,q&=8191;var z=D+E*d+S*f+A*c+I*l+x*s;D=z>>>13,z&=8191,D+=(z+=C*u+T*o+P*a+R*(5*v)+L*(5*h))>>>13,z&=8191;var j=D+E*h+S*d+A*f+I*c+x*l;D=j>>>13,j&=8191,D+=(j+=C*s+T*u+P*o+R*a+L*(5*v))>>>13,j&=8191;var K=D+E*v+S*h+A*d+I*f+x*c;D=K>>>13,K&=8191,D+=(K+=C*l+T*s+P*u+R*o+L*a)>>>13,K&=8191,M=8191&(D=(D=(D<<2)+D|0)+(M&=8191)|0),N+=D>>>=13,r[0]=M,r[1]=N,r[2]=O,r[3]=U,r[4]=F,r[5]=B,r[6]=q,r[7]=z,r[8]=j,r[9]=K}},{key:"finalize",value:function(){var e=this.h,t=this.pad,n=new Uint16Array(10),r=e[1]>>>13;e[1]&=8191;for(var i=2;i<10;i++)e[i]+=r,r=e[i]>>>13,e[i]&=8191;e[0]+=5*r,r=e[0]>>>13,e[0]&=8191,e[1]+=r,r=e[1]>>>13,e[1]&=8191,e[2]+=r,n[0]=e[0]+5,r=n[0]>>>13,n[0]&=8191;for(var a=1;a<10;a++)n[a]=e[a]+r,r=n[a]>>>13,n[a]&=8191;n[9]-=8192;for(var o=(1^r)-1,u=0;u<10;u++)n[u]&=o;o=~o;for(var s=0;s<10;s++)e[s]=e[s]&o|n[s];e[0]=65535&(e[0]|e[1]<<13),e[1]=65535&(e[1]>>>3|e[2]<<10),e[2]=65535&(e[2]>>>6|e[3]<<7),e[3]=65535&(e[3]>>>9|e[4]<<4),e[4]=65535&(e[4]>>>12|e[5]<<1|e[6]<<14),e[5]=65535&(e[6]>>>2|e[7]<<11),e[6]=65535&(e[7]>>>5|e[8]<<8),e[7]=65535&(e[8]>>>8|e[9]<<5);var l=e[0]+t[0];e[0]=65535&l;for(var c=1;c<8;c++)l=(e[c]+t[c]|0)+(l>>>16)|0,e[c]=65535&l;qd(n)}},{key:"update",value:function(e){Fd(this),Ud(e=jd(e));for(var t=this.buffer,n=this.blockLen,r=e.length,i=0;i<r;){var a=Math.min(n-this.pos,r-i);if(a!==n)t.set(e.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===n&&(this.process(t,0,!1),this.pos=0);else for(;n<=r-i;i+=n)this.process(e,i)}return this}},{key:"destroy",value:function(){qd(this.h,this.r,this.buffer,this.pad)}},{key:"digestInto",value:function(e){Fd(this),function(e,t){Ud(e);var n=t.outputLen;if(e.length<n)throw Error("digestInto() expects output buffer of length at least "+n)}(e,this),this.finished=!0;var t=this.buffer,n=this.h,r=this.pos;if(r){for(t[r++]=1;r<16;r++)t[r]=0;this.process(t,0,!0)}this.finalize();for(var i=0,a=0;a<8;a++)e[i++]=n[a]>>>0,e[i++]=n[a]>>>8;return e}},{key:"digest",value:function(){var e=this.buffer,t=this.outputLen;this.digestInto(e);var n=e.slice(0,t);return this.destroy(),n}}]),e}(),rh=function(e){var t=function(t,n){return e(n).update(jd(t)).digest()},n=e(new Uint8Array(32));return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=function(t){return e(t)},t}((function(e){return new nh(e)}));var ih=function(e,t){var n=function(e,t){if(null==t||"object"!=typeof t)throw Error("options must be defined");return Object.assign({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t)}(0,t),r=n.allowShortKeys,i=n.extendNonceFn,a=n.counterLength,o=n.counterRight,u=n.rounds;if("function"!=typeof e)throw Error("core must be a function");return Od(a),Od(u),Nd(o),Nd(r),function(t,n,s,l){var c=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0;Ud(t),Ud(n),Ud(s);var f=s.length;if(void 0===l&&(l=new Uint8Array(f)),Ud(l),Od(c),c<0||c>=$d)throw Error("arx: counter overflow");if(l.length<f)throw Error("arx: output (".concat(l.length,") is shorter than data (").concat(f,")"));var d,h,v=[],p=t.length;if(32===p)v.push(d=Hd(t)),h=Zd;else{if(16!==p||!r)throw Error("arx: invalid 32-byte key, got length="+p);(d=new Uint8Array(32)).set(t),d.set(t,16),h=Yd,v.push(d)}Jd(n)||v.push(n=Hd(n));var g=Bd(d);if(i){if(24!==n.length)throw Error("arx: extended nonce must be 24 bytes");i(h,g,Bd(n.subarray(0,16)),g),n=n.subarray(16)}var y=16-a;if(y!==n.length)throw Error("arx: nonce must be ".concat(y," or 16 bytes"));if(12!==y){var m=new Uint8Array(12);m.set(n,o?0:12-n.length),n=m,v.push(n)}var b=Bd(n);return function(e,t,n,r,i,a,o,u){for(var s=i.length,l=new Uint8Array(64),c=Bd(l),f=Jd(i)&&Jd(a),d=f?Bd(i):eh,h=f?Bd(a):eh,v=0;v<s;o++){if(e(t,n,r,c,o,u),o>=$d)throw Error("arx: counter overflow");var p=Math.min(64,s-v);if(f&&64===p){var g=v/4;if(v%4!=0)throw Error("arx: invalid block position");for(var y=void 0,m=0;m<16;m++)h[y=g+m]=d[y]^c[m];v+=64}else{for(var b=void 0,w=0;w<p;w++)a[b=v+w]=i[b]^l[w];v+=p}}}(e,h,g,b,s,l,c,u),qd.apply(void 0,(0,ce.default)(v)),l}}((function(e,t,n,r,i){for(var a=arguments.length>5&&void 0!==arguments[5]?arguments[5]:20,o=e[0],u=e[1],s=e[2],l=e[3],c=t[0],f=t[1],d=t[2],h=t[3],v=t[4],p=t[5],g=t[6],y=t[7],m=i,b=n[0],w=n[1],k=n[2],_=o,E=u,S=s,A=l,I=c,x=f,C=d,T=h,P=v,R=p,L=g,D=y,M=m,N=b,O=w,U=k,F=0;F<a;F+=2)M=Qd(M^(_=_+I|0),16),I=Qd(I^(P=P+M|0),12),M=Qd(M^(_=_+I|0),8),I=Qd(I^(P=P+M|0),7),N=Qd(N^(E=E+x|0),16),x=Qd(x^(R=R+N|0),12),N=Qd(N^(E=E+x|0),8),x=Qd(x^(R=R+N|0),7),O=Qd(O^(S=S+C|0),16),C=Qd(C^(L=L+O|0),12),O=Qd(O^(S=S+C|0),8),C=Qd(C^(L=L+O|0),7),U=Qd(U^(A=A+T|0),16),T=Qd(T^(D=D+U|0),12),U=Qd(U^(A=A+T|0),8),T=Qd(T^(D=D+U|0),7),U=Qd(U^(_=_+x|0),16),x=Qd(x^(L=L+U|0),12),U=Qd(U^(_=_+x|0),8),x=Qd(x^(L=L+U|0),7),M=Qd(M^(E=E+C|0),16),C=Qd(C^(D=D+M|0),12),M=Qd(M^(E=E+C|0),8),C=Qd(C^(D=D+M|0),7),N=Qd(N^(S=S+T|0),16),T=Qd(T^(P=P+N|0),12),N=Qd(N^(S=S+T|0),8),T=Qd(T^(P=P+N|0),7),O=Qd(O^(A=A+I|0),16),I=Qd(I^(R=R+O|0),12),O=Qd(O^(A=A+I|0),8),I=Qd(I^(R=R+O|0),7);var B=0;r[B++]=o+_|0,r[B++]=u+E|0,r[B++]=s+S|0,r[B++]=l+A|0,r[B++]=c+I|0,r[B++]=f+x|0,r[B++]=d+C|0,r[B++]=h+T|0,r[B++]=v+P|0,r[B++]=p+R|0,r[B++]=g+L|0,r[B++]=y+D|0,r[B++]=m+M|0,r[B++]=b+N|0,r[B++]=w+O|0,r[B++]=k+U|0}),{counterRight:!1,counterLength:4,allowShortKeys:!1}),ah=new Uint8Array(16),oh=function(e,t){e.update(t);var n=t.length%16;n&&e.update(ah.subarray(n))},uh=new Uint8Array(32);function sh(e,t,n,r,i){var a=e(t,n,uh),o=rh.create(a);i&&oh(o,i),oh(o,r);var u=function(e,t,n){Nd(n);var r,i=new Uint8Array(16),a=(r=i,new DataView(r.buffer,r.byteOffset,r.byteLength));return Vd(a,0,BigInt(t),n),Vd(a,8,BigInt(e),n),i}(r.length,i?i.length:0,!0);o.update(u);var s=o.digest();return qd(a,u),s}var lh,ch=function(e,t){var n=function(n){for(var r=arguments.length,i=new Array(r>1?r-1:0),a=1;a<r;a++)i[a-1]=arguments[a];if(Ud(n),!zd)throw Error("Non little-endian hardware is not yet supported");if(void 0!==e.nonceLength){var o=i[0];if(!o)throw Error("nonce / iv required");e.varSizeNonce?Ud(o):Ud(o,e.nonceLength)}var u=e.tagLength;u&&void 0!==i[1]&&Ud(i[1]);var s=t.apply(void 0,[n].concat((0,ce.default)(i))),l=function(e,t){if(void 0!==t){if(2!==e)throw Error("cipher output not supported");Ud(t)}},c=!1;return{encrypt:function(e,t){if(c)throw Error("cannot encrypt() twice with same key + nonce");return c=!0,Ud(e),l(s.encrypt.length,t),s.encrypt(e,t)},decrypt:function(e,t){if(Ud(e),u&&e.length<u)throw Error("invalid ciphertext length: smaller than tagLength="+u);return l(s.decrypt.length,t),s.decrypt(e,t)}}};return Object.assign(n,e),n}({blockSize:64,nonceLength:12,tagLength:16},(lh=ih,function(e,t,n){return{encrypt:function(r,i){var a=r.length;(i=Kd(a+16,i,!1)).set(r);var o=i.subarray(0,-16);lh(e,t,o,o,1);var u=sh(lh,e,t,o,n);return i.set(u,a),qd(u),i},decrypt:function(r,i){i=Kd(r.length-16,i,!1);var a=r.subarray(0,-16),o=r.subarray(-16),u=sh(lh,e,t,a,n);if(!function(e,t){if(e.length!==t.length)return!1;for(var n=0,r=0;r<e.length;r++)n|=e[r]^t[r];return 0===n}(o,u))throw Error("invalid tag");return i.set(r.subarray(0,-16)),lh(e,t,i,i,1),qd(u),i}}})),fh=Uint8Array.from([0]),dh=Uint8Array.of(),hh={hashSHA256:function(e){return Ci(e.subarray())},getHKDF:function(e,t){var n=function(e,t,n){return Pr(e),void 0===n&&(n=new Uint8Array(e.outputLen)),ql(e,Wr(n),Wr(t))}(Ci,t,e),r=function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:32;Pr(e),Cr(r);var i=e.outputLen;if(r>255*i)throw Error("Length should be <= 255*HashLen");var a=Math.ceil(r/i);void 0===n&&(n=dh);for(var o=new Uint8Array(a*i),u=ql.create(e,t),s=u._cloneInto(),l=new Uint8Array(u.outputLen),c=0;c<a;c++)fh[0]=c+1,s.update(0===c?dh:l).update(n).update(fh).digestInto(l),o.set(l,i*c),u._cloneInto(s);return u.destroy(),s.destroy(),Lr(l,fh),o.slice(0,r)}(Ci,n,void 0,96),i=r;return[i.subarray(0,32),i.subarray(32,64),i.subarray(64,96)]},generateX25519KeyPair:function(){var e=wl.utils.randomPrivateKey();return{publicKey:wl.getPublicKey(e),privateKey:e}},generateX25519KeyPairFromSeed:function(e){return{publicKey:wl.getPublicKey(e),privateKey:e}},generateX25519SharedKey:function(e,t){return wl.getSharedSecret(e.subarray(),t.subarray())},chaCha20Poly1305Encrypt:function(e,t,n,r){return ch(r,t,n).encrypt(e.subarray())},chaCha20Poly1305Decrypt:function(e,t,n,r,i){return ch(r,t,n).decrypt(e.subarray(),i)}},vh=hh,ph=function(e){var t=me(2);return t[0]=e>>8,t[1]=e,t};ph.bytes=2;var gh=function(e){if(e.length<2)throw RangeError("Could not decode int16BE");if(e instanceof Uint8Array){var t=0;return t+=e[0]<<8,t+=e[1]}return e.getUint16(0)};function yh(e,t){t.enabled&&Dd&&(e?(t("LOCAL_STATIC_PUBLIC_KEY "+Ti(e.publicKey,"hex")),t("LOCAL_STATIC_PRIVATE_KEY "+Ti(e.privateKey,"hex"))):t("Missing local static keys."))}function mh(e,t){t.enabled&&Dd&&(e?(t("LOCAL_PUBLIC_EPHEMERAL_KEY "+Ti(e.publicKey,"hex")),t("LOCAL_PRIVATE_EPHEMERAL_KEY "+Ti(e.privateKey,"hex"))):t("Missing local ephemeral keys."))}function bh(e,t){t.enabled&&Dd&&t(e?"REMOTE_EPHEMERAL_PUBLIC_KEY "+Ti(e.subarray(),"hex"):"Missing remote ephemeral keys.")}function wh(e,t,n){n.enabled&&Dd&&(n("CIPHER_STATE_1 ".concat(e.n.getUint64()," ").concat(e.k&&Ti(e.k,"hex"))),n("CIPHER_STATE_2 ".concat(t.n.getUint64()," ").concat(t.k&&Ti(t.k,"hex"))))}gh.bytes=2;var kh=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Invalid crypto exchange";return(0,H.default)(this,n),e=t.call(this,r),(0,te.default)((0,q.default)(e),"code",void 0),e.code=n.code,(0,ue.default)(e)}return n}((0,he.default)(Error));(0,te.default)(kh,"code","ERR_INVALID_CRYPTO_EXCHANGE");var _h,Eh,Sh=function(){"use strict";function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;(0,H.default)(this,e),(0,te.default)(this,"n",void 0),(0,te.default)(this,"bytes",void 0),(0,te.default)(this,"view",void 0),this.n=t,this.bytes=ye(12),this.view=new DataView(this.bytes.buffer,this.bytes.byteOffset,this.bytes.byteLength),this.view.setUint32(4,t,!0)}return(0,$.default)(e,[{key:"increment",value:function(){this.n++,this.view.setUint32(4,this.n,!0)}},{key:"getBytes",value:function(){return this.bytes}},{key:"getUint64",value:function(){return this.n}},{key:"assertValue",value:function(){if(this.n>4294967295)throw Error("Cipherstate has reached maximum n, a new handshake must be performed")}}]),e}(),Ah=ye(0),Ih=function(){"use strict";function e(t,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;(0,H.default)(this,e),(0,te.default)(this,"k",void 0),(0,te.default)(this,"n",void 0),(0,te.default)(this,"crypto",void 0),this.crypto=t,this.k=n,this.n=new Sh(r)}return(0,$.default)(e,[{key:"hasKey",value:function(){return!!this.k}},{key:"encryptWithAd",value:function(e,t){if(!this.hasKey())return t;this.n.assertValue();var n=this.crypto.encrypt(t,this.n.getBytes(),e,this.k);return this.n.increment(),n}},{key:"decryptWithAd",value:function(e,t,n){if(!this.hasKey())return t;this.n.assertValue();var r=this.crypto.decrypt(t,this.n.getBytes(),e,this.k,n);return this.n.increment(),r}}]),e}(),xh=function(){"use strict";function e(t,n){(0,H.default)(this,e),(0,te.default)(this,"cs",void 0),(0,te.default)(this,"ck",void 0),(0,te.default)(this,"h",void 0),(0,te.default)(this,"crypto",void 0),this.crypto=t;var r=wn(n,"utf-8");this.h=function(e,t){if(t.length<=32){var n=ye(32);return n.set(t),n}return e.hash(t)}(t,r),this.ck=this.h,this.cs=new Ih(t)}return(0,$.default)(e,[{key:"mixKey",value:function(e){var t=(0,se.default)(this.crypto.hkdf(this.ck,e),2),n=t[0],r=t[1];this.ck=n,this.cs=new Ih(this.crypto,r)}},{key:"mixHash",value:function(e){this.h=this.crypto.hash(new po(this.h,e))}},{key:"encryptAndHash",value:function(e){var t=this.cs.encryptWithAd(this.h,e);return this.mixHash(t),t}},{key:"decryptAndHash",value:function(e){var t=this.cs.decryptWithAd(this.h,e);return this.mixHash(e),t}},{key:"split",value:function(){var e=(0,se.default)(this.crypto.hkdf(this.ck,Ah),2),t=e[0],n=e[1];return[new Ih(this.crypto,t),new Ih(this.crypto,n)]}}]),e}(),Ch=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"ss",void 0),(0,te.default)(this,"s",void 0),(0,te.default)(this,"e",void 0),(0,te.default)(this,"rs",void 0),(0,te.default)(this,"re",void 0),(0,te.default)(this,"initiator",void 0),(0,te.default)(this,"crypto",void 0);var n=t.crypto,r=t.protocolName,i=t.prologue,a=t.initiator,o=t.s,u=t.e,s=t.rs,l=t.re;this.crypto=n,this.ss=new xh(n,r),this.ss.mixHash(i),this.initiator=a,this.s=o,this.e=u,this.rs=s,this.re=l}return(0,$.default)(e,[{key:"writeE",value:function(){if(this.e)throw Error("ephemeral keypair is already set");var e=this.crypto.generateKeypair();return this.ss.mixHash(e.publicKey),this.e=e,e.publicKey}},{key:"writeS",value:function(){if(!this.s)throw Error("static keypair is not set");return this.ss.encryptAndHash(this.s.publicKey)}},{key:"writeEE",value:function(){if(!this.e)throw Error("ephemeral keypair is not set");if(!this.re)throw Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.re))}},{key:"writeES",value:function(){if(this.initiator){if(!this.e)throw Error("ephemeral keypair is not set");if(!this.rs)throw Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}else{if(!this.s)throw Error("static keypair is not set");if(!this.re)throw Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}}},{key:"writeSE",value:function(){if(this.initiator){if(!this.s)throw Error("static keypair is not set");if(!this.re)throw Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}else{if(!this.e)throw Error("ephemeral keypair is not set");if(!this.rs)throw Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}}},{key:"readE",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(this.re)throw Error("remote ephemeral public key is already set");if(e.byteLength<t+32)throw Error("message is not long enough");this.re=e.sublist(t,t+32),this.ss.mixHash(this.re)}},{key:"readS",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(this.rs)throw Error("remote static public key is already set");var n=32+(this.ss.cs.hasKey()?16:0);if(e.byteLength<t+n)throw Error("message is not long enough");var r=e.sublist(t,t+n);return this.rs=this.ss.decryptAndHash(r),n}},{key:"readEE",value:function(){this.writeEE()}},{key:"readES",value:function(){this.writeES()}},{key:"readSE",value:function(){this.writeSE()}}]),e}(),Th=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){return(0,H.default)(this,n),t.apply(this,arguments)}return(0,$.default)(n,[{key:"writeMessageA",value:function(e){return new po(this.writeE(),this.ss.encryptAndHash(e))}},{key:"writeMessageB",value:function(e){var t=this.writeE();this.writeEE();var n=this.writeS();return this.writeES(),new po(t,n,this.ss.encryptAndHash(e))}},{key:"writeMessageC",value:function(e){var t=this.writeS();return this.writeSE(),new po(t,this.ss.encryptAndHash(e))}},{key:"readMessageA",value:function(e){try{return this.readE(e),this.ss.decryptAndHash(e.sublist(32))}catch(e){throw new kh("handshake stage 0 validation fail: "+e.message)}}},{key:"readMessageB",value:function(e){try{this.readE(e),this.readEE();var t=this.readS(e,32);return this.readES(),this.ss.decryptAndHash(e.sublist(32+t))}catch(e){throw new kh("handshake stage 1 validation fail: "+e.message)}}},{key:"readMessageC",value:function(e){try{var t=this.readS(e);return this.readSE(),this.ss.decryptAndHash(e.sublist(t))}catch(e){throw new kh("handshake stage 2 validation fail: "+e.message)}}}]),n}(Ch);function Ph(e,t,n){return Rh.apply(this,arguments)}function Rh(){return Rh=(0,K.default)((function(e,t,n){var r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:return[4,e.sign(Mh(t))];case 1:return r=i.sent(),[2,Eh.encode({identityKey:dc(e.publicKey),identitySig:r,extensions:n})]}}))})),Rh.apply(this,arguments)}function Lh(e,t,n){return Dh.apply(this,arguments)}function Dh(){return Dh=(0,K.default)((function(e,t,n){var r,i,a,o;return(0,pe.__generator)(this,(function(u){switch(u.label){case 0:if(u.trys.push([0,2,,3]),r=Eh.decode(e),i=fc(r.identityKey),!1===(null==n?void 0:n.equals(i)))throw Error("Payload identity key ".concat(i," does not match expected remote identity key ").concat(n));if(!t)throw Error("Remote static does not exist");return a=Mh(t),[4,i.verify(a,r.identitySig)];case 1:if(!u.sent())throw Error("Invalid payload signature");return[2,r];case 2:throw o=u.sent(),new ta(o.message);case 3:return[2]}}))})),Dh.apply(this,arguments)}function Mh(e){var t=wn("noise-libp2p-static-key:");return e instanceof Uint8Array?uo([t,e],t.length+e.length):(e.prepend(t),e)}function Nh(e,t){return Oh.apply(this,arguments)}function Oh(){return Oh=(0,K.default)((function(e,t){var n,r,i,a,o,u,s,l,c,f,d,h,v,p,g,y,m,b;return(0,pe.__generator)(this,(function(w){switch(w.label){case 0:return n=e.log,r=e.connection,i=e.crypto,a=e.privateKey,o=e.prologue,u=e.s,s=e.remoteIdentityKey,l=e.extensions,[4,Ph(a,u.publicKey,l)];case 1:return c=w.sent(),yh((f=new Th({crypto:i,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!0,prologue:o,s:u})).s,n),n.trace("Stage 0 - Initiator starting to send first message."),[4,r.write(f.writeMessageA(Ah),t)];case 2:return w.sent(),n.trace("Stage 0 - Initiator finished sending first message."),mh(f.e,n),n.trace("Stage 1 - Initiator waiting to receive first message from responder..."),h=f.readMessageB,[4,r.read(t)];case 3:return d=h.apply(f,[w.sent()]),n.trace("Stage 1 - Initiator received the message."),bh(f.re,n),v=f.rs,(p=n).enabled&&Dd&&p(v?"REMOTE_STATIC_PUBLIC_KEY "+Ti(v.subarray(),"hex"):"Missing remote static public key."),n.trace("Initiator going to check remote's signature..."),[4,Lh(d,f.rs,s)];case 4:return g=w.sent(),n.trace("All good with the signature!"),n.trace("Stage 2 - Initiator sending third handshake message."),[4,r.write(f.writeMessageC(c),t)];case 5:return w.sent(),n.trace("Stage 2 - Initiator sent message with signed payload."),y=(0,se.default)(f.ss.split(),2),m=y[0],b=y[1],[2,(wh(m,b,n),{payload:g,encrypt:function(e){return m.encryptWithAd(Ah,e)},decrypt:function(e,t){return b.decryptWithAd(Ah,e,t)}})]}}))})),Oh.apply(this,arguments)}(function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=!0,i=!1,a=void 0;if(!1!==n.lengthDelimited&&t.fork(),null!=e.webtransportCerthashes)try{for(var o,u=e.webtransportCerthashes[Symbol.iterator]();!(r=(o=u.next()).done);r=!0){var s=o.value;t.uint32(10),t.bytes(s)}}catch(e){i=!0,a=e}finally{try{r||null==u.return||u.return()}finally{if(i)throw a}}var l=!0,c=!1,f=void 0;if(null!=e.streamMuxers)try{for(var d,h=e.streamMuxers[Symbol.iterator]();!(l=(d=h.next()).done);l=!0){var v=d.value;t.uint32(18),t.string(v)}}catch(e){c=!0,f=e}finally{try{l||null==h.return||h.return()}finally{if(c)throw f}}!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r={webtransportCerthashes:[],streamMuxers:[]},i=null==t?e.len:e.pos+t;e.pos<i;){var a=e.uint32();switch(a>>>3){case 1:var o;if(null!=(null===(o=n.limits)||void 0===o?void 0:o.webtransportCerthashes)&&r.webtransportCerthashes.length===n.limits.webtransportCerthashes)throw new _r('Decode error - map field "webtransportCerthashes" had too many elements');r.webtransportCerthashes.push(e.bytes());break;case 2:var u;if(null!=(null===(u=n.limits)||void 0===u?void 0:u.streamMuxers)&&r.streamMuxers.length===n.limits.streamMuxers)throw new _r('Decode error - map field "streamMuxers" had too many elements');r.streamMuxers.push(e.string());break;default:e.skipType(7&a)}}return r}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}})(_h||(_h={})),function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};!1!==n.lengthDelimited&&t.fork(),null!=e.identityKey&&e.identityKey.byteLength>0&&(t.uint32(10),t.bytes(e.identityKey)),null!=e.identitySig&&e.identitySig.byteLength>0&&(t.uint32(18),t.bytes(e.identitySig)),null!=e.extensions&&(t.uint32(34),_h.codec().encode(e.extensions,t)),!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r={identityKey:ye(0),identitySig:ye(0)},i=null==t?e.len:e.pos+t;e.pos<i;){var a=e.uint32();switch(a>>>3){case 1:r.identityKey=e.bytes();break;case 2:r.identitySig=e.bytes();break;case 4:var o;r.extensions=_h.codec().decode(e,e.uint32(),{limits:null===(o=n.limits)||void 0===o?void 0:o.extensions});break;default:e.skipType(7&a)}}return r}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(Eh||(Eh={}));var Uh=Symbol.toStringTag,Fh=Ta,Bh=function(){"use strict";function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};(0,H.default)(this,e),(0,te.default)(this,"protocol","/noise"),(0,te.default)(this,"crypto",void 0),(0,te.default)(this,"prologue",void 0),(0,te.default)(this,"staticKey",void 0),(0,te.default)(this,"extensions",void 0),(0,te.default)(this,"metrics",void 0),(0,te.default)(this,"components",void 0),(0,te.default)(this,Uh,"@chainsafe/libp2p-noise"),(0,te.default)(this,Fh,["@libp2p/connection-encryption","@chainsafe/libp2p-noise"]);var r=n.staticNoiseKey,i=n.extensions,a=n.crypto,o=n.prologueBytes,u=t.metrics;this.components=t;var s=null!=a?a:vh;this.crypto=function(e){return{generateKeypair:e.generateX25519KeyPair,dh:function(t,n){return e.generateX25519SharedKey(t.privateKey,n).subarray(0,32)},encrypt:e.chaCha20Poly1305Encrypt,decrypt:e.chaCha20Poly1305Decrypt,hash:e.hashSHA256,hkdf:e.getHKDF}}(s),this.extensions=(0,ae.default)({webtransportCerthashes:[]},i),this.metrics=u?function(e){return{xxHandshakeSuccesses:e.registerCounter("libp2p_noise_xxhandshake_successes_total",{help:"Total count of noise xxHandshakes successes_"}),xxHandshakeErrors:e.registerCounter("libp2p_noise_xxhandshake_error_total",{help:"Total count of noise xxHandshakes errors"}),encryptedPackets:e.registerCounter("libp2p_noise_encrypted_packets_total",{help:"Total count of noise encrypted packets successfully"}),decryptedPackets:e.registerCounter("libp2p_noise_decrypted_packets_total",{help:"Total count of noise decrypted packets"}),decryptErrors:e.registerCounter("libp2p_noise_decrypt_errors_total",{help:"Total count of noise decrypt errors"})}}(u):void 0,this.staticKey=r?s.generateX25519KeyPairFromSeed(r):s.generateX25519KeyPair(),this.prologue=null!=o?o:ye(0)}return(0,$.default)(e,[{key:"secureOutbound",value:function(e,t){var n=this;return(0,K.default)((function(){var r,i,a,o,u,s;return(0,pe.__generator)(this,(function(l){switch(l.label){case 0:return a=Pd(e,{lengthEncoder:ph,lengthDecoder:gh,maxDataLength:Ld}),[4,n.performHandshakeInitiator(a,n.components.privateKey,null==t||null===(r=t.remotePeer)||void 0===r?void 0:r.publicKey,t)];case 1:return o=l.sent(),[4,n.createSecureConnection(a,o)];case 2:return u=l.sent(),e.source=u.source,e.sink=u.sink,s=fc(o.payload.identityKey),[2,{conn:e,remoteExtensions:o.payload.extensions,remotePeer:_c(s),streamMuxer:!0===(null==t?void 0:t.skipStreamMuxerNegotiation)?void 0:n.getStreamMuxer(null===(i=o.payload.extensions)||void 0===i?void 0:i.streamMuxers)}]}}))}))()}},{key:"getStreamMuxer",value:function(e){if(null!=e&&0!==e.length){var t=this.components.upgrader.getStreamMuxers(),n=!0,r=!1,i=void 0;if(null!=t)try{for(var a,o=e[Symbol.iterator]();!(n=(a=o.next()).done);n=!0){var u=a.value,s=t.get(u);if(null!=s)return s}}catch(e){r=!0,i=e}finally{try{n||null==o.return||o.return()}finally{if(r)throw i}}if(e.length)throw new na("Early muxer negotiation was requested but the initiator and responder had no common muxers")}}},{key:"secureInbound",value:function(e,t){var n=this;return(0,K.default)((function(){var r,i,a,o,u,s;return(0,pe.__generator)(this,(function(l){switch(l.label){case 0:return a=Pd(e,{lengthEncoder:ph,lengthDecoder:gh,maxDataLength:Ld}),[4,n.performHandshakeResponder(a,n.components.privateKey,null==t||null===(r=t.remotePeer)||void 0===r?void 0:r.publicKey,t)];case 1:return o=l.sent(),[4,n.createSecureConnection(a,o)];case 2:return u=l.sent(),e.source=u.source,e.sink=u.sink,s=fc(o.payload.identityKey),[2,{conn:e,remoteExtensions:o.payload.extensions,remotePeer:_c(s),streamMuxer:!0===(null==t?void 0:t.skipStreamMuxerNegotiation)?void 0:n.getStreamMuxer(null===(i=o.payload.extensions)||void 0===i?void 0:i.streamMuxers)}]}}))}))()}},{key:"performHandshakeInitiator",value:function(e,t,n,r){var i=this;return(0,K.default)((function(){var a,o,u,s,l;return(0,pe.__generator)(this,(function(c){switch(c.label){case 0:o=!0===(null==r?void 0:r.skipStreamMuxerNegotiation)?[]:(0,ce.default)(i.components.upgrader.getStreamMuxers().keys()),c.label=1;case 1:return c.trys.push([1,3,,4]),[4,Nh({connection:e,privateKey:t,remoteIdentityKey:n,log:i.components.logger.forComponent("libp2p:noise:xxhandshake"),crypto:i.crypto,prologue:i.prologue,s:i.staticKey,extensions:(0,ae.default)({streamMuxers:o,webtransportCerthashes:[]},i.extensions)},r)];case 2:return a=c.sent(),null===(u=i.metrics)||void 0===u||u.xxHandshakeSuccesses.increment(),[3,4];case 3:throw s=c.sent(),null===(l=i.metrics)||void 0===l||l.xxHandshakeErrors.increment(),s;case 4:return[2,a]}}))}))()}},{key:"performHandshakeResponder",value:function(e,t,n,r){var i=this;return(0,K.default)((function(){var a,o,u,s,l;return(0,pe.__generator)(this,(function(c){switch(c.label){case 0:o=!0===(null==r?void 0:r.skipStreamMuxerNegotiation)?[]:(0,ce.default)(i.components.upgrader.getStreamMuxers().keys()),c.label=1;case 1:return c.trys.push([1,3,,4]),[4,function(){var e=(0,K.default)((function(e,t){var n,r,i,a,o,u,s,l,c,f,d,h,v,p,g,y,m;return(0,pe.__generator)(this,(function(b){switch(b.label){case 0:return n=e.log,r=e.connection,i=e.crypto,a=e.privateKey,o=e.prologue,u=e.s,s=e.remoteIdentityKey,l=e.extensions,[4,Ph(a,u.publicKey,l)];case 1:return c=b.sent(),yh((f=new Th({crypto:i,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!1,prologue:o,s:u})).s,n),n.trace("Stage 0 - Responder waiting to receive first message."),d=f.readMessageA,[4,r.read(t)];case 2:return d.apply(f,[b.sent()]),n.trace("Stage 0 - Responder received first message."),bh(f.re,n),n.trace("Stage 1 - Responder sending out first message with signed payload and static key."),[4,r.write(f.writeMessageB(c),t)];case 3:return b.sent(),n.trace("Stage 1 - Responder sent the second handshake message with signed payload."),mh(f.e,n),n.trace("Stage 2 - Responder waiting for third handshake message..."),v=f.readMessageC,[4,r.read(t)];case 4:return h=v.apply(f,[b.sent()]),n.trace("Stage 2 - Responder received the message, finished handshake."),[4,Lh(h,f.rs,s)];case 5:return p=b.sent(),g=(0,se.default)(f.ss.split(),2),y=g[0],m=g[1],[2,(wh(y,m,n),{payload:p,encrypt:function(e){return m.encryptWithAd(Ah,e)},decrypt:function(e,t){return y.decryptWithAd(Ah,e,t)}})]}}))}));return function(t,n){return e.apply(this,arguments)}}()({connection:e,privateKey:t,remoteIdentityKey:n,log:i.components.logger.forComponent("libp2p:noise:xxhandshake"),crypto:i.crypto,prologue:i.prologue,s:i.staticKey,extensions:(0,ae.default)({streamMuxers:o,webtransportCerthashes:[]},i.extensions)},r)];case 2:return a=c.sent(),null===(u=i.metrics)||void 0===u||u.xxHandshakeSuccesses.increment(),[3,4];case 3:throw s=c.sent(),null===(l=i.metrics)||void 0===l||l.xxHandshakeErrors.increment(),s;case 4:return[2,a]}}))}))()}},{key:"createSecureConnection",value:function(e,t){var n=this;return(0,K.default)((function(){var r,i,a,o;return(0,pe.__generator)(this,(function(u){switch(u.label){case 0:return r=(0,se.default)(function(){var e=Rd(),t=Rd();return[{source:e.source,sink:t.sink},{source:t.source,sink:e.sink}]}(),2),i=r[0],a=r[1],o=e.unwrap(),[4,Bo(i,function(e,t){return function(){var n=(0,de.default)((function(n){var r,i,a,o,u,s,l,c,f,d,h;return(0,pe.__generator)(this,(function(v){switch(v.label){case 0:r=!1,i=!1,v.label=1;case 1:v.trys.push([1,9,10,15]),o=(0,j.default)(n),v.label=2;case 2:return[4,(0,V.default)(o.next())];case 3:if(!(r=!(u=v.sent()).done))return[3,8];s=u.value,l=s,c=0,v.label=4;case 4:return c<l.length?((d=c+65519)>l.length&&(d=l.length),f=l instanceof Uint8Array?e.encrypt(l.subarray(c,d)):e.encrypt(l.sublist(c,d)),null==t||t.encryptedPackets.increment(),[4,new po(ph(f.byteLength),f)]):[3,7];case 5:v.sent(),v.label=6;case 6:return c+=65519,[3,4];case 7:return r=!1,[3,2];case 8:return[3,15];case 9:return h=v.sent(),i=!0,a=h,[3,15];case 10:return v.trys.push([10,,13,14]),r&&null!=o.return?[4,o.return()]:[3,12];case 11:v.sent(),v.label=12;case 12:return[3,14];case 13:if(i)throw a;return[7];case 14:return[7];case 15:return[2]}}))}));return function(e){return n.apply(this,arguments)}}()}(t,n.metrics),o,(function(e){return Sd(e,{lengthDecoder:gh})}),function(e,t){return function(){var n=(0,de.default)((function(n){var r,i,a,o,u,s,l,c,f,d,h,v,p,g;return(0,pe.__generator)(this,(function(y){switch(y.label){case 0:r=!1,i=!1,y.label=1;case 1:y.trys.push([1,11,12,17]),o=(0,j.default)(n),y.label=2;case 2:return[4,(0,V.default)(o.next())];case 3:if(!(r=!(u=y.sent()).done))return[3,10];s=u.value,l=s,c=0,y.label=4;case 4:if(!(c<l.length))return[3,9];if((f=c+Ld)>l.length&&(f=l.length),f-16<c)throw Error("Invalid chunk");d=l.sublist(c,f),h=l.subarray(c,f-16),y.label=5;case 5:return y.trys.push([5,7,,8]),v=e.decrypt(d,h),null==t||t.decryptedPackets.increment(),[4,v];case 6:return y.sent(),[3,8];case 7:throw p=y.sent(),null==t||t.decryptErrors.increment(),p;case 8:return c+=Ld,[3,4];case 9:return r=!1,[3,2];case 10:return[3,17];case 11:return g=y.sent(),i=!0,a=g,[3,17];case 12:return y.trys.push([12,,15,16]),r&&null!=o.return?[4,o.return()]:[3,14];case 13:y.sent(),y.label=14;case 14:return[3,16];case 15:if(i)throw a;return[7];case 16:return[7];case 17:return[2]}}))}));return function(e){return n.apply(this,arguments)}}()}(t,n.metrics),i)];case 1:return[2,(u.sent(),a)]}}))}))()}}]),e}();function qh(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(t){return new Bh(t,e)}}var zh=mv("dns4"),jh=mv("dns6"),Kh=mv("dnsaddr"),Vh=yv(mv("dns"),Kh,zh,jh),Hh=yv(mv("ip4"),mv("ip6")),Wh=yv(gv(Hh,mv("tcp")),gv(Vh,mv("tcp"))),Gh=gv(Hh,mv("udp")),Xh=gv(Gh,mv("utp")),Yh=gv(Gh,mv("quic")),Zh=gv(Gh,mv("quic-v1")),Qh=yv(gv(Wh,mv("ws")),gv(Vh,mv("ws"))),Jh=yv(gv(Qh,mv("p2p")),Qh),$h=yv(gv(Wh,mv("wss")),gv(Vh,mv("wss")),gv(Wh,mv("tls"),mv("ws")),gv(Vh,mv("tls"),mv("ws"))),ev=yv(gv($h,mv("p2p")),$h),tv=yv(gv(Wh,mv("http")),gv(Hh,mv("http")),gv(Vh,mv("http"))),nv=yv(gv(Wh,mv("https")),gv(Hh,mv("https")),gv(Vh,mv("https"))),rv=gv(Gh,mv("webrtc-direct"),mv("certhash")),iv=yv(gv(rv,mv("p2p")),rv),av=gv(Zh,mv("webtransport"),mv("certhash"),mv("certhash")),ov=yv(gv(av,mv("p2p")),av),uv=yv(gv(Jh,mv("p2p-webrtc-star"),mv("p2p")),gv(ev,mv("p2p-webrtc-star"),mv("p2p")),gv(Jh,mv("p2p-webrtc-star")),gv(ev,mv("p2p-webrtc-star")));yv(gv(Jh,mv("p2p-websocket-star"),mv("p2p")),gv(ev,mv("p2p-websocket-star"),mv("p2p")),gv(Jh,mv("p2p-websocket-star")),gv(ev,mv("p2p-websocket-star")));var sv=yv(gv(tv,mv("p2p-webrtc-direct"),mv("p2p")),gv(nv,mv("p2p-webrtc-direct"),mv("p2p")),gv(tv,mv("p2p-webrtc-direct")),gv(nv,mv("p2p-webrtc-direct"))),lv=yv(Qh,$h,tv,nv,uv,sv,Wh,Xh,Yh,Vh,iv,ov);yv(gv(lv,mv("p2p-stardust"),mv("p2p")),gv(lv,mv("p2p-stardust")));var cv=yv(gv(lv,mv("p2p")),uv,sv,iv,ov,mv("p2p")),fv=yv(gv(cv,mv("p2p-circuit"),cv),gv(cv,mv("p2p-circuit")),gv(mv("p2p-circuit"),cv),gv(lv,mv("p2p-circuit")),gv(mv("p2p-circuit"),lv),mv("p2p-circuit")),dv=function(){return yv(gv(fv,dv),fv)},hv=dv(),vv=yv(gv(hv,cv,hv),gv(cv,hv),gv(hv,cv),hv,cv);function pv(e){return function(t){var n;try{n=pf(t)}catch(e){return!1}var r=e(n.protoNames());return null!==r&&(!0===r||!1===r?r:0===r.length)}}function gv(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];var r=function(e){if(e.length<t.length)return null;var n=e;return t.some((function(t){return n="function"==typeof t?t().partialMatch(e):t.partialMatch(e),Array.isArray(n)&&(e=n),null===n})),n};return{toString:function(){return"{ "+t.join(" ")+" }"},input:t,matches:pv(r),partialMatch:r}}function yv(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];var r=function(e){var n=null;return t.some((function(t){var r="function"==typeof t?t().partialMatch(e):t.partialMatch(e);return null!=r&&(n=r,!0)})),n};return{toString:function(){return"{ "+t.join(" ")+" }"},input:t,matches:pv(r),partialMatch:r}}function mv(e){var t=e;return{toString:function(){return t},matches:function(e){var n;try{n=pf(e)}catch(e){return!1}var r=n.protoNames();return 1===r.length&&r[0]===t},partialMatch:function(e){return 0===e.length?null:e[0]===t?e.slice(1):null}}}yv(gv(hv,mv("webrtc"),mv("p2p")),gv(hv,mv("webrtc")),gv(lv,mv("webrtc"),mv("p2p")),gv(lv,mv("webrtc")),mv("webrtc"));var bv,wv=Gi,kv=Symbol.toStringTag,_v=Ta,Ev=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(e){var r,i,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{list:[]};if((0,H.default)(this,n),null==a.list||0===a.list.length)throw Error("Bootstrap requires a list of peer addresses");r=t.call(this),(0,te.default)((0,q.default)(r),"log",void 0),(0,te.default)((0,q.default)(r),"timer",void 0),(0,te.default)((0,q.default)(r),"list",void 0),(0,te.default)((0,q.default)(r),"timeout",void 0),(0,te.default)((0,q.default)(r),"components",void 0),(0,te.default)((0,q.default)(r),"_init",void 0),(0,te.default)((0,q.default)(r),wv,(0,q.default)(r)),(0,te.default)((0,q.default)(r),kv,"@libp2p/bootstrap"),(0,te.default)((0,q.default)(r),_v,["@libp2p/peer-discovery"]),r.components=e,r.log=e.logger.forComponent("libp2p:bootstrap"),r.timeout=null!==(i=a.timeout)&&void 0!==i?i:1e3,r.list=[];var o=!0,u=!1,s=void 0;try{for(var l,c=a.list[Symbol.iterator]();!(o=(l=c.next()).done);o=!0){var f=l.value;if(vv.matches(f)){var d=pf(f),h=d.getPeerId();if(null!=h){var v={id:kc(h),multiaddrs:[d]};r.list.push(v)}else r.log.error("Invalid bootstrap multiaddr without peer id")}else r.log.error("Invalid multiaddr")}}catch(e){u=!0,s=e}finally{try{o||null==c.return||c.return()}finally{if(u)throw s}}return r._init=a,(0,ue.default)(r)}return(0,$.default)(n,[{key:"isStarted",value:function(){return!!this.timer}},{key:"start",value:function(){var e=this;this.isStarted()||(this.log("Starting bootstrap node discovery, discovering peers after %s ms",this.timeout),this.timer=setTimeout((function(){e._discoverBootstrapPeers().catch((function(t){e.log.error(t)}))}),this.timeout))}},{key:"_discoverBootstrapPeers",value:function(){var e=this;return(0,K.default)((function(){var t,n,r,i,a,o,u,s,l;return(0,pe.__generator)(this,(function(c){switch(c.label){case 0:if(t=!0,n=!1,r=void 0,null==e.timer)return[3,8];c.label=1;case 1:c.trys.push([1,6,7,8]),i=e.list[Symbol.iterator](),c.label=2;case 2:return(t=(a=i.next()).done)?[3,5]:(o=a.value,[4,e.components.peerStore.merge(o.id,{tags:(0,te.default)({},null!==(u=e._init.tagName)&&void 0!==u?u:"bootstrap",{value:null!==(s=e._init.tagValue)&&void 0!==s?s:50,ttl:e._init.tagTTL}),multiaddrs:o.multiaddrs})]);case 3:if(c.sent(),null==e.timer)return[2];e.safeDispatchEvent("peer",{detail:o}),e.components.connectionManager.openConnection(o.id).catch((function(t){e.log.error("could not dial bootstrap peer %p",o.id,t)})),c.label=4;case 4:return t=!0,[3,2];case 5:return[3,8];case 6:return l=c.sent(),n=!0,r=l,[3,8];case 7:try{t||null==i.return||i.return()}finally{if(n)throw r}return[7];case 8:return[2]}}))}))()}},{key:"stop",value:function(){null!=this.timer&&clearTimeout(this.timer),this.timer=void 0}}]),n}(xa);(0,te.default)(Ev,"tag","bootstrap"),function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};!1!==n.lengthDelimited&&t.fork(),null!=e.publicKey&&e.publicKey.byteLength>0&&(t.uint32(10),t.bytes(e.publicKey)),null!=e.payloadType&&e.payloadType.byteLength>0&&(t.uint32(18),t.bytes(e.payloadType)),null!=e.payload&&e.payload.byteLength>0&&(t.uint32(26),t.bytes(e.payload)),null!=e.signature&&e.signature.byteLength>0&&(t.uint32(42),t.bytes(e.signature)),!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n={publicKey:ye(0),payloadType:ye(0),payload:ye(0),signature:ye(0)},r=null==t?e.len:e.pos+t;e.pos<r;){var i=e.uint32();switch(i>>>3){case 1:n.publicKey=e.bytes();break;case 2:n.payloadType=e.bytes();break;case 3:n.payload=e.bytes();break;case 5:n.signature=e.bytes();break;default:e.skipType(7&i)}}return n}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(bv||(bv={}));var Sv=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Invalid signature";return(0,H.default)(this,n),(e=t.call(this,r)).name="InvalidSignatureError",(0,ue.default)(e)}return n}((0,he.default)(Error)),Av=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"publicKey",void 0),(0,te.default)(this,"payloadType",void 0),(0,te.default)(this,"payload",void 0),(0,te.default)(this,"signature",void 0),(0,te.default)(this,"marshaled",void 0);var n=t.publicKey,r=t.payloadType,i=t.payload,a=t.signature;this.publicKey=n,this.payloadType=r,this.payload=i,this.signature=a}return(0,$.default)(e,[{key:"marshal",value:function(){return null==this.marshaled&&(this.marshaled=bv.encode({publicKey:dc(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}},{key:"equals",value:function(e){return null!=e&&so(this.marshal(),e.marshal())}},{key:"validate",value:function(e,t){var n=this;return(0,K.default)((function(){var r;return(0,pe.__generator)(this,(function(i){return r=xv(e,n.payloadType,n.payload),[2,n.publicKey.verify(r.subarray(),n.signature,t)]}))}))()}}]),e}();(0,te.default)(Av,"createFromProtobuf",(function(e){var t=bv.decode(e),n=fc(t.publicKey);return new Av({publicKey:n,payloadType:t.payloadType,payload:t.payload,signature:t.signature})})),(0,te.default)(Av,"seal",function(){var e=(0,K.default)((function(e,t,n){var r,i,a,o,u;return(0,pe.__generator)(this,(function(s){switch(s.label){case 0:if(null==t)throw Error("Missing private key");return r=e.domain,i=e.codec,a=e.marshal(),o=xv(r,i,a),[4,t.sign(o.subarray(),n)];case 1:return u=s.sent(),[2,new Av({publicKey:t.publicKey,payloadType:i,payload:a,signature:u})]}}))}));return function(t,n,r){return e.apply(this,arguments)}}()),(0,te.default)(Av,"openAndCertify",function(){var e=(0,K.default)((function(e,t,n){var r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:return[4,(r=Av.createFromProtobuf(e)).validate(t,n)];case 1:if(!i.sent())throw new Sv("Envelope signature is not valid for the given domain");return[2,r]}}))}));return function(t,n,r){return e.apply(this,arguments)}}());var Iv,xv=function(e,t,n){var r=wn(e),i=Ce(r.byteLength),a=Ce(t.length),o=Ce(n.length);return new po(i,r,a,t,o,n)},Cv=Uint8Array.from([3,1]);!function(e){var t;(function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};!1!==n.lengthDelimited&&t.fork(),null!=e.multiaddr&&e.multiaddr.byteLength>0&&(t.uint32(10),t.bytes(e.multiaddr)),!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n={multiaddr:ye(0)},r=null==t?e.len:e.pos+t;e.pos<r;){var i=e.uint32();i>>>3==1?n.multiaddr=e.bytes():e.skipType(7&i)}return n}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}})(e.AddressInfo||(e.AddressInfo={})),e.codec=function(){return null==t&&(t=kr((function(t,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=!0,a=!1,o=void 0;if(!1!==r.lengthDelimited&&n.fork(),null!=t.peerId&&t.peerId.byteLength>0&&(n.uint32(10),n.bytes(t.peerId)),null!=t.seq&&0n!==t.seq&&(n.uint32(16),n.uint64(t.seq)),null!=t.addresses)try{for(var u,s=t.addresses[Symbol.iterator]();!(i=(u=s.next()).done);i=!0){var l=u.value;n.uint32(26),e.AddressInfo.codec().encode(l,n)}}catch(e){a=!0,o=e}finally{try{i||null==s.return||s.return()}finally{if(a)throw o}}!1!==r.lengthDelimited&&n.ldelim()}),(function(t,n){for(var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i={peerId:ye(0),seq:0n,addresses:[]},a=null==n?t.len:t.pos+n;t.pos<a;){var o=t.uint32();switch(o>>>3){case 1:i.peerId=t.bytes();break;case 2:i.seq=t.uint64();break;case 3:var u,s;if(null!=(null===(u=r.limits)||void 0===u?void 0:u.addresses)&&i.addresses.length===r.limits.addresses)throw new _r('Decode error - map field "addresses" had too many elements');i.addresses.push(e.AddressInfo.codec().decode(t,t.uint32(),{limits:null===(s=r.limits)||void 0===s?void 0:s.addresses$}));break;default:t.skipType(7&o)}}return i}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(Iv||(Iv={}));var Tv,Pv=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"peerId",void 0),(0,te.default)(this,"multiaddrs",void 0),(0,te.default)(this,"seqNumber",void 0),(0,te.default)(this,"domain",e.DOMAIN),(0,te.default)(this,"codec",e.CODEC),(0,te.default)(this,"marshaled",void 0);var n=t.peerId,r=t.multiaddrs,i=t.seqNumber;this.peerId=n,this.multiaddrs=null!=r?r:[],this.seqNumber=null!=i?i:BigInt(Date.now())}return(0,$.default)(e,[{key:"marshal",value:function(){return null==this.marshaled&&(this.marshaled=Iv.encode({peerId:this.peerId.toMultihash().bytes,seq:BigInt(this.seqNumber),addresses:this.multiaddrs.map((function(e){return{multiaddr:e.bytes}}))})),this.marshaled}},{key:"equals",value:function(t){return t instanceof e&&!!this.peerId.equals(t.peerId)&&this.seqNumber===t.seqNumber&&!!function(e,t){var n=function(e,t){return e.toString().localeCompare(t.toString())};return e.length===t.length&&(t.sort(n),e.sort(n).every((function(e,n){return t[n].equals(e)})))}(this.multiaddrs,t.multiaddrs)}}]),e}();function Rv(e,t){var n,r=function(){clearTimeout(n),n=setTimeout((function(){n=void 0,e()}),t)};return r.start=function(){},r.stop=function(){clearTimeout(n)},r}function Lv(e){if(null!=e[Symbol.asyncIterator])return(0,K.default)((function(){var t,n,r,i,a,o,u;return(0,pe.__generator)(this,(function(s){switch(s.label){case 0:t=!1,n=!1,s.label=1;case 1:s.trys.push([1,6,7,12]),i=(0,j.default)(e),s.label=2;case 2:return[4,i.next()];case 3:if(!(t=!(a=s.sent()).done))return[3,5];o=a.value,o,s.label=4;case 4:return t=!1,[3,2];case 5:return[3,12];case 6:return u=s.sent(),n=!0,r=u,[3,12];case 7:return s.trys.push([7,,10,11]),t&&null!=i.return?[4,i.return()]:[3,9];case 8:s.sent(),s.label=9;case 9:return[3,11];case 10:if(n)throw r;return[7];case 11:return[7];case 12:return[2]}}))}))();var t=!0,n=!1,r=void 0;try{for(var i,a=e[Symbol.iterator]();!(t=(i=a.next()).done);t=!0)i.value}catch(e){n=!0,r=e}finally{try{t||null==a.return||a.return()}finally{if(n)throw r}}}(0,te.default)(Pv,"createFromProtobuf",(function(e){var t,n=Iv.decode(e),r=Ec(Zt(n.peerId)),i=(null!==(t=n.addresses)&&void 0!==t?t:[]).map((function(e){return pf(e.multiaddr)})),a=n.seq;return new Pv({peerId:r,multiaddrs:i,seqNumber:a})})),(0,te.default)(Pv,"DOMAIN","libp2p-peer-record"),(0,te.default)(Pv,"CODEC",Cv);var Dv,Mv=null!==(Tv=globalThis.CustomEvent)&&void 0!==Tv?Tv:Event;function Nv(e,t){var n=Pd(e,t),r={read:function(e,t){return(0,K.default)((function(){var r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:return[4,n.read(t)];case 1:return r=i.sent(),[2,e.decode(r)]}}))}))()},write:function(e,t,r){return(0,K.default)((function(){return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:return[4,n.write(t.encode(e),r)];case 1:return i.sent(),[2]}}))}))()},writeV:function(e,t,r){return(0,K.default)((function(){return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:return[4,n.writeV(e.map((function(e){return t.encode(e)})),r)];case 1:return i.sent(),[2]}}))}))()},pb:function(e){return{read:function(t){return(0,K.default)((function(){return(0,pe.__generator)(this,(function(n){return[2,r.read(e,t)]}))}))()},write:function(t,n){return(0,K.default)((function(){return(0,pe.__generator)(this,(function(i){return[2,r.write(t,e,n)]}))}))()},writeV:function(t,n){return(0,K.default)((function(){return(0,pe.__generator)(this,(function(i){return[2,r.writeV(t,e,n)]}))}))()},unwrap:function(){return r}}},unwrap:function(){return n.unwrap()}};return r}!function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=!0,i=!1,a=void 0;if(!1!==n.lengthDelimited&&t.fork(),null!=e.protocolVersion&&(t.uint32(42),t.string(e.protocolVersion)),null!=e.agentVersion&&(t.uint32(50),t.string(e.agentVersion)),null!=e.publicKey&&(t.uint32(10),t.bytes(e.publicKey)),null!=e.listenAddrs)try{for(var o,u=e.listenAddrs[Symbol.iterator]();!(r=(o=u.next()).done);r=!0){var s=o.value;t.uint32(18),t.bytes(s)}}catch(e){i=!0,a=e}finally{try{r||null==u.return||u.return()}finally{if(i)throw a}}var l=!0,c=!1,f=void 0;if(null!=e.observedAddr&&(t.uint32(34),t.bytes(e.observedAddr)),null!=e.protocols)try{for(var d,h=e.protocols[Symbol.iterator]();!(l=(d=h.next()).done);l=!0){var v=d.value;t.uint32(26),t.string(v)}}catch(e){c=!0,f=e}finally{try{l||null==h.return||h.return()}finally{if(c)throw f}}null!=e.signedPeerRecord&&(t.uint32(66),t.bytes(e.signedPeerRecord)),!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r={listenAddrs:[],protocols:[]},i=null==t?e.len:e.pos+t;e.pos<i;){var a=e.uint32();switch(a>>>3){case 5:r.protocolVersion=e.string();break;case 6:r.agentVersion=e.string();break;case 1:r.publicKey=e.bytes();break;case 2:var o;if(null!=(null===(o=n.limits)||void 0===o?void 0:o.listenAddrs)&&r.listenAddrs.length===n.limits.listenAddrs)throw new _r('Decode error - map field "listenAddrs" had too many elements');r.listenAddrs.push(e.bytes());break;case 4:r.observedAddr=e.bytes();break;case 3:var u;if(null!=(null===(u=n.limits)||void 0===u?void 0:u.protocols)&&r.protocols.length===n.limits.protocols)throw new _r('Decode error - map field "protocols" had too many elements');r.protocols.push(e.string());break;case 8:r.signedPeerRecord=e.bytes();break;default:e.skipType(7&a)}}return r}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(Dv||(Dv={}));var Ov,Uv="ipfs",Fv=5e3,Bv=1,qv=1,zv=10,jv=8192,Kv=!0,Vv=!0,Hv=function(){"use strict";function e(t,n){var r,i,a,o,u,s,l,c,f;(0,H.default)(this,e),(0,te.default)(this,"host",void 0),(0,te.default)(this,"protocol",void 0),(0,te.default)(this,"started",void 0),(0,te.default)(this,"timeout",void 0),(0,te.default)(this,"peerId",void 0),(0,te.default)(this,"privateKey",void 0),(0,te.default)(this,"peerStore",void 0),(0,te.default)(this,"registrar",void 0),(0,te.default)(this,"addressManager",void 0),(0,te.default)(this,"maxInboundStreams",void 0),(0,te.default)(this,"maxOutboundStreams",void 0),(0,te.default)(this,"maxMessageSize",void 0),(0,te.default)(this,"maxObservedAddresses",void 0),(0,te.default)(this,"events",void 0),(0,te.default)(this,"runOnLimitedConnection",void 0),(0,te.default)(this,"log",void 0),this.protocol=n.protocol,this.started=!1,this.peerId=t.peerId,this.privateKey=t.privateKey,this.peerStore=t.peerStore,this.registrar=t.registrar,this.addressManager=t.addressManager,this.events=t.events,this.log=n.log,this.timeout=null!==(a=n.timeout)&&void 0!==a?a:Fv,this.maxInboundStreams=null!==(o=n.maxInboundStreams)&&void 0!==o?o:Bv,this.maxOutboundStreams=null!==(u=n.maxOutboundStreams)&&void 0!==u?u:qv,this.maxMessageSize=null!==(s=n.maxMessageSize)&&void 0!==s?s:jv,this.maxObservedAddresses=null!==(l=n.maxObservedAddresses)&&void 0!==l?l:zv,this.runOnLimitedConnection=null!==(c=n.runOnLimitedConnection)&&void 0!==c?c:Vv,this.host={protocolVersion:(null!==(f=n.protocolPrefix)&&void 0!==f?f:Uv)+"/0.1.0",agentVersion:(r=t.nodeInfo,i=n.agentVersion,null!=i?i:r.userAgent)}}return(0,$.default)(e,[{key:"isStarted",value:function(){return this.started}},{key:"start",value:function(){var e=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return e.started?[3,3]:[4,e.peerStore.merge(e.peerId,{metadata:{AgentVersion:wn(e.host.agentVersion),ProtocolVersion:wn(e.host.protocolVersion)}})];case 1:return t.sent(),[4,e.registrar.handle(e.protocol,(function(t){e.handleProtocol(t).catch((function(t){e.log.error(t)}))}),{maxInboundStreams:e.maxInboundStreams,maxOutboundStreams:e.maxOutboundStreams,runOnLimitedConnection:e.runOnLimitedConnection})];case 2:t.sent(),e.started=!0,t.label=3;case 3:return[2]}}))}))()}},{key:"stop",value:function(){var e=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return[4,e.registrar.unhandle(e.protocol)];case 1:return t.sent(),e.started=!1,[2]}}))}))()}}]),e}(),Wv={},Gv=(Ov||(Ov=1,function(){var e,t,n,r,i,a,o,u;u=function(e){return[(-16777216&e)>>>24,(16711680&e)>>>16,(65280&e)>>>8,255&e].join(".")},o=function(e){var n,r,i,a,o,u;for(n=[],i=a=0;a<=3&&0!==e.length;i=++a){if(i>0){if("."!==e[0])throw Error("Invalid IP");e=e.substring(1)}o=(u=t(e))[0],r=u[1],e=e.substring(r),n.push(o)}if(0!==e.length)throw Error("Invalid IP");switch(n.length){case 1:if(n[0]>4294967295)throw Error("Invalid IP");return n[0]>>>0;case 2:if(n[0]>255||n[1]>16777215)throw Error("Invalid IP");return(n[0]<<24|n[1])>>>0;case 3:if(n[0]>255||n[1]>255||n[2]>65535)throw Error("Invalid IP");return(n[0]<<24|n[1]<<16|n[2])>>>0;case 4:if(n[0]>255||n[1]>255||n[2]>255||n[3]>255)throw Error("Invalid IP");return(n[0]<<24|n[1]<<16|n[2]<<8|n[3])>>>0;default:throw Error("Invalid IP")}},r=(n=function(e){return e.charCodeAt(0)})("0"),a=n("a"),i=n("A"),t=function(e){var t,o,u,s,l;for(s=0,t=10,o="9",u=0,e.length>1&&"0"===e[u]&&("x"===e[u+1]||"X"===e[u+1]?(u+=2,t=16):"0"<=e[u+1]&&e[u+1]<="9"&&(u++,t=8,o="7")),l=u;u<e.length;){if("0"<=e[u]&&e[u]<=o)s=s*t+(n(e[u])-r)>>>0;else{if(16!==t)break;if("a"<=e[u]&&e[u]<="f")s=s*t+(10+n(e[u])-a)>>>0;else{if(!("A"<=e[u]&&e[u]<="F"))break;s=s*t+(10+n(e[u])-i)>>>0}}if(s>4294967295)throw Error("too large");u++}if(u===l)throw Error("empty octet");return[s,u]},e=function(){var e=function(e,t){var n,r,i;if("string"!=typeof e)throw Error("Missing `net' parameter");if(t||(i=e.split("/",2),e=i[0],t=i[1]),t||(t=32),"string"==typeof t&&t.indexOf(".")>-1){try{this.maskLong=o(t)}catch(e){throw Error("Invalid mask: "+t)}for(n=r=32;r>=0;n=--r)if(this.maskLong===4294967295<<32-n>>>0){this.bitmask=n;break}}else{if(!t&&0!==t)throw Error("Invalid mask: empty");this.bitmask=parseInt(t,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0)}try{this.netLong=(o(e)&this.maskLong)>>>0}catch(t){throw Error("Invalid net address: "+e)}if(!(this.bitmask<=32))throw Error("Invalid mask for ip4: "+t);this.size=Math.pow(2,32-this.bitmask),this.base=u(this.netLong),this.mask=u(this.maskLong),this.hostmask=u(~this.maskLong),this.first=this.bitmask<=30?u(this.netLong+1):this.base,this.last=this.bitmask<=30?u(this.netLong+this.size-2):u(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?u(this.netLong+this.size-1):void 0};return e.prototype.contains=function(t){return"string"==typeof t&&(t.indexOf("/")>0||4!==t.split(".").length)&&(t=new e(t)),t instanceof e?this.contains(t.base)&&this.contains(t.broadcast||t.last):(o(t)&this.maskLong)>>>0==(this.netLong&this.maskLong)>>>0},e.prototype.next=function(t){return null==t&&(t=1),new e(u(this.netLong+this.size*t),this.mask)},e.prototype.forEach=function(e){var t,n,r;for(r=o(this.first),n=o(this.last),t=0;r<=n;)e(u(r),r,t),t++,r++},e.prototype.toString=function(){return this.base+"/"+this.bitmask},e}(),Wv.ip2long=o,Wv.long2ip=u,Wv.Netmask=e}()),Wv),Xv=["0.0.0.0/8","10.0.0.0/8","100.64.0.0/10","127.0.0.0/8","169.254.0.0/16","172.16.0.0/12","192.0.0.0/24","192.0.0.0/29","192.0.0.8/32","192.0.0.9/32","192.0.0.10/32","192.0.0.170/32","192.0.0.171/32","192.0.2.0/24","192.31.196.0/24","192.52.193.0/24","192.88.99.0/24","192.168.0.0/16","192.175.48.0/24","198.18.0.0/15","198.51.100.0/24","203.0.113.0/24","240.0.0.0/4","255.255.255.255/32"].map((function(e){return new Gv.Netmask(e)}));function Yv(e){var t=!0,n=!1,r=void 0;try{for(var i,a=Xv[Symbol.iterator]();!(t=(i=a.next()).done);t=!0){if(i.value.contains(e))return!0}}catch(e){n=!0,r=e}finally{try{t||null==a.return||a.return()}finally{if(n)throw r}}return!1}function Zv(e){return Dc(e)?Yv(e):/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(e)?function(e){var t=e.split(":");if(t.length<2)return!1;var n=t[t.length-1].padStart(4,"0"),r=t[t.length-2].padStart(4,"0");return Yv("".concat(parseInt(r.substring(0,2),16),".").concat(parseInt(r.substring(2),16),".").concat(parseInt(n.substring(0,2),16),".").concat(parseInt(n.substring(2),16)))}(e):function(e){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(e)}(e)?function(e){var t=e.split(":");return Yv(t[t.length-1])}(e):Mc(e)?function(e){return/^::$/.test(e)||/^::1$/.test(e)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(e)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(e)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(e)||/^ff([0-9a-fA-F]{2,2}):/i.test(e)}(e):void 0}function Qv(e){try{var t=!0,n=!1,r=void 0;try{for(var i,a=e.getComponents()[Symbol.iterator]();!(t=(i=a.next()).done);t=!0){var o=i.value.code;if(o!==Oc)return 4===o||o===Nc}}catch(e){n=!0,r=e}finally{try{t||null==a.return||a.return()}finally{if(n)throw r}}}catch(e){}return!1}function Jv(e){try{if(!Qv(e))return!1;var t,n=(0,se.default)(e.stringTuples(),1),r=(0,se.default)(n[0],2)[1];return null!=r&&null!==(t=Zv(r))&&void 0!==t&&t}catch(e){}return!0}var $v=function(e){return{match:function(t){return!(t.length<1)&&!!e(t[0])&&t.slice(1)},pattern:"fn"}},ep=function(e){return{match:function(t){return $v((function(t){return t===e})).match(t)},pattern:e}},tp=function(){return{match:function(e){return $v((function(e){return"string"==typeof e})).match(e)},pattern:"{string}"}},np=function(){return{match:function(e){return $v((function(e){return!isNaN(parseInt(e))})).match(e)},pattern:"{number}"}},rp=function(){return{match:function(e){if(e.length<2)return!1;if("p2p"!==e[0]&&"ipfs"!==e[0])return!1;if(!e[1].startsWith("Q")&&!e[1].startsWith("1"))return!1;try{xt.decode("z"+e[1])}catch(e){return!1}return e.slice(2)},pattern:"/p2p/{peerid}"}},ip=function(){return{match:function(e){if(e.length<2)return!1;if("certhash"!==e[0])return!1;try{Lt.decode(e[1])}catch(e){return!1}return e.slice(2)},pattern:"/certhash/{certhash}"}},ap=function(e){return{match:function(t){var n=e.match(t);return!1===n?t:n},pattern:"optional(".concat(e.pattern,")")}},op=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return{match:function(e){var n,r=!0,i=!1,a=void 0;try{for(var o,u=t[Symbol.iterator]();!(r=(o=u.next()).done);r=!0){var s=o.value.match(e);!1!==s&&(null==n||s.length<n.length)&&(n=s)}}catch(e){i=!0,a=e}finally{try{r||null==u.return||u.return()}finally{if(i)throw a}}return null!=n&&n},pattern:"or(".concat(t.map((function(e){return e.pattern})).join(", "),")")}},up=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return{match:function(e){var n=!0,r=!1,i=void 0;try{for(var a,o=t[Symbol.iterator]();!(n=(a=o.next()).done);n=!0){var u=a.value.match(e);if(!1===u)return!1;e=u}}catch(e){r=!0,i=e}finally{try{n||null==o.return||o.return()}finally{if(r)throw i}}return e},pattern:"and(".concat(t.map((function(e){return e.pattern})).join(", "),")")}};function sp(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];var r=function(e){var n=function(e){return e.toString().split("/").slice(1)}(e),r=!0,i=!1,a=void 0;try{for(var o,u=t[Symbol.iterator]();!(r=(o=u.next()).done);r=!0){var s=o.value.match(n);if(!1===s)return!1;n=s}}catch(e){i=!0,a=e}finally{try{r||null==u.return||u.return()}finally{if(i)throw a}}return n};return{matchers:t,matches:function(e){return!1!==r(e)},exactMatch:function(e){var t=r(e);return!1!==t&&0===t.length}}}var lp=sp(rp()),cp=up(ep("dns4"),tp()),fp=up(ep("dns6"),tp()),dp=up(ep("dnsaddr"),tp()),hp=up(ep("dns"),tp());sp(cp,ap(rp())),sp(fp,ap(rp())),sp(dp,ap(rp())),sp(op(hp,dp,cp,fp),ap(rp()));var vp=up(ep("ip4"),$v(Dc)),pp=up(ep("ip6"),$v(Mc)),gp=op(vp,pp),yp=op(gp,hp,cp,fp,dp),mp=sp(op(gp,up(op(hp,dp,cp,fp),ap(rp())))),bp=sp(vp),wp=sp(pp);sp(gp);var kp=up(yp,ep("tcp"),np()),_p=up(yp,ep("udp"),np()),Ep=sp(up(kp,ap(rp())));sp(_p);var Sp=up(_p,ep("quic"),ap(rp())),Ap=up(_p,ep("quic-v1"),ap(rp())),Ip=op(Sp,Ap);sp(Sp);var xp=sp(Ap),Cp=op(yp,kp,_p,Sp,Ap),Tp=op(up(Cp,ep("ws"),ap(rp()))),Pp=sp(Tp),Rp=op(up(Cp,ep("wss"),ap(rp())),up(Cp,ep("tls"),ap(up(ep("sni"),tp())),ep("ws"),ap(rp()))),Lp=sp(Rp),Dp=up(_p,ep("webrtc-direct"),ap(ip()),ap(ip()),ap(rp())),Mp=sp(Dp),Np=up(Ap,ep("webtransport"),ap(ip()),ap(ip()),ap(rp())),Op=sp(Np),Up=op(Tp,Rp,up(kp,ap(rp())),up(Ip,ap(rp())),up(yp,ap(rp())),Dp,Np,rp());sp(Up);var Fp=sp(up(Up,ep("p2p-circuit"),rp())),Bp=sp(op(up(Up,ep("p2p-circuit"),ep("webrtc"),ap(rp())),up(Up,ep("webrtc"),ap(rp())),up(ep("webrtc"),ap(rp()))));sp(op(up(yp,ep("tcp"),np(),ep("http"),ap(rp())),up(yp,ep("http"),ap(rp())))),sp(op(up(yp,ep("tcp"),op(up(ep("443"),ep("http")),up(np(),ep("https")),up(np(),ep("tls"),ep("http"))),ap(rp())),up(yp,ep("tls"),ep("http"),ap(rp())),up(yp,ep("https"),ap(rp())))),sp(op(up(ep("memory"),tp(),ap(rp()))));var qp=Ta,zp=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(e){var r,i,a,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return(0,H.default)(this,n),r=t.call(this,e,(0,oe.default)((0,ae.default)({},o),{protocol:"/".concat(null!==(i=o.protocolPrefix)&&void 0!==i?i:Uv,"/id/1.0.0"),log:e.logger.forComponent("libp2p:identify")})),(0,te.default)((0,q.default)(r),qp,["@libp2p/identify"]),(null!==(a=o.runOnConnectionOpen)&&void 0!==a?a:Kv)&&e.events.addEventListener("connection:open",(function(e){var t=e.detail;r.identify(t).catch((function(e){e.name!==ga.name&&r.log.error("error during identify trigged by connection:open",e)}))})),(0,ue.default)(r)}return(0,$.default)(n,[{key:"_identify",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=this;return(0,K.default)((function(){var r,i,a,o;return(0,pe.__generator)(this,(function(u){switch(u.label){case 0:null==t.signal&&(i=AbortSignal.timeout(n.timeout),t=(0,oe.default)((0,ae.default)({},t),{signal:i})),u.label=1;case 1:return u.trys.push([1,5,,6]),[4,e.newStream(n.protocol,(0,oe.default)((0,ae.default)({},t),{runOnLimitedConnection:n.runOnLimitedConnection}))];case 2:return r=u.sent(),[4,Nv(r,{maxDataLength:n.maxMessageSize}).pb(Dv).read(t)];case 3:return a=u.sent(),[4,r.close(t)];case 4:return[2,(u.sent(),a)];case 5:throw o=u.sent(),null==r||r.abort(o),o;case 6:return[2]}}))}))()}},{key:"identify",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=this;return(0,K.default)((function(){var r,i,a,o,u;return(0,pe.__generator)(this,(function(s){switch(s.label){case 0:return[4,n._identify(e,t)];case 1:if(r=s.sent(),i=r.publicKey,a=r.protocols,o=r.observedAddr,null==i)throw new ya("public key was missing from identify message");if(u=Sc(fc(i).toCID()),!e.remotePeer.equals(u))throw new ya("identified peer does not match the expected peer");if(n.peerId.equals(u))throw new ya("identified peer is our own peer id?");return[2,(n.maybeAddObservedAddress(o),n.log("identify completed for peer %p and protocols %o",u,a),function(){var e=(0,K.default)((function(e,t,n,r,i){var a,o,u,s,l,c,f,d,h,v,p,g,y;return(0,pe.__generator)(this,(function(m){switch(m.label){case 0:if(n("received identify from %p",r.remotePeer),null==i)throw new ya("message was null or undefined");if(a={},i.listenAddrs.length>0&&(a.addresses=i.listenAddrs.map((function(e){return{isCertified:!1,multiaddr:pf(e)}}))),i.protocols.length>0&&(a.protocols=i.protocols),null!=i.publicKey){if(!_c(o=fc(i.publicKey)).equals(r.remotePeer))throw new ya("public key did not match remote PeerId");a.publicKey=o}return null==i.signedPeerRecord?[3,6]:(n.trace("received signedPeerRecord from %p",r.remotePeer),s=i.signedPeerRecord,[4,Av.openAndCertify(s,Pv.DOMAIN)]);case 1:if(l=m.sent(),c=Pv.createFromProtobuf(l.payload),f=Sc(l.publicKey.toCID()),!c.peerId.equals(f))throw new ya("signing key does not match PeerId in the PeerRecord");if(!r.remotePeer.equals(c.peerId))throw new ya("signing key does not match remote PeerId");m.label=2;case 2:return m.trys.push([2,4,,5]),[4,e.get(c.peerId)];case 3:return d=m.sent(),[3,5];case 4:if("NotFoundError"!==(h=m.sent()).name)throw h;return[3,5];case 5:return null!=d&&(a.metadata=d.metadata,null!=d.peerRecordEnvelope)&&(v=Av.createFromProtobuf(d.peerRecordEnvelope),(p=Pv.createFromProtobuf(v.payload)).seqNumber>=c.seqNumber&&(n("sequence number was lower or equal to existing sequence number - stored: %d received: %d",p.seqNumber,c.seqNumber),c=p,s=d.peerRecordEnvelope)),a.peerRecordEnvelope=s,a.addresses=c.multiaddrs.map((function(e){return{isCertified:!0,multiaddr:e}})),u={seq:c.seqNumber,addresses:c.multiaddrs},[3,7];case 6:n("%p did not send a signed peer record",r.remotePeer),m.label=7;case 7:return n.trace("patching %p with",r.remotePeer,a),[4,e.patch(r.remotePeer,a)];case 8:return m.sent(),null==i.agentVersion&&null==i.protocolVersion?[3,10]:(g={},null!=i.agentVersion&&(g.AgentVersion=wn(i.agentVersion)),null!=i.protocolVersion&&(g.ProtocolVersion=wn(i.protocolVersion)),n.trace("merging %p metadata",r.remotePeer,g),[4,e.merge(r.remotePeer,{metadata:g})]);case 9:m.sent(),m.label=10;case 10:return y={peerId:r.remotePeer,protocolVersion:i.protocolVersion,agentVersion:i.agentVersion,publicKey:i.publicKey,listenAddrs:i.listenAddrs.map((function(e){return pf(e)})),observedAddr:null==i.observedAddr?void 0:pf(i.observedAddr),protocols:i.protocols,signedPeerRecord:u,connection:r},[2,(t.safeDispatchEvent("peer:identify",{detail:y}),y)]}}))}));return function(t,n,r,i,a){return e.apply(this,arguments)}}()(n.peerStore,n.events,n.log,e,r))]}}))}))()}},{key:"maybeAddObservedAddress",value:function(e){var t=function(e){if(null!=e&&e.length>0)try{return pf(e)}catch(e){}}(e);if(null!=t)if(this.log.trace("our observed address was %a",t),Jv(t))this.log.trace("our observed address was private");else{var n=t.getComponents();n[0].code!==Nc&&(n[0].code!==Oc||n[1].code!==Nc)||function(e){try{var t=!0,n=!1,r=void 0;try{for(var i,a=e.getComponents()[Symbol.iterator]();!(t=(i=a.next()).done);t=!0){var o=i.value,u=o.code,s=o.value;if(null!=s&&u===Nc)return l=s,new cf("2000::/3").contains(l)}}catch(e){n=!0,r=e}finally{try{t||null==a.return||a.return()}finally{if(n)throw r}}}catch(e){}var l;return!1}(t)?Ep.exactMatch(t)||(this.log.trace("storing the observed address"),this.addressManager.addObservedAddr(t)):this.log.trace("our observed address was IPv6 but not a global unicast address")}}},{key:"handleProtocol",value:function(e){var t=this;return(0,K.default)((function(){var n,r,i,a,o,u,s,l,c;return(0,pe.__generator)(this,(function(f){switch(f.label){case 0:n=e.connection,r=e.stream,i=AbortSignal.timeout(t.timeout),f.label=1;case 1:return f.trys.push([1,7,,8]),[4,t.peerStore.get(t.peerId)];case 2:return a=f.sent(),o=t.addressManager.getAddresses().map((function(e){return e.decapsulateCode(gf("p2p").code)})),u=a.peerRecordEnvelope,o.length>0&&null==u?(s=new Pv({peerId:t.peerId,multiaddrs:o}),[4,Av.seal(s,t.privateKey)]):[3,4];case 3:u=f.sent().marshal().subarray(),f.label=4;case 4:return l=n.remoteAddr.bytes,mp.matches(n.remoteAddr)||(l=void 0),[4,Nv(r).pb(Dv).write({protocolVersion:t.host.protocolVersion,agentVersion:t.host.agentVersion,publicKey:dc(t.privateKey.publicKey),listenAddrs:o.map((function(e){return e.bytes})),signedPeerRecord:u,observedAddr:l,protocols:a.protocols},{signal:i})];case 5:return f.sent(),[4,r.close({signal:i})];case 6:return f.sent(),[3,8];case 7:return c=f.sent(),t.log.error("could not respond to identify request",c),r.abort(c),[3,8];case 8:return[2]}}))}))()}}]),n}(Hv);function jp(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(t){return new zp(t,e)}}function Kp(e,t){var n,r,i,a=null===(r=(n=function(e){if(null!=e){if("function"==typeof e[Symbol.iterator])return e[Symbol.iterator]();if("function"==typeof e[Symbol.asyncIterator])return e[Symbol.asyncIterator]();if("function"==typeof e.next)return e}throw Error("argument is not an iterator or iterable")}(e)).return)||void 0===r?void 0:r.call(n);null!=(i=a)&&"function"==typeof i.then&&"function"==typeof i.catch&&"function"==typeof i.finally&&a.catch((function(e){t.error("could not cause iterator to return",e)}))}var Vp,Hp=function(){var e=Error("Delay aborted");return e.name="AbortError",e},Wp=new WeakMap,Gp=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.clearTimeout,n=e.setTimeout;return function(e){var r,i,a,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},u=o.value,s=o.signal;if(null==s?void 0:s.aborted)return Promise.reject(Hp());var l=null!=t?t:clearTimeout,c=function(){l(r),a(Hp())},f=new Promise((function(t,o){i=function(){s&&s.removeEventListener("abort",c),t(u)},a=o,r=(null!=n?n:setTimeout)(i,e)}));return s&&s.addEventListener("abort",c,{once:!0}),Wp.set(f,(function(){l(r),r=null,i()})),f}}(),Xp=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Rate limit exceeded",i=arguments.length>1?arguments[1]:void 0;return(0,H.default)(this,n),e=t.call(this,r),(0,te.default)((0,q.default)(e),"remainingPoints",void 0),(0,te.default)((0,q.default)(e),"msBeforeNext",void 0),(0,te.default)((0,q.default)(e),"consumedPoints",void 0),(0,te.default)((0,q.default)(e),"isFirstInDuration",void 0),e.name="RateLimitError",e.remainingPoints=i.remainingPoints,e.msBeforeNext=i.msBeforeNext,e.consumedPoints=i.consumedPoints,e.isFirstInDuration=i.isFirstInDuration,(0,ue.default)(e)}return n}((0,he.default)(Error)),Yp=(U=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"The queue was full";return(0,H.default)(this,n),(e=t.call(this,r)).name="QueueFullError",(0,ue.default)(e)}return n}((0,he.default)(Error)),(0,te.default)(U,"name","QueueFullError"),U),Zp=function(){"use strict";function e(){var t,n,r,i,a,o,u=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};(0,H.default)(this,e),(0,te.default)(this,"memoryStorage",void 0),(0,te.default)(this,"points",void 0),(0,te.default)(this,"duration",void 0),(0,te.default)(this,"blockDuration",void 0),(0,te.default)(this,"execEvenly",void 0),(0,te.default)(this,"execEvenlyMinDelayMs",void 0),(0,te.default)(this,"keyPrefix",void 0),this.points=null!==(t=u.points)&&void 0!==t?t:4,this.duration=null!==(n=u.duration)&&void 0!==n?n:1,this.blockDuration=null!==(r=u.blockDuration)&&void 0!==r?r:0,this.execEvenly=null!==(i=u.execEvenly)&&void 0!==i&&i,this.execEvenlyMinDelayMs=null!==(a=u.execEvenlyMinDelayMs)&&void 0!==a?a:1e3*this.duration/this.points,this.keyPrefix=null!==(o=u.keyPrefix)&&void 0!==o?o:"rlflx",this.memoryStorage=new Qp}return(0,$.default)(e,[{key:"consume",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=this;return(0,K.default)((function(){var i,a,o,u;return(0,pe.__generator)(this,(function(s){switch(s.label){case 0:if(i=r.getKey(e),a=r._getKeySecDuration(n),(o=r.memoryStorage.incrby(i,t,a)).remainingPoints=Math.max(r.points-o.consumedPoints,0),o.consumedPoints>r.points)throw r.blockDuration>0&&o.consumedPoints<=r.points+t&&(o=r.memoryStorage.set(i,o.consumedPoints,r.blockDuration)),new Xp("Rate limit exceeded",o);return r.execEvenly&&o.msBeforeNext>0&&!o.isFirstInDuration?((u=Math.ceil(o.msBeforeNext/(o.remainingPoints+2)))<r.execEvenlyMinDelayMs&&(u=o.consumedPoints*r.execEvenlyMinDelayMs),[4,Gp(u)]):[3,2];case 1:s.sent(),s.label=2;case 2:return[2,o]}}))}))()}},{key:"penalty",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=this.getKey(e),i=this._getKeySecDuration(n),a=this.memoryStorage.incrby(r,t,i);return a.remainingPoints=Math.max(this.points-a.consumedPoints,0),a}},{key:"reward",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=this.getKey(e),i=this._getKeySecDuration(n),a=this.memoryStorage.incrby(r,-t,i);return a.remainingPoints=Math.max(this.points-a.consumedPoints,0),a}},{key:"block",value:function(e,t){var n=1e3*t,r=this.points+1;return this.memoryStorage.set(this.getKey(e),r,t),{remainingPoints:0,msBeforeNext:0===n?-1:n,consumedPoints:r,isFirstInDuration:!1}}},{key:"set",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,r=1e3*(n>=0?n:this.duration);return this.memoryStorage.set(this.getKey(e),t,n),{remainingPoints:0,msBeforeNext:0===r?-1:r,consumedPoints:t,isFirstInDuration:!1}}},{key:"get",value:function(e){var t=this.memoryStorage.get(this.getKey(e));return null!=t&&(t.remainingPoints=Math.max(this.points-t.consumedPoints,0)),t}},{key:"delete",value:function(e){this.memoryStorage.delete(this.getKey(e))}},{key:"_getKeySecDuration",value:function(e){return null!=(null==e?void 0:e.customDuration)&&e.customDuration>=0?e.customDuration:this.duration}},{key:"getKey",value:function(e){return this.keyPrefix.length>0?"".concat(this.keyPrefix,":").concat(e):e}},{key:"parseKey",value:function(e){return e.substring(this.keyPrefix.length)}}]),e}(),Qp=function(){"use strict";function e(){(0,H.default)(this,e),(0,te.default)(this,"storage",void 0),this.storage=new Map}return(0,$.default)(e,[{key:"incrby",value:function(e,t,n){var r=this.storage.get(e);if(null!=r){var i=null!=r.expiresAt?r.expiresAt.getTime()-(new Date).getTime():-1;return null==r.expiresAt||i>0?(r.value+=t,{remainingPoints:0,msBeforeNext:i,consumedPoints:r.value,isFirstInDuration:!1}):this.set(e,t,n)}return this.set(e,t,n)}},{key:"set",value:function(e,t,n){var r=this,i=1e3*n,a=this.storage.get(e);null!=a&&clearTimeout(a.timeoutId);var o={value:t,expiresAt:i>0?new Date(Date.now()+i):void 0};return this.storage.set(e,o),i>0&&(o.timeoutId=setTimeout((function(){r.storage.delete(e)}),i),null!=o.timeoutId.unref&&o.timeoutId.unref()),{remainingPoints:0,msBeforeNext:0===i?-1:i,consumedPoints:o.value,isFirstInDuration:!0}}},{key:"get",value:function(e){var t=this.storage.get(e);if(null!=t)return{remainingPoints:0,msBeforeNext:null!=t.expiresAt?t.expiresAt.getTime()-(new Date).getTime():-1,consumedPoints:t.value,isFirstInDuration:!1}}},{key:"delete",value:function(e){var t=this.storage.get(e);return null!=t&&(null!=t.timeoutId&&clearTimeout(t.timeoutId),this.storage.delete(e),!0)}}]),e}();!function(e){e[e.NEW_STREAM=0]="NEW_STREAM",e[e.MESSAGE_RECEIVER=1]="MESSAGE_RECEIVER",e[e.MESSAGE_INITIATOR=2]="MESSAGE_INITIATOR",e[e.CLOSE_RECEIVER=3]="CLOSE_RECEIVER",e[e.CLOSE_INITIATOR=4]="CLOSE_INITIATOR",e[e.RESET_RECEIVER=5]="RESET_RECEIVER",e[e.RESET_INITIATOR=6]="RESET_INITIATOR"}(Vp||(Vp={}));var Jp=Object.freeze({0:"NEW_STREAM",1:"MESSAGE_RECEIVER",2:"MESSAGE_INITIATOR",3:"CLOSE_RECEIVER",4:"CLOSE_INITIATOR",5:"RESET_RECEIVER",6:"RESET_INITIATOR"}),$p=Object.freeze({NEW_STREAM:Vp.NEW_STREAM,MESSAGE:Vp.MESSAGE_INITIATOR,CLOSE:Vp.CLOSE_INITIATOR,RESET:Vp.RESET_INITIATOR}),eg=Object.freeze({MESSAGE:Vp.MESSAGE_RECEIVER,CLOSE:Vp.CLOSE_RECEIVER,RESET:Vp.RESET_RECEIVER}),tg=1048576,ng=function(){"use strict";function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:tg,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:4194304;(0,H.default)(this,e),(0,te.default)(this,"_buffer",void 0),(0,te.default)(this,"_headerInfo",void 0),(0,te.default)(this,"_maxMessageSize",void 0),(0,te.default)(this,"_maxUnprocessedMessageQueueSize",void 0),this._buffer=new po,this._headerInfo=null,this._maxMessageSize=t,this._maxUnprocessedMessageQueueSize=n}return(0,$.default)(e,[{key:"write",value:function(e){if(null==e||0===e.length)return[];if(this._buffer.append(e),this._buffer.byteLength>this._maxUnprocessedMessageQueueSize)throw new ya("Unprocessed message queue size too large!");for(var t=[];0!==this._buffer.length;){if(null==this._headerInfo)try{this._headerInfo=this._decodeHeader(this._buffer)}catch(e){if("InvalidMessageError"===e.name)throw e;break}var n=this._headerInfo,r=n.id,i=n.type,a=n.length,o=n.offset;if(this._buffer.length-o<a)break;var u={id:r,type:i};i!==Vp.NEW_STREAM&&i!==Vp.MESSAGE_INITIATOR&&i!==Vp.MESSAGE_RECEIVER||(u.data=this._buffer.sublist(o,o+a)),t.push(u),this._buffer.consume(o+a),this._headerInfo=null}return t}},{key:"_decodeHeader",value:function(e){var t=ag(e),n=t.value,r=t.offset,i=ag(e,r),a=i.value,o=i.offset,u=7&n;if(null==Jp[u])throw Error("Invalid type received: "+u);if(a>this._maxMessageSize)throw new ya("Message size too large");return{id:n>>3,type:u,offset:r+o,length:a}}}]),e}(),rg=128,ig=127;function ag(e){var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=0,i=0,a=n,o=e.length;do{if(a>=o||i>49)throw n=0,new RangeError("Could not decode varint");t=e.get(a++),r+=i<28?(t&ig)<<i:(t&ig)*Math.pow(2,i),i+=7}while(t>=rg);return{value:r,offset:n=a-n}}var og=10240,ug=new(function(){"use strict";function e(){(0,H.default)(this,e),(0,te.default)(this,"_pool",void 0),(0,te.default)(this,"_poolOffset",void 0),this._pool=me(og),this._poolOffset=0}return(0,$.default)(e,[{key:"write",value:function(e,t){var n=this._pool,r=this._poolOffset;Ce(e.id<<3|e.type,n,r),r+=Ae(e.id<<3|e.type),e.type!==Vp.NEW_STREAM&&e.type!==Vp.MESSAGE_INITIATOR&&e.type!==Vp.MESSAGE_RECEIVER||null==e.data?(Ce(0,n,r),r+=Ae(0)):(Ce(e.data.length,n,r),r+=Ae(e.data.length));var i=n.subarray(this._poolOffset,r);og-r<100?(this._pool=me(og),this._poolOffset=0):this._poolOffset=r,t.append(i),e.type!==Vp.NEW_STREAM&&e.type!==Vp.MESSAGE_INITIATOR&&e.type!==Vp.MESSAGE_RECEIVER||null==e.data||t.append(e.data)}}]),e}()),sg=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Stream input buffer error";return(0,H.default)(this,n),(e=t.call(this,r)).name="StreamInputBufferError",(0,ue.default)(e)}return n}((0,he.default)(Error));function lg(e){return null!=e&&"function"==typeof e.then&&"function"==typeof e.catch&&"function"==typeof e.finally}var cg=function(){"use strict";function e(t){var n,r,i=this;(0,H.default)(this,e),(0,te.default)(this,"id",void 0),(0,te.default)(this,"direction",void 0),(0,te.default)(this,"timeline",void 0),(0,te.default)(this,"protocol",void 0),(0,te.default)(this,"metadata",void 0),(0,te.default)(this,"source",void 0),(0,te.default)(this,"status",void 0),(0,te.default)(this,"readStatus",void 0),(0,te.default)(this,"writeStatus",void 0),(0,te.default)(this,"log",void 0),(0,te.default)(this,"sinkController",void 0),(0,te.default)(this,"sinkEnd",void 0),(0,te.default)(this,"closed",void 0),(0,te.default)(this,"endErr",void 0),(0,te.default)(this,"streamSource",void 0),(0,te.default)(this,"onEnd",void 0),(0,te.default)(this,"onCloseRead",void 0),(0,te.default)(this,"onCloseWrite",void 0),(0,te.default)(this,"onReset",void 0),(0,te.default)(this,"onAbort",void 0),(0,te.default)(this,"sendCloseWriteTimeout",void 0),(0,te.default)(this,"sendingData",void 0),this.sinkController=new AbortController,this.sinkEnd=Io(),this.closed=Io(),this.log=t.log,this.status="open",this.readStatus="ready",this.writeStatus="ready",this.id=t.id,this.metadata=null!==(n=t.metadata)&&void 0!==n?n:{},this.direction=t.direction,this.timeline={open:Date.now()},this.sendCloseWriteTimeout=null!==(r=t.sendCloseWriteTimeout)&&void 0!==r?r:5e3,this.onEnd=t.onEnd,this.onCloseRead=t.onCloseRead,this.onCloseWrite=t.onCloseWrite,this.onReset=t.onReset,this.onAbort=t.onAbort,this.source=this.streamSource=Po({onEnd:function(e){null!=e?i.log.trace("source ended with error",e):i.log.trace("source ended"),i.onSourceEnd(e)}}),this.sink=this.sink.bind(this)}return(0,$.default)(e,[{key:"sink",value:function(e){var t=this;return(0,K.default)((function(){var n,r,i,a,o,u,s,l,c,f,d,h,v;return(0,pe.__generator)(this,(function(p){switch(p.label){case 0:if("ready"!==t.writeStatus)throw new ca('writable end state is "'.concat(t.writeStatus,'" not "ready"'));p.label=1;case 1:return p.trys.push([1,24,25,26]),t.writeStatus="writing",n={signal:t.sinkController.signal},"outbound"!==t.direction?[3,4]:(r=t.sendNewStream(n),lg(r)?[4,r]:[3,3]);case 2:p.sent(),p.label=3;case 3:p.label=4;case 4:i=function(){Kp(e,t.log)},p.label=5;case 5:p.trys.push([5,,20,21]),t.sinkController.signal.addEventListener("abort",i),t.log.trace("sink reading from source"),a=!1,o=!1,p.label=6;case 6:p.trys.push([6,13,14,19]),s=(0,j.default)(e),p.label=7;case 7:return[4,s.next()];case 8:return(a=!(l=p.sent()).done)?(c=l.value,f=(f=c)instanceof Uint8Array?new po(f):f,d=t.sendData(f,n),lg(d)?(t.sendingData=Io(),[4,d]):[3,10]):[3,12];case 9:p.sent(),t.sendingData.resolve(),t.sendingData=void 0,p.label=10;case 10:p.label=11;case 11:return a=!1,[3,7];case 12:return[3,19];case 13:return h=p.sent(),o=!0,u=h,[3,19];case 14:return p.trys.push([14,,17,18]),a&&null!=s.return?[4,s.return()]:[3,16];case 15:p.sent(),p.label=16;case 16:return[3,18];case 17:if(o)throw u;return[7];case 18:return[7];case 19:return[3,21];case 20:return t.sinkController.signal.removeEventListener("abort",i),[7];case 21:return t.log.trace('sink finished reading from source, write status is "%s"',t.writeStatus),"writing"===t.writeStatus?(t.writeStatus="closing",t.log.trace("send close write to remote"),[4,t.sendCloseWrite({signal:AbortSignal.timeout(t.sendCloseWriteTimeout)})]):[3,23];case 22:p.sent(),t.writeStatus="closed",p.label=23;case 23:return t.onSinkEnd(),[3,26];case 24:throw v=p.sent(),t.log.trace("sink ended with error, calling abort with error",v),t.abort(v),v;case 25:return t.log.trace("resolve sink end"),t.sinkEnd.resolve(),[7];case 26:return[2]}}))}))()}},{key:"onSourceEnd",value:function(e){var t;null==this.timeline.closeRead&&(this.timeline.closeRead=Date.now(),this.readStatus="closed",null!=e&&null==this.endErr&&(this.endErr=e),null===(t=this.onCloseRead)||void 0===t||t.call(this),null!=this.timeline.closeWrite?(this.log.trace("source and sink ended"),this.timeline.close=Date.now(),"aborted"!==this.status&&"reset"!==this.status&&(this.status="closed"),null!=this.onEnd&&this.onEnd(this.endErr),this.closed.resolve()):this.log.trace("source ended, waiting for sink to end"))}},{key:"onSinkEnd",value:function(e){var t;null==this.timeline.closeWrite&&(this.timeline.closeWrite=Date.now(),this.writeStatus="closed",null!=e&&null==this.endErr&&(this.endErr=e),null===(t=this.onCloseWrite)||void 0===t||t.call(this),null!=this.timeline.closeRead?(this.log.trace("sink and source ended"),this.timeline.close=Date.now(),"aborted"!==this.status&&"reset"!==this.status&&(this.status="closed"),null!=this.onEnd&&this.onEnd(this.endErr),this.closed.resolve()):this.log.trace("sink ended, waiting for source to end"))}},{key:"close",value:function(e){var t=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:return"open"===t.status?(t.log.trace("closing gracefully"),t.status="closing",[4,Lo(Promise.all([t.closeWrite(e),t.closeRead(e),t.closed.promise]),null==e?void 0:e.signal)]):[3,2];case 1:n.sent(),t.status="closed",t.log.trace("closed gracefully"),n.label=2;case 2:return[2]}}))}))()}},{key:"closeRead",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=this;return(0,K.default)((function(){var n;return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return"closing"===t.readStatus||"closed"===t.readStatus?[2]:(t.log.trace('closing readable end of stream with starting read status "%s"',t.readStatus),n=t.readStatus,t.readStatus="closing","reset"!==t.status&&"aborted"!==t.status&&null==t.timeline.closeRead?(t.log.trace("send close read to remote"),[4,t.sendCloseRead(e)]):[3,2]);case 1:r.sent(),r.label=2;case 2:return"ready"===n&&(t.log.trace("ending internal source queue with %d queued bytes",t.streamSource.readableLength),t.streamSource.end()),t.log.trace("closed readable end of stream"),[2]}}))}))()}},{key:"closeWrite",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:return"closing"!==t.writeStatus&&"closed"!==t.writeStatus?(t.log.trace('closing writable end of stream with starting write status "%s"',t.writeStatus),"ready"===t.writeStatus?(t.log.trace("sink was never sunk, sink an empty array"),[4,Lo(t.sink([]),e.signal)]):[3,2]):[3,7];case 1:n.sent(),n.label=2;case 2:return"writing"===t.writeStatus?null!=t.sendingData?[4,Lo(t.sendingData.promise,e.signal)]:[3,4]:[3,6];case 3:n.sent(),n.label=4;case 4:return t.log.trace("aborting source passed to .sink"),t.sinkController.abort(),[4,Lo(t.sinkEnd.promise,e.signal)];case 5:n.sent(),n.label=6;case 6:t.writeStatus="closed",t.log.trace("closed writable end of stream"),n.label=7;case 7:return[2]}}))}))()}},{key:"abort",value:function(e){var t,n=this;if("closed"!==this.status&&"aborted"!==this.status&&"reset"!==this.status){this.log("abort with error",e),this.log("try to send reset to remote");var r=this.sendReset();lg(r)&&r.catch((function(e){n.log.error("error sending reset message",e)})),this.status="aborted",this.timeline.abort=Date.now(),this._closeSinkAndSource(e),null===(t=this.onAbort)||void 0===t||t.call(this,e)}}},{key:"reset",value:function(){var e;if("closed"!==this.status&&"aborted"!==this.status&&"reset"!==this.status){var t=new la("stream reset");this.status="reset",this.timeline.reset=Date.now(),this._closeSinkAndSource(t),null===(e=this.onReset)||void 0===e||e.call(this)}}},{key:"_closeSinkAndSource",value:function(e){this._closeSink(e),this._closeSource(e)}},{key:"_closeSink",value:function(e){"writing"===this.writeStatus&&(this.log.trace("end sink source"),this.sinkController.abort()),this.onSinkEnd(e)}},{key:"_closeSource",value:function(e){"closing"!==this.readStatus&&"closed"!==this.readStatus&&(this.log.trace("ending source with %d bytes to be read by consumer",this.streamSource.readableLength),this.readStatus="closing",this.streamSource.end(e))}},{key:"remoteCloseWrite",value:function(){"closing"!==this.readStatus&&"closed"!==this.readStatus?(this.log.trace("remote close write"),this._closeSource()):this.log("received remote close write but local source is already closed")}},{key:"remoteCloseRead",value:function(){"closing"!==this.writeStatus&&"closed"!==this.writeStatus?(this.log.trace("remote close read"),this._closeSink()):this.log("received remote close read but local sink is already closed")}},{key:"destroy",value:function(){"closed"!==this.status&&"aborted"!==this.status&&"reset"!==this.status?(this.log.trace("stream destroyed"),this._closeSinkAndSource()):this.log("received destroy but we are already closed")}},{key:"sourcePush",value:function(e){this.streamSource.push(e)}},{key:"sourceReadableLength",value:function(){return this.streamSource.readableLength}}]),e}(),fg=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(e){var r;return(0,H.default)(this,n),r=t.call(this,e),(0,te.default)((0,q.default)(r),"name",void 0),(0,te.default)((0,q.default)(r),"streamId",void 0),(0,te.default)((0,q.default)(r),"send",void 0),(0,te.default)((0,q.default)(r),"types",void 0),(0,te.default)((0,q.default)(r),"maxDataSize",void 0),r.types="outbound"===e.direction?$p:eg,r.send=e.send,r.name=e.name,r.streamId=e.streamId,r.maxDataSize=e.maxDataSize,(0,ue.default)(r)}return(0,$.default)(n,[{key:"sendNewStream",value:function(){var e=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return[4,e.send({id:e.streamId,type:$p.NEW_STREAM,data:new po(wn(e.name))})];case 1:return t.sent(),[2]}}))}))()}},{key:"sendData",value:function(e){var t=this;return(0,K.default)((function(){var n;return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:e=e.sublist(),r.label=1;case 1:return e.byteLength>0?(n=Math.min(e.byteLength,t.maxDataSize),[4,t.send({id:t.streamId,type:t.types.MESSAGE,data:e.sublist(0,n)})]):[3,4];case 2:r.sent(),e.consume(n),r.label=3;case 3:return[3,1];case 4:return[2]}}))}))()}},{key:"sendReset",value:function(){var e=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return[4,e.send({id:e.streamId,type:e.types.RESET})];case 1:return t.sent(),[2]}}))}))()}},{key:"sendCloseWrite",value:function(){var e=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return[4,e.send({id:e.streamId,type:e.types.CLOSE})];case 1:return t.sent(),[2]}}))}))()}},{key:"sendCloseRead",value:function(){return(0,K.default)((function(){return(0,pe.__generator)(this,(function(e){return[2]}))}))()}}]),n}(cg);function dg(e){var t=(0,oe.default)((0,ae.default)({},e),{type:"".concat(Jp[e.type]," (").concat(e.type,")")});return e.type===Vp.NEW_STREAM&&(t.data=Ti(e.data instanceof Uint8Array?e.data:e.data.subarray())),e.type!==Vp.MESSAGE_INITIATOR&&e.type!==Vp.MESSAGE_RECEIVER||(t.data=Ti(e.data instanceof Uint8Array?e.data:e.data.subarray(),"base16")),t}var hg=function(){"use strict";function e(t,n){var r,i,a=this;(0,H.default)(this,e),(0,te.default)(this,"protocol","/mplex/6.7.0"),(0,te.default)(this,"sink",void 0),(0,te.default)(this,"source",void 0),(0,te.default)(this,"log",void 0),(0,te.default)(this,"_streamId",void 0),(0,te.default)(this,"_streams",void 0),(0,te.default)(this,"_init",void 0),(0,te.default)(this,"_source",void 0),(0,te.default)(this,"closeController",void 0),(0,te.default)(this,"rateLimiter",void 0),(0,te.default)(this,"closeTimeout",void 0),(0,te.default)(this,"logger",void 0),n=null!=n?n:{},this.log=t.logger.forComponent("libp2p:mplex"),this.logger=t.logger,this._streamId=0,this._streams={initiators:new Map,receivers:new Map},this._init=n,this.closeTimeout=null!==(r=n.closeTimeout)&&void 0!==r?r:500,this.sink=this._createSink(),this._source=Po({objectMode:!0,onEnd:function(){var e=!0,t=!1,n=void 0;try{for(var r,i=a._streams.initiators.values()[Symbol.iterator]();!(e=(r=i.next()).done);e=!0){r.value.destroy()}}catch(e){t=!0,n=e}finally{try{e||null==i.return||i.return()}finally{if(t)throw n}}var o=!0,u=!1,s=void 0;try{for(var l,c=a._streams.receivers.values()[Symbol.iterator]();!(o=(l=c.next()).done);o=!0){l.value.destroy()}}catch(e){u=!0,s=e}finally{try{o||null==c.return||c.return()}finally{if(u)throw s}}}}),this.source=Bo(this._source,(function(e){return function(){var e=(0,de.default)((function(e){var t,n,r,i,a,o,u,s,l;return(0,pe.__generator)(this,(function(c){switch(c.label){case 0:t=!1,n=!1,c.label=1;case 1:c.trys.push([1,7,8,13]),i=(0,j.default)(e),c.label=2;case 2:return[4,(0,V.default)(i.next())];case 3:return(t=!(a=c.sent()).done)?(o=a.value,u=o,s=new po,ug.write(u,s),[4,s]):[3,6];case 4:c.sent(),c.label=5;case 5:return t=!1,[3,2];case 6:return[3,13];case 7:return l=c.sent(),n=!0,r=l,[3,13];case 8:return c.trys.push([8,,11,12]),t&&null!=i.return?[4,i.return()]:[3,10];case 9:c.sent(),c.label=10;case 10:return[3,12];case 11:if(n)throw r;return[7];case 12:return[7];case 13:return[2]}}))}));return function(t){return e.apply(this,arguments)}}()(e)})),this.closeController=new AbortController,this.rateLimiter=new Zp({points:null!==(i=n.disconnectThreshold)&&void 0!==i?i:5,duration:1})}return(0,$.default)(e,[{key:"streams",get:function(){var e=[],t=!0,n=!1,r=void 0;try{for(var i,a=this._streams.initiators.values()[Symbol.iterator]();!(t=(i=a.next()).done);t=!0){var o=i.value;e.push(o)}}catch(e){n=!0,r=e}finally{try{t||null==a.return||a.return()}finally{if(n)throw r}}var u=!0,s=!1,l=void 0;try{for(var c,f=this._streams.receivers.values()[Symbol.iterator]();!(u=(c=f.next()).done);u=!0){var d=c.value;e.push(d)}}catch(e){s=!0,l=e}finally{try{u||null==f.return||f.return()}finally{if(s)throw l}}return e}},{key:"newStream",value:function(e){if(this.closeController.signal.aborted)throw new sa("Muxer already closed");var t=this._streamId++;e=null==e?t.toString():e.toString();var n=this._streams.initiators;return this._newStream({id:t,name:e,type:"initiator",registry:n})}},{key:"close",value:function(e){var t=this;return(0,K.default)((function(){var n,r,i;return(0,pe.__generator)(this,(function(a){switch(a.label){case 0:if(t.closeController.signal.aborted)return[2];r=null!==(n=null==e?void 0:e.signal)&&void 0!==n?n:AbortSignal.timeout(t.closeTimeout),a.label=1;case 1:return a.trys.push([1,4,,5]),[4,Promise.all(t.streams.map(function(){var e=(0,K.default)((function(e){return(0,pe.__generator)(this,(function(t){return[2,e.close({signal:r})]}))}));return function(t){return e.apply(this,arguments)}}()))];case 2:return a.sent(),t._source.end(),[4,t._source.onEmpty({signal:r})];case 3:return a.sent(),t.closeController.abort(),[3,5];case 4:return i=a.sent(),t.abort(i),[3,5];case 5:return[2]}}))}))()}},{key:"abort",value:function(e){this.closeController.signal.aborted||(this.streams.forEach((function(t){t.abort(e)})),this.closeController.abort(e))}},{key:"_newReceiverStream",value:function(e){var t=e.id,n=e.name,r=this._streams.receivers;return this._newStream({id:t,name:n,type:"receiver",registry:r})}},{key:"_newStream",value:function(e){var t,n=this,r=e.id,i=e.name,a=e.type,o=e.registry;if(this.log("new %s stream %s",a,r),"initiator"===a&&this._streams.initiators.size===(null!==(t=this._init.maxOutboundStreams)&&void 0!==t?t:1024))throw new Sa("Too many outbound streams open");if(o.has(r))throw Error("".concat(a," stream ").concat(r," already exists!"));var u=this,s=function(e){var t=e.id,n=e.name,r=e.send,i=e.onEnd,a=e.type,o=void 0===a?"initiator":a,u=e.maxMsgSize;return new fg({id:"initiator"===o?"i"+t:"r"+t,streamId:t,name:""+(null!=n?n:t),direction:"initiator"===o?"outbound":"inbound",maxDataSize:void 0===u?tg:u,onEnd:i,send:r,log:e.logger.forComponent("libp2p:mplex:stream:".concat(o,":").concat(t))})}({id:r,name:i,send:function(){var e=(0,K.default)((function(e){return(0,pe.__generator)(this,(function(t){return u.log.enabled&&u.log.trace("%s stream %s send",a,r,dg(e)),u._source.push(e),[2]}))}));return function(t){return e.apply(this,arguments)}}(),type:a,onEnd:function(){n.log("%s stream with id %s and protocol %s ended",a,r,s.protocol),o.delete(r),null!=n._init.onStreamEnd&&n._init.onStreamEnd(s)},maxMsgSize:this._init.maxMsgSize,logger:this.logger});return o.set(r,s),s}},{key:"_createSink",value:function(){var e=this;return function(){var t=(0,K.default)((function(t){var n,r,i,a,o,u,s,l,c,f,d,h,v,p,g,y,m,b;return(0,pe.__generator)(this,(function(w){switch(w.label){case 0:n=function(){Kp(t,e.log)},e.closeController.signal.addEventListener("abort",n),w.label=1;case 1:w.trys.push([1,21,22,23]),r=new ng(e._init.maxMsgSize,e._init.maxUnprocessedMessageQueueSize),i=!1,a=!1,w.label=2;case 2:w.trys.push([2,14,15,20]),u=(0,j.default)(t),w.label=3;case 3:return[4,u.next()];case 4:if(!(i=!(s=w.sent()).done))return[3,13];l=s.value,c=l,f=!0,d=!1,h=void 0,w.label=5;case 5:w.trys.push([5,10,11,12]),v=r.write(c)[Symbol.iterator](),w.label=6;case 6:return(f=(p=v.next()).done)?[3,9]:(g=p.value,[4,e._handleIncoming(g)]);case 7:w.sent(),w.label=8;case 8:return f=!0,[3,6];case 9:return[3,12];case 10:return y=w.sent(),d=!0,h=y,[3,12];case 11:try{f||null==v.return||v.return()}finally{if(d)throw h}return[7];case 12:return i=!1,[3,3];case 13:return[3,20];case 14:return m=w.sent(),a=!0,o=m,[3,20];case 15:return w.trys.push([15,,18,19]),i&&null!=u.return?[4,u.return()]:[3,17];case 16:w.sent(),w.label=17;case 17:return[3,19];case 18:if(a)throw o;return[7];case 19:return[7];case 20:return e._source.end(),[3,23];case 21:return b=w.sent(),e.log("error in sink",b),e._source.end(b),[3,23];case 22:return e.closeController.signal.removeEventListener("abort",n),[7];case 23:return[2]}}))}));return function(e){return t.apply(this,arguments)}}()}},{key:"_handleIncoming",value:function(e){var t=this;return(0,K.default)((function(){var n,r,i,a,o,u,s;return(0,pe.__generator)(this,(function(l){switch(l.label){case 0:if(n=e.id,r=e.type,t.log.enabled&&t.log.trace("incoming message",dg(e)),e.type!==Vp.NEW_STREAM)return[3,6];if(t._streams.receivers.size!==(null!==(i=t._init.maxInboundStreams)&&void 0!==i?i:1024))return[3,5];t.log("too many inbound streams open"),t._source.push({id:n,type:Vp.RESET_RECEIVER}),l.label=1;case 1:return l.trys.push([1,3,,4]),[4,t.rateLimiter.consume("new-stream",1)];case 2:return l.sent(),[3,4];case 3:return l.sent(),[2,(t.log("rate limit hit when opening too many new streams over the inbound stream limit - closing remote connection"),void t.abort(Error("Too many open streams")))];case 4:return[2];case 5:return a=t._newReceiverStream({id:n,name:Ti(e.data instanceof Uint8Array?e.data:e.data.subarray())}),[2,void(null!=t._init.onIncomingStream&&t._init.onIncomingStream(a))];case 6:if(null!=(o=(1&~r?t._streams.receivers:t._streams.initiators).get(n)))return[3,11];t.log("missing stream %s for message type %s",n,Jp[r]),l.label=7;case 7:return l.trys.push([7,9,,10]),[4,t.rateLimiter.consume("missing-stream",1)];case 8:return l.sent(),[3,10];case 9:return l.sent(),[2,(t.log("rate limit hit when receiving messages for streams that do not exist - closing remote connection"),void t.abort(Error("Too many messages for missing streams")))];case 10:return[2];case 11:s=null!==(u=t._init.maxStreamBufferSize)&&void 0!==u?u:4194304;try{switch(r){case Vp.MESSAGE_INITIATOR:case Vp.MESSAGE_RECEIVER:if(o.sourceReadableLength()>s)throw t._source.push({id:e.id,type:r===Vp.MESSAGE_INITIATOR?Vp.RESET_RECEIVER:Vp.RESET_INITIATOR}),new sg("Input buffer full - increase Mplex maxBufferSize to accommodate slow consumers");o.sourcePush(e.data);break;case Vp.CLOSE_INITIATOR:case Vp.CLOSE_RECEIVER:o.remoteCloseWrite();break;case Vp.RESET_INITIATOR:case Vp.RESET_RECEIVER:o.reset();break;default:t.log("unknown message type %s",r)}}catch(e){t.log.error("error while processing message",e),o.abort(e)}return[2]}}))}))()}}]),e}(),vg=Symbol.toStringTag,pg=Ta,gg=function(){"use strict";function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};(0,H.default)(this,e),(0,te.default)(this,"protocol","/mplex/6.7.0"),(0,te.default)(this,"_init",void 0),(0,te.default)(this,"components",void 0),(0,te.default)(this,vg,"@libp2p/mplex"),(0,te.default)(this,pg,["@libp2p/stream-multiplexing"]),this.components=t,this._init=n}return(0,$.default)(e,[{key:"createStreamMuxer",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return new hg(this.components,(0,ae.default)({},e,this._init))}}]),e}();function yg(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(t){return new gg(t,e)}}var mg=Symbol.toStringTag,bg=Ta,wg=function(){"use strict";function e(t){var n,r,i,a,o,u=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};(0,H.default)(this,e),(0,te.default)(this,"protocol",void 0),(0,te.default)(this,"components",void 0),(0,te.default)(this,"started",void 0),(0,te.default)(this,"timeout",void 0),(0,te.default)(this,"maxInboundStreams",void 0),(0,te.default)(this,"maxOutboundStreams",void 0),(0,te.default)(this,"runOnLimitedConnection",void 0),(0,te.default)(this,"log",void 0),(0,te.default)(this,mg,"@libp2p/ping"),(0,te.default)(this,bg,["@libp2p/ping"]),this.components=t,this.log=t.logger.forComponent("libp2p:ping"),this.started=!1,this.protocol="/".concat(null!==(n=u.protocolPrefix)&&void 0!==n?n:"ipfs","/ping/1.0.0"),this.timeout=null!==(r=u.timeout)&&void 0!==r?r:1e4,this.maxInboundStreams=null!==(i=u.maxInboundStreams)&&void 0!==i?i:2,this.maxOutboundStreams=null!==(a=u.maxOutboundStreams)&&void 0!==a?a:1,this.runOnLimitedConnection=null===(o=u.runOnLimitedConnection)||void 0===o||o,this.handleMessage=this.handleMessage.bind(this)}return(0,$.default)(e,[{key:"start",value:function(){var e=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return[4,e.components.registrar.handle(e.protocol,e.handleMessage,{maxInboundStreams:e.maxInboundStreams,maxOutboundStreams:e.maxOutboundStreams,runOnLimitedConnection:e.runOnLimitedConnection})];case 1:return t.sent(),e.started=!0,[2]}}))}))()}},{key:"stop",value:function(){var e=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return[4,e.components.registrar.unhandle(e.protocol)];case 1:return t.sent(),e.started=!1,[2]}}))}))()}},{key:"isStarted",value:function(){return this.started}},{key:"handleMessage",value:function(e){var t=this;this.log("incoming ping from %p",e.connection.remotePeer);var n=e.stream,r=Date.now(),i=Id(n),a=!1,o=this;Promise.resolve().then((0,K.default)((function(){var e,t;return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return(e=AbortSignal.timeout(o.timeout)).addEventListener("abort",(function(){null==n||n.abort(new ba("ping timeout"))})),[4,i.read({bytes:32,signal:e})];case 1:return t=r.sent(),[4,i.write(t,{signal:e})];case 2:r.sent(),a=!0,r.label=3;case 3:return[3,0];case 4:return[2]}}))}))).catch((function(r){a&&"UnexpectedEOFError"===r.name&&"ready"!==n.readStatus||(t.log.error("incoming ping from %p failed with error - %e",e.connection.remotePeer,r),null==n||n.abort(r))})).finally((function(){var i=Date.now()-r;t.log("incoming ping from %p complete in %dms",e.connection.remotePeer,i);var a=AbortSignal.timeout(t.timeout);n.close({signal:a}).catch((function(r){t.log.error("error closing ping stream from %p - %e",e.connection.remotePeer,r),null==n||n.abort(r)}))}))}},{key:"ping",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=this;return(0,K.default)((function(){var r,i,a,o,u,s,l,c,f,d;return(0,pe.__generator)(this,(function(h){switch(h.label){case 0:return n.log("pinging %p",e),r=Date.now(),i=Ol(32),[4,n.components.connectionManager.openConnection(e,t)];case 1:a=h.sent(),null==t.signal&&(u=AbortSignal.timeout(n.timeout),t=(0,oe.default)((0,ae.default)({},t),{signal:u})),h.label=2;case 2:return h.trys.push([2,5,6,9]),[4,a.newStream(n.protocol,(0,oe.default)((0,ae.default)({},t),{runOnLimitedConnection:n.runOnLimitedConnection}))];case 3:return o=h.sent(),s=Id(o),[4,Promise.all([s.write(i,t),s.read((0,oe.default)((0,ae.default)({},t),{bytes:32}))])];case 4:if(l=se.default.apply(void 0,[h.sent(),2]),c=l[1],f=Date.now()-r,!so(i,c.subarray()))throw new ma("Received wrong ping ack after ".concat(f,"ms"));return[2,(n.log("ping %p complete in %dms",a.remotePeer,f),f)];case 5:throw d=h.sent(),n.log.error("error while pinging %p",a.remotePeer,d),null==o||o.abort(d),d;case 6:return null!=o?[4,o.close(t)]:[3,8];case 7:h.sent(),h.label=8;case 8:return[7];case 9:return[2]}}))}))()}}]),e}();function kg(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(t){return new wg(t,e)}}var _g=[6,53,56,54,55];function Eg(e){var t;return null===(t=Ag("sni",e))||void 0===t?void 0:t.value}function Sg(e){var t,n=null===(t=Ag("tcp",e))||void 0===t?void 0:t.value;return null==n?"":":"+n}function Ag(e,t){return t.find((function(t){return t.name===e}))}function Ig(e){return e.some((function(e){return 448===e.code}))}function xg(e,t){var n=Pg[e.name];if(null==n)throw Error("Can't interpret protocol "+e.name);var r=n(e,t);return e.code===Nc?"[".concat(r,"]"):r}var Cg,Tg,Pg={ip4:function(e){return e.value},ip6:function(e,t){return 0===t.length?e.value:"[".concat(e.value,"]")},tcp:function(e,t){var n=t.pop();if(null==n)throw Error("Unexpected end of multiaddr");return"tcp://".concat(xg(n,t),":").concat(e.value)},udp:function(e,t){var n=t.pop();if(null==n)throw Error("Unexpected end of multiaddr");return"udp://".concat(xg(n,t),":").concat(e.value)},dnsaddr:function(e){return e.value},dns4:function(e){return e.value},dns6:function(e){return e.value},dns:function(e){return e.value},ipfs:function(e,t){var n=t.pop();if(null==n)throw Error("Unexpected end of multiaddr");return""+xg(n,t)},p2p:function(e,t){var n=t.pop();if(null==n)throw Error("Unexpected end of multiaddr");return""+xg(n,t)},http:function(e,t){var n=Ig(t),r=Eg(t),i=Sg(t);if(n&&null!=r)return"https://".concat(r).concat(i);var a=n?"https://":"http://",o=t.pop();if(null==o)throw Error("Unexpected end of multiaddr");var u=xg(o,t);return u=null==u?void 0:u.replace("tcp://",""),"".concat(a).concat(u)},"http-path":function(e,t){var n,r=t.pop();if(null==r)throw Error("Unexpected end of multiaddr");return"".concat(xg(r,t)).concat(decodeURIComponent(null!==(n=e.value)&&void 0!==n?n:""))},tls:function(e,t){var n=t.pop();if(null==n)throw Error("Unexpected end of multiaddr");return xg(n,t)},sni:function(e,t){var n=t.pop();if(null==n)throw Error("Unexpected end of multiaddr");return xg(n,t)},https:function(e,t){var n=t.pop();if(null==n)throw Error("Unexpected end of multiaddr");var r=xg(n,t);return"https://"+(r=null==r?void 0:r.replace("tcp://",""))},ws:function(e,t){var n=Ig(t),r=Eg(t),i=Sg(t);if(n&&null!=r)return"wss://".concat(r).concat(i);var a=n?"wss://":"ws://",o=t.pop();if(null==o)throw Error("Unexpected end of multiaddr");var u=xg(o,t);return u=null==u?void 0:u.replace("tcp://",""),"".concat(a).concat(u)},wss:function(e,t){var n=t.pop();if(null==n)throw Error("Unexpected end of multiaddr");var r=xg(n,t);return"wss://"+(r=null==r?void 0:r.replace("tcp://",""))}},Rg=function(){var e=(0,K.default)((function(e){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:if(e.readyState>=2)throw Error("socket closed");return 1!==e.readyState?[4,new Promise((function(t,n){function r(){e.removeEventListener("open",i),e.removeEventListener("error",a)}function i(){r(),t()}function a(t){var i;r(),n(null!==(i=t.error)&&void 0!==i?i:Error("connect ECONNREFUSED "+e.url))}e.addEventListener("open",i),e.addEventListener("error",a)}))]:[3,2];case 1:t.sent(),t.label=2;case 2:return[2]}}))}));return function(t){return e.apply(this,arguments)}}(),Lg=function(e,t){return(t=null!=t?t:{}).closeOnEnd=!1!==t.closeOnEnd,function(){var n=(0,K.default)((function(n){var r,i,a,o,u,s,l,c,f;return(0,pe.__generator)(this,(function(d){switch(d.label){case 0:r=!1,i=!1,d.label=1;case 1:d.trys.push([1,10,11,16]),o=(0,j.default)(n),d.label=2;case 2:return[4,o.next()];case 3:if(!(r=!(u=d.sent()).done))return[3,9];s=u.value,l=s,d.label=4;case 4:return d.trys.push([4,6,,7]),[4,Rg(e)];case 5:return d.sent(),[3,7];case 6:if("socket closed"===(c=d.sent()).message)return[3,9];throw c;case 7:if(e.readyState===e.CLOSING||e.readyState===e.CLOSED)return[3,9];e.send(l),d.label=8;case 8:return r=!1,[3,2];case 9:return[3,16];case 10:return f=d.sent(),i=!0,a=f,[3,16];case 11:return d.trys.push([11,,14,15]),r&&null!=o.return?[4,o.return()]:[3,13];case 12:d.sent(),d.label=13;case 13:return[3,15];case 14:if(i)throw a;return[7];case 15:return[7];case 16:return null!=t.closeOnEnd&&e.readyState<=1?[4,new Promise((function(t,n){e.addEventListener("close",(function(e){if(e.wasClean||1006===e.code)t();else{var r=Object.assign(Error("ws error"),{event:e});n(r)}})),setTimeout((function(){e.close()}))}))]:[3,18];case 17:d.sent(),d.label=18;case 18:return[2]}}))}));return function(e){return n.apply(this,arguments)}}()},Dg={},Mg={},Ng=function(){if(Tg)return Dg;Tg=1,Object.defineProperty(Dg,"__esModule",{value:!0});var e=function(){if(Cg)return Mg;Cg=1,Object.defineProperty(Mg,"__esModule",{value:!0});var e=function(){"use strict";function e(){(0,H.default)(this,e),this.pullQueue=[],this.pushQueue=[],this.eventHandlers={},this.isPaused=!1,this.isStopped=!1}return(0,$.default)(e,[{key:"push",value:function(e){if(!this.isStopped){var t={value:e,done:!1};if(this.pullQueue.length){var n=this.pullQueue.shift();n&&n.resolve(t)}else this.pushQueue.push(Promise.resolve(t)),void 0!==this.highWaterMark&&this.pushQueue.length>=this.highWaterMark&&!this.isPaused&&(this.isPaused=!0,this.eventHandlers.highWater?this.eventHandlers.highWater():console&&console.warn("EventIterator queue reached ".concat(this.pushQueue.length," items")))}}},{key:"stop",value:function(){if(!this.isStopped){this.isStopped=!0,this.remove();var e=!0,t=!1,n=void 0;try{for(var r,i=this.pullQueue[Symbol.iterator]();!(e=(r=i.next()).done);e=!0){r.value.resolve({value:void 0,done:!0})}}catch(e){t=!0,n=e}finally{try{e||null==i.return||i.return()}finally{if(t)throw n}}this.pullQueue.length=0}}},{key:"fail",value:function(e){if(!this.isStopped)if(this.isStopped=!0,this.remove(),this.pullQueue.length){var t=!0,n=!1,r=void 0;try{for(var i,a=this.pullQueue[Symbol.iterator]();!(t=(i=a.next()).done);t=!0){i.value.reject(e)}}catch(e){n=!0,r=e}finally{try{t||null==a.return||a.return()}finally{if(n)throw r}}this.pullQueue.length=0}else{var o=Promise.reject(e);o.catch((function(){})),this.pushQueue.push(o)}}},{key:"remove",value:function(){var e=this;Promise.resolve().then((function(){e.removeCallback&&e.removeCallback()}))}},{key:Symbol.asyncIterator,value:function(){var e=this;return{next:function(){var t=e.pushQueue.shift();return t?(void 0!==e.lowWaterMark&&e.pushQueue.length<=e.lowWaterMark&&e.isPaused&&(e.isPaused=!1,e.eventHandlers.lowWater&&e.eventHandlers.lowWater()),t):e.isStopped?Promise.resolve({value:void 0,done:!0}):new Promise((function(t,n){e.pullQueue.push({resolve:t,reject:n})}))},return:function(){return e.isStopped=!0,e.pushQueue.length=0,e.remove(),Promise.resolve({value:void 0,done:!0})}}}}]),e}(),t=function t(n){"use strict";var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=r.highWaterMark,a=void 0===i?100:i,o=r.lowWaterMark,u=void 0===o?1:o;(0,H.default)(this,t);var s=new e;s.highWaterMark=a,s.lowWaterMark=u,s.removeCallback=n({push:function(e){return s.push(e)},stop:function(){return s.stop()},fail:function(e){return s.fail(e)},on:function(e,t){s.eventHandlers[e]=t}})||function(){},this[Symbol.asyncIterator]=function(){return s[Symbol.asyncIterator]()},Object.freeze(this)};return Mg.EventIterator=t,Mg.default=t,Mg}();return Dg.EventIterator=e.EventIterator,Dg.subscribe=function(t,n,r){var i=this;return new e.EventIterator((function(e){var r=e.push;return i.addEventListener(t,r,n),function(){return i.removeEventListener(t,r,n)}}),r)},Dg.default=e.EventIterator,Dg}();function Og(e){var t;return e instanceof ArrayBuffer||"ArrayBuffer"===(null==e||null===(t=e.constructor)||void 0===t?void 0:t.name)&&"number"==typeof(null==e?void 0:e.byteLength)}var Ug=WebSocket,Fg={"http:":"ws:","https:":"wss:"};function Bg(e,t){t=null!=t?t:{};var n=function(e,t){var n;if(e.startsWith("//")&&(e="".concat(null!==(n=null==t?void 0:t.protocol)&&void 0!==n?n:"ws:").concat(e)),e.startsWith("/")&&null!=t){var r,i=null!==(r=t.protocol)&&void 0!==r?r:"ws:",a=t.host,o=null!=t.port&&!0!==(null==a?void 0:a.endsWith(":"+t.port))?":"+t.port:"";e="".concat(i,"//").concat(a).concat(o).concat(e)}var u=new URL(e),s=!0,l=!1,c=void 0;try{for(var f,d=Object.entries(Fg)[Symbol.iterator]();!(s=(f=d.next()).done);s=!0){var h=(0,se.default)(f.value,2),v=h[0],p=h[1];u.protocol===v&&(u.protocol=p)}}catch(e){l=!0,c=e}finally{try{s||null==d.return||d.return()}finally{if(l)throw c}}return u}(e,"undefined"==typeof window?void 0:window.location);return function(e,t){t=null!=t?t:{};var n=function(e){e.binaryType="arraybuffer";var t,n=function(){var n=(0,K.default)((function(){return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:return[4,new Promise((function(n,r){if(i)n();else if(null==t){var a=function(t){e.removeEventListener("open",o),e.removeEventListener("error",u),t()},o=function(){a(n)},u=function(t){a((function(){var n;r(null!==(n=t.error)&&void 0!==n?n:Error("connect ECONNREFUSED "+e.url))}))};e.addEventListener("open",o),e.addEventListener("error",u)}else r(t)}))];case 1:return n.sent(),[2]}}))}));return function(){return n.apply(this,arguments)}}(),r=(0,de.default)((function(){var t,r,i,a,o,u,s,l,c;return(0,pe.__generator)(this,(function(f){switch(f.label){case 0:return t=new Ng.EventIterator((function(t){var n=t.push,r=t.stop,i=t.fail,a=function(e){var t=null;"string"==typeof e.data&&(t=wn(e.data)),Og(e.data)&&(t=new Uint8Array(e.data)),e.data instanceof Uint8Array&&(t=e.data),null!=t&&n(t)},o=function(e){var t;i(null!==(t=e.error)&&void 0!==t?t:Error("Socket error"))};return e.addEventListener("message",a),e.addEventListener("error",o),e.addEventListener("close",r),function(){e.removeEventListener("message",a),e.removeEventListener("error",o),e.removeEventListener("close",r)}}),{highWaterMark:1/0}),[4,(0,V.default)(n())];case 1:f.sent(),r=!1,i=!1,f.label=2;case 2:f.trys.push([2,8,9,14]),o=(0,j.default)(t),f.label=3;case 3:return[4,(0,V.default)(o.next())];case 4:return(r=!(u=f.sent()).done)?(s=u.value,[4,Og(l=s)?new Uint8Array(l):l]):[3,7];case 5:f.sent(),f.label=6;case 6:return r=!1,[3,3];case 7:return[3,14];case 8:return c=f.sent(),i=!0,a=c,[3,14];case 9:return f.trys.push([9,,12,13]),r&&null!=o.return?[4,o.return()]:[3,11];case 10:f.sent(),f.label=11;case 11:return[3,13];case 12:if(i)throw a;return[7];case 13:return[7];case 14:return[2]}}))}))(),i=1===e.readyState;return e.addEventListener("open",(function(){i=!0,t=null})),e.addEventListener("close",(function(){i=!1,t=null})),e.addEventListener("error",(function(n){var r;i||(t=null!==(r=n.error)&&void 0!==r?r:Error("connect ECONNREFUSED "+e.url))})),Object.assign(r,{connected:n})}(e),r=t.remoteAddress,i=t.remotePort;if(null!=e.url)try{var a=new URL(e.url);r=a.hostname,i=parseInt(a.port,10)}catch(e){}if(null==r||null==i)throw Error("Remote connection did not have address and/or port");return{sink:Lg(e,t),source:n,connected:function(){return(0,K.default)((function(){return(0,pe.__generator)(this,(function(e){switch(e.label){case 0:return[4,n.connected()];case 1:return e.sent(),[2]}}))}))()},close:function(){return(0,K.default)((function(){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return e.readyState!==e.CONNECTING&&e.readyState!==e.OPEN?[3,2]:[4,new Promise((function(t){e.addEventListener("close",(function(){t()})),e.close()}))];case 1:t.sent(),t.label=2;case 2:return[2]}}))}))()},destroy:function(){null!=e.terminate?e.terminate():e.close()},remoteAddress:r,remotePort:i,socket:e}}(new Ug(n.toString(),t.websocket),t)}var qg=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(e,r){var i;return(0,H.default)(this,n),i=t.call(this,e),(0,te.default)((0,q.default)(i),"type",void 0),(0,te.default)((0,q.default)(i),"detail",void 0),i.type=e,i.detail=r,(0,ue.default)(i)}return n}((0,he.default)(Event));function zg(e){return e.filter((function(e){return Lp.exactMatch(e)||Pp.exactMatch(e)}))}function jg(e){return e.filter((function(e){return Lp.exactMatch(e)}))}var Kg=$i,Vg=Symbol.toStringTag,Hg=Ta,Wg=function(){"use strict";function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};(0,H.default)(this,e),(0,te.default)(this,"log",void 0),(0,te.default)(this,"init",void 0),(0,te.default)(this,"logger",void 0),(0,te.default)(this,"metrics",void 0),(0,te.default)(this,"components",void 0),(0,te.default)(this,Kg,!0),(0,te.default)(this,Vg,"@libp2p/websockets"),(0,te.default)(this,Hg,["@libp2p/transport"]),this.log=t.logger.forComponent("libp2p:websockets"),this.logger=t.logger,this.components=t,this.init=n,null!=t.metrics&&(this.metrics={dialerEvents:t.metrics.registerCounterGroup("libp2p_websockets_dialer_events_total",{label:"event",help:"Total count of WebSockets dialer events by type"})})}return(0,$.default)(e,[{key:"dial",value:function(e,t){var n=this;return(0,K.default)((function(){var r,i,a,o;return(0,pe.__generator)(this,(function(u){switch(u.label){case 0:return n.log("dialing %s",e),t=null!=t?t:{},a=function(e,t,n){var r,i=n.logger.forComponent("libp2p:websockets:maconn"),a=n.metrics,o=null!==(r=n.metricPrefix)&&void 0!==r?r:"",u={log:i,sink:function(t){return(0,K.default)((function(){var n;return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,e.sink((0,de.default)((function(){var e,n,r,i,a,o,u,s;return(0,pe.__generator)(this,(function(l){switch(l.label){case 0:e=!1,n=!1,l.label=1;case 1:l.trys.push([1,10,11,16]),i=(0,j.default)(t),l.label=2;case 2:return[4,(0,V.default)(i.next())];case 3:return(e=!(a=l.sent()).done)?(o=a.value,(u=o)instanceof Uint8Array?[4,u]:[3,5]):[3,9];case 4:return l.sent(),[3,7];case 5:return[4,u.subarray()];case 6:l.sent(),l.label=7;case 7:l.label=8;case 8:return e=!1,[3,2];case 9:return[3,16];case 10:return s=l.sent(),n=!0,r=s,[3,16];case 11:return l.trys.push([11,,14,15]),e&&null!=i.return?[4,i.return()]:[3,13];case 12:l.sent(),l.label=13;case 13:return[3,15];case 14:if(n)throw r;return[7];case 15:return[7];case 16:return[2]}}))}))())];case 1:return r.sent(),[3,3];case 2:return"aborted"!==(n=r.sent()).type&&i.error(n),[3,3];case 3:return[2]}}))}))()},source:e.source,remoteAddr:t,timeline:{open:Date.now()},close:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return(0,K.default)((function(){var n,r,a,o,s,l,c;return(0,pe.__generator)(this,(function(f){switch(f.label){case 0:n=this,a=Date.now(),null==t.signal&&(o=AbortSignal.timeout(500),t=(0,oe.default)((0,ae.default)({},t),{signal:o})),s=function(){var e=u.remoteAddr.toOptions(),t=e.host,r=e.port;i("timeout closing stream to %s:%s after %dms, destroying it manually",t,r,Date.now()-a),n.abort(new ea("Socket close timeout"))},null===(r=t.signal)||void 0===r||r.addEventListener("abort",s),f.label=1;case 1:return f.trys.push([1,3,4,5]),[4,e.close()];case 2:return f.sent(),[3,5];case 3:return l=f.sent(),i.error("error closing WebSocket gracefully",l),this.abort(l),[3,5];case 4:return null===(c=t.signal)||void 0===c||c.removeEventListener("abort",s),u.timeline.close=Date.now(),[7];case 5:return[2]}}))})).apply(this)},abort:function(t){var n=u.remoteAddr.toOptions(),r=n.host,s=n.port;i("timeout closing stream to %s:%s due to error",r,s,t),e.destroy(),u.timeline.close=Date.now(),null==a||a.increment((0,te.default)({},o+"error",!0))}};return e.socket.addEventListener("close",(function(){null==a||a.increment((0,te.default)({},o+"close",!0)),null==u.timeline.close&&(u.timeline.close=Date.now())}),{once:!0}),u},[4,n._connect(e,t)];case 1:return i=a.apply(void 0,[u.sent(),e,{logger:n.logger,metrics:null===(r=n.metrics)||void 0===r?void 0:r.dialerEvents}]),n.log("new outbound connection %s",i.remoteAddr),[4,t.upgrader.upgradeOutbound(i,t)];case 2:return o=u.sent(),[2,(n.log("outbound connection %s upgraded",i.remoteAddr),o)]}}))}))()}},{key:"_connect",value:function(e,t){var n=this;return(0,K.default)((function(){var r,i,a,o,u,s,l,c,f;return(0,pe.__generator)(this,(function(d){switch(d.label){case 0:null==t||null===(r=t.signal)||void 0===r||r.throwIfAborted(),a=e.toOptions(),n.log("dialing %s:%s",a.host,a.port),o=Io(),u=Bg(function(e){var t=pf(e).getComponents(),n=t.pop();if(null==n)throw Error("Unexpected end of multiaddr");var r,i=Pg[n.name];if(null==i)throw Error("No interpreter found for "+n.name);var a=null!==(r=i(n,t))&&void 0!==r?r:"";return _g.includes(n.code)&&(a=a.replace(/^.*:\/\//,""),a="443"===n.value?"https://"+a:"http://"+a),(a.startsWith("http://")||a.startsWith("https://")||a.startsWith("ws://")||a.startsWith("wss://"))&&((a=new URL(a).toString()).endsWith("/")&&(a=a.substring(0,a.length-1))),a}(e),n.init),u.socket.addEventListener("error",(function(){var t,r=new ua("Could not connect to "+e.toString());n.log.error("connection error:",r),null===(t=n.metrics)||void 0===t||t.dialerEvents.increment({error:!0}),o.reject(r)})),d.label=1;case 1:return d.trys.push([1,3,,4]),null===(s=t.onProgress)||void 0===s||s.call(t,new qg("websockets:open-connection")),[4,Lo(Promise.race([u.connected(),o.promise]),t.signal)];case 2:return d.sent(),[3,4];case 3:throw l=d.sent(),(null===(c=t.signal)||void 0===c?void 0:c.aborted)&&(null===(f=n.metrics)||void 0===f||f.dialerEvents.increment({abort:!0})),u.close().catch((function(e){n.log.error("error closing raw socket",e)})),l;case 4:return[2,(n.log("connected %s",e),null===(i=n.metrics)||void 0===i||i.dialerEvents.increment({connect:!0}),u)]}}))}))()}},{key:"createListener",value:function(e){return function(){throw Error("WebSocket Servers can not be created in the browser!")}((this.logger,this.components.events,this.components.metrics),this.init)}},{key:"listenFilter",value:function(e){var t,n;return e=Array.isArray(e)?e:[e],null!=(null===(t=this.init)||void 0===t?void 0:t.filter)?null===(n=this.init)||void 0===n?void 0:n.filter(e):zg(e)}},{key:"dialFilter",value:function(e){return this.listenFilter(e)}}]),e}();function Gg(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(t){return new Wg(t,e)}}function Xg(e){if("object"!=typeof e||null===e)return!1;var t=Object.getPrototypeOf(e);return!(null!==t&&t!==Object.prototype&&null!==Object.getPrototypeOf(t)||Symbol.toStringTag in e||Symbol.iterator in e)}var Yg=Object.prototype.hasOwnProperty,Zg=Object.propertyIsEnumerable,Qg=function(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})},Jg={concatArrays:!1,ignoreUndefined:!1},$g=function(e){var t=[];for(var n in e)Yg.call(e,n)&&t.push(n);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e),i=!0,a=!1,o=void 0;try{for(var u,s=r[Symbol.iterator]();!(i=(u=s.next()).done);i=!0){var l=u.value;Zg.call(e,l)&&t.push(l)}}catch(e){a=!0,o=e}finally{try{i||null==s.return||s.return()}finally{if(a)throw o}}}return t};function ey(e){return Array.isArray(e)?function(e){var t=e.slice(0,0);return $g(e).forEach((function(n){Qg(t,n,ey(e[n]))})),t}(e):Xg(e)?function(e){var t=null===Object.getPrototypeOf(e)?Object.create(null):{};return $g(e).forEach((function(n){Qg(t,n,ey(e[n]))})),t}(e):e}var ty=function(e,t,n,r){return n.forEach((function(n){void 0===t[n]&&r.ignoreUndefined||(n in e&&e[n]!==Object.getPrototypeOf(e)?Qg(e,n,ry(e[n],t[n],r)):Qg(e,n,ey(t[n])))})),e},ny=function(e,t,n){var r=e.slice(0,0),i=0;return[e,t].forEach((function(t){for(var a=[],o=0;o<t.length;o++)Yg.call(t,o)&&(a.push(o+""),Qg(r,i++,t===e?t[o]:ey(t[o])));r=ty(r,t,$g(t).filter((function(e){return!a.includes(e)})),n)})),r};function ry(e,t,n){return n.concatArrays&&Array.isArray(e)&&Array.isArray(t)?ny(e,t,n):Xg(t)&&Xg(e)?ty(e,t,$g(t),n):ey(t)}function iy(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];var r=ry(ey(Jg),void 0!==this&&this||{},Jg),i={_:{}},a=!0,o=!1,u=void 0;try{for(var s,l=t[Symbol.iterator]();!(a=(s=l.next()).done);a=!0){var c=s.value;if(void 0!==c){if(!Xg(c))throw new TypeError("`"+c+"` is not an Option Object");i=ry(i,{_:c},r)}}}catch(e){o=!0,u=e}finally{try{a||null==l.return||l.return()}finally{if(o)throw u}}return i._}var ay,oy,uy,sy={exports:{}},ly=(ay||(ay=1,function(e){var t=function(){},n=function(e,t,n){this.fn=e,this.context=t,this.once=n||!1},r=function(e,t,r,i,a){if("function"!=typeof r)throw new TypeError("The listener must be a function");var o=new n(r,i||e,a),s=u?u+t:t;return e._events[s]?e._events[s].fn?e._events[s]=[e._events[s],o]:e._events[s].push(o):(e._events[s]=o,e._eventsCount++),e},i=function(e,n){0==--e._eventsCount?e._events=new t:delete e._events[n]},a=function(){this._events=new t,this._eventsCount=0},o={}.hasOwnProperty,u="~";Object.create&&(t.prototype=Object.create(null),(new t).__proto__||(u=!1)),a.prototype.eventNames=function(){var e,t,n=[];if(0===this._eventsCount)return n;for(t in e=this._events)o.call(e,t)&&n.push(u?t.slice(1):t);return Object.getOwnPropertySymbols?n.concat(Object.getOwnPropertySymbols(e)):n},a.prototype.listeners=function(e){var t=u?u+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var r=0,i=n.length,a=Array(i);r<i;r++)a[r]=n[r].fn;return a},a.prototype.listenerCount=function(e){var t=u?u+e:e,n=this._events[t];return n?n.fn?1:n.length:0},a.prototype.emit=function(e,t,n,r,i,a){var o=u?u+e:e;if(!this._events[o])return!1;var s,l,c=this._events[o],f=arguments.length;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),f){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,n),!0;case 4:return c.fn.call(c.context,t,n,r),!0;case 5:return c.fn.call(c.context,t,n,r,i),!0;case 6:return c.fn.call(c.context,t,n,r,i,a),!0}for(l=1,s=Array(f-1);l<f;l++)s[l-1]=arguments[l];c.fn.apply(c.context,s)}else{var d,h=c.length;for(l=0;l<h;l++)switch(c[l].once&&this.removeListener(e,c[l].fn,void 0,!0),f){case 1:c[l].fn.call(c[l].context);break;case 2:c[l].fn.call(c[l].context,t);break;case 3:c[l].fn.call(c[l].context,t,n);break;case 4:c[l].fn.call(c[l].context,t,n,r);break;default:if(!s)for(d=1,s=Array(f-1);d<f;d++)s[d-1]=arguments[d];c[l].fn.apply(c[l].context,s)}}return!0},a.prototype.on=function(e,t,n){return r(this,e,t,n,!1)},a.prototype.once=function(e,t,n){return r(this,e,t,n,!0)},a.prototype.removeListener=function(e,t,n,r){var a=u?u+e:e;if(!this._events[a])return this;if(!t)return i(this,a),this;var o=this._events[a];if(o.fn)o.fn!==t||r&&!o.once||n&&o.context!==n||i(this,a);else{for(var s=0,l=[],c=o.length;s<c;s++)(o[s].fn!==t||r&&!o[s].once||n&&o[s].context!==n)&&l.push(o[s]);l.length?this._events[a]=1===l.length?l[0]:l:i(this,a)}return this},a.prototype.removeAllListeners=function(e){var n;return e?(n=u?u+e:e,this._events[n]&&i(this,n)):(this._events=new t,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=u,a.EventEmitter=a,e.exports=a}(sy)),sy.exports),cy=La(ly),fy=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(e){var r;return(0,H.default)(this,n),(r=t.call(this,e)).name="TimeoutError",(0,ue.default)(r)}return n}((0,he.default)(Error)),dy=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(e){var r;return(0,H.default)(this,n),(r=t.call(this)).name="AbortError",r.message=e,(0,ue.default)(r)}return n}((0,he.default)(Error)),hy=function(e){return void 0===globalThis.DOMException?new dy(e):new DOMException(e)},vy=function(e){var t=void 0===e.reason?hy("This operation was aborted."):e.reason;return t instanceof Error?t:hy(t)},py=(F=new WeakMap,function(){"use strict";function e(){(0,H.default)(this,e),(0,G.default)(this,F,{writable:!0,value:[]})}return(0,$.default)(e,[{key:"enqueue",value:function(e,t){var n={priority:(t=(0,ae.default)({priority:0},t)).priority,id:t.id,run:e};if(0===this.size||(0,W.default)(this,F)[this.size-1].priority>=t.priority)(0,W.default)(this,F).push(n);else{var r=function(e,t,n){for(var r=0,i=e.length;i>0;){var a=Math.trunc(i/2),o=r+a;n(e[o],t)<=0?(r=++o,i-=a+1):i=a}return r}((0,W.default)(this,F),n,(function(e,t){return t.priority-e.priority}));(0,W.default)(this,F).splice(r,0,n)}}},{key:"setPriority",value:function(e,t){var n=(0,W.default)(this,F).findIndex((function(t){return t.id===e}));if(-1===n)throw new ReferenceError('No promise function with the id "'.concat(e,'" exists in the queue.'));var r=(0,se.default)((0,W.default)(this,F).splice(n,1),1)[0];this.enqueue(r.run,{priority:t,id:e})}},{key:"dequeue",value:function(){var e=(0,W.default)(this,F).shift();return null==e?void 0:e.run}},{key:"filter",value:function(e){return(0,W.default)(this,F).filter((function(t){return t.priority===e.priority})).map((function(e){return e.run}))}},{key:"size",get:function(){return(0,W.default)(this,F).length}}]),e}()),gy=new WeakMap,yy=new WeakMap,my=new WeakMap,by=new WeakMap,wy=new WeakMap,ky=new WeakMap,_y=new WeakMap,Ey=new WeakMap,Sy=new WeakMap,Ay=new WeakMap,Iy=new WeakMap,xy=new WeakMap,Cy=new WeakMap,Ty=new WeakMap,Py=new WeakMap,Ry=new WeakMap,Ly=new WeakMap,Dy=new WeakSet,My=new WeakSet,Ny=new WeakMap,Oy=new WeakSet,Uy=new WeakSet,Fy=new WeakSet,By=new WeakSet,qy=new WeakSet,zy=new WeakSet,jy=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(e){var r,i,a,o,u;if((0,H.default)(this,n),r=t.call(this),(0,G.default)((0,q.default)(r),Ry,{get:Ky,set:void 0}),(0,G.default)((0,q.default)(r),Ly,{get:Vy,set:void 0}),(0,Q.default)((0,q.default)(r),Dy),(0,Q.default)((0,q.default)(r),My),(0,G.default)((0,q.default)(r),Ny,{get:Gy,set:void 0}),(0,Q.default)((0,q.default)(r),Oy),(0,Q.default)((0,q.default)(r),Uy),(0,Q.default)((0,q.default)(r),Fy),(0,Q.default)((0,q.default)(r),By),(0,Q.default)((0,q.default)(r),qy),(0,Q.default)((0,q.default)(r),zy),(0,G.default)((0,q.default)(r),gy,{writable:!0,value:void 0}),(0,G.default)((0,q.default)(r),yy,{writable:!0,value:void 0}),(0,G.default)((0,q.default)(r),my,{writable:!0,value:0}),(0,G.default)((0,q.default)(r),by,{writable:!0,value:void 0}),(0,G.default)((0,q.default)(r),wy,{writable:!0,value:void 0}),(0,G.default)((0,q.default)(r),ky,{writable:!0,value:0}),(0,G.default)((0,q.default)(r),_y,{writable:!0,value:void 0}),(0,G.default)((0,q.default)(r),Ey,{writable:!0,value:void 0}),(0,G.default)((0,q.default)(r),Sy,{writable:!0,value:void 0}),(0,G.default)((0,q.default)(r),Ay,{writable:!0,value:void 0}),(0,G.default)((0,q.default)(r),Iy,{writable:!0,value:0}),(0,G.default)((0,q.default)(r),xy,{writable:!0,value:void 0}),(0,G.default)((0,q.default)(r),Cy,{writable:!0,value:void 0}),(0,G.default)((0,q.default)(r),Ty,{writable:!0,value:void 0}),(0,G.default)((0,q.default)(r),Py,{writable:!0,value:1n}),(0,te.default)((0,q.default)(r),"timeout",void 0),!("number"==typeof(e=(0,ae.default)({carryoverConcurrencyCount:!1,intervalCap:1/0,interval:0,concurrency:1/0,autoStart:!0,queueClass:py},e)).intervalCap&&e.intervalCap>=1))throw new TypeError("Expected `intervalCap` to be a number from 1 and up, got `".concat(null!==(o=null===(i=e.intervalCap)||void 0===i?void 0:i.toString())&&void 0!==o?o:"","` (").concat((0,fe.default)(e.intervalCap),")"));if(void 0===e.interval||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError("Expected `interval` to be a finite number >= 0, got `".concat(null!==(u=null===(a=e.interval)||void 0===a?void 0:a.toString())&&void 0!==u?u:"","` (").concat((0,fe.default)(e.interval),")"));return(0,X.default)((0,q.default)(r),gy,e.carryoverConcurrencyCount),(0,X.default)((0,q.default)(r),yy,e.intervalCap===1/0||0===e.interval),(0,X.default)((0,q.default)(r),by,e.intervalCap),(0,X.default)((0,q.default)(r),wy,e.interval),(0,X.default)((0,q.default)(r),Sy,new e.queueClass),(0,X.default)((0,q.default)(r),Ay,e.queueClass),r.concurrency=e.concurrency,r.timeout=e.timeout,(0,X.default)((0,q.default)(r),Ty,!0===e.throwOnTimeout),(0,X.default)((0,q.default)(r),Cy,!1===e.autoStart),(0,ue.default)(r)}return(0,$.default)(n,[{key:"concurrency",get:function(){return(0,W.default)(this,xy)},set:function(e){if(!("number"==typeof e&&e>=1))throw new TypeError("Expected `concurrency` to be a number from 1 and up, got `".concat(e,"` (").concat(void 0===e?"undefined":(0,fe.default)(e),")"));(0,X.default)(this,xy,e),(0,Z.default)(this,By,Qy).call(this)}},{key:"setPriority",value:function(e,t){(0,W.default)(this,Sy).setPriority(e,t)}},{key:"add",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=this;return(0,K.default)((function(){var r;return(0,pe.__generator)(this,(function(i){return[2,(null!==(r=(u=t).id)&&void 0!==r||(u.id=""+(0,Y.default)(n,Py).value++),t=(0,ae.default)({timeout:n.timeout,throwOnTimeout:(0,W.default)(n,Ty)},t),new Promise((function(r,i){(0,W.default)(n,Sy).enqueue((0,K.default)((function(){var a,o,u,s;return(0,pe.__generator)(this,(function(l){switch(l.label){case 0:(0,Y.default)(n,Iy).value++,(0,Y.default)(n,my).value++,l.label=1;case 1:return l.trys.push([1,3,4,5]),null===(a=t.signal)||void 0===a||a.throwIfAborted(),o=e({signal:t.signal}),t.timeout&&(o=function(e,t){var n,r,i=t.milliseconds,a=t.fallback,o=t.message,u=t.customTimers,s=void 0===u?{setTimeout:setTimeout,clearTimeout:clearTimeout}:u,l=new Promise((function(u,l){if("number"!=typeof i||1!==Math.sign(i))throw new TypeError("Expected `milliseconds` to be a positive number, got `".concat(i,"`"));if(t.signal){var c=t.signal;c.aborted&&l(vy(c)),r=function(){l(vy(c))},c.addEventListener("abort",r,{once:!0})}if(i!==1/0){var f=new fy;n=s.setTimeout.call(void 0,(function(){if(a)try{u(a())}catch(e){l(e)}else"function"==typeof e.cancel&&e.cancel(),!1===o?u():o instanceof Error?l(o):(f.message=null!=o?o:"Promise timed out after ".concat(i," milliseconds"),l(f))}),i),(0,K.default)((function(){var t;return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,e];case 1:return u.apply(void 0,[n.sent()]),[3,3];case 2:return t=n.sent(),l(t),[3,3];case 3:return[2]}}))}))()}else e.then(u,l)})).finally((function(){l.clear(),r&&t.signal&&t.signal.removeEventListener("abort",r)}));return l.clear=function(){s.clearTimeout.call(void 0,n),n=void 0},l}(Promise.resolve(o),{milliseconds:t.timeout})),t.signal&&(o=Promise.race([o,(0,Z.default)(n,qy,Jy).call(n,t.signal)])),[4,o];case 2:return u=l.sent(),r(u),n.emit("completed",u),[3,5];case 3:return(s=l.sent())instanceof fy&&!t.throwOnTimeout?[2,void r()]:(i(s),n.emit("error",s),[3,5]);case 4:return(0,Z.default)(n,Dy,Hy).call(n),[7];case 5:return[2]}}))})),t),n.emit("add"),(0,Z.default)(n,Oy,Xy).call(n)})))]}))}))()}},{key:"addAll",value:function(e,t){var n=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(r){return[2,Promise.all(e.map(function(){var e=(0,K.default)((function(e){return(0,pe.__generator)(this,(function(r){return[2,n.add(e,t)]}))}));return function(t){return e.apply(this,arguments)}}()))]}))}))()}},{key:"start",value:function(){return(0,W.default)(this,Cy)?((0,X.default)(this,Cy,!1),(0,Z.default)(this,By,Qy).call(this),this):this}},{key:"pause",value:function(){(0,X.default)(this,Cy,!0)}},{key:"clear",value:function(){(0,X.default)(this,Sy,new((0,W.default)(this,Ay)))}},{key:"onEmpty",value:function(){var e=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return 0!==(0,W.default)(e,Sy).size?[4,(0,Z.default)(e,zy,em).call(e,"empty")]:[3,2];case 1:t.sent(),t.label=2;case 2:return[2]}}))}))()}},{key:"onSizeLessThan",value:function(e){var t=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:return(0,W.default)(t,Sy).size<e?[3,2]:[4,(0,Z.default)(t,zy,em).call(t,"next",(function(){return(0,W.default)(t,Sy).size<e}))];case 1:n.sent(),n.label=2;case 2:return[2]}}))}))()}},{key:"onIdle",value:function(){var e=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return 0===(0,W.default)(e,Iy)&&0===(0,W.default)(e,Sy).size?[3,2]:[4,(0,Z.default)(e,zy,em).call(e,"idle")];case 1:t.sent(),t.label=2;case 2:return[2]}}))}))()}},{key:"size",get:function(){return(0,W.default)(this,Sy).size}},{key:"sizeBy",value:function(e){return(0,W.default)(this,Sy).filter(e).length}},{key:"pending",get:function(){return(0,W.default)(this,Iy)}},{key:"isPaused",get:function(){return(0,W.default)(this,Cy)}}]),n}(cy);function Ky(){return(0,W.default)(this,yy)||(0,W.default)(this,my)<(0,W.default)(this,by)}function Vy(){return(0,W.default)(this,Iy)<(0,W.default)(this,xy)}function Hy(){(0,Y.default)(this,Iy).value--,(0,Z.default)(this,Oy,Xy).call(this),this.emit("next")}function Wy(){(0,Z.default)(this,Fy,Zy).call(this),(0,Z.default)(this,Uy,Yy).call(this),(0,X.default)(this,Ey,void 0)}function Gy(){var e=this,t=Date.now();if(void 0===(0,W.default)(this,_y)){var n=(0,W.default)(this,ky)-t;if(!(n<0))return void 0===(0,W.default)(this,Ey)&&(0,X.default)(this,Ey,setTimeout((function(){(0,Z.default)(e,My,Wy).call(e)}),n)),!0;(0,X.default)(this,my,(0,W.default)(this,gy)?(0,W.default)(this,Iy):0)}return!1}function Xy(){if(0===(0,W.default)(this,Sy).size)return(0,W.default)(this,_y)&&clearInterval((0,W.default)(this,_y)),(0,X.default)(this,_y,void 0),this.emit("empty"),0===(0,W.default)(this,Iy)&&this.emit("idle"),!1;if(!(0,W.default)(this,Cy)){var e=!(0,W.default)(this,Ny);if((0,W.default)(this,Ry)&&(0,W.default)(this,Ly)){var t=(0,W.default)(this,Sy).dequeue();return!!t&&(this.emit("active"),t(),e&&(0,Z.default)(this,Uy,Yy).call(this),!0)}}return!1}function Yy(){var e=this;(0,W.default)(this,yy)||void 0!==(0,W.default)(this,_y)||((0,X.default)(this,_y,setInterval((function(){(0,Z.default)(e,Fy,Zy).call(e)}),(0,W.default)(this,wy))),(0,X.default)(this,ky,Date.now()+(0,W.default)(this,wy)))}function Zy(){0===(0,W.default)(this,my)&&0===(0,W.default)(this,Iy)&&(0,W.default)(this,_y)&&(clearInterval((0,W.default)(this,_y)),(0,X.default)(this,_y,void 0)),(0,X.default)(this,my,(0,W.default)(this,gy)?(0,W.default)(this,Iy):0),(0,Z.default)(this,By,Qy).call(this)}function Qy(){for(;(0,Z.default)(this,Oy,Xy).call(this););}function Jy(e){return $y.apply(this,arguments)}function $y(){return $y=(0,K.default)((function(e){return(0,pe.__generator)(this,(function(t){return[2,new Promise((function(t,n){e.addEventListener("abort",(function(){n(e.reason)}),{once:!0})}))]}))})),$y.apply(this,arguments)}function em(e,t){return tm.apply(this,arguments)}function tm(){return tm=(0,K.default)((function(e,t){var n;return(0,pe.__generator)(this,(function(r){return n=this,[2,new Promise((function(r){var i=function(){t&&!t()||(n.off(e,i),r())};n.on(e,i)}))]}))})),tm.apply(this,arguments)}function nm(e){var t=[am.A];return null==e?t:Array.isArray(e)?0===e.length?t:e:[e]}function rm(e){var t,n,r,i,a,o,u,s,l,c,f,d,h,v,p,g,y;return{Status:null!==(t=e.Status)&&void 0!==t?t:0,TC:null!==(r=null!==(n=e.TC)&&void 0!==n?n:e.flag_tc)&&void 0!==r&&r,RD:null!==(a=null!==(i=e.RD)&&void 0!==i?i:e.flag_rd)&&void 0!==a&&a,RA:null!==(u=null!==(o=e.RA)&&void 0!==o?o:e.flag_ra)&&void 0!==u&&u,AD:null!==(l=null!==(s=e.AD)&&void 0!==s?s:e.flag_ad)&&void 0!==l&&l,CD:null!==(f=null!==(c=e.CD)&&void 0!==c?c:e.flag_cd)&&void 0!==f&&f,Question:(null!==(h=null!==(d=e.Question)&&void 0!==d?d:e.questions)&&void 0!==h?h:[]).map((function(e){return{name:e.name,type:am[e.type]}})),Answer:(null!==(p=null!==(v=e.Answer)&&void 0!==v?v:e.answers)&&void 0!==p?p:[]).map((function(e){return{name:e.name,type:am[e.type],TTL:null!==(y=null!==(g=e.TTL)&&void 0!==g?g:e.ttl)&&void 0!==y?y:60,data:e.data instanceof Uint8Array?Ti(e.data):e.data}}))}}function im(e){var t,n=new jy({concurrency:null!==(t=(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}).queryConcurrency)&&void 0!==t?t:4});return function(){var t=(0,K.default)((function(t){var r,i,a,o,u=arguments;return(0,pe.__generator)(this,(function(s){switch(s.label){case 0:return r=u.length>1&&void 0!==u[1]?u[1]:{},(a=new URLSearchParams).set("name",t),nm(r.types).forEach((function(e){a.append("type",am[e])})),null===(i=r.onProgress)||void 0===i||i.call(r,new qg("dns:query",{detail:t})),[4,n.add((0,K.default)((function(){var t,n,i;return(0,pe.__generator)(this,(function(o){switch(o.label){case 0:return[4,fetch("".concat(e,"?").concat(a),{headers:{accept:"application/dns-json"},signal:null==r?void 0:r.signal})];case 1:if(200!==(n=o.sent()).status)throw Error("Unexpected HTTP status: ".concat(n.status," - ").concat(n.statusText));return[4,n.json()];case 2:return i=rm.apply(void 0,[o.sent()]),[2,(null===(t=r.onProgress)||void 0===t||t.call(r,new qg("dns:response",{detail:i})),i)]}}))})),{signal:r.signal})];case 1:if(null==(o=s.sent()))throw Error("No DNS response received");return[2,o]}}))}));return function(e){return t.apply(this,arguments)}}()}var am,om=(uy||(uy=1,oy=function(e){var t=function(t,a){r[t]=a,++n>=e&&(n=0,i=r,r=Object.create(null))};if(!e)throw Error("hashlru must have a max value, of type number, greater than 0");var n=0,r=Object.create(null),i=Object.create(null);return{has:function(e){return void 0!==r[e]||void 0!==i[e]},remove:function(e){void 0!==r[e]&&(r[e]=void 0),void 0!==i[e]&&(i[e]=void 0)},get:function(e){var n=r[e];return void 0!==n?n:void 0!==(n=i[e])?(t(e,n),n):void 0},set:function(e,n){void 0!==r[e]?r[e]=n:t(e,n)},clear:function(){r=Object.create(null),i=Object.create(null)}}}),oy),um=La(om),sm=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"lru",void 0),this.lru=um(t)}return(0,$.default)(e,[{key:"get",value:function(e,t){var n=!0,r=[],i=!0,a=!1,o=void 0;try{for(var u,s=t[Symbol.iterator]();!(i=(u=s.next()).done);i=!0){var l,c=u.value,f=this.getAnswers(e,c);if(0===f.length){n=!1;break}(l=r).push.apply(l,(0,ce.default)(f))}}catch(e){a=!0,o=e}finally{try{i||null==s.return||s.return()}finally{if(a)throw o}}if(n)return rm({answers:r})}},{key:"getAnswers",value:function(e,t){var n="".concat(e.toLowerCase(),"-").concat(t),r=this.lru.get(n);if(null!=r){var i=r.filter((function(e){return e.expires>Date.now()})).map((function(e){var t=e.expires,n=e.value;return(0,oe.default)((0,ae.default)({},n),{TTL:Math.round((t-Date.now())/1e3),type:am[n.type]})}));return 0===i.length&&this.lru.remove(n),i}return[]}},{key:"add",value:function(e,t){var n,r,i="".concat(e.toLowerCase(),"-").concat(t.type),a=null!==(n=this.lru.get(i))&&void 0!==n?n:[];a.push({expires:Date.now()+1e3*(null!==(r=t.TTL)&&void 0!==r?r:60),value:t}),this.lru.set(i,a)}},{key:"remove",value:function(e,t){var n="".concat(e.toLowerCase(),"-").concat(t);this.lru.remove(n)}},{key:"clear",value:function(){this.lru.clear()}}]),e}(),lm=function(){"use strict";function e(t){var n,r,i,a=this;(0,H.default)(this,e),(0,te.default)(this,"resolvers",void 0),(0,te.default)(this,"cache",void 0),this.resolvers={},this.cache=(n=null!==(r=t.cacheSize)&&void 0!==r?r:1e3,new sm(n)),Object.entries(null!==(i=t.resolvers)&&void 0!==i?i:{}).forEach((function(e){var t=(0,se.default)(e,2),n=t[0],r=t[1];Array.isArray(r)||(r=[r]),n.endsWith(".")||(n+="."),a.resolvers[n]=r})),null==this.resolvers["."]&&(this.resolvers["."]=[im("https://cloudflare-dns.com/dns-query"),im("https://dns.google/resolve")])}return(0,$.default)(e,[{key:"query",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=this;return(0,K.default)((function(){var r,i,a,o,u,s,l,c,f,d,h,v,p,g,y,m,b,w,k,_,E,S,A,I;return(0,pe.__generator)(this,(function(x){switch(x.label){case 0:if(i=nm(t.types),null!=(a=!1!==t.cached?n.cache.get(e,i):void 0))return[2,(null===(r=t.onProgress)||void 0===r||r.call(t,new qg("dns:cache",{detail:a})),a)];u=e.split(".").pop()+".",s=(null!==(o=n.resolvers[u])&&void 0!==o?o:n.resolvers["."]).sort((function(){return Math.random()>.5?-1:1})),l=[],c=!0,f=!1,d=void 0,x.label=1;case 1:x.trys.push([1,8,9,10]),h=s[Symbol.iterator](),x.label=2;case 2:if(c=(v=h.next()).done)return[3,7];if(p=v.value,!0===(null===(g=t.signal)||void 0===g?void 0:g.aborted))return[3,7];x.label=3;case 3:return x.trys.push([3,5,,6]),[4,p(e,(0,oe.default)((0,ae.default)({},t),{types:i}))];case 4:y=x.sent(),m=!0,b=!1,w=void 0;try{for(k=y.Answer[Symbol.iterator]();!(m=(_=k.next()).done);m=!0)E=_.value,n.cache.add(e,E)}catch(e){b=!0,w=e}finally{try{m||null==k.return||k.return()}finally{if(b)throw w}}return[2,y];case 5:return S=x.sent(),l.push(S),null===(A=t.onProgress)||void 0===A||A.call(t,new qg("dns:error",{detail:S})),[3,6];case 6:return c=!0,[3,2];case 7:return[3,10];case 8:return I=x.sent(),f=!0,d=I,[3,10];case 9:try{c||null==h.return||h.return()}finally{if(f)throw d}return[7];case 10:if(1===l.length)throw l[0];throw new AggregateError(l,"DNS lookup of ".concat(e," ").concat(i," failed"))}}))}))()}}]),e}();!function(e){e[e.A=1]="A",e[e.CNAME=5]="CNAME",e[e.TXT=16]="TXT",e[e.AAAA=28]="AAAA"}(am||(am={}));var cm=-1,fm={},dm={};[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,cm,"ip6zone"],[43,8,"ipcidr"],[53,cm,"dns",!0],[54,cm,"dns4",!0],[55,cm,"dns6",!0],[56,cm,"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,cm,"unix",!1,!0],[421,cm,"ipfs"],[421,cm,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,cm,"garlic64"],[448,0,"tls"],[449,cm,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,cm,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,cm,"http-path"],[777,cm,"memory"]].forEach((function(e){var t=function(e,t,n,r,i){return{code:e,size:t,name:n,resolvable:!!r,path:!!i}}.apply(undefined,(0,ce.default)(e));dm[t.code]=t,fm[t.name]=t}));var hm=function(e){if(null!=fm[e])return fm[e];throw Error("no protocol with name: "+e)}("dnsaddr"),vm=hm.code,pm=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Max recursive depth reached";return(0,H.default)(this,n),(e=t.call(this,r)).name="RecursionLimitError",(0,ue.default)(e)}return n}((0,he.default)(Error)),gm=function(){var e=(0,K.default)((function(e){var t,n,r,i,a,o,u,s,l,c,f,d,h,v,p,g,y,m,b,w,k,_,E=arguments;return(0,pe.__generator)(this,(function(S){switch(S.label){case 0:if(0===(r=null!==(n=(t=E.length>1&&void 0!==E[1]?E[1]:{}).maxRecursiveDepth)&&void 0!==n?n:32))throw new pm("Max recursive depth reached");return o=(0,se.default)(null!==(i=e.stringTuples().find((function(e){return(0,se.default)(e,1)[0]===vm})))&&void 0!==i?i:[],2),u=o[1],s=null!==(a=null==t?void 0:t.dns)&&void 0!==a?a:function(){return new lm(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{})}(),[4,s.query("_dnsaddr."+u,{signal:null==t?void 0:t.signal,types:[am.TXT]})];case 1:l=S.sent(),c=e.getPeerId(),f=[],d=!0,h=!1,v=void 0,S.label=2;case 2:S.trys.push([2,8,9,10]),p=l.Answer[Symbol.iterator](),S.label=3;case 3:return(d=(g=p.next()).done)?[3,7]:(y=g.value,null==(m=y.data.replace(/["']/g,"").trim().split("=")[1])?[3,6]:null==c||m.includes(c)?(b=pf(m),m.startsWith("/dnsaddr")?[4,b.resolve((0,oe.default)((0,ae.default)({},t),{maxRecursiveDepth:r-1}))]:[3,5]):[3,6]);case 4:return k=S.sent(),(w=f).push.apply(w,(0,ce.default)(k.map((function(e){return e.toString()})))),[3,6];case 5:f.push(b.toString()),S.label=6;case 6:return d=!0,[3,3];case 7:return[3,10];case 8:return _=S.sent(),h=!0,v=_,[3,10];case 9:try{d||null==p.return||p.return()}finally{if(h)throw v}return[7];case 10:return[2,f]}}))}));return function(t){return e.apply(this,arguments)}}(),ym={addresses:{listen:[],announce:[],noAnnounce:[],announceFilter:function(e){return e}},connectionManager:{resolvers:{dnsaddr:gm}},transportManager:{faultTolerance:Zi.FATAL_ALL}};function mm(e){return bm.apply(this,arguments)}function bm(){return bm=(0,K.default)((function(e){var t,n,r;return(0,pe.__generator)(this,(function(i){if(null===(r=iy(ym,e)).connectionProtector&&null!=(null===(t=globalThis.process)||void 0===t||null===(n=t.env)||void 0===n?void 0:n.LIBP2P_FORCE_PNET))throw new ra("Private network is enforced, but no protector was provided");return[2,r]}))})),bm.apply(this,arguments)}var wm=1e3,km=6e4,_m=36e5,Em=864e5;function Sm(e,t){try{if("string"==typeof e&&e.length>0)return function(e){if((e+="").length>100)throw Error("Value exceeds the maximum length of 100 characters.");var t=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(!t)return NaN;var n=parseFloat(t[1]),r=(t[2]||"ms").toLowerCase();switch(r){case"years":case"year":case"yrs":case"yr":case"y":return 315576e5*n;case"weeks":case"week":case"w":return 6048e5*n;case"days":case"day":case"d":return n*Em;case"hours":case"hour":case"hrs":case"hr":case"h":return n*_m;case"minutes":case"minute":case"mins":case"min":case"m":return n*km;case"seconds":case"second":case"secs":case"sec":case"s":return n*wm;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return n;default:throw Error("The unit ".concat(r," was matched, but no matching case exists."))}}(e);if("number"==typeof e&&isFinite(e))return(null==t?void 0:t.long)?function(e){var t=Math.abs(e);return t>=Em?Am(e,t,Em,"day"):t>=_m?Am(e,t,_m,"hour"):t>=km?Am(e,t,km,"minute"):t>=wm?Am(e,t,wm,"second"):e+" ms"}(e):function(e){var t=Math.abs(e);return t>=Em?Math.round(e/Em)+"d":t>=_m?Math.round(e/_m)+"h":t>=km?Math.round(e/km)+"m":t>=wm?Math.round(e/wm)+"s":e+"ms"}(e);throw Error("Value is not a string or number.")}catch(t){var n=function(e){return"object"==typeof e&&null!==e&&"message"in e}(t)?"".concat(t.message,". value=").concat(JSON.stringify(e)):"An unknown error has occured.";throw Error(n)}}function Am(e,t,n,r){var i=t>=1.5*n;return"".concat(Math.round(e/n)," ").concat(r).concat(i?"s":"")}var Im,xm,Cm,Tm,Pm=function(){try{return localStorage}catch(e){}}(),Rm=null!==(xm=null!==(Im=console.debug)&&void 0!==Im?Im:console.log)&&void 0!==xm?xm:function(){},Lm=function(e){var t=function(e,t){var n=r(this.namespace+(void 0===t?":":t)+e);return n.log=this.log,n},n=function(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")};function r(e){var n,i,a,o=null;function u(){for(var e=arguments.length,t=new Array(e),i=0;i<e;i++)t[i]=arguments[i];if(u.enabled){var a=u,o=Number(new Date),s=o-(n||o);a.diff=s,a.prev=n,a.curr=o,n=o,t[0]=r.coerce(t[0]),"string"!=typeof t[0]&&t.unshift("%O");var l=0;t[0]=t[0].replace(/%([a-zA-Z%])/g,(function(e,n){if("%%"===e)return"%";l++;var i=r.formatters[n];if("function"==typeof i){var o=t[l];e=i.call(a,o),t.splice(l,1),l--}return e})),r.formatArgs.call(a,t),(a.log||r.log).apply(a,t)}}return u.namespace=e,u.useColors=r.useColors(),u.color=r.selectColor(e),u.extend=t,u.destroy=r.destroy,Object.defineProperty(u,"enabled",{enumerable:!0,configurable:!1,get:function(){return null!==o?o:(i!==r.namespaces&&(i=r.namespaces,a=r.enabled(e)),a)},set:function(e){o=e}}),"function"==typeof r.init&&r.init(u),u}return r.debug=r,r.default=r,r.coerce=function(e){var t;return e instanceof Error?null!==(t=e.stack)&&void 0!==t?t:e.message:e},r.disable=function(){var e=(0,ce.default)(r.names.map(n)).concat((0,ce.default)(r.skips.map(n).map((function(e){return"-"+e})))).join(",");return r.enable(""),e},r.enable=function(e){var t;r.save(e),r.namespaces=e,r.names=[],r.skips=[];var n=("string"==typeof e?e:"").split(/[\s,]+/),i=n.length;for(t=0;t<i;t++)n[t]&&("-"===(e=n[t].replace(/\*/g,".*?"))[0]?r.skips.push(RegExp("^"+e.substr(1)+"$")):r.names.push(RegExp("^"+e+"$")))},r.enabled=function(e){if("*"===e[e.length-1])return!0;var t,n;for(t=0,n=r.skips.length;t<n;t++)if(r.skips[t].test(e))return!1;for(t=0,n=r.names.length;t<n;t++)if(r.names[t].test(e))return!0;return!1},r.humanize=Sm,r.destroy=function(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")},Object.keys(e).forEach((function(t){r[t]=e[t]})),r.names=[],r.skips=[],r.formatters={},r.selectColor=function(e){for(var t=0,n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n),t|=0;return r.colors[Math.abs(t)%r.colors.length]},r.setupFormatters(r.formatters),r.enable(r.load()),r}({formatArgs:function(e){if(e[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+e[0]+(this.useColors?"%c ":" ")+"+"+Sm(this.diff),this.useColors){var t="color: "+this.color;e.splice(1,0,t,"color: inherit");var n=0,r=0;e[0].replace(/%[a-zA-Z%]/g,(function(e){"%%"!==e&&(n++,"%c"===e&&(r=n))})),e.splice(r,0,t)}},save:function(e){try{e?null==Pm||Pm.setItem("debug",e):null==Pm||Pm.removeItem("debug")}catch(e){}},load:function(){var e;try{e=null==Pm?void 0:Pm.getItem("debug")}catch(e){}return!e&&void 0!==globalThis.process&&"env"in globalThis.process&&(e=globalThis.process.env.DEBUG),e},useColors:function(){var e,t,n,r,i;return!("undefined"==typeof window||!window.process||"renderer"!==window.process.type&&!window.process.__nwjs)||("undefined"==typeof navigator||null==(null===(e=navigator.userAgent)||void 0===e?void 0:e.toLowerCase().match(/(edge|trident)\/(\d+)/)))&&("undefined"!=typeof document&&(null===(t=document.documentElement)||void 0===t||null===(n=t.style)||void 0===n?void 0:n.WebkitAppearance)||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&null!=(null===(r=navigator.userAgent)||void 0===r?void 0:r.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&(null===(i=navigator.userAgent)||void 0===i?void 0:i.toLowerCase().match(/applewebkit\/(\d+)/)))},setupFormatters:function(e){e.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}},colors:["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],storage:Pm,log:Rm});function Dm(){return{forComponent:function(e){return Mm(e)}}}function Mm(e){var t=function(e){var t=function(){};return t.enabled=!1,t.color="",t.diff=0,t.log=function(){},t.namespace=e,t.destroy=function(){return!0},t.extend=function(){return t},t}(e+":trace");return Lm.enabled(e+":trace")&&null!=Lm.names.map((function(e){return e.toString()})).find((function(e){return e.includes(":trace")}))&&(t=Lm(e+":trace")),Object.assign(Lm(e),{error:Lm(e+":error"),trace:t,newScope:function(t){return Mm("".concat(e,":").concat(t))}})}function Nm(e){if(null!=e&&0!==(e=e.trim()).length)return e}function Om(e,t){var n,r=(n={},(0,te.default)(n,Symbol.iterator,(function(){return r})),(0,te.default)(n,"next",(function(){var n=e.next(),r=n.value;return!0===n.done||null==r?{done:!0,value:void 0}:{done:!1,value:t(r)}})),n);return r}function Um(e){return Ec(Zt(xt.decode("z"+e)))}Lm.formatters.b=function(e){return null==e?"undefined":xt.baseEncode(e)},Lm.formatters.t=function(e){return null==e?"undefined":vt.baseEncode(e)},Lm.formatters.m=function(e){return null==e?"undefined":Pt.baseEncode(e)},Lm.formatters.p=function(e){return null==e?"undefined":e.toString()},Lm.formatters.c=function(e){return null==e?"undefined":e.toString()},Lm.formatters.k=function(e){return null==e?"undefined":e.toString()},Lm.formatters.a=function(e){return null==e?"undefined":e.toString()},Lm.formatters.e=function(e){return null==e?"undefined":null!==(Tm=null!==(Cm=Nm(e.stack))&&void 0!==Cm?Cm:Nm(e.message))&&void 0!==Tm?Tm:e.toString()};var Fm=Symbol.iterator,Bm=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"map",void 0);var n=!0,r=!1,i=void 0;if(this.map=new Map,null!=t)try{for(var a,o=t.entries()[Symbol.iterator]();!(n=(a=o.next()).done);n=!0){var u=(0,se.default)(a.value,2),s=u[0],l=u[1];this.map.set(s.toString(),{key:s,value:l})}}catch(e){r=!0,i=e}finally{try{n||null==o.return||o.return()}finally{if(r)throw i}}}return(0,$.default)(e,[{key:Fm,value:function(){return this.entries()}},{key:"clear",value:function(){this.map.clear()}},{key:"delete",value:function(e){return this.map.delete(e.toString())}},{key:"entries",value:function(){return Om(this.map.entries(),(function(e){return[e[1].key,e[1].value]}))}},{key:"forEach",value:function(e){var t=this;this.map.forEach((function(n){e(n.value,n.key,t)}))}},{key:"get",value:function(e){var t;return null===(t=this.map.get(e.toString()))||void 0===t?void 0:t.value}},{key:"has",value:function(e){return this.map.has(e.toString())}},{key:"set",value:function(e,t){this.map.set(e.toString(),{key:e,value:t})}},{key:"keys",value:function(){return Om(this.map.values(),(function(e){return e.key}))}},{key:"values",value:function(){return Om(this.map.values(),(function(e){return e.value}))}},{key:"size",get:function(){return this.map.size}}]),e}(),qm=Symbol.iterator,zm=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"set",void 0);var n=!0,r=!1,i=void 0;if(this.set=new Set,null!=t)try{for(var a,o=t[Symbol.iterator]();!(n=(a=o.next()).done);n=!0){var u=a.value;this.set.add(u.toString())}}catch(e){r=!0,i=e}finally{try{n||null==o.return||o.return()}finally{if(r)throw i}}}return(0,$.default)(e,[{key:"size",get:function(){return this.set.size}},{key:qm,value:function(){return this.values()}},{key:"add",value:function(e){this.set.add(e.toString())}},{key:"clear",value:function(){this.set.clear()}},{key:"delete",value:function(e){this.set.delete(e.toString())}},{key:"entries",value:function(){return Om(this.set.entries(),(function(e){var t=Um(e[0]);return[t,t]}))}},{key:"forEach",value:function(e){var t=this;this.set.forEach((function(n){var r=Um(n);e(r,r,t)}))}},{key:"has",value:function(e){return this.set.has(e.toString())}},{key:"values",value:function(){return Om(this.set.values(),(function(e){return Um(e)}))}},{key:"intersection",value:function(t){var n=new e,r=!0,i=!1,a=void 0;try{for(var o,u=t[Symbol.iterator]();!(r=(o=u.next()).done);r=!0){var s=o.value;this.has(s)&&n.add(s)}}catch(e){i=!0,a=e}finally{try{r||null==u.return||u.return()}finally{if(i)throw a}}return n}},{key:"difference",value:function(t){var n=new e,r=!0,i=!1,a=void 0;try{for(var o,u=this[Symbol.iterator]();!(r=(o=u.next()).done);r=!0){var s=o.value;t.has(s)||n.add(s)}}catch(e){i=!0,a=e}finally{try{r||null==u.return||u.return()}finally{if(i)throw a}}return n}},{key:"union",value:function(t){var n=new e,r=!0,i=!1,a=void 0;try{for(var o,u=t[Symbol.iterator]();!(r=(o=u.next()).done);r=!0){var s=o.value;n.add(s)}}catch(e){i=!0,a=e}finally{try{r||null==u.return||u.return()}finally{if(i)throw a}}var l=!0,c=!1,f=void 0;try{for(var d,h=this[Symbol.iterator]();!(l=(d=h.next()).done);l=!0){var v=d.value;n.add(v)}}catch(e){c=!0,f=e}finally{try{l||null==h.return||h.return()}finally{if(c)throw f}}return n}}]),e}(),jm={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},Km={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},Vm=new globalThis.TextEncoder;var Hm={hash:function(e){return Number(function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.size,r=void 0===n?32:n,i=t.utf8Buffer;if(!jm[r])throw Error("The `size` option must be one of 32, 64, 128, 256, 512, or 1024");if("string"==typeof e){if(i)return function(e,t,n){if(0===n.length)throw Error("The `utf8Buffer` option must have a length greater than zero");for(var r=jm[t],i=Km[t],a=e;a.length>0;){var o=Vm.encodeInto(a,n);a=a.slice(o.read);for(var u=0;u<o.written;u++)i^=BigInt(n[u]),i=BigInt.asUintN(t,i*r)}return i}(e,r,i);e=Vm.encode(e)}return function(e,t){for(var n=jm[t],r=Km[t],i=0;i<e.length;i++)r^=BigInt(e[i]),r=BigInt.asUintN(t,r*n);return r}(e,r)}(e,{size:32}))},hashV:function(e,t){return function(e){var t=e.toString(16);return t.length%2==1&&(t="0"+t),wn(t,"base16")}(Hm.hash(e,t))}},Wm=function(){"use strict";function e(t,n,r){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:2;if((0,H.default)(this,e),(0,te.default)(this,"fp",void 0),(0,te.default)(this,"h",void 0),(0,te.default)(this,"seed",void 0),i>64)throw new TypeError("Invalid Fingerprint Size");for(var a=n.hashV(t,r),o=ye(i),u=0;u<o.length;u++)o[u]=a[u];0===o.length&&(o[0]=7),this.fp=o,this.h=n,this.seed=r}return(0,$.default)(e,[{key:"hash",value:function(){return this.h.hash(this.fp,this.seed)}},{key:"equals",value:function(e){return(null==e?void 0:e.fp)instanceof Uint8Array&&so(this.fp,e.fp)}}]),e}();function Gm(e,t){return Math.floor(Math.random()*(t-e))+e}var Xm=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"contents",void 0),this.contents=Array(t).fill(null)}return(0,$.default)(e,[{key:"has",value:function(e){if(!(e instanceof Wm))throw new TypeError("Invalid Fingerprint");return this.contents.some((function(t){return e.equals(t)}))}},{key:"add",value:function(e){if(!(e instanceof Wm))throw new TypeError("Invalid Fingerprint");for(var t=0;t<this.contents.length;t++)if(null==this.contents[t])return this.contents[t]=e,!0;return!0}},{key:"swap",value:function(e){if(!(e instanceof Wm))throw new TypeError("Invalid Fingerprint");var t=Gm(0,this.contents.length-1),n=this.contents[t];return this.contents[t]=e,n}},{key:"remove",value:function(e){if(!(e instanceof Wm))throw new TypeError("Invalid Fingerprint");var t=this.contents.findIndex((function(t){return e.equals(t)}));return t>-1&&(this.contents[t]=null,!0)}}]),e}(),Ym=function(){"use strict";function e(t){var n,r,i,a;(0,H.default)(this,e),(0,te.default)(this,"bucketSize",void 0),(0,te.default)(this,"filterSize",void 0),(0,te.default)(this,"fingerprintSize",void 0),(0,te.default)(this,"buckets",void 0),(0,te.default)(this,"count",void 0),(0,te.default)(this,"hash",void 0),(0,te.default)(this,"seed",void 0),this.filterSize=t.filterSize,this.bucketSize=null!==(n=t.bucketSize)&&void 0!==n?n:4,this.fingerprintSize=null!==(r=t.fingerprintSize)&&void 0!==r?r:2,this.count=0,this.buckets=[],this.hash=null!==(i=t.hash)&&void 0!==i?i:Hm,this.seed=null!==(a=t.seed)&&void 0!==a?a:Gm(0,1024)}return(0,$.default)(e,[{key:"add",value:function(e){"string"==typeof e&&(e=wn(e));var t=new Wm(e,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(e,this.seed)%this.filterSize,r=(n^t.hash())%this.filterSize;if(null==this.buckets[n]&&(this.buckets[n]=new Xm(this.bucketSize)),null==this.buckets[r]&&(this.buckets[r]=new Xm(this.bucketSize)),this.buckets[n].add(t)||this.buckets[r].add(t))return this.count++,!0;var i=[n,r],a=i[Gm(0,i.length-1)];null==this.buckets[a]&&(this.buckets[a]=new Xm(this.bucketSize));for(var o=0;o<500;o++){var u=this.buckets[a].swap(t);if(null!=u&&(a=(a^u.hash())%this.filterSize,null==this.buckets[a]&&(this.buckets[a]=new Xm(this.bucketSize)),this.buckets[a].add(u)))return this.count++,!0}return!1}},{key:"has",value:function(e){var t,n,r;"string"==typeof e&&(e=wn(e));var i=new Wm(e,this.hash,this.seed,this.fingerprintSize),a=this.hash.hash(e,this.seed)%this.filterSize,o=null!==(r=null===(t=this.buckets[a])||void 0===t?void 0:t.has(i))&&void 0!==r&&r;if(o)return o;var u,s=(a^i.hash())%this.filterSize;return null!==(u=null===(n=this.buckets[s])||void 0===n?void 0:n.has(i))&&void 0!==u&&u}},{key:"remove",value:function(e){var t,n,r;"string"==typeof e&&(e=wn(e));var i,a=new Wm(e,this.hash,this.seed,this.fingerprintSize),o=this.hash.hash(e,this.seed)%this.filterSize,u=null!==(r=null===(t=this.buckets[o])||void 0===t?void 0:t.remove(a))&&void 0!==r&&r;if(u)return this.count--,u;var s=(o^a.hash())%this.filterSize,l=null!==(i=null===(n=this.buckets[s])||void 0===n?void 0:n.remove(a))&&void 0!==i&&i;return l&&this.count--,l}},{key:"reliable",get:function(){return Math.floor(this.count/this.filterSize*100)<=90}}]),e}(),Zm={1:.5,2:.84,4:.95,8:.98};var Qm=function(){"use strict";function e(t){var n,r,i,a,o,u;(0,H.default)(this,e),(0,te.default)(this,"filterSize",void 0),(0,te.default)(this,"bucketSize",void 0),(0,te.default)(this,"fingerprintSize",void 0),(0,te.default)(this,"scale",void 0),(0,te.default)(this,"filterSeries",void 0),(0,te.default)(this,"hash",void 0),(0,te.default)(this,"seed",void 0),this.bucketSize=null!==(n=t.bucketSize)&&void 0!==n?n:4,this.filterSize=null!==(r=t.filterSize)&&void 0!==r?r:262144/this.bucketSize,this.fingerprintSize=null!==(i=t.fingerprintSize)&&void 0!==i?i:2,this.scale=null!==(a=t.scale)&&void 0!==a?a:2,this.hash=null!==(o=t.hash)&&void 0!==o?o:Hm,this.seed=null!==(u=t.seed)&&void 0!==u?u:Gm(0,1024),this.filterSeries=[new Ym({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}return(0,$.default)(e,[{key:"add",value:function(e){if("string"==typeof e&&(e=wn(e)),this.has(e))return!0;var t=this.filterSeries.find((function(e){return e.reliable}));if(null==t){var n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);t=new Ym({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(t)}return t.add(e)}},{key:"has",value:function(e){"string"==typeof e&&(e=wn(e));for(var t=0;t<this.filterSeries.length;t++)if(this.filterSeries[t].has(e))return!0;return!1}},{key:"remove",value:function(e){"string"==typeof e&&(e=wn(e));for(var t=0;t<this.filterSeries.length;t++)if(this.filterSeries[t].remove(e))return!0;return!1}},{key:"count",get:function(){return this.filterSeries.reduce((function(e,t){return e+t.count}),0)}}]),e}();function Jm(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:.001;return new Qm((0,ae.default)({},function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:.001,n=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:.001;return e>.002?2:e>1e-5?4:8}(t);return{filterSize:Math.round(e/Zm[n]),bucketSize:n,fingerprintSize:Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*n)),64)}}(e,t)))}var $m=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(e){var r;(0,H.default)(this,n),r=t.call(this),(0,te.default)((0,q.default)(r),"metric",void 0);var i=e.name,a=e.metrics;return r.metric=a.registerMetric(i),r.updateComponentMetric(),r}return(0,$.default)(n,[{key:"set",value:function(e,t){return(0,ne.default)((0,re.default)(n.prototype),"set",this).call(this,e,t),this.updateComponentMetric(),this}},{key:"delete",value:function(e){var t=(0,ne.default)((0,re.default)(n.prototype),"delete",this).call(this,e);return this.updateComponentMetric(),t}},{key:"clear",value:function(){(0,ne.default)((0,re.default)(n.prototype),"clear",this).call(this),this.updateComponentMetric()}},{key:"updateComponentMetric",value:function(){this.metric.update(this.size)}}]),n}(Bm),eb=(B=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){for(var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"The operation was aborted",i=arguments.length,a=new Array(i>1?i-1:0),o=1;o<i;o++)a[o-1]=arguments[o];return(0,H.default)(this,n),e=t.call.apply(t,[this,r].concat((0,ce.default)(a))),(0,te.default)((0,q.default)(e),"name","AbortError"),e}return n}((0,he.default)(Error)),(0,te.default)(B,"name","AbortError"),B);function tb(e,t,n,r){return nb.apply(this,arguments)}function nb(){return nb=(0,K.default)((function(e,t,n,r){var i,a,o;return(0,pe.__generator)(this,(function(u){return i=new eb(null==r?void 0:r.errorMessage),null!=(null==r?void 0:r.errorCode)&&(i.code=r.errorCode),o=null!==(a=null==r?void 0:r.errorEvent)&&void 0!==a?a:"error",[2,!0===(null==n?void 0:n.aborted)?Promise.reject(i):new Promise((function(a,u){function s(){ib(n,"abort",f),ib(e,t,l),ib(e,o,c)}var l=function(e){try{var t;if(!1===(null==r||null===(t=r.filter)||void 0===t?void 0:t.call(r,e)))return}catch(e){return s(),void u(e)}s(),a(e)},c=function(e){var t,n;s(),u(e instanceof Error?e:null!==(n=null!==(t=e.detail)&&void 0!==t?t:null==r?void 0:r.error)&&void 0!==n?n:Error('The "'.concat(null==r?void 0:r.errorEvent,"\" event was emitted but the event had no '.detail' field. Pass an 'error' option to race-event to change this message.")))},f=function(){s(),u(i)};rb(n,"abort",f),rb(e,t,l),rb(e,o,c)}))]}))})),nb.apply(this,arguments)}function rb(e,t,n){null!=e&&(ab(e)?e.addEventListener(t,n):e.addListener(t,n))}function ib(e,t,n){null!=e&&(ab(e)?e.removeEventListener(t,n):e.removeListener(t,n))}function ab(e){return"function"==typeof e.addEventListener&&"function"==typeof e.removeEventListener}var ob=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"The queue was full";return(0,H.default)(this,n),(e=t.call(this,r)).name="QueueFullError",(0,ue.default)(e)}return n}((0,he.default)(Error));(0,te.default)(ob,"name","QueueFullError");var ub=function(){"use strict";function e(t){var n;(0,H.default)(this,e),(0,te.default)(this,"deferred",void 0),(0,te.default)(this,"signal",void 0),this.signal=t,this.deferred=Promise.withResolvers(),this.onAbort=this.onAbort.bind(this),null===(n=this.signal)||void 0===n||n.addEventListener("abort",this.onAbort)}return(0,$.default)(e,[{key:"onAbort",value:function(){var e,t;this.deferred.reject(null!==(t=null===(e=this.signal)||void 0===e?void 0:e.reason)&&void 0!==t?t:new eb)}},{key:"cleanup",value:function(){var e;null===(e=this.signal)||void 0===e||e.removeEventListener("abort",this.onAbort)}}]),e}(),sb=function(){"use strict";function e(t,n){(0,H.default)(this,e),(0,te.default)(this,"id",void 0),(0,te.default)(this,"fn",void 0),(0,te.default)(this,"options",void 0),(0,te.default)(this,"recipients",void 0),(0,te.default)(this,"status",void 0),(0,te.default)(this,"timeline",void 0),(0,te.default)(this,"controller",void 0),this.id="".concat(parseInt(1e9*Math.random()+"",10).toString()).concat(Date.now()),this.status="queued",this.fn=t,this.options=n,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.onAbort=this.onAbort.bind(this)}return(0,$.default)(e,[{key:"abort",value:function(e){this.controller.abort(e)}},{key:"onAbort",value:function(){this.recipients.reduce((function(e,t){var n;return e&&!0===(null===(n=t.signal)||void 0===n?void 0:n.aborted)}),!0)&&(this.controller.abort(new eb),this.cleanup())}},{key:"join",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=this;return(0,K.default)((function(){var n,r;return(0,pe.__generator)(this,(function(i){return r=new ub(e.signal),[2,(t.recipients.push(r),null===(n=e.signal)||void 0===n||n.addEventListener("abort",t.onAbort),r.deferred.promise)]}))}))()}},{key:"run",value:function(){var e=this;return(0,K.default)((function(){var t,n,r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:e.status="running",e.timeline.started=Date.now(),i.label=1;case 1:return i.trys.push([1,3,4,5]),e.controller.signal.throwIfAborted(),[4,Lo(e.fn((0,oe.default)((0,ae.default)({},null!==(t=e.options)&&void 0!==t?t:{}),{signal:e.controller.signal})),e.controller.signal)];case 2:return n=i.sent(),e.recipients.forEach((function(e){e.deferred.resolve(n)})),e.status="complete",[3,5];case 3:return r=i.sent(),e.recipients.forEach((function(e){e.deferred.reject(r)})),e.status="errored",[3,5];case 4:return e.timeline.finished=Date.now(),e.cleanup(),[7];case 5:return[2]}}))}))()}},{key:"cleanup",value:function(){var e=this;this.recipients.forEach((function(t){var n;t.cleanup(),null===(n=t.signal)||void 0===n||n.removeEventListener("abort",e.onAbort)}))}}]),e}();function lb(e,t){var n,r=function(){clearTimeout(n),n=setTimeout((function(){n=void 0,e()}),t)};return r.start=function(){},r.stop=function(){clearTimeout(n)},r}var cb,fb=(T=Symbol.asyncIterator,function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r,i,a,o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return(0,H.default)(this,n),e=t.call(this),(0,te.default)((0,q.default)(e),"concurrency",void 0),(0,te.default)((0,q.default)(e),"maxSize",void 0),(0,te.default)((0,q.default)(e),"queue",void 0),(0,te.default)((0,q.default)(e),"pending",void 0),(0,te.default)((0,q.default)(e),"sort",void 0),(0,te.default)((0,q.default)(e),"autoStart",void 0),e.concurrency=null!==(r=o.concurrency)&&void 0!==r?r:1/0,e.maxSize=null!==(i=o.maxSize)&&void 0!==i?i:1/0,e.pending=0,e.autoStart=null===(a=o.autoStart)||void 0===a||a,e.sort=o.sort,e.queue=[],e.emitEmpty=lb(e.emitEmpty.bind((0,q.default)(e)),1),e.emitIdle=lb(e.emitIdle.bind((0,q.default)(e)),1),(0,ue.default)(e)}return(0,$.default)(n,[{key:T,value:function(){return this.toGenerator()}},{key:"emitEmpty",value:function(){0===this.size&&this.safeDispatchEvent("empty")}},{key:"emitIdle",value:function(){0===this.running&&this.safeDispatchEvent("idle")}},{key:"tryToStartAnother",value:function(){var e=this;if(0===this.size)return this.emitEmpty(),0===this.running&&this.emitIdle(),!1;if(this.pending<this.concurrency){var t,n=!0,r=!1,i=void 0;try{for(var a,o=this.queue[Symbol.iterator]();!(n=(a=o.next()).done);n=!0){var u=a.value;if("queued"===u.status){t=u;break}}}catch(e){r=!0,i=e}finally{try{n||null==o.return||o.return()}finally{if(r)throw i}}return null!=t&&(this.safeDispatchEvent("active"),this.pending++,t.run().finally((function(){for(var n=0;n<e.queue.length;n++)if(e.queue[n]===t){e.queue.splice(n,1);break}e.pending--,e.safeDispatchEvent("next"),e.autoStart&&e.tryToStartAnother()})),!0)}return!1}},{key:"enqueue",value:function(e){this.queue.push(e),null!=this.sort&&this.queue.sort(this.sort)}},{key:"start",value:function(){!1===this.autoStart&&(this.autoStart=!0,this.tryToStartAnother())}},{key:"pause",value:function(){this.autoStart=!1}},{key:"add",value:function(e,t){var n=this;return(0,K.default)((function(){var r,i;return(0,pe.__generator)(this,(function(a){if(null==t||null===(r=t.signal)||void 0===r||r.throwIfAborted(),n.size===n.maxSize)throw new ob;return i=new sb(e,t),[2,(n.enqueue(i),n.safeDispatchEvent("add"),n.autoStart&&n.tryToStartAnother(),i.join(t).then((function(e){return n.safeDispatchEvent("success",{detail:{job:i,result:e}}),e})).catch((function(e){if("queued"===i.status)for(var t=0;t<n.queue.length;t++)if(n.queue[t]===i){n.queue.splice(t,1);break}throw n.safeDispatchEvent("failure",{detail:{job:i,error:e}}),e})))]}))}))()}},{key:"clear",value:function(){this.queue.splice(0,this.queue.length)}},{key:"abort",value:function(){this.queue.forEach((function(e){e.abort(new eb)})),this.clear()}},{key:"onEmpty",value:function(e){var t=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:return 0!==t.size?[4,tb(t,"empty",null==e?void 0:e.signal)]:[3,2];case 1:n.sent(),n.label=2;case 2:return[2]}}))}))()}},{key:"onSizeLessThan",value:function(e,t){var n=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return n.size<e?[3,2]:[4,tb(n,"next",null==t?void 0:t.signal,{filter:function(){return n.size<e}})];case 1:r.sent(),r.label=2;case 2:return[2]}}))}))()}},{key:"onIdle",value:function(e){var t=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:return 0===t.pending&&0===t.size?[3,2]:[4,tb(t,"idle",null==e?void 0:e.signal)];case 1:n.sent(),n.label=2;case 2:return[2]}}))}))()}},{key:"size",get:function(){return this.queue.length}},{key:"queued",get:function(){return this.queue.length-this.pending}},{key:"running",get:function(){return this.pending}},{key:"toGenerator",value:function(e){var t=this;return(0,de.default)((function(){var n,r,i,a,o,u,s,l,c;return(0,pe.__generator)(this,(function(f){switch(f.label){case 0:null==e||null===(n=e.signal)||void 0===n||n.throwIfAborted(),i=Po({objectMode:!0}),a=function(e){null!=e?t.abort():t.clear(),i.end(e)},o=function(e){null!=e.detail&&i.push(e.detail.result)},u=function(e){a(e.detail.error)},s=function(){a()},l=function(){a(new eb("Queue aborted"))},t.addEventListener("success",o),t.addEventListener("failure",u),t.addEventListener("idle",s),null==e||null===(r=e.signal)||void 0===r||r.addEventListener("abort",l),f.label=1;case 1:return f.trys.push([1,,3,4]),[5,(0,pe.__values)((0,z.default)((0,j.default)(i),V.default))];case 2:return f.sent(),[3,4];case 3:return t.removeEventListener("success",o),t.removeEventListener("failure",u),t.removeEventListener("idle",s),null==e||null===(c=e.signal)||void 0===c||c.removeEventListener("abort",l),a(),[7];case 4:return[2]}}))}))()}}]),n}(xa)),db="lock:worker:request-read",hb="lock:worker:abort-read-request",vb="lock:worker:release-read",pb="lock:master:grant-read",gb="lock:master:error-read",yb="lock:worker:request-write",mb="lock:worker:abort-write-request",bb="lock:worker:release-write",wb="lock:master:grant-write",kb="lock:master:error-write",_b="lock:worker:finalize",Eb="mortice",Sb={singleProcess:!1},Ab=function(e,t,n,r,i,a,o,u,s){return function(l){if(null!=l.data){var c={type:l.data.type,name:l.data.name,identifier:l.data.identifier};c.type===i&&e.safeDispatchEvent(n,{detail:{name:c.name,identifier:c.identifier,handler:function(){return(0,K.default)((function(){return(0,pe.__generator)(this,(function(e){switch(e.label){case 0:return t.postMessage({type:s,name:c.name,identifier:c.identifier}),[4,new Promise((function(e){var n=function(r){if(null!=(null==r?void 0:r.data)){var i=r.data.type,a=(r.data.name,r.data.identifier);i===u&&a===c.identifier&&(t.removeEventListener("message",n),e())}};t.addEventListener("message",n)}))];case 1:return e.sent(),[2]}}))}))()},onError:function(e){t.postMessage({type:o,name:c.name,identifier:c.identifier,error:{message:e.message,name:e.name,stack:e.stack}})}}}),c.type===a&&e.safeDispatchEvent(r,{detail:{name:c.name,identifier:c.identifier}}),c.type===_b&&e.safeDispatchEvent("finalizeRequest",{detail:{name:c.name}})}}},Ib=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"name",void 0),(0,te.default)(this,"channel",void 0),this.name=t,this.channel=new BroadcastChannel(Eb)}return(0,$.default)(e,[{key:"readLock",value:function(e){return this.sendRequest(db,hb,pb,gb,vb,e)}},{key:"writeLock",value:function(e){return this.sendRequest(yb,mb,wb,kb,bb,e)}},{key:"finalize",value:function(){this.channel.postMessage({type:_b,name:this.name}),this.channel.close()}},{key:"sendRequest",value:function(e,t,n,r,i,a){var o=this;return(0,K.default)((function(){var u,s;return(0,pe.__generator)(this,(function(l){return null==a||null===(u=a.signal)||void 0===u||u.throwIfAborted(),s=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:10;return Math.random().toString().substring(2,e+2)}(),[2,(o.channel.postMessage({type:e,identifier:s,name:o.name}),new Promise((function(e,u){var l,c=function(){o.channel.postMessage({type:t,identifier:s,name:o.name})};null==a||null===(l=a.signal)||void 0===l||l.addEventListener("abort",c,{once:!0});var f=function(t){var l,d,h;if((null===(l=t.data)||void 0===l?void 0:l.identifier)===s&&((null===(d=t.data)||void 0===d?void 0:d.type)===n&&(o.channel.removeEventListener("message",f),null==a||null===(h=a.signal)||void 0===h||h.removeEventListener("abort",c),e((function(){o.channel.postMessage({type:i,identifier:s,name:o.name})}))),t.data.type===r)){var v;o.channel.removeEventListener("message",f),null==a||null===(v=a.signal)||void 0===v||v.removeEventListener("abort",c);var p=Error();null!=t.data.error&&(p.message=t.data.error.message,p.name=t.data.error.name,p.stack=t.data.error.stack),u(p)}};o.channel.addEventListener("message",f)})))]}))}))()}}]),e}(),xb=new Map;function Cb(e){return"function"==typeof(null==e?void 0:e.readLock)&&"function"==typeof(null==e?void 0:e.writeLock)}function Tb(e,t){return Pb.apply(this,arguments)}function Pb(){return Pb=(0,K.default)((function(e,t){var n,r,i,a,o;return(0,pe.__generator)(this,(function(u){return a=new Promise((function(e,t){r=e,i=t})),o=function(){i(new eb)},[2,(null==t||null===(n=t.signal)||void 0===n||n.addEventListener("abort",o,{once:!0}),e.add((0,K.default)((function(){return(0,pe.__generator)(this,(function(e){switch(e.label){case 0:return[4,new Promise((function(e){r((function(){var n;null==t||null===(n=t.signal)||void 0===n||n.removeEventListener("abort",o),e()}))}))];case 1:return e.sent(),[2]}}))})),{signal:null==t?void 0:t.signal}).catch((function(e){i(e)})),a)]}))})),Pb.apply(this,arguments)}var Rb,Lb,Db,Mb={name:"lock",concurrency:1/0,singleProcess:!1,autoFinalize:!1};function Nb(e){var t=Object.assign({},Mb,e);return function(e,t){var n=xb.get(e);if(null!=n)return n;var r=function(e){if(null==cb&&(cb=function(e){if(e=Object.assign({},Sb,e),globalThis.document||e.singleProcess){var t=new BroadcastChannel(Eb),n=new xa;return t.addEventListener("message",Ab(n,t,"requestReadLock","abortReadLockRequest",db,hb,gb,vb,pb)),t.addEventListener("message",Ab(n,t,"requestWriteLock","abortWriteLockRequest",yb,mb,kb,bb,wb)),n}return new Ib(e.name)}(e),!Cb(cb))){var t=cb;t.addEventListener("requestReadLock",(function(e){var n=e.detail.name,r=e.detail.identifier,i=xb.get(n);if(null!=i){var a=new AbortController,o=function(e){e.detail.name===n&&e.detail.identifier===r&&a.abort()};t.addEventListener("abortReadLockRequest",o),i.readLock({signal:a.signal}).then(function(){var t=(0,K.default)((function(t){return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:return[4,e.detail.handler().finally((function(){t()}))];case 1:return n.sent(),[2]}}))}));return function(e){return t.apply(this,arguments)}}()).catch((function(t){e.detail.onError(t)})).finally((function(){t.removeEventListener("abortReadLockRequest",o)}))}})),t.addEventListener("requestWriteLock",(function(e){var n=e.detail.name,r=e.detail.identifier,i=xb.get(n);if(null!=i){var a=new AbortController,o=function(e){e.detail.name===n&&e.detail.identifier===r&&a.abort()};t.addEventListener("abortWriteLockRequest",o),i.writeLock({signal:a.signal}).then(function(){var t=(0,K.default)((function(t){return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:return[4,e.detail.handler().finally((function(){t()}))];case 1:return n.sent(),[2]}}))}));return function(e){return t.apply(this,arguments)}}()).catch((function(t){e.detail.onError(t)})).finally((function(){t.removeEventListener("abortWriteLockRequest",o)}))}})),t.addEventListener("finalizeRequest",(function(e){var t=e.detail.name,n=xb.get(t);null!=n&&n.finalize()}))}return cb}(t);if(Cb(r))return n=r,xb.set(e,n),n;var i,a=new fb({concurrency:1});return n={readLock:function(e){return(0,K.default)((function(){var n,r;return(0,pe.__generator)(this,(function(o){return null!=i?[2,Tb(i,e)]:(i=new fb({concurrency:t.concurrency,autoStart:!1}),n=i,r=Tb(i,e),[2,(a.add((0,K.default)((function(){return(0,pe.__generator)(this,(function(e){switch(e.label){case 0:return n.start(),[4,n.onIdle().then((function(){i===n&&(i=null)}))];case 1:return e.sent(),[2]}}))}))),r)])}))}))()},writeLock:function(e){return(0,K.default)((function(){return(0,pe.__generator)(this,(function(t){return[2,(i=null,Tb(a,e))]}))}))()},finalize:function(){xb.delete(e)},queue:a},xb.set(e,n),!0===t.autoFinalize&&a.addEventListener("idle",(function(){n.finalize()}),{once:!0}),n}(t.name,t)}function Ob(e,t){return null!=e.publicKey||null==t.publicKey?e:("RSA"===e.type&&(n=e.toMultihash()),_c(fc(t.publicKey,n)));var n}function Ub(e,t,n){var r,i=new Map,a=BigInt(Date.now()),o=!0,u=!1,s=void 0;try{for(var l,c=t.tags.entries()[Symbol.iterator]();!(o=(l=c.next()).done);o=!0){var f=(0,se.default)(l.value,2),d=f[0],h=f[1];null!=h.expiry&&h.expiry<a||i.set(d,h)}}catch(e){u=!0,s=e}finally{try{o||null==c.return||c.return()}finally{if(u)throw s}}return(0,oe.default)((0,ae.default)({},t),{id:Ob(e,t),addresses:t.addresses.filter((function(e){var t=e.observed;return null!=t&&t>Date.now()-n})).map((function(e){var t=e.multiaddr,n=e.isCertified;return{multiaddr:pf(t),isCertified:null!=n&&n}})),metadata:t.metadata,peerRecordEnvelope:null!==(r=t.peerRecordEnvelope)&&void 0!==r?r:void 0,tags:i})}function Fb(e,t){return qb(e.addresses,t.addresses,(function(e,t){return e.isCertified===t.isCertified&&!!so(e.multiaddr,t.multiaddr)}))&&qb(e.protocols,t.protocols,(function(e,t){return e===t}))&&Bb(e.publicKey,t.publicKey)&&Bb(e.peerRecordEnvelope,t.peerRecordEnvelope)&&zb(e.metadata,t.metadata,(function(e,t){return so(e,t)}))&&function(e,t){return zb(e,t,(function(e,t){return e.value===t.value&&e.expiry===t.expiry}))}(e.tags,t.tags)}function Bb(e,t){return null==e&&null==t||null!=e&&null!=t&&so(e,t)}function qb(e,t,n){if(e.length!==t.length)return!1;for(var r=0;r<e.length;r++)if(!n(e[r],t[r]))return!1;return!0}function zb(e,t,n){if(e.size!==t.size)return!1;var r=!0,i=!1,a=void 0;try{for(var o,u=e.entries()[Symbol.iterator]();!(r=(o=u.next()).done);r=!0){var s=(0,se.default)(o.value,2),l=s[0],c=s[1],f=t.get(l);if(null==f)return!1;if(!n(c,f))return!1}}catch(e){i=!0,a=e}finally{try{r||null==u.return||u.return()}finally{if(i)throw a}}return!0}(function(e){var t;(function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};!1!==n.lengthDelimited&&t.fork(),null!=e.key&&""!==e.key&&(t.uint32(10),t.string(e.key)),null!=e.value&&e.value.byteLength>0&&(t.uint32(18),t.bytes(e.value)),!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n={key:"",value:ye(0)},r=null==t?e.len:e.pos+t;e.pos<r;){var i=e.uint32();switch(i>>>3){case 1:n.key=e.string();break;case 2:n.value=e.bytes();break;default:e.skipType(7&i)}}return n}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}})(e.Peer$metadataEntry||(e.Peer$metadataEntry={})),function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};!1!==n.lengthDelimited&&t.fork(),null!=e.key&&""!==e.key&&(t.uint32(10),t.string(e.key)),null!=e.value&&(t.uint32(18),Db.codec().encode(e.value,t)),!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r={key:""},i=null==t?e.len:e.pos+t;e.pos<i;){var a=e.uint32();switch(a>>>3){case 1:r.key=e.string();break;case 2:var o;r.value=Db.codec().decode(e,e.uint32(),{limits:null===(o=n.limits)||void 0===o?void 0:o.value});break;default:e.skipType(7&a)}}return r}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(e.Peer$tagsEntry||(e.Peer$tagsEntry={})),e.codec=function(){return null==t&&(t=kr((function(t,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=!0,a=!1,o=void 0;if(!1!==r.lengthDelimited&&n.fork(),null!=t.addresses)try{for(var u,s=t.addresses[Symbol.iterator]();!(i=(u=s.next()).done);i=!0){var l=u.value;n.uint32(10),Lb.codec().encode(l,n)}}catch(e){a=!0,o=e}finally{try{i||null==s.return||s.return()}finally{if(a)throw o}}var c=!0,f=!1,d=void 0;if(null!=t.protocols)try{for(var h,v=t.protocols[Symbol.iterator]();!(c=(h=v.next()).done);c=!0){var p=h.value;n.uint32(18),n.string(p)}}catch(e){f=!0,d=e}finally{try{c||null==v.return||v.return()}finally{if(f)throw d}}var g=!0,y=!1,m=void 0;if(null!=t.publicKey&&(n.uint32(34),n.bytes(t.publicKey)),null!=t.peerRecordEnvelope&&(n.uint32(42),n.bytes(t.peerRecordEnvelope)),null!=t.metadata&&0!==t.metadata.size)try{for(var b,w=t.metadata.entries()[Symbol.iterator]();!(g=(b=w.next()).done);g=!0){var k=(0,se.default)(b.value,2),_=k[0],E=k[1];n.uint32(50),e.Peer$metadataEntry.codec().encode({key:_,value:E},n)}}catch(e){y=!0,m=e}finally{try{g||null==w.return||w.return()}finally{if(y)throw m}}var S=!0,A=!1,I=void 0;if(null!=t.tags&&0!==t.tags.size)try{for(var x,C=t.tags.entries()[Symbol.iterator]();!(S=(x=C.next()).done);S=!0){var T=(0,se.default)(x.value,2),P=T[0],R=T[1];n.uint32(58),e.Peer$tagsEntry.codec().encode({key:P,value:R},n)}}catch(e){A=!0,I=e}finally{try{S||null==C.return||C.return()}finally{if(A)throw I}}null!=t.updated&&(n.uint32(64),n.uint64Number(t.updated)),!1!==r.lengthDelimited&&n.ldelim()}),(function(t,n){for(var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i={addresses:[],protocols:[],metadata:new Map,tags:new Map},a=null==n?t.len:t.pos+n;t.pos<a;){var o=t.uint32();switch(o>>>3){case 1:var u,s;if(null!=(null===(u=r.limits)||void 0===u?void 0:u.addresses)&&i.addresses.length===r.limits.addresses)throw new _r('Decode error - map field "addresses" had too many elements');i.addresses.push(Lb.codec().decode(t,t.uint32(),{limits:null===(s=r.limits)||void 0===s?void 0:s.addresses$}));break;case 2:var l;if(null!=(null===(l=r.limits)||void 0===l?void 0:l.protocols)&&i.protocols.length===r.limits.protocols)throw new _r('Decode error - map field "protocols" had too many elements');i.protocols.push(t.string());break;case 4:i.publicKey=t.bytes();break;case 5:i.peerRecordEnvelope=t.bytes();break;case 6:var c;if(null!=(null===(c=r.limits)||void 0===c?void 0:c.metadata)&&i.metadata.size===r.limits.metadata)throw new Er('Decode error - map field "metadata" had too many elements');var f=e.Peer$metadataEntry.codec().decode(t,t.uint32());i.metadata.set(f.key,f.value);break;case 7:var d,h;if(null!=(null===(d=r.limits)||void 0===d?void 0:d.tags)&&i.tags.size===r.limits.tags)throw new Er('Decode error - map field "tags" had too many elements');var v=e.Peer$tagsEntry.codec().decode(t,t.uint32(),{limits:{value:null===(h=r.limits)||void 0===h?void 0:h.tags$value}});i.tags.set(v.key,v.value);break;case 8:i.updated=t.uint64Number();break;default:t.skipType(7&o)}}return i}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}})(Rb||(Rb={})),function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};!1!==n.lengthDelimited&&t.fork(),null!=e.multiaddr&&e.multiaddr.byteLength>0&&(t.uint32(10),t.bytes(e.multiaddr)),null!=e.isCertified&&(t.uint32(16),t.bool(e.isCertified)),null!=e.observed&&(t.uint32(24),t.uint64Number(e.observed)),!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n={multiaddr:ye(0)},r=null==t?e.len:e.pos+t;e.pos<r;){var i=e.uint32();switch(i>>>3){case 1:n.multiaddr=e.bytes();break;case 2:n.isCertified=e.bool();break;case 3:n.observed=e.uint64Number();break;default:e.skipType(7&i)}}return n}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(Lb||(Lb={})),function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};!1!==n.lengthDelimited&&t.fork(),null!=e.value&&0!==e.value&&(t.uint32(8),t.uint32(e.value)),null!=e.expiry&&(t.uint32(16),t.uint64(e.expiry)),!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n={value:0},r=null==t?e.len:e.pos+t;e.pos<r;){var i=e.uint32();switch(i>>>3){case 1:n.value=e.uint32();break;case 2:n.expiry=e.uint64();break;default:e.skipType(7&i)}}return n}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(Db||(Db={}));var jb="/",Kb=(new TextEncoder).encode(jb),Vb=Kb[0],Hb=Symbol.toStringTag,Wb=function(){"use strict";function e(t,n){if((0,H.default)(this,e),(0,te.default)(this,"_buf",void 0),"string"==typeof t)this._buf=wn(t);else{if(!(t instanceof Uint8Array))throw Error("Invalid key, should be String of Uint8Array");this._buf=t}if(null==n&&(n=!0),n&&this.clean(),0===this._buf.byteLength||this._buf[0]!==Vb)throw Error("Invalid key")}return(0,$.default)(e,[{key:"toString",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"utf8";return Ti(this._buf,e)}},{key:"uint8Array",value:function(){return this._buf}},{key:Hb,get:function(){return"Key(".concat(this.toString(),")")}},{key:"clean",value:function(){if(null!=this._buf&&0!==this._buf.byteLength||(this._buf=Kb),this._buf[0]!==Vb){var e=new Uint8Array(this._buf.byteLength+1);e.fill(Vb,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Vb;)this._buf=this._buf.subarray(0,-1)}},{key:"less",value:function(e){for(var t=this.list(),n=e.list(),r=0;r<t.length;r++){if(n.length<r+1)return!1;var i=t[r],a=n[r];if(i<a)return!0;if(i>a)return!1}return t.length<n.length}},{key:"reverse",value:function(){return e.withNamespaces(this.list().slice().reverse())}},{key:"namespaces",value:function(){return this.list()}},{key:"baseNamespace",value:function(){var e=this.namespaces();return e[e.length-1]}},{key:"list",value:function(){return this.toString().split(jb).slice(1)}},{key:"type",value:function(){return function(e){var t=e.split(":");return t.length<2?"":t.slice(0,-1).join(":")}(this.baseNamespace())}},{key:"name",value:function(){return function(e){var t=e.split(":");return t[t.length-1]}(this.baseNamespace())}},{key:"instance",value:function(t){return new e(this.toString()+":"+t)}},{key:"path",value:function(){var t=this.parent().toString();return t.endsWith(jb)||(t+=jb),new e(t+=this.type())}},{key:"parent",value:function(){var t=this.list();return 1===t.length?new e(jb):new e(t.slice(0,-1).join(jb))}},{key:"child",value:function(t){return this.toString()===jb?t:t.toString()===jb?this:new e(this.toString()+t.toString(),!1)}},{key:"isAncestorOf",value:function(e){return e.toString()!==this.toString()&&e.toString().startsWith(this.toString())}},{key:"isDecendantOf",value:function(e){return e.toString()!==this.toString()&&this.toString().startsWith(e.toString())}},{key:"isTopLevel",value:function(){return 1===this.list().length}},{key:"concat",value:function(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];var i,a;return e.withNamespaces((0,ce.default)(this.namespaces()).concat((0,ce.default)((a=n.map((function(e){return e.namespaces()})),(i=[]).concat.apply(i,(0,ce.default)(a))))))}}],[{key:"withNamespaces",value:function(t){return new e(t.join(jb))}},{key:"random",value:function(){return new e(Math.random().toString().substring(2))}},{key:"asKey",value:function(t){return t instanceof Uint8Array||"string"==typeof t?new e(t):"function"==typeof t.uint8Array?new e(t.uint8Array()):null}}]),e}(),Gb="/peers/";function Xb(e){if(!Yi(e)||null==e.type)throw new ra("Invalid PeerId");var t=e.toCID().toString();return new Wb("".concat(Gb).concat(t))}function Yb(e,t,n,r,i){return Zb.apply(this,arguments)}function Zb(){return Zb=(0,K.default)((function(e,t,n,r,i){var a,o,u,s,l,c,f,d,h,v,p,g;return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:a=new Map,o=!0,u=!1,s=void 0,r.label=1;case 1:r.trys.push([1,6,7,8]),l=n[Symbol.iterator](),r.label=2;case 2:if(o=(c=l.next()).done)return[3,5];if(null==(f=c.value))return[3,4];if(f.multiaddr instanceof Uint8Array&&(f.multiaddr=pf(f.multiaddr)),!vf(f.multiaddr))throw new ra("Multiaddr was invalid");return[4,t(e,f.multiaddr,i)];case 3:if(!r.sent())return[3,4];h=null!==(d=f.isCertified)&&void 0!==d&&d,v=f.multiaddr.toString(),null!=(p=a.get(v))?f.isCertified=p.isCertified||h:a.set(v,{multiaddr:f.multiaddr,isCertified:h}),r.label=4;case 4:return o=!0,[3,2];case 5:return[3,8];case 6:return g=r.sent(),u=!0,s=g,[3,8];case 7:try{o||null==l.return||l.return()}finally{if(u)throw s}return[7];case 8:return[2,(0,ce.default)(a.values()).sort((function(e,t){return e.multiaddr.toString().localeCompare(t.multiaddr.toString())})).map((function(t){var n=t.isCertified,r=t.multiaddr,i=r.getPeerId();return e.equals(i)&&(r=r.decapsulate(pf("/p2p/"+e))),{isCertified:n,multiaddr:r.bytes}}))]}}))})),Zb.apply(this,arguments)}function Qb(e,t,n,r){return Jb.apply(this,arguments)}function Jb(){return Jb=(0,K.default)((function(e,t,n,r){var i,a,o,u,s,l,c,f,d,h,v,p,g,y,m,b,w,k,_,E,S,A,I,x,C,T,P,R,L,D,M,N,O,U,F,B,q,z,j;return(0,pe.__generator)(this,(function(V){switch(V.label){case 0:if(null==t)throw new ra("Invalid PeerData");if(null!=t.publicKey&&null!=e.publicKey&&!t.publicKey.equals(e.publicKey))throw new ra("publicKey bytes do not match peer id publicKey bytes");if(null!=(o=null===(i=r.existingPeer)||void 0===i?void 0:i.peer)&&!e.equals(o.id))throw new ra("peer id did not match existing peer id");if(d=null!==(u=null==o?void 0:o.addresses)&&void 0!==u?u:[],h=new Set(null!==(s=null==o?void 0:o.protocols)&&void 0!==s?s:[]),v=null!==(l=null==o?void 0:o.metadata)&&void 0!==l?l:new Map,p=null!==(c=null==o?void 0:o.tags)&&void 0!==c?c:new Map,g=null==o?void 0:o.peerRecordEnvelope,"patch"===n&&(null==t.multiaddrs&&null==t.addresses||(d=[],null!=t.multiaddrs&&(y=d).push.apply(y,(0,ce.default)(t.multiaddrs.map((function(e){return{isCertified:!1,multiaddr:e}})))),null!=t.addresses&&(m=d).push.apply(m,(0,ce.default)(t.addresses))),null!=t.protocols&&(h=new Set(t.protocols)),null!=t.metadata&&(v=$b(t.metadata instanceof Map?(0,ce.default)(t.metadata.entries()):Object.entries(t.metadata),{validate:ew})),null!=t.tags&&(p=$b(t.tags instanceof Map?(0,ce.default)(t.tags.entries()):Object.entries(t.tags),{validate:tw,map:nw})),null!=t.peerRecordEnvelope&&(g=t.peerRecordEnvelope)),"merge"===n){if(null!=t.multiaddrs&&(b=d).push.apply(b,(0,ce.default)(t.multiaddrs.map((function(e){return{isCertified:!1,multiaddr:e}})))),null!=t.addresses&&(w=d).push.apply(w,(0,ce.default)(t.addresses)),null!=t.protocols&&(h=new Set((0,ce.default)(h).concat((0,ce.default)(t.protocols)))),null!=t.metadata){k=t.metadata instanceof Map?(0,ce.default)(t.metadata.entries()):Object.entries(t.metadata),_=!0,E=!1,S=void 0;try{for(A=k[Symbol.iterator]();!(_=(I=A.next()).done);_=!0)x=(0,se.default)(I.value,2),C=x[0],null==(T=x[1])?v.delete(C):v.set(C,T)}catch(e){E=!0,S=e}finally{try{_||null==A.return||A.return()}finally{if(E)throw S}}v=$b((0,ce.default)(v.entries()),{validate:ew})}if(null!=t.tags){P=t.tags instanceof Map?(0,ce.default)(t.tags.entries()):Object.entries(t.tags),R=new Map(p),L=!0,D=!1,M=void 0;try{for(N=P[Symbol.iterator]();!(L=(O=N.next()).done);L=!0)U=(0,se.default)(O.value,2),F=U[0],null==(B=U[1])?R.delete(F):R.set(F,B)}catch(e){D=!0,M=e}finally{try{L||null==N.return||N.return()}finally{if(D)throw M}}p=$b((0,ce.default)(R.entries()),{validate:tw,map:nw})}null!=t.peerRecordEnvelope&&(g=t.peerRecordEnvelope)}return null!=(null==o?void 0:o.id.publicKey)?f=dc(o.id.publicKey):null!=t.publicKey?f=dc(t.publicKey):null!=e.publicKey&&(f=dc(e.publicKey)),j={},[4,Yb(e,null!==(q=r.addressFilter)&&void 0!==q?q:(0,K.default)((function(){return(0,pe.__generator)(this,(function(e){return[2,!0]}))})),d,null===(a=r.existingPeer)||void 0===a?void 0:a.peerPB.addresses,r)];case 1:return j.addresses=V.sent(),j.protocols=(0,ce.default)(h.values()).sort((function(e,t){return e.localeCompare(t)})),j.metadata=v,j.tags=p,j.publicKey=f,j.peerRecordEnvelope=g,[2,((z=j).addresses.forEach((function(e){var t,n,i,a;e.observed=null!==(a=null===(t=null===(n=null===(i=r.existingPeer)||void 0===i?void 0:i.peerPB.addresses)||void 0===n?void 0:n.find((function(e){return so(e.multiaddr,e.multiaddr)})))||void 0===t?void 0:t.observed)&&void 0!==a?a:Date.now()})),"RSA"!==e.type&&delete z.publicKey,z)]}}))})),Jb.apply(this,arguments)}function $b(e,t){var n,r,i=new Map,a=!0,o=!1,u=void 0;try{for(var s,l=e[Symbol.iterator]();!(a=(s=l.next()).done);a=!0){var c=(0,se.default)(s.value,2),f=c[0],d=c[1];null!=d&&t.validate(f,d)}}catch(e){o=!0,u=e}finally{try{a||null==l.return||l.return()}finally{if(o)throw u}}var h=!0,v=!1,p=void 0;try{for(var g,y=e.sort((function(e,t){var n=(0,se.default)(e,1)[0],r=(0,se.default)(t,1)[0];return n.localeCompare(r)}))[Symbol.iterator]();!(h=(g=y.next()).done);h=!0){var m=(0,se.default)(g.value,2),b=m[0],w=m[1];null!=w&&i.set(b,null!==(r=null===(n=t.map)||void 0===n?void 0:n.call(t,b,w))&&void 0!==r?r:w)}}catch(e){v=!0,p=e}finally{try{h||null==y.return||y.return()}finally{if(v)throw p}}return i}function ew(e,t){if("string"!=typeof e)throw new ra("Metadata key must be a string");if(!(t instanceof Uint8Array))throw new ra("Metadata value must be a Uint8Array")}function tw(e,t){if("string"!=typeof e)throw new ra("Tag name must be a string");if(null!=t.value){if(parseInt(""+t.value,10)!==t.value)throw new ra("Tag value must be an integer");if(t.value<0||t.value>100)throw new ra("Tag value must be between 0-100")}if(null!=t.ttl){if(parseInt(""+t.ttl,10)!==t.ttl)throw new ra("Tag ttl must be an integer");if(t.ttl<0)throw new ra("Tag ttl must be between greater than 0")}}function nw(e,t){var n,r;null!=t.expiry&&(n=t.expiry),null!=t.ttl&&(n=BigInt(Date.now()+Number(t.ttl)));var i={value:null!==(r=t.value)&&void 0!==r?r:0};return null!=n&&(i.expiry=n),i}function rw(e){var t=e.toString().split("/")[2];return Sc(cn.parse(t,vt))}function iw(e,t,n){return function(e,t,n){return Ub(e,Rb.decode(t),n)}(rw(e),t,n)}var aw=new WeakSet,ow=new WeakSet,uw=new WeakSet,sw=function(){"use strict";function e(t){var n,r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};(0,H.default)(this,e),(0,Q.default)(this,aw),(0,Q.default)(this,ow),(0,Q.default)(this,uw),(0,te.default)(this,"peerId",void 0),(0,te.default)(this,"datastore",void 0),(0,te.default)(this,"locks",void 0),(0,te.default)(this,"addressFilter",void 0),(0,te.default)(this,"log",void 0),(0,te.default)(this,"maxAddressAge",void 0),(0,te.default)(this,"maxPeerAge",void 0),this.log=t.logger.forComponent("libp2p:peer-store"),this.peerId=t.peerId,this.datastore=t.datastore,this.addressFilter=i.addressFilter,this.locks=function(e){var t=e.metrics;return null!=t?new $m({name:e.name,metrics:t}):new Bm}({name:"libp2p_peer_store_locks",metrics:t.metrics}),this.maxAddressAge=null!==(n=i.maxAddressAge)&&void 0!==n?n:36e5,this.maxPeerAge=null!==(r=i.maxPeerAge)&&void 0!==r?r:216e5}return(0,$.default)(e,[{key:"getLock",value:function(e){var t=this.locks.get(e);return null==t&&(t={refs:0,lock:Nb({name:e.toString(),singleProcess:!0})},this.locks.set(e,t)),t.refs++,t}},{key:"maybeRemoveLock",value:function(e,t){t.refs--,0===t.refs&&(t.lock.finalize(),this.locks.delete(e))}},{key:"getReadLock",value:function(e,t){var n=this;return(0,K.default)((function(){var r,i,a;return(0,pe.__generator)(this,(function(o){switch(o.label){case 0:r=n.getLock(e),o.label=1;case 1:return o.trys.push([1,3,,4]),[4,r.lock.readLock(t)];case 2:return i=o.sent(),[2,function(){i(),n.maybeRemoveLock(e,r)}];case 3:throw a=o.sent(),n.maybeRemoveLock(e,r),a;case 4:return[2]}}))}))()}},{key:"getWriteLock",value:function(e,t){var n=this;return(0,K.default)((function(){var r,i,a;return(0,pe.__generator)(this,(function(o){switch(o.label){case 0:r=n.getLock(e),o.label=1;case 1:return o.trys.push([1,3,,4]),[4,r.lock.writeLock(t)];case 2:return i=o.sent(),[2,function(){i(),n.maybeRemoveLock(e,r)}];case 3:throw a=o.sent(),n.maybeRemoveLock(e,r),a;case 4:return[2]}}))}))()}},{key:"has",value:function(e,t){var n=this;return(0,K.default)((function(){var r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,n.load(e,t)];case 1:return[2,(i.sent(),!0)];case 2:if("NotFoundError"!==(r=i.sent()).name)throw r;return[3,3];case 3:return[2,!1]}}))}))()}},{key:"delete",value:function(e,t){var n=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return n.peerId.equals(e)?[3,2]:[4,n.datastore.delete(Xb(e),t)];case 1:r.sent(),r.label=2;case 2:return[2]}}))}))()}},{key:"load",value:function(e,t){var n=this;return(0,K.default)((function(){var r,i,a;return(0,pe.__generator)(this,(function(o){switch(o.label){case 0:return r=Xb(e),[4,n.datastore.get(r,t)];case 1:return i=o.sent(),a=Rb.decode(i),(0,Z.default)(n,uw,hw).call(n,e,a)?[4,n.datastore.delete(r,t)]:[3,3];case 2:throw o.sent(),new fa;case 3:return[2,Ub(e,a,n.peerId.equals(e)?1/0:n.maxAddressAge)]}}))}))()}},{key:"save",value:function(e,t,n){var r=this;return(0,K.default)((function(){var i,a;return(0,pe.__generator)(this,(function(o){switch(o.label){case 0:return[4,(0,Z.default)(r,aw,lw).call(r,e,n)];case 1:return i=o.sent(),[4,Qb(e,t,"patch",(0,oe.default)((0,ae.default)({},n),{addressFilter:r.addressFilter}))];case 2:return a=o.sent(),[2,(0,Z.default)(r,ow,fw).call(r,e,a,i)]}}))}))()}},{key:"patch",value:function(e,t,n){var r=this;return(0,K.default)((function(){var i,a;return(0,pe.__generator)(this,(function(o){switch(o.label){case 0:return[4,(0,Z.default)(r,aw,lw).call(r,e,n)];case 1:return i=o.sent(),[4,Qb(e,t,"patch",(0,oe.default)((0,ae.default)({},n),{addressFilter:r.addressFilter,existingPeer:i}))];case 2:return a=o.sent(),[2,(0,Z.default)(r,ow,fw).call(r,e,a,i)]}}))}))()}},{key:"merge",value:function(e,t,n){var r=this;return(0,K.default)((function(){var i,a;return(0,pe.__generator)(this,(function(o){switch(o.label){case 0:return[4,(0,Z.default)(r,aw,lw).call(r,e,n)];case 1:return i=o.sent(),[4,Qb(e,t,"merge",{addressFilter:r.addressFilter,existingPeer:i})];case 2:return a=o.sent(),[2,(0,Z.default)(r,ow,fw).call(r,e,a,i)]}}))}))()}},{key:"all",value:function(e){var t=this;return(0,de.default)((function(){var n,r,i,a,o,u,s,l,c,f,d;return(0,pe.__generator)(this,(function(h){switch(h.label){case 0:n=!1,r=!1,h.label=1;case 1:h.trys.push([1,10,11,16]),a=(0,j.default)(t.datastore.query(function(e,t){var n,r;return{prefix:Gb,filters:(null!==(n=e.filters)&&void 0!==n?n:[]).map((function(e){return function(n){var r=n.key,i=n.value;return e(iw(r,i,t))}})),orders:(null!==(r=e.orders)&&void 0!==r?r:[]).map((function(e){return function(n,r){return e(iw(n.key,n.value,t),iw(r.key,r.value,t))}}))}}(null!=e?e:{},t.maxAddressAge),e)),h.label=2;case 2:return[4,(0,V.default)(a.next())];case 3:return(n=!(o=h.sent()).done)?(u=o.value,s=u.key,l=u.value,(c=rw(s)).equals(t.peerId)?[3,8]:(f=Rb.decode(l),(0,Z.default)(t,uw,hw).call(t,c,f)?[4,(0,V.default)(t.datastore.delete(s,e))]:[3,5])):[3,9];case 4:return h.sent(),[3,7];case 5:return[4,Ub(c,f,t.peerId.equals(c)?1/0:t.maxAddressAge)];case 6:h.sent(),h.label=7;case 7:h.label=8;case 8:return n=!1,[3,2];case 9:return[3,16];case 10:return d=h.sent(),r=!0,i=d,[3,16];case 11:return h.trys.push([11,,14,15]),n&&null!=a.return?[4,a.return()]:[3,13];case 12:h.sent(),h.label=13;case 13:return[3,15];case 14:if(r)throw i;return[7];case 15:return[7];case 16:return[2]}}))}))()}}]),e}();function lw(e,t){return cw.apply(this,arguments)}function cw(){return cw=(0,K.default)((function(e,t){var n,r,i,a;return(0,pe.__generator)(this,(function(o){switch(o.label){case 0:return o.trys.push([0,4,,5]),n=Xb(e),[4,this.datastore.get(n,t)];case 1:return r=o.sent(),i=Rb.decode(r),(0,Z.default)(this,uw,hw).call(this,e,i)?[4,this.datastore.delete(n,t)]:[3,3];case 2:throw o.sent(),new fa;case 3:return[2,{peerPB:i,peer:Ub(e,i,this.maxAddressAge)}];case 4:return"NotFoundError"!==(a=o.sent()).name&&this.log.error("invalid peer data found in peer store - %e",a),[3,5];case 5:return[2]}}))})),cw.apply(this,arguments)}function fw(e,t,n,r){return dw.apply(this,arguments)}function dw(){return dw=(0,K.default)((function(e,t,n,r){var i;return(0,pe.__generator)(this,(function(a){switch(a.label){case 0:return t.updated=Date.now(),i=Rb.encode(t),[4,this.datastore.put(Xb(e),i,r)];case 1:return[2,(a.sent(),{peer:Ub(e,t,this.maxAddressAge),previous:null==n?void 0:n.peer,updated:null==n||!Fb(t,n.peerPB)})]}}))})),dw.apply(this,arguments)}function hw(e,t){if(null==t.updated)return!0;if(this.peerId.equals(e))return!1;var n=t.updated<Date.now()-this.maxPeerAge,r=Date.now()-this.maxAddressAge,i=t.addresses.filter((function(e){return null!=e.observed&&e.observed>r}));return n&&0===i.length}var vw=new WeakSet,pw=Symbol.toStringTag,gw=function(){"use strict";function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};(0,H.default)(this,e),(0,Q.default)(this,vw),(0,te.default)(this,"store",void 0),(0,te.default)(this,"events",void 0),(0,te.default)(this,"peerId",void 0),(0,te.default)(this,"log",void 0),(0,te.default)(this,pw,"@libp2p/peer-store"),this.log=t.logger.forComponent("libp2p:peer-store"),this.events=t.events,this.peerId=t.peerId,this.store=new sw(t,n)}return(0,$.default)(e,[{key:"forEach",value:function(e,t){var n=this;return(0,K.default)((function(){var r,i,a,o,u,s,l;return(0,pe.__generator)(this,(function(c){switch(c.label){case 0:r=!1,i=!1,c.label=1;case 1:c.trys.push([1,6,7,12]),o=(0,j.default)(n.store.all(t)),c.label=2;case 2:return[4,o.next()];case 3:if(!(r=!(u=c.sent()).done))return[3,5];s=u.value,e(s),c.label=4;case 4:return r=!1,[3,2];case 5:return[3,12];case 6:return l=c.sent(),i=!0,a=l,[3,12];case 7:return c.trys.push([7,,10,11]),r&&null!=o.return?[4,o.return()]:[3,9];case 8:c.sent(),c.label=9;case 9:return[3,11];case 10:if(i)throw a;return[7];case 11:return[7];case 12:return[2]}}))}))()}},{key:"all",value:function(e){var t=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(n){return[2,oo(t.store.all(e))]}))}))()}},{key:"delete",value:function(e,t){var n=this;return(0,K.default)((function(){var r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:return[4,n.store.getReadLock(e,t)];case 1:r=i.sent(),i.label=2;case 2:return i.trys.push([2,,4,5]),[4,n.store.delete(e,t)];case 3:return i.sent(),[3,5];case 4:return r(),[7];case 5:return[2]}}))}))()}},{key:"has",value:function(e,t){var n=this;return(0,K.default)((function(){var r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:return[4,n.store.getReadLock(e,t)];case 1:r=i.sent(),i.label=2;case 2:return i.trys.push([2,,4,5]),[4,n.store.has(e,t)];case 3:return[2,i.sent()];case 4:return n.log.trace("has release read lock"),null==r||r(),[7];case 5:return[2]}}))}))()}},{key:"get",value:function(e,t){var n=this;return(0,K.default)((function(){var r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:return[4,n.store.getReadLock(e,t)];case 1:r=i.sent(),i.label=2;case 2:return i.trys.push([2,,4,5]),[4,n.store.load(e,t)];case 3:return[2,i.sent()];case 4:return null==r||r(),[7];case 5:return[2]}}))}))()}},{key:"getInfo",value:function(e,t){var n=this;return(0,K.default)((function(){var r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:return[4,n.get(e,t)];case 1:return[2,{id:(r=i.sent()).id,multiaddrs:r.addresses.map((function(e){return e.multiaddr}))}]}}))}))()}},{key:"save",value:function(e,t,n){var r=this;return(0,K.default)((function(){var i,a;return(0,pe.__generator)(this,(function(o){switch(o.label){case 0:return[4,r.store.getWriteLock(e,n)];case 1:i=o.sent(),o.label=2;case 2:return o.trys.push([2,,4,5]),[4,r.store.save(e,t,n)];case 3:return a=o.sent(),[2,((0,Z.default)(r,vw,yw).call(r,e,a),a.peer)];case 4:return null==i||i(),[7];case 5:return[2]}}))}))()}},{key:"patch",value:function(e,t,n){var r=this;return(0,K.default)((function(){var i,a;return(0,pe.__generator)(this,(function(o){switch(o.label){case 0:return[4,r.store.getWriteLock(e,n)];case 1:i=o.sent(),o.label=2;case 2:return o.trys.push([2,,4,5]),[4,r.store.patch(e,t,n)];case 3:return a=o.sent(),[2,((0,Z.default)(r,vw,yw).call(r,e,a),a.peer)];case 4:return null==i||i(),[7];case 5:return[2]}}))}))()}},{key:"merge",value:function(e,t,n){var r=this;return(0,K.default)((function(){var i,a;return(0,pe.__generator)(this,(function(o){switch(o.label){case 0:return[4,r.store.getWriteLock(e,n)];case 1:i=o.sent(),o.label=2;case 2:return o.trys.push([2,,4,5]),[4,r.store.merge(e,t,n)];case 3:return a=o.sent(),[2,((0,Z.default)(r,vw,yw).call(r,e,a),a.peer)];case 4:return null==i||i(),[7];case 5:return[2]}}))}))()}},{key:"consumePeerRecord",value:function(e,t,n){var r=this;return(0,K.default)((function(){var i,a,o,u,s,l,c,f,d;return(0,pe.__generator)(this,(function(h){switch(h.label){case 0:return i=Yi(t)?t:Yi(null==t?void 0:t.expectedPeer)?t.expectedPeer:void 0,a=Yi(t)||void 0===t?n:t,[4,Av.openAndCertify(e,Pv.DOMAIN,a)];case 1:if(o=h.sent(),u=Sc(o.publicKey.toCID()),!1===(null==i?void 0:i.equals(u)))return[2,(r.log("envelope peer id was not the expected peer id - expected: %p received: %p",i,u),!1)];s=Pv.createFromProtobuf(o.payload),h.label=2;case 2:return h.trys.push([2,4,,5]),[4,r.get(u,a)];case 3:return l=h.sent(),[3,5];case 4:if("NotFoundError"!==(c=h.sent()).name)throw c;return[3,5];case 5:return null!=(null==l?void 0:l.peerRecordEnvelope)&&(f=Av.createFromProtobuf(l.peerRecordEnvelope),(d=Pv.createFromProtobuf(f.payload)).seqNumber>=s.seqNumber)?[2,(r.log("sequence number was lower or equal to existing sequence number - stored: %d received: %d",d.seqNumber,s.seqNumber),!1)]:[4,r.patch(s.peerId,{peerRecordEnvelope:e,addresses:s.multiaddrs.map((function(e){return{isCertified:!0,multiaddr:e}}))},a)];case 6:return[2,(h.sent(),!0)]}}))}))()}}]),e}();function yw(e,t){t.updated&&(this.peerId.equals(e)?this.events.safeDispatchEvent("self:peer:update",{detail:t}):this.events.safeDispatchEvent("peer:update",{detail:t}))}var mw=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Not Found";return(0,H.default)(this,n),e=t.call(this,r),(0,te.default)((0,q.default)(e),"name",n.name),(0,te.default)((0,q.default)(e),"code",n.code),e}return n}((0,he.default)(Error));function bw(e,t){var n=0;if(null!=e[Symbol.asyncIterator])return(0,de.default)((function(){var r,i,a,o,u,s,l,c;return(0,pe.__generator)(this,(function(f){switch(f.label){case 0:r=!1,i=!1,f.label=1;case 1:f.trys.push([1,9,10,15]),o=(0,j.default)(e),f.label=2;case 2:return[4,(0,V.default)(o.next())];case 3:return(r=!(u=f.sent()).done)?(s=u.value,l=s,[4,(0,V.default)(t(l,n++))]):[3,8];case 4:return f.sent()?[4,l]:[3,6];case 5:f.sent(),f.label=6;case 6:f.label=7;case 7:return r=!1,[3,2];case 8:return[3,15];case 9:return c=f.sent(),i=!0,a=c,[3,15];case 10:return f.trys.push([10,,13,14]),r&&null!=o.return?[4,o.return()]:[3,12];case 11:f.sent(),f.label=12;case 12:return[3,14];case 13:if(i)throw a;return[7];case 14:return[7];case 15:return[2]}}))}))();var r=function(e){var t=(0,se.default)(null!=e[Symbol.asyncIterator]?[e[Symbol.asyncIterator](),Symbol.asyncIterator]:[e[Symbol.iterator](),Symbol.iterator],2),n=t[0],r=t[1],i=[];return(0,te.default)({peek:function(){return n.next()},push:function(e){i.push(e)},next:function(){return i.length>0?{done:!1,value:i.shift()}:n.next()}},r,(function(){return this}))}(e),i=r.next(),a=i.value;if(!0===i.done)return function(){return(0,pe.__generator)(this,(function(e){return[2]}))}();var o=t(a,n++);if("function"==typeof o.then)return(0,de.default)((function(){var e,i,u,s,l,c,f,d;return(0,pe.__generator)(this,(function(h){switch(h.label){case 0:return[4,(0,V.default)(o)];case 1:return h.sent()?[4,a]:[3,3];case 2:h.sent(),h.label=3;case 3:e=!1,i=!1,h.label=4;case 4:h.trys.push([4,12,13,18]),s=(0,j.default)(r),h.label=5;case 5:return[4,(0,V.default)(s.next())];case 6:return(e=!(l=h.sent()).done)?(c=l.value,f=c,[4,(0,V.default)(t(f,n++))]):[3,11];case 7:return h.sent()?[4,f]:[3,9];case 8:h.sent(),h.label=9;case 9:h.label=10;case 10:return e=!1,[3,5];case 11:return[3,18];case 12:return d=h.sent(),i=!0,u=d,[3,18];case 13:return h.trys.push([13,,16,17]),e&&null!=s.return?[4,s.return()]:[3,15];case 14:h.sent(),h.label=15;case 15:return[3,17];case 16:if(i)throw u;return[7];case 17:return[7];case 18:return[2]}}))}))();var u=t;return function(){var e,t,i,s,l,c,f;return(0,pe.__generator)(this,(function(d){switch(d.label){case 0:return!0===o?[4,a]:[3,2];case 1:d.sent(),d.label=2;case 2:e=!0,t=!1,i=void 0,d.label=3;case 3:d.trys.push([3,9,10,11]),s=r[Symbol.iterator](),d.label=4;case 4:return(e=(l=s.next()).done)?[3,8]:(c=l.value,u(c,n++)?[4,c]:[3,6]);case 5:d.sent(),d.label=6;case 6:d.label=7;case 7:return e=!0,[3,4];case 8:return[3,11];case 9:return f=d.sent(),t=!0,i=f,[3,11];case 10:try{e||null==s.return||s.return()}finally{if(t)throw i}return[7];case 11:return[2]}}))}()}function ww(e,t){return null!=e[Symbol.asyncIterator]?(0,de.default)((function(){var n;return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return[4,(0,V.default)(oo(e))];case 1:return n=r.sent(),[5,(0,pe.__values)((0,z.default)((0,j.default)(n.sort(t)),V.default))];case 2:return r.sent(),[2]}}))}))():function(){var n;return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return n=oo(e),[5,(0,pe.__values)(n.sort(t))];case 1:return r.sent(),[2]}}))}()}function kw(e,t){return null!=e[Symbol.asyncIterator]?(0,de.default)((function(){var n,r,i,a,o,u,s,l;return(0,pe.__generator)(this,(function(c){switch(c.label){case 0:if(n=0,t<1)return[3,13];r=!1,i=!1,c.label=1;case 1:c.trys.push([1,7,8,13]),o=(0,j.default)(e),c.label=2;case 2:return[4,(0,V.default)(o.next())];case 3:return(r=!(u=c.sent()).done)?(s=u.value,[4,s]):[3,6];case 4:if(c.sent(),++n===t)return[2];c.label=5;case 5:return r=!1,[3,2];case 6:return[3,13];case 7:return l=c.sent(),i=!0,a=l,[3,13];case 8:return c.trys.push([8,,11,12]),r&&null!=o.return?[4,o.return()]:[3,10];case 9:c.sent(),c.label=10;case 10:return[3,12];case 11:if(i)throw a;return[7];case 12:return[7];case 13:return[2]}}))}))():function(){var n,r,i,a,o,u,s;return(0,pe.__generator)(this,(function(l){switch(l.label){case 0:if(n=0,t<1)return[3,8];r=!0,i=!1,a=void 0,l.label=1;case 1:l.trys.push([1,6,7,8]),o=e[Symbol.iterator](),l.label=2;case 2:return(r=(u=o.next()).done)?[3,5]:[4,u.value];case 3:if(l.sent(),++n===t)return[2];l.label=4;case 4:return r=!0,[3,2];case 5:return[3,8];case 6:return s=l.sent(),i=!0,a=s,[3,8];case 7:try{r||null==o.return||o.return()}finally{if(i)throw a}return[7];case 8:return[2]}}))}()}(0,te.default)(mw,"name","NotFoundError"),(0,te.default)(mw,"code","ERR_NOT_FOUND");var _w=function(){"use strict";function e(){(0,H.default)(this,e)}return(0,$.default)(e,[{key:"put",value:function(e,t,n){return Promise.reject(Error(".put is not implemented"))}},{key:"get",value:function(e,t){return Promise.reject(Error(".get is not implemented"))}},{key:"has",value:function(e,t){return Promise.reject(Error(".has is not implemented"))}},{key:"delete",value:function(e,t){return Promise.reject(Error(".delete is not implemented"))}},{key:"putMany",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=this;return(0,de.default)((function(){var r,i,a,o,u,s,l,c,f;return(0,pe.__generator)(this,(function(d){switch(d.label){case 0:r=!1,i=!1,d.label=1;case 1:d.trys.push([1,8,9,14]),o=(0,j.default)(e),d.label=2;case 2:return[4,(0,V.default)(o.next())];case 3:return(r=!(u=d.sent()).done)?(s=u.value,l=s.key,c=s.value,[4,(0,V.default)(n.put(l,c,t))]):[3,7];case 4:return d.sent(),[4,l];case 5:d.sent(),d.label=6;case 6:return r=!1,[3,2];case 7:return[3,14];case 8:return f=d.sent(),i=!0,a=f,[3,14];case 9:return d.trys.push([9,,12,13]),r&&null!=o.return?[4,o.return()]:[3,11];case 10:d.sent(),d.label=11;case 11:return[3,13];case 12:if(i)throw a;return[7];case 13:return[7];case 14:return[2]}}))}))()}},{key:"getMany",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=this;return(0,de.default)((function(){var r,i,a,o,u,s,l,c,f;return(0,pe.__generator)(this,(function(d){switch(d.label){case 0:r=!1,i=!1,d.label=1;case 1:d.trys.push([1,8,9,14]),o=(0,j.default)(e),d.label=2;case 2:return[4,(0,V.default)(o.next())];case 3:return(r=!(u=d.sent()).done)?(s=u.value,c={key:l=s},[4,(0,V.default)(n.get(l,t))]):[3,7];case 4:return[4,(c.value=d.sent(),c)];case 5:d.sent(),d.label=6;case 6:return r=!1,[3,2];case 7:return[3,14];case 8:return f=d.sent(),i=!0,a=f,[3,14];case 9:return d.trys.push([9,,12,13]),r&&null!=o.return?[4,o.return()]:[3,11];case 10:d.sent(),d.label=11;case 11:return[3,13];case 12:if(i)throw a;return[7];case 13:return[7];case 14:return[2]}}))}))()}},{key:"deleteMany",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=this;return(0,de.default)((function(){var r,i,a,o,u,s,l,c;return(0,pe.__generator)(this,(function(f){switch(f.label){case 0:r=!1,i=!1,f.label=1;case 1:f.trys.push([1,8,9,14]),o=(0,j.default)(e),f.label=2;case 2:return[4,(0,V.default)(o.next())];case 3:return(r=!(u=f.sent()).done)?(s=u.value,l=s,[4,(0,V.default)(n.delete(l,t))]):[3,7];case 4:return f.sent(),[4,l];case 5:f.sent(),f.label=6;case 6:return r=!1,[3,2];case 7:return[3,14];case 8:return c=f.sent(),i=!0,a=c,[3,14];case 9:return f.trys.push([9,,12,13]),r&&null!=o.return?[4,o.return()]:[3,11];case 10:f.sent(),f.label=11;case 11:return[3,13];case 12:if(i)throw a;return[7];case 13:return[7];case 14:return[2]}}))}))()}},{key:"batch",value:function(){var e=[],t=[],n=this;return{put:function(t,n){e.push({key:t,value:n})},delete:function(e){t.push(e)},commit:function(){var r=(0,K.default)((function(r){return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:return[4,Lv(n.putMany(e,r))];case 1:return i.sent(),e=[],[4,Lv(n.deleteMany(t,r))];case 2:return i.sent(),t=[],[2]}}))}));return function(e){return r.apply(this,arguments)}}()}}},{key:"_all",value:function(e,t){return(0,de.default)((function(){return(0,pe.__generator)(this,(function(e){throw Error("._all is not implemented")}))}))()}},{key:"_allKeys",value:function(e,t){return(0,de.default)((function(){return(0,pe.__generator)(this,(function(e){throw Error("._allKeys is not implemented")}))}))()}},{key:"query",value:function(e,t){var n=this._all(e,t);if(null!=e.prefix){var r=e.prefix;n=bw(n,(function(e){return e.key.toString().startsWith(r)}))}if(Array.isArray(e.filters)&&(n=e.filters.reduce((function(e,t){return bw(e,t)}),n)),Array.isArray(e.orders)&&(n=e.orders.reduce((function(e,t){return ww(e,t)}),n)),null!=e.offset){var i=0,a=e.offset;n=bw(n,(function(){return i++>=a}))}return null!=e.limit&&(n=kw(n,e.limit)),n}},{key:"queryKeys",value:function(e,t){var n=this._allKeys(e,t);if(null!=e.prefix){var r=e.prefix;n=bw(n,(function(e){return e.toString().startsWith(r)}))}if(Array.isArray(e.filters)&&(n=e.filters.reduce((function(e,t){return bw(e,t)}),n)),Array.isArray(e.orders)&&(n=e.orders.reduce((function(e,t){return ww(e,t)}),n)),null!=e.offset){var i=e.offset,a=0;n=bw(n,(function(){return a++>=i}))}return null!=e.limit&&(n=kw(n,e.limit)),n}}]),e}(),Ew=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e;return(0,H.default)(this,n),e=t.call(this),(0,te.default)((0,q.default)(e),"data",void 0),e.data=new Map,(0,ue.default)(e)}return(0,$.default)(n,[{key:"put",value:function(e,t){return this.data.set(e.toString(),t),e}},{key:"get",value:function(e){var t=this.data.get(e.toString());if(null==t)throw new mw;return t}},{key:"has",value:function(e){return this.data.has(e.toString())}},{key:"delete",value:function(e){this.data.delete(e.toString())}},{key:"_all",value:function(){var e,t,n,r,i,a,o,u,s;return(0,pe.__generator)(this,(function(l){switch(l.label){case 0:e=!0,t=!1,n=void 0,l.label=1;case 1:l.trys.push([1,6,7,8]),r=this.data.entries()[Symbol.iterator](),l.label=2;case 2:return(e=(i=r.next()).done)?[3,5]:(a=(0,se.default)(i.value,2),o=a[0],u=a[1],[4,{key:new Wb(o),value:u}]);case 3:l.sent(),l.label=4;case 4:return e=!0,[3,2];case 5:return[3,8];case 6:return s=l.sent(),t=!0,n=s,[3,8];case 7:try{e||null==r.return||r.return()}finally{if(t)throw n}return[7];case 8:return[2]}}))}},{key:"_allKeys",value:function(){var e,t,n,r,i,a,o;return(0,pe.__generator)(this,(function(u){switch(u.label){case 0:e=!0,t=!1,n=void 0,u.label=1;case 1:u.trys.push([1,6,7,8]),r=this.data.keys()[Symbol.iterator](),u.label=2;case 2:return(e=(i=r.next()).done)?[3,5]:(a=i.value,[4,new Wb(a)]);case 3:u.sent(),u.label=4;case 4:return e=!0,[3,2];case 5:return[3,8];case 6:return o=u.sent(),t=!0,n=o,[3,8];case 7:try{e||null==r.return||r.return()}finally{if(t)throw n}return[7];case 8:return[2]}}))}}]),n}(_w),Sw=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(e){var r;(0,H.default)(this,n),r=t.call(this),(0,te.default)((0,q.default)(r),"metric",void 0);var i=e.name,a=e.metrics;return r.metric=a.registerMetric(i),r.updateComponentMetric(),r}return(0,$.default)(n,[{key:"set",value:function(e,t){return(0,ne.default)((0,re.default)(n.prototype),"set",this).call(this,e,t),this.updateComponentMetric(),this}},{key:"delete",value:function(e){var t=(0,ne.default)((0,re.default)(n.prototype),"delete",this).call(this,e);return this.updateComponentMetric(),t}},{key:"clear",value:function(){(0,ne.default)((0,re.default)(n.prototype),"clear",this).call(this),this.updateComponentMetric()}},{key:"updateComponentMetric",value:function(){this.metric.update(this.size)}}]),n}((0,he.default)(Map));function Aw(e){var t=e.name,n=e.metrics;return null!=n?new Sw({name:t,metrics:n}):new Map}var Iw=864e13,xw=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"log",void 0),(0,te.default)(this,"mappings",void 0),this.log=t.logger.forComponent("libp2p:address-manager:dns-mappings"),this.mappings=Aw({name:"libp2p_address_manager_dns_mappings",metrics:t.metrics})}return(0,$.default)(e,[{key:"has",value:function(e){var t=this.findHost(e),n=!0,r=!1,i=void 0;try{for(var a,o=this.mappings.values()[Symbol.iterator]();!(n=(a=o.next()).done);n=!0){if(a.value.domain===t)return!0}}catch(e){r=!0,i=e}finally{try{n||null==o.return||o.return()}finally{if(r)throw i}}return!1}},{key:"add",value:function(e,t){var n=this;t.forEach((function(t){n.log("add DNS mapping %s to %s",t,e);var r=!0===Zv(t);n.mappings.set(t,{domain:e,verified:r,expires:r?Iw-Date.now():0,lastVerified:r?Iw-Date.now():void 0})}))}},{key:"remove",value:function(e){var t=this.findHost(e),n=!1,r=!0,i=!1,a=void 0;try{for(var o,u=this.mappings.entries()[Symbol.iterator]();!(r=(o=u.next()).done);r=!0){var s=(0,se.default)(o.value,2),l=s[0],c=s[1];c.domain===t&&(this.log("removing %s to %s DNS mapping %e",l,c.domain,Error("where")),this.mappings.delete(l),n=n||c.verified)}}catch(e){i=!0,a=e}finally{try{r||null==u.return||u.return()}finally{if(i)throw a}}return n}},{key:"getAll",value:function(e){for(var t=[],n=0;n<e.length;n++){var r=e[n].multiaddr.stringTuples(),i=r[0][1],a=!0,o=!1,u=void 0;if(null!=i)try{for(var s,l=this.mappings.entries()[Symbol.iterator]();!(a=(s=l.next()).done);a=!0){var c=(0,se.default)(s.value,2),f=c[0],d=c[1];i===f&&(this.maybeAddSNITuple(r,d.domain)&&(e.splice(n,1),n--,t.push({multiaddr:pf("/"+r.map((function(e){return[gf(e[0]).name,e[1]].join("/")})).join("/")),verified:d.verified,type:"dns-mapping",expires:d.expires,lastVerified:d.lastVerified})))}}catch(e){o=!0,u=e}finally{try{a||null==l.return||l.return()}finally{if(o)throw u}}}return t}},{key:"maybeAddSNITuple",value:function(e,t){for(var n,r=0;r<e.length;r++)if(448===e[r][0]&&449!==(null===(n=e[r+1])||void 0===n?void 0:n[0]))return e.splice(r+1,0,[449,t]),!0;return!1}},{key:"confirm",value:function(e,t){var n=this.findHost(e),r=!1,i=!0,a=!1,o=void 0;try{for(var u,s=this.mappings.entries()[Symbol.iterator]();!(i=(u=s.next()).done);i=!0){var l=(0,se.default)(u.value,2),c=l[0],f=l[1];f.domain===n&&(this.log("marking %s to %s DNS mapping as verified",c,f.domain),r=f.verified,f.verified=!0,f.expires=Date.now()+t,f.lastVerified=Date.now())}}catch(e){a=!0,o=e}finally{try{i||null==s.return||s.return()}finally{if(a)throw o}}return r}},{key:"unconfirm",value:function(e,t){var n=this.findHost(e),r=!1,i=!0,a=!1,o=void 0;try{for(var u,s=this.mappings.entries()[Symbol.iterator]();!(i=(u=s.next()).done);i=!0){var l=(0,se.default)(u.value,2),c=l[0],f=l[1];f.domain===n&&(this.log("removing verification of %s to %s DNS mapping",c,f.domain),r=r||f.verified,f.verified=!1,f.expires=Date.now()+t)}}catch(e){a=!0,o=e}finally{try{i||null==s.return||s.return()}finally{if(a)throw o}}return r}},{key:"findHost",value:function(e){var t=!0,n=!1,r=void 0;try{for(var i,a=e.stringTuples()[Symbol.iterator]();!(t=(i=a.next()).done);t=!0){var o=i.value;if(449===o[0])return o[1];if(53===o[0]||54===o[0]||55===o[0]||56===o[0])return o[1]}}catch(e){n=!0,r=e}finally{try{t||null==a.return||a.return()}finally{if(n)throw r}}}}]),e}(),Cw=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"log",void 0),(0,te.default)(this,"mappings",void 0),this.log=t.logger.forComponent("libp2p:address-manager:ip-mappings"),this.mappings=Aw({name:"libp2p_address_manager_ip_mappings",metrics:t.metrics})}return(0,$.default)(e,[{key:"has",value:function(e){var t=e.stringTuples(),n=!0,r=!1,i=void 0,a=!0,o=!1,u=void 0;try{for(var s,l=this.mappings.values()[Symbol.iterator]();!(a=(s=l.next()).done);a=!0){var c=s.value;try{for(var f,d=c[Symbol.iterator]();!(n=(f=d.next()).done);n=!0){if(f.value.externalIp===t[0][1])return!0}}catch(e){r=!0,i=e}finally{try{n||null==d.return||d.return()}finally{if(r)throw i}}}}catch(e){o=!0,u=e}finally{try{a||null==l.return||l.return()}finally{if(o)throw u}}return!1}},{key:"add",value:function(e,t,n){var r,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t,a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"tcp",o="".concat(e,"-").concat(t,"-").concat(a),u=null!==(r=this.mappings.get(o))&&void 0!==r?r:[],s={internalIp:e,internalPort:t,externalIp:n,externalPort:i,externalFamily:Dc(n)?4:6,protocol:a,verified:!1,expires:0};u.push(s),this.mappings.set(o,u)}},{key:"remove",value:function(e){var t,n,r=e.stringTuples(),i=null!==(t=r[0][1])&&void 0!==t?t:"",a=6===r[1][0]?"tcp":"udp",o=parseInt(null!==(n=r[1][1])&&void 0!==n?n:"0"),u=!1,s=!0,l=!1,c=void 0;try{for(var f,d=this.mappings.entries()[Symbol.iterator]();!(s=(f=d.next()).done);s=!0){for(var h=(0,se.default)(f.value,2),v=h[0],p=h[1],g=0;g<p.length;g++){var y=p[g];y.externalIp===i&&y.externalPort===o&&y.protocol===a&&(this.log("removing %s:%s to %s:%s %s IP mapping",y.externalIp,y.externalPort,i,o,a),u=u||y.verified,p.splice(g,1),g--)}0===p.length&&this.mappings.delete(v)}}catch(e){l=!0,c=e}finally{try{s||null==d.return||d.return()}finally{if(l)throw c}}return u}},{key:"getAll",value:function(e){var t=[],n=!0,r=!1,i=void 0;try{for(var a,o=e[Symbol.iterator]();!(n=(a=o.next()).done);n=!0){var u=a.value.multiaddr.stringTuples(),s=void 0;if(4!==u[0][0]&&41!==u[0][0]||6!==u[1][0]?4!==u[0][0]&&41!==u[0][0]||273!==u[1][0]||(s="".concat(u[0][1],"-").concat(u[1][1],"-udp")):s="".concat(u[0][1],"-").concat(u[1][1],"-tcp"),null!=s){var l=this.mappings.get(s),c=!0,f=!1,d=void 0;if(null!=l)try{for(var h,v=l[Symbol.iterator]();!(c=(h=v.next()).done);c=!0){var p=h.value;u[0][0]=4===p.externalFamily?4:41,u[0][1]=p.externalIp,u[1][1]=""+p.externalPort,t.push({multiaddr:pf("/"+u.map((function(e){return[gf(e[0]).name,e[1]].join("/")})).join("/")),verified:p.verified,type:"ip-mapping",expires:p.expires,lastVerified:p.lastVerified})}}catch(e){f=!0,d=e}finally{try{c||null==v.return||v.return()}finally{if(f)throw d}}}}}catch(e){r=!0,i=e}finally{try{n||null==o.return||o.return()}finally{if(r)throw i}}return t}},{key:"confirm",value:function(e,t){var n=e.stringTuples()[0][1],r=!1,i=!0,a=!1,o=void 0,u=!0,s=!1,l=void 0;try{for(var c,f=this.mappings.values()[Symbol.iterator]();!(u=(c=f.next()).done);u=!0){var d=c.value;try{for(var h,v=d[Symbol.iterator]();!(i=(h=v.next()).done);i=!0){var p=h.value;p.externalIp===n&&(this.log("marking %s to %s IP mapping as verified",p.internalIp,p.externalIp),r=p.verified,p.verified=!0,p.expires=Date.now()+t,p.lastVerified=Date.now())}}catch(e){a=!0,o=e}finally{try{i||null==v.return||v.return()}finally{if(a)throw o}}}}catch(e){s=!0,l=e}finally{try{u||null==f.return||f.return()}finally{if(s)throw l}}return r}},{key:"unconfirm",value:function(e,t){var n,r,i=e.stringTuples(),a=null!==(n=i[0][1])&&void 0!==n?n:"",o=6===i[1][0]?"tcp":"udp",u=parseInt(null!==(r=i[1][1])&&void 0!==r?r:"0"),s=!1,l=!0,c=!1,f=void 0;try{for(var d,h=this.mappings.values()[Symbol.iterator]();!(l=(d=h.next()).done);l=!0)for(var v=d.value,p=0;p<v.length;p++){var g=v[p];g.externalIp===a&&g.externalPort===u&&g.protocol===o&&(this.log("removing verification of %s:%s to %s:%s %s IP mapping",g.externalIp,g.externalPort,a,u,o),s=s||g.verified,g.verified=!1,g.expires=Date.now()+t)}}catch(e){c=!0,f=e}finally{try{l||null==h.return||h.return()}finally{if(c)throw f}}return s}}]),e}(),Tw=function(){"use strict";function e(t){var n,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};(0,H.default)(this,e),(0,te.default)(this,"log",void 0),(0,te.default)(this,"addresses",void 0),(0,te.default)(this,"maxObservedAddresses",void 0),this.log=t.logger.forComponent("libp2p:address-manager:observed-addresses"),this.addresses=Aw({name:"libp2p_address_manager_observed_addresses",metrics:t.metrics}),this.maxObservedAddresses=null!==(n=r.maxObservedAddresses)&&void 0!==n?n:10}return(0,$.default)(e,[{key:"has",value:function(e){return this.addresses.has(e.toString())}},{key:"removePrefixed",value:function(e){var t=!0,n=!1,r=void 0;try{for(var i,a=this.addresses.keys()[Symbol.iterator]();!(t=(i=a.next()).done);t=!0){var o=i.value;o.toString().startsWith(e)&&this.addresses.delete(o)}}catch(e){n=!0,r=e}finally{try{t||null==a.return||a.return()}finally{if(n)throw r}}}},{key:"add",value:function(e){this.addresses.size!==this.maxObservedAddresses&&(Jv(e)||function(e){try{var t=!0,n=!1,r=void 0;try{for(var i,a=e.getComponents()[Symbol.iterator]();!(t=(i=a.next()).done);t=!0){var o=i.value,u=o.code,s=o.value;if(u!==Oc&&null!=s){if(4===u)return s.startsWith("169.254.");if(u===Nc)return s.toLowerCase().startsWith("fe80")}}}catch(e){n=!0,r=e}finally{try{t||null==a.return||a.return()}finally{if(n)throw r}}}catch(e){}return!1}(e)||(this.log("adding observed address %a",e),this.addresses.set(e.toString(),{verified:!1,expires:0})))}},{key:"getAll",value:function(){return Array.from(this.addresses).map((function(e){var t=(0,se.default)(e,2),n=t[0],r=t[1];return{multiaddr:pf(n),verified:r.verified,type:"observed",expires:r.expires,lastVerified:r.lastVerified}}))}},{key:"remove",value:function(e){var t,n,r=null!==(n=null===(t=this.addresses.get(e.toString()))||void 0===t?void 0:t.verified)&&void 0!==n&&n;return this.log("removing observed address %a",e),this.addresses.delete(e.toString()),r}},{key:"confirm",value:function(e,t){var n,r=e.toString(),i=null!==(n=this.addresses.get(r))&&void 0!==n?n:{verified:!1,expires:Date.now()+t,lastVerified:Date.now()},a=i.verified;return i.verified=!0,i.expires=Date.now()+t,i.lastVerified=Date.now(),this.log("marking observed address %a as verified",r),this.addresses.set(r,i),a}}]),e}(),Pw=[4,Nc,53,54,55,56];function Rw(e){try{var t=!0,n=!1,r=void 0;try{for(var i,a=e.getComponents()[Symbol.iterator]();!(t=(i=a.next()).done);t=!0){var o=i.value.code;if(o!==Oc)return Pw.includes(o)}}catch(e){n=!0,r=e}finally{try{t||null==a.return||a.return()}finally{if(n)throw r}}}catch(e){}return!1}var Lw=function(){"use strict";function e(t){var n,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};(0,H.default)(this,e),(0,te.default)(this,"log",void 0),(0,te.default)(this,"addresses",void 0),(0,te.default)(this,"maxObservedAddresses",void 0),this.log=t.logger.forComponent("libp2p:address-manager:observed-addresses"),this.addresses=Aw({name:"libp2p_address_manager_transport_addresses",metrics:t.metrics}),this.maxObservedAddresses=null!==(n=r.maxObservedAddresses)&&void 0!==n?n:10}return(0,$.default)(e,[{key:"get",value:function(e,t){if(Jv(e))return{multiaddr:e,verified:!0,type:"transport",expires:Date.now()+t,lastVerified:Date.now()};var n=this.toKey(e),r=this.addresses.get(n);return null==r&&(r={verified:!Rw(e),expires:0},this.addresses.set(n,r)),{multiaddr:e,verified:r.verified,type:"transport",expires:r.expires,lastVerified:r.lastVerified}}},{key:"has",value:function(e){var t=this.toKey(e);return this.addresses.has(t)}},{key:"remove",value:function(e){var t,n,r=this.toKey(e),i=null!==(n=null===(t=this.addresses.get(r))||void 0===t?void 0:t.verified)&&void 0!==n&&n;return this.log("removing observed address %a",e),this.addresses.delete(r),i}},{key:"confirm",value:function(e,t){var n,r=this.toKey(e),i=null!==(n=this.addresses.get(r))&&void 0!==n?n:{verified:!1,expires:0,lastVerified:0},a=i.verified;return i.verified=!0,i.expires=Date.now()+t,i.lastVerified=Date.now(),this.addresses.set(r,i),a}},{key:"unconfirm",value:function(e,t){var n,r=this.toKey(e),i=null!==(n=this.addresses.get(r))&&void 0!==n?n:{verified:!1,expires:0},a=i.verified;return i.verified=!1,i.expires=Date.now()+t,this.addresses.set(r,i),a}},{key:"toKey",value:function(e){if(Rw(e)){var t=e.toOptions();return"".concat(t.host,"-").concat(t.port,"-").concat(t.transport)}return e.toString()}}]),e}(),Dw=6e5,Mw=3e5,Nw=function(e){return e};function Ow(e,t){var n=e.getPeerId();return null!=n&&kc(n).equals(t)&&(e=e.decapsulate(pf("/p2p/"+t.toString()))),e}var Uw,Fw=Symbol.toStringTag,Bw=function(){"use strict";function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=this;(0,H.default)(this,e),(0,te.default)(this,"log",void 0),(0,te.default)(this,"components",void 0),(0,te.default)(this,"listen",void 0),(0,te.default)(this,"announce",void 0),(0,te.default)(this,"appendAnnounce",void 0),(0,te.default)(this,"announceFilter",void 0),(0,te.default)(this,"observed",void 0),(0,te.default)(this,"dnsMappings",void 0),(0,te.default)(this,"ipMappings",void 0),(0,te.default)(this,"transportAddresses",void 0),(0,te.default)(this,"observedAddressFilter",void 0),(0,te.default)(this,"addressVerificationTTL",void 0),(0,te.default)(this,"addressVerificationRetry",void 0),(0,te.default)(this,Fw,"@libp2p/address-manager");var i,a,o,u=n.listen,s=void 0===u?[]:u,l=n.announce,c=void 0===l?[]:l,f=n.appendAnnounce,d=void 0===f?[]:f;this.components=t,this.log=t.logger.forComponent("libp2p:address-manager"),this.listen=s.map((function(e){return e.toString()})),this.announce=new Set(c.map((function(e){return e.toString()}))),this.appendAnnounce=new Set(d.map((function(e){return e.toString()}))),this.observed=new Tw(t,n),this.dnsMappings=new xw(t,n),this.ipMappings=new Cw(t,n),this.transportAddresses=new Lw(t,n),this.announceFilter=null!==(i=n.announceFilter)&&void 0!==i?i:Nw,this.observedAddressFilter=Jm(1024),this.addressVerificationTTL=null!==(a=n.addressVerificationTTL)&&void 0!==a?a:Dw,this.addressVerificationRetry=null!==(o=n.addressVerificationRetry)&&void 0!==o?o:Mw,this._updatePeerStoreAddresses=Rv(this._updatePeerStoreAddresses.bind(this),1e3),t.events.addEventListener("transport:listening",(function(){r._updatePeerStoreAddresses()})),t.events.addEventListener("transport:close",(function(){r._updatePeerStoreAddresses()}))}return(0,$.default)(e,[{key:"_updatePeerStoreAddresses",value:function(){var e=this,t=this.getAddresses().map((function(t){return t.getPeerId()===e.components.peerId.toString()?t.decapsulate("/p2p/"+e.components.peerId.toString()):t}));this.components.peerStore.patch(this.components.peerId,{multiaddrs:t}).catch((function(t){e.log.error("error updating addresses",t)}))}},{key:"getListenAddrs",value:function(){return Array.from(this.listen).map((function(e){return pf(e)}))}},{key:"getAnnounceAddrs",value:function(){return Array.from(this.announce).map((function(e){return pf(e)}))}},{key:"getAppendAnnounceAddrs",value:function(){return Array.from(this.appendAnnounce).map((function(e){return pf(e)}))}},{key:"getObservedAddrs",value:function(){return this.observed.getAll().map((function(e){return e.multiaddr}))}},{key:"addObservedAddr",value:function(e){var t=e.stringTuples(),n="".concat(t[0][1],":").concat(t[1][1]);this.observedAddressFilter.has(n)||(this.observedAddressFilter.add(n),e=Ow(e,this.components.peerId),this.ipMappings.has(e)||this.dnsMappings.has(e)||this.observed.add(e))}},{key:"confirmObservedAddr",value:function(e,t){e=Ow(e,this.components.peerId);var n,r,i,a,o,u=!0;(("transport"===(null==t?void 0:t.type)||this.transportAddresses.has(e))&&!this.transportAddresses.confirm(e,null!==(n=null==t?void 0:t.ttl)&&void 0!==n?n:this.addressVerificationTTL)&&u&&(u=!1),("dns-mapping"===(null==t?void 0:t.type)||this.dnsMappings.has(e))&&!this.dnsMappings.confirm(e,null!==(r=null==t?void 0:t.ttl)&&void 0!==r?r:this.addressVerificationTTL)&&u&&(u=!1),("ip-mapping"===(null==t?void 0:t.type)||this.ipMappings.has(e))&&!this.ipMappings.confirm(e,null!==(i=null==t?void 0:t.ttl)&&void 0!==i?i:this.addressVerificationTTL)&&u&&(u=!1),"observed"===(null==t?void 0:t.type)||this.observed.has(e))&&(this.maybeUpgradeToIPMapping(e)?(this.ipMappings.confirm(e,null!==(a=null==t?void 0:t.ttl)&&void 0!==a?a:this.addressVerificationTTL),u=!1):!this.observed.confirm(e,null!==(o=null==t?void 0:t.ttl)&&void 0!==o?o:this.addressVerificationTTL)&&u&&(u=!1));u||this._updatePeerStoreAddresses()}},{key:"removeObservedAddr",value:function(e,t){var n,r,i;e=Ow(e,this.components.peerId),this.observed.has(e)&&this.observed.remove(e),this.transportAddresses.has(e)&&this.transportAddresses.unconfirm(e,null!==(n=null==t?void 0:t.ttl)&&void 0!==n?n:this.addressVerificationRetry),this.dnsMappings.has(e)&&this.dnsMappings.unconfirm(e,null!==(r=null==t?void 0:t.ttl)&&void 0!==r?r:this.addressVerificationRetry),this.ipMappings.has(e)&&this.ipMappings.unconfirm(e,null!==(i=null==t?void 0:t.ttl)&&void 0!==i?i:this.addressVerificationRetry)}},{key:"getAddresses",value:function(){var e=this,t=new Set,n=this.getAddressesWithMetadata().filter((function(e){if(!e.verified)return!1;var n=e.multiaddr.toString();return!t.has(n)&&(t.add(n),!0)})).map((function(e){return e.multiaddr}));return this.announceFilter(n.map((function(t){var n=pf(t),r=n.getComponents().pop();return(null==r?void 0:r.value)===e.components.peerId.toString()?n:n.encapsulate("/p2p/"+e.components.peerId.toString())})))}},{key:"getAddressesWithMetadata",value:function(){var e=this,t=this.getAnnounceAddrs();if(t.length>0)return this.components.transportManager.getListeners().forEach((function(e){e.updateAnnounceAddrs(t)})),t.map((function(t){return{multiaddr:t,verified:!0,type:"announce",expires:Date.now()+e.addressVerificationTTL,lastVerified:Date.now()}}));var n=[];n=n.concat(this.components.transportManager.getAddrs().map((function(t){return e.transportAddresses.get(t,e.addressVerificationTTL)})));var r=this.getAppendAnnounceAddrs();return r.length>0&&(this.components.transportManager.getListeners().forEach((function(e){e.updateAnnounceAddrs(r)})),n=n.concat(r.map((function(t){return{multiaddr:t,verified:!0,type:"announce",expires:Date.now()+e.addressVerificationTTL,lastVerified:Date.now()}})))),n=(n=(n=n.concat(this.observed.getAll())).concat(this.ipMappings.getAll(n))).concat(this.dnsMappings.getAll(n))}},{key:"addDNSMapping",value:function(e,t){this.dnsMappings.add(e,t)}},{key:"removeDNSMapping",value:function(e){this.dnsMappings.remove(pf("/dns/"+e))&&this._updatePeerStoreAddresses()}},{key:"addPublicAddressMapping",value:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t,i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"tcp";this.ipMappings.add(e,t,n,r,i),this.observed.removePrefixed("/ip".concat(Dc(n)?4:6,"/").concat(n,"/").concat(i,"/").concat(r))}},{key:"removePublicAddressMapping",value:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t,i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"tcp";this.ipMappings.remove(pf("/ip".concat(Dc(n)?4:6,"/").concat(n,"/").concat(i,"/").concat(r)))&&this._updatePeerStoreAddresses()}},{key:"maybeUpgradeToIPMapping",value:function(e){if(this.ipMappings.has(e))return!1;var t=e.toOptions();if(6===t.family||"127.0.0.1"===t.host||!0===Zv(t.host))return!1;var n=this.components.transportManager.getListeners(),r=[function(e){return Pp.exactMatch(e)||Lp.exactMatch(e)},function(e){return Ep.exactMatch(e)},function(e){return xp.exactMatch(e)}],i=!0,a=!1,o=void 0;try{for(var u,s=this,l=function(){var r=u.value;if(!r(e))return"continue";var i=n.filter((function(e){return e.getAddrs().filter((function(e){return 4===e.toOptions().family&&r(e)})).length>0}));if(1!==i.length)return"continue";var a=i[0].getAddrs().filter((function(e){return"127.0.0.1"!==e.toOptions().host})).pop();if(null==a)return"continue";var o=a.toOptions();return{v:(s.observed.remove(e),s.ipMappings.add(o.host,o.port,t.host,t.port,t.transport),!0)}},c=r[Symbol.iterator]();!(i=(u=c.next()).done);i=!0){var f=l();if("object"===(0,fe.default)(f))return f.v}}catch(e){a=!0,o=e}finally{try{i||null==c.return||c.return()}finally{if(a)throw o}}return!1}}]),e}();!function(e){e.NOT_STARTED_YET="The libp2p node is not started yet",e.NOT_FOUND="Not found"}(Uw||(Uw={}));var qw=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Missing service";return(0,H.default)(this,n),(e=t.call(this,r)).name="MissingServiceError",(0,ue.default)(e)}return n}((0,he.default)(Error)),zw=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Unmet service dependencies";return(0,H.default)(this,n),(e=t.call(this,r)).name="UnmetServiceDependenciesError",(0,ue.default)(e)}return n}((0,he.default)(Error)),jw=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"No content routers available";return(0,H.default)(this,n),(e=t.call(this,r)).name="NoContentRoutersError",(0,ue.default)(e)}return n}((0,he.default)(Error)),Kw=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"No peer routers available";return(0,H.default)(this,n),(e=t.call(this,r)).name="NoPeerRoutersError",(0,ue.default)(e)}return n}((0,he.default)(Error)),Vw=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Should not try to find self";return(0,H.default)(this,n),(e=t.call(this,r)).name="QueriedForSelfError",(0,ue.default)(e)}return n}((0,he.default)(Error)),Hw=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Unhandled protocol error";return(0,H.default)(this,n),(e=t.call(this,r)).name="UnhandledProtocolError",(0,ue.default)(e)}return n}((0,he.default)(Error)),Ww=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Duplicate protocol handler error";return(0,H.default)(this,n),(e=t.call(this,r)).name="DuplicateProtocolHandlerError",(0,ue.default)(e)}return n}((0,he.default)(Error)),Gw=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Dial denied error";return(0,H.default)(this,n),(e=t.call(this,r)).name="DialDeniedError",(0,ue.default)(e)}return n}((0,he.default)(Error)),Xw=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"No transport was configured to listen on this address";return(0,H.default)(this,n),(e=t.call(this,r)).name="UnsupportedListenAddressError",(0,ue.default)(e)}return n}((0,he.default)(Error)),Yw=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Configured listen addresses could not be listened on";return(0,H.default)(this,n),(e=t.call(this,r)).name="UnsupportedListenAddressesError",(0,ue.default)(e)}return n}((0,he.default)(Error)),Zw=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"No valid addresses";return(0,H.default)(this,n),(e=t.call(this,r)).name="NoValidAddressesError",(0,ue.default)(e)}return n}((0,he.default)(Error)),Qw=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Connection intercepted";return(0,H.default)(this,n),(e=t.call(this,r)).name="ConnectionInterceptedError",(0,ue.default)(e)}return n}((0,he.default)(Error)),Jw=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Connection denied";return(0,H.default)(this,n),(e=t.call(this,r)).name="ConnectionDeniedError",(0,ue.default)(e)}return n}((0,he.default)(Error)),$w=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Stream is not multiplexed";return(0,H.default)(this,n),(e=t.call(this,r)).name="MuxerUnavailableError",(0,ue.default)(e)}return n}((0,he.default)(Error)),ek=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Encryption failed";return(0,H.default)(this,n),(e=t.call(this,r)).name="EncryptionFailedError",(0,ue.default)(e)}return n}((0,he.default)(Error)),tk=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Transport unavailable";return(0,H.default)(this,n),(e=t.call(this,r)).name="TransportUnavailableError",(0,ue.default)(e)}return n}((0,he.default)(Error)),nk=function(){"use strict";function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};(0,H.default)(this,e),(0,te.default)(this,"components",{}),(0,te.default)(this,"_started",!1),this.components={};var n=!0,r=!1,i=void 0;try{for(var a,o=Object.entries(t)[Symbol.iterator]();!(n=(a=o.next()).done);n=!0){var u=(0,se.default)(a.value,2),s=u[0],l=u[1];this.components[s]=l}}catch(e){r=!0,i=e}finally{try{n||null==o.return||o.return()}finally{if(r)throw i}}null==this.components.logger&&(this.components.logger=Dm())}return(0,$.default)(e,[{key:"isStarted",value:function(){return this._started}},{key:"_invokeStartableMethod",value:function(e){var t=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:return[4,Promise.all(Object.values(t.components).filter((function(e){return Ca(e)})).map(function(){var t=(0,K.default)((function(t){var n;return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return[4,null===(n=t[e])||void 0===n?void 0:n.call(t)];case 1:return r.sent(),[2]}}))}));return function(e){return t.apply(this,arguments)}}()))];case 1:return n.sent(),[2]}}))}))()}},{key:"beforeStart",value:function(){var e=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return[4,e._invokeStartableMethod("beforeStart")];case 1:return t.sent(),[2]}}))}))()}},{key:"start",value:function(){var e=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return[4,e._invokeStartableMethod("start")];case 1:return t.sent(),e._started=!0,[2]}}))}))()}},{key:"afterStart",value:function(){var e=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return[4,e._invokeStartableMethod("afterStart")];case 1:return t.sent(),[2]}}))}))()}},{key:"beforeStop",value:function(){var e=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return[4,e._invokeStartableMethod("beforeStop")];case 1:return t.sent(),[2]}}))}))()}},{key:"stop",value:function(){var e=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return[4,e._invokeStartableMethod("stop")];case 1:return t.sent(),e._started=!1,[2]}}))}))()}},{key:"afterStop",value:function(){var e=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return[4,e._invokeStartableMethod("afterStop")];case 1:return t.sent(),[2]}}))}))()}}]),e}(),rk=["metrics","connectionProtector","dns"],ik=["components","isStarted","beforeStart","start","afterStart","beforeStop","stop","afterStop","then","_invokeStartableMethod"];function ak(e){return Array.isArray(null==e?void 0:e[Ta])?e[Ta]:[]}function ok(e){return Array.isArray(null==e?void 0:e[Pa])?e[Pa]:[]}function uk(e){var t,n;return null!==(n=null!==(t=null==e?void 0:e[Symbol.toStringTag])&&void 0!==t?t:null==e?void 0:e.toString())&&void 0!==n?n:"unknown"}function sk(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return(0,ae.default)({denyDialPeer:function(){return(0,K.default)((function(){return(0,pe.__generator)(this,(function(e){return[2,!1]}))}))()},denyDialMultiaddr:function(e){return(0,K.default)((function(){var t;return(0,pe.__generator)(this,(function(n){return Pp.matches(e)?[2,!1]:[2,(4===(t=e.stringTuples())[0][0]||41===t[0][0])&&!!Zv(""+t[0][1])]}))}))()},denyInboundConnection:function(){return(0,K.default)((function(){return(0,pe.__generator)(this,(function(e){return[2,!1]}))}))()},denyOutboundConnection:function(){return(0,K.default)((function(){return(0,pe.__generator)(this,(function(e){return[2,!1]}))}))()},denyInboundEncryptedConnection:function(){return(0,K.default)((function(){return(0,pe.__generator)(this,(function(e){return[2,!1]}))}))()},denyOutboundEncryptedConnection:function(){return(0,K.default)((function(){return(0,pe.__generator)(this,(function(e){return[2,!1]}))}))()},denyInboundUpgradedConnection:function(){return(0,K.default)((function(){return(0,pe.__generator)(this,(function(e){return[2,!1]}))}))()},denyOutboundUpgradedConnection:function(){return(0,K.default)((function(){return(0,pe.__generator)(this,(function(e){return[2,!1]}))}))()},filterMultiaddrForPeer:function(){return(0,K.default)((function(){return(0,pe.__generator)(this,(function(e){return[2,!0]}))}))()}},e)}function lk(e){if(Yi(e))return{peerId:e,multiaddrs:[]};var t,n=Array.isArray(e)?e:[e];if(n.length>0){var r=n[0].getPeerId();t=null==r?void 0:kc(r),n.forEach((function(e){if(!vf(e))throw new ha("Invalid multiaddr");var n=e.getPeerId();if(null==n){if(null!=t)throw new ra("Multiaddrs must all have the same peer id or have no peer id")}else{var r=kc(n);if(!0!==(null==t?void 0:t.equals(r)))throw new ra("Multiaddrs must all have the same peer id or have no peer id")}}))}return n=n.filter((function(e){return!lp.exactMatch(e)})),{peerId:t,multiaddrs:n}}var ck=["/ipfs/id/1.0.0","/ipfs/id/push/1.0.0","/libp2p/autonat/1.0.0","/libp2p/dcutr"];function fk(e){try{var t;if(!(t="string"==typeof e?pf(e):e).protoNames().includes("ipcidr")){var n=t.protoNames().includes("ip6")?"/ipcidr/128":"/ipcidr/32";t=t.encapsulate(n)}return function(e){var t,n;if(e.getComponents().forEach((function(e){"ip4"!==e.name&&"ip6"!==e.name||(n=e.value),"ipcidr"===e.name&&(t=e.value)})),null==t||null==n)throw Error("Invalid multiaddr");return new cf(n,t)}(t)}catch(t){throw Error("Can't convert to IpNet, Invalid multiaddr format: "+e)}}var dk=function(){"use strict";function e(t){var n,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};(0,H.default)(this,e),(0,te.default)(this,"connectionManager",void 0),(0,te.default)(this,"peerStore",void 0),(0,te.default)(this,"allow",void 0),(0,te.default)(this,"events",void 0),(0,te.default)(this,"log",void 0),this.allow=(null!==(n=r.allow)&&void 0!==n?n:[]).map((function(e){return fk(e)})),this.connectionManager=t.connectionManager,this.peerStore=t.peerStore,this.events=t.events,this.log=t.logger.forComponent("libp2p:connection-manager:connection-pruner"),this.maybePruneConnections=this.maybePruneConnections.bind(this)}return(0,$.default)(e,[{key:"start",value:function(){this.events.addEventListener("connection:open",this.maybePruneConnections)}},{key:"stop",value:function(){this.events.removeEventListener("connection:open",this.maybePruneConnections)}},{key:"maybePruneConnections",value:function(){var e=this;this._maybePruneConnections().catch((function(t){e.log.error("error while pruning connections %e",t)}))}},{key:"_maybePruneConnections",value:function(){var e=this;return(0,K.default)((function(){var t,n,r,i,a,o,u,s,l,c,f,d,h,v,p,g,y,m,b,w,k,_,E;return(0,pe.__generator)(this,(function(S){switch(S.label){case 0:if(t=e.connectionManager.getConnections(),n=t.length,r=e.connectionManager.getMaxConnections(),e.log("checking max connections limit %d/%d",n,r),n<=r)return[2];i=new Bm,a=!0,o=!1,u=void 0,S.label=1;case 1:S.trys.push([1,8,9,10]),s=t[Symbol.iterator](),S.label=2;case 2:if(a=(l=s.next()).done)return[3,7];if(c=l.value,f=c.remotePeer,i.has(f))return[3,6];i.set(f,0),S.label=3;case 3:return S.trys.push([3,5,,6]),[4,e.peerStore.get(f)];case 4:return d=S.sent(),i.set(f,(0,ce.default)(d.tags.values()).reduce((function(e,t){return e+t.value}),0)),[3,6];case 5:return"NotFoundError"!==(h=S.sent()).name&&e.log.error("error loading peer tags",h),[3,6];case 6:return a=!0,[3,2];case 7:return[3,10];case 8:return v=S.sent(),o=!0,u=v,[3,10];case 9:try{a||null==s.return||s.return()}finally{if(o)throw u}return[7];case 10:p=e.sortConnections(t,i),g=Math.max(n-r,0),y=[],m=!0,b=!1,w=void 0;try{for(k=p[Symbol.iterator]();!(m=(_=k.next()).done)&&(E=_.value,e.log("too many connections open - closing a connection to %p",E.remotePeer),e.allow.some((function(e){return e.contains(E.remoteAddr.nodeAddress().address)}))||y.push(E),y.length!==g);m=!0);}catch(e){b=!0,w=e}finally{try{m||null==k.return||k.return()}finally{if(b)throw w}}return[4,Promise.all(y.map(function(){var e=(0,K.default)((function(e){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return[4,function(){var e=(0,K.default)((function(e,t){var n,r,i,a,o,u;return(0,pe.__generator)(this,(function(s){switch(s.label){case 0:if(a=null!==(r=null==e||null===(n=e.streams)||void 0===n?void 0:n.map((function(e){return e.protocol})))&&void 0!==r?r:[],o=null!==(i=null==t?void 0:t.closableProtocols)&&void 0!==i?i:ck,a.filter((function(e){return null!=e&&!o.includes(e)})).length>0)return[3,4];s.label=1;case 1:return s.trys.push([1,3,,4]),[4,null==e?void 0:e.close(t)];case 2:return s.sent(),[3,4];case 3:return u=s.sent(),null==e||e.abort(u),[3,4];case 4:return[2]}}))}));return function(t,n){return e.apply(this,arguments)}}()(e,{signal:AbortSignal.timeout(1e3)})];case 1:return t.sent(),[2]}}))}));return function(t){return e.apply(this,arguments)}}()))];case 11:return S.sent(),e.events.safeDispatchEvent("connection:prune",{detail:y}),[2]}}))}))()}},{key:"sortConnections",value:function(e,t){return e.sort((function(e,t){var n=e.timeline.open,r=t.timeline.open;return n<r?1:n>r?-1:0})).sort((function(e,t){return"outbound"===e.direction&&"inbound"===t.direction?1:"inbound"===e.direction&&"outbound"===t.direction?-1:0})).sort((function(e,t){return e.streams.length>t.streams.length?1:e.streams.length<t.streams.length?-1:0})).sort((function(e,n){var r,i,a=null!==(r=t.get(e.remotePeer))&&void 0!==r?r:0,o=null!==(i=t.get(n.remotePeer))&&void 0!==i?i:0;return a>o?1:a<o?-1:0}))}}]),e}(),hk=function(){"use strict";function e(t){var n;(0,H.default)(this,e),(0,te.default)(this,"deferred",void 0),(0,te.default)(this,"signal",void 0),this.signal=t,this.deferred=Io(),this.onAbort=this.onAbort.bind(this),null===(n=this.signal)||void 0===n||n.addEventListener("abort",this.onAbort)}return(0,$.default)(e,[{key:"onAbort",value:function(){var e,t;this.deferred.reject(null!==(t=null===(e=this.signal)||void 0===e?void 0:e.reason)&&void 0!==t?t:new ea)}},{key:"cleanup",value:function(){var e;null===(e=this.signal)||void 0===e||e.removeEventListener("abort",this.onAbort)}}]),e}(),vk=function(){"use strict";function e(t,n){(0,H.default)(this,e),(0,te.default)(this,"id",void 0),(0,te.default)(this,"fn",void 0),(0,te.default)(this,"options",void 0),(0,te.default)(this,"recipients",void 0),(0,te.default)(this,"status",void 0),(0,te.default)(this,"timeline",void 0),(0,te.default)(this,"controller",void 0),this.id="".concat(parseInt(1e9*Math.random()+"",10).toString()).concat(Date.now()),this.status="queued",this.fn=t,this.options=n,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.onAbort=this.onAbort.bind(this)}return(0,$.default)(e,[{key:"abort",value:function(e){this.controller.abort(e)}},{key:"onAbort",value:function(){this.recipients.reduce((function(e,t){var n;return e&&!0===(null===(n=t.signal)||void 0===n?void 0:n.aborted)}),!0)&&(this.controller.abort(new ea),this.cleanup())}},{key:"join",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=this;return(0,K.default)((function(){var n,r;return(0,pe.__generator)(this,(function(i){return r=new hk(e.signal),[2,(t.recipients.push(r),null===(n=e.signal)||void 0===n||n.addEventListener("abort",t.onAbort),r.deferred.promise)]}))}))()}},{key:"run",value:function(){var e=this;return(0,K.default)((function(){var t,n,r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:e.status="running",e.timeline.started=Date.now(),i.label=1;case 1:return i.trys.push([1,3,4,5]),e.controller.signal.throwIfAborted(),[4,Lo(e.fn((0,oe.default)((0,ae.default)({},null!==(t=e.options)&&void 0!==t?t:{}),{signal:e.controller.signal})),e.controller.signal)];case 2:return n=i.sent(),e.recipients.forEach((function(e){e.deferred.resolve(n)})),e.status="complete",[3,5];case 3:return r=i.sent(),e.recipients.forEach((function(e){e.deferred.reject(r)})),e.status="errored",[3,5];case 4:return e.timeline.finished=Date.now(),e.cleanup(),[7];case 5:return[2]}}))}))()}},{key:"cleanup",value:function(){var e=this;this.recipients.forEach((function(t){var n;t.cleanup(),null===(n=t.signal)||void 0===n||n.removeEventListener("abort",e.onAbort)}))}}]),e}(),pk=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r,i,a,o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return(0,H.default)(this,n),e=t.call(this),(0,te.default)((0,q.default)(e),"concurrency",void 0),(0,te.default)((0,q.default)(e),"maxSize",void 0),(0,te.default)((0,q.default)(e),"queue",void 0),(0,te.default)((0,q.default)(e),"pending",void 0),(0,te.default)((0,q.default)(e),"sort",void 0),e.concurrency=null!==(i=o.concurrency)&&void 0!==i?i:1/0,e.maxSize=null!==(a=o.maxSize)&&void 0!==a?a:1/0,e.pending=0,null!=o.metricName&&(null===(r=o.metrics)||void 0===r||r.registerMetricGroup(o.metricName,{calculate:function(){return{size:e.queue.length,running:e.pending,queued:e.queue.length-e.pending}}})),e.sort=o.sort,e.queue=[],e.emitEmpty=Rv(e.emitEmpty.bind((0,q.default)(e)),1),e.emitIdle=Rv(e.emitIdle.bind((0,q.default)(e)),1),(0,ue.default)(e)}return(0,$.default)(n,[{key:"emitEmpty",value:function(){0===this.size&&this.safeDispatchEvent("empty")}},{key:"emitIdle",value:function(){0===this.running&&this.safeDispatchEvent("idle")}},{key:"tryToStartAnother",value:function(){var e=this;if(0===this.size)return this.emitEmpty(),0===this.running&&this.emitIdle(),!1;if(this.pending<this.concurrency){var t,n=!0,r=!1,i=void 0;try{for(var a,o=this.queue[Symbol.iterator]();!(n=(a=o.next()).done);n=!0){var u=a.value;if("queued"===u.status){t=u;break}}}catch(e){r=!0,i=e}finally{try{n||null==o.return||o.return()}finally{if(r)throw i}}return null!=t&&(this.safeDispatchEvent("active"),this.pending++,t.run().finally((function(){for(var n=0;n<e.queue.length;n++)if(e.queue[n]===t){e.queue.splice(n,1);break}e.pending--,e.tryToStartAnother(),e.safeDispatchEvent("next")})),!0)}return!1}},{key:"enqueue",value:function(e){this.queue.push(e),null!=this.sort&&this.queue.sort(this.sort)}},{key:"add",value:function(e,t){var n=this;return(0,K.default)((function(){var r,i;return(0,pe.__generator)(this,(function(a){if(null==t||null===(r=t.signal)||void 0===r||r.throwIfAborted(),n.size===n.maxSize)throw new Yp;return i=new vk(e,t),[2,(n.enqueue(i),n.safeDispatchEvent("add"),n.tryToStartAnother(),i.join(t).then((function(e){return n.safeDispatchEvent("completed",{detail:e}),n.safeDispatchEvent("success",{detail:{job:i,result:e}}),e})).catch((function(e){if("queued"===i.status)for(var t=0;t<n.queue.length;t++)if(n.queue[t]===i){n.queue.splice(t,1);break}throw n.safeDispatchEvent("failure",{detail:{job:i,error:e}}),e})))]}))}))()}},{key:"clear",value:function(){this.queue.splice(0,this.queue.length)}},{key:"abort",value:function(){this.queue.forEach((function(e){e.abort(new ea)})),this.clear()}},{key:"onEmpty",value:function(e){var t=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:return 0!==t.size?[4,tb(t,"empty",null==e?void 0:e.signal)]:[3,2];case 1:n.sent(),n.label=2;case 2:return[2]}}))}))()}},{key:"onSizeLessThan",value:function(e,t){var n=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return n.size<e?[3,2]:[4,tb(n,"next",null==t?void 0:t.signal,{filter:function(){return n.size<e}})];case 1:r.sent(),r.label=2;case 2:return[2]}}))}))()}},{key:"onIdle",value:function(e){var t=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:return 0===t.pending&&0===t.size?[3,2]:[4,tb(t,"idle",null==e?void 0:e.signal)];case 1:n.sent(),n.label=2;case 2:return[2]}}))}))()}},{key:"size",get:function(){return this.queue.length}},{key:"queued",get:function(){return this.queue.length-this.pending}},{key:"running",get:function(){return this.pending}},{key:"toGenerator",value:function(e){var t=this;return(0,de.default)((function(){var n,r,i,a,o,u,s,l,c;return(0,pe.__generator)(this,(function(f){switch(f.label){case 0:null==e||null===(n=e.signal)||void 0===n||n.throwIfAborted(),i=Po({objectMode:!0}),a=function(e){null!=e?t.abort():t.clear(),i.end(e)},o=function(e){null!=e.detail&&i.push(e.detail)},u=function(e){a(e.detail.error)},s=function(){a()},l=function(){a(new ea("Queue aborted"))},t.addEventListener("completed",o),t.addEventListener("failure",u),t.addEventListener("idle",s),null==e||null===(r=e.signal)||void 0===r||r.addEventListener("abort",l),f.label=1;case 1:return f.trys.push([1,,3,4]),[5,(0,pe.__values)((0,z.default)((0,j.default)(i),V.default))];case 2:return f.sent(),[3,4];case 3:return t.removeEventListener("completed",o),t.removeEventListener("failure",u),t.removeEventListener("idle",s),null==e||null===(c=e.signal)||void 0===c||c.removeEventListener("abort",l),a(),[7];case 4:return[2]}}))}))()}}]),n}(xa),gk=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return(0,H.default)(this,n),t.call(this,(0,oe.default)((0,ae.default)({},e),{sort:function(e,t){return e.options.priority>t.options.priority?-1:e.options.priority<t.options.priority?1:0}}))}return n}(pk);function yk(e){var t=new globalThis.AbortController;function n(){t.abort();var r=!0,i=!1,a=void 0;try{for(var o,u=e[Symbol.iterator]();!(r=(o=u.next()).done);r=!0){var s=o.value;null!=(null==s?void 0:s.removeEventListener)&&s.removeEventListener("abort",n)}}catch(e){i=!0,a=e}finally{try{r||null==u.return||u.return()}finally{if(i)throw a}}}var r=!0,i=!1,a=void 0;try{for(var o,u=e[Symbol.iterator]();!(r=(o=u.next()).done);r=!0){var s=o.value;if(!0===(null==s?void 0:s.aborted)){n();break}null!=(null==s?void 0:s.addEventListener)&&s.addEventListener("abort",n)}}catch(e){i=!0,a=e}finally{try{r||null==u.return||u.return()}finally{if(i)throw a}}var l=t.signal;return l.clear=function(){var t=!0,r=!1,i=void 0;try{for(var a,o=e[Symbol.iterator]();!(t=(a=o.next()).done);t=!0){var u=a.value;null!=(null==u?void 0:u.removeEventListener)&&u.removeEventListener("abort",n)}}catch(e){r=!0,i=e}finally{try{t||null==o.return||o.return()}finally{if(r)throw i}}},l}function mk(e){if(!Qv(e))return!1;var t,n=e.nodeAddress().address;return/^127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(t=n)||/^::1$/.test(t)}function bk(e,t){var n=Ep.exactMatch(e.multiaddr),r=Ep.exactMatch(t.multiaddr);if(n&&!r)return-1;if(!n&&r)return 1;var i=Lp.exactMatch(e.multiaddr),a=Lp.exactMatch(t.multiaddr);if(i&&!a)return-1;if(!i&&a)return 1;var o=Pp.exactMatch(e.multiaddr),u=Pp.exactMatch(t.multiaddr);if(o&&!u)return-1;if(!o&&u)return 1;var s=Bp.exactMatch(e.multiaddr),l=Bp.exactMatch(t.multiaddr);if(s&&!l)return-1;if(!s&&l)return 1;var c=Mp.exactMatch(e.multiaddr),f=Mp.exactMatch(t.multiaddr);if(c&&!f)return-1;if(!c&&f)return 1;var d=Op.exactMatch(e.multiaddr),h=Op.exactMatch(t.multiaddr);return d&&!h?-1:!d&&h?1:0}function wk(e,t){var n=mk(e.multiaddr),r=mk(t.multiaddr);return n&&!r?1:!n&&r?-1:0}function kk(e,t){var n=Jv(e.multiaddr),r=Jv(t.multiaddr);return n&&!r?1:!n&&r?-1:0}function _k(e,t){return e.isCertified&&!t.isCertified?-1:!e.isCertified&&t.isCertified?1:0}function Ek(e,t){var n=Fp.exactMatch(e.multiaddr),r=Fp.exactMatch(t.multiaddr);return n&&!r?1:!n&&r?-1:0}var Sk,Ak,Ik,xk,Ck,Tk=function(){"use strict";function e(t){var n,r,i,a,o,u=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=this;(0,H.default)(this,e),(0,te.default)(this,"queue",void 0),(0,te.default)(this,"components",void 0),(0,te.default)(this,"addressSorter",void 0),(0,te.default)(this,"maxPeerAddrsToDial",void 0),(0,te.default)(this,"maxDialQueueLength",void 0),(0,te.default)(this,"dialTimeout",void 0),(0,te.default)(this,"shutDownController",void 0),(0,te.default)(this,"connections",void 0),(0,te.default)(this,"log",void 0),this.addressSorter=u.addressSorter,this.maxPeerAddrsToDial=null!==(n=u.maxPeerAddrsToDial)&&void 0!==n?n:25,this.maxDialQueueLength=null!==(r=u.maxDialQueueLength)&&void 0!==r?r:500,this.dialTimeout=null!==(i=u.dialTimeout)&&void 0!==i?i:1e4,this.connections=null!==(a=u.connections)&&void 0!==a?a:new Bm,this.log=t.logger.forComponent("libp2p:connection-manager:dial-queue"),this.components=t,this.shutDownController=new AbortController,this.shutDownController.signal;var l,c=!0,f=!1,d=void 0;try{for(var h,v=Object.entries(null!==(o=u.resolvers)&&void 0!==o?o:{})[Symbol.iterator]();!(c=(h=v.next()).done);c=!0){var p=(0,se.default)(h.value,2),g=p[0],y=p[1];hf.set(g,y)}}catch(e){f=!0,d=e}finally{try{c||null==v.return||v.return()}finally{if(f)throw d}}this.queue=new gk({concurrency:null!==(l=u.maxParallelDials)&&void 0!==l?l:50,metricName:"libp2p_dial_queue",metrics:t.metrics}),this.queue.addEventListener("error",(function(e){var t;(null===(t=e.detail)||void 0===t?void 0:t.name)!==ea.name&&s.log.error("error in dial queue - %e",e.detail)}))}return(0,$.default)(e,[{key:"start",value:function(){this.shutDownController=new AbortController,this.shutDownController.signal}},{key:"stop",value:function(){this.shutDownController.abort(),this.queue.abort()}},{key:"dial",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=this;return(0,K.default)((function(){var r,i,a,o,u,s,l,c,f,d,h,v,p,g,y,m;return(0,pe.__generator)(this,(function(b){if(a=lk(e),o=a.peerId,u=a.multiaddrs,s=Array.from(n.connections.values()).flat().find((function(e){return!0!==t.force&&(!!e.remotePeer.equals(o)||u.find((function(t){return t.equals(e.remoteAddr)})))})),"open"===(null==s?void 0:s.status))return[2,(n.log("already connected to %a",s.remoteAddr),null===(r=t.onProgress)||void 0===r||r.call(t,new qg("dial-queue:already-connected")),s)];if(l=n.queue.queue.find((function(e){if(!0===(null==o?void 0:o.equals(e.options.peerId)))return!0;var t=e.options.multiaddrs;if(null==t)return!1;var n=!0,r=!1,i=void 0;try{for(var a,s=u[Symbol.iterator]();!(n=(a=s.next()).done);n=!0){var l=a.value;if(t.has(l.toString()))return!0}}catch(e){r=!0,i=e}finally{try{n||null==s.return||s.return()}finally{if(r)throw i}}return!1})),null!=l){n.log("joining existing dial target for %p",o),f=!0,d=!1,h=void 0;try{for(v=u[Symbol.iterator]();!(f=(p=v.next()).done);f=!0)g=p.value,l.options.multiaddrs.add(g.toString())}catch(e){d=!0,h=e}finally{try{f||null==v.return||v.return()}finally{if(d)throw h}}return[2,(null===(c=t.onProgress)||void 0===c||c.call(t,new qg("dial-queue:already-in-dial-queue")),l.join(t))]}if(n.queue.size>=n.maxDialQueueLength)throw new ka("Dial queue is full");return[2,(n.log("creating dial target for %p",o,u.map((function(e){return e.toString()}))),null===(i=t.onProgress)||void 0===i||i.call(t,new qg("dial-queue:add-to-dial-queue")),n.queue.add(function(){var e=(0,K.default)((function(e){var t,r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:null===(t=e.onProgress)||void 0===t||t.call(e,new qg("dial-queue:start-dial")),r=yk([n.shutDownController.signal,e.signal]),i.label=1;case 1:return i.trys.push([1,,3,4]),[4,n.dialPeer(e,r)];case 2:return[2,i.sent()];case 3:return r.clear(),[7];case 4:return[2]}}))}));return function(t){return e.apply(this,arguments)}}(),{peerId:o,priority:null!==(y=t.priority)&&void 0!==y?y:Bk,multiaddrs:new Set(u.map((function(e){return e.toString()}))),signal:null!==(m=t.signal)&&void 0!==m?m:AbortSignal.timeout(n.dialTimeout),onProgress:t.onProgress}))]}))}))()}},{key:"dialPeer",value:function(e,t){var n=this;return(0,K.default)((function(){var r,i,a,o,u,s,l,c,f,d,h,v,p,g,y,m,b,w,k,_,E,S,A,I,x,C,T,P;return(0,pe.__generator)(this,(function(R){switch(R.label){case 0:r=e.peerId,i=e.multiaddrs,a=new Set,o=0===e.multiaddrs.size,u=0,s=0,l=[],n.log("starting dial to %p",r),R.label=1;case 1:return o||i.size>0?(s++,o=!1,f=[],d=new Set(e.multiaddrs),i.clear(),n.log("calculating addrs to dial %p from %s",r,(0,ce.default)(d)),[4,n.calculateMultiaddrs(r,d,(0,oe.default)((0,ae.default)({},e),{signal:t}))]):[3,21];case 2:h=R.sent(),v=!0,p=!1,g=void 0;try{for(y=h[Symbol.iterator]();!(v=(m=y.next()).done);v=!0)b=m.value,a.has(b.multiaddr.toString())?n.log.trace("skipping previously failed multiaddr %a while dialing %p",b.multiaddr,r):f.push(b)}catch(e){p=!0,g=e}finally{try{v||null==y.return||y.return()}finally{if(p)throw g}}n.log("%s dial to %p with %s",1===s?"starting":"continuing",r,f.map((function(e){return e.multiaddr.toString()}))),null==e||null===(c=e.onProgress)||void 0===c||c.call(e,new qg("dial-queue:calculated-addresses",f)),w=!0,k=!1,_=void 0,R.label=3;case 3:R.trys.push([3,18,19,20]),E=f[Symbol.iterator](),R.label=4;case 4:if(w=(S=E.next()).done)return[3,17];if(A=S.value,u===n.maxPeerAddrsToDial)throw n.log("dialed maxPeerAddrsToDial (%d) addresses for %p, not trying any others",u,e.peerId),new ka("Peer had more than maxPeerAddrsToDial");u++,R.label=5;case 5:return R.trys.push([5,11,,16]),[4,n.components.transportManager.dial(A.multiaddr,(0,oe.default)((0,ae.default)({},e),{signal:t}))];case 6:I=R.sent(),n.log("dial to %a succeeded",A.multiaddr),R.label=7;case 7:return R.trys.push([7,9,,10]),[4,n.components.peerStore.merge(I.remotePeer,{multiaddrs:[I.remoteAddr],metadata:(0,te.default)({},"last-dial-success",wn(Date.now().toString()))})];case 8:return R.sent(),[3,10];case 9:return x=R.sent(),n.log.error("could not update last dial failure key for %p",r,x),[3,10];case 10:return[2,I];case 11:if(C=R.sent(),n.log.error("dial failed to %a",A.multiaddr,C),a.add(A.multiaddr.toString()),null==r)return[3,15];R.label=12;case 12:return R.trys.push([12,14,,15]),[4,n.components.peerStore.merge(r,{metadata:(0,te.default)({},"last-dial-failure",wn(Date.now().toString()))})];case 13:return R.sent(),[3,15];case 14:return T=R.sent(),n.log.error("could not update last dial failure key for %p",r,T),[3,15];case 15:if(t.aborted)throw new ba(C.message);return l.push(C),[3,16];case 16:return w=!0,[3,4];case 17:return[3,20];case 18:return P=R.sent(),k=!0,_=P,[3,20];case 19:try{w||null==E.return||E.return()}finally{if(k)throw _}return[7];case 20:return[3,1];case 21:if(1===l.length)throw l[0];throw new AggregateError(l,"All multiaddr dials failed")}}))}))()}},{key:"calculateMultiaddrs",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new Set,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=this;return(0,K.default)((function(){var i,a,o,u,s,l,c,f,d,h,v,p,g,y,m,b,w,k,_,E,S,A,I,x,C,T,P,R,L,D,M,N,O;return(0,pe.__generator)(this,(function(U){switch(U.label){case 0:if(i=(0,ce.default)(t).map((function(e){return{multiaddr:pf(e),isCertified:!1}})),null==e)return[3,9];if(r.components.peerId.equals(e))throw new ka("Tried to dial self");return u=!0,[4,null===(o=(a=r.components.connectionGater).denyDialPeer)||void 0===o?void 0:o.call(a,e)];case 1:if(u===U.sent())throw new Gw("The dial request is blocked by gater.allowDialPeer");if(0!==i.length)return[3,5];r.log("loading multiaddrs for %p",e),U.label=2;case 2:return U.trys.push([2,4,,5]),[4,r.components.peerStore.get(e)];case 3:return l=U.sent(),(s=i).push.apply(s,(0,ce.default)(l.addresses)),r.log("loaded multiaddrs for %p",e,i.map((function(e){return e.multiaddr.toString()}))),[3,5];case 4:if("NotFoundError"!==(c=U.sent()).name)throw c;return[3,5];case 5:if(0!==i.length)return[3,9];r.log("looking up multiaddrs for %p in the peer routing",e),U.label=6;case 6:return U.trys.push([6,8,,9]),[4,r.components.peerRouting.findPeer(e,n)];case 7:return d=U.sent(),r.log("found multiaddrs for %p in the peer routing",e,i.map((function(e){return e.multiaddr.toString()}))),(f=i).push.apply(f,(0,ce.default)(d.multiaddrs.map((function(e){return{multiaddr:e,isCertified:!1}})))),[3,9];case 8:return"NoPeerRoutersError"===(h=U.sent()).name?r.log("no peer routers configured",e):r.log.error("looking up multiaddrs for %p in the peer routing failed - %e",e,h),[3,9];case 9:return[4,Promise.all(i.map(function(){var e=(0,K.default)((function(e){var t;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:return[4,function(){var e=(0,K.default)((function(e,t){var n,r,i,a,o,u,s,l;return(0,pe.__generator)(this,(function(c){switch(c.label){case 0:n=!1,r=!0,i=!1,a=void 0;try{for(o=hf.keys()[Symbol.iterator]();!(r=(u=o.next()).done)&&(s=u.value,!(n=e.protoNames().includes(s)));r=!0);}catch(e){i=!0,a=e}finally{try{r||null==o.return||o.return()}finally{if(i)throw a}}return n?[4,e.resolve(t)]:[2,[e]];case 1:return l=c.sent(),[2,(t.log("resolved %s to",e,l.map((function(e){return e.toString()}))),l)]}}))}));return function(t,n){return e.apply(this,arguments)}}()(e.multiaddr,(0,oe.default)((0,ae.default)({dns:r.components.dns},n),{log:r.log}))];case 1:return[2,1===(t=i.sent()).length&&t[0].equals(e.multiaddr)?e:t.map((function(e){return{multiaddr:e,isCertified:!1}}))]}}))}));return function(t){return e.apply(this,arguments)}}()))];case 10:v=U.sent().flat(),null!=e&&(p="/p2p/"+e.toString(),v=v.map((function(e){var t=e.multiaddr.getComponents().pop();return"p2p"!==(null==t?void 0:t.name)?{multiaddr:e.multiaddr.encapsulate(p),isCertified:e.isCertified}:e}))),g=v.filter((function(t){if(null==r.components.transportManager.dialTransportForMultiaddr(t.multiaddr))return!1;var n=t.multiaddr.getPeerId();return null==e||null==n||e.equals(n)})),y=new Map,m=!0,b=!1,w=void 0;try{for(k=g[Symbol.iterator]();!(m=(_=k.next()).done);m=!0)E=_.value,S=E.multiaddr.toString(),null==(A=y.get(S))?y.set(S,E):A.isCertified=A.isCertified||E.isCertified||!1}catch(e){b=!0,w=e}finally{try{m||null==k.return||k.return()}finally{if(b)throw w}}if(0===(I=(0,ce.default)(y.values())).length)throw new Zw("The dial request has no valid addresses");x=[],C=!0,T=!1,P=void 0,U.label=11;case 11:U.trys.push([11,17,18,19]),R=I[Symbol.iterator](),U.label=12;case 12:return(C=(L=R.next()).done)?[3,16]:(D=L.value,(M=null!=r.components.connectionGater.denyDialMultiaddr)?[4,r.components.connectionGater.denyDialMultiaddr(D.multiaddr)]:[3,14]);case 13:M=U.sent(),U.label=14;case 14:M||x.push(D),U.label=15;case 15:return C=!0,[3,12];case 16:return[3,19];case 17:return N=U.sent(),T=!0,P=N,[3,19];case 18:try{C||null==R.return||R.return()}finally{if(T)throw P}return[7];case 19:if(0===(O=null==r.addressSorter?x.sort(bk).sort(_k).sort(Ek).sort(kk).sort(wk):x.sort(r.addressSorter)).length)throw new Gw("The connection gater denied all addresses in the dial request");return[2,(r.log.trace("addresses for %p before filtering",null!=e?e:"unknown peer",v.map((function(e){return e.multiaddr.toString()}))),r.log.trace("addresses for %p after filtering",null!=e?e:"unknown peer",O.map((function(e){return e.multiaddr.toString()}))),O)]}}))}))()}},{key:"isDialable",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=this;return(0,K.default)((function(){var r,i;return(0,pe.__generator)(this,(function(a){switch(a.label){case 0:Array.isArray(e)||(e=[e]),a.label=1;case 1:return a.trys.push([1,3,,4]),[4,n.calculateMultiaddrs(void 0,new Set(e.map((function(e){return e.toString()}))),t)];case 2:return r=a.sent(),[2,!1!==t.runOnLimitedConnection||null!=r.find((function(e){return!Fp.matches(e.multiaddr)}))];case 3:return i=a.sent(),n.log.trace("error calculating if multiaddr(s) were dialable",i),[3,4];case 4:return[2,!1]}}))}))()}}]),e}(),Pk=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){return(0,H.default)(this,n),t.apply(this,arguments)}return(0,$.default)(n,[{key:"has",value:function(e){return null!=this.find(e)}},{key:"find",value:function(e){return this.queue.find((function(t){return e.equals(t.options.peerId)}))}}]),n}(pk),Rk={};var Lk=La(Ck?xk:(Ck=1,xk=function(){var e,t;return Ik||(Ik=1,e=Rk,t=function(){var e=function(e,t){"boolean"==typeof t&&(t={forever:t}),this._originalTimeouts=JSON.parse(JSON.stringify(e)),this._timeouts=e,this._options=t||{},this._maxRetryTime=t&&t.maxRetryTime||1/0,this._fn=null,this._errors=[],this._attempts=1,this._operationTimeout=null,this._operationTimeoutCb=null,this._timeout=null,this._operationStart=null,this._timer=null,this._options.forever&&(this._cachedTimeouts=this._timeouts.slice(0))};return Ak||(Ak=1,Sk=e,e.prototype.reset=function(){this._attempts=1,this._timeouts=this._originalTimeouts.slice(0)},e.prototype.stop=function(){this._timeout&&clearTimeout(this._timeout),this._timer&&clearTimeout(this._timer),this._timeouts=[],this._cachedTimeouts=null},e.prototype.retry=function(e){if(this._timeout&&clearTimeout(this._timeout),!e)return!1;var t=(new Date).getTime();if(e&&t-this._operationStart>=this._maxRetryTime)return this._errors.push(e),this._errors.unshift(Error("RetryOperation timeout occurred")),!1;this._errors.push(e);var n=this._timeouts.shift();if(void 0===n){if(!this._cachedTimeouts)return!1;this._errors.splice(0,this._errors.length-1),n=this._cachedTimeouts.slice(-1)}var r=this;return this._timer=setTimeout((function(){r._attempts++,r._operationTimeoutCb&&(r._timeout=setTimeout((function(){r._operationTimeoutCb(r._attempts)}),r._operationTimeout),r._options.unref&&r._timeout.unref()),r._fn(r._attempts)}),n),this._options.unref&&this._timer.unref(),!0},e.prototype.attempt=function(e,t){this._fn=e,t&&(t.timeout&&(this._operationTimeout=t.timeout),t.cb&&(this._operationTimeoutCb=t.cb));var n=this;this._operationTimeoutCb&&(this._timeout=setTimeout((function(){n._operationTimeoutCb()}),n._operationTimeout)),this._operationStart=(new Date).getTime(),this._fn(this._attempts)},e.prototype.try=function(e){this.attempt(e)},e.prototype.start=function(e){this.attempt(e)},e.prototype.start=e.prototype.try,e.prototype.errors=function(){return this._errors},e.prototype.attempts=function(){return this._attempts},e.prototype.mainError=function(){if(0===this._errors.length)return null;for(var e={},t=null,n=0,r=0;r<this._errors.length;r++){var i=this._errors[r],a=i.message,o=(e[a]||0)+1;e[a]=o,o>=n&&(t=i,n=o)}return t}),Sk}(),e.operation=function(n){var r=e.timeouts(n);return new t(r,{forever:n&&(n.forever||n.retries===1/0),unref:n&&n.unref,maxRetryTime:n&&n.maxRetryTime})},e.timeouts=function(e){if(e instanceof Array)return[].concat(e);var t={retries:10,factor:2,minTimeout:1e3,maxTimeout:1/0,randomize:!1};for(var n in e)t[n]=e[n];if(t.minTimeout>t.maxTimeout)throw Error("minTimeout is greater than maxTimeout");for(var r=[],i=0;i<t.retries;i++)r.push(this.createTimeout(i,t));return e&&e.forever&&!r.length&&r.push(this.createTimeout(i,t)),r.sort((function(e,t){return e-t})),r},e.createTimeout=function(e,t){var n=t.randomize?Math.random()+1:1,r=Math.round(n*Math.max(t.minTimeout,1)*Math.pow(t.factor,e));return Math.min(r,t.maxTimeout)},e.wrap=function(t,n,r){if(n instanceof Array&&(r=n,n=null),!r)for(var i in r=[],t)"function"==typeof t[i]&&r.push(i);for(var a=0;a<r.length;a++){var o=r[a],u=t[o];t[o]=function(r){var i=e.operation(n),a=[].slice.call(arguments,1),o=a.pop();a.push((function(e){i.retry(e)||(e&&(arguments[0]=i.mainError()),o.apply(this,arguments))})),i.attempt((function(){r.apply(t,a)}))}.bind(t,u),t[o].options=n}}),Rk}())),Dk={}.toString,Mk=new Set(["network error","Failed to fetch","NetworkError when attempting to fetch resource.","The Internet connection appears to be offline.","Load failed","Network request failed","fetch failed","terminated"]);var Nk=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(e){var r;return(0,H.default)(this,n),r=t.call(this),e instanceof Error?(r.originalError=e,e=e.message):(r.originalError=Error(e),r.originalError.stack=r.stack),r.name="AbortError",r.message=e,(0,ue.default)(r)}return n}((0,he.default)(Error)),Ok=function(e,t,n){var r=n.retries-(t-1);return e.attemptNumber=t,e.retriesLeft=r,e},Uk=function(){"use strict";function e(t){var n,r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=this;(0,H.default)(this,e),(0,te.default)(this,"log",void 0),(0,te.default)(this,"queue",void 0),(0,te.default)(this,"started",void 0),(0,te.default)(this,"peerStore",void 0),(0,te.default)(this,"retries",void 0),(0,te.default)(this,"retryInterval",void 0),(0,te.default)(this,"backoffFactor",void 0),(0,te.default)(this,"connectionManager",void 0),(0,te.default)(this,"events",void 0),this.log=t.logger.forComponent("libp2p:reconnect-queue"),this.peerStore=t.peerStore,this.connectionManager=t.connectionManager,this.queue=new Pk({concurrency:null!==(n=i.maxParallelReconnects)&&void 0!==n?n:5,metricName:"libp2p_reconnect_queue",metrics:t.metrics}),this.started=!1,this.retries=null!==(r=i.retries)&&void 0!==r?r:5,this.backoffFactor=i.backoffFactor,this.retryInterval=i.retryInterval,this.events=t.events,t.events.addEventListener("peer:disconnect",(function(e){a.maybeReconnect(e.detail).catch((function(t){a.log.error("failed to maybe reconnect to %p - %e",e.detail,t)}))}))}return(0,$.default)(e,[{key:"maybeReconnect",value:function(e){var t=this;return(0,K.default)((function(){var n;return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return t.started?[4,t.peerStore.get(e)]:[2];case 1:return Fk(n=r.sent())&&(t.queue.has(e)||t.queue.add(function(){var n=(0,K.default)((function(n){return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return[4,function(){var e=(0,K.default)((function(e,t){return(0,pe.__generator)(this,(function(n){return[2,new Promise((function(n,r){var i,a,o;t=(0,ae.default)({},t),null!==(i=(s=t).onFailedAttempt)&&void 0!==i||(s.onFailedAttempt=function(){}),null!==(a=(l=t).shouldRetry)&&void 0!==a||(l.shouldRetry=function(){return!0}),null!==(o=(c=t).retries)&&void 0!==o||(c.retries=10);var u=Lk.operation(t),f=function(){var e;u.stop(),r(null===(e=t.signal)||void 0===e?void 0:e.reason)};t.signal&&!t.signal.aborted&&t.signal.addEventListener("abort",f,{once:!0});var d=function(){var e;null===(e=t.signal)||void 0===e||e.removeEventListener("abort",f),u.stop()};u.attempt(function(){var i=(0,K.default)((function(i){var a,o,s;return(0,pe.__generator)(this,(function(l){switch(l.label){case 0:return l.trys.push([0,2,,8]),[4,e(i)];case 1:return a=l.sent(),d(),n(a),[3,8];case 2:o=l.sent(),l.label=3;case 3:if(l.trys.push([3,6,,7]),!(o instanceof Error))throw new TypeError('Non-error was thrown: "'.concat(o,'". You should only throw errors.'));if(o instanceof Nk)throw o.originalError;if(o instanceof TypeError&&!function(e){var t;return!(!e||(t=e,"[object Error]"!==Dk.call(t))||"TypeError"!==e.name||"string"!=typeof e.message)&&("Load failed"===e.message?void 0===e.stack:Mk.has(e.message))}(o))throw o;return Ok(o,i,t),[4,t.shouldRetry(o)];case 4:return l.sent()||(u.stop(),r(o)),[4,t.onFailedAttempt(o)];case 5:if(l.sent(),!u.retry(o))throw u.mainError();return[3,7];case 6:return s=l.sent(),Ok(s,i,t),d(),r(s),[3,7];case 7:return[3,8];case 8:return[2]}}))}));return function(e){return i.apply(this,arguments)}}())}))]}))}));return function(t,n){return e.apply(this,arguments)}}()(function(){var r=(0,K.default)((function(r){var i;return(0,pe.__generator)(this,(function(a){switch(a.label){case 0:if(!t.started)return[3,4];a.label=1;case 1:return a.trys.push([1,3,,4]),[4,t.connectionManager.openConnection(e,{signal:null==n?void 0:n.signal})];case 2:return a.sent(),[3,4];case 3:throw i=a.sent(),t.log("reconnecting to %p attempt %d of %d failed - %e",e,r,t.retries,i),i;case 4:return[2]}}))}));return function(e){return r.apply(this,arguments)}}(),{signal:null==n?void 0:n.signal,retries:t.retries,factor:t.backoffFactor,minTimeout:t.retryInterval})];case 1:return r.sent(),[2]}}))}));return function(e){return n.apply(this,arguments)}}(),{peerId:e}).catch(function(){var r=(0,K.default)((function(r){var i;return(0,pe.__generator)(this,(function(a){switch(a.label){case 0:return t.log.error("failed to reconnect to %p - %e",e,r),i={},(0,ce.default)(n.tags.keys()).forEach((function(e){e.startsWith(Ji)&&(i[e]=void 0)})),[4,t.peerStore.merge(e,{tags:i})];case 1:return a.sent(),t.events.safeDispatchEvent("peer:reconnect-failure",{detail:e}),[2]}}))}));return function(e){return r.apply(this,arguments)}}()).catch(function(){var n=(0,K.default)((function(n){return(0,pe.__generator)(this,(function(r){return t.log.error("failed to remove keep-alive tag from %p - %e",e,n),[2]}))}));return function(e){return n.apply(this,arguments)}}())),[2]}}))}))()}},{key:"start",value:function(){this.started=!0}},{key:"afterStart",value:function(){var e=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(t){return Promise.resolve().then((0,K.default)((function(){var t;return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:return[4,e.peerStore.all({filters:[function(e){return Fk(e)}]})];case 1:return t=n.sent(),[4,Promise.all(t.map(function(){var t=(0,K.default)((function(t){return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:return[4,e.connectionManager.openConnection(t.id).catch((function(t){e.log.error(t)}))];case 1:return n.sent(),[2]}}))}));return function(e){return t.apply(this,arguments)}}()))];case 2:return n.sent(),[2]}}))}))).catch((function(t){e.log.error(t)})),[2]}))}))()}},{key:"stop",value:function(){this.started=!1,this.queue.abort()}}]),e}();function Fk(e){var t=!0,n=!1,r=void 0;try{for(var i,a=e.tags.keys()[Symbol.iterator]();!(t=(i=a.next()).done);t=!0){if(i.value.startsWith(Ji))return!0}}catch(e){n=!0,r=e}finally{try{t||null==a.return||a.return()}finally{if(n)throw r}}return!1}var Bk=50,qk=Symbol.toStringTag,zk=function(){"use strict";function e(t){var n,r,i,a,o,u,s,l,c,f,d,h=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if((0,H.default)(this,e),(0,te.default)(this,"started",void 0),(0,te.default)(this,"connections",void 0),(0,te.default)(this,"allow",void 0),(0,te.default)(this,"deny",void 0),(0,te.default)(this,"maxIncomingPendingConnections",void 0),(0,te.default)(this,"incomingPendingConnections",void 0),(0,te.default)(this,"outboundPendingConnections",void 0),(0,te.default)(this,"maxConnections",void 0),(0,te.default)(this,"dialQueue",void 0),(0,te.default)(this,"reconnectQueue",void 0),(0,te.default)(this,"connectionPruner",void 0),(0,te.default)(this,"inboundConnectionRateLimiter",void 0),(0,te.default)(this,"peerStore",void 0),(0,te.default)(this,"metrics",void 0),(0,te.default)(this,"events",void 0),(0,te.default)(this,"log",void 0),(0,te.default)(this,"peerId",void 0),(0,te.default)(this,qk,"@libp2p/connection-manager"),this.maxConnections=null!==(r=h.maxConnections)&&void 0!==r?r:100,this.maxConnections<1)throw new ra("Connection Manager maxConnections must be greater than 0");this.connections=new Bm,this.started=!1,this.peerId=t.peerId,this.peerStore=t.peerStore,this.metrics=t.metrics,this.events=t.events,this.log=t.logger.forComponent("libp2p:connection-manager"),this.onConnect=this.onConnect.bind(this),this.onDisconnect=this.onDisconnect.bind(this),this.allow=(null!==(i=h.allow)&&void 0!==i?i:[]).map((function(e){return fk(e)})),this.deny=(null!==(a=h.deny)&&void 0!==a?a:[]).map((function(e){return fk(e)})),this.incomingPendingConnections=0,this.maxIncomingPendingConnections=null!==(o=h.maxIncomingPendingConnections)&&void 0!==o?o:10,this.outboundPendingConnections=0,this.inboundConnectionRateLimiter=new Zp({points:null!==(u=h.inboundConnectionThreshold)&&void 0!==u?u:5,duration:1}),this.connectionPruner=new dk({connectionManager:this,peerStore:t.peerStore,events:t.events,logger:t.logger},{allow:null===(n=h.allow)||void 0===n?void 0:n.map((function(e){return pf(e)}))}),this.dialQueue=new Tk(t,{addressSorter:h.addressSorter,maxParallelDials:null!==(s=h.maxParallelDials)&&void 0!==s?s:50,maxDialQueueLength:null!==(l=h.maxDialQueueLength)&&void 0!==l?l:500,maxPeerAddrsToDial:null!==(c=h.maxPeerAddrsToDial)&&void 0!==c?c:25,dialTimeout:null!==(f=h.dialTimeout)&&void 0!==f?f:1e4,resolvers:null!==(d=h.resolvers)&&void 0!==d?d:{dnsaddr:gm},connections:this.connections}),this.reconnectQueue=new Uk({events:t.events,peerStore:t.peerStore,logger:t.logger,connectionManager:this},{retries:h.reconnectRetries,retryInterval:h.reconnectRetryInterval,backoffFactor:h.reconnectBackoffFactor,maxParallelReconnects:h.maxParallelReconnects})}return(0,$.default)(e,[{key:"start",value:function(){var e=this;return(0,K.default)((function(){var t,n,r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:return null===(t=e.metrics)||void 0===t||t.registerMetricGroup("libp2p_connection_manager_connections",{calculate:function(){var t={inbound:0,"inbound pending":e.incomingPendingConnections,outbound:0,"outbound pending":e.outboundPendingConnections},n=!0,r=!1,i=void 0,a=!0,o=!1,u=void 0;try{for(var s,l=e.connections.values()[Symbol.iterator]();!(a=(s=l.next()).done);a=!0){var c=s.value;try{for(var f,d=c[Symbol.iterator]();!(n=(f=d.next()).done);n=!0){t[f.value.direction]++}}catch(e){r=!0,i=e}finally{try{n||null==d.return||d.return()}finally{if(r)throw i}}}}catch(e){o=!0,u=e}finally{try{a||null==l.return||l.return()}finally{if(o)throw u}}return t}}),null===(n=e.metrics)||void 0===n||n.registerMetricGroup("libp2p_protocol_streams_total",{label:"protocol",calculate:function(){var t={},n=!0,r=!1,i=void 0,a=!0,o=!1,u=void 0,s=!0,l=!1,c=void 0;try{for(var f,d=e.connections.values()[Symbol.iterator]();!(s=(f=d.next()).done);s=!0){var h=f.value;try{for(var v,p=h[Symbol.iterator]();!(a=(v=p.next()).done);a=!0){var g=v.value;try{for(var y,m=g.streams[Symbol.iterator]();!(n=(y=m.next()).done);n=!0){var b,w,k=y.value,_="".concat(k.direction," ").concat(null!==(b=k.protocol)&&void 0!==b?b:"unnegotiated");t[_]=(null!==(w=t[_])&&void 0!==w?w:0)+1}}catch(e){r=!0,i=e}finally{try{n||null==m.return||m.return()}finally{if(r)throw i}}}}catch(e){o=!0,u=e}finally{try{a||null==p.return||p.return()}finally{if(o)throw u}}}}catch(e){l=!0,c=e}finally{try{s||null==d.return||d.return()}finally{if(l)throw c}}return t}}),null===(r=e.metrics)||void 0===r||r.registerMetricGroup("libp2p_connection_manager_protocol_streams_per_connection_90th_percentile",{label:"protocol",calculate:function(){var t={},n=!0,r=!1,i=void 0,a=!0,o=!1,u=void 0;try{for(var s,l=e.connections.values()[Symbol.iterator]();!(a=(s=l.next()).done);a=!0){var c=s.value;try{for(var f,d=c[Symbol.iterator]();!(n=(f=d.next()).done);n=!0){var h,v=f.value,p={},g=!0,y=!1,m=void 0;try{for(var b,w=v.streams[Symbol.iterator]();!(g=(b=w.next()).done);g=!0){var k,_,E=b.value,S="".concat(E.direction," ").concat(null!==(k=E.protocol)&&void 0!==k?k:"unnegotiated");p[S]=(null!==(_=p[S])&&void 0!==_?_:0)+1}}catch(e){y=!0,m=e}finally{try{g||null==w.return||w.return()}finally{if(y)throw m}}var A=!0,I=!1,x=void 0;try{for(var C,T=Object.entries(p)[Symbol.iterator]();!(A=(C=T.next()).done);A=!0){var P=(0,se.default)(C.value,2),R=P[0],L=P[1];t[R]=null!==(h=t[R])&&void 0!==h?h:[],t[R].push(L)}}catch(e){I=!0,x=e}finally{try{A||null==T.return||T.return()}finally{if(I)throw x}}}}catch(e){r=!0,i=e}finally{try{n||null==d.return||d.return()}finally{if(r)throw i}}}}catch(e){o=!0,u=e}finally{try{a||null==l.return||l.return()}finally{if(o)throw u}}var D={},M=!0,N=!1,O=void 0;try{for(var U,F=Object.entries(t)[Symbol.iterator]();!(M=(U=F.next()).done);M=!0){var B=(0,se.default)(U.value,2),q=B[0],z=B[1];z=z.sort((function(e,t){return e-t}));var j=Math.floor(.9*z.length);D[q]=z[j]}}catch(e){N=!0,O=e}finally{try{M||null==F.return||F.return()}finally{if(N)throw O}}return D}}),e.events.addEventListener("connection:open",e.onConnect),e.events.addEventListener("connection:close",e.onDisconnect),[4,(0,K.default)((function(){var e,t,n,r,i,a,o,u,s,l,c=arguments;return(0,pe.__generator)(this,(function(f){switch(f.label){case 0:for(e=c.length,t=new Array(e),n=0;n<e;n++)t[n]=c[n];r=[],i=!0,a=!1,o=void 0;try{for(u=t[Symbol.iterator]();!(i=(s=u.next()).done);i=!0)Ca(l=s.value)&&r.push(l)}catch(e){a=!0,o=e}finally{try{i||null==u.return||u.return()}finally{if(a)throw o}}return[4,Promise.all(r.map(function(){var e=(0,K.default)((function(e){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return null!=e.beforeStart?[4,e.beforeStart()]:[3,2];case 1:t.sent(),t.label=2;case 2:return[2]}}))}));return function(t){return e.apply(this,arguments)}}()))];case 1:return f.sent(),[4,Promise.all(r.map(function(){var e=(0,K.default)((function(e){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return[4,e.start()];case 1:return t.sent(),[2]}}))}));return function(t){return e.apply(this,arguments)}}()))];case 2:return f.sent(),[4,Promise.all(r.map(function(){var e=(0,K.default)((function(e){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return null!=e.afterStart?[4,e.afterStart()]:[3,2];case 1:t.sent(),t.label=2;case 2:return[2]}}))}));return function(t){return e.apply(this,arguments)}}()))];case 3:return f.sent(),[2]}}))}))(e.dialQueue,e.reconnectQueue,e.connectionPruner)];case 1:return i.sent(),e.started=!0,e.log("started"),[2]}}))}))()}},{key:"stop",value:function(){var e=this;return(0,K.default)((function(){var t,n,r,i,a,o,u,s,l,c,f,d,h;return(0,pe.__generator)(this,(function(v){switch(v.label){case 0:return e.events.removeEventListener("connection:open",e.onConnect),e.events.removeEventListener("connection:close",e.onDisconnect),[4,(0,K.default)((function(){var e,t,n,r,i,a,o,u,s,l,c=arguments;return(0,pe.__generator)(this,(function(f){switch(f.label){case 0:for(e=c.length,t=new Array(e),n=0;n<e;n++)t[n]=c[n];r=[],i=!0,a=!1,o=void 0;try{for(u=t[Symbol.iterator]();!(i=(s=u.next()).done);i=!0)Ca(l=s.value)&&r.push(l)}catch(e){a=!0,o=e}finally{try{i||null==u.return||u.return()}finally{if(a)throw o}}return[4,Promise.all(r.map(function(){var e=(0,K.default)((function(e){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return null!=e.beforeStop?[4,e.beforeStop()]:[3,2];case 1:t.sent(),t.label=2;case 2:return[2]}}))}));return function(t){return e.apply(this,arguments)}}()))];case 1:return f.sent(),[4,Promise.all(r.map(function(){var e=(0,K.default)((function(e){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return[4,e.stop()];case 1:return t.sent(),[2]}}))}));return function(t){return e.apply(this,arguments)}}()))];case 2:return f.sent(),[4,Promise.all(r.map(function(){var e=(0,K.default)((function(e){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return null!=e.afterStop?[4,e.afterStop()]:[3,2];case 1:t.sent(),t.label=2;case 2:return[2]}}))}));return function(t){return e.apply(this,arguments)}}()))];case 3:return f.sent(),[2]}}))}))(e.reconnectQueue,e.dialQueue,e.connectionPruner)];case 1:v.sent(),t=[],n=!0,r=!1,i=void 0,a=!0,o=!1,u=void 0;try{for(s=e.connections.values()[Symbol.iterator]();!(a=(l=s.next()).done);a=!0){c=l.value;try{for(f=c[Symbol.iterator]();!(n=(d=f.next()).done);n=!0)h=d.value,t.push((0,K.default)((function(){var t;return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,h.close()];case 1:return n.sent(),[3,3];case 2:return t=n.sent(),e.log.error(t),[3,3];case 3:return[2]}}))}))())}catch(e){r=!0,i=e}finally{try{n||null==f.return||f.return()}finally{if(r)throw i}}}}catch(e){o=!0,u=e}finally{try{a||null==s.return||s.return()}finally{if(o)throw u}}return e.log("closing %d connections",t.length),[4,Promise.all(t)];case 2:return v.sent(),e.connections.clear(),e.log("stopped"),[2]}}))}))()}},{key:"getMaxConnections",value:function(){return this.maxConnections}},{key:"setMaxConnections",value:function(e){if(this.maxConnections<1)throw new ra("Connection Manager maxConnections must be greater than 0");var t=!1;e<this.maxConnections&&(t=!0),this.maxConnections=e,t&&this.connectionPruner.maybePruneConnections()}},{key:"onConnect",value:function(e){var t=this;this._onConnect(e).catch((function(e){t.log.error(e)}))}},{key:"_onConnect",value:function(e){var t=this;return(0,K.default)((function(){var n,r,i,a,o;return(0,pe.__generator)(this,(function(u){switch(u.label){case 0:return n=e.detail,t.started?[3,2]:[4,n.close()];case 1:return[2,void u.sent()];case 2:return"open"!==n.status?[2]:(i=n.remotePeer,a=!t.connections.has(i),(o=null!==(r=t.connections.get(i))&&void 0!==r?r:[]).push(n),t.connections.set(i,o),null!=i.publicKey&&"RSA"===i.type?[4,t.peerStore.patch(i,{publicKey:i.publicKey})]:[3,4]);case 3:u.sent(),u.label=4;case 4:return a&&t.events.safeDispatchEvent("peer:connect",{detail:n.remotePeer}),[2]}}))}))()}},{key:"onDisconnect",value:function(e){var t,n=e.detail,r=n.remotePeer,i=(null!==(t=this.connections.get(r))&&void 0!==t?t:[]).filter((function(e){return e.id!==n.id}));this.connections.set(r,i),0===i.length&&(this.log("onDisconnect remove all connections for peer %p",r),this.connections.delete(r),this.events.safeDispatchEvent("peer:disconnect",{detail:n.remotePeer}))}},{key:"getConnections",value:function(e){var t;if(null!=e)return null!==(t=this.connections.get(e))&&void 0!==t?t:[];var n=[],r=!0,i=!1,a=void 0;try{for(var o,u=this.connections.values()[Symbol.iterator]();!(r=(o=u.next()).done);r=!0){var s=o.value;n=n.concat(s)}}catch(e){i=!0,a=e}finally{try{r||null==u.return||u.return()}finally{if(i)throw a}}return n}},{key:"getConnectionsMap",value:function(){return this.connections}},{key:"openConnection",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=this;return(0,K.default)((function(){var r,i,a,o,u,s,l,c,f,d,h,v,p,g,y;return(0,pe.__generator)(this,(function(m){switch(m.label){case 0:if(!n.started)throw new wa("Not started");n.outboundPendingConnections++,m.label=1;case 1:if(m.trys.push([1,,3,4]),null===(r=t.signal)||void 0===r||r.throwIfAborted(),i=lk(e),a=i.peerId,n.peerId.equals(a))throw new da("Can not dial self");return null!=a&&!0!==t.force&&(n.log("dial %p",a),u=n.getConnections(a).find((function(e){return null==e.limits})),null!=u)?[2,(n.log("had an existing non-limited connection to %p",a),null===(o=t.onProgress)||void 0===o||o.call(t,new qg("dial-queue:already-connected")),u)]:[4,n.dialQueue.dial(e,(0,oe.default)((0,ae.default)({},t),{priority:null!==(s=t.priority)&&void 0!==s?s:Bk}))];case 2:if("open"!==(l=m.sent()).status)throw new oa("Remote closed connection during opening");null==(c=n.connections.get(l.remotePeer))&&(c=[],n.connections.set(l.remotePeer,c)),f=!1,d=!0,h=!1,v=void 0;try{for(p=c[Symbol.iterator]();!(d=(g=p.next()).done);d=!0)if((y=g.value).id===l.id&&(f=!0),!0!==t.force&&y.id!==l.id&&y.remoteAddr.equals(l.remoteAddr))return[2,(l.abort(new ha("Duplicate multiaddr connection")),y)]}catch(e){h=!0,v=e}finally{try{d||null==p.return||p.return()}finally{if(h)throw v}}return[2,(f||c.push(l),l)];case 3:return n.outboundPendingConnections--,[7];case 4:return[2]}}))}))()}},{key:"closeConnections",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=this;return(0,K.default)((function(){var r,i;return(0,pe.__generator)(this,(function(a){switch(a.label){case 0:return i=null!==(r=n.connections.get(e))&&void 0!==r?r:[],[4,Promise.all(i.map(function(){var e=(0,K.default)((function(e){var n;return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,e.close(t)];case 1:return r.sent(),[3,3];case 2:return n=r.sent(),e.abort(n),[3,3];case 3:return[2]}}))}));return function(t){return e.apply(this,arguments)}}()))];case 1:return a.sent(),[2]}}))}))()}},{key:"acceptIncomingConnection",value:function(e){var t=this;return(0,K.default)((function(){var n;return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:if(t.deny.some((function(t){return t.contains(e.remoteAddr.nodeAddress().address)})))return[2,(t.log("connection from %a refused - connection remote address was in deny list",e.remoteAddr),!1)];if(t.allow.some((function(t){return t.contains(e.remoteAddr.nodeAddress().address)})))return[2,(t.incomingPendingConnections++,!0)];if(t.incomingPendingConnections===t.maxIncomingPendingConnections)return[2,(t.log("connection from %a refused - incomingPendingConnections exceeded by host",e.remoteAddr),!1)];if(!e.remoteAddr.isThinWaistAddress())return[3,4];n=e.remoteAddr.nodeAddress().address,r.label=1;case 1:return r.trys.push([1,3,,4]),[4,t.inboundConnectionRateLimiter.consume(n,1)];case 2:return r.sent(),[3,4];case 3:return r.sent(),[2,(t.log("connection from %a refused - inboundConnectionThreshold exceeded by host %s",e.remoteAddr,n),!1)];case 4:return[2,t.getConnections().length<t.maxConnections?(t.incomingPendingConnections++,!0):(t.log("connection from %a refused - maxConnections exceeded",e.remoteAddr),!1)]}}))}))()}},{key:"afterUpgradeInbound",value:function(){this.incomingPendingConnections--}},{key:"getDialQueue",value:function(){var e={queued:"queued",running:"active",errored:"error",complete:"success"};return this.dialQueue.queue.queue.map((function(t){return{id:t.id,status:e[t.status],peerId:t.options.peerId,multiaddrs:(0,ce.default)(t.options.multiaddrs).map((function(e){return pf(e)}))}}))}},{key:"isDialable",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(r){return[2,n.dialQueue.isDialable(e,t)]}))}))()}}]),e}(),jk=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"movingAverage",void 0),(0,te.default)(this,"variance",void 0),(0,te.default)(this,"deviation",void 0),(0,te.default)(this,"forecast",void 0),(0,te.default)(this,"timeSpan",void 0),(0,te.default)(this,"previousTime",void 0),this.timeSpan=t,this.movingAverage=0,this.variance=0,this.deviation=0,this.forecast=0}return(0,$.default)(e,[{key:"alpha",value:function(e,t){return 1-Math.exp(-(e-t)/this.timeSpan)}},{key:"push",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Date.now();if(null!=this.previousTime){var n=this.alpha(t,this.previousTime),r=e-this.movingAverage,i=n*r;this.movingAverage=n*e+(1-n)*this.movingAverage,this.variance=(1-n)*(this.variance+r*i),this.deviation=Math.sqrt(this.variance),this.forecast=this.movingAverage+n*r}else this.movingAverage=e;this.previousTime=t}}]),e}(),Kk=function(){"use strict";function e(){var t,n,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};(0,H.default)(this,e),(0,te.default)(this,"success",void 0),(0,te.default)(this,"failure",void 0),(0,te.default)(this,"next",void 0),(0,te.default)(this,"metric",void 0),(0,te.default)(this,"timeoutMultiplier",void 0),(0,te.default)(this,"failureMultiplier",void 0),(0,te.default)(this,"minTimeout",void 0),(0,te.default)(this,"maxTimeout",void 0);var i,a,o,u,s=null!==(n=r.interval)&&void 0!==n?n:5e3;this.success=new jk(s),this.failure=new jk(s),this.next=new jk(s),this.failureMultiplier=null!==(i=r.failureMultiplier)&&void 0!==i?i:2,this.timeoutMultiplier=null!==(a=r.timeoutMultiplier)&&void 0!==a?a:1.2,this.minTimeout=null!==(o=r.minTimeout)&&void 0!==o?o:5e3,this.maxTimeout=null!==(u=r.maxTimeout)&&void 0!==u?u:6e4,null!=r.metricName&&(this.metric=null===(t=r.metrics)||void 0===t?void 0:t.registerMetricGroup(r.metricName))}return(0,$.default)(e,[{key:"getTimeoutSignal",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=Math.round(this.next.movingAverage*(null!==(e=t.timeoutFactor)&&void 0!==e?e:this.timeoutMultiplier));n<this.minTimeout&&(n=this.minTimeout),n>this.maxTimeout&&(n=this.maxTimeout);var r=AbortSignal.timeout(n),i=yk([t.signal,r]);return i.start=Date.now(),i.timeout=n,i}},{key:"cleanUp",value:function(e){var t,n,r=Date.now()-e.start;e.aborted?(this.failure.push(r),this.next.push(r*this.failureMultiplier),null===(t=this.metric)||void 0===t||t.update({failureMovingAverage:this.failure.movingAverage,failureDeviation:this.failure.deviation,failureForecast:this.failure.forecast,failureVariance:this.failure.variance,failure:r})):(this.success.push(r),this.next.push(r),null===(n=this.metric)||void 0===n||n.update({successMovingAverage:this.success.movingAverage,successDeviation:this.success.deviation,successForecast:this.success.forecast,successVariance:this.success.variance,success:r}))}}]),e}(),Vk=Symbol.toStringTag,Hk=Ta,Wk=function(){"use strict";function e(t){var n,r,i,a,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};(0,H.default)(this,e),(0,te.default)(this,"protocol",void 0),(0,te.default)(this,"components",void 0),(0,te.default)(this,"log",void 0),(0,te.default)(this,"heartbeatInterval",void 0),(0,te.default)(this,"pingIntervalMs",void 0),(0,te.default)(this,"abortController",void 0),(0,te.default)(this,"timeout",void 0),(0,te.default)(this,"abortConnectionOnPingFailure",void 0),(0,te.default)(this,Vk,"@libp2p/connection-monitor"),(0,te.default)(this,Hk,["@libp2p/connection-monitor"]),this.components=t,this.protocol="/".concat(null!==(n=o.protocolPrefix)&&void 0!==n?n:"ipfs","/ping/1.0.0"),this.log=t.logger.forComponent("libp2p:connection-monitor"),this.pingIntervalMs=null!==(r=o.pingInterval)&&void 0!==r?r:1e4,this.abortConnectionOnPingFailure=null===(i=o.abortConnectionOnPingFailure)||void 0===i||i,this.timeout=new Kk((0,oe.default)((0,ae.default)({},null!==(a=o.pingTimeout)&&void 0!==a?a:{}),{metrics:t.metrics,metricName:"libp2p_connection_monitor_ping_time_milliseconds"}))}return(0,$.default)(e,[{key:"start",value:function(){var e=this;this.abortController=new AbortController,this.abortController.signal,this.heartbeatInterval=setInterval((function(){e.components.connectionManager.getConnections().forEach((function(t){var n=e;Promise.resolve().then((0,K.default)((function(){var e,r,i,a,o;return(0,pe.__generator)(this,(function(u){switch(u.label){case 0:e=Date.now(),u.label=1;case 1:return u.trys.push([1,5,,6]),i=n.timeout.getTimeoutSignal({signal:null===(r=n.abortController)||void 0===r?void 0:r.signal}),[4,t.newStream(n.protocol,{signal:i,runOnLimitedConnection:!0})];case 2:return a=Id.apply(void 0,[u.sent()]),e=Date.now(),[4,Promise.all([a.write(Ol(32),{signal:i}),a.read({bytes:32,signal:i})])];case 3:return u.sent(),t.rtt=Date.now()-e,[4,a.unwrap().close({signal:i})];case 4:return u.sent(),[3,6];case 5:if("UnsupportedProtocolError"!==(o=u.sent()).name)throw o;return t.rtt=(Date.now()-e)/2,[3,6];case 6:return[2]}}))}))).catch((function(n){e.log.error("error during heartbeat",n),e.abortConnectionOnPingFailure?(e.log.error("aborting connection due to ping failure"),t.abort(n)):e.log("connection ping failed, but not aborting due to abortConnectionOnPingFailure flag")}))}))}),this.pingIntervalMs)}},{key:"stop",value:function(){var e;null===(e=this.abortController)||void 0===e||e.abort(),null!=this.heartbeatInterval&&clearInterval(this.heartbeatInterval)}}]),e}(),Gk=Symbol.toStringTag,Xk=function(){"use strict";function e(t,n){var r,i,a,o,u,s,l,c,f,d,h;(0,H.default)(this,e),(0,te.default)(this,"routers",void 0),(0,te.default)(this,"started",void 0),(0,te.default)(this,"components",void 0),(0,te.default)(this,Gk,"@libp2p/content-routing"),this.routers=null!==(s=n.routers)&&void 0!==s?s:[],this.started=!1,this.components=t,this.findProviders=null!==(l=null===(r=t.metrics)||void 0===r?void 0:r.traceFunction("libp2p.contentRouting.findProviders",this.findProviders.bind(this),{optionsIndex:1,getAttributesFromArgs:function(e,t){var n=(0,se.default)(e,1)[0];return(0,oe.default)((0,ae.default)({},t),{cid:n.toString()})},getAttributesFromYieldedValue:function(e,t){return(0,oe.default)((0,ae.default)({},t),{providers:(0,ce.default)(Array.isArray(t.providers)?t.providers:[]).concat([e.id.toString()])})}}))&&void 0!==l?l:this.findProviders,this.provide=null!==(c=null===(i=t.metrics)||void 0===i?void 0:i.traceFunction("libp2p.contentRouting.provide",this.provide.bind(this),{optionsIndex:1,getAttributesFromArgs:function(e,t){var n=(0,se.default)(e,1)[0];return(0,oe.default)((0,ae.default)({},t),{cid:n.toString()})}}))&&void 0!==c?c:this.provide,this.cancelReprovide=null!==(f=null===(a=t.metrics)||void 0===a?void 0:a.traceFunction("libp2p.contentRouting.cancelReprovide",this.cancelReprovide.bind(this),{optionsIndex:1,getAttributesFromArgs:function(e,t){var n=(0,se.default)(e,1)[0];return(0,oe.default)((0,ae.default)({},t),{cid:n.toString()})}}))&&void 0!==f?f:this.cancelReprovide,this.put=null!==(d=null===(o=t.metrics)||void 0===o?void 0:o.traceFunction("libp2p.contentRouting.put",this.put.bind(this),{optionsIndex:2,getAttributesFromArgs:function(e){return{key:Ti((0,se.default)(e,1)[0],"base36")}}}))&&void 0!==d?d:this.put,this.get=null!==(h=null===(u=t.metrics)||void 0===u?void 0:u.traceFunction("libp2p.contentRouting.get",this.get.bind(this),{optionsIndex:1,getAttributesFromArgs:function(e){return{key:Ti((0,se.default)(e,1)[0],"base36")}}}))&&void 0!==h?h:this.get}return(0,$.default)(e,[{key:"isStarted",value:function(){return this.started}},{key:"start",value:function(){var e=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(t){return e.started=!0,[2]}))}))()}},{key:"stop",value:function(){var e=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(t){return e.started=!1,[2]}))}))()}},{key:"findProviders",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=this;return(0,de.default)((function(){var r,i,a,o,u,s,l,c,f,d,h;return(0,pe.__generator)(this,(function(v){switch(v.label){case 0:if(0===n.routers.length)throw new jw("No content routers available");r=n,i=new zm,a=!1,o=!1,v.label=1;case 1:v.trys.push([1,11,12,17]),s=(0,j.default)(Fo.apply(void 0,(0,ce.default)(r.routers.filter((function(e){return e.findProviders instanceof Function})).map((function(n){return n.findProviders(e,t)}))))),v.label=2;case 2:return[4,(0,V.default)(s.next())];case 3:return(a=!(l=v.sent()).done)?(c=l.value,null!=(f=c)?f.multiaddrs.length>0?[4,(0,V.default)(n.components.peerStore.merge(f.id,{multiaddrs:f.multiaddrs},t))]:[3,5]:[3,8]):[3,10];case 4:v.sent(),v.label=5;case 5:return(d=i.has(f.id))?[3,7]:(i.add(f.id),[4,f]);case 6:d=v.sent(),v.label=7;case 7:d,v.label=8;case 8:v.label=9;case 9:return a=!1,[3,2];case 10:return[3,17];case 11:return h=v.sent(),o=!0,u=h,[3,17];case 12:return v.trys.push([12,,15,16]),a&&null!=s.return?[4,s.return()]:[3,14];case 13:v.sent(),v.label=14;case 14:return[3,16];case 15:if(o)throw u;return[7];case 16:return[7];case 17:return[2]}}))}))()}},{key:"provide",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:if(0===n.routers.length)throw new jw("No content routers available");return[4,Promise.all(n.routers.filter((function(e){return e.provide instanceof Function})).map(function(){var n=(0,K.default)((function(n){return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return[4,n.provide(e,t)];case 1:return r.sent(),[2]}}))}));return function(e){return n.apply(this,arguments)}}()))];case 1:return r.sent(),[2]}}))}))()}},{key:"cancelReprovide",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:if(0===n.routers.length)throw new jw("No content routers available");return[4,Promise.all(n.routers.filter((function(e){return e.cancelReprovide instanceof Function})).map(function(){var n=(0,K.default)((function(n){return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return[4,n.cancelReprovide(e,t)];case 1:return r.sent(),[2]}}))}));return function(e){return n.apply(this,arguments)}}()))];case 1:return r.sent(),[2]}}))}))()}},{key:"put",value:function(e,t,n){var r=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:if(!r.isStarted())throw new wa;return[4,Promise.all(r.routers.filter((function(e){return e.put instanceof Function})).map(function(){var r=(0,K.default)((function(r){return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:return[4,r.put(e,t,n)];case 1:return i.sent(),[2]}}))}));return function(e){return r.apply(this,arguments)}}()))];case 1:return i.sent(),[2]}}))}))()}},{key:"get",value:function(e,t){var n=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(r){if(!n.isStarted())throw new wa;return[2,Promise.any(n.routers.filter((function(e){return e.get instanceof Function})).map(function(){var n=(0,K.default)((function(n){return(0,pe.__generator)(this,(function(r){return[2,n.get(e,t)]}))}));return function(e){return n.apply(this,arguments)}}()))]}))}))()}}]),e}(),Yk=Symbol.toStringTag,Zk=function(){"use strict";function e(t){var n,r,i,a,o,u=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};(0,H.default)(this,e),(0,te.default)(this,"log",void 0),(0,te.default)(this,"peerId",void 0),(0,te.default)(this,"peerStore",void 0),(0,te.default)(this,"routers",void 0),(0,te.default)(this,Yk,"@libp2p/peer-routing"),this.log=t.logger.forComponent("libp2p:peer-routing"),this.peerId=t.peerId,this.peerStore=t.peerStore,this.routers=null!==(i=u.routers)&&void 0!==i?i:[],this.findPeer=null!==(a=null===(n=t.metrics)||void 0===n?void 0:n.traceFunction("libp2p.peerRouting.findPeer",this.findPeer.bind(this),{optionsIndex:1,getAttributesFromArgs:function(e,t){var n=(0,se.default)(e,1)[0];return(0,oe.default)((0,ae.default)({},t),{peer:n.toString()})}}))&&void 0!==a?a:this.findPeer,this.getClosestPeers=null!==(o=null===(r=t.metrics)||void 0===r?void 0:r.traceFunction("libp2p.peerRouting.getClosestPeers",this.getClosestPeers.bind(this),{optionsIndex:1,getAttributesFromArgs:function(e,t){var n=(0,se.default)(e,1)[0];return(0,oe.default)((0,ae.default)({},t),{key:Ti(n,"base36")})},getAttributesFromYieldedValue:function(e,t){return(0,oe.default)((0,ae.default)({},t),{peers:(0,ce.default)(Array.isArray(t.peers)?t.peers:[]).concat([e.id.toString()])})}}))&&void 0!==o?o:this.getClosestPeers}return(0,$.default)(e,[{key:"findPeer",value:function(e,t){var n=this;return(0,K.default)((function(){var r,i,a,o,u,s,l,c,f,d;return(0,pe.__generator)(this,(function(h){switch(h.label){case 0:if(0===n.routers.length)throw new Kw("No peer routers available");if(e.toString()===n.peerId.toString())throw new Vw("Should not try to find self");r=n,i=Fo.apply(void 0,(0,ce.default)(n.routers.filter((function(e){return e.findPeer instanceof Function})).map((function(n){return(0,de.default)((function(){var i;return(0,pe.__generator)(this,(function(a){switch(a.label){case 0:return a.trys.push([0,3,,4]),[4,(0,V.default)(n.findPeer(e,t))];case 1:return[4,a.sent()];case 2:return a.sent(),[3,4];case 3:return i=a.sent(),r.log.error(i),[3,4];case 4:return[2]}}))}))()})))),a=!1,o=!1,h.label=1;case 1:h.trys.push([1,8,9,14]),s=(0,j.default)(i),h.label=2;case 2:return[4,s.next()];case 3:return(a=!(l=h.sent()).done)?(c=l.value,null==(f=c)?[3,6]:f.multiaddrs.length>0?[4,n.peerStore.merge(f.id,{multiaddrs:f.multiaddrs},t)]:[3,5]):[3,7];case 4:h.sent(),h.label=5;case 5:return[2,f];case 6:return a=!1,[3,2];case 7:return[3,14];case 8:return d=h.sent(),o=!0,u=d,[3,14];case 9:return h.trys.push([9,,12,13]),a&&null!=s.return?[4,s.return()]:[3,11];case 10:h.sent(),h.label=11;case 11:return[3,13];case 12:if(o)throw u;return[7];case 13:return[7];case 14:throw new fa}}))}))()}},{key:"getClosestPeers",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=this;return(0,de.default)((function(){var r,i,a,o,u,s,l,c,f,d,h;return(0,pe.__generator)(this,(function(v){switch(v.label){case 0:if(0===n.routers.length)throw new Kw("No peer routers available");r=n,i=Jm(1024),a=!1,o=!1,v.label=1;case 1:v.trys.push([1,11,12,17]),s=(0,j.default)(function(){var e=(0,de.default)((function(e){var t,n,r,i,a,o,u,s,l,c,f,d,h=arguments;function v(){var e;return a?null===(e=u[0])||void 0===e?void 0:e.done:!!u.find((function(e){return e.done}))}function p(){var e;return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:if(!(u.length>0&&u[0].done))return[3,3];if(e=u[0],u.shift(),!e.ok)throw d=!0,l.resolve(),e.err;return[4,e.value];case 1:t.sent(),l.resolve(),t.label=2;case 2:return[3,0];case 3:return[2]}}))}function g(){var e,t;return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:if(!v())return[3,5];e=0,n.label=1;case 1:if(!(e<u.length))return[3,4];if(!u[e].done)return[3,3];if(t=u[e],u.splice(e,1),e--,!t.ok)throw d=!0,l.resolve(),t.err;return[4,t.value];case 2:n.sent(),l.resolve(),n.label=3;case 3:return e++,[3,1];case 4:return[3,0];case 5:return[2]}}))}return(0,pe.__generator)(this,(function(y){switch(y.label){case 0:(r=null!==(n=(t=h.length>1&&void 0!==h[1]?h[1]:{}).concurrency)&&void 0!==n?n:1/0)<1&&(r=1/0),a=null!==(i=t.ordered)&&void 0!==i&&i,o=new EventTarget,u=[],l=Io(),c=Io(),f=!1,d=!1,o.addEventListener("task-complete",(function(){c.resolve()})),Promise.resolve().then((0,K.default)((function(){var t,n,i,a,c,h,v,p,g,y;return(0,pe.__generator)(this,(function(m){switch(m.label){case 0:m.trys.push([0,15,,16]),t=!1,n=!1,m.label=1;case 1:m.trys.push([1,8,9,14]),a=(0,j.default)(e),m.label=2;case 2:return[4,a.next()];case 3:return(t=!(c=m.sent()).done)?(h=c.value,v=h,u.length===r?[4,(l=Io()).promise]:[3,5]):[3,7];case 4:m.sent(),m.label=5;case 5:if(d)return[3,7];p={done:!1},u.push(p),v().then((function(e){p.done=!0,p.ok=!0,p.value=e,o.dispatchEvent(new Mv("task-complete"))}),(function(e){p.done=!0,p.err=e,o.dispatchEvent(new Mv("task-complete"))})),m.label=6;case 6:return t=!1,[3,2];case 7:return[3,14];case 8:return g=m.sent(),n=!0,i=g,[3,14];case 9:return m.trys.push([9,,12,13]),t&&null!=a.return?[4,a.return()]:[3,11];case 10:m.sent(),m.label=11;case 11:return[3,13];case 12:if(n)throw i;return[7];case 13:return[7];case 14:return f=!0,o.dispatchEvent(new Mv("task-complete")),[3,16];case 15:return y=m.sent(),s=y,o.dispatchEvent(new Mv("task-complete")),[3,16];case 16:return[2]}}))}))),y.label=1;case 1:return v()?[3,3]:(c=Io(),[4,(0,V.default)(c.promise)]);case 2:y.sent(),y.label=3;case 3:if(null!=s)throw s;return a?[5,(0,pe.__values)((0,z.default)((0,j.default)(p()),V.default))]:[3,5];case 4:return y.sent(),[3,7];case 5:return[5,(0,pe.__values)((0,z.default)((0,j.default)(g()),V.default))];case 6:y.sent(),y.label=7;case 7:if(null!=s)throw s;if(f&&0===u.length)return[3,9];y.label=8;case 8:return[3,1];case 9:return[2]}}))}));return function(t){return e.apply(this,arguments)}}()((0,de.default)((function(){var n,i,a,o,u,s,l,c,f;return(0,pe.__generator)(this,(function(d){switch(d.label){case 0:n=Fo.apply(void 0,(0,ce.default)(r.routers.filter((function(e){return e.getClosestPeers instanceof Function})).map((function(n){return n.getClosestPeers(e,t)})))),i=!1,a=!1,d.label=1;case 1:d.trys.push([1,7,8,13]),u=(0,j.default)(n),d.label=2;case 2:return[4,(0,V.default)(u.next())];case 3:return(i=!(s=d.sent()).done)?(l=s.value,c=l,[4,(0,K.default)((function(){var e;return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:if(0!==c.multiaddrs.length)return[3,4];n.label=1;case 1:return n.trys.push([1,3,,4]),[4,r.findPeer(c.id,(0,oe.default)((0,ae.default)({},t),{useCache:!1}))];case 2:return c=n.sent(),[3,4];case 3:return e=n.sent(),[2,void r.log.error("could not find peer multiaddrs",e)];case 4:return[2,c]}}))}))]):[3,6];case 4:d.sent(),d.label=5;case 5:return i=!1,[3,2];case 6:return[3,13];case 7:return f=d.sent(),a=!0,o=f,[3,13];case 8:return d.trys.push([8,,11,12]),i&&null!=u.return?[4,u.return()]:[3,10];case 9:d.sent(),d.label=10;case 10:return[3,12];case 11:if(a)throw o;return[7];case 12:return[7];case 13:return[2]}}))}))())),v.label=2;case 2:return[4,(0,V.default)(s.next())];case 3:return(a=!(l=v.sent()).done)?(c=l.value,null!=(f=c)?f.multiaddrs.length>0?[4,(0,V.default)(n.peerStore.merge(f.id,{multiaddrs:f.multiaddrs},t))]:[3,5]:[3,8]):[3,10];case 4:v.sent(),v.label=5;case 5:return(d=i.has(f.id.toMultihash().bytes))?[3,7]:(i.add(f.id.toMultihash().bytes),[4,f]);case 6:d=v.sent(),v.label=7;case 7:d,v.label=8;case 8:v.label=9;case 9:return a=!1,[3,2];case 10:return[3,17];case 11:return h=v.sent(),o=!0,u=h,[3,17];case 12:return v.trys.push([12,,15,16]),a&&null!=s.return?[4,s.return()]:[3,14];case 13:v.sent(),v.label=14;case 14:return[3,16];case 15:if(o)throw u;return[7];case 16:return[7];case 17:return[2]}}))}))()}}]),e}(),Qk=Symbol.toStringTag,Jk=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(e){var r;return(0,H.default)(this,n),r=t.call(this),(0,te.default)((0,q.default)(r),"peerRouting",void 0),(0,te.default)((0,q.default)(r),"log",void 0),(0,te.default)((0,q.default)(r),"walking",void 0),(0,te.default)((0,q.default)(r),"walkers",void 0),(0,te.default)((0,q.default)(r),"shutdownController",void 0),(0,te.default)((0,q.default)(r),"walkController",void 0),(0,te.default)((0,q.default)(r),"needNext",void 0),(0,te.default)((0,q.default)(r),Qk,"@libp2p/random-walk"),r.log=e.logger.forComponent("libp2p:random-walk"),r.peerRouting=e.peerRouting,r.walkers=0,r.walking=!1,r.shutdownController=new AbortController,r.shutdownController.signal,(0,ue.default)(r)}return(0,$.default)(n,[{key:"start",value:function(){this.shutdownController=new AbortController,this.shutdownController.signal}},{key:"stop",value:function(){this.shutdownController.abort()}},{key:"walk",value:function(e){var t=this;return(0,de.default)((function(){var n,r,i;return(0,pe.__generator)(this,(function(a){switch(a.label){case 0:t.walking||t.startWalk(),t.walkers++,n=yk([t.shutdownController.signal,null==e?void 0:e.signal]),a.label=1;case 1:return a.trys.push([1,,6,7]),null===(r=t.needNext)||void 0===r||r.resolve(),t.needNext=Io(),[4,(0,V.default)(tb(t,"walk:peer",n,{errorEvent:"walk:error"}))];case 2:return[4,a.sent().detail];case 3:a.sent(),a.label=4;case 4:return[3,1];case 5:return[3,7];case 6:return n.clear(),t.walkers--,0===t.walkers&&(null===(i=t.walkController)||void 0===i||i.abort(),t.walkController=void 0),[7];case 7:return[2]}}))}))()}},{key:"startWalk",value:function(){var e=this;this.walking=!0,this.walkController=new AbortController,this.walkController.signal;var t=yk([this.walkController.signal,this.shutdownController.signal]),n=Date.now(),r=0,i=this;Promise.resolve().then((0,K.default)((function(){var e,n,a,o,u,s,l,c,f,d,h;return(0,pe.__generator)(this,(function(v){switch(v.label){case 0:i.log("start walk"),v.label=1;case 1:if(!(i.walkers>0))return[3,19];v.label=2;case 2:v.trys.push([2,17,,18]),e=Ol(32),n=Date.now(),a=!1,o=!1,v.label=3;case 3:v.trys.push([3,10,11,16]),s=(0,j.default)(i.peerRouting.getClosestPeers(e,{signal:t})),v.label=4;case 4:return[4,s.next()];case 5:return(a=!(l=v.sent()).done)?(c=l.value,f=c,t.aborted&&i.log("aborting walk"),t.throwIfAborted(),i.log("found peer %p after %dms for %d walkers",f.id,Date.now()-n,i.walkers),r++,i.safeDispatchEvent("walk:peer",{detail:f}),1===i.walkers&&null!=i.needNext?(i.log("wait for need next"),[4,Lo(i.needNext.promise,t)]):[3,7]):[3,9];case 6:v.sent(),v.label=7;case 7:n=Date.now(),v.label=8;case 8:return a=!1,[3,4];case 9:return[3,16];case 10:return d=v.sent(),o=!0,u=d,[3,16];case 11:return v.trys.push([11,,14,15]),a&&null!=s.return?[4,s.return()]:[3,13];case 12:v.sent(),v.label=13;case 13:return[3,15];case 14:if(o)throw u;return[7];case 15:return[7];case 16:return i.log("walk iteration for %b and %d walkers finished, found %d peers",e,i.walkers,r),[3,18];case 17:return h=v.sent(),i.log.error("random walk errored",h),i.safeDispatchEvent("walk:error",{detail:h}),[3,18];case 18:return[3,1];case 19:return i.log("no walkers left, ended walk"),[2]}}))}))).catch((function(t){e.log.error("random walk errored",t)})).finally((function(){e.log("finished walk, found %d peers after %dms",r,Date.now()-n),e.walking=!1}))}}]),n}(xa),$k=Symbol.toStringTag,e_=function(){"use strict";function e(t){var n,r=this;(0,H.default)(this,e),(0,te.default)(this,"log",void 0),(0,te.default)(this,"topologies",void 0),(0,te.default)(this,"handlers",void 0),(0,te.default)(this,"components",void 0),(0,te.default)(this,$k,"@libp2p/registrar"),this.components=t,this.log=t.logger.forComponent("libp2p:registrar"),this.topologies=new Map,null===(n=t.metrics)||void 0===n||n.registerMetricGroup("libp2p_registrar_topologies",{calculate:function(){var e={},t=!0,n=!1,i=void 0;try{for(var a,o=r.topologies[Symbol.iterator]();!(t=(a=o.next()).done);t=!0){var u=(0,se.default)(a.value,2),s=u[0],l=u[1];e[s]=l.size}}catch(e){n=!0,i=e}finally{try{t||null==o.return||o.return()}finally{if(n)throw i}}return e}}),this.handlers=Aw({name:"libp2p_registrar_protocol_handlers",metrics:t.metrics}),this._onDisconnect=this._onDisconnect.bind(this),this._onPeerUpdate=this._onPeerUpdate.bind(this),this._onPeerIdentify=this._onPeerIdentify.bind(this),this.components.events.addEventListener("peer:disconnect",this._onDisconnect),this.components.events.addEventListener("peer:update",this._onPeerUpdate),this.components.events.addEventListener("peer:identify",this._onPeerIdentify)}return(0,$.default)(e,[{key:"getProtocols",value:function(){return Array.from(new Set((0,ce.default)(this.handlers.keys()))).sort()}},{key:"getHandler",value:function(e){var t=this.handlers.get(e);if(null==t)throw new Hw("No handler registered for protocol "+e);return t}},{key:"getTopologies",value:function(e){var t=this.topologies.get(e);return null==t?[]:(0,ce.default)(t.values())}},{key:"handle",value:function(e,t,n){var r=this;return(0,K.default)((function(){var i;return(0,pe.__generator)(this,(function(a){switch(a.label){case 0:if(r.handlers.has(e)&&!0!==(null==n?void 0:n.force))throw new Ww("Handler already registered for protocol "+e);return i=iy.bind({ignoreUndefined:!0})({maxInboundStreams:32,maxOutboundStreams:64},n),r.handlers.set(e,{handler:t,options:i}),[4,r.components.peerStore.merge(r.components.peerId,{protocols:[e]},n)];case 1:return a.sent(),[2]}}))}))()}},{key:"unhandle",value:function(e,t){var n=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return(Array.isArray(e)?e:[e]).forEach((function(e){n.handlers.delete(e)})),[4,n.components.peerStore.patch(n.components.peerId,{protocols:n.getProtocols()},t)];case 1:return r.sent(),[2]}}))}))()}},{key:"register",value:function(e,t){var n=this;return(0,K.default)((function(){var r,i;return(0,pe.__generator)(this,(function(a){if(null==t)throw new ra("invalid topology");return r="".concat((1e9*Math.random()).toString(36)).concat(Date.now()),[2,(null==(i=n.topologies.get(e))&&(i=new Map,n.topologies.set(e,i)),i.set(r,t),r)]}))}))()}},{key:"unregister",value:function(e){var t=!0,n=!1,r=void 0;try{for(var i,a=this.topologies.entries()[Symbol.iterator]();!(t=(i=a.next()).done);t=!0){var o=(0,se.default)(i.value,2),u=o[0],s=o[1];s.has(e)&&(s.delete(e),0===s.size&&this.topologies.delete(u))}}catch(e){n=!0,r=e}finally{try{t||null==a.return||a.return()}finally{if(n)throw r}}}},{key:"_onDisconnect",value:function(e){var t=this,n=e.detail,r={signal:AbortSignal.timeout(5e3)};this.components.peerStore.get(n,r).then((function(e){var r=!0,i=!1,a=void 0;try{for(var o,u=e.protocols[Symbol.iterator]();!(r=(o=u.next()).done);r=!0){var s,l,c,f=o.value,d=t.topologies.get(f),h=!0,v=!1,p=void 0;if(null!=d)try{for(var g,y=d.values()[Symbol.iterator]();!(h=(g=y.next()).done);h=!0){var m=g.value;!1!==(null===(s=m.filter)||void 0===s?void 0:s.has(n))&&(null===(l=m.filter)||void 0===l||l.remove(n),null===(c=m.onDisconnect)||void 0===c||c.call(m,n))}}catch(e){v=!0,p=e}finally{try{h||null==y.return||y.return()}finally{if(v)throw p}}}}catch(e){i=!0,a=e}finally{try{r||null==u.return||u.return()}finally{if(i)throw a}}})).catch((function(e){"NotFoundError"!==e.name&&t.log.error("could not inform topologies of disconnecting peer %p",n,e)}))}},{key:"_onPeerUpdate",value:function(e){var t,n=e.detail,r=n.peer,i=n.previous,a=(null!==(t=null==i?void 0:i.protocols)&&void 0!==t?t:[]).filter((function(e){return!r.protocols.includes(e)})),o=!0,u=!1,s=void 0;try{for(var l,c=a[Symbol.iterator]();!(o=(l=c.next()).done);o=!0){var f,d,h,v=l.value,p=this.topologies.get(v),g=!0,y=!1,m=void 0;if(null!=p)try{for(var b,w=p.values()[Symbol.iterator]();!(g=(b=w.next()).done);g=!0){var k=b.value;!1!==(null===(f=k.filter)||void 0===f?void 0:f.has(r.id))&&(null===(d=k.filter)||void 0===d||d.remove(r.id),null===(h=k.onDisconnect)||void 0===h||h.call(k,r.id))}}catch(e){y=!0,m=e}finally{try{g||null==w.return||w.return()}finally{if(y)throw m}}}}catch(e){u=!0,s=e}finally{try{o||null==c.return||c.return()}finally{if(u)throw s}}}},{key:"_onPeerIdentify",value:function(e){var t=e.detail.protocols,n=e.detail.connection,r=e.detail.peerId,i=!0,a=!1,o=void 0;try{for(var u,s=t[Symbol.iterator]();!(i=(u=s.next()).done);i=!0){var l,c,f,d=u.value,h=this.topologies.get(d),v=!0,p=!1,g=void 0;if(null!=h)try{for(var y,m=h.values()[Symbol.iterator]();!(v=(y=m.next()).done);v=!0){var b=y.value;null!=n.limits&&!0!==b.notifyOnLimitedConnection||!0!==(null===(l=b.filter)||void 0===l?void 0:l.has(r))&&(null===(c=b.filter)||void 0===c||c.add(r),null===(f=b.onConnect)||void 0===f||f.call(b,r,n))}}catch(e){p=!0,g=e}finally{try{v||null==m.return||m.return()}finally{if(p)throw g}}}}catch(e){a=!0,o=e}finally{try{i||null==s.return||s.return()}finally{if(a)throw o}}}}]),e}(),t_=Symbol.toStringTag,n_=function(){"use strict";function e(t){var n,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};(0,H.default)(this,e),(0,te.default)(this,"log",void 0),(0,te.default)(this,"components",void 0),(0,te.default)(this,"transports",void 0),(0,te.default)(this,"listeners",void 0),(0,te.default)(this,"faultTolerance",void 0),(0,te.default)(this,"started",void 0),(0,te.default)(this,t_,"@libp2p/transport-manager"),this.log=t.logger.forComponent("libp2p:transports"),this.components=t,this.started=!1,this.transports=Aw({name:"libp2p_transport_manager_transports",metrics:this.components.metrics}),this.listeners=Aw({name:"libp2p_transport_manager_listeners",metrics:this.components.metrics}),this.faultTolerance=null!==(n=r.faultTolerance)&&void 0!==n?n:Zi.FATAL_ALL}return(0,$.default)(e,[{key:"add",value:function(e){var t=e[Symbol.toStringTag];if(null==t)throw new ra("Transport must have a valid tag");if(this.transports.has(t))throw new ra("There is already a transport with the tag "+t);this.log("adding transport %s",t),this.transports.set(t,e),this.listeners.has(t)||this.listeners.set(t,[])}},{key:"isStarted",value:function(){return this.started}},{key:"start",value:function(){this.started=!0}},{key:"afterStart",value:function(){var e=this;return(0,K.default)((function(){var t;return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:return t=e.components.addressManager.getListenAddrs(),[4,e.listen(t)];case 1:return n.sent(),[2]}}))}))()}},{key:"stop",value:function(){var e=this;return(0,K.default)((function(){var t,n,r,i,a,o,u,s,l,c,f,d,h,v,p,g;return(0,pe.__generator)(this,(function(y){switch(y.label){case 0:t=[],n=!0,r=!1,i=void 0;try{for(a=e.listeners[Symbol.iterator]();!(n=(o=a.next()).done);n=!0)for(u=(0,se.default)(o.value,2),s=u[0],l=u[1],e.log("closing listeners for %s",s);l.length>0;)null!=(c=l.pop())&&t.push(c.close())}catch(e){r=!0,i=e}finally{try{n||null==a.return||a.return()}finally{if(r)throw i}}return[4,Promise.all(t)];case 1:y.sent(),e.log("all listeners closed"),f=!0,d=!1,h=void 0;try{for(v=e.listeners.keys()[Symbol.iterator]();!(f=(p=v.next()).done);f=!0)g=p.value,e.listeners.set(g,[])}catch(e){d=!0,h=e}finally{try{f||null==v.return||v.return()}finally{if(d)throw h}}return e.started=!1,[2]}}))}))()}},{key:"dial",value:function(e,t){var n=this;return(0,K.default)((function(){var r,i;return(0,pe.__generator)(this,(function(a){if(null==(i=n.dialTransportForMultiaddr(e)))throw new tk("No transport available for address "+e);return[2,(null==t||null===(r=t.onProgress)||void 0===r||r.call(t,new qg("transport-manager:selected-transport",i[Symbol.toStringTag])),i.dial(e,(0,oe.default)((0,ae.default)({},t),{upgrader:n.components.upgrader})))]}))}))()}},{key:"getAddrs",value:function(){var e=[],t=!0,n=!1,r=void 0,i=!0,a=!1,o=void 0;try{for(var u,s=this.listeners.values()[Symbol.iterator]();!(i=(u=s.next()).done);i=!0){var l=u.value;try{for(var c,f=l[Symbol.iterator]();!(t=(c=f.next()).done);t=!0){var d=c.value;e=(0,ce.default)(e).concat((0,ce.default)(d.getAddrs()))}}catch(e){n=!0,r=e}finally{try{t||null==f.return||f.return()}finally{if(n)throw r}}}}catch(e){a=!0,o=e}finally{try{i||null==s.return||s.return()}finally{if(a)throw o}}return e}},{key:"getTransports",value:function(){var e;return(e=Array).of.apply(e,(0,ce.default)(this.transports.values()))}},{key:"getListeners",value:function(){var e;return(e=Array).of.apply(e,(0,ce.default)(this.listeners.values())).flat()}},{key:"dialTransportForMultiaddr",value:function(e){var t=!0,n=!1,r=void 0;try{for(var i,a=this.transports.values()[Symbol.iterator]();!(t=(i=a.next()).done);t=!0){var o=i.value;if(o.dialFilter([e]).length>0)return o}}catch(e){n=!0,r=e}finally{try{t||null==a.return||a.return()}finally{if(n)throw r}}}},{key:"listenTransportForMultiaddr",value:function(e){var t=!0,n=!1,r=void 0;try{for(var i,a=this.transports.values()[Symbol.iterator]();!(t=(i=a.next()).done);t=!0){var o=i.value;if(o.listenFilter([e]).length>0)return o}}catch(e){n=!0,r=e}finally{try{t||null==a.return||a.return()}finally{if(n)throw r}}}},{key:"listen",value:function(e){var t=this;return(0,K.default)((function(){var n,r,i,a,o,u,s,l,c,f,d,h,v,p,g,y,m,b,w,k,_,E;return(0,pe.__generator)(this,(function(S){switch(S.label){case 0:if(!t.isStarted())throw new wa("Not started");if(null==e||0===e.length)return[2,void t.log("no addresses were provided for listening, this node is dial only")];n={errors:new Map,ipv4:{success:0,attempts:0},ipv6:{success:0,attempts:0}},e.forEach((function(e){n.errors.set(e.toString(),new Xw)})),r=[],i=!0,a=!1,o=void 0;try{for(u=t.transports.entries()[Symbol.iterator]();!(i=(s=u.next()).done);i=!0){l=(0,se.default)(s.value,2),c=l[0],f=l[1],d=f.listenFilter(e),h=!0,v=!1,p=void 0;try{for(g=d[Symbol.iterator]();!(h=(y=g.next()).done);h=!0)m=y.value,t.log("creating listener for %s on %a",c,m),b=f.createListener({upgrader:t.components.upgrader}),null==(k=null!==(w=t.listeners.get(c))&&void 0!==w?w:[])&&(k=[],t.listeners.set(c,k)),k.push(b),b.addEventListener("listening",(function(){t.components.events.safeDispatchEvent("transport:listening",{detail:b})})),b.addEventListener("close",(function(){var e=k.findIndex((function(e){return e===b}));k.splice(e,1),t.components.events.safeDispatchEvent("transport:close",{detail:b})})),bp.matches(m)?n.ipv4.attempts++:wp.matches(m)&&n.ipv6.attempts++,r.push(b.listen(m).then((function(){n.errors.delete(m.toString()),bp.matches(m)&&n.ipv4.success++,wp.matches(m)&&n.ipv6.success++}),(function(e){throw t.log.error("transport %s could not listen on address %a - %e",c,m,e),n.errors.set(m.toString(),e),e})))}catch(e){v=!0,p=e}finally{try{h||null==g.return||g.return()}finally{if(v)throw p}}}}catch(e){a=!0,o=e}finally{try{i||null==u.return||u.return()}finally{if(a)throw o}}return[4,Promise.allSettled(r)];case 1:if(!((_=S.sent()).length>0&&_.every((function(e){return"fulfilled"===e.status}))))if(t.ipv6Unsupported(n))t.log("all IPv4 addresses succeed but all IPv6 failed");else{if(t.faultTolerance!==Zi.NO_FATAL)throw new Yw("Some configured addresses failed to be listened on, you may need to remove one or more listen addresses from your configuration or set `transportManager.faultTolerance` to NO_FATAL:\n"+(0,ce.default)(n.errors.entries()).map((function(e){var t=(0,se.default)(e,2),n=t[0],r=t[1];return"\n  ".concat(n,": ").concat((""+(null!==(E=r.stack)&&void 0!==E?E:r)).split("\n").join("\n  "),"\n")})).join(""));t.log("failed to listen on any address but fault tolerance allows this")}return[2]}}))}))()}},{key:"ipv6Unsupported",value:function(e){if(0===e.ipv4.attempts||0===e.ipv6.attempts)return!1;var t=e.ipv4.attempts===e.ipv4.success,n=0===e.ipv6.success;return t&&n}},{key:"remove",value:function(e){var t=this;return(0,K.default)((function(){var n,r,i,a;return(0,pe.__generator)(this,(function(o){switch(o.label){case 0:for(r=null!==(n=t.listeners.get(e))&&void 0!==n?n:[],t.log.trace("removing transport %s",e),i=[],t.log.trace("closing listeners for %s",e);r.length>0;)null!=(a=r.pop())&&i.push(a.close());return[4,Promise.all(i)];case 1:return o.sent(),t.transports.delete(e),t.listeners.delete(e),[2]}}))}))()}},{key:"removeAll",value:function(){var e=this;return(0,K.default)((function(){var t,n,r,i,a,o,u;return(0,pe.__generator)(this,(function(s){switch(s.label){case 0:t=[],n=!0,r=!1,i=void 0;try{for(a=e.transports.keys()[Symbol.iterator]();!(n=(o=a.next()).done);n=!0)u=o.value,t.push(e.remove(u))}catch(e){r=!0,i=e}finally{try{n||null==a.return||a.return()}finally{if(r)throw i}}return[4,Promise.all(t)];case 1:return s.sent(),[2]}}))}))()}}]),e}(),r_="/multistream/1.0.0",i_=1024,a_=wn("\n");function o_(e,t,n){return u_.apply(this,arguments)}function u_(){return u_=(0,K.default)((function(e,t,n){return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return[4,e.write(t,n)];case 1:return r.sent(),[2]}}))})),u_.apply(this,arguments)}function s_(e,t){return l_.apply(this,arguments)}function l_(){return l_=(0,K.default)((function(e,t){return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:return[4,function(){var e=(0,K.default)((function(e,t){var n;return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return[4,e.read(t)];case 1:if(0===(n=r.sent()).byteLength||n.get(n.byteLength-1)!==a_[0])throw t.log.error("Invalid mss message - missing newline",n),new ya("Missing newline");return[2,n.sublist(0,-1)]}}))}));return function(t,n){return e.apply(this,arguments)}}()(e,t)];case 1:return[2,Ti(n.sent().subarray())]}}))})),l_.apply(this,arguments)}function c_(e,t,n){return f_.apply(this,arguments)}function f_(){return f_=(0,K.default)((function(e,t,n){var r,i,a,o,u,s,l,c,f,d,h,v,p;return(0,pe.__generator)(this,(function(g){switch(g.label){case 0:if(1===(t=Array.isArray(t)?(0,ce.default)(t):[t]).length&&!1===n.negotiateFully)return[2,function(e,t,n){var r=e.sink.bind(e),i=e.source,a=!1,o=!1,u=Io(),s=!1,l=!1,c=Io(),f=!1,d=!1,h=Io(),v=Pd({sink:r,source:i},(0,oe.default)((0,ae.default)({},n),{maxDataLength:i_}));function p(){return g.apply(this,arguments)}function g(){return g=(0,K.default)((function(){return(0,pe.__generator)(this,(function(e){switch(e.label){case 0:return o?(n.log.trace("optimistic: already negotiating %s stream",t),[4,u.promise]):[3,2];case 1:return[2,void e.sent()];case 2:o=!0,e.label=3;case 3:return e.trys.push([3,,8,9]),s?[3,5]:(n.log.trace("optimistic: doing send protocol for %s stream",t),[4,y()]);case 4:e.sent(),e.label=5;case 5:return f?[3,7]:(n.log.trace("optimistic: doing read protocol for %s stream",t),[4,b()]);case 6:e.sent(),e.label=7;case 7:return[3,9];case 8:return o=!1,a=!0,u.resolve(),[7];case 9:return[2]}}))})),g.apply(this,arguments)}function y(){return m.apply(this,arguments)}function m(){return m=(0,K.default)((function(){return(0,pe.__generator)(this,(function(e){switch(e.label){case 0:return l?[4,c.promise]:[3,2];case 1:return e.sent(),[3,6];case 2:l=!0,e.label=3;case 3:return e.trys.push([3,,5,6]),n.log.trace('optimistic: write ["%s", "%s", data] in source',r_,t),[4,v.writeV([wn(r_+"\n"),wn(t+"\n")])];case 4:return e.sent(),n.log.trace('optimistic: wrote ["%s", "%s", data] in source',r_,t),[3,6];case 5:return s=!0,l=!1,c.resolve(),[7];case 6:return[2]}}))})),m.apply(this,arguments)}function b(){return w.apply(this,arguments)}function w(){return w=(0,K.default)((function(){var e;return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return d?[4,h.promise]:[3,2];case 1:return r.sent(),[3,8];case 2:d=!0,r.label=3;case 3:return r.trys.push([3,,7,8]),n.log.trace("optimistic: reading multistream select header"),[4,s_(v,n)];case 4:return e=r.sent(),n.log.trace('optimistic: read multistream select header "%s"',e),e===r_?[4,s_(v,n)]:[3,6];case 5:e=r.sent(),r.label=6;case 6:if(n.log.trace('optimistic: read protocol "%s", expecting "%s"',e,t),e!==t)throw new ga("protocol selection failed");return[3,8];case 7:return f=!0,d=!1,h.resolve(),[7];case 8:return[2]}}))})),w.apply(this,arguments)}if(e.sink=function(){var e=(0,K.default)((function(e){var r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:return r=v.unwrap(),[4,(0,r.sink)((0,de.default)((function(){var r,i,a,o,u,f,d,h,v,g;return(0,pe.__generator)(this,(function(y){switch(y.label){case 0:r=!1,i=!1,a=!1,y.label=1;case 1:y.trys.push([1,12,13,18]),u=(0,j.default)(e),y.label=2;case 2:return[4,(0,V.default)(u.next())];case 3:return(i=!(f=y.sent()).done)?(d=f.value,h=d,l?[4,(0,V.default)(c.promise)]:[3,5]):[3,11];case 4:y.sent(),y.label=5;case 5:return s?[4,h]:[3,7];case 6:return y.sent(),[3,9];case 7:return l=!0,n.log.trace('optimistic: write ["%s", "%s", data(%d)] in sink',r_,t,h.byteLength),v=t+"\n",[4,new po(Uint8Array.from([19]),wn(r_+"\n"),Ce(v.length),wn(v),h).subarray()];case 8:y.sent(),n.log.trace('optimistic: wrote ["%s", "%s", data(%d)] in sink',r_,t,h.byteLength),s=!0,l=!1,c.resolve(),p().catch((function(e){n.log.error("could not finish optimistic protocol negotiation of %s",t,e)})),y.label=9;case 9:r=!0,y.label=10;case 10:return i=!1,[3,2];case 11:return[3,18];case 12:return g=y.sent(),a=!0,o=g,[3,18];case 13:return y.trys.push([13,,16,17]),i&&null!=u.return?[4,u.return()]:[3,15];case 14:y.sent(),y.label=15;case 15:return[3,17];case 16:if(a)throw o;return[7];case 17:return[7];case 18:return r?[3,20]:[4,(0,V.default)(p())];case 19:y.sent(),y.label=20;case 20:return[2]}}))}))())];case 1:return i.sent(),[2]}}))}));return function(t){return e.apply(this,arguments)}}(),e.source=(0,de.default)((function(){return(0,pe.__generator)(this,(function(e){switch(e.label){case 0:return[4,(0,V.default)(p())];case 1:return e.sent(),n.log.trace('optimistic: reading data from "%s" stream',t),[5,(0,pe.__values)((0,z.default)((0,j.default)(v.unwrap().source),V.default))];case 2:return e.sent(),[2]}}))}))(),null!=e.closeRead){var k=e.closeRead.bind(e);e.closeRead=function(){var e=(0,K.default)((function(e){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return a?[3,2]:[4,p().catch((function(e){n.log.error("could not negotiate protocol before close read",e)}))];case 1:t.sent(),t.label=2;case 2:return[4,k(e)];case 3:return t.sent(),[2]}}))}));return function(t){return e.apply(this,arguments)}}()}if(null!=e.closeWrite){var _=e.closeWrite.bind(e);e.closeWrite=function(){var e=(0,K.default)((function(e){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return a?[3,2]:[4,p().catch((function(e){n.log.error("could not negotiate protocol before close write",e)}))];case 1:t.sent(),t.label=2;case 2:return[4,_(e)];case 3:return t.sent(),[2]}}))}));return function(t){return e.apply(this,arguments)}}()}if(null!=e.close){var E=e.close.bind(e);e.close=function(){var e=(0,K.default)((function(e){var t;return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:return t=[],l&&t.push(c.promise),d&&t.push(h.promise),t.length>0?[4,Lo(Promise.all(t),null==e?void 0:e.signal)]:[3,2];case 1:return n.sent(),[3,3];case 2:a=!0,o=!1,u.resolve(),n.label=3;case 3:return[4,E(e)];case 4:return n.sent(),[2]}}))}));return function(t){return e.apply(this,arguments)}}()}return{stream:e,protocol:t}}(e,t[0],n)];if(r=Pd(e,(0,oe.default)((0,ae.default)({},n),{maxDataLength:i_})),null==(i=t.shift()))throw Error("At least one protocol must be specified");return n.log.trace('select: write ["%s", "%s"]',r_,i),a=wn(r_+"\n"),o=wn(i+"\n"),[4,function(){var e=(0,K.default)((function(e,t,n){return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return[4,e.writeV(t,n)];case 1:return r.sent(),[2]}}))}));return function(t,n,r){return e.apply(this,arguments)}}()(r,[a,o],n)];case 1:return g.sent(),n.log.trace("select: reading multistream-select header"),[4,s_(r,n)];case 2:return u=g.sent(),n.log.trace('select: read "%s"',u),u===r_?(n.log.trace("select: reading protocol response"),[4,s_(r,n)]):[3,4];case 3:u=g.sent(),n.log.trace('select: read "%s"',u),g.label=4;case 4:if(u===i)return[2,{stream:r.unwrap(),protocol:i}];s=!0,l=!1,c=void 0,g.label=5;case 5:g.trys.push([5,11,12,13]),f=t[Symbol.iterator](),g.label=6;case 6:return(s=(d=f.next()).done)?[3,10]:(h=d.value,n.log.trace('select: write "%s"',h),[4,o_(r,wn(h+"\n"),n)]);case 7:return g.sent(),n.log.trace("select: reading protocol response"),[4,s_(r,n)];case 8:if(v=g.sent(),n.log.trace('select: read "%s" for "%s"',v,h),v===h)return[2,{stream:r.unwrap(),protocol:h}];g.label=9;case 9:return s=!0,[3,6];case 10:return[3,13];case 11:return p=g.sent(),l=!0,c=p,[3,13];case 12:try{s||null==f.return||f.return()}finally{if(l)throw c}return[7];case 13:throw new ga("protocol selection failed")}}))})),f_.apply(this,arguments)}function d_(e,t,n){return h_.apply(this,arguments)}function h_(){return h_=(0,K.default)((function(e,t,n){var r,i,a;return(0,pe.__generator)(this,(function(o){switch(o.label){case 0:t=Array.isArray(t)?t:[t],n.log.trace("handle: available protocols %s",t),r=Pd(e,(0,oe.default)((0,ae.default)({},n),{maxDataLength:i_,maxLengthLength:2})),o.label=1;case 1:return n.log.trace("handle: reading incoming string"),[4,s_(r,n)];case 2:return i=o.sent(),n.log.trace('handle: read "%s"',i),i===r_?[3,9]:t.includes(i)?(n.log.trace('handle: respond with "%s" for "%s"',i,i),[4,o_(r,wn(i+"\n"),n)]):[3,4];case 3:return[2,(o.sent(),n.log.trace('handle: responded with "%s" for "%s"',i,i),{stream:r.unwrap(),protocol:i})];case 4:return"ls"===i?[3,6]:(n.log.trace('handle: respond with "na" for "%s"',i),[4,o_(r,wn("na\n"),n)]);case 5:return o.sent(),n.log('handle: responded with "na" for "%s"',i),[3,8];case 6:return a=(0,J.default)(po,(0,ce.default)(t.map((function(e){return _d.single(wn(e+"\n"))}))).concat([wn("\n")])),n.log.trace('handle: respond with "%s" for %s',t,i),[4,o_(r,a,n)];case 7:o.sent(),n.log.trace('handle: responded with "%s" for %s',t,i),o.label=8;case 8:return[3,11];case 9:return n.log.trace('handle: respond with "%s" for "%s"',r_,i),[4,o_(r,wn(r_+"\n"),n)];case 10:o.sent(),n.log.trace('handle: responded with "%s" for "%s"',r_,i),o.label=11;case 11:return[3,1];case 12:return[2]}}))})),h_.apply(this,arguments)}var v_=Symbol.toStringTag,p_=Hi,g_=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"id",void 0),(0,te.default)(this,"remoteAddr",void 0),(0,te.default)(this,"remotePeer",void 0),(0,te.default)(this,"direction",void 0),(0,te.default)(this,"timeline",void 0),(0,te.default)(this,"multiplexer",void 0),(0,te.default)(this,"encryption",void 0),(0,te.default)(this,"status",void 0),(0,te.default)(this,"limits",void 0),(0,te.default)(this,"log",void 0),(0,te.default)(this,"tags",void 0),(0,te.default)(this,"_newStream",void 0),(0,te.default)(this,"_close",void 0),(0,te.default)(this,"_abort",void 0),(0,te.default)(this,"_getStreams",void 0),(0,te.default)(this,v_,"Connection"),(0,te.default)(this,p_,!0);var n=t.remoteAddr,r=t.remotePeer,i=t.newStream,a=t.close,o=t.abort,u=t.getStreams;this.id="".concat(parseInt(1e9*Math.random()+"").toString(36)).concat(Date.now()),this.remoteAddr=n,this.remotePeer=r,this.direction=t.direction,this.status="open",this.timeline=t.timeline,this.multiplexer=t.multiplexer,this.encryption=t.encryption,this.limits=t.limits,this.log=t.logger.forComponent("libp2p:connection:".concat(this.direction,":").concat(this.id)),null==this.remoteAddr.getPeerId()&&(this.remoteAddr=this.remoteAddr.encapsulate("/p2p/"+this.remotePeer)),this._newStream=i,this._close=a,this._abort=o,this._getStreams=u,this.tags=[]}return(0,$.default)(e,[{key:"streams",get:function(){return this._getStreams()}},{key:"newStream",value:function(e,t){var n=this;return(0,K.default)((function(){var r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:if("closing"===n.status)throw new aa("the connection is being closed");if("closed"===n.status)throw new oa("the connection is closed");if(Array.isArray(e)||(e=[e]),null!=n.limits&&!0!==(null==t?void 0:t.runOnLimitedConnection))throw new _a("Cannot open protocol stream on limited connection");return[4,n._newStream(e,t)];case 1:return[2,((r=i.sent()).direction="outbound",r)]}}))}))()}},{key:"close",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=this;return(0,K.default)((function(){var n,r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:if("closed"===t.status||"closing"===t.status)return[3,4];t.log("closing connection to %a",t.remoteAddr),t.status="closing",null==e.signal&&(n=AbortSignal.timeout(500),e=(0,oe.default)((0,ae.default)({},e),{signal:n})),i.label=1;case 1:return i.trys.push([1,3,,4]),t.log.trace("closing underlying transport"),[4,t._close(e)];case 2:return i.sent(),t.log.trace("updating timeline with close time"),t.status="closed",t.timeline.close=Date.now(),[3,4];case 3:return r=i.sent(),t.log.error("error encountered during graceful close of connection to %a",t.remoteAddr,r),t.abort(r),[3,4];case 4:return[2]}}))}))()}},{key:"abort",value:function(e){"closed"!==this.status&&(this.log.error("aborting connection to %a due to error",this.remoteAddr,e),this.status="closing",this._abort(e),this.status="closed",this.timeline.close=Date.now())}}]),e}();function y_(e,t,n){var r=0;return n.streams.forEach((function(n){n.direction===t&&n.protocol===e&&r++})),r}var m_=Symbol.toStringTag,b_=function(){"use strict";function e(t,n){var r,i,a,o,u,s,l,c=this;(0,H.default)(this,e),(0,te.default)(this,"components",void 0),(0,te.default)(this,"connectionEncrypters",void 0),(0,te.default)(this,"streamMuxers",void 0),(0,te.default)(this,"inboundUpgradeTimeout",void 0),(0,te.default)(this,"inboundStreamProtocolNegotiationTimeout",void 0),(0,te.default)(this,"outboundStreamProtocolNegotiationTimeout",void 0),(0,te.default)(this,"events",void 0),(0,te.default)(this,"metrics",void 0),(0,te.default)(this,m_,"@libp2p/upgrader"),this.components=t,this.connectionEncrypters=Aw({name:"libp2p_upgrader_connection_encrypters",metrics:this.components.metrics}),n.connectionEncrypters.forEach((function(e){c.connectionEncrypters.set(e.protocol,e)})),this.streamMuxers=Aw({name:"libp2p_upgrader_stream_multiplexers",metrics:this.components.metrics}),n.streamMuxers.forEach((function(e){c.streamMuxers.set(e.protocol,e)})),this.inboundUpgradeTimeout=null!==(u=n.inboundUpgradeTimeout)&&void 0!==u?u:1e4,this.inboundStreamProtocolNegotiationTimeout=null!==(s=n.inboundStreamProtocolNegotiationTimeout)&&void 0!==s?s:1e4,this.outboundStreamProtocolNegotiationTimeout=null!==(l=n.outboundStreamProtocolNegotiationTimeout)&&void 0!==l?l:1e4,this.events=t.events,this.metrics={dials:null===(r=t.metrics)||void 0===r?void 0:r.registerCounterGroup("libp2p_connection_manager_dials_total"),errors:null===(i=t.metrics)||void 0===i?void 0:i.registerCounterGroup("libp2p_connection_manager_dial_errors_total"),inboundErrors:null===(a=t.metrics)||void 0===a?void 0:a.registerCounterGroup("libp2p_connection_manager_dials_inbound_errors_total"),outboundErrors:null===(o=t.metrics)||void 0===o?void 0:o.registerCounterGroup("libp2p_connection_manager_dials_outbound_errors_total")}}return(0,$.default)(e,[{key:"shouldBlockConnection",value:function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];var i=this;return(0,K.default)((function(){var t,r;return(0,pe.__generator)(this,(function(a){switch(a.label){case 0:return null==(t=i.components.connectionGater[e])?[2]:(r=!0,[4,t.apply(i.components.connectionGater,n)]);case 1:if(r===a.sent())throw new Qw("The multiaddr connection is blocked by gater."+e);return[2]}}))}))()}},{key:"createInboundAbortSignal",value:function(e){return yk([AbortSignal.timeout(this.inboundUpgradeTimeout),e])}},{key:"upgradeInbound",value:function(e,t){var n=this;return(0,K.default)((function(){var r,i,a,o,u,s,l;return(0,pe.__generator)(this,(function(c){switch(c.label){case 0:r=!1,i=n.createInboundAbortSignal(t.signal),c.label=1;case 1:return c.trys.push([1,5,6,7]),null===(a=n.metrics.dials)||void 0===a||a.increment({inbound:!0}),[4,Lo(n.components.connectionManager.acceptIncomingConnection(e),i)];case 2:if(!(r=c.sent()))throw new Jw("Connection denied");return[4,Lo(n.shouldBlockConnection("denyInboundConnection",e),i)];case 3:return c.sent(),[4,n._performUpgrade(e,"inbound",(0,oe.default)((0,ae.default)({},t),{signal:i}))];case 4:return c.sent(),[3,7];case 5:throw o=c.sent(),null===(u=n.metrics.errors)||void 0===u||u.increment({inbound:!0}),null===(s=n.metrics.inboundErrors)||void 0===s||s.increment((0,te.default)({},null!==(l=o.name)&&void 0!==l?l:"Error",!0)),o;case 6:return i.clear(),r&&n.components.connectionManager.afterUpgradeInbound(),[7];case 7:return[2]}}))}))()}},{key:"upgradeOutbound",value:function(e,t){var n=this;return(0,K.default)((function(){var r,i,a,o,u,s,l,c;return(0,pe.__generator)(this,(function(f){switch(f.label){case 0:return f.trys.push([0,4,,5]),null===(r=n.metrics.dials)||void 0===r||r.increment({outbound:!0}),i=e.remoteAddr.getPeerId(),null!=i?(a=kc(i),[4,Lo(n.shouldBlockConnection("denyOutboundConnection",a,e),t.signal)]):[3,2];case 1:f.sent(),f.label=2;case 2:return o="outbound",!1===t.initiator&&(o="inbound"),[4,n._performUpgrade(e,o,t)];case 3:return[2,f.sent()];case 4:throw u=f.sent(),null===(s=n.metrics.errors)||void 0===s||s.increment({outbound:!0}),null===(l=n.metrics.outboundErrors)||void 0===l||l.increment((0,te.default)({},null!==(c=u.name)&&void 0!==c?c:"Error",!0)),u;case 5:return[2]}}))}))()}},{key:"_performUpgrade",value:function(e,t,n){var r=this;return(0,K.default)((function(){var i,a,o,u,s,l,c,f,d,h,v,p,g,y,m,b,w;return(0,pe.__generator)(this,(function(k){switch(k.label){case 0:return null===(i=r.components.metrics)||void 0===i||i.trackMultiaddrConnection(e),e.log.trace("starting the %s connection upgrade",t),c=e,!0===(null==n?void 0:n.skipProtection)?[3,3]:(f=r.components.connectionProtector,null!=f?(e.log("protecting the %s connection",t),[4,f.protect(e,n)]):[3,2]);case 1:c=k.sent(),k.label=2;case 2:k.label=3;case 3:return k.trys.push([3,11,,12]),a=c,!0===(null==n?void 0:n.skipEncryption)?[3,6]:[4,"inbound"===t?r._encryptInbound(c,n):r._encryptOutbound(c,n)];case 4:return null==n||null===(d=n.onProgress)||void 0===d||d.call(n,new qg("upgrader:encrypt-".concat(t,"-connection"))),h=k.sent(),a=h.conn,o=h.remotePeer,l=h.protocol,s=h.streamMuxer,v=(0,ae.default)({},c,a),[4,r.shouldBlockConnection("inbound"===t?"denyInboundEncryptedConnection":"denyOutboundEncryptedConnection",o,v)];case 5:return k.sent(),[3,7];case 6:if(null==(p=e.remoteAddr.getPeerId()))throw new ha(t+" connection that skipped encryption must have a peer id");g=kc(p),l="native",o=g,k.label=7;case 7:if(o.equals(r.components.peerId))throw y=new da("Can not dial self"),e.abort(y),y;return u=a,null==(null==n?void 0:n.muxerFactory)?[3,8]:(s=n.muxerFactory,[3,10]);case 8:return null==s&&r.streamMuxers.size>0?(null==n||null===(m=n.onProgress)||void 0===m||m.call(n,new qg("upgrader:multiplex-".concat(t,"-connection"))),[4,"inbound"===t?r._multiplexInbound((0,ae.default)({},c,a),r.streamMuxers,n):r._multiplexOutbound((0,ae.default)({},c,a),r.streamMuxers,n)]):[3,10];case 9:b=k.sent(),s=b.muxerFactory,u=b.stream,k.label=10;case 10:return[3,12];case 11:throw w=k.sent(),e.log.error("failed to upgrade inbound connection %s %a - %e","inbound"===t?"from":"to",e.remoteAddr,w),w;case 12:return[4,r.shouldBlockConnection("inbound"===t?"denyInboundUpgradedConnection":"denyOutboundUpgradedConnection",o,e)];case 13:return[2,(k.sent(),e.log("successfully upgraded %s connection",t),r._createConnection({cryptoProtocol:l,direction:t,maConn:e,upgradedConn:u,muxerFactory:s,remotePeer:o,limits:null==n?void 0:n.limits}))]}}))}))()}},{key:"_createConnection",value:function(e){var t,n,r,i,a=this,o=e.cryptoProtocol,u=e.direction,s=e.maConn,l=e.upgradedConn,c=e.remotePeer,f=e.muxerFactory,d=e.limits,h=this;null!=f&&(n=f.createStreamMuxer({direction:u,onIncomingStream:function(e){if(null!=i){var t=AbortSignal.timeout(a.inboundStreamProtocolNegotiationTimeout),n=a;Promise.resolve().then((0,K.default)((function(){var r,a,o,u,s,l,f;return(0,pe.__generator)(this,(function(d){switch(d.label){case 0:return a=n.components.registrar.getProtocols(),[4,d_(e,a,{signal:t,log:e.log,yieldBytes:!1})];case 1:if(o=d.sent(),u=o.stream,s=o.protocol,null==i)return[2];if(i.log("incoming stream opened on %s",s),l=function(e,t){try{return t.getHandler(e).options.maxInboundStreams}catch(e){if("UnhandledProtocolError"!==e.name)throw e}return 32}(s,n.components.registrar),y_(s,"inbound",i)===l)throw f=new Ea('Too many inbound protocol streams for protocol "'.concat(s,'" - limit ').concat(l)),e.abort(f),f;return e.source=u.source,e.sink=u.sink,e.protocol=s,null!=u.closeWrite&&(e.closeWrite=u.closeWrite),null!=u.closeRead&&(e.closeRead=u.closeRead),null!=u.close&&(e.close=u.close),[4,n.components.peerStore.merge(c,{protocols:[s]},{signal:t})];case 2:return d.sent(),null===(r=n.components.metrics)||void 0===r||r.trackProtocolStream(e,i),n._onStream({connection:i,stream:e,protocol:s}),[2]}}))}))).catch(function(){var n=(0,K.default)((function(n){return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return i.log.error("error handling incoming stream id %s - %e",e.id,n),null==e.timeline.close?[4,e.close({signal:t}).catch((function(t){return e.abort(t)}))]:[3,2];case 1:r.sent(),r.label=2;case 2:return[2]}}))}));return function(e){return n.apply(this,arguments)}}())}}}),r=function(){var t=(0,K.default)((function(t){var r,a,o,s,l,f,d,v,p,g,y,m=arguments;return(0,pe.__generator)(this,(function(b){switch(b.label){case 0:if(r=m.length>1&&void 0!==m[1]?m[1]:{},null==n)throw new $w("Connection is not multiplexed");return i.log.trace("starting new stream for protocols %s",t),[4,n.newStream()];case 1:a=b.sent(),i.log.trace("started new stream %s for protocols %s",a.id,t),b.label=2;case 2:return b.trys.push([2,5,,6]),null==r.signal&&(a.log("no abort signal was passed while trying to negotiate protocols %s falling back to default timeout",t),s=AbortSignal.timeout(h.outboundStreamProtocolNegotiationTimeout),r=(0,oe.default)((0,ae.default)({},r),{signal:s})),a.log.trace("selecting protocol from protocols %s",t),[4,c_(a,t,(0,oe.default)((0,ae.default)({},r),{log:a.log,yieldBytes:!0}))];case 3:if(l=b.sent(),f=l.stream,d=l.protocol,a.log.trace("selected protocol %s",d),v=function(e,t){var n,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};try{var i=t.getHandler(e).options;if(null!=i.maxOutboundStreams)return i.maxOutboundStreams}catch(e){if("UnhandledProtocolError"!==e.name)throw e}return null!==(n=r.maxOutboundStreams)&&void 0!==n?n:64}(d,h.components.registrar,r),(p=y_(d,"outbound",i))>=v)throw g=new Sa('Too many outbound protocol streams for protocol "'.concat(d,'" - ').concat(p,"/").concat(v)),a.abort(g),g;return[4,h.components.peerStore.merge(c,{protocols:[d]})];case 4:return[2,(b.sent(),a.source=f.source,a.sink=f.sink,a.protocol=d,null!=f.closeWrite&&(a.closeWrite=f.closeWrite),null!=f.closeRead&&(a.closeRead=f.closeRead),null!=f.close&&(a.close=f.close),null===(o=h.components.metrics)||void 0===o||o.trackProtocolStream(a,i),a)];case 5:throw y=b.sent(),i.log.error("could not create new outbound stream on connection %s %a for protocols %s - %e","inbound"===u?"from":"to",e.maConn.remoteAddr,t,y),null==a.timeline.close&&a.abort(y),y;case 6:return[2]}}))}));return function(e){return t.apply(this,arguments)}}(),Promise.all([n.sink(l.source),l.sink(n.source)]).catch((function(e){i.log.error("error piping data through muxer - %e",e)})));var v,p,g=s.timeline,y=this;return s.timeline=new Proxy(g,{set:function(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return"close"===n[1]&&null!=n[2]&&null==g.close&&(0,K.default)((function(){var e;return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return t.trys.push([0,3,4,5]),"open"===i.status?[4,i.close()]:[3,2];case 1:t.sent(),t.label=2;case 2:return[3,5];case 3:return e=t.sent(),i.log.error("error closing connection after timeline close %e",e),[3,5];case 4:return y.events.safeDispatchEvent("connection:close",{detail:i}),[7];case 5:return[2]}}))}))().catch((function(e){i.log.error("error thrown while dispatching connection:close event %e",e)})),(t=Reflect).set.apply(t,(0,ce.default)(n))}}),s.timeline.upgraded=Date.now(),v={remoteAddr:s.remoteAddr,remotePeer:c,status:"open",direction:u,timeline:s.timeline,multiplexer:null==n?void 0:n.protocol,encryption:o,limits:d,logger:this.components.logger,newStream:null!=r?r:function(){throw new $w("Connection is not multiplexed")},getStreams:function(){return null!==(p=null==n?void 0:n.streams)&&void 0!==p?p:[]},close:function(e){return(0,K.default)((function(){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return[4,null==n?void 0:n.close(e)];case 1:return t.sent(),[4,s.close(e)];case 2:return t.sent(),[2]}}))}))()},abort:function(e){s.abort(e),null==n||n.abort(e)}},i=new g_(v),this.events.safeDispatchEvent("connection:open",{detail:i}),i.__maConnTimeline=g,i}},{key:"_onStream",value:function(e){var t=e.connection,n=e.stream,r=e.protocol,i=this.components.registrar.getHandler(r),a=i.handler,o=i.options;if(null!=t.limits&&!0!==o.runOnLimitedConnection)throw new _a("Cannot open protocol stream on limited connection");a({connection:t,stream:n})}},{key:"_encryptInbound",value:function(e,t){var n=this;return(0,K.default)((function(){var r,i,a,o,u,s,l;return(0,pe.__generator)(this,(function(c){switch(c.label){case 0:r=Array.from(n.connectionEncrypters.keys()),c.label=1;case 1:return c.trys.push([1,4,,5]),[4,d_(e,r,(0,oe.default)((0,ae.default)({},t),{log:e.log}))];case 2:if(i=c.sent(),a=i.stream,o=i.protocol,null==(u=n.connectionEncrypters.get(o)))throw new ek("no crypto module found for "+o);return e.log("encrypting inbound connection to %a using %s",e.remoteAddr,o),s=[{}],[4,u.secureInbound(a,t)];case 3:return[2,oe.default.apply(void 0,[ae.default.apply(void 0,s.concat([c.sent()])),{protocol:o}])];case 4:throw l=c.sent(),e.log.error("encrypting inbound connection from %a failed",e.remoteAddr,l),new ek(l.message);case 5:return[2]}}))}))()}},{key:"_encryptOutbound",value:function(e,t){var n=this;return(0,K.default)((function(){var r,i,a,o,u,s,l;return(0,pe.__generator)(this,(function(c){switch(c.label){case 0:r=Array.from(n.connectionEncrypters.keys()),c.label=1;case 1:return c.trys.push([1,4,,5]),e.log.trace("selecting encrypter from %s",r),[4,c_(e,r,(0,oe.default)((0,ae.default)({},t),{log:e.log,yieldBytes:!0}))];case 2:if(i=c.sent(),a=i.stream,o=i.protocol,null==(u=n.connectionEncrypters.get(o)))throw new ek("no crypto module found for "+o);return e.log("encrypting outbound connection to %a using %s",e.remoteAddr,o),s=[{}],[4,u.secureOutbound(a,t)];case 3:return[2,oe.default.apply(void 0,[ae.default.apply(void 0,s.concat([c.sent()])),{protocol:o}])];case 4:throw l=c.sent(),e.log.error("encrypting outbound connection to %a failed",e.remoteAddr,l),new ek(l.message);case 5:return[2]}}))}))()}},{key:"_multiplexOutbound",value:function(e,t,n){return(0,K.default)((function(){var r,i,a,o,u;return(0,pe.__generator)(this,(function(s){switch(s.label){case 0:r=Array.from(t.keys()),e.log("outbound selecting muxer %s",r),s.label=1;case 1:return s.trys.push([1,3,,4]),e.log.trace("selecting stream muxer from %s",r),[4,c_(e,r,(0,oe.default)((0,ae.default)({},n),{log:e.log,yieldBytes:!0}))];case 2:return i=s.sent(),a=i.stream,o=i.protocol,e.log("selected %s as muxer protocol",o),[2,{stream:a,muxerFactory:t.get(o)}];case 3:throw u=s.sent(),e.log.error("error multiplexing outbound connection",u),new $w(u+"");case 4:return[2]}}))}))()}},{key:"_multiplexInbound",value:function(e,t,n){return(0,K.default)((function(){var r,i,a,o,u;return(0,pe.__generator)(this,(function(s){switch(s.label){case 0:r=Array.from(t.keys()),e.log("inbound handling muxers %s",r),s.label=1;case 1:return s.trys.push([1,3,,4]),[4,d_(e,r,(0,oe.default)((0,ae.default)({},n),{log:e.log}))];case 2:return i=s.sent(),a=i.stream,o=i.protocol,[2,{stream:a,muxerFactory:t.get(o)}];case 3:throw u=s.sent(),e.log.error("error multiplexing inbound connection",u),new $w(u+"");case 4:return[2]}}))}))()}},{key:"getConnectionEncrypters",value:function(){return this.connectionEncrypters}},{key:"getStreamMuxers",value:function(){return this.streamMuxers}}]),e}(),w_="2.8.11",k_="js-libp2p";function __(e,t){return"".concat(null!=e?e:k_,"/").concat(null!=t?t:w_," browser/").concat(globalThis.navigator.userAgent)}var E_=new WeakSet,S_=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(e){var r,i,a,o,u,s,l,c,f,d,h;(0,H.default)(this,n),r=t.call(this),(0,Q.default)((0,q.default)(r),E_),(0,te.default)((0,q.default)(r),"peerId",void 0),(0,te.default)((0,q.default)(r),"peerStore",void 0),(0,te.default)((0,q.default)(r),"contentRouting",void 0),(0,te.default)((0,q.default)(r),"peerRouting",void 0),(0,te.default)((0,q.default)(r),"metrics",void 0),(0,te.default)((0,q.default)(r),"services",void 0),(0,te.default)((0,q.default)(r),"logger",void 0),(0,te.default)((0,q.default)(r),"status",void 0),(0,te.default)((0,q.default)(r),"components",void 0),(0,te.default)((0,q.default)(r),"log",void 0),r.status="stopped";var v,p,g,y,m,b=new xa,w=b.dispatchEvent.bind(b);b.dispatchEvent=function(e){var t=w(e),n=r.dispatchEvent(new CustomEvent(e.type,{detail:e.detail}));return t||n},r.peerId=e.peerId,r.logger=null!==(v=e.logger)&&void 0!==v?v:Dm(),r.log=r.logger.forComponent("libp2p"),r.services={};var k,_,E,S,A,I=null!==(p=null===(i=e.nodeInfo)||void 0===i?void 0:i.name)&&void 0!==p?p:k_,x=null!==(g=null===(a=e.nodeInfo)||void 0===a?void 0:a.version)&&void 0!==g?g:w_,C=r.components=function(){var e=new nk(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{});return new Proxy(e,{get:function(t,n,r){if("string"==typeof n&&!ik.includes(n)){var i=e.components[n];if(null==i&&!rk.includes(n))throw new qw(n+" not set");return i}return Reflect.get(t,n,r)},set:function(t,n,r){return"string"==typeof n?e.components[n]=r:Reflect.set(t,n,r),!0}})}({peerId:e.peerId,privateKey:e.privateKey,nodeInfo:{name:I,version:x,userAgent:null!==(y=null===(o=e.nodeInfo)||void 0===o?void 0:o.userAgent)&&void 0!==y?y:__(I,x)},logger:r.logger,events:b,datastore:null!==(m=e.datastore)&&void 0!==m?m:new Ew,connectionGater:sk(e.connectionGater),dns:e.dns});null!=e.metrics&&(r.metrics=r.configureComponent("metrics",e.metrics(r.components))),r.peerStore=r.configureComponent("peerStore",function(e){return new gw(e,arguments.length>1&&void 0!==arguments[1]?arguments[1]:{})}(C,(0,ae.default)({addressFilter:r.components.connectionGater.filterMultiaddrForPeer},e.peerStore))),C.events.addEventListener("peer:update",(function(e){if(null==e.detail.previous){var t={id:e.detail.peer.id,multiaddrs:e.detail.peer.addresses.map((function(e){return e.multiaddr}))};C.events.safeDispatchEvent("peer:discovery",{detail:t})}})),null!=e.connectionProtector&&r.configureComponent("connectionProtector",e.connectionProtector(C)),r.components.upgrader=new b_(r.components,{connectionEncrypters:(null!==(k=e.connectionEncrypters)&&void 0!==k?k:[]).map((function(e,t){return r.configureComponent("connection-encryption-"+t,e(r.components))})),streamMuxers:(null!==(_=e.streamMuxers)&&void 0!==_?_:[]).map((function(e,t){return r.configureComponent("stream-muxers-"+t,e(r.components))})),inboundUpgradeTimeout:null===(u=e.connectionManager)||void 0===u?void 0:u.inboundUpgradeTimeout,inboundStreamProtocolNegotiationTimeout:null!==(E=null===(s=e.connectionManager)||void 0===s?void 0:s.inboundStreamProtocolNegotiationTimeout)&&void 0!==E?E:null===(l=e.connectionManager)||void 0===l?void 0:l.protocolNegotiationTimeout,outboundStreamProtocolNegotiationTimeout:null!==(S=null===(c=e.connectionManager)||void 0===c?void 0:c.outboundStreamProtocolNegotiationTimeout)&&void 0!==S?S:null===(f=e.connectionManager)||void 0===f?void 0:f.protocolNegotiationTimeout}),r.configureComponent("transportManager",new n_(r.components,e.transportManager)),r.configureComponent("connectionManager",new zk(r.components,e.connectionManager)),!1!==(null===(d=e.connectionMonitor)||void 0===d?void 0:d.enabled)&&r.configureComponent("connectionMonitor",new Wk(r.components,e.connectionMonitor)),r.configureComponent("registrar",new e_(r.components)),r.configureComponent("addressManager",new Bw(r.components,e.addresses));var T,P=(null!==(A=e.peerRouters)&&void 0!==A?A:[]).map((function(e,t){return r.configureComponent("peer-router-"+t,e(r.components))}));r.peerRouting=r.components.peerRouting=r.configureComponent("peerRouting",new Zk(r.components,{routers:P}));var R,L=(null!==(T=e.contentRouters)&&void 0!==T?T:[]).map((function(e,t){return r.configureComponent("content-router-"+t,e(r.components))})),D=!0,M=!1,N=void 0;if(r.contentRouting=r.components.contentRouting=r.configureComponent("contentRouting",new Xk(r.components,{routers:L})),r.configureComponent("randomWalk",new Jk(r.components)),(null!==(R=e.peerDiscovery)&&void 0!==R?R:[]).forEach((function(e,t){r.configureComponent("peer-discovery-"+t,e(r.components)).addEventListener("peer",(function(e){(0,Z.default)(r,E_,A_).call((0,q.default)(r),e)}))})),null===(h=e.transports)||void 0===h||h.forEach((function(e,t){r.components.transportManager.add(r.configureComponent("transport-"+t,e(r.components)))})),null!=e.services)try{for(var O,U=Object.keys(e.services)[Symbol.iterator]();!(D=(O=U.next()).done);D=!0){var F,B,z=O.value,j=(0,e.services[z])(r.components);null!=j?(r.services[z]=j,r.configureComponent(z,j),null!=j[Wi]&&(r.log("registering service %s for content routing",z),L.push(j[Wi])),null!=j[Qi]&&(r.log("registering service %s for peer routing",z),P.push(j[Qi])),null!=j[Gi]&&(r.log("registering service %s for peer discovery",z),null===(B=(F=j[Gi]).addEventListener)||void 0===B||B.call(F,"peer",(function(e){(0,Z.default)(r,E_,A_).call((0,q.default)(r),e)})))):r.log.error("service factory %s returned null or undefined instance",z)}}catch(e){M=!0,N=e}finally{try{D||null==U.return||U.return()}finally{if(M)throw N}}return function(e){var t={},n=!0,r=!1,i=void 0,a=!0,o=!1,u=void 0;try{for(var s,l=Object.values(e.components)[Symbol.iterator]();!(a=(s=l.next()).done);a=!0){var c=s.value;try{for(var f,d=ak(c)[Symbol.iterator]();!(n=(f=d.next()).done);n=!0){t[f.value]=!0}}catch(e){r=!0,i=e}finally{try{n||null==d.return||d.return()}finally{if(r)throw i}}}}catch(e){o=!0,u=e}finally{try{a||null==l.return||l.return()}finally{if(o)throw u}}var h=!0,v=!1,p=void 0,g=!0,y=!1,m=void 0;try{for(var b,w=Object.values(e.components)[Symbol.iterator]();!(g=(b=w.next()).done);g=!0){var k=b.value;try{for(var _,E=ok(k)[Symbol.iterator]();!(h=(_=E.next()).done);h=!0){var S=_.value;if(!0!==t[S])throw new zw('Service "'.concat(uk(k),'" required capability "').concat(S,'" but it was not provided by any component, you may need to add additional configuration when creating your node.'))}}catch(e){v=!0,p=e}finally{try{h||null==E.return||E.return()}finally{if(v)throw p}}}}catch(e){y=!0,m=e}finally{try{g||null==w.return||w.return()}finally{if(y)throw m}}}(C),(0,ue.default)(r)}return(0,$.default)(n,[{key:"configureComponent",value:function(e,t){return null==t&&this.log.error("component %s was null or undefined",e),this.components[e]=t,t}},{key:"start",value:function(){var e=this;return(0,K.default)((function(){var t,n,r,i,a;return(0,pe.__generator)(this,(function(o){switch(o.label){case 0:if("stopped"!==e.status)return[3,7];e.status="starting",e.log("libp2p is starting"),o.label=1;case 1:return o.trys.push([1,5,,7]),[4,null===(n=(t=e.components).beforeStart)||void 0===n?void 0:n.call(t)];case 2:return o.sent(),[4,e.components.start()];case 3:return o.sent(),[4,null===(i=(r=e.components).afterStart)||void 0===i?void 0:i.call(r)];case 4:return o.sent(),e.status="started",e.safeDispatchEvent("start",{detail:e}),e.log("libp2p has started"),[3,7];case 5:return a=o.sent(),e.log.error("An error occurred starting libp2p",a),e.status="started",[4,e.stop()];case 6:throw o.sent(),a;case 7:return[2]}}))}))()}},{key:"stop",value:function(){var e=this;return(0,K.default)((function(){var t,n,r,i;return(0,pe.__generator)(this,(function(a){switch(a.label){case 0:return"started"===e.status?(e.log("libp2p is stopping"),e.status="stopping",[4,null===(n=(t=e.components).beforeStop)||void 0===n?void 0:n.call(t)]):[3,4];case 1:return a.sent(),[4,e.components.stop()];case 2:return a.sent(),[4,null===(i=(r=e.components).afterStop)||void 0===i?void 0:i.call(r)];case 3:a.sent(),e.status="stopped",e.safeDispatchEvent("stop",{detail:e}),e.log("libp2p has stopped"),a.label=4;case 4:return[2]}}))}))()}},{key:"getConnections",value:function(e){return this.components.connectionManager.getConnections(e)}},{key:"getDialQueue",value:function(){return this.components.connectionManager.getDialQueue()}},{key:"getPeers",value:function(){var e=new zm,t=!0,n=!1,r=void 0;try{for(var i,a=this.components.connectionManager.getConnections()[Symbol.iterator]();!(t=(i=a.next()).done);t=!0){var o=i.value;e.add(o.remotePeer)}}catch(e){n=!0,r=e}finally{try{t||null==a.return||a.return()}finally{if(n)throw r}}return Array.from(e)}},{key:"dial",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(r){return[2,n.components.connectionManager.openConnection(e,(0,ae.default)({priority:75},t))]}))}))()}},{key:"dialProtocol",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:if(null==t)throw new ra("no protocols were provided to open a stream");if(0===(t=Array.isArray(t)?t:[t]).length)throw new ra("no protocols were provided to open a stream");return[4,r.dial(e,n)];case 1:return[2,i.sent().newStream(t,n)]}}))}))()}},{key:"getMultiaddrs",value:function(){return this.components.addressManager.getAddresses()}},{key:"getProtocols",value:function(){return this.components.registrar.getProtocols()}},{key:"hangUp",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=this;return(0,K.default)((function(){var r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:return vf(e)&&(e=kc(null!==(r=e.getPeerId())&&void 0!==r?r:"")),[4,n.components.connectionManager.closeConnections(e,t)];case 1:return i.sent(),[2]}}))}))()}},{key:"getPublicKey",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=this;return(0,K.default)((function(){var r,i,a,o;return(0,pe.__generator)(this,(function(u){switch(u.label){case 0:if(n.log("getPublicKey %p",e),null!=e.publicKey)return[2,e.publicKey];u.label=1;case 1:return u.trys.push([1,3,,4]),[4,n.peerStore.get(e,t)];case 2:return null!=(r=u.sent()).id.publicKey?[2,r.id.publicKey]:[3,4];case 3:if("NotFoundError"!==(i=u.sent()).name)throw i;return[3,4];case 4:return a=uo([wn("/pk/"),e.toMultihash().bytes]),[4,n.contentRouting.get(a,t)];case 5:return o=fc.apply(void 0,[u.sent()]),[4,n.peerStore.patch(e,{publicKey:o},t)];case 6:return[2,(u.sent(),o)]}}))}))()}},{key:"handle",value:function(e,t,n){var r=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:return Array.isArray(e)||(e=[e]),[4,Promise.all(e.map(function(){var e=(0,K.default)((function(e){return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:return[4,r.components.registrar.handle(e,t,n)];case 1:return i.sent(),[2]}}))}));return function(t){return e.apply(this,arguments)}}()))];case 1:return i.sent(),[2]}}))}))()}},{key:"unhandle",value:function(e,t){var n=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return Array.isArray(e)||(e=[e]),[4,Promise.all(e.map(function(){var e=(0,K.default)((function(e){return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return[4,n.components.registrar.unhandle(e,t)];case 1:return r.sent(),[2]}}))}));return function(t){return e.apply(this,arguments)}}()))];case 1:return r.sent(),[2]}}))}))()}},{key:"register",value:function(e,t,n){var r=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(i){return[2,r.components.registrar.register(e,t,n)]}))}))()}},{key:"unregister",value:function(e){this.components.registrar.unregister(e)}},{key:"isDialable",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(r){return[2,n.components.connectionManager.isDialable(e,t)]}))}))()}}]),n}(xa);function A_(e){var t=this,n=e.detail;n.id.toString()!==this.peerId.toString()?this.components.peerStore.merge(n.id,{multiaddrs:n.multiaddrs}).catch((function(e){t.log.error(e)})):this.log.error("peer discovery mechanism discovered self")}function I_(){try{return!1}catch(e){return!1}}var x_="enrtree://AIRVQ5DDA4FFWLRBCHJWUWOO6X6S4ZTZ5B667LQ6AJU6PEYDLRD5O@sandbox.waku.nodes.status.im",C_="enrtree://AOGYWMBYOUIMOENHXCHILPKY3ZRFEULMFI4DOM442QSZ73TT2A7VI@test.waku.nodes.status.im",T_=to.BOOTSTRAP,P_="Invalid record id",R_=Object.freeze({__proto__:null,default:{}}),L_=BigInt(0),D_=BigInt(1),M_=BigInt(2),N_=BigInt(3),O_=BigInt(8),U_=Object.freeze({a:L_,b:BigInt(7),P:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:D_,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee")}),F_=function(e,t){return(e+t/M_)/t},B_=BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),q_=function(e){var t=U_.n,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-D_*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),a=n,o=BigInt("0x100000000000000000000000000000000"),u=F_(a*e,t),s=F_(-r*e,t),l=mE(e-u*n-s*i,t),c=mE(-u*r-s*a,t),f=l>o,d=c>o;if(f&&(l=t-l),d&&(c=t-c),l>o||c>o)throw Error("splitScalarEndo: Endomorphism failed, k="+e);return{k1neg:f,k1:l,k2neg:d,k2:c}},z_=32,j_=32;function K_(e){var t=U_.a,n=U_.b,r=mE(e*e),i=mE(r*e);return mE(i+t*e+n)}var V_=U_.a===L_,H_=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(e){return(0,H.default)(this,n),t.call(this,e)}return n}((0,he.default)(Error));function W_(e){if(!(e instanceof G_))throw new TypeError("JacobianPoint expected")}var G_=function(){"use strict";function e(t,n,r){(0,H.default)(this,e),this.x=t,this.y=n,this.z=r}return(0,$.default)(e,[{key:"equals",value:function(e){W_(e);var t=this,n=t.x,r=t.y,i=t.z,a=e.x,o=e.y,u=e.z,s=mE(i*i),l=mE(u*u),c=mE(n*l),f=mE(a*s),d=mE(mE(r*u)*l),h=mE(mE(o*i)*s);return c===f&&d===h}},{key:"negate",value:function(){return new e(this.x,mE(-this.y),this.z)}},{key:"double",value:function(){var t=this,n=t.x,r=t.y,i=t.z,a=mE(n*n),o=mE(r*r),u=mE(o*o),s=n+o,l=mE(M_*(mE(s*s)-a-u)),c=mE(N_*a),f=mE(c*c),d=mE(f-M_*l);return new e(d,mE(c*(l-d)-O_*u),mE(M_*r*i))}},{key:"add",value:function(t){W_(t);var n=this,r=n.x,i=n.y,a=n.z,o=t.x,u=t.y,s=t.z;if(o===L_||u===L_)return this;if(r===L_||i===L_)return t;var l=mE(a*a),c=mE(s*s),f=mE(r*c),d=mE(o*l),h=mE(mE(i*s)*c),v=mE(mE(u*a)*l),p=mE(d-f),g=mE(v-h);if(p===L_)return g===L_?this.double():e.ZERO;var y=mE(p*p),m=mE(p*y),b=mE(f*y),w=mE(g*g-m-M_*b);return new e(w,mE(g*(b-w)-h*m),mE(a*s*p))}},{key:"subtract",value:function(e){return this.add(e.negate())}},{key:"multiplyUnsafe",value:function(t){var n=e.ZERO;if("bigint"==(void 0===t?"undefined":(0,fe.default)(t))&&t===L_)return n;var r=yE(t);if(r===D_)return this;if(!V_){for(var i=n,a=this;r>L_;)r&D_&&(i=i.add(a)),a=a.double(),r>>=D_;return i}for(var o=q_(r),u=o.k1neg,s=o.k1,l=o.k2neg,c=o.k2,f=n,d=n,h=this;s>L_||c>L_;)s&D_&&(f=f.add(h)),c&D_&&(d=d.add(h)),h=h.double(),s>>=D_,c>>=D_;return u&&(f=f.negate()),l&&(d=d.negate()),d=new e(mE(d.x*B_),d.y,d.z),f.add(d)}},{key:"precomputeWindow",value:function(e){for(var t=V_?128/e+1:256/e+1,n=[],r=this,i=r,a=0;a<t;a++){i=r,n.push(i);for(var o=1;o<Math.pow(2,e-1);o++)i=i.add(r),n.push(i);r=i.double()}return n}},{key:"wNAF",value:function(t,n){!n&&this.equals(e.BASE)&&(n=Z_.BASE);var r=n&&n._WINDOW_SIZE||1;if(256%r)throw Error("Point#wNAF: Invalid precomputation window, must be power of 2");var i=n&&Y_.get(n);i||(i=this.precomputeWindow(r),n&&1!==r&&(i=e.normalizeZ(i),Y_.set(n,i)));for(var a=e.ZERO,o=e.BASE,u=1+(V_?128/r:256/r),s=Math.pow(2,r-1),l=BigInt(Math.pow(2,r)-1),c=Math.pow(2,r),f=BigInt(r),d=0;d<u;d++){var h=d*s,v=Number(t&l);t>>=f,v>s&&(v-=c,t+=D_);var p=h,g=h+Math.abs(v)-1,y=d%2!=0,m=v<0;0===v?o=o.add(X_(y,i[p])):a=a.add(X_(m,i[g]))}return{p:a,f:o}}},{key:"multiply",value:function(t,n){var r,i,a=yE(t);if(V_){var o=q_(a),u=o.k1neg,s=o.k1,l=o.k2neg,c=o.k2,f=this.wNAF(s,n),d=f.p,h=f.f,v=this.wNAF(c,n),p=v.p,g=v.f;d=X_(u,d),p=new e(mE((p=X_(l,p)).x*B_),p.y,p.z),r=d.add(p),i=h.add(g)}else{var y=this.wNAF(a,n);r=y.p,i=y.f}return e.normalizeZ([r,i])[0]}},{key:"toAffine",value:function(t){var n=this,r=n.x,i=n.y,a=n.z,o=this.equals(e.ZERO);null==t&&(t=o?O_:wE(a));var u=t,s=mE(u*u),l=mE(s*u),c=mE(r*s),f=mE(i*l),d=mE(a*u);if(o)return Z_.ZERO;if(d!==D_)throw Error("invZ was invalid");return new Z_(c,f)}}],[{key:"fromAffine",value:function(t){if(!(t instanceof Z_))throw new TypeError("JacobianPoint#fromAffine: expected Point");return t.equals(Z_.ZERO)?e.ZERO:new e(t.x,t.y,D_)}},{key:"toAffineBatch",value:function(e){var t=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:U_.P,n=Array(e.length),r=wE(e.reduce((function(e,r,i){return r===L_?e:(n[i]=e,mE(e*r,t))}),D_),t);return e.reduceRight((function(e,r,i){return r===L_?e:(n[i]=mE(e*n[i],t),mE(e*r,t))}),r),n}(e.map((function(e){return e.z})));return e.map((function(e,n){return e.toAffine(t[n])}))}},{key:"normalizeZ",value:function(t){return e.toAffineBatch(t).map(e.fromAffine)}}]),e}();function X_(e,t){var n=t.negate();return e?n:t}G_.BASE=new G_(U_.Gx,U_.Gy,D_),G_.ZERO=new G_(L_,D_,L_);var Y_=new WeakMap,Z_=function(){"use strict";function e(t,n){(0,H.default)(this,e),this.x=t,this.y=n}return(0,$.default)(e,[{key:"_setWindowSize",value:function(e){this._WINDOW_SIZE=e,Y_.delete(this)}},{key:"hasEvenY",value:function(){return this.y%M_===L_}},{key:"toRawBytes",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return uE(this.toHex(e))}},{key:"toHex",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t=fE(this.x);return e?"".concat(this.hasEvenY()?"02":"03").concat(t):"04".concat(t).concat(fE(this.y))}},{key:"toHexX",value:function(){return this.toHex(!0).slice(2)}},{key:"toRawX",value:function(){return this.toRawBytes(!0).slice(1)}},{key:"assertValidity",value:function(){var e="Point is not on elliptic curve",t=this.x,n=this.y;if(!SE(t)||!SE(n))throw Error(e);var r=mE(n*n);if(mE(r-K_(t))!==L_)throw Error(e)}},{key:"equals",value:function(e){return this.x===e.x&&this.y===e.y}},{key:"negate",value:function(){return new e(this.x,mE(-this.y))}},{key:"double",value:function(){return G_.fromAffine(this).double().toAffine()}},{key:"add",value:function(e){return G_.fromAffine(this).add(G_.fromAffine(e)).toAffine()}},{key:"subtract",value:function(e){return this.add(e.negate())}},{key:"multiply",value:function(e){return G_.fromAffine(this).multiply(e,this).toAffine()}},{key:"multiplyAndAddUnsafe",value:function(t,n,r){var i=G_.fromAffine(this),a=n===L_||n===D_||this!==e.BASE?i.multiplyUnsafe(n):i.multiply(n),o=G_.fromAffine(t).multiplyUnsafe(r),u=a.add(o);return u.equals(G_.ZERO)?void 0:u.toAffine()}}],[{key:"fromCompressedHex",value:function(t){var n=32===t.length,r=pE(n?t:t.subarray(1));if(!SE(r))throw Error("Point is not on curve");var i=function(e){var t=U_.P,n=BigInt(6),r=BigInt(11),i=BigInt(22),a=BigInt(23),o=BigInt(44),u=BigInt(88),s=e*e*e%t,l=s*s*e%t,c=bE(l,N_)*l%t,f=bE(c,N_)*l%t,d=bE(f,M_)*s%t,h=bE(d,r)*d%t,v=bE(h,i)*h%t,p=bE(v,o)*v%t,g=bE(p,u)*p%t,y=bE(g,o)*v%t,m=bE(y,N_)*l%t,b=bE(m,a)*h%t,w=bE(b,n)*s%t,k=bE(w,M_);if(k*k%t!==e)throw Error("Cannot find square root");return k}(K_(r)),a=(i&D_)===D_;n?a&&(i=mE(-i)):!(1&~t[0])!==a&&(i=mE(-i));var o=new e(r,i);return o.assertValidity(),o}},{key:"fromUncompressedHex",value:function(t){var n=new e(pE(t.subarray(1,33)),pE(t.subarray(33,65)));return n.assertValidity(),n}},{key:"fromHex",value:function(e){var t=gE(e),n=t.length,r=t[0];if(n===z_)return this.fromCompressedHex(t);if(33===n&&(2===r||3===r))return this.fromCompressedHex(t);if(65===n&&4===r)return this.fromUncompressedHex(t);throw Error("Point.fromHex: received invalid point. Expected 32-33 compressed bytes or 65 uncompressed bytes, not "+n)}},{key:"fromPrivateKey",value:function(t){return e.BASE.multiply(IE(t))}},{key:"fromSignature",value:function(t,n,r){var i=xE(n),a=i.r,o=i.s;if(![0,1,2,3].includes(r))throw Error("Cannot recover: invalid recovery bit");var u=kE(gE(t)),s=U_.n,l=2===r||3===r?a+s:a,c=wE(l,s),f=mE(-u*c,s),d=mE(o*c,s),h=1&r?"03":"02",v=e.fromHex(h+fE(l)),p=e.BASE.multiplyAndAddUnsafe(v,f,d);if(!p)throw Error("Cannot recover signature: point at infinify");return p.assertValidity(),p}}]),e}();function Q_(e){return Number.parseInt(e[0],16)>=8?"00"+e:e}function J_(e){if(e.length<2||2!==e[0])throw Error("Invalid signature integer tag: "+iE(e));var t=e[1],n=e.subarray(2,t+2);if(!t||n.length!==t)throw Error("Invalid signature integer: wrong length");if(0===n[0]&&n[1]<=127)throw Error("Invalid signature integer: trailing length");return{data:pE(n),left:e.subarray(t+2)}}Z_.BASE=new Z_(U_.Gx,U_.Gy),Z_.ZERO=new Z_(L_,L_);var $_=function(){"use strict";function e(t,n){(0,H.default)(this,e),this.r=t,this.s=n,this.assertValidity()}return(0,$.default)(e,[{key:"assertValidity",value:function(){var e=this.r,t=this.s;if(!EE(e))throw Error("Invalid Signature: r must be 0 < r < n");if(!EE(t))throw Error("Invalid Signature: s must be 0 < s < n")}},{key:"hasHighS",value:function(){var e=U_.n>>D_;return this.s>e}},{key:"normalizeS",value:function(){return this.hasHighS()?new e(this.r,mE(-this.s,U_.n)):this}},{key:"toDERRawBytes",value:function(){return uE(this.toDERHex())}},{key:"toDERHex",value:function(){var e=Q_(hE(this.s)),t=Q_(hE(this.r)),n=e.length/2,r=t.length/2,i=hE(n),a=hE(r);return"30".concat(hE(r+n+4),"02").concat(a).concat(t,"02").concat(i).concat(e)}},{key:"toRawBytes",value:function(){return this.toDERRawBytes()}},{key:"toHex",value:function(){return this.toDERHex()}},{key:"toCompactRawBytes",value:function(){return uE(this.toCompactHex())}},{key:"toCompactHex",value:function(){return fE(this.r)+fE(this.s)}}],[{key:"fromCompact",value:function(t){var n=eE(t),r="Signature.fromCompact";if("string"!=typeof t&&!n)throw new TypeError(r+": Expected string or Uint8Array");var i=n?iE(t):t;if(128!==i.length)throw Error(r+": Expected 64-byte hex");return new e(vE(i.slice(0,64)),vE(i.slice(64,128)))}},{key:"fromDER",value:function(t){var n=eE(t);if("string"!=typeof t&&!n)throw new TypeError("Signature.fromDER: Expected string or Uint8Array");var r=function(e){if(e.length<2||48!=e[0])throw Error("Invalid signature tag: "+iE(e));if(e[1]!==e.length-2)throw Error("Invalid signature: incorrect length");var t=J_(e.subarray(2)),n=t.data,r=J_(t.left),i=r.data,a=r.left;if(a.length)throw Error("Invalid signature: left bytes after parsing: "+iE(a));return{r:n,s:i}}(n?t:uE(t));return new e(r.r,r.s)}},{key:"fromHex",value:function(e){return this.fromDER(e)}}]),e}();function eE(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function tE(e){if(!eE(e))throw Error("Uint8Array expected")}function nE(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];if(t.every(tE),1===t.length)return t[0];for(var r=t.reduce((function(e,t){return e+t.length}),0),i=new Uint8Array(r),a=0,o=0;a<t.length;a++){var u=t[a];i.set(u,o),o+=u.length}return i}var rE=Array.from({length:256},(function(e,t){return t.toString(16).padStart(2,"0")}));function iE(e){tE(e);for(var t="",n=0;n<e.length;n++)t+=rE[e[n]];return t}var aE={_0:48,_9:57,A:65,F:70,a:97,f:102};function oE(e){return e>=aE._0&&e<=aE._9?e-aE._0:e>=aE.A&&e<=aE.F?e-(aE.A-10):e>=aE.a&&e<=aE.f?e-(aE.a-10):void 0}function uE(e){if("string"!=typeof e)throw Error("hex string expected, got "+(void 0===e?"undefined":(0,fe.default)(e)));var t=e.length,n=t/2;if(t%2)throw Error("hex string expected, got unpadded hex of length "+t);for(var r=new Uint8Array(n),i=0,a=0;i<n;i++,a+=2){var o=oE(e.charCodeAt(a)),u=oE(e.charCodeAt(a+1));if(void 0===o||void 0===u){var s=e[a]+e[a+1];throw Error('hex string expected, got non-hex character "'+s+'" at index '+a)}r[i]=16*o+u}return r}var sE,lE,cE=BigInt("0x10000000000000000000000000000000000000000000000000000000000000000");function fE(e){if("bigint"!=(void 0===e?"undefined":(0,fe.default)(e)))throw Error("Expected bigint");if(!(L_<=e&&e<cE))throw Error("Expected number 0 <= n < 2^256");return e.toString(16).padStart(64,"0")}function dE(e){var t=uE(fE(e));if(32!==t.length)throw Error("Error: expected 32 bytes");return t}function hE(e){var t=e.toString(16);return 1&t.length?"0"+t:t}function vE(e){if("string"!=typeof e)throw new TypeError("hexToNumber: expected string, got "+(void 0===e?"undefined":(0,fe.default)(e)));return BigInt("0x"+e)}function pE(e){return vE(iE(e))}function gE(e){return eE(e)?Uint8Array.from(e):uE(e)}function yE(e){if("number"==typeof e&&Number.isSafeInteger(e)&&e>0)return BigInt(e);if("bigint"==(void 0===e?"undefined":(0,fe.default)(e))&&EE(e))return e;throw new TypeError("Expected valid private scalar: 0 < scalar < curve.n")}function mE(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:U_.P,n=e%t;return n>=L_?n:t+n}function bE(e,t){for(var n=U_.P,r=e;t-- >L_;)r*=r,r%=n;return r}function wE(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:U_.P;if(e===L_||t<=L_)throw Error("invert: expected positive integers, got n=".concat(e," mod=").concat(t));for(var n=mE(e,t),r=t,i=L_,a=D_;n!==L_;){var o=r%n,u=i-a*(r/n);r=n,n=o,i=a,a=u}if(r!==D_)throw Error("invert: does not exist");return mE(i,t)}function kE(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=function(e){var t=8*e.length-256,n=pE(e);return t>0?n>>BigInt(t):n}(e);if(t)return n;var r=U_.n;return n>=r?n-r:n}var _E=function(){"use strict";function e(t,n){if((0,H.default)(this,e),this.hashLen=t,this.qByteLen=n,"number"!=typeof t||t<2)throw Error("hashLen must be a number");if("number"!=typeof n||n<2)throw Error("qByteLen must be a number");this.v=new Uint8Array(t).fill(1),this.k=new Uint8Array(t).fill(0),this.counter=0}return(0,$.default)(e,[{key:"hmac",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];var r;return(r=UE).hmacSha256.apply(r,[this.k].concat((0,ce.default)(t)))}},{key:"hmacSync",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return lE.apply(void 0,[this.k].concat((0,ce.default)(t)))}},{key:"checkSync",value:function(){if("function"!=typeof lE)throw new H_("hmacSha256Sync needs to be set")}},{key:"incr",value:function(){if(this.counter>=1e3)throw Error("Tried 1,000 k values for sign(), all were invalid");this.counter+=1}},{key:"reseed",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new Uint8Array,t=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:return[4,t.hmac(t.v,Uint8Array.from([0]),e)];case 1:return t.k=n.sent(),[4,t.hmac(t.v)];case 2:return t.v=n.sent(),0!==e.length?[4,t.hmac(t.v,Uint8Array.from([1]),e)]:[3,5];case 3:return t.k=n.sent(),[4,t.hmac(t.v)];case 4:t.v=n.sent(),n.label=5;case 5:return[2]}}))}))()}},{key:"reseedSync",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new Uint8Array;this.checkSync(),this.k=this.hmacSync(this.v,Uint8Array.from([0]),e),this.v=this.hmacSync(this.v),0!==e.length&&(this.k=this.hmacSync(this.v,Uint8Array.from([1]),e),this.v=this.hmacSync(this.v))}},{key:"generate",value:function(){var e=this;return(0,K.default)((function(){var t,n,r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:e.incr(),t=0,n=[],i.label=1;case 1:return t<e.qByteLen?[4,e.hmac(e.v)]:[3,4];case 2:e.v=i.sent(),r=e.v.slice(),n.push(r),t+=e.v.length,i.label=3;case 3:return[3,1];case 4:return[2,nE.apply(void 0,(0,ce.default)(n))]}}))}))()}},{key:"generateSync",value:function(){this.checkSync(),this.incr();for(var e=0,t=[];e<this.qByteLen;){this.v=this.hmacSync(this.v);var n=this.v.slice();t.push(n),e+=this.v.length}return nE.apply(void 0,(0,ce.default)(t))}}]),e}();function EE(e){return L_<e&&e<U_.n}function SE(e){return L_<e&&e<U_.P}function AE(e,t,n){var r=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],i=U_.n,a=kE(e,!0);if(EE(a)){var o=wE(a,i),u=Z_.BASE.multiply(a),s=mE(u.x,i);if(s!==L_){var l=mE(o*mE(t+n*s,i),i);if(l!==L_){var c=new $_(s,l),f=(u.x===c.r?0:2)|Number(u.y&D_);return r&&c.hasHighS()&&(c=c.normalizeS(),f^=1),{sig:c,recovery:f}}}}}function IE(e){var t;if("bigint"==(void 0===e?"undefined":(0,fe.default)(e)))t=e;else if("number"==typeof e&&Number.isSafeInteger(e)&&e>0)t=BigInt(e);else if("string"==typeof e){if(64!==e.length)throw Error("Expected 32 bytes of private key");t=vE(e)}else{if(!eE(e))throw new TypeError("Expected valid private key");if(e.length!==j_)throw Error("Expected 32 bytes of private key");t=pE(e)}if(!EE(t))throw Error("Expected private key: 0 < key < n");return t}function xE(e){if(e instanceof $_)return e.assertValidity(),e;try{return $_.fromDER(e)}catch(t){return $_.fromCompact(e)}}function CE(e){return pE(e.length>z_?e.slice(0,z_):e)}function TE(e){var t=CE(e),n=mE(t,U_.n);return PE(n<L_?t:n)}function PE(e){return dE(e)}function RE(e,t){return LE.apply(this,arguments)}function LE(){return LE=(0,K.default)((function(e,t){var n,r,i,a,o,u,s,l=arguments;return(0,pe.__generator)(this,(function(c){switch(c.label){case 0:return r=function(e,t,n){if(null==e)throw Error('sign: expected valid message hash, not "'.concat(e,'"'));var r=gE(e),i=IE(t),a=[PE(i),TE(r)];if(null!=n){!0===n&&(n=UE.randomBytes(z_));var o=gE(n);if(o.length!==z_)throw Error("sign: Expected 32 bytes of extra data");a.push(o)}return{seed:nE.apply(void 0,(0,ce.default)(a)),m:CE(r),d:i}}(e,t,(n=l.length>2&&void 0!==l[2]?l[2]:{}).extraEntropy),i=r.seed,a=r.m,o=r.d,[4,(u=new _E(32,j_)).reseed(i)];case 1:c.sent(),c.label=2;case 2:return[4,u.generate()];case 3:return(s=AE.apply(void 0,[c.sent(),a,o,n.canonical]))?[3,6]:[4,u.reseed()];case 4:c.sent(),c.label=5;case 5:return[3,2];case 6:return[2,function(e,t){var n=e.sig,r=e.recovery,i=Object.assign({canonical:!0,der:!0},t),a=i.der,o=i.recovered,u=a?n.toDERRawBytes():n.toCompactRawBytes();return o?[u,r]:u}(s,n)]}}))})),LE.apply(this,arguments)}var DE,ME={strict:!0};Z_.BASE._setWindowSize(8);var NE={node:R_,web:"object"==typeof self&&"crypto"in self?self.crypto:void 0},OE={},UE=(DE={bytesToHex:iE,hexToBytes:uE,concatBytes:nE,mod:mE,invert:wE,isValidPrivateKey:function(e){try{return IE(e),!0}catch(e){return!1}},_bigintTo32Bytes:dE,_normalizePrivateKey:IE,hashToPrivateKey:function(e){if((e=gE(e)).length<40||e.length>1024)throw Error("Expected valid bytes of private key as per FIPS 186");return dE(mE(pE(e),U_.n-D_)+D_)}},(0,te.default)(DE,"randomBytes",(function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:32;if(NE.web)return NE.web.getRandomValues(new Uint8Array(e));if(NE.node){var t=NE.node.randomBytes;return Uint8Array.from(t(e))}throw Error("The environment doesn't have randomBytes function")})),(0,te.default)(DE,"randomPrivateKey",(function(){return UE.hashToPrivateKey(UE.randomBytes(40))})),(0,te.default)(DE,"precompute",(function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:8,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z_.BASE,n=t===Z_.BASE?t:new Z_(t.x,t.y);return n._setWindowSize(e),n.multiply(N_),n})),(0,te.default)(DE,"sha256",(function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return(0,K.default)((function(){var e,n,r,i;return(0,pe.__generator)(this,(function(a){switch(a.label){case 0:return NE.web?[4,NE.web.subtle.digest("SHA-256",nE.apply(void 0,(0,ce.default)(t)))]:[3,2];case 1:return e=a.sent(),[2,new Uint8Array(e)];case 2:if(NE.node)return n=NE.node,r=n.createHash,i=r("sha256"),[2,(t.forEach((function(e){return i.update(e)})),Uint8Array.from(i.digest()))];throw Error("The environment doesn't have sha256 function")}}))}))()})),(0,te.default)(DE,"hmacSha256",(function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return(0,K.default)((function(){var t,r,i,a,o,u;return(0,pe.__generator)(this,(function(s){switch(s.label){case 0:return NE.web?[4,NE.web.subtle.importKey("raw",e,{name:"HMAC",hash:{name:"SHA-256"}},!1,["sign"])]:[3,3];case 1:return t=s.sent(),r=nE.apply(void 0,(0,ce.default)(n)),[4,NE.web.subtle.sign("HMAC",t,r)];case 2:return i=s.sent(),[2,new Uint8Array(i)];case 3:if(NE.node)return a=NE.node,o=a.createHmac,u=o("sha256",e),[2,(n.forEach((function(e){return u.update(e)})),Uint8Array.from(u.digest()))];throw Error("The environment doesn't have hmac-sha256 function")}}))}))()})),(0,te.default)(DE,"sha256Sync",void 0),(0,te.default)(DE,"hmacSha256Sync",void 0),(0,te.default)(DE,"taggedHash",(function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return(0,K.default)((function(){var t,r,i;return(0,pe.__generator)(this,(function(a){switch(a.label){case 0:return void 0!==(r=OE[e])?[3,2]:[4,UE.sha256(Uint8Array.from(e,(function(e){return e.charCodeAt(0)})))];case 1:i=a.sent(),r=nE(i,i),OE[e]=r,a.label=2;case 2:return[2,(t=UE).sha256.apply(t,[r].concat((0,ce.default)(n)))]}}))}))()})),(0,te.default)(DE,"taggedHashSync",(function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];if("function"!=typeof sE)throw new H_("sha256Sync is undefined, you need to set it");var i=OE[e];if(void 0===i){var a=sE(Uint8Array.from(e,(function(e){return e.charCodeAt(0)})));i=nE(a,a),OE[e]=i}return sE.apply(void 0,[i].concat((0,ce.default)(n)))})),(0,te.default)(DE,"_JacobianPoint",G_),DE);Object.defineProperties(UE,{sha256Sync:{configurable:!1,get:function(){return sE},set:function(e){sE||(sE=e)}},hmacSha256Sync:{configurable:!1,get:function(){return lE},set:function(e){lE||(lE=e)}}});var FE,BE,qE={exports:{}},zE=(FE||(FE=1,BE=qE,function(){var e=function(e,t,n){this.blocks=[],this.s=[],this.padding=t,this.outputBits=n,this.reset=!0,this.finalized=!1,this.block=0,this.start=0,this.blockCount=1600-(e<<1)>>5,this.byteCount=this.blockCount<<2,this.outputBlocks=n>>5,this.extraBytes=(31&n)>>3;for(var r=0;r<50;++r)this.s[r]=0},t=function(t,n,r){e.call(this,t,n,r)},n="input is invalid type",r="object"==typeof window,i=r?window:{};i.JS_SHA3_NO_WINDOW&&(r=!1);var a=!r&&"object"==typeof self;!i.JS_SHA3_NO_NODE_JS&&"object"==typeof ge&&ge.versions&&ge.versions.node?i=Ra:a&&(i=self);for(var o=!i.JS_SHA3_NO_COMMON_JS&&BE.exports,u=!i.JS_SHA3_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,s="0123456789abcdef".split(""),l=[4,1024,262144,67108864],c=[0,8,16,24],f=[1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,2147516545,2147483648,32777,2147483648,138,0,136,0,2147516425,0,2147483658,0,2147516555,0,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,2147483648,32778,0,2147483658,2147483648,2147516545,2147483648,32896,2147483648,2147483649,0,2147516424,2147483648],d=[224,256,384,512],h=[128,256],v=["hex","buffer","arrayBuffer","array","digest"],p={128:168,256:136},g=i.JS_SHA3_NO_NODE_JS||!Array.isArray?function(e){return"[object Array]"==={}.toString.call(e)}:Array.isArray,y=!u||!i.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW&&ArrayBuffer.isView?ArrayBuffer.isView:function(e){return"object"==typeof e&&e.buffer&&e.buffer.constructor===ArrayBuffer},m=function(e){var t=void 0===e?"undefined":(0,fe.default)(e);if("string"===t)return[e,!0];if("object"!==t||null===e)throw Error(n);if(u&&e.constructor===ArrayBuffer)return[new Uint8Array(e),!1];if(!g(e)&&!y(e))throw Error(n);return[e,!1]},b=function(e){return 0===m(e)[0].length},w=function(e){for(var t=[],n=0;n<e.length;++n)t[n]=e[n];return t},k=function(t,n,r){return function(i){return new e(t,n,t).update(i)[r]()}},_=function(t,n,r){return function(i,a){return new e(t,n,a).update(i)[r]()}},E=function(e,t,n){return function(t,r,i,a){return C["cshake"+e].update(t,r,i,a)[n]()}},S=function(e,t,n){return function(t,r,i,a){return C["kmac"+e].update(t,r,i,a)[n]()}},A=function(e,t,n,r){for(var i=0;i<v.length;++i){var a=v[i];e[a]=t(n,r,a)}return e},I=function(t,n){var r=k(t,n,"hex");return r.create=function(){return new e(t,n,t)},r.update=function(e){return r.create().update(e)},A(r,k,t,n)},x=[{name:"keccak",padding:[1,256,65536,16777216],bits:d,createMethod:I},{name:"sha3",padding:[6,1536,393216,100663296],bits:d,createMethod:I},{name:"shake",padding:[31,7936,2031616,520093696],bits:h,createMethod:function(t,n){var r=_(t,n,"hex");return r.create=function(r){return new e(t,n,r)},r.update=function(e,t){return r.create(t).update(e)},A(r,_,t,n)}},{name:"cshake",padding:l,bits:h,createMethod:function(t,n){var r=p[t],i=E(t,0,"hex");return i.create=function(i,a,o){return b(a)&&b(o)?C["shake"+t].create(i):new e(t,n,i).bytepad([a,o],r)},i.update=function(e,t,n,r){return i.create(t,n,r).update(e)},A(i,E,t,n)}},{name:"kmac",padding:l,bits:h,createMethod:function(e,n){var r=p[e],i=S(e,0,"hex");return i.create=function(i,a,o){return new t(e,n,a).bytepad(["KMAC",o],r).bytepad([i],r)},i.update=function(e,t,n,r){return i.create(e,n,r).update(t)},A(i,S,e,n)}}],C={},T=[],P=0;P<x.length;++P)for(var R=x[P],L=R.bits,D=0;D<L.length;++D){var M=R.name+"_"+L[D];if(T.push(M),C[M]=R.createMethod(L[D],R.padding),"sha3"!==R.name){var N=R.name+L[D];T.push(N),C[N]=C[M]}}e.prototype.update=function(e){if(this.finalized)throw Error("finalize already called");var t=m(e);e=t[0];for(var n,r,i=t[1],a=this.blocks,o=this.byteCount,u=e.length,s=this.blockCount,l=0,f=this.s;l<u;){if(this.reset)for(this.reset=!1,a[0]=this.block,n=1;n<s+1;++n)a[n]=0;if(i)for(n=this.start;l<u&&n<o;++l)(r=e.charCodeAt(l))<128?a[n>>2]|=r<<c[3&n++]:r<2048?(a[n>>2]|=(192|r>>6)<<c[3&n++],a[n>>2]|=(128|63&r)<<c[3&n++]):r<55296||r>=57344?(a[n>>2]|=(224|r>>12)<<c[3&n++],a[n>>2]|=(128|r>>6&63)<<c[3&n++],a[n>>2]|=(128|63&r)<<c[3&n++]):(r=65536+((1023&r)<<10|1023&e.charCodeAt(++l)),a[n>>2]|=(240|r>>18)<<c[3&n++],a[n>>2]|=(128|r>>12&63)<<c[3&n++],a[n>>2]|=(128|r>>6&63)<<c[3&n++],a[n>>2]|=(128|63&r)<<c[3&n++]);else for(n=this.start;l<u&&n<o;++l)a[n>>2]|=e[l]<<c[3&n++];if(this.lastByteIndex=n,n>=o){for(this.start=n-o,this.block=a[s],n=0;n<s;++n)f[n]^=a[n];O(f),this.reset=!0}else this.start=n}return this},e.prototype.encode=function(e,t){var n=255&e,r=1,i=[n];for(n=255&(e>>=8);n>0;)i.unshift(n),n=255&(e>>=8),++r;return t?i.push(r):i.unshift(r),this.update(i),i.length},e.prototype.encodeString=function(e){var t=m(e);e=t[0];var n=t[1],r=0,i=e.length;if(n)for(var a=0;a<e.length;++a){var o=e.charCodeAt(a);o<128?r+=1:o<2048?r+=2:o<55296||o>=57344?r+=3:(o=65536+((1023&o)<<10|1023&e.charCodeAt(++a)),r+=4)}else r=i;return r+=this.encode(8*r),this.update(e),r},e.prototype.bytepad=function(e,t){for(var n=this.encode(t),r=0;r<e.length;++r)n+=this.encodeString(e[r]);var i=(t-n%t)%t,a=[];return a.length=i,this.update(a),this},e.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var e=this.blocks,t=this.lastByteIndex,n=this.blockCount,r=this.s;if(e[t>>2]|=this.padding[3&t],this.lastByteIndex===this.byteCount)for(e[0]=e[n],t=1;t<n+1;++t)e[t]=0;for(e[n-1]|=2147483648,t=0;t<n;++t)r[t]^=e[t];O(r)}},e.prototype.toString=e.prototype.hex=function(){this.finalize();for(var e,t=this.blockCount,n=this.s,r=this.outputBlocks,i=this.extraBytes,a=0,o=0,u="";o<r;){for(a=0;a<t&&o<r;++a,++o)e=n[a],u+=s[e>>4&15]+s[15&e]+s[e>>12&15]+s[e>>8&15]+s[e>>20&15]+s[e>>16&15]+s[e>>28&15]+s[e>>24&15];o%t==0&&(n=w(n),O(n),a=0)}return i&&(e=n[a],u+=s[e>>4&15]+s[15&e],i>1&&(u+=s[e>>12&15]+s[e>>8&15]),i>2&&(u+=s[e>>20&15]+s[e>>16&15])),u},e.prototype.arrayBuffer=function(){this.finalize();var e,t=this.blockCount,n=this.s,r=this.outputBlocks,i=this.extraBytes,a=0,o=0,u=this.outputBits>>3;e=i?new ArrayBuffer(r+1<<2):new ArrayBuffer(u);for(var s=new Uint32Array(e);o<r;){for(a=0;a<t&&o<r;++a,++o)s[o]=n[a];o%t==0&&(n=w(n),O(n))}return i&&(s[o]=n[a],e=e.slice(0,u)),e},e.prototype.buffer=e.prototype.arrayBuffer,e.prototype.digest=e.prototype.array=function(){this.finalize();for(var e,t,n=this.blockCount,r=this.s,i=this.outputBlocks,a=this.extraBytes,o=0,u=0,s=[];u<i;){for(o=0;o<n&&u<i;++o,++u)e=u<<2,t=r[o],s[e]=255&t,s[e+1]=t>>8&255,s[e+2]=t>>16&255,s[e+3]=t>>24&255;u%n==0&&(r=w(r),O(r))}return a&&(e=u<<2,t=r[o],s[e]=255&t,a>1&&(s[e+1]=t>>8&255),a>2&&(s[e+2]=t>>16&255)),s},(t.prototype=new e).finalize=function(){return this.encode(this.outputBits,!0),e.prototype.finalize.call(this)};var O=function(e){var t,n,r,i,a,o,u,s,l,c,d,h,v,p,g,y,m,b,w,k,_,E,S,A,I,x,C,T,P,R,L,D,M,N,O,U,F,B,q,z,j,K,V,H,W,G,X,Y,Z,Q,J,$,ee,te,ne,re,ie,ae,oe,ue,se,le,ce;for(r=0;r<48;r+=2)i=e[0]^e[10]^e[20]^e[30]^e[40],a=e[1]^e[11]^e[21]^e[31]^e[41],o=e[2]^e[12]^e[22]^e[32]^e[42],u=e[3]^e[13]^e[23]^e[33]^e[43],s=e[4]^e[14]^e[24]^e[34]^e[44],l=e[5]^e[15]^e[25]^e[35]^e[45],c=e[6]^e[16]^e[26]^e[36]^e[46],d=e[7]^e[17]^e[27]^e[37]^e[47],t=(h=e[8]^e[18]^e[28]^e[38]^e[48])^(o<<1|u>>>31),n=(v=e[9]^e[19]^e[29]^e[39]^e[49])^(u<<1|o>>>31),e[0]^=t,e[1]^=n,e[10]^=t,e[11]^=n,e[20]^=t,e[21]^=n,e[30]^=t,e[31]^=n,e[40]^=t,e[41]^=n,t=i^(s<<1|l>>>31),n=a^(l<<1|s>>>31),e[2]^=t,e[3]^=n,e[12]^=t,e[13]^=n,e[22]^=t,e[23]^=n,e[32]^=t,e[33]^=n,e[42]^=t,e[43]^=n,t=o^(c<<1|d>>>31),n=u^(d<<1|c>>>31),e[4]^=t,e[5]^=n,e[14]^=t,e[15]^=n,e[24]^=t,e[25]^=n,e[34]^=t,e[35]^=n,e[44]^=t,e[45]^=n,t=s^(h<<1|v>>>31),n=l^(v<<1|h>>>31),e[6]^=t,e[7]^=n,e[16]^=t,e[17]^=n,e[26]^=t,e[27]^=n,e[36]^=t,e[37]^=n,e[46]^=t,e[47]^=n,t=c^(i<<1|a>>>31),n=d^(a<<1|i>>>31),e[8]^=t,e[9]^=n,e[18]^=t,e[19]^=n,e[28]^=t,e[29]^=n,e[38]^=t,e[39]^=n,e[48]^=t,e[49]^=n,p=e[0],g=e[1],G=e[11]<<4|e[10]>>>28,X=e[10]<<4|e[11]>>>28,T=e[20]<<3|e[21]>>>29,P=e[21]<<3|e[20]>>>29,ue=e[31]<<9|e[30]>>>23,se=e[30]<<9|e[31]>>>23,K=e[40]<<18|e[41]>>>14,V=e[41]<<18|e[40]>>>14,N=e[2]<<1|e[3]>>>31,O=e[3]<<1|e[2]>>>31,y=e[13]<<12|e[12]>>>20,m=e[12]<<12|e[13]>>>20,Y=e[22]<<10|e[23]>>>22,Z=e[23]<<10|e[22]>>>22,R=e[33]<<13|e[32]>>>19,L=e[32]<<13|e[33]>>>19,le=e[42]<<2|e[43]>>>30,ce=e[43]<<2|e[42]>>>30,te=e[5]<<30|e[4]>>>2,ne=e[4]<<30|e[5]>>>2,U=e[14]<<6|e[15]>>>26,F=e[15]<<6|e[14]>>>26,b=e[25]<<11|e[24]>>>21,w=e[24]<<11|e[25]>>>21,Q=e[34]<<15|e[35]>>>17,J=e[35]<<15|e[34]>>>17,D=e[45]<<29|e[44]>>>3,M=e[44]<<29|e[45]>>>3,A=e[6]<<28|e[7]>>>4,I=e[7]<<28|e[6]>>>4,re=e[17]<<23|e[16]>>>9,ie=e[16]<<23|e[17]>>>9,B=e[26]<<25|e[27]>>>7,q=e[27]<<25|e[26]>>>7,k=e[36]<<21|e[37]>>>11,_=e[37]<<21|e[36]>>>11,$=e[47]<<24|e[46]>>>8,ee=e[46]<<24|e[47]>>>8,H=e[8]<<27|e[9]>>>5,W=e[9]<<27|e[8]>>>5,x=e[18]<<20|e[19]>>>12,C=e[19]<<20|e[18]>>>12,ae=e[29]<<7|e[28]>>>25,oe=e[28]<<7|e[29]>>>25,z=e[38]<<8|e[39]>>>24,j=e[39]<<8|e[38]>>>24,E=e[48]<<14|e[49]>>>18,S=e[49]<<14|e[48]>>>18,e[0]=p^~y&b,e[1]=g^~m&w,e[10]=A^~x&T,e[11]=I^~C&P,e[20]=N^~U&B,e[21]=O^~F&q,e[30]=H^~G&Y,e[31]=W^~X&Z,e[40]=te^~re&ae,e[41]=ne^~ie&oe,e[2]=y^~b&k,e[3]=m^~w&_,e[12]=x^~T&R,e[13]=C^~P&L,e[22]=U^~B&z,e[23]=F^~q&j,e[32]=G^~Y&Q,e[33]=X^~Z&J,e[42]=re^~ae&ue,e[43]=ie^~oe&se,e[4]=b^~k&E,e[5]=w^~_&S,e[14]=T^~R&D,e[15]=P^~L&M,e[24]=B^~z&K,e[25]=q^~j&V,e[34]=Y^~Q&$,e[35]=Z^~J&ee,e[44]=ae^~ue&le,e[45]=oe^~se&ce,e[6]=k^~E&p,e[7]=_^~S&g,e[16]=R^~D&A,e[17]=L^~M&I,e[26]=z^~K&N,e[27]=j^~V&O,e[36]=Q^~$&H,e[37]=J^~ee&W,e[46]=ue^~le&te,e[47]=se^~ce&ne,e[8]=E^~p&y,e[9]=S^~g&m,e[18]=D^~A&x,e[19]=M^~I&C,e[28]=K^~N&U,e[29]=V^~O&F,e[38]=$^~H&G,e[39]=ee^~W&X,e[48]=le^~te&re,e[49]=ce^~ne&ie,e[0]^=f[r],e[1]^=f[r+1]};if(o)BE.exports=C;else for(P=0;P<T.length;++P)i[T[P]]=C[T[P]]}()),qE.exports),jE=La(zE);function KE(e){return new Uint8Array(jE.keccak256.arrayBuffer(e))}function VE(e,t,n){try{return function(e,t,n){var r,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:ME;try{r=xE(e),t=gE(t)}catch(e){return!1}var a=r.r,o=r.s;if(i.strict&&r.hasHighS())return!1;var u,s=kE(t);try{u=function(e){return e instanceof Z_?(e.assertValidity(),e):Z_.fromHex(e)}(n)}catch(e){return!1}var l=U_.n,c=wE(o,l),f=mE(s*c,l),d=mE(a*c,l),h=Z_.BASE.multiplyAndAddUnsafe(u,f,d);return!!h&&mE(h.x,l)===a}($_.fromCompact(e.slice(0,64)),t,n)}catch(e){return!1}}function HE(e,t){switch(t){case"udp":return HE(e,"udp4")||HE(e,"udp6");case"tcp":return HE(e,"tcp4")||HE(e,"tcp6")}var n=t.endsWith("6"),r=e.get(n?"ip6":"ip");if(r){var i,a=t.slice(0,3);switch(a){case"udp":i=n?e.get("udp6"):e.get("udp");break;case"tcp":i=n?e.get("tcp6"):e.get("tcp");break;default:return}return i?function(e,t,n,r){var i=pf("/"+e+"/"+ff(e,n));return i=i.encapsulate(pf("/"+t+"/"+ff(t,r)))}(n?"ip6":"ip4",a,r,i):void 0}}var WE=parseInt("11111",2),GE=parseInt("10000000",2),XE=parseInt("01111111",2),YE={0:JE,1:JE,2:function(e,t){for(var n=QE(e,t),r=t.offset,i=t.offset+n,a=[],o=r;o<i;o++)o===r&&0===e[o]||a.push(e[o]);return t.offset+=n,Uint8Array.from(a)},3:function(e,t){var n=QE(e,t),r=e[t.offset];t.offset++;var i=e.subarray(t.offset,t.offset+n-1);if(t.offset+=n,0!==r)throw Error("Unused bits in bit string is unimplemented");return i},4:function(e,t){var n=QE(e,t),r=e.subarray(t.offset,t.offset+n);return t.offset+=n,r},5:function(e,t){return t.offset++,null},6:function(e,t){var n=QE(e,t),r=t.offset+n,i=e[t.offset];t.offset++;var a=0,o=0;i<40?(a=0,o=i):i<80?(a=1,o=i-40):(a=2,o=i-80);for(var u="".concat(a,".").concat(o),s=[];t.offset<r;){var l=e[t.offset];if(t.offset++,s.push(127&l),l<128){s.reverse();for(var c=0,f=0;f<s.length;f++)c+=s[f]<<7*f;u+="."+c,s=[]}}return u},16:JE,22:JE,48:JE};function ZE(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{offset:0},n=e[t.offset]&WE;if(t.offset++,null!=YE[n])return YE[n](e,t);throw Error("No decoder for tag "+n)}function QE(e,t){var n=0;if((e[t.offset]&GE)===GE){var r=e[t.offset]&XE,i="0x";t.offset++;for(var a=0;a<r;a++,t.offset++)i+=e[t.offset].toString(16).padStart(2,"0");n=parseInt(i,16)}else n=e[t.offset],t.offset++;return n}function JE(e,t){QE(e,t);for(var n=[];!(t.offset>=e.byteLength);){var r=ZE(e,t);if(null===r)break;n.push(r)}return n}function $E(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);var t=function(e){var t=e.toString(16);t.length%2==1&&(t="0"+t);for(var n=new po,r=0;r<t.length;r+=2)n.append(Uint8Array.from([parseInt("".concat(t[r]).concat(t[r+1]),16)]));return n}(e.byteLength);return new po(Uint8Array.from([t.byteLength|GE]),t)}function eS(e){var t=new po;return!(128&~e.subarray()[0])&&t.append(Uint8Array.from([0])),t.append(e),new po(Uint8Array.from([2]),$E(t),t)}function tS(e){var t=Uint8Array.from([0]),n=new po(t,e);return new po(Uint8Array.from([3]),$E(n),n)}function nS(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:48,n=new po,r=!0,i=!1,a=void 0;try{for(var o,u=e[Symbol.iterator]();!(r=(o=u.next()).done);r=!0){var s=o.value;n.append(s)}}catch(e){i=!0,a=e}finally{try{r||null==u.return||u.return()}finally{if(i)throw a}}return new po(Uint8Array.from([t]),$E(n),n)}var rS=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),iS=Uint8Array.from([6,5,43,129,4,0,34]),aS=Uint8Array.from([6,5,43,129,4,0,35]),oS={ext:!0,kty:"EC",crv:"P-256"},uS={ext:!0,kty:"EC",crv:"P-384"},sS={ext:!0,kty:"EC",crv:"P-521"};function lS(e){if("P-256"===e)return rS;if("P-384"===e)return iS;if("P-521"===e)return aS;throw new ra("Invalid curve "+e)}var cS,fS=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"type","ECDSA"),(0,te.default)(this,"jwk",void 0),(0,te.default)(this,"_raw",void 0),this.jwk=t}return(0,$.default)(e,[{key:"raw",get:function(){var e,t,n;return null==this._raw&&(this._raw=(e=this.jwk,nS([eS(Uint8Array.from([1])),nS([lS(e.crv)],160),nS([tS(new po(Uint8Array.from([4]),wn(null!==(t=e.x)&&void 0!==t?t:"","base64url"),wn(null!==(n=e.y)&&void 0!==n?n:"","base64url")))],161)]).subarray())),this._raw}},{key:"toMultihash",value:function(){return tn.digest(CS(this))}},{key:"toCID",value:function(){return cn.createV1(114,this.toMultihash())}},{key:"toString",value:function(){return xt.encode(this.toMultihash().bytes).substring(1)}},{key:"equals",value:function(e){return null!=e&&e.raw instanceof Uint8Array&&so(this.raw,e.raw)}},{key:"verify",value:function(e,t,n){var r=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(i){return[2,function(){var e=(0,K.default)((function(e,t,n,r){var i,a,o,u,s;return(0,pe.__generator)(this,(function(l){switch(l.label){case 0:return[4,crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:null!==(o=e.crv)&&void 0!==o?o:"P-256"},!1,["verify"])];case 1:return u=l.sent(),null==r||null===(i=r.signal)||void 0===i||i.throwIfAborted(),[4,crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},u,t,n.subarray())];case 2:return s=l.sent(),[2,(null==r||null===(a=r.signal)||void 0===a||a.throwIfAborted(),s)]}}))}));return function(t,n,r,i){return e.apply(this,arguments)}}()(r.jwk,t,e,n)]}))}))()}}]),e}(),dS=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"An error occurred while verifying a message";return(0,H.default)(this,n),(e=t.call(this,r)).name="VerificationError",(0,ue.default)(e)}return n}((0,he.default)(Error)),hS=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Missing Web Crypto API";return(0,H.default)(this,n),(e=t.call(this,r)).name="WebCryptoMissingError",(0,ue.default)(e)}return n}((0,he.default)(Error)),vS={get:function(){var e=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:globalThis).crypto;if(null==(null==e?void 0:e.subtle))throw new hS("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");return e}},pS=(0,K.default)((function(){return(0,pe.__generator)(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,vS.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"])];case 1:return[2,(e.sent(),!0)];case 2:return e.sent(),[2,!1];case 3:return[2]}}))}))();function gS(){return gS=(0,K.default)((function(e,t,n){return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return null==cS?[4,pS]:[3,2];case 1:cS=r.sent(),r.label=2;case 2:return[2,cS?function(){var e=(0,K.default)((function(e,t,n){var r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:return e.buffer instanceof ArrayBuffer?[4,vS.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"])]:[3,3];case 1:return r=i.sent(),[4,vS.get().subtle.verify({name:"Ed25519"},r,t,n instanceof Uint8Array?n:n.subarray())];case 2:return[2,i.sent()];case 3:throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}}))}));return function(t,n,r){return e.apply(this,arguments)}}()(e,t,n):function(e,t,n){return bl.verify(t,n instanceof Uint8Array?n:n.subarray(),e)}(e,t,n)]}}))})),gS.apply(this,arguments)}function yS(e){return null!=e&&"function"==typeof e.then&&"function"==typeof e.catch&&"function"==typeof e.finally}var mS,bS,wS,kS,_S=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"type","Ed25519"),(0,te.default)(this,"raw",void 0),this.raw=ES(t,32)}return(0,$.default)(e,[{key:"toMultihash",value:function(){return tn.digest(CS(this))}},{key:"toCID",value:function(){return cn.createV1(114,this.toMultihash())}},{key:"toString",value:function(){return xt.encode(this.toMultihash().bytes).substring(1)}},{key:"equals",value:function(e){return null!=e&&e.raw instanceof Uint8Array&&so(this.raw,e.raw)}},{key:"verify",value:function(e,t,n){var r;null==n||null===(r=n.signal)||void 0===r||r.throwIfAborted();var i=function(e,t,n){return gS.apply(this,arguments)}(this.raw,t,e);return yS(i)?i.then((function(e){var t;return null==n||null===(t=n.signal)||void 0===t||t.throwIfAborted(),e})):i}}]),e}();function ES(e,t){if((e=Uint8Array.from(null!=e?e:[])).length!==t)throw new ra("Key must be a Uint8Array of length ".concat(t,", got ").concat(e.length));return e}(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(mS||(mS={})),function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"}(bS||(bS={})),function(e){e.codec=function(){return wr(bS)}}(mS||(mS={})),function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};!1!==n.lengthDelimited&&t.fork(),null!=e.Type&&(t.uint32(8),mS.codec().encode(e.Type,t)),null!=e.Data&&(t.uint32(18),t.bytes(e.Data)),!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n={},r=null==t?e.len:e.pos+t;e.pos<r;){var i=e.uint32();switch(i>>>3){case 1:n.Type=mS.codec().decode(e);break;case 2:n.Data=e.bytes();break;default:e.skipType(7&i)}}return n}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(wS||(wS={})),function(e){var t;e.codec=function(){return null==t&&(t=kr((function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};!1!==n.lengthDelimited&&t.fork(),null!=e.Type&&(t.uint32(8),mS.codec().encode(e.Type,t)),null!=e.Data&&(t.uint32(18),t.bytes(e.Data)),!1!==n.lengthDelimited&&t.ldelim()}),(function(e,t){for(var n={},r=null==t?e.len:e.pos+t;e.pos<r;){var i=e.uint32();switch(i>>>3){case 1:n.Type=mS.codec().decode(e);break;case 2:n.Data=e.bytes();break;default:e.skipType(7&i)}}return n}))),t},e.encode=function(t){return mr(t,e.codec())},e.decode=function(t,n){return He(t,e.codec(),n)}}(kS||(kS={}));var SS=function(){"use strict";function e(t,n){(0,H.default)(this,e),(0,te.default)(this,"type","RSA"),(0,te.default)(this,"jwk",void 0),(0,te.default)(this,"_raw",void 0),(0,te.default)(this,"_multihash",void 0),this.jwk=t,this._multihash=n}return(0,$.default)(e,[{key:"raw",get:function(){return null==this._raw&&(this._raw=function(e){if(null==e.n||null==e.e)throw new ra("JWK was missing components");return nS([AS,tS(nS([eS(wn(e.n,"base64url")),eS(wn(e.e,"base64url"))]))]).subarray()}(this.jwk)),this._raw}},{key:"toMultihash",value:function(){return this._multihash}},{key:"toCID",value:function(){return cn.createV1(114,this._multihash)}},{key:"toString",value:function(){return xt.encode(this.toMultihash().bytes).substring(1)}},{key:"equals",value:function(e){return null!=e&&e.raw instanceof Uint8Array&&so(this.raw,e.raw)}},{key:"verify",value:function(e,t,n){return function(){var e=(0,K.default)((function(e,t,n,r){var i,a,o,u;return(0,pe.__generator)(this,(function(s){switch(s.label){case 0:return[4,vS.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"])];case 1:return o=s.sent(),null==r||null===(i=r.signal)||void 0===i||i.throwIfAborted(),[4,vS.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,n instanceof Uint8Array?n:n.subarray())];case 2:return u=s.sent(),[2,(null==r||null===(a=r.signal)||void 0===a||a.throwIfAborted(),u)]}}))}));return function(t,n,r,i){return e.apply(this,arguments)}}()(this.jwk,t,e,n)}}]),e}(),AS=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);var IS=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"type","secp256k1"),(0,te.default)(this,"raw",void 0),(0,te.default)(this,"_key",void 0),this._key=function(e){try{return oc.ProjectivePoint.fromHex(e),e}catch(e){throw new ia(e+"")}}(t),this.raw=function(e){return oc.ProjectivePoint.fromHex(e).toRawBytes(!0)}(this._key)}return(0,$.default)(e,[{key:"toMultihash",value:function(){return tn.digest(CS(this))}},{key:"toCID",value:function(){return cn.createV1(114,this.toMultihash())}},{key:"toString",value:function(){return xt.encode(this.toMultihash().bytes).substring(1)}},{key:"equals",value:function(e){return null!=e&&e.raw instanceof Uint8Array&&so(this.raw,e.raw)}},{key:"verify",value:function(e,t,n){return function(e,t,n,r){var i=rn.digest(n instanceof Uint8Array?n:n.subarray());if(yS(i))return i.then((function(n){var i,a=n.digest;return null==r||null===(i=r.signal)||void 0===i||i.throwIfAborted(),oc.verify(t,a,e)})).catch((function(e){if("AbortError"===e.name)throw e;throw new dS(e+"")}));try{var a;return null==r||null===(a=r.signal)||void 0===a||a.throwIfAborted(),oc.verify(t,i.digest,e)}catch(e){throw new dS(e+"")}}(this._key,t,e,n)}}]),e}();function xS(e){var t,n,r;if(32===e.byteLength)return r=ES(r=e,32),new _S(r);if(33===e.byteLength)return function(e){return new IS(e)}(e);var i=ZE(e),a=null===(t=i[1])||void 0===t?void 0:t[0];if("1.2.840.10045.3.1.7"===a||"1.3.132.0.34"===a||"1.3.132.0.35"===a)return function(e){var t,n,r=e[1][1][0];if(65===r.byteLength)return t=Ti(r.subarray(1,33),"base64url"),n=Ti(r.subarray(33),"base64url"),new fS((0,oe.default)((0,ae.default)({},oS),{key_ops:["verify"],x:t,y:n}));if(97===r.byteLength)return t=Ti(r.subarray(1,49),"base64url"),n=Ti(r.subarray(49),"base64url"),new fS((0,oe.default)((0,ae.default)({},uS),{key_ops:["verify"],x:t,y:n}));if(133===r.byteLength)return t=Ti(r.subarray(1,67),"base64url"),n=Ti(r.subarray(67),"base64url"),new fS((0,oe.default)((0,ae.default)({},sS),{key_ops:["verify"],x:t,y:n}));throw new ra("coordinates were wrong length, got ".concat(r.byteLength,", expected 65, 97 or 133"))}(i);if("1.2.840.113549.1.1.1"===(null===(n=i[0])||void 0===n?void 0:n[0]))return function(e,t,n){var r=function(e){var t=ZE(e[1],{offset:0});return{kty:"RSA",n:Ti(t[0],"base64url"),e:Ti(t[1],"base64url")}}(e);return null==n&&(n=Yt(18,Ci(wS.encode({Type:mS.RSA,Data:t})))),new SS(r,n)}(i,e);throw new ra("Could not extract public key from raw bytes")}function CS(e){return wS.encode({Type:mS[e.type],Data:e.raw})}var TS=Symbol.for("nodejs.util.inspect.custom"),PS=Symbol.toStringTag,RS=Xi,LS=TS,DS=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"type",void 0),(0,te.default)(this,"multihash",void 0),(0,te.default)(this,"publicKey",void 0),(0,te.default)(this,"string",void 0),(0,te.default)(this,RS,!0),this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}return(0,$.default)(e,[{key:PS,get:function(){return"PeerId(".concat(this.toString(),")")}},{key:"toString",value:function(){return null==this.string&&(this.string=xt.encode(this.multihash.bytes).slice(1)),this.string}},{key:"toMultihash",value:function(){return this.multihash}},{key:"toCID",value:function(){return cn.createV1(114,this.multihash)}},{key:"toJSON",value:function(){return this.toString()}},{key:"equals",value:function(e){var t;if(null==e)return!1;if(e instanceof Uint8Array)return so(this.multihash.bytes,e);if("string"==typeof e)return this.toString()===e;if(null!=(null===(t=null==e?void 0:e.toMultihash())||void 0===t?void 0:t.bytes))return so(this.multihash.bytes,e.toMultihash().bytes);throw Error("not valid Id")}},{key:LS,value:function(){return"PeerId(".concat(this.toString(),")")}}]),e}(),MS=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(e){var r;return(0,H.default)(this,n),r=t.call(this,(0,oe.default)((0,ae.default)({},e),{type:"RSA"})),(0,te.default)((0,q.default)(r),"type","RSA"),(0,te.default)((0,q.default)(r),"publicKey",void 0),r.publicKey=e.publicKey,(0,ue.default)(r)}return n}(DS),NS=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(e){var r;return(0,H.default)(this,n),r=t.call(this,(0,oe.default)((0,ae.default)({},e),{type:"Ed25519"})),(0,te.default)((0,q.default)(r),"type","Ed25519"),(0,te.default)((0,q.default)(r),"publicKey",void 0),r.publicKey=e.publicKey,(0,ue.default)(r)}return n}(DS),OS=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(e){var r;return(0,H.default)(this,n),r=t.call(this,(0,oe.default)((0,ae.default)({},e),{type:"secp256k1"})),(0,te.default)((0,q.default)(r),"type","secp256k1"),(0,te.default)((0,q.default)(r),"publicKey",void 0),r.publicKey=e.publicKey,(0,ue.default)(r)}return n}(DS);function US(e){var t=e.reduce((function(e,t){return e+2+t.bytes.length}),0),n=new Uint8Array(t),r=new DataView(n.buffer),i=0;return e.forEach((function(e){if(e.getPeerId())throw Error("`multiaddr` field MUST not contain peer id");r.setUint16(i,e.bytes.length),i+=2,n.set(e.bytes,i),i+=e.bytes.length})),n}function FS(e){var t=0;return e.lightPush&&(t+=1),t<<=1,e.filter&&(t+=1),t<<=1,e.store&&(t+=1),t<<=1,e.relay&&(t+=1),t}var BS=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:BigInt(1),a=arguments.length>2?arguments[2]:void 0;return(0,H.default)(this,n),e=t.call(this,Object.entries(r)),(0,te.default)((0,q.default)(e),"seq",void 0),(0,te.default)((0,q.default)(e),"signature",void 0),e.seq=i,e.signature=a,(0,ue.default)(e)}return(0,$.default)(n,[{key:"set",value:function(e,t){return this.signature=void 0,this.seq++,(0,ne.default)((0,re.default)(n.prototype),"set",this).call(this,e,t)}},{key:"id",get:function(){var e=this.get("id");if(!e)throw Error("id not found.");return Di(e)}},{key:"publicKey",get:function(){if("v4"===this.id)return this.get("secp256k1");throw Error(P_)}},{key:"rs",get:function(){var e=this.get("rs");if(e)return Ki(e)}},{key:"rsv",get:function(){var e=this.get("rsv");if(e)return Ki(e)}},{key:"ip",get:function(){return qS(this,"ip","ip4")},set:function(e){jS(this,"ip","ip4",e)}},{key:"tcp",get:function(){return zS(this,"tcp","tcp")},set:function(e){KS(this,"tcp","tcp",e)}},{key:"udp",get:function(){return zS(this,"udp","udp")},set:function(e){KS(this,"udp","udp",e)}},{key:"ip6",get:function(){return qS(this,"ip6","ip6")},set:function(e){jS(this,"ip6","ip6",e)}},{key:"tcp6",get:function(){return zS(this,"tcp6","tcp")},set:function(e){KS(this,"tcp6","tcp",e)}},{key:"udp6",get:function(){return zS(this,"udp6","udp")},set:function(e){KS(this,"udp6","udp",e)}},{key:"multiaddrs",get:function(){var e=this.get("multiaddrs");if(e)return function(e){for(var t=[],n=0;n<e.length;){var r=new DataView(e.buffer,n,2).getUint16(0);n+=2;var i=e.slice(n,n+r);n+=r,t.push(pf(i))}return t}(e)},set:function(e){VS(this,"multiaddrs",e,US)}},{key:"waku2",get:function(){var e=this.get("waku2");if(e)return function(e){var t={relay:!1,store:!1,filter:!1,lightPush:!1};return e%2&&(t.relay=!0),(e>>=1)%2&&(t.store=!0),(e>>=1)%2&&(t.filter=!0),(e>>=1)%2&&(t.lightPush=!0),t}(e[0])},set:function(e){VS(this,"waku2",e,(function(e){return new Uint8Array([FS(e)])}))}}]),n}((0,he.default)(Map));function qS(e,t,n){var r=e.get(t);if(r)return ff(n,r)}function zS(e,t,n){var r=e.get(t);if(r)return Number(ff(n,r))}function jS(e,t,n,r){VS(e,t,r,df.bind({},n))}function KS(e,t,n,r){jS(e,t,n,null==r?void 0:r.toString(10))}function VS(e,t,n,r){void 0!==n?e.set(t,r(n)):e.delete(t)}var HS,WS,GS=new ja("enr");(function(e){e.TCP="tcp",e.UDP="udp"})(HS||(HS={})),function(e){e.TCP4="tcp4",e.UDP4="udp4",e.TCP6="tcp6",e.UDP6="udp6"}(WS||(WS={}));var XS=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e;return(0,H.default)(this,n),e=t.apply(this,arguments),(0,te.default)((0,q.default)(e),"peerId",void 0),(0,te.default)((0,q.default)(e),"getLocationMultiaddr",HE.bind({},(0,q.default)(e))),e}return(0,$.default)(n,[{key:"nodeId",get:function(){if("v4"===this.id)return this.publicKey?function(e){var t=Z_.fromHex(e).toRawBytes(!1);return Li(KE(t.slice(1)))}(this.publicKey):void 0;throw Error(P_)}},{key:"shardInfo",get:function(){return this.rs&&this.rsv&&GS.warn("ENR contains both `rs` and `rsv` fields."),this.rs||this.rsv}},{key:"setLocationMultiaddr",value:function(e){var t=e.protoNames();if(2!==t.length&&"udp"!==t[1]&&"tcp"!==t[1])throw Error("Invalid multiaddr");var n=e.tuples();if(!n[0][1]||!n[1][1])throw Error("Invalid multiaddr");4===n[0][0]?(this.set("ip",n[0][1]),this.set(t[1],n[1][1])):(this.set("ip6",n[0][1]),this.set(t[1]+"6",n[1][1]))}},{key:"getAllLocationMultiaddrs",value:function(){var e,t=this,n=[],r=!0,i=!1,a=void 0;try{for(var o,u=Object.values(WS)[Symbol.iterator]();!(r=(o=u.next()).done);r=!0){var s=o.value,l=this.getLocationMultiaddr(s);l&&n.push(l)}}catch(e){i=!0,a=e}finally{try{r||null==u.return||u.return()}finally{if(i)throw a}}var c=null!==(e=this.multiaddrs)&&void 0!==e?e:[];return n.concat(c).map((function(e){return t.peerId?e.encapsulate("/p2p/"+t.peerId.toString()):e}))}},{key:"peerInfo",get:function(){var e=this.peerId;if(e)return{id:e,multiaddrs:this.getAllLocationMultiaddrs()}}},{key:"getFullMultiaddr",value:function(e){if(this.peerId){var t=this.getLocationMultiaddr(e);if(t)return t.encapsulate("/p2p/"+this.peerId.toString())}}},{key:"getFullMultiaddrs",value:function(){if(this.peerId&&this.multiaddrs){var e=this.peerId;return this.multiaddrs.map((function(t){return t.encapsulate("/p2p/"+e.toString())}))}return[]}},{key:"verify",value:function(e,t){if(!this.get("id")||"v4"!==this.id)throw Error(P_);if(!this.publicKey)throw Error("Failed to verify ENR: No public key");return VE(t,KE(e),this.publicKey)}},{key:"sign",value:function(e,t){var n=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:if("v4"!==n.id)throw Error(P_);return[4,function(){var e=(0,K.default)((function(e,t){return(0,pe.__generator)(this,(function(n){return[2,RE(KE(t),e,{der:!1})]}))}));return function(t,n){return e.apply(this,arguments)}}()(t,e)];case 1:return[2,(n.signature=r.sent(),n.signature)]}}))}))()}}],[{key:"create",value:function(){var e=new n(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},arguments.length>1&&void 0!==arguments[1]?arguments[1]:BigInt(1),arguments.length>2?arguments[2]:void 0);try{var t=e.publicKey;t&&(e.peerId=function(e){var t=xS(e);if("secp256k1"!==t.type)throw Error("Keypair type not implemented");return function(e){if("Ed25519"===e.type)return new NS({multihash:e.toCID().multihash,publicKey:e});if("secp256k1"===e.type)return new OS({multihash:e.toCID().multihash,publicKey:e});if("RSA"===e.type)return new MS({multihash:e.toCID().multihash,publicKey:e});throw new Aa}(t)}(t))}catch(e){GS.error("Could not calculate peer id for ENR",e)}return e}}]),n}(BS);(0,te.default)(XS,"RECORD_PREFIX","enr:");var YS,ZS,QS=!1,JS=!1,$S={debug:1,default:2,info:2,warning:3,error:4,off:5},eA=null,tA=function(){try{var e=[];if(["NFD","NFC","NFKD","NFKC"].forEach((function(t){try{if("test"!=="test".normalize(t))throw Error("bad normalize")}catch(n){e.push(t)}})),e.length)throw Error("missing "+e.join(", "))}catch(e){return e.message}return null}();(function(e){e.DEBUG="DEBUG",e.INFO="INFO",e.WARNING="WARNING",e.ERROR="ERROR",e.OFF="OFF"})(YS||(YS={})),function(e){e.UNKNOWN_ERROR="UNKNOWN_ERROR",e.NOT_IMPLEMENTED="NOT_IMPLEMENTED",e.UNSUPPORTED_OPERATION="UNSUPPORTED_OPERATION",e.NETWORK_ERROR="NETWORK_ERROR",e.SERVER_ERROR="SERVER_ERROR",e.TIMEOUT="TIMEOUT",e.BUFFER_OVERRUN="BUFFER_OVERRUN",e.NUMERIC_FAULT="NUMERIC_FAULT",e.MISSING_NEW="MISSING_NEW",e.INVALID_ARGUMENT="INVALID_ARGUMENT",e.MISSING_ARGUMENT="MISSING_ARGUMENT",e.UNEXPECTED_ARGUMENT="UNEXPECTED_ARGUMENT",e.CALL_EXCEPTION="CALL_EXCEPTION",e.INSUFFICIENT_FUNDS="INSUFFICIENT_FUNDS",e.NONCE_EXPIRED="NONCE_EXPIRED",e.REPLACEMENT_UNDERPRICED="REPLACEMENT_UNDERPRICED",e.UNPREDICTABLE_GAS_LIMIT="UNPREDICTABLE_GAS_LIMIT",e.TRANSACTION_REPLACED="TRANSACTION_REPLACED",e.ACTION_REJECTED="ACTION_REJECTED"}(ZS||(ZS={}));var nA="0123456789abcdef",rA=function(){"use strict";function e(t){(0,H.default)(this,e),Object.defineProperty(this,"version",{enumerable:!0,value:t,writable:!1})}return(0,$.default)(e,[{key:"_log",value:function(e,t){var n=e.toLowerCase();null==$S[n]&&this.throwArgumentError("invalid log level name","logLevel",e)}},{key:"debug",value:function(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];this._log(e.levels.DEBUG,n)}},{key:"info",value:function(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];this._log(e.levels.INFO,n)}},{key:"warn",value:function(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];this._log(e.levels.WARNING,n)}},{key:"makeError",value:function(t,n,r){if(JS)return this.makeError("censored error",n,{});n||(n=e.errors.UNKNOWN_ERROR),r||(r={});var i=[];Object.keys(r).forEach((function(e){var t=r[e];try{if(t instanceof Uint8Array){for(var n="",a=0;a<t.length;a++)n+=nA[t[a]>>4],n+=nA[15&t[a]];i.push(e+"=Uint8Array(0x"+n+")")}else i.push(e+"="+JSON.stringify(t))}catch(t){i.push(e+"="+JSON.stringify(r[e].toString()))}})),i.push("code="+n),i.push("version="+this.version);var a=t,o="";switch(n){case ZS.NUMERIC_FAULT:o="NUMERIC_FAULT";var u=t;switch(u){case"overflow":case"underflow":case"division-by-zero":o+="-"+u;break;case"negative-power":case"negative-width":o+="-unsupported";break;case"unbound-bitwise-result":o+="-unbound-result"}break;case ZS.CALL_EXCEPTION:case ZS.INSUFFICIENT_FUNDS:case ZS.MISSING_NEW:case ZS.NONCE_EXPIRED:case ZS.REPLACEMENT_UNDERPRICED:case ZS.TRANSACTION_REPLACED:case ZS.UNPREDICTABLE_GAS_LIMIT:o=n}o&&(t+=" [ See: https://links.ethers.org/v5-errors-"+o+" ]"),i.length&&(t+=" ("+i.join(", ")+")");var s=Error(t);return s.reason=a,s.code=n,Object.keys(r).forEach((function(e){s[e]=r[e]})),s}},{key:"throwError",value:function(e,t,n){throw this.makeError(e,t,n)}},{key:"throwArgumentError",value:function(t,n,r){return this.throwError(t,e.errors.INVALID_ARGUMENT,{argument:n,value:r})}},{key:"assert",value:function(e,t,n,r){e||this.throwError(t,n,r)}},{key:"assertArgument",value:function(e,t,n,r){e||this.throwArgumentError(t,n,r)}},{key:"checkNormalize",value:function(t){tA&&this.throwError("platform missing String.prototype.normalize",e.errors.UNSUPPORTED_OPERATION,{operation:"String.prototype.normalize",form:tA})}},{key:"checkSafeUint53",value:function(t,n){"number"==typeof t&&(null==n&&(n="value not safe"),(t<0||t>=9007199254740991)&&this.throwError(n,e.errors.NUMERIC_FAULT,{operation:"checkSafeInteger",fault:"out-of-safe-range",value:t}),t%1&&this.throwError(n,e.errors.NUMERIC_FAULT,{operation:"checkSafeInteger",fault:"non-integer",value:t}))}},{key:"checkArgumentCount",value:function(t,n,r){r=r?": "+r:"",t<n&&this.throwError("missing argument"+r,e.errors.MISSING_ARGUMENT,{count:t,expectedCount:n}),t>n&&this.throwError("too many arguments"+r,e.errors.UNEXPECTED_ARGUMENT,{count:t,expectedCount:n})}},{key:"checkNew",value:function(t,n){t!==Object&&null!=t||this.throwError("missing new",e.errors.MISSING_NEW,{name:n.name})}},{key:"checkAbstract",value:function(t,n){t===n?this.throwError("cannot instantiate abstract class "+JSON.stringify(n.name)+" directly; use a sub-class",e.errors.UNSUPPORTED_OPERATION,{name:t.name,operation:"new"}):t!==Object&&null!=t||this.throwError("missing new",e.errors.MISSING_NEW,{name:n.name})}}],[{key:"globalLogger",value:function(){return eA||(eA=new e("logger/5.8.0")),eA}},{key:"setCensorship",value:function(t,n){if(!t&&n&&this.globalLogger().throwError("cannot permanently disable censorship",e.errors.UNSUPPORTED_OPERATION,{operation:"setCensorship"}),QS){if(!t)return;this.globalLogger().throwError("error censorship permanent",e.errors.UNSUPPORTED_OPERATION,{operation:"setCensorship"})}JS=!!t,QS=!!n}},{key:"setLogLevel",value:function(t){var n=$S[t.toLowerCase()];null!=n?n:e.globalLogger().warn("invalid log level - "+t)}},{key:"from",value:function(t){return new e(t)}}]),e}();rA.errors=ZS,rA.levels=YS;var iA=new rA("bytes/5.8.0");function aA(e){return!!e.toHexString}function oA(e){return e.slice||(e.slice=function(){var t=[].slice.call(arguments);return oA(new Uint8Array([].slice.apply(e,t)))}),e}function uA(e){return"number"==typeof e&&e==e&&e%1==0}function sA(e){if(null==e)return!1;if(e.constructor===Uint8Array)return!0;if("string"==typeof e)return!1;if(!uA(e.length)||e.length<0)return!1;for(var t=0;t<e.length;t++){var n=e[t];if(!uA(n)||n<0||n>=256)return!1}return!0}function lA(e,t){if(t||(t={}),"number"==typeof e){iA.checkSafeUint53(e,"invalid arrayify value");for(var n=[];e;)n.unshift(255&e),e=parseInt(e/256+"");return 0===n.length&&n.push(0),oA(new Uint8Array(n))}if(t.allowMissingPrefix&&"string"==typeof e&&"0x"!==e.substring(0,2)&&(e="0x"+e),aA(e)&&(e=e.toHexString()),cA(e)){var r=e.substring(2);r.length%2&&("left"===t.hexPad?r="0"+r:"right"===t.hexPad?r+="0":iA.throwArgumentError("hex data is odd-length","value",e));for(var i=[],a=0;a<r.length;a+=2)i.push(parseInt(r.substring(a,a+2),16));return oA(new Uint8Array(i))}return sA(e)?oA(new Uint8Array(e)):iA.throwArgumentError("invalid arrayify value","value",e)}function cA(e){return!("string"!=typeof e||!e.match(/^0x[0-9A-Fa-f]*$/))}var fA="0123456789abcdef";function dA(e,t){if(t||(t={}),"number"==typeof e){iA.checkSafeUint53(e,"invalid hexlify value");for(var n="";e;)n=fA[15&e]+n,e=Math.floor(e/16);return n.length?(n.length%2&&(n="0"+n),"0x"+n):"0x00"}if("bigint"==(void 0===e?"undefined":(0,fe.default)(e)))return(e=e.toString(16)).length%2?"0x0"+e:"0x"+e;if(t.allowMissingPrefix&&"string"==typeof e&&"0x"!==e.substring(0,2)&&(e="0x"+e),aA(e))return e.toHexString();if(cA(e))return e.length%2&&("left"===t.hexPad?e="0x0"+e.substring(2):"right"===t.hexPad?e+="0":iA.throwArgumentError("hex data is odd-length","value",e)),e.toLowerCase();if(sA(e)){for(var r="0x",i=0;i<e.length;i++){var a=e[i];r+=fA[(240&a)>>4]+fA[15&a]}return r}return iA.throwArgumentError("invalid hexlify value","value",e)}var hA=new rA("rlp/5.8.0");function vA(e){for(var t=[];e;)t.unshift(255&e),e>>=8;return t}function pA(e,t,n){for(var r=0,i=0;i<n;i++)r=256*r+e[t+i];return r}function gA(e){if(Array.isArray(e)){var t=[];if(e.forEach((function(e){t=t.concat(gA(e))})),t.length<=55)return t.unshift(192+t.length),t;var n=vA(t.length);return n.unshift(247+n.length),n.concat(t)}var r;cA(r=e)&&!(r.length%2)||sA(r)||hA.throwArgumentError("RLP object must be BytesLike","object",e);var i=[].slice.call(lA(e));if(1===i.length&&i[0]<=127)return i;if(i.length<=55)return i.unshift(128+i.length),i;var a=vA(i.length);return a.unshift(183+a.length),a.concat(i)}function yA(e,t,n,r){for(var i=[];n<t+1+r;){var a=mA(e,n);i.push(a.result),(n+=a.consumed)>t+1+r&&hA.throwError("child data too short",rA.errors.BUFFER_OVERRUN,{})}return{consumed:1+r,result:i}}function mA(e,t){if(0===e.length&&hA.throwError("data too short",rA.errors.BUFFER_OVERRUN,{}),e[t]>=248){var n=e[t]-247;t+1+n>e.length&&hA.throwError("data short segment too short",rA.errors.BUFFER_OVERRUN,{});var r=pA(e,t+1,n);return t+1+n+r>e.length&&hA.throwError("data long segment too short",rA.errors.BUFFER_OVERRUN,{}),yA(e,t,t+1+n,n+r)}if(e[t]>=192){var i=e[t]-192;return t+1+i>e.length&&hA.throwError("data array too short",rA.errors.BUFFER_OVERRUN,{}),yA(e,t,t+1,i)}if(e[t]>=184){var a=e[t]-183;t+1+a>e.length&&hA.throwError("data array too short",rA.errors.BUFFER_OVERRUN,{});var o=pA(e,t+1,a);return t+1+a+o>e.length&&hA.throwError("data array too short",rA.errors.BUFFER_OVERRUN,{}),{consumed:1+a+o,result:dA(e.slice(t+1+a,t+1+a+o))}}if(e[t]>=128){var u=e[t]-128;return t+1+u>e.length&&hA.throwError("data too short",rA.errors.BUFFER_OVERRUN,{}),{consumed:1+u,result:dA(e.slice(t+1,t+1+u))}}return{consumed:1,result:dA(e[t])}}var bA=new ja("enr:decoder"),wA=function(){"use strict";function e(){(0,H.default)(this,e)}return(0,$.default)(e,null,[{key:"fromString",value:function(t){if(!t.startsWith(XS.RECORD_PREFIX))throw Error("\"string encoded ENR must start with '".concat(XS.RECORD_PREFIX,"'"));return e.fromRLP(wn(t.slice(4),"base64url"))}},{key:"fromRLP",value:function(e){return function(){var e=(0,K.default)((function(e){var t,n,r,i,a,o,u,s;return(0,pe.__generator)(this,(function(l){for(t=function(e){if(!Array.isArray(e))throw Error("Decoded ENR must be an array");if(e.length%2!=0)throw Error("Decoded ENR must have an even number of elements");var t=(0,le.default)(e),n=t[0],r=t[1],i=t.slice(2);if(!n||Array.isArray(n))throw Error("Decoded ENR invalid signature: must be a byte array");if(!r||Array.isArray(r))throw Error("Decoded ENR invalid sequence number: must be a byte array");return{signature:n,seq:r,kvs:i}}(e),n=t.signature,r=t.seq,i=t.kvs,a={},o=0;o<i.length;o+=2)try{a[Di(i[o])]=i[o+1]}catch(e){bA.error("Failed to decode ENR key to UTF-8, skipping it",i[o],e)}return u=function(e){return e.length?BigInt("0x"+Li(e)):BigInt(0)}(r),s=XS.create(a,u,n),[2,(function(e,t,n,r){var i=Pi(dA(gA([e].concat((0,ce.default)(t)))));if(!n.verify(i,r))throw Error("Unable to verify ENR signature")}(r,i,s,n),s)]}))}));return function(t){return e.apply(this,arguments)}}()(function(e){var t=lA(e),n=mA(t,0);return n.consumed!==t.length&&hA.throwArgumentError("invalid rlp data","data",e),n.result}(e).map(Pi))}}]),e}(),kA=new WeakMap,_A=new WeakMap,EA=new WeakMap,SA=new WeakMap,AA=new WeakMap,IA=new WeakMap,xA=new WeakSet,CA=new WeakSet,TA=new WeakSet,PA=new WeakSet,RA=new WeakSet,LA=new WeakSet,DA=new WeakSet,MA=new WeakSet,NA=Symbol.iterator,OA=Symbol.toStringTag,UA=Symbol.for("nodejs.util.inspect.custom"),FA=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if((0,H.default)(this,n),e=t.call(this),(0,Q.default)((0,q.default)(e),xA),(0,Q.default)((0,q.default)(e),CA),(0,Q.default)((0,q.default)(e),TA),(0,Q.default)((0,q.default)(e),PA),(0,Q.default)((0,q.default)(e),RA),(0,Q.default)((0,q.default)(e),LA),(0,Q.default)((0,q.default)(e),DA),(0,Q.default)((0,q.default)(e),MA),(0,G.default)((0,q.default)(e),kA,{writable:!0,value:0}),(0,G.default)((0,q.default)(e),_A,{writable:!0,value:new Map}),(0,G.default)((0,q.default)(e),EA,{writable:!0,value:new Map}),(0,G.default)((0,q.default)(e),SA,{writable:!0,value:void 0}),(0,G.default)((0,q.default)(e),AA,{writable:!0,value:void 0}),(0,G.default)((0,q.default)(e),IA,{writable:!0,value:void 0}),!(r.maxSize&&r.maxSize>0))throw new TypeError("`maxSize` must be a number greater than 0");if("number"==typeof r.maxAge&&0===r.maxAge)throw new TypeError("`maxAge` must be a number greater than 0");return(0,X.default)((0,q.default)(e),SA,r.maxSize),(0,X.default)((0,q.default)(e),AA,r.maxAge||1/0),(0,X.default)((0,q.default)(e),IA,r.onEviction),(0,ue.default)(e)}return(0,$.default)(n,[{key:"__oldCache",get:function(){return(0,W.default)(this,EA)}},{key:"get",value:function(e){if((0,W.default)(this,_A).has(e)){var t=(0,W.default)(this,_A).get(e);return(0,Z.default)(this,PA,jA).call(this,e,t)}if((0,W.default)(this,EA).has(e)){var n=(0,W.default)(this,EA).get(e);if(!1===(0,Z.default)(this,CA,qA).call(this,e,n))return(0,Z.default)(this,DA,HA).call(this,e,n),n.value}}},{key:"set",value:function(e,t){var n=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}).maxAge,r=void 0===n?(0,W.default)(this,AA):n,i="number"==typeof r&&r!==1/0?Date.now()+r:void 0;return(0,W.default)(this,_A).has(e)?(0,W.default)(this,_A).set(e,{value:t,expiry:i}):(0,Z.default)(this,LA,VA).call(this,e,{value:t,expiry:i}),this}},{key:"has",value:function(e){return(0,W.default)(this,_A).has(e)?!(0,Z.default)(this,CA,qA).call(this,e,(0,W.default)(this,_A).get(e)):!!(0,W.default)(this,EA).has(e)&&!(0,Z.default)(this,CA,qA).call(this,e,(0,W.default)(this,EA).get(e))}},{key:"peek",value:function(e){return(0,W.default)(this,_A).has(e)?(0,Z.default)(this,RA,KA).call(this,e,(0,W.default)(this,_A)):(0,W.default)(this,EA).has(e)?(0,Z.default)(this,RA,KA).call(this,e,(0,W.default)(this,EA)):void 0}},{key:"expiresIn",value:function(e){var t,n=null!==(t=(0,W.default)(this,_A).get(e))&&void 0!==t?t:(0,W.default)(this,EA).get(e);if(n)return n.expiry?n.expiry-Date.now():1/0}},{key:"delete",value:function(e){var t=(0,W.default)(this,_A).delete(e);return t&&(0,Y.default)(this,kA).value--,(0,W.default)(this,EA).delete(e)||t}},{key:"clear",value:function(){(0,W.default)(this,_A).clear(),(0,W.default)(this,EA).clear(),(0,X.default)(this,kA,0)}},{key:"resize",value:function(e){if(!(e&&e>0))throw new TypeError("`maxSize` must be a number greater than 0");var t=(0,ce.default)((0,Z.default)(this,MA,WA).call(this)),n=t.length-e;n<0?((0,X.default)(this,_A,new Map(t)),(0,X.default)(this,EA,new Map),(0,X.default)(this,kA,t.length)):(n>0&&(0,Z.default)(this,xA,BA).call(this,t.slice(0,n)),(0,X.default)(this,EA,new Map(t.slice(n))),(0,X.default)(this,_A,new Map),(0,X.default)(this,kA,0)),(0,X.default)(this,SA,e)}},{key:"evict",value:function(){var e=Number(arguments.length>0&&void 0!==arguments[0]?arguments[0]:1);if(e&&!(e<=0)){var t=(0,ce.default)((0,Z.default)(this,MA,WA).call(this)),n=Math.trunc(Math.min(e,Math.max(t.length-1,0)));n<=0||((0,Z.default)(this,xA,BA).call(this,t.slice(0,n)),(0,X.default)(this,EA,new Map(t.slice(n))),(0,X.default)(this,_A,new Map),(0,X.default)(this,kA,0))}}},{key:"keys",value:function(){var e,t,n,r,i,a,o;return(0,pe.__generator)(this,(function(u){switch(u.label){case 0:e=!0,t=!1,n=void 0,u.label=1;case 1:u.trys.push([1,6,7,8]),r=this[Symbol.iterator](),u.label=2;case 2:return(e=(i=r.next()).done)?[3,5]:(a=(0,se.default)(i.value,1),[4,a[0]]);case 3:u.sent(),u.label=4;case 4:return e=!0,[3,2];case 5:return[3,8];case 6:return o=u.sent(),t=!0,n=o,[3,8];case 7:try{e||null==r.return||r.return()}finally{if(t)throw n}return[7];case 8:return[2]}}))}},{key:"values",value:function(){var e,t,n,r,i,a,o;return(0,pe.__generator)(this,(function(u){switch(u.label){case 0:e=!0,t=!1,n=void 0,u.label=1;case 1:u.trys.push([1,6,7,8]),r=this[Symbol.iterator](),u.label=2;case 2:return(e=(i=r.next()).done)?[3,5]:(a=(0,se.default)(i.value,2),[4,a[1]]);case 3:u.sent(),u.label=4;case 4:return e=!0,[3,2];case 5:return[3,8];case 6:return o=u.sent(),t=!0,n=o,[3,8];case 7:try{e||null==r.return||r.return()}finally{if(t)throw n}return[7];case 8:return[2]}}))}},{key:NA,value:function(){var e,t,n,r,i,a,o,u,s,l,c,f,d,h,v,p,g,y,m;return(0,pe.__generator)(this,(function(b){switch(b.label){case 0:e=!0,t=!1,n=void 0,b.label=1;case 1:b.trys.push([1,7,8,9]),r=(0,W.default)(this,_A)[Symbol.iterator](),b.label=2;case 2:return(e=(i=r.next()).done)?[3,6]:(a=i.value,o=(0,se.default)(a,2),u=o[0],s=o[1],!1===(0,Z.default)(this,CA,qA).call(this,u,s)?[4,[u,s.value]]:[3,4]);case 3:b.sent(),b.label=4;case 4:b.label=5;case 5:return e=!0,[3,2];case 6:return[3,9];case 7:return m=b.sent(),t=!0,n=m,[3,9];case 8:try{e||null==r.return||r.return()}finally{if(t)throw n}return[7];case 9:l=!0,c=!1,f=void 0,b.label=10;case 10:b.trys.push([10,16,17,18]),d=(0,W.default)(this,EA)[Symbol.iterator](),b.label=11;case 11:return(l=(h=d.next()).done)?[3,15]:(v=h.value,p=(0,se.default)(v,2),g=p[0],y=p[1],(0,W.default)(this,_A).has(g)?[3,14]:!1===(0,Z.default)(this,CA,qA).call(this,g,y)?[4,[g,y.value]]:[3,13]);case 12:b.sent(),b.label=13;case 13:b.label=14;case 14:return l=!0,[3,11];case 15:return[3,18];case 16:return m=b.sent(),c=!0,f=m,[3,18];case 17:try{l||null==d.return||d.return()}finally{if(c)throw f}return[7];case 18:return[2]}}))}},{key:"entriesDescending",value:function(){var e,t,n,r,i,a,o,u,s,l,c;return(0,pe.__generator)(this,(function(f){switch(f.label){case 0:e=(0,ce.default)((0,W.default)(this,_A)),t=e.length-1,f.label=1;case 1:return t>=0?(n=e[t],r=(0,se.default)(n,2),i=r[0],a=r[1],!1===(0,Z.default)(this,CA,qA).call(this,i,a)?[4,[i,a.value]]:[3,3]):[3,5];case 2:f.sent(),f.label=3;case 3:f.label=4;case 4:return--t,[3,1];case 5:e=(0,ce.default)((0,W.default)(this,EA)),o=e.length-1,f.label=6;case 6:return o>=0?(u=e[o],s=(0,se.default)(u,2),l=s[0],c=s[1],(0,W.default)(this,_A).has(l)?[3,9]:!1===(0,Z.default)(this,CA,qA).call(this,l,c)?[4,[l,c.value]]:[3,8]):[3,10];case 7:f.sent(),f.label=8;case 8:f.label=9;case 9:return--o,[3,6];case 10:return[2]}}))}},{key:"entriesAscending",value:function(){var e,t,n,r,i,a,o,u,s;return(0,pe.__generator)(this,(function(l){switch(l.label){case 0:e=!0,t=!1,n=void 0,l.label=1;case 1:l.trys.push([1,6,7,8]),r=(0,Z.default)(this,MA,WA).call(this)[Symbol.iterator](),l.label=2;case 2:return(e=(i=r.next()).done)?[3,5]:(a=(0,se.default)(i.value,2),o=a[0],u=a[1],[4,[o,u.value]]);case 3:l.sent(),l.label=4;case 4:return e=!0,[3,2];case 5:return[3,8];case 6:return s=l.sent(),t=!0,n=s,[3,8];case 7:try{e||null==r.return||r.return()}finally{if(t)throw n}return[7];case 8:return[2]}}))}},{key:"size",get:function(){if(!(0,W.default)(this,kA))return(0,W.default)(this,EA).size;var e=0,t=!0,n=!1,r=void 0;try{for(var i,a=(0,W.default)(this,EA).keys()[Symbol.iterator]();!(t=(i=a.next()).done);t=!0){var o=i.value;(0,W.default)(this,_A).has(o)||e++}}catch(e){n=!0,r=e}finally{try{t||null==a.return||a.return()}finally{if(n)throw r}}return Math.min((0,W.default)(this,kA)+e,(0,W.default)(this,SA))}},{key:"maxSize",get:function(){return(0,W.default)(this,SA)}},{key:"maxAge",get:function(){return(0,W.default)(this,AA)}},{key:"entries",value:function(){return this.entriesAscending()}},{key:"forEach",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this,n=!0,r=!1,i=void 0;try{for(var a,o=this.entriesAscending()[Symbol.iterator]();!(n=(a=o.next()).done);n=!0){var u=(0,se.default)(a.value,2),s=u[0],l=u[1];e.call(t,l,s,this)}}catch(e){r=!0,i=e}finally{try{n||null==o.return||o.return()}finally{if(r)throw i}}}},{key:OA,get:function(){return"QuickLRU"}},{key:"toString",value:function(){return"QuickLRU(".concat(this.size,"/").concat(this.maxSize,")")}},{key:UA,value:function(){return this.toString()}}]),n}((0,he.default)(Map));function BA(e){var t=!0,n=!1,r=void 0;if("function"==typeof(0,W.default)(this,IA))try{for(var i,a=e[Symbol.iterator]();!(t=(i=a.next()).done);t=!0){var o=(0,se.default)(i.value,2),u=o[0],s=o[1];(0,W.default)(this,IA).call(this,u,s.value)}}catch(e){n=!0,r=e}finally{try{t||null==a.return||a.return()}finally{if(n)throw r}}}function qA(e,t){return"number"==typeof t.expiry&&t.expiry<=Date.now()&&("function"==typeof(0,W.default)(this,IA)&&(0,W.default)(this,IA).call(this,e,t.value),this.delete(e))}function zA(e,t){if(!1===(0,Z.default)(this,CA,qA).call(this,e,t))return t.value}function jA(e,t){return t.expiry?(0,Z.default)(this,TA,zA).call(this,e,t):t.value}function KA(e,t){var n=t.get(e);return(0,Z.default)(this,PA,jA).call(this,e,n)}function VA(e,t){(0,W.default)(this,_A).set(e,t),(0,Y.default)(this,kA).value++,(0,W.default)(this,kA)>=(0,W.default)(this,SA)&&((0,X.default)(this,kA,0),(0,Z.default)(this,xA,BA).call(this,(0,W.default)(this,EA)),(0,X.default)(this,EA,(0,W.default)(this,_A)),(0,X.default)(this,_A,new Map))}function HA(e,t){(0,W.default)(this,EA).delete(e),(0,Z.default)(this,LA,VA).call(this,e,t)}function WA(){var e,t,n,r,i,a,o,u,s,l,c,f,d,h,v,p,g,y,m;return(0,pe.__generator)(this,(function(b){switch(b.label){case 0:e=!0,t=!1,n=void 0,b.label=1;case 1:b.trys.push([1,7,8,9]),r=(0,W.default)(this,EA)[Symbol.iterator](),b.label=2;case 2:return(e=(i=r.next()).done)?[3,6]:(a=i.value,o=(0,se.default)(a,2),u=o[0],s=o[1],(0,W.default)(this,_A).has(u)?[3,5]:!1===(0,Z.default)(this,CA,qA).call(this,u,s)?[4,a]:[3,4]);case 3:b.sent(),b.label=4;case 4:b.label=5;case 5:return e=!0,[3,2];case 6:return[3,9];case 7:return m=b.sent(),t=!0,n=m,[3,9];case 8:try{e||null==r.return||r.return()}finally{if(t)throw n}return[7];case 9:l=!0,c=!1,f=void 0,b.label=10;case 10:b.trys.push([10,16,17,18]),d=(0,W.default)(this,_A)[Symbol.iterator](),b.label=11;case 11:return(l=(h=d.next()).done)?[3,15]:(v=h.value,p=(0,se.default)(v,2),g=p[0],y=p[1],!1===(0,Z.default)(this,CA,qA).call(this,g,y)?[4,v]:[3,13]);case 12:b.sent(),b.label=13;case 13:b.label=14;case 14:return l=!0,[3,11];case 15:return[3,18];case 16:return m=b.sent(),c=!0,f=m,[3,18];case 17:try{l||null==d.return||d.return()}finally{if(c)throw f}return[7];case 18:return[2]}}))}function GA(e,t,n){return"".concat(e,"?name=").concat(t,"&type=").concat(n)}function XA(e,t){return YA.apply(this,arguments)}function YA(){return YA=(0,K.default)((function(e,t){return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:return[4,fetch(e,{headers:new Headers({accept:"application/dns-json"}),signal:t})];case 1:return[4,n.sent().json()];case 2:return[2,n.sent()]}}))})),YA.apply(this,arguments)}function ZA(e,t){return"".concat(t,"_").concat(e)}var QA,JA=Object.assign(Lm("dns-over-http-resolver"),{error:Lm("dns-over-http-resolver:error")}),$A=function(){"use strict";function e(){var t,n,r,i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};(0,H.default)(this,e),(0,te.default)(this,"_cache",void 0),(0,te.default)(this,"_TXTcache",void 0),(0,te.default)(this,"_servers",void 0),(0,te.default)(this,"_request",void 0),(0,te.default)(this,"_abortControllers",void 0),this._cache=new FA({maxSize:null!==(t=null==i?void 0:i.maxCache)&&void 0!==t?t:100}),this._TXTcache=new FA({maxSize:null!==(n=null==i?void 0:i.maxCache)&&void 0!==n?n:100}),this._servers=["https://cloudflare-dns.com/dns-query","https://dns.google/resolve"],this._request=null!==(r=i.request)&&void 0!==r?r:XA,this._abortControllers=[]}return(0,$.default)(e,[{key:"cancel",value:function(){this._abortControllers.forEach((function(e){e.abort()}))}},{key:"getServers",value:function(){return this._servers}},{key:"_getShuffledServers",value:function(){for(var e=(0,ce.default)(this._servers),t=e.length-1;t>0;t--){var n=Math.floor(Math.random()*t),r=e[t];e[t]=e[n],e[n]=r}return e}},{key:"setServers",value:function(e){this._servers=e}},{key:"resolve",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"A",n=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(r){switch(t){case"A":return[2,n.resolve4(e)];case"AAAA":return[2,n.resolve6(e)];case"TXT":return[2,n.resolveTxt(e)];default:throw Error(t+" is not supported")}return[2]}))}))()}},{key:"resolve4",value:function(e){var t=this;return(0,K.default)((function(){var n,r,i,a,o,u,s,l,c,f,d,h,v,p,g;return(0,pe.__generator)(this,(function(y){switch(y.label){case 0:if(n="A",null!=(r=t._cache.get(ZA(e,n))))return[2,r];i=!1,a=!0,o=!1,u=void 0,y.label=1;case 1:y.trys.push([1,9,10,11]),s=t._getShuffledServers()[Symbol.iterator](),y.label=2;case 2:if(a=(l=s.next()).done)return[3,8];c=l.value,f=new AbortController,t._abortControllers.push(f),y.label=3;case 3:return y.trys.push([3,5,6,7]),[4,t._request(GA(c,e,n),f.signal)];case 4:return h=y.sent(),v=h.Answer.map((function(e){return e.data})),p=(d=Math).min.apply(d,(0,ce.default)(h.Answer.map((function(e){return e.TTL})))),[2,(t._cache.set(ZA(e,n),v,{maxAge:p}),v)];case 5:return y.sent(),f.signal.aborted&&(i=!0),JA.error("".concat(c," could not resolve ").concat(e," record ").concat(n)),[3,7];case 6:return t._abortControllers=t._abortControllers.filter((function(e){return e!==f})),[7];case 7:return a=!0,[3,2];case 8:return[3,11];case 9:return g=y.sent(),o=!0,u=g,[3,11];case 10:try{a||null==s.return||s.return()}finally{if(o)throw u}return[7];case 11:if(i)throw Object.assign(Error("queryA ECANCELLED"),{code:"ECANCELLED"});throw Error("Could not resolve ".concat(e," record ").concat(n))}}))}))()}},{key:"resolve6",value:function(e){var t=this;return(0,K.default)((function(){var n,r,i,a,o,u,s,l,c,f,d,h,v,p,g;return(0,pe.__generator)(this,(function(y){switch(y.label){case 0:if(n="AAAA",null!=(r=t._cache.get(ZA(e,n))))return[2,r];i=!1,a=!0,o=!1,u=void 0,y.label=1;case 1:y.trys.push([1,9,10,11]),s=t._getShuffledServers()[Symbol.iterator](),y.label=2;case 2:if(a=(l=s.next()).done)return[3,8];c=l.value,f=new AbortController,t._abortControllers.push(f),y.label=3;case 3:return y.trys.push([3,5,6,7]),[4,t._request(GA(c,e,n),f.signal)];case 4:return h=y.sent(),v=h.Answer.map((function(e){return e.data})),p=(d=Math).min.apply(d,(0,ce.default)(h.Answer.map((function(e){return e.TTL})))),[2,(t._cache.set(ZA(e,n),v,{maxAge:p}),v)];case 5:return y.sent(),f.signal.aborted&&(i=!0),JA.error("".concat(c," could not resolve ").concat(e," record ").concat(n)),[3,7];case 6:return t._abortControllers=t._abortControllers.filter((function(e){return e!==f})),[7];case 7:return a=!0,[3,2];case 8:return[3,11];case 9:return g=y.sent(),o=!0,u=g,[3,11];case 10:try{a||null==s.return||s.return()}finally{if(o)throw u}return[7];case 11:if(i)throw Object.assign(Error("queryAaaa ECANCELLED"),{code:"ECANCELLED"});throw Error("Could not resolve ".concat(e," record ").concat(n))}}))}))()}},{key:"resolveTxt",value:function(e){var t=this;return(0,K.default)((function(){var n,r,i,a,o,u,s,l,c,f,d,h,v,p,g;return(0,pe.__generator)(this,(function(y){switch(y.label){case 0:if(n="TXT",null!=(r=t._TXTcache.get(ZA(e,n))))return[2,r];i=!1,a=!0,o=!1,u=void 0,y.label=1;case 1:y.trys.push([1,9,10,11]),s=t._getShuffledServers()[Symbol.iterator](),y.label=2;case 2:if(a=(l=s.next()).done)return[3,8];c=l.value,f=new AbortController,t._abortControllers.push(f),y.label=3;case 3:return y.trys.push([3,5,6,7]),[4,t._request(GA(c,e,n),f.signal)];case 4:return h=y.sent(),v=h.Answer.map((function(e){return[e.data.replace(/['"]+/g,"")]})),p=(d=Math).min.apply(d,(0,ce.default)(h.Answer.map((function(e){return e.TTL})))),[2,(t._TXTcache.set(ZA(e,n),v,{maxAge:p}),v)];case 5:return y.sent(),f.signal.aborted&&(i=!0),JA.error("".concat(c," could not resolve ").concat(e," record ").concat(n)),[3,7];case 6:return t._abortControllers=t._abortControllers.filter((function(e){return e!==f})),[7];case 7:return a=!0,[3,2];case 8:return[3,11];case 9:return g=y.sent(),o=!0,u=g,[3,11];case 10:try{a||null==s.return||s.return()}finally{if(o)throw u}return[7];case 11:if(i)throw Object.assign(Error("queryTxt ECANCELLED"),{code:"ECANCELLED"});throw Error("Could not resolve ".concat(e," record ").concat(n))}}))}))()}},{key:"clearCache",value:function(){this._cache.clear(),this._TXTcache.clear()}}]),e}(),eI=new ja("dns-over-https"),tI=function(){"use strict";function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new $A;(0,H.default)(this,e),(0,te.default)(this,"resolver",void 0),this.resolver=t}return(0,$.default)(e,[{key:"resolveTXT",value:function(e){var t=this;return(0,K.default)((function(){var n,r,i;return(0,pe.__generator)(this,(function(a){switch(a.label){case 0:return a.trys.push([0,2,,3]),[4,t.resolver.resolveTxt(e)];case 1:return n=a.sent(),[3,3];case 2:throw r=a.sent(),eI.error("query failed: ",r),Error("DNS query failed");case 3:if(!n)throw Error("Could not resolve "+e);return i=[],[2,(n.forEach((function(e){"string"==typeof e?i.push(e):Array.isArray(e)?e.forEach((function(e){"string"==typeof e?i.push(e):i.push(Di(e))})):i.push(Di(e))})),i)]}}))}))()}}],[{key:"create",value:function(){return(0,K.default)((function(){return(0,pe.__generator)(this,(function(t){return[2,new e]}))}))()}}]),e}(),nI={exports:{}},rI=(QA||(QA=1,function(e){!function(){var t="object"==typeof window?window:{};!t.HI_BASE32_NO_NODE_JS&&"object"==typeof ge&&ge.versions&&ge.versions.node&&(t=Ra);var n=!t.HI_BASE32_NO_COMMON_JS&&e.exports,r="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567".split(""),i={A:0,B:1,C:2,D:3,E:4,F:5,G:6,H:7,I:8,J:9,K:10,L:11,M:12,N:13,O:14,P:15,Q:16,R:17,S:18,T:19,U:20,V:21,W:22,X:23,Y:24,Z:25,2:26,3:27,4:28,5:29,6:30,7:31},a=[0,0,0,0,0,0,0,0],o=function(e,t){t.length>10&&(t="..."+t.substr(-10));var n=Error("Decoded data is not valid UTF-8. Maybe try base32.decode.asBytes()? Partial data after reading "+e+" bytes: "+t+" <-");throw n.position=e,n},u=function(e){if(""===e)return[];if(!/^[A-Z2-7=]+$/.test(e))throw Error("Invalid base32 characters");for(var t,n,r,a,o,u,s,l,c=[],f=0,d=(e=e.replace(/=/g,"")).length,h=0,v=d>>3<<3;h<v;)t=i[e.charAt(h++)],n=i[e.charAt(h++)],r=i[e.charAt(h++)],a=i[e.charAt(h++)],o=i[e.charAt(h++)],u=i[e.charAt(h++)],s=i[e.charAt(h++)],l=i[e.charAt(h++)],c[f++]=255&(t<<3|n>>>2),c[f++]=255&(n<<6|r<<1|a>>>4),c[f++]=255&(a<<4|o>>>1),c[f++]=255&(o<<7|u<<2|s>>>3),c[f++]=255&(s<<5|l);var p=d-v;return 2===p?(t=i[e.charAt(h++)],n=i[e.charAt(h++)],c[f++]=255&(t<<3|n>>>2)):4===p?(t=i[e.charAt(h++)],n=i[e.charAt(h++)],r=i[e.charAt(h++)],a=i[e.charAt(h++)],c[f++]=255&(t<<3|n>>>2),c[f++]=255&(n<<6|r<<1|a>>>4)):5===p?(t=i[e.charAt(h++)],n=i[e.charAt(h++)],r=i[e.charAt(h++)],a=i[e.charAt(h++)],o=i[e.charAt(h++)],c[f++]=255&(t<<3|n>>>2),c[f++]=255&(n<<6|r<<1|a>>>4),c[f++]=255&(a<<4|o>>>1)):7===p&&(t=i[e.charAt(h++)],n=i[e.charAt(h++)],r=i[e.charAt(h++)],a=i[e.charAt(h++)],o=i[e.charAt(h++)],u=i[e.charAt(h++)],s=i[e.charAt(h++)],c[f++]=255&(t<<3|n>>>2),c[f++]=255&(n<<6|r<<1|a>>>4),c[f++]=255&(a<<4|o>>>1),c[f++]=255&(o<<7|u<<2|s>>>3)),c},s=function(e,t){if(!t)return function(e){for(var t,n,r="",i=e.length,a=0,u=0;a<i;)if((t=e[a++])<=127)r+=String.fromCharCode(t);else{t>191&&t<=223?(n=31&t,u=1):t<=239?(n=15&t,u=2):t<=247?(n=7&t,u=3):o(a,r);for(var s=0;s<u;++s)((t=e[a++])<128||t>191)&&o(a,r),n<<=6,n+=63&t;n>=55296&&n<=57343&&o(a,r),n>1114111&&o(a,r),n<=65535?r+=String.fromCharCode(n):(r+=String.fromCharCode(55296+((n-=65536)>>10)),r+=String.fromCharCode(56320+(1023&n)))}return r}(u(e));if(""===e)return"";if(!/^[A-Z2-7=]+$/.test(e))throw Error("Invalid base32 characters");var n,r,a,s,l,c,f,d,h="",v=e.indexOf("=");-1===v&&(v=e.length);for(var p=0,g=v>>3<<3;p<g;)n=i[e.charAt(p++)],r=i[e.charAt(p++)],a=i[e.charAt(p++)],s=i[e.charAt(p++)],l=i[e.charAt(p++)],c=i[e.charAt(p++)],f=i[e.charAt(p++)],d=i[e.charAt(p++)],h+=String.fromCharCode(255&(n<<3|r>>>2))+String.fromCharCode(255&(r<<6|a<<1|s>>>4))+String.fromCharCode(255&(s<<4|l>>>1))+String.fromCharCode(255&(l<<7|c<<2|f>>>3))+String.fromCharCode(255&(f<<5|d));var y=v-g;return 2===y?(n=i[e.charAt(p++)],r=i[e.charAt(p++)],h+=String.fromCharCode(255&(n<<3|r>>>2))):4===y?(n=i[e.charAt(p++)],r=i[e.charAt(p++)],a=i[e.charAt(p++)],s=i[e.charAt(p++)],h+=String.fromCharCode(255&(n<<3|r>>>2))+String.fromCharCode(255&(r<<6|a<<1|s>>>4))):5===y?(n=i[e.charAt(p++)],r=i[e.charAt(p++)],a=i[e.charAt(p++)],s=i[e.charAt(p++)],l=i[e.charAt(p++)],h+=String.fromCharCode(255&(n<<3|r>>>2))+String.fromCharCode(255&(r<<6|a<<1|s>>>4))+String.fromCharCode(255&(s<<4|l>>>1))):7===y&&(n=i[e.charAt(p++)],r=i[e.charAt(p++)],a=i[e.charAt(p++)],s=i[e.charAt(p++)],l=i[e.charAt(p++)],c=i[e.charAt(p++)],f=i[e.charAt(p++)],h+=String.fromCharCode(255&(n<<3|r>>>2))+String.fromCharCode(255&(r<<6|a<<1|s>>>4))+String.fromCharCode(255&(s<<4|l>>>1))+String.fromCharCode(255&(l<<7|c<<2|f>>>3))),h},l={encode:function(e,t){var n="string"!=typeof e;return n&&e.constructor===ArrayBuffer&&(e=new Uint8Array(e)),n?function(e){for(var t,n,i,a,o,u="",s=e.length,l=0,c=5*parseInt(s/5);l<c;)t=e[l++],n=e[l++],i=e[l++],a=e[l++],o=e[l++],u+=r[t>>>3]+r[31&(t<<2|n>>>6)]+r[n>>>1&31]+r[31&(n<<4|i>>>4)]+r[31&(i<<1|a>>>7)]+r[a>>>2&31]+r[31&(a<<3|o>>>5)]+r[31&o];var f=s-c;return 1===f?(t=e[l],u+=r[t>>>3]+r[t<<2&31]+"======"):2===f?(t=e[l++],n=e[l],u+=r[t>>>3]+r[31&(t<<2|n>>>6)]+r[n>>>1&31]+r[n<<4&31]+"===="):3===f?(t=e[l++],n=e[l++],i=e[l],u+=r[t>>>3]+r[31&(t<<2|n>>>6)]+r[n>>>1&31]+r[31&(n<<4|i>>>4)]+r[i<<1&31]+"==="):4===f&&(t=e[l++],n=e[l++],i=e[l++],a=e[l],u+=r[t>>>3]+r[31&(t<<2|n>>>6)]+r[n>>>1&31]+r[31&(n<<4|i>>>4)]+r[31&(i<<1|a>>>7)]+r[a>>>2&31]+r[a<<3&31]+"="),u}(e):t?function(e){for(var t,n,i,a,o,u="",s=e.length,l=0,c=5*parseInt(s/5);l<c;)t=e.charCodeAt(l++),n=e.charCodeAt(l++),i=e.charCodeAt(l++),a=e.charCodeAt(l++),o=e.charCodeAt(l++),u+=r[t>>>3]+r[31&(t<<2|n>>>6)]+r[n>>>1&31]+r[31&(n<<4|i>>>4)]+r[31&(i<<1|a>>>7)]+r[a>>>2&31]+r[31&(a<<3|o>>>5)]+r[31&o];var f=s-c;return 1===f?(t=e.charCodeAt(l),u+=r[t>>>3]+r[t<<2&31]+"======"):2===f?(t=e.charCodeAt(l++),n=e.charCodeAt(l),u+=r[t>>>3]+r[31&(t<<2|n>>>6)]+r[n>>>1&31]+r[n<<4&31]+"===="):3===f?(t=e.charCodeAt(l++),n=e.charCodeAt(l++),i=e.charCodeAt(l),u+=r[t>>>3]+r[31&(t<<2|n>>>6)]+r[n>>>1&31]+r[31&(n<<4|i>>>4)]+r[i<<1&31]+"==="):4===f&&(t=e.charCodeAt(l++),n=e.charCodeAt(l++),i=e.charCodeAt(l++),a=e.charCodeAt(l),u+=r[t>>>3]+r[31&(t<<2|n>>>6)]+r[n>>>1&31]+r[31&(n<<4|i>>>4)]+r[31&(i<<1|a>>>7)]+r[a>>>2&31]+r[a<<3&31]+"="),u}(e):function(e){var t,n,i,o,u,s,l,c=!1,f="",d=0,h=0,v=e.length;if(""===e)return f;do{for(a[0]=a[5],a[1]=a[6],a[2]=a[7],l=h;d<v&&l<5;++d)(s=e.charCodeAt(d))<128?a[l++]=s:s<2048?(a[l++]=192|s>>6,a[l++]=128|63&s):s<55296||s>=57344?(a[l++]=224|s>>12,a[l++]=128|s>>6&63,a[l++]=128|63&s):(s=65536+((1023&s)<<10|1023&e.charCodeAt(++d)),a[l++]=240|s>>18,a[l++]=128|s>>12&63,a[l++]=128|s>>6&63,a[l++]=128|63&s);h=l-5,d===v&&++d,d>v&&l<6&&(c=!0),t=a[0],l>4?(n=a[1],i=a[2],o=a[3],u=a[4],f+=r[t>>>3]+r[31&(t<<2|n>>>6)]+r[n>>>1&31]+r[31&(n<<4|i>>>4)]+r[31&(i<<1|o>>>7)]+r[o>>>2&31]+r[31&(o<<3|u>>>5)]+r[31&u]):1===l?f+=r[t>>>3]+r[t<<2&31]+"======":2===l?(n=a[1],f+=r[t>>>3]+r[31&(t<<2|n>>>6)]+r[n>>>1&31]+r[n<<4&31]+"===="):3===l?(n=a[1],i=a[2],f+=r[t>>>3]+r[31&(t<<2|n>>>6)]+r[n>>>1&31]+r[31&(n<<4|i>>>4)]+r[i<<1&31]+"==="):(n=a[1],i=a[2],o=a[3],f+=r[t>>>3]+r[31&(t<<2|n>>>6)]+r[n>>>1&31]+r[31&(n<<4|i>>>4)]+r[31&(i<<1|o>>>7)]+r[o>>>2&31]+r[o<<3&31]+"=")}while(!c);return f}(e)},decode:s};s.asBytes=u,n?e.exports=l:t.base32=l}()}(nI)),nI.exports),iI=La(rI),aI=function(){"use strict";function e(){(0,H.default)(this,e)}return(0,$.default)(e,null,[{key:"parseAndVerifyRoot",value:function(t,n){if(!t.startsWith(this.ROOT_PREFIX))throw Error("ENRTree root entry must start with '".concat(this.ROOT_PREFIX,"'"));var r=e.parseRootValues(t),i=iI.decode.asBytes(n),a=t.split(" sig")[0],o=Mi(a);if(!VE(wn(r.signature,"base64url").slice(0,64),KE(o),new Uint8Array(i)))throw Error("Unable to verify ENRTree root signature");return r.eRoot}},{key:"parseRootValues",value:function(e){var t=e.match(/^enrtree-root:v1 e=([^ ]+) l=([^ ]+) seq=(\d+) sig=([^ ]+)$/);if(!Array.isArray(t))throw Error("Could not parse ENRTree root entry");t.shift();var n=(0,se.default)(t,4),r=n[0],i=n[1],a=n[2],o=n[3];if(!r)throw Error("Could not parse 'e' value from ENRTree root entry");if(!i)throw Error("Could not parse 'l' value from ENRTree root entry");if(!a)throw Error("Could not parse 'seq' value from ENRTree root entry");if(!o)throw Error("Could not parse 'sig' value from ENRTree root entry");return{eRoot:r,lRoot:i,seq:Number(a),signature:o}}},{key:"parseTree",value:function(e){if(!e.startsWith(this.TREE_PREFIX))throw Error("ENRTree tree entry must start with '".concat(this.TREE_PREFIX,"'"));var t=e.match(/^enrtree:\/\/([^@]+)@(.+)$/);if(!Array.isArray(t))throw Error("Could not parse ENRTree tree entry");t.shift();var n=(0,se.default)(t,2),r=n[0],i=n[1];if(!r)throw Error("Could not parse public key from ENRTree tree entry");if(!i)throw Error("Could not parse domain from ENRTree tree entry");return{publicKey:r,domain:i}}},{key:"parseBranch",value:function(e){if(!e.startsWith(this.BRANCH_PREFIX))throw Error("ENRTree branch entry must start with '".concat(this.BRANCH_PREFIX,"'"));return e.split(this.BRANCH_PREFIX)[1].split(",")}}]),e}();(0,te.default)(aI,"RECORD_PREFIX",XS.RECORD_PREFIX),(0,te.default)(aI,"TREE_PREFIX","enrtree:"),(0,te.default)(aI,"BRANCH_PREFIX","enrtree-branch:"),(0,te.default)(aI,"ROOT_PREFIX","enrtree-root:");var oI=new ja("discovery:fetch_nodes");function uI(){return uI=(0,de.default)((function(e){var t,n,r,i,a,o,u,s=arguments;return(0,pe.__generator)(this,(function(l){switch(l.label){case 0:t=s.length>1&&void 0!==s[1]?s[1]:10,n=s.length>2&&void 0!==s[2]?s[2]:3,r=new Set,i=0,a=0,l.label=1;case 1:return i<t&&a<n?(i++,[4,(0,V.default)(e())]):[3,9];case 2:return(o=l.sent())&&o.nodeId?(u=r.has(o.nodeId))?[3,5]:(r.add(o.nodeId),o.waku2?[4,o]:[3,4]):[3,6];case 3:l.sent(),l.label=4;case 4:u=oI.info("got new peer candidate from DNS address=".concat(o.nodeId,"@").concat(o.ip)),l.label=5;case 5:return u,[3,7];case 6:a++,l.label=7;case 7:l.label=8;case 8:return[3,1];case 9:return[2]}}))})),uI.apply(this,arguments)}var sI=new ja("discovery:dns"),lI=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"dns",void 0),(0,te.default)(this,"_DNSTreeCache",void 0),this._DNSTreeCache={},this.dns=t}return(0,$.default)(e,[{key:"getNextPeer",value:function(e){var t=this;return(0,de.default)((function(){var n,r,i,a,o,u,s,l,c,f,d,h,v,p,g,y,m,b;return(0,pe.__generator)(this,(function(w){switch(w.label){case 0:n=!0,r=!1,i=void 0,w.label=1;case 1:w.trys.push([1,17,18,19]),a=function(e){if(e.length<=1)return e;for(var t=0;t<e.length;t++){var n=Math.floor(Math.random()*Math.floor(e.length)),r=e[t];e[t]=e[n],e[n]=r}return e}(e)[Symbol.iterator](),w.label=2;case 2:if(n=(o=a.next()).done)return[3,16];u=o.value,s=aI.parseTree(u),l=s.publicKey,c=s.domain,f={domain:c,publicKey:l,visits:{}},d=!1,h=!1,w.label=3;case 3:w.trys.push([3,9,10,15]),p=(0,j.default)(function(e){return uI.apply(this,arguments)}((function(){return t._search(c,f)}))),w.label=4;case 4:return[4,(0,V.default)(p.next())];case 5:return(d=!(g=w.sent()).done)?(y=g.value,[4,y]):[3,8];case 6:w.sent(),w.label=7;case 7:return d=!1,[3,4];case 8:return[3,15];case 9:return m=w.sent(),h=!0,v=m,[3,15];case 10:return w.trys.push([10,,13,14]),d&&null!=p.return?[4,p.return()]:[3,12];case 11:w.sent(),w.label=12;case 12:return[3,14];case 13:if(h)throw v;return[7];case 14:return[7];case 15:return n=!0,[3,2];case 16:return[3,19];case 17:return b=w.sent(),r=!0,i=b,[3,19];case 18:try{n||null==a.return||a.return()}finally{if(r)throw i}return[7];case 19:return[2]}}))}))()}},{key:"_search",value:function(e,t){var n=this;return(0,K.default)((function(){var r,i,a,o,u,s;return(0,pe.__generator)(this,(function(l){switch(l.label){case 0:return l.trys.push([0,12,,13]),[4,n._getTXTRecord(e,t)];case 1:r=l.sent(),t.visits[e]=!0,o=function(e){return e.startsWith(aI.ROOT_PREFIX)?aI.ROOT_PREFIX:e.startsWith(aI.BRANCH_PREFIX)?aI.BRANCH_PREFIX:e.startsWith(aI.RECORD_PREFIX)?aI.RECORD_PREFIX:""}(r),l.label=2;case 2:switch(l.trys.push([2,10,,11]),o){case aI.ROOT_PREFIX:return[3,3];case aI.BRANCH_PREFIX:return[3,5];case aI.RECORD_PREFIX:return[3,7]}return[3,8];case 3:return i=aI.parseAndVerifyRoot(r,t.publicKey),[4,n._search(i,t)];case 4:return[2,l.sent()];case 5:return a=aI.parseBranch(r),i=function(e,t){var n,r={},i=!0,a=!1,o=void 0;try{for(var u,s=e.entries()[Symbol.iterator]();!(i=(u=s.next()).done);i=!0){var l=(0,se.default)(u.value,2),c=l[0],f=l[1];t.visits[f]&&(r[c]=!0)}}catch(e){a=!0,o=e}finally{try{i||null==s.return||s.return()}finally{if(a)throw o}}if(Object.keys(r).length===e.length)throw Error("Unresolvable circular path detected");do{n=Math.floor(Math.random()*e.length)}while(r[n]);return e[n]}(a,t),[4,n._search(i,t)];case 6:return[2,l.sent()];case 7:return[2,wA.fromString(r)];case 8:return[2,null];case 9:return[3,11];case 10:return u=l.sent(),[2,(sI.error("Failed to search DNS tree ".concat(o," at subdomain ").concat(e,": ").concat(u)),null)];case 11:return[3,13];case 12:return s=l.sent(),[2,(sI.error("Failed to retrieve TXT record at subdomain ".concat(e,": ").concat(s)),null)];case 13:return[2]}}))}))()}},{key:"_getTXTRecord",value:function(e,t){var n=this;return(0,K.default)((function(){var r,i,a;return(0,pe.__generator)(this,(function(o){switch(o.label){case 0:return n._DNSTreeCache[e]?[2,n._DNSTreeCache[e]]:(r=e!==t.domain?"".concat(e,".").concat(t.domain):t.domain,[4,n.dns.resolveTXT(r)]);case 1:if(!(i=o.sent()).length)throw Error("Received empty result array while fetching TXT record");if(!i[0].length)throw Error("Received empty TXT record");return a=i.join(""),[2,(n._DNSTreeCache[e]=a,a)]}}))}))()}}],[{key:"dnsOverHttp",value:function(t){return(0,K.default)((function(){return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:return t?[3,2]:[4,tI.create()];case 1:t=n.sent(),n.label=2;case 2:return[2,new e(t)]}}))}))()}}]),e}(),cI=new ja("peer-discovery-dns"),fI=Gi,dI=Symbol.toStringTag,hI=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(e,r){var i;(0,H.default)(this,n),i=t.call(this),(0,te.default)((0,q.default)(i),"nextPeer",void 0),(0,te.default)((0,q.default)(i),"_started",void 0),(0,te.default)((0,q.default)(i),"_components",void 0),(0,te.default)((0,q.default)(i),"_options",void 0),i._started=!1,i._components=e,i._options=r;var a=r.enrUrls;return cI.info("Use following EIP-1459 ENR Tree URLs: ",a),(0,ue.default)(i)}return(0,$.default)(n,[{key:"start",value:function(){var e=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return cI.info("Starting peer discovery via dns"),e._started=!0,[4,e.findPeers()];case 1:return t.sent(),[2]}}))}))()}},{key:"findPeers",value:function(){var e=this;return(0,K.default)((function(){var t,n,r,i,a,o,u,s,l,c,f,d,h,v,p,g,y;return(0,pe.__generator)(this,(function(m){switch(m.label){case 0:return e.nextPeer?[3,2]:(t=e._options,n=t.enrUrls,Array.isArray(n)||(n=[n]),[4,lI.dnsOverHttp()]);case 1:r=m.sent(),e.nextPeer=r.getNextPeer.bind(r,n),m.label=2;case 2:i=!1,a=!1,m.label=3;case 3:m.trys.push([3,15,16,21]),u=(0,j.default)(e.nextPeer()),m.label=4;case 4:return[4,u.next()];case 5:return(i=!(s=m.sent()).done)?(l=s.value,c=l,e._started?(f=c.peerInfo,d=c.shardInfo,f?(p=(0,te.default)({},T_,{value:null!==(h=e._options.tagValue)&&void 0!==h?h:50,ttl:null!==(v=e._options.tagTTL)&&void 0!==v?v:1e8}),g=!1,[4,e._components.peerStore.has(f.id)]):[3,13]):[2]):[3,14];case 6:return m.sent()?[4,e._components.peerStore.get(f.id)]:[3,10];case 7:return m.sent().tags.has(T_)?[3,9]:(g=!0,[4,e._components.peerStore.merge(f.id,{tags:p})]);case 8:m.sent(),m.label=9;case 9:return[3,12];case 10:return g=!0,[4,e._components.peerStore.save(f.id,(0,ae.default)({tags:p},d&&{metadata:{shardInfo:Vi(d)}}))];case 11:m.sent(),m.label=12;case 12:g&&e.dispatchEvent(new CustomEvent("peer",{detail:f})),m.label=13;case 13:return i=!1,[3,4];case 14:return[3,21];case 15:return y=m.sent(),a=!0,o=y,[3,21];case 16:return m.trys.push([16,,19,20]),i&&null!=u.return?[4,u.return()]:[3,18];case 17:m.sent(),m.label=18;case 18:return[3,20];case 19:if(a)throw o;return[7];case 20:return[7];case 21:return[2]}}))}))()}},{key:"stop",value:function(){this._started=!1}},{key:fI,get:function(){return!0}},{key:dI,get:function(){return"@waku/bootstrap"}}]),n}(xa),vI=to.PEER_EXCHANGE,pI="/vac/waku/peer-exchange/2.0.0-alpha1",gI=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"proto",void 0),this.proto=t}return(0,$.default)(e,[{key:"encode",value:function(){return or.encode(this.proto)}},{key:"query",get:function(){return this.proto.query}},{key:"response",get:function(){return this.proto.response}}],[{key:"createRequest",value:function(t){return new e({query:{numPeers:t.numPeers},response:void 0})}},{key:"decode",value:function(t){return new e(or.decode(t))}}]),e}(),yI=new ja("peer-exchange"),mI=function(){"use strict";function e(t){(0,H.default)(this,e),(0,te.default)(this,"components",void 0),(0,te.default)(this,"streamManager",void 0),this.components=t,this.streamManager=new Xo(pI,t)}return(0,$.default)(e,[{key:"query",value:function(e){var t=this;return(0,K.default)((function(){var n,r,i,a,o,u,s,l,c,f,d;return(0,pe.__generator)(this,(function(h){switch(h.label){case 0:return r=e.numPeers,i=e.peerId,a=gI.createRequest({numPeers:BigInt(r)}),[4,t.components.peerStore.has(i)];case 1:return h.sent()?[4,t.streamManager.getStream(i)]:[2,{peerInfos:null,error:$a.NO_PEER_AVAILABLE}];case 2:return(o=h.sent())?[4,Bo([a.encode()],_d,o,Sd,function(){var e=(0,K.default)((function(e){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return[4,oo(e)];case 1:return[2,t.sent()]}}))}));return function(t){return e.apply(this,arguments)}}())]:[2,(yI.error("Failed to get a stream for remote peer:"+(null==i||null===(n=i.toString)||void 0===n?void 0:n.call(i))),{peerInfos:null,error:$a.NO_STREAM_AVAILABLE})];case 3:u=h.sent(),h.label=4;case 4:return h.trys.push([4,6,,7]),s=new po,u.forEach((function(e){s.append(e)})),l=gI.decode(s),(c=l.response)?(f={},[4,Promise.all(c.peerInfos.map((function(e){return e.enr})).filter(Sr).map(function(){var e=(0,K.default)((function(e){var t;return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:return t={},[4,wA.fromRLP(e)];case 1:return[2,(t.ENR=n.sent(),t)]}}))}));return function(t){return e.apply(this,arguments)}}()))]):[2,(yI.error("PeerExchangeRPC message did not contains a `response` field"),{peerInfos:null,error:$a.EMPTY_PAYLOAD})];case 5:return[2,(f.peerInfos=h.sent(),f.error=null,f)];case 6:return d=h.sent(),[2,(yI.error("Failed to decode push reply",d),{peerInfos:null,error:$a.DECODE_FAILED})];case 7:return[2]}}))}))()}}]),e}(),bI=new ja("peer-exchange-discovery"),wI=Gi,kI=Symbol.toStringTag,_I=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(e){var r,i,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return(0,H.default)(this,n),r=t.call(this),(0,te.default)((0,q.default)(r),"components",void 0),(0,te.default)((0,q.default)(r),"peerExchange",void 0),(0,te.default)((0,q.default)(r),"options",void 0),(0,te.default)((0,q.default)(r),"isStarted",!1),(0,te.default)((0,q.default)(r),"queryingPeers",new Set),(0,te.default)((0,q.default)(r),"peerExpirationRecords",new Map),(0,te.default)((0,q.default)(r),"continuousDiscoveryInterval",null),r.components=e,r.peerExchange=new mI(e),r.options=(0,oe.default)((0,ae.default)({},a),{TTL:null!==(i=a.TTL)&&void 0!==i?i:3e4}),r.handleDiscoveredPeer=r.handleDiscoveredPeer.bind((0,q.default)(r)),(0,ue.default)(r)}return(0,$.default)(n,[{key:"start",value:function(){var e=this;this.isStarted||(bI.info("Starting peer exchange node discovery, discovering peers"),this.isStarted=!0,this.components.events.addEventListener("peer:identify",this.handleDiscoveredPeer),this.continuousDiscoveryInterval=setInterval((function(){e.handlePeriodicDiscovery()}),this.options.TTL))}},{key:"stop",value:function(){this.isStarted&&(bI.info("Stopping peer exchange node discovery"),this.isStarted=!1,this.queryingPeers.clear(),this.peerExpirationRecords.clear(),this.continuousDiscoveryInterval&&clearInterval(this.continuousDiscoveryInterval),this.components.events.removeEventListener("peer:identify",this.handleDiscoveredPeer))}},{key:wI,get:function(){return!0}},{key:kI,get:function(){return"@waku/peer-exchange"}},{key:"handleDiscoveredPeer",value:function(e){var t=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(n){return t.runQuery(e.detail.peerId,e.detail.protocols),[2]}))}))()}},{key:"handlePeriodicDiscovery",value:function(){var e=this;return(0,K.default)((function(){var t;return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:return t=e.components.connectionManager.getConnections(),[4,Promise.all(t.map(function(){var t=(0,K.default)((function(t){var n,r,i;return(0,pe.__generator)(this,(function(a){switch(a.label){case 0:return a.trys.push([0,2,,3]),n=t.remotePeer.toString(),!e.peerExpirationRecords.has(n)||e.peerExpirationRecords.get(n)<=Date.now()?[4,e.components.peerStore.get(t.remotePeer)]:[2,null];case 1:return r=a.sent(),[2,e.runQuery(t.remotePeer,r.protocols)];case 2:return i=a.sent(),[2,(bI.warn("Error getting peer info",i),null)];case 3:return[2]}}))}));return function(e){return t.apply(this,arguments)}}()))];case 1:return n.sent(),[2]}}))}))()}},{key:"runQuery",value:function(e,t){var n=this;return(0,K.default)((function(){var r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:if(!t.includes(pI)||n.queryingPeers.has(e.toString()))return[3,5];i.label=1;case 1:return i.trys.push([1,3,,4]),n.queryingPeers.add(e.toString()),[4,n.query(e)];case 2:return i.sent(),[3,4];case 3:return r=i.sent(),bI.error("Error querying peer",r),[3,4];case 4:return n.peerExpirationRecords.set(e.toString(),Date.now()+n.options.TTL),n.queryingPeers.delete(e.toString()),[3,6];case 5:bI.info("Skipping peer ".concat(e," as it is already querying or does not support peer exchange")),i.label=6;case 6:return[2]}}))}))()}},{key:"query",value:function(e){var t=this;return(0,K.default)((function(){var n,r,i,a,o,u,s,l,c,f,d,h,v,p,g;return(0,pe.__generator)(this,(function(y){switch(y.label){case 0:return n=e.toString(),bI.info("Querying peer exchange for "+n),[4,t.peerExchange.query({numPeers:60,peerId:e})];case 1:return r=y.sent(),i=r.error,a=r.peerInfos,o=!0,u=!1,s=void 0,i?(bI.error("Peer exchange query to ".concat(n," failed"),i),[3,10]):[3,2];case 2:y.trys.push([2,8,9,10]),l=a[Symbol.iterator](),y.label=3;case 3:return(o=(c=l.next()).done)?[3,7]:(f=c.value,(d=f.ENR)?(h=d.peerInfo,v=d.shardInfo,h?[4,t.hasShardInfo(h.id)]:(bI.warn("No peerInfo in ENR from ".concat(n,", skipping")),[3,6])):(bI.warn("No ENR in peerInfo object from ".concat(n,", skipping")),[3,6]));case 4:return p=!y.sent()&&v?{metadata:{shardInfo:Vi(v)}}:void 0,[4,t.components.peerStore.merge(h.id,(0,ae.default)({tags:(0,te.default)({},vI,{value:50})},p,h.multiaddrs&&{multiaddrs:h.multiaddrs}))];case 5:y.sent(),bI.info("Discovered peer: "+h.id.toString()),t.dispatchEvent(new CustomEvent("peer",{detail:{id:h.id,multiaddrs:h.multiaddrs}})),y.label=6;case 6:return o=!0,[3,3];case 7:return[3,10];case 8:return g=y.sent(),u=!0,s=g,[3,10];case 9:try{o||null==l.return||l.return()}finally{if(u)throw s}return[7];case 10:return[2]}}))}))()}},{key:"hasShardInfo",value:function(e){var t=this;return(0,K.default)((function(){var n,r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,t.components.peerStore.get(e)];case 1:return[2,!!(n=i.sent())&&n.metadata.has("shardInfo")];case 2:return r=i.sent(),bI.warn("Error getting shard info for "+e.toString(),r),[3,3];case 3:return[2,!1]}}))}))()}}]),n}(xa),EI=to.PEER_CACHE,SI=function(e){return!!e&&"object"==typeof e&&"id"in e&&"string"==typeof e.id&&"multiaddrs"in e&&Array.isArray(e.multiaddrs)},AI=function(){"use strict";function e(){(0,H.default)(this,e)}return(0,$.default)(e,[{key:"get",value:function(){return[]}},{key:"set",value:function(e){}},{key:"remove",value:function(){}}]),e}(),II=function(){"use strict";function e(){(0,H.default)(this,e)}return(0,$.default)(e,[{key:"get",value:function(){try{var e=localStorage.getItem("waku:peers");return(e?JSON.parse(e):[]).filter(SI)}catch(e){return[]}}},{key:"set",value:function(e){try{localStorage.setItem("waku:peers",JSON.stringify(e))}catch(e){}}},{key:"remove",value:function(){try{localStorage.removeItem("waku:peers")}catch(e){}}}]),e}(),xI=new ja("peer-cache"),CI=Symbol.toStringTag,TI=function(e){"use strict";(0,ie.default)(n,e);var t=(0,ve.default)(n);function n(e,r){var i,a;return(0,H.default)(this,n),i=t.call(this),(0,te.default)((0,q.default)(i),"components",void 0),(0,te.default)((0,q.default)(i),"isStarted",!1),(0,te.default)((0,q.default)(i),"cache",void 0),(0,te.default)((0,q.default)(i),"handleDiscoveredPeer",(function(e){var t=e.detail,n=t.peerId,r=t.listenAddrs.map((function(e){return e.toString()})),a=n.toString(),o=i.readPeerInfoFromCache(),u=o.findIndex((function(e){return e.id===a}));-1!==u?o[u].multiaddrs=r:o.push({id:a,multiaddrs:r}),i.writePeerInfoToCache(o)})),i.components=e,i.cache=null!==(a=null==r?void 0:r.cache)&&void 0!==a?a:function(){try{if("undefined"!=typeof localStorage)return new II}catch(e){}return new AI}(),(0,ue.default)(i)}return(0,$.default)(n,[{key:CI,get:function(){return"@waku/"+EI}},{key:"start",value:function(){var e=this;return(0,K.default)((function(){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return e.isStarted?[3,2]:(xI.info("Starting Peer Cache Discovery"),e.components.events.addEventListener("peer:identify",e.handleDiscoveredPeer),[4,e.discoverPeers()]);case 1:t.sent(),e.isStarted=!0,t.label=2;case 2:return[2]}}))}))()}},{key:"stop",value:function(){this.isStarted&&(xI.info("Stopping Peer Cache Discovery"),this.components.events.removeEventListener("peer:identify",this.handleDiscoveredPeer),this.isStarted=!1)}},{key:"discoverPeers",value:function(){var e=this;return(0,K.default)((function(){var t,n,r,i,a,o,u,s,l,c;return(0,pe.__generator)(this,(function(f){switch(f.label){case 0:t=e.readPeerInfoFromCache(),n=!0,r=!1,i=void 0,f.label=1;case 1:f.trys.push([1,8,9,10]),a=t[Symbol.iterator](),f.label=2;case 2:return(n=(o=a.next()).done)?[3,7]:(u=o.value,s=kc(u.id),l=u.multiaddrs.map((function(e){return pf(e)})),[4,e.components.peerStore.has(s)]);case 3:return f.sent()?[3,5]:[4,e.components.peerStore.save(s,{multiaddrs:l,tags:(0,te.default)({},EI,{value:50})})];case 4:f.sent(),e.dispatchEvent(new CustomEvent("peer",{detail:{id:s,multiaddrs:l}})),f.label=5;case 5:f.label=6;case 6:return n=!0,[3,2];case 7:return[3,10];case 8:return c=f.sent(),r=!0,i=c,[3,10];case 9:try{n||null==a.return||a.return()}finally{if(r)throw i}return[7];case 10:return[2]}}))}))()}},{key:"readPeerInfoFromCache",value:function(){try{return this.cache.get()}catch(e){return xI.error("Error parsing peers from cache:",e),[]}}},{key:"writePeerInfoToCache",value:function(e){try{this.cache.set(e)}catch(e){xI.error("Error saving peers to cache:",e)}}}]),n}(xa);function PI(e,t){var n,r=[x_,C_],i=[];return(null==e?void 0:e.dns)&&i.push((n=r,function(e){return new hI(e,{enrUrls:n})})),((null==e?void 0:e.peerCache)||t)&&i.push(function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(t){return new TI(t,e)}}({cache:t})),(null==e?void 0:e.peerExchange)&&i.push(function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(t){return new _I(t,e)}}()),i}var RI=new ja("sdk:create");function LI(e,t,n){return DI.apply(this,arguments)}function DI(){return DI=(0,K.default)((function(e,t,n){var r;return(0,pe.__generator)(this,(function(i){return!(null==t?void 0:t.hideWebSocketInfo)&&I_(),[2,(0,K.default)((function(){var e,t,n,r,i,a,o=arguments;return(0,pe.__generator)(this,(function(u){switch(u.label){case 0:return null===(t=(f=e=o.length>0&&void 0!==o[0]?o[0]:{}).privateKey)||void 0===t?[3,1]:(t,[3,3]);case 1:return[4,lc()];case 2:f.privateKey=u.sent(),u.label=3;case 3:return r=S_.bind,i=[{}],[4,mm(e)];case 4:return n=new(r.apply(S_,[void 0,oe.default.apply(void 0,[ae.default.apply(void 0,i.concat([u.sent()])),{peerId:(a=e.privateKey,_c(a.publicKey))}])])),!1!==e.start?[4,n.start()]:[3,6];case 5:u.sent(),u.label=6;case 6:return[2,n]}}))}))((0,oe.default)((0,ae.default)({transports:[Gg({filter:!1===(null==t?void 0:t.filterMultiaddrs)||I_()?zg:jg})],streamMuxers:[yg()],connectionEncrypters:[qh()]},t),{services:(0,ae.default)({identify:jp({agentVersion:null!=n?n:"js-waku"}),ping:kg({maxInboundStreams:null!==(r=null==t?void 0:t.pingMaxInboundStreams)&&void 0!==r?r:10}),metadata:Nf(e)},null==t?void 0:t.services)}))]}))})),DI.apply(this,arguments)}function MI(e){return NI.apply(this,arguments)}function NI(){return NI=(0,K.default)((function(e){var t,n,r,i,a,o,u,s,l,c,f,d;return(0,pe.__generator)(this,(function(h){return o=null!==(a=(null!==(i=e.networkConfig)&&void 0!==i?i:ao).clusterId)&&void 0!==a?a:1,RI.info("Creating Waku node with cluster id: ",o),l=null!==(u=null==e?void 0:e.libp2p)&&void 0!==u?u:{},c=null!==(s=l.peerDiscovery)&&void 0!==s?s:[],(null==e?void 0:e.defaultBootstrap)?(t=c).push.apply(t,(0,ce.default)(PI((0,ae.default)({dns:!0,peerExchange:!0,peerCache:!0},e.discovery),e.peerCache))):(n=c).push.apply(n,(0,ce.default)(PI(e.discovery,e.peerCache))),[2,((f=(0,ce.default)(e.bootstrapPeers||[]).concat((0,ce.default)((null===(r=e.store)||void 0===r?void 0:r.peers)||[]))).length&&c.push((d={list:f},function(e){return new Ev(e,d)})),l.peerDiscovery=c,LI(o,l,null==e?void 0:e.userAgent))]}))})),NI.apply(this,arguments)}var OI=0,UI={size:0,kind:17,base:null,node:null,finalizer:null},FI={size:0,kind:17,base:null,node:null,finalizer:null},BI={size:0,kind:17,base:null,node:null,finalizer:null},qI={size:0,kind:17,base:null,node:null,finalizer:null},zI={size:0,kind:17,base:null,node:null,finalizer:null},jI={size:0,kind:22,base:null,node:null,finalizer:null},KI={size:0,kind:28,base:null,node:null,finalizer:null},VI={size:0,kind:22,base:null,node:null,finalizer:null},HI={size:0,kind:17,base:null,node:null,finalizer:null},WI={size:0,kind:17,base:null,node:null,finalizer:null},GI={size:0,kind:17,base:null,node:null,finalizer:null},XI={size:0,kind:17,base:null,node:(null,{kind:2,len:0,offset:0,typ:null,name:null,sons:[]}),finalizer:null};GI.node={kind:2,len:0,offset:0,typ:null,name:null,sons:[]},WI.node={kind:2,len:0,offset:0,typ:null,name:null,sons:[]},VI.base=HI,jI.base=HI;var YI={kind:2,len:5,offset:0,typ:null,name:null,sons:[{kind:1,offset:"parent",len:0,typ:VI,name:"parent",sons:null},{kind:1,offset:"name",len:0,typ:{size:0,kind:29,base:null,node:null,finalizer:null},name:"name",sons:null},{kind:1,offset:"message",len:0,typ:KI,name:"msg",sons:null},{kind:1,offset:"trace",len:0,typ:KI,name:"trace",sons:null},{kind:1,offset:"up",len:0,typ:jI,name:"up",sons:null}]};function ZI(e,t){throw e.name=t,0==OI&&function(e){var t=[[]];0!=e.message.length?(t[0].push.call(t[0],69,114,114,111,114,58,32,117,110,104,97,110,100,108,101,100,32,101,120,99,101,112,116,105,111,110,58,32),t[0].push.apply(t[0],e.message)):t[0].push.call(t[0],69,114,114,111,114,58,32,117,110,104,97,110,100,108,101,100,32,101,120,99,101,112,116,105,111,110),t[0].push.call(t[0],32,91),function(e,t,n){null===e[0]&&(e[0]=[]);var r=e[0].length;e[0].length+=n.length;for(var i=0;i<n.length;++i)e[0][r+i]=n.charCodeAt(i)}(t,0,e.name),t[0].push.call(t[0],93,10);var n=function(e){for(var t=cx(e.length),n=0,r=0;n<e.length;){var i=e[n];if(i<128)t[r]=String.fromCharCode(i),n+=1;else{var a=cx(0);e:for(;;){var o=i.toString(16);if(1==(null==o?0:o.length)?a.push("%0"):a.push("%"),a.push(o),n+=1,e.length<=n||e[n]<128)break e;i=e[n]}++OI;try{t[r]=decodeURIComponent(a.join("")),--OI}catch(e){--OI,t[r]=a.join("")}}r+=1}if(t.length<r)for(var u=t.length;u<r;++u)t.push(null);else t.length=r;return t.join("")}(t[0]);throw void 0!==Error?Error(n):n}(e),e}function QI(e,t){return 0==t&&fx(),-1==t&&2147483647==e&&dx(),Math.trunc(e%t)}function JI(e){return e<0?-1*e:e}function $I(e,t){var n=e*t;return hx(n),n}function ex(e,t){var n=e-t;return hx(n),n}function tx(e,t){var n=e+t;return hx(n),n}HI.node=YI,zI.node={kind:2,len:0,offset:0,typ:null,name:null,sons:[]},HI.base=zI,WI.base=HI,GI.base=WI,XI.base=GI,qI.node={kind:2,len:0,offset:0,typ:null,name:null,sons:[]},qI.base=GI,BI.node={kind:2,len:0,offset:0,typ:null,name:null,sons:[]},BI.base=WI,FI.node={kind:2,len:0,offset:0,typ:null,name:null,sons:[]},FI.base=WI,UI.node={kind:2,len:0,offset:0,typ:null,name:null,sons:[]},UI.base=WI;var nx,rx,ix,ax,ox,ux=function(){for(var e={},t=0;t<arguments.length;++t){var n=arguments[t];if("object"==typeof n)for(var r=n[0];r<=n[1];++r)e[r]=!0;else e[n]=!0}return e}(17,16,4,18,27,19,23,22,21);function sx(e,t,n){var r=null;switch(n.kind){case 21:case 22:case 23:case 5:r=function(e){return!(null!=ux[e.base.kind])}(n)?[t[0],t[1]]:t;break;case 19:if(null==e)e={};else for(var i in e)delete e[i];for(var i in t)e[i]=t[i];r=e;break;case 18:case 17:gx(r=null!=n.base?sx(e,t,n.base):17==n.kind?null==e?{m_type:n}:e:null==e?{}:e,t,n.node);break;case 4:case 16:if(ArrayBuffer.isView(t))null==e||e.length!=t.length?e=new t.constructor(t):e.set(t,0),r=e;else if(null===t)r=null;else{null!=e&&e.length==t.length||(e=Array(t.length)),r=e;for(var a=0;a<t.length;++a)r[a]=sx(r[a],t[a],n.base)}break;case 24:case 27:if(null===t)r=null;else for(null!=e&&e.length==t.length||(e=Array(t.length)),r=e,a=0;a<t.length;++a)r[a]=sx(r[a],t[a],n.base);break;case 28:null!==t&&(r=t.slice(0));break;default:r=t}return r}function lx(e,t,n){var r=0;return t<=e&&e<=n?r=e:function(e,t,n){ZI({message:sx(null,n<t?[105,110,100,101,120,32,111,117,116,32,111,102,32,98,111,117,110,100,115,44,32,116,104,101,32,99,111,110,116,97,105,110,101,114,32,105,115,32,101,109,112,116,121]:[105,110,100,101,120,32].concat(px(e),[32,110,111,116,32,105,110,32],px(t),[32,46,46,32],px(n)),KI),parent:null,m_type:FI,name:null,trace:[],up:null},"IndexDefect")}(e,t,n),r}function cx(e){var t=[];t=Array(e);for(var n=0;n<e;++n)t[n]=null;return t}function fx(){ZI({message:[100,105,118,105,115,105,111,110,32,98,121,32,122,101,114,111],parent:null,m_type:XI,name:null,trace:[],up:null},"DivByZeroDefect")}function dx(){ZI({message:[111,118,101,114,45,32,111,114,32,117,110,100,101,114,102,108,111,119],parent:null,m_type:qI,name:null,trace:[],up:null},"OverflowDefect")}function hx(e){(e>2147483647||e<-2147483648)&&dx()}function vx(e,t,n){!function(e,t,n,r,i){var a,o=e[t].length;if(e[t].length<(a=function(e,t,n){var r=0;return t<=e&&e<=n?r=e:ZI({message:[118,97,108,117,101,32,111,117,116,32,111,102,32,114,97,110,103,101],parent:null,m_type:BI,name:null,trace:[],up:null},"RangeDefect"),r}(tx(o,i),0,2147483647)))for(var u=e[t].length;u<a;++u)e[t].push(0);else e[t].length=a;for(var s=0,l=0;l<i;)s=l,e[t][lx(tx(o,s),0,e[t].length-1)]=n.charCodeAt(lx(tx(0,s),0,n.length-1)),l=tx(l,1)}(e,t,n,0,null==n?0:n.length)}function px(e){var t=[[]];return function(e,t,n){!function(e,t,n){vx(e,t,n+"")}(e,t,n)}(t,0,e),t[0]}function gx(e,t,n){switch(n.kind){case 0:break;case 1:e[n.offset]=sx(e[n.offset],t[n.offset],n.typ);break;case 2:for(var r=0;r<n.sons.length;r++)gx(e,t,n.sons[r]);break;case 3:for(e[n.offset]=sx(e[n.offset],t[n.offset],n.typ),r=0;r<n.sons.length;++r)gx(e,t,n.sons[r][1])}}function yx(e,t){var n=65535,r=(e&n)>>>0,i=(t&n)>>>0;return(r*i>>>0)+((((e>>>16&n)>>>0)*i>>>0)+(r*((t>>>16&n)>>>0)>>>0)>>>0<<16>>>0)>>>0}function mx(e,t){return(e<<t>>>0|e>>>ex(32,t))>>>0}function bx(e){return function(e){for(var t=e.length,n=(u=t,Math.trunc(u/4)),r=0,i=0;i<$I(n,4);){for(var a=0,o=4;0<o;)o=ex(o,1),a=(a<<8>>>0|Number(BigInt.asUintN(32,BigInt(e[lx(tx(i,o),0,e.length-1)]))))>>>0;i=tx(i,4),a=mx(a=yx(a,3432918353),15),r=3864292196+(5*(r=mx(r=(r^(a=yx(a,461845907)))>>>0,13))>>>0)>>>0}for(var u,s=0,l=QI(t,4);0<l;)l=ex(l,1),s=(s<<8>>>0|Number(BigInt.asUintN(32,BigInt(e[lx(tx(i,l),0,e.length-1)]))))>>>0;return s=yx(s,3432918353),s=yx(s=mx(s,15),461845907),r=yx(r=((r=((r=(r^s)>>>0)^Number(BigInt.asUintN(32,BigInt(t))))>>>0)^r>>>16)>>>0,2246822507),r=((r=yx(r=(r^r>>>13)>>>0,3266489909))^r>>>16)>>>0,Number(BigInt.asIntN(32,BigInt(r)))}(e.slice(0,e.length-1+1))}0!=(0,1,rx=QI(JI(bx(nx=[100,117,109,109,121])),1),ix=QI(JI(bx(nx.concat([32,98]))),1),QI(JI(tx(rx,$I(0,ix))),1))&&function(e){ZI({message:sx(null,e,KI),m_type:UI,parent:null,name:null,trace:[],up:null},"AssertionDefect")}([110,105,109,95,104,97,115,104,46,110,105,109,40,50,54,44,32,51,41,32,96,104,97,115,104,78,40,34,100,117,109,109,121,34,44,32,48,44,32,49,41,32,61,61,32,48,96,32]),function(e){e.Send="send",e.Receive="receive",e.SendEphemeral="sendEphemeral"}(ax||(ax={})),function(e){e.OutMessageSent="sds:out:message-sent",e.InMessageDelivered="sds:in:message-delivered",e.InMessageReceived="sds:in:message-received",e.OutMessageAcknowledged="sds:out:message-acknowledged",e.OutMessagePossiblyAcknowledged="sds:out:message-possibly-acknowledged",e.InMessageMissing="sds:in:message-missing",e.OutSyncSent="sds:out:sync-sent",e.InSyncReceived="sds:in:sync-received",e.InMessageLost="sds:in:message-irretrievably-lost",e.ErrorTask="sds:error-task"}(ox||(ox={}));var wx,kx,_x={exports:{}};wx||(wx=1,function(e,t){!function(){var n,r=function(e,t,n){switch(n.length){case 0:return e.call(t);case 1:return e.call(t,n[0]);case 2:return e.call(t,n[0],n[1]);case 3:return e.call(t,n[0],n[1],n[2])}return e.apply(t,n)},i=function(e,t,n,r){for(var i=-1,a=null==e?0:e.length;++i<a;){var o=e[i];t(r,o,n(o),e)}return r},a=function(e,t){for(var n=-1,r=null==e?0:e.length;++n<r&&!1!==t(e[n],n,e););return e},o=function(e,t){for(var n=null==e?0:e.length;n--&&!1!==t(e[n],n,e););return e},u=function(e,t){for(var n=-1,r=null==e?0:e.length;++n<r;)if(!t(e[n],n,e))return!1;return!0},s=function(e,t){for(var n=-1,r=null==e?0:e.length,i=0,a=[];++n<r;){var o=e[n];t(o,n,e)&&(a[i++]=o)}return a},l=function(e,t){return!(null==e||!e.length)&&m(e,t,0)>-1},c=function(e,t,n){for(var r=-1,i=null==e?0:e.length;++r<i;)if(n(t,e[r]))return!0;return!1},f=function(e,t){for(var n=-1,r=null==e?0:e.length,i=Array(r);++n<r;)i[n]=t(e[n],n,e);return i},d=function(e,t){for(var n=-1,r=t.length,i=e.length;++n<r;)e[i+n]=t[n];return e},h=function(e,t,n,r){var i=-1,a=null==e?0:e.length;for(r&&a&&(n=e[++i]);++i<a;)n=t(n,e[i],i,e);return n},v=function(e,t,n,r){var i=null==e?0:e.length;for(r&&i&&(n=e[--i]);i--;)n=t(n,e[i],i,e);return n},p=function(e,t){for(var n=-1,r=null==e?0:e.length;++n<r;)if(t(e[n],n,e))return!0;return!1},g=function(e,t,n){var r;return n(e,(function(e,n,i){if(t(e,n,i))return r=n,!1})),r},y=function(e,t,n,r){for(var i=e.length,a=n+(r?1:-1);r?a--:++a<i;)if(t(e[a],a,e))return a;return-1},m=function(e,t,n){return t==t?function(e,t,n){for(var r=n-1,i=e.length;++r<i;)if(e[r]===t)return r;return-1}(e,t,n):y(e,w,n)},b=function(e,t,n,r){for(var i=n-1,a=e.length;++i<a;)if(r(e[i],t))return i;return-1},w=function(e){return e!=e},k=function(e,t){var n=null==e?0:e.length;return n?A(e,t)/n:Y},_=function(e){return function(t){return null==t?n:t[e]}},E=function(e){return function(t){return null==e?n:e[t]}},S=function(e,t,n,r,i){return i(e,(function(e,i,a){n=r?(r=!1,e):t(n,e,i,a)})),n},A=function(e,t){for(var r,i=-1,a=e.length;++i<a;){var o=t(e[i]);o!==n&&(r=r===n?o:r+o)}return r},I=function(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r},x=function(e){return e?e.slice(0,z(e)+1).replace(ze,""):e},C=function(e){return function(t){return e(t)}},T=function(e,t){return f(t,(function(t){return e[t]}))},P=function(e,t){return e.has(t)},R=function(e,t){for(var n=-1,r=e.length;++n<r&&m(t,e[n],0)>-1;);return n},L=function(e,t){for(var n=e.length;n--&&m(t,e[n],0)>-1;);return n},D=function(e){return"\\"+Vt[e]},M=function(e){return Ft.test(e)},N=function(e){var t=-1,n=Array(e.size);return e.forEach((function(e,r){n[++t]=[r,e]})),n},O=function(e,t){return function(n){return e(t(n))}},U=function(e,t){for(var n=-1,r=e.length,i=0,a=[];++n<r;){var o=e[n];o!==t&&o!==V||(e[n]=V,a[i++]=n)}return a},F=function(e){var t=-1,n=Array(e.size);return e.forEach((function(e){n[++t]=e})),n},B=function(e){return M(e)?function(e){for(var t=Ot.lastIndex=0;Ot.test(e);)++t;return t}(e):sn(e)},q=function(e){return M(e)?function(e){return e.match(Ot)||[]}(e):function(e){return e.split("")}(e)},z=function(e){for(var t=e.length;t--&&je.test(e.charAt(t)););return t},j="Expected a function",K="__lodash_hash_undefined__",V="__lodash_placeholder__",H=32,W=128,G=1/0,X=9007199254740991,Y=NaN,Z=4294967295,Q=[["ary",W],["bind",1],["bindKey",2],["curry",8],["curryRight",16],["flip",512],["partial",H],["partialRight",64],["rearg",256]],J="[object Arguments]",$="[object Array]",ee="[object Boolean]",te="[object Date]",ne="[object Error]",re="[object Function]",ie="[object GeneratorFunction]",ae="[object Map]",oe="[object Number]",ue="[object Object]",se="[object Promise]",le="[object RegExp]",ce="[object Set]",de="[object String]",he="[object Symbol]",ve="[object WeakMap]",pe="[object ArrayBuffer]",ge="[object DataView]",ye="[object Float32Array]",me="[object Float64Array]",be="[object Int8Array]",we="[object Int16Array]",ke="[object Int32Array]",_e="[object Uint8Array]",Ee="[object Uint8ClampedArray]",Se="[object Uint16Array]",Ae="[object Uint32Array]",Ie=/\b__p \+= '';/g,xe=/\b(__p \+=) '' \+/g,Ce=/(__e\(.*?\)|\b__t\)) \+\n'';/g,Te=/&(?:amp|lt|gt|quot|#39);/g,Pe=/[&<>"']/g,Re=RegExp(Te.source),Le=RegExp(Pe.source),De=/<%-([\s\S]+?)%>/g,Me=/<%([\s\S]+?)%>/g,Ne=/<%=([\s\S]+?)%>/g,Oe=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Ue=/^\w*$/,Fe=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Be=/[\\^$.*+?()[\]{}|]/g,qe=RegExp(Be.source),ze=/^\s+/,je=/\s/,Ke=/\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,Ve=/\{\n\/\* \[wrapped with (.+)\] \*/,He=/,? & /,We=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g,Ge=/[()=,{}\[\]\/\s]/,Xe=/\\(\\)?/g,Ye=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,Ze=/\w*$/,Qe=/^[-+]0x[0-9a-f]+$/i,Je=/^0b[01]+$/i,$e=/^\[object .+?Constructor\]$/,et=/^0o[0-7]+$/i,tt=/^(?:0|[1-9]\d*)$/,nt=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,rt=/($^)/,it=/['\n\r\u2028\u2029\\]/g,at="\ud800-\udfff",ot="\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff",ut="\\u2700-\\u27bf",st="a-z\\xdf-\\xf6\\xf8-\\xff",lt="A-Z\\xc0-\\xd6\\xd8-\\xde",ct="\\ufe0e\\ufe0f",ft="\\xac\\xb1\\xd7\\xf7\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf\\u2000-\\u206f \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000",dt="[\ud800-\udfff]",ht="["+ft+"]",vt="["+ot+"]",pt="\\d+",gt="["+ut+"]",yt="["+st+"]",mt="[^"+at+ft+pt+ut+st+lt+"]",bt="\ud83c[\udffb-\udfff]",wt="[^\ud800-\udfff]",kt="(?:\ud83c[\udde6-\uddff]){2}",_t="[\ud800-\udbff][\udc00-\udfff]",Et="["+lt+"]",St="\\u200d",At="(?:"+yt+"|"+mt+")",It="(?:"+Et+"|"+mt+")",xt="(?:['โ€™](?:d|ll|m|re|s|t|ve))?",Ct="(?:['โ€™](?:D|LL|M|RE|S|T|VE))?",Tt="(?:"+vt+"|"+bt+")?",Pt="["+ct+"]?",Rt=Pt+Tt+"(?:"+St+"(?:"+[wt,kt,_t].join("|")+")"+Pt+Tt+")*",Lt="(?:"+[gt,kt,_t].join("|")+")"+Rt,Dt="(?:"+[wt+vt+"?",vt,kt,_t,dt].join("|")+")",Mt=RegExp("['โ€™]","g"),Nt=RegExp(vt,"g"),Ot=RegExp(bt+"(?="+bt+")|"+Dt+Rt,"g"),Ut=RegExp([Et+"?"+yt+"+"+xt+"(?="+[ht,Et,"$"].join("|")+")",It+"+"+Ct+"(?="+[ht,Et+At,"$"].join("|")+")",Et+"?"+At+"+"+xt,Et+"+"+Ct,"\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])|\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",pt,Lt].join("|"),"g"),Ft=RegExp("["+St+at+ot+ct+"]"),Bt=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/,qt=["Array","Buffer","DataView","Date","Error","Float32Array","Float64Array","Function","Int8Array","Int16Array","Int32Array","Map","Math","Object","Promise","RegExp","Set","String","Symbol","TypeError","Uint8Array","Uint8ClampedArray","Uint16Array","Uint32Array","WeakMap","_","clearTimeout","isFinite","parseInt","setTimeout"],zt=-1,jt={};jt[ye]=jt[me]=jt[be]=jt[we]=jt[ke]=jt[_e]=jt[Ee]=jt[Se]=jt[Ae]=!0,jt[J]=jt[$]=jt[pe]=jt[ee]=jt[ge]=jt[te]=jt[ne]=jt[re]=jt[ae]=jt[oe]=jt[ue]=jt[le]=jt[ce]=jt[de]=jt[ve]=!1;var Kt={};Kt[J]=Kt[$]=Kt[pe]=Kt[ge]=Kt[ee]=Kt[te]=Kt[ye]=Kt[me]=Kt[be]=Kt[we]=Kt[ke]=Kt[ae]=Kt[oe]=Kt[ue]=Kt[le]=Kt[ce]=Kt[de]=Kt[he]=Kt[_e]=Kt[Ee]=Kt[Se]=Kt[Ae]=!0,Kt[ne]=Kt[re]=Kt[ve]=!1;var Vt={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"},Ht=parseFloat,Wt=parseInt,Gt="object"==typeof Ra&&Ra&&Ra.Object===Object&&Ra,Xt="object"==typeof self&&self&&self.Object===Object&&self,Yt=Gt||Xt||Function("return this")(),Zt=t&&!t.nodeType&&t,Qt=Zt&&e&&!e.nodeType&&e,Jt=Qt&&Qt.exports===Zt,$t=Jt&&Gt.process,en=function(){try{return Qt&&Qt.require&&Qt.require("util").types||$t&&$t.binding&&$t.binding("util")}catch(e){}}(),tn=en&&en.isArrayBuffer,nn=en&&en.isDate,rn=en&&en.isMap,an=en&&en.isRegExp,on=en&&en.isSet,un=en&&en.isTypedArray,sn=_("length"),ln=E({"ร€":"A","ร":"A","ร‚":"A","รƒ":"A","ร„":"A","ร…":"A","ร ":"a","รก":"a","รข":"a","รฃ":"a","รค":"a","รฅ":"a","ร‡":"C","รง":"c","ร":"D","รฐ":"d","รˆ":"E","ร‰":"E","รŠ":"E","ร‹":"E","รจ":"e","รฉ":"e","รช":"e","รซ":"e","รŒ":"I","ร":"I","รŽ":"I","ร":"I","รฌ":"i","รญ":"i","รฎ":"i","รฏ":"i","ร‘":"N","รฑ":"n","ร’":"O","ร“":"O","ร”":"O","ร•":"O","ร–":"O","ร˜":"O","รฒ":"o","รณ":"o","รด":"o","รต":"o","รถ":"o","รธ":"o","ร™":"U","รš":"U","ร›":"U","รœ":"U","รน":"u","รบ":"u","รป":"u","รผ":"u","ร":"Y","รฝ":"y","รฟ":"y","ร†":"Ae","รฆ":"ae","รž":"Th","รพ":"th","รŸ":"ss","ฤ€":"A","ฤ‚":"A","ฤ„":"A","ฤ":"a","ฤƒ":"a","ฤ…":"a","ฤ†":"C","ฤˆ":"C","ฤŠ":"C","ฤŒ":"C","ฤ‡":"c","ฤ‰":"c","ฤ‹":"c","ฤ":"c","ฤŽ":"D","ฤ":"D","ฤ":"d","ฤ‘":"d","ฤ’":"E","ฤ”":"E","ฤ–":"E","ฤ˜":"E","ฤš":"E","ฤ“":"e","ฤ•":"e","ฤ—":"e","ฤ™":"e","ฤ›":"e","ฤœ":"G","ฤž":"G","ฤ ":"G","ฤข":"G","ฤ":"g","ฤŸ":"g","ฤก":"g","ฤฃ":"g","ฤค":"H","ฤฆ":"H","ฤฅ":"h","ฤง":"h","ฤจ":"I","ฤช":"I","ฤฌ":"I","ฤฎ":"I","ฤฐ":"I","ฤฉ":"i","ฤซ":"i","ฤญ":"i","ฤฏ":"i","ฤฑ":"i","ฤด":"J","ฤต":"j","ฤถ":"K","ฤท":"k","ฤธ":"k","ฤน":"L","ฤป":"L","ฤฝ":"L","ฤฟ":"L","ล":"L","ฤบ":"l","ฤผ":"l","ฤพ":"l","ล€":"l","ล‚":"l","ลƒ":"N","ล…":"N","ล‡":"N","ลŠ":"N","ล„":"n","ล†":"n","ลˆ":"n","ล‹":"n","ลŒ":"O","ลŽ":"O","ล":"O","ล":"o","ล":"o","ล‘":"o","ล”":"R","ล–":"R","ล˜":"R","ล•":"r","ล—":"r","ล™":"r","ลš":"S","ลœ":"S","ลž":"S","ล ":"S","ล›":"s","ล":"s","ลŸ":"s","ลก":"s","ลข":"T","ลค":"T","ลฆ":"T","ลฃ":"t","ลฅ":"t","ลง":"t","ลจ":"U","ลช":"U","ลฌ":"U","ลฎ":"U","ลฐ":"U","ลฒ":"U","ลฉ":"u","ลซ":"u","ลญ":"u","ลฏ":"u","ลฑ":"u","ลณ":"u","ลด":"W","ลต":"w","ลถ":"Y","ลท":"y","ลธ":"Y","ลน":"Z","ลป":"Z","ลฝ":"Z","ลบ":"z","ลผ":"z","ลพ":"z","ฤฒ":"IJ","ฤณ":"ij","ล’":"Oe","ล“":"oe","ล‰":"'n","ลฟ":"s"}),cn=E({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"}),fn=E({"&amp;":"&","&lt;":"<","&gt;":">","&quot;":'"',"&#39;":"'"}),dn=function e(t){var E,je=function(e){if(Ai(e)&&!Eu(e)&&!(e instanceof ut)){if(e instanceof ot)return e;if(va.call(e,"__wrapped__"))return Jr(e)}return new ot(e)},at=function(){},ot=function(e,t){this.__wrapped__=e,this.__actions__=[],this.__chain__=!!t,this.__index__=0,this.__values__=n},ut=function(e){this.__wrapped__=e,this.__actions__=[],this.__dir__=1,this.__filtered__=!1,this.__iteratees__=[],this.__takeCount__=Z,this.__views__=[]},st=function(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}},lt=function(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}},ct=function(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}},ft=function(e){var t=-1,n=null==e?0:e.length;for(this.__data__=new ct;++t<n;)this.add(e[t])},dt=function(e){var t=this.__data__=new lt(e);this.size=t.size},ht=function(e,t){var n=Eu(e),r=!n&&_u(e),i=!n&&!r&&Au(e),a=!n&&!r&&!i&&Pu(e),o=n||r||i||a,u=o?I(e.length,ua):[],s=u.length;for(var l in e)!t&&!va.call(e,l)||o&&("length"==l||i&&("offset"==l||"parent"==l)||a&&("buffer"==l||"byteLength"==l||"byteOffset"==l)||Ur(l,s))||u.push(l);return u},vt=function(e){var t=e.length;return t?e[An(0,t-1)]:n},pt=function(e,t){return Yr(tr(e),St(t,0,e.length))},gt=function(e){return Yr(tr(e))},yt=function(e,t,r){(r!==n&&!yi(e[t],r)||r===n&&!(t in e))&&_t(e,t,r)},mt=function(e,t,r){var i=e[t];va.call(e,t)&&yi(i,r)&&(r!==n||t in e)||_t(e,t,r)},bt=function(e,t){for(var n=e.length;n--;)if(yi(e[n][0],t))return n;return-1},wt=function(e,t,n,r){return vo(e,(function(e,i,a){t(r,e,n(e),a)})),r},kt=function(e,t){return e&&nr(t,Bi(t),e)},_t=function(e,t,n){"__proto__"==t&&La?La(e,t,{configurable:!0,enumerable:!0,value:n,writable:!0}):e[t]=n},Et=function(e,t){for(var r=-1,i=t.length,a=ea(i),o=null==e;++r<i;)a[r]=o?n:Ui(e,t[r]);return a},St=function(e,t,r){return e==e&&(r!==n&&(e=e<=r?e:r),t!==n&&(e=e>=t?e:t)),e},At=function(e,t,r){var i=r.length;if(null==e)return!i;for(e=aa(e);i--;){var a=r[i],o=t[a],u=e[a];if(u===n&&!(a in e)||!o(u))return!1}return!0},It=function(e,t,r){if("function"!=typeof e)throw new sa(j);return No((function(){e.apply(n,r)}),t)},xt=function(e,t,n,r){var i=-1,a=l,o=!0,u=e.length,s=[],d=t.length;if(!u)return s;n&&(t=f(t,C(n))),r?(a=c,o=!1):t.length>=200&&(a=P,o=!1,t=new ft(t));e:for(;++i<u;){var h=e[i],v=null==n?h:n(h);if(h=r||0!==h?h:0,o&&v==v){for(var p=d;p--;)if(t[p]===v)continue e;s.push(h)}else a(t,v,r)||s.push(h)}return s},Ct=function(e,t){var n=!0;return vo(e,(function(e,r,i){return n=!!t(e,r,i)})),n},Tt=function(e,t,r){for(var i=-1,a=e.length;++i<a;){var o=e[i],u=t(o);if(null!=u&&(s===n?u==u&&!Ti(u):r(u,s)))var s=u,l=o}return l},Pt=function(e,t){var n=[];return vo(e,(function(e,r,i){t(e,r,i)&&n.push(e)})),n},Rt=function(e,t){return e&&yo(e,t,Bi)},Lt=function(e,t){return e&&mo(e,t,Bi)},Dt=function(e,t){return s(t,(function(t){return ki(e[t])}))},Ot=function(e,t){for(var r=0,i=(t=Gn(t,e)).length;null!=e&&r<i;)e=e[Zr(t[r++])];return r&&r==i?e:n},Ft=function(e,t,n){var r=t(e);return Eu(e)?r:d(r,n(e))},Vt=function(e){return null==e?e===n?"[object Undefined]":"[object Null]":Ra&&Ra in aa(e)?function(e){var t=va.call(e,Ra),r=e[Ra];try{e[Ra]=n;var i=!0}catch(e){}var a=ya.call(e);return i&&(t?e[Ra]=r:delete e[Ra]),a}(e):function(e){return ya.call(e)}(e)},Gt=function(e,t){return e>t},Xt=function(e,t){return null!=e&&va.call(e,t)},Zt=function(e,t){return null!=e&&t in aa(e)},Qt=function(e,t,r){for(var i=r?c:l,a=e[0].length,o=e.length,u=o,s=ea(o),d=1/0,h=[];u--;){var v=e[u];u&&t&&(v=f(v,C(t))),d=Va(v.length,d),s[u]=!r&&(t||a>=120&&v.length>=120)?new ft(u&&v):n}v=e[0];var p=-1,g=s[0];e:for(;++p<a&&h.length<d;){var y=v[p],m=t?t(y):y;if(y=r||0!==y?y:0,!(g?P(g,m):i(h,m,r))){for(u=o;--u;){var b=s[u];if(!(b?P(b,m):i(e[u],m,r)))continue e}g&&g.push(m),h.push(y)}}return h},$t=function(e,t,i){var a=null==(e=Hr(e,t=Gn(t,e)))?e:e[Zr(ri(t))];return null==a?n:r(a,e,i)},en=function(e){return Ai(e)&&Vt(e)==J},sn=function(e,t,r,i){var a=r.length,o=a,u=!i;if(null==e)return!o;for(e=aa(e);a--;){var s=r[a];if(u&&s[2]?s[1]!==e[s[0]]:!(s[0]in e))return!1}for(;++a<o;){var l=(s=r[a])[0],c=e[l],f=s[1];if(u&&s[2]){if(c===n&&!(l in e))return!1}else{var d=new dt;if(i)var h=i(c,f,l,e,t,d);if(!(h===n?bo(f,c,3,i,d):h))return!1}}return!0},hn=function(e){return!(!Si(e)||function(e){return!!ga&&ga in e}(e))&&(ki(e)?wa:$e).test(Qr(e))},vn=function(e){return"function"==typeof e?e:null==e?Gi:"object"==typeof e?Eu(e)?bn(e[0],e[1]):mn(e):Qi(e)},pn=function(e){if(!zr(e))return ja(e);var t=[];for(var n in aa(e))va.call(e,n)&&"constructor"!=n&&t.push(n);return t},gn=function(e,t){return e<t},yn=function(e,t){var n=-1,r=mi(e)?ea(e.length):[];return vo(e,(function(e,i,a){r[++n]=t(e,i,a)})),r},mn=function(e){var t=Lr(e);return 1==t.length&&t[0][2]?Kr(t[0][0],t[0][1]):function(n){return n===e||sn(n,e,t)}},bn=function(e,t){return Br(e)&&jr(t)?Kr(Zr(e),t):function(r){var i=Ui(r,e);return i===n&&i===t?Fi(r,e):bo(t,i,3)}},wn=function(e,t){var r=e.length;if(r)return Ur(t+=t<0?r:0,r)?e[t]:n},kn=function(e,t,n){t=t.length?f(t,(function(e){return Eu(e)?function(t){return Ot(t,1===e.length?e[0]:e)}:e})):[Gi];var r=-1;t=f(t,C(Pr()));var i=yn(e,(function(e){var n=f(t,(function(t){return t(e)}));return{criteria:n,index:++r,value:e}}));return function(e,t){var n=e.length;for(e.sort(t);n--;)e[n]=e[n].value;return e}(i,(function(e,t){return function(e,t,n){for(var r=-1,i=e.criteria,a=t.criteria,o=i.length,u=n.length;++r<o;){var s=Jn(i[r],a[r]);if(s)return r>=u?s:s*("desc"==n[r]?-1:1)}return e.index-t.index}(e,t,n)}))},_n=function(e,t,n){for(var r=-1,i=t.length,a={};++r<i;){var o=t[r],u=Ot(e,o);n(u,o)&&Pn(a,Gn(o,e),u)}return a},En=function(e,t,n,r){var i=r?b:m,a=-1,o=t.length,u=e;for(e===t&&(t=tr(t)),n&&(u=f(e,C(n)));++a<o;)for(var s=0,l=t[a],c=n?n(l):l;(s=i(u,c,s,r))>-1;)u!==e&&Ca.call(u,s,1),Ca.call(e,s,1);return e},Sn=function(e,t){for(var n=e?t.length:0,r=n-1;n--;){var i=t[n];if(n==r||i!==a){var a=i;Ur(i)?Ca.call(e,i,1):Bn(e,i)}}return e},An=function(e,t){return e+Ua(Ga()*(t-e+1))},In=function(e,t){var n="";if(!e||t<1||t>X)return n;do{t%2&&(n+=e),(t=Ua(t/2))&&(e+=e)}while(t);return n},xn=function(e,t){return Oo(Vr(e,t,Gi),e+"")},Cn=function(e){return vt(ji(e))},Tn=function(e,t){var n=ji(e);return Yr(n,St(t,0,n.length))},Pn=function(e,t,r,i){if(!Si(e))return e;for(var a=-1,o=(t=Gn(t,e)).length,u=o-1,s=e;null!=s&&++a<o;){var l=Zr(t[a]),c=r;if("__proto__"===l||"constructor"===l||"prototype"===l)return e;if(a!=u){var f=s[l];(c=i?i(f,l,s):n)===n&&(c=Si(f)?f:Ur(t[a+1])?[]:{})}mt(s,l,c),s=s[l]}return e},Rn=function(e){return Yr(ji(e))},Ln=function(e,t,n){var r=-1,i=e.length;t<0&&(t=-t>i?0:i+t),(n=n>i?i:n)<0&&(n+=i),i=t>n?0:n-t>>>0,t>>>=0;for(var a=ea(i);++r<i;)a[r]=e[r+t];return a},Dn=function(e,t){var n;return vo(e,(function(e,r,i){return!(n=t(e,r,i))})),!!n},Mn=function(e,t,n){var r=0,i=null==e?r:e.length;if("number"==typeof t&&t==t&&i<=2147483647){for(;r<i;){var a=r+i>>>1,o=e[a];null!==o&&!Ti(o)&&(n?o<=t:o<t)?r=a+1:i=a}return i}return Nn(e,t,Gi,n)},Nn=function(e,t,r,i){var a=0,o=null==e?0:e.length;if(0===o)return 0;for(var u=(t=r(t))!=t,s=null===t,l=Ti(t),c=t===n;a<o;){var f=Ua((a+o)/2),d=r(e[f]),h=d!==n,v=null===d,p=d==d,g=Ti(d);if(u)var y=i||p;else y=c?p&&(i||h):s?p&&h&&(i||!v):l?p&&h&&!v&&(i||!g):!v&&!g&&(i?d<=t:d<t);y?a=f+1:o=f}return Va(o,4294967294)},On=function(e,t){for(var n=-1,r=e.length,i=0,a=[];++n<r;){var o=e[n],u=t?t(o):o;if(!n||!yi(u,s)){var s=u;a[i++]=0===o?0:o}}return a},Un=function(e){return"number"==typeof e?e:Ti(e)?Y:+e},Fn=function(e,t,n){var r=-1,i=l,a=e.length,o=!0,u=[],s=u;if(n)o=!1,i=c;else if(a>=200){var f=t?null:xo(e);if(f)return F(f);o=!1,i=P,s=new ft}else s=t?[]:u;e:for(;++r<a;){var d=e[r],h=t?t(d):d;if(d=n||0!==d?d:0,o&&h==h){for(var v=s.length;v--;)if(s[v]===h)continue e;t&&s.push(h),u.push(d)}else i(s,h,n)||(s!==u&&s.push(h),u.push(d))}return u},Bn=function(e,t){return null==(e=Hr(e,t=Gn(t,e)))||delete e[Zr(ri(t))]},qn=function(e,t,n,r){return Pn(e,t,n(Ot(e,t)),r)},zn=function(e,t,n,r){for(var i=e.length,a=r?i:-1;(r?a--:++a<i)&&t(e[a],a,e););return n?Ln(e,r?0:a,r?a+1:i):Ln(e,r?a+1:0,r?i:a)},jn=function(e,t){var n=e;return n instanceof ut&&(n=n.value()),h(t,(function(e,t){return t.func.apply(t.thisArg,d([e],t.args))}),n)},Kn=function(e,t,n){var r=e.length;if(r<2)return r?Fn(e[0]):[];for(var i=-1,a=ea(r);++i<r;)for(var o=e[i],u=-1;++u<r;)u!=i&&(a[i]=xt(a[i]||o,e[u],t,n));return Fn(go(a,1),t,n)},Vn=function(e,t,r){for(var i=-1,a=e.length,o=t.length,u={};++i<a;){var s=i<o?t[i]:n;r(u,e[i],s)}return u},Hn=function(e){return bi(e)?e:[]},Wn=function(e){return"function"==typeof e?e:Gi},Gn=function(e,t){return Eu(e)?e:Br(e,t)?[e]:Uo(Oi(e))},Xn=function(e,t,r){var i=e.length;return r=r===n?i:r,!t&&r>=i?e:Ln(e,t,r)},Yn=function(e,t){if(t)return e.slice();var n=e.length,r=Sa?Sa(n):new e.constructor(n);return e.copy(r),r},Zn=function(e){var t=new e.constructor(e.byteLength);return new Ea(t).set(new Ea(e)),t},Qn=function(e,t){var n=t?Zn(e.buffer):e.buffer;return new e.constructor(n,e.byteOffset,e.length)},Jn=function(e,t){if(e!==t){var r=e!==n,i=null===e,a=e==e,o=Ti(e),u=t!==n,s=null===t,l=t==t,c=Ti(t);if(!s&&!c&&!o&&e>t||o&&u&&l&&!s&&!c||i&&u&&l||!r&&l||!a)return 1;if(!i&&!o&&!c&&e<t||c&&r&&a&&!i&&!o||s&&r&&a||!u&&a||!l)return-1}return 0},$n=function(e,t,n,r){for(var i=-1,a=e.length,o=n.length,u=-1,s=t.length,l=Ka(a-o,0),c=ea(s+l),f=!r;++u<s;)c[u]=t[u];for(;++i<o;)(f||i<a)&&(c[n[i]]=e[i]);for(;l--;)c[u++]=e[i++];return c},er=function(e,t,n,r){for(var i=-1,a=e.length,o=-1,u=n.length,s=-1,l=t.length,c=Ka(a-u,0),f=ea(c+l),d=!r;++i<c;)f[i]=e[i];for(var h=i;++s<l;)f[h+s]=t[s];for(;++o<u;)(d||i<a)&&(f[h+n[o]]=e[i++]);return f},tr=function(e,t){var n=-1,r=e.length;for(t||(t=ea(r));++n<r;)t[n]=e[n];return t},nr=function(e,t,r,i){var a=!r;r||(r={});for(var o=-1,u=t.length;++o<u;){var s=t[o],l=i?i(r[s],e[s],s,r,e):n;l===n&&(l=e[s]),a?_t(r,s,l):mt(r,s,l)}return r},rr=function(e,t){return function(n,r){var a=Eu(n)?i:wt,o=t?t():{};return a(n,e,Pr(r,2),o)}},ir=function(e){return xn((function(t,r){var i=-1,a=r.length,o=a>1?r[a-1]:n,u=a>2?r[2]:n;for(o=e.length>3&&"function"==typeof o?(a--,o):n,u&&Fr(r[0],r[1],u)&&(o=a<3?n:o,a=1),t=aa(t);++i<a;){var s=r[i];s&&e(t,s,i,o)}return t}))},ar=function(e,t){return function(n,r){if(null==n)return n;if(!mi(n))return e(n,r);for(var i=n.length,a=t?i:-1,o=aa(n);(t?a--:++a<i)&&!1!==r(o[a],a,o););return n}},or=function(e){return function(t,n,r){for(var i=-1,a=aa(t),o=r(t),u=o.length;u--;){var s=o[e?u:++i];if(!1===n(a[s],s,a))break}return t}},ur=function(e){return function(t){var r=M(t=Oi(t))?q(t):n,i=r?r[0]:t.charAt(0),a=r?Xn(r,1).join(""):t.slice(1);return i[e]()+a}},sr=function(e){return function(t){return h(Hi(Vi(t).replace(Mt,"")),e,"")}},lr=function(e){return function(){var t=arguments;switch(t.length){case 0:return new e;case 1:return new e(t[0]);case 2:return new e(t[0],t[1]);case 3:return new e(t[0],t[1],t[2]);case 4:return new e(t[0],t[1],t[2],t[3]);case 5:return new e(t[0],t[1],t[2],t[3],t[4]);case 6:return new e(t[0],t[1],t[2],t[3],t[4],t[5]);case 7:return new e(t[0],t[1],t[2],t[3],t[4],t[5],t[6])}var n=fo(e.prototype),r=e.apply(n,t);return Si(r)?r:n}},cr=function(e){return function(t,r,i){var a=aa(t);if(!mi(t)){var o=Pr(r,3);t=Bi(t),r=function(e){return o(a[e],e,a)}}var u=e(t,r,i);return u>-1?a[o?t[u]:u]:n}},fr=function(e){return Ar((function(t){var r=t.length,i=r,a=ot.prototype.thru;for(e&&t.reverse();i--;){var o=t[i];if("function"!=typeof o)throw new sa(j);if(a&&!u&&"wrapper"==Cr(o))var u=new ot([],!0)}for(i=u?i:r;++i<r;){var s=Cr(o=t[i]),l="wrapper"==s?To(o):n;u=l&&qr(l[0])&&424==l[1]&&!l[4].length&&1==l[9]?u[Cr(l[0])].apply(u,l[3]):1==o.length&&qr(o)?u[s]():u.thru(o)}return function(){var e=arguments,n=e[0];if(u&&1==e.length&&Eu(n))return u.plant(n).value();for(var i=0,a=r?t[i].apply(this,e):n;++i<r;)a=t[i].call(this,a);return a}}))},dr=function(e,t){return function(n,r){return function(e,t,n,r){return Rt(e,(function(e,i,a){t(r,n(e),i,a)})),r}(n,e,t(r),{})}},hr=function(e,t){return function(r,i){var a;if(r===n&&i===n)return t;if(r!==n&&(a=r),i!==n){if(a===n)return i;"string"==typeof r||"string"==typeof i?(r=Eo(r),i=Eo(i)):(r=Un(r),i=Un(i)),a=e(r,i)}return a}},vr=function(e){return Ar((function(t){return t=f(t,C(Pr())),xn((function(n){var i=this;return e(t,(function(e){return r(e,i,n)}))}))}))},pr=function(e,t){var r=(t=t===n?" ":Eo(t)).length;if(r<2)return r?In(t,e):t;var i=In(t,Oa(e/B(t)));return M(t)?Xn(q(i),0,e).join(""):i.slice(0,e)},gr=function(e){return function(t,r,i){return i&&"number"!=typeof i&&Fr(t,r,i)&&(r=i=n),t=Ri(t),r===n?(r=t,t=0):r=Ri(r),function(e,t,n,r){for(var i=-1,a=Ka(Oa((t-e)/(n||1)),0),o=ea(a);a--;)o[r?a:++i]=e,e+=n;return o}(t,r,i=i===n?t<r?1:-1:Ri(i),e)}},yr=function(e){return function(t,n){return"string"==typeof t&&"string"==typeof n||(t=Mi(t),n=Mi(n)),e(t,n)}},mr=function(e,t,r,i,a,o,u,s,l,c){var f=8&t;t|=f?H:64,4&(t&=~(f?64:H))||(t&=-4);var d=[e,t,a,f?o:n,f?u:n,f?n:o,f?n:u,s,l,c],h=r.apply(n,d);return qr(e)&&Mo(h,d),h.placeholder=i,Gr(h,e,t)},br=function(e){var t=ia[e];return function(e,n){if(e=Mi(e),(n=null==n?0:Va(Li(n),292))&&qa(e)){var r=(Oi(e)+"e").split("e");return+((r=(Oi(t(r[0]+"e"+(+r[1]+n)))+"e").split("e"))[0]+"e"+(+r[1]-n))}return t(e)}},wr=function(e){return function(t){var n=Lo(t);return n==ae?N(t):n==ce?function(e){var t=-1,n=Array(e.size);return e.forEach((function(e){n[++t]=[e,e]})),n}(t):function(e,t){return f(t,(function(t){return[t,e[t]]}))}(t,e(t))}},kr=function(e,t,i,a,o,u,s,l){var c=2&t;if(!c&&"function"!=typeof e)throw new sa(j);var f=a?a.length:0;if(f||(t&=-97,a=o=n),s=s===n?s:Ka(Li(s),0),l=l===n?l:Li(l),f-=o?o.length:0,64&t){var d=a,h=o;a=o=n}var v=c?n:To(e),p=[e,t,i,a,o,d,h,u,s,l];if(v&&function(e,t){var n=e[1],r=t[1],i=n|r,a=i<131,o=r==W&&8==n||r==W&&256==n&&e[7].length<=t[8]||384==r&&t[7].length<=t[8]&&8==n;if(!a&&!o)return e;1&r&&(e[2]=t[2],i|=1&n?0:4);var u=t[3];if(u){var s=e[3];e[3]=s?$n(s,u,t[4]):u,e[4]=s?U(e[3],V):t[4]}(u=t[5])&&(s=e[5],e[5]=s?er(s,u,t[6]):u,e[6]=s?U(e[5],V):t[6]),(u=t[7])&&(e[7]=u),r&W&&(e[8]=null==e[8]?t[8]:Va(e[8],t[8])),null==e[9]&&(e[9]=t[9]),e[0]=t[0],e[1]=i}(p,v),e=p[0],t=p[1],i=p[2],a=p[3],o=p[4],!(l=p[9]=p[9]===n?c?0:e.length:Ka(p[9]-f,0))&&24&t&&(t&=-25),t&&1!=t)g=8==t||16==t?function(e,t,i){var a=lr(e);return function o(){for(var u=arguments.length,s=ea(u),l=u,c=Tr(o);l--;)s[l]=arguments[l];var f=u<3&&s[0]!==c&&s[u-1]!==c?[]:U(s,c);return(u-=f.length)<i?mr(e,t,Io,o.placeholder,n,s,f,n,n,i-u):r(this&&this!==Yt&&this instanceof o?a:e,this,s)}}(e,t,l):t!=H&&33!=t||o.length?Io.apply(n,p):function(e,t,n,i){var a=1&t,o=lr(e);return function t(){for(var u=-1,s=arguments.length,l=-1,c=i.length,f=ea(c+s),d=this&&this!==Yt&&this instanceof t?o:e;++l<c;)f[l]=i[l];for(;s--;)f[l++]=arguments[++u];return r(d,a?n:this,f)}}(e,t,i,a);else var g=function(e,t,n){var r=1&t,i=lr(e);return function t(){return(this&&this!==Yt&&this instanceof t?i:e).apply(r?n:this,arguments)}}(e,t,i);return Gr((v?ko:Mo)(g,p),e,t)},_r=function(e,t,r,i){return e===n||yi(e,fa[r])&&!va.call(i,r)?t:e},Er=function(e){return xi(e)?n:e},Sr=function(e,t,r,i,a,o){var u=1&r,s=e.length,l=t.length;if(s!=l&&!(u&&l>s))return!1;var c=o.get(e),f=o.get(t);if(c&&f)return c==t&&f==e;var d=-1,h=!0,v=2&r?new ft:n;for(o.set(e,t),o.set(t,e);++d<s;){var g=e[d],y=t[d];if(i)var m=u?i(y,g,d,t,e,o):i(g,y,d,e,t,o);if(m!==n){if(m)continue;h=!1;break}if(v){if(!p(t,(function(e,t){if(!P(v,t)&&(g===e||a(g,e,r,i,o)))return v.push(t)}))){h=!1;break}}else if(g!==y&&!a(g,y,r,i,o)){h=!1;break}}return o.delete(e),o.delete(t),h},Ar=function(e){return Oo(Vr(e,n,ti),e+"")},Ir=function(e){return Ft(e,Bi,Po)},xr=function(e){return Ft(e,qi,Ro)},Cr=function(e){for(var t=e.name+"",n=no[t],r=va.call(no,t)?n.length:0;r--;){var i=n[r],a=i.func;if(null==a||a==e)return i.name}return t},Tr=function(e){return(va.call(je,"placeholder")?je:e).placeholder},Pr=function(){var e=je.iteratee||Xi;return e=e===Xi?vn:e,arguments.length?e(arguments[0],arguments[1]):e},Rr=function(e,t){var n,r,i=e.__data__;return("string"==(r=(0,fe.default)(n=t))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==n:null===n)?i["string"==typeof t?"string":"hash"]:i.map},Lr=function(e){for(var t=Bi(e),n=t.length;n--;){var r=t[n],i=e[r];t[n]=[r,i,jr(i)]}return t},Dr=function(e,t){var r=function(e,t){return null==e?n:e[t]}(e,t);return hn(r)?r:n},Mr=function(e,t,n){for(var r=-1,i=(t=Gn(t,e)).length,a=!1;++r<i;){var o=Zr(t[r]);if(!(a=null!=e&&n(e,o)))break;e=e[o]}return a||++r!=i?a:!!(i=null==e?0:e.length)&&Ei(i)&&Ur(o,i)&&(Eu(e)||_u(e))},Nr=function(e){return"function"!=typeof e.constructor||zr(e)?{}:fo(Aa(e))},Or=function(e){return Eu(e)||_u(e)||!!(Ta&&e&&e[Ta])},Ur=function(e,t){var n=void 0===e?"undefined":(0,fe.default)(e);return!!(t=null==t?X:t)&&("number"==n||"symbol"!=n&&tt.test(e))&&e>-1&&e%1==0&&e<t},Fr=function(e,t,n){if(!Si(n))return!1;var r=void 0===t?"undefined":(0,fe.default)(t);return!!("number"==r?mi(n)&&Ur(t,n.length):"string"==r&&t in n)&&yi(n[t],e)},Br=function(e,t){if(Eu(e))return!1;var n=void 0===e?"undefined":(0,fe.default)(e);return!("number"!=n&&"symbol"!=n&&"boolean"!=n&&null!=e&&!Ti(e))||Ue.test(e)||!Oe.test(e)||null!=t&&e in aa(t)},qr=function(e){var t=Cr(e),n=je[t];if("function"!=typeof n||!(t in ut.prototype))return!1;if(e===n)return!0;var r=To(n);return!!r&&e===r[0]},zr=function(e){var t=e&&e.constructor;return e===("function"==typeof t&&t.prototype||fa)},jr=function(e){return e==e&&!Si(e)},Kr=function(e,t){return function(r){return null!=r&&r[e]===t&&(t!==n||e in aa(r))}},Vr=function(e,t,i){return t=Ka(t===n?e.length-1:t,0),function(){for(var n=arguments,a=-1,o=Ka(n.length-t,0),u=ea(o);++a<o;)u[a]=n[t+a];a=-1;for(var s=ea(t+1);++a<t;)s[a]=n[a];return s[t]=i(u),r(e,this,s)}},Hr=function(e,t){return t.length<2?e:Ot(e,Ln(t,0,-1))},Wr=function(e,t){if(("constructor"!==t||"function"!=typeof e[t])&&"__proto__"!=t)return e[t]},Gr=function(e,t,n){var r=t+"";return Oo(e,function(e,t){var n=t.length;if(!n)return e;var r=n-1;return t[r]=(n>1?"& ":"")+t[r],t=t.join(n>2?", ":" "),e.replace(Ke,"{\n/* [wrapped with "+t+"] */\n")}(r,function(e,t){return a(Q,(function(n){var r="_."+n[0];t&n[1]&&!l(e,r)&&e.push(r)})),e.sort()}(function(e){var t=e.match(Ve);return t?t[1].split(He):[]}(r),n)))},Xr=function(e){var t=0,r=0;return function(){var i=Ha(),a=16-(i-r);if(r=i,a>0){if(++t>=800)return arguments[0]}else t=0;return e.apply(n,arguments)}},Yr=function(e,t){var r=-1,i=e.length,a=i-1;for(t=t===n?i:t;++r<t;){var o=An(r,a),u=e[o];e[o]=e[r],e[r]=u}return e.length=t,e},Zr=function(e){if("string"==typeof e||Ti(e))return e;var t=e+"";return"0"==t&&1/e==-1/0?"-0":t},Qr=function(e){if(null!=e){try{return ha.call(e)}catch(e){}try{return e+""}catch(e){}}return""},Jr=function(e){if(e instanceof ut)return e.clone();var t=new ot(e.__wrapped__,e.__chain__);return t.__actions__=tr(e.__actions__),t.__index__=e.__index__,t.__values__=e.__values__,t},$r=function(e,t,n){var r=null==e?0:e.length;if(!r)return-1;var i=null==n?0:Li(n);return i<0&&(i=Ka(r+i,0)),y(e,Pr(t,3),i)},ei=function(e,t,r){var i=null==e?0:e.length;if(!i)return-1;var a=i-1;return r!==n&&(a=Li(r),a=r<0?Ka(i+a,0):Va(a,i-1)),y(e,Pr(t,3),a,!0)},ti=function(e){return null!=e&&e.length?go(e,1):[]},ni=function(e){return e&&e.length?e[0]:n},ri=function(e){var t=null==e?0:e.length;return t?e[t-1]:n},ii=function(e,t){return e&&e.length&&t&&t.length?En(e,t):e},ai=function(e){return null==e?e:Xa.call(e)},oi=function(e){if(!e||!e.length)return[];var t=0;return e=s(e,(function(e){if(bi(e))return t=Ka(e.length,t),!0})),I(t,(function(t){return f(e,_(t))}))},ui=function(e,t){if(!e||!e.length)return[];var i=oi(e);return null==t?i:f(i,(function(e){return r(t,n,e)}))},si=function(e){var t=je(e);return t.__chain__=!0,t},li=function(e,t){return t(e)},ci=function(e,t){return(Eu(e)?a:vo)(e,Pr(t,3))},fi=function(e,t){return(Eu(e)?o:po)(e,Pr(t,3))},di=function(e,t){return(Eu(e)?f:yn)(e,Pr(t,3))},hi=function(e,t,r){return t=r?n:t,t=e&&null==t?e.length:t,kr(e,W,n,n,n,n,t)},vi=function(e,t){var r;if("function"!=typeof t)throw new sa(j);return e=Li(e),function(){return--e>0&&(r=t.apply(this,arguments)),e<=1&&(t=n),r}},pi=function(e,t,r){var i,a,o,u,s,l,c=0,f=!1,d=!1,h=!0;if("function"!=typeof e)throw new sa(j);function v(t){var r=i,o=a;return i=a=n,c=t,u=e.apply(o,r)}function p(e){var r=e-l;return l===n||r>=t||r<0||d&&e-c>=o}function g(){var e=cu();if(p(e))return y(e);s=No(g,function(e){var n=t-(e-l);return d?Va(n,o-(e-c)):n}(e))}function y(e){return s=n,h&&i?v(e):(i=a=n,u)}function m(){var e=cu(),r=p(e);if(i=arguments,a=this,l=e,r){if(s===n)return function(e){return c=e,s=No(g,t),f?v(e):u}(l);if(d)return Ao(s),s=No(g,t),v(l)}return s===n&&(s=No(g,t)),u}return t=Mi(t)||0,Si(r)&&(f=!!r.leading,o=(d="maxWait"in r)?Ka(Mi(r.maxWait)||0,t):o,h="trailing"in r?!!r.trailing:h),m.cancel=function(){s!==n&&Ao(s),c=0,i=l=a=s=n},m.flush=function(){return s===n?u:y(cu())},m},gi=function(e){if("function"!=typeof e)throw new sa(j);return function(){var t=arguments;switch(t.length){case 0:return!e.call(this);case 1:return!e.call(this,t[0]);case 2:return!e.call(this,t[0],t[1]);case 3:return!e.call(this,t[0],t[1],t[2])}return!e.apply(this,t)}},yi=function(e,t){return e===t||e!=e&&t!=t},mi=function(e){return null!=e&&Ei(e.length)&&!ki(e)},bi=function(e){return Ai(e)&&mi(e)},wi=function(e){if(!Ai(e))return!1;var t=Vt(e);return t==ne||"[object DOMException]"==t||"string"==typeof e.message&&"string"==typeof e.name&&!xi(e)},ki=function(e){if(!Si(e))return!1;var t=Vt(e);return t==re||t==ie||"[object AsyncFunction]"==t||"[object Proxy]"==t},_i=function(e){return"number"==typeof e&&e==Li(e)},Ei=function(e){return"number"==typeof e&&e>-1&&e%1==0&&e<=X},Si=function(e){var t=void 0===e?"undefined":(0,fe.default)(e);return null!=e&&("object"==t||"function"==t)},Ai=function(e){return null!=e&&"object"==typeof e},Ii=function(e){return"number"==typeof e||Ai(e)&&Vt(e)==oe},xi=function(e){if(!Ai(e)||Vt(e)!=ue)return!1;var t=Aa(e);if(null===t)return!0;var n=va.call(t,"constructor")&&t.constructor;return"function"==typeof n&&n instanceof n&&ha.call(n)==ma},Ci=function(e){return"string"==typeof e||!Eu(e)&&Ai(e)&&Vt(e)==de},Ti=function(e){return"symbol"==(void 0===e?"undefined":(0,fe.default)(e))||Ai(e)&&Vt(e)==he},Pi=function(e){if(!e)return[];if(mi(e))return Ci(e)?q(e):tr(e);if(Pa&&e[Pa])return function(e){for(var t,n=[];!(t=e.next()).done;)n.push(t.value);return n}(e[Pa]());var t=Lo(e);return(t==ae?N:t==ce?F:ji)(e)},Ri=function(e){return e?(e=Mi(e))===G||e===-1/0?17976931348623157e292*(e<0?-1:1):e==e?e:0:0===e?e:0},Li=function(e){var t=Ri(e),n=t%1;return t==t?n?t-n:t:0},Di=function(e){return e?St(Li(e),0,Z):0},Mi=function(e){if("number"==typeof e)return e;if(Ti(e))return Y;if(Si(e)){var t="function"==typeof e.valueOf?e.valueOf():e;e=Si(t)?t+"":t}if("string"!=typeof e)return 0===e?e:+e;e=x(e);var n=Je.test(e);return n||et.test(e)?Wt(e.slice(2),n?2:8):Qe.test(e)?Y:+e},Ni=function(e){return nr(e,qi(e))},Oi=function(e){return null==e?"":Eo(e)},Ui=function(e,t,r){var i=null==e?n:Ot(e,t);return i===n?r:i},Fi=function(e,t){return null!=e&&Mr(e,t,Zt)},Bi=function(e){return mi(e)?ht(e):pn(e)},qi=function(e){return mi(e)?ht(e,!0):function(e){if(!Si(e))return function(e){var t=[];if(null!=e)for(var n in aa(e))t.push(n);return t}(e);var t=zr(e),n=[];for(var r in e)("constructor"!=r||!t&&va.call(e,r))&&n.push(r);return n}(e)},zi=function(e,t){if(null==e)return{};var n=f(xr(e),(function(e){return[e]}));return t=Pr(t),_n(e,n,(function(e,n){return t(e,n[0])}))},ji=function(e){return null==e?[]:T(e,Bi(e))},Ki=function(e){return ns(Oi(e).toLowerCase())},Vi=function(e){return(e=Oi(e))&&e.replace(nt,ln).replace(Nt,"")},Hi=function(e,t,r){return e=Oi(e),(t=r?n:t)===n?function(e){return Bt.test(e)}(e)?function(e){return e.match(Ut)||[]}(e):function(e){return e.match(We)||[]}(e):e.match(t)||[]},Wi=function(e){return function(){return e}},Gi=function(e){return e},Xi=function(e){return vn("function"==typeof e?e:ho(e,1))},Yi=function(e,t,n){var r=Bi(t),i=Dt(t,r);null!=n||Si(t)&&(i.length||!r.length)||(n=t,t=e,e=this,i=Dt(t,Bi(t)));var o=!(Si(n)&&"chain"in n&&!n.chain),u=ki(e);return a(i,(function(n){var r=t[n];e[n]=r,u&&(e.prototype[n]=function(){var t=this.__chain__;if(o||t){var n=e(this.__wrapped__);return(n.__actions__=tr(this.__actions__)).push({func:r,args:arguments,thisArg:e}),n.__chain__=t,n}return r.apply(e,d([this.value()],arguments))})})),e},Zi=function(){},Qi=function(e){return Br(e)?_(Zr(e)):function(e){return function(t){return Ot(t,e)}}(e)},Ji=function(){return[]},$i=function(){return!1},ea=(t=null==t?Yt:dn.defaults(Yt.Object(),t,dn.pick(Yt,qt))).Array,ta=t.Date,na=t.Error,ra=t.Function,ia=t.Math,aa=t.Object,oa=t.RegExp,ua=t.String,sa=t.TypeError,la=ea.prototype,ca=ra.prototype,fa=aa.prototype,da=t["__core-js_shared__"],ha=ca.toString,va=fa.hasOwnProperty,pa=0,ga=(E=/[^.]+$/.exec(da&&da.keys&&da.keys.IE_PROTO||""))?"Symbol(src)_1."+E:"",ya=fa.toString,ma=ha.call(aa),ba=Yt._,wa=oa("^"+ha.call(va).replace(Be,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),ka=Jt?t.Buffer:n,_a=t.Symbol,Ea=t.Uint8Array,Sa=ka?ka.allocUnsafe:n,Aa=O(aa.getPrototypeOf,aa),Ia=aa.create,xa=fa.propertyIsEnumerable,Ca=la.splice,Ta=_a?_a.isConcatSpreadable:n,Pa=_a?_a.iterator:n,Ra=_a?_a.toStringTag:n,La=function(){try{var e=Dr(aa,"defineProperty");return e({},"",{}),e}catch(e){}}(),Da=t.clearTimeout!==Yt.clearTimeout&&t.clearTimeout,Ma=ta&&ta.now!==Yt.Date.now&&ta.now,Na=t.setTimeout!==Yt.setTimeout&&t.setTimeout,Oa=ia.ceil,Ua=ia.floor,Fa=aa.getOwnPropertySymbols,Ba=ka?ka.isBuffer:n,qa=t.isFinite,za=la.join,ja=O(aa.keys,aa),Ka=ia.max,Va=ia.min,Ha=ta.now,Wa=t.parseInt,Ga=ia.random,Xa=la.reverse,Ya=Dr(t,"DataView"),Za=Dr(t,"Map"),Qa=Dr(t,"Promise"),Ja=Dr(t,"Set"),$a=Dr(t,"WeakMap"),eo=Dr(aa,"create"),to=$a&&new $a,no={},ro=Qr(Ya),io=Qr(Za),ao=Qr(Qa),oo=Qr(Ja),uo=Qr($a),so=_a?_a.prototype:n,lo=so?so.valueOf:n,co=so?so.toString:n,fo=function(){var e=function(){};return function(t){if(!Si(t))return{};if(Ia)return Ia(t);e.prototype=t;var r=new e;return e.prototype=n,r}}();function ho(e,t,r,i,o,u){var s,l=1&t,c=2&t,f=4&t;if(r&&(s=o?r(e,i,o,u):r(e)),s!==n)return s;if(!Si(e))return e;var d=Eu(e);if(d){if(s=function(e){var t=e.length,n=new e.constructor(t);return t&&"string"==typeof e[0]&&va.call(e,"index")&&(n.index=e.index,n.input=e.input),n}(e),!l)return tr(e,s)}else{var h=Lo(e),v=h==re||h==ie;if(Au(e))return Yn(e,l);if(h==ue||h==J||v&&!o){if(s=c||v?{}:Nr(e),!l)return c?function(e,t){return nr(e,Ro(e),t)}(e,function(e,t){return e&&nr(t,qi(t),e)}(s,e)):function(e,t){return nr(e,Po(e),t)}(e,kt(s,e))}else{if(!Kt[h])return o?e:{};s=function(e,t,n){var r=e.constructor;switch(t){case pe:return Zn(e);case ee:case te:return new r(+e);case ge:return function(e,t){var n=t?Zn(e.buffer):e.buffer;return new e.constructor(n,e.byteOffset,e.byteLength)}(e,n);case ye:case me:case be:case we:case ke:case _e:case Ee:case Se:case Ae:return Qn(e,n);case ae:return new r;case oe:case de:return new r(e);case le:return function(e){var t=new e.constructor(e.source,Ze.exec(e));return t.lastIndex=e.lastIndex,t}(e);case ce:return new r;case he:return function(e){return lo?aa(lo.call(e)):{}}(e)}}(e,h,l)}}u||(u=new dt);var p=u.get(e);if(p)return p;u.set(e,s),Tu(e)?e.forEach((function(n){s.add(ho(n,t,r,n,e,u))})):xu(e)&&e.forEach((function(n,i){s.set(i,ho(n,t,r,i,e,u))}));var g=d?n:(f?c?xr:Ir:c?qi:Bi)(e);return a(g||e,(function(n,i){g&&(n=e[i=n]),mt(s,i,ho(n,t,r,i,e,u))})),s}je.templateSettings={escape:De,evaluate:Me,interpolate:Ne,variable:"",imports:{_:je}},(je.prototype=at.prototype).constructor=je,ot.prototype=fo(at.prototype),ot.prototype.constructor=ot,ut.prototype=fo(at.prototype),ut.prototype.constructor=ut,st.prototype.clear=function(){this.__data__=eo?eo(null):{},this.size=0},st.prototype.delete=function(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t},st.prototype.get=function(e){var t=this.__data__;if(eo){var r=t[e];return r===K?n:r}return va.call(t,e)?t[e]:n},st.prototype.has=function(e){var t=this.__data__;return eo?t[e]!==n:va.call(t,e)},st.prototype.set=function(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=eo&&t===n?K:t,this},lt.prototype.clear=function(){this.__data__=[],this.size=0},lt.prototype.delete=function(e){var t=this.__data__,n=bt(t,e);return!(n<0||(n==t.length-1?t.pop():Ca.call(t,n,1),--this.size,0))},lt.prototype.get=function(e){var t=this.__data__,r=bt(t,e);return r<0?n:t[r][1]},lt.prototype.has=function(e){return bt(this.__data__,e)>-1},lt.prototype.set=function(e,t){var n=this.__data__,r=bt(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this},ct.prototype.clear=function(){this.size=0,this.__data__={hash:new st,map:new(Za||lt),string:new st}},ct.prototype.delete=function(e){var t=Rr(this,e).delete(e);return this.size-=t?1:0,t},ct.prototype.get=function(e){return Rr(this,e).get(e)},ct.prototype.has=function(e){return Rr(this,e).has(e)},ct.prototype.set=function(e,t){var n=Rr(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this},ft.prototype.add=ft.prototype.push=function(e){return this.__data__.set(e,K),this},ft.prototype.has=function(e){return this.__data__.has(e)},dt.prototype.clear=function(){this.__data__=new lt,this.size=0},dt.prototype.delete=function(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n},dt.prototype.get=function(e){return this.__data__.get(e)},dt.prototype.has=function(e){return this.__data__.has(e)},dt.prototype.set=function(e,t){var n=this.__data__;if(n instanceof lt){var r=n.__data__;if(!Za||r.length<199)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new ct(r)}return n.set(e,t),this.size=n.size,this};var vo=ar(Rt),po=ar(Lt,!0);function go(e,t,n,r,i){var a=-1,o=e.length;for(n||(n=Or),i||(i=[]);++a<o;){var u=e[a];t>0&&n(u)?t>1?go(u,t-1,n,r,i):d(i,u):r||(i[i.length]=u)}return i}var yo=or(),mo=or(!0);function bo(e,t,r,i,a){return e===t||(null==e||null==t||!Ai(e)&&!Ai(t)?e!=e&&t!=t:function(e,t,r,i,a,o){var u=Eu(e),s=Eu(t),l=u?$:Lo(e),c=s?$:Lo(t),f=(l=l==J?ue:l)==ue,d=(c=c==J?ue:c)==ue,h=l==c;if(h&&Au(e)){if(!Au(t))return!1;u=!0,f=!1}if(h&&!f)return o||(o=new dt),u||Pu(e)?Sr(e,t,r,i,a,o):function(e,t,n,r,i,a,o){switch(n){case ge:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case pe:return!(e.byteLength!=t.byteLength||!a(new Ea(e),new Ea(t)));case ee:case te:case oe:return yi(+e,+t);case ne:return e.name==t.name&&e.message==t.message;case le:case de:return e==t+"";case ae:var u=N;case ce:var s=1&r;if(u||(u=F),e.size!=t.size&&!s)return!1;var l=o.get(e);if(l)return l==t;r|=2,o.set(e,t);var c=Sr(u(e),u(t),r,i,a,o);return o.delete(e),c;case he:if(lo)return lo.call(e)==lo.call(t)}return!1}(e,t,l,r,i,a,o);if(!(1&r)){var v=f&&va.call(e,"__wrapped__"),p=d&&va.call(t,"__wrapped__");if(v||p){var g=v?e.value():e,y=p?t.value():t;return o||(o=new dt),a(g,y,r,i,o)}}return!!h&&(o||(o=new dt),function(e,t,r,i,a,o){var u=1&r,s=Ir(e),l=s.length;if(l!=Ir(t).length&&!u)return!1;for(var c=l;c--;){var f=s[c];if(!(u?f in t:va.call(t,f)))return!1}var d=o.get(e),h=o.get(t);if(d&&h)return d==t&&h==e;var v=!0;o.set(e,t),o.set(t,e);for(var p=u;++c<l;){var g=e[f=s[c]],y=t[f];if(i)var m=u?i(y,g,f,t,e,o):i(g,y,f,e,t,o);if(!(m===n?g===y||a(g,y,r,i,o):m)){v=!1;break}p||(p="constructor"==f)}if(v&&!p){var b=e.constructor,w=t.constructor;b==w||!("constructor"in e)||!("constructor"in t)||"function"==typeof b&&b instanceof b&&"function"==typeof w&&w instanceof w||(v=!1)}return o.delete(e),o.delete(t),v}(e,t,r,i,a,o))}(e,t,r,i,bo,a))}function wo(e,t,r,i,a){e!==t&&yo(t,(function(o,u){if(a||(a=new dt),Si(o))!function(e,t,r,i,a,o,u){var s=Wr(e,r),l=Wr(t,r),c=u.get(l);if(c)yt(e,r,c);else{var f=o?o(s,l,r+"",e,t,u):n,d=f===n;if(d){var h=Eu(l),v=!h&&Au(l),p=!h&&!v&&Pu(l);f=l,h||v||p?Eu(s)?f=s:bi(s)?f=tr(s):v?(d=!1,f=Yn(l,!0)):p?(d=!1,f=Qn(l,!0)):f=[]:xi(l)||_u(l)?(f=s,_u(s)?f=Ni(s):Si(s)&&!ki(s)||(f=Nr(l))):d=!1}d&&(u.set(l,f),a(f,l,i,o,u),u.delete(l)),yt(e,r,f)}}(e,t,u,r,wo,i,a);else{var s=i?i(Wr(e,u),o,u+"",e,t,a):n;s===n&&(s=o),yt(e,u,s)}}),qi)}var ko=to?function(e,t){return to.set(e,t),e}:Gi,_o=La?function(e,t){return La(e,"toString",{configurable:!0,enumerable:!1,value:Wi(t),writable:!0})}:Gi;function Eo(e){if("string"==typeof e)return e;if(Eu(e))return f(e,Eo)+"";if(Ti(e))return co?co.call(e):"";var t=e+"";return"0"==t&&1/e==-1/0?"-0":t}var So=xn,Ao=Da||function(e){return Yt.clearTimeout(e)};function Io(e,t,r,i,a,o,u,s,l,c){var f=t&W,d=1&t,h=2&t,v=24&t,p=512&t,g=h?n:lr(e);return function y(){for(var m=arguments.length,b=ea(m),w=m;w--;)b[w]=arguments[w];if(v)var k=Tr(y),_=function(e,t){for(var n=e.length,r=0;n--;)e[n]===t&&++r;return r}(b,k);if(i&&(b=$n(b,i,a,v)),o&&(b=er(b,o,u,v)),m-=_,v&&m<c){var E=U(b,k);return mr(e,t,Io,y.placeholder,r,b,E,s,l,c-m)}var S=d?r:this,A=h?S[e]:e;return m=b.length,s?b=function(e,t){for(var r=e.length,i=Va(t.length,r),a=tr(e);i--;){var o=t[i];e[i]=Ur(o,r)?a[o]:n}return e}(b,s):p&&m>1&&b.reverse(),f&&l<m&&(b.length=l),this&&this!==Yt&&this instanceof y&&(A=g||lr(A)),A.apply(S,b)}}var xo=Ja&&1/F(new Ja([,-0]))[1]==G?function(e){return new Ja(e)}:Zi;function Co(e,t,r,i,a,o){return Si(e)&&Si(t)&&(o.set(t,e),wo(e,t,n,Co,o),o.delete(t)),e}var To=to?function(e){return to.get(e)}:Zi,Po=Fa?function(e){return null==e?[]:(e=aa(e),s(Fa(e),(function(t){return xa.call(e,t)})))}:Ji,Ro=Fa?function(e){for(var t=[];e;)d(t,Po(e)),e=Aa(e);return t}:Ji,Lo=Vt;(Ya&&Lo(new Ya(new ArrayBuffer(1)))!=ge||Za&&Lo(new Za)!=ae||Qa&&Lo(Qa.resolve())!=se||Ja&&Lo(new Ja)!=ce||$a&&Lo(new $a)!=ve)&&(Lo=function(e){var t=Vt(e),r=t==ue?e.constructor:n,i=r?Qr(r):"";if(i)switch(i){case ro:return ge;case io:return ae;case ao:return se;case oo:return ce;case uo:return ve}return t});var Do=da?ki:$i,Mo=Xr(ko),No=Na||function(e,t){return Yt.setTimeout(e,t)},Oo=Xr(_o),Uo=function(e){var t=pu((function(e){var t=[];return 46===e.charCodeAt(0)&&t.push(""),e.replace(Fe,(function(e,n,r,i){t.push(r?i.replace(Xe,"$1"):n||e)})),t}),(function(e){return 500===n.size&&n.clear(),e})),n=t.cache;return t}(),Fo=xn((function(e,t){return bi(e)?xt(e,go(t,1,bi,!0)):[]})),Bo=xn((function(e,t){var r=ri(t);return bi(r)&&(r=n),bi(e)?xt(e,go(t,1,bi,!0),Pr(r,2)):[]})),qo=xn((function(e,t){var r=ri(t);return bi(r)&&(r=n),bi(e)?xt(e,go(t,1,bi,!0),n,r):[]})),zo=xn((function(e){var t=f(e,Hn);return t.length&&t[0]===e[0]?Qt(t):[]})),jo=xn((function(e){var t=ri(e),r=f(e,Hn);return t===ri(r)?t=n:r.pop(),r.length&&r[0]===e[0]?Qt(r,Pr(t,2)):[]})),Ko=xn((function(e){var t=ri(e),r=f(e,Hn);return(t="function"==typeof t?t:n)&&r.pop(),r.length&&r[0]===e[0]?Qt(r,n,t):[]})),Vo=xn(ii),Ho=Ar((function(e,t){var n=null==e?0:e.length,r=Et(e,t);return Sn(e,f(t,(function(e){return Ur(e,n)?+e:e})).sort(Jn)),r})),Wo=xn((function(e){return Fn(go(e,1,bi,!0))})),Go=xn((function(e){var t=ri(e);return bi(t)&&(t=n),Fn(go(e,1,bi,!0),Pr(t,2))})),Xo=xn((function(e){var t=ri(e);return t="function"==typeof t?t:n,Fn(go(e,1,bi,!0),n,t)})),Yo=xn((function(e,t){return bi(e)?xt(e,t):[]})),Zo=xn((function(e){return Kn(s(e,bi))})),Qo=xn((function(e){var t=ri(e);return bi(t)&&(t=n),Kn(s(e,bi),Pr(t,2))})),Jo=xn((function(e){var t=ri(e);return t="function"==typeof t?t:n,Kn(s(e,bi),n,t)})),$o=xn(oi),eu=xn((function(e){var t=e.length,r=t>1?e[t-1]:n;return r="function"==typeof r?(e.pop(),r):n,ui(e,r)})),tu=Ar((function(e){var t=e.length,r=t?e[0]:0,i=this.__wrapped__,a=function(t){return Et(t,e)};return!(t>1||this.__actions__.length)&&i instanceof ut&&Ur(r)?((i=i.slice(r,+r+(t?1:0))).__actions__.push({func:li,args:[a],thisArg:n}),new ot(i,this.__chain__).thru((function(e){return t&&!e.length&&e.push(n),e}))):this.thru(a)})),nu=rr((function(e,t,n){va.call(e,n)?++e[n]:_t(e,n,1)})),ru=cr($r),iu=cr(ei),au=rr((function(e,t,n){va.call(e,n)?e[n].push(t):_t(e,n,[t])})),ou=xn((function(e,t,n){var i=-1,a="function"==typeof t,o=mi(e)?ea(e.length):[];return vo(e,(function(e){o[++i]=a?r(t,e,n):$t(e,t,n)})),o})),uu=rr((function(e,t,n){_t(e,n,t)})),su=rr((function(e,t,n){e[n?0:1].push(t)}),(function(){return[[],[]]})),lu=xn((function(e,t){if(null==e)return[];var n=t.length;return n>1&&Fr(e,t[0],t[1])?t=[]:n>2&&Fr(t[0],t[1],t[2])&&(t=[t[0]]),kn(e,go(t,1),[])})),cu=Ma||function(){return Yt.Date.now()},fu=xn((function(e,t,n){var r=1;if(n.length){var i=U(n,Tr(fu));r|=H}return kr(e,r,t,n,i)})),du=xn((function(e,t,n){var r=3;if(n.length){var i=U(n,Tr(du));r|=H}return kr(t,r,e,n,i)})),hu=xn((function(e,t){return It(e,1,t)})),vu=xn((function(e,t,n){return It(e,Mi(t)||0,n)}));function pu(e,t){if("function"!=typeof e||null!=t&&"function"!=typeof t)throw new sa(j);var n=function(){var r=arguments,i=t?t.apply(this,r):r[0],a=n.cache;if(a.has(i))return a.get(i);var o=e.apply(this,r);return n.cache=a.set(i,o)||a,o};return n.cache=new(pu.Cache||ct),n}pu.Cache=ct;var gu=So((function(e,t){var n=(t=1==t.length&&Eu(t[0])?f(t[0],C(Pr())):f(go(t,1),C(Pr()))).length;return xn((function(i){for(var a=-1,o=Va(i.length,n);++a<o;)i[a]=t[a].call(this,i[a]);return r(e,this,i)}))})),yu=xn((function(e,t){var r=U(t,Tr(yu));return kr(e,H,n,t,r)})),mu=xn((function(e,t){var r=U(t,Tr(mu));return kr(e,64,n,t,r)})),bu=Ar((function(e,t){return kr(e,256,n,n,n,t)})),wu=yr(Gt),ku=yr((function(e,t){return e>=t})),_u=en(function(){return arguments}())?en:function(e){return Ai(e)&&va.call(e,"callee")&&!xa.call(e,"callee")},Eu=ea.isArray,Su=tn?C(tn):function(e){return Ai(e)&&Vt(e)==pe},Au=Ba||$i,Iu=nn?C(nn):function(e){return Ai(e)&&Vt(e)==te},xu=rn?C(rn):function(e){return Ai(e)&&Lo(e)==ae},Cu=an?C(an):function(e){return Ai(e)&&Vt(e)==le},Tu=on?C(on):function(e){return Ai(e)&&Lo(e)==ce},Pu=un?C(un):function(e){return Ai(e)&&Ei(e.length)&&!!jt[Vt(e)]},Ru=yr(gn),Lu=yr((function(e,t){return e<=t})),Du=ir((function(e,t){if(zr(t)||mi(t))nr(t,Bi(t),e);else for(var n in t)va.call(t,n)&&mt(e,n,t[n])})),Mu=ir((function(e,t){nr(t,qi(t),e)})),Nu=ir((function(e,t,n,r){nr(t,qi(t),e,r)})),Ou=ir((function(e,t,n,r){nr(t,Bi(t),e,r)})),Uu=Ar(Et),Fu=xn((function(e,t){e=aa(e);var r=-1,i=t.length,a=i>2?t[2]:n;for(a&&Fr(t[0],t[1],a)&&(i=1);++r<i;)for(var o=t[r],u=qi(o),s=-1,l=u.length;++s<l;){var c=u[s],f=e[c];(f===n||yi(f,fa[c])&&!va.call(e,c))&&(e[c]=o[c])}return e})),Bu=xn((function(e){return e.push(n,Co),r(Vu,n,e)})),qu=dr((function(e,t,n){null!=t&&"function"!=typeof t.toString&&(t=ya.call(t)),e[t]=n}),Wi(Gi)),zu=dr((function(e,t,n){null!=t&&"function"!=typeof t.toString&&(t=ya.call(t)),va.call(e,t)?e[t].push(n):e[t]=[n]}),Pr),ju=xn($t),Ku=ir((function(e,t,n){wo(e,t,n)})),Vu=ir((function(e,t,n,r){wo(e,t,n,r)})),Hu=Ar((function(e,t){var n={};if(null==e)return n;var r=!1;t=f(t,(function(t){return t=Gn(t,e),r||(r=t.length>1),t})),nr(e,xr(e),n),r&&(n=ho(n,7,Er));for(var i=t.length;i--;)Bn(n,t[i]);return n})),Wu=Ar((function(e,t){return null==e?{}:function(e,t){return _n(e,t,(function(t,n){return Fi(e,n)}))}(e,t)})),Gu=wr(Bi),Xu=wr(qi),Yu=sr((function(e,t,n){return t=t.toLowerCase(),e+(n?Ki(t):t)})),Zu=sr((function(e,t,n){return e+(n?"-":"")+t.toLowerCase()})),Qu=sr((function(e,t,n){return e+(n?" ":"")+t.toLowerCase()})),Ju=ur("toLowerCase"),$u=sr((function(e,t,n){return e+(n?"_":"")+t.toLowerCase()})),es=sr((function(e,t,n){return e+(n?" ":"")+ns(t)})),ts=sr((function(e,t,n){return e+(n?" ":"")+t.toUpperCase()})),ns=ur("toUpperCase"),rs=xn((function(e,t){try{return r(e,n,t)}catch(e){return wi(e)?e:new na(e)}})),is=Ar((function(e,t){return a(t,(function(t){t=Zr(t),_t(e,t,fu(e[t],e))})),e})),as=fr(),os=fr(!0),us=xn((function(e,t){return function(n){return $t(n,e,t)}})),ss=xn((function(e,t){return function(n){return $t(e,n,t)}})),ls=vr(f),cs=vr(u),fs=vr(p),ds=gr(),hs=gr(!0),vs=hr((function(e,t){return e+t}),0),ps=br("ceil"),gs=hr((function(e,t){return e/t}),1),ys=br("floor"),ms=hr((function(e,t){return e*t}),1),bs=br("round"),ws=hr((function(e,t){return e-t}),0);return je.after=function(e,t){if("function"!=typeof t)throw new sa(j);return e=Li(e),function(){if(--e<1)return t.apply(this,arguments)}},je.ary=hi,je.assign=Du,je.assignIn=Mu,je.assignInWith=Nu,je.assignWith=Ou,je.at=Uu,je.before=vi,je.bind=fu,je.bindAll=is,je.bindKey=du,je.castArray=function(){if(!arguments.length)return[];var e=arguments[0];return Eu(e)?e:[e]},je.chain=si,je.chunk=function(e,t,r){t=(r?Fr(e,t,r):t===n)?1:Ka(Li(t),0);var i=null==e?0:e.length;if(!i||t<1)return[];for(var a=0,o=0,u=ea(Oa(i/t));a<i;)u[o++]=Ln(e,a,a+=t);return u},je.compact=function(e){for(var t=-1,n=null==e?0:e.length,r=0,i=[];++t<n;){var a=e[t];a&&(i[r++]=a)}return i},je.concat=function(){var e=arguments.length;if(!e)return[];for(var t=ea(e-1),n=arguments[0],r=e;r--;)t[r-1]=arguments[r];return d(Eu(n)?tr(n):[n],go(t,1))},je.cond=function(e){var t=null==e?0:e.length,n=Pr();return e=t?f(e,(function(e){if("function"!=typeof e[1])throw new sa(j);return[n(e[0]),e[1]]})):[],xn((function(n){for(var i=-1;++i<t;){var a=e[i];if(r(a[0],this,n))return r(a[1],this,n)}}))},je.conforms=function(e){return function(e){var t=Bi(e);return function(n){return At(n,e,t)}}(ho(e,1))},je.constant=Wi,je.countBy=nu,je.create=function(e,t){var n=fo(e);return null==t?n:kt(n,t)},je.curry=function e(t,r,i){var a=kr(t,8,n,n,n,n,n,r=i?n:r);return a.placeholder=e.placeholder,a},je.curryRight=function e(t,r,i){var a=kr(t,16,n,n,n,n,n,r=i?n:r);return a.placeholder=e.placeholder,a},je.debounce=pi,je.defaults=Fu,je.defaultsDeep=Bu,je.defer=hu,je.delay=vu,je.difference=Fo,je.differenceBy=Bo,je.differenceWith=qo,je.drop=function(e,t,r){var i=null==e?0:e.length;return i?Ln(e,(t=r||t===n?1:Li(t))<0?0:t,i):[]},je.dropRight=function(e,t,r){var i=null==e?0:e.length;return i?Ln(e,0,(t=i-(t=r||t===n?1:Li(t)))<0?0:t):[]},je.dropRightWhile=function(e,t){return e&&e.length?zn(e,Pr(t,3),!0,!0):[]},je.dropWhile=function(e,t){return e&&e.length?zn(e,Pr(t,3),!0):[]},je.fill=function(e,t,r,i){var a=null==e?0:e.length;return a?(r&&"number"!=typeof r&&Fr(e,t,r)&&(r=0,i=a),function(e,t,r,i){var a=e.length;for((r=Li(r))<0&&(r=-r>a?0:a+r),(i=i===n||i>a?a:Li(i))<0&&(i+=a),i=r>i?0:Di(i);r<i;)e[r++]=t;return e}(e,t,r,i)):[]},je.filter=function(e,t){return(Eu(e)?s:Pt)(e,Pr(t,3))},je.flatMap=function(e,t){return go(di(e,t),1)},je.flatMapDeep=function(e,t){return go(di(e,t),G)},je.flatMapDepth=function(e,t,r){return r=r===n?1:Li(r),go(di(e,t),r)},je.flatten=ti,je.flattenDeep=function(e){return null!=e&&e.length?go(e,G):[]},je.flattenDepth=function(e,t){return null!=e&&e.length?go(e,t=t===n?1:Li(t)):[]},je.flip=function(e){return kr(e,512)},je.flow=as,je.flowRight=os,je.fromPairs=function(e){for(var t=-1,n=null==e?0:e.length,r={};++t<n;){var i=e[t];r[i[0]]=i[1]}return r},je.functions=function(e){return null==e?[]:Dt(e,Bi(e))},je.functionsIn=function(e){return null==e?[]:Dt(e,qi(e))},je.groupBy=au,je.initial=function(e){return null!=e&&e.length?Ln(e,0,-1):[]},je.intersection=zo,je.intersectionBy=jo,je.intersectionWith=Ko,je.invert=qu,je.invertBy=zu,je.invokeMap=ou,je.iteratee=Xi,je.keyBy=uu,je.keys=Bi,je.keysIn=qi,je.map=di,je.mapKeys=function(e,t){var n={};return t=Pr(t,3),Rt(e,(function(e,r,i){_t(n,t(e,r,i),e)})),n},je.mapValues=function(e,t){var n={};return t=Pr(t,3),Rt(e,(function(e,r,i){_t(n,r,t(e,r,i))})),n},je.matches=function(e){return mn(ho(e,1))},je.matchesProperty=function(e,t){return bn(e,ho(t,1))},je.memoize=pu,je.merge=Ku,je.mergeWith=Vu,je.method=us,je.methodOf=ss,je.mixin=Yi,je.negate=gi,je.nthArg=function(e){return e=Li(e),xn((function(t){return wn(t,e)}))},je.omit=Hu,je.omitBy=function(e,t){return zi(e,gi(Pr(t)))},je.once=function(e){return vi(2,e)},je.orderBy=function(e,t,r,i){return null==e?[]:(Eu(t)||(t=null==t?[]:[t]),Eu(r=i?n:r)||(r=null==r?[]:[r]),kn(e,t,r))},je.over=ls,je.overArgs=gu,je.overEvery=cs,je.overSome=fs,je.partial=yu,je.partialRight=mu,je.partition=su,je.pick=Wu,je.pickBy=zi,je.property=Qi,je.propertyOf=function(e){return function(t){return null==e?n:Ot(e,t)}},je.pull=Vo,je.pullAll=ii,je.pullAllBy=function(e,t,n){return e&&e.length&&t&&t.length?En(e,t,Pr(n,2)):e},je.pullAllWith=function(e,t,r){return e&&e.length&&t&&t.length?En(e,t,n,r):e},je.pullAt=Ho,je.range=ds,je.rangeRight=hs,je.rearg=bu,je.reject=function(e,t){return(Eu(e)?s:Pt)(e,gi(Pr(t,3)))},je.remove=function(e,t){var n=[];if(!e||!e.length)return n;var r=-1,i=[],a=e.length;for(t=Pr(t,3);++r<a;){var o=e[r];t(o,r,e)&&(n.push(o),i.push(r))}return Sn(e,i),n},je.rest=function(e,t){if("function"!=typeof e)throw new sa(j);return xn(e,t=t===n?t:Li(t))},je.reverse=ai,je.sampleSize=function(e,t,r){return t=(r?Fr(e,t,r):t===n)?1:Li(t),(Eu(e)?pt:Tn)(e,t)},je.set=function(e,t,n){return null==e?e:Pn(e,t,n)},je.setWith=function(e,t,r,i){return i="function"==typeof i?i:n,null==e?e:Pn(e,t,r,i)},je.shuffle=function(e){return(Eu(e)?gt:Rn)(e)},je.slice=function(e,t,r){var i=null==e?0:e.length;return i?(r&&"number"!=typeof r&&Fr(e,t,r)?(t=0,r=i):(t=null==t?0:Li(t),r=r===n?i:Li(r)),Ln(e,t,r)):[]},je.sortBy=lu,je.sortedUniq=function(e){return e&&e.length?On(e):[]},je.sortedUniqBy=function(e,t){return e&&e.length?On(e,Pr(t,2)):[]},je.split=function(e,t,r){return r&&"number"!=typeof r&&Fr(e,t,r)&&(t=r=n),(r=r===n?Z:r>>>0)?(e=Oi(e))&&("string"==typeof t||null!=t&&!Cu(t))&&!(t=Eo(t))&&M(e)?Xn(q(e),0,r):e.split(t,r):[]},je.spread=function(e,t){if("function"!=typeof e)throw new sa(j);return t=null==t?0:Ka(Li(t),0),xn((function(n){var i=n[t],a=Xn(n,0,t);return i&&d(a,i),r(e,this,a)}))},je.tail=function(e){var t=null==e?0:e.length;return t?Ln(e,1,t):[]},je.take=function(e,t,r){return e&&e.length?Ln(e,0,(t=r||t===n?1:Li(t))<0?0:t):[]},je.takeRight=function(e,t,r){var i=null==e?0:e.length;return i?Ln(e,(t=i-(t=r||t===n?1:Li(t)))<0?0:t,i):[]},je.takeRightWhile=function(e,t){return e&&e.length?zn(e,Pr(t,3),!1,!0):[]},je.takeWhile=function(e,t){return e&&e.length?zn(e,Pr(t,3)):[]},je.tap=function(e,t){return t(e),e},je.throttle=function(e,t,n){var r=!0,i=!0;if("function"!=typeof e)throw new sa(j);return Si(n)&&(r="leading"in n?!!n.leading:r,i="trailing"in n?!!n.trailing:i),pi(e,t,{leading:r,maxWait:t,trailing:i})},je.thru=li,je.toArray=Pi,je.toPairs=Gu,je.toPairsIn=Xu,je.toPath=function(e){return Eu(e)?f(e,Zr):Ti(e)?[e]:tr(Uo(Oi(e)))},je.toPlainObject=Ni,je.transform=function(e,t,n){var r=Eu(e),i=r||Au(e)||Pu(e);if(t=Pr(t,4),null==n){var o=e&&e.constructor;n=i?r?new o:[]:Si(e)&&ki(o)?fo(Aa(e)):{}}return(i?a:Rt)(e,(function(e,r,i){return t(n,e,r,i)})),n},je.unary=function(e){return hi(e,1)},je.union=Wo,je.unionBy=Go,je.unionWith=Xo,je.uniq=function(e){return e&&e.length?Fn(e):[]},je.uniqBy=function(e,t){return e&&e.length?Fn(e,Pr(t,2)):[]},je.uniqWith=function(e,t){return t="function"==typeof t?t:n,e&&e.length?Fn(e,n,t):[]},je.unset=function(e,t){return null==e||Bn(e,t)},je.unzip=oi,je.unzipWith=ui,je.update=function(e,t,n){return null==e?e:qn(e,t,Wn(n))},je.updateWith=function(e,t,r,i){return i="function"==typeof i?i:n,null==e?e:qn(e,t,Wn(r),i)},je.values=ji,je.valuesIn=function(e){return null==e?[]:T(e,qi(e))},je.without=Yo,je.words=Hi,je.wrap=function(e,t){return yu(Wn(t),e)},je.xor=Zo,je.xorBy=Qo,je.xorWith=Jo,je.zip=$o,je.zipObject=function(e,t){return Vn(e||[],t||[],mt)},je.zipObjectDeep=function(e,t){return Vn(e||[],t||[],Pn)},je.zipWith=eu,je.entries=Gu,je.entriesIn=Xu,je.extend=Mu,je.extendWith=Nu,Yi(je,je),je.add=vs,je.attempt=rs,je.camelCase=Yu,je.capitalize=Ki,je.ceil=ps,je.clamp=function(e,t,r){return r===n&&(r=t,t=n),r!==n&&(r=(r=Mi(r))==r?r:0),t!==n&&(t=(t=Mi(t))==t?t:0),St(Mi(e),t,r)},je.clone=function(e){return ho(e,4)},je.cloneDeep=function(e){return ho(e,5)},je.cloneDeepWith=function(e,t){return ho(e,5,t="function"==typeof t?t:n)},je.cloneWith=function(e,t){return ho(e,4,t="function"==typeof t?t:n)},je.conformsTo=function(e,t){return null==t||At(e,t,Bi(t))},je.deburr=Vi,je.defaultTo=function(e,t){return null==e||e!=e?t:e},je.divide=gs,je.endsWith=function(e,t,r){e=Oi(e),t=Eo(t);var i=e.length,a=r=r===n?i:St(Li(r),0,i);return(r-=t.length)>=0&&e.slice(r,a)==t},je.eq=yi,je.escape=function(e){return(e=Oi(e))&&Le.test(e)?e.replace(Pe,cn):e},je.escapeRegExp=function(e){return(e=Oi(e))&&qe.test(e)?e.replace(Be,"\\$&"):e},je.every=function(e,t,r){var i=Eu(e)?u:Ct;return r&&Fr(e,t,r)&&(t=n),i(e,Pr(t,3))},je.find=ru,je.findIndex=$r,je.findKey=function(e,t){return g(e,Pr(t,3),Rt)},je.findLast=iu,je.findLastIndex=ei,je.findLastKey=function(e,t){return g(e,Pr(t,3),Lt)},je.floor=ys,je.forEach=ci,je.forEachRight=fi,je.forIn=function(e,t){return null==e?e:yo(e,Pr(t,3),qi)},je.forInRight=function(e,t){return null==e?e:mo(e,Pr(t,3),qi)},je.forOwn=function(e,t){return e&&Rt(e,Pr(t,3))},je.forOwnRight=function(e,t){return e&&Lt(e,Pr(t,3))},je.get=Ui,je.gt=wu,je.gte=ku,je.has=function(e,t){return null!=e&&Mr(e,t,Xt)},je.hasIn=Fi,je.head=ni,je.identity=Gi,je.includes=function(e,t,n,r){e=mi(e)?e:ji(e),n=n&&!r?Li(n):0;var i=e.length;return n<0&&(n=Ka(i+n,0)),Ci(e)?n<=i&&e.indexOf(t,n)>-1:!!i&&m(e,t,n)>-1},je.indexOf=function(e,t,n){var r=null==e?0:e.length;if(!r)return-1;var i=null==n?0:Li(n);return i<0&&(i=Ka(r+i,0)),m(e,t,i)},je.inRange=function(e,t,r){return t=Ri(t),r===n?(r=t,t=0):r=Ri(r),function(e,t,n){return e>=Va(t,n)&&e<Ka(t,n)}(e=Mi(e),t,r)},je.invoke=ju,je.isArguments=_u,je.isArray=Eu,je.isArrayBuffer=Su,je.isArrayLike=mi,je.isArrayLikeObject=bi,je.isBoolean=function(e){return!0===e||!1===e||Ai(e)&&Vt(e)==ee},je.isBuffer=Au,je.isDate=Iu,je.isElement=function(e){return Ai(e)&&1===e.nodeType&&!xi(e)},je.isEmpty=function(e){if(null==e)return!0;if(mi(e)&&(Eu(e)||"string"==typeof e||"function"==typeof e.splice||Au(e)||Pu(e)||_u(e)))return!e.length;var t=Lo(e);if(t==ae||t==ce)return!e.size;if(zr(e))return!pn(e).length;for(var n in e)if(va.call(e,n))return!1;return!0},je.isEqual=function(e,t){return bo(e,t)},je.isEqualWith=function(e,t,r){var i=(r="function"==typeof r?r:n)?r(e,t):n;return i===n?bo(e,t,n,r):!!i},je.isError=wi,je.isFinite=function(e){return"number"==typeof e&&qa(e)},je.isFunction=ki,je.isInteger=_i,je.isLength=Ei,je.isMap=xu,je.isMatch=function(e,t){return e===t||sn(e,t,Lr(t))},je.isMatchWith=function(e,t,r){return r="function"==typeof r?r:n,sn(e,t,Lr(t),r)},je.isNaN=function(e){return Ii(e)&&e!=+e},je.isNative=function(e){if(Do(e))throw new na("Unsupported core-js use. Try https://npms.io/search?q=ponyfill.");return hn(e)},je.isNil=function(e){return null==e},je.isNull=function(e){return null===e},je.isNumber=Ii,je.isObject=Si,je.isObjectLike=Ai,je.isPlainObject=xi,je.isRegExp=Cu,je.isSafeInteger=function(e){return _i(e)&&e>=-9007199254740991&&e<=X},je.isSet=Tu,je.isString=Ci,je.isSymbol=Ti,je.isTypedArray=Pu,je.isUndefined=function(e){return e===n},je.isWeakMap=function(e){return Ai(e)&&Lo(e)==ve},je.isWeakSet=function(e){return Ai(e)&&"[object WeakSet]"==Vt(e)},je.join=function(e,t){return null==e?"":za.call(e,t)},je.kebabCase=Zu,je.last=ri,je.lastIndexOf=function(e,t,r){var i=null==e?0:e.length;if(!i)return-1;var a=i;return r!==n&&(a=(a=Li(r))<0?Ka(i+a,0):Va(a,i-1)),t==t?function(e,t,n){for(var r=n+1;r--;)if(e[r]===t)return r;return r}(e,t,a):y(e,w,a,!0)},je.lowerCase=Qu,je.lowerFirst=Ju,je.lt=Ru,je.lte=Lu,je.max=function(e){return e&&e.length?Tt(e,Gi,Gt):n},je.maxBy=function(e,t){return e&&e.length?Tt(e,Pr(t,2),Gt):n},je.mean=function(e){return k(e,Gi)},je.meanBy=function(e,t){return k(e,Pr(t,2))},je.min=function(e){return e&&e.length?Tt(e,Gi,gn):n},je.minBy=function(e,t){return e&&e.length?Tt(e,Pr(t,2),gn):n},je.stubArray=Ji,je.stubFalse=$i,je.stubObject=function(){return{}},je.stubString=function(){return""},je.stubTrue=function(){return!0},je.multiply=ms,je.nth=function(e,t){return e&&e.length?wn(e,Li(t)):n},je.noConflict=function(){return Yt._===this&&(Yt._=ba),this},je.noop=Zi,je.now=cu,je.pad=function(e,t,n){e=Oi(e);var r=(t=Li(t))?B(e):0;if(!t||r>=t)return e;var i=(t-r)/2;return pr(Ua(i),n)+e+pr(Oa(i),n)},je.padEnd=function(e,t,n){e=Oi(e);var r=(t=Li(t))?B(e):0;return t&&r<t?e+pr(t-r,n):e},je.padStart=function(e,t,n){e=Oi(e);var r=(t=Li(t))?B(e):0;return t&&r<t?pr(t-r,n)+e:e},je.parseInt=function(e,t,n){return n||null==t?t=0:t&&(t=+t),Wa(Oi(e).replace(ze,""),t||0)},je.random=function(e,t,r){if(r&&"boolean"!=typeof r&&Fr(e,t,r)&&(t=r=n),r===n&&("boolean"==typeof t?(r=t,t=n):"boolean"==typeof e&&(r=e,e=n)),e===n&&t===n?(e=0,t=1):(e=Ri(e),t===n?(t=e,e=0):t=Ri(t)),e>t){var i=e;e=t,t=i}if(r||e%1||t%1){var a=Ga();return Va(e+a*(t-e+Ht("1e-"+((a+"").length-1))),t)}return An(e,t)},je.reduce=function(e,t,n){var r=Eu(e)?h:S,i=arguments.length<3;return r(e,Pr(t,4),n,i,vo)},je.reduceRight=function(e,t,n){var r=Eu(e)?v:S,i=arguments.length<3;return r(e,Pr(t,4),n,i,po)},je.repeat=function(e,t,r){return t=(r?Fr(e,t,r):t===n)?1:Li(t),In(Oi(e),t)},je.replace=function(){var e=arguments,t=Oi(e[0]);return e.length<3?t:t.replace(e[1],e[2])},je.result=function(e,t,r){var i=-1,a=(t=Gn(t,e)).length;for(a||(a=1,e=n);++i<a;){var o=null==e?n:e[Zr(t[i])];o===n&&(i=a,o=r),e=ki(o)?o.call(e):o}return e},je.round=bs,je.runInContext=e,je.sample=function(e){return(Eu(e)?vt:Cn)(e)},je.size=function(e){if(null==e)return 0;if(mi(e))return Ci(e)?B(e):e.length;var t=Lo(e);return t==ae||t==ce?e.size:pn(e).length},je.snakeCase=$u,je.some=function(e,t,r){var i=Eu(e)?p:Dn;return r&&Fr(e,t,r)&&(t=n),i(e,Pr(t,3))},je.sortedIndex=function(e,t){return Mn(e,t)},je.sortedIndexBy=function(e,t,n){return Nn(e,t,Pr(n,2))},je.sortedIndexOf=function(e,t){var n=null==e?0:e.length;if(n){var r=Mn(e,t);if(r<n&&yi(e[r],t))return r}return-1},je.sortedLastIndex=function(e,t){return Mn(e,t,!0)},je.sortedLastIndexBy=function(e,t,n){return Nn(e,t,Pr(n,2),!0)},je.sortedLastIndexOf=function(e,t){if(null!=e&&e.length){var n=Mn(e,t,!0)-1;if(yi(e[n],t))return n}return-1},je.startCase=es,je.startsWith=function(e,t,n){return e=Oi(e),n=null==n?0:St(Li(n),0,e.length),t=Eo(t),e.slice(n,n+t.length)==t},je.subtract=ws,je.sum=function(e){return e&&e.length?A(e,Gi):0},je.sumBy=function(e,t){return e&&e.length?A(e,Pr(t,2)):0},je.template=function(e,t,r){var i=je.templateSettings;r&&Fr(e,t,r)&&(t=n),e=Oi(e),t=Nu({},t,i,_r);var a,o,u=Nu({},t.imports,i.imports,_r),s=Bi(u),l=T(u,s),c=0,f=t.interpolate||rt,d="__p += '",h=oa((t.escape||rt).source+"|"+f.source+"|"+(f===Ne?Ye:rt).source+"|"+(t.evaluate||rt).source+"|$","g"),v="//# sourceURL="+(va.call(t,"sourceURL")?(t.sourceURL+"").replace(/\s/g," "):"lodash.templateSources["+ ++zt+"]")+"\n";e.replace(h,(function(t,n,r,i,u,s){return r||(r=i),d+=e.slice(c,s).replace(it,D),n&&(a=!0,d+="' +\n__e("+n+") +\n'"),u&&(o=!0,d+="';\n"+u+";\n__p += '"),r&&(d+="' +\n((__t = ("+r+")) == null ? '' : __t) +\n'"),c=s+t.length,t})),d+="';\n";var p=va.call(t,"variable")&&t.variable;if(p){if(Ge.test(p))throw new na("Invalid `variable` option passed into `_.template`")}else d="with (obj) {\n"+d+"\n}\n";d=(o?d.replace(Ie,""):d).replace(xe,"$1").replace(Ce,"$1;"),d="function("+(p||"obj")+") {\n"+(p?"":"obj || (obj = {});\n")+"var __t, __p = ''"+(a?", __e = _.escape":"")+(o?", __j = Array.prototype.join;\nfunction print() { __p += __j.call(arguments, '') }\n":";\n")+d+"return __p\n}";var g=rs((function(){return ra(s,v+"return "+d).apply(n,l)}));if(g.source=d,wi(g))throw g;return g},je.times=function(e,t){if((e=Li(e))<1||e>X)return[];var n=Z,r=Va(e,Z);t=Pr(t),e-=Z;for(var i=I(r,t);++n<e;)t(n);return i},je.toFinite=Ri,je.toInteger=Li,je.toLength=Di,je.toLower=function(e){return Oi(e).toLowerCase()},je.toNumber=Mi,je.toSafeInteger=function(e){return e?St(Li(e),-9007199254740991,X):0===e?e:0},je.toString=Oi,je.toUpper=function(e){return Oi(e).toUpperCase()},je.trim=function(e,t,r){if((e=Oi(e))&&(r||t===n))return x(e);if(!e||!(t=Eo(t)))return e;var i=q(e),a=q(t);return Xn(i,R(i,a),L(i,a)+1).join("")},je.trimEnd=function(e,t,r){if((e=Oi(e))&&(r||t===n))return e.slice(0,z(e)+1);if(!e||!(t=Eo(t)))return e;var i=q(e);return Xn(i,0,L(i,q(t))+1).join("")},je.trimStart=function(e,t,r){if((e=Oi(e))&&(r||t===n))return e.replace(ze,"");if(!e||!(t=Eo(t)))return e;var i=q(e);return Xn(i,R(i,q(t))).join("")},je.truncate=function(e,t){var r=30,i="...";if(Si(t)){var a="separator"in t?t.separator:a;r="length"in t?Li(t.length):r,i="omission"in t?Eo(t.omission):i}var o=(e=Oi(e)).length;if(M(e)){var u=q(e);o=u.length}if(r>=o)return e;var s=r-B(i);if(s<1)return i;var l=u?Xn(u,0,s).join(""):e.slice(0,s);if(a===n)return l+i;if(u&&(s+=l.length-s),Cu(a)){if(e.slice(s).search(a)){var c,f=l;for(a.global||(a=oa(a.source,Oi(Ze.exec(a))+"g")),a.lastIndex=0;c=a.exec(f);)var d=c.index;l=l.slice(0,d===n?s:d)}}else if(e.indexOf(Eo(a),s)!=s){var h=l.lastIndexOf(a);h>-1&&(l=l.slice(0,h))}return l+i},je.unescape=function(e){return(e=Oi(e))&&Re.test(e)?e.replace(Te,fn):e},je.uniqueId=function(e){var t=++pa;return Oi(e)+t},je.upperCase=ts,je.upperFirst=ns,je.each=ci,je.eachRight=fi,je.first=ni,Yi(je,function(){var e={};return Rt(je,(function(t,n){va.call(je.prototype,n)||(e[n]=t)})),e}(),{chain:!1}),je.VERSION="4.17.21",a(["bind","bindKey","curry","curryRight","partial","partialRight"],(function(e){je[e].placeholder=je})),a(["drop","take"],(function(e,t){ut.prototype[e]=function(r){r=r===n?1:Ka(Li(r),0);var i=this.__filtered__&&!t?new ut(this):this.clone();return i.__filtered__?i.__takeCount__=Va(r,i.__takeCount__):i.__views__.push({size:Va(r,Z),type:e+(i.__dir__<0?"Right":"")}),i},ut.prototype[e+"Right"]=function(t){return this.reverse()[e](t).reverse()}})),a(["filter","map","takeWhile"],(function(e,t){var n=t+1,r=1==n||3==n;ut.prototype[e]=function(e){var t=this.clone();return t.__iteratees__.push({iteratee:Pr(e,3),type:n}),t.__filtered__=t.__filtered__||r,t}})),a(["head","last"],(function(e,t){var n="take"+(t?"Right":"");ut.prototype[e]=function(){return this[n](1).value()[0]}})),a(["initial","tail"],(function(e,t){var n="drop"+(t?"":"Right");ut.prototype[e]=function(){return this.__filtered__?new ut(this):this[n](1)}})),ut.prototype.compact=function(){return this.filter(Gi)},ut.prototype.find=function(e){return this.filter(e).head()},ut.prototype.findLast=function(e){return this.reverse().find(e)},ut.prototype.invokeMap=xn((function(e,t){return"function"==typeof e?new ut(this):this.map((function(n){return $t(n,e,t)}))})),ut.prototype.reject=function(e){return this.filter(gi(Pr(e)))},ut.prototype.slice=function(e,t){e=Li(e);var r=this;return r.__filtered__&&(e>0||t<0)?new ut(r):(e<0?r=r.takeRight(-e):e&&(r=r.drop(e)),t!==n&&(r=(t=Li(t))<0?r.dropRight(-t):r.take(t-e)),r)},ut.prototype.takeRightWhile=function(e){return this.reverse().takeWhile(e).reverse()},ut.prototype.toArray=function(){return this.take(Z)},Rt(ut.prototype,(function(e,t){var r=/^(?:filter|find|map|reject)|While$/.test(t),i=/^(?:head|last)$/.test(t),a=je[i?"take"+("last"==t?"Right":""):t],o=i||/^find/.test(t);a&&(je.prototype[t]=function(){var t=this.__wrapped__,u=i?[1]:arguments,s=t instanceof ut,l=u[0],c=s||Eu(t),f=function(e){var t=a.apply(je,d([e],u));return i&&h?t[0]:t};c&&r&&"function"==typeof l&&1!=l.length&&(s=c=!1);var h=this.__chain__,v=!!this.__actions__.length,p=o&&!h,g=s&&!v;if(!o&&c){t=g?t:new ut(this);var y=e.apply(t,u);return y.__actions__.push({func:li,args:[f],thisArg:n}),new ot(y,h)}return p&&g?e.apply(this,u):(y=this.thru(f),p?i?y.value()[0]:y.value():y)})})),a(["pop","push","shift","sort","splice","unshift"],(function(e){var t=la[e],n=/^(?:push|sort|unshift)$/.test(e)?"tap":"thru",r=/^(?:pop|shift)$/.test(e);je.prototype[e]=function(){var e=arguments;if(r&&!this.__chain__){var i=this.value();return t.apply(Eu(i)?i:[],e)}return this[n]((function(n){return t.apply(Eu(n)?n:[],e)}))}})),Rt(ut.prototype,(function(e,t){var n=je[t];if(n){var r=n.name+"";va.call(no,r)||(no[r]=[]),no[r].push({name:t,func:n})}})),no[Io(n,2).name]=[{name:"wrapper",func:n}],ut.prototype.clone=function(){var e=new ut(this.__wrapped__);return e.__actions__=tr(this.__actions__),e.__dir__=this.__dir__,e.__filtered__=this.__filtered__,e.__iteratees__=tr(this.__iteratees__),e.__takeCount__=this.__takeCount__,e.__views__=tr(this.__views__),e},ut.prototype.reverse=function(){if(this.__filtered__){var e=new ut(this);e.__dir__=-1,e.__filtered__=!0}else(e=this.clone()).__dir__*=-1;return e},ut.prototype.value=function(){var e=this.__wrapped__.value(),t=this.__dir__,n=Eu(e),r=t<0,i=n?e.length:0,a=function(e,t,n){for(var r=-1,i=n.length;++r<i;){var a=n[r],o=a.size;switch(a.type){case"drop":e+=o;break;case"dropRight":t-=o;break;case"take":t=Va(t,e+o);break;case"takeRight":e=Ka(e,t-o)}}return{start:e,end:t}}(0,i,this.__views__),o=a.start,u=a.end,s=u-o,l=r?u:o-1,c=this.__iteratees__,f=c.length,d=0,h=Va(s,this.__takeCount__);if(!n||!r&&i==s&&h==s)return jn(e,this.__actions__);var v=[];e:for(;s--&&d<h;){for(var p=-1,g=e[l+=t];++p<f;){var y=c[p],m=y.iteratee,b=y.type,w=m(g);if(2==b)g=w;else if(!w){if(1==b)continue e;break e}}v[d++]=g}return v},je.prototype.at=tu,je.prototype.chain=function(){return si(this)},je.prototype.commit=function(){return new ot(this.value(),this.__chain__)},je.prototype.next=function(){this.__values__===n&&(this.__values__=Pi(this.value()));var e=this.__index__>=this.__values__.length;return{done:e,value:e?n:this.__values__[this.__index__++]}},je.prototype.plant=function(e){for(var t,r=this;r instanceof at;){var i=Jr(r);i.__index__=0,i.__values__=n,t?a.__wrapped__=i:t=i;var a=i;r=r.__wrapped__}return a.__wrapped__=e,t},je.prototype.reverse=function(){var e=this.__wrapped__;if(e instanceof ut){var t=e;return this.__actions__.length&&(t=new ut(this)),(t=t.reverse()).__actions__.push({func:li,args:[ai],thisArg:n}),new ot(t,this.__chain__)}return this.thru(ai)},je.prototype.toJSON=je.prototype.valueOf=je.prototype.value=function(){return jn(this.__wrapped__,this.__actions__)},je.prototype.first=je.prototype.head,Pa&&(je.prototype[Pa]=function(){return this}),je}();Qt?((Qt.exports=dn)._=dn,Zt._=dn):Yt._=dn}()}(_x,_x.exports)),new ja("sds:message"),new ja("sds:message-channel"),new ja("sdk:query-on-connect"),function(e){e.MessagesRetrieved="messages:retrieved"}(kx||(kx={})),new ja("sdk:missing-message-retriever"),new ja("sdk:reliable-channel"),Qa.ENCODE_FAILED,Qa.EMPTY_PAYLOAD,Qa.SIZE_TOO_BIG,Qa.RLN_PROOF_GENERATION;var Ex=Math.floor,Sx=Math.random,Ax="Trystero",Ix=function(e,t){return Array(e).fill().map(t)},xx=Ix(20,(function(){return"0123456789AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"[Ex(62*Sx())]})).join(""),Cx=Promise.all.bind(Promise),Tx="undefined"!=typeof window,Px=Object.entries,Rx=Object.fromEntries,Lx=Object.keys,Dx=function(){},Mx=function(e){return Error("".concat(Ax,": ").concat(e))},Nx=new TextEncoder,Ox=new TextDecoder,Ux=function(e){return Nx.encode(e)},Fx=function(e){return Ox.decode(e)},Bx=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return t.join("@")},qx=JSON.stringify,zx=JSON.parse,jx=null,Kx=null,Vx=function(){jx||(jx=new Promise((function(e){Kx=e})).finally((function(){Kx=null,jx=null})))},Hx=function(){return null==Kx?void 0:Kx()},Wx="AES-GCM",Gx={},Xx=function(){var e=(0,K.default)((function(e){var t,n;return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return(t=(d=Gx)[h=e])?[3,2]:(n=Array.from,[4,function(){var e=(0,K.default)((function(e,t){var n;return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return n=Uint8Array.bind,[4,crypto.subtle.digest(e,Ux(t))];case 1:return[2,new(n.apply(Uint8Array,[void 0,r.sent()]))]}}))}));return function(t,n){return e.apply(this,arguments)}}()("SHA-1",e)]);case 1:t=d[h]=n.apply(Array,[r.sent()]).map((function(e){return e.toString(36)})).join(""),r.label=2;case 2:return[2,t]}}))}));return function(t){return e.apply(this,arguments)}}(),Yx=function(){var e=(0,K.default)((function(e,t){var n,r,i,a,o,u;return(0,pe.__generator)(this,(function(s){switch(s.label){case 0:return n=crypto.getRandomValues(new Uint8Array(16)),i=n.join(",")+"$",o=(a=crypto.subtle).encrypt,u=[{name:Wx,iv:n}],[4,e];case 1:return[4,o.apply(a,u.concat([s.sent(),Ux(t)]))];case 2:return[2,i+(r=s.sent(),btoa(String.fromCharCode.apply(null,new Uint8Array(r))))]}}))}));return function(t,n){return e.apply(this,arguments)}}(),Zx=function(){var e=(0,K.default)((function(e,t){var n,r,i,a,o,u;return(0,pe.__generator)(this,(function(s){switch(s.label){case 0:return n=(0,se.default)(t.split("$"),2),r=n[0],i=n[1],o=(a=crypto.subtle).decrypt,u=[{name:Wx,iv:new Uint8Array(r.split(","))}],[4,e];case 1:return[4,o.apply(a,u.concat([s.sent(),function(e){var t=atob(e);return new Uint8Array(t.length).map((function(e,n){return t.charCodeAt(n)})).buffer}(i)]))];case 2:return[2,Fx.apply(void 0,[s.sent()])]}}))}));return function(t,n){return e.apply(this,arguments)}}(),Qx="icegatheringstatechange",Jx="offer",$x=function(e,t){var n=t.rtcConfig,r=t.rtcPolyfill,i=t.turnConfig,a=new(r||RTCPeerConnection)((0,ae.default)({iceServers:eC.concat(i||[])},n)),o={},u=!1,s=!1,l=null,c=function(e){e.binaryType="arraybuffer",e.bufferedAmountLowThreshold=65535,e.onmessage=function(e){var t;return null===(t=o.data)||void 0===t?void 0:t.call(o,e.data)},e.onopen=function(){var e;return null===(e=o.connect)||void 0===e?void 0:e.call(o)},e.onclose=function(){var e;return null===(e=o.close)||void 0===e?void 0:e.call(o)},e.onerror=function(e){var t;return null===(t=o.error)||void 0===t?void 0:t.call(o,e)}},f=function(e){return Promise.race([new Promise((function(t){var n=function(){"complete"===e.iceGatheringState&&(e.removeEventListener(Qx,n),t())};e.addEventListener(Qx,n),n()})),new Promise((function(e){return setTimeout(e,5e3)}))]).then((function(){return{type:e.localDescription.type,sdp:e.localDescription.sdp.replace(/a=ice-options:trickle\s\n/g,"")}}))};return e?(l=a.createDataChannel("data"),c(l)):a.ondatachannel=function(e){var t=e.channel;l=t,c(t)},a.onnegotiationneeded=(0,K.default)((function(){var e,t,n,r;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:return i.trys.push([0,3,4,5]),u=!0,[4,a.setLocalDescription()];case 1:return i.sent(),[4,f(a)];case 2:return t=i.sent(),null===(e=o.signal)||void 0===e||e.call(o,t),[3,5];case 3:return n=i.sent(),null===(r=o.error)||void 0===r||r.call(o,n),[3,5];case 4:return u=!1,[7];case 5:return[2]}}))})),a.onconnectionstatechange=function(){var e;["disconnected","failed","closed"].includes(a.connectionState)&&(null===(e=o.close)||void 0===e||e.call(o))},a.ontrack=function(e){var t,n;null===(t=o.track)||void 0===t||t.call(o,e.track,e.streams[0]),null===(n=o.stream)||void 0===n||n.call(o,e.streams[0])},a.onremovestream=function(e){var t;return null===(t=o.stream)||void 0===t?void 0:t.call(o,e.stream)},e&&(a.canTrickleIceCandidates||a.onnegotiationneeded()),{created:Date.now(),connection:a,get channel(){return l},get isDead(){return"closed"===a.connectionState},signal:function(t){return(0,K.default)((function(){var n,r,i,c,d;return(0,pe.__generator)(this,(function(h){switch(h.label){case 0:if("open"===(null==l?void 0:l.readyState)&&!(null===(n=t.sdp)||void 0===n?void 0:n.includes("a=rtpmap")))return[3,14];h.label=1;case 1:return h.trys.push([1,13,,14]),t.type!==Jx?[3,8]:u||"stable"!==a.signalingState&&!s?e?[2]:[4,Cx([a.setLocalDescription({type:"rollback"}),a.setRemoteDescription(t)])]:[3,3];case 2:return h.sent(),[3,5];case 3:return[4,a.setRemoteDescription(t)];case 4:h.sent(),h.label=5;case 5:return[4,a.setLocalDescription()];case 6:return h.sent(),[4,f(a)];case 7:return i=h.sent(),[2,(null===(r=o.signal)||void 0===r||r.call(o,i),i)];case 8:if("answer"!==t.type)return[3,12];s=!0,h.label=9;case 9:return h.trys.push([9,,11,12]),[4,a.setRemoteDescription(t)];case 10:return h.sent(),[3,12];case 11:return s=!1,[7];case 12:return[3,14];case 13:return c=h.sent(),null===(d=o.error)||void 0===d||d.call(o,c),[3,14];case 14:return[2]}}))}))()},sendData:function(e){return l.send(e)},destroy:function(){null==l||l.close(),a.close(),u=!1,s=!1},setHandlers:function(e){return Object.assign(o,e)},offerPromise:e?new Promise((function(e){return o.signal=function(t){t.type===Jx&&e(t)}})):Promise.resolve(),addStream:function(e){return e.getTracks().forEach((function(t){return a.addTrack(t,e)}))},removeStream:function(e){return a.getSenders().filter((function(t){return e.getTracks().includes(t.track)})).forEach((function(e){return a.removeTrack(e)}))},addTrack:function(e,t){return a.addTrack(e,t)},removeTrack:function(e){var t=a.getSenders().find((function(t){return t.track===e}));t&&a.removeTrack(t)},replaceTrack:function(e,t){var n=a.getSenders().find((function(t){return t.track===e}));if(n)return n.replaceTrack(t)}}},eC=(0,ce.default)(Ix(3,(function(e,t){return"stun:stun".concat(t||"",".l.google.com:19302")}))).concat(["stun:stun.cloudflare.com:3478"]).map((function(e){return{urls:e}})),tC=Object.getPrototypeOf(Uint8Array),nC=16369,rC=255,iC="bufferedamountlow",aC=function(e){return"@_"+e},oC=function(e){return"/".concat(Ax,"-").concat(e,"/0/msg/json")},uC=function(e,t,n){return e.lightPush.send(e.createEncoder({contentTopic:oC(t),ephemeral:!0}),{payload:Ux(n)},{autoRetry:!0})},sC=function(e){var t,n,r,i,a=e.init,o=e.subscribe,u=e.announce,s={},l=!1;return function(e,c,f){var d,h,I=e.appId;if(null===(h=s[I])||void 0===h?void 0:h[c])return s[I][c];var x={},C={},T=Bx(Ax,I,c),P=Xx(T),R=Xx(Bx(T,xx)),L=function(){var e=(0,K.default)((function(e,t,n){var r,i,a;return(0,pe.__generator)(this,(function(o){switch(o.label){case 0:return i=(r=crypto.subtle).importKey,a=["raw"],[4,crypto.subtle.digest({name:"SHA-256"},Ux("".concat(e,":").concat(t,":").concat(n)))];case 1:return[2,i.apply(r,a.concat([o.sent(),{name:Wx},!1,["encrypt","decrypt"]]))]}}))}));return function(t,n,r){return e.apply(this,arguments)}}()(e.password||"",I,c),D=function(e){return function(){var t=(0,K.default)((function(t){var n;return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return n={type:t.type},[4,e(L,t.sdp)];case 1:return[2,(n.sdp=r.sent(),n)]}}))}));return function(e){return t.apply(this,arguments)}}()},M=D(Zx),N=D(Yx),O=function(){return $x(!0,e)},U=function(e,t,n){var r;C[t]?C[t]!==e&&e.destroy():(C[t]=e,G(e,t),null===(r=x[t])||void 0===r||r.forEach((function(e,t){t!==n&&e.destroy()})),delete x[t])},F=function(e,t){C[t]===e&&delete C[t]},B=function(e){return(d=n).push.apply(d,(0,ce.default)(Ix(e,O))),Cx(n.splice(0,e).map((function(e){return e.offerPromise.then(N).then((function(t){return{peer:e,offer:t}}))})))},q=function(t,n){return null==f?void 0:f({error:"incorrect password (".concat(e.password,") when decrypting ").concat(n),appId:I,peerId:t,roomId:c})},z=function(t){return function(){var n=(0,K.default)((function(n,r,i){var a,o,u,s,l,c,f,d,h,v,p,g,y,m,b,w,k,S,A,I,L,D,O,z,j,K;return(0,pe.__generator)(this,(function(H){switch(H.label){case 0:return[4,Cx([P,R])];case 1:if(a=se.default.apply(void 0,[H.sent(),2]),o=a[0],u=a[1],n!==o&&n!==u)return[2];if(s="string"==typeof r?zx(r):r,l=s.peerId,c=s.offer,f=s.answer,d=s.peer,l===xx||C[l])return[3,16];if(l&&!c&&!f)return[3,14];if(!c)return[3,8];if((null===(h=x[l])||void 0===h?void 0:h[t])&&xx>l)return[2];(v=$x(!1,e)).setHandlers({connect:function(){return U(v,l,t)},close:function(){return F(v,l)}}),H.label=2;case 2:return H.trys.push([2,4,,5]),[4,M(c)];case 3:return p=H.sent(),[3,5];case 4:return H.sent(),[2,void q(l,"offer")];case 5:return v.isDead?[2]:[4,Cx([Xx(Bx(T,l)),v.signal(p)])];case 6:return g=se.default.apply(void 0,[H.sent(),2]),y=g[0],m=g[1],b=[y],w={peerId:xx},[4,N(m)];case 7:return i.apply(void 0,b.concat([qx.apply(void 0,[(w.answer=H.sent(),w)])])),[3,13];case 8:if(!f)return[3,13];H.label=9;case 9:return H.trys.push([9,11,,12]),[4,M(f)];case 10:return k=H.sent(),[3,12];case 11:return H.sent(),[2,void q(l,"answer")];case 12:d?(d.setHandlers({connect:function(){return U(d,l,t)},close:function(){return F(d,l)}}),d.signal(k)):(A=null===(S=x[l])||void 0===S?void 0:S[t])&&!A.isDead&&A.signal(k),H.label=13;case 13:return[3,16];case 14:return(null===(I=x[l])||void 0===I?void 0:I[t])?[2]:[4,Cx([B(1),Xx(Bx(T,l))])];case 15:L=se.default.apply(void 0,[H.sent(),2]),D=(0,se.default)(L[0],1),O=D[0],z=O.peer,j=O.offer,K=L[1],(_=x)[E=l]||(_[E]=[]),x[l][t]=z,setTimeout((function(){return function(e,t){var n;if(!C[e]){var r=null===(n=x[e])||void 0===n?void 0:n[t];r&&(delete x[e][t],r.destroy())}}(l,t)}),.9*V[t]),z.setHandlers({connect:function(){return U(z,l,t)},close:function(){return F(z,l)}}),i(K,qx({peerId:xx,offer:j})),H.label=16;case 16:return[2]}}))}));return function(e,t,r){return n.apply(this,arguments)}}()};if(!e)throw Mx("requires a config map as the first argument");if(!I&&!e.firebaseApp)throw Mx("config map is missing appId field");if(!c)throw Mx("roomId argument required");if(!l){var j=a(e);n=Ix(20,O),t=Array.isArray(j)?j:[j],l=!0,r=setInterval((function(){return n=n.filter((function(e){var t=Date.now()-e.created<57333;return t||e.destroy(),t}))}),59052.99),i=e.manualRelayReconnection?Dx:function(){if(Tx){var e=new AbortController;return addEventListener("online",Hx,{signal:e.signal}),addEventListener("offline",Vx,{signal:e.signal}),function(){return e.abort()}}return Dx}()}var V=t.map((function(){return 5333})),H=[],W=t.map(function(){var e=(0,K.default)((function(e,t){var n;return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return[4,e];case 1:return n=[r.sent()],[4,P];case 2:return n=n.concat(r.sent()),[4,R];case 3:return[2,o.apply(void 0,n.concat([r.sent(),z(t),B]))]}}))}));return function(t,n){return e.apply(this,arguments)}}());Cx([P,R]).then((function(e){var n=(0,se.default)(e,2),r=n[0],i=n[1],a=function(){var e=(0,K.default)((function(e,t){var n;return(0,pe.__generator)(this,(function(o){switch(o.label){case 0:return[4,u(e,r,i)];case 1:return"number"==typeof(n=o.sent())&&(V[t]=n),H[t]=setTimeout((function(){return a(e,t)}),V[t]),[2]}}))}));return function(t,n){return e.apply(this,arguments)}}();W.forEach(function(){var e=(0,K.default)((function(e,n){return(0,pe.__generator)(this,(function(r){switch(r.label){case 0:return[4,e];case 1:return r.sent(),[4,t[n]];case 2:return a.apply(void 0,[r.sent(),n]),[2]}}))}));return function(t,n){return e.apply(this,arguments)}}())}));var G=Dx;return(S=s)[A=I]||(S[A]={}),s[I][c]=function(e,t,n){var r={},i={},a={},o={},u={},s={},l={},c={onPeerJoin:Dx,onPeerLeave:Dx,onPeerStream:Dx,onPeerTrack:Dx},f=function(e,t){return(e?Array.isArray(e)?e:[e]:Lx(r)).flatMap((function(e){var n=r[e];return n?t(e,n):(console.warn("".concat(Ax,": no peer with id ").concat(e," found")),[])}))},d=function(e){r[e]&&(r[e].destroy(),delete r[e],delete o[e],delete u[e],c.onPeerLeave(e),t(e))},h=function(e){if(i[e])return a[e];if(!e)throw Mx("action type argument is required");var t=Ux(e);if(t.byteLength>12)throw Mx('action type string "'.concat(e,'" (').concat(t.byteLength,"b) exceeds byte limit (12). Hint: choose a shorter name."));var n=new Uint8Array(12);n.set(t);var o=0;return i[e]={onComplete:Dx,onProgress:Dx,setOnComplete:function(t){return i[e]=(0,oe.default)((0,ae.default)({},i[e]),{onComplete:t})},setOnProgress:function(t){return i[e]=(0,oe.default)((0,ae.default)({},i[e]),{onProgress:t})},send:function(e,t,i,a){return(0,K.default)((function(){var u,s,l,c,d,h,v,p,g,y,m;return(0,pe.__generator)(this,(function(b){switch(b.label){case 0:if(i&&"object"!=typeof i)throw Mx("action meta argument must be an object");if("undefined"===(u=void 0===e?"undefined":(0,fe.default)(e)))throw Mx("action data cannot be undefined");if(s="string"!==u,l=e instanceof Blob,c=l||e instanceof ArrayBuffer||e instanceof tC,i&&!c)throw Mx("action meta argument can only be used with binary data");return c?(y=Uint8Array.bind,l?[4,e.arrayBuffer()]:[3,2]):[3,4];case 1:return m=b.sent(),[3,3];case 2:m=e,b.label=3;case 3:return g=new(y.apply(Uint8Array,[void 0,m])),[3,5];case 4:g=Ux(s?qx(e):e),b.label=5;case 5:return d=g,h=i?Ux(qx(i)):null,v=Math.ceil(d.byteLength/nC)+(i?1:0)||1,p=Ix(v,(function(e,t){var r=t===v-1,a=i&&0===t,u=new Uint8Array(15+(a?h.byteLength:r?d.byteLength-nC*(v-(i?2:1)):nC));return u.set(n),u.set([o],12),u.set([r|a<<1|c<<2|s<<3],13),u.set([Math.round((t+1)/v*rC)],14),u.set(i?a?h:d.subarray((t-1)*nC,t*nC):d.subarray(t*nC,(t+1)*nC),15),u})),[2,(o=o+1&rC,Cx(f(t,function(){var e=(0,K.default)((function(e,t){var n,o,u;return(0,pe.__generator)(this,(function(s){switch(s.label){case 0:n=t.channel,o=0,s.label=1;case 1:return o<v?(u=p[o],n.bufferedAmount>n.bufferedAmountLowThreshold?[4,new Promise((function(e){var t=function(){n.removeEventListener(iC,t),e()};n.addEventListener(iC,t)}))]:[3,3]):[3,5];case 2:s.sent(),s.label=3;case 3:if(!r[e])return[3,5];t.sendData(u),o++,null==a||a(u[14]/rC,e,i),s.label=4;case 4:return[3,1];case 5:return[2]}}))}));return function(t,n){return e.apply(this,arguments)}}())))]}}))}))()}},(v=a)[p=e]||(v[p]=[i[e].send,i[e].setOnComplete,i[e].setOnProgress])},_=function(){var e=(0,K.default)((function(){return(0,pe.__generator)(this,(function(e){switch(e.label){case 0:return[4,B("")];case 1:return e.sent(),[4,new Promise((function(e){return setTimeout(e,99)}))];case 2:return e.sent(),Px(r).forEach((function(e){var t=(0,se.default)(e,2),n=t[0];t[1].destroy(),delete r[n]})),n(),[2]}}))}));return function(){return e.apply(this,arguments)}}(),E=(0,se.default)(h(aC("ping")),2),S=E[0],A=E[1],I=(0,se.default)(h(aC("pong")),2),x=I[0],C=I[1],T=(0,se.default)(h(aC("signal")),2),P=T[0],R=T[1],L=(0,se.default)(h(aC("stream")),2),D=L[0],M=L[1],N=(0,se.default)(h(aC("track")),2),O=N[0],U=N[1],F=(0,se.default)(h(aC("leave")),2),B=F[0],q=F[1];return e((function(e,t){r[t]||(r[t]=e,e.setHandlers({data:function(e){return function(e,t){var n=new Uint8Array(t),r=Fx(n.subarray(0,12)).replaceAll("\0",""),a=(0,se.default)(n.subarray(12,13),1)[0],u=(0,se.default)(n.subarray(13,14),1)[0],s=(0,se.default)(n.subarray(14,15),1)[0],l=n.subarray(15),c=!!(1&u),f=!!(2&u),d=!!(4&u),h=!!(8&u);if(i[r]){(g=o)[y=e]||(g[y]={}),(m=o[e])[b=r]||(m[b]={});var v=(w=o[e][r])[k=a]||(w[k]={chunks:[]});if(f?v.meta=zx(Fx(l)):v.chunks.push(l),i[r].onProgress(s/rC,e,v.meta),c){var p=new Uint8Array(v.chunks.reduce((function(e,t){return e+t.byteLength}),0));if(v.chunks.reduce((function(e,t){return p.set(t,e),e+t.byteLength}),0),delete o[e][r][a],d)i[r].onComplete(p,e,v.meta);else{var _=Fx(p);i[r].onComplete(h?zx(_):_,e)}}}else console.warn("".concat(Ax,": received message with unregistered type (").concat(r,")"))}(t,e)},stream:function(e){c.onPeerStream(e,t,s[t]),delete s[t]},track:function(e,n){c.onPeerTrack(e,n,t,l[t]),delete l[t]},signal:function(e){return P(e,t)},close:function(){return d(t)},error:function(e){console.error(e),d(t)}}),c.onPeerJoin(t))})),A((function(e,t){return x("",t)})),C((function(e,t){var n;null===(n=u[t])||void 0===n||n.call(u),delete u[t]})),R((function(e,t){var n;return null===(n=r[t])||void 0===n?void 0:n.signal(e)})),M((function(e,t){return s[t]=e})),U((function(e,t){return l[t]=e})),q((function(e,t){return d(t)})),Tx&&addEventListener("beforeunload",_),{makeAction:h,leave:_,ping:function(e){return(0,K.default)((function(){var t;return(0,pe.__generator)(this,(function(n){switch(n.label){case 0:if(!e)throw Mx("ping() must be called with target peer ID");return t=Date.now(),S("",e),[4,new Promise((function(t){return u[e]=t}))];case 1:return[2,(n.sent(),Date.now()-t)]}}))}))()},getPeers:function(){return Rx(Px(r).map((function(e){var t=(0,se.default)(e,2);return[t[0],t[1].connection]})))},addStream:function(e,t,n){return f(t,function(){var t=(0,K.default)((function(t,r){return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:return n?[4,D(n,t)]:[3,2];case 1:i.sent(),i.label=2;case 2:return r.addStream(e),[2]}}))}));return function(e,n){return t.apply(this,arguments)}}())},removeStream:function(e,t){return f(t,(function(t,n){return n.removeStream(e)}))},addTrack:function(e,t,n,r){return f(n,function(){var n=(0,K.default)((function(n,i){return(0,pe.__generator)(this,(function(a){switch(a.label){case 0:return r?[4,O(r,n)]:[3,2];case 1:a.sent(),a.label=2;case 2:return i.addTrack(e,t),[2]}}))}));return function(e,t){return n.apply(this,arguments)}}())},removeTrack:function(e,t){return f(t,(function(t,n){return n.removeTrack(e)}))},replaceTrack:function(e,t,n,r){return f(n,function(){var n=(0,K.default)((function(n,i){return(0,pe.__generator)(this,(function(a){switch(a.label){case 0:return r?[4,O(r,n)]:[3,2];case 1:a.sent(),a.label=2;case 2:return i.replaceTrack(e,t),[2]}}))}));return function(e,t){return n.apply(this,arguments)}}())},onPeerJoin:function(e){return c.onPeerJoin=e},onPeerLeave:function(e){return c.onPeerLeave=e},onPeerStream:function(e){return c.onPeerStream=e},onPeerTrack:function(e){return c.onPeerTrack=e}}}((function(e){return G=e}),(function(e){return delete C[e]}),(function(){delete s[I][c],H.forEach(clearTimeout),W.forEach(function(){var e=(0,K.default)((function(e){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return[4,e];case 1:return[2,t.sent()()]}}))}));return function(t){return e.apply(this,arguments)}}()),clearInterval(r),i(),l=!1}))}}({init:function(){return(0,K.default)((function(){var e,t,n,r=arguments;return(0,pe.__generator)(this,(function(i){switch(i.label){case 0:return[4,MI(e=r.length>0&&void 0!==r[0]?r[0]:{})];case 1:return t=i.sent(),n=new dd(e,t,{store:!0,lightpush:!0,filter:!0}),!1!==(null==e?void 0:e.autoStart)?[4,n.start()]:[3,3];case 2:i.sent(),i.label=3;case 3:return[2,n]}}))}))({defaultBootstrap:!0,discovery:{dns:!0,peerExchange:!0,peerCache:!0}}).then(function(){var e=(0,K.default)((function(e){return(0,pe.__generator)(this,(function(t){switch(t.label){case 0:return[4,e.start()];case 1:return t.sent(),[4,e.waitForPeers()];case 2:return[2,(t.sent(),e)]}}))}));return function(t){return e.apply(this,arguments)}}())},subscribe:function(e,t,n,r){return(0,K.default)((function(){var i;return(0,pe.__generator)(this,(function(a){switch(a.label){case 0:return[4,Cx([t,n].map((function(t){var n=e.createDecoder({contentTopic:oC(t)});return e.filter.subscribe(n,function(t){return function(n){n.payload&&r(t,Fx(n.payload),(function(t,n){return uC(e,t,n)}))}}(t)),function(){return e.filter.unsubscribe(n)}})))];case 1:return i=a.sent(),[2,function(){return i.forEach((function(e){return e()}))}]}}))}))()},announce:function(e,t){return uC(e,t,qx({peerId:xx}))}})})),n.register("1PH9R",(function(e,n){function r(e,t){var n={},r=!1;function i(n,i){return r=!0,i=new Promise((function(t){t(e[n](i))})),{done:!1,value:t(i)}}return"function"==typeof Symbol&&Symbol.iterator&&(n[Symbol.iterator]=function(){return this}),n.next=function(e){return r?(r=!1,e):i("next",e)},"function"==typeof e.throw&&(n.throw=function(e){if(r)throw r=!1,e;return i("throw",e)}),"function"==typeof e.return&&(n.return=function(e){return i("return",e)}),n}t(e.exports,"default",(function(){return r}))})),n.register("3u2tY",(function(e,n){function r(e){var t,n,r,a=2;for("undefined"!=typeof Symbol&&(n=Symbol.asyncIterator,r=Symbol.iterator);a--;){if(n&&null!=(t=e[n]))return t.call(e);if(r&&null!=(t=e[r]))return new i(t.call(e));n="@@asyncIterator",r="@@iterator"}throw new TypeError("Object is not async iterable")}function i(e){function t(e){if(Object(e)!==e)return Promise.reject(new TypeError(e+" is not an object."));var t=e.done;return Promise.resolve(e.value).then((function(e){return{value:e,done:t}}))}return i=function(e){this.s=e,this.n=e.next},i.prototype={s:null,n:null,next:function(){return t(this.n.apply(this.s,arguments))},return:function(e){var n=this.s.return;return void 0===n?Promise.resolve({value:e,done:!0}):t(n.apply(this.s,arguments))},throw:function(e){var n=this.s.return;return void 0===n?Promise.reject(e):t(n.apply(this.s,arguments))}},new i(e)}t(e.exports,"default",(function(){return r}))})),n.register("9yQwa",(function(e,r){t(e.exports,"default",(function(){return a}));var i=n("kRxx3");function a(e){return new(0,i.default)(e)}})),n.register("kRxx3",(function(e,n){function r(e){this.wrapped=e}t(e.exports,"default",(function(){return r}))})),n.register("8qpTe",(function(e,r){t(e.exports,"default",(function(){return o}));var i=n("k7SOi"),a=n("laD7J");function o(e,t){var n=(0,i.default)(e,t,"get");return(0,a.default)(e,n)}})),n.register("k7SOi",(function(e,n){function r(e,t,n){if(!t.has(e))throw new TypeError("attempted to "+n+" private field on non-instance");return t.get(e)}t(e.exports,"default",(function(){return r}))})),n.register("laD7J",(function(e,n){function r(e,t){return t.get?t.get.call(e):t.value}t(e.exports,"default",(function(){return r}))})),n.register("gwSkA",(function(e,r){t(e.exports,"default",(function(){return a}));var i=n("hv1Iw");function a(e,t,n){(0,i.default)(e,t),t.set(e,n)}})),n.register("hv1Iw",(function(e,n){function r(e,t){if(t.has(e))throw new TypeError("Cannot initialize the same private elements twice on an object")}t(e.exports,"default",(function(){return r}))})),n.register("7ukXT",(function(e,r){t(e.exports,"default",(function(){return o}));var i=n("k7SOi"),a=n("c4HTA");function o(e,t,n){var r=(0,i.default)(e,t,"set");return(0,a.default)(e,r,n),n}})),n.register("c4HTA",(function(e,n){function r(e,t,n){if(t.set)t.set.call(e,n);else{if(!t.writable)throw new TypeError("attempted to set read only private field");t.value=n}}t(e.exports,"default",(function(){return r}))})),n.register("8TzS1",(function(e,r){t(e.exports,"default",(function(){return o}));var i=n("k7SOi"),a=n("Fzx8d");function o(e,t){var n=(0,i.default)(e,t,"update");return(0,a.default)(e,n)}})),n.register("Fzx8d",(function(e,n){function r(e,t){if(t.set){if(!t.get)throw new TypeError("attempted to read set only private field");return"__destrWrapper"in t||(t.__destrWrapper={set value(n){t.set.call(e,n)},get value(){return t.get.call(e)}}),t.__destrWrapper}if(!t.writable)throw new TypeError("attempted to set read only private field");return t}t(e.exports,"default",(function(){return r}))})),n.register("aFAb1",(function(e,n){function r(e,t,n){if(!t.has(e))throw new TypeError("attempted to get private field on non-instance");return n}t(e.exports,"default",(function(){return r}))})),n.register("kw2NY",(function(e,r){t(e.exports,"default",(function(){return a}));var i=n("hv1Iw");function a(e,t){(0,i.default)(e,t),t.add(e)}})),n.register("W5eu1",(function(e,n){function r(e,t){for(var n in t){(a=t[n]).configurable=a.enumerable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,n,a)}if(Object.getOwnPropertySymbols)for(var r=Object.getOwnPropertySymbols(t),i=0;i<r.length;i++){var a,o=r[i];(a=t[o]).configurable=a.enumerable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,o,a)}return e}t(e.exports,"default",(function(){return r}))})),n.register("iPOEm",(function(e,r){t(e.exports,"default",(function(){return s}));var i=n("eqVIU"),a=n("bMo4c"),o=n("9Xv6W"),u=n("ecfGL");function s(e){return(0,i.default)(e)||(0,a.default)(e)||(0,u.default)(e)||(0,o.default)()}})),n.register("hXL9f",(function(e,r){t(e.exports,"default",(function(){return a}));var i=n("4pMaJ");function a(e){return function(){return new(0,i.default)(e.apply(this,arguments))}}})),n.register("4pMaJ",(function(e,r){t(e.exports,"default",(function(){return a}));var i=n("kRxx3");function a(e){var t,n;function r(t,n){try{var o=e[t](n),u=o.value,s=u instanceof i.default;Promise.resolve(s?u.wrapped:u).then((function(e){s?r("next",e):a(o.done?"return":"normal",e)}),(function(e){r("throw",e)}))}catch(e){a("throw",e)}}function a(e,i){switch(e){case"return":t.resolve({value:i,done:!0});break;case"throw":t.reject(i);break;default:t.resolve({value:i,done:!1})}(t=t.next)?r(t.key,t.arg):n=null}this._invoke=function(e,i){return new Promise((function(a,o){var u={key:e,arg:i,resolve:a,reject:o,next:null};n?n=n.next=u:(t=n=u,r(e,i))}))},"function"!=typeof e.return&&(this.return=void 0)}"function"==typeof Symbol&&Symbol.asyncIterator&&(a.prototype[Symbol.asyncIterator]=function(){return this}),a.prototype.next=function(e){return this._invoke("next",e)},a.prototype.throw=function(e){return this._invoke("throw",e)},a.prototype.return=function(e){return this._invoke("return",e)}}))}();