var lt=Object.create;var Le=Object.defineProperty;var pt=Object.getOwnPropertyDescriptor;var dt=Object.getOwnPropertyNames;var mt=Object.getPrototypeOf,yt=Object.prototype.hasOwnProperty;var vt=(t,e,r)=>e in t?Le(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var gt=(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 Me=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var wt=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of dt(e))!yt.call(t,o)&&o!==r&&Le(t,o,{get:()=>e[o],enumerable:!(n=pt(e,o))||n.enumerable});return t};var je=(t,e,r)=>(r=t!=null?lt(mt(t)):{},wt(e||!t||!t.__esModule?Le(r,"default",{value:t,enumerable:!0}):r,t));var D=(t,e,r)=>vt(t,typeof e!="symbol"?e+"":e,r);var ze=Me((or,z)=>{"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 We(this,t,0)},decrypt:function(t){return We(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 We(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],b=a[2],O=a[3],j=a[4];for(l=0;l>>24]^v[i>>16&255]^b[s>>8&255]^O[e&255]^n[m],f=t[i>>>24]^v[s>>16&255]^b[e>>8&255]^O[o&255]^n[m+1],u=t[s>>>24]^v[e>>16&255]^b[o>>8&255]^O[i&255]^n[m+2],e=t[e>>>24]^v[o>>16&255]^b[i>>8&255]^O[s&255]^n[m+3],m+=4,o=a,i=f,s=u;for(l=0;4>l;l++)p[r?3&-l:l]=j[o>>>24]<<24^j[i>>16&255]<<16^j[s>>8&255]<<8^j[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<>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>>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>>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>>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>>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;na)throw new c.exception.invalid("this isn't base64!");26>>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),9007199254740991e;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),9007199254740991r;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],b=n[10],O=n[11],j=n[12],ae=n[13],Ce=n[14],fe=n[15],E;if(typeof Uint32Array<"u"){E=Array(160);for(var w=0;32>w;w++)E[w]=t[w]}else E=t;var w=i,x=s,$=a,F=f,X=u,W=h,we=l,V=m,C=p,L=v,ue=b,q=O,he=j,Q=ae,Ee=Ce,Z=fe;for(t=0;80>t;t++){if(16>t)e=E[2*t],r=E[2*t+1];else{r=E[2*(t-15)];var y=E[2*(t-15)+1];e=(y<<31|r>>>1)^(y<<24|r>>>8)^r>>>7;var S=(r<<31|y>>>1)^(r<<24|y>>>8)^(r<<25|y>>>7);r=E[2*(t-2)];var P=E[2*(t-2)+1],y=(P<<13|r>>>19)^(r<<3|P>>>29)^r>>>6,P=(r<<13|P>>>19)^(P<<3|r>>>29)^(r<<26|P>>>6),Ae=E[2*(t-7)],xe=E[2*(t-16)],ee=E[2*(t-16)+1];r=S+E[2*(t-7)+1],e=e+Ae+(r>>>0>>0?1:0),r+=P,e+=y+(r>>>0

>>0?1:0),r+=ee,e+=xe+(r>>>0>>0?1:0)}E[2*t]=e|=0,E[2*t+1]=r|=0;var Ae=C&ue^~C&he,Se=L&q^~L&Q,P=w&$^w&X^$&X,ut=x&F^x&W^F&W,xe=(x<<4|w>>>28)^(w<<30|x>>>2)^(w<<25|x>>>7),ee=(w<<4|x>>>28)^(x<<30|w>>>2)^(x<<25|w>>>7),ht=o[2*t],Pe=o[2*t+1],y=Z+((C<<18|L>>>14)^(C<<14|L>>>18)^(L<<23|C>>>9)),S=Ee+((L<<18|C>>>14)^(L<<14|C>>>18)^(C<<23|L>>>9))+(y>>>0>>0?1:0),y=y+Se,S=S+(Ae+(y>>>0>>0?1:0)),y=y+Pe,S=S+(ht+(y>>>0>>0?1:0)),y=y+r|0,S=S+(e+(y>>>0>>0?1:0));r=ee+ut,e=xe+P+(r>>>0>>0?1:0),Ee=he,Z=Q,he=ue,Q=q,ue=C,q=L,L=V+y|0,C=we+S+(L>>>0>>0?1:0)|0,we=X,V=W,X=$,W=F,$=w,F=x,x=y+r|0,w=S+e+(x>>>0>>0?1:0)|0}s=n[1]=s+x|0,n[0]=i+w+(s>>>0>>0?1:0)|0,f=n[3]=f+F|0,n[2]=a+$+(f>>>0>>0?1:0)|0,h=n[5]=h+W|0,n[4]=u+X+(h>>>0>>0?1:0)|0,m=n[7]=m+V|0,n[6]=l+we+(m>>>0>>0?1:0)|0,v=n[9]=v+L|0,n[8]=p+C+(v>>>0>>0?1:0)|0,O=n[11]=O+q|0,n[10]=b+ue+(O>>>0>>0?1:0)|0,ae=n[13]=ae+Q|0,n[12]=j+he+(ae>>>0>>0?1:0)|0,fe=n[15]=fe+Z|0,n[14]=Ce+Ee+(fe>>>0>>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),-1f)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;eo||16h&&(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;nn||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;ss;s++)o.push(4294967296*Math.random()|0);for(s=0;s=1<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>>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&&Ne("seeded",Math.max(this.u,this.i)),Ne("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:ne(this,this.la),mouseCollector:ne(this,this.na),keyboardCollector:ne(this,this.ja),accelerometerCollector:ne(this,this.ca),touchCollector:ne(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;re&&(t.m[e]=t.m[e]+1|0,!t.m[e]);e++);return t.K.encrypt(t.m)}function ne(t,e){return function(){e.apply(t,arguments)}}c.random=new c.prng(6);e:try{if(de=typeof z<"u"&&z.exports){try{me=gt("crypto")}catch{me=null}de=pe=me}if(de&&pe.randomBytes)oe=pe.randomBytes(128),oe=new Uint32Array(new Uint8Array(oe).buffer),c.random.addEntropy(oe,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(ie=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(ie);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(ie);else break e;c.random.addEntropy(ie,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 oe,pe,ie,de,me;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=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{"use strict";var K=typeof Reflect=="object"?Reflect:null,Xe=K&&typeof K.apply=="function"?K.apply:function(e,r,n){return Function.prototype.apply.call(e,r,n)},ye;K&&typeof K.ownKeys=="function"?ye=K.ownKeys:Object.getOwnPropertySymbols?ye=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:ye=function(e){return Object.getOwnPropertyNames(e)};function Bt(t){console&&console.warn&&console.warn(t)}var qe=Number.isNaN||function(e){return e!==e};function d(){d.init.call(this)}_e.exports=d;_e.exports.once=Ft;d.EventEmitter=d;d.prototype._events=void 0;d.prototype._eventsCount=0;d.prototype._maxListeners=void 0;var Ve=10;function ve(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 Ve},set:function(t){if(typeof t!="number"||t<0||qe(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");Ve=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||qe(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 Qe(t){return t._maxListeners===void 0?d.defaultMaxListeners:t._maxListeners}d.prototype.getMaxListeners=function(){return Qe(this)};d.prototype.emit=function(e){for(var r=[],n=1;n0&&(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")Xe(f,this,r);else for(var u=f.length,h=nt(f,u),n=0;n0&&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,Bt(a)}return t}d.prototype.addListener=function(e,r){return Ze(this,e,r,!1)};d.prototype.on=d.prototype.addListener;d.prototype.prependListener=function(e,r){return Ze(this,e,r,!0)};function It(){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 et(t,e,r){var n={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},o=It.bind(n);return o.listener=r,n.wrapFn=o,o}d.prototype.once=function(e,r){return ve(r),this.on(e,et(this,e,r)),this};d.prototype.prependOnceListener=function(e,r){return ve(r),this.prependListener(e,et(this,e,r)),this};d.prototype.removeListener=function(e,r){var n,o,i,s,a;if(ve(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():Ut(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=0;o--)this.removeListener(e,r[o]);return this};function tt(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?Tt(o):nt(o,o.length)}d.prototype.listeners=function(e){return tt(this,e,!0)};d.prototype.rawListeners=function(e){return tt(this,e,!1)};d.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):rt.call(t,e)};d.prototype.listenerCount=rt;function rt(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?ye(this._events):[]};function nt(t,e){for(var r=new Array(e),n=0;n>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>4,n[f++]=(i&15)<<4|s>>2,n[f++]=(s&3)<<6|a;return n.buffer}};var Et=new N("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function te(t){return Et.Encode(t)}var At=new N("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function be(t){return At.Decode(t)}var Lt={withStackTrace:!1},Ue=(t,e,r=Lt)=>{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 H(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 Be(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 M(t){return this instanceof M?(this.v=t,this):new M(t)}function Ie(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(b){return new Promise(function(O,j){i.push([p,b,O,j])>1||f(p,b)})},v&&(o[p]=v(o[p])))}function f(p,v){try{u(n[p](v))}catch(b){m(i[0][3],b)}}function u(p){p.value instanceof M?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 bt(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:M(t[o](s)),done:!1}:i?i(s):s}:i}}function Dt(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 Be=="function"?Be(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 A=class t{constructor(e){this._promise=e}static fromSafePromise(e){let r=e.then(n=>new k(n));return new t(r)}static fromPromise(e,r){let n=e.then(o=>new k(o)).catch(o=>new _(r(o)));return new t(n)}static fromThrowable(e,r){return(...n)=>new t(H(this,void 0,void 0,function*(){try{return new k(yield e(...n))}catch(o){return new _(r?r(o):o)}}))}static combine(e){return kt(e)}static combineWithAllErrors(e){return _t(e)}map(e){return new t(this._promise.then(r=>H(this,void 0,void 0,function*(){return r.isErr()?new _(r.error):new k(yield e(r.value))})))}andThrough(e){return new t(this._promise.then(r=>H(this,void 0,void 0,function*(){if(r.isErr())return new _(r.error);let n=yield e(r.value);return n.isErr()?new _(n.error):new k(r.value)})))}andTee(e){return new t(this._promise.then(r=>H(this,void 0,void 0,function*(){if(r.isErr())return new _(r.error);try{yield e(r.value)}catch{}return new k(r.value)})))}mapErr(e){return new t(this._promise.then(r=>H(this,void 0,void 0,function*(){return r.isOk()?new k(r.value):new _(yield e(r.error))})))}andThen(e){return new t(this._promise.then(r=>{if(r.isErr())return new _(r.error);let n=e(r.value);return n instanceof t?n._promise:n}))}orElse(e){return new t(this._promise.then(r=>H(this,void 0,void 0,function*(){return r.isErr()?e(r.error):new k(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 Ie(this,arguments,function*(){return yield M(yield M(yield*bt(Dt(yield M(this._promise.then(r=>r.safeUnwrap()))))))})}then(e,r){return this._promise.then(e,r)}[Symbol.asyncIterator](){return Ie(this,arguments,function*(){let r=yield M(this._promise);return r.isErr()&&(yield yield M(T(r.error))),yield M(r.value)})}},le=t=>new A(Promise.resolve(new k(t))),T=t=>new A(Promise.resolve(new _(t))),Zt=A.fromPromise,er=A.fromSafePromise,tr=A.fromThrowable,Te=t=>{let e=U([]);for(let r of t)if(r.isErr()){e=R(r.error);break}else e.map(n=>n.push(r.value));return e},kt=t=>A.fromSafePromise(Promise.all(t)).andThen(Te),Fe=t=>{let e=U([]);for(let r of t)r.isErr()&&e.isErr()?e.error.push(r.error):r.isErr()&&e.isOk()?e=R([r.error]):r.isOk()&&e.isOk()&&e.value.push(r.value);return e},_t=t=>A.fromSafePromise(Promise.all(t)).andThen(Fe),De;(function(t){function e(o,i){return(...s)=>{try{let a=o(...s);return U(a)}catch(a){return R(i?i(a):a)}}}t.fromThrowable=e;function r(o){return Te(o)}t.combine=r;function n(o){return Fe(o)}t.combineWithAllErrors=n})(De||(De={}));var U=t=>new k(t);function R(t){return new _(t)}var k=class{constructor(e){this.value=e}isOk(){return!0}isErr(){return!this.isOk()}map(e){return U(e(this.value))}mapErr(e){return U(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 U(this.value)}orElse(e){return U(this.value)}asyncAndThen(e){return e(this.value)}asyncAndThrough(e){return e(this.value).map(()=>this.value)}asyncMap(e){return A.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 Ue("Called `_unsafeUnwrapErr` on an Ok",this,e)}*[Symbol.iterator](){return this.value}},_=class{constructor(e){this.error=e}isOk(){return!1}isErr(){return!this.isOk()}map(e){return R(this.error)}mapErr(e){return R(e(this.error))}andThrough(e){return R(this.error)}andTee(e){return R(this.error)}andThen(e){return R(this.error)}orElse(e){return e(this.error)}asyncAndThen(e){return T(this.error)}asyncAndThrough(e){return T(this.error)}asyncMap(e){return T(this.error)}unwrapOr(e){return e}match(e,r){return r(this.error)}safeUnwrap(){let e=this.error;return function*(){throw yield R(e),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(e){throw Ue("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}*[Symbol.iterator](){let e=this;return yield e,e}},rr=De.fromThrowable;var Ge=je(ze());var I=class extends Error{constructor(r,n={}){let{cause:o,context:i}=n;super(r,{cause:o});D(this,"context");this.name=this.constructor.name,this.context=i}};var B=class extends I{};var J=class extends B{constructor(){super(...arguments);D(this,"message","Unable to encrypt the provided data")}};var se=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 Ot=()=>typeof Deno<"u";var G=t=>Ot()?new URL(`./worker/${t}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${t==="main"?`worker/${t}`:t}.js`));var Ke=(t,e)=>{try{let r=Ge.default.encrypt(t,te(e));return le({algo:0,data:r,iv:JSON.parse(r).iv})}catch(r){return T(new J(void 0,{cause:se(r)}))}};var Ye=(t,e)=>Mt(t).andThen(r=>{let n=crypto.getRandomValues(new Uint8Array(12));return A.fromPromise(crypto.subtle.encrypt({name:"AES-GCM",iv:n},r,e),o=>new J(void 0,{cause:se(o)})).andThen(o=>le({algo:1,data:te(o),iv:n}))}),Mt=t=>A.fromPromise(crypto.subtle.importKey("raw",be(t),{name:"AES-GCM"},!1,["encrypt","decrypt"]),e=>new B("Unable to import cryptography key",{cause:se(e)}));var $e=(t,e,r)=>{let n;return r===0?n=Ke(t,e):(typeof e=="string"&&(e=new TextEncoder().encode(e).buffer),n=Ye(t,e)),n};var ct=je(it());var Oe=new ct.default,g,st=!1;self.onmessage=t=>{Ht(t),st||(st=!0,Oe.once("OPERATION_FAILED",()=>{g&&g.terminate()}))};var Ht=(t,e)=>{let{action:r}=t.data;if(r===5||r===8)g.postMessage(t.data);else{switch(r){case 2:g=new Worker(G("cancel"),{type:"module"}),g.postMessage(t.data);break;case 3:g=new Worker(G("download"),{type:"module"}),g.postMessage(t.data);break;case 4:g=new Worker(G("infos"),{type:"module"}),g.postMessage(t.data);break;case 7:g=g||new Worker(G("remove"),{type:"module"}),g.postMessage(t.data);break;case 9:g=g||new Worker(G("upload"),{type:"module"}),g.postMessage(t.data);break;default:console.error("Action not found")}g.onmessage=n=>{e&&e(n),self.postMessage(n.data)},g.onerror=n=>{console.error(`Error: ${n.message}`)}}},at=()=>{Oe.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),Oe.once("OPERATION_FAILED",t=>{self.postMessage({event:"OPERATION_FAILED",error:t})})};var Y=class extends I{};var ce=class extends Y{constructor(){super(...arguments);D(this,"message","Parameter cannot be undefined")}};var ge=class extends Y{constructor(){super(...arguments);D(this,"message","File upload already failed")}};var ft=!1;self.onmessage=t=>{ft||(at(),ft=!0);let{lufiFile:e,chunk:r,algo:n}=t.data.args;r&&typeof n<"u"?e.uploadStatus!==2?$e(e.keys.client,r.buffer,n).map(o=>{self.postMessage({encryptedData:o,chunkIndex:r.index})}).mapErr(o=>{self.postMessage({error:o})}):self.postMessage({error:new ge("File upload already failed")}):(r||self.postMessage({error:new ce("chunk buffer cannot be undefined")}),typeof n>"u"&&self.postMessage({error:new ce("algo cannot be undefined")}))};