2 lines
40 KiB
JavaScript
2 lines
40 KiB
JavaScript
var at=Object.create;var Ee=Object.defineProperty;var ft=Object.getOwnPropertyDescriptor;var ut=Object.getOwnPropertyNames;var ht=Object.getPrototypeOf,lt=Object.prototype.hasOwnProperty;var pt=(t,e,r)=>e in t?Ee(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var dt=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var Ce=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var mt=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ut(e))!lt.call(t,o)&&o!==r&&Ee(t,o,{get:()=>e[o],enumerable:!(n=ft(e,o))||n.enumerable});return t};var Se=(t,e,r)=>(r=t!=null?at(ht(t)):{},mt(e||!t||!t.__esModule?Ee(r,"default",{value:t,enumerable:!0}):r,t));var b=(t,e,r)=>pt(t,typeof e!="symbol"?e+"":e,r);var Fe=Ce((Vt,K)=>{"use strict";var c={cipher:{},hash:{},keyexchange:{},mode:{},misc:{},codec:{},exception:{corrupt:function(t){this.toString=function(){return"CORRUPT: "+this.message},this.message=t},invalid:function(t){this.toString=function(){return"INVALID: "+this.message},this.message=t},bug:function(t){this.toString=function(){return"BUG: "+this.message},this.message=t},notReady:function(t){this.toString=function(){return"NOT READY: "+this.message},this.message=t}}};c.cipher.aes=function(t){this.w[0][0][0]||this.C();var e,r,n,o,i=this.w[0][4],s=this.w[1];e=t.length;var a=1;if(e!==4&&e!==6&&e!==8)throw new c.exception.invalid("invalid aes key size");for(this.b=[n=t.slice(0),o=[]],t=e;t<4*e+28;t++)r=n[t-1],(t%e===0||e===8&&t%e===4)&&(r=i[r>>>24]<<24^i[r>>16&255]<<16^i[r>>8&255]<<8^i[r&255],t%e===0&&(r=r<<8^r>>>24^a<<24,a=a<<1^283*(a>>7))),n[t]=n[t-e]^r;for(e=0;t;e++,t--)r=n[e&3?t:t-4],o[e]=4>=t||4>e?r:s[0][i[r>>>24]]^s[1][i[r>>16&255]]^s[2][i[r>>8&255]]^s[3][i[r&255]]};c.cipher.aes.prototype={encrypt:function(t){return Te(this,t,0)},decrypt:function(t){return Te(this,t,1)},w:[[[],[],[],[],[]],[[],[],[],[],[]]],C:function(){var t=this.w[0],e=this.w[1],r=t[4],n=e[4],o,i,s,a=[],f=[],u,h,l,m;for(o=0;256>o;o++)f[(a[o]=o<<1^283*(o>>7))^o]=o;for(i=s=0;!r[i];i^=u||1,s=f[s]||1)for(l=s^s<<1^s<<2^s<<3^s<<4,l=l>>8^l&255^99,r[i]=l,n[l]=i,h=a[o=a[u=a[i]]],m=16843009*h^65537*o^257*u^16843008*i,h=257*a[l]^16843008*l,o=0;4>o;o++)t[o][i]=h=h<<24^h>>>8,e[o][l]=m=m<<24^m>>>8;for(o=0;5>o;o++)t[o]=t[o].slice(0),e[o]=e[o].slice(0)}};function Te(t,e,r){if(e.length!==4)throw new c.exception.invalid("invalid aes block size");var n=t.b[r],o=e[0]^n[0],i=e[r?3:1]^n[1],s=e[2]^n[2];e=e[r?1:3]^n[3];var a,f,u,h=n.length/4-2,l,m=4,p=[0,0,0,0];a=t.w[r],t=a[0];var v=a[1],L=a[2],D=a[3],P=a[4];for(l=0;l<h;l++)a=t[o>>>24]^v[i>>16&255]^L[s>>8&255]^D[e&255]^n[m],f=t[i>>>24]^v[s>>16&255]^L[e>>8&255]^D[o&255]^n[m+1],u=t[s>>>24]^v[e>>16&255]^L[o>>8&255]^D[i&255]^n[m+2],e=t[e>>>24]^v[o>>16&255]^L[i>>8&255]^D[s&255]^n[m+3],m+=4,o=a,i=f,s=u;for(l=0;4>l;l++)p[r?3&-l:l]=P[o>>>24]<<24^P[i>>16&255]<<16^P[s>>8&255]<<8^P[e&255]^n[m++],a=o,o=i,i=s,s=e,e=a;return p}c.bitArray={bitSlice:function(t,e,r){return t=c.bitArray.Y(t.slice(e/32),32-(e&31)).slice(1),r===void 0?t:c.bitArray.clamp(t,r-e)},extract:function(t,e,r){var n=Math.floor(-e-r&31);return((e+r-1^e)&-32?t[e/32|0]<<32-n^t[e/32+1|0]>>>n:t[e/32|0]>>>n)&(1<<r)-1},concat:function(t,e){if(t.length===0||e.length===0)return t.concat(e);var r=t[t.length-1],n=c.bitArray.getPartial(r);return n===32?t.concat(e):c.bitArray.Y(e,n,r|0,t.slice(0,t.length-1))},bitLength:function(t){var e=t.length;return e===0?0:32*(e-1)+c.bitArray.getPartial(t[e-1])},clamp:function(t,e){if(32*t.length<e)return t;t=t.slice(0,Math.ceil(e/32));var r=t.length;return e=e&31,0<r&&e&&(t[r-1]=c.bitArray.partial(e,t[r-1]&2147483648>>e-1,1)),t},partial:function(t,e,r){return t===32?e:(r?e|0:e<<32-t)+1099511627776*t},getPartial:function(t){return Math.round(t/1099511627776)||32},equal:function(t,e){if(c.bitArray.bitLength(t)!==c.bitArray.bitLength(e))return!1;var r=0,n;for(n=0;n<t.length;n++)r|=t[n]^e[n];return r===0},Y:function(t,e,r,n){var o;for(o=0,n===void 0&&(n=[]);32<=e;e-=32)n.push(r),r=0;if(e===0)return n.concat(t);for(o=0;o<t.length;o++)n.push(r|t[o]>>>e),r=t[o]<<32-e;return o=t.length?t[t.length-1]:0,t=c.bitArray.getPartial(o),n.push(c.bitArray.partial(e+t&31,32<e+t?r:n.pop(),1)),n},P:function(t,e){return[t[0]^e[0],t[1]^e[1],t[2]^e[2],t[3]^e[3]]},byteswapM:function(t){var e,r;for(e=0;e<t.length;++e)r=t[e],t[e]=r>>>24|r>>>8&65280|(r&65280)<<8|r<<24;return t}};c.codec.utf8String={fromBits:function(t){var e="",r=c.bitArray.bitLength(t),n,o;for(n=0;n<r/8;n++)!(n&3)&&(o=t[n/4]),e+=String.fromCharCode(o>>>8>>>8>>>8),o<<=8;return decodeURIComponent(escape(e))},toBits:function(t){t=unescape(encodeURIComponent(t));var e=[],r,n=0;for(r=0;r<t.length;r++)n=n<<8|t.charCodeAt(r),(r&3)===3&&(e.push(n),n=0);return r&3&&e.push(c.bitArray.partial(8*(r&3),n)),e}};c.codec.hex={fromBits:function(t){var e="",r;for(r=0;r<t.length;r++)e+=((t[r]|0)+0xf00000000000).toString(16).substr(4);return e.substr(0,c.bitArray.bitLength(t)/4)},toBits:function(t){var e,r=[],n;for(t=t.replace(/\s|0x/g,""),n=t.length,t=t+"00000000",e=0;e<t.length;e+=8)r.push(parseInt(t.substr(e,8),16)^0);return c.bitArray.clamp(r,4*n)}};c.codec.base64={S:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",fromBits:function(t,e,r){var n="",o=0,i=c.codec.base64.S,s=0,a=c.bitArray.bitLength(t);for(r&&(i=i.substr(0,62)+"-_"),r=0;6*n.length<a;)n+=i.charAt((s^t[r]>>>o)>>>26),6>o?(s=t[r]<<6-o,o+=26,r++):(s<<=6,o-=6);for(;n.length&3&&!e;)n+="=";return n},toBits:function(t,e){t=t.replace(/\s|=/g,"");var r=[],n,o=0,i=c.codec.base64.S,s=0,a;for(e&&(i=i.substr(0,62)+"-_"),n=0;n<t.length;n++){if(a=i.indexOf(t.charAt(n)),0>a)throw new c.exception.invalid("this isn't base64!");26<o?(o-=26,r.push(s^a>>>o),s=a<<32-o):(o+=6,s^=a<<32-o)}return o&56&&r.push(c.bitArray.partial(o&56,s,1)),r}};c.codec.base64url={fromBits:function(t){return c.codec.base64.fromBits(t,1,1)},toBits:function(t){return c.codec.base64.toBits(t,1)}};c.hash.sha256=function(t){this.b[0]||this.C(),t?(this.g=t.g.slice(0),this.f=t.f.slice(0),this.c=t.c):this.reset()};c.hash.sha256.hash=function(t){return new c.hash.sha256().update(t).finalize()};c.hash.sha256.prototype={blockSize:512,reset:function(){return this.g=this.o.slice(0),this.f=[],this.c=0,this},update:function(t){typeof t=="string"&&(t=c.codec.utf8String.toBits(t));var e,r=this.f=c.bitArray.concat(this.f,t);if(e=this.c,t=this.c=e+c.bitArray.bitLength(t),9007199254740991<t)throw new c.exception.invalid("Cannot hash more than 2^53 - 1 bits");if(typeof Uint32Array<"u"){var n=new Uint32Array(r),o=0;for(e=512+e-(512+e&511);e<=t;e+=512)this.l(n.subarray(16*o,16*(o+1))),o+=1;r.splice(0,16*o)}else for(e=512+e-(512+e&511);e<=t;e+=512)this.l(r.splice(0,16));return this},finalize:function(){var t,r=this.f,e=this.g,r=c.bitArray.concat(r,[c.bitArray.partial(1,1)]);for(t=r.length+2;t&15;t++)r.push(0);for(r.push(Math.floor(this.c/4294967296)),r.push(this.c|0);r.length;)this.l(r.splice(0,16));return this.reset(),e},o:[],b:[],C:function(){function t(i){return 4294967296*(i-Math.floor(i))|0}for(var e=0,r=2,n,o;64>e;r++){for(o=!0,n=2;n*n<=r;n++)if(r%n===0){o=!1;break}o&&(8>e&&(this.o[e]=t(Math.pow(r,.5))),this.b[e]=t(Math.pow(r,1/3)),e++)}},l:function(t){var e,r,n,o=this.g,i=this.b,s=o[0],a=o[1],f=o[2],u=o[3],h=o[4],l=o[5],m=o[6],p=o[7];for(e=0;64>e;e++)16>e?r=t[e]:(r=t[e+1&15],n=t[e+14&15],r=t[e&15]=(r>>>7^r>>>18^r>>>3^r<<25^r<<14)+(n>>>17^n>>>19^n>>>10^n<<15^n<<13)+t[e&15]+t[e+9&15]|0),r=r+p+(h>>>6^h>>>11^h>>>25^h<<26^h<<21^h<<7)+(m^h&(l^m))+i[e],p=m,m=l,l=h,h=u+r|0,u=f,f=a,a=s,s=r+(a&f^u&(a^f))+(a>>>2^a>>>13^a>>>22^a<<30^a<<19^a<<10)|0;o[0]=o[0]+s|0,o[1]=o[1]+a|0,o[2]=o[2]+f|0,o[3]=o[3]+u|0,o[4]=o[4]+h|0,o[5]=o[5]+l|0,o[6]=o[6]+m|0,o[7]=o[7]+p|0}};c.hash.sha512=function(t){this.b[0]||this.C(),t?(this.g=t.g.slice(0),this.f=t.f.slice(0),this.c=t.c):this.reset()};c.hash.sha512.hash=function(t){return new c.hash.sha512().update(t).finalize()};c.hash.sha512.prototype={blockSize:1024,reset:function(){return this.g=this.o.slice(0),this.f=[],this.c=0,this},update:function(t){typeof t=="string"&&(t=c.codec.utf8String.toBits(t));var e,r=this.f=c.bitArray.concat(this.f,t);if(e=this.c,t=this.c=e+c.bitArray.bitLength(t),9007199254740991<t)throw new c.exception.invalid("Cannot hash more than 2^53 - 1 bits");if(typeof Uint32Array<"u"){var n=new Uint32Array(r),o=0;for(e=1024+e-(1024+e&1023);e<=t;e+=1024)this.l(n.subarray(32*o,32*(o+1))),o+=1;r.splice(0,32*o)}else for(e=1024+e-(1024+e&1023);e<=t;e+=1024)this.l(r.splice(0,32));return this},finalize:function(){var t,r=this.f,e=this.g,r=c.bitArray.concat(r,[c.bitArray.partial(1,1)]);for(t=r.length+4;t&31;t++)r.push(0);for(r.push(0),r.push(0),r.push(Math.floor(this.c/4294967296)),r.push(this.c|0);r.length;)this.l(r.splice(0,32));return this.reset(),e},o:[],ia:[12372232,13281083,9762859,1914609,15106769,4090911,4308331,8266105],b:[],ka:[2666018,15689165,5061423,9034684,4764984,380953,1658779,7176472,197186,7368638,14987916,16757986,8096111,1480369,13046325,6891156,15813330,5187043,9229749,11312229,2818677,10937475,4324308,1135541,6741931,11809296,16458047,15666916,11046850,698149,229999,945776,13774844,2541862,12856045,9810911,11494366,7844520,15576806,8533307,15795044,4337665,16291729,5553712,15684120,6662416,7413802,12308920,13816008,4303699,9366425,10176680,13195875,4295371,6546291,11712675,15708924,1519456,15772530,6568428,6495784,8568297,13007125,7492395,2515356,12632583,14740254,7262584,1535930,13146278,16321966,1853211,294276,13051027,13221564,1051980,4080310,6651434,14088940,4675607],C:function(){function t(s){return 4294967296*(s-Math.floor(s))|0}function e(s){return 1099511627776*(s-Math.floor(s))&255}for(var r=0,n=2,o,i;80>r;n++){for(i=!0,o=2;o*o<=n;o++)if(n%o===0){i=!1;break}i&&(8>r&&(this.o[2*r]=t(Math.pow(n,.5)),this.o[2*r+1]=e(Math.pow(n,.5))<<24|this.ia[r]),this.b[2*r]=t(Math.pow(n,1/3)),this.b[2*r+1]=e(Math.pow(n,1/3))<<24|this.ka[r],r++)}},l:function(t){var e,r,n=this.g,o=this.b,i=n[0],s=n[1],a=n[2],f=n[3],u=n[4],h=n[5],l=n[6],m=n[7],p=n[8],v=n[9],L=n[10],D=n[11],P=n[12],ie=n[13],Oe=n[14],se=n[15],w;if(typeof Uint32Array<"u"){w=Array(160);for(var g=0;32>g;g++)w[g]=t[g]}else w=t;var g=i,A=s,G=a,U=f,Y=u,F=h,ye=l,X=m,k=p,x=v,ce=L,$=D,ae=P,q=ie,ve=Oe,Q=se;for(t=0;80>t;t++){if(16>t)e=w[2*t],r=w[2*t+1];else{r=w[2*(t-15)];var y=w[2*(t-15)+1];e=(y<<31|r>>>1)^(y<<24|r>>>8)^r>>>7;var C=(r<<31|y>>>1)^(r<<24|y>>>8)^(r<<25|y>>>7);r=w[2*(t-2)];var S=w[2*(t-2)+1],y=(S<<13|r>>>19)^(r<<3|S>>>29)^r>>>6,S=(r<<13|S>>>19)^(S<<3|r>>>29)^(r<<26|S>>>6),ge=w[2*(t-7)],we=w[2*(t-16)],V=w[2*(t-16)+1];r=C+w[2*(t-7)+1],e=e+ge+(r>>>0<C>>>0?1:0),r+=S,e+=y+(r>>>0<S>>>0?1:0),r+=V,e+=we+(r>>>0<V>>>0?1:0)}w[2*t]=e|=0,w[2*t+1]=r|=0;var ge=k&ce^~k&ae,De=x&$^~x&q,S=g&G^g&Y^G&Y,st=A&U^A&F^U&F,we=(A<<4|g>>>28)^(g<<30|A>>>2)^(g<<25|A>>>7),V=(g<<4|A>>>28)^(A<<30|g>>>2)^(A<<25|g>>>7),ct=o[2*t],ke=o[2*t+1],y=Q+((k<<18|x>>>14)^(k<<14|x>>>18)^(x<<23|k>>>9)),C=ve+((x<<18|k>>>14)^(x<<14|k>>>18)^(k<<23|x>>>9))+(y>>>0<Q>>>0?1:0),y=y+De,C=C+(ge+(y>>>0<De>>>0?1:0)),y=y+ke,C=C+(ct+(y>>>0<ke>>>0?1:0)),y=y+r|0,C=C+(e+(y>>>0<r>>>0?1:0));r=V+st,e=we+S+(r>>>0<V>>>0?1:0),ve=ae,Q=q,ae=ce,q=$,ce=k,$=x,x=X+y|0,k=ye+C+(x>>>0<X>>>0?1:0)|0,ye=Y,X=F,Y=G,F=U,G=g,U=A,A=y+r|0,g=C+e+(A>>>0<y>>>0?1:0)|0}s=n[1]=s+A|0,n[0]=i+g+(s>>>0<A>>>0?1:0)|0,f=n[3]=f+U|0,n[2]=a+G+(f>>>0<U>>>0?1:0)|0,h=n[5]=h+F|0,n[4]=u+Y+(h>>>0<F>>>0?1:0)|0,m=n[7]=m+X|0,n[6]=l+ye+(m>>>0<X>>>0?1:0)|0,v=n[9]=v+x|0,n[8]=p+k+(v>>>0<x>>>0?1:0)|0,D=n[11]=D+$|0,n[10]=L+ce+(D>>>0<$>>>0?1:0)|0,ie=n[13]=ie+q|0,n[12]=P+ae+(ie>>>0<q>>>0?1:0)|0,se=n[15]=se+Q|0,n[14]=Oe+ve+(se>>>0<Q>>>0?1:0)|0}};c.mode.ccm={name:"ccm",F:[],listenProgress:function(t){c.mode.ccm.F.push(t)},unListenProgress:function(t){t=c.mode.ccm.F.indexOf(t),-1<t&&c.mode.ccm.F.splice(t,1)},da:function(t){var e=c.mode.ccm.F.slice(),r;for(r=0;r<e.length;r+=1)e[r](t)},encrypt:function(t,e,r,n,o){var i,s=e.slice(0),a=c.bitArray,f=a.bitLength(r)/8,u=a.bitLength(s)/8;if(o=o||64,n=n||[],7>f)throw new c.exception.invalid("ccm: iv must be at least 7 bytes");for(i=2;4>i&&u>>>8*i;i++);return i<15-f&&(i=15-f),r=a.clamp(r,8*(15-i)),e=c.mode.ccm.U(t,e,r,n,o,i),s=c.mode.ccm.V(t,s,r,e,o,i),a.concat(s.data,s.tag)},decrypt:function(t,e,r,n,o){o=o||64,n=n||[];var i=c.bitArray,s=i.bitLength(r)/8,u=i.bitLength(e),a=i.clamp(e,u-o),f=i.bitSlice(e,u-o),u=(u-o)/8;if(7>s)throw new c.exception.invalid("ccm: iv must be at least 7 bytes");for(e=2;4>e&&u>>>8*e;e++);if(e<15-s&&(e=15-s),r=i.clamp(r,8*(15-e)),a=c.mode.ccm.V(t,a,r,f,o,e),t=c.mode.ccm.U(t,a.data,r,n,o,e),!i.equal(a.tag,t))throw new c.exception.corrupt("ccm: tag doesn't match");return a.data},ma:function(t,e,r,n,o,i){var s=[],a=c.bitArray,f=a.P;if(n=[a.partial(8,(e.length?64:0)|n-2<<2|i-1)],n=a.concat(n,r),n[3]|=o,n=t.encrypt(n),e.length)for(r=a.bitLength(e)/8,65279>=r?s=[a.partial(16,r)]:4294967295>=r&&(s=a.concat([a.partial(16,65534)],[r])),s=a.concat(s,e),e=0;e<s.length;e+=4)n=t.encrypt(f(n,s.slice(e,e+4).concat([0,0,0])));return n},U:function(t,e,r,n,o,i){var s=c.bitArray,a=s.P;if(o/=8,o%2||4>o||16<o)throw new c.exception.invalid("ccm: invalid tag length");if(4294967295<n.length||4294967295<e.length)throw new c.exception.bug("ccm: can't deal with 4GiB or more data");for(r=c.mode.ccm.ma(t,n,r,o,s.bitLength(e)/8,i),n=0;n<e.length;n+=4)r=t.encrypt(a(r,e.slice(n,n+4).concat([0,0,0])));return s.clamp(r,8*o)},V:function(t,e,r,n,o,i){var s,a=c.bitArray;s=a.P;var f=e.length,u=a.bitLength(e),h=f/50,l=h;if(r=a.concat([a.partial(8,i-1)],r).concat([0,0,0]).slice(0,4),n=a.bitSlice(s(n,t.encrypt(r)),0,o),!f)return{tag:n,data:[]};for(s=0;s<f;s+=4)s>h&&(c.mode.ccm.da(s/f),h+=l),r[3]++,o=t.encrypt(r),e[s]^=o[0],e[s+1]^=o[1],e[s+2]^=o[2],e[s+3]^=o[3];return{tag:n,data:a.clamp(e,u)}}};c.misc.hmac=function(t,e){this.W=e=e||c.hash.sha256;var r=[[],[]],n,o=e.prototype.blockSize/32;for(this.B=[new e,new e],t.length>o&&(t=e.hash(t)),n=0;n<o;n++)r[0][n]=t[n]^909522486,r[1][n]=t[n]^1549556828;this.B[0].update(r[0]),this.B[1].update(r[1]),this.O=new e(this.B[0])};c.misc.hmac.prototype.encrypt=c.misc.hmac.prototype.mac=function(t){if(this.Z)throw new c.exception.invalid("encrypt on already updated hmac called!");return this.update(t),this.digest(t)};c.misc.hmac.prototype.reset=function(){this.O=new this.W(this.B[0]),this.Z=!1};c.misc.hmac.prototype.update=function(t){this.Z=!0,this.O.update(t)};c.misc.hmac.prototype.digest=function(){var t=this.O.finalize(),t=new this.W(this.B[1]).update(t).finalize();return this.reset(),t};c.misc.pbkdf2=function(t,e,r,n,o){if(r=r||1e4,0>n||0>r)throw new c.exception.invalid("invalid params to pbkdf2");typeof t=="string"&&(t=c.codec.utf8String.toBits(t)),typeof e=="string"&&(e=c.codec.utf8String.toBits(e)),o=o||c.misc.hmac,t=new o(t);var i,s,a,f,u=[],h=c.bitArray;for(f=1;32*u.length<(n||1);f++){for(o=i=t.encrypt(h.concat(e,[f])),s=1;s<r;s++)for(i=t.encrypt(i),a=0;a<i.length;a++)o[a]^=i[a];u=u.concat(o)}return n&&(u=h.clamp(u,n)),u};c.prng=function(t){this.h=[new c.hash.sha256],this.s=[0],this.N=0,this.G={},this.M=0,this.T={},this.X=this.i=this.u=this.fa=0,this.b=[0,0,0,0,0,0,0,0],this.m=[0,0,0,0],this.K=void 0,this.L=t,this.D=!1,this.J={progress:{},seeded:{}},this.A=this.ea=0,this.H=1,this.I=2,this.aa=65536,this.R=[0,48,64,96,128,192,256,384,512,768,1024],this.ba=3e4,this.$=80};c.prng.prototype={randomWords:function(t,e){var r=[],n;n=this.isReady(e);var o;if(n===this.A)throw new c.exception.notReady("generator isn't seeded");if(n&this.I){n=!(n&this.H),o=[];var i=0,s;for(this.X=o[0]=new Date().valueOf()+this.ba,s=0;16>s;s++)o.push(4294967296*Math.random()|0);for(s=0;s<this.h.length&&(o=o.concat(this.h[s].finalize()),i+=this.s[s],this.s[s]=0,n||!(this.N&1<<s));s++);for(this.N>=1<<this.h.length&&(this.h.push(new c.hash.sha256),this.s.push(0)),this.i-=i,i>this.u&&(this.u=i),this.N++,this.b=c.hash.sha256.hash(this.b.concat(o)),this.K=new c.cipher.aes(this.b),n=0;4>n&&(this.m[n]=this.m[n]+1|0,!this.m[n]);n++);}for(n=0;n<t;n+=4)(n+1)%this.aa===0&&Ue(this),o=be(this),r.push(o[0],o[1],o[2],o[3]);return Ue(this),r.slice(0,t)},setDefaultParanoia:function(t,e){if(t===0&&e!=="Setting paranoia=0 will ruin your security; use it only for testing")throw new c.exception.invalid("Setting paranoia=0 will ruin your security; use it only for testing");this.L=t},addEntropy:function(t,e,r){r=r||"user";var n,o,i=new Date().valueOf(),s=this.G[r],a=this.isReady(),f=0;switch(n=this.T[r],n===void 0&&(n=this.T[r]=this.fa++),s===void 0&&(s=this.G[r]=0),this.G[r]=(this.G[r]+1)%this.h.length,typeof t){case"number":e===void 0&&(e=1),this.h[s].update([n,this.M++,1,e,i,1,t|0]);break;case"object":if(r=Object.prototype.toString.call(t),r==="[object Uint32Array]"){for(o=[],r=0;r<t.length;r++)o.push(t[r]);t=o}else for(r!=="[object Array]"&&(f=1),r=0;r<t.length&&!f;r++)typeof t[r]!="number"&&(f=1);if(!f){if(e===void 0)for(r=e=0;r<t.length;r++)for(o=t[r];0<o;)e++,o=o>>>1;this.h[s].update([n,this.M++,2,e,i,t.length].concat(t))}break;case"string":e===void 0&&(e=t.length),this.h[s].update([n,this.M++,3,e,i,t.length]),this.h[s].update(t);break;default:f=1}if(f)throw new c.exception.bug("random: addEntropy only supports number, array of numbers or string");this.s[s]+=e,this.i+=e,a===this.A&&(this.isReady()!==this.A&&Be("seeded",Math.max(this.u,this.i)),Be("progress",this.getProgress()))},isReady:function(t){return t=this.R[t!==void 0?t:this.L],this.u&&this.u>=t?this.s[0]>this.$&&new Date().valueOf()>this.X?this.I|this.H:this.H:this.i>=t?this.I|this.A:this.A},getProgress:function(t){return t=this.R[t||this.L],this.u>=t||this.i>t?1:this.i/t},startCollectors:function(){if(!this.D){if(this.a={loadTimeCollector:ee(this,this.la),mouseCollector:ee(this,this.na),keyboardCollector:ee(this,this.ja),accelerometerCollector:ee(this,this.ca),touchCollector:ee(this,this.pa)},window.addEventListener)window.addEventListener("load",this.a.loadTimeCollector,!1),window.addEventListener("mousemove",this.a.mouseCollector,!1),window.addEventListener("keypress",this.a.keyboardCollector,!1),window.addEventListener("devicemotion",this.a.accelerometerCollector,!1),window.addEventListener("touchmove",this.a.touchCollector,!1);else if(document.attachEvent)document.attachEvent("onload",this.a.loadTimeCollector),document.attachEvent("onmousemove",this.a.mouseCollector),document.attachEvent("keypress",this.a.keyboardCollector);else throw new c.exception.bug("can't attach event");this.D=!0}},stopCollectors:function(){this.D&&(window.removeEventListener?(window.removeEventListener("load",this.a.loadTimeCollector,!1),window.removeEventListener("mousemove",this.a.mouseCollector,!1),window.removeEventListener("keypress",this.a.keyboardCollector,!1),window.removeEventListener("devicemotion",this.a.accelerometerCollector,!1),window.removeEventListener("touchmove",this.a.touchCollector,!1)):document.detachEvent&&(document.detachEvent("onload",this.a.loadTimeCollector),document.detachEvent("onmousemove",this.a.mouseCollector),document.detachEvent("keypress",this.a.keyboardCollector)),this.D=!1)},addEventListener:function(t,e){this.J[t][this.ea++]=e},removeEventListener:function(t,e){var r,n,o=this.J[t],i=[];for(n in o)o.hasOwnProperty(n)&&o[n]===e&&i.push(n);for(r=0;r<i.length;r++)n=i[r],delete o[n]},ja:function(){Z(this,1)},na:function(t){var e,r;try{e=t.x||t.clientX||t.offsetX||0,r=t.y||t.clientY||t.offsetY||0}catch{r=e=0}e!=0&&r!=0&&this.addEntropy([e,r],2,"mouse"),Z(this,0)},pa:function(t){t=t.touches[0]||t.changedTouches[0],this.addEntropy([t.pageX||t.clientX,t.pageY||t.clientY],1,"touch"),Z(this,0)},la:function(){Z(this,2)},ca:function(t){if(t=t.accelerationIncludingGravity.x||t.accelerationIncludingGravity.y||t.accelerationIncludingGravity.z,window.orientation){var e=window.orientation;typeof e=="number"&&this.addEntropy(e,1,"accelerometer")}t&&this.addEntropy(t,2,"accelerometer"),Z(this,0)}};function Be(t,e){var r,n=c.random.J[t],o=[];for(r in n)n.hasOwnProperty(r)&&o.push(n[r]);for(r=0;r<o.length;r++)o[r](e)}function Z(t,e){typeof window<"u"&&window.performance&&typeof window.performance.now=="function"?t.addEntropy(window.performance.now(),e,"loadtime"):t.addEntropy(new Date().valueOf(),e,"loadtime")}function Ue(t){t.b=be(t).concat(be(t)),t.K=new c.cipher.aes(t.b)}function be(t){for(var e=0;4>e&&(t.m[e]=t.m[e]+1|0,!t.m[e]);e++);return t.K.encrypt(t.m)}function ee(t,e){return function(){e.apply(t,arguments)}}c.random=new c.prng(6);e:try{if(he=typeof K<"u"&&K.exports){try{le=dt("crypto")}catch{le=null}he=ue=le}if(he&&ue.randomBytes)te=ue.randomBytes(128),te=new Uint32Array(new Uint8Array(te).buffer),c.random.addEntropy(te,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(re=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(re);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(re);else break e;c.random.addEntropy(re,1024,"crypto['getRandomValues']")}}catch(t){typeof window<"u"&&window.console&&(console.log("There was an error collecting entropy from the browser:"),console.log(t))}var te,ue,re,he,le;c.json={defaults:{v:1,iter:1e4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ha:function(t,e,r,n){r=r||{},n=n||{};var o=c.json,i=o.j({iv:c.random.randomWords(4,0)},o.defaults),s;if(o.j(i,r),r=i.adata,typeof i.salt=="string"&&(i.salt=c.codec.base64.toBits(i.salt)),typeof i.iv=="string"&&(i.iv=c.codec.base64.toBits(i.iv)),!c.mode[i.mode]||!c.cipher[i.cipher]||typeof t=="string"&&100>=i.iter||i.ts!==64&&i.ts!==96&&i.ts!==128||i.ks!==128&&i.ks!==192&&i.ks!==256||2>i.iv.length||4<i.iv.length)throw new c.exception.invalid("json encrypt: invalid parameters");return typeof t=="string"?(s=c.misc.cachedPbkdf2(t,i),t=s.key.slice(0,i.ks/32),i.salt=s.salt):c.ecc&&t instanceof c.ecc.elGamal.publicKey&&(s=t.kem(),i.kemtag=s.tag,t=s.key.slice(0,i.ks/32)),typeof e=="string"&&(e=c.codec.utf8String.toBits(e)),typeof r=="string"&&(i.adata=r=c.codec.utf8String.toBits(r)),s=new c.cipher[i.cipher](t),o.j(n,i),n.key=t,i.ct=i.mode==="ccm"&&c.arrayBuffer&&c.arrayBuffer.ccm&&e instanceof ArrayBuffer?c.arrayBuffer.ccm.encrypt(s,e,i.iv,r,i.ts):c.mode[i.mode].encrypt(s,e,i.iv,r,i.ts),i},encrypt:function(t,e,r,n){var o=c.json,i=o.ha.apply(o,arguments);return o.encode(i)},ga:function(t,e,r,n){r=r||{},n=n||{};var o=c.json;e=o.j(o.j(o.j({},o.defaults),e),r,!0);var i,s;if(i=e.adata,typeof e.salt=="string"&&(e.salt=c.codec.base64.toBits(e.salt)),typeof e.iv=="string"&&(e.iv=c.codec.base64.toBits(e.iv)),!c.mode[e.mode]||!c.cipher[e.cipher]||typeof t=="string"&&100>=e.iter||e.ts!==64&&e.ts!==96&&e.ts!==128||e.ks!==128&&e.ks!==192&&e.ks!==256||!e.iv||2>e.iv.length||4<e.iv.length)throw new c.exception.invalid("json decrypt: invalid parameters");return typeof t=="string"?(s=c.misc.cachedPbkdf2(t,e),t=s.key.slice(0,e.ks/32),e.salt=s.salt):c.ecc&&t instanceof c.ecc.elGamal.secretKey&&(t=t.unkem(c.codec.base64.toBits(e.kemtag)).slice(0,e.ks/32)),typeof i=="string"&&(i=c.codec.utf8String.toBits(i)),s=new c.cipher[e.cipher](t),i=e.mode==="ccm"&&c.arrayBuffer&&c.arrayBuffer.ccm&&e.ct instanceof ArrayBuffer?c.arrayBuffer.ccm.decrypt(s,e.ct,e.iv,e.tag,i,e.ts):c.mode[e.mode].decrypt(s,e.ct,e.iv,i,e.ts),o.j(n,e),n.key=t,r.raw===1?i:c.codec.utf8String.fromBits(i)},decrypt:function(t,e,r,n){var o=c.json;return o.ga(t,o.decode(e),r,n)},encode:function(t){var e,r="{",n="";for(e in t)if(t.hasOwnProperty(e)){if(!e.match(/^[a-z0-9]+$/i))throw new c.exception.invalid("json encode: invalid property name");switch(r+=n+'"'+e+'":',n=",",typeof t[e]){case"number":case"boolean":r+=t[e];break;case"string":r+='"'+escape(t[e])+'"';break;case"object":r+='"'+c.codec.base64.fromBits(t[e],0)+'"';break;default:throw new c.exception.bug("json encode: unsupported type")}}return r+"}"},decode:function(t){if(t=t.replace(/\s/g,""),!t.match(/^\{.*\}$/))throw new c.exception.invalid("json decode: this isn't json!");t=t.replace(/^\{|\}$/g,"").split(/,/);var e={},r,n;for(r=0;r<t.length;r++){if(!(n=t[r].match(/^\s*(?:(["']?)([a-z][a-z0-9]*)\1)\s*:\s*(?:(-?\d+)|"([a-z0-9+\/%*_.@=\-]*)"|(true|false))$/i)))throw new c.exception.invalid("json decode: this isn't json!");n[3]!=null?e[n[2]]=parseInt(n[3],10):n[4]!=null?e[n[2]]=n[2].match(/^(ct|adata|salt|iv)$/)?c.codec.base64.toBits(n[4]):unescape(n[4]):n[5]!=null&&(e[n[2]]=n[5]==="true")}return e},j:function(t,e,r){if(t===void 0&&(t={}),e===void 0)return t;for(var n in e)if(e.hasOwnProperty(n)){if(r&&t[n]!==void 0&&t[n]!==e[n])throw new c.exception.invalid("required parameter overridden");t[n]=e[n]}return t},ra:function(t,e){var r={},n;for(n in t)t.hasOwnProperty(n)&&t[n]!==e[n]&&(r[n]=t[n]);return r},qa:function(t,e){var r={},n;for(n=0;n<e.length;n++)t[e[n]]!==void 0&&(r[e[n]]=t[e[n]]);return r}};c.encrypt=c.json.encrypt;c.decrypt=c.json.decrypt;c.misc.oa={};c.misc.cachedPbkdf2=function(t,e){var r=c.misc.oa,n;return e=e||{},n=e.iter||1e3,r=r[t]=r[t]||{},n=r[n]=r[n]||{firstSalt:e.salt&&e.salt.length?e.salt.slice(0):c.random.randomWords(2,0)},r=e.salt===void 0?n.firstSalt:e.salt,n[r]=n[r]||c.misc.pbkdf2(t,r,e.iter),{key:n[r].slice(0),salt:r.slice(0)}};typeof K<"u"&&K.exports&&(K.exports=c);typeof define=="function"&&define([],function(){return c})});var tt=Ce((qr,_e)=>{"use strict";var H=typeof Reflect=="object"?Reflect:null,Je=H&&typeof H.apply=="function"?H.apply:function(e,r,n){return Function.prototype.apply.call(e,r,n)},pe;H&&typeof H.ownKeys=="function"?pe=H.ownKeys:Object.getOwnPropertySymbols?pe=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:pe=function(e){return Object.getOwnPropertyNames(e)};function St(t){console&&console.warn&&console.warn(t)}var Ye=Number.isNaN||function(e){return e!==e};function d(){d.init.call(this)}_e.exports=d;_e.exports.once=jt;d.EventEmitter=d;d.prototype._events=void 0;d.prototype._eventsCount=0;d.prototype._maxListeners=void 0;var Ge=10;function de(t){if(typeof t!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}Object.defineProperty(d,"defaultMaxListeners",{enumerable:!0,get:function(){return Ge},set:function(t){if(typeof t!="number"||t<0||Ye(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");Ge=t}});d.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0};d.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||Ye(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};function Xe(t){return t._maxListeners===void 0?d.defaultMaxListeners:t._maxListeners}d.prototype.getMaxListeners=function(){return Xe(this)};d.prototype.emit=function(e){for(var r=[],n=1;n<arguments.length;n++)r.push(arguments[n]);var o=e==="error",i=this._events;if(i!==void 0)o=o&&i.error===void 0;else if(!o)return!1;if(o){var s;if(r.length>0&&(s=r[0]),s instanceof Error)throw s;var a=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw a.context=s,a}var f=i[e];if(f===void 0)return!1;if(typeof f=="function")Je(f,this,r);else for(var u=f.length,h=Ze(f,u),n=0;n<u;++n)Je(h[n],this,r);return!0};function $e(t,e,r,n){var o,i,s;if(de(r),i=t._events,i===void 0?(i=t._events=Object.create(null),t._eventsCount=0):(i.newListener!==void 0&&(t.emit("newListener",e,r.listener?r.listener:r),i=t._events),s=i[e]),s===void 0)s=i[e]=r,++t._eventsCount;else if(typeof s=="function"?s=i[e]=n?[r,s]:[s,r]:n?s.unshift(r):s.push(r),o=Xe(t),o>0&&s.length>o&&!s.warned){s.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=t,a.type=e,a.count=s.length,St(a)}return t}d.prototype.addListener=function(e,r){return $e(this,e,r,!1)};d.prototype.on=d.prototype.addListener;d.prototype.prependListener=function(e,r){return $e(this,e,r,!0)};function Rt(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function qe(t,e,r){var n={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},o=Rt.bind(n);return o.listener=r,n.wrapFn=o,o}d.prototype.once=function(e,r){return de(r),this.on(e,qe(this,e,r)),this};d.prototype.prependOnceListener=function(e,r){return de(r),this.prependListener(e,qe(this,e,r)),this};d.prototype.removeListener=function(e,r){var n,o,i,s,a;if(de(r),o=this._events,o===void 0)return this;if(n=o[e],n===void 0)return this;if(n===r||n.listener===r)--this._eventsCount===0?this._events=Object.create(null):(delete o[e],o.removeListener&&this.emit("removeListener",e,n.listener||r));else if(typeof n!="function"){for(i=-1,s=n.length-1;s>=0;s--)if(n[s]===r||n[s].listener===r){a=n[s].listener,i=s;break}if(i<0)return this;i===0?n.shift():Pt(n,i),n.length===1&&(o[e]=n[0]),o.removeListener!==void 0&&this.emit("removeListener",e,a||r)}return this};d.prototype.off=d.prototype.removeListener;d.prototype.removeAllListeners=function(e){var r,n,o;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[e]),this;if(arguments.length===0){var i=Object.keys(n),s;for(o=0;o<i.length;++o)s=i[o],s!=="removeListener"&&this.removeAllListeners(s);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(r=n[e],typeof r=="function")this.removeListener(e,r);else if(r!==void 0)for(o=r.length-1;o>=0;o--)this.removeListener(e,r[o]);return this};function Qe(t,e,r){var n=t._events;if(n===void 0)return[];var o=n[e];return o===void 0?[]:typeof o=="function"?r?[o.listener||o]:[o]:r?It(o):Ze(o,o.length)}d.prototype.listeners=function(e){return Qe(this,e,!0)};d.prototype.rawListeners=function(e){return Qe(this,e,!1)};d.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):Ve.call(t,e)};d.prototype.listenerCount=Ve;function Ve(t){var e=this._events;if(e!==void 0){var r=e[t];if(typeof r=="function")return 1;if(r!==void 0)return r.length}return 0}d.prototype.eventNames=function(){return this._eventsCount>0?pe(this._events):[]};function Ze(t,e){for(var r=new Array(e),n=0;n<e;++n)r[n]=t[n];return r}function Pt(t,e){for(;e+1<t.length;e++)t[e]=t[e+1];t.pop()}function It(t){for(var e=new Array(t.length),r=0;r<e.length;++r)e[r]=t[r].listener||t[r];return e}function jt(t,e){return new Promise(function(r,n){function o(s){t.removeListener(e,i),n(s)}function i(){typeof t.removeListener=="function"&&t.removeListener("error",o),r([].slice.call(arguments))}et(t,e,i,{once:!0}),e!=="error"&&Mt(t,o,{once:!0})})}function Mt(t,e,r){typeof t.on=="function"&&et(t,"error",e,r)}function et(t,e,r,n){if(typeof t.on=="function")n.once?t.once(e,r):t.on(e,r);else if(typeof t.addEventListener=="function")t.addEventListener(e,function o(i){n.once&&t.removeEventListener(e,o),r(i)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof t)}});var W=class{constructor(e,r){if(!e||e.length!=64)throw Error("Charset must contain 64 characters");this._charset=e,this._noPadding=!!r,this._valid=new RegExp("^["+this._charset.replace("-","\\-")+"]+={0,2}$")}Encode(e){let r=e.byteLength;if(!r)return"";let n=new Uint8Array(e),o="";for(let i=0;i<r;i+=3)o+=this._charset[n[i]>>2]+this._charset[(n[i]&3)<<4|n[i+1]>>4]+this._charset[(n[i+1]&15)<<2|n[i+2]>>6]+this._charset[n[i+2]&63];return r%3==2?(o=o.substring(0,o.length-1),this._noPadding||(o+="=")):r%3==1&&(o=o.substring(0,o.length-2),this._noPadding||(o+="==")),o}Decode(e){if(e=(e||"").replace(/[\s]/g,""),!e)return new ArrayBuffer(0);if(!this._valid.test(e))throw Error("Invalid base64 input sequence");let r=Math.floor(e.length*.75);e[e.length-2]=="="?r-=2:e[e.length-1]=="="&&r--;let n=new Uint8Array(r),o,i,s,a,f=0,u=0;for(;f<e.length*.75;)o=this._charset.indexOf(e.charAt(u++)),i=this._charset.indexOf(e.charAt(u++)),s=this._charset.indexOf(e.charAt(u++)),a=this._charset.indexOf(e.charAt(u++)),n[f++]=o<<2|i>>4,n[f++]=(i&15)<<4|s>>2,n[f++]=(s&3)<<6|a;return n.buffer}};var yt=new W("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function Ae(t){return yt.Encode(t)}var vt=new W("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function xe(t){return vt.Decode(t)}var Et={withStackTrace:!1},Ie=(t,e,r=Et)=>{let n=e.isOk()?{type:"Ok",value:e.value}:{type:"Err",value:e.error},o=r.withStackTrace?new Error().stack:void 0;return{data:n,message:t,stack:o}};function N(t,e,r,n){function o(i){return i instanceof r?i:new r(function(s){s(i)})}return new(r||(r=Promise))(function(i,s){function a(h){try{u(n.next(h))}catch(l){s(l)}}function f(h){try{u(n.throw(h))}catch(l){s(l)}}function u(h){h.done?i(h.value):o(h.value).then(a,f)}u((n=n.apply(t,e||[])).next())})}function Re(t){var e=typeof Symbol=="function"&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function R(t){return this instanceof R?(this.v=t,this):new R(t)}function Pe(t,e,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(t,e||[]),o,i=[];return o=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),a("next"),a("throw"),a("return",s),o[Symbol.asyncIterator]=function(){return this},o;function s(p){return function(v){return Promise.resolve(v).then(p,l)}}function a(p,v){n[p]&&(o[p]=function(L){return new Promise(function(D,P){i.push([p,L,D,P])>1||f(p,L)})},v&&(o[p]=v(o[p])))}function f(p,v){try{u(n[p](v))}catch(L){m(i[0][3],L)}}function u(p){p.value instanceof R?Promise.resolve(p.value.v).then(h,l):m(i[0][2],p)}function h(p){f("next",p)}function l(p){f("throw",p)}function m(p,v){p(v),i.shift(),i.length&&f(i[0][0],i[0][1])}}function At(t){var e,r;return e={},n("next"),n("throw",function(o){throw o}),n("return"),e[Symbol.iterator]=function(){return this},e;function n(o,i){e[o]=t[o]?function(s){return(r=!r)?{value:R(t[o](s)),done:!1}:i?i(s):s}:i}}function xt(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=t[Symbol.asyncIterator],r;return e?e.call(t):(t=typeof Re=="function"?Re(t):t[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(i){r[i]=t[i]&&function(s){return new Promise(function(a,f){s=t[i](s),o(a,f,s.done,s.value)})}}function o(i,s,a,f){Promise.resolve(f).then(function(u){i({value:u,done:a})},s)}}var E=class t{constructor(e){this._promise=e}static fromSafePromise(e){let r=e.then(n=>new _(n));return new t(r)}static fromPromise(e,r){let n=e.then(o=>new _(o)).catch(o=>new O(r(o)));return new t(n)}static fromThrowable(e,r){return(...n)=>new t(N(this,void 0,void 0,function*(){try{return new _(yield e(...n))}catch(o){return new O(r?r(o):o)}}))}static combine(e){return Lt(e)}static combineWithAllErrors(e){return bt(e)}map(e){return new t(this._promise.then(r=>N(this,void 0,void 0,function*(){return r.isErr()?new O(r.error):new _(yield e(r.value))})))}andThrough(e){return new t(this._promise.then(r=>N(this,void 0,void 0,function*(){if(r.isErr())return new O(r.error);let n=yield e(r.value);return n.isErr()?new O(n.error):new _(r.value)})))}andTee(e){return new t(this._promise.then(r=>N(this,void 0,void 0,function*(){if(r.isErr())return new O(r.error);try{yield e(r.value)}catch{}return new _(r.value)})))}mapErr(e){return new t(this._promise.then(r=>N(this,void 0,void 0,function*(){return r.isOk()?new _(r.value):new O(yield e(r.error))})))}andThen(e){return new t(this._promise.then(r=>{if(r.isErr())return new O(r.error);let n=e(r.value);return n instanceof t?n._promise:n}))}orElse(e){return new t(this._promise.then(r=>N(this,void 0,void 0,function*(){return r.isErr()?e(r.error):new _(r.value)})))}match(e,r){return this._promise.then(n=>n.match(e,r))}unwrapOr(e){return this._promise.then(r=>r.unwrapOr(e))}safeUnwrap(){return Pe(this,arguments,function*(){return yield R(yield R(yield*At(xt(yield R(this._promise.then(r=>r.safeUnwrap()))))))})}then(e,r){return this._promise.then(e,r)}[Symbol.asyncIterator](){return Pe(this,arguments,function*(){let r=yield R(this._promise);return r.isErr()&&(yield yield R(B(r.error))),yield R(r.value)})}},fe=t=>new E(Promise.resolve(new _(t))),B=t=>new E(Promise.resolve(new O(t))),Yt=E.fromPromise,Xt=E.fromSafePromise,$t=E.fromThrowable,je=t=>{let e=T([]);for(let r of t)if(r.isErr()){e=I(r.error);break}else e.map(n=>n.push(r.value));return e},Lt=t=>E.fromSafePromise(Promise.all(t)).andThen(je),Me=t=>{let e=T([]);for(let r of t)r.isErr()&&e.isErr()?e.error.push(r.error):r.isErr()&&e.isOk()?e=I([r.error]):r.isOk()&&e.isOk()&&e.value.push(r.value);return e},bt=t=>E.fromSafePromise(Promise.all(t)).andThen(Me),Le;(function(t){function e(o,i){return(...s)=>{try{let a=o(...s);return T(a)}catch(a){return I(i?i(a):a)}}}t.fromThrowable=e;function r(o){return je(o)}t.combine=r;function n(o){return Me(o)}t.combineWithAllErrors=n})(Le||(Le={}));var T=t=>new _(t);function I(t){return new O(t)}var _=class{constructor(e){this.value=e}isOk(){return!0}isErr(){return!this.isOk()}map(e){return T(e(this.value))}mapErr(e){return T(this.value)}andThen(e){return e(this.value)}andThrough(e){return e(this.value).map(r=>this.value)}andTee(e){try{e(this.value)}catch{}return T(this.value)}orElse(e){return T(this.value)}asyncAndThen(e){return e(this.value)}asyncAndThrough(e){return e(this.value).map(()=>this.value)}asyncMap(e){return E.fromSafePromise(e(this.value))}unwrapOr(e){return this.value}match(e,r){return e(this.value)}safeUnwrap(){let e=this.value;return function*(){return e}()}_unsafeUnwrap(e){return this.value}_unsafeUnwrapErr(e){throw Ie("Called `_unsafeUnwrapErr` on an Ok",this,e)}*[Symbol.iterator](){return this.value}},O=class{constructor(e){this.error=e}isOk(){return!1}isErr(){return!this.isOk()}map(e){return I(this.error)}mapErr(e){return I(e(this.error))}andThrough(e){return I(this.error)}andTee(e){return I(this.error)}andThen(e){return I(this.error)}orElse(e){return e(this.error)}asyncAndThen(e){return B(this.error)}asyncAndThrough(e){return B(this.error)}asyncMap(e){return B(this.error)}unwrapOr(e){return e}match(e,r){return r(this.error)}safeUnwrap(){let e=this.error;return function*(){throw yield I(e),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(e){throw Ie("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}*[Symbol.iterator](){let e=this;return yield e,e}},qt=Le.fromThrowable;var Ne=Se(Fe());var M=class extends Error{constructor(r,n={}){let{cause:o,context:i}=n;super(r,{cause:o});b(this,"context");this.name=this.constructor.name,this.context=i}};var j=class extends M{};var z=class extends j{constructor(){super(...arguments);b(this,"message","Unable to encrypt the provided data")}};var ne=t=>{if(t instanceof Error)return t;let e="[Unable to stringify the thrown value]";try{e=JSON.stringify(t)}catch{}return new Error(e)};var Ke=(t,e)=>{try{let r=Ne.default.encrypt(t,Ae(e));return fe({algo:0,data:r,iv:JSON.parse(r).iv})}catch(r){return B(new z(void 0,{cause:ne(r)}))}};var ze=(t,e)=>kt(t).andThen(r=>{let n=crypto.getRandomValues(new Uint8Array(12));return E.fromPromise(crypto.subtle.encrypt({name:"AES-GCM",iv:n},r,e),o=>new z(void 0,{cause:ne(o)})).andThen(o=>fe({algo:1,data:o,iv:n}))}),kt=t=>E.fromPromise(crypto.subtle.importKey("raw",xe(t),{name:"AES-GCM"},!1,["encrypt","decrypt"]),e=>new j("Unable to import cryptography key",{cause:ne(e)}));var He=(t,e,r)=>r===0?Ke(t,e):ze(t,e);var nt=Se(tt());var rt=new nt.default;var ot=()=>{rt.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),rt.once("OPERATION_FAILED",t=>{self.postMessage({event:"OPERATION_FAILED",error:t})})};var J=class extends M{};var oe=class extends J{constructor(){super(...arguments);b(this,"message","Parameter cannot be undefined")}};var me=class extends J{constructor(){super(...arguments);b(this,"message","File upload already failed")}};var it=!1;self.onmessage=t=>{it||(ot(),it=!0);let{lufiFile:e,chunk:r,algo:n}=t.data.args;r&&typeof n<"u"?e.uploadStatus!==2?He(e.keys.client,r.buffer,n).map(o=>{self.postMessage({encryptedData:o,chunkIndex:r.index},[typeof o.data=="string"?new TextEncoder().encode(o.data):o.data])}).mapErr(o=>{self.postMessage({error:o})}):self.postMessage({error:new me("File upload already failed")}):(r||self.postMessage({error:new oe("chunk buffer cannot be undefined")}),typeof n>"u"&&self.postMessage({error:new oe("algo cannot be undefined")}))};
|