@liascript/exporter
Version:
A generic exporter for LiaScript
2 lines • 105 kB
JavaScript
!function(){var e=("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{}).parcelRequire55a5;e.register("1UDrq",(function(t,n){var r,i;r=t.exports,i=function(){return Jr},Object.defineProperty(r,"joinRoom",{get:i,set:undefined,enumerable:!0,configurable:!0});var a,o,u,s,c,l,f,d,h,p,v,y,g=e("f1evb"),m=e("hnmIs"),_=e("9Klpk"),b=e("3bWnf"),w=e("eT7f3"),E=e("kb0qF"),S=e("bgoEC"),k=e("7j4mF"),C=e("1Qswt"),x=e("5ENmm"),A=e("6Wo7Q"),T=e("rJmE6"),R=e("fSF4h"),I=e("bWNdT"),N=e("32Euv"),B=e("84cK9");function O(e){if(!Number.isSafeInteger(e)||e<0)throw Error("positive integer expected, not "+e)}function L(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(!((i=e)instanceof Uint8Array||null!=i&&"object"==typeof i&&"Uint8Array"===i.constructor.name))throw Error("Uint8Array expected");var i;if(n.length>0&&!n.includes(e.length))throw Error("Uint8Array expected of length ".concat(n,", not of length=").concat(e.length))}function P(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")}var F="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0,D=function(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)},U=function(e,t){return e<<32-t|e>>>t};function q(e){return"string"==typeof e&&(e=function(e){if("string"!=typeof e)throw Error("utf8ToBytes expected string, got "+(void 0===e?"undefined":(0,T.default)(e)));return new Uint8Array((new TextEncoder).encode(e))}(e)),L(e),e}new Uint8Array(new Uint32Array([287454020]).buffer)[0];var M=function(){"use strict";function e(){(0,_.default)(this,e)}return(0,b.default)(e,[{key:"clone",value:function(){return this._cloneInto()}}]),e}();function j(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:32;if(F&&"function"==typeof F.getRandomValues)return F.getRandomValues(new Uint8Array(e));throw Error("crypto.getRandomValues must be defined")}var H=function(e,t,n){return e&t^e&n^t&n},z=function(e){"use strict";(0,E.default)(n,e);var t=(0,I.default)(n);function n(e,r,i,a){var o;return(0,_.default)(this,n),(o=t.call(this)).blockLen=e,o.outputLen=r,o.padOffset=i,o.isLE=a,o.finished=!1,o.length=0,o.pos=0,o.destroyed=!1,o.buffer=new Uint8Array(e),o.view=D(o.buffer),(0,C.default)(o)}return(0,b.default)(n,[{key:"update",value:function(e){P(this);for(var t=this,n=t.view,r=t.buffer,i=t.blockLen,a=(e=q(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=D(e);i<=a-o;o+=i)this.process(s,o)}return this.length+=e.length,this.roundClean(),this}},{key:"digestInto",value:function(e){P(this),function(e,t){L(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,this.buffer.subarray(o).fill(0),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,c=r?0:4;e.setUint32(t+s,o,r),e.setUint32(t+c,u,r)}(r,i-8,BigInt(8*this.length),a),this.process(r,0);var s=D(e),c=this.outputLen;if(c%4)throw Error("_sha2: outputLen should be aligned to 32bit");var l=c/4,f=this.get();if(l>f.length)throw Error("_sha2: outputLen bigger than state");for(var d=0;d<l;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,A.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.length=a,e.pos=s,e.finished=o,e.destroyed=u,a%r&&e.buffer.set(i),e}}]),n}(M),W=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),K=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),V=new Uint32Array(64),Z=function(e){"use strict";(0,E.default)(n,e);var t=(0,I.default)(n);function n(){var e;return(0,_.default)(this,n),(e=t.call(this,64,32,8,!1)).A=0|K[0],e.B=0|K[1],e.C=0|K[2],e.D=0|K[3],e.E=0|K[4],e.F=0|K[5],e.G=0|K[6],e.H=0|K[7],(0,C.default)(e)}return(0,b.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)V[n]=e.getUint32(t,!1);for(var r=16;r<64;r++){var i=V[r-15],a=V[r-2],o=U(i,7)^U(i,18)^i>>>3,u=U(a,17)^U(a,19)^a>>>10;V[r]=u+V[r-7]+o+V[r-16]|0}for(var s,c=this,l=c.A,f=c.B,d=c.C,h=c.D,p=c.E,v=c.F,y=c.G,g=c.H,m=0;m<64;m++){var _=g+(U(p,6)^U(p,11)^U(p,25))+((s=p)&v^~s&y)+W[m]+V[m]|0,b=(U(l,2)^U(l,13)^U(l,22))+H(l,f,d)|0;g=y,y=v,v=p,p=h+_|0,h=d,d=f,f=l,l=_+b|0}l=l+this.A|0,f=f+this.B|0,d=d+this.C|0,h=h+this.D|0,p=p+this.E|0,v=v+this.F|0,y=y+this.G|0,g=g+this.H|0,this.set(l,f,d,h,p,v,y,g)}},{key:"roundClean",value:function(){V.fill(0)}},{key:"destroy",value:function(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}]),n}(z),Y=function(e){var t=function(t){return e().update(q(t)).digest()},n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=function(){return e()},t}((function(){return new Z})),G=function(e){"use strict";(0,E.default)(n,e);var t=(0,I.default)(n);function n(e,r){var i;(0,_.default)(this,n),(i=t.call(this)).finished=!1,i.destroyed=!1,function(e){if("function"!=typeof e||"function"!=typeof e.create)throw Error("Hash should be wrapped by utils.wrapConstructor");O(e.outputLen),O(e.blockLen)}(e);var a=q(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 c=0;c<u.length;c++)u[c]^=106;return i.oHash.update(u),u.fill(0),(0,C.default)(i)}return(0,b.default)(n,[{key:"update",value:function(e){return P(this),this.iHash.update(e),this}},{key:"digestInto",value:function(e){P(this),L(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:"destroy",value:function(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}]),n}(M),J=function(e,t,n){return new G(e,t).update(n).digest()};J.create=function(e,t){return new G(e,t)};var $=BigInt(0),Q=BigInt(1),X=BigInt(2);function ee(e){return e instanceof Uint8Array||null!=e&&"object"==typeof e&&"Uint8Array"===e.constructor.name}function te(e){if(!ee(e))throw Error("Uint8Array expected")}var ne=Array.from({length:256},(function(e,t){return t.toString(16).padStart(2,"0")}));function re(e){te(e);for(var t="",n=0;n<e.length;n++)t+=ne[e[n]];return t}function ie(e){var t=e.toString(16);return 1&t.length?"0"+t:t}function ae(e){if("string"!=typeof e)throw Error("hex string expected, got "+(void 0===e?"undefined":(0,T.default)(e)));return BigInt(""===e?"0":"0x"+e)}var oe={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function ue(e){return e>=oe._0&&e<=oe._9?e-oe._0:e>=oe._A&&e<=oe._F?e-(oe._A-10):e>=oe._a&&e<=oe._f?e-(oe._a-10):void 0}function se(e){if("string"!=typeof e)throw Error("hex string expected, got "+(void 0===e?"undefined":(0,T.default)(e)));var t=e.length,n=t/2;if(t%2)throw Error("padded 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=ue(e.charCodeAt(a)),u=ue(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 ce(e){return ae(re(e))}function le(e){return te(e),ae(re(Uint8Array.from(e).reverse()))}function fe(e,t){return se(e.toString(16).padStart(2*t,"0"))}function de(e,t){return fe(e,t).reverse()}function he(e,t,n){var r;if("string"==typeof t)try{r=se(t)}catch(n){throw Error("".concat(e,' must be valid hex string, got "').concat(t,'". Cause: ').concat(n))}else{if(!ee(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("".concat(e," expected ").concat(n," bytes, got ").concat(i));return r}function pe(){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];te(a),r+=a.length}for(var o=new Uint8Array(r),u=0,s=0;u<t.length;u++){var c=t[u];o.set(c,s),s+=c.length}return o}var ve=function(e){return(X<<BigInt(e-1))-Q},ye=function(e){return new Uint8Array(e)},ge=function(e){return Uint8Array.from(e)};function me(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=ye(e),i=ye(e),a=0,o=function(){r.fill(1),i.fill(0),a=0},u=function(){for(var e=arguments.length,t=new Array(e),a=0;a<e;a++)t[a]=arguments[a];return n.apply(void 0,[i,r].concat((0,A.default)(t)))},s=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:ye();i=u(ge([0]),e),r=u(),0!==e.length&&(i=u(ge([1]),e),r=u())},c=function(){if(a++>=1e3)throw Error("drbg: tried 1000 values");for(var e=0,n=[];e<t;){var i=(r=u()).slice();n.push(i),e+=r.length}return pe.apply(void 0,(0,A.default)(n))};return function(e,t){var n;for(o(),s(e);!(n=t(c()));)s();return o(),n}}var _e={bigint:function(e){return"bigint"==(void 0===e?"undefined":(0,T.default)(e))},function:function(e){return"function"==typeof e},boolean:function(e){return"boolean"==typeof e},string:function(e){return"string"==typeof e},stringOrUint8Array:function(e){return"string"==typeof e||ee(e)},isSafeInteger:function(e){return Number.isSafeInteger(e)},array:function(e){return Array.isArray(e)},field:function(e,t){return t.Fp.isValid(e)},hash:function(e){return"function"==typeof e&&Number.isSafeInteger(e.outputLen)}};function be(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=function(t,n,r){var i=_e[n];if("function"!=typeof i)throw Error('Invalid validator "'.concat(n,'", expected function'));var a=e[t];if(!(r&&void 0===a||i(a,e)))throw Error("Invalid param ".concat(t+"","=").concat(a," (").concat(void 0===a?"undefined":(0,T.default)(a),"), expected ").concat(n))},i=!0,a=!1,o=void 0;try{for(var u,s=Object.entries(t)[Symbol.iterator]();!(i=(u=s.next()).done);i=!0){var c=(0,x.default)(u.value,2);r(c[0],c[1],!1)}}catch(e){a=!0,o=e}finally{try{i||null==s.return||s.return()}finally{if(a)throw o}}var l=!0,f=!1,d=void 0;try{for(var h,p=Object.entries(n)[Symbol.iterator]();!(l=(h=p.next()).done);l=!0){var v=(0,x.default)(h.value,2);r(v[0],v[1],!0)}}catch(e){f=!0,d=e}finally{try{l||null==p.return||p.return()}finally{if(f)throw d}}return e}var we=Object.freeze({__proto__:null,abytes:te,bitGet:function(e,t){return e>>BigInt(t)&Q},bitLen:function(e){var t;for(t=0;e>$;e>>=Q,t+=1);return t},bitMask:ve,bitSet:function(e,t,n){return e|(n?Q:$)<<BigInt(t)},bytesToHex:re,bytesToNumberBE:ce,bytesToNumberLE:le,concatBytes:pe,createHmacDrbg:me,ensureBytes:he,equalBytes: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},hexToBytes:se,hexToNumber:ae,isBytes:ee,numberToBytesBE:fe,numberToBytesLE:de,numberToHexUnpadded:ie,numberToVarBytesBE:function(e){return se(ie(e))},utf8ToBytes:function(e){if("string"!=typeof e)throw Error("utf8ToBytes expected string, got "+(void 0===e?"undefined":(0,T.default)(e)));return new Uint8Array((new TextEncoder).encode(e))},validateObject:be}),Ee=BigInt(0),Se=BigInt(1),ke=BigInt(2),Ce=BigInt(3),xe=BigInt(4),Ae=BigInt(5),Te=BigInt(8);function Re(e,t){var n=e%t;return n>=Ee?n:t+n}function Ie(e,t,n){if(n<=Ee||t<Ee)throw Error("Expected power/modulo > 0");if(n===Se)return Ee;for(var r=Se;t>Ee;)t&Se&&(r=r*e%n),e=e*e%n,t>>=Se;return r}function Ne(e,t,n){for(var r=e;t-- >Ee;)r*=r,r%=n;return r}function Be(e,t){if(e===Ee||t<=Ee)throw Error("invert: expected positive integers, got n=".concat(e," mod=").concat(t));for(var n=Re(e,t),r=t,i=Ee,a=Se;n!==Ee;){var o=r%n,u=i-a*(r/n);r=n,n=o,i=a,a=u}if(r!==Se)throw Error("invert: does not exist");return Re(i,t)}BigInt(9),BigInt(16);var Oe=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Le(e,t){var n=void 0!==t?t:e.toString(2).length;return{nBitLength:n,nByteLength:Math.ceil(n/8)}}function Pe(e){if("bigint"!=(void 0===e?"undefined":(0,T.default)(e)))throw Error("field order must be bigint");var t=e.toString(2).length;return Math.ceil(t/8)}function Fe(e){var t=Pe(e);return t+Math.ceil(t/2)}var De,Ue=BigInt(0),qe=BigInt(1);function Me(e){return be(e.Fp,Oe.reduce((function(e,t){return e[t]="function",e}),{ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"})),be(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze((0,k.default)((0,S.default)({},Le(e.n,e.nBitLength),e),{p:e.Fp.ORDER}))}var je=we.bytesToNumberBE,He=we.hexToBytes,ze=(De={Err:function(e){"use strict";(0,E.default)(n,e);var t=(0,I.default)(n);function n(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return(0,_.default)(this,n),t.call(this,e)}return n}((0,R.default)(Error))},(0,w.default)(De,"_parseInt",(function(e){var t=ze.Err;if(e.length<2||2!==e[0])throw new t("Invalid signature integer tag");var n=e[1],r=e.subarray(2,n+2);if(!n||r.length!==n)throw new t("Invalid signature integer: wrong length");if(128&r[0])throw new t("Invalid signature integer: negative");if(0===r[0]&&!(128&r[1]))throw new t("Invalid signature integer: unnecessary leading zero");return{d:je(r),l:e.subarray(n+2)}})),(0,w.default)(De,"toSig",(function(e){var t=ze.Err,n="string"==typeof e?He(e):e;te(n);var r=n.length;if(r<2||48!=n[0])throw new t("Invalid signature tag");if(n[1]!==r-2)throw new t("Invalid signature: incorrect length");var i=ze._parseInt(n.subarray(2)),a=i.d,o=i.l,u=ze._parseInt(o),s=u.d;if(u.l.length)throw new t("Invalid signature: left bytes after parsing");return{r:a,s:s}})),(0,w.default)(De,"hexFromSig",(function(e){var t=function(e){return 8&Number.parseInt(e[0],16)?"00"+e:e},n=function(e){var t=e.toString(16);return 1&t.length?"0"+t:t},r=t(n(e.s)),i=t(n(e.r)),a=r.length/2,o=i.length/2,u=n(a),s=n(o);return"30".concat(n(o+a+4),"02").concat(s).concat(i,"02").concat(u).concat(r)})),De),We=BigInt(0),Ke=BigInt(1);BigInt(2);var Ve=BigInt(3);BigInt(4);var Ze=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Ye=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Ge=BigInt(1),Je=BigInt(2),$e=function(e,t){return(e+t/Je)/t};function Qe(e){var t=Ze,n=BigInt(3),r=BigInt(6),i=BigInt(11),a=BigInt(22),o=BigInt(23),u=BigInt(44),s=BigInt(88),c=e*e*e%t,l=c*c*e%t,f=Ne(l,n,t)*l%t,d=Ne(f,n,t)*l%t,h=Ne(d,Je,t)*c%t,p=Ne(h,i,t)*h%t,v=Ne(p,a,t)*p%t,y=Ne(v,u,t)*v%t,g=Ne(y,s,t)*y%t,m=Ne(g,u,t)*v%t,_=Ne(m,n,t)*l%t,b=Ne(_,o,t)*p%t,w=Ne(b,r,t)*c%t,E=Ne(w,Je,t);if(!Xe.eql(Xe.sqr(E),e))throw Error("Cannot find square root");return E}var Xe=function(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<=Ee)throw Error("Expected Field ORDER > 0, got "+e);var i=Le(e,t),a=i.nBitLength,o=i.nByteLength;if(o>2048)throw Error("Field lengths over 2048 bytes are not supported");var u=function(e){if(e%xe===Ce){var t=(e+Se)/xe;return function(e,n){var r=e.pow(n,t);if(!e.eql(e.sqr(r),n))throw Error("Cannot find square root");return r}}if(e%Te===Ae){var n=(e-Ae)/Te;return function(e,t){var r=e.mul(t,ke),i=e.pow(r,n),a=e.mul(t,i),o=e.mul(e.mul(a,ke),i),u=e.mul(a,e.sub(o,e.ONE));if(!e.eql(e.sqr(u),t))throw Error("Cannot find square root");return u}}return function(e){var t,n,r,i=(e-Se)/ke;for(t=e-Se,n=0;t%ke===Ee;t/=ke,n++);for(r=ke;r<e&&Ie(r,i,e)!==e-Se;r++);if(1===n){var a=(e+Se)/xe;return function(e,t){var n=e.pow(t,a);if(!e.eql(e.sqr(n),t))throw Error("Cannot find square root");return n}}var o=(t+Se)/ke;return function(e,a){if(e.pow(a,i)===e.neg(e.ONE))throw Error("Cannot find square root");for(var u=n,s=e.pow(e.mul(e.ONE,r),t),c=e.pow(a,o),l=e.pow(a,t);!e.eql(l,e.ONE);){if(e.eql(l,e.ZERO))return e.ZERO;for(var f=1,d=e.sqr(l);f<u&&!e.eql(d,e.ONE);f++)d=e.sqr(d);var h=e.pow(s,Se<<BigInt(u-f-1));s=e.sqr(h),c=e.mul(c,h),l=e.mul(l,s),u=f}return c}}(e)}(e),s=Object.freeze({ORDER:e,BITS:a,BYTES:o,MASK:ve(a),ZERO:Ee,ONE:Se,create:function(t){return Re(t,e)},isValid:function(t){if("bigint"!=(void 0===t?"undefined":(0,T.default)(t)))throw Error("Invalid field element: expected bigint, got "+(void 0===t?"undefined":(0,T.default)(t)));return Ee<=t&&t<e},is0:function(e){return e===Ee},isOdd:function(e){return(e&Se)===Se},neg:function(t){return Re(-t,e)},eql:function(e,t){return e===t},sqr:function(t){return Re(t*t,e)},add:function(t,n){return Re(t+n,e)},sub:function(t,n){return Re(t-n,e)},mul:function(t,n){return Re(t*n,e)},pow:function(e,t){return function(e,t,n){if(n<Ee)throw Error("Expected power > 0");if(n===Ee)return e.ONE;if(n===Se)return t;for(var r=e.ONE,i=t;n>Ee;)n&Se&&(r=e.mul(r,i)),i=e.sqr(i),n>>=Se;return r}(s,e,t)},div:function(t,n){return Re(t*Be(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 Be(t,e)},sqrt:r.sqrt||function(e){return u(s,e)},invertBatch:function(e){return function(e,t){var n=Array(t.length),r=t.reduce((function(t,r,i){return e.is0(r)?t:(n[i]=t,e.mul(t,r))}),e.ONE),i=e.inv(r);return t.reduceRight((function(t,r,i){return e.is0(r)?t:(n[i]=e.mul(t,n[i]),e.mul(t,r))}),i),n}(s,e)},cmov:function(e,t,n){return n?t:e},toBytes:function(e){return n?de(e,o):fe(e,o)},fromBytes:function(e){if(e.length!==o)throw Error("Fp.fromBytes: expected ".concat(o,", got ").concat(e.length));return n?le(e):ce(e)}});return Object.freeze(s)}(Ze,void 0,void 0,{sqrt:Qe}),et=function(e,t){var n=function(t){return function(e){var t=function(e){var t=Me(e);return be(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze((0,S.default)({lowS:!0},t))}(e),n=t.Fp,r=t.n,i=n.BYTES+1,a=2*n.BYTES+1;function o(e){return Re(e,r)}function u(e){return Be(e,r)}var s=function(e){var t=function(e){var t=Me(e);be(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});var n=t.endo,r=t.Fp,i=t.a;if(n){if(!r.eql(i,r.ZERO))throw Error("Endomorphism can only be defined for Koblitz curves that have a=0");if("object"!=typeof n||"bigint"!=(0,T.default)(n.beta)||"function"!=typeof n.splitScalar)throw Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze((0,S.default)({},t))}(e),n=t.Fp,r=t.toBytes||function(e,t){var r=t.toAffine();return pe(Uint8Array.from([4]),n.toBytes(r.x),n.toBytes(r.y))},i=t.fromBytes||function(e){var t=e.subarray(1);return{x:n.fromBytes(t.subarray(0,n.BYTES)),y:n.fromBytes(t.subarray(n.BYTES,2*n.BYTES))}};function a(e){var r=t.a,i=t.b,a=n.sqr(e),o=n.mul(a,e);return n.add(n.add(o,n.mul(e,r)),i)}if(!n.eql(n.sqr(t.Gy),a(t.Gx)))throw Error("bad generator point: equation left != right");function o(e){return"bigint"==(void 0===e?"undefined":(0,T.default)(e))&&We<e&&e<t.n}function u(e){if(!o(e))throw Error("Expected valid bigint: 0 < bigint < curve.n")}function s(e){var n,r=t.allowedPrivateKeyLengths,i=t.nByteLength,a=t.wrapPrivateKey,o=t.n;if(r&&"bigint"!=(void 0===e?"undefined":(0,T.default)(e))){if(ee(e)&&(e=re(e)),"string"!=typeof e||!r.includes(e.length))throw Error("Invalid key");e=e.padStart(2*i,"0")}try{n="bigint"==(void 0===e?"undefined":(0,T.default)(e))?e:ce(he("private key",e,i))}catch(t){throw Error("private key must be ".concat(i," bytes, hex or bigint, not ").concat(void 0===e?"undefined":(0,T.default)(e)))}return a&&(n=Re(n,o)),u(n),n}var c=new Map;function l(e){if(!(e instanceof f))throw Error("ProjectivePoint expected")}var f=function(){"use strict";function e(t,r,i){if((0,_.default)(this,e),this.px=t,this.py=r,this.pz=i,null==t||!n.isValid(t))throw Error("x required");if(null==r||!n.isValid(r))throw Error("y required");if(null==i||!n.isValid(i))throw Error("z required")}return(0,b.default)(e,[{key:"x",get:function(){return this.toAffine().x}},{key:"y",get:function(){return this.toAffine().y}},{key:"_setWindowSize",value:function(e){this._WINDOW_SIZE=e,c.delete(this)}},{key:"assertValidity",value:function(){if(this.is0()){if(t.allowInfinityPoint&&!n.is0(this.py))return;throw Error("bad point: ZERO")}var e=this.toAffine(),r=e.x,i=e.y;if(!n.isValid(r)||!n.isValid(i))throw Error("bad point: x or y not FE");var o=n.sqr(i),u=a(r);if(!n.eql(o,u))throw Error("bad point: equation left != right");if(!this.isTorsionFree())throw Error("bad point: not in prime-order subgroup")}},{key:"hasEvenY",value:function(){var e=this.toAffine().y;if(n.isOdd)return!n.isOdd(e);throw Error("Field doesn't support isOdd")}},{key:"equals",value:function(e){l(e);var t=this,r=t.px,i=t.py,a=t.pz,o=e.px,u=e.py,s=e.pz,c=n.eql(n.mul(r,s),n.mul(o,a)),f=n.eql(n.mul(i,s),n.mul(u,a));return c&&f}},{key:"negate",value:function(){return new e(this.px,n.neg(this.py),this.pz)}},{key:"double",value:function(){var r=t.a,i=t.b,a=n.mul(i,Ve),o=this,u=o.px,s=o.py,c=o.pz,l=n.ZERO,f=n.ZERO,d=n.ZERO,h=n.mul(u,u),p=n.mul(s,s),v=n.mul(c,c),y=n.mul(u,s);return y=n.add(y,y),d=n.mul(u,c),d=n.add(d,d),l=n.mul(r,d),f=n.mul(a,v),f=n.add(l,f),l=n.sub(p,f),f=n.add(p,f),f=n.mul(l,f),l=n.mul(y,l),d=n.mul(a,d),v=n.mul(r,v),y=n.sub(h,v),y=n.mul(r,y),y=n.add(y,d),d=n.add(h,h),h=n.add(d,h),h=n.add(h,v),h=n.mul(h,y),f=n.add(f,h),v=n.mul(s,c),v=n.add(v,v),h=n.mul(v,y),l=n.sub(l,h),d=n.mul(v,p),d=n.add(d,d),new e(l,f,d=n.add(d,d))}},{key:"add",value:function(r){l(r);var i=this,a=i.px,o=i.py,u=i.pz,s=r.px,c=r.py,f=r.pz,d=n.ZERO,h=n.ZERO,p=n.ZERO,v=t.a,y=n.mul(t.b,Ve),g=n.mul(a,s),m=n.mul(o,c),_=n.mul(u,f),b=n.add(a,o),w=n.add(s,c);b=n.mul(b,w),w=n.add(g,m),b=n.sub(b,w),w=n.add(a,u);var E=n.add(s,f);return w=n.mul(w,E),E=n.add(g,_),w=n.sub(w,E),E=n.add(o,u),d=n.add(c,f),E=n.mul(E,d),d=n.add(m,_),E=n.sub(E,d),p=n.mul(v,w),d=n.mul(y,_),p=n.add(d,p),d=n.sub(m,p),p=n.add(m,p),h=n.mul(d,p),m=n.add(g,g),m=n.add(m,g),_=n.mul(v,_),w=n.mul(y,w),m=n.add(m,_),_=n.sub(g,_),_=n.mul(v,_),w=n.add(w,_),g=n.mul(m,w),h=n.add(h,g),g=n.mul(E,w),d=n.mul(b,d),d=n.sub(d,g),g=n.mul(b,m),p=n.mul(E,p),new e(d,h,p=n.add(p,g))}},{key:"subtract",value:function(e){return this.add(e.negate())}},{key:"is0",value:function(){return this.equals(e.ZERO)}},{key:"wNAF",value:function(t){return h.wNAFCached(this,c,t,(function(t){var r=n.invertBatch(t.map((function(e){return e.pz})));return t.map((function(e,t){return e.toAffine(r[t])})).map(e.fromAffine)}))}},{key:"multiplyUnsafe",value:function(r){var i=e.ZERO;if(r===We)return i;if(u(r),r===Ke)return this;var a=t.endo;if(!a)return h.unsafeLadder(this,r);for(var o=a.splitScalar(r),s=o.k1neg,c=o.k1,l=o.k2neg,f=o.k2,d=i,p=i,v=this;c>We||f>We;)c&Ke&&(d=d.add(v)),f&Ke&&(p=p.add(v)),v=v.double(),c>>=Ke,f>>=Ke;return s&&(d=d.negate()),l&&(p=p.negate()),p=new e(n.mul(p.px,a.beta),p.py,p.pz),d.add(p)}},{key:"multiply",value:function(r){u(r);var i,a,o=r,s=t.endo;if(s){var c=s.splitScalar(o),l=c.k1neg,f=c.k1,d=c.k2neg,p=c.k2,v=this.wNAF(f),y=v.p,g=v.f,m=this.wNAF(p),_=m.p,b=m.f;y=h.constTimeNegate(l,y),_=h.constTimeNegate(d,_),_=new e(n.mul(_.px,s.beta),_.py,_.pz),i=y.add(_),a=g.add(b)}else{var w=this.wNAF(o);i=w.p,a=w.f}return e.normalizeZ([i,a])[0]}},{key:"multiplyAndAddUnsafe",value:function(t,n,r){var i=e.BASE,a=function(e,t){return t!==We&&t!==Ke&&e.equals(i)?e.multiply(t):e.multiplyUnsafe(t)},o=a(this,n).add(a(t,r));return o.is0()?void 0:o}},{key:"toAffine",value:function(e){var t=this,r=t.px,i=t.py,a=t.pz,o=this.is0();null==e&&(e=o?n.ONE:n.inv(a));var u=n.mul(r,e),s=n.mul(i,e),c=n.mul(a,e);if(o)return{x:n.ZERO,y:n.ZERO};if(!n.eql(c,n.ONE))throw Error("invZ was invalid");return{x:u,y:s}}},{key:"isTorsionFree",value:function(){var n=t.h,r=t.isTorsionFree;if(n===Ke)return!0;if(r)return r(e,this);throw Error("isTorsionFree() has not been declared for the elliptic curve")}},{key:"clearCofactor",value:function(){var n=t.h,r=t.clearCofactor;return n===Ke?this:r?r(e,this):this.multiplyUnsafe(t.h)}},{key:"toRawBytes",value:function(){var t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];return this.assertValidity(),r(e,this,t)}},{key:"toHex",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];return re(this.toRawBytes(e))}}],[{key:"fromAffine",value:function(t){var r=t||{},i=r.x,a=r.y;if(!t||!n.isValid(i)||!n.isValid(a))throw Error("invalid affine point");if(t instanceof e)throw Error("projective point not allowed");var o=function(e){return n.eql(e,n.ZERO)};return o(i)&&o(a)?e.ZERO:new e(i,a,n.ONE)}},{key:"normalizeZ",value:function(t){var r=n.invertBatch(t.map((function(e){return e.pz})));return t.map((function(e,t){return e.toAffine(r[t])})).map(e.fromAffine)}},{key:"fromHex",value:function(t){var n=e.fromAffine(i(he("pointHex",t)));return n.assertValidity(),n}},{key:"fromPrivateKey",value:function(t){return e.BASE.multiply(s(t))}}]),e}();f.BASE=new f(t.Gx,t.Gy,n.ONE),f.ZERO=new f(n.ZERO,n.ONE,n.ZERO);var d=t.nBitLength,h=function(e,t){var n,r=function(e,t){var n=t.negate();return e?n:t},i=function(e){return{windows:Math.ceil(t/e)+1,windowSize:Math.pow(2,e-1)}};return n={constTimeNegate:r,unsafeLadder:function(t,n){for(var r=e.ZERO,i=t;n>Ue;)n&qe&&(r=r.add(i)),i=i.double(),n>>=qe;return r},precomputeWindow:function(e,t){for(var n=i(t),r=n.windows,a=n.windowSize,o=[],u=e,s=u,c=0;c<r;c++){s=u,o.push(s);for(var l=1;l<a;l++)s=s.add(u),o.push(s);u=s.double()}return o}},(0,w.default)(n,"wNAF",(function(t,n,a){for(var o=i(t),u=o.windows,s=o.windowSize,c=e.ZERO,l=e.BASE,f=BigInt(Math.pow(2,t)-1),d=Math.pow(2,t),h=BigInt(t),p=0;p<u;p++){var v=p*s,y=Number(a&f);a>>=h,y>s&&(y-=d,a+=qe);var g=v,m=v+Math.abs(y)-1,_=p%2!=0,b=y<0;0===y?l=l.add(r(_,n[g])):c=c.add(r(b,n[m]))}return{p:c,f:l}})),(0,w.default)(n,"wNAFCached",(function(e,t,n,r){var i=e._WINDOW_SIZE||1,a=t.get(e);return a||(a=this.precomputeWindow(e,i),1!==i&&t.set(e,r(a))),this.wNAF(i,a,n)})),n}(f,t.endo?Math.ceil(d/2):d);return{CURVE:t,ProjectivePoint:f,normPrivateKeyToScalar:s,weierstrassEquation:a,isWithinCurveOrder:o}}((0,k.default)((0,S.default)({},t),{toBytes:function(e,t,r){var i=t.toAffine(),a=n.toBytes(i.x),o=pe;return r?o(Uint8Array.from([t.hasEvenY()?2:3]),a):o(Uint8Array.from([4]),a,n.toBytes(i.y))},fromBytes:function(e){var t=e.length,r=e[0],o=e.subarray(1);if(t!==i||2!==r&&3!==r){if(t===a&&4===r)return{x:n.fromBytes(o.subarray(0,n.BYTES)),y:n.fromBytes(o.subarray(n.BYTES,2*n.BYTES))};throw Error("Point of length ".concat(t," was invalid. Expected ").concat(i," compressed bytes or ").concat(a," uncompressed bytes"))}var u=ce(o);if(!(We<(c=u)&&c<n.ORDER))throw Error("Point is not on curve");var s,c,l=f(u);try{s=n.sqrt(l)}catch(e){var d=e instanceof Error?": "+e.message:"";throw Error("Point is not on curve"+d)}return!(1&~r)!=((s&Ke)===Ke)&&(s=n.neg(s)),{x:u,y:s}}})),c=s.ProjectivePoint,l=s.normPrivateKeyToScalar,f=s.weierstrassEquation,d=s.isWithinCurveOrder,h=function(e){return re(fe(e,t.nByteLength))};function p(e){return e>r>>Ke}var v=function(e,t,n){return ce(e.slice(t,n))},y=function(){"use strict";function e(t,n,r){(0,_.default)(this,e),this.r=t,this.s=n,this.recovery=r,this.assertValidity()}return(0,b.default)(e,[{key:"assertValidity",value:function(){if(!d(this.r))throw Error("r must be 0 < r < CURVE.n");if(!d(this.s))throw Error("s must be 0 < s < CURVE.n")}},{key:"addRecoveryBit",value:function(t){return new e(this.r,this.s,t)}},{key:"recoverPublicKey",value:function(e){var r=this,i=r.r,a=r.s,s=r.recovery,l=C(he("msgHash",e));if(null==s||![0,1,2,3].includes(s))throw Error("recovery id invalid");var f=2===s||3===s?i+t.n:i;if(f>=n.ORDER)throw Error("recovery id 2 or 3 invalid");var d=1&s?"03":"02",p=c.fromHex(d+h(f)),v=u(f),y=o(-l*v),g=o(a*v),m=c.BASE.multiplyAndAddUnsafe(p,y,g);if(!m)throw Error("point at infinify");return m.assertValidity(),m}},{key:"hasHighS",value:function(){return p(this.s)}},{key:"normalizeS",value:function(){return this.hasHighS()?new e(this.r,o(-this.s),this.recovery):this}},{key:"toDERRawBytes",value:function(){return se(this.toDERHex())}},{key:"toDERHex",value:function(){return ze.hexFromSig({r:this.r,s:this.s})}},{key:"toCompactRawBytes",value:function(){return se(this.toCompactHex())}},{key:"toCompactHex",value:function(){return h(this.r)+h(this.s)}}],[{key:"fromCompact",value:function(n){var r=t.nByteLength;return n=he("compactSignature",n,2*r),new e(v(n,0,r),v(n,r,2*r))}},{key:"fromDER",value:function(t){var n=ze.toSig(he("DER",t));return new e(n.r,n.s)}}]),e}(),g={isValidPrivateKey:function(e){try{return l(e),!0}catch(e){return!1}},normPrivateKeyToScalar:l,randomPrivateKey:function(){var e=Fe(t.n);return function(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=e.length,i=Pe(t),a=Fe(t);if(r<16||r<a||r>1024)throw Error("expected ".concat(a,"-1024 bytes of input, got ").concat(r));var o=Re(n?ce(e):le(e),t-Se)+Se;return n?de(o,i):fe(o,i)}(t.randomBytes(e),t.n)},precompute:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:8,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:c.BASE;return t._setWindowSize(e),t.multiply(BigInt(3)),t}};function m(e){var t=ee(e),n="string"==typeof e,r=(t||n)&&e.length;return t?r===i||r===a:n?r===2*i||r===2*a:e instanceof c}var E=t.bits2int||function(e){var n=ce(e),r=8*e.length-t.nBitLength;return r>0?n>>BigInt(r):n},C=t.bits2int_modN||function(e){return o(E(e))},x=ve(t.nBitLength);function R(e){if("bigint"!=(void 0===e?"undefined":(0,T.default)(e)))throw Error("bigint expected");if(!(We<=e&&e<x))throw Error("bigint expected < 2^"+t.nBitLength);return fe(e,t.nByteLength)}function I(e,r){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:B;if(["recovered","canonical"].some((function(e){return e in i})))throw Error("sign() legacy options not supported");var a=t.hash,s=t.randomBytes,f=i.lowS,h=i.prehash,v=i.extraEntropy;null==f&&(f=!0),e=he("msgHash",e),h&&(e=he("prehashed msgHash",a(e)));var g=C(e),m=l(r),_=[R(m),R(g)];if(null!=v&&!1!==v){var b=!0===v?s(n.BYTES):v;_.push(he("extraEntropy",b))}var w=pe.apply(void 0,(0,A.default)(_)),S=g;return{seed:w,k2sig:function(e){var t=E(e);if(d(t)){var n=u(t),r=c.BASE.multiply(t).toAffine(),i=o(r.x);if(i!==We){var a=o(n*o(S+i*m));if(a!==We){var s=(r.x===i?0:2)|Number(r.y&Ke),l=a;return f&&p(a)&&(l=function(e){return p(e)?o(-e):e}(a),s^=1),new y(i,l,s)}}}}}}var N,B={lowS:t.lowS,prehash:!1},O={lowS:t.lowS,prehash:!1};return c.BASE._setWindowSize(8),N={CURVE:t,getPublicKey:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return c.fromPrivateKey(e).toRawBytes(t)},getSharedSecret:function(e,t){var n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];if(m(e))throw Error("first arg must be private key");if(!m(t))throw Error("second arg must be public key");return c.fromHex(t).multiply(l(e)).toRawBytes(n)},sign:function(e,n){var r=I(e,n,arguments.length>2&&void 0!==arguments[2]?arguments[2]:B),i=r.seed,a=r.k2sig,o=t;return me(o.hash.outputLen,o.nByteLength,o.hmac)(i,a)}},(0,w.default)(N,"verify",(function(e,n,r){var i,a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:O,s=e;if(n=he("msgHash",n),r=he("publicKey",r),"strict"in a)throw Error("options.strict was renamed to lowS");var l,f,d=a.lowS,h=a.prehash;try{if("string"==typeof s||ee(s))try{l=y.fromDER(s)}catch(e){if(!(e instanceof ze.Err))throw e;l=y.fromCompact(s)}else{if("object"!=typeof s||"bigint"!=(0,T.default)(s.r)||"bigint"!=(0,T.default)(s.s))throw Error("PARSE");var p=s.r,v=s.s;l=new y(p,v)}f=c.fromHex(r)}catch(e){if("PARSE"===e.message)throw Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(d&&l.hasHighS())return!1;h&&(n=t.hash(n));var g=l.r,m=l.s,_=C(n),b=u(m),w=o(_*b),E=o(g*b),S=null===(i=c.BASE.multiplyAndAddUnsafe(f,w,E))||void 0===i?void 0:i.toAffine();return!!S&&o(S.x)===g})),(0,w.default)(N,"ProjectivePoint",c),(0,w.default)(N,"Signature",y),(0,w.default)(N,"utils",g),N}((0,S.default)({},e,function(e){return{hash:e,hmac:function(t){for(var n=arguments.length,r=new Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];return J(e,t,function(){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];L(a),r+=a.length}for(var o=new Uint8Array(r),u=0,s=0;u<t.length;u++){var c=t[u];o.set(c,s),s+=c.length}return o}.apply(this,(0,A.default)(r)))},randomBytes:j}}(t)))};return Object.freeze((0,k.default)((0,S.default)({},n(t)),{create:n}))}({a:BigInt(0),b:BigInt(7),Fp:Xe,n:Ye,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:function(e){var t=Ye,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-Ge*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),a=n,o=BigInt("0x100000000000000000000000000000000"),u=$e(a*e,t),s=$e(-r*e,t),c=Re(e-u*n-s*i,t),l=Re(-u*r-s*a,t),f=c>o,d=l>o;if(f&&(c=t-c),d&&(l=t-l),c>o||l>o)throw Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:f,k1:c,k2neg:d,k2:l}}}},Y),tt=BigInt(0),nt=function(e){return"bigint"==(void 0===e?"undefined":(0,T.default)(e))&&tt<e&&e<Ze},rt=function(e){return"bigint"==(void 0===e?"undefined":(0,T.default)(e))&&tt<e&&e<Ye},it={};function at(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=it[e];if(void 0===i){var a=Y(Uint8Array.from(e,(function(e){return e.charCodeAt(0)})));i=pe(a,a),it[e]=i}return Y(pe.apply(void 0,[i].concat((0,A.default)(n))))}var ot=function(e){return e.toRawBytes(!0).slice(1)},ut=function(e){return fe(e,32)},st=function(e){return Re(e,Ze)},ct=function(e){return Re(e,Ye)},lt=et.ProjectivePoint,ft=function(e,t,n){return lt.BASE.multiplyAndAddUnsafe(e,t,n)};function dt(e){var t=et.utils.normPrivateKeyToScalar(e),n=lt.fromPrivateKey(t);return{scalar:n.hasEvenY()?t:ct(-t),bytes:ot(n)}}function ht(e){if(!nt(e))throw Error("bad x: need 0 < x < p");var t=st(e*e),n=Qe(st(t*e+BigInt(7)));n%Je!==tt&&(n=st(-n));var r=new lt(e,n,Ge);return r.assertValidity(),r}function pt(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return ct(ce(at.apply(void 0,["BIP0340/challenge"].concat((0,A.default)(t)))))}function vt(e,t,n){var r=he("signature",e,64),i=he("message",t),a=he("publicKey",n,32);try{var o=ht(ce(a)),u=ce(r.subarray(0,32));if(!nt(u))return!1;var s=ce(r.subarray(32,64));if(!rt(s))return!1;var c=pt(ut(u),ot(o),i),l=ft(o,s,ct(-c));return!(!l||!l.hasEvenY()||l.toAffine().x!==u)}catch(e){return!1}}var yt,gt={getPublicKey:function(e){return dt(e).bytes},sign:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:j(32),r=he("message",e),i=dt(t),a=i.bytes,o=i.scalar,u=he("auxRand",n,32),s=ut(o^ce(at("BIP0340/aux",u))),c=at("BIP0340/nonce",s,a,r),l=ct(ce(c));if(l===tt)throw Error("sign failed: k is zero");var f=dt(l),d=f.bytes,h=f.scalar,p=pt(d,a,r),v=new Uint8Array(64);if(v.set(d,0),v.set(ut(ct(h+p*o)),32),!vt(v,r,a))throw Error("sign: Invalid signature produced");return v},verify:vt,utils:{randomPrivateKey:et.utils.randomPrivateKey,lift_x:ht,pointToBytes:ot,numberToBytesBE:fe,bytesToNumberBE:ce,taggedHash:at,mod:Re}},mt="Trystero",_t=function(e,t){return Array(e).fill().map(t)},bt=function(e){return _t(e,(function(){return"0123456789AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"[Math.floor(62*Math.random())]})).join("")},wt=bt(20),Et=Promise.all.bind(Promise),St="undefined"!=typeof window,kt=Object.entries,Ct=Object.fromEntries,xt=Object.keys,At=function(){},Tt=function(e){return Error("".concat(mt,": ").concat(e))},Rt=new TextEncoder,It=new TextDecoder,Nt=function(e){return Rt.encode(e)},Bt=function(e){return It.decode(e)},Ot=function(e){return e.reduce((function(e,t){return e+t.toString(16).padStart(2,"0")}),"")},Lt=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return t.join("@")},Pt=JSON.stringify,Ft=JSON.parse,Dt={},Ut="AES-GCM",qt={},Mt=(yt=(0,m.default)((function(e){var t,n,r;return(0,N.__generator)(this,(function(i){switch(i.label){case 0:return qt[e]?[2,qt[e]]:(n=Array.from,r=Uint8Array.bind,[4,crypto.subtle.digest("SHA-1",Nt(e))]);case 1:return t=n.apply(Array,[new(r.apply(Uint8Array,[void 0,i.sent()]))]).map((function(e){return e.toString(36)})).join(""),[2,(qt[e]=t,t)]}}))})),function(e){return yt.apply(this,arguments)}),jt=function(){var e=(0,m.default)((function(e,t){var n,r,i,a,o,u;return(0,N.__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:Ut,iv:n}],[4,e];case 1:return[4,o.apply(a,u.concat([s.sent(),Nt(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)}}(),Ht=function(){var e=(0,m.default)((function(e,t){var n,r,i,a,o,u;return(0,N.__generator)(this,(function(s){switch(s.label){case 0:return n=(0,x.default)(t.split("$"),2),r=n[0],i=n[1],o=(a=crypto.subtle).decrypt,u=[{name:Ut,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,Bt.apply(void 0,[s.sent()])]}}))}));return function(t,n){return e.apply(this,arguments)}}();function zt(e){return e&&e.__esModule&&{}.hasOwnProperty.call(e,"default")?e.default:e}var Wt,Kt,Vt={exports:{}};!function(e,t){var n;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")}catch(e){}return!e&&void 0!==B&&"env"in B&&(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&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/))},t.storage=function(){try{return localStorage}catch(e){}}(),t.destroy=(n=!1,function(){n||(n=!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=function(e){function t(e){var r,i,a,o=null;function u(){for(var e=arguments.length,n=new Array(e),i=0;i<e;i++)n[i]=arguments[i];if(u.enabled){var a=u,o=Number(new Date),s=o-(r||o);a.diff=s,a.prev=r,a.curr=o,r=o,n[0]=t.coerce(n[0]),"string"!=typeof n[0]&&n.unshift("%O");var c=0;n[0]=n[0].replace(/%([a-zA-Z%])/g,(function(e,r){if("%%"===e)return"%";c++;var i=t.formatters[r];if("function"==typeof i){var o=n[c];e=i.call(a,o),n.splice(c,1),c--}return e})),t.formatArgs.call(a,n),(a.log||t.log).apply(a,n)}}return u.namespace=e,u.useColors=t.useColors(),u.color=t.selectColor(e),u.extend=n,u.destroy=t.destroy,Object.defineProperty(u,"enabled",{enumerable:!0,configurable:!1,get:function(){return null!==o?o:(i!==t.namespaces&&(i=t.namespaces,a=t.enabled(e)),a)},set:function(e){o=e}}),"function"==typeof t.init&&t.init(u),u}function n(e,n){var r=t(this.namespace+(void 0===n?":":n)+e);return r.log=this.log,r}function r(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return t.debug=t,t.default=t,t.coerce=function(e){return e instanceof Error?e.stack||e.message:e},t.disable=function(){var e=(0,A.default)(t.names.map(r)).concat((0,A.default)(t.skips.map(r).map((function(e){return"-"+e})))).join(",");return t.enable(""),e},t.enable=function(e){var n;t.save(e),t.namespaces=e,t.names=[],t.skips=[];var r=("string"==typeof e?e:"").split(/[\s,]+/),i=r.length;for(n=0;n<i;n++)r[n]&&("-"===(e=r[n].replace(/\*/g,".*?"))[0]?t.skips.push(RegExp("^"+e.slice(1)+"$")):t.names.push(RegExp("^"+e+"$")))},t.enabled=function(e){if("*"===e[e.length-1])return!0;var n,r;for(n=0,r=t.skips.length;n<r;n++)if(t.skips[n].test(e))return!1;for(n=0,r=t.names.length;n<r;n++)if(t.names[n].test(e))return!0;return!1},t.humanize=function(){if(Kt)return Wt;Kt=1;var e=1e3,t=60*e,n=60*t,r=24*n;function i(e,t,n,r){var i=t>=1.5*n;return Math.round(e/n)+" "+r+(i?"s":"")}return Wt=function(a,o){o=o||{};var u=void 0===a?"undefined":(0,T.default)(a);if("string"===u&&a.length>0)return function(i){if(!((i+="").length>100)){var a=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(i);if(a){var o=parseFloat(a[1]);switch((a[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return 315576e5*o;case"weeks":case"week":case"w":return 6048e5*o;case"days":case"day":case"d":return o*r;case"hours":case"hour":case"hrs":case"hr":case"h":return o*n;case"minutes":case"minute":case"mins":case"min":case"m":return o*t;case"seconds":case"second":case"secs":case"sec":case"s":return o*e;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return o;default:return}}}}(a);if("number"===u&&isFinite(a))return o.long?function(a){var o=Math.abs(a);return o>=r?i(a,o,r,"day"):o>=n?i(a,o,n,"hour"):o>=t?i(a,o,t,"minute"):o>=e?i(a,o,e,"second"):a+" ms"}(a):function(i){var a=Math.abs(i);return a>=r?Math.round(i/r)+"d":a>=n?Math.round(i/n)+"h":a>=t?Math.round(i/t)+"m":a>=e?Math.round(i/e)+"s":i+"ms"}(a);throw Error("val is not a non-empty string or a valid number. val="+JSON.stringify(a))}}(),t.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(n){t[n]=e[n]})),t.names=[],t.skips=[],t.formatters={},t.selectColor=function(e){for(var n=0,r=0;r<e.length;r++)n=(n<<5)-n+e.charCodeAt(r),n|=0;return t.colors[Math.abs(n)%t.colors.length]},t.enable(t.load()),t}(t),e.exports.formatters.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}(Vt,Vt.exports);var Zt,Yt=zt(Vt.exports),Gt="undefined"!=typeof window?window:self,Jt=Gt.RTCPeerConnection||Gt.mozRTCPeerConnection||Gt.webkitRTCPeerConnection,$t=Gt.RTCSessionDescription||Gt.mozRTCSessionDescription||Gt.webkitRTCSessionDescription,Qt=Gt.RTCIceCandidate||Gt.mozRTCIceCandidate||Gt.webkitRTCIceCandidate,Xt={exports:{}},en="object"==typeof Reflect?Reflect:null,tn=en&&"function"==typeof en.apply?en.apply:function(e,t,n){return function(){}.apply.call(e,t,n)};Zt=en&&"function"==typeof en.ownKeys?en.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var nn=Number.isNaN||function(e){return e!=e};function rn(){rn.init.call(this)}Xt.exports=rn,Xt.exports.once=function(e,t){return new Promise((function(n,r){function i(n){e.removeListener(t,a),r(n)}function a(){"function"==typeof e.removeListener&&e.removeListener("error",i),n([].slice.call(arguments))}pn(e,t,a,{once:!0}),"error"!==t&&function(e,t,n){"function"==typeof e.on&&pn(e,"error",t,{once:!0})}(e,i)}))},rn.EventEmitter=rn,rn.prototype._events=void 0,rn.prototype._eventsCount=0,rn.prototype._maxListeners=void 0;var an=10;function on(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+(void 0===e?"undefined":(0,T.default)(e)))}function un(e){return void 0===e._maxListeners?rn.defaultMaxListeners:e._maxListeners}function sn(e,t,n,r){var i,a,o,u;if(on(n),void 0===(a=e._events)?(a=e._events=Object.create(null),e._eventsCount=0):(void 0!==a.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),a=e._events),o=a[t]),void 0===o)o=a[t]=n,++e._eventsCount;else if("function"==typeof o?o=a[t]=r?[n,o]:[o,n]:r?o.unshift(n):o.push(n),(i=un(e))>0&&o.length>i&&!o.warned){o.warned=!0;var s=Error("Possible EventEmitter memory leak detected. "+o.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");s.name="MaxListenersExceededWarning",s.emitter=e,s.type=t,s.count=o.length,u=s,console&&console.warn&&console.warn(u)}return e}function cn(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function ln(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},i=cn.bind(r);return i.listener=n,r.wrapFn=i,i}function fn(e,t,n){var r=e._events;if(void 0===r)return[];var i=r[t];return void 0===i?[]:"function"==typeof i?n?[i.listener||i]:[i]:n?function(e){for(var t=Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(i):hn(i,i.length)}function dn(e){var t=this._events;if(void 0!==t){var n=t[e];if("function"==typeof n)return 1;if(void 0!==n)return n.length}return 0}function hn(e,t){for(var n=Array(t),r=0;r<t;++r)n[r]=e[r];return n}function pn(e,t,n,r){if("function"==typeof e.on)r.once?e.once(t,n):e.on(t,n);else{if("function"!=typeof e.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+(void 0===e?"undefined":(0,T.default)(e)));e.addEventListener(t,(function i(a){r.once&&e.removeEventListener(t,i),n(a)}))}}Object.defineProperty(rn,"defaultMaxListeners",{enumerable:!0,get:function(){return an},set:function(e){if("number"!=typeof e||e<0||nn(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");an=e}}),rn.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},rn.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||nn(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},rn.prototype.getMaxListeners=function(){return un(this)},rn.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.push(arguments[n]);var r="error"===e,i=this._events;if(void 0!==i)r=r&&void 0===i.error;else if(!r)return!1;if(r){var a;if(t.length>0&&(a=t[0]),a instanceof Error)throw a;var o=Error("Unhandled error."+(a?" ("+a.message+")":""));throw o.context=a,o}var u=i[e];if(void 0===u)return!1;if("function"==typeof u)tn(u,this,t);else{var s=u.length,c=hn(u,s);for(n=0;n<s;++n)tn(c[n],this,t)}return!0},rn.prototype.addListener=function(e,t){return sn(this,e,t,!1)},rn.prototype.on=rn.prototype.addListener,rn.prototype.prependListener=function(e,t){return sn(this,e,t,!0)},rn.prototype.once=function(e,t){return on(t),this.on(e,ln(this,e,t)),this},rn.prototype.prependOnceListener=function(e,t){return on(t),this.prependListener(e,ln(this,e,t)),this},rn.prototype.removeListener=function(e,t){var n,r,i,a,o;if(on(t),void 0===(r=this._events))return this;if(void 0===(n=r[e]))return this;if(n===t||n.listener===t)0==--this._eventsCount?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(i=-1,a=n.length-1;a>=0;a--)if(n[a]===t||n[a].listener===t){o=n[a].listener,i=a;break}if(i<0)return this;0===i?n.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(n,i),1===n.length&&(r[e]=n[0]),void 0!==r.removeListener&&this.emit("removeListener",e,o||t)}return this},rn.prototype.off=rn.prototype.removeListener,rn.prototype.removeAllListeners=function(e){var t,n,r;if(void 0===(n=this._events))return this;if(void 0===n.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==n[e]&&(0==--this._eventsCount?this._events=Object.create(null):delete n[e]),this;if(0===arguments.length){var i,a=Object.keys(n);for(r=0;r<a.length;++r)"removeListener"!==(i=a[r])&&this.removeAllListeners(i);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(void 0!==t)for(r=t.length-1;r>=0;r--)this.removeListener(e,t[r]);return this},rn.prototype.listeners=function(e){return fn(this,e,!0)},rn.prototype.rawListeners=function(e){return fn(this,e,!1)},rn.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):dn.call(e,t)},rn.prototype.listenerCount=dn,rn.prototype.eventNames=function(){return this._eventsCount>0?Zt(this._events):[]};var vn=Xt.exports,yn="function"==typeof queueMicrotask?queueMicrotask:function(e){return Promise.resolve().then(e)},gn=function(){"use strict";function e(t){if((0,_.default)(this,e),!(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,b.default)(e,[{key:"clear",value:function(){this.top=this.btm=0,this.next=null,this.buffer.fill(void 0)}},{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:"peek",value:function(){return this.buffer[this.btm]}},{key:"isEmpty",value:function(){return void 0===this.buffer[this.btm]}}]),e}(),mn=function(){"use strict";function e(t){(0,_.default)(this,e),this.decoder=new TextDecoder("utf16le"===t?"utf16-le":t)}return(0,b.default)(e,[{key:"decode",value:function(e){return this.decoder.decode(e,{stream:!0})}},{key:"flush",value:function(){return this.decoder.decode(new Uint8Array(0))}}]),e}(),_n=mn,bn=mn,wn=vn.EventEmitter,En=Error("Stream was destroyed"),Sn=yn,kn=function(){"use strict";function e(t){(0,_.default)(this,e),this.hwm=t||16,this.head=new gn(this.hwm),this.tail=this.head,this.length=0}return(0,b.default)(e,[{key:"clear",value:function(){this.head=this.tail,this.head.clear(),this.length=0}},{key:"push",value:function(e){if(this.length++,!this.head.push(e)){var t=this.head;this.head=t.next=new gn(2*this.head.buffer.length),this.head.push(e)}}},{key:"shift",value:function(){0!==this.length&&this.length--;var e=this.tail.shift();if(void 0===e&&this.tail.next){var t=this.tail.next;return this.tail.next=null,this.tail=t,this.tail.shift()}return e}},{key:"peek",value:function(){var e=this.tail.peek();return void 0===e&&this.tail.next?this.tail.next.peek():e}},{key:"isEmpty",value:function(){return 0===this.length}}]),e}(),Cn=function(){"use strict";function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"utf8";switch((0,_.default)(this,e),this.encoding=function(e){switch(e=e.toLowerCase()){case"utf8":case"utf-8":return"utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return"utf16le";case"latin1":case"binary":return"latin1";case"base64":case"ascii":case"hex":return e;default:throw Error("Unknown encoding: "+e)}}(t),this.encoding){case"utf8":this.decoder=new bn;break;case"utf16le":case"base64":throw Error("Unsupported encoding: "+this.encoding);default:this.decoder=new _n(this.encoding)}}return(0,b.default)(e,[{key:"push",value:function(e){return"string"==typeof e?e:this.decoder.decode(e)}},{key:"write",value:function(e){return this.push(e)}},{key:"end",value:function(e){var t="";return e&&(t=this.push(e)),t+this.decoder.flush()}}]),e}(),xn=536870910,An=16384,Tn=32768,Rn=131072,In=536870143,Nn=536838143,Bn=536739839,On=524288,Ln=1048576,Pn=2097152,Fn=8388608,Dn=16777216,Un=33554432,qn=469499903,Mn=503316479,jn=262160,Hn=8404992,zn=8405006,Wn=33587200,Kn=33587215,Vn=270794767,Zn=Symbol.asyncIterator||Symbol(),Yn=function(){"use strict";function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=n.highWaterMark,i=void 0===r?16384:r,a=n.map,o=void 0===a?null:a,u=n.mapWritable,s=n.byteLength,c=n.byteLengthWritable;(0,_.default)(this,e),this.stream=t,this.queue=new kn,this.highWaterMark=i,this.buffered=0,this.error=null,this.pipeline=null,this.drains=null,this.byteLength=c||s||lr,this.map=u||o,this.afterWrite=er.bind(this),this.afterUpdateNextTick=rr.bind(this)}return(0,b.default)(e,[{key:"ended",get:function(){return!!(this.stream._duplexState&Fn)}},{key:"push",value:function(e){return null!==this.map&&(e=this.map(e)),this.buffered+=this.byteLength(e),this.queue.push(e),this.buffered<this.highWaterMark?(this.stream._duplexState|=Pn,!0):(this.stream._duplexState|=6291456,!1)}},{key:"shift",value:function(){var e=this.queue.shift();return this.buffered-=this.byteLength(e),0===this.buffered&&(this.stream._duplexState&=534773759),e}},{key:"end",value:function(e){"function"==typeof e?this.stream.once("finish",e):null!=e&&this.push(e),this.stream._duplexState=535822335&this.stream._duplexState|134217728}},{key:"autoBatch",value:function(e,t){var n=[],r=this.stream;for(n.push(e);2359296==(r._duplexState&Vn);)n.push(r._writableState.shift());if(15&r._duplexState)return t(null);r._writev(n,t)}},{key:"update",value:function(){var e=this.stream;e._duplexState|=On;do{for(;(e._duplexState&Vn)===Pn;){var t=this.shift();e._duplexState|=67371008,e._write(t,this.afterWrite)}1310720&e._duplexState||this.updateNonPrimary()}while(!0===this.continueUpdate());e._duplexState&=536346623}},{key:"updateNonPrimary",value:function(){var e=this.stream;if(134217728==(144965647&e._duplexState))return e._duplexState=402653183&e._duplexState|262144,void e._final(Qn.bind(this));4!=(14&e._duplexState)?1==(e._duplexState&Kn)&&(e._duplexState=(e._duplexState|jn)&xn,e._open(ir.bind(this))):e._duplexState&Wn||(e._duplexState|=jn,e._destroy(Xn.bind(this)))}},{key:"continueUpdate",value:function(){return!!(this.stream._duplexState&Un)&&(this.stream._duplexState&=Mn,!0)}},{key:"updateCallback",value:function(){(35127311&this.stream._duplexState)===Ln?this.update():this.updateNextTick()}},{key:"updateNextTick",value:function(){this.stream._duplexState&Un||(this.stream._duplexState|=Un,this.stream._duplexState&On||Sn(this.afterUpdateNextTick))}}]),e}(),Gn=function(){"use strict";function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=n.highWaterMark,i=void 0===r?16384:r,a=n.map,o=void 0===a?null:a,u=n.mapReadable,s=n.byteLength,c=n.byteLengthReadable;(0,_.default)(this,e),this.stream=t,this.queue=new kn,this.highWaterMark=0===i?1:i,this.buffered=0,this.readAhead=i>0,this.error=null,this.pipeline=null,this.byteLength=c||s||lr,this.map=u||o,this.pipeTo=null,this.afterRead=tr.bind(this),this.afterUpdateNextTick=nr.bind(this)}return(0,b.default)(e,[{key:"ended",get:function(){return!!(this.stream._duplexState&An)}},{key:"pipe",value:function(e,t){if(null!==this.pipeTo)throw Error("Can only pipe to one destination");if("function"!=typeof t&&(t=null),this.stream._duplexState|=512,this.pipeTo=e,this.pipeline=new Jn(this.stream,e,t),t&&this.stream.on("error",fr),cr(e))e._writableState.pipeline=this.pipeline,t&&e.on("error",fr),e.on("finish",this.pipeline.finished.bind(this.pipeline));else{var n=this.pipeline.done.bind(this.pipeline,e),r=this.pipeline.done.bind(this.pipeline,e,null);e.on("error",n),e.on("close",r),e.on("finish",this.pipeline.finished.bind(this.pipeline))}e.on("drain",$n.bind(this)),this.stream.emit("piping",e),e.emit("pipe",this.stream)}},{key:"push",value:function(e){var t=this.stream;return null===e?(this.highWaterMark=0,t._duplexState=536805311&t._duplexState|1024,!1):(null!==this.map&&null===(e=this.map(e))||(this.buffered+=this.byteLength(e),this.queue.push(e),t._duplexState=536805375&t._duplexState|128),this.buffered<this.highWaterMark)}},{key:"shift",value:function(){var e=this.queue.shift();return this.buffered-=this.byteLength(e),0===this.buffered&&(this.stream._duplexState&=536862591),e}},{key:"unshift",value:function(e){for(var t=[null!==this.map?this.map(e):e];this.buffered>0;)t.push(this.shift());for(var n=0;n<t.length-1;n++){var r=t[n];this.buffered+=this.byteLength(r),this.queue.push(r)}this.push(t[t.length-1])}},{key:"read",value:function(){var e=this.stream;if(128==(16527&e._duplexState)){var t=this.shift();return null!==this.pipeTo&&!1===this.pipeTo.write(t)&&(e._duplexState&=In),2048&e._duplexState&&e.emit("data",t),t}return!1===this.readAhead&&(e._duplexState|=Rn,this.updateNextTick()),null}},{key:"drain",value:function(){for(var e=this.stream;128==(16527&e._duplexState)&&768&e._duplexState;){var t=this.shift();null!==this.pipeTo&&!1===this.pipeTo.write(t)&&(e._duplexState&=In),2048&e._duplexState&&e.emit("data",t)}}},{key:"update",value:function(){var e=this.stream;e._duplexState|=32;do{for(this.drain();this.buffered<this.highWaterMark&&(214047&e._duplexState)===Rn;)e._duplexState|=65552,e._read(this.afterRead),this.drain();4224==(12431&e._duplexState)&&(e._duplexState|=8192,e.emit("readable")),80&e._duplexState||this.updateNonPrimary()}while(!0===this.continueUpdate());e._duplexState&=536870879}},{key:"updateNonPrimary",value:function(){var e=this.stream;1024==(1167&e._duplexState)&&(e._duplexState=536869887&e._duplexState|16384,e.emit("end"),(e._duplexState&zn)===Hn&&(e._duplexState|=4),null!==this.pipeTo&&this.pipeTo.end()),4!=(14&e._duplexState)?1==(e._duplexState&Kn)&&(e._duplexState=(e._duplexState|jn)&xn,e._open(ir.bind(this))):e._duplexState&Wn||(e._duplexState|=jn,e._destroy(Xn.bind(this)))}},{key:"continueUpdate",value:function(){return!!(this.stream._duplexState&Tn)&&(this.stream._duplexState&=Nn,!0)}},{key:"updateCallback",value:function(){64==(32879&this.stream._duplexState)?this.update():this.updateNextTick()}},{key:"updateNextTick",value:function(){this.stream._duplexState&Tn||(this.stream._duplexState|=Tn,32&this.stream._duplexState||Sn(this.afterUpdateNextTick))}}]),e}(),Jn=function(){"use strict";function e(t,n,r){(0,_.default)(this,e),this.from=t,this.to=n,this.afterPipe=r,this.error=null,this.pipeToFinished=!1}return(0,b.default)(e,[{key:"finished",value:function(){this.pipeToFinished=!0}},{key:"done",value:function(e,t){t&&(this.error=t),e!==this.to||(this.to=null,null===this.from)?e!==this.from||(this.from=null,null===this.to)?(null!==this.afterPipe&&this.afterPipe(this.error),this.to=this.from=this.afterPipe=null):e._duplexState&An||this.to.destroy(this.error||Error("Readable stream closed before ending")):this.from._duplexState&An&&this.pipeToFinished||this.from.destroy(this.error||Error("Writable stream closed prematurely"))}}]),e}();function $n(){this.stream._duplexState|=512,this.updateCallback()}function Qn(e){var t=this.stream;e&&t.destroy(e),14&t._duplexState||(t._duplexState|=Fn,t.emit("finish")),(t._duplexState&zn)===Hn&&(t._duplexState|=4),t._duplexState&=qn,t._duplexState&On?this.updateNextTick():this.update()}function Xn(e){var t=this.stream;e||this.error===En||(e=this.error),e&&t.emit("error",e),t._duplexState|=8,t.emit("close");var n=t._readableState,r=t._writableState;if(null!==n&&null!==n.pipeline&&n.pipeline.done(t,e),null!==r){for(;null!==r.drains&&r.drains.length>0;)r.drains.shift().resolve(!1);null!==r.pipeline&&r.pipeline.done(t,e)}}function er(e){var t=this.stream;e&&t.destroy(e),t._duplexState&=qn,null!==this.drains&&function(e){for(var t=0;t<e.length;t++)0==--e[t].writes&&(e.shift().resolve(!0),t--)}(this.drains),4194304==(6553615&t._duplexState)&&(t._duplexState&=532676607,(t._duplexState&Dn)===Dn&&t.emit("drain")),this.updateCallback()}function tr(e){e&&this.stream.destroy(e),this.stream._duplexState&=536870895,!1!==this.readAhead||256&this.stream._duplexState||(this.stream._duplexState&=Bn),this.updateCallback()}function nr(){32&this.stream._duplexState||(this.stream._duplexState&=Nn,this.update())}function rr(){this.stream._duplexState&On||(this.stream._duplexState&=Mn,this.update())}function ir(e){var t=this.stream;e&&t.destroy(e),4&t._duplexState||(17423&t._duplexState||(t._duplexState|=64),142606351&t._duplexState||(t._duplexState|=Ln),t.emit("open")),t._duplexState&=536608751,null!==t._writableState&&t._writableState.updateCallback(),null!==t._readableState&&t._readableState.updateCallback()}function ar(e){null!==this._readableState&&("data"===e&&(this._duplexState|=133376,this._readableState.updateNextTick()),"readable"===e&&(this._duplexState|=4096,this._readableState.updateNextTick())),null!==this._writableState&&"drain"===e&&(this._duplexState|=Dn,this._writableState.updateNextTick())}var or=function(e){"use strict";(0,E.default)(n,e);var t=(0,I.default)(n);function n(e){var r;return(0,_.default)(this,n),(r=t.call(this,e))._duplexState|=8519681,r._readableState=new Gn((0,g.default)(r),e),e&&(!1===r._readableState.readAhead&&(r._duplexState&=Bn),e.read&&(r._read=e.read),e.eagerOpen&&r._readableState.updateNextTick(),e.encoding&&r.setEncoding(e.encoding)),(0,C.default)(r)}return(0,b.default)(n,[{key:"setEncoding",value:function(e){var t=new Cn(e),n=this._readableState.map||sr;return this._readableState.map=function(e){var r=t.push(e);return""===r?null:n(r)},this}},{key:"_read",value:function(e){e(null)}},{key:"pipe",value:function(e,t){return this._readableState.updateNextTick(),this._readableState.pipe(e,t),e}},{key:"read",value:function(){return this._readableState.updateNextTick(),this._readableState.read()}},{key:"push",value:function(e){return this._readableState.updateNextTick(),this._readableState.push(e)}},{key:"unshift",value:function(e){return this._readableState.updateNextTick(),this._readableState.unshift(e)}},{key:"resume",value:function(){return this._duplexState|=131328,this._readableState.updateNextTick(),this}},{key:"pause",value:function(){return this._duplexState&=!1===this._readableState.readAhead?536739583:536870655,this}},{key:Zn,value:function(){var e,t=this,n=null,r=null,i=null;return this.on("error",(function(e){n=e})),this.on("readable",(function(){null!==r&&a(t.read())})),this.on("close",(function(){null!==r&&a(null)})),e={},(0,w.default)(e,Zn,(function(){return this})),(0,w.default)(e,"next",(function(){return new Promise((function(e,n){r=e,i=n;var o=t.read();null!==o?a(o):8&t._duplexState&&a(null)}))})),(0,w.default)(e,"return",(function(){return o(null)})),(0,w.default)(e,"throw",(function(e){return o(e)})),e;function a(e){null!==i&&(n?i(n):null!==e||t._duplexState&An?r({value:e,done:null===e}):i(En),i=r=null)}function o(e){return t.destroy(e),new Promise((function(n,r){if(8&t._duplexState)return n({value:void 0,done:!0});t.once("close",(function(){e?r(e):n({value:void 0,done:!0})}))}))}}}],[{key:"_fromAsyncIterator",value:function(e,t){var r,i=new n((0,k.default)((0,S.default)({},t),{read:function(t){e.next().then(a).then(t.bind(null,null)).catch(t)},predestroy:function(){r=e.return()},destroy:function(e){if(!r)return e(null);r.then(e.bind(null,null)).catch(e)}}));return i;function a(e){e.done?i.push(null):i.push(e.value)}}},{key:"from",value:function(e,t){if(cr(r=e)&&r.readable)return e;var r;if(e[Zn])return this._fromAsyncIterator(e[Zn](),t);Array.isArray(e)||(e=void 0===e?[]:[e]);var i=0;return new n((0,k.default)((0,S.default)({},t),{read:function(t){this.push(i===e.length?null:e[i++]),t(null)}}))}},{key:"isBackpressured",value:function(e){return!!(17422&e._duplexState)||e._readableState.buffered>=e._readableState.highWaterMark}},{key:"isPaused",value:function(e){return!(256&e._duplexState)}}]),n}(function(e){"use strict";(0,E.default)(n,e);var t=(0,I.default)(n);function n(e){var r;return(0,_.default)(this,n),(r=t.call(this))._duplexState=0,r._readableState=null,r._writableState=null,e&&(e.open&&(r._open=e.open),e.destroy&&(r._destroy=e.destroy),e.predestroy&&(r._predestroy=e.predestroy),e.signal&&e.signal.addEventListener("abort",dr.bind((0,g.default)(r)))),r.on("newListener",ar),(0,C.default)(r)}return(0,b.default)(n,[{key:"_open",value:function(e){e(null)}},{key:"_destroy",value:function(e){e(null)}},{key:"_predestroy",value:function(){}},{key:"readable",get:function(){return null!==this._readableState||void 0}},{key:"writable",get:function(){return null!==this._writableState||void 0}},{key:"destroyed",get:function(){return!!(8&this._duplexState)}},{key:"destroying",get:function(){return!!(14&this._duplexState)}},{key:"destroy",value:function(e){14&this._duplexState||(e||(e=En),this._duplexState=535822271&this._duplexState|4,null!==this._readableState&&(this._readableState.highWaterMark=0,this._readableState.error=e),null!==this._writableState&&(this._writableState.highWaterMark=0,this._writableState.error=e),this._duplexState|=2,this._predestroy(),this._duplexState&=536870909,null!==this._readableState&&this._readableState.updateNextTick(),null!==this._writableState&&this._writableState.updateNextTick())}}]),n}(wn)),ur=function(e){"use strict";(0,E.default)(n,e);var t=(0,I.default)(n);function n(e){var r;return(0,_.default)(this,n),(r=t.call(this,e))._duplexState=1|r._duplexState&Rn,r._writableState=new Yn((0,g.default)(r),e),e&&(e.writev&&(r._writev=e.writev),e.write&&(r._write=e.write),e.final&&(r._final=e.final)),(0,C.default)(r)}return(0,b.default)(n,[{key:"cork",value:function(){this._duplexState|=268435456}},{key:"uncork",value:function(){this._duplexState&=268435455,this._writableState.updateNextTick()}},{key:"_writev",value:function(e,t){t(null)}},{key:"_write",value:function(e,t){this._writableState.autoBatch(e,t)}},{key:"_final",value:function(e){e(null)}},{key:"write",value:function(e){return this._writableState.updateNextTick(),this._writableState.push(e)}},{key:"end",value:function(e){return this._writableState.updateNextTick(),this._writableState.end(e),this}}]),n}(or);function sr(e){return e}function cr(e){return"number"==typeof e._duplexState&&function(e){return!!e._readableState||!!e._writableState}(e)}function lr(e){return function(e){return"object"==typeof e&&null!==e&&"number"==typeof e.byteLength}(e)?e.byteLength:1024}function fr(){}function dr(){this.destroy(Error("Stream aborted."))}var hr=ur;function pr(e,t){for(var n in t)Object.defineProperty(e,n,{value:t[n],enumerable:!0,configurable:!0});return e}for(var vr=zt((function(e,t,n){if(!e||"string"==typeof e)throw new TypeError("Please pass an Error to err-code");n||(n={}),"object"==typeof t&&(n=t,t=""),t&&(n.code=t);try{return pr(e,n)}catch(t){n.message=e.message,n.stack=e.stack;var r=function(){};return r.prototype=Object.create(Object.getPrototypeOf(e)),pr(new r,n)}})),yr="0123456789abcdef",gr=[],mr=0;mr<256;mr++)gr[mr]=yr[mr>>4&15]+yr[15&mr];for(var _r=function(e){for(var t=e.length,n="",r=0;r<t;)n+=gr[e[r++]];return n},br="undefined"==typeof Uint8Array?[]:new Uint8Array(256),wr=0;wr<64;wr++)br["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charCodeAt(wr)]=wr;new TextDecoder;var Er=new TextEncoder,Sr="undefined"!=typeof window?window:self,kr=Sr.crypto||Sr.msCrypto||{};kr.subtle||kr.webkitSubtle;var Cr=function(e){var t=new Uint8Array(e);return kr.getRandomValues(t)},xr=Yt("simple-peer"),Ar=65536;function Tr(e){return e.replace(/a=ice-options:trickle\s\n/g,"")}var Rr=function(e){"use strict";(0,E.default)(n,e);var t=(0,I.default)(n);function n(e){var r;if((0,_.default)(this,n),r=t.call(this,e=Object.assign({allowHalfOpen:!1},e)),(0,w.default)((0,g.default)(r),"_pc",void 0),r.__objectMode=!!e.objectMode,r._id=_r(Cr(4)).slice(0,7),r._debug("new peer %o",e),r.channelName=e.initiator?e.channelName||_r(Cr(20)):null,r.initiator=e.initiator||!1,r.channelConfig=e.channelConfig||n.channelConfig,r.channelNegotiated=r.channelConfig.negotiated,r.config=Object.assign({},n.config,e.config),r.offerOptions=e.offerOptions||{},r.answerOptions=e.answerOptions||{},r.sdpTransform=e.sdpTransform||function(e){return e},r.trickle=void 0===e.trickle||e.trickle,r.allowHalfTrickle=void 0!==e.allowHalfTrickle&&e.allowHalfTrickle,r.iceCompleteTimeout=e.iceCompleteTimeout||5e3,r._destroying=!1,r._connected=!1,r.remoteAddress=void 0,r.remoteFamily=void 0,r.remotePort=void 0,r.localAddress=void 0,r.localFamily=void 0,r.localPort=void 0,!Jt)throw"undefined"==typeof window?vr(Error("No WebRTC support: Specify `opts.wrtc` option in this environment"),"ERR_WEBRTC_SUPPORT"):vr(Error("No WebRTC support: Not a supported browser"),"ERR_WEBRTC_SUPPORT");r._pcReady=!1,r._channelReady=!1,r._iceComplete=!1,r._iceCompleteTimer=null,r._channel=null,r._pendingCandidates=[],r._isNegotiating=!1,r._firstNegotiation=!0,r._batchedNegotiation=!1,r._queuedNegotiation=!1,r._sendersAwaitingStable=[],r._closingInterval=null,r._remoteTracks=[],r._remoteStreams=[],r._chunk=null,r._cb=null,r._interval=null;try{r._pc=new Jt(r.config)}catch(e){return(0,C.default)(r,void r.__destroy(vr(e,"ERR_PC_CONSTRUCTOR")))}return r._isReactNativeWebrtc="number"==typeof r._pc._peerConnectionId,r._pc.oniceconnectionstatechange=function(){r._onIceStateChange()},r._pc.onicegatheringstatechange=function(){r._onIceStateChange()},r._pc.onconnectionstatechange=function(){r._onConnectionStateChange()},r._pc.onsignalingstatechange=function(){r._onSignalingStateChange()},r._pc.onicecandidate=function(e){r._onIceCandidate(e)},"object"==typeof r._pc.peerIdentity&&r._pc.peerIdentity.catch((function(e){r.__destroy(vr(e,"ERR_PC_PEER_IDENTITY"))})),r.initiator||r.channelNegotiated?r._setupData({channel:r._pc.createDataChannel(r.channelName,r.channelConfig)}):r._pc.ondatachannel=function(e){r._setupData(e)},r._debug("initial negotiation"),r._needsNegotiation(),r._onFinishBound=function(){r._onFinish()},r.once("finish",r._onFinishBound),(0,C.default)(r)}return(0,b.default)(n,[{key:"bufferSize",get:function(){return this._channel&&this._channel.bufferedAmount||0}},{key:"connected",get:function(){return this._connected&&"open"===this._channel.readyState}},{key:"address",value:function(){return{port:this.localPort,family:this.localFamily,address:this.localAddress}}},{key:"signal",value:function(e){var t=this;if(!this._destroying){if(this.destroyed)throw vr(Error("cannot signal after peer is destroyed"),"ERR_DESTROYED");if("string"==typeof e)try{e=JSON.parse(e)}catch(t){e={}}this._debug("signal()"),e.renegotiate&&this.initiator&&(this._debug("got request to renegotiate"),this._needsNegotiation()),e.transceiverRequest&&this.initiator&&(this._debug("got request for transceiver"),this.addTransceiver(e.transceiverRequest.kind,e.transceiverRequest.init)),e.candidate&&(this._pc.remoteDescription&&this._pc.remoteDescription.type?this._addIceCandidate(e.candidate):this._pendingCandidates.push(e.candidate)),e.sdp&&this._pc.setRemoteDescription(new $t(e)).then((function(){t.destroyed||(t._pendingCandidates.forEach((function(e){t._addIceCandidate(e)})),t._pendingCandidates=[],"offer"===t._pc.remoteDescription.type&&t._createAnswer())})).catch((function(e){t.__destroy(vr(e,"ERR_SET_REMOTE_DESCRIPTION"))})),e.sdp||e.candidate||e.renegotiate||e.transceiverRequest||this.__destroy(vr(Error("signal() called with invalid signal data"),"ERR_SIGNALING"))}}},{key:"_addIceCandidate",value:function(e){var t=this,n=new Qt(e);this._pc.addIceCandidate(n).catch((function(e){!n.address||n.address.endsWith(".local")?console.warn("Ignoring unsupported ICE candidate."):t.__destroy(vr(e,"ERR_ADD_ICE_CANDIDATE"))}))}},{key:"send",value:function(e){if(!this._destroying){if(this.destroyed)throw vr(Error("cannot send after peer is destroyed"),"ERR_DESTROYED");this._channel.send(e)}}},{key:"_needsNegotiation",value:function(){var e=this;this._debug("_needsNegotiation"),this._batchedNegotiation||(this._batchedNegotiation=!0,queueMicrotask((function(){e._batchedNegotiation=!1,e.initiator||!e._firstNegotiation?(e._debug("starting batched negotiation"),e.negotiate()):e._debug("non-initiator initial negotiation request discarded"),e._firstNegotiation=!1})))}},{key:"negotiate",value:function(){var e=this;if(!this._destroying){if(this.destroyed)throw vr(Error("cannot negotiate after peer is destroyed"),"ERR_DESTROYED");this.initiator?this._isNegotiating?(this._queuedNegotiation=!0,this._debug("already negotiating, queueing")):(this._debug("start negotiation"),setTimeout((function(){e._createOffer()}),0)):this._isNegotiating?(this._queuedNegotiation=!0,this._debug("already negotiating, queueing")):(this._debug("requesting negotiation from initiator"),this.emit("signal",{type:"renegotiate",renegotiate:!0})),this._isNegotiating=!0}}},{key:"_final",value:function(e){this._readableState.ended||this.push(null),e(null)}},{key:"__destroy",value:function(e){this.end(),this._destroy((function(){}),e)}},{key:"_destroy",value:function(e,t){var n=this;this.destroyed||this._destroying||(this._destroying=!0,this._debug("destroying (error: %s)",t&&(t.message||t)),setTimeout((function(){if(n._connected=!1,n._pcReady=!1,n._channelReady=!1,n._remoteTracks=null,n._remoteStreams=null,n._senderMap=null,clearInterval(n._closingInterval),n._closingInterval=null,clearInterval(n._interval),n._interval=null,n._chunk=null,n._cb=null,n._onFinishBound&&n.removeListener("finish",n._onFinishBound),n._onFinishBound=null,n._channel){try{n._channel.close()}catch(e){}n._channel.onmessage=null,n._channel.onopen=null,n._channel.onclose=null,n._channel.onerror=null}if(n._pc){try{n._pc.close()}catch(e){}n._pc.oniceconnectionstatechange=null,n._pc.onicegatheringstatechange=null,n._pc.onsignalingstatechange=null,n._pc.onicecandidate=null,n._pc.ontrack=null,n._pc.ondatachannel=null}n._pc=null,n._channel=null,t&&n.emit("error",t),e()}),0))}},{key:"_setupData",value:function(e){var t=this;if(!e.channel)return this.__destroy(vr(Error("Data channel event is missing `channel` property"),"ERR_DATA_CHANNEL"));this._channel=e.channel,this._channel.binaryType="arraybuffer","number"==typeof this._channel.bufferedAmountLowThreshold&&(this._channel.bufferedAmountLowThreshold=Ar),this.channelName=this._channel.label,this._channel.onmessage=function(e){t._onChannelMessage(e)},this._channel.onbufferedamountlow=function(){t._onChannelBufferedAmountLow()},this._channel.onopen=function(){t._onChannelOpen()},this._channel.onclose=function(){t._onChannelClose()},this._channel.onerror=function(e){var n=e.error instanceof Error?e.error:Error("Datachannel error: ".concat(e.message," ").concat(e.filename,":").concat(e.lineno,":").concat(e.colno));t.__destroy(vr(n,"ERR_DATA_CHANNEL"))};var n=!1;this._closingInterval=setInterval((function(){t._channel&&"closing"===t._channel.readyState?(n&&t._onChannelClose(),n=!0):n=!1}),5e3)}},{key:"_write",value:function(e,t){if(this.destroyed)return t(vr(Error("cannot write after peer is destroyed"),"ERR_DATA_CHANNEL"));if(this._connected){try{this.send(e)}catch(e){return this.__destroy(vr(e,"ERR_DATA_CHANNEL"))}this._channel.bufferedAmount>Ar?(this._debug("start backpressure: bufferedAmount %d",this._channel.bufferedAmount),this._cb=t):t(null)}else this._debug("write before connect"),this._chunk=e,this._cb=t}},{key:"_onFinish",value:function(){var e=this;if(!this.destroyed){var t=function(){setTimeout((function(){return e.__destroy()}),1e3)};this._connected?t():this.once("connect",t)}}},{key:"_startIceCompleteTimeout",value:function(){var e=this;this.destroyed||this._iceCompleteTimer||(this._debug("started iceComplete timeout"),this._iceCompleteTimer=setTimeout((function(){e._iceComplete||(e._iceComplete=!0,e._debug("iceComplete timeout completed"),e.emit("iceTimeout"),e.emit("_iceComplete"))}),this.iceCompleteTimeout))}},{key:"_createOffer",value:function(){var e=this;this.destroyed||this._pc.createOffer(this.offerOptions).then((function(t){if(!e.destroyed){e.trickle||e.allowHalfTrickle||(t.sdp=Tr(t.sdp)),t.sdp=e.sdpTransform(t.sdp);var n=function(){if(!e.destroyed){var n=e._pc.localDescription||t;e._debug("signal"),e.emit("signal",{type:n.type,sdp:n.sdp})}};e._pc.setLocalDescription(t).then((function(){e._debug("createOffer success"),e.destroyed||(e.trickle||e._iceComplete?n():e.once("_iceComplete",n))})).catch((function(t){e.__destroy(vr(t,"ERR_SET_LOCAL_DESCRIPTION"))}))}})).catch((function(t){e.__destroy(vr(t,"ERR_CREATE_OFFER"))}))}},{key:"_createAnswer",value:function(){var e=this;this.destroyed||this._pc.createAnswer(this.answerOptions).then((function(t){if(!e.destroyed){e.trickle||e.allowHalfTrickle||(t.sdp=Tr(t.sdp)),t.sdp=e.sdpTransform(t.sdp);var n=function(){var n,r;if(!e.destroyed){var i=e._pc.localDescription||t;e._debug("signal"),e.emit("signal",{type:i.type,sdp:i.sdp}),e.initiator||null===(r=(n=e)._requestMissingTransceivers)||void 0===r||r.call(n)}};e._pc.setLocalDescription(t).then((function(){e.destroyed||(e.trickle||e._iceComplete?n():e.once("_iceComplete",n))})).catch((function(t){e.__destroy(vr(t,"ERR_SET_LOCAL_DESCRIPTION"))}))}})).catch((function(t){e.__destroy(vr(t,"ERR_CREATE_ANSWER"))}))}},{key:"_onConnectionStateChange",value:function(){this.destroyed||this._destroying||"failed"===this._pc.connectionState&&this.__destroy(vr(Error("Connection failed."),"ERR_CONNECTION_FAILURE"))}},{key:"_onIceStateChange",value:function(){if(!this.destroyed){var e=this._pc.iceConnectionState,t=this._pc.iceGatheringState;this._debug("iceStateChange (connection: %s) (gathering: %s)",e,t),this.emit("iceStateChange",e,t),"connected"!==e&&"completed"!==e||(this._pcReady=!0,this._maybeReady()),"failed"===e&&this.__destroy(vr(Error("Ice connection failed."),"ERR_ICE_CONNECTION_FAILURE")),"closed"===e&&this.__destroy(vr(Error("Ice connection closed."),"ERR_ICE_CONNECTION_CLOSED"))}}},{key:"getStats",value:function(e){var t=this,n=function(e){return"[object Array]"==={}.toString.call(e.values)&&e.values.forEach((function(t){Object.assign(e,t)})),e};0===this._pc.getStats.length||this._isReactNativeWebrtc?this._pc.getStats().then((function(t){var r=[];t.forEach((function(e){r.push(n(e))})),e(null,r)}),(function(t){return e(t)})):this._pc.getStats.length>0?this._pc.getStats((function(r){if(!t.destroyed){var i=[];r.result().forEach((function(e){var t={};e.names().forEach((function(n){t[n]=e.stat(n)})),t.id=e.id,t.type=e.type,t.timestamp=e.timestamp,i.push(n(t))})),e(null,i)}}),(function(t){return e(t)})):e(null,[])}},{key:"_maybeReady",value:function(){var e=this;if(this._debug("maybeReady pc %s channel %s",this._pcReady,this._channelReady),!this._connected&&!this._connecting&&this._pcReady&&this._channelReady){this._connecting=!0;var t=function(){e.destroyed||e._destroying||e.getStats((function(n,r){if(!e.destroyed&&!e._destroying){n&&(r=[]);var i={},a={},o={},u=!1;r.forEach((function(e){"remotecandidate"!==e.type&&"remote-candidate"!==e.type||(i[e.id]=e),"localcandidate"!==e.type&&"local-candidate"!==e.type||(a[e.id]=e),"candidatepair"!==e.type&&"candidate-pair"!==e.type||(o[e.id]=e)}));var s=function(t){u=!0;var n=a[t.localCandidateId];n&&(n.ip||n.address)?(e.localAddress=n.ip||n.address,e.localPort=Number(n.port)):n&&n.ipAddress?(e.localAddress=n.ipAddress,e.localPort=Number(n.portNumber)):"string"==typeof t.googLocalAddress&&(n=t.googLocalAddress.split(":"),e.localAddress=n[0],e.localPort=Number(n[1])),e.localAddress&&(e.localFamily=e.localAddress.includes(":")?"IPv6":"IPv4");var r=i[t.remoteCandidateId];r&&(r.ip||r.address)?(e.remoteAddress=r.ip||r.address,e.remotePort=Number(r.port)):r&&r.ipAddress?(e.remoteAddress=r.ipAddress,e.remotePort=Number(r.portNumber)):"string"==typeof t.googRemoteAddress&&(r=t.googRemoteAddress.split(":"),e.remoteAddress=r[0],e.remotePort=Number(r[1])),e.remoteAddress&&(e.remoteFamily=e.remoteAddress.includes(":")?"IPv6":"IPv4"),e._debug("connect local: %s:%s remote: %s:%s",e.localAddress,e.localPort,e.remoteAddress,e.remotePort)};if(r.forEach((function(e){"transport"===e.type&&e.selectedCandidatePairId&&s(o[e.selectedCandidatePairId]),("googCandidatePair"===e.type&&"true"===e.googActiveConnection||("candidatepair"===e.type||"candidate-pair"===e.type)&&e.selected)&&s(e)})),u||Object.keys(o).length&&!Object.keys(a).length){if(e._connecting=!1,e._connected=!0,e._chunk){try{e.send(e._chunk)}catch(n){return e.__destroy(vr(n,"ERR_DATA_CHANNEL"))}e._chunk=null,e._debug('sent chunk from "write before connect"');var c=e._cb;e._cb=null,c(null)}"number"!=typeof e._channel.bufferedAmountLowThreshold&&(e._interval=setInterval((function(){return e._onInterval()}),150),e._interval.unref&&e._interval.unref()),e._debug("connect"),e.emit("connect")}else setTimeout(t,100)}}))};t()}}},{key:"_onInterval",value:function(){!this._cb||!this._channel||this._channel.bufferedAmount>Ar||this._onChannelBufferedAmountLow()}},{key:"_onSignalingStateChange",value:function(){var e=this;this.destroyed||("stable"===this._pc.signalingState&&(this._isNegotiating=!1,this._debug("flushing sender queue",this._sendersAwaitingStable),this._sendersAwaitingStable.forEach((function(t){e._pc.removeTrack(t),e._queuedNegotiation=!0})),this._sendersAwaitingStable=[],this._queuedNegotiation?(this._debug("flushing negotiation queue"),this._queuedNegotiation=!1,this._needsNegotiation()):(this._debug("negotiated"),this.emit("negotiated"))),this._debug("signalingStateChange %s",this._pc.signalingState),this.emit("signalingStateChange",this._pc.signalingState))}},{key:"_onIceCandidate",value:function(e){this.destroyed||(e.candidate&&this.trickle?this.emit("signal",{type:"candidate",candidate:{candidate:e.candidate.candidate,sdpMLineIndex:e.candidate.sdpMLineIndex,sdpMid:e.candidate.sdpMid}}):e.candidate||this._iceComplete||(this._iceComplete=!0,this.emit("_iceComplete")),e.candidate&&this._startIceCompleteTimeout())}},{key:"_onChannelMessage",value:function(e){if(!this.destroyed){var t,n=e.data;n instanceof ArrayBuffer?n=new Uint8Array(n):!1===this.__objectMode&&(t=n,n=Er.encode(t)),this.push(n)}}},{key:"_onChannelBufferedAmountLow",value:function(){if(!this.destroyed&&this._cb){this._debug("ending backpressure: bufferedAmount %d",this._channel.bufferedAmount);var e=this._cb;this._cb=null,e(null)}}},{key:"_onChannelOpen",value:function(){this._connected||this.destroyed||(this._debug("on channel open"),this._channelReady=!0,this._maybeReady())}},{key:"_onChannelClose",value:function(){this.destroyed||(this._debug("on channel close"),this.__destroy())}},{key:"_debug",value:function(){var e=[].slice.call(arguments);e[0]="["+this._id+"] "+e[0],xr.apply(null,e)}}]),n}(hr);Rr.WEBRTC_SUPPORT=!!Jt,Rr.config={iceServers:[{urls:["stun:stun.l.google.com:19302","stun:global.stun.twilio.com:3478"]}],sdpSemantics:"unified-plan"},Rr.channelConfig={};var Ir=function(e){"use strict";(0,E.default)(n,e);var t=(0,I.default)(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return(0,_.default)(this,n),(e=t.call(this,r))._pc&&(e.streams=r.streams||(r.stream?[r.stream]:[]),e._senderMap=new Map,e.streams&&e.streams.forEach((function(t){e.addStream(t)})),e._pc.ontrack=function(t){e._onTrack(t)}),(0,C.default)(e)}return(0,b.default)(n,[{key:"addTransceiver",value:function(e,t){if(!this._destroying){if(this.destroyed)throw vr(Error("cannot addTransceiver after peer is destroyed"),"ERR_DESTROYED");if(this._debug("addTransceiver()"),this.initiator)try{this._pc.addTransceiver(e,t),this._needsNegotiation()}catch(e){this.__destroy(vr(e,"ERR_ADD_TRANSCEIVER"))}else this.emit("signal",{type:"transceiverRequest",transceiverRequest:{kind:e,init:t}})}}},{key:"addStream",value:function(e){var t=this;if(!this._destroying){if(this.destroyed)throw vr(Error("cannot addStream after peer is destroyed"),"ERR_DESTROYED");this._debug("addStream()"),e.getTracks().forEach((function(n){t.addTrack(n,e)}))}}},{key:"addTrack",value:function(e,t){if(!this._destroying){if(this.destroyed)throw vr(Error("cannot addTrack after peer is destroyed"),"ERR_DESTROYED");this._debug("addTrack()");var n=this._senderMap.get(e)||new Map,r=n.get(t);if(r)throw r.removed?vr(Error("Track has been removed. You should enable/disable tracks that you want to re-add."),"ERR_SENDER_REMOVED"):vr(Error("Track has already been added to that stream."),"ERR_SENDER_ALREADY_ADDED");r=this._pc.addTrack(e,t),n.set(t,r),this._senderMap.set(e,n),this._needsNegotiation()}}},{key:"replaceTrack",value:function(e,t,n){if(!this._destroying){if(this.destroyed)throw vr(Error("cannot replaceTrack after peer is destroyed"),"ERR_DESTROYED");this._debug("replaceTrack()");var r=this._senderMap.get(e),i=r?r.get(n):null;if(!i)throw vr(Error("Cannot replace track that was never added."),"ERR_TRACK_NOT_ADDED");t&&this._senderMap.set(t,r),null!=i.replaceTrack?i.replaceTrack(t):this.__destroy(vr(Error("replaceTrack is not supported in this browser"),"ERR_UNSUPPORTED_REPLACETRACK"))}}},{key:"removeTrack",value:function(e,t){if(!this._destroying){if(this.destroyed)throw vr(Error("cannot removeTrack after peer is destroyed"),"ERR_DESTROYED");this._debug("removeSender()");var n=this._senderMap.get(e),r=n?n.get(t):null;if(!r)throw vr(Error("Cannot remove track that was never added."),"ERR_TRACK_NOT_ADDED");try{r.removed=!0,this._pc.removeTrack(r)}catch(e){"NS_ERROR_UNEXPECTED"===e.name?this._sendersAwaitingStable.push(r):this.__destroy(vr(e,"ERR_REMOVE_TRACK"))}this._needsNegotiation()}}},{key:"removeStream",value:function(e){var t=this;if(!this._destroying){if(this.destroyed)throw vr(Error("cannot removeStream after peer is destroyed"),"ERR_DESTROYED");this._debug("removeSenders()"),e.getTracks().forEach((function(n){t.removeTrack(n,e)}))}}},{key:"_requestMissingTransceivers",value:function(){var e=this;this._pc.getTransceivers&&this._pc.getTransceivers().forEach((function(t){t.mid||!t.sender.track||t.requested||(t.requested=!0,e.addTransceiver(t.sender.track.kind))}))}},{key:"_onTrack",value:function(e){var t=this;this.destroyed||e.streams.forEach((function(n){t._debug("on track"),t.emit("track",e.track,n),t._remoteTracks.push({track:e.track,stream:n}),t._remoteStreams.some((function(e){return e.id===n.id}))||(t._remoteStreams.push(n),queueMicrotask((function(){t._debug("on stream"),t.emit("stream",n)})))}))}}]),n}(Rr),Nr="data",Br="signal",Or=function(e,t){var n=new Ir((0,k.default)((0,S.default)({iceServers:[{urls:Lr}]},t),{initiator:e,trickle:!1})),r=function(e){return i.push(e)},i=[];return n.on(Nr,r),{id:n._id,created:Date.now(),connection:n._pc,get channel(){return n._channel},get isDead(){return n.destroyed},signal:function(t){return new Promise((function(r){e||n.on(Br,r),n.signal(t)}))},sendData:function(e){return n.send(e)},destroy:function(){return n.destroy()},setHandlers:function(e){return Object.entries(e).forEach((function(e){var t=(0,x.default)(e,2),r=t[0],i=t[1];return n.on(r,i)}))},offerPromise:e?new Promise((function(e){return n.on(Br,e)})):Promise.resolve(),addStream:function(e){return n.addStream(e)},removeStream:function(e){return n.removeStream(e)},addTrack:function(e,t){return n.addTrack(e,t)},removeTrack:function(e,t){return n.removeTrack(e,t)},replaceTrack:function(e,t,r){return n.replaceTrack(e,t,r)},drainEarlyData:function(e){n.off(Nr,r),i.forEach(e),i=null}}},Lr=(0,A.default)(_t(5,(function(e,t){return"stun:stun".concat(t||"",".l.google.com:19302")}))).concat(["stun:global.stun.twilio.com:3478"]),Pr=Object.getPrototypeOf(Uint8Array),Fr=16369,Dr=255,Ur="bufferedamountlow",qr=function(e){return"@_"+e},Mr={},jr="EVENT",Hr=St&>.utils.randomPrivateKey(),zr=St&&Ot(gt.getPublicKey(Hr)),Wr={},Kr={},Vr=function(){return Math.floor(Date.now()/1e3)},Zr=function(){var e=(0,m.default)((function(e,t){var n,r,i,a,o,u;return(0,N.__generator)(this,(function(s){switch(s.label){case 0:return n={kind:29333,content:t,pubkey:zr,created_at:Vr(),tags:[["x",e]]},i=Uint8Array.bind,[4,crypto.subtle.digest("SHA-256",Nt(Pt([0,n.pubkey,n.created_at,n.kind,n.tags,n.content])))];case 1:return r=Ot.apply(void 0,[new(i.apply(Uint8Array,[void 0,s.sent()]))]),a=[jr],o=[(0,S.default)({},n)],u={id:r},[4,gt.sign(r,Hr)];case 2:return[2,Pt.apply(void 0,[a.concat([k.default.apply(void 0,o.concat([(u.sig=Ot.apply(void 0,[s.sent()]),u)]))])])]}}))}));return function(t,n){return e.apply(this,arguments)}}(),Yr=function(e,t){return Wr[e]=t,Pt(["REQ",e,{kinds:[29333],since:Vr(),"#x":[t]}])},Gr=function(e){return delete Wr[e],Pt(["CLOSE",e])},Jr=function(e){var t,n,r,i=e.init,v=e.subscribe,y=e.announce,g={},_=!1;return function(e,b,w){var E,C,R=e.appId;if(null===(C=g[R])||void 0===C?void 0:C[b])return g[R][b];var I={},B={},O=Lt(mt,R,b),L=Mt(O),P=Mt(Lt(O,wt)),F=e.password&&function(){var e=(0,m.default)((function(e,t,n){var r,i,a;return(0,N.__generator)(this,(function(o){switch(o.label){case 0:return i=(r=crypto.subtle).importKey,a=["raw"],[4,crypto.subtle.digest({name:"SHA-256"},Nt("".concat(e,":").concat(t,":").concat(n)))];case 1:return[2,i.apply(r,a.concat([o.sent(),{name:Ut},!1,["encrypt","decrypt"]]))]}}))}));return function(t,n,r){return e.apply(this,arguments)}}()(e.password,R,b),D=function(e){return function(){var t=(0,m.default)((function(t){var n,r;return(0,N.__generator)(this,(function(i){switch(i.label){case 0:return F?(r={type:t.type},[4,e(F,t.sdp)]):[3,2];case 1:return r.sdp=i.sent(),n=r,[3,3];case 2:n=t,i.label=3;case 3:return[2,n]}}))}));return function(e){return t.apply(this,arguments)}}()},U=D(Ht),q=D(jt),M=function(){return Or(!0,e.rtcConfig)},j=function(e,t,n){var r;B[t]?B[t]!==e&&e.destroy():(B[t]=e,J(e,t),null===(r=I[t])||void 0===r||r.forEach((function(e,t){t!==n&&e.destroy()})),delete I[t])},H=function(e,t){B[t]===e&&delete B[t]},z=function(e){return(E=n).push.apply(E,(0,A.default)(_t(e,M))),Et(n.splice(0,e).map((function(e){return e.offerPromise.then(q).then((function(t){return{peer:e,offer:t}}))})))},W=function(t,n){return null==w?void 0:w({error:"incorrect password (".concat(e.password,") when decrypting ").concat(n),appId:R,peerId:t,roomId:b})},K=function(t){return function(){var n=(0,m.default)((function(n,r,i){var u,s,c,l,f,d,h,p,v,y,g,m,_,b,w,E,S,k,C,A,T,R,F,D,M,K;return(0,N.__generator)(this,(function(N){switch(N.label){case 0:return[4,Et([L,P])];case 1:if(u=x.default.apply(void 0,[N.sent(),2]),s=u[0],c=u[1],n!==s&&n!==c)return[2];if(l="string"==typeof r?Ft(r):r,f=l.peerId,d=l.offer,h=l.answer,p=l.peer,f===wt||B[f])return[3,16];if(f&&!d&&!h)return[3,14];if(!d)return[3,8];if((null===(v=I[f])||void 0===v?void 0:v[t])&&wt>f)return[2];(y=Or(!1,e.rtcConfig)).setHandlers({connect:function(){return j(y,f,t)},close:function(){return H(y,f)}}),N.label=2;case 2:return N.trys.push([2,4,,5]),[4,U(d)];case 3:return g=N.sent(),[3,5];case 4:return N.sent(),[2,void W(f,"offer")];case 5:return y.isDead?[2]:[4,Et([Mt(Lt(O,f)),y.signal(g)])];case 6:return m=x.default.apply(void 0,[N.sent(),2]),_=m[0],b=m[1],w=[_],E={peerId:wt},[4,q(b)];case 7:return i.apply(void 0,w.concat([Pt.apply(void 0,[(E.answer=N.sent(),E)])])),[3,13];case 8:if(!h)return[3,13];N.label=9;case 9:return N.trys.push([9,11,,12]),[4,U(h)];case 10:return S=N.sent(),[3,12];case 11:return N.sent(),[2,void W(f,"answer")];case 12:p?(p.setHandlers({connect:function(){return j(p,f,t)},close:function(){return H(p,f)}}),p.signal(S)):(C=null===(k=I[f])||void 0===k?void 0:k[t])&&!C.isDead&&C.signal(S),N.label=13;case 13:return[3,16];case 14:return(null===(A=I[f])||void 0===A?void 0:A[t])?[2]:[4,Et([z(1),Mt(Lt(O,f))])];case 15:T=x.default.apply(void 0,[N.sent(),2]),R=(0,x.default)(T[0],1),F=R[0],D=F.peer,M=F.offer,K=T[1],(a=I)[o=f]||(a[o]=[]),I[f][t]=D,setTimeout((function(){return function(e,t){var n;if(!B[e]){var r=null===(n=I[e])||void 0===n?void 0:n[t];r&&(delete I[e][t],r.destroy())}}(f,t)}),.9*Z[t]),D.setHandlers({connect:function(){return j(D,f,t)},close:function(){return H(D,f)}}),i(K,Pt({peerId:wt,offer:M})),N.label=16;case 16:return[2]}}))}));return function(e,t,r){return n.apply(this,arguments)}}()};if(!e)throw Tt("requires a config map as the first argument");if(!R&&!e.firebaseApp)throw Tt("config map is missing appId field");if(!b)throw Tt("roomId argument required");if(!_){var V=i(e);n=_t(20,M),t=Array.isArray(V)?V:[V],_=!0,r=setInterval((function(){return n=n.filter((function(e){var t=Date.now()-e.created<57333;return t||e.destroy(),t}))}),59052.99)}var Z=t.map((function(){return 5333})),Y=[],G=t.map(function(){var e=(0,m.default)((function(e,t){var n;return(0,N.__generator)(this,(function(r){switch(r.label){case 0:return[4,e];case 1:return n=[r.sent()],[4,L];case 2:return n=n.concat(r.sent()),[4,P];case 3:return[2,v.apply(void 0,n.concat([r.sent(),K(t),z]))]}}))}));return function(t,n){return e.apply(this,arguments)}}());Et([L,P]).then((function(e){var n=(0,x.default)(e,2),r=n[0],i=n[1],a=function(){var e=(0,m.default)((function(e,t){var n;return(0,N.__generator)(this,(function(o){switch(o.label){case 0:return[4,y(e,r,i)];case 1:return"number"==typeof(n=o.sent())&&(Z[t]=n),Y[t]=setTimeout((function(){return a(e,t)}),Z[t]),[2]}}))}));return function(t,n){return e.apply(this,arguments)}}();G.forEach(function(){var e=(0,m.default)((function(e,n){return(0,N.__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 J=At;return(u=g)[s=R]||(u[s]={}),g[R][b]=function(e,t,n){var r={},i={},a={},o={},u={},s={},v={onPeerJoin:At,onPeerLeave:At,onPeerStream:At,onPeerTrack:At},y=function(e,t){return(e?Array.isArray(e)?e:[e]:xt(r)).flatMap((function(e){var n=r[e];return n?t(e,n):(console.warn("".concat(mt,": no peer with id ").concat(e," found")),[])}))},g=function(e){r[e]&&(delete r[e],delete a[e],delete o[e],v.onPeerLeave(e),t(e))},_=function(e){if(i[e])return[i[e].send,i[e].setOnComplete,i[e].setOnProgress];if(!e)throw Tt("action type argument is required");var t=Nt(e);if(t.byteLength>12)throw Tt('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 a=0;return i[e]={onComplete:At,onProgress:At,setOnComplete:function(t){return i[e]=(0,k.default)((0,S.default)({},i[e]),{onComplete:t})},setOnProgress:function(t){return i[e]=(0,k.default)((0,S.default)({},i[e]),{onProgress:t})},send:function(e,t,i,o){return(0,m.default)((function(){var u,s,c,l,f,d,h,p,v,g,_;return(0,N.__generator)(this,(function(b){switch(b.label){case 0:if(i&&"object"!=typeof i)throw Tt("action meta argument must be an object");if("undefined"===(u=void 0===e?"undefined":(0,T.default)(e)))throw Tt("action data cannot be undefined");if(s="string"!==u,c=e instanceof Blob,l=c||e instanceof ArrayBuffer||e instanceof Pr,i&&!l)throw Tt("action meta argument can only be used with binary data");return l?(g=Uint8Array.bind,c?[4,e.arrayBuffer()]:[3,2]):[3,4];case 1:return _=b.sent(),[3,3];case 2:_=e,b.label=3;case 3:return v=new(g.apply(Uint8Array,[void 0,_])),[3,5];case 4:v=Nt(s?Pt(e):e),b.label=5;case 5:return f=v,d=i?Nt(Pt(i)):null,h=Math.ceil(f.byteLength/Fr)+(i?1:0)||1,p=_t(h,(function(e,t){var r=t===h-1,o=i&&0===t,u=new Uint8Array(15+(o?d.byteLength:r?f.byteLength-Fr*(h-(i?2:1)):Fr));return u.set(n),u.set([a],12),u.set([r|o<<1|l<<2|s<<3],13),u.set([Math.round((t+1)/h*Dr)],14),u.set(i?o?d:f.subarray((t-1)*Fr,t*Fr):f.subarray(t*Fr,(t+1)*Fr),15),u})),[2,(a=a+1&Dr,Et(y(t,function(){var e=(0,m.default)((function(e,t){var n,a,u;return(0,N.__generator)(this,(function(s){switch(s.label){case 0:n=t.channel,a=0,s.label=1;case 1:return a<h?(u=p[a],n.bufferedAmount>n.bufferedAmountLowThreshold?[4,new Promise((function(e){var t=function(){n.removeEventListener(Ur,t),e()};n.addEventListener(Ur,t)}))]:[3,3]):[3,5];case 2:s.sent(),s.label=3;case 3:if(!r[e])return[3,5];t.sendData(u),a++,null==o||o(u[14]/Dr,e,i),s.label=4;case 4:return[3,1];case 5:return[2]}}))}));return function(t,n){return e.apply(this,arguments)}}())))]}}))}))()}},[i[e].send,i[e].setOnComplete,i[e].setOnProgress]},b=function(e,t){var n=new Uint8Array(t),r=Bt(n.subarray(0,12)).replaceAll("\0",""),o=(0,x.default)(n.subarray(12,13),1)[0],u=(0,x.default)(n.subarray(13,14),1)[0],s=(0,x.default)(n.subarray(14,15),1)[0],v=n.subarray(15),y=!!(1&u),g=!!(2&u),m=!!(4&u),_=!!(8&u);if(i[r]){(c=a)[l=e]||(c[l]={}),(f=a[e])[d=r]||(f[d]={});var b=(h=a[e][r])[p=o]||(h[p]={chunks:[]});if(g?b.meta=Ft(Bt(v)):b.chunks.push(v),i[r].onProgress(s/Dr,e,b.meta),y){var w=new Uint8Array(b.chunks.reduce((function(e,t){return e+t.byteLength}),0));if(b.chunks.reduce((function(e,t){return w.set(t,e),e+t.byteLength}),0),delete a[e][r][o],m)i[r].onComplete(w,e,b.meta);else{var E=Bt(w);i[r].onComplete(_?Ft(E):E,e)}}}else console.warn("".concat(mt,": received message with unregistered type (").concat(r,")"))},w=(0,x.default)(_(qr("ping")),2),E=w[0],C=w[1],A=(0,x.default)(_(qr("pong")),2),R=A[0],I=A[1],B=(0,x.default)(_(qr("signal")),2),O=B[0],L=B[1],P=(0,x.default)(_(qr("stream")),2),F=P[0],D=P[1],U=(0,x.default)(_(qr("track")),2),q=U[0],M=U[1],j=(0,x.default)(_(qr("leave")),2),H=j[0],z=j[1];return J=function(e,t){var n;r[t]||(r[t]=e,e.setHandlers({data:function(e){return b(t,e)},stream:function(e){v.onPeerStream(e,t,u[t]),delete u[t]},track:function(e,n){v.onPeerTrack(e,n,t,s[t]),delete s[t]},signal:function(e){return O(e,t)},close:function(){return g(t)},error:function(){return g(t)}}),v.onPeerJoin(t),null===(n=e.drainEarlyData)||void 0===n||n.call(e,(function(e){return b(t,e)})))},C((function(e,t){return R("",t)})),I((function(e,t){var n;null===(n=o[t])||void 0===n||n.call(o),delete o[t]})),L((function(e,t){var n;return null===(n=r[t])||void 0===n?void 0:n.signal(e)})),D((function(e,t){return u[t]=e})),M((function(e,t){return s[t]=e})),z((function(e,t){return g(t)})),{makeAction:_,ping:function(e){return(0,m.default)((function(){var t;return(0,N.__generator)(this,(function(n){switch(n.label){case 0:if(!e)throw Tt("ping() must be called with target peer ID");return t=Date.now(),E("",e),[4,new Promise((function(t){return o[e]=t}))];case 1:return[2,(n.sent(),Date.now()-t)]}}))}))()},leave:function(){return(0,m.default)((function(){return(0,N.__generator)(this,(function(e){switch(e.label){case 0:return[4,H("")];case 1:return e.sent(),[4,new Promise((function(e){return setTimeout(e,99)}))];case 2:return e.sent(),kt(r).forEach((function(e){var t=(0,x.default)(e,2),n=t[0];t[1].destroy(),delete r[n]})),n(),[2]}}))}))()},getPeers:function(){return Ct(kt(r).map((function(e){var t=(0,x.default)(e,2);return[t[0],t[1].connection]})))},addStream:function(e,t,n){return y(t,function(){var t=(0,m.default)((function(t,r){return(0,N.__generator)(this,(function(i){switch(i.label){case 0:return n?[4,F(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 y(t,(function(t,n){return n.removeStream(e)}))},addTrack:function(e,t,n,r){return y(n,function(){var n=(0,m.default)((function(n,i){return(0,N.__generator)(this,(function(a){switch(a.label){case 0:return r?[4,q(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,n){return y(n,(function(n,r){return r.removeTrack(e,t)}))},replaceTrack:function(e,t,n,r,i){return y(r,function(){var r=(0,m.default)((function(r,a){return(0,N.__generator)(this,(function(o){switch(o.label){case 0:return i?[4,q(i,r)]:[3,2];case 1:o.sent(),o.label=2;case 2:return a.replaceTrack(e,t,n),[2]}}))}));return function(e,t){return r.apply(this,arguments)}}())},onPeerJoin:function(e){return v.onPeerJoin=e},onPeerLeave:function(e){return v.onPeerLeave=e},onPeerStream:function(e){return v.onPeerStream=e},onPeerTrack:function(e){return v.onPeerTrack=e}}}(0,(function(e){return delete B[e]}),(function(){delete g[R][b],Y.forEach(clearTimeout),G.forEach(function(){var e=(0,m.default)((function(e){return(0,N.__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)}))}}({init:function(e){return function(e,t,n){return(e.relayUrls||t).slice(0,e.relayUrls?e.relayUrls.length:e.relayRedundancy||5)}(e,$r).map((function(e){var t=function(e,t){var n={},r=function(){var i=new WebSocket(e);i.onclose=function(){var t;null!==(t=(v=Dt)[y=e])&&void 0!==t||(v[y]=3333),setTimeout(r,Dt[e]),Dt[e]*=2},i.onmessage=function(e){return t(e.data)},n.socket=i,n.url=i.url,n.ready=new Promise((function(t){return i.onopen=function(){t(n),Dt[e]=3333}})),n.send=function(e){1===i.readyState&&i.send(e)}};return r(),n}(e,(function(e){var n,r=(0,x.default)(Ft(e),4),i=r[0],a=r[1],o=r[2],u=r[3];if(i===jr)null===(n=Kr[a])||void 0===n||n.call(Kr,Wr[a],o.content);else{var s="".concat(mt,": relay failure from ").concat(t.url," - ");"NOTICE"===i?console.warn(s+a):"OK"!==i||o||console.warn(s+u)}}));return Mr[e]=t,t.ready}))},subscribe:function(e,t,n,r){var i=bt(64),a=bt(64);return Kr[i]=Kr[a]=function(t,n){return r(t,n,function(){var t=(0,m.default)((function(t,n){var r;return(0,N.__generator)(this,(function(i){switch(i.label){case 0:return r=e.send,[4,Zr(t,n)];case 1:return[2,r.apply(e,[i.sent()])]}}))}));return function(e,n){return t.apply(this,arguments)}}())},e.send(Yr(i,t)),e.send(Yr(a,n)),function(){e.send(Gr(i)),e.send(Gr(a)),delete Kr[i],delete Kr[a]}},announce:function(e,t){return(0,m.default)((function(){var n;return(0,N.__generator)(this,(function(r){switch(r.label){case 0:return n=e.send,[4,Zr(t,Pt({peerId:wt}))];case 1:return[2,n.apply(e,[r.sent()])]}}))}))()}}),$r=(Mr,["relay.nostr.net","relay.snort.social","relay.piazza.today","relay.exit.pub","nostr.lu.ke","nostr.mom","relay.urbanzap.space","nostr.data.haus","nostr.sathoarder.com","relay.nostromo.social","relay.nostr.bg","nostr.stakey.net","nostr.vulpem.com","a.nos.lol","eu.purplerelay.com","nostr2.sanhauf.com","relay.rebelbase.site","e.nos.lol"].map((function(e){return"wss://"+e})))}))}();