UNPKG

@liascript/exporter

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